mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
test_utf16.rb: refine valid_encoding tests
* test/ruby/enc/test_utf16.rb (test_utf16be_valid_encoding): assert all data and use assert_predicate. * test/ruby/enc/test_utf16.rb (test_utf16le_valid_encoding): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57815 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2ebc44656f
commit
e65c9bd177
1 changed files with 62 additions and 50 deletions
|
@ -56,59 +56,71 @@ EOT
|
||||||
# tests start
|
# tests start
|
||||||
|
|
||||||
def test_utf16be_valid_encoding
|
def test_utf16be_valid_encoding
|
||||||
[
|
all_assertions do |a|
|
||||||
"\x00\x00",
|
[
|
||||||
"\xd7\xff",
|
"\x00\x00",
|
||||||
"\xd8\x00\xdc\x00",
|
"\xd7\xff",
|
||||||
"\xdb\xff\xdf\xff",
|
"\xd8\x00\xdc\x00",
|
||||||
"\xe0\x00",
|
"\xdb\xff\xdf\xff",
|
||||||
"\xff\xff",
|
"\xe0\x00",
|
||||||
].each {|s|
|
"\xff\xff",
|
||||||
s.force_encoding("utf-16be")
|
].each {|s|
|
||||||
assert_equal(true, s.valid_encoding?, "#{encdump s}.valid_encoding?")
|
s.force_encoding("utf-16be")
|
||||||
}
|
a.for(s) {
|
||||||
[
|
assert_predicate(s, :valid_encoding?, "#{encdump s}.valid_encoding?")
|
||||||
"\x00",
|
}
|
||||||
"\xd7",
|
}
|
||||||
"\xd8\x00",
|
[
|
||||||
"\xd8\x00\xd8\x00",
|
"\x00",
|
||||||
"\xdc\x00",
|
"\xd7",
|
||||||
"\xdc\x00\xd8\x00",
|
"\xd8\x00",
|
||||||
"\xdc\x00\xdc\x00",
|
"\xd8\x00\xd8\x00",
|
||||||
"\xe0",
|
"\xdc\x00",
|
||||||
"\xff",
|
"\xdc\x00\xd8\x00",
|
||||||
].each {|s|
|
"\xdc\x00\xdc\x00",
|
||||||
s.force_encoding("utf-16be")
|
"\xe0",
|
||||||
assert_equal(false, s.valid_encoding?, "#{encdump s}.valid_encoding?")
|
"\xff",
|
||||||
}
|
].each {|s|
|
||||||
|
s.force_encoding("utf-16be")
|
||||||
|
a.for(s) {
|
||||||
|
assert_not_predicate(s, :valid_encoding?, "#{encdump s}.valid_encoding?")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_utf16le_valid_encoding
|
def test_utf16le_valid_encoding
|
||||||
[
|
all_assertions do |a|
|
||||||
"\x00\x00",
|
[
|
||||||
"\xff\xd7",
|
"\x00\x00",
|
||||||
"\x00\xd8\x00\xdc",
|
"\xff\xd7",
|
||||||
"\xff\xdb\xff\xdf",
|
"\x00\xd8\x00\xdc",
|
||||||
"\x00\xe0",
|
"\xff\xdb\xff\xdf",
|
||||||
"\xff\xff",
|
"\x00\xe0",
|
||||||
].each {|s|
|
"\xff\xff",
|
||||||
s.force_encoding("utf-16le")
|
].each {|s|
|
||||||
assert_equal(true, s.valid_encoding?, "#{encdump s}.valid_encoding?")
|
s.force_encoding("utf-16le")
|
||||||
}
|
a.for(s) {
|
||||||
[
|
assert_predicate(s, :valid_encoding?, "#{encdump s}.valid_encoding?")
|
||||||
"\x00",
|
}
|
||||||
"\xd7",
|
}
|
||||||
"\x00\xd8",
|
[
|
||||||
"\x00\xd8\x00\xd8",
|
"\x00",
|
||||||
"\x00\xdc",
|
"\xd7",
|
||||||
"\x00\xdc\x00\xd8",
|
"\x00\xd8",
|
||||||
"\x00\xdc\x00\xdc",
|
"\x00\xd8\x00\xd8",
|
||||||
"\xe0",
|
"\x00\xdc",
|
||||||
"\xff",
|
"\x00\xdc\x00\xd8",
|
||||||
].each {|s|
|
"\x00\xdc\x00\xdc",
|
||||||
s.force_encoding("utf-16le")
|
"\xe0",
|
||||||
assert_equal(false, s.valid_encoding?, "#{encdump s}.valid_encoding?")
|
"\xff",
|
||||||
}
|
].each {|s|
|
||||||
|
s.force_encoding("utf-16le")
|
||||||
|
a.for(s) {
|
||||||
|
assert_not_predicate(s, :valid_encoding?, "#{encdump s}.valid_encoding?")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_strftime
|
def test_strftime
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue