Skip to content

Commit 626a43a

Browse files
herwinweregon
authored andcommitted
Add additional test for encoding of rb_str_to_interned_str
The documentation in the MRI source refers to rb_interned_str as being similar, this test is just to accentuate the difference between these two funcitons.
1 parent 6b67caf commit 626a43a

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

optional/capi/string_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,13 @@ def inspect
13691369
result1.should_not.equal?(result2)
13701370
end
13711371

1372+
it "preserves the encoding of the original string" do
1373+
result1 = @s.rb_str_to_interned_str("hello".dup.force_encoding(Encoding::US_ASCII))
1374+
result2 = @s.rb_str_to_interned_str("hello".dup.force_encoding(Encoding::UTF_8))
1375+
result1.encoding.should == Encoding::US_ASCII
1376+
result2.encoding.should == Encoding::UTF_8
1377+
end
1378+
13721379
it "returns the same string as String#-@" do
13731380
@s.rb_str_to_interned_str("hello").should.equal?(-"hello")
13741381
end

0 commit comments

Comments
 (0)