diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-12-18 03:09:16 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-12-18 03:09:16 +0000 |
commit | 28f3a7e3d5da9cbb00a75d29dcacce3a82d2b975 (patch) | |
tree | 3017b951de574832fc145ff7773322f739bc114c /test | |
parent | e735475f54eb9ce035b7d8acef901c0bd7a4b483 (diff) | |
download | ruby-28f3a7e3d5da9cbb00a75d29dcacce3a82d2b975.tar.gz |
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')
-rw-r--r-- | test/stringio/test_stringio.rb | 30 |
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 |