aboutsummaryrefslogtreecommitdiffstats
path: root/spec/ruby/core
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-13 21:58:54 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-13 21:58:54 +0000
commitb46da8d84efeb97cb52ba0560d5b149ccda0d561 (patch)
tree382ba848ef97215f1a5ec991727db3ed7f90973c /spec/ruby/core
parent5b55eaa00db05004d1a6b74c3aaa5e680fc73235 (diff)
downloadruby-b46da8d84efeb97cb52ba0560d5b149ccda0d561.tar.gz
Update to ruby/spec@4bb0f25
* Specs added by TruffleRuby. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63654 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core')
-rw-r--r--spec/ruby/core/array/pack/buffer_spec.rb4
-rw-r--r--spec/ruby/core/basicobject/instance_eval_spec.rb8
-rw-r--r--spec/ruby/core/exception/dup_spec.rb61
-rw-r--r--spec/ruby/core/exception/fixtures/common.rb20
-rw-r--r--spec/ruby/core/file/expand_path_spec.rb2
-rw-r--r--spec/ruby/core/file/fixtures/file_types.rb30
-rw-r--r--spec/ruby/core/file/open_spec.rb2
-rw-r--r--spec/ruby/core/file/pipe_spec.rb2
-rw-r--r--spec/ruby/core/file/stat/pipe_spec.rb2
-rw-r--r--spec/ruby/core/integer/dup_spec.rb15
-rw-r--r--spec/ruby/core/io/write_spec.rb2
-rw-r--r--spec/ruby/core/marshal/dump_spec.rb10
-rw-r--r--spec/ruby/core/string/capitalize_spec.rb139
-rw-r--r--spec/ruby/core/string/casecmp_spec.rb20
-rw-r--r--spec/ruby/core/string/downcase_spec.rb139
-rw-r--r--spec/ruby/core/string/swapcase_spec.rb129
-rw-r--r--spec/ruby/core/string/upcase_spec.rb130
-rw-r--r--spec/ruby/core/time/comparison_spec.rb10
18 files changed, 679 insertions, 46 deletions
diff --git a/spec/ruby/core/array/pack/buffer_spec.rb b/spec/ruby/core/array/pack/buffer_spec.rb
index b3bba76cdc..f2dc3e1930 100644
--- a/spec/ruby/core/array/pack/buffer_spec.rb
+++ b/spec/ruby/core/array/pack/buffer_spec.rb
@@ -3,7 +3,7 @@
require_relative '../../../spec_helper'
ruby_version_is '2.4' do
- describe "Aray#pack with `buffer` option" do
+ describe "Array#pack with :buffer option" do
it "returns specified buffer" do
n = [ 65, 66, 67 ]
buffer = " "*3
@@ -36,7 +36,7 @@ ruby_version_is '2.4' do
n.pack("@3ccc", buffer: buffer).should == "123ABC"
end
- it "fills the gap with \0 if buffer content is shorter than offset" do
+ it "fills the gap with \\0 if buffer content is shorter than offset" do
n = [ 65, 66, 67 ]
buffer = "123"
n.pack("@6ccc", buffer: buffer).should == "123\0\0\0ABC"
diff --git a/spec/ruby/core/basicobject/instance_eval_spec.rb b/spec/ruby/core/basicobject/instance_eval_spec.rb
index fc3af6fa83..24b4d6dc69 100644
--- a/spec/ruby/core/basicobject/instance_eval_spec.rb
+++ b/spec/ruby/core/basicobject/instance_eval_spec.rb
@@ -177,4 +177,12 @@ end
end
err.backtrace.first.split(":")[0..1].should == ["b_file", "-98"]
end
+
+ it "has access to the caller's local variables" do
+ x = nil
+
+ instance_eval "x = :value"
+
+ x.should == :value
+ end
end
diff --git a/spec/ruby/core/exception/dup_spec.rb b/spec/ruby/core/exception/dup_spec.rb
new file mode 100644
index 0000000000..f5a067ed2f
--- /dev/null
+++ b/spec/ruby/core/exception/dup_spec.rb
@@ -0,0 +1,61 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+
+describe "Exception#dup" do
+ before :each do
+ @obj = ExceptionSpecs::InitializeException.new("my exception")
+ end
+
+ it "calls #initialize_copy on the new instance" do
+ dup = @obj.dup
+ ScratchPad.recorded.should_not == @obj.object_id
+ ScratchPad.recorded.should == dup.object_id
+ end
+
+ it "copies instance variables" do
+ dup = @obj.dup
+ dup.ivar.should == 1
+ end
+
+ it "does not copy singleton methods" do
+ def @obj.special() :the_one end
+ dup = @obj.dup
+ lambda { dup.special }.should raise_error(NameError)
+ end
+
+ it "does not copy modules included in the singleton class" do
+ class << @obj
+ include ExceptionSpecs::ExceptionModule
+ end
+
+ dup = @obj.dup
+ lambda { dup.repr }.should raise_error(NameError)
+ end
+
+ it "does not copy constants defined in the singleton class" do
+ class << @obj
+ CLONE = :clone
+ end
+
+ dup = @obj.dup
+ lambda { class << dup; CLONE; end }.should raise_error(NameError)
+ end
+
+ it "does copy the message" do
+ @obj.dup.message.should == @obj.message
+ end
+
+ it "does copy the backtrace" do
+ begin
+ # Explicitly raise so a backtrace is associated with the exception.
+ # It's tempting to call `set_backtrace` instead, but that complicates
+ # the test because it might affect other state (e.g., instance variables)
+ # on some implementations.
+ raise ExceptionSpecs::InitializeException.new("my exception")
+ rescue => e
+ @obj = e
+ end
+
+ @obj.dup.backtrace.should == @obj.backtrace
+ end
+end \ No newline at end of file
diff --git a/spec/ruby/core/exception/fixtures/common.rb b/spec/ruby/core/exception/fixtures/common.rb
index 9ddabace11..0ffb3ed855 100644
--- a/spec/ruby/core/exception/fixtures/common.rb
+++ b/spec/ruby/core/exception/fixtures/common.rb
@@ -46,6 +46,26 @@ module ExceptionSpecs
""
end
end
+
+ class InitializeException < StandardError
+ attr_reader :ivar
+
+ def initialize(message = nil)
+ super
+ @ivar = 1
+ end
+
+ def initialize_copy(other)
+ super
+ ScratchPad.record object_id
+ end
+ end
+
+ module ExceptionModule
+ def repr
+ 1
+ end
+ end
end
module NoMethodErrorSpecs
diff --git a/spec/ruby/core/file/expand_path_spec.rb b/spec/ruby/core/file/expand_path_spec.rb
index 9d08cbb02b..99279aec85 100644
--- a/spec/ruby/core/file/expand_path_spec.rb
+++ b/spec/ruby/core/file/expand_path_spec.rb
@@ -109,8 +109,8 @@ describe "File.expand_path" do
File.expand_path(Dir.pwd).should == Dir.pwd
File.expand_path('~/').should == @home
File.expand_path('~/..badfilename').should == "#{@home}/..badfilename"
- File.expand_path('..').should == Dir.pwd.split('/')[0...-1].join("/")
File.expand_path('~/a','~/b').should == "#{@home}/a"
+ File.expand_path('..').should == File.dirname(Dir.pwd)
end
it "does not replace multiple '/' at the beginning of the path" do
diff --git a/spec/ruby/core/file/fixtures/file_types.rb b/spec/ruby/core/file/fixtures/file_types.rb
index 397cac9b6b..a36817fb4e 100644
--- a/spec/ruby/core/file/fixtures/file_types.rb
+++ b/spec/ruby/core/file/fixtures/file_types.rb
@@ -5,17 +5,11 @@ module FileSpecs
@file = tmp("test.txt")
@dir = Dir.pwd
@fifo = tmp("test_fifo")
+ @link = tmp("test_link")
platform_is_not :windows do
- @block = `find /dev /devices -type b 2> /dev/null`.split("\n").first
- @char = `{ tty || find /dev /devices -type c; } 2> /dev/null`.split("\n").last
-
- %w[/dev /usr/bin /usr/local/bin].each do |dir|
- links = `find #{dir} -type l 2> /dev/null`.split("\n")
- next if links.empty?
- @link = links.first
- break
- end
+ @block = `find /dev /devices -type b 2>/dev/null`.split("\n").first
+ @char = `{ tty || find /dev /devices -type c; } 2>/dev/null`.split("\n").last
end
@configured = true
@@ -32,24 +26,29 @@ module FileSpecs
yield @dir
end
- # TODO: need a platform-independent helper here
def self.fifo
- system "mkfifo #{@fifo} 2> /dev/null"
+ File.mkfifo(@fifo)
yield @fifo
ensure
rm_r @fifo
end
def self.block_device
+ raise "Could not find a block device" unless @block
yield @block
end
def self.character_device
+ raise "Could not find a character device" unless @char
yield @char
end
def self.symlink
+ touch(@file)
+ File.symlink(@file, @link)
yield @link
+ ensure
+ rm_r @file, @link
end
def self.socket
@@ -57,8 +56,11 @@ module FileSpecs
name = tmp("ftype_socket.socket")
rm_r name
socket = UNIXServer.new name
- yield name
- socket.close
- rm_r name
+ begin
+ yield name
+ ensure
+ socket.close
+ rm_r name
+ end
end
end
diff --git a/spec/ruby/core/file/open_spec.rb b/spec/ruby/core/file/open_spec.rb
index 6ccac75a9a..a22a856dd9 100644
--- a/spec/ruby/core/file/open_spec.rb
+++ b/spec/ruby/core/file/open_spec.rb
@@ -604,7 +604,7 @@ describe "File.open" do
describe "on a FIFO" do
before :each do
@fifo = tmp("File_open_fifo")
- system "mkfifo #{@fifo}"
+ File.mkfifo(@fifo)
end
after :each do
diff --git a/spec/ruby/core/file/pipe_spec.rb b/spec/ruby/core/file/pipe_spec.rb
index 64e6fce09a..01d72dbe85 100644
--- a/spec/ruby/core/file/pipe_spec.rb
+++ b/spec/ruby/core/file/pipe_spec.rb
@@ -22,7 +22,7 @@ describe "File.pipe?" do
platform_is_not :windows do
it "returns true if the file is a pipe" do
filename = tmp("i_am_a_pipe")
- system "mkfifo #{filename}"
+ File.mkfifo(filename)
File.pipe?(filename).should == true
diff --git a/spec/ruby/core/file/stat/pipe_spec.rb b/spec/ruby/core/file/stat/pipe_spec.rb
index 027b40eaaa..7abb6c742a 100644
--- a/spec/ruby/core/file/stat/pipe_spec.rb
+++ b/spec/ruby/core/file/stat/pipe_spec.rb
@@ -20,7 +20,7 @@ describe "File::Stat#pipe?" do
platform_is_not :windows do
it "returns true if the file is a pipe" do
filename = tmp("i_am_a_pipe")
- system "mkfifo #{filename}"
+ File.mkfifo(filename)
st = File.stat(filename)
st.pipe?.should == true
diff --git a/spec/ruby/core/integer/dup_spec.rb b/spec/ruby/core/integer/dup_spec.rb
new file mode 100644
index 0000000000..214367f0b4
--- /dev/null
+++ b/spec/ruby/core/integer/dup_spec.rb
@@ -0,0 +1,15 @@
+require_relative '../../spec_helper'
+
+ruby_version_is '2.4' do
+ describe "Integer#dup" do
+ it "returns self for small integers" do
+ integer = 1_000
+ integer.dup.should equal(integer)
+ end
+
+ it "returns self for large integers" do
+ integer = 4_611_686_018_427_387_905
+ integer.dup.should equal(integer)
+ end
+ end
+end
diff --git a/spec/ruby/core/io/write_spec.rb b/spec/ruby/core/io/write_spec.rb
index 1c48a42584..e6db3351db 100644
--- a/spec/ruby/core/io/write_spec.rb
+++ b/spec/ruby/core/io/write_spec.rb
@@ -103,7 +103,7 @@ describe "IO.write" do
describe "on a FIFO" do
before :each do
@fifo = tmp("File_open_fifo")
- system "mkfifo #{@fifo}"
+ File.mkfifo(@fifo)
end
after :each do
diff --git a/spec/ruby/core/marshal/dump_spec.rb b/spec/ruby/core/marshal/dump_spec.rb
index 7718c118ef..f214abc31d 100644
--- a/spec/ruby/core/marshal/dump_spec.rb
+++ b/spec/ruby/core/marshal/dump_spec.rb
@@ -539,6 +539,16 @@ describe "Marshal.dump" do
end
+ describe "when passed a StringIO" do
+
+ it "should raise an error" do
+ require "stringio"
+
+ lambda { Marshal.dump(StringIO.new) }.should raise_error(TypeError)
+ end
+
+ end
+
it "raises a TypeError if marshalling a Method instance" do
lambda { Marshal.dump(Marshal.method(:dump)) }.should raise_error(TypeError)
end
diff --git a/spec/ruby/core/string/capitalize_spec.rb b/spec/ruby/core/string/capitalize_spec.rb
index e279f7d061..10f9ab00a1 100644
--- a/spec/ruby/core/string/capitalize_spec.rb
+++ b/spec/ruby/core/string/capitalize_spec.rb
@@ -26,8 +26,65 @@ describe "String#capitalize" do
end
ruby_version_is '2.4' do
- it "works for all of Unicode" do
- "äöü".capitalize.should == "Äöü"
+ describe "full Unicode case mapping" do
+ it "works for all of Unicode with no option" do
+ "äöÜ".capitalize.should == "Äöü"
+ end
+
+ it "only capitalizes the first resulting character when upcasing a character produces a multi-character sequence" do
+ "ß".capitalize.should == "Ss"
+ end
+
+ it "updates string metadata" do
+ capitalized = "ßeT".capitalize
+
+ capitalized.should == "Sset"
+ capitalized.size.should == 4
+ capitalized.bytesize.should == 4
+ capitalized.ascii_only?.should be_true
+ end
+ end
+
+ describe "ASCII-only case mapping" do
+ it "does not capitalize non-ASCII characters" do
+ "ßet".capitalize(:ascii).should == "ßet"
+ end
+ end
+
+ describe "full Unicode case mapping adapted for Turkic languages" do
+ it "capitalizes ASCII characters according to Turkic semantics" do
+ "iSa".capitalize(:turkic).should == "İsa"
+ end
+
+ it "allows Lithuanian as an extra option" do
+ "iSa".capitalize(:turkic, :lithuanian).should == "İsa"
+ end
+
+ it "does not allow any other additional option" do
+ lambda { "iSa".capitalize(:turkic, :ascii) }.should raise_error(ArgumentError)
+ end
+ end
+
+ describe "full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ "iß".capitalize(:lithuanian).should == "Iß"
+ end
+
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ "iß".capitalize(:lithuanian, :turkic).should == "İß"
+ end
+
+ it "does not allow any other additional option" do
+ lambda { "iß".capitalize(:lithuanian, :ascii) }.should raise_error(ArgumentError)
+ end
+ end
+
+ it "does not allow the :fold option for upcasing" do
+ lambda { "abc".capitalize(:fold) }.should raise_error(ArgumentError)
+ end
+
+ it "does not allow invalid options" do
+ lambda { "abc".capitalize(:invalid_option) }.should raise_error(ArgumentError)
end
end
@@ -45,10 +102,80 @@ describe "String#capitalize!" do
end
ruby_version_is '2.4' do
- it "capitalizes self in place for all of Unicode" do
- a = "äöü"
- a.capitalize!.should equal(a)
- a.should == "Äöü"
+ describe "full Unicode case mapping" do
+ it "modifies self in place for all of Unicode with no option" do
+ a = "äöÜ"
+ a.capitalize!
+ a.should == "Äöü"
+ end
+
+ it "only capitalizes the first resulting character when upcasing a character produces a multi-character sequence" do
+ a = "ß"
+ a.capitalize!
+ a.should == "Ss"
+ end
+
+ it "updates string metadata" do
+ capitalized = "ßeT"
+ capitalized.capitalize!
+
+ capitalized.should == "Sset"
+ capitalized.size.should == 4
+ capitalized.bytesize.should == 4
+ capitalized.ascii_only?.should be_true
+ end
+ end
+
+ describe "modifies self in place for ASCII-only case mapping" do
+ it "does not capitalize non-ASCII characters" do
+ a = "ßet"
+ a.capitalize!(:ascii)
+ a.should == "ßet"
+ end
+ end
+
+ describe "modifies self in place for full Unicode case mapping adapted for Turkic languages" do
+ it "capitalizes ASCII characters according to Turkic semantics" do
+ a = "iSa"
+ a.capitalize!(:turkic)
+ a.should == "İsa"
+ end
+
+ it "allows Lithuanian as an extra option" do
+ a = "iSa"
+ a.capitalize!(:turkic, :lithuanian)
+ a.should == "İsa"
+ end
+
+ it "does not allow any other additional option" do
+ lambda { a = "iSa"; a.capitalize!(:turkic, :ascii) }.should raise_error(ArgumentError)
+ end
+ end
+
+ describe "modifies self in place for full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ a = "iß"
+ a.capitalize!(:lithuanian)
+ a.should == "Iß"
+ end
+
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ a = "iß"
+ a.capitalize!(:lithuanian, :turkic)
+ a.should == "İß"
+ end
+
+ it "does not allow any other additional option" do
+ lambda { a = "iß"; a.capitalize!(:lithuanian, :ascii) }.should raise_error(ArgumentError)
+ end
+ end
+
+ it "does not allow the :fold option for upcasing" do
+ lambda { a = "abc"; a.capitalize!(:fold) }.should raise_error(ArgumentError)
+ end
+
+ it "does not allow invalid options" do
+ lambda { a = "abc"; a.capitalize!(:invalid_option) }.should raise_error(ArgumentError)
end
end
diff --git a/spec/ruby/core/string/casecmp_spec.rb b/spec/ruby/core/string/casecmp_spec.rb
index 9e89e1314d..87be999964 100644
--- a/spec/ruby/core/string/casecmp_spec.rb
+++ b/spec/ruby/core/string/casecmp_spec.rb
@@ -37,6 +37,10 @@ describe "String#casecmp independent of case" do
end
end
+ it "returns nil if incompatible encodings" do
+ "あれ".casecmp("れ".encode(Encoding::EUC_JP)).should be_nil
+ end
+
describe "in UTF-8 mode" do
describe "for non-ASCII characters" do
before :each do
@@ -96,6 +100,12 @@ describe "String#casecmp independent of case" do
it "returns 1 when numerically greater than other" do
@lower_a_tilde.casecmp(@upper_a_tilde).should == 1
end
+
+ ruby_version_is "2.4" do
+ it "does not case fold" do
+ "ß".casecmp("ss").should == 1
+ end
+ end
end
describe "when comparing a subclass instance" do
@@ -138,6 +148,10 @@ ruby_version_is "2.4" do
"abc".casecmp?(other).should == true
end
+ it "returns nil if incompatible encodings" do
+ "あれ".casecmp?("れ".encode(Encoding::EUC_JP)).should be_nil
+ end
+
describe 'for UNICODE characters' do
it 'returns true when downcase(:fold) on unicode' do
'äöü'.casecmp?('ÄÖÜ').should == true
@@ -181,6 +195,12 @@ ruby_version_is "2.4" do
end
end
+ ruby_version_is "2.4" do
+ it "case folds" do
+ "ß".casecmp?("ss").should be_true
+ end
+ end
+
ruby_version_is "2.4" ... "2.5" do
it "raises a TypeError if other can't be converted to a string" do
lambda { "abc".casecmp?(mock('abc')) }.should raise_error(TypeError)
diff --git a/spec/ruby/core/string/downcase_spec.rb b/spec/ruby/core/string/downcase_spec.rb
index 30116db5e6..9fb93902b1 100644
--- a/spec/ruby/core/string/downcase_spec.rb
+++ b/spec/ruby/core/string/downcase_spec.rb
@@ -23,8 +23,64 @@ describe "String#downcase" do
end
ruby_version_is '2.4' do
- it "works for all of Unicode" do
- "ÄÖÜ".downcase.should == "äöü"
+ describe "full Unicode case mapping" do
+ it "works for all of Unicode with no option" do
+ "ÄÖÜ".downcase.should == "äöü"
+ end
+
+ it "updates string metadata" do
+ downcased = "\u{212A}ING".downcase
+
+ downcased.should == "king"
+ downcased.size.should == 4
+ downcased.bytesize.should == 4
+ downcased.ascii_only?.should be_true
+ end
+ end
+
+ describe "ASCII-only case mapping" do
+ it "does not downcase non-ASCII characters" do
+ "CÅR".downcase(:ascii).should == "cÅr"
+ end
+ end
+
+ describe "full Unicode case mapping adapted for Turkic languages" do
+ it "downcases characters according to Turkic semantics" do
+ "İ".downcase(:turkic).should == "i"
+ end
+
+ it "allows Lithuanian as an extra option" do
+ "İ".downcase(:turkic, :lithuanian).should == "i"
+ end
+
+ it "does not allow any other additional option" do
+ lambda { "İ".downcase(:turkic, :ascii) }.should raise_error(ArgumentError)
+ end
+ end
+
+ describe "full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ "İS".downcase(:lithuanian).should == "i\u{307}s"
+ end
+
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ "İS".downcase(:lithuanian, :turkic).should == "is"
+ end
+
+ it "does not allow any other additional option" do
+ lambda { "İS".downcase(:lithuanian, :ascii) }.should raise_error(ArgumentError)
+ end
+ end
+
+ describe "case folding" do
+ it "case folds special characters" do
+ "ß".downcase.should == "ß"
+ "ß".downcase(:fold).should == "ss"
+ end
+ end
+
+ it "does not allow invalid options" do
+ lambda { "ABC".downcase(:invalid_option) }.should raise_error(ArgumentError)
end
end
@@ -47,10 +103,81 @@ describe "String#downcase!" do
end
ruby_version_is '2.4' do
- it "modifies self in place for all of Unicode" do
- a = "ÄÖÜ"
- a.downcase!.should equal(a)
- a.should == "äöü"
+ describe "full Unicode case mapping" do
+ it "modifies self in place for all of Unicode with no option" do
+ a = "ÄÖÜ"
+ a.downcase!
+ a.should == "äöü"
+ end
+
+ it "updates string metadata" do
+ downcased = "\u{212A}ING"
+ downcased.downcase!
+
+ downcased.should == "king"
+ downcased.size.should == 4
+ downcased.bytesize.should == 4
+ downcased.ascii_only?.should be_true
+ end
+ end
+
+ describe "ASCII-only case mapping" do
+ it "does not downcase non-ASCII characters" do
+ a = "CÅR"
+ a.downcase!(:ascii)
+ a.should == "cÅr"
+ end
+ end
+
+ describe "full Unicode case mapping adapted for Turkic languages" do
+ it "downcases characters according to Turkic semantics" do
+ a = "İ"
+ a.downcase!(:turkic)
+ a.should == "i"
+ end
+
+ it "allows Lithuanian as an extra option" do
+ a = "İ"
+ a.downcase!(:turkic, :lithuanian)
+ a.should == "i"
+ end
+
+ it "does not allow any other additional option" do
+ lambda { a = "İ"; a.downcase!(:turkic, :ascii) }.should raise_error(ArgumentError)
+ end
+ end
+
+ describe "full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ a = "İS"
+ a.downcase!(:lithuanian)
+ a.should == "i\u{307}s"
+ end
+
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ a = "İS"
+ a.downcase!(:lithuanian, :turkic)
+ a.should == "is"
+ end
+
+ it "does not allow any other additional option" do
+ lambda { a = "İS"; a.downcase!(:lithuanian, :ascii) }.should raise_error(ArgumentError)
+ end
+ end
+
+ describe "case folding" do
+ it "case folds special characters" do
+ a = "ß"
+ a.downcase!
+ a.should == "ß"
+
+ a.downcase!(:fold)
+ a.should == "ss"
+ end
+ end
+
+ it "does not allow invalid options" do
+ lambda { a = "ABC"; a.downcase!(:invalid_option) }.should raise_error(ArgumentError)
end
end
diff --git a/spec/ruby/core/string/swapcase_spec.rb b/spec/ruby/core/string/swapcase_spec.rb
index 6d00906aad..bb89dee48f 100644
--- a/spec/ruby/core/string/swapcase_spec.rb
+++ b/spec/ruby/core/string/swapcase_spec.rb
@@ -23,8 +23,61 @@ describe "String#swapcase" do
end
ruby_version_is '2.4' do
- it "works for all of Unicode" do
- "äÖü".swapcase.should == "ÄöÜ"
+ describe "full Unicode case mapping" do
+ it "works for all of Unicode with no option" do
+ "äÖü".swapcase.should == "ÄöÜ"
+ end
+
+ it "updates string metadata" do
+ swapcased = "Aßet".swapcase
+
+ swapcased.should == "aSSET"
+ swapcased.size.should == 5
+ swapcased.bytesize.should == 5
+ swapcased.ascii_only?.should be_true
+ end
+ end
+
+ describe "ASCII-only case mapping" do
+ it "does not swapcase non-ASCII characters" do
+ "aßet".swapcase(:ascii).should == "AßET"
+ end
+ end
+
+ describe "full Unicode case mapping adapted for Turkic languages" do
+ it "swaps case of ASCII characters according to Turkic semantics" do
+ "aiS".swapcase(:turkic).should == "Aİs"
+ end
+
+ it "allows Lithuanian as an extra option" do
+ "aiS".swapcase(:turkic, :lithuanian).should == "Aİs"
+ end
+
+ it "does not allow any other additional option" do
+ lambda { "aiS".swapcase(:turkic, :ascii) }.should raise_error(ArgumentError)
+ end
+ end
+
+ describe "full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ "Iß".swapcase(:lithuanian).should == "iSS"
+ end
+
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ "iS".swapcase(:lithuanian, :turkic).should == "İs"
+ end
+
+ it "does not allow any other additional option" do
+ lambda { "aiS".swapcase(:lithuanian, :ascii) }.should raise_error(ArgumentError)
+ end
+ end
+
+ it "does not allow the :fold option for upcasing" do
+ lambda { "abc".swapcase(:fold) }.should raise_error(ArgumentError)
+ end
+
+ it "does not allow invalid options" do
+ lambda { "abc".swapcase(:invalid_option) }.should raise_error(ArgumentError)
end
end
@@ -42,10 +95,74 @@ describe "String#swapcase!" do
end
ruby_version_is '2.4' do
- it "modifies self in place for all of Unicode" do
- a = "äÖü"
- a.swapcase!.should equal(a)
- a.should == "ÄöÜ"
+ describe "full Unicode case mapping" do
+ it "modifies self in place for all of Unicode with no option" do
+ a = "äÖü"
+ a.swapcase!
+ a.should == "ÄöÜ"
+ end
+
+ it "updates string metadata" do
+ swapcased = "Aßet"
+ swapcased.swapcase!
+
+ swapcased.should == "aSSET"
+ swapcased.size.should == 5
+ swapcased.bytesize.should == 5
+ swapcased.ascii_only?.should be_true
+ end
+ end
+
+ describe "modifies self in place for ASCII-only case mapping" do
+ it "does not swapcase non-ASCII characters" do
+ a = "aßet"
+ a.swapcase!(:ascii)
+ a.should == "AßET"
+ end
+ end
+
+ describe "modifies self in place for full Unicode case mapping adapted for Turkic languages" do
+ it "swaps case of ASCII characters according to Turkic semantics" do
+ a = "aiS"
+ a.swapcase!(:turkic)
+ a.should == "Aİs"
+ end
+
+ it "allows Lithuanian as an extra option" do
+ a = "aiS"
+ a.swapcase!(:turkic, :lithuanian)
+ a.should == "Aİs"
+ end
+
+ it "does not allow any other additional option" do
+ lambda { a = "aiS"; a.swapcase!(:turkic, :ascii) }.should raise_error(ArgumentError)
+ end
+ end
+
+ describe "full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ a = "Iß"
+ a.swapcase!(:lithuanian)
+ a.should == "iSS"
+ end
+
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ a = "iS"
+ a.swapcase!(:lithuanian, :turkic)
+ a.should == "İs"
+ end
+
+ it "does not allow any other additional option" do
+ lambda { a = "aiS"; a.swapcase!(:lithuanian, :ascii) }.should raise_error(ArgumentError)
+ end
+ end
+
+ it "does not allow the :fold option for upcasing" do
+ lambda { a = "abc"; a.swapcase!(:fold) }.should raise_error(ArgumentError)
+ end
+
+ it "does not allow invalid options" do
+ lambda { a = "abc"; a.swapcase!(:invalid_option) }.should raise_error(ArgumentError)
end
end
diff --git a/spec/ruby/core/string/upcase_spec.rb b/spec/ruby/core/string/upcase_spec.rb
index 001cf1f495..347f567be9 100644
--- a/spec/ruby/core/string/upcase_spec.rb
+++ b/spec/ruby/core/string/upcase_spec.rb
@@ -23,8 +23,61 @@ describe "String#upcase" do
end
ruby_version_is '2.4' do
- it "works for all of Unicode" do
- "äöü".upcase.should == "ÄÖÜ"
+ describe "full Unicode case mapping" do
+ it "works for all of Unicode with no option" do
+ "äöü".upcase.should == "ÄÖÜ"
+ end
+
+ it "updates string metadata" do
+ upcased = "aßet".upcase
+
+ upcased.should == "ASSET"
+ upcased.size.should == 5
+ upcased.bytesize.should == 5
+ upcased.ascii_only?.should be_true
+ end
+ end
+
+ describe "ASCII-only case mapping" do
+ it "does not upcase non-ASCII characters" do
+ "aßet".upcase(:ascii).should == "AßET"
+ end
+ end
+
+ describe "full Unicode case mapping adapted for Turkic languages" do
+ it "upcases ASCII characters according to Turkic semantics" do
+ "i".upcase(:turkic).should == "İ"
+ end
+
+ it "allows Lithuanian as an extra option" do
+ "i".upcase(:turkic, :lithuanian).should == "İ"
+ end
+
+ it "does not allow any other additional option" do
+ lambda { "i".upcase(:turkic, :ascii) }.should raise_error(ArgumentError)
+ end
+ end
+
+ describe "full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ "iß".upcase(:lithuanian).should == "ISS"
+ end
+
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ "iß".upcase(:lithuanian, :turkic).should == "İSS"
+ end
+
+ it "does not allow any other additional option" do
+ lambda { "iß".upcase(:lithuanian, :ascii) }.should raise_error(ArgumentError)
+ end
+ end
+
+ it "does not allow the :fold option for upcasing" do
+ lambda { "abc".upcase(:fold) }.should raise_error(ArgumentError)
+ end
+
+ it "does not allow invalid options" do
+ lambda { "abc".upcase(:invalid_option) }.should raise_error(ArgumentError)
end
end
@@ -46,12 +99,75 @@ describe "String#upcase!" do
a.should == "HELLO"
end
-
ruby_version_is '2.4' do
- it "modifies self in place for all of Unicode" do
- a = "äöü"
- a.upcase!.should equal(a)
- a.should == "ÄÖÜ"
+ describe "full Unicode case mapping" do
+ it "modifies self in place for all of Unicode with no option" do
+ a = "äöü"
+ a.upcase!
+ a.should == "ÄÖÜ"
+ end
+
+ it "updates string metadata for self" do
+ upcased = "aßet"
+ upcased.upcase!
+
+ upcased.should == "ASSET"
+ upcased.size.should == 5
+ upcased.bytesize.should == 5
+ upcased.ascii_only?.should be_true
+ end
+ end
+
+ describe "modifies self in place for ASCII-only case mapping" do
+ it "does not upcase non-ASCII characters" do
+ a = "aßet"
+ a.upcase!(:ascii)
+ a.should == "AßET"
+ end
+ end
+
+ describe "modifies self in place for full Unicode case mapping adapted for Turkic languages" do
+ it "upcases ASCII characters according to Turkic semantics" do
+ a = "i"
+ a.upcase!(:turkic)
+ a.should == "İ"
+ end
+
+ it "allows Lithuanian as an extra option" do
+ a = "i"
+ a.upcase!(:turkic, :lithuanian)
+ a.should == "İ"
+ end
+
+ it "does not allow any other additional option" do
+ lambda { a = "i"; a.upcase!(:turkic, :ascii) }.should raise_error(ArgumentError)
+ end
+ end
+
+ describe "modifies self in place for full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ a = "iß"
+ a.upcase!(:lithuanian)
+ a.should == "ISS"
+ end
+
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ a = "iß"
+ a.upcase!(:lithuanian, :turkic)
+ a.should == "İSS"
+ end
+
+ it "does not allow any other additional option" do
+ lambda { a = "iß"; a.upcase!(:lithuanian, :ascii) }.should raise_error(ArgumentError)
+ end
+ end
+
+ it "does not allow the :fold option for upcasing" do
+ lambda { a = "abc"; a.upcase!(:fold) }.should raise_error(ArgumentError)
+ end
+
+ it "does not allow invalid options" do
+ lambda { a = "abc"; a.upcase!(:invalid_option) }.should raise_error(ArgumentError)
end
end
diff --git a/spec/ruby/core/time/comparison_spec.rb b/spec/ruby/core/time/comparison_spec.rb
index 44d8778da4..5b53c9fb50 100644
--- a/spec/ruby/core/time/comparison_spec.rb
+++ b/spec/ruby/core/time/comparison_spec.rb
@@ -45,6 +45,16 @@ describe "Time#<=>" do
(Time.at(100, 0) <=> Time.at(100, Rational(1,1000))).should == -1
end
+ it "returns nil when compared to an Integer because Time does not respond to #coerce" do
+ time = Time.at(1)
+ time.respond_to?(:coerce).should == false
+ time.should_receive(:respond_to?).exactly(2).and_return(false)
+ -> {
+ (time <=> 2).should == nil
+ (2 <=> time).should == nil
+ }.should_not complain
+ end
+
describe "given a non-Time argument" do
it "returns nil if argument <=> self returns nil" do
t = Time.now