rroonga 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/AUTHORS +5 -0
  2. data/Gemfile +1 -12
  3. data/Rakefile +4 -57
  4. data/bin/grndump +11 -1
  5. data/ext/groonga/extconf.rb +125 -54
  6. data/ext/groonga/rb-grn-context.c +25 -7
  7. data/ext/groonga/rb-grn-database.c +25 -0
  8. data/ext/groonga/rb-grn-object.c +19 -7
  9. data/ext/groonga/rb-grn-table.c +8 -10
  10. data/ext/groonga/rb-grn.h +9 -2
  11. data/lib/groonga/dumper.rb +2 -2
  12. data/lib/groonga/expression-builder.rb +33 -18
  13. data/rroonga-build.rb +1 -1
  14. metadata +97 -180
  15. data/TODO +0 -0
  16. data/test/groonga-test-utils.rb +0 -139
  17. data/test/run-test.rb +0 -60
  18. data/test/test-accessor.rb +0 -36
  19. data/test/test-array.rb +0 -123
  20. data/test/test-column.rb +0 -350
  21. data/test/test-command-select.rb +0 -147
  22. data/test/test-context.rb +0 -130
  23. data/test/test-database-dumper.rb +0 -259
  24. data/test/test-database.rb +0 -148
  25. data/test/test-double-array-trie.rb +0 -164
  26. data/test/test-encoding.rb +0 -33
  27. data/test/test-exception.rb +0 -96
  28. data/test/test-expression-builder.rb +0 -269
  29. data/test/test-expression.rb +0 -134
  30. data/test/test-fix-size-column.rb +0 -77
  31. data/test/test-gqtp.rb +0 -70
  32. data/test/test-hash.rb +0 -344
  33. data/test/test-index-column.rb +0 -180
  34. data/test/test-index-cursor.rb +0 -93
  35. data/test/test-logger.rb +0 -37
  36. data/test/test-pagination.rb +0 -249
  37. data/test/test-patricia-trie.rb +0 -415
  38. data/test/test-plugin.rb +0 -35
  39. data/test/test-procedure.rb +0 -37
  40. data/test/test-query-log.rb +0 -258
  41. data/test/test-record.rb +0 -569
  42. data/test/test-remote.rb +0 -63
  43. data/test/test-schema-create-table.rb +0 -267
  44. data/test/test-schema-dumper.rb +0 -235
  45. data/test/test-schema-type.rb +0 -208
  46. data/test/test-schema-view.rb +0 -90
  47. data/test/test-schema.rb +0 -886
  48. data/test/test-snippet.rb +0 -130
  49. data/test/test-table-cursor.rb +0 -187
  50. data/test/test-table-dumper.rb +0 -83
  51. data/test/test-table-offset-and-limit.rb +0 -100
  52. data/test/test-table-select-mecab.rb +0 -80
  53. data/test/test-table-select-normalize.rb +0 -57
  54. data/test/test-table-select-weight.rb +0 -123
  55. data/test/test-table-select.rb +0 -191
  56. data/test/test-table.rb +0 -675
  57. data/test/test-type.rb +0 -79
  58. data/test/test-variable-size-column.rb +0 -147
  59. data/test/test-variable.rb +0 -28
  60. data/test/test-vector-column.rb +0 -76
  61. data/test/test-version.rb +0 -61
  62. data/test/test-view.rb +0 -72
@@ -1,134 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2009-2011 Kouhei Sutou <kou@clear-code.com>
4
- #
5
- # This library is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU Lesser General Public
7
- # License version 2.1 as published by the Free Software Foundation.
8
- #
9
- # This library is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- # Lesser General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU Lesser General Public
15
- # License along with this library; if not, write to the Free Software
16
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
-
18
- class ExpressionTest < Test::Unit::TestCase
19
- include GroongaTestUtils
20
-
21
- setup :setup_database
22
-
23
- def test_array_reference
24
- expression = Groonga::Expression.new
25
- ryoqun = expression.define_variable({:name => "user"})
26
- ryoqun.value = "ryoqun"
27
- mori = expression.define_variable
28
- mori.value = "mori"
29
-
30
- expression.append_object(ryoqun)
31
- expression.append_object(mori)
32
-
33
- assert_equal("ryoqun", expression["user"])
34
- assert_equal("ryoqun", expression[0])
35
- assert_equal("mori", expression[1])
36
- end
37
-
38
- def test_get_value
39
- users = Groonga::Hash.create(:name => "Users")
40
- name = users.define_column("name", "ShortText")
41
-
42
- morita = users.add("morita", :name => "mori daijiro")
43
-
44
- expression = Groonga::Expression.new
45
- expression.append_constant(morita)
46
- expression.append_constant("name")
47
- expression.append_operation(Groonga::Operation::GET_VALUE, 2)
48
- expression.compile
49
- assert_equal("mori daijiro", expression.execute)
50
- end
51
-
52
- def test_get_value_with_variable
53
- users = Groonga::Hash.create(:name => "Users")
54
- name = users.define_column("name", "ShortText")
55
-
56
- morita = users.add("morita", :name => "mori daijiro")
57
- gunyara_kun = users.add("gunyara-kun", :name => "Tasuku SUENAGA")
58
-
59
- expression = Groonga::Expression.new
60
- variable = expression.define_variable
61
- variable.value = morita
62
- expression.append_object(variable)
63
- expression.append_constant("name")
64
- expression.append_operation(Groonga::Operation::GET_VALUE, 2)
65
- expression.compile
66
- assert_equal("mori daijiro", expression.execute)
67
-
68
- variable.value = gunyara_kun.id
69
- assert_equal("Tasuku SUENAGA", expression.execute)
70
- end
71
-
72
- def test_inspect
73
- expression = Groonga::Expression.new
74
- expression.append_constant(1)
75
- expression.append_constant(1)
76
- expression.append_operation(Groonga::Operation::PLUS, 2)
77
- expression.compile
78
-
79
- assert_equal("#<Groonga::Expression noname(){21,01,0PLUS}>",
80
- expression.inspect)
81
- end
82
-
83
- def test_snippet
84
- users = Groonga::Array.create(:name => "Users")
85
- users.define_column("name", "ShortText")
86
- Groonga::Hash.create(:name => "Terms",
87
- :key_type => "ShortText",
88
- :default_tokenizer => "TokenBigram")
89
- users.define_index_column("user_name", users,
90
- :source => "Users.name",
91
- :with_position => true)
92
-
93
- expression = Groonga::Expression.new
94
- variable = expression.define_variable(:domain => users)
95
- expression.append_object(variable)
96
- expression.parse("ラングバ OR Ruby OR groonga", :default_column => name)
97
- expression.compile
98
-
99
- snippet = expression.snippet([["[[", "]]"], ["<", ">"]],
100
- :width => 30)
101
- assert_equal(["[[ラングバ]]プロジェクト",
102
- "ン[[groonga]]の機能を<Ruby>か",
103
- "。[[groonga]]の機能を<Ruby>ら"],
104
- snippet.execute("ラングバプロジェクトはカラムストア機能も" +
105
- "備える高速・高機能な全文検索エンジンgroonga" +
106
- "の機能をRubyから利用するためのライブラリを" +
107
- "提供するプロジェクトです。groongaの機能を" +
108
- "Rubyらしい読み書きしやすい構文で利用できる" +
109
- "ことが利点です。"))
110
- snippet.close
111
- end
112
-
113
- def test_snippet_without_tags
114
- users = Groonga::Array.create(:name => "Users")
115
- users.define_column("name", "ShortText")
116
- Groonga::Hash.create(:name => "Terms",
117
- :key_type => "ShortText",
118
- :default_tokenizer => "TokenBigram")
119
- users.define_index_column("user_name", users,
120
- :source => "Users.name",
121
- :with_position => true)
122
-
123
- expression = Groonga::Expression.new
124
- variable = expression.define_variable(:domain => users)
125
- expression.append_object(variable)
126
- expression.parse("ラングバ", :default_column => name)
127
- expression.compile
128
-
129
- snippet = expression.snippet([], :width => 30)
130
- assert_equal(["ラングバプロジェクト"],
131
- snippet.execute("ラングバプロジェクトはカラムストア機能も"))
132
- snippet.close
133
- end
134
- end
@@ -1,77 +0,0 @@
1
- # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
2
- #
3
- # This library is free software; you can redistribute it and/or
4
- # modify it under the terms of the GNU Lesser General Public
5
- # License version 2.1 as published by the Free Software Foundation.
6
- #
7
- # This library is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
- # Lesser General Public License for more details.
11
- #
12
- # You should have received a copy of the GNU Lesser General Public
13
- # License along with this library; if not, write to the Free Software
14
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
-
16
- class FixSizeColumnTest < Test::Unit::TestCase
17
- include GroongaTestUtils
18
-
19
- def setup
20
- setup_database
21
-
22
- setup_bookmarks_table
23
- end
24
-
25
- def setup_bookmarks_table
26
- @bookmarks_path = @tables_dir + "bookmarks"
27
- @bookmarks = Groonga::Array.create(:name => "Bookmarks",
28
- :path => @bookmarks_path.to_s)
29
-
30
- @viewed_column_path = @columns_dir + "viewed"
31
- @viewed = @bookmarks.define_column("viewed", "Int32",
32
- :path => @viewed_column_path.to_s)
33
- end
34
-
35
- def test_index?
36
- assert_not_predicate(@viewed, :index?)
37
- end
38
-
39
- def test_vector?
40
- assert_not_predicate(@viewed, :vector?)
41
- end
42
-
43
- def test_scalar?
44
- assert_predicate(@viewed, :scalar?)
45
- end
46
-
47
- def test_inspect
48
- assert_equal("#<Groonga::FixSizeColumn " +
49
- "id: <#{@viewed.id}>, " +
50
- "name: <Bookmarks.viewed>, " +
51
- "path: <#{@viewed_column_path}>, " +
52
- "domain: <Bookmarks>, " +
53
- "range: <Int32>, " +
54
- "flags: <KEY_INT>" +
55
- ">",
56
- @viewed.inspect)
57
- end
58
-
59
- def test_domain
60
- assert_equal(@bookmarks, @viewed.domain)
61
- end
62
-
63
- def test_table
64
- assert_equal(@bookmarks, @viewed.table)
65
- end
66
-
67
- def test_assign_time
68
- comments = Groonga::Array.create(:name => "Comments")
69
- comments.define_column("title", "ShortText")
70
- comments.define_column("issued", "Time")
71
- title = "Good"
72
- issued = 1187430026
73
- record = comments.add(:title => title, :issued => issued)
74
- assert_equal([title, Time.at(issued)],
75
- [record["title"], record["issued"]])
76
- end
77
- end
data/test/test-gqtp.rb DELETED
@@ -1,70 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2010-2011 Kouhei Sutou <kou@clear-code.com>
4
- #
5
- # This library is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU Lesser General Public
7
- # License version 2.1 as published by the Free Software Foundation.
8
- #
9
- # This library is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- # Lesser General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU Lesser General Public
15
- # License along with this library; if not, write to the Free Software
16
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
-
18
- class GQTPTest < Test::Unit::TestCase
19
- include GroongaTestUtils
20
-
21
- setup :setup_database
22
-
23
- setup
24
- def setup_comments
25
- @users = Groonga::Hash.create(:name => "Users", :key_type => "ShortText")
26
-
27
- @comments = Groonga::Array.create(:name => "Comments")
28
- @comments.define_column("content", "Text")
29
- @comments.define_column("created_at", "Time")
30
- @comments.define_column("user", "Users")
31
-
32
- terms = Groonga::PatriciaTrie.create(:name => "Terms",
33
- :default_tokenizer => "TokenBigram")
34
- terms.define_index_column("comment_content", @comments,
35
- :with_section => true,
36
- :source => "content")
37
- @comment1 = @comments.add(:content => "Hello Good-bye!",
38
- :created_at => Time.parse("2009-08-09"),
39
- :user => "morita")
40
- @comment2 = @comments.add(:content => "Hello World",
41
- :created_at => Time.parse("2009-07-09"),
42
- :user => "")
43
- @comment3 = @comments.add(:content => "test",
44
- :created_at => Time.parse("2009-06-09"),
45
- :user => "gunyara-kun")
46
- @japanese_comment =
47
- @comments.add(:content => "うちのボロTVはまだ現役です",
48
- :created_at => Time.parse("2009-06-09"),
49
- :user => "darashi")
50
- end
51
-
52
- def test_select_filter_by_existent_user
53
- assert_equal([[[1], [["user", "Users"]], ["darashi"]]],
54
- process("select Comments --output_columns user " +
55
- "--filter 'user == \"darashi\"'"))
56
- end
57
-
58
- def test_select_filter_by_nonexistent_user
59
- assert_equal([[[0], [["user", "Users"]]]],
60
- process("select Comments --output_columns user " +
61
- "--filter 'user == \"yu\"'"))
62
- end
63
-
64
- private
65
- def process(gqtp)
66
- context.send(gqtp)
67
- _, result = context.receive
68
- JSON.parse(result)
69
- end
70
- end
data/test/test-hash.rb DELETED
@@ -1,344 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2009-2011 Kouhei Sutou <kou@clear-code.com>
4
- #
5
- # This library is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU Lesser General Public
7
- # License version 2.1 as published by the Free Software Foundation.
8
- #
9
- # This library is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- # Lesser General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU Lesser General Public
15
- # License along with this library; if not, write to the Free Software
16
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
-
18
- class HashTest < Test::Unit::TestCase
19
- include GroongaTestUtils
20
-
21
- setup :setup_database
22
-
23
- def test_support_key?
24
- assert_predicate(Groonga::Hash.create(:name => "Users",
25
- :key_type => "ShortText"),
26
- :support_key?)
27
- end
28
-
29
- def test_delete
30
- bookmarks_path = @tables_dir + "bookmarks"
31
- bookmarks = Groonga::Hash.create(:name => "Bookmarks",
32
- :path => bookmarks_path.to_s)
33
-
34
- bookmarks.add("groonga")
35
- google = bookmarks.add("Google")
36
- cutter = bookmarks.add("Cutter")
37
-
38
- assert_equal(["groonga", "Google", "Cutter"],
39
- bookmarks.collect {|bookmark| bookmark.key})
40
-
41
- bookmarks.delete(google.id)
42
- assert_equal(["groonga", "Cutter"],
43
- bookmarks.collect {|bookmark| bookmark.key})
44
-
45
- bookmarks.delete(cutter.key)
46
- assert_equal(["groonga"],
47
- bookmarks.collect {|bookmark| bookmark.key})
48
- end
49
-
50
- def test_value
51
- bookmarks_path = @tables_dir + "bookmarks"
52
- bookmarks = Groonga::Hash.create(:name => "Bookmarks",
53
- :path => bookmarks_path.to_s,
54
- :key_type => "ShortText",
55
- :value_type => "UInt32")
56
- bookmarks.set_value("http://google.com/", 29)
57
- assert_equal(29, bookmarks.value("http://google.com/"))
58
- end
59
-
60
- def test_column_value
61
- bookmarks_path = @tables_dir + "bookmarks"
62
- bookmarks = Groonga::Hash.create(:name => "Bookmarks",
63
- :path => bookmarks_path.to_s,
64
- :key_type => "ShortText")
65
- bookmarks.define_column("uri", "ShortText")
66
- bookmarks.set_column_value("google", "uri", "http://google.com/")
67
- assert_equal("http://google.com/", bookmarks.column_value("google", "uri"))
68
- end
69
-
70
- def test_array_reference
71
- bookmarks_path = @tables_dir + "bookmarks"
72
- bookmarks = Groonga::Hash.create(:name => "bookmarks",
73
- :path => bookmarks_path.to_s,
74
- :key_type => "ShortText")
75
- bookmark = bookmarks.add("http://google.com/")
76
- assert_equal(bookmark, bookmarks["http://google.com/"])
77
- end
78
-
79
- def test_inspect_anonymous
80
- path = @tables_dir + "anoymous.groonga"
81
- anonymous_table = Groonga::Hash.create(:path => path.to_s)
82
- assert_equal("#<Groonga::Hash " +
83
- "id: <#{anonymous_table.id}>, " +
84
- "name: (anonymous), " +
85
- "path: <#{path}>, " +
86
- "domain: <ShortText>, " +
87
- "range: (nil), " +
88
- "flags: <>, " +
89
- "encoding: <#{encoding.inspect}>, " +
90
- "size: <0>>",
91
- anonymous_table.inspect)
92
- end
93
-
94
- def test_inspect_anonymous_temporary
95
- anonymous_table = Groonga::Hash.create
96
- assert_equal("#<Groonga::Hash " +
97
- "id: <#{anonymous_table.id}>, " +
98
- "name: (anonymous), " +
99
- "path: (temporary), " +
100
- "domain: <ShortText>, " +
101
- "range: (nil), " +
102
- "flags: <>, " +
103
- "encoding: <#{encoding.inspect}>, " +
104
- "size: <0>>",
105
- anonymous_table.inspect)
106
- end
107
-
108
- def test_inspect_named
109
- path = @tables_dir + "named.groonga"
110
- named_table = Groonga::Hash.create(:name => "Users", :path => path.to_s)
111
- assert_equal("#<Groonga::Hash " +
112
- "id: <#{named_table.id}>, " +
113
- "name: <Users>, " +
114
- "path: <#{path}>, " +
115
- "domain: <ShortText>, " +
116
- "range: (nil), " +
117
- "flags: <>, " +
118
- "encoding: <#{encoding.inspect}>, " +
119
- "size: <0>>",
120
- named_table.inspect)
121
- end
122
-
123
- def test_inspect_temporary
124
- named_table = Groonga::Hash.create
125
- assert_equal("#<Groonga::Hash " +
126
- "id: <#{named_table.id}>, " +
127
- "name: (anonymous), " +
128
- "path: (temporary), " +
129
- "domain: <ShortText>, " +
130
- "range: (nil), " +
131
- "flags: <>, " +
132
- "encoding: <#{encoding.inspect}>, " +
133
- "size: <0>>",
134
- named_table.inspect)
135
- end
136
-
137
- def test_encoding
138
- assert_equal(Groonga::Encoding.default,
139
- Groonga::Hash.create.encoding)
140
- end
141
-
142
- def test_tokenizer
143
- hash = Groonga::Hash.create
144
- assert_nil(hash.default_tokenizer)
145
- hash.default_tokenizer = "TokenBigram"
146
- assert_equal(Groonga::Context.default["TokenBigram"],
147
- hash.default_tokenizer)
148
- end
149
-
150
- def test_search
151
- users = Groonga::Array.create(:name => "Users")
152
- users.define_column("name", "ShortText")
153
-
154
- bookmarks = Groonga::Hash.create(:name => "Bookmarks",
155
- :key_type => "ShortText")
156
- bookmarks.define_column("user_id", users)
157
-
158
- daijiro = users.add
159
- daijiro["name"] = "daijiro"
160
- gunyarakun = users.add
161
- gunyarakun["name"] = "gunyarakun"
162
-
163
- groonga = bookmarks.add("http://groonga.org/")
164
- groonga["user_id"] = daijiro
165
-
166
- records = bookmarks.search("http://groonga.org/")
167
- assert_equal(["daijiro"],
168
- records.records.collect {|record| record["user_id.name"]})
169
- end
170
-
171
- def test_add
172
- users = Groonga::Hash.create(:name => "Users")
173
- users.define_column("address", "Text")
174
- me = users.add("me", :address => "me@example.com")
175
- assert_equal("me@example.com", me[:address])
176
- end
177
-
178
- def test_default_tokenizer_on_create
179
- terms = Groonga::Hash.create(:name => "Terms",
180
- :default_tokenizer => "TokenTrigram")
181
- assert_equal(context[Groonga::Type::TRIGRAM],
182
- terms.default_tokenizer)
183
- end
184
-
185
- def test_duplicated_name
186
- Groonga::Hash.create(:name => "Users")
187
- assert_raise(Groonga::InvalidArgument) do
188
- Groonga::Hash.create(:name => "Users")
189
- end
190
- end
191
-
192
- def test_define_index_column_implicit_with_position
193
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
194
- bookmarks.define_column("comment", "Text")
195
- terms = Groonga::Hash.create(:name => "Terms",
196
- :default_tokenizer => "TokenBigram")
197
- index = terms.define_index_column("comment", bookmarks,
198
- :source => "Bookmarks.comment")
199
- bookmarks.add("groonga", :comment => "search engine by Brazil")
200
- bookmarks.add("google", :comment => "search engine by Google")
201
- bookmarks.add("ruby", :comment => "programing language")
202
-
203
- assert_equal(["groonga", "google"],
204
- index.search("engine").collect {|record| record.key.key})
205
- end
206
-
207
- def test_has_key?
208
- users = Groonga::Hash.create(:name => "Users")
209
- assert_false(users.has_key?("morita"))
210
- users.add("morita")
211
- assert_true(users.has_key?("morita"))
212
- end
213
-
214
- def test_big_key
215
- hash = Groonga::Hash.create(:key_type => "UInt64")
216
- assert_nothing_raised do
217
- hash.add(1 << 63)
218
- end
219
- end
220
-
221
- def test_value_by_key
222
- users = Groonga::Hash.create(:key_type => "ShortText",
223
- :value_type => "Int32")
224
- key = "niku"
225
- users.add(key)
226
- users.set_value(key, 29)
227
- assert_equal(29, users.value(key))
228
- end
229
-
230
- def test_value_by_id
231
- users = Groonga::Hash.create(:key_type => "ShortText",
232
- :value_type => "Int32")
233
- user_id = users.add("niku").id
234
- users.set_value(user_id, 29, :id => true)
235
- assert_equal(29, users.value(user_id, :id => true))
236
- end
237
-
238
- def test_id
239
- users = Groonga::Hash.create(:key_type => "ShortText")
240
-
241
- key = "niku"
242
- assert_nil(users.id(key))
243
- user_id = users.add(key).id
244
- assert_equal(user_id, users.id(key))
245
- end
246
-
247
- def test_set_multi_values
248
- users = Groonga::Hash.create(:name => "Users",
249
- :key_type => "ShortText")
250
- users.define_column("self_introduction", "ShortText")
251
- users.define_column("age", "UInt32")
252
-
253
- key = "niku"
254
- niku = users.add(key)
255
- assert_equal({
256
- "_id" => niku.id,
257
- "_key" => key,
258
- "self_introduction" => nil,
259
- "age" => 0,
260
- },
261
- niku.attributes)
262
- users[key] = {
263
- "self_introduction" => "I'm a meet lover.",
264
- "age" => 29
265
- }
266
- assert_equal({
267
- "_id" => niku.id,
268
- "_key" => key,
269
- "self_introduction" => "I'm a meet lover.",
270
- "age" => 29,
271
- },
272
- niku.attributes)
273
- end
274
-
275
- def test_set_multi_values_for_nonexistent_record
276
- users = Groonga::Hash.create(:name => "Users",
277
- :key_type => "ShortText")
278
- users.define_column("self_introduction", "ShortText")
279
- users.define_column("age", "UInt32")
280
-
281
- key = "niku"
282
- users[key] = {
283
- "self_introduction" => "I'm a meet lover.",
284
- "age" => 29
285
- }
286
-
287
- assert_equal({
288
- "_id" => users[key].id,
289
- "_key" => key,
290
- "self_introduction" => "I'm a meet lover.",
291
- "age" => 29,
292
- },
293
- users[key].attributes)
294
- end
295
-
296
- def test_set_multi_values_with_nonexistent_column
297
- users = Groonga::Hash.create(:name => "Users",
298
- :key_type => "ShortText")
299
- users.define_column("self_introduction", "ShortText")
300
- users.define_column("age", "UInt32")
301
-
302
- key = "niku"
303
- inspected_users = users.inspect.sub(/size: <0>/, "size: <1>")
304
- message = "no such column: <\"nonexistent\">: <#{inspected_users}>"
305
- assert_raise(Groonga::NoSuchColumn.new(message)) do
306
- users[key] = {
307
- "nonexistent" => "No!",
308
- }
309
- end
310
- end
311
-
312
- def test_added?
313
- users = Groonga::Hash.create(:name => "Users",
314
- :key_type => "ShortText")
315
- bob = users.add("bob")
316
- assert_predicate(bob, :added?)
317
- bob_again = users.add("bob")
318
- assert_not_predicate(bob_again, :added?)
319
- end
320
-
321
- def test_defrag
322
- users = Groonga::Hash.create(:name => "Users",
323
- :key_type => "ShortText")
324
- users.define_column("name", "ShortText")
325
- users.define_column("address", "ShortText")
326
- 1000.times do |i|
327
- users.add("user #{i}",
328
- :name => "user #{i}" * 1000,
329
- :address => "address #{i}" * 1000)
330
- end
331
- assert_equal(7, users.defrag)
332
- end
333
-
334
- def test_rename
335
- users = Groonga::Hash.create(:name => "Users",
336
- :key_type => "ShortText")
337
- name = users.define_column("name", "ShortText")
338
- address = users.define_column("address", "ShortText")
339
-
340
- users.rename("People")
341
- assert_equal(["People", "People.name", "People.address"],
342
- [users.name, name.name, address.name])
343
- end
344
- end