summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-23 07:58:48 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-23 07:58:48 +0000
commitf2d84ac87b6f45d16b9c4ed3247aaf8822690769 (patch)
tree785c02e2d2af8f9960b75dba7c9aa13e788ad593 /test
parent5628d949f99a4b5debd91341b8c27ff14d4076b0 (diff)
split UTF-16 tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15183 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_m17n.rb42
-rw-r--r--test/ruby/test_utf16.rb68
2 files changed, 68 insertions, 42 deletions
diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb
index dfae3a7bb9..f45dae9a47 100644
--- a/test/ruby/test_m17n.rb
+++ b/test/ruby/test_m17n.rb
@@ -291,42 +291,6 @@ class TestM17N < Test::Unit::TestCase
}
end
- def test_utf16_valid_encoding
- s = "\xd8\x00\xd8\x00".force_encoding("utf-16be")
- assert_equal(false, s.valid_encoding?, "#{encdump s}.valid_encoding?")
- end
-
- def test_utf16
- s = "aa".force_encoding("utf-16be")
- assert_raise(ArgumentError, "Time.now.strftime(#{encdump s})") { Time.now.strftime(s) }
-
- s = "aaaa".force_encoding("utf-16be")
- assert_equal(s.encoding, s.intern.to_s.encoding, "#{encdump s}.intern.to_s.encoding")
-
- s1 = "aa".force_encoding("utf-16be")
- s2 = "z".force_encoding("us-ascii")
- assert_nil(Encoding.compatible?(s1, s2), "Encoding.compatible?(#{encdump s1}, #{encdump s2})")
-
- s1 = "ab".force_encoding("utf-16be")
- s2 = "b".force_encoding("utf-16be")
- assert_equal(false, s1.end_with?(s2), "#{encdump s1}.end_with?(#{encdump s2})")
-
- s1 = "f\0f\0".force_encoding("utf-16le")
- assert_equal(255, s1.hex, "#{encdump s1}.hex")
-
- s1 = "aa".force_encoding("utf-16be")
- s2 = "aa"
- assert_raise(ArgumentError, "#{encdump s1}.count(#{encdump s2})") {
- s1.count(s2)
- }
-
- s1 = "a".force_encoding("us-ascii")
- s2 = "aa".force_encoding("utf-16be")
- assert_raise(ArgumentError, "#{encdump s1} + #{encdump s2}") {
- s1 + s2
- }
- end
-
def test_regexp_too_short_multibyte_character
assert_raise(SyntaxError) { eval('/\xfe/e') }
assert_raise(SyntaxError) { eval('/\x8e/e') }
@@ -998,10 +962,4 @@ class TestM17N < Test::Unit::TestCase
assert_equal(Encoding::ASCII_8BIT, v.encoding)
}
end
-
- def test_encoding_find
- assert_raise(ArgumentError) {
- Encoding.find("utf-8".force_encoding("utf-16be"))
- }
- end
end
diff --git a/test/ruby/test_utf16.rb b/test/ruby/test_utf16.rb
new file mode 100644
index 0000000000..807f8afa6f
--- /dev/null
+++ b/test/ruby/test_utf16.rb
@@ -0,0 +1,68 @@
+require 'test/unit'
+
+class TestM17N < Test::Unit::TestCase
+ def encdump(str)
+ d = str.dump
+ if /\.force_encoding\("[A-Za-z0-9.:_+-]*"\)\z/ =~ d
+ d
+ else
+ "#{d}.force_encoding(#{str.encoding.name.dump})"
+ end
+ end
+
+ # tests start
+
+ def test_utf16be_valid_encoding
+ s = "\xd8\x00\xd8\x00".force_encoding("utf-16be")
+ assert_equal(false, s.valid_encoding?, "#{encdump s}.valid_encoding?")
+ end
+
+ def test_strftime
+ s = "aa".force_encoding("utf-16be")
+ assert_raise(ArgumentError, "Time.now.strftime(#{encdump s})") { Time.now.strftime(s) }
+ end
+
+ def test_intern
+ s = "aaaa".force_encoding("utf-16be")
+ assert_equal(s.encoding, s.intern.to_s.encoding, "#{encdump s}.intern.to_s.encoding")
+ end
+
+ def test_compatible
+ s1 = "aa".force_encoding("utf-16be")
+ s2 = "z".force_encoding("us-ascii")
+ assert_nil(Encoding.compatible?(s1, s2), "Encoding.compatible?(#{encdump s1}, #{encdump s2})")
+ end
+
+ def test_end_with
+ s1 = "ab".force_encoding("utf-16be")
+ s2 = "b".force_encoding("utf-16be")
+ assert_equal(false, s1.end_with?(s2), "#{encdump s1}.end_with?(#{encdump s2})")
+ end
+
+ def test_hex
+ s1 = "f\0f\0".force_encoding("utf-16le")
+ assert_equal(255, s1.hex, "#{encdump s1}.hex")
+ end
+
+ def test_count
+ s1 = "aa".force_encoding("utf-16be")
+ s2 = "aa"
+ assert_raise(ArgumentError, "#{encdump s1}.count(#{encdump s2})") {
+ s1.count(s2)
+ }
+ end
+
+ def test_plus
+ s1 = "a".force_encoding("us-ascii")
+ s2 = "aa".force_encoding("utf-16be")
+ assert_raise(ArgumentError, "#{encdump s1} + #{encdump s2}") {
+ s1 + s2
+ }
+ end
+
+ def test_encoding_find
+ assert_raise(ArgumentError) {
+ Encoding.find("utf-8".force_encoding("utf-16be"))
+ }
+ end
+end