diff options
Diffstat (limited to 'spec/ruby/core/string/each_codepoint_spec.rb')
| -rw-r--r-- | spec/ruby/core/string/each_codepoint_spec.rb | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/spec/ruby/core/string/each_codepoint_spec.rb b/spec/ruby/core/string/each_codepoint_spec.rb index 4e910f44b5..08d4292371 100644 --- a/spec/ruby/core/string/each_codepoint_spec.rb +++ b/spec/ruby/core/string/each_codepoint_spec.rb @@ -1,10 +1,38 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../shared/codepoints', __FILE__) -require File.expand_path('../shared/each_codepoint_without_block', __FILE__) - -with_feature :encoding do - describe "String#each_codepoint" do - it_behaves_like(:string_codepoints, :each_codepoint) - it_behaves_like(:string_each_codepoint_without_block, :each_codepoint) +# encoding: binary +require_relative '../../spec_helper' +require_relative 'shared/codepoints' + +describe "String#each_codepoint" do + it_behaves_like :string_codepoints, :each_codepoint + + describe "when no block is given" do + it "returns an Enumerator" do + "".each_codepoint.should.instance_of?(Enumerator) + end + + it "returns an Enumerator even when self has an invalid encoding" do + s = "\xDF".dup.force_encoding(Encoding::UTF_8) + s.valid_encoding?.should == false + s.each_codepoint.should.instance_of?(Enumerator) + end + + describe "returned Enumerator" do + describe "size" do + it "should return the size of the string" do + str = "hello" + str.each_codepoint.size.should == str.size + str = "ola" + str.each_codepoint.size.should == str.size + str = "\303\207\342\210\202\303\251\306\222g" + str.each_codepoint.size.should == str.size + end + + it "should return the size of the string even when the string has an invalid encoding" do + s = "\xDF".dup.force_encoding(Encoding::UTF_8) + s.valid_encoding?.should == false + s.each_codepoint.size.should == 1 + end + end + end end end |
