From cc22350fa01f2f87b0020b49a0e679f8d1d6dbf4 Mon Sep 17 00:00:00 2001 From: Laurent Sansonetti Date: Mon, 22 Oct 2012 13:03:30 +0200 Subject: [PATCH] add test for String#<< --- test/test/spec/string_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/test/spec/string_spec.rb b/test/test/spec/string_spec.rb index 8529cd1a..ac65e5fa 100644 --- a/test/test/spec/string_spec.rb +++ b/test/test/spec/string_spec.rb @@ -8,3 +8,22 @@ describe "Strings containing null terminators" do s.size.should == 3 end end + +describe "String#<< with a codepoint" do + it "works on ASCII/BINARY strings" do + s = "" + s.encoding.should == Encoding::UTF_8 + s << 3 + s.should == "\x03" + + s.force_encoding 'ASCII-8BIT' + s.encoding.should == Encoding::ASCII_8BIT + s << 3 + s.should == "\x03\x03" + + s.force_encoding 'US-ASCII' + s.encoding.should == Encoding::ASCII + s << 3 + s.should == "\x03\x03\x03" + end +end