Backport #6487 ยป bad_bom.patch
test/ruby/test_file.rb | ||
---|---|---|
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"
|