From 3583d442727ff66814e6cea437d823849946b937 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 16 Jul 2008 19:33:15 +0000 Subject: * test/ruby/enc: moved tests for particular encodings. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@18095 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/enc/test_big5.rb | 28 +++ test/ruby/enc/test_cp949.rb | 28 +++ test/ruby/enc/test_euc_jp.rb | 20 +++ test/ruby/enc/test_euc_kr.rb | 28 +++ test/ruby/enc/test_euc_tw.rb | 28 +++ test/ruby/enc/test_gb18030.rb | 125 +++++++++++++ test/ruby/enc/test_gbk.rb | 28 +++ test/ruby/enc/test_iso_8859.rb | 163 +++++++++++++++++ test/ruby/enc/test_shift_jis.rb | 27 +++ test/ruby/enc/test_utf16.rb | 358 +++++++++++++++++++++++++++++++++++++ test/ruby/enc/test_utf32.rb | 93 ++++++++++ test/ruby/enc/test_windows_1251.rb | 16 ++ test/ruby/test_big5.rb | 28 --- test/ruby/test_cp949.rb | 28 --- test/ruby/test_euc_jp.rb | 20 --- test/ruby/test_euc_kr.rb | 28 --- test/ruby/test_euc_tw.rb | 28 --- test/ruby/test_gb18030.rb | 125 ------------- test/ruby/test_gbk.rb | 28 --- test/ruby/test_iso_8859.rb | 163 ----------------- test/ruby/test_shift_jis.rb | 27 --- test/ruby/test_utf16.rb | 358 ------------------------------------- test/ruby/test_utf32.rb | 93 ---------- test/ruby/test_windows_1251.rb | 16 -- 24 files changed, 942 insertions(+), 942 deletions(-) create mode 100644 test/ruby/enc/test_big5.rb create mode 100644 test/ruby/enc/test_cp949.rb create mode 100644 test/ruby/enc/test_euc_jp.rb create mode 100644 test/ruby/enc/test_euc_kr.rb create mode 100644 test/ruby/enc/test_euc_tw.rb create mode 100644 test/ruby/enc/test_gb18030.rb create mode 100644 test/ruby/enc/test_gbk.rb create mode 100644 test/ruby/enc/test_iso_8859.rb create mode 100644 test/ruby/enc/test_shift_jis.rb create mode 100644 test/ruby/enc/test_utf16.rb create mode 100644 test/ruby/enc/test_utf32.rb create mode 100644 test/ruby/enc/test_windows_1251.rb delete mode 100644 test/ruby/test_big5.rb delete mode 100644 test/ruby/test_cp949.rb delete mode 100644 test/ruby/test_euc_jp.rb delete mode 100644 test/ruby/test_euc_kr.rb delete mode 100644 test/ruby/test_euc_tw.rb delete mode 100644 test/ruby/test_gb18030.rb delete mode 100644 test/ruby/test_gbk.rb delete mode 100644 test/ruby/test_iso_8859.rb delete mode 100644 test/ruby/test_shift_jis.rb delete mode 100644 test/ruby/test_utf16.rb delete mode 100644 test/ruby/test_utf32.rb delete mode 100644 test/ruby/test_windows_1251.rb (limited to 'test/ruby') diff --git a/test/ruby/enc/test_big5.rb b/test/ruby/enc/test_big5.rb new file mode 100644 index 000000000..e8fe0270a --- /dev/null +++ b/test/ruby/enc/test_big5.rb @@ -0,0 +1,28 @@ +require "test/unit" + +class TestBig5 < Test::Unit::TestCase + def s(s) + s.force_encoding("big5") + end + + def test_mbc_enc_len + assert_equal(1, s("\xa1\xa1").size) + end + + def test_mbc_to_code + assert_equal(0xa1a1, s("\xa1\xa1").ord) + end + + def test_code_to_mbc + assert_equal(s("\xa1\xa1"), 0xa1a1.chr("big5")) + end + + def test_mbc_case_fold + r = Regexp.new(s("(\xa1\xa1)\\1"), "i") + assert_match(r, s("\xa1\xa1\xa1\xa1")) + end + + def test_left_adjust_char_head + assert_equal(s("\xa1\xa1"), s("\xa1\xa1\xa1\xa1").chop) + end +end diff --git a/test/ruby/enc/test_cp949.rb b/test/ruby/enc/test_cp949.rb new file mode 100644 index 000000000..e675c7b80 --- /dev/null +++ b/test/ruby/enc/test_cp949.rb @@ -0,0 +1,28 @@ +require "test/unit" + +class TestCP949 < Test::Unit::TestCase + def s(s) + s.force_encoding("cp949") + end + + def test_mbc_enc_len + assert_equal(1, s("\xa1\xa1").size) + end + + def test_mbc_to_code + assert_equal(0xa1a1, s("\xa1\xa1").ord) + end + + def test_code_to_mbc + assert_equal(s("\xa1\xa1"), 0xa1a1.chr("cp949")) + end + + def test_mbc_case_fold + r = Regexp.new(s("(\xa1\xa1)\\1"), "i") + assert_match(r, s("\xa1\xa1\xa1\xa1")) + end + + def test_left_adjust_char_head + assert_equal(s("\xa1\xa1"), s("\xa1\xa1\xa1\xa1").chop) + end +end diff --git a/test/ruby/enc/test_euc_jp.rb b/test/ruby/enc/test_euc_jp.rb new file mode 100644 index 000000000..82abe2116 --- /dev/null +++ b/test/ruby/enc/test_euc_jp.rb @@ -0,0 +1,20 @@ +# vim: set fileencoding=euc-jp + +require "test/unit" + +class TestEUC_JP < Test::Unit::TestCase + def test_mbc_case_fold + assert_match(/(a)(a)\1\2/i, "aaaA") + assert_no_match(/(a)(a)\1\2/i, "aaAA") + end + + def test_property + assert_match(/あ{0}\p{Hiragana}{4}/, "ひらがな") + assert_no_match(/あ{0}\p{Hiragana}{4}/, "カタカナ") + assert_no_match(/あ{0}\p{Hiragana}{4}/, "漢字漢字") + assert_no_match(/あ{0}\p{Katakana}{4}/, "ひらがな") + assert_match(/あ{0}\p{Katakana}{4}/, "カタカナ") + assert_no_match(/あ{0}\p{Katakana}{4}/, "漢字漢字") + assert_raise(RegexpError) { Regexp.new('あ{0}\p{foobarbaz}') } + end +end diff --git a/test/ruby/enc/test_euc_kr.rb b/test/ruby/enc/test_euc_kr.rb new file mode 100644 index 000000000..087bc795f --- /dev/null +++ b/test/ruby/enc/test_euc_kr.rb @@ -0,0 +1,28 @@ +require "test/unit" + +class TestEucKr < Test::Unit::TestCase + def s(s) + s.force_encoding("euc-kr") + end + + def test_mbc_enc_len + assert_equal(1, s("\xa1\xa1").size) + end + + def test_mbc_to_code + assert_equal(0xa1a1, s("\xa1\xa1").ord) + end + + def test_code_to_mbc + assert_equal(s("\xa1\xa1"), 0xa1a1.chr("euc-kr")) + end + + def test_mbc_case_fold + r = Regexp.new(s("(\xa1\xa1)\\1"), "i") + assert_match(r, s("\xa1\xa1\xa1\xa1")) + end + + def test_left_adjust_char_head + assert_equal(s("\xa1\xa1"), s("\xa1\xa1\xa1\xa1").chop) + end +end diff --git a/test/ruby/enc/test_euc_tw.rb b/test/ruby/enc/test_euc_tw.rb new file mode 100644 index 000000000..f36d86b08 --- /dev/null +++ b/test/ruby/enc/test_euc_tw.rb @@ -0,0 +1,28 @@ +require "test/unit" + +class TestEucTw < Test::Unit::TestCase + def s(s) + s.force_encoding("euc-tw") + end + + def test_mbc_enc_len + assert_equal(1, s("\xa1\xa1").size) + end + + def test_mbc_to_code + assert_equal(0xa1a1, s("\xa1\xa1").ord) + end + + def test_code_to_mbc + assert_equal(s("\xa1\xa1"), 0xa1a1.chr("euc-tw")) + end + + def test_mbc_case_fold + r = Regexp.new(s("(\xa1\xa1)\\1"), "i") + assert_match(r, s("\xa1\xa1\xa1\xa1")) + end + + def test_left_adjust_char_head + assert_equal(s("\xa1\xa1"), s("\xa1\xa1\xa1\xa1").chop) + end +end diff --git a/test/ruby/enc/test_gb18030.rb b/test/ruby/enc/test_gb18030.rb new file mode 100644 index 000000000..a33a9eb28 --- /dev/null +++ b/test/ruby/enc/test_gb18030.rb @@ -0,0 +1,125 @@ +require "test/unit" + +class TestGB18030 < Test::Unit::TestCase + def s(s) + s.force_encoding("gb18030") + end + + def test_mbc_enc_len + assert_equal(1, s("\x81\x40").size) + assert_equal(1, s("\x81\x30\x81\x30").size) + end + + def test_mbc_to_code + assert_equal(0x8140, s("\x81\x40").ord) + end + + def test_code_to_mbc + assert_equal(s("\x81\x40"), 0x8140.chr("gb18030")) + end + + def test_mbc_case_fold + r = Regexp.new(s("(\x81\x40)\\1"), "i") + assert_match(r, s("\x81\x40\x81\x40")) + end + + def scheck(c, i) + assert_equal(s(c.reverse.take(c.size - i).join), s(c.reverse.join).chop) + end + + def fcheck(c) + assert_raise(ArgumentError) { s(c.reverse.join).chop } + end + + def test_left_adjust_char_head + # C1: 00-2f, 3a-3f, 7f, ff + # C2: 40-7e, 80 + # C4: 30-39 + # CM: 81-fe + c1 = "\x2f" + c2 = "\x40" + c4 = "\x30" + cm = "\x81" + + # S_START-c1 + # S_START-c2-S_one_C2-0 + # S_START-c2-S_one_C2-c1 + # S_START-c2-S_one_C2-cm-S_odd_CM_one_CX-c1 + # S_START-c2-S_one_C2-cm-S_odd_CM_one_CX-cm-S_even_CM_one_CX-c1 + # S_START-c2-S_one_C2-cm-S_odd_CM_one_CX-cm-S_even_CM_one_CX-cm-S_odd_CM_one_CX(rec) + # S_START-c4-S_one_C4-c1 + # S_START-c4-S_one_C4-cm-S_one_CMC4-c1 + # S_START-c4-S_one_C4-cm-S_one_CMC4-c4-S_one_C4_odd_CMC4-c1 + # S_START-c4-S_one_C4-cm-S_one_CMC4-c4-S_one_C4_odd_CMC4-cm-S_even_CMC4-c1 + # S_START-c4-S_one_C4-cm-S_one_CMC4-c4-S_one_C4_odd_CMC4-cm-S_even_CMC4-c4-S_one_C4_even_CMC4-c1 + # S_START-c4-S_one_C4-cm-S_one_CMC4-c4-S_one_C4_odd_CMC4-cm-S_even_CMC4-c4-S_one_C4_even_CMC4-cm-S_odd_CMC4-c1 + # S_START-c4-S_one_C4-cm-S_one_CMC4-c4-S_one_C4_odd_CMC4-cm-S_even_CMC4-c4-S_one_C4_even_CMC4-cm-S_odd_CMC4-c4-S_one_C4_odd_CMC4(rec) + # S_START-c4-S_one_C4-cm-S_one_CMC4-c4-S_one_C4_odd_CMC4-cm-S_even_CMC4-c4-S_one_C4_even_CMC4-cm-S_odd_CMC4-cm-S_odd_CM_odd_CMC4-c1 + # S_START-c4-S_one_C4-cm-S_one_CMC4-c4-S_one_C4_odd_CMC4-cm-S_even_CMC4-c4-S_one_C4_even_CMC4-cm-S_odd_CMC4-cm-S_odd_CM_odd_CMC4-cm-S_even_CM_odd_CMC4-c1 + # S_START-c4-S_one_C4-cm-S_one_CMC4-c4-S_one_C4_odd_CMC4-cm-S_even_CMC4-c4-S_one_C4_even_CMC4-cm-S_odd_CMC4-cm-S_odd_CM_odd_CMC4-cm-S_even_CM_odd_CMC4-cm-S_odd_CM_odd_CMC4(rec) + # S_START-c4-S_one_C4-cm-S_one_CMC4-c4-S_one_C4_odd_CMC4-cm-S_even_CMC4-cm-S_odd_CM_even_CMC4-c1 + # S_START-c4-S_one_C4-cm-S_one_CMC4-c4-S_one_C4_odd_CMC4-cm-S_even_CMC4-cm-S_odd_CM_even_CMC4-cm-S_even_CM_even_CMC4-c1 + # S_START-c4-S_one_C4-cm-S_one_CMC4-c4-S_one_C4_odd_CMC4-cm-S_even_CMC4-cm-S_odd_CM_even_CMC4-cm-S_even_CM_even_CMC4-cm-S_odd_CM_even_CMC4(rec) + # S_START-c4-S_one_C4-cm-S_one_CMC4-cm-S_even_CM_one_CX(rec) + # S_START-cm-S_one_CM-c1 + # S_START-cm-S_one_CM-c4-S_odd_C4CM-c1 + # S_START-cm-S_one_CM-c4-S_odd_C4CM-cm-S_one_CM_odd_C4CM-c1 + # S_START-cm-S_one_CM-c4-S_odd_C4CM-cm-S_one_CM_odd_C4CM-c4-S_even_C4CM-c1 + # S_START-cm-S_one_CM-c4-S_odd_C4CM-cm-S_one_CM_odd_C4CM-c4-S_even_C4CM-cm-S_one_CM_even_C4CM-c1 + # S_START-cm-S_one_CM-c4-S_odd_C4CM-cm-S_one_CM_odd_C4CM-c4-S_even_C4CM-cm-S_one_CM_even_C4CM-c4-S_odd_C4CM(rec) + # S_START-cm-S_one_CM-c4-S_odd_C4CM-cm-S_one_CM_odd_C4CM-c4-S_even_C4CM-cm-S_one_CM_even_C4CM-cm-S_even_CM_even_C4CM-c1 + # S_START-cm-S_one_CM-c4-S_odd_C4CM-cm-S_one_CM_odd_C4CM-c4-S_even_C4CM-cm-S_one_CM_even_C4CM-cm-S_even_CM_even_C4CM-cm-S_odd_CM_even_C4CM-c1 + # S_START-cm-S_one_CM-c4-S_odd_C4CM-cm-S_one_CM_odd_C4CM-c4-S_even_C4CM-cm-S_one_CM_even_C4CM-cm-S_even_CM_even_C4CM-cm-S_odd_CM_even_C4CM-cm-S_even_CM_even_C4CM(rec) + # S_START-cm-S_one_CM-c4-S_odd_C4CM-cm-S_one_CM_odd_C4CM-cm-S_even_CM_odd_C4CM-c1 + # S_START-cm-S_one_CM-c4-S_odd_C4CM-cm-S_one_CM_odd_C4CM-cm-S_even_CM_odd_C4CM-cm-S_odd_CM_odd_C4CM-c1 + # S_START-cm-S_one_CM-c4-S_odd_C4CM-cm-S_one_CM_odd_C4CM-cm-S_even_CM_odd_C4CM-cm-S_odd_CM_odd_C4CM-cm-S_even_CM_odd_C4CM(rec) + # S_START-cm-S_one_CM-cm-S_odd_CM_one_CX(rec) + + scheck([c1], 1) + scheck([c2], 1) + scheck([c2, c1], 1) + scheck([c2, cm, c1], 2) + scheck([c2, cm, cm, c1], 1) + scheck([c2, cm, cm, cm], 2) + scheck([c4], 1) + scheck([c4, c1], 1) + scheck([c4, cm], 2) + fcheck([c4, cm, c1]) + fcheck([c4, cm, c4, c1]) + scheck([c4, cm, c4, cm], 4) + scheck([c4, cm, c4, cm, c1], 4) + scheck([c4, cm, c4, cm, c4], 4) + scheck([c4, cm, c4, cm, c4, c1], 4) + fcheck([c4, cm, c4, cm, c4, cm]) + fcheck([c4, cm, c4, cm, c4, cm, c1]) + fcheck([c4, cm, c4, cm, c4, cm, c4]) + scheck([c4, cm, c4, cm, c4, cm, cm, c1], 4) + fcheck([c4, cm, c4, cm, c4, cm, cm, cm]) + fcheck([c4, cm, c4, cm, c4, cm, cm, cm, c1]) + scheck([c4, cm, c4, cm, c4, cm, cm, cm, cm], 4) + fcheck([c4, cm, c4, cm, cm, c1]) + scheck([c4, cm, c4, cm, cm, cm], 4) + scheck([c4, cm, c4, cm, cm, cm, c1], 4) + fcheck([c4, cm, c4, cm, cm, cm, cm]) + scheck([c4, cm, cm], 1) + scheck([cm], 1) + fcheck([cm, c1]) + fcheck([cm, c4, c1]) + scheck([cm, c4, cm], 3) + fcheck([cm, c4, cm, c1]) + fcheck([cm, c4, cm, c4]) + fcheck([cm, c4, cm, c4, c1]) + fcheck([cm, c4, cm, c4, cm]) + fcheck([cm, c4, cm, c4, cm, c1]) + fcheck([cm, c4, cm, c4, cm, c4]) + fcheck([cm, c4, cm, c4, cm, cm, c1]) + fcheck([cm, c4, cm, c4, cm, cm, cm]) + fcheck([cm, c4, cm, c4, cm, cm, cm, c1]) + fcheck([cm, c4, cm, c4, cm, cm, cm, cm]) + fcheck([cm, c4, cm, cm, c1]) + fcheck([cm, c4, cm, cm, cm]) + fcheck([cm, c4, cm, cm, cm, c1]) + fcheck([cm, c4, cm, cm, cm, cm]) + scheck([cm, cm], 2) + end +end diff --git a/test/ruby/enc/test_gbk.rb b/test/ruby/enc/test_gbk.rb new file mode 100644 index 000000000..d6dc5d6d1 --- /dev/null +++ b/test/ruby/enc/test_gbk.rb @@ -0,0 +1,28 @@ +require "test/unit" + +class TestGBK < Test::Unit::TestCase + def s(s) + s.force_encoding("gbk") + end + + def test_mbc_enc_len + assert_equal(1, s("\x81\x40").size) + end + + def test_mbc_to_code + assert_equal(0x8140, s("\x81\x40").ord) + end + + def test_code_to_mbc + assert_equal(s("\x81\x40"), 0x8140.chr("gbk")) + end + + def test_mbc_case_fold + r = Regexp.new(s("(\x81\x40)\\1"), "i") + assert_match(r, s("\x81\x40\x81\x40")) + end + + def test_left_adjust_char_head + assert_equal(s("\x81\x40"), s("\x81\x40\x81\x40").chop) + end +end diff --git a/test/ruby/enc/test_iso_8859.rb b/test/ruby/enc/test_iso_8859.rb new file mode 100644 index 000000000..64cc7cd76 --- /dev/null +++ b/test/ruby/enc/test_iso_8859.rb @@ -0,0 +1,163 @@ +require 'test/unit' + +class TestISO8859 < Test::Unit::TestCase + ASSERTS = %q( + assert_match(/^(\xdf)\1$/i, "\xdf\xdf") + assert_match(/^(\xdf)\1$/i, "ssss") + # assert_match(/^(\xdf)\1$/i, "\xdfss") # this must be bug... + assert_match(/^[\xdfz]+$/i, "sszzsszz") + assert_match(/^SS$/i, "\xdf") + assert_match(/^Ss$/i, "\xdf") + ((0xc0..0xde).to_a - [0xd7]).each do |c| + c1 = c.chr("ENCODING") + c2 = (c + 0x20).chr("ENCODING") + assert_match(/^(#{ c1 })\1$/i, c2 + c1) + assert_match(/^(#{ c2 })\1$/i, c1 + c2) + assert_match(/^[#{ c1 }]+$/i, c2 + c1) + assert_match(/^[#{ c2 }]+$/i, c1 + c2) + end + assert_match(/^\xff$/i, "\xff") + ) + + def test_iso_8859_1 + eval("# encoding: iso8859-1\n" + ASSERTS.gsub(/ENCODING/m, "iso8859-1")) + end + + def test_iso_8859_2 + eval("# encoding: iso8859-2\n" + ASSERTS.gsub(/ENCODING/m, "iso8859-2")) + end + + def test_iso_8859_3 + eval(%q(# encoding: iso8859-3 + assert_match(/^(\xdf)\1$/i, "\xdf\xdf") + assert_match(/^(\xdf)\1$/i, "ssss") + assert_match(/^[\xdfz]+$/i, "sszzsszz") + assert_match(/^SS$/i, "\xdf") + assert_match(/^Ss$/i, "\xdf") + [0xa1, 0xa6, *(0xa9..0xac), 0xaf].each do |c| + c1 = c.chr("iso8859-3") + c2 = (c + 0x10).chr("iso8859-3") + assert_match(/^(#{ c1 })\1$/i, c2 + c1) + assert_match(/^(#{ c2 })\1$/i, c1 + c2) + assert_match(/^[#{ c1 }]+$/i, c2 + c1) + assert_match(/^[#{ c2 }]+$/i, c1 + c2) + end + ([*(0xc0..0xde)] - [0xc3, 0xd0, 0xd7]).each do |c| + c1 = c.chr("iso8859-3") + c2 = (c + 0x20).chr("iso8859-3") + assert_match(/^(#{ c1 })\1$/i, c2 + c1) + assert_match(/^(#{ c2 })\1$/i, c1 + c2) + assert_match(/^[#{ c1 }]+$/i, c2 + c1) + assert_match(/^[#{ c2 }]+$/i, c1 + c2) + end + )) + end + + def test_iso_8859_4 + eval("# encoding: iso8859-4\n" + ASSERTS.gsub(/ENCODING/m, "iso8859-4")) + end + + def test_iso_8859_5 + eval(%q(# encoding: iso8859-5 + (0xb0..0xcf).each do |c| + c1 = c.chr("iso8859-5") + c2 = (c + 0x20).chr("iso8859-5") + assert_match(/^(#{ c1 })\1$/i, c2 + c1) + assert_match(/^(#{ c2 })\1$/i, c1 + c2) + assert_match(/^[#{ c1 }]+$/i, c2 + c1) + assert_match(/^[#{ c2 }]+$/i, c1 + c2) + end + ((0xa1..0xaf).to_a - [0xad]).each do |c| + c1 = c.chr("iso8859-5") + c2 = (c + 0x50).chr("iso8859-5") + assert_match(/^(#{ c1 })\1$/i, c2 + c1) + assert_match(/^(#{ c2 })\1$/i, c1 + c2) + assert_match(/^[#{ c1 }]+$/i, c2 + c1) + assert_match(/^[#{ c2 }]+$/i, c1 + c2) + end + )) + end + + def test_iso_8859_6 + eval(%q(# encoding: iso8859-6 + [0xa4, 0xac, 0xbb, 0xbf, *(0xc1..0xda), *(0xe0..0xf2)].each do |c| + c1 = c.chr("iso8859-6") + assert_match(/^(#{ c1 })\1$/i, c1 * 2) + end + )) + end + + def test_iso_8859_7 + eval(%q(# encoding: iso8859-7 + ((0xa0..0xfe).to_a - [0xae, 0xd2]).each do |c| + c1 = c.chr("iso8859-7") + assert_match(/^(#{ c1 })\1$/i, c1 * 2) + end + ((0xc1..0xd9).to_a - [0xd2]).each do |c| + c1 = c.chr("iso8859-7") + c2 = (c + 0x20).chr("iso8859-7") + assert_match(/^(#{ c1 })\1$/i, c2 + c1) + assert_match(/^(#{ c2 })\1$/i, c1 + c2) + assert_match(/^[#{ c1 }]+$/i, c2 + c1) + assert_match(/^[#{ c2 }]+$/i, c1 + c2) + end + )) + end + + def test_iso_8859_8 + eval(%q(# encoding: iso8859-8 + [0xa0, *(0xa2..0xbe), *(0xdf..0xfa), 0xfc, 0xfd].each do |c| + c1 = c.chr("iso8859-8") + assert_match(/^(#{ c1 })\1$/i, c1 * 2) + end + )) + end + + def test_iso_8859_9 + eval(%q(# encoding: iso8859-9 + assert_match(/^(\xdf)\1$/i, "\xdf\xdf") + assert_match(/^(\xdf)\1$/i, "ssss") + assert_match(/^[\xdfz]+$/i, "sszzsszz") + assert_match(/^SS$/i, "\xdf") + assert_match(/^Ss$/i, "\xdf") + ([*(0xc0..0xdc)] - [0xd7]).each do |c| + c1 = c.chr("iso8859-9") + c2 = (c + 0x20).chr("iso8859-9") + assert_match(/^(#{ c1 })\1$/i, c2 + c1) + assert_match(/^(#{ c2 })\1$/i, c1 + c2) + assert_match(/^[#{ c1 }]+$/i, c2 + c1) + assert_match(/^[#{ c2 }]+$/i, c1 + c2) + end + )) + end + + def test_iso_8859_10 + eval("# encoding: iso8859-10\n" + ASSERTS.gsub(/ENCODING/m, "iso8859-10")) + end + + def test_iso_8859_11 + eval(%q(# encoding: iso8859-11 + [*(0xa0..0xda), *(0xdf..0xfb)].each do |c| + c1 = c.chr("iso8859-11") + assert_match(/^(#{ c1 })\1$/i, c1 * 2) + end + )) + end + + def test_iso_8859_13 + eval("# encoding: iso8859-13\n" + ASSERTS.gsub(/ENCODING/m, "iso8859-13")) + end + + def test_iso_8859_14 + eval("# encoding: iso8859-14\n" + ASSERTS.gsub(/ENCODING/m, "iso8859-14")) + end + + def test_iso_8859_15 + eval("# encoding: iso8859-15\n" + ASSERTS.gsub(/ENCODING/m, "iso8859-15")) + end + + def test_iso_8859_16 + eval("# encoding: iso8859-16\n" + ASSERTS.gsub(/ENCODING/m, "iso8859-16")) + end +end + diff --git a/test/ruby/enc/test_shift_jis.rb b/test/ruby/enc/test_shift_jis.rb new file mode 100644 index 000000000..f81cb7801 --- /dev/null +++ b/test/ruby/enc/test_shift_jis.rb @@ -0,0 +1,27 @@ +# vim: set fileencoding=shift_jis + +require "test/unit" + +class TestShiftJIS < Test::Unit::TestCase + def test_mbc_case_fold + assert_match(/()(a)\1\2/i, "aA") + assert_no_match(/()(a)\1\2/i, "a`A") + end + + def test_property + assert_match(/{0}\p{Hiragana}{4}/, "") + assert_no_match(/{0}\p{Hiragana}{4}/, "J^Ji") + assert_no_match(/{0}\p{Hiragana}{4}/, "") + assert_no_match(/{0}\p{Katakana}{4}/, "") + assert_match(/{0}\p{Katakana}{4}/, "J^Ji") + assert_no_match(/{0}\p{Katakana}{4}/, "") + assert_raise(RegexpError) { Regexp.new('{0}\p{foobarbaz}') } + end + + def test_code_to_mbclen + s = "" + s << 0x82a9 + assert_equal("", s) + assert_raise(ArgumentError) { s << 0x82 } + end +end diff --git a/test/ruby/enc/test_utf16.rb b/test/ruby/enc/test_utf16.rb new file mode 100644 index 000000000..c10463b2b --- /dev/null +++ b/test/ruby/enc/test_utf16.rb @@ -0,0 +1,358 @@ +require 'test/unit' + +class TestUTF16 < 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 + + def enccall(recv, meth, *args) + desc = '' + if String === recv + desc << encdump(recv) + else + desc << recv.inspect + end + desc << '.' << meth.to_s + if !args.empty? + desc << '(' + args.each_with_index {|a, i| + desc << ',' if 0 < i + if String === a + desc << encdump(a) + else + desc << a.inspect + end + } + desc << ')' + end + result = nil + assert_nothing_raised(desc) { + result = recv.send(meth, *args) + } + result + end + + def assert_str_equal(expected, actual, message=nil) + full_message = build_message(message, <