Kouhei Sutou
kous****@users*****
2006年 11月 30日 (木) 15:27:19 JST
Index: tomoe/test/dict_spec.rb diff -u tomoe/test/dict_spec.rb:1.11 tomoe/test/dict_spec.rb:1.12 --- tomoe/test/dict_spec.rb:1.11 Wed Nov 29 11:53:11 2006 +++ tomoe/test/dict_spec.rb Thu Nov 30 15:27:19 2006 @@ -1,16 +1,36 @@ require 'tomoe-spec-utils' -context "Tomoe::Context" do +context "Tomoe::Dict" do setup do setup_dict_file + setup_est_draft_file end - specify "should load" do - dict = Tomoe::Dict.new("xml", @dict_file.path, true) + specify "should load XML dictionary" do + dict = Tomoe::Dict.new("xml", + "filename" => @dict_file.path, + "editable" => true) a = dict[@utf8] a.writing.strokes.should == @strokes end + specify "should make Hyper Estraier dictionary" do + begin + est_db = File.join(tmp_dir, "est") + + `estcmd create #{est_db.dump}` + `estcmd put #{est_db.dump} #{@est_draft_file.path.dump}` + + dict = Tomoe::Dict.new("est", + "database_name" => est_db, + "editable" => true) + a = dict[@utf8] + a.writing.strokes.should == @strokes + ensure + FileUtils.rm_rf(est_db) + end + end + def setup_strokes @strokes = [ [ @@ -37,7 +57,7 @@ end def setup_dict_file - @dict_file = Tempfile.new("tomoe-dict") + @dict_file = Tempfile.new("tomoe-dict-xml") @utf8 = "ã" setup_strokes @@ -51,39 +71,54 @@ end strokes_xml << " </strokes>" - @dict_content = <<-EOX -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<!DOCTYPE dictionary SYSTEM "tomoe-dict.dtd"> -<dictionary> + @character_xml = <<-EOC <character> <utf8>#{@utf8}</utf8> #{strokes_xml} </character> +EOC + + @dict_content = <<-EOX +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE dictionary SYSTEM "tomoe-dict.dtd"> +<dictionary> +#{@character_xml} </dictionary> EOX - set_content(@dict_content) + set_content(@dict_file, @dict_content) + end + + def setup_est_draft_file + @est_draft_file = Tempfile.new("tomoe-dict-est-draft") + @est_draft_content = <<-EOC + @ uri=font:#{@utf8} +utf8=#{@utf8} + +#{@character_xml.collect {|line| "\t#{line}"}} +EOC + set_content(@est_draft_file, @est_draft_content) end - def set_content(content) - @dict_file.open - @dict_file.truncate(0) - @dict_file.rewind - @dict_file.print(content) - @dict_file.close + def set_content(file, content) + file.open + file.truncate(0) + file.rewind + file.print(content) + file.close - @dict_file.open - @dict_file.read.should == content - @dict_file.close + file.open + file.read.should == content + file.close end - def truncate_content - set_content("") + def truncate_content(file) + file.set_content("") end - def content - @dict_file.open - @dict_file.read + def content(file) + file.open + file.read ensure - @dict_file.close + file.close end end Index: tomoe/test/tomoe-spec-utils.rb diff -u tomoe/test/tomoe-spec-utils.rb:1.14 tomoe/test/tomoe-spec-utils.rb:1.15 --- tomoe/test/tomoe-spec-utils.rb:1.14 Thu Nov 30 11:53:15 2006 +++ tomoe/test/tomoe-spec-utils.rb Thu Nov 30 15:27:19 2006 @@ -1,4 +1,5 @@ require 'tempfile' +require 'fileutils' require 'tomoe' @@ -59,6 +60,10 @@ File.expand_path(File.dirname(__FILE__)) end + def tmp_dir + File.join(base_dir, "tmp") + end + def top_dir File.expand_path(File.join(base_dir, "..")) end @@ -86,10 +91,12 @@ def setup_context super @config_file = make_config_file + FileUtils.mkdir_p(tmp_dir) end def teardown_context super + FileUtils.rm_rf(tmp_dir) end def dictionaries