null+****@clear*****
null+****@clear*****
2012年 6月 6日 (水) 16:10:59 JST
Haruka Yoshihara 2012-06-06 16:10:59 +0900 (Wed, 06 Jun 2012)
New Revision: 568a651fa9652f23f07b0aadf66a6561937dd72a
Log:
Support non named arguments after named arguments
Modified files:
lib/groonga/tester.rb
test/test-executor.rb
Modified: lib/groonga/tester.rb (+7 -4)
===================================================================
--- lib/groonga/tester.rb 2012-06-06 16:04:28 +0900 (ae70261)
+++ lib/groonga/tester.rb 2012-06-06 16:10:59 +0900 (3e22722)
@@ -641,17 +641,20 @@ module Groonga
def convert_to_named_arguments(command, arguments)
named_arguments = {}
- last_parameter = ""
- arguments.each_with_index do |argument, count|
+ last_parameter = nil
+ n_non_named_arguments = 0
+ arguments.each do |argument|
if argument =~ /\A--/
last_parameter = argument.sub(/\A--/, "")
next
end
- if last_parameter.empty?
- query_parameter = arguments_name(command)[count]
+ if last_parameter.nil?
+ query_parameter = arguments_name(command)[n_non_named_arguments]
+ n_non_named_arguments += 1
else
query_parameter = last_parameter
+ last_parameter = nil
end
value = argument
Modified: test/test-executor.rb (+13 -0)
===================================================================
--- test/test-executor.rb 2012-06-06 16:04:28 +0900 (ef2e2e0)
+++ test/test-executor.rb 2012-06-06 16:10:59 +0900 (2558ddf)
@@ -75,6 +75,19 @@ class TestExecutor < Test::Unit::TestCase
assert_equal(expected_url, actual_url)
end
+ def test_non_named_argument_after_named_arguement
+ command = "table_create --flags TABLE_HASH_KEY --key_type ShortText Site"
+ arguments = {
+ "flags" => "TABLE_HASH_KEY",
+ "key_type" => "ShortText",
+ "name" => "Site",
+ }
+ actual_url = convert(command)
+ expected_url = build_url("table_create", arguments)
+
+ assert_equal(expected_url, actual_url)
+ end
+
def test_without_arguments
command = "dump"
actual_url = convert(command)