rroonga 2.0.2 → 2.0.3
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/Gemfile +1 -12
- data/Rakefile +4 -57
- data/bin/grndump +11 -1
- data/ext/groonga/extconf.rb +125 -54
- data/ext/groonga/rb-grn-context.c +25 -7
- data/ext/groonga/rb-grn-database.c +25 -0
- data/ext/groonga/rb-grn-object.c +19 -7
- data/ext/groonga/rb-grn-table.c +8 -10
- data/ext/groonga/rb-grn.h +9 -2
- data/lib/groonga/dumper.rb +2 -2
- data/lib/groonga/expression-builder.rb +33 -18
- data/rroonga-build.rb +1 -1
- metadata +97 -180
- data/TODO +0 -0
- data/test/groonga-test-utils.rb +0 -139
- data/test/run-test.rb +0 -60
- data/test/test-accessor.rb +0 -36
- data/test/test-array.rb +0 -123
- data/test/test-column.rb +0 -350
- data/test/test-command-select.rb +0 -147
- data/test/test-context.rb +0 -130
- data/test/test-database-dumper.rb +0 -259
- data/test/test-database.rb +0 -148
- data/test/test-double-array-trie.rb +0 -164
- data/test/test-encoding.rb +0 -33
- data/test/test-exception.rb +0 -96
- data/test/test-expression-builder.rb +0 -269
- data/test/test-expression.rb +0 -134
- data/test/test-fix-size-column.rb +0 -77
- data/test/test-gqtp.rb +0 -70
- data/test/test-hash.rb +0 -344
- data/test/test-index-column.rb +0 -180
- data/test/test-index-cursor.rb +0 -93
- data/test/test-logger.rb +0 -37
- data/test/test-pagination.rb +0 -249
- data/test/test-patricia-trie.rb +0 -415
- data/test/test-plugin.rb +0 -35
- data/test/test-procedure.rb +0 -37
- data/test/test-query-log.rb +0 -258
- data/test/test-record.rb +0 -569
- data/test/test-remote.rb +0 -63
- data/test/test-schema-create-table.rb +0 -267
- data/test/test-schema-dumper.rb +0 -235
- data/test/test-schema-type.rb +0 -208
- data/test/test-schema-view.rb +0 -90
- data/test/test-schema.rb +0 -886
- data/test/test-snippet.rb +0 -130
- data/test/test-table-cursor.rb +0 -187
- data/test/test-table-dumper.rb +0 -83
- data/test/test-table-offset-and-limit.rb +0 -100
- data/test/test-table-select-mecab.rb +0 -80
- data/test/test-table-select-normalize.rb +0 -57
- data/test/test-table-select-weight.rb +0 -123
- data/test/test-table-select.rb +0 -191
- data/test/test-table.rb +0 -675
- data/test/test-type.rb +0 -79
- data/test/test-variable-size-column.rb +0 -147
- data/test/test-variable.rb +0 -28
- data/test/test-vector-column.rb +0 -76
- data/test/test-version.rb +0 -61
- data/test/test-view.rb +0 -72
data/test/test-database.rb
DELETED
@@ -1,148 +0,0 @@
|
|
1
|
-
# Copyright (C) 2009-2011 Kouhei Sutou <kou@clear-code.com>
|
2
|
-
#
|
3
|
-
# This library is free software; you can redistribute it and/or
|
4
|
-
# modify it under the terms of the GNU Lesser General Public
|
5
|
-
# License version 2.1 as published by the Free Software Foundation.
|
6
|
-
#
|
7
|
-
# This library is distributed in the hope that it will be useful,
|
8
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
10
|
-
# Lesser General Public License for more details.
|
11
|
-
#
|
12
|
-
# You should have received a copy of the GNU Lesser General Public
|
13
|
-
# License along with this library; if not, write to the Free Software
|
14
|
-
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
15
|
-
|
16
|
-
class 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
|
-
database.close
|
42
|
-
|
43
|
-
assert_predicate(database, :closed?)
|
44
|
-
called = false
|
45
|
-
Groonga::Database.open(db_path.to_s) do |_database|
|
46
|
-
database = _database
|
47
|
-
assert_not_predicate(database, :closed?)
|
48
|
-
called = true
|
49
|
-
end
|
50
|
-
assert_true(called)
|
51
|
-
assert_predicate(database, :closed?)
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_close
|
55
|
-
db_path = @tmp_dir + "db"
|
56
|
-
database = Groonga::Database.create(:path => db_path.to_s)
|
57
|
-
database.close
|
58
|
-
|
59
|
-
database = Groonga::Database.open(db_path.to_s)
|
60
|
-
assert_not_predicate(database, :closed?)
|
61
|
-
database.close
|
62
|
-
assert_predicate(database, :closed?)
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_new
|
66
|
-
db_path = @tmp_dir + "db"
|
67
|
-
assert_raise(Groonga::NoSuchFileOrDirectory) do
|
68
|
-
Groonga::Database.new(db_path.to_s)
|
69
|
-
end
|
70
|
-
|
71
|
-
Groonga::Database.create(:path => db_path.to_s)
|
72
|
-
assert_not_predicate(Groonga::Database.new(db_path.to_s), :closed?)
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_each
|
76
|
-
db_path = @tmp_dir + "db"
|
77
|
-
database = Groonga::Database.create(:path => db_path.to_s)
|
78
|
-
default_object_names = database.collect {|object| object.name}.sort
|
79
|
-
assert_send([default_object_names, :include?, "Bool"])
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_encoding
|
83
|
-
assert_equal(Groonga::Encoding.default,
|
84
|
-
Groonga::Database.create.encoding)
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_lock
|
88
|
-
database = Groonga::Database.create
|
89
|
-
|
90
|
-
assert_not_predicate(database, :locked?)
|
91
|
-
database.lock
|
92
|
-
assert_predicate(database, :locked?)
|
93
|
-
database.unlock
|
94
|
-
assert_not_predicate(database, :locked?)
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_lock_failed
|
98
|
-
database = Groonga::Database.create
|
99
|
-
|
100
|
-
database.lock
|
101
|
-
assert_raise(Groonga::ResourceDeadlockAvoided) do
|
102
|
-
database.lock
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_lock_block
|
107
|
-
database = Groonga::Database.create
|
108
|
-
|
109
|
-
assert_not_predicate(database, :locked?)
|
110
|
-
database.lock do
|
111
|
-
assert_predicate(database, :locked?)
|
112
|
-
end
|
113
|
-
assert_not_predicate(database, :locked?)
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_clear_lock
|
117
|
-
database = Groonga::Database.create
|
118
|
-
|
119
|
-
assert_not_predicate(database, :locked?)
|
120
|
-
database.lock
|
121
|
-
assert_predicate(database, :locked?)
|
122
|
-
database.clear_lock
|
123
|
-
assert_not_predicate(database, :locked?)
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_touch
|
127
|
-
database = Groonga::Database.create
|
128
|
-
assert_nothing_raised do
|
129
|
-
database.touch
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
def test_defrag
|
134
|
-
setup_database
|
135
|
-
Groonga::Schema.define do |schema|
|
136
|
-
schema.create_table("Users") do |table|
|
137
|
-
table.short_text("name")
|
138
|
-
table.short_text("address")
|
139
|
-
end
|
140
|
-
end
|
141
|
-
users = context["Users"]
|
142
|
-
1000.times do |i|
|
143
|
-
users.add(:name => "user #{i}" * 1000,
|
144
|
-
:address => "address #{i}" * 1000)
|
145
|
-
end
|
146
|
-
assert_equal(7, @database.defrag)
|
147
|
-
end
|
148
|
-
end
|
@@ -1,164 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
#
|
3
|
-
# Copyright (C) 2011 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
|
-
class DoubleArrayTrieTest < Test::Unit::TestCase
|
19
|
-
include GroongaTestUtils
|
20
|
-
include ERB::Util
|
21
|
-
|
22
|
-
setup :setup_database
|
23
|
-
|
24
|
-
def test_support_key?
|
25
|
-
assert_predicate(Groonga::DoubleArrayTrie.create(:name => "Users",
|
26
|
-
:key_type => "ShortText"),
|
27
|
-
:support_key?)
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_encoding
|
31
|
-
assert_equal(Groonga::Encoding.default,
|
32
|
-
Groonga::DoubleArrayTrie.create.encoding)
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_tokenizer
|
36
|
-
trie = Groonga::DoubleArrayTrie.create
|
37
|
-
assert_nil(trie.default_tokenizer)
|
38
|
-
trie.default_tokenizer = "TokenTrigram"
|
39
|
-
assert_equal(Groonga::Context.default["TokenTrigram"],
|
40
|
-
trie.default_tokenizer)
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_search
|
44
|
-
users = Groonga::Array.create(:name => "Users")
|
45
|
-
users.define_column("name", "ShortText")
|
46
|
-
|
47
|
-
bookmarks = Groonga::DoubleArrayTrie.create(:name => "Bookmarks",
|
48
|
-
:key_type => "ShortText")
|
49
|
-
bookmarks.define_column("user_id", users)
|
50
|
-
|
51
|
-
daijiro = users.add
|
52
|
-
daijiro["name"] = "daijiro"
|
53
|
-
gunyarakun = users.add
|
54
|
-
gunyarakun["name"] = "gunyarakun"
|
55
|
-
|
56
|
-
groonga = bookmarks.add("http://groonga.org/")
|
57
|
-
groonga["user_id"] = daijiro
|
58
|
-
|
59
|
-
records = bookmarks.search("http://groonga.org/")
|
60
|
-
assert_equal(["daijiro"],
|
61
|
-
records.records.collect {|record| record[".user_id.name"]})
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_add
|
65
|
-
users = Groonga::DoubleArrayTrie.create(:name => "Users")
|
66
|
-
users.define_column("address", "Text")
|
67
|
-
me = users.add("me", :address => "me@example.com")
|
68
|
-
assert_equal("me@example.com", me[:address])
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_default_tokenizer_on_create
|
72
|
-
terms = Groonga::DoubleArrayTrie.create(:name => "Terms",
|
73
|
-
:default_tokenizer => "TokenUnigram")
|
74
|
-
assert_equal(context[Groonga::Type::UNIGRAM],
|
75
|
-
terms.default_tokenizer)
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_duplicated_name
|
79
|
-
Groonga::DoubleArrayTrie.create(:name => "Users")
|
80
|
-
assert_raise(Groonga::InvalidArgument) do
|
81
|
-
Groonga::DoubleArrayTrie.create(:name => "Users")
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_has_key?
|
86
|
-
users = Groonga::DoubleArrayTrie.create(:name => "Users")
|
87
|
-
assert_false(users.has_key?("morita"))
|
88
|
-
users.add("morita")
|
89
|
-
assert_true(users.has_key?("morita"))
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_prefix_cursor
|
93
|
-
paths = Groonga::DoubleArrayTrie.create(:name => "Paths",
|
94
|
-
:key_type => 'ShortText')
|
95
|
-
paths.add('/')
|
96
|
-
paths.add('/tmp')
|
97
|
-
paths.add('/usr/bin')
|
98
|
-
paths.add('/usr/local/bin')
|
99
|
-
|
100
|
-
assert_prefix_cursor(["/usr/local/bin", "/usr/bin", "/tmp", "/"],
|
101
|
-
paths, "/", {:order => :desc})
|
102
|
-
assert_prefix_cursor(["/", "/tmp", "/usr/bin", "/usr/local/bin"],
|
103
|
-
paths, "/")
|
104
|
-
assert_prefix_cursor(["/usr/local/bin", "/usr/bin"],
|
105
|
-
paths, "/usr/local",
|
106
|
-
{:key_bytes => "/usr".size, :order => :desc})
|
107
|
-
assert_prefix_cursor(["/tmp", "/usr/bin"],
|
108
|
-
paths, "/",
|
109
|
-
{:offset => 1, :limit => 2})
|
110
|
-
end
|
111
|
-
|
112
|
-
def assert_prefix_cursor(expected, tables, prefix, options={})
|
113
|
-
actual = []
|
114
|
-
tables.open_prefix_cursor(prefix, options) do |cursor|
|
115
|
-
cursor.each do |record|
|
116
|
-
actual << record.key
|
117
|
-
end
|
118
|
-
end
|
119
|
-
assert_equal(expected, actual)
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_add_uint_key
|
123
|
-
numbers = Groonga::DoubleArrayTrie.create(:name => "Numbers",
|
124
|
-
:key_type => "UInt32")
|
125
|
-
numbers.add(1)
|
126
|
-
numbers.add(2)
|
127
|
-
numbers.add(5)
|
128
|
-
numbers.add(7)
|
129
|
-
assert_equal([1, 2, 5, 7], numbers.collect {|number| number.key})
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_added?
|
133
|
-
users = Groonga::DoubleArrayTrie.create(:name => "Users",
|
134
|
-
:key_type => "ShortText")
|
135
|
-
bob = users.add("bob")
|
136
|
-
assert_predicate(bob, :added?)
|
137
|
-
bob_again = users.add("bob")
|
138
|
-
assert_not_predicate(bob_again, :added?)
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_defrag
|
142
|
-
users = Groonga::DoubleArrayTrie.create(:name => "Users",
|
143
|
-
:key_type => "ShortText")
|
144
|
-
users.define_column("name", "ShortText")
|
145
|
-
users.define_column("address", "ShortText")
|
146
|
-
1000.times do |i|
|
147
|
-
users.add("user #{i}",
|
148
|
-
:name => "user #{i}" * 1000,
|
149
|
-
:address => "address #{i}" * 1000)
|
150
|
-
end
|
151
|
-
assert_equal(7, users.defrag)
|
152
|
-
end
|
153
|
-
|
154
|
-
def test_rename
|
155
|
-
users = Groonga::DoubleArrayTrie.create(:name => "Users",
|
156
|
-
:key_type => "ShortText")
|
157
|
-
name = users.define_column("name", "ShortText")
|
158
|
-
address = users.define_column("address", "ShortText")
|
159
|
-
|
160
|
-
users.rename("People")
|
161
|
-
assert_equal(["People", "People.name", "People.address"],
|
162
|
-
[users.name, name.name, address.name])
|
163
|
-
end
|
164
|
-
end
|
data/test/test-encoding.rb
DELETED
@@ -1,33 +0,0 @@
|
|
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
|
data/test/test-exception.rb
DELETED
@@ -1,96 +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 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
|
-
assert_const_defined(Groonga, :TooSmallOffset)
|
93
|
-
assert_const_defined(Groonga, :TooLargeOffset)
|
94
|
-
assert_const_defined(Groonga, :TooSmallLimit)
|
95
|
-
end
|
96
|
-
end
|
@@ -1,269 +0,0 @@
|
|
1
|
-
# Copyright (C) 2009-2011 Kouhei Sutou <kou@clear-code.com>
|
2
|
-
#
|
3
|
-
# This library is free software; you can redistribute it and/or
|
4
|
-
# modify it under the terms of the GNU Lesser General Public
|
5
|
-
# License version 2.1 as published by the Free Software Foundation.
|
6
|
-
#
|
7
|
-
# This library is distributed in the hope that it will be useful,
|
8
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
10
|
-
# Lesser General Public License for more details.
|
11
|
-
#
|
12
|
-
# You should have received a copy of the GNU Lesser General Public
|
13
|
-
# License along with this library; if not, write to the Free Software
|
14
|
-
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
15
|
-
|
16
|
-
class 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
|
-
@sections = Groonga::PatriciaTrie.create(:name => "Sections",
|
28
|
-
:key_type => "ShortText")
|
29
|
-
|
30
|
-
@users = Groonga::Hash.create(:name => "Users", :key_type => "ShortText")
|
31
|
-
@name = @users.define_column("name", "ShortText")
|
32
|
-
@hp = @users.define_column("hp", "UInt32")
|
33
|
-
@user_pet = @users.define_column("pet", @pets)
|
34
|
-
@user_section = @users.define_column("section", @sections)
|
35
|
-
|
36
|
-
@terms = Groonga::PatriciaTrie.create(:name => "Terms",
|
37
|
-
:default_tokenizer => "TokenBigram",
|
38
|
-
:key_type => "ShortText")
|
39
|
-
@terms.define_index_column("user_name", @users, :source => @name)
|
40
|
-
|
41
|
-
@bookmarks = Groonga::Array.create(:name => "Bookmarks")
|
42
|
-
@bookmarks.define_column("user", @users)
|
43
|
-
@bookmarks.define_column("uri", "ShortText")
|
44
|
-
|
45
|
-
@sections.define_index_column("user_section", @users,
|
46
|
-
:source => @user_section)
|
47
|
-
end
|
48
|
-
|
49
|
-
def setup_data
|
50
|
-
@morita = @users.add("morita",
|
51
|
-
:name => "mori daijiro",
|
52
|
-
:hp => 100,
|
53
|
-
:section => "search/core")
|
54
|
-
@gunyara_kun = @users.add("gunyara-kun",
|
55
|
-
:name => "Tasuku SUENAGA",
|
56
|
-
:hp => 150,
|
57
|
-
:section => "suggest/all")
|
58
|
-
@yu = @users.add("yu",
|
59
|
-
:name => "Yutaro Shimamura",
|
60
|
-
:hp => 200,
|
61
|
-
:section => "search/all")
|
62
|
-
|
63
|
-
@groonga = @bookmarks.add(:user => @morita, :uri => "http://groonga.org/")
|
64
|
-
@ruby = @bookmarks.add(:user => @morita, :uri => "http://ruby-lang.org/")
|
65
|
-
@nico_dict = @bookmarks.add(:user => @gunyara_kun,
|
66
|
-
:uri => "http://dic.nicovideo.jp/")
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_equal
|
70
|
-
result = @users.select do |record|
|
71
|
-
record["name"] == "mori daijiro"
|
72
|
-
end
|
73
|
-
assert_equal(["morita"],
|
74
|
-
result.collect {|record| record.key.key})
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_not_equal
|
78
|
-
only_ruby19
|
79
|
-
result = @users.select do |record|
|
80
|
-
record["name"] != "mori daijiro"
|
81
|
-
end
|
82
|
-
assert_equal(["gunyara-kun", "yu"],
|
83
|
-
result.collect {|record| record.key.key})
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_less
|
87
|
-
result = @users.select do |record|
|
88
|
-
record["hp"] < 150
|
89
|
-
end
|
90
|
-
assert_equal(["morita"], result.collect {|record| record.key.key})
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_less_equal
|
94
|
-
result = @users.select do |record|
|
95
|
-
record["hp"] <= 150
|
96
|
-
end
|
97
|
-
assert_equal(["morita", "gunyara-kun"],
|
98
|
-
result.collect {|record| record.key.key})
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_greater
|
102
|
-
result = @users.select do |record|
|
103
|
-
record["hp"] > 150
|
104
|
-
end
|
105
|
-
assert_equal(["yu"], result.collect {|record| record.key.key})
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_greater_equal
|
109
|
-
result = @users.select do |record|
|
110
|
-
record["hp"] >= 150
|
111
|
-
end
|
112
|
-
assert_equal(["gunyara-kun", "yu"],
|
113
|
-
result.collect {|record| record.key.key})
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_and
|
117
|
-
result = @users.select do |record|
|
118
|
-
(record["hp"] > 100) & (record["hp"] <= 200)
|
119
|
-
end
|
120
|
-
assert_equal(["gunyara-kun", "yu"],
|
121
|
-
result.collect {|record| record.key.key})
|
122
|
-
end
|
123
|
-
|
124
|
-
def test_match
|
125
|
-
result = @users.select do |record|
|
126
|
-
record["name"] =~ "ro"
|
127
|
-
end
|
128
|
-
assert_equal(["morita", "yu"],
|
129
|
-
result.collect {|record| record.key.key})
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_prefix_saerch
|
133
|
-
result = @users.select do |record|
|
134
|
-
record.section.prefix_search("search")
|
135
|
-
end
|
136
|
-
assert_equal(["morita", "yu"].sort,
|
137
|
-
result.collect {|record| record.key.key}.sort)
|
138
|
-
end
|
139
|
-
|
140
|
-
def test_suffix_search
|
141
|
-
result = @users.select do |record|
|
142
|
-
record.name.suffix_search("jiro")
|
143
|
-
end
|
144
|
-
assert_equal(["morita"].sort,
|
145
|
-
result.collect {|record| record.key.key}.sort)
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_query_string
|
149
|
-
result = @users.select("name:@ro")
|
150
|
-
assert_equal(["morita", "yu"],
|
151
|
-
result.collect {|record| record.key.key})
|
152
|
-
end
|
153
|
-
|
154
|
-
def test_record
|
155
|
-
result = @bookmarks.select do |record|
|
156
|
-
record["user"] == @morita
|
157
|
-
end
|
158
|
-
assert_equal(["http://groonga.org/", "http://ruby-lang.org/"],
|
159
|
-
result.collect {|record| record.key["uri"]})
|
160
|
-
end
|
161
|
-
|
162
|
-
def test_record_id
|
163
|
-
result = @bookmarks.select do |record|
|
164
|
-
record["user"] == @morita.id
|
165
|
-
end
|
166
|
-
assert_equal(["http://groonga.org/", "http://ruby-lang.org/"],
|
167
|
-
result.collect {|record| record.key["uri"]})
|
168
|
-
end
|
169
|
-
|
170
|
-
def test_record_id_object
|
171
|
-
morita = Object.new
|
172
|
-
morita_singleton_class = (class << morita; self; end)
|
173
|
-
morita_id = @morita.id
|
174
|
-
morita_singleton_class.send(:define_method, :record_id) do
|
175
|
-
morita_id
|
176
|
-
end
|
177
|
-
result = @bookmarks.select do |record|
|
178
|
-
record["user"] == morita
|
179
|
-
end
|
180
|
-
assert_equal(["http://groonga.org/", "http://ruby-lang.org/"],
|
181
|
-
result.collect {|record| record.key["uri"]})
|
182
|
-
end
|
183
|
-
|
184
|
-
def test_nested_column
|
185
|
-
result = @bookmarks.select do |record|
|
186
|
-
record[".user.name"] == @morita["name"]
|
187
|
-
end
|
188
|
-
assert_equal(["http://groonga.org/", "http://ruby-lang.org/"],
|
189
|
-
result.collect {|record| record["uri"]})
|
190
|
-
end
|
191
|
-
|
192
|
-
def test_method_chain
|
193
|
-
result = @bookmarks.select do |record|
|
194
|
-
record.user.name == @morita["name"]
|
195
|
-
end
|
196
|
-
assert_equal(["http://groonga.org/", "http://ruby-lang.org/"],
|
197
|
-
result.collect {|record| record["uri"]})
|
198
|
-
end
|
199
|
-
|
200
|
-
def test_deep_method_chain
|
201
|
-
@pets.add("bob", :name => "morita Bob")
|
202
|
-
@morita["pet"] = "bob"
|
203
|
-
|
204
|
-
result = @bookmarks.select do |record|
|
205
|
-
record.user.pet.name == "morita Bob"
|
206
|
-
end
|
207
|
-
assert_equal(["http://groonga.org/", "http://ruby-lang.org/"],
|
208
|
-
result.collect {|record| record["uri"]})
|
209
|
-
end
|
210
|
-
|
211
|
-
def test_nil_match
|
212
|
-
@users.select do |record|
|
213
|
-
exception = ArgumentError.new("match word should not be nil: Users.name")
|
214
|
-
assert_raise(exception) do
|
215
|
-
record["name"] =~ nil
|
216
|
-
end
|
217
|
-
record["name"] == "dummy"
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
def test_id
|
222
|
-
result = @users.select do |record|
|
223
|
-
record.id == 1
|
224
|
-
end
|
225
|
-
assert_equal(["morita"],
|
226
|
-
result.collect {|record| record.key.key})
|
227
|
-
end
|
228
|
-
|
229
|
-
def test_key
|
230
|
-
result = @users.select do |record|
|
231
|
-
record.key == "morita"
|
232
|
-
end
|
233
|
-
assert_equal(["morita"],
|
234
|
-
result.collect {|record| record.key.key})
|
235
|
-
end
|
236
|
-
|
237
|
-
def test_score
|
238
|
-
result = @users.select do |record|
|
239
|
-
(record.name =~ "o") | (record.hp >= 150)
|
240
|
-
end
|
241
|
-
result = result.select do |record|
|
242
|
-
record.score > 1
|
243
|
-
end
|
244
|
-
assert_equal(["yu"],
|
245
|
-
result.collect {|record| record["_key"]})
|
246
|
-
end
|
247
|
-
|
248
|
-
def test_n_sub_records
|
249
|
-
result = @users.select do |record|
|
250
|
-
(record.name =~ "o") | (record.hp >= 150)
|
251
|
-
end
|
252
|
-
result = result.select do |record|
|
253
|
-
record.n_sub_records > 1
|
254
|
-
end
|
255
|
-
assert_equal(["yu"],
|
256
|
-
result.collect {|record| record["_key"]})
|
257
|
-
end
|
258
|
-
|
259
|
-
def test_array_result
|
260
|
-
result = @users.select do |record|
|
261
|
-
conditions = []
|
262
|
-
conditions << (record.hp > 100)
|
263
|
-
conditions << (record.hp < 200)
|
264
|
-
conditions
|
265
|
-
end
|
266
|
-
assert_equal(["gunyara-kun"],
|
267
|
-
result.collect {|record| record.key.key})
|
268
|
-
end
|
269
|
-
end
|