From 24df07c00baaa1e7750aae58657432c33253459e Mon Sep 17 00:00:00 2001 From: eto Date: Thu, 10 Jun 2004 08:51:08 +0000 Subject: [PATCH] i --- chise/db.rb | 16 +-- chise/util.rb | 20 +++ test/org/org-test-char.rb | 163 ++++++++++++++++++++++ test/org/org-test-db.rb | 179 ++++++++++++++++++++++++ test/org/org-test-ids.rb | 298 ++++++++++++++++++++++++++++++++++++++++ test/org/org-test-kage.rb | 39 ++++++ test/org/org-test-kanjilist.rb | 34 +++++ test/org/org-test-network.rb | 22 +++ test/org/org-test-str.rb | 99 +++++++++++++ test/test-char.rb | 163 ---------------------- test/test-ids.rb | 298 ---------------------------------------- test/test-kage.rb | 38 ----- test/test-kanjilist.rb | 34 ----- test/test-network.rb | 22 --- test/test-str.rb | 99 ------------- tools/.cvsignore | 1 + tools/make-chisedb-tarball.rb | 38 +++++ tools/mkdbtarball.rb | 35 ----- 18 files changed, 894 insertions(+), 704 deletions(-) create mode 100644 chise/util.rb create mode 100755 test/org/org-test-char.rb create mode 100755 test/org/org-test-db.rb create mode 100755 test/org/org-test-ids.rb create mode 100755 test/org/org-test-kage.rb create mode 100755 test/org/org-test-kanjilist.rb create mode 100755 test/org/org-test-network.rb create mode 100755 test/org/org-test-str.rb delete mode 100755 test/test-char.rb delete mode 100755 test/test-ids.rb delete mode 100755 test/test-kage.rb delete mode 100755 test/test-kanjilist.rb delete mode 100755 test/test-network.rb delete mode 100755 test/test-str.rb create mode 100644 tools/.cvsignore create mode 100755 tools/make-chisedb-tarball.rb delete mode 100755 tools/mkdbtarball.rb diff --git a/chise/db.rb b/chise/db.rb index 71716c5..9785ae2 100755 --- a/chise/db.rb +++ b/chise/db.rb @@ -5,6 +5,7 @@ require "bdb" require "chise/config" require "chise/rbchise" require "chise/management" +require "chise/util" module CHISE @@ -65,21 +66,6 @@ module CHISE class DB # abstract class for DataBase # translate file name for deal with Windows file system. - def self.unix_to_win(unix_path) - win = unix_path.gsub(//, ")") - win = win.gsub(/\*/, "+") - win = win.gsub(/\?/, "!") - win - end - - def self.win_to_unix(win_path) - unix = win_path.gsub(/\)/, ">") - unix = unix.gsub(/\(/, "<") - unix = unix.gsub(/\!/, "?") - unix = unix.gsub(/\+/, "*") - unix - end def get_filename(t) return @pre + DB.unix_to_win(t) + @post if CHISE.windows? diff --git a/chise/util.rb b/chise/util.rb new file mode 100644 index 0000000..b8e2918 --- /dev/null +++ b/chise/util.rb @@ -0,0 +1,20 @@ +# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved. + +module CHISE + def unix_to_win(unix_path) + win = unix_path.gsub(//, ")") + win = win.gsub(/\*/, "+") + win = win.gsub(/\?/, "!") + win + end + + def win_to_unix(win_path) + unix = win_path.gsub(/\)/, ">") + unix = unix.gsub(/\(/, "<") + unix = unix.gsub(/\!/, "?") + unix = unix.gsub(/\+/, "*") + unix + end + module_function :unix_to_win, :win_to_unix +end diff --git a/test/org/org-test-char.rb b/test/org/org-test-char.rb new file mode 100755 index 0000000..fbf1aa3 --- /dev/null +++ b/test/org/org-test-char.rb @@ -0,0 +1,163 @@ +#!/usr/bin/env ruby +# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved. +# by eto 2003-0112 + +require "common" + +class TestCharacter < Test::Unit::TestCase + def setup() + @char = CHISE::Character.get("字") #UTF8で与えること + end + + def test_char(char) +# assert_equal(6, char.get_char_attribute("total_strokes"), "get total strokes by XEmacs UTF-2000 like method") + assert_equal(6, char["total_strokes"], "get total strokes by Hash like method") if char.is_a? CHISE::Character + assert_equal(6, char.total_strokes, "get total strokes by method") + assert_equal(23383, char.ucs, "translate to ucs") + assert_equal(22358, char.gb2312, "get character code in chinese GB2312") + assert_equal(1777, char.shinjigen_2, "get shinjigen 2") + assert_equal(3, char.ideographic_strokes, "get") + assert_equal(39, char.ideographic_radical, "get") + end + + def test_chars + test_char(CHISE::Character.get("字")) + test_char(CHISE::Character.new("字")) + test_char("字".char) + test_char("字") + end + +# def test_create +# assert_equal(23383, CHISE::Character.parse_char_id("字")) +# end + + def test_put_attributes + @char.put_char_attribute("test_attribute", "test") + assert_equal("test", @char.get_char_attribute("test_attribute"), "put, get") + @char["test_attribute"] = "test" + assert_equal("test", @char["test_attribute"], "[]=, []") + end + + def test_method + assert_instance_of(Hash, @char.char_attribute_alist, "returns Hash") + assert_instance_of(Hash, @char.alist, ".alist returns Hash") + assert_instance_of(Array, @char.char_attribute_list, "returns Array") + assert_instance_of(Array, @char.list, ".list returns Array") + assert_instance_of(String, @char.inspect) + end + + def test_er + assert_equal(@char, CHISE::Character.get("&J90-3B7A;"), "jisx0208") #まだ継承関係を実装していない。 +# assert_equal("&J90-3B7A;", @char.to_er, "jisx0208") + assert_equal(@char, CHISE::Character.get("&MCS-00005B57;"), "mcs") + assert_equal(@char, CHISE::Character.get("&M-06942;"), "ideograph-daikanwa, Morohashi") + end + + def test_latin + char = CHISE::Character.get("A") + assert_equal(65, char.ascii, "ascii") + assert_equal(char.bidi_category, "L", "bidi") + assert_equal(char.name, "LATIN CAPITAL LETTER A", "name") + assert_equal(65, char.ucs, "ucs") + assert_equal(char.latin_jisx0201, 65, "jisx0201") + assert_equal(char.latin_viscii, 65, "viscii") #って何? +#->fullwidth: (((name . "FULLWIDTH LATIN CAPITAL LETTER A") (ucs . 65313))) +#->lowercase: (((name . "LATIN SMALL LETTER A") (ucs . 97))) +#general-category: (letter uppercase) +#このへんのS式の展開が必要なものは、また後程扱うべし。 + end + + def test_ids + char = CHISE::Character.get("â¿°") + assert_equal("IDEOGRAPHIC DESCRIPTION CHARACTER LEFT TO RIGHT", char.name, "ids name") + #assert_equal(char.to_er, "&U+2FF0;", "ids er") + assert_equal(char.to_er, "⿰", "ids er") + assert_equal(char.bidi_category, "ON", "ids bidi") + end + + def test_jis + char = CHISE::Character.get("逢") + assert_instance_of(String, char.get_attributes) + char = CHISE::Character.get("å­¦") + assert_instance_of(String, char.get_attributes) + end + + def test_flyweight + char1 = CHISE::Character.new("字") + char2 = CHISE::Character.new("字") #.newで生成した場合は別々のinstanceになるのだ + assert_equal(char1, char2) #==ではある + assert_not_same(char1, char2) #equal?かというと違う + + cf = CHISE::CharacterFactory.instance + char1 = cf.get("字") + char2 = cf.get("字") + assert_equal(char1, char2, "factory") #==である + assert_same(char1, char2, "factory") #かつ同じinstanceであることが保証される + + char1 = CHISE::Character.get("字") #Character.newの代りにCharacter.getを使うとCharacterFactoryを使ったのと同じ効果がある。 + char2 = CHISE::Character.get("字") + assert_equal(char1, char2) #==である + assert_same(char1, char2) #かつ同じinstanceであることが保証される + end + + def p_er(er) + p er.de_er.char.inspect_all + end + + def nu_test_has_attribute + assert("&J90-4833;".de_er.char.has_attribute?) #罪 + assert(! "&MCS-00E06E9B;;".de_er.char.has_attribute?) #罪のisolated character, attributeを持ってない + assert("&C1-602E;".de_er.char.has_attribute?) #渡 + assert("&J90-454F;".de_er.char.has_attribute?) #渡 + p_er("&C1-602E;") #渡 + p_er("&J90-454F;") + p_er("&J83-4D63;") #翼 + p_er("&J90-4D63;") + p_er("&J83-3958;") #è³¼ + p_er("&J90-3958;") + end + + def test_read_ucs + assert_equal("字", "&U5B57;".de_er) + assert_equal("字", "&U-5B57;".de_er) + assert_equal("字", "&U+5B57;".de_er) + assert_equal("字", "字".de_er) + end + + def test_alias + assert_raises(NameError, message=""){ + t = "字字".ucs + } + assert_equal(23383, "字".ucs) + assert_equal(0x5B57, "字".ucs) + assert_equal(0x5B57, @char.ucs) + + assert_equal(0xfa55, "突".char["=>ucs@jis"]) + assert_equal(0xfa55, "突".map_ucs_at_jis) + + char1 = CHISE::Character.get("23383") + char2 = CHISE::Character.get(23383) + assert_equal(char1, char2) + + char1 = CHISE::Character.get("2") + char2 = CHISE::Character.get(2) + assert_not_equal(char1, char2) + + assert_equal("(((name . \"FULLWIDTH DIGIT ONE\") (=ucs . 65297)))", "1".char["->fullwidth"]) + assert_equal("(((name . \"FULLWIDTH DIGIT ONE\") (=ucs . 65297)))", "1".char.to_fullwidth) + assert_equal("(((name . \"DIGIT ONE\") (=ucs . 49)))", "1".char["<-fullwidth"]) + assert_equal("(((name . \"DIGIT ONE\") (=ucs . 49)))", "1".char.from_fullwidth) + end +end + +#===== PRINT_ALL [字] MCS-00005B57 &J90-3B7A; ===== +#chinese-gb2312: 0x5756 +#chinese-isoir165: 0x5756 +#korean-ksc5601: 0x6D2E +#ucs: 0x5B57 +#chinese-cns11643-1: 0x4773 +#chinese-big5: 0xA672 + +# test_print(CHISE::Character.get("&CDP-8B42;")) +# test_print(CHISE::Character.get("&I-CDP-8AF6;")) +#===== PRINT_ALL [舛] MCS-00ECA524 &K0-743F; ===== diff --git a/test/org/org-test-db.rb b/test/org/org-test-db.rb new file mode 100755 index 0000000..5b1bc98 --- /dev/null +++ b/test/org/org-test-db.rb @@ -0,0 +1,179 @@ +#!/usr/bin/env ruby +# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved. +# This file is in SJIS charset. Japanese Character -> Š¿Žš. + +require "common" + +class TestDataBase < Test::Unit::TestCase + def setup + @cdb = CHISE::CharDB.instance + @sdb = CHISE::CodesysDB.instance + end + + def test_db + assert_equal("()+!", CHISE::DB.unix_to_win("<>*?")) + assert_equal("<>*?", CHISE::DB.win_to_unix("()+!")) + end + + def test_each_db(db) + assert_instance_of(Array, db.keys) + end + + def test_make_db(db) + h = {"a" => 1, "b" => 2, "c" => 3} + db.remove_db("test-db") #‚Ü‚¸Å‰‚ɏÁ‚µ‚Ä‚¨‚­ + assert_not_nil(db.make_db("test-db", h)) + assert_not_nil(db.open_db("test-db")) + assert_equal(1, db.get("test-db", "a")) + assert_equal(2, db.get("test-db", "b")) + assert_equal(3, db.get("test-db", "c")) + db.remove_db("test-db") #ÅŒã‚É‚Ü‚½Á‚µ‚Ä‚¨‚­ + end + + def test_dbs + test_each_db(@cdb) + test_each_db(@sdb) +# test_make_db(@cdb) +# test_make_db(@sdb) + end + + def test_db_put + char = "Žš".char + char.put_char_attribute("test-attribute", "test") + assert_equal("test", char.test_attribute) + end + +end + +class TestCodesys < Test::Unit::TestCase + def setup + @db = CHISE::CodesysDB.instance + end + + def test_dummy + end + + def nu_test_db_length + assert_equal(6287, @db.get("=jis-x0208").keys.length, "keys") + assert_equal(590, @db.get("japanese-jisx0208").keys.length, "keys") + assert_equal(499, @db.get("japanese-jisx0208-1978").keys.length, "keys") + assert_equal(593, @db.get("japanese-jisx0208-1990").keys.length, "keys") + assert_equal(6067, @db.get("japanese-jisx0212").keys.length, "keys") + assert_equal(1697, @db.get("japanese-jisx0213-1").keys.length, "keys") + assert_equal(2345, @db.get("japanese-jisx0213-2").keys.length, "keys") + assert_equal(4270, @db.get("ucs-jis").keys.length, "keys") + end + + def nutest_db + keys = @db.keys + assert_instance_of(Array, @db.keys, "db.keys") + db = @db.get("ascii") + assert_equal(128, db.keys.length, "can get keys") + assert_equal(63, @db.get("katakana-jisx0201").keys.length, "keys") + assert_equal(94, @db.get("latin-jisx0201").keys.length, "keys") + + counter = 0 + @db.each("=jis-x0208"){|k, v| #ˆø”‚ÌCodesysƒf[ƒ^ƒx[ƒX‚Ì‚»‚ꂼ‚ê‚ɑ΂µ‚ÄŽÀs‚·‚é + er0 = sprintf("&J90-%04X;", k) + er1 = CHISE::Character.new(v).to_er + counter += 1; break if 10 < counter + } + end + + def nutest_ascii + db = CHISE::CodesysDB.instance + codesys = db.get_codesys("ascii") + char = codesys.get(65) + assert_equal("A", char.to_s) + assert_equal(128, codesys.keys.length) + ks = codesys.keys + end + + def nutest_jis_codesys + db = CHISE::CodesysDB.instance + codesys = db.get_codesys("=jis-x0208") + ks = codesys.keys.sort #‚Æ‚·‚邱‚Æ‚É‚æ‚Á‚āAJISX0208 1990‚̏W‡‘S•”‚Ìkeys‚ª“¾‚ç‚ê‚é +# assert_equal(6880, ks.length) + assert_equal(8481, ks.first) + assert_equal(29566, ks.last) + char = codesys.get(15226) #"Žš" + assert_equal("Žš".su, char.to_s) + + assert_equal("ˆŸ".su, codesys.get(12321)) + jis = "ˆŸ".su.char.japanese_jisx0208_1990 +# assert_equal("ˆŸ", codesys.get(jis)) +# assert_equal("ˆŸ", sprintf("&J90-%04X;", jis).de_er) + +# codesys = db.get_codesys("japanese-jisx0208-1990") #‹Œ–¼ + codesys = db.get_codesys("=jis-x0208-1990") + assert_equal(8481, ks.first) + assert_equal(29566, ks.last) + end + +end + +class TestCodesys < Test::Unit::TestCase + def setup + @db = CHISE::CodesysDB.instance + end + + def test_dummy + end + + def nu_test_db_length + assert_equal(6287, @db.get("=jis-x0208").keys.length, "keys") + assert_equal(590, @db.get("japanese-jisx0208").keys.length, "keys") + assert_equal(499, @db.get("japanese-jisx0208-1978").keys.length, "keys") + assert_equal(593, @db.get("japanese-jisx0208-1990").keys.length, "keys") + assert_equal(6067, @db.get("japanese-jisx0212").keys.length, "keys") + assert_equal(1697, @db.get("japanese-jisx0213-1").keys.length, "keys") + assert_equal(2345, @db.get("japanese-jisx0213-2").keys.length, "keys") + assert_equal(4270, @db.get("ucs-jis").keys.length, "keys") + end + + def nutest_db + keys = @db.keys + assert_instance_of(Array, @db.keys, "db.keys") + db = @db.get("ascii") + assert_equal(128, db.keys.length, "can get keys") + assert_equal(63, @db.get("katakana-jisx0201").keys.length, "keys") + assert_equal(94, @db.get("latin-jisx0201").keys.length, "keys") + + counter = 0 + @db.each("=jis-x0208"){|k, v| #ˆø”‚ÌCodesysƒf[ƒ^ƒx[ƒX‚Ì‚»‚ꂼ‚ê‚ɑ΂µ‚ÄŽÀs‚·‚é + er0 = sprintf("&J90-%04X;", k) + er1 = CHISE::Character.new(v).to_er + counter += 1; break if 10 < counter + } + end + + def nutest_ascii + db = CHISE::CodesysDB.instance + codesys = db.get_codesys("ascii") + char = codesys.get(65) + assert_equal("A", char.to_s) + assert_equal(128, codesys.keys.length) + ks = codesys.keys + end + + def nutest_jis_codesys + db = CHISE::CodesysDB.instance + codesys = db.get_codesys("=jis-x0208") + ks = codesys.keys.sort #‚Æ‚·‚邱‚Æ‚É‚æ‚Á‚āAJISX0208 1990‚̏W‡‘S•”‚Ìkeys‚ª“¾‚ç‚ê‚é +# assert_equal(6880, ks.length) + assert_equal(8481, ks.first) + assert_equal(29566, ks.last) + char = codesys.get(15226) #"Žš" + assert_equal("Žš".su, char.to_s) + + assert_equal("ˆŸ".su, codesys.get(12321)) + jis = "ˆŸ".su.char.japanese_jisx0208_1990 +# assert_equal("ˆŸ", codesys.get(jis)) +# assert_equal("ˆŸ", sprintf("&J90-%04X;", jis).de_er) + +# codesys = db.get_codesys("japanese-jisx0208-1990") #‹Œ–¼ + codesys = db.get_codesys("=jis-x0208-1990") + assert_equal(8481, ks.first) + assert_equal(29566, ks.last) + end +end diff --git a/test/org/org-test-ids.rb b/test/org/org-test-ids.rb new file mode 100755 index 0000000..d10f28b --- /dev/null +++ b/test/org/org-test-ids.rb @@ -0,0 +1,298 @@ +#!/usr/bin/env ruby +# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved. +# by eto 2003-0112 + +require "common" + +class TestIDS < Test::Unit::TestCase + def setup + end + + def test_ids + char = "榊".char + assert_equal("⿰木神", char.ids) + assert_equal("⿰木神", char.decompose) + str = "榊" + assert_equal("⿰木神", str.char.ids) + assert_equal("⿰木神", str.decompose) + assert_equal("⿰木⿰⺭申", str.decompose.decompose) + assert_equal("⿰木神", str.decompose!) + assert_equal("⿰木⿰⺭申", str.decompose!) + str = "榊" + assert_equal("⿰木⿰⺭申", str.decompose_all) + assert_equal("⿰木⿰⺭申", str.decompose_all!) + assert_equal("⿰木⿰⺭申", str) + #今はまだcomposeはできない。 + + de = "ç´°".decompose + assert_match(/田$/, de) + assert_equal(3, de.char_length) + de = "&JX2-7577;".de_er.decompose + de = "&CDP-8B60;".de_er.decompose + assert_equal(1, de.char_length) + de = "&JX2-217E;".de_er.decompose + assert_match(/^â¿°/, de) + assert_equal(3, de.char_length) + assert_equal(6, de.decompose!.char_length) +# assert_equal(6, de.decompose!.char_length) + + assert("⿸".char.is_ids?) + assert(! "木".char.is_ids?) + assert_equal(2, "â¿°".char.ids_operator_argc) + assert_equal(2, "&U+2FF0;".de_er.char.ids_operator_argc) + assert_equal(2, "&U+2FF1;".de_er.char.ids_operator_argc) + assert_equal(3, "&U+2FF2;".de_er.char.ids_operator_argc) + assert_equal(3, "&U+2FF3;".de_er.char.ids_operator_argc) + + assert_equal("â¿°", "&U+2FF0;".de_er.to_s) + assert("&U+2FF0;".de_er.char.is_ids?) + assert("&U+2FFF;".de_er.char.is_ids?) + #assert_match(/U\+2FF0/, "&U+2FF0;".de_er.char.inspect_x) + assert_match(/IDEOGRAPHIC DESCRIPTION CHARACTER LEFT TO RIGHT/, "&U+2FF0;".de_er.char.inspect_all) + (0x2FF0..0x2FFB).each {|i| + assert_match(/IDEOGRAPHIC DESCRIPTION CHARACTER/, CHISE::Character.new(i).name) + } + + assert_match(/LEFT TO RIGHT/, "&U+2FF0;".de_er.char.name) #∫ + assert_match(/ABOVE TO BELOW/, "&U+2FF1;".de_er.char.name) #∨ + assert_match(/LEFT TO MIDDLE AND RIGHT/, "&U+2FF2;".de_er.char.name) #∬ + assert_match(/ABOVE TO MIDDLE AND BELOW/, "&U+2FF3;".de_er.char.name) #∀ + assert_match(/FULL SURROUND/, "&U+2FF4;".de_er.char.name) #∃ + assert_match(/SURROUND FROM ABOVE/, "&U+2FF5;".de_er.char.name) #∩ + assert_match(/SURROUND FROM BELOW/, "&U+2FF6;".de_er.char.name) #∪ + assert_match(/SURROUND FROM LEFT/, "&U+2FF7;".de_er.char.name) #⊂ + assert_match(/SURROUND FROM UPPER LEFT/, "&U+2FF8;".de_er.char.name) #√ + assert_match(/SURROUND FROM UPPER RIGHT/, "&U+2FF9;".de_er.char.name) #∂ + assert_match(/SURROUND FROM LOWER LEFT/, "&U+2FFA;".de_er.char.name) #∠ + assert_match(/OVERLAID/, "&U+2FFB;".de_er.char.name) #∵ + end + + def test_tree + assert_equal("[]", CHISE::Tree.new().inspect) + assert_equal("[1]", CHISE::Tree.new().add_leaf(1).inspect) + assert_equal("[1, 2]", CHISE::Tree.new().add_leaf(1).add_leaf(2).inspect) + assert_equal("[[]]", CHISE::Tree.new().add_node.inspect) + assert_equal("[[1]]", CHISE::Tree.new().add_node.add_leaf(1).inspect) + assert_equal("[[1, 2]]", CHISE::Tree.new().add_node.add_leaf(1).add_leaf(2).inspect) + assert_equal("[[1]]", CHISE::Tree.new().add_node.add_leaf(1).end_node.inspect) + assert_equal("[[1], [1]]", CHISE::Tree.new().add_node.add_leaf(1).end_node.add_node.add_leaf(1).end_node.inspect) + + tree = CHISE::Tree.new + assert_equal("[]", tree.inspect) + assert_equal("[1]", tree.add_leaf(1).inspect) + assert_equal(0, tree.depth) + assert_equal("[1, 2]", tree.add_leaf(2).inspect) + assert_equal("[1, 2, []]", tree.add_node.inspect) + assert_equal("[1, 2, [3]]", tree.add_leaf(3).inspect) + assert_equal(1, tree.depth) + assert_equal("[1, 2, [3, 4]]", tree.add_leaf(4).inspect) + assert_equal("[1, 2, [3, 4]]", tree.end_node.inspect) + assert_equal("[1, 2, [3, 4], [5]]", tree.add_node.add_leaf(5).inspect) + assert_equal("[1, 2, [3, 4], [5, [6]]]", tree.add_node.add_leaf(6).inspect) + assert_equal(2, tree.depth) + + tree = CHISE::Tree.new + assert_equal("[[\"+\"]]", tree.add_node("+", 2).inspect) + assert_equal("[[\"+\", 1]]", tree.add_leaf(1).inspect) + assert_equal("unmatch leaves", tree.check_integrity) + assert_equal("[[\"+\", 1, 2]]", tree.add_leaf(2).inspect) + assert_nil(tree.check_integrity) + assert_equal("[[\"+\", 1, 2], 3]", tree.add_leaf(3).inspect) + assert_equal("extra nodes", tree.check_integrity) + + tree = CHISE::Tree.new + assert_equal("[[\"+\"]]", tree.add_node("+", 2).inspect) + assert_equal("unmatch leaves", tree.check_integrity) + assert_equal("[[\"+\", 1]]", tree.add_leaf(1).inspect) + assert_equal("unmatch leaves", tree.check_integrity) + assert_equal("[[\"+\", 1, [\"+\"]]]", tree.add_node("+", 2).inspect) + assert_equal("unmatch leaves", tree.check_integrity) + assert_equal("[[\"+\", 1, [\"+\", 2]]]", tree.add_leaf(2).inspect) + assert_equal("unmatch leaves", tree.check_integrity) + assert_equal("[[\"+\", 1, [\"+\", 2, 3]]]", tree.add_leaf(3).inspect) + assert_nil(tree.check_integrity) + + tree = CHISE::Tree.new + assert_equal("[1]", tree.add_leaf(1).inspect) + assert_nil(tree.check_integrity) + assert_equal("[1, 2]", tree.add_leaf(2).inspect) + assert_equal("extra leaves", tree.check_integrity) + end + + def test_ids_tree +# assert_equal("[[<+,U+002B>, , ]]", CHISE::IDS_Tree.new("+AB").inspect) +# assert_equal("[[<+,U+002B>, , ], ]", CHISE::IDS_Tree.new("+ABC").inspect) +# assert_equal("[[<+,U+002B>, , [<+,U+002B>, , ]]]", CHISE::IDS_Tree.new("+A+BC").inspect) +# assert_equal("[[<+,U+002B>, , [<+,U+002B>, , ]], ]", CHISE::IDS_Tree.new("+A+BCD").inspect) + + #assert_equal("[<榊,U+698A>]", CHISE::IDS_Tree.new("榊").inspect) +# assert_equal("[[<â¿°,U+2FF0>, <木,J90-4C5A>, <神,J90-3F40>]]", CHISE::IDS_Tree.new("⿰木神").inspect) + assert_equal(1, CHISE::IDS_Tree.new("⿰木神").depth) +# assert_equal("[[<â¿°,U+2FF0>, <木,J90-4C5A>, [<â¿°,U+2FF0>, <⺭,CDP-8B70>, <申,J90-3F3D>]]]", CHISE::IDS_Tree.new("⿰木⿰⺭申").inspect) + assert_equal(2, CHISE::IDS_Tree.new("⿰木⿰⺭申").depth) + assert_equal("unmatch leaves", CHISE::IDS_Tree.new("⿰木").check_integrity) + assert_nil(CHISE::IDS_Tree.new("⿰木神").check_integrity) + assert_equal("unmatch leaves", CHISE::IDS_Tree.new("⿰木⿰申").check_integrity) + assert_nil(CHISE::IDS_Tree.new("⿰木⿰⺭申").check_integrity) + assert_equal("extra nodes", CHISE::IDS_Tree.new("⿰木⿰⺭申申").check_integrity) + assert_nil(CHISE::IDS_Tree.new("榊").check_integrity) + assert_equal("extra leaves", CHISE::IDS_Tree.new("榊榊").check_integrity) + + assert_equal(3, "⿳".char.ids_operator_argc) + assert_equal("⿳士冖匕", "壱".char.ids) + assert_equal(3, "壱".char.ids.char.ids_operator_argc) + assert_nil(CHISE::IDS_Tree.new("⿳士冖匕").check_integrity) + assert_equal("unmatch leaves", CHISE::IDS_Tree.new("⿳士冖").check_integrity) + assert_equal("extra nodes", CHISE::IDS_Tree.new("⿳士冖匕匕").check_integrity) + + assert_equal("contains ques", CHISE::IDS_Tree.new("⿳士冖?").check_integrity) + end + + def test_tree_depth + assert_equal(1, CHISE::IDS_Tree.new("林".decompose).depth) +# assert_equal("["⿰木木"]", CHISE::IDS_Tree.new("林".decompose).nodes.inspect) +# assert_equal("[]", CHISE::IDS_Tree.new("林".decompose).sub_nodes.inspect) + assert_equal(2, CHISE::IDS_Tree.new("榊".decompose_all).depth) +# assert_equal("["⿰木⿰⺭申", "⿰⺭申"]", CHISE::IDS_Tree.new("榊".decompose_all).nodes.inspect) +# assert_equal("["⿰⺭申"]", CHISE::IDS_Tree.new("榊".decompose_all).sub_nodes.inspect) + +# assert_equal(3, CHISE::IDS_Tree.new("焔".decompose_all).depth) +# assert_equal(3, CHISE::IDS_Tree.new("焔".decompose_all).nodes.length) +# assert_equal(2, CHISE::IDS_Tree.new("焔".decompose_all).sub_nodes.length) + + assert_equal(2, CHISE::IDS_Tree.new("屡".decompose_all).depth) + assert_equal("⿸尸娄", "⿸尸⿱米女".aggregate) + assert_equal(3, CHISE::IDS_Tree.new("醤".decompose_all).depth) + end + + def test_compose_exact #正確に一致するIDSを検知する + assert_equal("榊", "榊".decompose.compose) + assert_equal("壱", "壱".decompose.compose) + assert_equal("⿰木木", "林".decompose) + assert_equal("林", "⿰木木".compose) + assert_equal("林", "林".decompose.compose) + assert_equal("⿰木木", "⿰木木".compose.decompose) + assert_equal("林".ucs, "⿰木木".compose.ucs) + end + + def test_idc_shortcut + assert_equal(IDC_LR, "林".decompose.first_char) + assert_equal(IDC_LR+"木木", "林".decompose) + + assert_equal(IDC_AB, "森".decompose.first_char) + assert_equal(IDC_AB+"木林", "森".decompose) + assert_equal(IDC_AB+"火火", "炎".decompose) + + assert_equal(IDC_LMR, "班".decompose.first_char) + assert_equal(IDC_LMR+"å½³"+IDC_AB+"山王"+"攵", "å¾´".decompose) #meaning? + + assert_equal(IDC_AMB, "é¼»".decompose.first_char) + assert_equal(IDC_AMB+"自田廾", "é¼»".decompose) + assert_equal(IDC_AMB+"士冖匕", "壱".decompose) + assert_equal(IDC_AMB+"穴厶心", "窓".decompose) + assert_equal(IDC_AMB+"丗冖巾", "帯".decompose) + + assert_equal(IDC_FS, "囲".decompose.first_char) + assert_equal(IDC_FS+"囗井", "囲".decompose) + assert_equal(IDC_FS+"行韋", "衛".decompose) + assert_equal(IDC_FS+"行圭", "街".decompose) + assert_equal(IDC_FS+"行重", "衝".decompose) + assert_equal(IDC_FS+IDC_AB+"一凵田", "画".decompose) + + assert_equal(IDC_FA, "問".decompose.first_char) + assert_equal(IDC_FA+"門口", "問".decompose) + assert_equal(IDC_FA+"門"+IDC_LR+"豆寸", "闘".decompose) + assert_equal(IDC_FA+"戌女", "威".decompose) + assert_equal(IDC_FA+"茂臣", "蔵".decompose) + assert_equal(IDC_FA+"尺旦", "昼".decompose) + assert_equal(IDC_FA+"冂入", "内".decompose) + assert_equal(IDC_FA+"几丶", "凡".decompose) + assert_equal(IDC_FA+"几"+IDC_AB+"丿虫", "風".decompose) + + assert_equal(IDC_FB, "凶".decompose.first_char) + assert_equal(IDC_AB+"æ­¢"+IDC_FB+"凵米", "æ­¯".decompose) + + assert_equal(IDC_FL, "匠".decompose.first_char) + assert_equal(IDC_FL+"匚斤", "匠".decompose) + assert_equal(IDC_FL+"匚矢", "医".decompose) + assert_equal(IDC_FL+"匚若", "匿".decompose) + assert_equal(IDC_FL+"匚儿", "匹".decompose) + + assert_equal(IDC_FUL, "庁".decompose.first_char) + assert_equal(IDC_FUL+"广丁", "庁".decompose) + assert_equal(IDC_FUL+"歹匕", "æ­»".decompose) + assert_equal(IDC_FUL+"尹口", "君".decompose) + assert_equal(IDC_FUL+"麻鬼", "魔".decompose) + assert_equal(IDC_FUL+"府肉", "腐".decompose) + assert_equal(IDC_FUL+"麻手", "摩".decompose) + assert_equal(IDC_FUL+"虍思", "慮".decompose) + assert_equal(IDC_FUL+"食口", "倉".decompose) + assert_equal(IDC_AB+"日"+IDC_FUL+"耳又", "最".decompose) + assert_equal(IDC_FUL+"手目", "看".decompose) #meaning + assert_equal(IDC_FUL+"辰口", "唇".decompose) #? + + assert_equal(IDC_FUR, "句".decompose.first_char) + assert_equal(IDC_FUR+"勹口", "句".decompose) + assert_equal(IDC_FUR+"勹丶", "勺".decompose) + assert_equal(IDC_FUR+"勹日", "旬".decompose) + assert_equal(IDC_FUR+"戈廾", "戒".decompose) + assert_equal(IDC_FUR+"弋工", "式".decompose) + assert_equal(IDC_FUR+"刀丿", "刃".decompose) + assert_equal(IDC_FUR+"鳥山", "島".decompose) #meaning + + assert_equal(IDC_FLL, "通".decompose.first_char) + assert_equal(IDC_FLL+"廴聿", "建".decompose) + assert_equal(IDC_FLL+"走戉", "越".decompose) + assert_equal(IDC_FLL+"èµ°å·³", "èµ·".decompose) + assert_equal(IDC_FLL+"走取", "趣".decompose) + assert_equal(IDC_FLL+"走召", "超".decompose) + assert_equal(IDC_FLL+"是頁", "題".decompose) + assert_equal(IDC_FLL+"免力", "勉".decompose) + assert_equal(IDC_FLL+"鬼未", "魅".decompose) + assert_equal(IDC_FLL+"黒犬", "黙".decompose) + + assert_equal(IDC_O, "太".decompose.first_char) + assert_equal(IDC_O+"大丶", "太".decompose) + assert_equal(IDC_O+"衣中", "è¡·".decompose) + assert_equal(IDC_O+"衣里", "裏".decompose) + assert_equal(IDC_O+"勹巳", "包".decompose) + assert_equal(IDC_O+"勹乂", "匁".decompose) + assert_equal(IDC_O+"木日", "東".decompose) + assert_equal(IDC_O+"弍一", "弐".decompose) + assert_equal(IDC_O+"衣保", "褒".decompose) + end + + def test_glyph_decompose + assert_equal("音", "音".decompose) +# assert_equal(IDC_AB+"立日", "音".glyph_decompose) + assert_equal(IDC_FLL, "世".decompose.first_char) + assert_equal("世", "世".glyph_decompose) + end + + def test_find() +# p "日雲".find #"曇" + assert(4 <= "日雲".find .char_length) #"曇" + end + + def test_compose_part() +# p de.compose_ar +# p "神".compose_ar +# p "木".compose_ar.join + end + + def test_aggregate() +# db = IDS_DB.instance +# db.list_aggregate + end + + def test_ids_error() +# p "実".char.inspect_all +# p "実".char.ids +# assert_equal("contains ques", "実".char.ids_error) +# assert_equal("unmatch leaves", "実".char.ids_error) +# p CharDB.instance.get("ascii").keys +# p CharDB.instance.get("no-such-attribute").keys +# p CharDB.instance.get("ids-error").keys + end + +end diff --git a/test/org/org-test-kage.rb b/test/org/org-test-kage.rb new file mode 100755 index 0000000..d476a7b --- /dev/null +++ b/test/org/org-test-kage.rb @@ -0,0 +1,39 @@ +#!/usr/bin/env ruby +# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved. +# kage testcase by eto 2003-0318 + +require "common" +#require "chise/stroke" +#include StrokeFont + +#class TestKage < Test::Unit::TestCase +class TestKage + def setup + @kage = KageFont.new + end + + def test_stroke + end + + def test_kage + char = Character.get(0x4e03) #七 + font = @kage.get(0x4e03) + assert_instance_of(KageGlyph, font) + font.parse + + svg = <<"EOT" + M 50,540 950,255 + M 330,50 330,900 M 330,900 Q 330,950 380,950 M 380,950 840,950 M 840,950 Q 890,950 915,850 +EOT + strokes = KageParser.parse(svg) + #p strokes + end + + def test_path + pr = PathResolver.new + assert_equal([[0, 0, 1000, 1000]], pr.parse("M 0,0 1000,1000")) + assert_equal([[0, 0, 0, 1000], [0, 1000, 1000, 1000]], pr.parse("M 0,0 0,1000 1000,1000")) +# assert_equal([[0, 0, 0.0, 0.0], [0.0, 0.0, 62.5, 437.5], [62.5, 437.5, 250.0, 750.0], [250.0, 750.0, 562.5, 937.5]], pr.parse("M 0,0 Q 0,1000 1000,1000")) + end + +end diff --git a/test/org/org-test-kanjilist.rb b/test/org/org-test-kanjilist.rb new file mode 100755 index 0000000..48c1e6c --- /dev/null +++ b/test/org/org-test-kanjilist.rb @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby +# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved. +# testcase for KanjiNetwork by eto 2003-0227 + +require "common" +require "chise/kanjilist" + +class TestKanjiList < Test::Unit::TestCase + def setup + @kl = CHISE::KanjiList.instance + end + + def test_kyoiku_kanji_list # 範囲指定が複雑なのでtestするべし。 + assert_equal("愛悪圧安暗案以位囲委意易異移胃衣遺医域育一印員因引飲院右宇羽雨運雲営映栄永泳英衛液益駅円園延沿演遠塩央往応横王黄億屋恩温音下化仮何価加可夏家科果歌河火花荷課貨過我画芽賀会解回快改械海灰界絵開階貝外害街各拡格確覚角閣革学楽額割活株寒刊巻完官干幹感慣漢看管簡観間関館丸岸眼岩顔願危喜器基寄希揮机旗期機帰気汽季紀規記貴起技疑義議客逆久休吸宮弓急救求泣球究級給旧牛去居挙許漁魚京供競共協境強教橋胸興郷鏡業局曲極玉勤均禁筋近金銀九句区苦具空君訓群軍郡係兄型形径敬景系経計警軽芸劇激欠決潔穴結血月件健券建憲検権犬研絹県見険験元原厳減源現言限個古呼固己庫戸故湖五午後語誤護交候光公功効厚口向后好孝工幸広康校構港皇紅耕考航行講鉱鋼降高号合刻告国穀黒骨今困根混左差査砂座再最妻才採済災祭細菜裁際在材罪財坂作昨策桜冊刷察札殺雑皿三参山散産算蚕賛酸残仕使司史四士始姉姿子市師志思指支枝止死氏私糸紙至視詞詩試誌資飼歯事似児字寺持時次治磁示耳自辞式識七失室質実舎写射捨社者謝車借尺若弱主取守手種酒首受授樹収周宗就州修拾秋終習衆週集住十従縦重宿祝縮熟出術述春準純順処初所暑署書諸助女序除傷勝商唱将小少承招昭松消焼照省章笑証象賞障 上乗城場常情条状蒸植織職色食信心新森深申真神臣親身進針人仁図垂推水数寸世制勢性成政整星晴正清生盛精聖声製西誠青静税席昔石積績責赤切接折設節説雪絶舌先千宣専川戦泉浅洗染線船選銭前善然全祖素組創倉奏層想操早巣争相窓総草装走送像増臓蔵造側則息束測足速属族続卒存孫尊損村他多太打体対帯待態貸退隊代台大第題宅達谷単担探炭短誕団断暖段男談値知地池置築竹茶着中仲宙忠昼柱注虫著貯丁兆帳庁張朝潮町腸調長頂鳥直賃追痛通低停定底庭弟提程敵的笛適鉄典天展店転点伝田電徒登都努度土党冬刀島投東湯灯当等答糖統討豆頭働動同堂導童道銅得徳特毒独読届内南難二肉日乳入任認熱年念燃納能脳農波派破馬俳拝敗背肺配倍梅買売博白麦箱畑八発判半反板版犯班飯晩番否悲批比皮秘肥費非飛備美鼻必筆百俵標氷票表評病秒品貧不付夫婦富布府父負武部風副復服福腹複仏物分奮粉文聞兵平並閉陛米別変片編辺返便勉弁保歩補墓暮母包報宝放方法訪豊亡忘暴望棒貿防北牧本妹枚毎幕末万満味未密脈民務夢無名命明盟迷鳴綿面模毛木目問門夜野矢役約薬訳油輸優勇友有由遊郵夕予余預幼容曜様洋用羊葉要陽養欲浴翌来落乱卵覧利理裏里陸律率立略流留旅両料良量領力緑林臨輪類令例冷礼歴列練連路労朗老六録論和話", @kl.kyoiku()) + assert_equal("一右雨円王音下火花学気休金九空月犬見五口校左三山四子糸字耳七車手十出女小上森人水正生青石赤先千川早足村大男中虫町天田土二日入年白八百文本名木目夕立力林六", @kl.kyoiku(1)) + assert_equal("引雲遠黄何夏家科歌画会回海絵貝外楽間顔帰汽記牛魚京強教玉近形計元原古戸午後語交光工広考行高合国黒今才作算市思止紙寺時自室社弱首秋春書少場色食心新親図数星晴声西切雪船前組草走多太体台谷知地池竹茶昼朝長鳥通弟店点電冬刀東当答頭同道読南馬買売麦半番父風分聞米歩母方北妹毎明鳴毛門夜野友曜用来理里話", @kl.kyoiku(2)) + assert_equal("一右雨円王音下火花学気休金九空月犬見五口校左三山四子糸字耳七車手十出女小上森人水正生青石赤先千川早足村大男中虫町天田土二日入年白八百文本名木目夕立力林六引雲遠黄何夏家科歌画会回海絵貝外楽間顔帰汽記牛魚京強教玉近形計元原古戸午後語交光工広考行高合国黒今才作算市思止紙寺時自室社弱首秋春書少場色食心新親図数星晴声西切雪船前組草走多太体台谷知地池竹茶昼朝長鳥通弟店点電冬刀東当答頭同道読南馬買売麦半番父風分聞米歩母方北妹毎明鳴毛門夜野友曜用来理里話", @kl.kyoiku(1..2)) + + assert_equal("右雨王音火貝九玉金月犬見口左山子糸耳車手十女人水夕石川早足大竹虫天田土日年白文木目立力六", @kl.kyoiku(1, CHISE::KanjiList::SHOUKEI)) + assert_equal("一二三四五下七小上生中入八本", @kl.kyoiku(1, CHISE::KanjiList::SHIJI)) + assert_equal("円休出森正赤千男町名林", @kl.kyoiku(1, CHISE::KanjiList::KAII)) + assert_equal("花学気空校字青先草村百", @kl.kyoiku(1, CHISE::KanjiList::KEISEI)) + + assert_equal("羽雲夏画回会外角弓牛魚京兄原戸古午工交行高黄才止矢自首心西長鳥弟刀東肉馬米歩母方北万毛門用来", @kl.kyoiku(2, CHISE::KanjiList::SHOUKEI)) + assert_equal("", @kl.kyoiku(2, CHISE::KanjiList::SHIJI)) + assert_equal("科楽岩顔汽教計公谷黒今思春少声雪走多太台直電内売半番父明鳴友里", @kl.kyoiku(2, CHISE::KanjiList::KAII)) + assert_equal("引園遠何家歌海絵活間丸記帰強近形元言後語広光考合国細作算市姉紙寺時室社弱配秋週書場色食新親図数星晴切船線前組体地池茶昼朝通店点冬当答頭同道読南買麦風分聞毎妹夜野曜理話", @kl.kyoiku(2, CHISE::KanjiList::KEISEI)) + + assert_equal("右雨王音火貝九玉金月犬見口左山子糸耳車手十女人水夕石川早足大竹虫天田土日年白文木目立力六羽雲夏画回会外角弓牛魚京兄原戸古午工交行高黄才止矢自首心西長鳥弟刀東肉馬米歩母方北万毛門用来", @kl.kyoiku(1..2, CHISE::KanjiList::SHOUKEI)) + assert_equal("一二三四五下七小上生中入八本", @kl.kyoiku(1..2, CHISE::KanjiList::SHIJI)) + assert_equal("円休出森正赤千男町名林科楽岩顔汽教計公谷黒今思春少声雪走多太台直電内売半番父明鳴友里", @kl.kyoiku(1..2, CHISE::KanjiList::KAII)) + assert_equal("花学気空校字青先草村百引園遠何家歌海絵活間丸記帰強近形元言後語広光考合国細作算市姉紙寺時室社弱配秋週書場色食新親図数星晴切船線前組体地池茶昼朝通店点冬当答頭同道読南買麦風分聞毎妹夜野曜理話", @kl.kyoiku(1..2, CHISE::KanjiList::KEISEI)) + end +end diff --git a/test/org/org-test-network.rb b/test/org/org-test-network.rb new file mode 100755 index 0000000..7578ee8 --- /dev/null +++ b/test/org/org-test-network.rb @@ -0,0 +1,22 @@ +#!/usr/bin/env ruby +# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved. +# testcase for KanjiNetwork by eto 2003-0227 + +require "common" +require "chise/network" + +class Test_KanjiNetwork < Test::Unit::TestCase + def test_network + @kl = CHISE::KanjiList.instance + @kn = CHISE::KanjiNetwork.new + @kn.make_network(@kl.awase) + @kn.out("min.dot") #途中状態を保存 + + @gv = CHISE::GraphvizOLE.new() #OLE version + @gv.type = CHISE::Graphviz::TWOPI + @gv.target = "svg" + @gv.in = "min.dot" + @gv.out = "min.svg" + @gv.generate() + end +end diff --git a/test/org/org-test-str.rb b/test/org/org-test-str.rb new file mode 100755 index 0000000..550c20b --- /dev/null +++ b/test/org/org-test-str.rb @@ -0,0 +1,99 @@ +#!/usr/bin/env ruby +# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved. + +require "common" + +class TestString < Test::Unit::TestCase + def setup + @str = "文字列" + end + + def test_str + ar = [] + @str.each_char {|char| ar << char } + assert_equal(["文","字","列"], ar) + assert_equal(["文","字","列"], @str.to_a) + assert_equal("文", @str.char_at(0)) + assert_equal("字", @str.char_at(1)) + assert_equal("列", @str.char_at(2)) + assert_equal(nil, @str.char_at(3)) + assert_equal("列", @str.char_at(-1)) + end + + def test_attributes + assert_equal(23383, "字".ucs) + assert_raises(NameError, message=""){ + assert_equal(23383, "字字".ucs) #エラーが発生する + } + assert_equal(25991, "文".ucs) + assert_raises(NameError, message=""){ + assert_equal(25991, @str.ucs) #エラーが発生する + } + end + + def test_er + @char = @str.char_at(1) + assert_equal(@char, CHISE::Character.get("&J90-3B7A;").to_s, "jisx0208") + assert_equal("字", CHISE::Character.get("&J90-3B7A;").to_s, "jisx0208") + assert_equal("字", "&J90-3B7A;".de_er, "jisx0208") + assert_equal("文字", "文&J90-3B7A;".de_er, "with other character, at the bottom") + assert_equal("字文", "&J90-3B7A;文".de_er, "at the top") + assert_equal("文字字", "文&J90-3B7A;&J90-3B7A;".de_er, "two ERs") + assert_equal("文字文字", "文&J90-3B7A;文&J90-3B7A;".de_er, "two ERs") + assert_equal("文字", "文&MCS-00005B57;".de_er, "mcs") + assert_equal("文字", "文&M-06942;".de_er, "morohashi") + assert_equal("字", "字".de_er) + + str = "文&J90-3B7A;" + str2 = str.de_er #本体に変更無し + assert_equal("文&J90-3B7A;", str) + assert_equal("文字", str2) + str3 = str.de_er! #本体が変わります + assert_equal("文字", str) + assert_equal("文字", str3) + + assert_equal("字", "&MCS-00005B57;".de_er) + assert_equal("字", "&U-5B57;".de_er) + assert_equal("字", "&U+5B57;".de_er) +# assert_equal("", "&nosucher;".de_er) + assert_equal("字", "&U-5b57;".de_er) + end + + def test_method + str = @str.map_char {|ch| + ch+ch + } + assert_equal("文文字字列列", str) + assert_equal("文字列", @str) + str = @str.map_char! {|ch| + ch+ch + } + assert_equal("文文字字列列", str) + assert_equal("文文字字列列", @str) + assert_equal("文文字字列列", @str) + +# assert_equal("<文,C1-4546>", "文".inspect_x) +# assert_equal("<字,J90-3B7A>", "字".inspect_x) +# assert_equal("<列,J90-4E73>", "列".inspect_x) +# assert_equal("<文,C1-4546><字,J90-3B7A><列,J90-4E73>", "文字列".inspect_x) + + ins = "字".inspect_all +# assert_match(/^<字,J90-3B7A,/, ins) + assert_match(/^<字,#x5b57,/, ins) + assert_match(/=big5:42610/, ins) + assert_match(/=cns11643-1:18291/, ins) + assert_match(/=gb2312:22358/, ins) + assert_match(/=daikanwa:6942/, ins) + assert_match(/ideographic-radical:39/, ins) + assert_match(/ideographic-strokes:3/, ins) + assert_match(/=ks-x1001:27950/, ins) + assert_match(/shinjigen-2:1777/, ins) + assert_match(/total-strokes:6/, ins) + assert_match(/=ucs:23383/, ins) + assert_match(/=gt:8734/, ins) + assert_match(/=gt-k:1624/, ins) + assert_match(/=gt-pj-1:15226/, ins) + assert_match(/=jis-x0208:15226/, ins) + end + +end diff --git a/test/test-char.rb b/test/test-char.rb deleted file mode 100755 index c664864..0000000 --- a/test/test-char.rb +++ /dev/null @@ -1,163 +0,0 @@ -#!/usr/bin/env ruby -# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved. -# by eto 2003-0112 - -require "common" - -class TestCharacter < Test::Unit::TestCase - def setup() - @char = Character.get("字") #UTF8で与えること - end - - def test_char(char) -# assert_equal(6, char.get_char_attribute("total_strokes"), "get total strokes by XEmacs UTF-2000 like method") - assert_equal(6, char["total_strokes"], "get total strokes by Hash like method") if char.is_a? Character - assert_equal(6, char.total_strokes, "get total strokes by method") - assert_equal(23383, char.ucs, "translate to ucs") - assert_equal(22358, char.gb2312, "get character code in chinese GB2312") - assert_equal(1777, char.shinjigen_2, "get shinjigen 2") - assert_equal(3, char.ideographic_strokes, "get") - assert_equal(39, char.ideographic_radical, "get") - end - - def test_chars - test_char(Character.get("字")) - test_char(Character.new("字")) - test_char("字".char) - test_char("字") - end - -# def test_create -# assert_equal(23383, Character.parse_char_id("字")) -# end - - def test_put_attributes - @char.put_char_attribute("test_attribute", "test") - assert_equal("test", @char.get_char_attribute("test_attribute"), "put, get") - @char["test_attribute"] = "test" - assert_equal("test", @char["test_attribute"], "[]=, []") - end - - def test_method - assert_instance_of(Hash, @char.char_attribute_alist, "returns Hash") - assert_instance_of(Hash, @char.alist, ".alist returns Hash") - assert_instance_of(Array, @char.char_attribute_list, "returns Array") - assert_instance_of(Array, @char.list, ".list returns Array") - assert_instance_of(String, @char.inspect) - end - - def test_er - assert_equal(@char, Character.get("&J90-3B7A;"), "jisx0208") #まだ継承関係を実装していない。 -# assert_equal("&J90-3B7A;", @char.to_er, "jisx0208") - assert_equal(@char, Character.get("&MCS-00005B57;"), "mcs") - assert_equal(@char, Character.get("&M-06942;"), "ideograph-daikanwa, Morohashi") - end - - def test_latin - char = Character.get("A") - assert_equal(65, char.ascii, "ascii") - assert_equal(char.bidi_category, "L", "bidi") - assert_equal(char.name, "LATIN CAPITAL LETTER A", "name") - assert_equal(65, char.ucs, "ucs") - assert_equal(char.latin_jisx0201, 65, "jisx0201") - assert_equal(char.latin_viscii, 65, "viscii") #って何? -#->fullwidth: (((name . "FULLWIDTH LATIN CAPITAL LETTER A") (ucs . 65313))) -#->lowercase: (((name . "LATIN SMALL LETTER A") (ucs . 97))) -#general-category: (letter uppercase) -#このへんのS式の展開が必要なものは、また後程扱うべし。 - end - - def test_ids - char = Character.get("â¿°") - assert_equal("IDEOGRAPHIC DESCRIPTION CHARACTER LEFT TO RIGHT", char.name, "ids name") - #assert_equal(char.to_er, "&U+2FF0;", "ids er") - assert_equal(char.to_er, "⿰", "ids er") - assert_equal(char.bidi_category, "ON", "ids bidi") - end - - def test_jis - char = Character.get("逢") - assert_instance_of(String, char.get_attributes) - char = Character.get("å­¦") - assert_instance_of(String, char.get_attributes) - end - - def test_flyweight - char1 = Character.new("字") - char2 = Character.new("字") #.newで生成した場合は別々のinstanceになるのだ - assert_equal(char1, char2) #==ではある - assert_not_same(char1, char2) #equal?かというと違う - - cf = CharacterFactory.instance - char1 = cf.get("字") - char2 = cf.get("字") - assert_equal(char1, char2, "factory") #==である - assert_same(char1, char2, "factory") #かつ同じinstanceであることが保証される - - char1 = Character.get("字") #Character.newの代りにCharacter.getを使うとCharacterFactoryを使ったのと同じ効果がある。 - char2 = Character.get("字") - assert_equal(char1, char2) #==である - assert_same(char1, char2) #かつ同じinstanceであることが保証される - end - - def p_er(er) - p er.de_er.char.inspect_all - end - - def nu_test_has_attribute - assert("&J90-4833;".de_er.char.has_attribute?) #罪 - assert(! "&MCS-00E06E9B;;".de_er.char.has_attribute?) #罪のisolated character, attributeを持ってない - assert("&C1-602E;".de_er.char.has_attribute?) #渡 - assert("&J90-454F;".de_er.char.has_attribute?) #渡 - p_er("&C1-602E;") #渡 - p_er("&J90-454F;") - p_er("&J83-4D63;") #翼 - p_er("&J90-4D63;") - p_er("&J83-3958;") #è³¼ - p_er("&J90-3958;") - end - - def test_read_ucs - assert_equal("字", "&U5B57;".de_er) - assert_equal("字", "&U-5B57;".de_er) - assert_equal("字", "&U+5B57;".de_er) - assert_equal("字", "字".de_er) - end - - def test_alias - assert_raises(NameError, message=""){ - t = "字字".ucs - } - assert_equal(23383, "字".ucs) - assert_equal(0x5B57, "字".ucs) - assert_equal(0x5B57, @char.ucs) - - assert_equal(0xfa55, "突".char["=>ucs@jis"]) - assert_equal(0xfa55, "突".map_ucs_at_jis) - - char1 = Character.get("23383") - char2 = Character.get(23383) - assert_equal(char1, char2) - - char1 = Character.get("2") - char2 = Character.get(2) - assert_not_equal(char1, char2) - - assert_equal("(((name . \"FULLWIDTH DIGIT ONE\") (=ucs . 65297)))", "1".char["->fullwidth"]) - assert_equal("(((name . \"FULLWIDTH DIGIT ONE\") (=ucs . 65297)))", "1".char.to_fullwidth) - assert_equal("(((name . \"DIGIT ONE\") (=ucs . 49)))", "1".char["<-fullwidth"]) - assert_equal("(((name . \"DIGIT ONE\") (=ucs . 49)))", "1".char.from_fullwidth) - end -end - -#===== PRINT_ALL [字] MCS-00005B57 &J90-3B7A; ===== -#chinese-gb2312: 0x5756 -#chinese-isoir165: 0x5756 -#korean-ksc5601: 0x6D2E -#ucs: 0x5B57 -#chinese-cns11643-1: 0x4773 -#chinese-big5: 0xA672 - -# test_print(Character.get("&CDP-8B42;")) -# test_print(Character.get("&I-CDP-8AF6;")) -#===== PRINT_ALL [舛] MCS-00ECA524 &K0-743F; ===== diff --git a/test/test-ids.rb b/test/test-ids.rb deleted file mode 100755 index d26bc75..0000000 --- a/test/test-ids.rb +++ /dev/null @@ -1,298 +0,0 @@ -#!/usr/bin/env ruby -# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved. -# by eto 2003-0112 - -require "common" - -class TestIDS < Test::Unit::TestCase - def setup - end - - def test_ids - char = "榊".char - assert_equal("⿰木神", char.ids) - assert_equal("⿰木神", char.decompose) - str = "榊" - assert_equal("⿰木神", str.char.ids) - assert_equal("⿰木神", str.decompose) - assert_equal("⿰木⿰⺭申", str.decompose.decompose) - assert_equal("⿰木神", str.decompose!) - assert_equal("⿰木⿰⺭申", str.decompose!) - str = "榊" - assert_equal("⿰木⿰⺭申", str.decompose_all) - assert_equal("⿰木⿰⺭申", str.decompose_all!) - assert_equal("⿰木⿰⺭申", str) - #今はまだcomposeはできない。 - - de = "ç´°".decompose - assert_match(/田$/, de) - assert_equal(3, de.char_length) - de = "&JX2-7577;".de_er.decompose - de = "&CDP-8B60;".de_er.decompose - assert_equal(1, de.char_length) - de = "&JX2-217E;".de_er.decompose - assert_match(/^â¿°/, de) - assert_equal(3, de.char_length) - assert_equal(6, de.decompose!.char_length) -# assert_equal(6, de.decompose!.char_length) - - assert("⿸".char.is_ids?) - assert(! "木".char.is_ids?) - assert_equal(2, "â¿°".char.ids_operator_argc) - assert_equal(2, "&U+2FF0;".de_er.char.ids_operator_argc) - assert_equal(2, "&U+2FF1;".de_er.char.ids_operator_argc) - assert_equal(3, "&U+2FF2;".de_er.char.ids_operator_argc) - assert_equal(3, "&U+2FF3;".de_er.char.ids_operator_argc) - - assert_equal("â¿°", "&U+2FF0;".de_er.to_s) - assert("&U+2FF0;".de_er.char.is_ids?) - assert("&U+2FFF;".de_er.char.is_ids?) - #assert_match(/U\+2FF0/, "&U+2FF0;".de_er.char.inspect_x) - assert_match(/IDEOGRAPHIC DESCRIPTION CHARACTER LEFT TO RIGHT/, "&U+2FF0;".de_er.char.inspect_all) - (0x2FF0..0x2FFB).each {|i| - assert_match(/IDEOGRAPHIC DESCRIPTION CHARACTER/, Character.new(i).name) - } - - assert_match(/LEFT TO RIGHT/, "&U+2FF0;".de_er.char.name) #∫ - assert_match(/ABOVE TO BELOW/, "&U+2FF1;".de_er.char.name) #∨ - assert_match(/LEFT TO MIDDLE AND RIGHT/, "&U+2FF2;".de_er.char.name) #∬ - assert_match(/ABOVE TO MIDDLE AND BELOW/, "&U+2FF3;".de_er.char.name) #∀ - assert_match(/FULL SURROUND/, "&U+2FF4;".de_er.char.name) #∃ - assert_match(/SURROUND FROM ABOVE/, "&U+2FF5;".de_er.char.name) #∩ - assert_match(/SURROUND FROM BELOW/, "&U+2FF6;".de_er.char.name) #∪ - assert_match(/SURROUND FROM LEFT/, "&U+2FF7;".de_er.char.name) #⊂ - assert_match(/SURROUND FROM UPPER LEFT/, "&U+2FF8;".de_er.char.name) #√ - assert_match(/SURROUND FROM UPPER RIGHT/, "&U+2FF9;".de_er.char.name) #∂ - assert_match(/SURROUND FROM LOWER LEFT/, "&U+2FFA;".de_er.char.name) #∠ - assert_match(/OVERLAID/, "&U+2FFB;".de_er.char.name) #∵ - end - - def test_tree - assert_equal("[]", Tree.new().inspect) - assert_equal("[1]", Tree.new().add_leaf(1).inspect) - assert_equal("[1, 2]", Tree.new().add_leaf(1).add_leaf(2).inspect) - assert_equal("[[]]", Tree.new().add_node.inspect) - assert_equal("[[1]]", Tree.new().add_node.add_leaf(1).inspect) - assert_equal("[[1, 2]]", Tree.new().add_node.add_leaf(1).add_leaf(2).inspect) - assert_equal("[[1]]", Tree.new().add_node.add_leaf(1).end_node.inspect) - assert_equal("[[1], [1]]", Tree.new().add_node.add_leaf(1).end_node.add_node.add_leaf(1).end_node.inspect) - - tree = Tree.new - assert_equal("[]", tree.inspect) - assert_equal("[1]", tree.add_leaf(1).inspect) - assert_equal(0, tree.depth) - assert_equal("[1, 2]", tree.add_leaf(2).inspect) - assert_equal("[1, 2, []]", tree.add_node.inspect) - assert_equal("[1, 2, [3]]", tree.add_leaf(3).inspect) - assert_equal(1, tree.depth) - assert_equal("[1, 2, [3, 4]]", tree.add_leaf(4).inspect) - assert_equal("[1, 2, [3, 4]]", tree.end_node.inspect) - assert_equal("[1, 2, [3, 4], [5]]", tree.add_node.add_leaf(5).inspect) - assert_equal("[1, 2, [3, 4], [5, [6]]]", tree.add_node.add_leaf(6).inspect) - assert_equal(2, tree.depth) - - tree = Tree.new - assert_equal("[[\"+\"]]", tree.add_node("+", 2).inspect) - assert_equal("[[\"+\", 1]]", tree.add_leaf(1).inspect) - assert_equal("unmatch leaves", tree.check_integrity) - assert_equal("[[\"+\", 1, 2]]", tree.add_leaf(2).inspect) - assert_nil(tree.check_integrity) - assert_equal("[[\"+\", 1, 2], 3]", tree.add_leaf(3).inspect) - assert_equal("extra nodes", tree.check_integrity) - - tree = Tree.new - assert_equal("[[\"+\"]]", tree.add_node("+", 2).inspect) - assert_equal("unmatch leaves", tree.check_integrity) - assert_equal("[[\"+\", 1]]", tree.add_leaf(1).inspect) - assert_equal("unmatch leaves", tree.check_integrity) - assert_equal("[[\"+\", 1, [\"+\"]]]", tree.add_node("+", 2).inspect) - assert_equal("unmatch leaves", tree.check_integrity) - assert_equal("[[\"+\", 1, [\"+\", 2]]]", tree.add_leaf(2).inspect) - assert_equal("unmatch leaves", tree.check_integrity) - assert_equal("[[\"+\", 1, [\"+\", 2, 3]]]", tree.add_leaf(3).inspect) - assert_nil(tree.check_integrity) - - tree = Tree.new - assert_equal("[1]", tree.add_leaf(1).inspect) - assert_nil(tree.check_integrity) - assert_equal("[1, 2]", tree.add_leaf(2).inspect) - assert_equal("extra leaves", tree.check_integrity) - end - - def test_ids_tree -# assert_equal("[[<+,U+002B>, , ]]", IDS_Tree.new("+AB").inspect) -# assert_equal("[[<+,U+002B>, , ], ]", IDS_Tree.new("+ABC").inspect) -# assert_equal("[[<+,U+002B>, , [<+,U+002B>, , ]]]", IDS_Tree.new("+A+BC").inspect) -# assert_equal("[[<+,U+002B>, , [<+,U+002B>, , ]], ]", IDS_Tree.new("+A+BCD").inspect) - - #assert_equal("[<榊,U+698A>]", IDS_Tree.new("榊").inspect) -# assert_equal("[[<â¿°,U+2FF0>, <木,J90-4C5A>, <神,J90-3F40>]]", IDS_Tree.new("⿰木神").inspect) - assert_equal(1, IDS_Tree.new("⿰木神").depth) -# assert_equal("[[<â¿°,U+2FF0>, <木,J90-4C5A>, [<â¿°,U+2FF0>, <⺭,CDP-8B70>, <申,J90-3F3D>]]]", IDS_Tree.new("⿰木⿰⺭申").inspect) - assert_equal(2, IDS_Tree.new("⿰木⿰⺭申").depth) - assert_equal("unmatch leaves", IDS_Tree.new("⿰木").check_integrity) - assert_nil(IDS_Tree.new("⿰木神").check_integrity) - assert_equal("unmatch leaves", IDS_Tree.new("⿰木⿰申").check_integrity) - assert_nil(IDS_Tree.new("⿰木⿰⺭申").check_integrity) - assert_equal("extra nodes", IDS_Tree.new("⿰木⿰⺭申申").check_integrity) - assert_nil(IDS_Tree.new("榊").check_integrity) - assert_equal("extra leaves", IDS_Tree.new("榊榊").check_integrity) - - assert_equal(3, "⿳".char.ids_operator_argc) - assert_equal("⿳士冖匕", "壱".char.ids) - assert_equal(3, "壱".char.ids.char.ids_operator_argc) - assert_nil(IDS_Tree.new("⿳士冖匕").check_integrity) - assert_equal("unmatch leaves", IDS_Tree.new("⿳士冖").check_integrity) - assert_equal("extra nodes", IDS_Tree.new("⿳士冖匕匕").check_integrity) - - assert_equal("contains ques", IDS_Tree.new("⿳士冖?").check_integrity) - end - - def test_tree_depth - assert_equal(1, IDS_Tree.new("林".decompose).depth) -# assert_equal("["⿰木木"]", IDS_Tree.new("林".decompose).nodes.inspect) -# assert_equal("[]", IDS_Tree.new("林".decompose).sub_nodes.inspect) - assert_equal(2, IDS_Tree.new("榊".decompose_all).depth) -# assert_equal("["⿰木⿰⺭申", "⿰⺭申"]", IDS_Tree.new("榊".decompose_all).nodes.inspect) -# assert_equal("["⿰⺭申"]", IDS_Tree.new("榊".decompose_all).sub_nodes.inspect) - -# assert_equal(3, IDS_Tree.new("焔".decompose_all).depth) -# assert_equal(3, IDS_Tree.new("焔".decompose_all).nodes.length) -# assert_equal(2, IDS_Tree.new("焔".decompose_all).sub_nodes.length) - - assert_equal(2, IDS_Tree.new("屡".decompose_all).depth) - assert_equal("⿸尸娄", "⿸尸⿱米女".aggregate) - assert_equal(3, IDS_Tree.new("醤".decompose_all).depth) - end - - def test_compose_exact #正確に一致するIDSを検知する - assert_equal("榊", "榊".decompose.compose) - assert_equal("壱", "壱".decompose.compose) - assert_equal("⿰木木", "林".decompose) - assert_equal("林", "⿰木木".compose) - assert_equal("林", "林".decompose.compose) - assert_equal("⿰木木", "⿰木木".compose.decompose) - assert_equal("林".ucs, "⿰木木".compose.ucs) - end - - def test_idc_shortcut - assert_equal(IDC_LR, "林".decompose.first_char) - assert_equal(IDC_LR+"木木", "林".decompose) - - assert_equal(IDC_AB, "森".decompose.first_char) - assert_equal(IDC_AB+"木林", "森".decompose) - assert_equal(IDC_AB+"火火", "炎".decompose) - - assert_equal(IDC_LMR, "班".decompose.first_char) - assert_equal(IDC_LMR+"å½³"+IDC_AB+"山王"+"攵", "å¾´".decompose) #meaning? - - assert_equal(IDC_AMB, "é¼»".decompose.first_char) - assert_equal(IDC_AMB+"自田廾", "é¼»".decompose) - assert_equal(IDC_AMB+"士冖匕", "壱".decompose) - assert_equal(IDC_AMB+"穴厶心", "窓".decompose) - assert_equal(IDC_AMB+"丗冖巾", "帯".decompose) - - assert_equal(IDC_FS, "囲".decompose.first_char) - assert_equal(IDC_FS+"囗井", "囲".decompose) - assert_equal(IDC_FS+"行韋", "衛".decompose) - assert_equal(IDC_FS+"行圭", "街".decompose) - assert_equal(IDC_FS+"行重", "衝".decompose) - assert_equal(IDC_FS+IDC_AB+"一凵田", "画".decompose) - - assert_equal(IDC_FA, "問".decompose.first_char) - assert_equal(IDC_FA+"門口", "問".decompose) - assert_equal(IDC_FA+"門"+IDC_LR+"豆寸", "闘".decompose) - assert_equal(IDC_FA+"戌女", "威".decompose) - assert_equal(IDC_FA+"茂臣", "蔵".decompose) - assert_equal(IDC_FA+"尺旦", "昼".decompose) - assert_equal(IDC_FA+"冂入", "内".decompose) - assert_equal(IDC_FA+"几丶", "凡".decompose) - assert_equal(IDC_FA+"几"+IDC_AB+"丿虫", "風".decompose) - - assert_equal(IDC_FB, "凶".decompose.first_char) - assert_equal(IDC_AB+"æ­¢"+IDC_FB+"凵米", "æ­¯".decompose) - - assert_equal(IDC_FL, "匠".decompose.first_char) - assert_equal(IDC_FL+"匚斤", "匠".decompose) - assert_equal(IDC_FL+"匚矢", "医".decompose) - assert_equal(IDC_FL+"匚若", "匿".decompose) - assert_equal(IDC_FL+"匚儿", "匹".decompose) - - assert_equal(IDC_FUL, "庁".decompose.first_char) - assert_equal(IDC_FUL+"广丁", "庁".decompose) - assert_equal(IDC_FUL+"歹匕", "æ­»".decompose) - assert_equal(IDC_FUL+"尹口", "君".decompose) - assert_equal(IDC_FUL+"麻鬼", "魔".decompose) - assert_equal(IDC_FUL+"府肉", "腐".decompose) - assert_equal(IDC_FUL+"麻手", "摩".decompose) - assert_equal(IDC_FUL+"虍思", "慮".decompose) - assert_equal(IDC_FUL+"食口", "倉".decompose) - assert_equal(IDC_AB+"日"+IDC_FUL+"耳又", "最".decompose) - assert_equal(IDC_FUL+"手目", "看".decompose) #meaning - assert_equal(IDC_FUL+"辰口", "唇".decompose) #? - - assert_equal(IDC_FUR, "句".decompose.first_char) - assert_equal(IDC_FUR+"勹口", "句".decompose) - assert_equal(IDC_FUR+"勹丶", "勺".decompose) - assert_equal(IDC_FUR+"勹日", "旬".decompose) - assert_equal(IDC_FUR+"戈廾", "戒".decompose) - assert_equal(IDC_FUR+"弋工", "式".decompose) - assert_equal(IDC_FUR+"刀丿", "刃".decompose) - assert_equal(IDC_FUR+"鳥山", "島".decompose) #meaning - - assert_equal(IDC_FLL, "通".decompose.first_char) - assert_equal(IDC_FLL+"廴聿", "建".decompose) - assert_equal(IDC_FLL+"走戉", "越".decompose) - assert_equal(IDC_FLL+"èµ°å·³", "èµ·".decompose) - assert_equal(IDC_FLL+"走取", "趣".decompose) - assert_equal(IDC_FLL+"走召", "超".decompose) - assert_equal(IDC_FLL+"是頁", "題".decompose) - assert_equal(IDC_FLL+"免力", "勉".decompose) - assert_equal(IDC_FLL+"鬼未", "魅".decompose) - assert_equal(IDC_FLL+"黒犬", "黙".decompose) - - assert_equal(IDC_O, "太".decompose.first_char) - assert_equal(IDC_O+"大丶", "太".decompose) - assert_equal(IDC_O+"衣中", "è¡·".decompose) - assert_equal(IDC_O+"衣里", "裏".decompose) - assert_equal(IDC_O+"勹巳", "包".decompose) - assert_equal(IDC_O+"勹乂", "匁".decompose) - assert_equal(IDC_O+"木日", "東".decompose) - assert_equal(IDC_O+"弍一", "弐".decompose) - assert_equal(IDC_O+"衣保", "褒".decompose) - end - - def test_glyph_decompose - assert_equal("音", "音".decompose) -# assert_equal(IDC_AB+"立日", "音".glyph_decompose) - assert_equal(IDC_FLL, "世".decompose.first_char) - assert_equal("世", "世".glyph_decompose) - end - - def test_find() -# p "日雲".find #"曇" - assert(4 <= "日雲".find .char_length) #"曇" - end - - def test_compose_part() -# p de.compose_ar -# p "神".compose_ar -# p "木".compose_ar.join - end - - def test_aggregate() -# db = IDS_DB.instance -# db.list_aggregate - end - - def test_ids_error() -# p "実".char.inspect_all -# p "実".char.ids -# assert_equal("contains ques", "実".char.ids_error) -# assert_equal("unmatch leaves", "実".char.ids_error) -# p CharDB.instance.get("ascii").keys -# p CharDB.instance.get("no-such-attribute").keys -# p CharDB.instance.get("ids-error").keys - end - -end diff --git a/test/test-kage.rb b/test/test-kage.rb deleted file mode 100755 index 7bad058..0000000 --- a/test/test-kage.rb +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env ruby -# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved. -# kage testcase by eto 2003-0318 - -require "common" -require "chise/stroke" -include StrokeFont - -class TestKage < Test::Unit::TestCase - def setup - @kage = KageFont.new - end - - def test_stroke - end - - def test_kage - char = Character.get(0x4e03) #七 - font = @kage.get(0x4e03) - assert_instance_of(KageGlyph, font) - font.parse - - svg = <<"EOT" - M 50,540 950,255 - M 330,50 330,900 M 330,900 Q 330,950 380,950 M 380,950 840,950 M 840,950 Q 890,950 915,850 -EOT - strokes = KageParser.parse(svg) - #p strokes - end - - def test_path - pr = PathResolver.new - assert_equal([[0, 0, 1000, 1000]], pr.parse("M 0,0 1000,1000")) - assert_equal([[0, 0, 0, 1000], [0, 1000, 1000, 1000]], pr.parse("M 0,0 0,1000 1000,1000")) -# assert_equal([[0, 0, 0.0, 0.0], [0.0, 0.0, 62.5, 437.5], [62.5, 437.5, 250.0, 750.0], [250.0, 750.0, 562.5, 937.5]], pr.parse("M 0,0 Q 0,1000 1000,1000")) - end - -end diff --git a/test/test-kanjilist.rb b/test/test-kanjilist.rb deleted file mode 100755 index 9683cca..0000000 --- a/test/test-kanjilist.rb +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env ruby -# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved. -# testcase for KanjiNetwork by eto 2003-0227 - -require "common" -require "chise/kanjilist" - -class TestKanjiList < Test::Unit::TestCase - def setup - @kl = KanjiList.instance - end - - def test_kyoiku_kanji_list # 範囲指定が複雑なのでtestするべし。 - assert_equal("愛悪圧安暗案以位囲委意易異移胃衣遺医域育一印員因引飲院右宇羽雨運雲営映栄永泳英衛液益駅円園延沿演遠塩央往応横王黄億屋恩温音下化仮何価加可夏家科果歌河火花荷課貨過我画芽賀会解回快改械海灰界絵開階貝外害街各拡格確覚角閣革学楽額割活株寒刊巻完官干幹感慣漢看管簡観間関館丸岸眼岩顔願危喜器基寄希揮机旗期機帰気汽季紀規記貴起技疑義議客逆久休吸宮弓急救求泣球究級給旧牛去居挙許漁魚京供競共協境強教橋胸興郷鏡業局曲極玉勤均禁筋近金銀九句区苦具空君訓群軍郡係兄型形径敬景系経計警軽芸劇激欠決潔穴結血月件健券建憲検権犬研絹県見険験元原厳減源現言限個古呼固己庫戸故湖五午後語誤護交候光公功効厚口向后好孝工幸広康校構港皇紅耕考航行講鉱鋼降高号合刻告国穀黒骨今困根混左差査砂座再最妻才採済災祭細菜裁際在材罪財坂作昨策桜冊刷察札殺雑皿三参山散産算蚕賛酸残仕使司史四士始姉姿子市師志思指支枝止死氏私糸紙至視詞詩試誌資飼歯事似児字寺持時次治磁示耳自辞式識七失室質実舎写射捨社者謝車借尺若弱主取守手種酒首受授樹収周宗就州修拾秋終習衆週集住十従縦重宿祝縮熟出術述春準純順処初所暑署書諸助女序除傷勝商唱将小少承招昭松消焼照省章笑証象賞障 上乗城場常情条状蒸植織職色食信心新森深申真神臣親身進針人仁図垂推水数寸世制勢性成政整星晴正清生盛精聖声製西誠青静税席昔石積績責赤切接折設節説雪絶舌先千宣専川戦泉浅洗染線船選銭前善然全祖素組創倉奏層想操早巣争相窓総草装走送像増臓蔵造側則息束測足速属族続卒存孫尊損村他多太打体対帯待態貸退隊代台大第題宅達谷単担探炭短誕団断暖段男談値知地池置築竹茶着中仲宙忠昼柱注虫著貯丁兆帳庁張朝潮町腸調長頂鳥直賃追痛通低停定底庭弟提程敵的笛適鉄典天展店転点伝田電徒登都努度土党冬刀島投東湯灯当等答糖統討豆頭働動同堂導童道銅得徳特毒独読届内南難二肉日乳入任認熱年念燃納能脳農波派破馬俳拝敗背肺配倍梅買売博白麦箱畑八発判半反板版犯班飯晩番否悲批比皮秘肥費非飛備美鼻必筆百俵標氷票表評病秒品貧不付夫婦富布府父負武部風副復服福腹複仏物分奮粉文聞兵平並閉陛米別変片編辺返便勉弁保歩補墓暮母包報宝放方法訪豊亡忘暴望棒貿防北牧本妹枚毎幕末万満味未密脈民務夢無名命明盟迷鳴綿面模毛木目問門夜野矢役約薬訳油輸優勇友有由遊郵夕予余預幼容曜様洋用羊葉要陽養欲浴翌来落乱卵覧利理裏里陸律率立略流留旅両料良量領力緑林臨輪類令例冷礼歴列練連路労朗老六録論和話", @kl.kyoiku()) - assert_equal("一右雨円王音下火花学気休金九空月犬見五口校左三山四子糸字耳七車手十出女小上森人水正生青石赤先千川早足村大男中虫町天田土二日入年白八百文本名木目夕立力林六", @kl.kyoiku(1)) - assert_equal("引雲遠黄何夏家科歌画会回海絵貝外楽間顔帰汽記牛魚京強教玉近形計元原古戸午後語交光工広考行高合国黒今才作算市思止紙寺時自室社弱首秋春書少場色食心新親図数星晴声西切雪船前組草走多太体台谷知地池竹茶昼朝長鳥通弟店点電冬刀東当答頭同道読南馬買売麦半番父風分聞米歩母方北妹毎明鳴毛門夜野友曜用来理里話", @kl.kyoiku(2)) - assert_equal("一右雨円王音下火花学気休金九空月犬見五口校左三山四子糸字耳七車手十出女小上森人水正生青石赤先千川早足村大男中虫町天田土二日入年白八百文本名木目夕立力林六引雲遠黄何夏家科歌画会回海絵貝外楽間顔帰汽記牛魚京強教玉近形計元原古戸午後語交光工広考行高合国黒今才作算市思止紙寺時自室社弱首秋春書少場色食心新親図数星晴声西切雪船前組草走多太体台谷知地池竹茶昼朝長鳥通弟店点電冬刀東当答頭同道読南馬買売麦半番父風分聞米歩母方北妹毎明鳴毛門夜野友曜用来理里話", @kl.kyoiku(1..2)) - - assert_equal("右雨王音火貝九玉金月犬見口左山子糸耳車手十女人水夕石川早足大竹虫天田土日年白文木目立力六", @kl.kyoiku(1, KanjiList::SHOUKEI)) - assert_equal("一二三四五下七小上生中入八本", @kl.kyoiku(1, KanjiList::SHIJI)) - assert_equal("円休出森正赤千男町名林", @kl.kyoiku(1, KanjiList::KAII)) - assert_equal("花学気空校字青先草村百", @kl.kyoiku(1, KanjiList::KEISEI)) - - assert_equal("羽雲夏画回会外角弓牛魚京兄原戸古午工交行高黄才止矢自首心西長鳥弟刀東肉馬米歩母方北万毛門用来", @kl.kyoiku(2, KanjiList::SHOUKEI)) - assert_equal("", @kl.kyoiku(2, KanjiList::SHIJI)) - assert_equal("科楽岩顔汽教計公谷黒今思春少声雪走多太台直電内売半番父明鳴友里", @kl.kyoiku(2, KanjiList::KAII)) - assert_equal("引園遠何家歌海絵活間丸記帰強近形元言後語広光考合国細作算市姉紙寺時室社弱配秋週書場色食新親図数星晴切船線前組体地池茶昼朝通店点冬当答頭同道読南買麦風分聞毎妹夜野曜理話", @kl.kyoiku(2, KanjiList::KEISEI)) - - assert_equal("右雨王音火貝九玉金月犬見口左山子糸耳車手十女人水夕石川早足大竹虫天田土日年白文木目立力六羽雲夏画回会外角弓牛魚京兄原戸古午工交行高黄才止矢自首心西長鳥弟刀東肉馬米歩母方北万毛門用来", @kl.kyoiku(1..2, KanjiList::SHOUKEI)) - assert_equal("一二三四五下七小上生中入八本", @kl.kyoiku(1..2, KanjiList::SHIJI)) - assert_equal("円休出森正赤千男町名林科楽岩顔汽教計公谷黒今思春少声雪走多太台直電内売半番父明鳴友里", @kl.kyoiku(1..2, KanjiList::KAII)) - assert_equal("花学気空校字青先草村百引園遠何家歌海絵活間丸記帰強近形元言後語広光考合国細作算市姉紙寺時室社弱配秋週書場色食新親図数星晴切船線前組体地池茶昼朝通店点冬当答頭同道読南買麦風分聞毎妹夜野曜理話", @kl.kyoiku(1..2, KanjiList::KEISEI)) - end -end diff --git a/test/test-network.rb b/test/test-network.rb deleted file mode 100755 index 2c75b6c..0000000 --- a/test/test-network.rb +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env ruby -# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved. -# testcase for KanjiNetwork by eto 2003-0227 - -require "common" -require "chise/network" - -class Test_KanjiNetwork < Test::Unit::TestCase - def test_network - @kl = KanjiList.instance - @kn = KanjiNetwork.new - @kn.make_network(@kl.awase(0)) - @kn.out("min.dot") #途中状態を保存 - - @gv = GraphvizOLE.new() #OLE version - @gv.type = Graphviz::TWOPI - @gv.target = "svg" - @gv.in = "min.dot" - @gv.out = "min.svg" - @gv.generate() - end -end diff --git a/test/test-str.rb b/test/test-str.rb deleted file mode 100755 index 2513deb..0000000 --- a/test/test-str.rb +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env ruby -# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved. - -require "common" - -class TestString < Test::Unit::TestCase - def setup - @str = "文字列" - end - - def test_str - ar = [] - @str.each_char {|char| ar << char } - assert_equal(["文","字","列"], ar) - assert_equal(["文","字","列"], @str.to_a) - assert_equal("文", @str.char_at(0)) - assert_equal("字", @str.char_at(1)) - assert_equal("列", @str.char_at(2)) - assert_equal(nil, @str.char_at(3)) - assert_equal("列", @str.char_at(-1)) - end - - def test_attributes - assert_equal(23383, "字".ucs) - assert_raises(NameError, message=""){ - assert_equal(23383, "字字".ucs) #エラーが発生する - } - assert_equal(25991, "文".ucs) - assert_raises(NameError, message=""){ - assert_equal(25991, @str.ucs) #エラーが発生する - } - end - - def test_er - @char = @str.char_at(1) - assert_equal(@char, Character.get("&J90-3B7A;").to_s, "jisx0208") - assert_equal("字", Character.get("&J90-3B7A;").to_s, "jisx0208") - assert_equal("字", "&J90-3B7A;".de_er, "jisx0208") - assert_equal("文字", "文&J90-3B7A;".de_er, "with other character, at the bottom") - assert_equal("字文", "&J90-3B7A;文".de_er, "at the top") - assert_equal("文字字", "文&J90-3B7A;&J90-3B7A;".de_er, "two ERs") - assert_equal("文字文字", "文&J90-3B7A;文&J90-3B7A;".de_er, "two ERs") - assert_equal("文字", "文&MCS-00005B57;".de_er, "mcs") - assert_equal("文字", "文&M-06942;".de_er, "morohashi") - assert_equal("字", "字".de_er) - - str = "文&J90-3B7A;" - str2 = str.de_er #本体に変更無し - assert_equal("文&J90-3B7A;", str) - assert_equal("文字", str2) - str3 = str.de_er! #本体が変わります - assert_equal("文字", str) - assert_equal("文字", str3) - - assert_equal("字", "&MCS-00005B57;".de_er) - assert_equal("字", "&U-5B57;".de_er) - assert_equal("字", "&U+5B57;".de_er) -# assert_equal("", "&nosucher;".de_er) - assert_equal("字", "&U-5b57;".de_er) - end - - def test_method - str = @str.map_char {|ch| - ch+ch - } - assert_equal("文文字字列列", str) - assert_equal("文字列", @str) - str = @str.map_char! {|ch| - ch+ch - } - assert_equal("文文字字列列", str) - assert_equal("文文字字列列", @str) - assert_equal("文文字字列列", @str) - -# assert_equal("<文,C1-4546>", "文".inspect_x) -# assert_equal("<字,J90-3B7A>", "字".inspect_x) -# assert_equal("<列,J90-4E73>", "列".inspect_x) -# assert_equal("<文,C1-4546><字,J90-3B7A><列,J90-4E73>", "文字列".inspect_x) - - ins = "字".inspect_all -# assert_match(/^<字,J90-3B7A,/, ins) - assert_match(/^<字,#x5b57,/, ins) - assert_match(/=big5:42610/, ins) - assert_match(/=cns11643-1:18291/, ins) - assert_match(/=gb2312:22358/, ins) - assert_match(/=daikanwa:6942/, ins) - assert_match(/ideographic-radical:39/, ins) - assert_match(/ideographic-strokes:3/, ins) - assert_match(/=ks-x1001:27950/, ins) - assert_match(/shinjigen-2:1777/, ins) - assert_match(/total-strokes:6/, ins) - assert_match(/=ucs:23383/, ins) - assert_match(/=gt:8734/, ins) - assert_match(/=gt-k:1624/, ins) - assert_match(/=gt-pj-1:15226/, ins) - assert_match(/=jis-x0208:15226/, ins) - end - -end diff --git a/tools/.cvsignore b/tools/.cvsignore new file mode 100644 index 0000000..8a70bb0 --- /dev/null +++ b/tools/.cvsignore @@ -0,0 +1 @@ +chise-db.tar.gz diff --git a/tools/make-chisedb-tarball.rb b/tools/make-chisedb-tarball.rb new file mode 100755 index 0000000..cf95cf1 --- /dev/null +++ b/tools/make-chisedb-tarball.rb @@ -0,0 +1,38 @@ +#!/usr/bin/env ruby +# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved. + +$LOAD_PATH.unshift("..") +require "find" +require "chise/util" + +def usage() + print "Usage: make-chisedb-tarball.rb \n" + print "% ./make-chisedb-tarball.rb /usr/local/lib/xemacs-21.4.14/i686-pc-linux /var/tmp\n" + exit +end + +usage if ARGV.length < 1 +dir = ARGV[0] +unless FileTest.directory?(dir+"/chise-db") + print "no chise-db here. #{dir}\n" + usage +end +tmpdir = ARGV[1] +tmpdir = "/var/tmp" if tmpdir.nil? + +orgdir = Dir.pwd +Dir.chdir(tmpdir) # “K“–‚Èdir‚Ɉړ®‚µ‚Ä‚©‚ç +system "cp -a #{dir}/chise-db ." # ‚Ü‚¸‚»‚Ìdirectory‚É–â“š–³—p‚Å‘S•”ƒRƒs[‚·‚éB + +Find.find("."){|f| + if f =~ /([*?<>])/ # Windows‚É‚¨‚¯‚é‹ÖŽ~•¶Žš‚ªŠÜ‚Ü‚ê‚Ä‚¢‚½‚çA’uŠ·‚·‚é + nf = CHISE.unix_to_win(f) + cmd = "mv '#{f}' '#{nf}'" + #print cmd, "\n" + system cmd + end +} + +system "tar czf chise-db.tar.gz chise-db" +system "mv chise-db.tar.gz #{orgdir}" +system "rm -rf #{tmpdir}/chise-db" diff --git a/tools/mkdbtarball.rb b/tools/mkdbtarball.rb deleted file mode 100755 index 3bbabec..0000000 --- a/tools/mkdbtarball.rb +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env ruby -# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved. - -$LOAD_PATH.unshift("..") -require "chise/char" -require "find" - -def usage() - print "Usage: mkdbtarball.rb \n" - print "% ./mkdbtarball.rb /usr/local/lib/xemacs-21.4.10/i686-pc-linux/ /var/tmp\n" - exit -end - -usage if ARGV.length < 1 -dir = ARGV[0] -usage if ! FileTest.directory?("#{dir}/char-db") -tmpdir = ARGV[1] -tmpdir = "/var/tmp" if tmpdir == nil - -orgdir = Dir.pwd -Dir.chdir(tmpdir) #“K“–‚Èdir‚Ɉړ®‚µ‚Ä‚©‚ç -system "cp -a #{dir}/char-db ." #‚Ü‚¸‚»‚Ìdirectory‚É–â“š–³—p‚Å‘S•”ƒRƒs[‚·‚éB - -Find.find("."){|f| - if f =~ /([*?<>])/ #Windows‚É‚¨‚¯‚é‹ÖŽ~•¶Žš‚ªŠÜ‚Ü‚ê‚Ä‚¢‚½‚çA’uŠ·‚·‚é - nf = DB.unix_to_win(f) - cmd = "mv '#{f}' '#{nf}'" - #print cmd, "\n" - system cmd - end -} - -system "tar czf char-db.tar.gz char-db" -system "mv char-db.tar.gz #{orgdir}" -system "rm -rf #{tmpdir}/char-db" -- 1.7.10.4