rroonga 0.9.2-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +5 -0
- data/NEWS.ja.rdoc +114 -0
- data/NEWS.rdoc +116 -0
- data/README.ja.rdoc +65 -0
- data/README.rdoc +66 -0
- data/Rakefile +206 -0
- data/benchmark/common.rb +49 -0
- data/benchmark/read-write-many-small-items.rb +144 -0
- data/benchmark/write-many-small-items.rb +135 -0
- data/example/bookmark.rb +161 -0
- data/example/index-html.rb +89 -0
- data/example/search/config.ru +230 -0
- data/example/search/public/css/groonga.css +122 -0
- data/ext/.gitignore +2 -0
- data/ext/groonga/extconf.rb +93 -0
- data/ext/groonga/rb-grn-accessor.c +52 -0
- data/ext/groonga/rb-grn-array-cursor.c +36 -0
- data/ext/groonga/rb-grn-array.c +210 -0
- data/ext/groonga/rb-grn-column.c +573 -0
- data/ext/groonga/rb-grn-context.c +662 -0
- data/ext/groonga/rb-grn-database.c +472 -0
- data/ext/groonga/rb-grn-encoding-support.c +64 -0
- data/ext/groonga/rb-grn-encoding.c +257 -0
- data/ext/groonga/rb-grn-exception.c +1110 -0
- data/ext/groonga/rb-grn-expression-builder.c +75 -0
- data/ext/groonga/rb-grn-expression.c +731 -0
- data/ext/groonga/rb-grn-fix-size-column.c +166 -0
- data/ext/groonga/rb-grn-hash-cursor.c +38 -0
- data/ext/groonga/rb-grn-hash.c +294 -0
- data/ext/groonga/rb-grn-index-column.c +488 -0
- data/ext/groonga/rb-grn-logger.c +504 -0
- data/ext/groonga/rb-grn-object.c +1369 -0
- data/ext/groonga/rb-grn-operation.c +198 -0
- data/ext/groonga/rb-grn-patricia-trie-cursor.c +39 -0
- data/ext/groonga/rb-grn-patricia-trie.c +488 -0
- data/ext/groonga/rb-grn-procedure.c +52 -0
- data/ext/groonga/rb-grn-query.c +260 -0
- data/ext/groonga/rb-grn-record.c +40 -0
- data/ext/groonga/rb-grn-snippet.c +334 -0
- data/ext/groonga/rb-grn-table-cursor-key-support.c +69 -0
- data/ext/groonga/rb-grn-table-cursor.c +247 -0
- data/ext/groonga/rb-grn-table-key-support.c +714 -0
- data/ext/groonga/rb-grn-table.c +1977 -0
- data/ext/groonga/rb-grn-type.c +181 -0
- data/ext/groonga/rb-grn-utils.c +769 -0
- data/ext/groonga/rb-grn-variable-size-column.c +36 -0
- data/ext/groonga/rb-grn-variable.c +108 -0
- data/ext/groonga/rb-grn-view-accessor.c +53 -0
- data/ext/groonga/rb-grn-view-cursor.c +35 -0
- data/ext/groonga/rb-grn-view-record.c +41 -0
- data/ext/groonga/rb-grn-view.c +421 -0
- data/ext/groonga/rb-grn.h +698 -0
- data/ext/groonga/rb-groonga.c +107 -0
- data/extconf.rb +130 -0
- data/html/bar.svg +153 -0
- data/html/developer.html +117 -0
- data/html/developer.svg +469 -0
- data/html/download.svg +253 -0
- data/html/favicon.ico +0 -0
- data/html/favicon.xcf +0 -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 +147 -0
- data/html/install.svg +636 -0
- data/html/logo.xcf +0 -0
- data/html/ranguba.css +250 -0
- data/html/tutorial.svg +559 -0
- data/lib/1.8/groonga.so +0 -0
- data/lib/1.9/groonga.so +0 -0
- data/lib/groonga.rb +90 -0
- data/lib/groonga/context.rb +184 -0
- data/lib/groonga/expression-builder.rb +324 -0
- data/lib/groonga/patricia-trie.rb +85 -0
- data/lib/groonga/record.rb +311 -0
- data/lib/groonga/schema.rb +1191 -0
- data/lib/groonga/view-record.rb +56 -0
- data/license/GPL +340 -0
- data/license/LGPL +504 -0
- data/license/RUBY +59 -0
- data/misc/grnop2ruby.rb +49 -0
- data/pkg-config.rb +333 -0
- data/rroonga-build.rb +57 -0
- data/test-unit/Rakefile +40 -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 +323 -0
- data/test-unit/lib/test/unit/assertionfailederror.rb +25 -0
- data/test-unit/lib/test/unit/assertions.rb +1230 -0
- data/test-unit/lib/test/unit/attribute.rb +125 -0
- data/test-unit/lib/test/unit/autorunner.rb +360 -0
- data/test-unit/lib/test/unit/collector.rb +36 -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 +144 -0
- data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
- data/test-unit/lib/test/unit/color-scheme.rb +102 -0
- data/test-unit/lib/test/unit/color.rb +96 -0
- data/test-unit/lib/test/unit/diff.rb +724 -0
- data/test-unit/lib/test/unit/error.rb +130 -0
- data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
- data/test-unit/lib/test/unit/failure.rb +136 -0
- data/test-unit/lib/test/unit/fixture.rb +176 -0
- data/test-unit/lib/test/unit/notification.rb +129 -0
- data/test-unit/lib/test/unit/omission.rb +191 -0
- data/test-unit/lib/test/unit/pending.rb +150 -0
- data/test-unit/lib/test/unit/priority.rb +180 -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/runner/tap.rb +8 -0
- data/test-unit/lib/test/unit/testcase.rb +476 -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 +466 -0
- data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +63 -0
- data/test-unit/lib/test/unit/ui/tap/testrunner.rb +92 -0
- data/test-unit/lib/test/unit/ui/testrunner.rb +28 -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/test_adder.rb +20 -0
- data/test-unit/sample/test_subtracter.rb +20 -0
- data/test-unit/sample/test_user.rb +23 -0
- data/test-unit/test/collector/test-descendant.rb +133 -0
- data/test-unit/test/collector/test-load.rb +442 -0
- data/test-unit/test/collector/test_dir.rb +406 -0
- data/test-unit/test/collector/test_objectspace.rb +100 -0
- data/test-unit/test/run-test.rb +15 -0
- data/test-unit/test/test-attribute.rb +86 -0
- data/test-unit/test/test-color-scheme.rb +67 -0
- data/test-unit/test/test-color.rb +47 -0
- data/test-unit/test/test-diff.rb +518 -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-testcase.rb +544 -0
- data/test-unit/test/test_assertions.rb +1151 -0
- data/test-unit/test/test_error.rb +26 -0
- data/test-unit/test/test_failure.rb +33 -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 +134 -0
- data/test/run-test.rb +58 -0
- data/test/test-array.rb +90 -0
- data/test/test-column.rb +316 -0
- data/test/test-context-select.rb +93 -0
- data/test/test-context.rb +73 -0
- data/test/test-database.rb +113 -0
- data/test/test-encoding.rb +33 -0
- data/test/test-exception.rb +93 -0
- data/test/test-expression-builder.rb +217 -0
- data/test/test-expression.rb +134 -0
- data/test/test-fix-size-column.rb +65 -0
- data/test/test-gqtp.rb +72 -0
- data/test/test-hash.rb +305 -0
- data/test/test-index-column.rb +81 -0
- data/test/test-logger.rb +37 -0
- data/test/test-patricia-trie.rb +205 -0
- data/test/test-procedure.rb +37 -0
- data/test/test-query.rb +22 -0
- data/test/test-record.rb +243 -0
- data/test/test-remote.rb +54 -0
- data/test/test-schema-view.rb +90 -0
- data/test/test-schema.rb +459 -0
- data/test/test-snippet.rb +130 -0
- data/test/test-table-cursor.rb +153 -0
- data/test/test-table-offset-and-limit.rb +102 -0
- data/test/test-table-select-normalize.rb +53 -0
- data/test/test-table-select.rb +150 -0
- data/test/test-table.rb +594 -0
- data/test/test-type.rb +71 -0
- data/test/test-variable-size-column.rb +98 -0
- data/test/test-variable.rb +28 -0
- data/test/test-vector-column.rb +76 -0
- data/test/test-version.rb +31 -0
- data/test/test-view.rb +72 -0
- data/text/TUTORIAL.ja.rdoc +392 -0
- data/text/expression.rdoc +284 -0
- metadata +276 -0
@@ -0,0 +1,93 @@
|
|
1
|
+
# Copyright (C) 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 ContextSelectTest < Test::Unit::TestCase
|
17
|
+
include GroongaTestUtils
|
18
|
+
|
19
|
+
setup :setup_database
|
20
|
+
setup
|
21
|
+
def setup_data
|
22
|
+
@books = Groonga::Hash.create(:name => "Books", :key_type => "ShortText")
|
23
|
+
@books.define_column("published", "Time")
|
24
|
+
@users = Groonga::Hash.create(:name => "Users", :key_type => "ShortText")
|
25
|
+
@users.define_column("book", "Books")
|
26
|
+
|
27
|
+
@books.add("the groonga book", :published => Time.parse("2010/04/01"))
|
28
|
+
@users.add("morita", :book => "the groonga book")
|
29
|
+
@users.add("gunyara-kun", :book => "the groonga book")
|
30
|
+
@users.add("yu")
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_no_option
|
34
|
+
result = context.select(@users)
|
35
|
+
assert_equal([3,
|
36
|
+
[{"_id" => 1, "_key" => "morita",
|
37
|
+
"book" => "the groonga book"},
|
38
|
+
{"_id" => 2, "_key" => "gunyara-kun",
|
39
|
+
"book" => "the groonga book"},
|
40
|
+
{"_id" => 3, "_key" => "yu",
|
41
|
+
"book" => ""}]],
|
42
|
+
[result.n_hits, result.records])
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_success
|
46
|
+
result = context.select(@users)
|
47
|
+
assert_equal([true, 0, nil],
|
48
|
+
[result.success?, result.return_code, result.error_message])
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_output_columns
|
52
|
+
result = context.select(@users, :output_columns => ["_key"])
|
53
|
+
assert_equal([3,
|
54
|
+
[{"_key" => "morita"},
|
55
|
+
{"_key" => "gunyara-kun"},
|
56
|
+
{"_key" => "yu"}]],
|
57
|
+
[result.n_hits, result.records])
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_drill_down
|
61
|
+
result = context.select(@users,
|
62
|
+
:output_columns => ["_key"],
|
63
|
+
:drill_down => ["_key", "book"],
|
64
|
+
:drill_down_output_columns => "_key",
|
65
|
+
:drill_down_limit => 10)
|
66
|
+
normalized_drill_down = {}
|
67
|
+
result.drill_down.each do |key, drill_down|
|
68
|
+
normalized_drill_down[key] = [drill_down.n_hits, drill_down.records]
|
69
|
+
end
|
70
|
+
assert_equal([3,
|
71
|
+
[{"_key" => "morita"},
|
72
|
+
{"_key" => "gunyara-kun"},
|
73
|
+
{"_key" => "yu"}],
|
74
|
+
{
|
75
|
+
"_key" => [3, [{"_key" => "morita"},
|
76
|
+
{"_key" => "gunyara-kun"},
|
77
|
+
{"_key" => "yu"}]],
|
78
|
+
"book" => [1, [{"_key" => "the groonga book"}]],
|
79
|
+
},
|
80
|
+
],
|
81
|
+
[result.n_hits, result.records, normalized_drill_down])
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_time
|
85
|
+
result = context.select(@books)
|
86
|
+
assert_equal([{
|
87
|
+
"_id" => 1,
|
88
|
+
"_key" => "the groonga book",
|
89
|
+
"published" => Time.parse("2010/04/01"),
|
90
|
+
}],
|
91
|
+
result.records)
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,73 @@
|
|
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 ContextTest < Test::Unit::TestCase
|
17
|
+
include GroongaTestUtils
|
18
|
+
|
19
|
+
def test_default
|
20
|
+
context = Groonga::Context.default
|
21
|
+
assert_equal(Groonga::Encoding.default, context.encoding)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_default_options
|
25
|
+
Groonga::Context.default_options = {
|
26
|
+
:encoding => :utf8,
|
27
|
+
}
|
28
|
+
context = Groonga::Context.default
|
29
|
+
assert_equal(Groonga::Encoding::UTF8, context.encoding)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_encoding
|
33
|
+
context = Groonga::Context.new
|
34
|
+
assert_equal(Groonga::Encoding.default, context.encoding)
|
35
|
+
|
36
|
+
context = Groonga::Context.new(:encoding => :utf8)
|
37
|
+
assert_equal(Groonga::Encoding::UTF8, context.encoding)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_inspect
|
41
|
+
context = Groonga::Context.new(:encoding => Groonga::Encoding::UTF8)
|
42
|
+
assert_equal("#<Groonga::Context " +
|
43
|
+
"encoding: <:utf8>, " +
|
44
|
+
"database: <nil>>",
|
45
|
+
context.inspect)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_inspect_with_database
|
49
|
+
db = Groonga::Database.create
|
50
|
+
context = Groonga::Context.default
|
51
|
+
assert_equal("#<Groonga::Context " +
|
52
|
+
"encoding: <#{Groonga::Encoding.default.inspect}>, " +
|
53
|
+
"database: <#{db.inspect}>>",
|
54
|
+
context.inspect)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_array_reference_by_string
|
58
|
+
Groonga::Database.create
|
59
|
+
context = Groonga::Context.default
|
60
|
+
assert_equal("Int32", context["<int>"].name)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_array_reference_by_symbol
|
64
|
+
Groonga::Database.create
|
65
|
+
context = Groonga::Context.default
|
66
|
+
assert_equal("Bool", context[:Bool].name)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_shortcut_access
|
70
|
+
Groonga::Database.create
|
71
|
+
assert_equal("ShortText", Groonga["ShortText"].name)
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,113 @@
|
|
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 DatabaseTest < Test::Unit::TestCase
|
17
|
+
include GroongaTestUtils
|
18
|
+
|
19
|
+
def test_create
|
20
|
+
assert_nil(Groonga::Context.default.database)
|
21
|
+
|
22
|
+
db_path = @tmp_dir + "db"
|
23
|
+
assert_not_predicate(db_path, :exist?)
|
24
|
+
database = Groonga::Database.create(:path => db_path.to_s)
|
25
|
+
assert_predicate(db_path, :exist?)
|
26
|
+
assert_not_predicate(database, :closed?)
|
27
|
+
|
28
|
+
assert_equal(database, Groonga::Context.default.database)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_temporary
|
32
|
+
before_files = @tmp_dir.children
|
33
|
+
database = Groonga::Database.create
|
34
|
+
assert_nil(database.name)
|
35
|
+
assert_equal(before_files, @tmp_dir.children)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_open
|
39
|
+
db_path = @tmp_dir + "db"
|
40
|
+
database = Groonga::Database.create(:path => db_path.to_s)
|
41
|
+
|
42
|
+
called = false
|
43
|
+
Groonga::Database.open(db_path.to_s) do |_database|
|
44
|
+
database = _database
|
45
|
+
assert_not_predicate(database, :closed?)
|
46
|
+
called = true
|
47
|
+
end
|
48
|
+
assert_true(called)
|
49
|
+
assert_predicate(database, :closed?)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_new
|
53
|
+
db_path = @tmp_dir + "db"
|
54
|
+
assert_raise(Groonga::NoSuchFileOrDirectory) do
|
55
|
+
Groonga::Database.new(db_path.to_s)
|
56
|
+
end
|
57
|
+
|
58
|
+
database = Groonga::Database.create(:path => db_path.to_s)
|
59
|
+
|
60
|
+
assert_not_predicate(Groonga::Database.new(db_path.to_s), :closed?)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_each
|
64
|
+
db_path = @tmp_dir + "db"
|
65
|
+
database = Groonga::Database.create(:path => db_path.to_s)
|
66
|
+
default_object_names = database.collect {|object| object.name}.sort
|
67
|
+
assert_send([default_object_names, :include?, "Bool"])
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_encoding
|
71
|
+
assert_equal(Groonga::Encoding.default,
|
72
|
+
Groonga::Database.create.encoding)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_lock
|
76
|
+
database = Groonga::Database.create
|
77
|
+
|
78
|
+
assert_not_predicate(database, :locked?)
|
79
|
+
database.lock
|
80
|
+
assert_predicate(database, :locked?)
|
81
|
+
database.unlock
|
82
|
+
assert_not_predicate(database, :locked?)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_lock_failed
|
86
|
+
database = Groonga::Database.create
|
87
|
+
|
88
|
+
database.lock
|
89
|
+
assert_raise(Groonga::ResourceDeadlockAvoided) do
|
90
|
+
database.lock
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_lock_block
|
95
|
+
database = Groonga::Database.create
|
96
|
+
|
97
|
+
assert_not_predicate(database, :locked?)
|
98
|
+
database.lock do
|
99
|
+
assert_predicate(database, :locked?)
|
100
|
+
end
|
101
|
+
assert_not_predicate(database, :locked?)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_clear_lock
|
105
|
+
database = Groonga::Database.create
|
106
|
+
|
107
|
+
assert_not_predicate(database, :locked?)
|
108
|
+
database.lock
|
109
|
+
assert_predicate(database, :locked?)
|
110
|
+
database.clear_lock
|
111
|
+
assert_not_predicate(database, :locked?)
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,33 @@
|
|
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 EncodingTest < Test::Unit::TestCase
|
17
|
+
include GroongaTestUtils
|
18
|
+
|
19
|
+
def test_constants
|
20
|
+
assert_equal(:default, Groonga::Encoding::DEFAULT)
|
21
|
+
assert_equal(:none, Groonga::Encoding::NONE)
|
22
|
+
assert_equal(:euc_jp, Groonga::Encoding::EUC_JP)
|
23
|
+
assert_equal(:sjis, Groonga::Encoding::SJIS)
|
24
|
+
assert_equal(:utf8, Groonga::Encoding::UTF8)
|
25
|
+
assert_equal(:latin1, Groonga::Encoding::LATIN1)
|
26
|
+
assert_equal(:koi8r, Groonga::Encoding::KOI8R)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_default
|
30
|
+
Groonga::Encoding.default = :utf8
|
31
|
+
assert_equal(:utf8, Groonga::Encoding.default)
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,93 @@
|
|
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 ExceptionTest < Test::Unit::TestCase
|
17
|
+
include GroongaTestUtils
|
18
|
+
|
19
|
+
def test_defined
|
20
|
+
assert_not_const_defined(Groonga, :Success)
|
21
|
+
|
22
|
+
assert_const_defined(Groonga, :Error)
|
23
|
+
assert_const_defined(Groonga, :ObjectClosed)
|
24
|
+
|
25
|
+
assert_const_defined(Groonga, :EndOfData)
|
26
|
+
assert_const_defined(Groonga, :UnknownError)
|
27
|
+
assert_const_defined(Groonga, :OperationNotPermitted)
|
28
|
+
assert_const_defined(Groonga, :NoSuchFileOrDirectory)
|
29
|
+
assert_const_defined(Groonga, :NoSuchProcess)
|
30
|
+
assert_const_defined(Groonga, :InterruptedFunctionCall)
|
31
|
+
assert_const_defined(Groonga, :InputOutputError)
|
32
|
+
assert_const_defined(Groonga, :NoSuchDeviceOrAddress)
|
33
|
+
assert_const_defined(Groonga, :ArgumentListTooLong)
|
34
|
+
assert_const_defined(Groonga, :ExecFormatError)
|
35
|
+
assert_const_defined(Groonga, :BadFileDescriptor)
|
36
|
+
assert_const_defined(Groonga, :NoChildProcesses)
|
37
|
+
assert_const_defined(Groonga, :ResourceTemporarilyUnavailable)
|
38
|
+
assert_const_defined(Groonga, :NotEnoughSpace)
|
39
|
+
assert_const_defined(Groonga, :PermissionDenied)
|
40
|
+
assert_const_defined(Groonga, :BadAddress)
|
41
|
+
assert_const_defined(Groonga, :ResourceBusy)
|
42
|
+
assert_const_defined(Groonga, :FileExists)
|
43
|
+
assert_const_defined(Groonga, :ImproperLink)
|
44
|
+
assert_const_defined(Groonga, :NoSuchDevice)
|
45
|
+
assert_const_defined(Groonga, :NotADirectory)
|
46
|
+
assert_const_defined(Groonga, :IsADirectory)
|
47
|
+
assert_const_defined(Groonga, :InvalidArgument)
|
48
|
+
assert_const_defined(Groonga, :TooManyOpenFilesInSystem)
|
49
|
+
assert_const_defined(Groonga, :TooManyOpenFiles)
|
50
|
+
assert_const_defined(Groonga, :InappropriateIOControlOperation)
|
51
|
+
assert_const_defined(Groonga, :FileTooLarge)
|
52
|
+
assert_const_defined(Groonga, :NoSpaceLeftOnDevice)
|
53
|
+
assert_const_defined(Groonga, :InvalidSeek)
|
54
|
+
assert_const_defined(Groonga, :ReadOnlyFileSystem)
|
55
|
+
assert_const_defined(Groonga, :TooManyLinks)
|
56
|
+
assert_const_defined(Groonga, :BrokenPipe)
|
57
|
+
assert_const_defined(Groonga, :DomainError)
|
58
|
+
assert_const_defined(Groonga, :ResultTooLarge)
|
59
|
+
assert_const_defined(Groonga, :ResourceDeadlockAvoided)
|
60
|
+
assert_const_defined(Groonga, :NoMemoryAvailable)
|
61
|
+
assert_const_defined(Groonga, :FilenameTooLong)
|
62
|
+
assert_const_defined(Groonga, :NoLocksAvailable)
|
63
|
+
assert_const_defined(Groonga, :FunctionNotImplemented)
|
64
|
+
assert_const_defined(Groonga, :DirectoryNotEmpty)
|
65
|
+
assert_const_defined(Groonga, :IllegalByteSequence)
|
66
|
+
assert_const_defined(Groonga, :SocketNotInitialized)
|
67
|
+
assert_const_defined(Groonga, :OperationWouldBlock)
|
68
|
+
assert_const_defined(Groonga, :AddressIsNotAvailable)
|
69
|
+
assert_const_defined(Groonga, :NetworkIsDown)
|
70
|
+
assert_const_defined(Groonga, :NoBuffer)
|
71
|
+
assert_const_defined(Groonga, :SocketIsAlreadyConnected)
|
72
|
+
assert_const_defined(Groonga, :SocketIsNotConnected)
|
73
|
+
assert_const_defined(Groonga, :SocketIsAlreadyShutdowned)
|
74
|
+
assert_const_defined(Groonga, :OperationTimeout)
|
75
|
+
assert_const_defined(Groonga, :ConnectionRefused)
|
76
|
+
assert_const_defined(Groonga, :RangeError)
|
77
|
+
assert_const_defined(Groonga, :TokenizerError)
|
78
|
+
assert_const_defined(Groonga, :FileCorrupt)
|
79
|
+
assert_const_defined(Groonga, :InvalidFormat)
|
80
|
+
assert_const_defined(Groonga, :ObjectCorrupt)
|
81
|
+
assert_const_defined(Groonga, :TooManySymbolicLinks)
|
82
|
+
assert_const_defined(Groonga, :NotSocket)
|
83
|
+
assert_const_defined(Groonga, :OperationNotSupported)
|
84
|
+
assert_const_defined(Groonga, :AddressIsInUse)
|
85
|
+
assert_const_defined(Groonga, :ZLibError)
|
86
|
+
assert_const_defined(Groonga, :LZOError)
|
87
|
+
assert_const_defined(Groonga, :StackOverFlow)
|
88
|
+
assert_const_defined(Groonga, :SyntaxError)
|
89
|
+
assert_const_defined(Groonga, :RetryMax)
|
90
|
+
assert_const_defined(Groonga, :IncompatibleFileFormat)
|
91
|
+
assert_const_defined(Groonga, :UpdateNotAllowed)
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,217 @@
|
|
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 ExpressionBuilderTest < Test::Unit::TestCase
|
17
|
+
include GroongaTestUtils
|
18
|
+
|
19
|
+
setup :setup_database
|
20
|
+
setup :setup_tables
|
21
|
+
setup :setup_data
|
22
|
+
|
23
|
+
def setup_tables
|
24
|
+
@pets = Groonga::Hash.create(:name => "Pets", :key_type => "ShortText")
|
25
|
+
@pets.define_column("name", "ShortText")
|
26
|
+
|
27
|
+
@users = Groonga::Hash.create(:name => "Users", :key_type => "ShortText")
|
28
|
+
@name = @users.define_column("name", "ShortText")
|
29
|
+
@hp = @users.define_column("hp", "UInt32")
|
30
|
+
@users.define_column("pet", @pets)
|
31
|
+
|
32
|
+
@terms = Groonga::PatriciaTrie.create(:name => "Terms",
|
33
|
+
:default_tokenizer => "TokenBigram")
|
34
|
+
@terms.define_index_column("user_name", @users, :source => @name)
|
35
|
+
|
36
|
+
@bookmarks = Groonga::Array.create(:name => "Bookmarks")
|
37
|
+
@bookmarks.define_column("user", @users)
|
38
|
+
@bookmarks.define_column("uri", "ShortText")
|
39
|
+
end
|
40
|
+
|
41
|
+
def setup_data
|
42
|
+
@morita = @users.add("morita",
|
43
|
+
:name => "mori daijiro",
|
44
|
+
:hp => 100)
|
45
|
+
@gunyara_kun = @users.add("gunyara-kun",
|
46
|
+
:name => "Tasuku SUENAGA",
|
47
|
+
:hp => 150)
|
48
|
+
@yu = @users.add("yu",
|
49
|
+
:name => "Yutaro Shimamura",
|
50
|
+
:hp => 200)
|
51
|
+
|
52
|
+
@groonga = @bookmarks.add(:user => @morita, :uri => "http://groonga.org/")
|
53
|
+
@ruby = @bookmarks.add(:user => @morita, :uri => "http://ruby-lang.org/")
|
54
|
+
@nico_dict = @bookmarks.add(:user => @gunyara_kun,
|
55
|
+
:uri => "http://dic.nicovideo.jp/")
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_equal
|
59
|
+
result = @users.select do |record|
|
60
|
+
record["name"] == "mori daijiro"
|
61
|
+
end
|
62
|
+
assert_equal(["morita"],
|
63
|
+
result.collect {|record| record.key.key})
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_not_equal
|
67
|
+
omit("not supported yet!!!")
|
68
|
+
result = @users.select do |record|
|
69
|
+
record["name"] != "mori daijiro"
|
70
|
+
end
|
71
|
+
assert_equal(["gunyara-kun", "yu"],
|
72
|
+
result.collect {|record| record.key.key})
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_less
|
76
|
+
result = @users.select do |record|
|
77
|
+
record["hp"] < 150
|
78
|
+
end
|
79
|
+
assert_equal(["morita"], result.collect {|record| record.key.key})
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_less_equal
|
83
|
+
result = @users.select do |record|
|
84
|
+
record["hp"] <= 150
|
85
|
+
end
|
86
|
+
assert_equal(["morita", "gunyara-kun"],
|
87
|
+
result.collect {|record| record.key.key})
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_greater
|
91
|
+
result = @users.select do |record|
|
92
|
+
record["hp"] > 150
|
93
|
+
end
|
94
|
+
assert_equal(["yu"], result.collect {|record| record.key.key})
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_greater_equal
|
98
|
+
result = @users.select do |record|
|
99
|
+
record["hp"] >= 150
|
100
|
+
end
|
101
|
+
assert_equal(["gunyara-kun", "yu"],
|
102
|
+
result.collect {|record| record.key.key})
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_and
|
106
|
+
result = @users.select do |record|
|
107
|
+
(record["hp"] > 100) & (record["hp"] <= 200)
|
108
|
+
end
|
109
|
+
assert_equal(["gunyara-kun", "yu"],
|
110
|
+
result.collect {|record| record.key.key})
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_match
|
114
|
+
result = @users.select do |record|
|
115
|
+
record["name"] =~ "ro"
|
116
|
+
end
|
117
|
+
assert_equal(["morita", "yu"],
|
118
|
+
result.collect {|record| record.key.key})
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_query_string
|
122
|
+
result = @users.select("name:@ro")
|
123
|
+
assert_equal(["morita", "yu"],
|
124
|
+
result.collect {|record| record.key.key})
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_record
|
128
|
+
result = @bookmarks.select do |record|
|
129
|
+
record["user"] == @morita
|
130
|
+
end
|
131
|
+
assert_equal(["http://groonga.org/", "http://ruby-lang.org/"],
|
132
|
+
result.collect {|record| record.key["uri"]})
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_record_id
|
136
|
+
result = @bookmarks.select do |record|
|
137
|
+
record["user"] == @morita.id
|
138
|
+
end
|
139
|
+
assert_equal(["http://groonga.org/", "http://ruby-lang.org/"],
|
140
|
+
result.collect {|record| record.key["uri"]})
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_nested_column
|
144
|
+
result = @bookmarks.select do |record|
|
145
|
+
record[".user.name"] == @morita["name"]
|
146
|
+
end
|
147
|
+
assert_equal(["http://groonga.org/", "http://ruby-lang.org/"],
|
148
|
+
result.collect {|record| record["uri"]})
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_method_chain
|
152
|
+
result = @bookmarks.select do |record|
|
153
|
+
record.user.name == @morita["name"]
|
154
|
+
end
|
155
|
+
assert_equal(["http://groonga.org/", "http://ruby-lang.org/"],
|
156
|
+
result.collect {|record| record["uri"]})
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_deep_method_chain
|
160
|
+
@pets.add("bob", :name => "morita Bob")
|
161
|
+
@morita["pet"] = "bob"
|
162
|
+
|
163
|
+
result = @bookmarks.select do |record|
|
164
|
+
record.user.pet.name == "morita Bob"
|
165
|
+
end
|
166
|
+
assert_equal(["http://groonga.org/", "http://ruby-lang.org/"],
|
167
|
+
result.collect {|record| record["uri"]})
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_nil_match
|
171
|
+
@users.select do |record|
|
172
|
+
exception = ArgumentError.new("match word should not be nil: Users.name")
|
173
|
+
assert_raise(exception) do
|
174
|
+
record["name"] =~ nil
|
175
|
+
end
|
176
|
+
record["name"] == "dummy"
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_id
|
181
|
+
result = @users.select do |record|
|
182
|
+
record.id == 1
|
183
|
+
end
|
184
|
+
assert_equal(["morita"],
|
185
|
+
result.collect {|record| record.key.key})
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_key
|
189
|
+
result = @users.select do |record|
|
190
|
+
record.key == "morita"
|
191
|
+
end
|
192
|
+
assert_equal(["morita"],
|
193
|
+
result.collect {|record| record.key.key})
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_score
|
197
|
+
result = @users.select do |record|
|
198
|
+
(record.name =~ "o") | (record.hp >= 150)
|
199
|
+
end
|
200
|
+
result = result.select do |record|
|
201
|
+
record.score > 1
|
202
|
+
end
|
203
|
+
assert_equal(["yu"],
|
204
|
+
result.collect {|record| record["_key"]})
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_n_sub_records
|
208
|
+
result = @users.select do |record|
|
209
|
+
(record.name =~ "o") | (record.hp >= 150)
|
210
|
+
end
|
211
|
+
result = result.select do |record|
|
212
|
+
record.n_sub_records > 1
|
213
|
+
end
|
214
|
+
assert_equal(["yu"],
|
215
|
+
result.collect {|record| record["_key"]})
|
216
|
+
end
|
217
|
+
end
|