summaryrefslogtreecommitdiff
path: root/test/stringio/test_stringio.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-18 03:09:16 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-18 03:09:16 +0000
commitb7d153699153629f037a059b930d8e928c42a4a1 (patch)
tree3017b951de574832fc145ff7773322f739bc114c /test/stringio/test_stringio.rb
parent07f53e483042f8d154912b9414808ad40973cd44 (diff)
stringio.c: padding in ungetbyte
* ext/stringio/stringio.c (strio_ungetbyte): pad with \000 when the current position is after the end. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53181 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/stringio/test_stringio.rb')
-rw-r--r--test/stringio/test_stringio.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb
index af6efc684e..7b99d62f51 100644
--- a/test/stringio/test_stringio.rb
+++ b/test/stringio/test_stringio.rb
@@ -362,6 +362,11 @@ class TestStringIO < Test::Unit::TestCase
t.ungetbyte("\xe7")
t.ungetbyte("\xe7\xb4\x85")
assert_equal("\u7d05\u7389bar\n", t.gets)
+ assert_equal("q\u7d05\u7389bar\n", s)
+ t.pos = 1
+ t.ungetbyte("\u{30eb 30d3 30fc}")
+ assert_equal(0, t.pos)
+ assert_equal("\u{30eb 30d3 30fc}\u7d05\u7389bar\n", s)
end
def test_ungetc
@@ -582,6 +587,31 @@ class TestStringIO < Test::Unit::TestCase
assert_equal("b""\0""a", s.string)
end
+ def test_ungetbyte_pos
+ b = '\\b00010001 \\B00010001 \\b1 \\B1 \\b000100011'
+ s = StringIO.new( b )
+ expected_pos = 0
+ while n = s.getbyte
+ assert_equal( expected_pos + 1, s.pos )
+
+ s.ungetbyte( n )
+ assert_equal( expected_pos, s.pos )
+ assert_equal( n, s.getbyte )
+
+ expected_pos += 1
+ end
+ end
+
+ def test_ungetbyte_padding
+ s = StringIO.new()
+ s.pos = 2
+ s.ungetbyte("a".ord)
+ assert_equal("\0""a", s.string)
+ s.pos = 0
+ s.ungetbyte("b".ord)
+ assert_equal("b""\0""a", s.string)
+ end
+
def test_frozen
s = StringIO.new
s.freeze