diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-22 03:59:53 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-22 03:59:53 +0000 |
commit | 65a8185eb212639875ae8db14dfffb1fa06b71e9 (patch) | |
tree | 95b915e9c09bac1eaff6cc86b70d590a053c3ba4 /test/ruby/test_m17n.rb | |
parent | 157664b9f3cfeb485abe1cf8298e82accef23acf (diff) | |
download | ruby-65a8185eb212639875ae8db14dfffb1fa06b71e9.tar.gz |
* configure.in (MINIRUBY): remove -I$(EXTOUT)/$(arch) from
MINIRUBY since miniruby might not be able to load DLL.
* test/ruby/test_m17n.rb: move tests from bootstrap test.
* encoding.c (enc_find): should check name if ASCII compatible.
* string.c (rb_str_end_with): should check character boundary.
* encoding.c (rb_enc_compatible): encoding must be ASCII
compatible before checking ENC_CODERANGE_7BIT.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15167 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_m17n.rb')
-rw-r--r-- | test/ruby/test_m17n.rb | 109 |
1 files changed, 100 insertions, 9 deletions
diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb index 5a0115e285..a7ec25d57d 100644 --- a/test/ruby/test_m17n.rb +++ b/test/ruby/test_m17n.rb @@ -690,6 +690,9 @@ class TestM17N < Test::Unit::TestCase #assert_raise(ArgumentError) { s("%c") % 0xc2a1 } assert_strenc("\u{c2a1}", 'UTF-8', u("%c") % 0xc2a1) assert_strenc("\u{c2}", 'UTF-8', u("%c") % 0xc2) + assert_raise(ArgumentError) { + "%s%s" % [s("\xc2\xa1"), e("\xc2\xa1")] + } end def test_sprintf_p @@ -744,6 +747,7 @@ class TestM17N < Test::Unit::TestCase assert_strenc("\x00", 'EUC-JP', e("%s") % e("\x00")) assert_strenc("\x00", 'Windows-31J', s("%s") % s("\x00")) assert_strenc("\x00", 'UTF-8', u("%s") % u("\x00")) + assert_equal("EUC-JP", (e("\xc2\xa1 %s") % "foo").encoding.name) end def test_str_lt @@ -791,29 +795,34 @@ class TestM17N < Test::Unit::TestCase assert_equal(nil, u("\xc2\xa1\xc2\xa2\xc2\xa3")[u("\xa1\xc2")]) assert_raise(ArgumentError) { u("\xc2\xa1\xc2\xa2\xc2\xa3")[a("\xa1\xc2")] } + assert_nil(e("\xa1\xa2\xa3\xa4")[e("\xa2\xa3")]) + end + + def test_aset + s = e("\xa3\xb0\xa3\xb1\xa3\xb2\xa3\xb3\xa3\xb4") + assert_raise(ArgumentError){s["\xb0\xa3"] = "foo"} end def test_str_center - assert_encoding("EUC-JP", "a".center(5, "\xa1\xa2".force_encoding("euc-jp")).encoding) + assert_encoding("EUC-JP", "a".center(5, e("\xa1\xa2")).encoding) + assert_encoding("EUC-JP", e("\xa3\xb0").center(10).encoding) end def test_squeeze - s = "\xa3\xb0\xa3\xb1\xa3\xb1\xa3\xb3\xa3\xb4".force_encoding("euc-jp") - assert_equal("\xa3\xb0\xa3\xb1\xa3\xb3\xa3\xb4".force_encoding("euc-jp"), s.squeeze) + s = e("\xa3\xb0\xa3\xb1\xa3\xb1\xa3\xb3\xa3\xb4") + assert_equal(e("\xa3\xb0\xa3\xb1\xa3\xb3\xa3\xb4"), s.squeeze) end def test_tr - s = "\x81\x41".force_encoding("shift_jis") + s = s("\x81\x41") assert_equal(s.tr("A", "B"), s) assert_equal(s.tr_s("A", "B"), s) assert_nothing_raised { - "a".force_encoding("ASCII-8BIT").tr("a".force_encoding("ASCII-8BIT"), "a".force_encoding("EUC-JP")) + "a".force_encoding("ASCII-8BIT").tr(a("a"), a("a")) } - assert_equal("\xA1\xA1".force_encoding("EUC-JP"), - "a".force_encoding("ASCII-8BIT").tr("a".force_encoding("ASCII-8BIT"), "\xA1\xA1".force_encoding("EUC-JP"))) - + assert_equal(e("\xA1\xA1"), a("a").tr(a("a"), e("\xA1\xA1"))) end def test_tr_s @@ -821,6 +830,40 @@ class TestM17N < Test::Unit::TestCase "a".force_encoding("ASCII-8BIT").tr("a".force_encoding("ASCII-8BIT"), "\xA1\xA1".force_encoding("EUC-JP"))) end + def test_count + assert_equal(0, e("\xa1\xa2").count("z")) + s = e("\xa3\xb0\xa3\xb1\xa3\xb2\xa3\xb3\xa3\xb4") + assert_raise(ArgumentError){s.count(a("\xa3\xb0"))} + end + + def test_delete + assert_equal(1, e("\xa1\xa2").delete("z").length) + s = e("\xa3\xb0\xa3\xb1\xa3\xb2\xa3\xb3\xa3\xb4") + assert_raise(ArgumentError){s.delete(a("\xa3\xb2"))} + end + + def test_include? + assert_equal(false, e("\xa1\xa2\xa3\xa4").include?(e("\xa3"))) + s = e("\xa3\xb0\xa3\xb1\xa3\xb2\xa3\xb3\xa3\xb4") + assert_equal(false, s.include?(e("\xb0\xa3"))) + end + + def test_index + s = e("\xa3\xb0\xa3\xb1\xa3\xb2\xa3\xb3\xa3\xb4") + assert_nil(s.index(e("\xb3\xa3"))) + assert_nil(e("\xa1\xa2\xa3\xa4").index(e("\xa3"))) + assert_nil(e("\xa1\xa2\xa3\xa4").rindex(e("\xa3"))) + s = e("\xa3\xb0\xa3\xb1\xa3\xb2\xa3\xb3\xa3\xb4") + assert_raise(ArgumentError){s.rindex(a("\xb1\xa3"))} + end + + def test_next + s1 = e("\xa1\xa1") + s2 = s1.dup + (94*94+94).times { s2.next! } + assert_not_equal(s1, s2) + end + def test_sub s = "abc".sub(/b/, "\xa1\xa1".force_encoding("euc-jp")) assert_encoding("EUC-JP", s.encoding) @@ -828,6 +871,40 @@ class TestM17N < Test::Unit::TestCase assert_equal(Encoding::EUC_JP, "\xa4\xa2".force_encoding("euc-jp").gsub(/./, '\&').encoding) end + def test_insert + s = e("\xa3\xb0\xa3\xb1\xa3\xb2\xa3\xb3\xa3\xb4") + assert_equal(e("\xa3\xb0\xa3\xb1\xa3\xb2\xa3\xb3\xa3\xb4a"), s.insert(-1, "a")) + end + + def test_scan + assert_equal(["a"], e("\xa1\xa2a\xa3\xa4").scan(/a/)) + end + + def test_upto + s1 = e("\xa1\xa2") + s2 = s("\xa1\xa2") + assert_raise(ArgumentError){s1.upto(s2) {|x| break }} + end + + def test_casecmp + s1 = s("\x81\x41") + s2 = s("\x81\x61") + assert_not_equal(0, s1.casecmp(s2)) + end + + def test_reverse + assert_equal(u("\xf0jihgfedcba"), u("abcdefghij\xf0").reverse) + end + + def test_plus + assert_raise(ArgumentError){u("\xe3\x81\x82") + a("\xa1")} + end + + def test_chomp + s = e("\xa3\xb0\xa3\xb1\xa3\xb2\xa3\xb3\xa3\xb4") + assert_raise(ArgumentError){s.chomp(s("\xa3\xb4"))} + end + def test_gsub s = 'abc' s.ascii_only? @@ -844,14 +921,21 @@ class TestM17N < Test::Unit::TestCase "\xc2\xa1".force_encoding("utf-8") } } + s = e("\xa3\xb0\xa3\xb1\xa3\xb2\xa3\xb3\xa3\xb4") + assert_equal(e("\xa3\xb0z\xa3\xb2\xa3\xb3\xa3\xb4"), s.gsub(/\xa3\xb1/e, "z")) end def test_end_with - s1 = "\x81\x40".force_encoding("sjis") + s1 = s("\x81\x40") s2 = "@" assert_equal(false, s1.end_with?(s2), "#{encdump s1}.end_with?(#{encdump s2})") end + def test_each_line + s = e("\xa3\xb0\xa3\xb1\xa3\xb2\xa3\xb3\xa3\xb4") + assert_raise(ArgumentError){s.each_line(a("\xa3\xb1")) {|l| }} + end + def test_each_char a = [e("\xa4\xa2"), "b", e("\xa4\xa4"), "c"] s = "\xa4\xa2b\xa4\xa4c".force_encoding("euc-jp") @@ -860,6 +944,13 @@ class TestM17N < Test::Unit::TestCase def test_regexp_match assert_equal([0,0], //.match("\xa1\xa1".force_encoding("euc-jp"),-1).offset(0)) + assert_equal(0, // =~ :a) + end + + def test_split + assert_equal(e("\xa1\xa2\xa1\xa3").split(//), + [e("\xa1\xa2"), e("\xa1\xa3")], + '[ruby-dev:32452]') end def test_nonascii_method_name |