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@67112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2019-02-21 15:38:59 +00:00
parent b8e389a0f3
commit da7976235f
75 changed files with 940 additions and 258 deletions

View file

@ -1,5 +1,11 @@
# -*- encoding: binary -*-
describe :string_codepoints, shared: true do
it "returns self" do
s = "foo"
result = s.send(@method) {}
result.should equal s
end
it "raises an ArgumentError when self has an invalid encoding and a method is called on the returned Enumerator" do
s = "\xDF".force_encoding(Encoding::UTF_8)
s.valid_encoding?.should be_false
@ -20,13 +26,13 @@ describe :string_codepoints, shared: true do
lambda { s.send(@method) { } }.should raise_error(ArgumentError)
end
it "returns codepoints as Fixnums" do
it "yields codepoints as Fixnums" do
"glark\u{20}".send(@method).to_a.each do |codepoint|
codepoint.should be_an_instance_of(Fixnum)
end
end
it "returns one codepoint for each character" do
it "yields one codepoint for each character" do
s = "\u{9876}\u{28}\u{1987}"
s.send(@method).to_a.size.should == s.chars.to_a.size
end
@ -37,7 +43,7 @@ describe :string_codepoints, shared: true do
s.send(@method).to_a.should == [38937]
end
it "returns the codepoint corresponding to the character's position in the String's encoding" do
it "yields the codepoints corresponding to the character's position in the String's encoding" do
"\u{787}".send(@method).to_a.should == [1927]
end