fantasdic r349 - in trunk: . lib/fantasdic test
- From: mblondel svn gnome org
- To: svn-commits-list gnome org
- Subject: fantasdic r349 - in trunk: . lib/fantasdic test
- Date: Sat, 30 Aug 2008 15:13:03 +0000 (UTC)
Author: mblondel
Date: Sat Aug 30 15:13:03 2008
New Revision: 349
URL: http://svn.gnome.org/viewvc/fantasdic?rev=349&view=rev
Log:
* test/test_utils.rb: Don't use global variables for filenames because it
can cause conflicts.
* test/test_preferences.rb: Ditto.
* test/test_dictd_file.rb: Ditto.
* test/test_edict_file.rb: Ditto.
* test/test_google_translate.rb: Ditto.
* test/test_dict_server.rb: Ditto.
* test/test_source_base.rb: Ditto.
* test/test_virtual_dictionary.rb: Ditto.
Modified:
trunk/ChangeLog
trunk/lib/fantasdic/utils.rb
trunk/test/test_dict_server.rb
trunk/test/test_dictd_file.rb
trunk/test/test_edict_file.rb
trunk/test/test_google_translate.rb
trunk/test/test_preferences.rb
trunk/test/test_source_base.rb
trunk/test/test_utils.rb
trunk/test/test_virtual_dictionary.rb
Modified: trunk/lib/fantasdic/utils.rb
==============================================================================
--- trunk/lib/fantasdic/utils.rb (original)
+++ trunk/lib/fantasdic/utils.rb Sat Aug 30 15:13:03 2008
@@ -16,6 +16,19 @@
#Â51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
class String
+
+ LITTLE_ENDIAN = ([42].pack('i')[0] == 42)
+ BIG_ENDIAN = !LITTLE_ENDIAN
+
+ def nbo32_to_integer
+ self.unpack("N*")[0]
+ end
+
+ def nbo64_to_integer
+ str = BIG_ENDIAN ? self : self.reverse
+ str.unpack("Q*")[0]
+ end
+
def utf8_length
self.unpack("U*").length
end
Modified: trunk/test/test_dict_server.rb
==============================================================================
--- trunk/test/test_dict_server.rb (original)
+++ trunk/test/test_dict_server.rb Sat Aug 30 15:13:03 2008
@@ -15,10 +15,11 @@
#Âwith this program; if not, write to the Free Software Foundation, Inc.,
#Â51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-test_dir = File.expand_path(File.dirname(__FILE__))
-top_dir = File.expand_path(File.join(test_dir, ".."))
-lib_dir = File.expand_path(File.join(top_dir, "lib"))
-$LOAD_PATH.unshift(lib_dir)
+$test_dir = File.expand_path(File.dirname(__FILE__))
+$top_dir = File.expand_path(File.join($test_dir, ".."))
+$lib_dir = File.expand_path(File.join($top_dir, "lib"))
+$test_data_dir = File.expand_path(File.join($test_dir, "data"))
+$LOAD_PATH.unshift($lib_dir)
require "test/unit"
require "fantasdic"
Modified: trunk/test/test_dictd_file.rb
==============================================================================
--- trunk/test/test_dictd_file.rb (original)
+++ trunk/test/test_dictd_file.rb Sat Aug 30 15:13:03 2008
@@ -15,14 +15,11 @@
#Âwith this program; if not, write to the Free Software Foundation, Inc.,
#Â51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-test_dir = File.expand_path(File.dirname(__FILE__))
-top_dir = File.expand_path(File.join(test_dir, ".."))
-lib_dir = File.expand_path(File.join(top_dir, "lib"))
-$test_data_dir = File.expand_path(File.join(test_dir, "data"))
-$index_file = File.join($test_data_dir, "freedict-wel-eng.index")
-$dict_file = File.join($test_data_dir, "freedict-wel-eng.dict")
-$dict_dz_file = File.join($test_data_dir, "freedict-wel-eng.dict.dz")
-$LOAD_PATH.unshift(lib_dir)
+$test_dir = File.expand_path(File.dirname(__FILE__))
+$top_dir = File.expand_path(File.join($test_dir, ".."))
+$lib_dir = File.expand_path(File.join($top_dir, "lib"))
+$test_data_dir = File.expand_path(File.join($test_dir, "data"))
+$LOAD_PATH.unshift($lib_dir)
require "test/unit"
require "fantasdic"
@@ -31,8 +28,14 @@
class TestDictdFileSource < Test::Unit::TestCase
include Fantasdic::Source
+ def setup
+ @index_file = File.join($test_data_dir, "freedict-wel-eng.index")
+ @dict_file = File.join($test_data_dir, "freedict-wel-eng.dict")
+ @dict_dz_file = File.join($test_data_dir, "freedict-wel-eng.dict.dz")
+ end
+
def test_binary_search
- DictdIndex.open($index_file) do |index|
+ DictdIndex.open(@index_file) do |index|
res = index.binary_search("notfound") do |s1, s2|
s1 <=> s2
end
@@ -46,7 +49,7 @@
end
def test_seek_prev_offset
- DictdIndex.open($index_file) do |index|
+ DictdIndex.open(@index_file) do |index|
assert_equal(index.get_prev_offset(52), 25)
assert_equal(index.get_prev_offset(2005), 1994)
assert_equal(index.get_prev_offset(25), nil)
@@ -54,7 +57,7 @@
end
def test_seek_next_offset
- DictdIndex.open($index_file) do |index|
+ DictdIndex.open(@index_file) do |index|
assert_equal(index.get_next_offset(52), 72)
assert_equal(index.get_next_offset(9462), 9472)
assert_equal(index.get_next_offset(9472), nil)
@@ -62,7 +65,7 @@
end
def test_match_prefix
- DictdIndex.open($index_file) do |index|
+ DictdIndex.open(@index_file) do |index|
assert_equal(index.match_prefix("ca").map { |a| a.first },
["cadair", "cadnawes", "cadno", "cadw", "cael", "caerdydd", "caeredin",
"caerefrog", "caerludd", "caint", "caled", "calon", "canol", "cant",
@@ -76,7 +79,7 @@
end
def test_match_exact
- DictdIndex.open($index_file) do |index|
+ DictdIndex.open(@index_file) do |index|
assert_equal(index.match_exact("ca").map { |a| a.first },
[])
@@ -86,7 +89,7 @@
end
def test_match_suffix
- DictdIndex.open($index_file) do |index|
+ DictdIndex.open(@index_file) do |index|
assert_equal(index.match_suffix("din").map { |a| a.first },
["caeredin", "lladin"])
@@ -96,7 +99,7 @@
end
def test_match_substring
- DictdIndex.open($index_file) do |index|
+ DictdIndex.open(@index_file) do |index|
assert_equal(index.match_substring("hufein").map { |a| a.first },
["rhufeinaidd", "rhufeiniad", "rhufeinig",
"rhufeiniwr"])
@@ -107,7 +110,7 @@
end
def test_match_word
- DictdIndex.open($index_file) do |index|
+ DictdIndex.open(@index_file) do |index|
assert_equal(index.match_word("os").map { |a| a.first },
["os", "os gwelwch yn dda"])
@@ -117,7 +120,7 @@
end
def test_get_word_list
- DictdIndex.open($index_file) do |index|
+ DictdIndex.open(@index_file) do |index|
assert_equal(index.get_word_list[0..24].map { |a| a.first },
["00databasealphabet",
"00databasedictfmt11010",
Modified: trunk/test/test_edict_file.rb
==============================================================================
--- trunk/test/test_edict_file.rb (original)
+++ trunk/test/test_edict_file.rb Sat Aug 30 15:13:03 2008
@@ -15,11 +15,11 @@
#Âwith this program; if not, write to the Free Software Foundation, Inc.,
#Â51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-test_dir = File.expand_path(File.dirname(__FILE__))
-top_dir = File.expand_path(File.join(test_dir, ".."))
-lib_dir = File.expand_path(File.join(top_dir, "lib"))
-$test_data_dir = File.expand_path(File.join(test_dir, "data"))
-$LOAD_PATH.unshift(lib_dir)
+$test_dir = File.expand_path(File.dirname(__FILE__))
+$top_dir = File.expand_path(File.join($test_dir, ".."))
+$lib_dir = File.expand_path(File.join($top_dir, "lib"))
+$test_data_dir = File.expand_path(File.join($test_dir, "data"))
+$LOAD_PATH.unshift($lib_dir)
require "test/unit"
require "fantasdic"
Modified: trunk/test/test_google_translate.rb
==============================================================================
--- trunk/test/test_google_translate.rb (original)
+++ trunk/test/test_google_translate.rb Sat Aug 30 15:13:03 2008
@@ -15,10 +15,11 @@
#Âwith this program; if not, write to the Free Software Foundation, Inc.,
#Â51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-test_dir = File.expand_path(File.dirname(__FILE__))
-top_dir = File.expand_path(File.join(test_dir, ".."))
-lib_dir = File.expand_path(File.join(top_dir, "lib"))
-$LOAD_PATH.unshift(lib_dir)
+$test_dir = File.expand_path(File.dirname(__FILE__))
+$top_dir = File.expand_path(File.join($test_dir, ".."))
+$lib_dir = File.expand_path(File.join($top_dir, "lib"))
+$test_data_dir = File.expand_path(File.join($test_dir, "data"))
+$LOAD_PATH.unshift($lib_dir)
require "test/unit"
require "fantasdic"
Modified: trunk/test/test_preferences.rb
==============================================================================
--- trunk/test/test_preferences.rb (original)
+++ trunk/test/test_preferences.rb Sat Aug 30 15:13:03 2008
@@ -15,11 +15,11 @@
#Âwith this program; if not, write to the Free Software Foundation, Inc.,
#Â51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-test_dir = File.expand_path(File.dirname(__FILE__))
-top_dir = File.expand_path(File.join(test_dir, ".."))
-lib_dir = File.expand_path(File.join(top_dir, "lib"))
-$config_file = File.expand_path(File.join(test_dir, "data", "config.yaml"))
-$LOAD_PATH.unshift(lib_dir)
+$test_dir = File.expand_path(File.dirname(__FILE__))
+$top_dir = File.expand_path(File.join($test_dir, ".."))
+$lib_dir = File.expand_path(File.join($top_dir, "lib"))
+$test_data_dir = File.expand_path(File.join($test_dir, "data"))
+$LOAD_PATH.unshift($lib_dir)
require "test/unit"
require "fileutils"
@@ -28,7 +28,9 @@
class TestPreferences < Test::Unit::TestCase
def setup
- @prefs = Fantasdic::PreferencesBase.new($config_file)
+ @config_file = File.expand_path(File.join($test_data_dir,
+ "config.yaml"))
+ @prefs = Fantasdic::PreferencesBase.new(@config_file)
end
def teardown
@@ -202,7 +204,7 @@
def test_save
begin
temp_file = "config_temp.yaml"
- FileUtils.cp($config_file, temp_file)
+ FileUtils.cp(@config_file, temp_file)
prefs = Fantasdic::PreferencesBase.new(temp_file)
prefs.view_statusbar = false
prefs.save!
Modified: trunk/test/test_source_base.rb
==============================================================================
--- trunk/test/test_source_base.rb (original)
+++ trunk/test/test_source_base.rb Sat Aug 30 15:13:03 2008
@@ -15,10 +15,11 @@
#Âwith this program; if not, write to the Free Software Foundation, Inc.,
#Â51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-test_dir = File.expand_path(File.dirname(__FILE__))
-top_dir = File.expand_path(File.join(test_dir, ".."))
-lib_dir = File.expand_path(File.join(top_dir, "lib"))
-$LOAD_PATH.unshift(lib_dir)
+$test_dir = File.expand_path(File.dirname(__FILE__))
+$top_dir = File.expand_path(File.join($test_dir, ".."))
+$lib_dir = File.expand_path(File.join($top_dir, "lib"))
+$test_data_dir = File.expand_path(File.join($test_dir, "data"))
+$LOAD_PATH.unshift($lib_dir)
require "test/unit"
require "fantasdic"
Modified: trunk/test/test_utils.rb
==============================================================================
--- trunk/test/test_utils.rb (original)
+++ trunk/test/test_utils.rb Sat Aug 30 15:13:03 2008
@@ -15,10 +15,11 @@
#Âwith this program; if not, write to the Free Software Foundation, Inc.,
#Â51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-test_dir = File.expand_path(File.dirname(__FILE__))
-top_dir = File.expand_path(File.join(test_dir, ".."))
-lib_dir = File.expand_path(File.join(top_dir, "lib"))
-$LOAD_PATH.unshift(lib_dir)
+$test_dir = File.expand_path(File.dirname(__FILE__))
+$top_dir = File.expand_path(File.join($test_dir, ".."))
+$lib_dir = File.expand_path(File.join($top_dir, "lib"))
+$test_data_dir = File.expand_path(File.join($test_dir, "data"))
+$LOAD_PATH.unshift($lib_dir)
require "test/unit"
require "fantasdic"
Modified: trunk/test/test_virtual_dictionary.rb
==============================================================================
--- trunk/test/test_virtual_dictionary.rb (original)
+++ trunk/test/test_virtual_dictionary.rb Sat Aug 30 15:13:03 2008
@@ -15,14 +15,11 @@
#Âwith this program; if not, write to the Free Software Foundation, Inc.,
#Â51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-test_dir = File.expand_path(File.dirname(__FILE__))
-top_dir = File.expand_path(File.join(test_dir, ".."))
-lib_dir = File.expand_path(File.join(top_dir, "lib"))
-$config_file = File.expand_path(File.join(test_dir, "data", "config.yaml"))
-$test_data_dir = File.expand_path(File.join(test_dir, "data"))
-$edict_file = File.join($test_data_dir, "edict.utf8")
-$dict_index_file = File.join($test_data_dir, "freedict-wel-eng.index")
-$LOAD_PATH.unshift(lib_dir)
+$test_dir = File.expand_path(File.dirname(__FILE__))
+$top_dir = File.expand_path(File.join($test_dir, ".."))
+$lib_dir = File.expand_path(File.join($top_dir, "lib"))
+$test_data_dir = File.expand_path(File.join($test_dir, "data"))
+$LOAD_PATH.unshift($lib_dir)
require "test/unit"
require "fantasdic"
@@ -33,11 +30,17 @@
class TestVirtualDictionarySource < Test::Unit::TestCase
def setup
- prefs = Fantasdic::PreferencesBase.new($config_file)
+ @config_file = File.expand_path(File.join($test_data_dir,
+ "config.yaml"))
+ @edict_file = File.join($test_data_dir, "edict.utf8")
+ @dict_index_file = File.join($test_data_dir, "freedict-wel-eng.index")
+
+
+ prefs = Fantasdic::PreferencesBase.new(@config_file)
prefs.dictionaries = ["edict", "dictdfile"]
prefs.dictionaries_infos["edict"] = {
:source => "EdictFile",
- :filename => $edict_file,
+ :filename => @edict_file,
:all_dbs => true,
:sel_dbs => [],
:encoding => "UTF-8"}
@@ -45,7 +48,7 @@
:source => "DictdFile",
:all_dbs => true,
:sel_dbs => [],
- :filename => $dict_index_file}
+ :filename => @dict_index_file}
@source = Fantasdic::Source::VirtualDictionaryBase.new(prefs)
end
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]