Split test_strip_bom for each encoding
This commit is contained in:
parent
a8ef498d6b
commit
562c0bfeda
@ -2080,26 +2080,42 @@ EOT
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_strip_bom
|
%w/UTF-8 UTF-16BE UTF-16LE UTF-32BE UTF-32LE/.each do |name|
|
||||||
|
define_method("test_strip_bom:#{name}") do
|
||||||
|
path = "#{name}-bom.txt"
|
||||||
with_tmpdir {
|
with_tmpdir {
|
||||||
text = "\uFEFFa"
|
text = "\uFEFFa"
|
||||||
stripped = "a"
|
stripped = "a"
|
||||||
%w/UTF-8 UTF-16BE UTF-16LE UTF-32BE UTF-32LE/.each do |name|
|
|
||||||
path = '%s-bom.txt' % name
|
|
||||||
content = text.encode(name)
|
content = text.encode(name)
|
||||||
generate_file(path, content)
|
generate_file(path, content)
|
||||||
result = File.read(path, mode: 'rb:BOM|UTF-8')
|
result = File.read(path, mode: 'rb:BOM|UTF-8')
|
||||||
assert_equal(Encoding.find(name), result.encoding, name)
|
assert_equal(Encoding.find(name), result.encoding, name)
|
||||||
assert_equal(content[1..-1].b, result.b, name)
|
assert_equal(content[1..-1].b, result.b, name)
|
||||||
result = File.read(path, mode: 'rb:BOM|UTF-8:UTF-8')
|
%w[rb rt r].each do |mode|
|
||||||
assert_equal(Encoding::UTF_8, result.encoding, name)
|
message = "#{name}, mode: #{mode.dump}"
|
||||||
assert_equal(stripped, result, name)
|
result = File.read(path, mode: "#{mode}:BOM|UTF-8:UTF-8")
|
||||||
|
assert_equal(Encoding::UTF_8, result.encoding, message)
|
||||||
|
assert_equal(stripped, result, message)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
bug3407 = '[ruby-core:30641]'
|
def test_strip_bom_no_conv
|
||||||
|
with_tmpdir {
|
||||||
path = 'UTF-8-bom.txt'
|
path = 'UTF-8-bom.txt'
|
||||||
|
generate_file(path, "\uFEFFa")
|
||||||
|
|
||||||
|
bug3407 = '[ruby-core:30641]'
|
||||||
result = File.read(path, encoding: 'BOM|UTF-8')
|
result = File.read(path, encoding: 'BOM|UTF-8')
|
||||||
assert_equal("a", result.force_encoding("ascii-8bit"), bug3407)
|
assert_equal("a", result.b, bug3407)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_strip_bom_invalid
|
||||||
|
with_tmpdir {
|
||||||
|
path = 'UTF-8-bom.txt'
|
||||||
|
generate_file(path, "\uFEFFa")
|
||||||
|
|
||||||
bug8323 = '[ruby-core:54563] [Bug #8323]'
|
bug8323 = '[ruby-core:54563] [Bug #8323]'
|
||||||
expected = "a\xff".force_encoding("utf-8")
|
expected = "a\xff".force_encoding("utf-8")
|
||||||
@ -2110,8 +2126,14 @@ EOT
|
|||||||
result = File.read(path, encoding: 'BOM|UTF-8:UTF-8')
|
result = File.read(path, encoding: 'BOM|UTF-8:UTF-8')
|
||||||
assert_not_predicate(result, :valid_encoding?, bug8323)
|
assert_not_predicate(result, :valid_encoding?, bug8323)
|
||||||
assert_equal(expected, result, bug8323)
|
assert_equal(expected, result, bug8323)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_strip_bom_no_bom
|
||||||
|
with_tmpdir {
|
||||||
|
bug8323 = '[ruby-core:54563] [Bug #8323]'
|
||||||
path = 'ascii.txt'
|
path = 'ascii.txt'
|
||||||
|
stripped = "a"
|
||||||
generate_file(path, stripped)
|
generate_file(path, stripped)
|
||||||
result = File.read(path, encoding: 'BOM|UTF-8')
|
result = File.read(path, encoding: 'BOM|UTF-8')
|
||||||
assert_equal(stripped, result, bug8323)
|
assert_equal(stripped, result, bug8323)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user