diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-05-14 07:07:55 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-05-14 07:07:55 +0000 |
commit | fc9664d3d853af61ee48265eaf4788ffd7970403 (patch) | |
tree | 182da57d1302b6a6c0e15482a553d26d103abeb2 /test | |
parent | 794a52fc6e0da1f7ecc85f6eaef9e88742238f71 (diff) | |
download | ruby-fc9664d3d853af61ee48265eaf4788ffd7970403.tar.gz ruby-fc9664d3d853af61ee48265eaf4788ffd7970403.tar.xz ruby-fc9664d3d853af61ee48265eaf4788ffd7970403.zip |
* ext/stringio/stringio.c (strio_ungetbyte): encoding should not
be effective.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@23424 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_io.rb | 16 | ||||
-rw-r--r-- | test/stringio/test_stringio.rb | 15 |
2 files changed, 31 insertions, 0 deletions
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index f45677988..69e3666cf 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -118,6 +118,22 @@ class TestIO < Test::Unit::TestCase r.close end + def test_ungetbyte + t = make_tempfile + t.open + t.ungetbyte(0x41) + assert_equal(0x41, t.getbyte) + t.rewind + t.ungetbyte("qux") + assert_equal("quxfoo\n", t.gets) + t.set_encoding("utf-8") + t.ungetbyte(0x89) + t.ungetbyte(0x8e) + t.ungetbyte("\xe7") + t.ungetbyte("\xe7\xb4\x85") + assert_equal("\u7d05\u7389bar\n", t.gets) + end + def test_each_byte r, w = IO.pipe w << "abc def" diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb index 33bef0690..8c72803b4 100644 --- a/test/stringio/test_stringio.rb +++ b/test/stringio/test_stringio.rb @@ -289,6 +289,21 @@ class TestStringIO < Test::Unit::TestCase f.close unless f.closed? end + def test_ungetbyte + s = "foo\nbar\n" + t = StringIO.new(s, "r") + t.ungetbyte(0x41) + assert_equal(0x41, t.getbyte) + t.ungetbyte("qux") + assert_equal("quxfoo\n", t.gets) + t.set_encoding("utf-8") + t.ungetbyte(0x89) + t.ungetbyte(0x8e) + t.ungetbyte("\xe7") + t.ungetbyte("\xe7\xb4\x85") + assert_equal("\u7d05\u7389bar\n", t.gets) + end + def test_ungetc s = "1234" f = StringIO.new(s, "r") |