groonga 0.9.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. metadata +38 -227
  2. data/AUTHORS +0 -5
  3. data/NEWS.ja.rdoc +0 -114
  4. data/NEWS.rdoc +0 -116
  5. data/README.ja.rdoc +0 -63
  6. data/README.rdoc +0 -64
  7. data/Rakefile +0 -216
  8. data/benchmark/common.rb +0 -49
  9. data/benchmark/read-write-many-small-items.rb +0 -144
  10. data/benchmark/write-many-small-items.rb +0 -135
  11. data/example/bookmark.rb +0 -161
  12. data/example/index-html.rb +0 -89
  13. data/example/search/config.ru +0 -211
  14. data/example/search/public/css/groonga.css +0 -122
  15. data/ext/.gitignore +0 -2
  16. data/ext/rb-grn-accessor.c +0 -52
  17. data/ext/rb-grn-array-cursor.c +0 -36
  18. data/ext/rb-grn-array.c +0 -210
  19. data/ext/rb-grn-column.c +0 -570
  20. data/ext/rb-grn-context.c +0 -655
  21. data/ext/rb-grn-database.c +0 -415
  22. data/ext/rb-grn-encoding-support.c +0 -64
  23. data/ext/rb-grn-encoding.c +0 -257
  24. data/ext/rb-grn-exception.c +0 -1110
  25. data/ext/rb-grn-expression-builder.c +0 -75
  26. data/ext/rb-grn-expression.c +0 -732
  27. data/ext/rb-grn-fix-size-column.c +0 -166
  28. data/ext/rb-grn-hash-cursor.c +0 -38
  29. data/ext/rb-grn-hash.c +0 -294
  30. data/ext/rb-grn-index-column.c +0 -488
  31. data/ext/rb-grn-logger.c +0 -325
  32. data/ext/rb-grn-object.c +0 -1335
  33. data/ext/rb-grn-operation.c +0 -198
  34. data/ext/rb-grn-patricia-trie-cursor.c +0 -39
  35. data/ext/rb-grn-patricia-trie.c +0 -488
  36. data/ext/rb-grn-procedure.c +0 -52
  37. data/ext/rb-grn-query.c +0 -260
  38. data/ext/rb-grn-record.c +0 -40
  39. data/ext/rb-grn-snippet.c +0 -328
  40. data/ext/rb-grn-table-cursor-key-support.c +0 -69
  41. data/ext/rb-grn-table-cursor.c +0 -246
  42. data/ext/rb-grn-table-key-support.c +0 -731
  43. data/ext/rb-grn-table.c +0 -2038
  44. data/ext/rb-grn-type.c +0 -181
  45. data/ext/rb-grn-utils.c +0 -769
  46. data/ext/rb-grn-variable-size-column.c +0 -36
  47. data/ext/rb-grn-variable.c +0 -108
  48. data/ext/rb-grn.h +0 -684
  49. data/ext/rb-groonga.c +0 -113
  50. data/extconf.rb +0 -216
  51. data/html/bar.svg +0 -153
  52. data/html/developer.html +0 -121
  53. data/html/developer.svg +0 -469
  54. data/html/download.svg +0 -253
  55. data/html/favicon.ico +0 -0
  56. data/html/favicon.xcf +0 -0
  57. data/html/footer.html.erb +0 -28
  58. data/html/head.html.erb +0 -4
  59. data/html/header.html.erb +0 -17
  60. data/html/index.html +0 -147
  61. data/html/install.svg +0 -636
  62. data/html/logo.xcf +0 -0
  63. data/html/ranguba.css +0 -248
  64. data/html/tutorial.svg +0 -559
  65. data/lib/groonga.rb +0 -83
  66. data/lib/groonga/expression-builder.rb +0 -285
  67. data/lib/groonga/patricia-trie.rb +0 -53
  68. data/lib/groonga/record.rb +0 -276
  69. data/lib/groonga/schema.rb +0 -916
  70. data/license/GPL +0 -340
  71. data/license/LGPL +0 -504
  72. data/license/RUBY +0 -59
  73. data/misc/grnop2ruby.rb +0 -49
  74. data/pkg-config.rb +0 -333
  75. data/src/rb-grn-table-cursor.c +0 -296
  76. data/test-unit/Rakefile +0 -40
  77. data/test-unit/TODO +0 -5
  78. data/test-unit/bin/testrb +0 -5
  79. data/test-unit/html/classic.html +0 -15
  80. data/test-unit/html/index.html +0 -25
  81. data/test-unit/html/index.html.ja +0 -27
  82. data/test-unit/lib/test/unit.rb +0 -323
  83. data/test-unit/lib/test/unit/assertionfailederror.rb +0 -25
  84. data/test-unit/lib/test/unit/assertions.rb +0 -1230
  85. data/test-unit/lib/test/unit/attribute.rb +0 -125
  86. data/test-unit/lib/test/unit/autorunner.rb +0 -353
  87. data/test-unit/lib/test/unit/collector.rb +0 -36
  88. data/test-unit/lib/test/unit/collector/descendant.rb +0 -23
  89. data/test-unit/lib/test/unit/collector/dir.rb +0 -108
  90. data/test-unit/lib/test/unit/collector/load.rb +0 -136
  91. data/test-unit/lib/test/unit/collector/objectspace.rb +0 -34
  92. data/test-unit/lib/test/unit/color-scheme.rb +0 -102
  93. data/test-unit/lib/test/unit/color.rb +0 -96
  94. data/test-unit/lib/test/unit/diff.rb +0 -724
  95. data/test-unit/lib/test/unit/error.rb +0 -130
  96. data/test-unit/lib/test/unit/exceptionhandler.rb +0 -39
  97. data/test-unit/lib/test/unit/failure.rb +0 -136
  98. data/test-unit/lib/test/unit/fixture.rb +0 -176
  99. data/test-unit/lib/test/unit/notification.rb +0 -129
  100. data/test-unit/lib/test/unit/omission.rb +0 -191
  101. data/test-unit/lib/test/unit/pending.rb +0 -150
  102. data/test-unit/lib/test/unit/priority.rb +0 -181
  103. data/test-unit/lib/test/unit/runner/console.rb +0 -52
  104. data/test-unit/lib/test/unit/runner/emacs.rb +0 -8
  105. data/test-unit/lib/test/unit/runner/tap.rb +0 -8
  106. data/test-unit/lib/test/unit/testcase.rb +0 -476
  107. data/test-unit/lib/test/unit/testresult.rb +0 -89
  108. data/test-unit/lib/test/unit/testsuite.rb +0 -110
  109. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +0 -14
  110. data/test-unit/lib/test/unit/ui/console/testrunner.rb +0 -464
  111. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +0 -63
  112. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +0 -92
  113. data/test-unit/lib/test/unit/ui/testrunner.rb +0 -28
  114. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +0 -77
  115. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +0 -41
  116. data/test-unit/lib/test/unit/util/backtracefilter.rb +0 -41
  117. data/test-unit/lib/test/unit/util/method-owner-finder.rb +0 -28
  118. data/test-unit/lib/test/unit/util/observable.rb +0 -90
  119. data/test-unit/lib/test/unit/util/procwrapper.rb +0 -48
  120. data/test-unit/lib/test/unit/version.rb +0 -7
  121. data/test-unit/sample/adder.rb +0 -13
  122. data/test-unit/sample/subtracter.rb +0 -12
  123. data/test-unit/sample/test_adder.rb +0 -20
  124. data/test-unit/sample/test_subtracter.rb +0 -20
  125. data/test-unit/sample/test_user.rb +0 -23
  126. data/test-unit/test/collector/test-descendant.rb +0 -133
  127. data/test-unit/test/collector/test-load.rb +0 -329
  128. data/test-unit/test/collector/test_dir.rb +0 -406
  129. data/test-unit/test/collector/test_objectspace.rb +0 -100
  130. data/test-unit/test/run-test.rb +0 -15
  131. data/test-unit/test/test-attribute.rb +0 -86
  132. data/test-unit/test/test-color-scheme.rb +0 -67
  133. data/test-unit/test/test-color.rb +0 -47
  134. data/test-unit/test/test-diff.rb +0 -518
  135. data/test-unit/test/test-emacs-runner.rb +0 -60
  136. data/test-unit/test/test-fixture.rb +0 -287
  137. data/test-unit/test/test-notification.rb +0 -33
  138. data/test-unit/test/test-omission.rb +0 -81
  139. data/test-unit/test/test-pending.rb +0 -70
  140. data/test-unit/test/test-priority.rb +0 -119
  141. data/test-unit/test/test-testcase.rb +0 -554
  142. data/test-unit/test/test_assertions.rb +0 -1151
  143. data/test-unit/test/test_error.rb +0 -26
  144. data/test-unit/test/test_failure.rb +0 -33
  145. data/test-unit/test/test_testresult.rb +0 -113
  146. data/test-unit/test/test_testsuite.rb +0 -129
  147. data/test-unit/test/testunit-test-util.rb +0 -14
  148. data/test-unit/test/ui/test_testrunmediator.rb +0 -20
  149. data/test-unit/test/util/test-method-owner-finder.rb +0 -38
  150. data/test-unit/test/util/test_backtracefilter.rb +0 -41
  151. data/test-unit/test/util/test_observable.rb +0 -102
  152. data/test-unit/test/util/test_procwrapper.rb +0 -36
  153. data/test/.gitignore +0 -1
  154. data/test/groonga-test-utils.rb +0 -106
  155. data/test/run-test.rb +0 -58
  156. data/test/test-array.rb +0 -97
  157. data/test/test-column.rb +0 -298
  158. data/test/test-context.rb +0 -73
  159. data/test/test-database.rb +0 -113
  160. data/test/test-encoding.rb +0 -33
  161. data/test/test-exception.rb +0 -93
  162. data/test/test-expression-builder.rb +0 -156
  163. data/test/test-expression.rb +0 -133
  164. data/test/test-fix-size-column.rb +0 -65
  165. data/test/test-gqtp.rb +0 -70
  166. data/test/test-hash.rb +0 -312
  167. data/test/test-index-column.rb +0 -81
  168. data/test/test-patricia-trie.rb +0 -189
  169. data/test/test-procedure.rb +0 -37
  170. data/test/test-query.rb +0 -22
  171. data/test/test-record.rb +0 -268
  172. data/test/test-remote.rb +0 -53
  173. data/test/test-schema.rb +0 -416
  174. data/test/test-snippet.rb +0 -121
  175. data/test/test-table-cursor.rb +0 -153
  176. data/test/test-table-offset-and-limit.rb +0 -102
  177. data/test/test-table-select-normalize.rb +0 -48
  178. data/test/test-table-select.rb +0 -145
  179. data/test/test-table.rb +0 -642
  180. data/test/test-type.rb +0 -61
  181. data/test/test-variable-size-column.rb +0 -98
  182. data/test/test-variable.rb +0 -28
  183. data/test/test-vector-column.rb +0 -76
  184. data/test/test-version.rb +0 -31
  185. data/text/TUTORIAL.ja.rdoc +0 -392
  186. data/text/expression.rdoc +0 -284
data/test/test-table.rb DELETED
@@ -1,642 +0,0 @@
1
- # Copyright (C) 2009-2010 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_open
39
- table_path = @tables_dir + "bookmarks"
40
- table = Groonga::Hash.create(:name => "Bookmarks",
41
- :path => table_path.to_s)
42
- assert_equal("Bookmarks", table.name)
43
-
44
- called = false
45
- Groonga::Table.open(:name => "Bookmarks") do |_table|
46
- table = _table
47
- assert_not_predicate(table, :closed?)
48
- assert_equal("Bookmarks", _table.name)
49
- called = true
50
- end
51
- assert_true(called)
52
- assert_predicate(table, :closed?)
53
- end
54
-
55
- def test_open_by_path
56
- table_path = @tables_dir + "bookmarks"
57
- table = Groonga::PatriciaTrie.create(:name => "Bookmarks",
58
- :path => table_path.to_s)
59
- assert_equal("Bookmarks", table.name)
60
- table.close
61
-
62
- called = false
63
- Groonga::Table.open(:path => table_path.to_s) do |_table|
64
- table = _table
65
- assert_not_predicate(table, :closed?)
66
- assert_nil(_table.name)
67
- called = true
68
- end
69
- assert_true(called)
70
- assert_predicate(table, :closed?)
71
- end
72
-
73
- def test_open_override_name
74
- table_path = @tables_dir + "bookmarks"
75
- table = Groonga::PatriciaTrie.create(:name => "Bookmarks",
76
- :path => table_path.to_s)
77
- assert_equal("Bookmarks", table.name)
78
- table.close
79
-
80
- called = false
81
- Groonga::Table.open(:name => "Marks", :path => table_path.to_s) do |_table|
82
- table = _table
83
- assert_not_predicate(table, :closed?)
84
- assert_equal("Marks", _table.name)
85
- called = true
86
- end
87
- assert_true(called)
88
- assert_predicate(table, :closed?)
89
- end
90
-
91
- def test_open_wrong_table
92
- table_path = @tables_dir + "bookmarks"
93
- Groonga::Hash.create(:name => "Bookmarks",
94
- :path => table_path.to_s) do
95
- end
96
-
97
- assert_raise(TypeError) do
98
- Groonga::PatriciaTrie.open(:name => "Bookmarks",
99
- :path => table_path.to_s)
100
- end
101
- end
102
-
103
- def test_new
104
- table_path = @tables_dir + "no-name"
105
- assert_raise(Groonga::NoSuchFileOrDirectory) do
106
- Groonga::Hash.new(:path => table_path.to_s)
107
- end
108
-
109
- Groonga::Hash.create(:path => table_path.to_s)
110
- assert_not_predicate(Groonga::Hash.new(:path => table_path.to_s), :closed?)
111
- end
112
-
113
- def test_define_column
114
- table_path = @tables_dir + "bookmarks"
115
- table = Groonga::Hash.create(:name => "Bookmarks",
116
- :path => table_path.to_s)
117
- column = table.define_column("name", "Text")
118
- assert_equal("Bookmarks.name", column.name)
119
- assert_equal(column, table.column("name"))
120
- end
121
-
122
- def test_temporary_table_define_column_default_persistent
123
- table = Groonga::Hash.create
124
- name = table.define_column("name", "ShortText")
125
- assert_predicate(name, :temporary?)
126
- end
127
-
128
- def test_temporary_table_define_index_column_default_persistent
129
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
130
- terms = Groonga::Hash.create
131
- url = terms.define_index_column("url", bookmarks)
132
- assert_predicate(url, :temporary?)
133
- end
134
-
135
- def test_define_column_default_persistent
136
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
137
- real_name = bookmarks.define_column("real_name", "ShortText")
138
- assert_predicate(real_name, :persistent?)
139
- end
140
-
141
- def test_define_column_not_persistent
142
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
143
- real_name = bookmarks.define_column("real_name", "ShortText",
144
- :persistent => false)
145
- assert_predicate(real_name, :temporary?)
146
- end
147
-
148
- def test_define_column_not_persistent_and_path
149
- column_path = @tables_dir + "bookmakrs.real_name.column"
150
-
151
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
152
- message = "should not pass :path if :persistent is false: <#{column_path}>"
153
- assert_raise(ArgumentError.new(message)) do
154
- real_name = bookmarks.define_column("real_name", "ShortText",
155
- :path => column_path.to_s,
156
- :persistent => false)
157
- end
158
- end
159
-
160
- def test_define_index_column_default_persistent
161
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
162
- terms = Groonga::Hash.create(:name => "Terms")
163
- real_name = terms.define_index_column("real_name", bookmarks)
164
- assert_predicate(real_name, :persistent?)
165
- end
166
-
167
- def test_define_index_column_not_persistent
168
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
169
- terms = Groonga::Hash.create(:name => "Terms")
170
- real_name = terms.define_index_column("real_name", bookmarks,
171
- :persistent => false)
172
- assert_predicate(real_name, :temporary?)
173
- end
174
-
175
- def test_define_index_column_not_persistent_and_path
176
- column_path = @tables_dir + "bookmakrs.real_name.column"
177
-
178
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
179
- terms = Groonga::Hash.create(:name => "Terms")
180
- message = "should not pass :path if :persistent is false: <#{column_path}>"
181
- assert_raise(ArgumentError.new(message)) do
182
- real_name = terms.define_index_column("real_name", bookmarks,
183
- :path => column_path.to_s,
184
- :persistent => false)
185
- end
186
- end
187
-
188
- def test_define_index_column
189
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
190
- bookmarks.define_column("content", "Text")
191
- terms = Groonga::Hash.create(:name => "Terms")
192
- terms.default_tokenizer = "TokenBigram"
193
- index = terms.define_index_column("content-index", bookmarks,
194
- :with_section => true,
195
- :source => "Bookmarks.content")
196
- bookmarks.add("google", :content => "Search engine")
197
- assert_equal(["google"],
198
- index.search("engine").collect {|record| record.key.key})
199
- end
200
-
201
- def test_add_column
202
- bookmarks = Groonga::Hash.create(:name => "Bookmarks",
203
- :path => (@tables_dir + "bookmarks").to_s)
204
-
205
- description_column_path = @columns_dir + "description"
206
- bookmarks_description =
207
- bookmarks.define_index_column("description", "Text",
208
- :path => description_column_path.to_s)
209
-
210
- books = Groonga::Hash.create(:name => "Books",
211
- :path => (@tables_dir + "books").to_s)
212
- books_description = books.add_column("description",
213
- "LongText",
214
- description_column_path.to_s)
215
- assert_equal("Books.description", books_description.name)
216
- assert_equal(books_description, books.column("description"))
217
-
218
- assert_equal(bookmarks_description, bookmarks.column("description"))
219
- end
220
-
221
- def test_column_nonexistent
222
- table_path = @tables_dir + "bookmarks"
223
- table = Groonga::Hash.create(:name => "Bookmarks",
224
- :path => table_path.to_s)
225
- assert_nil(table.column("nonexistent"))
226
- end
227
-
228
- def test_set_value
229
- table_path = @tables_dir + "bookmarks"
230
- bookmarks = Groonga::Hash.create(:name => "Bookmarks",
231
- :value_type => "Int32",
232
- :path => table_path.to_s)
233
- comment_column_path = @columns_dir + "comment"
234
- bookmarks_comment =
235
- bookmarks.define_column("comment", "ShortText",
236
- :type => "scalar",
237
- :path => comment_column_path.to_s)
238
- groonga = bookmarks.add("groonga")
239
- groonga.value = 29
240
- bookmarks_comment[groonga.id] = "fulltext search engine"
241
-
242
- assert_equal([29, "fulltext search engine"],
243
- [groonga.value, bookmarks_comment[groonga.id]])
244
- end
245
-
246
- def test_array_set
247
- bookmarks = Groonga::Hash.create(:name => "Bookmarks",
248
- :value_type => "Int32")
249
- bookmarks.set_value("groonga", 29)
250
-
251
- values = bookmarks.records.collect do |record|
252
- record.value
253
- end
254
- assert_equal([29], values)
255
- end
256
-
257
- def test_add_without_name
258
- users_path = @tables_dir + "users"
259
- users = Groonga::Array.create(:name => "Users",
260
- :path => users_path.to_s)
261
- name_column_path = @columns_dir + "name"
262
- users_name = users.define_column("name", "ShortText",
263
- :path => name_column_path.to_s)
264
- morita = users.add
265
- users_name[morita.id] = "morita"
266
- assert_equal("morita", users_name[morita.id])
267
- end
268
-
269
- def test_add_by_id
270
- users_path = @tables_dir + "users"
271
- users = Groonga::Hash.create(:name => "Users",
272
- :path => users_path.to_s)
273
-
274
- bookmarks_path = @tables_dir + "bookmarks"
275
- bookmarks = Groonga::Hash.create(:name => "Bookmarks",
276
- :key_type => users,
277
- :value_type => "Int32",
278
- :path => bookmarks_path.to_s)
279
- morita = users.add("morita")
280
- groonga = bookmarks.add(morita.id)
281
- groonga.value = 29
282
- assert_equal(29, groonga.value)
283
- end
284
-
285
- def test_columns
286
- bookmarks_path = @tables_dir + "bookmarks"
287
- bookmarks = Groonga::Array.create(:name => "Bookmarks",
288
- :path => bookmarks_path.to_s)
289
-
290
- uri_column = bookmarks.define_column("uri", "ShortText")
291
- comment_column = bookmarks.define_column("comment", "Text")
292
- assert_equal([uri_column.name, comment_column.name].sort,
293
- bookmarks.columns.collect {|column| column.name}.sort)
294
- end
295
-
296
- def test_column_by_symbol
297
- bookmarks_path = @tables_dir + "bookmarks"
298
- bookmarks = Groonga::Array.create(:name => "Bookmarks",
299
- :path => bookmarks_path.to_s)
300
-
301
- uri_column = bookmarks.define_column("uri", "Text")
302
- assert_equal(uri_column, bookmarks.column(:uri))
303
- end
304
-
305
- def test_size
306
- bookmarks_path = @tables_dir + "bookmarks"
307
- bookmarks = Groonga::Array.create(:name => "Bookmarks",
308
- :path => bookmarks_path.to_s)
309
-
310
- assert_equal(0, bookmarks.size)
311
-
312
- bookmarks.add
313
- bookmarks.add
314
- bookmarks.add
315
-
316
- assert_equal(3, bookmarks.size)
317
- end
318
-
319
- def test_path
320
- bookmarks_path = @tables_dir + "bookmarks"
321
- bookmarks = Groonga::Array.create(:name => "Bookmarks",
322
- :path => bookmarks_path.to_s)
323
- assert_equal(bookmarks_path.to_s, bookmarks.path)
324
- end
325
-
326
- def test_time_column
327
- bookmarks_path = @tables_dir + "bookmarks"
328
- bookmarks = Groonga::Array.create(:name => "Bookmarks",
329
- :path => bookmarks_path.to_s)
330
- column = bookmarks.define_column("created_at", "Time")
331
-
332
- bookmark = bookmarks.add
333
- now = Time.now
334
- bookmark["created_at"] = now
335
- assert_equal(now.to_a,
336
- bookmark["created_at"].to_a)
337
- end
338
-
339
- def test_delete
340
- bookmarks_path = @tables_dir + "bookmarks"
341
- bookmarks = Groonga::Array.create(:name => "Bookmarks",
342
- :path => bookmarks_path.to_s)
343
-
344
- bookmark1 = bookmarks.add
345
- bookmark2 = bookmarks.add
346
- bookmark3 = bookmarks.add
347
-
348
- assert_equal(3, bookmarks.size)
349
- bookmarks.delete(bookmark2.id)
350
- assert_equal(2, bookmarks.size)
351
- end
352
-
353
- def test_remove
354
- bookmarks_path = @tables_dir + "bookmarks"
355
- bookmarks = Groonga::Array.create(:name => "Bookmarks",
356
- :path => bookmarks_path.to_s)
357
- assert_predicate(bookmarks_path, :exist?)
358
- bookmarks.remove
359
- assert_not_predicate(bookmarks_path, :exist?)
360
- end
361
-
362
- def test_temporary_add
363
- table = Groonga::Hash.create(:key_type => "ShortText")
364
- assert_equal(0, table.size)
365
- table.add("key")
366
- assert_equal(1, table.size)
367
- end
368
-
369
- def test_each
370
- users = Groonga::Array.create(:name => "Users")
371
- user_name = users.define_column("name", "ShortText")
372
-
373
- names = ["daijiro", "gunyarakun", "yu"]
374
- names.each do |name|
375
- user = users.add
376
- user["name"] = name
377
- end
378
-
379
- assert_equal(names.sort, users.collect {|user| user["name"]}.sort)
380
- end
381
-
382
- def test_truncate
383
- users = Groonga::Array.create(:name => "Users")
384
- users.add
385
- users.add
386
- users.add
387
- assert_equal(3, users.size)
388
- assert_nothing_raised do
389
- users.truncate
390
- end
391
- # assert_equal(0, users.size) # truncate isn't implemented in groonga.
392
- end
393
-
394
- def test_sort
395
- bookmarks = create_bookmarks
396
- add_shuffled_ids(bookmarks)
397
-
398
- results = bookmarks.sort([
399
- {
400
- :key => "id",
401
- :order => :descending,
402
- },
403
- ],
404
- :limit => 20)
405
- assert_equal((180..199).to_a.reverse,
406
- results.collect {|record| record["id"]})
407
- end
408
-
409
- def test_sort_simple
410
- bookmarks = create_bookmarks
411
- add_shuffled_ids(bookmarks)
412
-
413
- results = bookmarks.sort(["id"], :limit => 20)
414
- assert_equal((100..119).to_a,
415
- results.collect {|record| record["id"]})
416
- end
417
-
418
- def test_sort_by_array
419
- bookmarks = create_bookmarks
420
- add_shuffled_ids(bookmarks)
421
-
422
- results = bookmarks.sort([["id", "descending"]], :limit => 20)
423
- assert_equal((180..199).to_a.reverse,
424
- results.collect {|record| record["id"]})
425
- end
426
-
427
- def test_sort_without_limit_and_offset
428
- bookmarks = create_bookmarks
429
- add_shuffled_ids(bookmarks)
430
-
431
- results = bookmarks.sort([{:key => "id", :order => :descending}])
432
- assert_equal((100..199).to_a.reverse,
433
- results.collect {|record| record["id"]})
434
- end
435
-
436
- def test_sort_with_limit
437
- bookmarks = create_bookmarks
438
- add_shuffled_ids(bookmarks)
439
-
440
- results = bookmarks.sort([{:key => "id", :order => :descending}],
441
- :limit => 20)
442
- assert_equal((180..199).to_a.reverse,
443
- results.collect {|record| record["id"]})
444
- end
445
-
446
- def test_sort_with_offset
447
- bookmarks = create_bookmarks
448
- add_shuffled_ids(bookmarks)
449
-
450
- results = bookmarks.sort([{:key => "id", :order => :descending}],
451
- :offset => 20)
452
- assert_equal((100..179).to_a.reverse,
453
- results.collect {|record| record["id"]})
454
- end
455
-
456
- def test_sort_with_limit_and_offset
457
- bookmarks = create_bookmarks
458
- add_shuffled_ids(bookmarks)
459
-
460
- results = bookmarks.sort([{:key => "id", :order => :descending}],
461
- :limit => 20, :offset => 20)
462
- assert_equal((160..179).to_a.reverse,
463
- results.collect {|record| record["id"]})
464
- end
465
-
466
- def test_sort_with_nonexistent_key
467
- omit("maybe crash!!!")
468
- bookmarks = create_bookmarks
469
- add_shuffled_ids(bookmarks)
470
- results = bookmarks.sort([{:key => "nonexistent", :order => :descending}])
471
- assert_equal("unknown",
472
- results.collect {|record| record["id"]})
473
- end
474
-
475
- def test_group
476
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
477
- bookmarks.define_column("title", "Text")
478
- comments = Groonga::Array.create(:name => "Comments")
479
- comments.define_column("bookmark", bookmarks)
480
- comments.define_column("content", "Text")
481
- comments.define_column("issued", "Int32")
482
-
483
- groonga = bookmarks.add("http://groonga.org/", :title => "groonga")
484
- ruby = bookmarks.add("http://ruby-lang.org/", :title => "Ruby")
485
-
486
- now = Time.now.to_i
487
- comments.add(:bookmark => groonga,
488
- :content => "full-text search",
489
- :issued => now)
490
- comments.add(:bookmark => groonga,
491
- :content => "column store",
492
- :issued => now)
493
- comments.add(:bookmark => ruby,
494
- :content => "object oriented script language",
495
- :issued => now)
496
-
497
- records = comments.select do |record|
498
- record["issued"] > 0
499
- end
500
- assert_equal([[2, "groonga", "http://groonga.org/"],
501
- [1, "Ruby", "http://ruby-lang.org/"]],
502
- records.group(".bookmark").collect do |record|
503
- bookmark = record.key
504
- [record.n_sub_records,
505
- bookmark["title"],
506
- bookmark.key]
507
- end)
508
- end
509
-
510
- def test_union!
511
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
512
- bookmarks.define_column("title", "ShortText")
513
-
514
- groonga = bookmarks.add("http://groonga.org/", :title => "groonga")
515
- ruby = bookmarks.add("http://ruby-lang.org/", :title => "Ruby")
516
-
517
- ruby_bookmarks = bookmarks.select {|record| record["title"] == "Ruby"}
518
- groonga_bookmarks = bookmarks.select {|record| record["title"] == "groonga"}
519
- assert_equal(["Ruby", "groonga"],
520
- ruby_bookmarks.union!(groonga_bookmarks).collect do |record|
521
- record[".title"]
522
- end)
523
- end
524
-
525
- def test_intersection!
526
- bookmarks = Groonga::Hash.create(:name => "bookmarks")
527
- bookmarks.define_column("title", "ShortText")
528
-
529
- bookmarks.add("http://groonga.org/", :title => "groonga")
530
- bookmarks.add("http://ruby-lang.org/", :title => "Ruby")
531
-
532
- ruby_bookmarks = bookmarks.select {|record| record["title"] == "Ruby"}
533
- all_bookmarks = bookmarks.select
534
- assert_equal(["Ruby"],
535
- ruby_bookmarks.intersection!(all_bookmarks).collect do |record|
536
- record[".title"]
537
- end)
538
- end
539
-
540
- def test_difference!
541
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
542
- bookmarks.define_column("title", "ShortText")
543
-
544
- bookmarks.add("http://groonga.org/", :title => "groonga")
545
- bookmarks.add("http://ruby-lang.org/", :title => "Ruby")
546
-
547
- ruby_bookmarks = bookmarks.select {|record| record["title"] == "Ruby"}
548
- all_bookmarks = bookmarks.select
549
- assert_equal(["groonga"],
550
- all_bookmarks.difference!(ruby_bookmarks).collect do |record|
551
- record[".title"]
552
- end)
553
- end
554
-
555
- def test_merge!
556
- bookmarks = Groonga::Hash.create(:name => "Bookmarks")
557
- bookmarks.define_column("title", "ShortText")
558
-
559
- bookmarks.add("http://groonga.org/", :title => "groonga")
560
- bookmarks.add("http://ruby-lang.org/", :title => "Ruby")
561
-
562
- ruby_bookmarks = bookmarks.select {|record| (record["title"] == "Ruby") &
563
- (record["title"] == "Ruby") }
564
- all_bookmarks = bookmarks.select
565
- assert_equal([["groonga", 1], ["Ruby", 2]],
566
- all_bookmarks.merge!(ruby_bookmarks).collect do |record|
567
- [record[".title"], record.score]
568
- end)
569
- end
570
-
571
- def test_lock
572
- bookmarks = Groonga::Array.create(:name => "Bookmarks")
573
- bookmark = bookmarks.add
574
-
575
- assert_not_predicate(bookmarks, :locked?)
576
- bookmarks.lock
577
- assert_predicate(bookmarks, :locked?)
578
- bookmarks.unlock
579
- assert_not_predicate(bookmarks, :locked?)
580
- end
581
-
582
- def test_lock_failed
583
- bookmarks = Groonga::Array.create(:name => "Bookmarks")
584
- bookmark = bookmarks.add
585
-
586
- bookmarks.lock
587
- assert_raise(Groonga::ResourceDeadlockAvoided) do
588
- bookmarks.lock
589
- end
590
- end
591
-
592
- def test_lock_block
593
- bookmarks = Groonga::Array.create(:name => "Bookmarks")
594
- bookmark = bookmarks.add
595
-
596
- assert_not_predicate(bookmarks, :locked?)
597
- bookmarks.lock do
598
- assert_predicate(bookmarks, :locked?)
599
- end
600
- assert_not_predicate(bookmarks, :locked?)
601
- end
602
-
603
- def test_clear_lock
604
- bookmarks = Groonga::Array.create(:name => "Bookmarks")
605
- bookmark = bookmarks.add
606
-
607
- assert_not_predicate(bookmarks, :locked?)
608
- bookmarks.lock
609
- assert_predicate(bookmarks, :locked?)
610
- bookmarks.clear_lock
611
- assert_not_predicate(bookmarks, :locked?)
612
- end
613
-
614
- def test_auto_record_register
615
- users = Groonga::Hash.create(:name => "Users",
616
- :key_type => "ShortText")
617
- books = Groonga::Hash.create(:name => "Books",
618
- :key_type => "ShortText")
619
- users.define_column("book", "Books")
620
-
621
- assert_equal([], books.select.collect {|book| book.key})
622
- users.add("ryoqun", :book => "XP")
623
- assert_equal([books["XP"]],
624
- books.select.collect {|book| book.key})
625
- end
626
-
627
- private
628
- def create_bookmarks
629
- bookmarks = Groonga::Array.create(:name => "Bookmarks")
630
- bookmarks.define_column("id", "Int32")
631
- bookmarks
632
- end
633
-
634
- def add_shuffled_ids(bookmarks)
635
- srand(Time.now.to_i)
636
- (0...100).to_a.shuffle.each do |i|
637
- bookmark = bookmarks.add
638
- bookmark["id"] = i + 100
639
- end
640
- bookmarks
641
- end
642
- end