summaryrefslogtreecommitdiff
path: root/spec/ruby/core/string
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/string')
-rw-r--r--spec/ruby/core/string/shared/codepoints.rb12
-rw-r--r--spec/ruby/core/string/split_spec.rb16
2 files changed, 18 insertions, 10 deletions
diff --git a/spec/ruby/core/string/shared/codepoints.rb b/spec/ruby/core/string/shared/codepoints.rb
index 589d2ee1d0..84a0e3ae39 100644
--- a/spec/ruby/core/string/shared/codepoints.rb
+++ b/spec/ruby/core/string/shared/codepoints.rb
@@ -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
diff --git a/spec/ruby/core/string/split_spec.rb b/spec/ruby/core/string/split_spec.rb
index b451921c66..0c82ef8c58 100644
--- a/spec/ruby/core/string/split_spec.rb
+++ b/spec/ruby/core/string/split_spec.rb
@@ -413,15 +413,17 @@ describe "String#split with Regexp" do
end
describe "for a String subclass" do
- a = []
- StringSpecs::MyString.new("a|b").split("|") { |str| a << str }
- first, last = a
+ it "yields instances of the same subclass" do
+ a = []
+ StringSpecs::MyString.new("a|b").split("|") { |str| a << str }
+ first, last = a
- first.should be_an_instance_of(StringSpecs::MyString)
- first.should == "a"
+ first.should be_an_instance_of(StringSpecs::MyString)
+ first.should == "a"
- last.should be_an_instance_of(StringSpecs::MyString)
- last.should == "b"
+ last.should be_an_instance_of(StringSpecs::MyString)
+ last.should == "b"
+ end
end
end
end