rroonga 0.9.2-x86-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,36 @@
|
|
1
|
+
# Author:: Nathaniel Talbott.
|
2
|
+
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
3
|
+
# License:: Ruby license.
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'test/unit/util/procwrapper'
|
7
|
+
|
8
|
+
module Test
|
9
|
+
module Unit
|
10
|
+
module Util
|
11
|
+
class TC_ProcWrapper < TestCase
|
12
|
+
def munge_proc(&a_proc)
|
13
|
+
return a_proc
|
14
|
+
end
|
15
|
+
def setup
|
16
|
+
@original = proc {}
|
17
|
+
@munged = munge_proc(&@original)
|
18
|
+
@wrapped_original = ProcWrapper.new(@original)
|
19
|
+
@wrapped_munged = ProcWrapper.new(@munged)
|
20
|
+
end
|
21
|
+
def test_wrapping
|
22
|
+
assert_same(@original, @wrapped_original.to_proc, "The wrapper should return what was wrapped")
|
23
|
+
end
|
24
|
+
def test_hashing
|
25
|
+
|
26
|
+
assert_equal(@wrapped_original.hash, @wrapped_munged.hash, "The original and munged should have the same hash when wrapped")
|
27
|
+
assert_equal(@wrapped_original, @wrapped_munged, "The wrappers should be equivalent")
|
28
|
+
|
29
|
+
a_hash = {@wrapped_original => @original}
|
30
|
+
assert(a_hash[@wrapped_original], "Should be able to access the wrapper in the hash")
|
31
|
+
assert_equal(a_hash[@wrapped_original], @original, "Should be able to access the wrapper in the hash")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/test/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/.test-result
|
@@ -0,0 +1,134 @@
|
|
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
|
+
require 'fileutils'
|
17
|
+
require 'pathname'
|
18
|
+
require 'time'
|
19
|
+
require 'erb'
|
20
|
+
begin
|
21
|
+
require 'json'
|
22
|
+
rescue LoadError
|
23
|
+
require 'rubygems'
|
24
|
+
require 'json'
|
25
|
+
end
|
26
|
+
require 'pkg-config'
|
27
|
+
|
28
|
+
require 'groonga'
|
29
|
+
|
30
|
+
module GroongaTestUtils
|
31
|
+
class << self
|
32
|
+
def included(base)
|
33
|
+
base.setup :setup_sandbox, :before => :prepend
|
34
|
+
base.teardown :teardown_sandbox, :after => :append
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def setup_sandbox
|
39
|
+
setup_tmp_directory
|
40
|
+
setup_log_path
|
41
|
+
|
42
|
+
setup_tables_directory
|
43
|
+
setup_columns_directory
|
44
|
+
|
45
|
+
setup_encoding
|
46
|
+
setup_context
|
47
|
+
end
|
48
|
+
|
49
|
+
def setup_tmp_directory
|
50
|
+
@tmp_dir = Pathname(File.dirname(__FILE__)) + "tmp"
|
51
|
+
FileUtils.rm_rf(@tmp_dir.to_s)
|
52
|
+
FileUtils.mkdir_p(@tmp_dir.to_s)
|
53
|
+
end
|
54
|
+
|
55
|
+
def setup_log_path
|
56
|
+
@dump_log = false
|
57
|
+
Groonga::Logger.log_path = (@tmp_dir + "groonga.log").to_s
|
58
|
+
Groonga::Logger.query_log_path = (@tmp_dir + "groonga-query.log").to_s
|
59
|
+
end
|
60
|
+
|
61
|
+
def setup_tables_directory
|
62
|
+
@tables_dir = @tmp_dir + "tables"
|
63
|
+
FileUtils.mkdir_p(@tables_dir.to_s)
|
64
|
+
end
|
65
|
+
|
66
|
+
def setup_columns_directory
|
67
|
+
@columns_dir = @tmp_dir + "columns"
|
68
|
+
FileUtils.mkdir_p(@columns_dir.to_s)
|
69
|
+
end
|
70
|
+
|
71
|
+
def setup_encoding
|
72
|
+
Groonga::Encoding.default = nil
|
73
|
+
end
|
74
|
+
|
75
|
+
def setup_context
|
76
|
+
Groonga::Context.default = nil
|
77
|
+
Groonga::Context.default_options = nil
|
78
|
+
end
|
79
|
+
|
80
|
+
def context
|
81
|
+
Groonga::Context.default
|
82
|
+
end
|
83
|
+
|
84
|
+
def encoding
|
85
|
+
Groonga::Encoding.default
|
86
|
+
end
|
87
|
+
|
88
|
+
def setup_logger
|
89
|
+
Groonga::Logger.register(:level => :dump) do |level, time, title, message, location|
|
90
|
+
p [level, time, title, message, location]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def setup_database
|
95
|
+
@database_path = @tmp_dir + "database"
|
96
|
+
@database = Groonga::Database.create(:path => @database_path.to_s)
|
97
|
+
end
|
98
|
+
|
99
|
+
def teardown_sandbox
|
100
|
+
@database = nil
|
101
|
+
GC.start
|
102
|
+
teardown_log_path
|
103
|
+
teardown_tmp_directory
|
104
|
+
end
|
105
|
+
|
106
|
+
def teardown_log_path
|
107
|
+
return unless @dump_log
|
108
|
+
log_path = Groonga::Logger.log_path
|
109
|
+
query_log_path = Groonga::Logger.query_log_path
|
110
|
+
if File.exist?(log_path)
|
111
|
+
header = "--- log: #{log_path} ---"
|
112
|
+
puts(header)
|
113
|
+
puts(File.read(log_path))
|
114
|
+
puts("-" * header.length)
|
115
|
+
end
|
116
|
+
if File.exist?(query_log_path)
|
117
|
+
header = "--- query log: #{query_log_path} ---"
|
118
|
+
puts(header)
|
119
|
+
puts(File.read(query_log_path))
|
120
|
+
puts("-" * header.length)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def teardown_tmp_directory
|
125
|
+
FileUtils.rm_rf(@tmp_dir.to_s)
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
def assert_equal_select_result(expected, actual)
|
130
|
+
assert_equal(expected,
|
131
|
+
actual.collect {|record| record.key},
|
132
|
+
actual.expression.inspect)
|
133
|
+
end
|
134
|
+
end
|
data/test/run-test.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Copyright (C) 2009-2010 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License version 2.1 as published by the Free Software Foundation.
|
8
|
+
#
|
9
|
+
# This library is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
# Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
15
|
+
# License along with this library; if not, write to the Free Software
|
16
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
+
|
18
|
+
$VERBOSE = true
|
19
|
+
|
20
|
+
$KCODE = "u" if RUBY_VERSION < "1.9"
|
21
|
+
|
22
|
+
base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
23
|
+
test_unit_dir = File.join(base_dir, "test-unit", "lib")
|
24
|
+
ext_dir = File.join(base_dir, "ext", "groonga")
|
25
|
+
lib_dir = File.join(base_dir, "lib")
|
26
|
+
test_dir = File.join(base_dir, "test")
|
27
|
+
|
28
|
+
make = nil
|
29
|
+
if system("which gmake > /dev/null")
|
30
|
+
make = "gmake"
|
31
|
+
elsif system("which make > /dev/null")
|
32
|
+
make = "make"
|
33
|
+
end
|
34
|
+
if make
|
35
|
+
system("cd #{base_dir.dump} && #{make} > /dev/null") or exit(1)
|
36
|
+
end
|
37
|
+
|
38
|
+
$LOAD_PATH.unshift(test_unit_dir)
|
39
|
+
|
40
|
+
require 'test/unit'
|
41
|
+
|
42
|
+
ARGV.unshift("--priority-mode")
|
43
|
+
|
44
|
+
$LOAD_PATH.unshift(ext_dir)
|
45
|
+
$LOAD_PATH.unshift(lib_dir)
|
46
|
+
$LOAD_PATH.unshift(base_dir)
|
47
|
+
|
48
|
+
$LOAD_PATH.unshift(test_dir)
|
49
|
+
require 'groonga-test-utils'
|
50
|
+
|
51
|
+
pkg_config = File.join(base_dir, "vendor", "local", "lib", "pkgconfig")
|
52
|
+
PackageConfig.prepend_default_path(pkg_config)
|
53
|
+
|
54
|
+
Dir.glob("#{base_dir}/test/**/test{_,-}*.rb") do |file|
|
55
|
+
require file.sub(/\.rb$/, '')
|
56
|
+
end
|
57
|
+
|
58
|
+
exit Test::Unit::AutoRunner.run(false)
|
data/test/test-array.rb
ADDED
@@ -0,0 +1,90 @@
|
|
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 ArrayTest < Test::Unit::TestCase
|
17
|
+
include GroongaTestUtils
|
18
|
+
|
19
|
+
setup :setup_database
|
20
|
+
|
21
|
+
def test_inspect_size
|
22
|
+
path = @tables_dir + "named.groonga"
|
23
|
+
contain_table = Groonga::Array.create(:name => "name", :path => path.to_s)
|
24
|
+
3.times do
|
25
|
+
contain_table.add
|
26
|
+
end
|
27
|
+
assert_equal("#<Groonga::Array " +
|
28
|
+
"id: <#{contain_table.id}>, " +
|
29
|
+
"name: <name>, " +
|
30
|
+
"path: <#{path}>, " +
|
31
|
+
"domain: (nil), " +
|
32
|
+
"range: (nil), " +
|
33
|
+
"flags: <>, " +
|
34
|
+
"size: <3>>",
|
35
|
+
contain_table.inspect)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_encoding
|
39
|
+
array = Groonga::Array.create
|
40
|
+
assert_false(array.respond_to?(:encoding))
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_add
|
44
|
+
users = Groonga::Array.create(:name => "Users")
|
45
|
+
users.define_column("name", "Text")
|
46
|
+
me = users.add(:name => "me")
|
47
|
+
assert_equal("me", me[:name])
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_define_index_column
|
51
|
+
users = Groonga::Array.create(:name => "Users")
|
52
|
+
users.define_column("name", "Text")
|
53
|
+
bookmarks = Groonga::Array.create(:name => "Bookmarks")
|
54
|
+
bookmarks.define_column("title", "Text")
|
55
|
+
bookmarks.define_column("user", users)
|
56
|
+
|
57
|
+
index = users.define_index_column("bookmarks", bookmarks,
|
58
|
+
:source => "Bookmarks.user")
|
59
|
+
morita = users.add(:name => "morita")
|
60
|
+
gunyara_kun = users.add(:name => "gunyara-kun")
|
61
|
+
groonga = bookmarks.add(:title => "groonga", :user => morita)
|
62
|
+
google = bookmarks.add(:title => "google", :user => morita)
|
63
|
+
python = bookmarks.add(:title => "Python", :user => gunyara_kun)
|
64
|
+
|
65
|
+
assert_equal(["groonga", "google"],
|
66
|
+
index.search(morita.id).collect {|record| record.key["title"]})
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_create_duplicated_name
|
70
|
+
Groonga::Array.create(:name => "Users")
|
71
|
+
assert_raise(Groonga::InvalidArgument) do
|
72
|
+
Groonga::Array.create(:name => "Users")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_value
|
77
|
+
users = Groonga::Array.create(:value_type => "Int32")
|
78
|
+
user_id = users.add.id
|
79
|
+
users.set_value(user_id, 29)
|
80
|
+
assert_equal(29, users.value(user_id))
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_column_value
|
84
|
+
users = Groonga::Array.create(:name => "Users")
|
85
|
+
name = users.define_column("name", "ShortText")
|
86
|
+
morita_id = users.add.id
|
87
|
+
users.set_column_value(morita_id, "name", "morita")
|
88
|
+
assert_equal("morita", users.column_value(morita_id, "name"))
|
89
|
+
end
|
90
|
+
end
|
data/test/test-column.rb
ADDED
@@ -0,0 +1,316 @@
|
|
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 ColumnTest < Test::Unit::TestCase
|
17
|
+
include GroongaTestUtils
|
18
|
+
|
19
|
+
def setup
|
20
|
+
setup_database
|
21
|
+
|
22
|
+
setup_users_table
|
23
|
+
setup_bookmarks_table
|
24
|
+
setup_indexes
|
25
|
+
end
|
26
|
+
|
27
|
+
def setup_users_table
|
28
|
+
@users_path = @tables_dir + "users"
|
29
|
+
@users = Groonga::Array.create(:name => "Users",
|
30
|
+
:path => @users_path.to_s)
|
31
|
+
|
32
|
+
@users_name_column_path = @columns_dir + "name"
|
33
|
+
@users_name_column =
|
34
|
+
@users.define_column("name", "ShortText",
|
35
|
+
:path => @users_name_column_path.to_s)
|
36
|
+
end
|
37
|
+
|
38
|
+
def setup_bookmarks_table
|
39
|
+
@bookmarks_path = @tables_dir + "bookmarks"
|
40
|
+
@bookmarks = Groonga::Array.create(:name => "Bookmarks",
|
41
|
+
:path => @bookmarks_path.to_s)
|
42
|
+
|
43
|
+
@uri_column_path = @columns_dir + "uri"
|
44
|
+
@bookmarks_uri = @bookmarks.define_column("uri", "ShortText",
|
45
|
+
:path => @uri_column_path.to_s)
|
46
|
+
|
47
|
+
@comment_column_path = @columns_dir + "comment"
|
48
|
+
@bookmarks_comment =
|
49
|
+
@bookmarks.define_column("comment", "Text",
|
50
|
+
:path => @comment_column_path.to_s)
|
51
|
+
|
52
|
+
@content_column_path = @columns_dir + "content"
|
53
|
+
@bookmarks_content = @bookmarks.define_column("content", "LongText")
|
54
|
+
|
55
|
+
@user_column_path = @columns_dir + "user"
|
56
|
+
@bookmarks_user = @bookmarks.define_column("user", @users)
|
57
|
+
end
|
58
|
+
|
59
|
+
def setup_indexes
|
60
|
+
@bookmarks_index_path = @tables_dir + "bookmarks-index"
|
61
|
+
@bookmarks_index =
|
62
|
+
Groonga::PatriciaTrie.create(:name => "BookmarksIndex",
|
63
|
+
:path => @bookmarks_index_path.to_s,
|
64
|
+
:key_type => "ShortText")
|
65
|
+
@bookmarks_index.default_tokenizer = "TokenBigram"
|
66
|
+
|
67
|
+
@content_index_column_path = @columns_dir + "content-index"
|
68
|
+
@bookmarks_index_content =
|
69
|
+
@bookmarks_index.define_index_column("content", @bookmarks,
|
70
|
+
:with_section => true,
|
71
|
+
:with_weight => true,
|
72
|
+
:with_position => true,
|
73
|
+
:path => @content_index_column_path.to_s)
|
74
|
+
|
75
|
+
@uri_index_column_path = @columns_dir + "uri-index"
|
76
|
+
@bookmarks_index_uri =
|
77
|
+
@bookmarks_index.define_index_column("uri", @bookmarks,
|
78
|
+
:path => @uri_index_column_path.to_s)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_source_info
|
82
|
+
@bookmarks_index_content.sources = [@bookmarks_content]
|
83
|
+
|
84
|
+
groonga = @bookmarks.add
|
85
|
+
groonga["content"] = "<html><body>groonga</body></html>"
|
86
|
+
|
87
|
+
ruby = @bookmarks.add
|
88
|
+
ruby["content"] = "<html><body>ruby</body></html>"
|
89
|
+
|
90
|
+
assert_content_search([groonga], "groonga")
|
91
|
+
assert_content_search([groonga, ruby], "html")
|
92
|
+
|
93
|
+
assert_equal([@bookmarks_content], @bookmarks_index_content.sources)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_update_index_column
|
97
|
+
groonga = @bookmarks.add
|
98
|
+
groonga["content"] = "<html><body>groonga</body></html>"
|
99
|
+
|
100
|
+
ruby = @bookmarks.add
|
101
|
+
ruby["content"] = "<html><body>ruby</body></html>"
|
102
|
+
|
103
|
+
@bookmarks_index_content[groonga.id] = groonga["content"]
|
104
|
+
@bookmarks_index_content[ruby.id] = ruby["content"]
|
105
|
+
|
106
|
+
assert_content_search([groonga], "groonga")
|
107
|
+
assert_content_search([groonga, ruby], "html")
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_range
|
111
|
+
assert_equal(context[Groonga::Type::SHORT_TEXT], @bookmarks_uri.range)
|
112
|
+
assert_equal(context[Groonga::Type::TEXT], @bookmarks_comment.range)
|
113
|
+
assert_equal(context[Groonga::Type::LONG_TEXT], @bookmarks_content.range)
|
114
|
+
assert_equal(@users, @bookmarks_user.range)
|
115
|
+
assert_equal(@bookmarks, @bookmarks_index_content.range)
|
116
|
+
assert_equal(@bookmarks, @bookmarks_index_uri.range)
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_accessor
|
120
|
+
posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText")
|
121
|
+
posts.define_column("body", "Text")
|
122
|
+
comments = Groonga::Hash.create(:name => "Comments",
|
123
|
+
:key_type => "ShortText")
|
124
|
+
content = comments.define_column("content", "ShortText")
|
125
|
+
comments.define_column("post", posts)
|
126
|
+
|
127
|
+
index = Groonga::PatriciaTrie.create(:name => "Terms",
|
128
|
+
:key_type => "ShortText")
|
129
|
+
index.default_tokenizer = "TokenBigram"
|
130
|
+
content_index = index.define_index_column("content_index", comments,
|
131
|
+
:with_position => true)
|
132
|
+
content_index.source = content
|
133
|
+
|
134
|
+
first_post = posts.add("Hello!")
|
135
|
+
first_post["body"] = "World"
|
136
|
+
hobby = posts.add("My Hobby")
|
137
|
+
hobby["body"] = "Drive and Eat"
|
138
|
+
|
139
|
+
friend = comments.add("Me too")
|
140
|
+
friend["content"] = "I'm also like drive"
|
141
|
+
friend["post"] = hobby
|
142
|
+
|
143
|
+
result = content_index.search("drive")
|
144
|
+
assert_equal([["I'm also like drive", "My Hobby"]],
|
145
|
+
result.records.collect do |record|
|
146
|
+
[record[".content"], record[".post._key"]]
|
147
|
+
end)
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_accessor_reference
|
151
|
+
bookmark = @bookmarks.add
|
152
|
+
assert_nil(@bookmarks_user[bookmark.id])
|
153
|
+
|
154
|
+
daijiro = @users.add
|
155
|
+
daijiro["name"] = "daijiro"
|
156
|
+
@bookmarks_user[bookmark.id] = daijiro
|
157
|
+
assert_equal(daijiro, @bookmarks_user[bookmark.id])
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_array_set_with_key_of_table
|
161
|
+
languages = Groonga::Hash.create(:name => "Languages",
|
162
|
+
:key_type => "ShortText")
|
163
|
+
sites = Groonga::Hash.create(:name => "Sites")
|
164
|
+
sites.define_column("language", languages)
|
165
|
+
|
166
|
+
languages.add("Ruby")
|
167
|
+
taiyaki_ru = sites.add("http://taiyaki.ru/", :language => "Ruby")
|
168
|
+
assert_equal("Ruby", taiyaki_ru[:language].key)
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_local_name
|
172
|
+
items = Groonga::Array.create(:name => "Items")
|
173
|
+
title = items.define_column("title", "ShortText")
|
174
|
+
assert_equal("Items.title", title.name)
|
175
|
+
assert_equal("title", title.local_name)
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_select_query
|
179
|
+
populate_table_for_select
|
180
|
+
|
181
|
+
result = @body.select("drive")
|
182
|
+
assert_equal(["Drive and Eat"],
|
183
|
+
result.records.collect do |record|
|
184
|
+
record["body"]
|
185
|
+
end)
|
186
|
+
assert_equal("#<Groonga::Expression noname(?0:\"\")" +
|
187
|
+
"{2body GET_VALUE,0\"drive\",0MATCH}>",
|
188
|
+
result.expression.inspect)
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_select_query_from_ctx
|
192
|
+
populate_table_for_select
|
193
|
+
|
194
|
+
body = Groonga::Context.default['Posts.body']
|
195
|
+
# select twice.
|
196
|
+
result = body.select("drive")
|
197
|
+
assert_equal(["Drive and Eat"],
|
198
|
+
result.records.collect do |record|
|
199
|
+
record["body"]
|
200
|
+
end)
|
201
|
+
|
202
|
+
result = body.select("drive")
|
203
|
+
assert_equal(["Drive and Eat"],
|
204
|
+
result.records.collect do |record|
|
205
|
+
record["body"]
|
206
|
+
end)
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_select_query_with_parser
|
210
|
+
populate_table_for_select
|
211
|
+
|
212
|
+
result = @body.select("body @ \"drive\"", :syntax => :script)
|
213
|
+
assert_equal(["Drive and Eat"],
|
214
|
+
result.records.collect do |record|
|
215
|
+
record["body"]
|
216
|
+
end)
|
217
|
+
assert_equal("#<Groonga::Expression noname(?0:\"\")" +
|
218
|
+
"{2body GET_VALUE,0\"drive\",0MATCH}>",
|
219
|
+
result.expression.inspect)
|
220
|
+
end
|
221
|
+
|
222
|
+
def test_select_expression
|
223
|
+
populate_table_for_select
|
224
|
+
|
225
|
+
expression = Groonga::Expression.new
|
226
|
+
variable = expression.define_variable(:domain => @posts)
|
227
|
+
expression.append_object(variable)
|
228
|
+
expression.parse("body:@drive", :syntax => :query)
|
229
|
+
expression.compile
|
230
|
+
result = @body.select(expression)
|
231
|
+
assert_equal(["Drive and Eat"],
|
232
|
+
result.records.collect do |record|
|
233
|
+
record["body"]
|
234
|
+
end)
|
235
|
+
assert_equal("#<Groonga::Expression noname(?0:\"\")" +
|
236
|
+
"{0?0,2body GET_VALUE,0\"drive\",0MATCH}>",
|
237
|
+
result.expression.inspect)
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_select_with_block
|
241
|
+
populate_table_for_select
|
242
|
+
|
243
|
+
result = @body.select do |column|
|
244
|
+
column =~ "drive"
|
245
|
+
end
|
246
|
+
assert_equal(["Drive and Eat"],
|
247
|
+
result.records.collect do |record|
|
248
|
+
record["body"]
|
249
|
+
end)
|
250
|
+
assert_equal("#<Groonga::Expression noname(?0:\"\")" +
|
251
|
+
"{1?0,2body GET_VALUE,0\"drive\",0MATCH}>",
|
252
|
+
result.expression.inspect)
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_set_time
|
256
|
+
posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText")
|
257
|
+
body = posts.define_column("issued", "Time")
|
258
|
+
|
259
|
+
post = posts.add("hello", :issued => 123456)
|
260
|
+
assert_equal(Time.at(123456), post[".issued"])
|
261
|
+
post = posts.add("groonga", :issued => 1251380635)
|
262
|
+
assert_equal(Time.parse("2009-08-27 22:43:55"), post[".issued"])
|
263
|
+
post = posts.add("mroonga", :issued => 1251380635.1234567)
|
264
|
+
assert_in_delta(Time.at(1251380635.1234567).usec, post[".issued"].usec, 10)
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_set_nil_to_time
|
268
|
+
posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText")
|
269
|
+
body = posts.define_column("issued", "Time")
|
270
|
+
|
271
|
+
post = posts.add("hello", :issued => nil)
|
272
|
+
assert_equal(Time.at(0), post["issued"])
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_bool
|
276
|
+
posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText")
|
277
|
+
hidden = posts.define_column("hidden", "Bool")
|
278
|
+
|
279
|
+
post = posts.add("hello")
|
280
|
+
assert_false(post["hidden"])
|
281
|
+
|
282
|
+
post["hidden"] = true
|
283
|
+
assert_true(post["hidden"])
|
284
|
+
|
285
|
+
post["hidden"] = false
|
286
|
+
assert_false(post["hidden"])
|
287
|
+
end
|
288
|
+
|
289
|
+
private
|
290
|
+
def assert_content_search(expected_records, term)
|
291
|
+
records = @bookmarks_index_content.search(term).records
|
292
|
+
expected_contents = expected_records.collect do |record|
|
293
|
+
record["content"]
|
294
|
+
end
|
295
|
+
actual_contents = records.collect do |record|
|
296
|
+
record.key["content"]
|
297
|
+
end
|
298
|
+
assert_equal(expected_contents, actual_contents)
|
299
|
+
end
|
300
|
+
|
301
|
+
def populate_table_for_select
|
302
|
+
@posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText")
|
303
|
+
@body = @posts.define_column("body", "Text")
|
304
|
+
|
305
|
+
index = Groonga::PatriciaTrie.create(:name => "Terms",
|
306
|
+
:key_type => "ShortText",
|
307
|
+
:key_normalize => true)
|
308
|
+
index.default_tokenizer = "TokenBigram"
|
309
|
+
body_index = index.define_index_column("body_index", @posts,
|
310
|
+
:with_position => true,
|
311
|
+
:source => @body)
|
312
|
+
|
313
|
+
first_post = @posts.add("Hello!", :body => "World")
|
314
|
+
hobby = @posts.add("My Hobby", :body => "Drive and Eat")
|
315
|
+
end
|
316
|
+
end
|