Kouhei Sutou
null+****@clear*****
Wed Oct 25 15:26:37 JST 2017
Kouhei Sutou 2017-10-25 15:26:37 +0900 (Wed, 25 Oct 2017) New Revision: 51a3fe0766e05186634449d58835a8373a39d35c https://github.com/ranguba/groonga-client/commit/51a3fe0766e05186634449d58835a8373a39d35c Message: column_list response: add convenient readers Removed files: test/results/test-column-list.rb Modified files: lib/groonga/client/response/column-list.rb test/response/test-column-list.rb Modified: lib/groonga/client/response/column-list.rb (+32 -3) =================================================================== --- lib/groonga/client/response/column-list.rb 2017-10-25 15:13:41 +0900 (4ded1f8) +++ lib/groonga/client/response/column-list.rb 2017-10-25 15:26:37 +0900 (d0b3bf8) @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- -# # Copyright (C) 2013 Haruka Yoshihara <yoshihara �� clear-code.com> -# Copyright (C) 2013 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2013-2017 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 @@ -66,6 +64,37 @@ module Groonga :domain, :range, :source) + # @return [::Array<String>] + # The flag names of the column. + # + # @since 0.5.3 + def flags + (super || "").split("|") + end + + # @return [Boolean] + # `true` if the column is a scalar column, `false` otherwise. + # + # @since 0.5.3 + def scalar? + flags.include?("COLUMN_SCALAR") + end + + # @return [Boolean] + # `true` if the column is a vector column, `false` otherwise. + # + # @since 0.5.3 + def vector? + flags.include?("COLUMN_VECTOR") + end + + # @return [Boolean] + # `true` if the column is an index column, `false` otherwise. + # + # @since 0.5.3 + def index? + flags.include?("COLUMN_INDEX") + end end end end Modified: test/response/test-column-list.rb (+114 -43) =================================================================== --- test/response/test-column-list.rb 2017-10-25 15:13:41 +0900 (e4c588f) +++ test/response/test-column-list.rb 2017-10-25 15:26:37 +0900 (68d171d) @@ -18,54 +18,125 @@ require "response/helper" class TestResponseColumnList < Test::Unit::TestCase - include TestResponseHelper + class TestParse < self + include TestResponseHelper - def column(attributes) - c = Groonga::Client::Response::ColumnList::Column.new - attributes.each do |name, value| - c[name] = value + def column(attributes) + c = Groonga::Client::Response::ColumnList::Column.new + attributes.each do |name, value| + c[name] = value + end + c + end + + def test_parse + header = [0, 1372430096.70991, 0.000522851943969727] + body = [ + [ + ["id", "UInt32"], + ["name", "ShortText"], + ["path", "ShortText"], + ["type", "ShortText"], + ["flags", "ShortText"], + ["domain", "ShortText"], + ["range", "ShortText"], + ["source", "ShortText"], + ], + [ + 256, + "content", + "/tmp/test.db.0000100", + "var", + "COLUMN_SCALAR|PERSISTENT", + "TestTable", + "ShortText", + [], + ], + ] + raw_response = [header, body].to_json + + response = parse_raw_response("column_list", raw_response) + assert_equal([ + column(:id => 256, + :name => "content", + :path => "/tmp/test.db.0000100", + :type => "var", + :flags => "COLUMN_SCALAR|PERSISTENT", + :domain => "TestTable", + :range => "ShortText", + :source => []), + ], + response.to_a) end - c end - def test_parse - header = [0, 1372430096.70991, 0.000522851943969727] - body = [ - [ - ["id", "UInt32"], - ["name", "ShortText"], - ["path", "ShortText"], - ["type", "ShortText"], - ["flags", "ShortText"], - ["domain", "ShortText"], - ["range", "ShortText"], - ["source", "ShortText"], - ], - [ - 256, - "Text", - "/tmp/test.db.0000100", - "var", - "COLUMN_SCALAR|PERSISTENT", - "TestTable", - "ShortText", - [], - ], - ] - raw_response = [header, body].to_json + class TestBody < self + def setup + @command = Groonga::Command::Base.new("column_list", "table" => "Memos") + end + + def create_response(columns) + header = [0, 1372430096.70991, 0.000522851943969727] + body = [ + [ + ["id", "UInt32"], + ["name", "ShortText"], + ["path", "ShortText"], + ["type", "ShortText"], + ["flags", "ShortText"], + ["domain", "ShortText"], + ["range", "ShortText"], + ["source", "ShortText"], + ], + *columns, + ] + Groonga::Client::Response::ColumnList.new(@command, header, body) + end - response = parse_raw_response("column_list", raw_response) - assert_equal([ - column(:id => 256, - :name => "Text", - :path => "/tmp/test.db.0000100", - :type => "var", - :flags => "COLUMN_SCALAR|PERSISTENT", - :domain => "TestTable", - :range => "ShortText", - :source => []), - ], - response.to_a) + class TestFlags < self + def create_response(flags) + columns = [ + [ + 256, + "content", + "/tmp/test.db.0000100", + "var", + flags, + "Memos", + "ShortText", + [], + ] + ] + super(columns) + end + + def test_multiple + response = create_response("COLUMN_SCALAR|PERSISTENT") + assert_equal(["COLUMN_SCALAR", "PERSISTENT"], + response[0].flags) + end + + def test_scalar? + response = create_response("COLUMN_SCALAR|PERSISTENT") + assert do + response[0].scalar? + end + end + + def test_vector? + response = create_response("COLUMN_VECTOR|PERSISTENT") + assert do + response[0].vector? + end + end + + def test_index? + response = create_response("COLUMN_INDEX|WITH_POSITION|PERSISTENT") + assert do + response[0].index? + end + end + end end end Deleted: test/results/test-column-list.rb (+0 -64) 100644 =================================================================== --- test/results/test-column-list.rb 2017-10-25 15:13:41 +0900 (810824c) +++ /dev/null @@ -1,64 +0,0 @@ -require "test/unit/rr" - -class TestResultsColumnList < Test::Unit::TestCase - class TestResults < self - def setup - command = nil - header = [0,1372430096.70991,0.000522851943969727] - body = [[["id","UInt32"],["name","ShortText"],["path","ShortText"],["type","ShortText"],["flags","ShortText"],["domain","ShortText"],["range","ShortText"],["source","ShortText"]], - [259,"_key","","","COLUMN_SCALAR","Bigram","ShortText",[]], - [278,"comment_index","/tmp/db.db.0000116","index","COLUMN_INDEX|WITH_POSITION|PERSISTENT","Bigram","Comments",["Comments.comment"]], - [277,"users_index","/tmp/db.db.0000115","index","COLUMN_INDEX|WITH_SECTION|WITH_POSITION|PERSISTENT","Bigram","Users",["Users.name","Users.location_str","Users.description"]]] - @column_list = Groonga::Client::Response::ColumnList.new(command, header, body) - end - - def test_column_list - assert_equal( - [ - { - :id => 259, - :name => "_key", - :path => "", - :type => "", - :flags => "COLUMN_SCALAR", - :domain => "Bigram", - :range => "ShortText", - :source => [], - }, - { - :id => 278, - :name => "comment_index", - :path => "/tmp/db.db.0000116", - :type => "index", - :flags => "COLUMN_INDEX|WITH_POSITION|PERSISTENT", - :domain => "Bigram", - :range => "Comments", - :source => ["Comments.comment"], - }, - { - :id => 277, - :name => "users_index", - :path => "/tmp/db.db.0000115", - :type => "index", - :flags => "COLUMN_INDEX|WITH_SECTION|WITH_POSITION|PERSISTENT", - :domain => "Bigram", - :range => "Users", - :source => ["Users.name","Users.location_str", "Users.description"], - }, - ], - @column_list.collect {|column| - { - :id => column.id, - :name => column.name, - :path => column.path, - :type => column.type, - :flags => column.flags, - :domain => column.domain, - :range => column.range, - :source => column.source, - } - } - ) - end - end -end -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20171025/b09799d9/attachment-0001.htm