[Groonga-commit] groonga/groonga-command at 48c1c72 [fix-travis-ci-error] Add Groonga::Command::Base#has_key?

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Jan 13 17:18:36 JST 2016


Kouhei Sutou	2012-11-27 17:28:32 +0900 (Tue, 27 Nov 2012)

  New Revision: 48c1c729030b53b543d057e04cbc677cfddc7398
  https://github.com/groonga/groonga-command/commit/48c1c729030b53b543d057e04cbc677cfddc7398

  Message:
    Add Groonga::Command::Base#has_key?

  Modified files:
    lib/groonga/command/base.rb
    test/command/test-base.rb

  Modified: lib/groonga/command/base.rb (+10 -2)
===================================================================
--- lib/groonga/command/base.rb    2012-11-27 16:33:33 +0900 (b0b2566)
+++ lib/groonga/command/base.rb    2012-11-27 17:28:32 +0900 (e92acac)
@@ -49,8 +49,11 @@ module Groonga
       end
 
       def [](name)
-        name = name.to_sym if name.is_a?(String)
-        @arguments[name]
+        @arguments[normalize_name(name)]
+      end
+
+      def has_key?(name)
+        @arguments.has_key?(normalize_name(name))
       end
 
       def ==(other)
@@ -125,6 +128,11 @@ module Groonga
 
         arguments
       end
+
+      def normalize_name(name)
+        name = name.to_sym if name.is_a?(String)
+        name
+      end
     end
   end
 end

  Modified: test/command/test-base.rb (+29 -0)
===================================================================
--- test/command/test-base.rb    2012-11-27 16:33:33 +0900 (15d5754)
+++ test/command/test-base.rb    2012-11-27 17:28:32 +0900 (52a7213)
@@ -82,4 +82,33 @@ class BaseCommandTest < Test::Unit::TestCase
                    select.to_command_format)
     end
   end
+
+  sub_test_case("#[]") do
+    def setup
+      @table = "Users"
+      @select = Groonga::Command::Base.new("select", :table => @table)
+    end
+
+    def test_symbol
+      assert_equal(@table, @select[:table])
+    end
+
+    def test_string
+      assert_equal(@table, @select["table"])
+    end
+  end
+
+  sub_test_case("#has_key?") do
+    def setup
+      @select = Groonga::Command::Base.new("select", :table => "Users")
+    end
+
+    def test_symbol
+      assert_true(@select.has_key?(:table))
+    end
+
+    def test_string
+      assert_true(@select.has_key?("table"))
+    end
+  end
 end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index