[Groonga-commit] groonga/grntest [master] Translater: Fix translate_command to translate a whole command

Back to archive index

null+****@clear***** null+****@clear*****
2012年 6月 5日 (火) 19:24:25 JST


Haruka Yoshihara	2012-06-05 19:24:25 +0900 (Tue, 05 Jun 2012)

  New Revision: 91270d122d2df077fc6b687434a87f6fc5a703bf

  Log:
    Translater: Fix translate_command to translate a whole command

  Modified files:
    lib/groonga/tester.rb
    test/test-executor.rb

  Modified: lib/groonga/tester.rb (+10 -9)
===================================================================
--- lib/groonga/tester.rb    2012-06-05 18:05:00 +0900 (69a07e8)
+++ lib/groonga/tester.rb    2012-06-05 19:24:25 +0900 (18a6711)
@@ -616,22 +616,23 @@ module Groonga
     end
 
     class Translater
-      def translate_command(command)
-        command = command.chomp
-        return "" if command.empty?
+      def translate_command(line)
+        line = line.chomp
+        return "" if line.empty?
 
-        return Rack::Utils.escape(command) if command =~ /\A(?!\s+)\W/
+        line = line.gsub(/"/, "\\\\\"")
+        json = line[/\[.+\]/]
 
-        now_command, *arguments = Shellwords.split(command)
+        unless json.nil?
+          line[/\[.+\]/] = "--values #{json.gsub(/\s/, "")}"
+        end
+
+        now_command, *arguments = Shellwords.split(line)
 
         translated_values = translate_arguments(now_command, arguments)
         translated_command =
           build_url(now_command, translated_values)
 
-        if now_command == "load"
-          translated_command << "&values="
-        end
-
         translated_command
       end
 

  Modified: test/test-executor.rb (+18 -15)
===================================================================
--- test/test-executor.rb    2012-06-05 18:05:00 +0900 (bf0ba2d)
+++ test/test-executor.rb    2012-06-05 19:24:25 +0900 (d2a72b1)
@@ -96,15 +96,16 @@ class TestExecutor < Test::Unit::TestCase
 ["razil","http://razil.jp/"]
 ]
 EOF
-      commands = "#{load_command}\n#{load_values}"
-      actual_commands = commands.lines.collect do |line|
-        translate(line)
-      end
-
-      expected_command = build_url("load", "table" => "Sites")
-      expected_command << load_values_query(load_values)
+      load_values = load_values.gsub(/\n/, "")
+      commands = "#{load_command} #{load_values}"
+      actual_commands = translate(commands)
+      arguments = {
+        "table" => "Sites",
+        "values" => load_values
+      }
+      expected_command = build_url("load", arguments)
 
-      assert_equal(expected_command, actual_commands.join("\n"))
+      assert_equal(expected_command, actual_commands)
     end
 
     def test_load_command_with_json_value
@@ -114,15 +115,17 @@ EOF
 {"_key": "ruby", "uri": "http://ruby-lang.org/"}
 ]
 EOF
-      commands = "#{load_command}\n#{load_values}"
-      actual_commands = commands.lines.collect do |line|
-        translate(line)
-      end
+      load_values = load_values.gsub(/\n/, "")
+      commands = "#{load_command} #{load_values}"
+      actual_commands = translate(commands)
 
-      expected_command = build_url("load", "table" => "Sites")
-      expected_command << load_values_query(load_values)
+      arguments = {
+        "table" => "Sites",
+        "values" => load_values.gsub(/\s/, "")
+      }
+      expected_command = build_url("load", arguments)
 
-      assert_equal(expected_command, actual_commands.join("\n"))
+      assert_equal(expected_command, actual_commands)
     end
 
     def test_command_with_single_quote




Groonga-commit メーリングリストの案内
Back to archive index