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
data/test/test-table.rb DELETED
@@ -1,675 +0,0 @@
1
- # Copyright (C) 2009-2011 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 TableTest < Test::Unit::TestCase
17
- include GroongaTestUtils
18
-
19
- setup :setup_database
20
-
21
- def test_create
22
- table_path = @tables_dir + "bookmarks"
23
- assert_not_predicate(table_path, :exist?)
24
- table = Groonga::PatriciaTrie.create(:name => "Bookmarks",
25
- :path => table_path.to_s)
26
- assert_equal("Bookmarks", table.name)
27
- assert_predicate(table_path, :exist?)
28
- end
29
-
30
- def test_temporary
31
- table = Groonga::PatriciaTrie.create
32
- assert_nil(table.name)
33
- assert_predicate(table, :temporary?)
34
- assert_not_predicate(table, :persistent?)
35
- assert_equal([], @tables_dir.children)
36
- end
37
-
38
- def test_define_column
39
- table_path = @tables_dir + "bookmarks"
40
- table = Groonga::Hash.create(:name => "Bookmarks",
41
- :path => table_path.to_s)
42
- column = table.define_column("name", "Text")
43
- assert_equal("Bookmarks.name", column.name)
44
- assert_equal(column, table.column("name"))
45
- end
46
-
47
- def test_temporary_table_define_column_default_persistent
48
- table = Groonga::Hash.create
49
- assert_raise(Groonga::InvalidArgument) do
50
- table.define_column("name", "ShortText")
51
- end
52
- end
53
-
54
- def test_temporary_table_define_index_column_default_persistent
55
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
56
- terms = Groonga::Hash.create
57
- assert_raise(Groonga::InvalidArgument) do
58
- terms.define_index_column("url", bookmarks)
59
- end
60
- end
61
-
62
- def test_define_column_default_persistent
63
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
64
- real_name = bookmarks.define_column("real_name", "ShortText")
65
- assert_predicate(real_name, :persistent?)
66
- end
67
-
68
- def test_define_column_not_persistent
69
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
70
- real_name = bookmarks.define_column("real_name", "ShortText",
71
- :persistent => false)
72
- assert_predicate(real_name, :temporary?)
73
- end
74
-
75
- def test_define_column_not_persistent_and_path
76
- column_path = @tables_dir + "bookmakrs.real_name.column"
77
-
78
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
79
- message = "should not pass :path if :persistent is false: <#{column_path}>"
80
- assert_raise(ArgumentError.new(message)) do
81
- bookmarks.define_column("real_name", "ShortText",
82
- :path => column_path.to_s,
83
- :persistent => false)
84
- end
85
- end
86
-
87
- def test_define_index_column_default_persistent
88
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
89
- terms = Groonga::Hash.create(:name => "Terms")
90
- real_name = terms.define_index_column("real_name", bookmarks)
91
- assert_predicate(real_name, :persistent?)
92
- end
93
-
94
- def test_define_index_column_not_persistent
95
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
96
- terms = Groonga::Hash.create(:name => "Terms")
97
- real_name = terms.define_index_column("real_name", bookmarks,
98
- :persistent => false)
99
- assert_predicate(real_name, :temporary?)
100
- end
101
-
102
- def test_define_index_column_not_persistent_and_path
103
- column_path = @tables_dir + "bookmakrs.real_name.column"
104
-
105
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
106
- terms = Groonga::Hash.create(:name => "Terms")
107
- message = "should not pass :path if :persistent is false: <#{column_path}>"
108
- assert_raise(ArgumentError.new(message)) do
109
- terms.define_index_column("real_name", bookmarks,
110
- :path => column_path.to_s,
111
- :persistent => false)
112
- end
113
- end
114
-
115
- def test_define_index_column
116
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
117
- bookmarks.define_column("content", "Text")
118
- terms = Groonga::Hash.create(:name => "Terms")
119
- terms.default_tokenizer = "TokenBigram"
120
- index = terms.define_index_column("content_index", bookmarks,
121
- :with_section => true,
122
- :source => "Bookmarks.content")
123
- bookmarks.add("google", :content => "Search engine")
124
- assert_equal(["google"],
125
- index.search("engine").collect {|record| record.key.key})
126
- end
127
-
128
- def test_column_nonexistent
129
- table_path = @tables_dir + "bookmarks"
130
- table = Groonga::Hash.create(:name => "Bookmarks",
131
- :path => table_path.to_s)
132
- assert_nil(table.column("nonexistent"))
133
- end
134
-
135
- def test_set_value
136
- table_path = @tables_dir + "bookmarks"
137
- bookmarks = Groonga::Hash.create(:name => "Bookmarks",
138
- :value_type => "Int32",
139
- :path => table_path.to_s)
140
- comment_column_path = @columns_dir + "comment"
141
- bookmarks_comment =
142
- bookmarks.define_column("comment", "ShortText",
143
- :type => "scalar",
144
- :path => comment_column_path.to_s)
145
- groonga = bookmarks.add("groonga")
146
- groonga.value = 29
147
- bookmarks_comment[groonga.id] = "fulltext search engine"
148
-
149
- assert_equal([29, "fulltext search engine"],
150
- [groonga.value, bookmarks_comment[groonga.id]])
151
- end
152
-
153
- def test_array_set
154
- bookmarks = Groonga::Hash.create(:name => "Bookmarks",
155
- :value_type => "Int32")
156
- bookmarks.set_value("groonga", 29)
157
-
158
- values = bookmarks.records.collect do |record|
159
- record.value
160
- end
161
- assert_equal([29], values)
162
- end
163
-
164
- def test_add_without_name
165
- users_path = @tables_dir + "users"
166
- users = Groonga::Array.create(:name => "Users",
167
- :path => users_path.to_s)
168
- name_column_path = @columns_dir + "name"
169
- users_name = users.define_column("name", "ShortText",
170
- :path => name_column_path.to_s)
171
- morita = users.add
172
- users_name[morita.id] = "morita"
173
- assert_equal("morita", users_name[morita.id])
174
- end
175
-
176
- def test_add_by_id
177
- users_path = @tables_dir + "users"
178
- users = Groonga::Hash.create(:name => "Users",
179
- :path => users_path.to_s)
180
-
181
- bookmarks_path = @tables_dir + "bookmarks"
182
- bookmarks = Groonga::Hash.create(:name => "Bookmarks",
183
- :key_type => users,
184
- :value_type => "Int32",
185
- :path => bookmarks_path.to_s)
186
- morita = users.add("morita")
187
- groonga = bookmarks.add(morita.id)
188
- groonga.value = 29
189
- assert_equal(29, groonga.value)
190
- end
191
-
192
- def test_columns
193
- bookmarks_path = @tables_dir + "bookmarks"
194
- bookmarks = Groonga::Array.create(:name => "Bookmarks",
195
- :path => bookmarks_path.to_s)
196
-
197
- uri_column = bookmarks.define_column("uri", "ShortText")
198
- comment_column = bookmarks.define_column("comment", "Text")
199
- assert_equal([uri_column.name, comment_column.name].sort,
200
- bookmarks.columns.collect {|column| column.name}.sort)
201
- end
202
-
203
- def test_column_by_symbol
204
- bookmarks_path = @tables_dir + "bookmarks"
205
- bookmarks = Groonga::Array.create(:name => "Bookmarks",
206
- :path => bookmarks_path.to_s)
207
-
208
- uri_column = bookmarks.define_column("uri", "Text")
209
- assert_equal(uri_column, bookmarks.column(:uri))
210
- end
211
-
212
- def test_size
213
- bookmarks_path = @tables_dir + "bookmarks"
214
- bookmarks = Groonga::Array.create(:name => "Bookmarks",
215
- :path => bookmarks_path.to_s)
216
-
217
- assert_equal(0, bookmarks.size)
218
-
219
- bookmarks.add
220
- bookmarks.add
221
- bookmarks.add
222
-
223
- assert_equal(3, bookmarks.size)
224
- end
225
-
226
- def test_empty?
227
- bookmarks_path = @tables_dir + "bookmarks"
228
- bookmarks = Groonga::Array.create(:name => "Bookmarks",
229
- :path => bookmarks_path.to_s)
230
-
231
- assert_predicate(bookmarks, :empty?)
232
- bookmarks.add
233
- assert_not_predicate(bookmarks, :empty?)
234
- end
235
-
236
- def test_path
237
- bookmarks_path = @tables_dir + "bookmarks"
238
- bookmarks = Groonga::Array.create(:name => "Bookmarks",
239
- :path => bookmarks_path.to_s)
240
- assert_equal(bookmarks_path.to_s, bookmarks.path)
241
- end
242
-
243
- def test_time_column
244
- bookmarks_path = @tables_dir + "bookmarks"
245
- bookmarks = Groonga::Array.create(:name => "Bookmarks",
246
- :path => bookmarks_path.to_s)
247
- bookmarks.define_column("created_at", "Time")
248
-
249
- bookmark = bookmarks.add
250
- now = Time.now
251
- bookmark["created_at"] = now
252
- assert_equal(now.to_a,
253
- bookmark["created_at"].to_a)
254
- end
255
-
256
- def test_delete
257
- bookmarks_path = @tables_dir + "bookmarks"
258
- bookmarks = Groonga::Array.create(:name => "Bookmarks",
259
- :path => bookmarks_path.to_s)
260
-
261
- bookmark_records = []
262
- bookmark_records << bookmarks.add
263
- bookmark_records << bookmarks.add
264
- bookmark_records << bookmarks.add
265
-
266
- assert_equal(3, bookmarks.size)
267
- bookmarks.delete(bookmark_records[1].id)
268
- assert_equal(2, bookmarks.size)
269
- end
270
-
271
- def test_remove
272
- bookmarks_path = @tables_dir + "bookmarks"
273
- bookmarks = Groonga::Array.create(:name => "Bookmarks",
274
- :path => bookmarks_path.to_s)
275
- assert_predicate(bookmarks_path, :exist?)
276
- bookmarks.remove
277
- assert_not_predicate(bookmarks_path, :exist?)
278
- end
279
-
280
- def test_temporary_add
281
- table = Groonga::Hash.create(:key_type => "ShortText")
282
- assert_equal(0, table.size)
283
- table.add("key")
284
- assert_equal(1, table.size)
285
- end
286
-
287
- def test_each
288
- users = Groonga::Array.create(:name => "Users")
289
- users.define_column("name", "ShortText")
290
-
291
- names = ["daijiro", "gunyarakun", "yu"]
292
- names.each do |name|
293
- user = users.add
294
- user["name"] = name
295
- end
296
-
297
- assert_equal(names.sort, users.collect {|user| user["name"]}.sort)
298
- end
299
-
300
- def test_truncate
301
- users = Groonga::Array.create(:name => "Users")
302
- users.add
303
- users.add
304
- users.add
305
- assert_equal(3, users.size)
306
- assert_nothing_raised do
307
- users.truncate
308
- end
309
- assert_equal(0, users.size)
310
- end
311
-
312
- def test_sort
313
- bookmarks = create_bookmarks
314
- add_shuffled_ids(bookmarks)
315
-
316
- results = bookmarks.sort([
317
- {
318
- :key => "id",
319
- :order => :descending,
320
- },
321
- ],
322
- :limit => 20)
323
- assert_equal((180..199).to_a.reverse,
324
- results.collect {|record| record["id"]})
325
- end
326
-
327
- def test_sort_simple
328
- bookmarks = create_bookmarks
329
- add_shuffled_ids(bookmarks)
330
-
331
- results = bookmarks.sort(["id"], :limit => 20)
332
- assert_equal((100..119).to_a,
333
- results.collect {|record| record["id"]})
334
- end
335
-
336
- def test_sort_by_array
337
- bookmarks = create_bookmarks
338
- add_shuffled_ids(bookmarks)
339
-
340
- results = bookmarks.sort([["id", "descending"]], :limit => 20)
341
- assert_equal((180..199).to_a.reverse,
342
- results.collect {|record| record["id"]})
343
- end
344
-
345
- def test_sort_without_limit_and_offset
346
- bookmarks = create_bookmarks
347
- add_shuffled_ids(bookmarks)
348
-
349
- results = bookmarks.sort([{:key => "id", :order => :descending}])
350
- assert_equal((100..199).to_a.reverse,
351
- results.collect {|record| record["id"]})
352
- end
353
-
354
- def test_sort_with_limit
355
- bookmarks = create_bookmarks
356
- add_shuffled_ids(bookmarks)
357
-
358
- results = bookmarks.sort([{:key => "id", :order => :descending}],
359
- :limit => 20)
360
- assert_equal((180..199).to_a.reverse,
361
- results.collect {|record| record["id"]})
362
- end
363
-
364
- def test_sort_with_offset
365
- bookmarks = create_bookmarks
366
- add_shuffled_ids(bookmarks)
367
-
368
- results = bookmarks.sort([{:key => "id", :order => :descending}],
369
- :offset => 20)
370
- assert_equal((100..179).to_a.reverse,
371
- results.collect {|record| record["id"]})
372
- end
373
-
374
- def test_sort_with_limit_and_offset
375
- bookmarks = create_bookmarks
376
- add_shuffled_ids(bookmarks)
377
-
378
- results = bookmarks.sort([{:key => "id", :order => :descending}],
379
- :limit => 20, :offset => 20)
380
- assert_equal((160..179).to_a.reverse,
381
- results.collect {|record| record["id"]})
382
- end
383
-
384
- def test_sort_with_nonexistent_key
385
- bookmarks = create_bookmarks
386
- add_shuffled_ids(bookmarks)
387
- message = "no such column: <\"nonexistent\">: <#{bookmarks.inspect}>"
388
- assert_raise(Groonga::NoSuchColumn.new(message)) do
389
- bookmarks.sort([{:key => "nonexistent", :order => :descending}])
390
- end
391
- end
392
-
393
- def test_sort_with_nonexistent_value
394
- bookmarks = create_bookmarks
395
- bookmarks.define_column("uri", "ShortText")
396
- empty1 = bookmarks.add
397
- groonga = bookmarks.add(:uri => "http://groonga.org/")
398
- empty2 = bookmarks.add
399
- assert_equal([groonga, empty1, empty2],
400
- bookmarks.sort([{:key => "uri", :order => :descending}]))
401
- end
402
-
403
- def test_group
404
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
405
- bookmarks.define_column("title", "Text")
406
- comments = Groonga::Array.create(:name => "Comments")
407
- comments.define_column("bookmark", bookmarks)
408
- comments.define_column("content", "Text")
409
- comments.define_column("issued", "Int32")
410
-
411
- groonga = bookmarks.add("http://groonga.org/", :title => "groonga")
412
- ruby = bookmarks.add("http://ruby-lang.org/", :title => "Ruby")
413
-
414
- now = Time.now.to_i
415
- comments.add(:bookmark => groonga,
416
- :content => "full-text search",
417
- :issued => now)
418
- comments.add(:bookmark => groonga,
419
- :content => "column store",
420
- :issued => now)
421
- comments.add(:bookmark => ruby,
422
- :content => "object oriented script language",
423
- :issued => now)
424
-
425
- records = comments.select do |record|
426
- record["issued"] > 0
427
- end
428
- assert_equal([[2, "groonga", "http://groonga.org/"],
429
- [1, "Ruby", "http://ruby-lang.org/"]],
430
- records.group(".bookmark").collect do |record|
431
- bookmark = record.key
432
- [record.n_sub_records,
433
- bookmark["title"],
434
- bookmark.key]
435
- end)
436
- assert_equal([[2, "groonga", "http://groonga.org/"],
437
- [1, "Ruby", "http://ruby-lang.org/"]],
438
- records.group(%w".bookmark").collect do |record|
439
- bookmark = record.key
440
- [record.n_sub_records,
441
- bookmark["title"],
442
- bookmark.key]
443
- end)
444
- end
445
-
446
- def test_group_with_unknown_key
447
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
448
- message = "unknown group key: <\"nonexistent\">: <#{bookmarks.inspect}>"
449
- assert_raise(ArgumentError.new(message)) do
450
- bookmarks.group("nonexistent")
451
- end
452
- end
453
-
454
- def test_union!
455
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
456
- bookmarks.define_column("title", "ShortText")
457
-
458
- bookmarks.add("http://groonga.org/", :title => "groonga")
459
- bookmarks.add("http://ruby-lang.org/", :title => "Ruby")
460
-
461
- ruby_bookmarks = bookmarks.select {|record| record["title"] == "Ruby"}
462
- groonga_bookmarks = bookmarks.select {|record| record["title"] == "groonga"}
463
- assert_equal(["Ruby", "groonga"],
464
- ruby_bookmarks.union!(groonga_bookmarks).collect do |record|
465
- record[".title"]
466
- end)
467
- end
468
-
469
- def test_intersection!
470
- bookmarks = Groonga::Hash.create(:name => "bookmarks")
471
- bookmarks.define_column("title", "ShortText")
472
-
473
- bookmarks.add("http://groonga.org/", :title => "groonga")
474
- bookmarks.add("http://ruby-lang.org/", :title => "Ruby")
475
-
476
- ruby_bookmarks = bookmarks.select {|record| record["title"] == "Ruby"}
477
- all_bookmarks = bookmarks.select
478
- assert_equal(["Ruby"],
479
- ruby_bookmarks.intersection!(all_bookmarks).collect do |record|
480
- record[".title"]
481
- end)
482
- end
483
-
484
- def test_difference!
485
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
486
- bookmarks.define_column("title", "ShortText")
487
-
488
- bookmarks.add("http://groonga.org/", :title => "groonga")
489
- bookmarks.add("http://ruby-lang.org/", :title => "Ruby")
490
-
491
- ruby_bookmarks = bookmarks.select {|record| record["title"] == "Ruby"}
492
- all_bookmarks = bookmarks.select
493
- assert_equal(["groonga"],
494
- all_bookmarks.difference!(ruby_bookmarks).collect do |record|
495
- record[".title"]
496
- end)
497
- end
498
-
499
- def test_merge!
500
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
501
- bookmarks.define_column("title", "ShortText")
502
-
503
- bookmarks.add("http://groonga.org/", :title => "groonga")
504
- bookmarks.add("http://ruby-lang.org/", :title => "Ruby")
505
-
506
- ruby_bookmarks = bookmarks.select {|record| (record["title"] == "Ruby") &
507
- (record["title"] == "Ruby") }
508
- all_bookmarks = bookmarks.select
509
- assert_equal([["groonga", 1], ["Ruby", 2]],
510
- all_bookmarks.merge!(ruby_bookmarks).collect do |record|
511
- [record[".title"], record.score]
512
- end)
513
- end
514
-
515
- def test_lock
516
- bookmarks = Groonga::Array.create(:name => "Bookmarks")
517
- assert_not_predicate(bookmarks, :locked?)
518
- bookmarks.lock
519
- assert_predicate(bookmarks, :locked?)
520
- bookmarks.unlock
521
- assert_not_predicate(bookmarks, :locked?)
522
- end
523
-
524
- def test_lock_failed
525
- bookmarks = Groonga::Array.create(:name => "Bookmarks")
526
- bookmarks.lock
527
- assert_raise(Groonga::ResourceDeadlockAvoided) do
528
- bookmarks.lock
529
- end
530
- end
531
-
532
- def test_lock_block
533
- bookmarks = Groonga::Array.create(:name => "Bookmarks")
534
- assert_not_predicate(bookmarks, :locked?)
535
- bookmarks.lock do
536
- assert_predicate(bookmarks, :locked?)
537
- end
538
- assert_not_predicate(bookmarks, :locked?)
539
- end
540
-
541
- def test_clear_lock
542
- bookmarks = Groonga::Array.create(:name => "Bookmarks")
543
- assert_not_predicate(bookmarks, :locked?)
544
- bookmarks.lock
545
- assert_predicate(bookmarks, :locked?)
546
- bookmarks.clear_lock
547
- assert_not_predicate(bookmarks, :locked?)
548
- end
549
-
550
- def test_auto_record_register
551
- users = Groonga::Hash.create(:name => "Users",
552
- :key_type => "ShortText")
553
- books = Groonga::Hash.create(:name => "Books",
554
- :key_type => "ShortText")
555
- users.define_column("book", "Books")
556
-
557
- assert_equal([], books.select.collect {|book| book.key})
558
- users.add("ryoqun", :book => "XP")
559
- assert_equal([books["XP"]],
560
- books.select.collect {|book| book.key})
561
- end
562
-
563
- def test_get_common_prefix_column
564
- users = Groonga::Array.create(:name => "Users")
565
- users.define_column("name_kana", "ShortText")
566
- name = users.define_column("name", "ShortText")
567
-
568
- assert_equal(name, users.column("name"))
569
- end
570
-
571
- def test_empty_reference_column_value
572
- users = Groonga::Hash.create(:name => "Users",
573
- :key_type => "ShortText")
574
- books = Groonga::Hash.create(:name => "Books",
575
- :key_type => "ShortText")
576
- users.define_column("book", books)
577
- users.add("morita", :book => "")
578
- assert_equal({"_id" => 1, "_key" => "morita", "book" => nil},
579
- users["morita"].attributes)
580
- end
581
-
582
- def test_have_column
583
- users = Groonga::Hash.create(:name => "Users",
584
- :key_type => "ShortText")
585
- users.define_column("name", "ShortText")
586
- assert_true(users.have_column?("name"), "name")
587
- assert_false(users.have_column?("description"), "description")
588
- end
589
-
590
- def test_have_column_id
591
- users = Groonga::Array.create(:name => "Users")
592
- assert_true(users.have_column?(:_id))
593
- end
594
-
595
- def test_have_column_key_hash
596
- users = Groonga::Hash.create(:name => "Users",
597
- :key_type => "ShortText")
598
- assert_true(users.have_column?(:_key))
599
- end
600
-
601
- def test_have_column_key_array
602
- users = Groonga::Array.create(:name => "Users")
603
- assert_false(users.have_column?(:_key))
604
- end
605
-
606
- def test_have_column_value_hash_with_value_type
607
- users = Groonga::Hash.create(:name => "Users",
608
- :key_type => "ShortText",
609
- :value_type => "Int32")
610
- assert_true(users.have_column?(:_value))
611
- end
612
-
613
- def test_have_column_value_hash_without_value_type
614
- users = Groonga::Hash.create(:name => "Users",
615
- :key_type => "ShortText")
616
- assert_false(users.have_column?(:_value))
617
- end
618
-
619
- def test_have_column_value_array
620
- users = Groonga::Array.create(:name => "Users")
621
- assert_false(users.have_column?(:_value))
622
- end
623
-
624
- def test_have_column_nsubrecs_existent
625
- users = Groonga::Hash.create(:name => "Users",
626
- :key_type => "ShortText")
627
- assert_true(users.select.have_column?(:_nsubrecs))
628
- end
629
-
630
- def test_have_column_nsubrecs_nonexistent
631
- users = Groonga::Hash.create(:name => "Users",
632
- :key_type => "ShortText")
633
- assert_false(users.have_column?(:_nsubrecs))
634
- end
635
-
636
- def test_have_column_score_existent
637
- users = Groonga::Hash.create(:name => "Users",
638
- :key_type => "ShortText")
639
- assert_true(users.select.have_column?(:_score))
640
- end
641
-
642
- def test_have_column_score_nonexistent
643
- users = Groonga::Hash.create(:name => "Users",
644
- :key_type => "ShortText")
645
- assert_false(users.have_column?(:_score))
646
- end
647
-
648
- def test_exist?
649
- users = Groonga::Hash.create(:name => "Users")
650
- morita = users.add("morita")
651
- assert_true(users.exist?(morita.id))
652
- assert_false(users.exist?(morita.id + 1))
653
- end
654
-
655
- def test_builtin?
656
- bookmarks = Groonga::PatriciaTrie.create(:name => "Bookmarks")
657
- assert_not_predicate(bookmarks, :builtin?)
658
- end
659
-
660
- private
661
- def create_bookmarks
662
- bookmarks = Groonga::Array.create(:name => "Bookmarks")
663
- bookmarks.define_column("id", "Int32")
664
- bookmarks
665
- end
666
-
667
- def add_shuffled_ids(bookmarks)
668
- srand(Time.now.to_i)
669
- (0...100).to_a.shuffle.each do |i|
670
- bookmark = bookmarks.add
671
- bookmark["id"] = i + 100
672
- end
673
- bookmarks
674
- end
675
- end