groonga-command 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,87 +17,88 @@
17
17
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
 
19
19
  class SelectCommandTest < Test::Unit::TestCase
20
- include GroongaCommandTestUtils::CommandLineCommandParser
20
+ private
21
+ def select_command(pair_arguments={}, ordered_arguments=[])
22
+ Groonga::Command::Select.new("select", pair_arguments, ordered_arguments)
23
+ end
21
24
 
22
- def test_ordered_argument
23
- table = "Users"
24
- match_columns = "name * 10 || description"
25
- query = "groonga"
26
- filter = "age >= 18"
27
- scorer = "_score = age"
28
- sortby = "_score"
29
- output_columns = "_key, name"
30
- offset = "10"
31
- limit = "20"
32
- drilldown = "name"
33
- drilldown_sortby = "_nsubrecs"
34
- drilldown_output_columns = "name, _nsubrecs"
35
- drilldown_offset = "5"
36
- drilldown_limit = "10"
37
- cache = "no"
38
- match_escalation_threshold = "-1"
39
- query_expansion = "deprecated"
40
- query_flags = "ALLOW_LEADING_NOT"
41
- query_expander = "Terms.synonym"
42
- command = parse("select",
43
- [
44
- table,
45
- match_columns,
46
- query,
47
- filter,
48
- scorer,
49
- sortby,
50
- output_columns,
51
- offset,
52
- limit,
53
- drilldown,
54
- drilldown_sortby,
55
- drilldown_output_columns,
56
- drilldown_offset,
57
- drilldown_limit,
58
- cache,
59
- match_escalation_threshold,
60
- query_expansion,
61
- query_flags,
62
- query_expander,
63
- ],
64
- :output_type => false)
25
+ class ConstructorTest < self
26
+ def test_ordered_argument
27
+ table = "Users"
28
+ match_columns = "name * 10 || description"
29
+ query = "groonga"
30
+ filter = "age >= 18"
31
+ scorer = "_score = age"
32
+ sortby = "_score"
33
+ output_columns = "_key, name"
34
+ offset = "10"
35
+ limit = "20"
36
+ drilldown = "name"
37
+ drilldown_sortby = "_nsubrecs"
38
+ drilldown_output_columns = "name, _nsubrecs"
39
+ drilldown_offset = "5"
40
+ drilldown_limit = "10"
41
+ cache = "no"
42
+ match_escalation_threshold = "-1"
43
+ query_expansion = "deprecated"
44
+ query_flags = "ALLOW_LEADING_NOT"
45
+ query_expander = "Terms.synonym"
65
46
 
66
- assert_instance_of(Groonga::Command::Select, command)
67
- assert_equal({
68
- :table => table,
69
- :match_columns => match_columns,
70
- :query => query,
71
- :filter => filter,
72
- :scorer => scorer,
73
- :sortby => sortby,
74
- :output_columns => output_columns,
75
- :offset => offset,
76
- :limit => limit,
77
- :drilldown => drilldown,
78
- :drilldown_sortby => drilldown_sortby,
79
- :drilldown_output_columns => drilldown_output_columns,
80
- :drilldown_offset => drilldown_offset,
81
- :drilldown_limit => drilldown_limit,
82
- :cache => cache,
83
- :match_escalation_threshold => match_escalation_threshold,
84
- :query_expansion => query_expansion,
85
- :query_flags => query_flags,
86
- :query_expander => query_expander,
87
- },
88
- command.arguments)
89
- end
47
+ ordered_arguments = [
48
+ table,
49
+ match_columns,
50
+ query,
51
+ filter,
52
+ scorer,
53
+ sortby,
54
+ output_columns,
55
+ offset,
56
+ limit,
57
+ drilldown,
58
+ drilldown_sortby,
59
+ drilldown_output_columns,
60
+ drilldown_offset,
61
+ drilldown_limit,
62
+ cache,
63
+ match_escalation_threshold,
64
+ query_expansion,
65
+ query_flags,
66
+ query_expander,
67
+ ]
68
+ command = select_command({}, ordered_arguments)
90
69
 
91
- def test_scorer
92
- select = command(:table => "Users",
93
- :filter => "age<=30",
94
- :scorer => "_score = random()")
95
- assert_equal("_score = random()", select.scorer)
70
+ assert_equal({
71
+ :table => table,
72
+ :match_columns => match_columns,
73
+ :query => query,
74
+ :filter => filter,
75
+ :scorer => scorer,
76
+ :sortby => sortby,
77
+ :output_columns => output_columns,
78
+ :offset => offset,
79
+ :limit => limit,
80
+ :drilldown => drilldown,
81
+ :drilldown_sortby => drilldown_sortby,
82
+ :drilldown_output_columns => drilldown_output_columns,
83
+ :drilldown_offset => drilldown_offset,
84
+ :drilldown_limit => drilldown_limit,
85
+ :cache => cache,
86
+ :match_escalation_threshold => match_escalation_threshold,
87
+ :query_expansion => query_expansion,
88
+ :query_flags => query_flags,
89
+ :query_expander => query_expander,
90
+ },
91
+ command.arguments)
92
+ end
96
93
  end
97
94
 
98
- private
99
- def command(arguments)
100
- Groonga::Command::Select.new("select", arguments)
95
+ class ScorerTest < self
96
+ def test_reader
97
+ command = select_command(:table => "Users",
98
+ :filter => "age<=30",
99
+ :scorer => "_score = random()")
100
+ assert_equal("_score = random()", command.scorer)
101
+ end
101
102
  end
102
103
 
103
104
  class FilterTest < self
@@ -106,8 +107,8 @@ class SelectCommandTest < Test::Unit::TestCase
106
107
  '"35.73360x139.7394","62614x139.7714") && ' +
107
108
  '((type == "たいやき" || type == "和菓子")) && ' +
108
109
  'keyword @ "たいやき" &! keyword @ "白" &! keyword @ "養殖"'
109
- select = command(:table => "Users",
110
- :filter => filter)
110
+ command = select_command(:table => "Users",
111
+ :filter => filter)
111
112
  assert_equal(['geo_in_rectangle(location,' +
112
113
  '"35.73360x139.7394","62614x139.7714")',
113
114
  'type == "たいやき"',
@@ -115,14 +116,14 @@ class SelectCommandTest < Test::Unit::TestCase
115
116
  'keyword @ "たいやき"',
116
117
  'keyword @ "白"',
117
118
  'keyword @ "養殖"'],
118
- select.conditions)
119
+ command.conditions)
119
120
  end
120
121
 
121
122
  def test_omitted
122
- select = command(:table => "Users",
123
- :filter => nil)
123
+ command = select_command(:table => "Users",
124
+ :filter => nil)
124
125
  assert_equal([],
125
- select.conditions)
126
+ command.conditions)
126
127
  end
127
128
  end
128
129
  end
@@ -1,5 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
+ # Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
3
4
  # Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
4
5
  #
5
6
  # This library is free software; you can redistribute it and/or
@@ -17,52 +18,59 @@
17
18
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19
 
19
20
  class SuggestCommandTest < Test::Unit::TestCase
20
- class CommandLineTest < self
21
- include GroongaCommandTestUtils::CommandLineCommandParser
21
+ private
22
+ def suggest_command(pair_arguments={}, ordered_arguments=[])
23
+ Groonga::Command::Suggest.new("suggest",
24
+ pair_arguments,
25
+ ordered_arguments)
26
+ end
22
27
 
28
+ class ConstructorTest < self
23
29
  def test_ordered_arguments
24
- types = "complete"
25
- table = "Users"
26
- column = "name"
27
- query = "name:@ Ali"
28
- sortby = "_score"
29
- output_columns = "name"
30
- offset = "0"
31
- limit = "5"
32
- frequency_threshold = "120"
30
+ types = "complete"
31
+ table = "Users"
32
+ column = "name"
33
+ query = "name:@ Ali"
34
+ sortby = "_score"
35
+ output_columns = "name"
36
+ offset = "0"
37
+ limit = "5"
38
+ frequency_threshold = "120"
33
39
  conditional_probability_threshold = "0.3"
34
- prefix_search = "yes"
35
- similar_search = "yes"
40
+ prefix_search = "yes"
41
+ similar_search = "yes"
36
42
 
37
- arguments = [
38
- types, table, column, query, sortby, output_columns,
39
- offset, limit, frequency_threshold,
43
+ ordered_arguments = [
44
+ types,
45
+ table,
46
+ column,
47
+ query,
48
+ sortby,
49
+ output_columns,
50
+ offset,
51
+ limit,
52
+ frequency_threshold,
40
53
  conditional_probability_threshold,
41
- prefix_search, similar_search
54
+ prefix_search,
55
+ similar_search
42
56
  ]
43
- command = parse(*arguments)
44
- assert_instance_of(Groonga::Command::Suggest, command)
57
+ command = suggest_command({}, ordered_arguments)
45
58
 
46
59
  expected_arguments = {
47
- :types => types,
48
- :table => table,
49
- :column => column,
50
- :query => query,
51
- :sortby => sortby,
52
- :output_columns => output_columns,
53
- :offset => offset,
54
- :limit => limit,
55
- :frequency_threshold => frequency_threshold,
60
+ :types => types,
61
+ :table => table,
62
+ :column => column,
63
+ :query => query,
64
+ :sortby => sortby,
65
+ :output_columns => output_columns,
66
+ :offset => offset,
67
+ :limit => limit,
68
+ :frequency_threshold => frequency_threshold,
56
69
  :conditional_probability_threshold => conditional_probability_threshold,
57
- :prefix_search => prefix_search,
58
- :similar_search => similar_search
70
+ :prefix_search => prefix_search,
71
+ :similar_search => similar_search
59
72
  }
60
73
  assert_equal(expected_arguments, command.arguments)
61
74
  end
62
-
63
- private
64
- def parse(*arguments)
65
- super("suggest", arguments, :output_type => false)
66
- end
67
75
  end
68
76
  end
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -17,9 +17,14 @@
17
17
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
 
19
19
  class TableCreateCommandTest < Test::Unit::TestCase
20
- class CommandLineTest < self
21
- include GroongaCommandTestUtils::CommandLineCommandParser
20
+ private
21
+ def table_create_command(pair_arguments={}, ordered_arguments=[])
22
+ Groonga::Command::TableCreate.new("table_create",
23
+ pair_arguments,
24
+ ordered_arguments)
25
+ end
22
26
 
27
+ class ConstructorTest < self
23
28
  def test_ordered_arguments
24
29
  name = "Users"
25
30
  flags = "TABLE_PAT_KEY"
@@ -28,8 +33,15 @@ class TableCreateCommandTest < Test::Unit::TestCase
28
33
  default_tokenizer = "TokenBigram"
29
34
  normalizer = "NormalizerAuto"
30
35
 
31
- command = parse([name, flags, key_type, value_type, default_tokenizer, normalizer])
32
- assert_instance_of(Groonga::Command::TableCreate, command)
36
+ ordered_arguments = [
37
+ name,
38
+ flags,
39
+ key_type,
40
+ value_type,
41
+ default_tokenizer,
42
+ normalizer,
43
+ ]
44
+ command = table_create_command({}, ordered_arguments)
33
45
  assert_equal({
34
46
  :name => name,
35
47
  :flags => flags,
@@ -40,105 +52,100 @@ class TableCreateCommandTest < Test::Unit::TestCase
40
52
  },
41
53
  command.arguments)
42
54
  end
55
+ end
43
56
 
44
- private
45
- def parse(arguments)
46
- super("table_create", arguments, :output_type => false)
57
+ class FlagsTest < self
58
+ def test_multiple
59
+ command = table_create_command({"flags" => "TABLE_PAT_KEY|KEY_WITH_SIS"})
60
+ assert_equal(["TABLE_PAT_KEY", "KEY_WITH_SIS"],
61
+ command.flags)
47
62
  end
48
63
 
49
- class FlagsTest < self
50
- def test_multiple
51
- command = parse({"flags" => "TABLE_PAT_KEY|KEY_WITH_SIS"})
52
- assert_equal(["TABLE_PAT_KEY", "KEY_WITH_SIS"],
53
- command.flags)
54
- end
64
+ def test_one
65
+ command = table_create_command({"flags" => "TABLE_NO_KEY"})
66
+ assert_equal(["TABLE_NO_KEY"],
67
+ command.flags)
68
+ end
55
69
 
56
- def test_one
57
- command = parse({"flags" => "TABLE_NO_KEY"})
58
- assert_equal(["TABLE_NO_KEY"],
59
- command.flags)
60
- end
70
+ def test_no_flags
71
+ command = table_create_command
72
+ assert_equal([], command.flags)
73
+ end
61
74
 
62
- def test_no_flags
63
- command = parse({})
64
- assert_equal([], command.flags)
75
+ class PredicateTest < self
76
+ data({
77
+ "TABLE_NO_KEY" => {
78
+ :expected => true,
79
+ :flags => "TABLE_NO_KEY",
80
+ },
81
+ "other flag" => {
82
+ :expected => false,
83
+ :flags => "TABLE_HASH_KEY",
84
+ }
85
+ })
86
+ def test_table_no_key?(data)
87
+ command = table_create_command({"flags" => data[:flags]})
88
+ assert_equal(data[:expected], command.table_no_key?)
65
89
  end
66
90
 
67
- class PredicateTest < self
68
- data({
69
- "TABLE_NO_KEY" => {
70
- :expected => true,
71
- :flags => "TABLE_NO_KEY",
72
- },
73
- "other flag" => {
74
- :expected => false,
75
- :flags => "TABLE_HASH_KEY",
76
- }
77
- })
78
- def test_table_no_key?(data)
79
- command = parse({"flags" => data[:flags]})
80
- assert_equal(data[:expected], command.table_no_key?)
81
- end
82
-
83
- data({
84
- "TABLE_HASH_KEY" => {
85
- :expected => true,
86
- :flags => "TABLE_HASH_KEY",
87
- },
88
- "other flag" => {
89
- :expected => false,
90
- :flags => "TABLE_PAT_KEY",
91
- }
92
- })
93
- def test_table_hash_key?(data)
94
- command = parse({"flags" => data[:flags]})
95
- assert_equal(data[:expected], command.table_hash_key?)
96
- end
91
+ data({
92
+ "TABLE_HASH_KEY" => {
93
+ :expected => true,
94
+ :flags => "TABLE_HASH_KEY",
95
+ },
96
+ "other flag" => {
97
+ :expected => false,
98
+ :flags => "TABLE_PAT_KEY",
99
+ }
100
+ })
101
+ def test_table_hash_key?(data)
102
+ command = table_create_command({"flags" => data[:flags]})
103
+ assert_equal(data[:expected], command.table_hash_key?)
104
+ end
97
105
 
98
- data({
99
- "TABLE_PAT_KEY" => {
100
- :expected => true,
101
- :flags => "TABLE_PAT_KEY",
102
- },
103
- "other flag" => {
104
- :expected => false,
105
- :flags => "TABLE_DAT_KEY",
106
- }
107
- })
108
- def test_table_pat_key?(data)
109
- command = parse({"flags" => data[:flags]})
110
- assert_equal(data[:expected], command.table_pat_key?)
111
- end
106
+ data({
107
+ "TABLE_PAT_KEY" => {
108
+ :expected => true,
109
+ :flags => "TABLE_PAT_KEY",
110
+ },
111
+ "other flag" => {
112
+ :expected => false,
113
+ :flags => "TABLE_DAT_KEY",
114
+ }
115
+ })
116
+ def test_table_pat_key?(data)
117
+ command = table_create_command({"flags" => data[:flags]})
118
+ assert_equal(data[:expected], command.table_pat_key?)
119
+ end
112
120
 
113
- data({
114
- "TABLE_DAT_KEY" => {
115
- :expected => true,
116
- :flags => "TABLE_DAT_KEY",
117
- },
118
- "other flag" => {
119
- :expected => false,
120
- :flags => "TABLE_NO_KEY",
121
- }
122
- })
123
- def test_table_dat_key?(data)
124
- command = parse({"flags" => data[:flags]})
125
- assert_equal(data[:expected], command.table_dat_key?)
126
- end
121
+ data({
122
+ "TABLE_DAT_KEY" => {
123
+ :expected => true,
124
+ :flags => "TABLE_DAT_KEY",
125
+ },
126
+ "other flag" => {
127
+ :expected => false,
128
+ :flags => "TABLE_NO_KEY",
129
+ }
130
+ })
131
+ def test_table_dat_key?(data)
132
+ command = table_create_command({"flags" => data[:flags]})
133
+ assert_equal(data[:expected], command.table_dat_key?)
134
+ end
127
135
 
128
- data({
129
- "KEY_WITH_SIS" => {
130
- :expected => true,
131
- :flags => "KEY_WITH_SIS|TABLE_PAT_KEY",
132
- },
133
- "other flag" => {
134
- :expected => false,
135
- :flags => "TABLE_NO_KEY",
136
- }
137
- })
138
- def test_key_with_sis?(data)
139
- command = parse({"flags" => data[:flags]})
140
- assert_equal(data[:expected], command.key_with_sis?)
141
- end
136
+ data({
137
+ "KEY_WITH_SIS" => {
138
+ :expected => true,
139
+ :flags => "KEY_WITH_SIS|TABLE_PAT_KEY",
140
+ },
141
+ "other flag" => {
142
+ :expected => false,
143
+ :flags => "TABLE_NO_KEY",
144
+ }
145
+ })
146
+ def test_key_with_sis?(data)
147
+ command = table_create_command({"flags" => data[:flags]})
148
+ assert_equal(data[:expected], command.key_with_sis?)
142
149
  end
143
150
  end
144
151
  end
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -17,23 +17,22 @@
17
17
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
 
19
19
  class TableRemoveCommandTest < Test::Unit::TestCase
20
- class CommandLineTest < self
21
- include GroongaCommandTestUtils::CommandLineCommandParser
20
+ private
21
+ def table_remove_command(pair_arguments={}, ordered_arguments=[])
22
+ Groonga::Command::TableRemove.new("table_remove",
23
+ pair_arguments,
24
+ ordered_arguments)
25
+ end
22
26
 
27
+ class ConstructorTest < self
23
28
  def test_ordered_arguments
24
29
  name = "Users"
25
30
 
26
- command = parse(name)
27
- assert_instance_of(Groonga::Command::TableRemove, command)
31
+ command = table_remove_command({}, [name])
28
32
  assert_equal({
29
33
  :name => name,
30
34
  },
31
35
  command.arguments)
32
36
  end
33
-
34
- private
35
- def parse(*arguments)
36
- super("table_remove", arguments, :output_type => false)
37
- end
38
37
  end
39
38
  end
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -17,25 +17,24 @@
17
17
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
 
19
19
  class TableRenameCommandTest < Test::Unit::TestCase
20
- class CommandLineTest < self
21
- include GroongaCommandTestUtils::CommandLineCommandParser
20
+ private
21
+ def table_rename_command(pair_arguments={}, ordered_arguments=[])
22
+ Groonga::Command::TableRename.new("table_rename",
23
+ pair_arguments,
24
+ ordered_arguments)
25
+ end
22
26
 
27
+ class ConstructorTest < self
23
28
  def test_ordered_arguments
24
29
  name = "Users"
25
30
  new_name = "People"
26
31
 
27
- command = parse(name, new_name)
28
- assert_instance_of(Groonga::Command::TableRename, command)
32
+ command = table_rename_command({}, [name, new_name])
29
33
  assert_equal({
30
34
  :name => name,
31
35
  :new_name => new_name,
32
36
  },
33
37
  command.arguments)
34
38
  end
35
-
36
- private
37
- def parse(*arguments)
38
- super("table_rename", arguments, :output_type => false)
39
- end
40
39
  end
41
40
  end
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -17,23 +17,22 @@
17
17
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
 
19
19
  class TruncateCommandTest < Test::Unit::TestCase
20
- class CommandLineTest < self
21
- include GroongaCommandTestUtils::CommandLineCommandParser
20
+ private
21
+ def truncate_command(pair_arguments={}, ordered_arguments=[])
22
+ Groonga::Command::Truncate.new("truncate",
23
+ pair_arguments,
24
+ ordered_arguments)
25
+ end
22
26
 
27
+ class ConstructorTest < self
23
28
  def test_ordered_arguments
24
29
  table = "Users"
25
30
 
26
- command = parse(table)
27
- assert_instance_of(Groonga::Command::Truncate, command)
31
+ command = truncate_command([], [table])
28
32
  assert_equal({
29
33
  :table => table,
30
34
  },
31
35
  command.arguments)
32
36
  end
33
-
34
- private
35
- def parse(*arguments)
36
- super("truncate", arguments, :output_type => false)
37
- end
38
37
  end
39
38
  end