1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2017-10-28 15:15:48 +00:00
parent 6530b14cee
commit 8c5b60eb22
218 changed files with 4069 additions and 328 deletions

View file

@ -42,10 +42,8 @@ describe :string_chars, shared: true do
it "returns a different character if the String is transcoded" do
s = "\u{20AC}".force_encoding('UTF-8')
s.encode('UTF-8').send(@method).to_a.should == ["\u{20AC}".force_encoding('UTF-8')]
s.encode('iso-8859-15').send(@method).to_a.should == [
[0xA4].pack('C').force_encoding('iso-8859-15')]
s.encode('iso-8859-15').encode('UTF-8').send(@method).to_a.should == [
"\u{20AC}".force_encoding('UTF-8')]
s.encode('iso-8859-15').send(@method).to_a.should == [[0xA4].pack('C').force_encoding('iso-8859-15')]
s.encode('iso-8859-15').encode('UTF-8').send(@method).to_a.should == ["\u{20AC}".force_encoding('UTF-8')]
end
it "uses the String's encoding to determine what characters it contains" do

View file

@ -48,7 +48,7 @@ describe :string_codepoints, shared: true do
s.should == s2
end
it "is synonomous with #bytes for Strings which are single-byte optimisable" do
it "is synonymous with #bytes for Strings which are single-byte optimisable" do
s = "(){}".encode('ascii')
s.ascii_only?.should be_true
s.send(@method).to_a.should == s.bytes.to_a

View file

@ -133,4 +133,18 @@ end
it "raises a TypeError when the separator is a symbol" do
lambda { "hello world".send(@method, :o).to_a }.should raise_error(TypeError)
end
ruby_version_is '2.4' do
context "when `chomp` keyword argument is passed" do
it "removes new line characters" do
a = []
"hello \nworld\n".send(@method, chomp: true) { |s| a << s }
a.should == ["hello ", "world"]
a = []
"hello \r\nworld\r\n".send(@method, chomp: true) { |s| a << s }
a.should == ["hello ", "world"]
end
end
end
end

View file

@ -1,24 +1,63 @@
describe :string_to_sym, shared: true do
it "returns the symbol corresponding to self" do
"Koala".send(@method).should == :Koala
'cat'.send(@method).should == :cat
'@cat'.send(@method).should == :@cat
'cat and dog'.send(@method).should == :"cat and dog"
"abc=".send(@method).should == :abc=
"Koala".send(@method).should equal :Koala
'cat'.send(@method).should equal :cat
'@cat'.send(@method).should equal :@cat
'cat and dog'.send(@method).should equal :"cat and dog"
"abc=".send(@method).should equal :abc=
end
it "does not special case +(binary) and -(binary)" do
"+(binary)".send(@method).should == :"+(binary)"
"-(binary)".send(@method).should == :"-(binary)"
"+(binary)".send(@method).should equal :"+(binary)"
"-(binary)".send(@method).should equal :"-(binary)"
end
it "does not special case certain operators" do
[ ["!@", :"!@"],
["~@", :"~@"],
["!(unary)", :"!(unary)"],
["~(unary)", :"~(unary)"],
["+(unary)", :"+(unary)"],
["-(unary)", :"-(unary)"]
].should be_computed_by(@method)
"!@".send(@method).should equal :"!@"
"~@".send(@method).should equal :"~@"
"!(unary)".send(@method).should equal :"!(unary)"
"~(unary)".send(@method).should equal :"~(unary)"
"+(unary)".send(@method).should equal :"+(unary)"
"-(unary)".send(@method).should equal :"-(unary)"
end
it "returns a US-ASCII Symbol for a UTF-8 String containing only US-ASCII characters" do
sym = "foobar".send(@method)
sym.encoding.should == Encoding::US_ASCII
sym.should equal :"foobar"
end
it "returns a US-ASCII Symbol for a binary String containing only US-ASCII characters" do
sym = "foobar".b.send(@method)
sym.encoding.should == Encoding::US_ASCII
sym.should equal :"foobar"
end
it "returns a UTF-8 Symbol for a UTF-8 String containing non US-ASCII characters" do
sym = "il était une fois".send(@method)
sym.encoding.should == Encoding::UTF_8
sym.should equal :"il était une #{'fois'}"
end
it "returns a UTF-16LE Symbol for a UTF-16LE String containing non US-ASCII characters" do
utf16_str = "UtéF16".encode(Encoding::UTF_16LE)
sym = utf16_str.send(@method)
sym.encoding.should == Encoding::UTF_16LE
sym.to_s.should == utf16_str
end
it "returns a binary Symbol for a binary String containing non US-ASCII characters" do
binary_string = "binarí".b
sym = binary_string.send(@method)
sym.encoding.should == Encoding::BINARY
sym.to_s.should == binary_string
end
it "raises an EncodingError for UTF-8 String containing invalid bytes" do
invalid_utf8 = "\xC3"
invalid_utf8.valid_encoding?.should == false
-> {
invalid_utf8.send(@method)
}.should raise_error(EncodingError, /invalid/)
end
end