rroonga 0.9.4-x86-mingw32 → 0.9.5-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/NEWS.ja.rdoc +29 -0
- data/NEWS.rdoc +29 -0
- data/Rakefile +6 -6
- data/ext/groonga/rb-grn-array.c +1 -1
- data/ext/groonga/rb-grn-context.c +15 -28
- data/ext/groonga/rb-grn-exception.c +46 -1
- data/ext/groonga/rb-grn-expression.c +22 -13
- data/ext/groonga/rb-grn-fix-size-column.c +2 -8
- data/ext/groonga/rb-grn-hash.c +8 -1
- data/ext/groonga/rb-grn-object.c +1 -1
- data/ext/groonga/rb-grn-patricia-trie.c +23 -1
- data/ext/groonga/rb-grn-table-key-support.c +22 -0
- data/ext/groonga/rb-grn-table.c +37 -5
- data/ext/groonga/rb-grn-utils.c +20 -2
- data/ext/groonga/rb-grn.h +1 -1
- data/ext/groonga/rb-groonga.c +76 -38
- data/extconf.rb +17 -1
- data/html/developer.html +32 -7
- data/html/footer.html.erb +5 -0
- data/html/heading-mark.svg +393 -0
- data/html/index.html +33 -3
- data/lib/1.8/groonga.so +0 -0
- data/lib/1.9/groonga.so +0 -0
- data/lib/groonga.rb +3 -7
- data/lib/groonga/context.rb +2 -13
- data/lib/groonga/expression-builder.rb +273 -67
- data/lib/groonga/pagination.rb +143 -0
- data/lib/groonga/record.rb +2 -0
- data/lib/groonga/schema.rb +140 -29
- data/pkg/rroonga-0.9.5/NEWS.ja.rdoc +156 -0
- data/pkg/rroonga-0.9.5/NEWS.rdoc +158 -0
- data/pkg/rroonga-0.9.5/README.ja.rdoc +65 -0
- data/pkg/rroonga-0.9.5/README.rdoc +66 -0
- data/pkg/rroonga-0.9.5/text/TUTORIAL.ja.rdoc +394 -0
- data/pkg/rroonga-0.9.5/text/expression.rdoc +285 -0
- data/rroonga-build.rb +2 -2
- 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/groonga-test-utils.rb +3 -2
- data/test/run-test.rb +14 -2
- data/test/test-column.rb +7 -7
- data/test/test-context-select.rb +34 -11
- data/test/test-exception.rb +3 -0
- data/test/test-expression-builder.rb +11 -0
- data/test/test-expression.rb +3 -6
- data/test/test-gqtp.rb +3 -5
- data/test/test-pagination.rb +249 -0
- data/test/test-record.rb +36 -8
- data/test/test-remote.rb +11 -4
- data/test/test-schema-create-table.rb +251 -0
- data/test/test-schema.rb +4 -24
- data/test/test-table-offset-and-limit.rb +3 -5
- data/test/test-table-select-mecab.rb +80 -0
- data/test/test-table-select-weight.rb +104 -0
- data/test/test-table.rb +22 -4
- data/test/test-version.rb +1 -1
- data/text/TUTORIAL.ja.rdoc +2 -0
- data/text/expression.rdoc +1 -0
- data/vendor/local/bin/grntest.exe +0 -0
- data/vendor/local/bin/groonga.exe +0 -0
- data/vendor/local/bin/libgroonga-0.dll +0 -0
- data/vendor/local/include/{groonga.h → groonga/groonga.h} +93 -32
- data/vendor/local/lib/groonga/modules/functions/cast.dll +0 -0
- data/vendor/local/lib/groonga/modules/functions/cast.la +41 -0
- data/vendor/local/lib/pkgconfig/groonga.pc +12 -0
- data/vendor/local/share/groonga/admin_html/css/admin.css +104 -0
- data/vendor/local/share/groonga/admin_html/css/ui-lightness/jquery-ui-1.8.1.custom.css +486 -0
- data/vendor/local/share/groonga/admin_html/index.html +1355 -0
- data/vendor/local/share/groonga/admin_html/js/jquery-1.4.2.min.js +154 -0
- data/vendor/local/share/groonga/admin_html/js/jquery-ui-1.8.1.custom.min.js +756 -0
- data/vendor/local/share/groonga/munin/plugins/groonga_cpu_load +47 -0
- data/vendor/local/share/groonga/munin/plugins/groonga_cpu_time +57 -0
- data/vendor/local/share/groonga/munin/plugins/groonga_disk +162 -0
- data/vendor/local/share/groonga/munin/plugins/groonga_memory +51 -0
- data/vendor/local/share/groonga/munin/plugins/groonga_n_records +110 -0
- data/vendor/local/share/groonga/munin/plugins/groonga_query_performance +133 -0
- data/vendor/local/share/groonga/munin/plugins/groonga_status +84 -0
- metadata +126 -36
@@ -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/groonga-test-utils.rb
CHANGED
@@ -126,9 +126,10 @@ module GroongaTestUtils
|
|
126
126
|
end
|
127
127
|
|
128
128
|
private
|
129
|
-
def assert_equal_select_result(expected, actual)
|
129
|
+
def assert_equal_select_result(expected, actual, &normalizer)
|
130
|
+
normalizer ||= Proc.new {|record| record.key}
|
130
131
|
assert_equal(expected,
|
131
|
-
actual.collect
|
132
|
+
actual.collect(&normalizer),
|
132
133
|
actual.expression.inspect)
|
133
134
|
end
|
134
135
|
end
|
data/test/run-test.rb
CHANGED
@@ -22,6 +22,8 @@ $KCODE = "u" if RUBY_VERSION < "1.9"
|
|
22
22
|
base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
23
23
|
test_unit_dir = File.join(base_dir, "test-unit")
|
24
24
|
test_unit_lib_dir = File.join(test_unit_dir, "lib")
|
25
|
+
test_unit_notify_dir = File.join(base_dir, "test-unit-notify")
|
26
|
+
test_unit_notify_lib_dir = File.join(test_unit_notify_dir, "lib")
|
25
27
|
ext_dir = File.join(base_dir, "ext", "groonga")
|
26
28
|
lib_dir = File.join(base_dir, "lib")
|
27
29
|
test_dir = File.join(base_dir, "test")
|
@@ -36,16 +38,26 @@ if make
|
|
36
38
|
system("cd #{base_dir.dump} && #{make} > /dev/null") or exit(false)
|
37
39
|
end
|
38
40
|
|
41
|
+
test_unit_repository_base = "http://test-unit.rubyforge.org/svn/"
|
39
42
|
unless File.exist?(test_unit_dir)
|
40
|
-
test_unit_repository = "
|
41
|
-
system("svn co
|
43
|
+
test_unit_repository = "#{test_unit_repository_base}trunk/"
|
44
|
+
system("svn", "co", test_unit_repository, test_unit_dir) or exit(false)
|
45
|
+
end
|
46
|
+
|
47
|
+
unless File.exist?(test_unit_notify_dir)
|
48
|
+
test_unit_notify_repository = "#{test_unit_repository_base}/extensions/test-unit-notify/trunk/"
|
49
|
+
system("svn", "co", test_unit_notify_repository, test_unit_notify_dir) or exit(false)
|
50
|
+
system("svn", "up", test_unit_dir) or exit(false)
|
42
51
|
end
|
43
52
|
|
44
53
|
$LOAD_PATH.unshift(test_unit_lib_dir)
|
54
|
+
$LOAD_PATH.unshift(test_unit_notify_lib_dir)
|
45
55
|
|
46
56
|
require 'test/unit'
|
57
|
+
require 'test/unit/notify'
|
47
58
|
|
48
59
|
ARGV.unshift("--priority-mode")
|
60
|
+
ARGV.unshift("--notify")
|
49
61
|
|
50
62
|
$LOAD_PATH.unshift(ext_dir)
|
51
63
|
$LOAD_PATH.unshift(lib_dir)
|
data/test/test-column.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
|
1
|
+
# Copyright (C) 2009-2010 Kouhei Sutou <kou@clear-code.com>
|
2
2
|
#
|
3
3
|
# This library is free software; you can redistribute it and/or
|
4
4
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -183,7 +183,7 @@ class ColumnTest < Test::Unit::TestCase
|
|
183
183
|
result.records.collect do |record|
|
184
184
|
record["body"]
|
185
185
|
end)
|
186
|
-
assert_equal("#<Groonga::Expression noname(
|
186
|
+
assert_equal("#<Groonga::Expression noname($1:\"\")" +
|
187
187
|
"{2body GET_VALUE,0\"drive\",0MATCH}>",
|
188
188
|
result.expression.inspect)
|
189
189
|
end
|
@@ -214,7 +214,7 @@ class ColumnTest < Test::Unit::TestCase
|
|
214
214
|
result.records.collect do |record|
|
215
215
|
record["body"]
|
216
216
|
end)
|
217
|
-
assert_equal("#<Groonga::Expression noname(
|
217
|
+
assert_equal("#<Groonga::Expression noname($1:\"\")" +
|
218
218
|
"{2body GET_VALUE,0\"drive\",0MATCH}>",
|
219
219
|
result.expression.inspect)
|
220
220
|
end
|
@@ -232,8 +232,8 @@ class ColumnTest < Test::Unit::TestCase
|
|
232
232
|
result.records.collect do |record|
|
233
233
|
record["body"]
|
234
234
|
end)
|
235
|
-
assert_equal("#<Groonga::Expression noname(
|
236
|
-
"{0
|
235
|
+
assert_equal("#<Groonga::Expression noname($1:\"\")" +
|
236
|
+
"{0\"\",2body GET_VALUE,0\"drive\",0MATCH}>",
|
237
237
|
result.expression.inspect)
|
238
238
|
end
|
239
239
|
|
@@ -247,8 +247,8 @@ class ColumnTest < Test::Unit::TestCase
|
|
247
247
|
result.records.collect do |record|
|
248
248
|
record["body"]
|
249
249
|
end)
|
250
|
-
assert_equal("#<Groonga::Expression noname(
|
251
|
-
"{1
|
250
|
+
assert_equal("#<Groonga::Expression noname($1:\"\")" +
|
251
|
+
"{1\"\",2body GET_VALUE,0\"drive\",0MATCH}>",
|
252
252
|
result.expression.inspect)
|
253
253
|
end
|
254
254
|
|
data/test/test-context-select.rb
CHANGED
@@ -42,12 +42,6 @@ class ContextSelectTest < Test::Unit::TestCase
|
|
42
42
|
[result.n_hits, result.records])
|
43
43
|
end
|
44
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
45
|
def test_output_columns
|
52
46
|
result = context.select(@users, :output_columns => ["_key"])
|
53
47
|
assert_equal([3,
|
@@ -63,10 +57,7 @@ class ContextSelectTest < Test::Unit::TestCase
|
|
63
57
|
:drill_down => ["_key", "book"],
|
64
58
|
:drill_down_output_columns => "_key",
|
65
59
|
:drill_down_limit => 10)
|
66
|
-
|
67
|
-
result.drill_down.each do |key, drill_down|
|
68
|
-
normalized_drill_down[key] = [drill_down.n_hits, drill_down.records]
|
69
|
-
end
|
60
|
+
drill_down = normalize_drill_down(result.drill_down)
|
70
61
|
assert_equal([3,
|
71
62
|
[{"_key" => "morita"},
|
72
63
|
{"_key" => "gunyara-kun"},
|
@@ -78,7 +69,24 @@ class ContextSelectTest < Test::Unit::TestCase
|
|
78
69
|
"book" => [1, [{"_key" => "the groonga book"}]],
|
79
70
|
},
|
80
71
|
],
|
81
|
-
[result.n_hits, result.records,
|
72
|
+
[result.n_hits, result.records, drill_down])
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_drill_down_with_no_hit
|
76
|
+
result = context.select(@users,
|
77
|
+
:filter => "_key == \"no hit\"",
|
78
|
+
:output_columns => ["_key"],
|
79
|
+
:drill_down => ["_key", "book"],
|
80
|
+
:drill_down_output_columns => "_key",
|
81
|
+
:drill_down_limit => 10)
|
82
|
+
drill_down = normalize_drill_down(result.drill_down)
|
83
|
+
assert_equal([0, [],
|
84
|
+
{
|
85
|
+
"_key" => [0, []],
|
86
|
+
"book" => [0, []],
|
87
|
+
},
|
88
|
+
],
|
89
|
+
[result.n_hits, result.records, drill_down])
|
82
90
|
end
|
83
91
|
|
84
92
|
def test_time
|
@@ -90,4 +98,19 @@ class ContextSelectTest < Test::Unit::TestCase
|
|
90
98
|
}],
|
91
99
|
result.records)
|
92
100
|
end
|
101
|
+
|
102
|
+
def test_invalid_select
|
103
|
+
assert_raise(Groonga::SyntaxError) do
|
104
|
+
context.select(@books, :query => "<")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
def normalize_drill_down(drill_down)
|
110
|
+
normalized_drill_down = {}
|
111
|
+
drill_down.each do |key, drill|
|
112
|
+
normalized_drill_down[key] = [drill.n_hits, drill.records]
|
113
|
+
end
|
114
|
+
normalized_drill_down
|
115
|
+
end
|
93
116
|
end
|
data/test/test-exception.rb
CHANGED
@@ -89,5 +89,8 @@ class ExceptionTest < Test::Unit::TestCase
|
|
89
89
|
assert_const_defined(Groonga, :RetryMax)
|
90
90
|
assert_const_defined(Groonga, :IncompatibleFileFormat)
|
91
91
|
assert_const_defined(Groonga, :UpdateNotAllowed)
|
92
|
+
assert_const_defined(Groonga, :TooSmallOffset)
|
93
|
+
assert_const_defined(Groonga, :TooLargeOffset)
|
94
|
+
assert_const_defined(Groonga, :TooSmallLimit)
|
92
95
|
end
|
93
96
|
end
|
@@ -214,4 +214,15 @@ class ExpressionBuilderTest < Test::Unit::TestCase
|
|
214
214
|
assert_equal(["yu"],
|
215
215
|
result.collect {|record| record["_key"]})
|
216
216
|
end
|
217
|
+
|
218
|
+
def test_array_result
|
219
|
+
result = @users.select do |record|
|
220
|
+
conditions = []
|
221
|
+
conditions << (record.hp > 100)
|
222
|
+
conditions << (record.hp < 200)
|
223
|
+
conditions
|
224
|
+
end
|
225
|
+
assert_equal(["gunyara-kun"],
|
226
|
+
result.collect {|record| record.key.key})
|
227
|
+
end
|
217
228
|
end
|
data/test/test-expression.rb
CHANGED
@@ -45,8 +45,7 @@ class ExpressionTest < Test::Unit::TestCase
|
|
45
45
|
expression.append_constant("name")
|
46
46
|
expression.append_operation(Groonga::Operation::GET_VALUE, 2)
|
47
47
|
expression.compile
|
48
|
-
expression.execute
|
49
|
-
assert_equal("mori daijiro", context.pop)
|
48
|
+
assert_equal("mori daijiro", expression.execute)
|
50
49
|
end
|
51
50
|
|
52
51
|
def test_get_value_with_variable
|
@@ -63,12 +62,10 @@ class ExpressionTest < Test::Unit::TestCase
|
|
63
62
|
expression.append_constant("name")
|
64
63
|
expression.append_operation(Groonga::Operation::GET_VALUE, 2)
|
65
64
|
expression.compile
|
66
|
-
expression.execute
|
67
|
-
assert_equal("mori daijiro", context.pop)
|
65
|
+
assert_equal("mori daijiro", expression.execute)
|
68
66
|
|
69
67
|
variable.value = gunyara_kun.id
|
70
|
-
expression.execute
|
71
|
-
assert_equal("Tasuku SUENAGA", context.pop)
|
68
|
+
assert_equal("Tasuku SUENAGA", expression.execute)
|
72
69
|
end
|
73
70
|
|
74
71
|
def test_inspect
|
data/test/test-gqtp.rb
CHANGED
@@ -50,13 +50,13 @@ class GQTPTest < Test::Unit::TestCase
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def test_select_filter_by_existent_user
|
53
|
-
assert_equal([[
|
53
|
+
assert_equal([[[1], [["user", "Users"]], ["darashi"]]],
|
54
54
|
process("select Comments --output_columns user " +
|
55
55
|
"--filter 'user == \"darashi\"'"))
|
56
56
|
end
|
57
57
|
|
58
58
|
def test_select_filter_by_nonexistent_user
|
59
|
-
assert_equal([[
|
59
|
+
assert_equal([[[0], [["user", "Users"]]]],
|
60
60
|
process("select Comments --output_columns user " +
|
61
61
|
"--filter 'user == \"yu\"'"))
|
62
62
|
end
|
@@ -65,8 +65,6 @@ class GQTPTest < Test::Unit::TestCase
|
|
65
65
|
def process(gqtp)
|
66
66
|
context.send(gqtp)
|
67
67
|
id, result = context.receive
|
68
|
-
|
69
|
-
result[0][1..2] = [0.0, 0.0] if result[0][0].zero?
|
70
|
-
result
|
68
|
+
JSON.parse(result)
|
71
69
|
end
|
72
70
|
end
|
@@ -0,0 +1,249 @@
|
|
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 PaginationTest < Test::Unit::TestCase
|
17
|
+
include GroongaTestUtils
|
18
|
+
|
19
|
+
setup :setup_database
|
20
|
+
|
21
|
+
setup
|
22
|
+
def setup_data
|
23
|
+
Groonga::Schema.define do |schema|
|
24
|
+
schema.create_table("Users",
|
25
|
+
:type => :hash,
|
26
|
+
:key_type => "ShortText") do |table|
|
27
|
+
table.uint32(:number)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
@users = context["Users"]
|
31
|
+
150.times do |i|
|
32
|
+
@users.add("user#{i + 1}", :number => i + 1)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_default
|
37
|
+
assert_paginate({
|
38
|
+
:current_page => 1,
|
39
|
+
:page_size => 10,
|
40
|
+
:n_pages => 15,
|
41
|
+
:n_records => 150,
|
42
|
+
:start_offset => 1,
|
43
|
+
:end_offset => 10,
|
44
|
+
:have_previous_page? => false,
|
45
|
+
:previous_page => nil,
|
46
|
+
:have_next_page? => true,
|
47
|
+
:next_page => 2,
|
48
|
+
:first_page? => true,
|
49
|
+
:last_page? => false,
|
50
|
+
:have_pages? => true,
|
51
|
+
})
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_no_entries
|
55
|
+
@users.each do |user|
|
56
|
+
user.delete
|
57
|
+
end
|
58
|
+
assert_paginate({
|
59
|
+
:current_page => 1,
|
60
|
+
:page_size => 10,
|
61
|
+
:n_pages => 1,
|
62
|
+
:n_records => 0,
|
63
|
+
:start_offset => nil,
|
64
|
+
:end_offset => nil,
|
65
|
+
:have_previous_page? => false,
|
66
|
+
:previous_page => nil,
|
67
|
+
:have_next_page? => false,
|
68
|
+
:next_page => nil,
|
69
|
+
:first_page? => true,
|
70
|
+
:last_page? => true,
|
71
|
+
:have_pages? => false,
|
72
|
+
:keys => [],
|
73
|
+
})
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_page
|
77
|
+
assert_paginate({
|
78
|
+
:current_page => 6,
|
79
|
+
:page_size => 10,
|
80
|
+
:n_pages => 15,
|
81
|
+
:n_records => 150,
|
82
|
+
:start_offset => 51,
|
83
|
+
:end_offset => 60,
|
84
|
+
:have_previous_page? => true,
|
85
|
+
:previous_page => 5,
|
86
|
+
:have_next_page? => true,
|
87
|
+
:next_page => 7,
|
88
|
+
:first_page? => false,
|
89
|
+
:last_page? => false,
|
90
|
+
:have_pages? => true,
|
91
|
+
},
|
92
|
+
:page => 6)
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_max_page
|
96
|
+
assert_paginate({
|
97
|
+
:current_page => 15,
|
98
|
+
:page_size => 10,
|
99
|
+
:n_pages => 15,
|
100
|
+
:n_records => 150,
|
101
|
+
:start_offset => 141,
|
102
|
+
:end_offset => 150,
|
103
|
+
:have_previous_page? => true,
|
104
|
+
:previous_page => 14,
|
105
|
+
:have_next_page? => false,
|
106
|
+
:next_page => nil,
|
107
|
+
:first_page? => false,
|
108
|
+
:last_page? => true,
|
109
|
+
:have_pages? => true,
|
110
|
+
},
|
111
|
+
:page => 15)
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_too_large_page
|
115
|
+
assert_raise(Groonga::TooLargePage) do
|
116
|
+
assert_paginate({},
|
117
|
+
:page => 16)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_zero_page
|
122
|
+
assert_raise(Groonga::TooSmallPage) do
|
123
|
+
assert_paginate({},
|
124
|
+
:page => 0)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_negative_page
|
129
|
+
assert_raise(Groonga::TooSmallPage) do
|
130
|
+
assert_paginate({},
|
131
|
+
:page => -1)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_size
|
136
|
+
assert_paginate({
|
137
|
+
:current_page => 1,
|
138
|
+
:page_size => 7,
|
139
|
+
:n_pages => 22,
|
140
|
+
:n_records => 150,
|
141
|
+
:start_offset => 1,
|
142
|
+
:end_offset => 7,
|
143
|
+
:have_previous_page? => false,
|
144
|
+
:previous_page => nil,
|
145
|
+
:have_next_page? => true,
|
146
|
+
:next_page => 2,
|
147
|
+
:first_page? => true,
|
148
|
+
:last_page? => false,
|
149
|
+
:have_pages? => true,
|
150
|
+
},
|
151
|
+
:size => 7)
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_max_size
|
155
|
+
assert_paginate({
|
156
|
+
:current_page => 1,
|
157
|
+
:page_size => 150,
|
158
|
+
:n_pages => 1,
|
159
|
+
:n_records => 150,
|
160
|
+
:start_offset => 1,
|
161
|
+
:end_offset => 150,
|
162
|
+
:have_previous_page? => false,
|
163
|
+
:previous_page => nil,
|
164
|
+
:have_next_page? => false,
|
165
|
+
:next_page => nil,
|
166
|
+
:first_page? => true,
|
167
|
+
:last_page? => true,
|
168
|
+
:have_pages? => false,
|
169
|
+
},
|
170
|
+
:size => 150)
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_too_large_size
|
174
|
+
assert_paginate({
|
175
|
+
:current_page => 1,
|
176
|
+
:page_size => 151,
|
177
|
+
:n_pages => 1,
|
178
|
+
:n_records => 150,
|
179
|
+
:start_offset => 1,
|
180
|
+
:end_offset => 150,
|
181
|
+
:have_previous_page? => false,
|
182
|
+
:previous_page => nil,
|
183
|
+
:have_next_page? => false,
|
184
|
+
:next_page => nil,
|
185
|
+
:first_page? => true,
|
186
|
+
:last_page? => true,
|
187
|
+
:have_pages? => false,
|
188
|
+
},
|
189
|
+
:size => 151)
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_zero_size
|
193
|
+
assert_raise(Groonga::TooSmallPageSize) do
|
194
|
+
assert_paginate({},
|
195
|
+
:size => 0)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_negative_size
|
200
|
+
assert_raise(Groonga::TooSmallPageSize) do
|
201
|
+
assert_paginate({},
|
202
|
+
:size => -1)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def test_full
|
207
|
+
assert_paginate({
|
208
|
+
:current_page => 2,
|
209
|
+
:page_size => 50,
|
210
|
+
:n_pages => 3,
|
211
|
+
:n_records => 150,
|
212
|
+
:start_offset => 51,
|
213
|
+
:end_offset => 100,
|
214
|
+
:have_previous_page? => true,
|
215
|
+
:previous_page => 1,
|
216
|
+
:have_next_page? => true,
|
217
|
+
:next_page => 3,
|
218
|
+
:first_page? => false,
|
219
|
+
:last_page? => false,
|
220
|
+
:have_pages? => true,
|
221
|
+
},
|
222
|
+
:page => 2,
|
223
|
+
:size => 50)
|
224
|
+
end
|
225
|
+
|
226
|
+
private
|
227
|
+
def assert_paginate(expected, options={})
|
228
|
+
users = @users.paginate([["number"]], options)
|
229
|
+
if expected[:keys].nil?
|
230
|
+
range = (expected[:start_offset]..expected[:end_offset])
|
231
|
+
expected[:keys] = range.collect {|i| "user#{i}"}
|
232
|
+
end
|
233
|
+
assert_equal(expected,
|
234
|
+
:current_page => users.current_page,
|
235
|
+
:page_size => users.page_size,
|
236
|
+
:n_pages => users.n_pages,
|
237
|
+
:n_records => users.n_records,
|
238
|
+
:start_offset => users.start_offset,
|
239
|
+
:end_offset => users.end_offset,
|
240
|
+
:previous_page => users.previous_page,
|
241
|
+
:have_previous_page? => users.have_previous_page?,
|
242
|
+
:next_page => users.next_page,
|
243
|
+
:have_next_page? => users.have_next_page?,
|
244
|
+
:first_page? => users.first_page?,
|
245
|
+
:last_page? => users.last_page?,
|
246
|
+
:have_pages? => users.have_pages?,
|
247
|
+
:keys => users.collect(&:key))
|
248
|
+
end
|
249
|
+
end
|