1
0
Fork 0
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:
nobu 2017-03-09 01:55:43 +00:00
parent 2ebc44656f
commit e65c9bd177

View file

@ -56,59 +56,71 @@ EOT
# tests start
def test_utf16be_valid_encoding
[
"\x00\x00",
"\xd7\xff",
"\xd8\x00\xdc\x00",
"\xdb\xff\xdf\xff",
"\xe0\x00",
"\xff\xff",
].each {|s|
s.force_encoding("utf-16be")
assert_equal(true, s.valid_encoding?, "#{encdump s}.valid_encoding?")
}
[
"\x00",
"\xd7",
"\xd8\x00",
"\xd8\x00\xd8\x00",
"\xdc\x00",
"\xdc\x00\xd8\x00",
"\xdc\x00\xdc\x00",
"\xe0",
"\xff",
].each {|s|
s.force_encoding("utf-16be")
assert_equal(false, s.valid_encoding?, "#{encdump s}.valid_encoding?")
}
all_assertions do |a|
[
"\x00\x00",
"\xd7\xff",
"\xd8\x00\xdc\x00",
"\xdb\xff\xdf\xff",
"\xe0\x00",
"\xff\xff",
].each {|s|
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",
"\xdc\x00",
"\xdc\x00\xd8\x00",
"\xdc\x00\xdc\x00",
"\xe0",
"\xff",
].each {|s|
s.force_encoding("utf-16be")
a.for(s) {
assert_not_predicate(s, :valid_encoding?, "#{encdump s}.valid_encoding?")
}
}
end
end
def test_utf16le_valid_encoding
[
"\x00\x00",
"\xff\xd7",
"\x00\xd8\x00\xdc",
"\xff\xdb\xff\xdf",
"\x00\xe0",
"\xff\xff",
].each {|s|
s.force_encoding("utf-16le")
assert_equal(true, s.valid_encoding?, "#{encdump s}.valid_encoding?")
}
[
"\x00",
"\xd7",
"\x00\xd8",
"\x00\xd8\x00\xd8",
"\x00\xdc",
"\x00\xdc\x00\xd8",
"\x00\xdc\x00\xdc",
"\xe0",
"\xff",
].each {|s|
s.force_encoding("utf-16le")
assert_equal(false, s.valid_encoding?, "#{encdump s}.valid_encoding?")
}
all_assertions do |a|
[
"\x00\x00",
"\xff\xd7",
"\x00\xd8\x00\xdc",
"\xff\xdb\xff\xdf",
"\x00\xe0",
"\xff\xff",
].each {|s|
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\xdc",
"\x00\xdc\x00\xd8",
"\x00\xdc\x00\xdc",
"\xe0",
"\xff",
].each {|s|
s.force_encoding("utf-16le")
a.for(s) {
assert_not_predicate(s, :valid_encoding?, "#{encdump s}.valid_encoding?")
}
}
end
end
def test_strftime