update.
[chise/ruby.git] / test / test-char.rb
1 #!/usr/bin/env ruby
2 # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
3
4 require "common"
5
6 class TestCharacter < Test::Unit::TestCase
7   def test_equality
8     c1 = "字".char # flyweight pattern
9     c2 = CHISE::Character.get("?字")
10     assert_equal(c1, c2) # equal
11     assert_same(c1, c2)  # same instance
12     c3 = CHISE::Character.new(0x5b57)
13     assert_not_equal(c1, c3) # not equal
14     assert_not_same(c1, c3)  # not same instance
15     assert_equal(c1.char_id, c3.char_id)
16   end
17
18   def test_char
19     char = "字".char
20     assert_equal(23383, char["=ucs"])
21     assert_equal(23383, char["ucs"])
22     assert_equal(23383, char.ucs)
23     assert_equal(22358, char.gb2312)
24     assert_equal(6,     char.total_strokes)
25     assert_equal(3,     char.ideographic_strokes)
26     assert_equal(39,    char.ideographic_radical)
27     assert_equal(nil,   char.nosuchfeature)
28     assert_raise(RuntimeError){ char.nosuchmethod(0) }
29   end
30
31   def test_each
32     "字".each_feature {|f, v|
33       #qp f, v
34       assert_instance_of(String, f)
35     }
36
37     h = "字".hash_feature
38     assert_instance_of(Hash, h)
39   end
40
41   def test_bignum
42     char = CHISE::Character.get(1644203214)
43     assert_equal("\375\242\200\210\263\216",    char.to_s)
44   end
45
46   def test_latin
47     char = "A".char
48     assert_equal(65, char.ascii)
49     assert_equal(65, char.ucs)
50     assert_equal(65, char.latin_jisx0201)
51     assert_equal(65, char.latin_viscii)
52     assert_equal("L", char.bidi_category)
53     assert_equal("LATIN CAPITAL LETTER A", char.name)
54   end
55
56   def test_to_er
57     #assert_equal("&J90-3B7A;", "字".char.to_er)
58     assert_equal("&#x5b57;",    "字".char.to_er)
59     assert_equal("&#x5b57;",    "&M-06942;".de_er.char.to_er)
60     assert_equal("&#x2166b;",   "&M-06000;".de_er.char.to_er)
61   end
62
63   def test_alias
64     assert_equal("DIGIT ONE", "1".name)
65     assert_equal("DIGIT ONE", "1".char.name)
66     assert_equal("DIGIT ONE", "1".char["name"])
67     #assert_equal("(((name . \"FULLWIDTH DIGIT ONE\") (=ucs . 65297)))", "1".char["->fullwidth"])
68     assert_equal("(((name . \"FULLWIDTH DIGIT ONE\") (=ucs . 65297)))", "1".to_fullwidth)
69     assert_equal("(((name . \"DIGIT ONE\") (=ucs . 49)))", "1".char["<-fullwidth"])
70     assert_equal("(((name . \"DIGIT ONE\") (=ucs . 49)))", "1".from_fullwidth)
71 #   assert_equal(0xfa55, "突".map_ucs_at_jis)
72 #   assert_equal(0xfa55, "突".char["=>ucs@jis"])
73   end
74
75   def test_put
76     char = "字".char
77     #qp char.test_feature
78     char.test_feature = "test1"
79     assert_equal("test1", char.test_feature)
80     #qp char.test_feature
81     char.test_feature = "test2"
82     assert_equal("test2", char.test_feature)
83   end
84 end