diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-08-14 10:43:46 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-08-14 11:20:58 +0900 |
commit | cad41bb6d35c09b0e5d9e50280e3bfcd1bd9bcc0 (patch) | |
tree | 2a8d19d1715eb39b8a1c6c942d8ccb6c87ef1af9 /test | |
parent | 22e942deb2580faae44176064a569a84bccb5028 (diff) | |
download | ruby-cad41bb6d35c09b0e5d9e50280e3bfcd1bd9bcc0.tar.gz |
[ruby/stringio] Supported BOM
https://github.com/ruby/stringio/commit/b249631c43
Diffstat (limited to 'test')
-rw-r--r-- | test/stringio/test_stringio.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb index 1e8e5482ce..b4369ede5f 100644 --- a/test/stringio/test_stringio.rb +++ b/test/stringio/test_stringio.rb @@ -795,6 +795,20 @@ class TestStringIO < Test::Unit::TestCase assert_equal("\0\0\0a\0\0\0b\0\0\0c", s.read) end + %w/UTF-8 UTF-16BE UTF-16LE UTF-32BE UTF-32LE/.each do |name| + define_method("test_strip_bom:#{name}") do + text = "\uFEFF\u0100a" + content = text.encode(name) + result = StringIO.new(content, mode: 'rb:BOM|UTF-8').read + assert_equal(Encoding.find(name), result.encoding, name) + assert_equal(content[1..-1].b, result.b, name) + + StringIO.open(content) {|f| + assert_equal(Encoding.find(name), f.set_encoding_by_bom) + } + end + end + def assert_string(content, encoding, str, mesg = nil) assert_equal([content, encoding], [str, str.encoding], mesg) end |