fantasdic r319 - in trunk: . lib/fantasdic/sources test



Author: mblondel
Date: Tue Aug 19 15:57:33 2008
New Revision: 319
URL: http://svn.gnome.org/viewvc/fantasdic?rev=319&view=rev

Log:
    * lib/fantasdic/sources/google_translate.rb: Fixed bug which made the
    source return no results. This was due to a change in the HTML structure of
    the results in translate.google.com.
    * test/test_google_translate.rb: Added a unit-test.
    * README: Added a note on how to run tests.


Added:
   trunk/test/
   trunk/test/test_google_translate.rb
Modified:
   trunk/README
   trunk/lib/fantasdic/sources/google_translate.rb

Modified: trunk/README
==============================================================================
--- trunk/README	(original)
+++ trunk/README	Tue Aug 19 15:57:33 2008
@@ -45,6 +45,11 @@
 
     $ fantasdic --help
 
+Tests
+-----
+
+    $ ruby setup.rb test
+
 License
 -------
 

Modified: trunk/lib/fantasdic/sources/google_translate.rb
==============================================================================
--- trunk/lib/fantasdic/sources/google_translate.rb	(original)
+++ trunk/lib/fantasdic/sources/google_translate.rb	Tue Aug 19 15:57:33 2008
@@ -29,7 +29,7 @@
         copyright "Copyright (C) 2007 Mathieu Blondel"
         disable_search_all_databases true
 
-        START_MARKUP = "<div id=result_box dir=(ltr|rtl)>"
+        START_MARKUP = "<div id=[\"]?result_box[\"]? dir=[\"]?(ltr|rtl)[\"]?>"
         END_MARKUP = "</div>"
         URL = "http://translate.google.com/translate_t"; + \
               "?ie=UTF8&langpair=%s&text=%s"
@@ -74,7 +74,7 @@
 
         def define(db, word)
             db_escaped, word_escaped = CGI.escape(db), CGI.escape(word)
-            begin
+            begin               
                 Kernel::open(URL % [db_escaped, word_escaped]) do |buffer|
                     case buffer.read
                         when /#{START_MARKUP}(.*)/

Added: trunk/test/test_google_translate.rb
==============================================================================
--- (empty file)
+++ trunk/test/test_google_translate.rb	Tue Aug 19 15:57:33 2008
@@ -0,0 +1,39 @@
+# Fantasdic
+# Copyright (C) 2008 Mathieu Blondel
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+#Â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)
+
+require "test/unit"
+require "fantasdic"
+require "fantasdic/sources/google_translate"
+
+class TestGoogleTranslateSource < Test::Unit::TestCase
+
+    def setup
+        @source = Fantasdic::Source::GoogleTranslate.new({})
+    end
+
+    def test_define
+        defs = @source.define("fr|en", "Salut")
+        assert_equal(1, defs.length)
+        assert_equal("Hi", defs[0].body)
+    end
+
+end



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]