rroonga 0.9.2-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) hide show
  1. data/AUTHORS +5 -0
  2. data/NEWS.ja.rdoc +114 -0
  3. data/NEWS.rdoc +116 -0
  4. data/README.ja.rdoc +65 -0
  5. data/README.rdoc +66 -0
  6. data/Rakefile +217 -0
  7. data/benchmark/common.rb +49 -0
  8. data/benchmark/read-write-many-small-items.rb +144 -0
  9. data/benchmark/write-many-small-items.rb +135 -0
  10. data/example/bookmark.rb +161 -0
  11. data/example/index-html.rb +89 -0
  12. data/example/search/config.ru +211 -0
  13. data/example/search/public/css/groonga.css +122 -0
  14. data/ext/.gitignore +2 -0
  15. data/ext/libruby-groonga.a +0 -0
  16. data/ext/rb-grn-accessor.c +52 -0
  17. data/ext/rb-grn-array-cursor.c +36 -0
  18. data/ext/rb-grn-array.c +210 -0
  19. data/ext/rb-grn-column.c +573 -0
  20. data/ext/rb-grn-context.c +655 -0
  21. data/ext/rb-grn-database.c +472 -0
  22. data/ext/rb-grn-encoding-support.c +64 -0
  23. data/ext/rb-grn-encoding.c +257 -0
  24. data/ext/rb-grn-exception.c +1110 -0
  25. data/ext/rb-grn-expression-builder.c +75 -0
  26. data/ext/rb-grn-expression.c +735 -0
  27. data/ext/rb-grn-fix-size-column.c +166 -0
  28. data/ext/rb-grn-hash-cursor.c +38 -0
  29. data/ext/rb-grn-hash.c +294 -0
  30. data/ext/rb-grn-index-column.c +488 -0
  31. data/ext/rb-grn-logger.c +504 -0
  32. data/ext/rb-grn-object.c +1369 -0
  33. data/ext/rb-grn-operation.c +198 -0
  34. data/ext/rb-grn-patricia-trie-cursor.c +39 -0
  35. data/ext/rb-grn-patricia-trie.c +488 -0
  36. data/ext/rb-grn-procedure.c +52 -0
  37. data/ext/rb-grn-query.c +260 -0
  38. data/ext/rb-grn-record.c +40 -0
  39. data/ext/rb-grn-snippet.c +334 -0
  40. data/ext/rb-grn-table-cursor-key-support.c +69 -0
  41. data/ext/rb-grn-table-cursor.c +247 -0
  42. data/ext/rb-grn-table-key-support.c +731 -0
  43. data/ext/rb-grn-table.c +2141 -0
  44. data/ext/rb-grn-type.c +181 -0
  45. data/ext/rb-grn-utils.c +769 -0
  46. data/ext/rb-grn-variable-size-column.c +36 -0
  47. data/ext/rb-grn-variable.c +108 -0
  48. data/ext/rb-grn-view-accessor.c +53 -0
  49. data/ext/rb-grn-view-cursor.c +35 -0
  50. data/ext/rb-grn-view-record.c +41 -0
  51. data/ext/rb-grn-view.c +421 -0
  52. data/ext/rb-grn.h +700 -0
  53. data/ext/rb-groonga.c +117 -0
  54. data/extconf.rb +266 -0
  55. data/html/bar.svg +153 -0
  56. data/html/developer.html +117 -0
  57. data/html/developer.svg +469 -0
  58. data/html/download.svg +253 -0
  59. data/html/favicon.ico +0 -0
  60. data/html/favicon.xcf +0 -0
  61. data/html/footer.html.erb +28 -0
  62. data/html/head.html.erb +4 -0
  63. data/html/header.html.erb +17 -0
  64. data/html/index.html +147 -0
  65. data/html/install.svg +636 -0
  66. data/html/logo.xcf +0 -0
  67. data/html/ranguba.css +250 -0
  68. data/html/tutorial.svg +559 -0
  69. data/lib/groonga.rb +90 -0
  70. data/lib/groonga/context.rb +184 -0
  71. data/lib/groonga/expression-builder.rb +285 -0
  72. data/lib/groonga/patricia-trie.rb +53 -0
  73. data/lib/groonga/record.rb +311 -0
  74. data/lib/groonga/schema.rb +1191 -0
  75. data/lib/groonga/view-record.rb +56 -0
  76. data/license/GPL +340 -0
  77. data/license/LGPL +504 -0
  78. data/license/RUBY +59 -0
  79. data/misc/grnop2ruby.rb +49 -0
  80. data/pkg-config.rb +333 -0
  81. data/test-unit/Rakefile +40 -0
  82. data/test-unit/TODO +5 -0
  83. data/test-unit/bin/testrb +5 -0
  84. data/test-unit/html/classic.html +15 -0
  85. data/test-unit/html/index.html +25 -0
  86. data/test-unit/html/index.html.ja +27 -0
  87. data/test-unit/lib/test/unit.rb +323 -0
  88. data/test-unit/lib/test/unit/assertionfailederror.rb +25 -0
  89. data/test-unit/lib/test/unit/assertions.rb +1230 -0
  90. data/test-unit/lib/test/unit/attribute.rb +125 -0
  91. data/test-unit/lib/test/unit/autorunner.rb +360 -0
  92. data/test-unit/lib/test/unit/collector.rb +36 -0
  93. data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
  94. data/test-unit/lib/test/unit/collector/dir.rb +108 -0
  95. data/test-unit/lib/test/unit/collector/load.rb +136 -0
  96. data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
  97. data/test-unit/lib/test/unit/color-scheme.rb +102 -0
  98. data/test-unit/lib/test/unit/color.rb +96 -0
  99. data/test-unit/lib/test/unit/diff.rb +724 -0
  100. data/test-unit/lib/test/unit/error.rb +130 -0
  101. data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
  102. data/test-unit/lib/test/unit/failure.rb +136 -0
  103. data/test-unit/lib/test/unit/fixture.rb +176 -0
  104. data/test-unit/lib/test/unit/notification.rb +129 -0
  105. data/test-unit/lib/test/unit/omission.rb +191 -0
  106. data/test-unit/lib/test/unit/pending.rb +150 -0
  107. data/test-unit/lib/test/unit/priority.rb +180 -0
  108. data/test-unit/lib/test/unit/runner/console.rb +52 -0
  109. data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
  110. data/test-unit/lib/test/unit/runner/tap.rb +8 -0
  111. data/test-unit/lib/test/unit/testcase.rb +476 -0
  112. data/test-unit/lib/test/unit/testresult.rb +89 -0
  113. data/test-unit/lib/test/unit/testsuite.rb +110 -0
  114. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
  115. data/test-unit/lib/test/unit/ui/console/testrunner.rb +466 -0
  116. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +63 -0
  117. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +92 -0
  118. data/test-unit/lib/test/unit/ui/testrunner.rb +28 -0
  119. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
  120. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
  121. data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
  122. data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
  123. data/test-unit/lib/test/unit/util/observable.rb +90 -0
  124. data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
  125. data/test-unit/lib/test/unit/version.rb +7 -0
  126. data/test-unit/sample/adder.rb +13 -0
  127. data/test-unit/sample/subtracter.rb +12 -0
  128. data/test-unit/sample/test_adder.rb +20 -0
  129. data/test-unit/sample/test_subtracter.rb +20 -0
  130. data/test-unit/sample/test_user.rb +23 -0
  131. data/test-unit/test/collector/test-descendant.rb +133 -0
  132. data/test-unit/test/collector/test-load.rb +348 -0
  133. data/test-unit/test/collector/test_dir.rb +406 -0
  134. data/test-unit/test/collector/test_objectspace.rb +100 -0
  135. data/test-unit/test/run-test.rb +15 -0
  136. data/test-unit/test/test-attribute.rb +86 -0
  137. data/test-unit/test/test-color-scheme.rb +67 -0
  138. data/test-unit/test/test-color.rb +47 -0
  139. data/test-unit/test/test-diff.rb +518 -0
  140. data/test-unit/test/test-emacs-runner.rb +60 -0
  141. data/test-unit/test/test-fixture.rb +287 -0
  142. data/test-unit/test/test-notification.rb +33 -0
  143. data/test-unit/test/test-omission.rb +81 -0
  144. data/test-unit/test/test-pending.rb +70 -0
  145. data/test-unit/test/test-priority.rb +119 -0
  146. data/test-unit/test/test-testcase.rb +544 -0
  147. data/test-unit/test/test_assertions.rb +1151 -0
  148. data/test-unit/test/test_error.rb +26 -0
  149. data/test-unit/test/test_failure.rb +33 -0
  150. data/test-unit/test/test_testresult.rb +113 -0
  151. data/test-unit/test/test_testsuite.rb +129 -0
  152. data/test-unit/test/testunit-test-util.rb +14 -0
  153. data/test-unit/test/ui/test_testrunmediator.rb +20 -0
  154. data/test-unit/test/util/test-method-owner-finder.rb +38 -0
  155. data/test-unit/test/util/test_backtracefilter.rb +41 -0
  156. data/test-unit/test/util/test_observable.rb +102 -0
  157. data/test-unit/test/util/test_procwrapper.rb +36 -0
  158. data/test/.gitignore +1 -0
  159. data/test/groonga-test-utils.rb +133 -0
  160. data/test/run-test.rb +58 -0
  161. data/test/test-array.rb +97 -0
  162. data/test/test-column.rb +316 -0
  163. data/test/test-context-select.rb +93 -0
  164. data/test/test-context.rb +73 -0
  165. data/test/test-database.rb +113 -0
  166. data/test/test-encoding.rb +33 -0
  167. data/test/test-exception.rb +93 -0
  168. data/test/test-expression-builder.rb +156 -0
  169. data/test/test-expression.rb +134 -0
  170. data/test/test-fix-size-column.rb +65 -0
  171. data/test/test-gqtp.rb +72 -0
  172. data/test/test-hash.rb +312 -0
  173. data/test/test-index-column.rb +81 -0
  174. data/test/test-logger.rb +37 -0
  175. data/test/test-patricia-trie.rb +189 -0
  176. data/test/test-procedure.rb +37 -0
  177. data/test/test-query.rb +22 -0
  178. data/test/test-record.rb +279 -0
  179. data/test/test-remote.rb +54 -0
  180. data/test/test-schema-view.rb +90 -0
  181. data/test/test-schema.rb +459 -0
  182. data/test/test-snippet.rb +130 -0
  183. data/test/test-table-cursor.rb +153 -0
  184. data/test/test-table-offset-and-limit.rb +102 -0
  185. data/test/test-table-select-normalize.rb +53 -0
  186. data/test/test-table-select.rb +150 -0
  187. data/test/test-table.rb +690 -0
  188. data/test/test-type.rb +71 -0
  189. data/test/test-variable-size-column.rb +98 -0
  190. data/test/test-variable.rb +28 -0
  191. data/test/test-vector-column.rb +76 -0
  192. data/test/test-version.rb +31 -0
  193. data/test/test-view.rb +72 -0
  194. data/text/TUTORIAL.ja.rdoc +392 -0
  195. data/text/expression.rdoc +284 -0
  196. data/vendor/local/bin/grntest.exe +0 -0
  197. data/vendor/local/bin/groonga.exe +0 -0
  198. data/vendor/local/bin/libgroonga.dll +0 -0
  199. data/vendor/local/bin/libmecab.dll +0 -0
  200. data/vendor/local/include/groonga.h +2285 -0
  201. data/vendor/local/lib/libgroonga.lib +0 -0
  202. metadata +280 -0
@@ -0,0 +1,134 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License version 2.1 as published by the Free Software Foundation.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
+
17
+ class ExpressionTest < Test::Unit::TestCase
18
+ include GroongaTestUtils
19
+
20
+ setup :setup_database
21
+
22
+ def test_array_reference
23
+ expression = Groonga::Expression.new
24
+ ryoqun = expression.define_variable({:name => "user"})
25
+ ryoqun.value = "ryoqun"
26
+ mori = expression.define_variable
27
+ mori.value = "mori"
28
+
29
+ expression.append_object(ryoqun)
30
+ expression.append_object(mori)
31
+
32
+ assert_equal("ryoqun", expression["user"])
33
+ assert_equal("ryoqun", expression[0])
34
+ assert_equal("mori", expression[1])
35
+ end
36
+
37
+ def test_get_value
38
+ users = Groonga::Hash.create(:name => "Users")
39
+ name = users.define_column("name", "ShortText")
40
+
41
+ morita = users.add("morita", :name => "mori daijiro")
42
+
43
+ expression = Groonga::Expression.new
44
+ expression.append_constant(morita)
45
+ expression.append_constant("name")
46
+ expression.append_operation(Groonga::Operation::GET_VALUE, 2)
47
+ expression.compile
48
+ expression.execute
49
+ assert_equal("mori daijiro", context.pop)
50
+ end
51
+
52
+ def test_get_value_with_variable
53
+ users = Groonga::Hash.create(:name => "Users")
54
+ name = users.define_column("name", "ShortText")
55
+
56
+ morita = users.add("morita", :name => "mori daijiro")
57
+ gunyara_kun = users.add("gunyara-kun", :name => "Tasuku SUENAGA")
58
+
59
+ expression = Groonga::Expression.new
60
+ variable = expression.define_variable
61
+ variable.value = morita
62
+ expression.append_object(variable)
63
+ expression.append_constant("name")
64
+ expression.append_operation(Groonga::Operation::GET_VALUE, 2)
65
+ expression.compile
66
+ expression.execute
67
+ assert_equal("mori daijiro", context.pop)
68
+
69
+ variable.value = gunyara_kun.id
70
+ expression.execute
71
+ assert_equal("Tasuku SUENAGA", context.pop)
72
+ end
73
+
74
+ def test_inspect
75
+ expression = Groonga::Expression.new
76
+ expression.append_constant(1)
77
+ expression.append_constant(1)
78
+ expression.append_operation(Groonga::Operation::PLUS, 2)
79
+ expression.compile
80
+
81
+ assert_equal("#<Groonga::Expression noname(){21,01,0PLUS}>",
82
+ expression.inspect)
83
+ end
84
+
85
+ def test_snippet
86
+ users = Groonga::Array.create(:name => "Users")
87
+ name = users.define_column("name", "ShortText")
88
+ terms = Groonga::Hash.create(:name => "Terms",
89
+ :key_type => "ShortText",
90
+ :default_tokenizer => "TokenBigram")
91
+ users.define_index_column("user_name", users,
92
+ :source => "Users.name",
93
+ :with_position => true)
94
+
95
+ expression = Groonga::Expression.new
96
+ variable = expression.define_variable(:domain => users)
97
+ expression.append_object(variable)
98
+ expression.parse("ラングバ OR Ruby OR groonga", :default_column => name)
99
+ expression.compile
100
+
101
+ snippet = expression.snippet([["[[", "]]"], ["<", ">"]],
102
+ :width => 30)
103
+ assert_equal(["[[ラングバ]]プロジェクト",
104
+ "ン[[groonga]]の機能を<Ruby>か",
105
+ "。[[groonga]]の機能を<Ruby>ら"],
106
+ snippet.execute("ラングバプロジェクトはカラムストア機能も" +
107
+ "備える高速・高機能な全文検索エンジンgroonga" +
108
+ "の機能をRubyから利用するためのライブラリを" +
109
+ "提供するプロジェクトです。groongaの機能を" +
110
+ "Rubyらしい読み書きしやすい構文で利用できる" +
111
+ "ことが利点です。"))
112
+ end
113
+
114
+ def test_snippet_without_tags
115
+ users = Groonga::Array.create(:name => "Users")
116
+ name = users.define_column("name", "ShortText")
117
+ terms = Groonga::Hash.create(:name => "Terms",
118
+ :key_type => "ShortText",
119
+ :default_tokenizer => "TokenBigram")
120
+ users.define_index_column("user_name", users,
121
+ :source => "Users.name",
122
+ :with_position => true)
123
+
124
+ expression = Groonga::Expression.new
125
+ variable = expression.define_variable(:domain => users)
126
+ expression.append_object(variable)
127
+ expression.parse("ラングバ", :default_column => name)
128
+ expression.compile
129
+
130
+ snippet = expression.snippet([], :width => 30)
131
+ assert_equal(["ラングバプロジェクト"],
132
+ snippet.execute("ラングバプロジェクトはカラムストア機能も"))
133
+ end
134
+ end
@@ -0,0 +1,65 @@
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 FixSizeColumnTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ def setup
20
+ setup_database
21
+
22
+ setup_bookmarks_table
23
+ end
24
+
25
+ def setup_bookmarks_table
26
+ @bookmarks_path = @tables_dir + "bookmarks"
27
+ @bookmarks = Groonga::Array.create(:name => "Bookmarks",
28
+ :path => @bookmarks_path.to_s)
29
+
30
+ @viewed_column_path = @columns_dir + "viewed"
31
+ @viewed = @bookmarks.define_column("viewed", "Int32",
32
+ :path => @viewed_column_path.to_s)
33
+ end
34
+
35
+ def test_inspect
36
+ assert_equal("#<Groonga::FixSizeColumn " +
37
+ "id: <#{@viewed.id}>, " +
38
+ "name: <Bookmarks.viewed>, " +
39
+ "path: <#{@viewed_column_path}>, " +
40
+ "domain: <Bookmarks>, " +
41
+ "range: <Int32>, " +
42
+ "flags: <KEY_INT>" +
43
+ ">",
44
+ @viewed.inspect)
45
+ end
46
+
47
+ def test_domain
48
+ assert_equal(@bookmarks, @viewed.domain)
49
+ end
50
+
51
+ def test_table
52
+ assert_equal(@bookmarks, @viewed.table)
53
+ end
54
+
55
+ def test_assign_time
56
+ comments = Groonga::Array.create(:name => "Comments")
57
+ comments.define_column("title", "ShortText")
58
+ comments.define_column("issued", "Time")
59
+ title = "Good"
60
+ issued = 1187430026
61
+ record = comments.add(:title => title, :issued => issued)
62
+ assert_equal([title, Time.at(issued)],
63
+ [record["title"], record["issued"]])
64
+ end
65
+ end
data/test/test-gqtp.rb ADDED
@@ -0,0 +1,72 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 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
+ class GQTPTest < Test::Unit::TestCase
19
+ include GroongaTestUtils
20
+
21
+ setup :setup_database
22
+
23
+ setup
24
+ def setup_comments
25
+ @users = Groonga::Hash.create(:name => "Users", :key_type => "ShortText")
26
+
27
+ @comments = Groonga::Array.create(:name => "Comments")
28
+ @comments.define_column("content", "Text")
29
+ @comments.define_column("created_at", "Time")
30
+ @comments.define_column("user", "Users")
31
+
32
+ terms = Groonga::PatriciaTrie.create(:name => "Terms",
33
+ :default_tokenizer => "TokenBigram")
34
+ terms.define_index_column("comment_content", @comments,
35
+ :with_section => true,
36
+ :source => "content")
37
+ @comment1 = @comments.add(:content => "Hello Good-bye!",
38
+ :created_at => Time.parse("2009-08-09"),
39
+ :user => "morita")
40
+ @comment2 = @comments.add(:content => "Hello World",
41
+ :created_at => Time.parse("2009-07-09"),
42
+ :user => "")
43
+ @comment3 = @comments.add(:content => "test",
44
+ :created_at => Time.parse("2009-06-09"),
45
+ :user => "gunyara-kun")
46
+ @japanese_comment =
47
+ @comments.add(:content => "うちのボロTVはまだ現役です",
48
+ :created_at => Time.parse("2009-06-09"),
49
+ :user => "darashi")
50
+ end
51
+
52
+ def test_select_filter_by_existent_user
53
+ assert_equal([[0, 0.0, 0.0], [[[1], [["user", "Users"]], ["darashi"]]]],
54
+ process("select Comments --output_columns user " +
55
+ "--filter 'user == \"darashi\"'"))
56
+ end
57
+
58
+ def test_select_filter_by_nonexistent_user
59
+ assert_equal([[0, 0.0, 0.0], [[[0], [["user", "Users"]]]]],
60
+ process("select Comments --output_columns user " +
61
+ "--filter 'user == \"yu\"'"))
62
+ end
63
+
64
+ private
65
+ def process(gqtp)
66
+ context.send(gqtp)
67
+ id, result = context.receive
68
+ result = JSON.parse(result)
69
+ result[0][1..2] = [0.0, 0.0] if result[0][0].zero?
70
+ result
71
+ end
72
+ end
data/test/test-hash.rb ADDED
@@ -0,0 +1,312 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (C) 2009-2010 Kouhei Sutou <kou@clear-code.com>
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License version 2.1 as published by the Free Software Foundation.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
+
17
+ class HashTest < Test::Unit::TestCase
18
+ include GroongaTestUtils
19
+
20
+ setup :setup_database
21
+
22
+ def test_delete
23
+ bookmarks_path = @tables_dir + "bookmarks"
24
+ bookmarks = Groonga::Hash.create(:name => "Bookmarks",
25
+ :path => bookmarks_path.to_s)
26
+
27
+ groonga = bookmarks.add("groonga")
28
+ google = bookmarks.add("Google")
29
+ cutter = bookmarks.add("Cutter")
30
+
31
+ assert_equal(["groonga", "Google", "Cutter"],
32
+ bookmarks.collect {|bookmark| bookmark.key})
33
+
34
+ bookmarks.delete(google.id)
35
+ assert_equal(["groonga", "Cutter"],
36
+ bookmarks.collect {|bookmark| bookmark.key})
37
+
38
+ bookmarks.delete(cutter.key)
39
+ assert_equal(["groonga"],
40
+ bookmarks.collect {|bookmark| bookmark.key})
41
+ end
42
+
43
+ def test_value
44
+ bookmarks_path = @tables_dir + "bookmarks"
45
+ bookmarks = Groonga::Hash.create(:name => "Bookmarks",
46
+ :path => bookmarks_path.to_s,
47
+ :key_type => "ShortText",
48
+ :value_type => "UInt32")
49
+ bookmarks.set_value("http://google.com/", 29)
50
+ assert_equal(29, bookmarks.value("http://google.com/"))
51
+ end
52
+
53
+ def test_column_value
54
+ bookmarks_path = @tables_dir + "bookmarks"
55
+ bookmarks = Groonga::Hash.create(:name => "Bookmarks",
56
+ :path => bookmarks_path.to_s,
57
+ :key_type => "ShortText")
58
+ uri = bookmarks.define_column("uri", "ShortText")
59
+ bookmarks.set_column_value("google", "uri", "http://google.com/")
60
+ assert_equal("http://google.com/", bookmarks.column_value("google", "uri"))
61
+ end
62
+
63
+ def test_array_reference
64
+ bookmarks_path = @tables_dir + "bookmarks"
65
+ bookmarks = Groonga::Hash.create(:name => "bookmarks",
66
+ :path => bookmarks_path.to_s,
67
+ :key_type => "ShortText")
68
+ bookmark = bookmarks.add("http://google.com/")
69
+ assert_equal(bookmark, bookmarks["http://google.com/"])
70
+ end
71
+
72
+
73
+ def test_inspect_anonymous
74
+ path = @tables_dir + "anoymous.groonga"
75
+ anonymous_table = Groonga::Hash.create(:path => path.to_s)
76
+ assert_equal("#<Groonga::Hash " +
77
+ "id: <#{anonymous_table.id}>, " +
78
+ "name: (anonymous), " +
79
+ "path: <#{path}>, " +
80
+ "domain: (nil), " +
81
+ "range: (nil), " +
82
+ "flags: <>, " +
83
+ "encoding: <#{encoding.inspect}>, " +
84
+ "size: <0>>",
85
+ anonymous_table.inspect)
86
+ end
87
+
88
+ def test_inspect_anonymous_temporary
89
+ anonymous_table = Groonga::Hash.create
90
+ assert_equal("#<Groonga::Hash " +
91
+ "id: <#{anonymous_table.id}>, " +
92
+ "name: (anonymous), " +
93
+ "path: (temporary), " +
94
+ "domain: (nil), " +
95
+ "range: (nil), " +
96
+ "flags: <>, " +
97
+ "encoding: <#{encoding.inspect}>, " +
98
+ "size: <0>>",
99
+ anonymous_table.inspect)
100
+ end
101
+
102
+ def test_inspect_named
103
+ path = @tables_dir + "named.groonga"
104
+ named_table = Groonga::Hash.create(:name => "Users", :path => path.to_s)
105
+ assert_equal("#<Groonga::Hash " +
106
+ "id: <#{named_table.id}>, " +
107
+ "name: <Users>, " +
108
+ "path: <#{path}>, " +
109
+ "domain: (nil), " +
110
+ "range: (nil), " +
111
+ "flags: <>, " +
112
+ "encoding: <#{encoding.inspect}>, " +
113
+ "size: <0>>",
114
+ named_table.inspect)
115
+ end
116
+
117
+ def test_inspect_temporary
118
+ named_table = Groonga::Hash.create
119
+ assert_equal("#<Groonga::Hash " +
120
+ "id: <#{named_table.id}>, " +
121
+ "name: (anonymous), " +
122
+ "path: (temporary), " +
123
+ "domain: (nil), " +
124
+ "range: (nil), " +
125
+ "flags: <>, " +
126
+ "encoding: <#{encoding.inspect}>, " +
127
+ "size: <0>>",
128
+ named_table.inspect)
129
+ end
130
+
131
+ def test_encoding
132
+ assert_equal(Groonga::Encoding.default,
133
+ Groonga::Hash.create.encoding)
134
+ end
135
+
136
+ def test_tokenizer
137
+ hash = Groonga::Hash.create
138
+ assert_nil(hash.default_tokenizer)
139
+ hash.default_tokenizer = "TokenBigram"
140
+ assert_equal(Groonga::Context.default["TokenBigram"],
141
+ hash.default_tokenizer)
142
+ end
143
+
144
+ def test_search
145
+ users = Groonga::Array.create(:name => "Users")
146
+ user_name = users.define_column("name", "ShortText")
147
+
148
+ bookmarks = Groonga::Hash.create(:name => "Bookmarks",
149
+ :key_type => "ShortText")
150
+ bookmark_user_id = bookmarks.define_column("user_id", users)
151
+
152
+ daijiro = users.add
153
+ daijiro["name"] = "daijiro"
154
+ gunyarakun = users.add
155
+ gunyarakun["name"] = "gunyarakun"
156
+
157
+ groonga = bookmarks.add("http://groonga.org/")
158
+ groonga["user_id"] = daijiro
159
+
160
+ records = bookmarks.search("http://groonga.org/")
161
+ assert_equal(["daijiro"],
162
+ records.records.collect {|record| record[".user_id.name"]})
163
+ end
164
+
165
+ def test_add
166
+ users = Groonga::Hash.create(:name => "Users")
167
+ users.define_column("address", "Text")
168
+ me = users.add("me", :address => "me@example.com")
169
+ assert_equal("me@example.com", me[:address])
170
+ end
171
+
172
+ def test_default_tokenizer_on_create
173
+ terms = Groonga::Hash.create(:name => "Terms",
174
+ :default_tokenizer => "TokenTrigram")
175
+ assert_equal(context[Groonga::Type::TRIGRAM],
176
+ terms.default_tokenizer)
177
+ end
178
+
179
+ def test_duplicated_name
180
+ Groonga::Hash.create(:name => "Users")
181
+ assert_raise(Groonga::InvalidArgument) do
182
+ Groonga::Hash.create(:name => "Users")
183
+ end
184
+ end
185
+
186
+ def test_define_index_column_implicit_with_position
187
+ bookmarks = Groonga::Hash.create(:name => "Bookmarks")
188
+ bookmarks.define_column("comment", "Text")
189
+ terms = Groonga::Hash.create(:name => "Terms",
190
+ :default_tokenizer => "TokenBigram")
191
+ index = terms.define_index_column("comment", bookmarks,
192
+ :source => "Bookmarks.comment")
193
+ groonga = bookmarks.add("groonga", :comment => "search engine by Brazil")
194
+ google = bookmarks.add("google", :comment => "search engine by Google")
195
+ ruby = bookmarks.add("ruby", :comment => "programing language")
196
+
197
+ assert_equal(["groonga", "google"],
198
+ index.search("engine").collect {|record| record.key.key})
199
+ end
200
+
201
+ def test_open_same_name
202
+ users_created = Groonga::Hash.create(:name => "Users")
203
+ users_opened = Groonga::Hash.open(:name => "Users")
204
+ users_opened.add("morita")
205
+ assert_equal(1, users_created.size)
206
+ end
207
+
208
+ def test_has_key?
209
+ users = Groonga::Hash.create(:name => "Users")
210
+ assert_false(users.has_key?("morita"))
211
+ users.add("morita")
212
+ assert_true(users.has_key?("morita"))
213
+ end
214
+
215
+ def test_big_key
216
+ hash = Groonga::Hash.create(:key_type => "UInt64")
217
+ assert_nothing_raised do
218
+ hash.add(1 << 63)
219
+ end
220
+ end
221
+
222
+ def test_value_by_key
223
+ users = Groonga::Hash.create(:key_type => "ShortText",
224
+ :value_type => "Int32")
225
+ key = "niku"
226
+ users.add(key)
227
+ users.set_value(key, 29)
228
+ assert_equal(29, users.value(key))
229
+ end
230
+
231
+ def test_value_by_id
232
+ users = Groonga::Hash.create(:key_type => "ShortText",
233
+ :value_type => "Int32")
234
+ user_id = users.add("niku").id
235
+ users.set_value(user_id, 29, :id => true)
236
+ assert_equal(29, users.value(user_id, :id => true))
237
+ end
238
+
239
+ def test_id
240
+ users = Groonga::Hash.create(:key_type => "ShortText")
241
+
242
+ key = "niku"
243
+ assert_nil(users.id(key))
244
+ user_id = users.add(key).id
245
+ assert_equal(user_id, users.id(key))
246
+ end
247
+
248
+ def test_set_multi_values
249
+ users = Groonga::Hash.create(:name => "Users",
250
+ :key_type => "ShortText")
251
+ users.define_column("self_introduction", "ShortText")
252
+ users.define_column("age", "UInt32")
253
+
254
+ key = "niku"
255
+ niku = users.add(key)
256
+ assert_equal({
257
+ "id" => niku.id,
258
+ "key" => key,
259
+ "self_introduction" => nil,
260
+ "age" => 0,
261
+ },
262
+ niku.attributes)
263
+ users[key] = {
264
+ "self_introduction" => "I'm a meet lover.",
265
+ "age" => 29
266
+ }
267
+ assert_equal({
268
+ "id" => niku.id,
269
+ "key" => key,
270
+ "self_introduction" => "I'm a meet lover.",
271
+ "age" => 29,
272
+ },
273
+ niku.attributes)
274
+ end
275
+
276
+ def test_set_multi_values_for_nonexistent_record
277
+ users = Groonga::Hash.create(:name => "Users",
278
+ :key_type => "ShortText")
279
+ users.define_column("self_introduction", "ShortText")
280
+ users.define_column("age", "UInt32")
281
+
282
+ key = "niku"
283
+ users[key] = {
284
+ "self_introduction" => "I'm a meet lover.",
285
+ "age" => 29
286
+ }
287
+
288
+ assert_equal({
289
+ "id" => users[key].id,
290
+ "key" => key,
291
+ "self_introduction" => "I'm a meet lover.",
292
+ "age" => 29,
293
+ },
294
+ users[key].attributes)
295
+ end
296
+
297
+ def test_set_multi_values_with_nonexistent_column
298
+ users = Groonga::Hash.create(:name => "Users",
299
+ :key_type => "ShortText")
300
+ users.define_column("self_introduction", "ShortText")
301
+ users.define_column("age", "UInt32")
302
+
303
+ key = "niku"
304
+ inspected_users = users.inspect.sub(/size: <0>/, "size: <1>")
305
+ message = "no such column: <\"nonexistent\">: <#{inspected_users}>"
306
+ assert_raise(Groonga::NoSuchColumn.new(message)) do
307
+ users[key] = {
308
+ "nonexistent" => "No!",
309
+ }
310
+ end
311
+ end
312
+ end