groonga 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +1 -0
- data/NEWS.ja.rdoc +5 -0
- data/NEWS.rdoc +5 -0
- data/README.ja.rdoc +53 -0
- data/README.rdoc +54 -0
- data/Rakefile +209 -0
- data/TUTORIAL.ja.rdoc +160 -0
- data/benchmark/small-many-items.rb +175 -0
- data/example/bookmark.rb +38 -0
- data/ext/.gitignore +2 -0
- data/ext/rb-grn-accessor.c +52 -0
- data/ext/rb-grn-array-cursor.c +28 -0
- data/ext/rb-grn-array.c +168 -0
- data/ext/rb-grn-column.c +273 -0
- data/ext/rb-grn-context.c +333 -0
- data/ext/rb-grn-database.c +128 -0
- data/ext/rb-grn-encoding.c +163 -0
- data/ext/rb-grn-exception.c +1014 -0
- data/ext/rb-grn-hash-cursor.c +30 -0
- data/ext/rb-grn-hash.c +40 -0
- data/ext/rb-grn-logger.c +277 -0
- data/ext/rb-grn-object.c +985 -0
- data/ext/rb-grn-patricia-trie-cursor.c +30 -0
- data/ext/rb-grn-patricia-trie.c +40 -0
- data/ext/rb-grn-procedure.c +52 -0
- data/ext/rb-grn-query.c +207 -0
- data/ext/rb-grn-record.c +33 -0
- data/ext/rb-grn-snippet.c +274 -0
- data/ext/rb-grn-table-cursor-key-support.c +55 -0
- data/ext/rb-grn-table-cursor.c +294 -0
- data/ext/rb-grn-table-key-support.c +299 -0
- data/ext/rb-grn-table.c +706 -0
- data/ext/rb-grn-type.c +114 -0
- data/ext/rb-grn-utils.c +578 -0
- data/ext/rb-grn.h +346 -0
- data/ext/rb-groonga.c +98 -0
- data/extconf.rb +171 -0
- data/html/bar.svg +153 -0
- data/html/developer.html +121 -0
- data/html/developer.svg +469 -0
- data/html/download.svg +253 -0
- data/html/footer.html.erb +28 -0
- data/html/head.html.erb +4 -0
- data/html/header.html.erb +17 -0
- data/html/index.html +153 -0
- data/html/install.svg +636 -0
- data/html/logo.xcf +0 -0
- data/html/ranguba.css +248 -0
- data/html/tutorial.svg +559 -0
- data/lib/groonga.rb +50 -0
- data/lib/groonga/record.rb +98 -0
- data/license/GPL +340 -0
- data/license/LGPL +504 -0
- data/license/RUBY +59 -0
- data/pkg-config.rb +328 -0
- data/test-unit/Rakefile +35 -0
- data/test-unit/TODO +5 -0
- data/test-unit/bin/testrb +5 -0
- data/test-unit/html/classic.html +15 -0
- data/test-unit/html/index.html +25 -0
- data/test-unit/html/index.html.ja +27 -0
- data/test-unit/lib/test/unit.rb +342 -0
- data/test-unit/lib/test/unit/assertionfailederror.rb +14 -0
- data/test-unit/lib/test/unit/assertions.rb +1149 -0
- data/test-unit/lib/test/unit/attribute.rb +125 -0
- data/test-unit/lib/test/unit/autorunner.rb +306 -0
- data/test-unit/lib/test/unit/collector.rb +43 -0
- data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
- data/test-unit/lib/test/unit/collector/dir.rb +108 -0
- data/test-unit/lib/test/unit/collector/load.rb +135 -0
- data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
- data/test-unit/lib/test/unit/color-scheme.rb +86 -0
- data/test-unit/lib/test/unit/color.rb +96 -0
- data/test-unit/lib/test/unit/diff.rb +538 -0
- data/test-unit/lib/test/unit/error.rb +124 -0
- data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
- data/test-unit/lib/test/unit/failure.rb +110 -0
- data/test-unit/lib/test/unit/fixture.rb +176 -0
- data/test-unit/lib/test/unit/notification.rb +125 -0
- data/test-unit/lib/test/unit/omission.rb +143 -0
- data/test-unit/lib/test/unit/pending.rb +146 -0
- data/test-unit/lib/test/unit/priority.rb +161 -0
- data/test-unit/lib/test/unit/runner/console.rb +52 -0
- data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
- data/test-unit/lib/test/unit/testcase.rb +360 -0
- data/test-unit/lib/test/unit/testresult.rb +89 -0
- data/test-unit/lib/test/unit/testsuite.rb +110 -0
- data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
- data/test-unit/lib/test/unit/ui/console/testrunner.rb +220 -0
- data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +49 -0
- data/test-unit/lib/test/unit/ui/testrunner.rb +20 -0
- data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
- data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
- data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
- data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
- data/test-unit/lib/test/unit/util/observable.rb +90 -0
- data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
- data/test-unit/lib/test/unit/version.rb +7 -0
- data/test-unit/sample/adder.rb +13 -0
- data/test-unit/sample/subtracter.rb +12 -0
- data/test-unit/sample/tc_adder.rb +18 -0
- data/test-unit/sample/tc_subtracter.rb +18 -0
- data/test-unit/sample/test_user.rb +22 -0
- data/test-unit/sample/ts_examples.rb +7 -0
- data/test-unit/test/collector/test-descendant.rb +135 -0
- data/test-unit/test/collector/test-load.rb +333 -0
- data/test-unit/test/collector/test_dir.rb +406 -0
- data/test-unit/test/collector/test_objectspace.rb +98 -0
- data/test-unit/test/run-test.rb +13 -0
- data/test-unit/test/test-attribute.rb +86 -0
- data/test-unit/test/test-color-scheme.rb +56 -0
- data/test-unit/test/test-color.rb +47 -0
- data/test-unit/test/test-diff.rb +477 -0
- data/test-unit/test/test-emacs-runner.rb +60 -0
- data/test-unit/test/test-fixture.rb +287 -0
- data/test-unit/test/test-notification.rb +33 -0
- data/test-unit/test/test-omission.rb +81 -0
- data/test-unit/test/test-pending.rb +70 -0
- data/test-unit/test/test-priority.rb +119 -0
- data/test-unit/test/test_assertions.rb +1082 -0
- data/test-unit/test/test_error.rb +26 -0
- data/test-unit/test/test_failure.rb +33 -0
- data/test-unit/test/test_testcase.rb +478 -0
- data/test-unit/test/test_testresult.rb +113 -0
- data/test-unit/test/test_testsuite.rb +129 -0
- data/test-unit/test/testunit-test-util.rb +14 -0
- data/test-unit/test/ui/test_testrunmediator.rb +20 -0
- data/test-unit/test/util/test-method-owner-finder.rb +38 -0
- data/test-unit/test/util/test_backtracefilter.rb +41 -0
- data/test-unit/test/util/test_observable.rb +102 -0
- data/test-unit/test/util/test_procwrapper.rb +36 -0
- data/test/.gitignore +1 -0
- data/test/groonga-test-utils.rb +90 -0
- data/test/run-test.rb +54 -0
- data/test/test-column.rb +190 -0
- data/test/test-context.rb +90 -0
- data/test/test-database.rb +62 -0
- data/test/test-encoding.rb +33 -0
- data/test/test-exception.rb +85 -0
- data/test/test-procedure.rb +35 -0
- data/test/test-query.rb +22 -0
- data/test/test-record.rb +188 -0
- data/test/test-snippet.rb +121 -0
- data/test/test-table-cursor.rb +51 -0
- data/test/test-table.rb +447 -0
- data/test/test-type.rb +52 -0
- data/test/test-version.rb +31 -0
- metadata +213 -0
@@ -0,0 +1,51 @@
|
|
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 TableCursorTest < Test::Unit::TestCase
|
17
|
+
include GroongaTestUtils
|
18
|
+
|
19
|
+
def setup
|
20
|
+
setup_database
|
21
|
+
|
22
|
+
@bookmarks_path = @tables_dir + "table"
|
23
|
+
@bookmarks = Groonga::PatriciaTrie.create(:name => "bookmarks",
|
24
|
+
:path => @bookmarks_path.to_s)
|
25
|
+
@groonga_bookmark = @bookmarks.add("groonga")
|
26
|
+
@cutter_bookmark = @bookmarks.add("Cutter")
|
27
|
+
@ruby_bookmark = @bookmarks.add("Ruby")
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_open
|
31
|
+
keys = []
|
32
|
+
@bookmarks.open_cursor do |cursor|
|
33
|
+
while cursor.next
|
34
|
+
keys << cursor.key
|
35
|
+
end
|
36
|
+
end
|
37
|
+
assert_equal(["Cutter", "Ruby", "groonga"],
|
38
|
+
keys)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_open_ascendent
|
42
|
+
record_and_key_list = []
|
43
|
+
@bookmarks.open_cursor(:order => :ascending) do |cursor|
|
44
|
+
record_and_key_list = cursor.collect {|record| [record, cursor.key]}
|
45
|
+
end
|
46
|
+
assert_equal([[@cutter_bookmark, "Cutter"],
|
47
|
+
[@ruby_bookmark, "Ruby"],
|
48
|
+
[@groonga_bookmark, "groonga"]],
|
49
|
+
record_and_key_list)
|
50
|
+
end
|
51
|
+
end
|
data/test/test-table.rb
ADDED
@@ -0,0 +1,447 @@
|
|
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 TableTest < Test::Unit::TestCase
|
17
|
+
include GroongaTestUtils
|
18
|
+
|
19
|
+
setup :setup_database
|
20
|
+
|
21
|
+
def test_create
|
22
|
+
table_path = @tables_dir + "table"
|
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_equal([], @tables_dir.children)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_open
|
37
|
+
table_path = @tables_dir + "table"
|
38
|
+
table = Groonga::Hash.create(:name => "bookmarks",
|
39
|
+
:path => table_path.to_s)
|
40
|
+
assert_equal("bookmarks", table.name)
|
41
|
+
table.close
|
42
|
+
|
43
|
+
called = false
|
44
|
+
Groonga::Table.open(:name => "bookmarks") do |_table|
|
45
|
+
table = _table
|
46
|
+
assert_not_predicate(table, :closed?)
|
47
|
+
assert_equal("bookmarks", _table.name)
|
48
|
+
called = true
|
49
|
+
end
|
50
|
+
assert_true(called)
|
51
|
+
assert_predicate(table, :closed?)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_open_by_path
|
55
|
+
table_path = @tables_dir + "table"
|
56
|
+
table = Groonga::PatriciaTrie.create(:name => "bookmarks",
|
57
|
+
:path => table_path.to_s)
|
58
|
+
assert_equal("bookmarks", table.name)
|
59
|
+
table.close
|
60
|
+
|
61
|
+
called = false
|
62
|
+
Groonga::Table.open(:path => table_path.to_s) do |_table|
|
63
|
+
table = _table
|
64
|
+
assert_not_predicate(table, :closed?)
|
65
|
+
assert_nil(_table.name)
|
66
|
+
called = true
|
67
|
+
end
|
68
|
+
assert_true(called)
|
69
|
+
assert_predicate(table, :closed?)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_open_override_name
|
73
|
+
table_path = @tables_dir + "table"
|
74
|
+
table = Groonga::PatriciaTrie.create(:name => "bookmarks",
|
75
|
+
:path => table_path.to_s)
|
76
|
+
assert_equal("bookmarks", table.name)
|
77
|
+
table.close
|
78
|
+
|
79
|
+
called = false
|
80
|
+
Groonga::Table.open(:name => "no-name", :path => table_path.to_s) do |_table|
|
81
|
+
table = _table
|
82
|
+
assert_not_predicate(table, :closed?)
|
83
|
+
assert_equal("no-name", _table.name)
|
84
|
+
called = true
|
85
|
+
end
|
86
|
+
assert_true(called)
|
87
|
+
assert_predicate(table, :closed?)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_open_wrong_table
|
91
|
+
table_path = @tables_dir + "table"
|
92
|
+
Groonga::Hash.create(:name => "bookmarks",
|
93
|
+
:path => table_path.to_s) do
|
94
|
+
end
|
95
|
+
|
96
|
+
assert_raise(TypeError) do
|
97
|
+
Groonga::PatriciaTrie.open(:name => "bookmarks",
|
98
|
+
:path => table_path.to_s)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_new
|
103
|
+
table_path = @tables_dir + "table"
|
104
|
+
assert_raise(Groonga::NoSuchFileOrDirectory) do
|
105
|
+
Groonga::Hash.new(:path => table_path.to_s)
|
106
|
+
end
|
107
|
+
|
108
|
+
Groonga::Hash.create(:path => table_path.to_s)
|
109
|
+
assert_not_predicate(Groonga::Hash.new(:path => table_path.to_s), :closed?)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_define_column
|
113
|
+
table_path = @tables_dir + "table"
|
114
|
+
table = Groonga::Hash.create(:name => "bookmarks",
|
115
|
+
:path => table_path.to_s)
|
116
|
+
column = table.define_column("name", "<text>",
|
117
|
+
:type => "index",
|
118
|
+
:compress => "zlib",
|
119
|
+
:with_section => true,
|
120
|
+
:with_weight => true,
|
121
|
+
:with_position => true)
|
122
|
+
assert_equal("bookmarks.name", column.name)
|
123
|
+
assert_equal(column, table.column("name"))
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_add_column
|
127
|
+
bookmarks = Groonga::Hash.create(:name => "bookmarks",
|
128
|
+
:path => (@tables_dir + "bookmarks").to_s)
|
129
|
+
|
130
|
+
description_column_path = @columns_dir + "description"
|
131
|
+
bookmarks_description =
|
132
|
+
bookmarks.define_column("description", "<text>",
|
133
|
+
:type => "index",
|
134
|
+
:path => description_column_path.to_s)
|
135
|
+
|
136
|
+
books = Groonga::Hash.create(:name => "books",
|
137
|
+
:path => (@tables_dir + "books").to_s)
|
138
|
+
books_description = books.add_column("description",
|
139
|
+
"<longtext>",
|
140
|
+
description_column_path.to_s)
|
141
|
+
assert_equal("books.description", books_description.name)
|
142
|
+
assert_equal(books_description, books.column("description"))
|
143
|
+
|
144
|
+
assert_equal(bookmarks_description, bookmarks.column("description"))
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_column_nonexistent
|
148
|
+
table_path = @tables_dir + "bookmarks"
|
149
|
+
table = Groonga::Hash.create(:name => "bookmarks",
|
150
|
+
:path => table_path.to_s)
|
151
|
+
assert_nil(table.column("nonexistent"))
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_set_value
|
155
|
+
table_path = @tables_dir + "bookmarks"
|
156
|
+
bookmarks = Groonga::Hash.create(:name => "bookmarks",
|
157
|
+
:value_size => 512,
|
158
|
+
:path => table_path.to_s)
|
159
|
+
comment_column_path = @columns_dir + "comment"
|
160
|
+
bookmarks_comment =
|
161
|
+
bookmarks.define_column("comment", "<shorttext>",
|
162
|
+
:type => "scalar",
|
163
|
+
:path => comment_column_path.to_s)
|
164
|
+
groonga = bookmarks.add("groonga")
|
165
|
+
url = "http://groonga.org/"
|
166
|
+
groonga.value = url
|
167
|
+
bookmarks_comment[groonga.id] = "fulltext search engine"
|
168
|
+
|
169
|
+
assert_equal([url, "fulltext search engine"],
|
170
|
+
[groonga.value[0, url.length],
|
171
|
+
bookmarks_comment[groonga.id]])
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_array_set
|
175
|
+
bookmarks = Groonga::Hash.create(:name => "bookmarks",
|
176
|
+
:value_size => 512)
|
177
|
+
url = "http://groonga.org/"
|
178
|
+
bookmarks["groonga"] = "#{url}\0"
|
179
|
+
|
180
|
+
values = bookmarks.records.collect do |record|
|
181
|
+
record.value.split(/\0/, 2)[0]
|
182
|
+
end
|
183
|
+
assert_equal([url], values)
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_add_without_name
|
187
|
+
users_path = @tables_dir + "users"
|
188
|
+
users = Groonga::Array.create(:name => "users",
|
189
|
+
:path => users_path.to_s)
|
190
|
+
name_column_path = @columns_dir + "name"
|
191
|
+
users_name = users.define_column("name", "<shorttext>",
|
192
|
+
:path => name_column_path.to_s)
|
193
|
+
morita = users.add
|
194
|
+
users_name[morita.id] = "morita"
|
195
|
+
assert_equal("morita", users_name[morita.id])
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_add_by_id
|
199
|
+
users_path = @tables_dir + "users"
|
200
|
+
users = Groonga::Hash.create(:name => "users",
|
201
|
+
:path => users_path.to_s)
|
202
|
+
bookmarks_path = @tables_dir + "bookmarks"
|
203
|
+
bookmarks = Groonga::Hash.create(:name => "bookmarks",
|
204
|
+
:key_type => users,
|
205
|
+
:value_size => 512,
|
206
|
+
:path => bookmarks_path.to_s)
|
207
|
+
morita = users.add("morita")
|
208
|
+
groonga = bookmarks.add(morita.id)
|
209
|
+
url = "http://groonga.org/"
|
210
|
+
groonga.value = url
|
211
|
+
|
212
|
+
assert_equal(url, groonga.value[0, url.length])
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_columns
|
216
|
+
bookmarks_path = @tables_dir + "bookmarks"
|
217
|
+
bookmarks = Groonga::Array.create(:name => "bookmarks",
|
218
|
+
:path => bookmarks_path.to_s)
|
219
|
+
|
220
|
+
uri_column = bookmarks.define_column("uri", "<shorttext>")
|
221
|
+
comment_column = bookmarks.define_column("comment", "<text>")
|
222
|
+
assert_equal([uri_column.name, comment_column.name].sort,
|
223
|
+
bookmarks.columns.collect {|column| column.name}.sort)
|
224
|
+
end
|
225
|
+
|
226
|
+
def test_size
|
227
|
+
bookmarks_path = @tables_dir + "bookmarks"
|
228
|
+
bookmarks = Groonga::Array.create(:name => "bookmarks",
|
229
|
+
:path => bookmarks_path.to_s)
|
230
|
+
|
231
|
+
assert_equal(0, bookmarks.size)
|
232
|
+
|
233
|
+
bookmarks.add
|
234
|
+
bookmarks.add
|
235
|
+
bookmarks.add
|
236
|
+
|
237
|
+
assert_equal(3, bookmarks.size)
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_time_column
|
241
|
+
bookmarks_path = @tables_dir + "bookmarks"
|
242
|
+
bookmarks = Groonga::Array.create(:name => "bookmarks",
|
243
|
+
:path => bookmarks_path.to_s)
|
244
|
+
column = bookmarks.define_column("created_at", "<time>")
|
245
|
+
|
246
|
+
bookmark = bookmarks.add
|
247
|
+
now = Time.now
|
248
|
+
bookmark["created_at"] = now
|
249
|
+
assert_equal(now.to_a,
|
250
|
+
bookmark["created_at"].to_a)
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_delete
|
254
|
+
bookmarks_path = @tables_dir + "bookmarks"
|
255
|
+
bookmarks = Groonga::Array.create(:name => "bookmarks",
|
256
|
+
:path => bookmarks_path.to_s)
|
257
|
+
|
258
|
+
bookmark1 = bookmarks.add
|
259
|
+
bookmark2 = bookmarks.add
|
260
|
+
bookmark3 = bookmarks.add
|
261
|
+
|
262
|
+
assert_equal(3, bookmarks.size)
|
263
|
+
bookmarks.delete(bookmark2.id)
|
264
|
+
assert_equal(2, bookmarks.size)
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_remove
|
268
|
+
bookmarks_path = @tables_dir + "bookmarks"
|
269
|
+
bookmarks = Groonga::Array.create(:name => "bookmarks",
|
270
|
+
:path => bookmarks_path.to_s)
|
271
|
+
assert_predicate(bookmarks_path, :exist?)
|
272
|
+
bookmarks.remove
|
273
|
+
assert_not_predicate(bookmarks_path, :exist?)
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_array_reference
|
277
|
+
bookmarks_path = @tables_dir + "bookmarks"
|
278
|
+
bookmarks = Groonga::Hash.create(:name => "bookmarks",
|
279
|
+
:path => bookmarks_path.to_s,
|
280
|
+
:key_type => "<shorttext>")
|
281
|
+
bookmark = bookmarks.add("http://google.com/")
|
282
|
+
assert_equal(bookmark, bookmarks["http://google.com/"])
|
283
|
+
end
|
284
|
+
|
285
|
+
def test_tokenizer
|
286
|
+
table = Groonga::Hash.create
|
287
|
+
assert_equal(Groonga::Context.default["<token:bigram>"],
|
288
|
+
table.default_tokenizer)
|
289
|
+
table.default_tokenizer = "<token:mecab>"
|
290
|
+
assert_equal(Groonga::Context.default["<token:mecab>"],
|
291
|
+
table.default_tokenizer)
|
292
|
+
end
|
293
|
+
|
294
|
+
def test_inspect_anonymous
|
295
|
+
path = @tables_dir + "anoymous.groonga"
|
296
|
+
anonymous_table = Groonga::Hash.create(:path => path.to_s)
|
297
|
+
assert_equal("#<Groonga::Hash " +
|
298
|
+
"id: <#{anonymous_table.id}>, " +
|
299
|
+
"name: (anonymous), " +
|
300
|
+
"path: <#{path}>, " +
|
301
|
+
"domain: <nil>, " +
|
302
|
+
"range: <nil>, " +
|
303
|
+
"encoding: <#{encoding.inspect}>, " +
|
304
|
+
"size: <0>>",
|
305
|
+
anonymous_table.inspect)
|
306
|
+
end
|
307
|
+
|
308
|
+
def test_inspect_anonymous_temporary
|
309
|
+
anonymous_table = Groonga::Hash.create
|
310
|
+
assert_equal("#<Groonga::Hash " +
|
311
|
+
"id: <#{anonymous_table.id}>, " +
|
312
|
+
"name: (anonymous), " +
|
313
|
+
"path: (temporary), " +
|
314
|
+
"domain: <nil>, " +
|
315
|
+
"range: <nil>, " +
|
316
|
+
"encoding: <#{encoding.inspect}>, " +
|
317
|
+
"size: <0>>",
|
318
|
+
anonymous_table.inspect)
|
319
|
+
end
|
320
|
+
|
321
|
+
def test_inspect_named
|
322
|
+
path = @tables_dir + "named.groonga"
|
323
|
+
named_table = Groonga::Hash.create(:name => "name", :path => path.to_s)
|
324
|
+
assert_equal("#<Groonga::Hash " +
|
325
|
+
"id: <#{named_table.id}>, " +
|
326
|
+
"name: <name>, " +
|
327
|
+
"path: <#{path}>, " +
|
328
|
+
"domain: <nil>, " +
|
329
|
+
"range: <nil>, " +
|
330
|
+
"encoding: <#{encoding.inspect}>, " +
|
331
|
+
"size: <0>>",
|
332
|
+
named_table.inspect)
|
333
|
+
end
|
334
|
+
|
335
|
+
def test_inspect_named_temporary
|
336
|
+
named_table = Groonga::Hash.create(:name => "name")
|
337
|
+
assert_equal("#<Groonga::Hash " +
|
338
|
+
"id: <#{named_table.id}>, " +
|
339
|
+
"name: <name>, " +
|
340
|
+
"path: (temporary), " +
|
341
|
+
"domain: <nil>, " +
|
342
|
+
"range: <nil>, " +
|
343
|
+
"encoding: <#{encoding.inspect}>, " +
|
344
|
+
"size: <0>>",
|
345
|
+
named_table.inspect)
|
346
|
+
end
|
347
|
+
|
348
|
+
def test_inspect_size
|
349
|
+
path = @tables_dir + "named.groonga"
|
350
|
+
contain_table = Groonga::Array.create(:name => "name", :path => path.to_s)
|
351
|
+
3.times do
|
352
|
+
contain_table.add
|
353
|
+
end
|
354
|
+
assert_equal("#<Groonga::Array " +
|
355
|
+
"id: <#{contain_table.id}>, " +
|
356
|
+
"name: <name>, " +
|
357
|
+
"path: <#{path}>, " +
|
358
|
+
"domain: <nil>, " +
|
359
|
+
"range: <nil>, " +
|
360
|
+
"size: <3>>",
|
361
|
+
contain_table.inspect)
|
362
|
+
end
|
363
|
+
|
364
|
+
def test_temporary_add
|
365
|
+
table = Groonga::Hash.create(:key_type => "<shorttext>")
|
366
|
+
assert_equal(0, table.size)
|
367
|
+
table.add("key")
|
368
|
+
assert_equal(1, table.size)
|
369
|
+
end
|
370
|
+
|
371
|
+
def test_search
|
372
|
+
users = Groonga::Array.create(:name => "<users>")
|
373
|
+
user_name = users.define_column("name", "<shorttext>")
|
374
|
+
|
375
|
+
bookmarks = Groonga::Hash.create(:name => "<bookmarks>",
|
376
|
+
:key_type => "<shorttext>")
|
377
|
+
bookmark_user_id = bookmarks.define_column("user_id", users)
|
378
|
+
|
379
|
+
daijiro = users.add
|
380
|
+
daijiro["name"] = "daijiro"
|
381
|
+
gunyarakun = users.add
|
382
|
+
gunyarakun["name"] = "gunyarakun"
|
383
|
+
|
384
|
+
groonga = bookmarks.add("http://groonga.org/")
|
385
|
+
groonga["user_id"] = daijiro
|
386
|
+
|
387
|
+
records = bookmarks.search("http://groonga.org/")
|
388
|
+
assert_equal(["daijiro"],
|
389
|
+
records.records.collect {|record| record[".user_id.name"]})
|
390
|
+
end
|
391
|
+
|
392
|
+
def test_each
|
393
|
+
users = Groonga::Array.create(:name => "<users>")
|
394
|
+
user_name = users.define_column("name", "<shorttext>")
|
395
|
+
|
396
|
+
names = ["daijiro", "gunyarakun", "yu"]
|
397
|
+
names.each do |name|
|
398
|
+
user = users.add
|
399
|
+
user["name"] = name
|
400
|
+
end
|
401
|
+
|
402
|
+
assert_equal(names.sort, users.collect {|user| user["name"]}.sort)
|
403
|
+
end
|
404
|
+
|
405
|
+
def test_truncate
|
406
|
+
users = Groonga::Array.create(:name => "<users>")
|
407
|
+
users.add
|
408
|
+
users.add
|
409
|
+
users.add
|
410
|
+
assert_equal(3, users.size)
|
411
|
+
assert_nothing_raised do
|
412
|
+
users.truncate
|
413
|
+
end
|
414
|
+
# assert_equal(0, users.size) # truncate isn't implemented in groonga.
|
415
|
+
end
|
416
|
+
|
417
|
+
def test_encoding
|
418
|
+
assert_equal(Groonga::Encoding.default,
|
419
|
+
Groonga::Hash.create.encoding)
|
420
|
+
assert_equal(Groonga::Encoding.default,
|
421
|
+
Groonga::PatriciaTrie.create.encoding)
|
422
|
+
|
423
|
+
array = Groonga::Array.create
|
424
|
+
assert_false(array.respond_to?(:encoding))
|
425
|
+
end
|
426
|
+
|
427
|
+
def test_sort
|
428
|
+
bookmarks = Groonga::Array.create(:name => "<bookmarks>")
|
429
|
+
id_column = bookmarks.define_column("id", "<int>")
|
430
|
+
100.times do |i|
|
431
|
+
bookmark = bookmarks.add
|
432
|
+
bookmark["id"] = i + 100
|
433
|
+
end
|
434
|
+
|
435
|
+
results = bookmarks.sort([
|
436
|
+
{
|
437
|
+
:key => "id",
|
438
|
+
:order => :descending,
|
439
|
+
},
|
440
|
+
],
|
441
|
+
:limit => 20)
|
442
|
+
results = results.records(:order => :ascending).collect do |record|
|
443
|
+
id_column[record.value.unpack("i")[0]]
|
444
|
+
end
|
445
|
+
assert_equal((180..199).to_a.reverse, results)
|
446
|
+
end
|
447
|
+
end
|