diff --git a/test/ruby/test_file.rb b/test/ruby/test_file.rb index 54983d6..d66591b 100644 --- a/test/ruby/test_file.rb +++ b/test/ruby/test_file.rb @@ -38,6 +38,58 @@ class TestFile < Test::Unit::TestCase include TestEOF::Seek + def test_empty_file_bom + f = Tempfile.new(__method__.to_s) + assert File.exists? f.path + assert_equal '', File.open(f.path, 'r:utf-8') { |f| f.read } + assert_equal '', File.open(f.path, 'r:bom|utf-8') { |f| f.read } + f.close(true) + end + + def test_bad_bom_8 + f = Tempfile.new(__method__.to_s) + f.sync = true + + [0xEF, 0xBB].each do |x| + f.write x.chr + assert File.new(f.path, 'r:bom|utf-8').close + end + f.close(true) + end + + def test_bad_bom_16 + f = Tempfile.new(__method__.to_s) + f.sync = true + + [0xFE].each do |x| + f.write x.chr + assert File.new(f.path, 'r:bom|utf-8').close + end + f.close(true) + end + + def test_bad_bom_32le + f = Tempfile.new(__method__.to_s) + f.sync = true + + [0xFF, 0xFE, 0].each do |x| + f.write x.chr + assert File.new(f.path, 'r:bom|utf-8').close + end + f.close(true) + end + + def test_bad_bom_32be + f = Tempfile.new(__method__.to_s) + f.sync = true + + [0x0, 0xFE].each do |x| + f.write x.chr + assert File.new(f.path, 'r:bom|utf-8').close + end + f.close(true) + end + def test_truncate_wbuf f = Tempfile.new("test-truncate") f.print "abc"