3fe679e259e3b88907760cf02de64174f8d6b778
[chise/ruby.git] / t / tc_db.rb
1 #!/usr/bin/env ruby
2 # by eto 2003-0112
3
4 require 'test/unit'
5 $LOAD_PATH << '../src'
6 require 'chise'
7 include CHISE
8
9 class TC_DB < Test::Unit::TestCase
10   def setup
11     @cdb = CharDB.instance
12     @sdb = CodesysDB.instance
13   end
14   def test_db
15     assert_equal("()+!", DB.unix_to_win("<>*?"))
16     assert_equal("<>*?", DB.win_to_unix("()+!"))
17   end
18   def test_each_db(db)
19     assert_instance_of(Array, db.keys)
20   end
21   def test_make_db(db)
22     h = {'a' => 1, 'b' => 2, 'c' => 3}
23     db.remove_db('test-db') #まず最初に消しておく
24     assert_not_nil(db.make_db('test-db', h))
25     assert_not_nil(db.open_db('test-db'))
26     assert_equal(1, db.get('test-db', 'a'))
27     assert_equal(2, db.get('test-db', 'b'))
28     assert_equal(3, db.get('test-db', 'c'))
29     db.remove_db('test-db') #最後にまた消しておく
30   end
31   def test_dbs
32     test_each_db(@cdb)
33     test_each_db(@sdb)
34 #    test_make_db(@cdb)
35 #    test_make_db(@sdb)
36   end
37   def test_db_put
38     char = "字".char
39     char.put_char_attribute('test-attribute', 'test')
40     assert_equal('test', char.test_attribute)
41   end
42 end
43
44 class TC_Codesys < Test::Unit::TestCase
45   def setup
46     @db = CodesysDB.instance
47   end
48   def nu_test_db_length
49     assert_equal(6287, @db.get('=jis-x0208').keys.length, "keys")
50     assert_equal(590,  @db.get('japanese-jisx0208').keys.length, "keys")
51     assert_equal(499,  @db.get('japanese-jisx0208-1978').keys.length, "keys")
52     assert_equal(593,  @db.get('japanese-jisx0208-1990').keys.length, "keys")
53     assert_equal(6067, @db.get('japanese-jisx0212').keys.length, "keys")
54     assert_equal(1697, @db.get('japanese-jisx0213-1').keys.length, "keys")
55     assert_equal(2345, @db.get('japanese-jisx0213-2').keys.length, "keys")
56     assert_equal(4270, @db.get('ucs-jis').keys.length, "keys")
57   end
58   def test_db
59     keys = @db.keys
60     assert_instance_of(Array, @db.keys, "db.keys")
61     db = @db.get('ascii')
62     assert_equal(128, db.keys.length, "can get keys")
63     assert_equal(63,   @db.get('katakana-jisx0201').keys.length, "keys")
64     assert_equal(94,   @db.get('latin-jisx0201').keys.length, "keys")
65
66     counter = 0
67     @db.each('=jis-x0208'){|k, v| #引数のCodesysデータベースのそれぞれに対して実行する
68       er0 = sprintf("&J90-%04X;", k)
69       er1 = Character.new(v).to_er
70       counter += 1; break if 10 < counter
71     }
72   end
73   def test_jis
74     db = CodesysDB.instance
75     codesys = db.get_codesys('ascii')
76     char = codesys.get(65)
77     assert_equal("A", char.to_s)
78     assert_equal(128, codesys.keys.length)
79     ks = codesys.keys
80
81     codesys = db.get_codesys('japanese-jisx0208-1990')
82     ks = codesys.keys.sort #とすることによって、JISX0208 1990の集合全部のkeysが得られる
83 #    assert_equal(6880, ks.length)
84     assert_equal(8481, ks.first)
85     assert_equal(29734, ks.last)
86     char = codesys.get(15226) #"字"
87     assert_equal("字", char.to_s)
88
89     assert_equal("亜", codesys.get(12321))
90     jis = "亜".char.japanese_jisx0208_1990
91     assert_equal("亜", codesys.get(jis))
92     assert_equal("亜", sprintf("&J90-%04X;", jis).de_er)
93   end
94 end
95
96 #----------------------------------------------------------------------end.