[Groonga-commit] ranguba/rroonga at 5455a3d [master] dumper: ignore :order_by => :key for Groonga::Array and Groonga::Hash

Zurück zum Archiv-Index

Kouhei Sutou null+****@clear*****
Wed Sep 2 18:39:23 JST 2015


Kouhei Sutou	2015-09-02 18:39:23 +0900 (Wed, 02 Sep 2015)

  New Revision: 5455a3d38d4b16191250457e27a66d485dc38981
  https://github.com/ranguba/rroonga/commit/5455a3d38d4b16191250457e27a66d485dc38981

  Message:
    dumper: ignore :order_by => :key for Groonga::Array and Groonga::Hash

  Modified files:
    lib/groonga/dumper.rb
    test/test-table-dumper.rb

  Modified: lib/groonga/dumper.rb (+6 -1)
===================================================================
--- lib/groonga/dumper.rb    2015-09-02 18:36:53 +0900 (ec692a3)
+++ lib/groonga/dumper.rb    2015-09-02 18:39:23 +0900 (92b6e98)
@@ -704,7 +704,12 @@ module Groonga
     end
 
     def dump_records(columns)
-      @table.each(:order_by => @options[:order_by]) do |record|
+      order_by = @options[:order_by]
+      case @table
+      when Groonga::Array, Groonga::Hash
+        order_by = nil if order_by == :key
+      end
+      @table.each(:order_by => order_by) do |record|
         write(",\n")
         values = columns.collect do |column|
           resolve_value(record, column, column[record.id])

  Modified: test/test-table-dumper.rb (+170 -1)
===================================================================
--- test/test-table-dumper.rb    2015-09-02 18:36:53 +0900 (9700ae1)
+++ test/test-table-dumper.rb    2015-09-02 18:39:23 +0900 (2b7a7a8)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2011-2014  Kouhei Sutou <kou �� clear-code.com>
+# Copyright (C) 2011-2015  Kouhei Sutou <kou �� clear-code.com>
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -33,6 +33,175 @@ class TableDumperTest < Test::Unit::TestCase
     context["Posts"]
   end
 
+  class TableTest < self
+    class ArrayTest < self
+      class OrderByTest < self
+        def setup
+          Groonga::Schema.define do |schema|
+            schema.create_table("Users") do |table|
+              table.text("name")
+            end
+          end
+
+          @users = Groonga["Users"]
+          @users.add(:name => "Chris")
+          @users.add(:name => "Bob")
+          @users.add(:name => "Alice")
+        end
+
+        def test_id
+          assert_equal(<<-DUMP, dump("Users", :order_by => :id))
+load --table Users
+[
+["_id","name"],
+[1,"Chris"],
+[2,"Bob"],
+[3,"Alice"]
+]
+          DUMP
+        end
+
+        def test_key
+          assert_equal(<<-DUMP, dump("Users", :order_by => :key))
+load --table Users
+[
+["_id","name"],
+[1,"Chris"],
+[2,"Bob"],
+[3,"Alice"]
+]
+          DUMP
+        end
+      end
+    end
+
+    class HashTest < self
+      class OrderByTest < self
+        def setup
+          Groonga::Schema.define do |schema|
+            schema.create_table("Users",
+                                :type => :hash,
+                                :key_type => "ShortText") do |table|
+            end
+          end
+
+          @users = Groonga["Users"]
+          @users.add("Chris")
+          @users.add("Bob")
+          @users.add("Alice")
+        end
+
+        def test_id
+          assert_equal(<<-DUMP, dump("Users", :order_by => :id))
+load --table Users
+[
+["_key"],
+["Chris"],
+["Bob"],
+["Alice"]
+]
+          DUMP
+        end
+
+        def test_key
+          assert_equal(<<-DUMP, dump("Users", :order_by => :key))
+load --table Users
+[
+["_key"],
+["Chris"],
+["Bob"],
+["Alice"]
+]
+          DUMP
+        end
+      end
+    end
+
+    class PatriciaTrieTest < self
+      class OrderByTest < self
+        def setup
+          Groonga::Schema.define do |schema|
+            schema.create_table("Users",
+                                :type => :patricia_trie,
+                                :key_type => "ShortText") do |table|
+            end
+          end
+
+          @users = Groonga["Users"]
+          @users.add("Chris")
+          @users.add("Bob")
+          @users.add("Alice")
+        end
+
+        def test_id
+          assert_equal(<<-DUMP, dump("Users", :order_by => :id))
+load --table Users
+[
+["_key"],
+["Chris"],
+["Bob"],
+["Alice"]
+]
+          DUMP
+        end
+
+        def test_key
+          assert_equal(<<-DUMP, dump("Users", :order_by => :key))
+load --table Users
+[
+["_key"],
+["Alice"],
+["Bob"],
+["Chris"]
+]
+          DUMP
+        end
+      end
+    end
+
+    class DoubleArrayTrieTest < self
+      class OrderByTest < self
+        def setup
+          Groonga::Schema.define do |schema|
+            schema.create_table("Users",
+                                :type => :double_array_trie,
+                                :key_type => "ShortText") do |table|
+            end
+          end
+
+          @users = Groonga["Users"]
+          @users.add("Chris")
+          @users.add("Bob")
+          @users.add("Alice")
+        end
+
+        def test_id
+          assert_equal(<<-DUMP, dump("Users", :order_by => :id))
+load --table Users
+[
+["_key"],
+["Chris"],
+["Bob"],
+["Alice"]
+]
+          DUMP
+        end
+
+        def test_key
+          assert_equal(<<-DUMP, dump("Users", :order_by => :key))
+load --table Users
+[
+["_key"],
+["Alice"],
+["Bob"],
+["Chris"]
+]
+          DUMP
+        end
+      end
+    end
+  end
+
   class TextTest < self
     class ScalarTest < self
       def setup
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Zurück zum Archiv-Index