87e3c7662bc07323084d2f2fe15b1cd33b4c2921
[chise/ruby.git] / test / test-string.rb
1 #!/usr/bin/env ruby
2 # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
3
4 require "common"
5
6 class TestString < Test::Unit::TestCase
7   def test_string
8     # test_utf8
9     assert_equal(true,  "字".is_a_utf8?)
10     assert_equal(false, "字字".is_a_utf8?)
11     assert_raises(RuntimeError){ "字字".char }
12     assert_raises(RuntimeError){ "字字".ucs }
13
14     # test_feature
15     assert_equal(25991, "文".ucs)
16     assert_equal(23383, "字".ucs)
17   end
18
19   def test_er
20     assert_equal("字", CHISE::Character.get("&J90-3B7A;").to_s)
21     assert_equal("字", "字".de_er) # no effect
22     assert_equal("字", "&J90-3B7A;".de_er)
23     assert_equal("文字列", "文&J90-3B7A;列".de_er)
24     assert_equal("文字列", "文&M-06942;列".de_er)
25     assert_equal("文字列", "文&MCS-00005B57;列".de_er)
26     assert_equal("文字列", "文&U-5B57;列".de_er)
27     assert_equal("文字列", "文&U+5B57;列".de_er)
28     assert_raises(RuntimeError){ "文&nosucher;列".de_er }
29   end
30
31   def test_characters
32     @str = "文字列"
33     assert_equal(["文","字","列"], @str.to_a)
34     ar = []
35     @str.each_char {|char| ar << char }
36     assert_equal(["文","字","列"], ar)
37   end
38 end