rroonga 0.9.2-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) 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 +206 -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 +230 -0
  13. data/example/search/public/css/groonga.css +122 -0
  14. data/ext/.gitignore +2 -0
  15. data/ext/groonga/extconf.rb +93 -0
  16. data/ext/groonga/rb-grn-accessor.c +52 -0
  17. data/ext/groonga/rb-grn-array-cursor.c +36 -0
  18. data/ext/groonga/rb-grn-array.c +210 -0
  19. data/ext/groonga/rb-grn-column.c +573 -0
  20. data/ext/groonga/rb-grn-context.c +662 -0
  21. data/ext/groonga/rb-grn-database.c +472 -0
  22. data/ext/groonga/rb-grn-encoding-support.c +64 -0
  23. data/ext/groonga/rb-grn-encoding.c +257 -0
  24. data/ext/groonga/rb-grn-exception.c +1110 -0
  25. data/ext/groonga/rb-grn-expression-builder.c +75 -0
  26. data/ext/groonga/rb-grn-expression.c +731 -0
  27. data/ext/groonga/rb-grn-fix-size-column.c +166 -0
  28. data/ext/groonga/rb-grn-hash-cursor.c +38 -0
  29. data/ext/groonga/rb-grn-hash.c +294 -0
  30. data/ext/groonga/rb-grn-index-column.c +488 -0
  31. data/ext/groonga/rb-grn-logger.c +504 -0
  32. data/ext/groonga/rb-grn-object.c +1369 -0
  33. data/ext/groonga/rb-grn-operation.c +198 -0
  34. data/ext/groonga/rb-grn-patricia-trie-cursor.c +39 -0
  35. data/ext/groonga/rb-grn-patricia-trie.c +488 -0
  36. data/ext/groonga/rb-grn-procedure.c +52 -0
  37. data/ext/groonga/rb-grn-query.c +260 -0
  38. data/ext/groonga/rb-grn-record.c +40 -0
  39. data/ext/groonga/rb-grn-snippet.c +334 -0
  40. data/ext/groonga/rb-grn-table-cursor-key-support.c +69 -0
  41. data/ext/groonga/rb-grn-table-cursor.c +247 -0
  42. data/ext/groonga/rb-grn-table-key-support.c +714 -0
  43. data/ext/groonga/rb-grn-table.c +1977 -0
  44. data/ext/groonga/rb-grn-type.c +181 -0
  45. data/ext/groonga/rb-grn-utils.c +769 -0
  46. data/ext/groonga/rb-grn-variable-size-column.c +36 -0
  47. data/ext/groonga/rb-grn-variable.c +108 -0
  48. data/ext/groonga/rb-grn-view-accessor.c +53 -0
  49. data/ext/groonga/rb-grn-view-cursor.c +35 -0
  50. data/ext/groonga/rb-grn-view-record.c +41 -0
  51. data/ext/groonga/rb-grn-view.c +421 -0
  52. data/ext/groonga/rb-grn.h +698 -0
  53. data/ext/groonga/rb-groonga.c +107 -0
  54. data/extconf.rb +130 -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/1.8/groonga.so +0 -0
  70. data/lib/1.9/groonga.so +0 -0
  71. data/lib/groonga.rb +90 -0
  72. data/lib/groonga/context.rb +184 -0
  73. data/lib/groonga/expression-builder.rb +324 -0
  74. data/lib/groonga/patricia-trie.rb +85 -0
  75. data/lib/groonga/record.rb +311 -0
  76. data/lib/groonga/schema.rb +1191 -0
  77. data/lib/groonga/view-record.rb +56 -0
  78. data/license/GPL +340 -0
  79. data/license/LGPL +504 -0
  80. data/license/RUBY +59 -0
  81. data/misc/grnop2ruby.rb +49 -0
  82. data/pkg-config.rb +333 -0
  83. data/rroonga-build.rb +57 -0
  84. data/test-unit/Rakefile +40 -0
  85. data/test-unit/TODO +5 -0
  86. data/test-unit/bin/testrb +5 -0
  87. data/test-unit/html/classic.html +15 -0
  88. data/test-unit/html/index.html +25 -0
  89. data/test-unit/html/index.html.ja +27 -0
  90. data/test-unit/lib/test/unit.rb +323 -0
  91. data/test-unit/lib/test/unit/assertionfailederror.rb +25 -0
  92. data/test-unit/lib/test/unit/assertions.rb +1230 -0
  93. data/test-unit/lib/test/unit/attribute.rb +125 -0
  94. data/test-unit/lib/test/unit/autorunner.rb +360 -0
  95. data/test-unit/lib/test/unit/collector.rb +36 -0
  96. data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
  97. data/test-unit/lib/test/unit/collector/dir.rb +108 -0
  98. data/test-unit/lib/test/unit/collector/load.rb +144 -0
  99. data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
  100. data/test-unit/lib/test/unit/color-scheme.rb +102 -0
  101. data/test-unit/lib/test/unit/color.rb +96 -0
  102. data/test-unit/lib/test/unit/diff.rb +724 -0
  103. data/test-unit/lib/test/unit/error.rb +130 -0
  104. data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
  105. data/test-unit/lib/test/unit/failure.rb +136 -0
  106. data/test-unit/lib/test/unit/fixture.rb +176 -0
  107. data/test-unit/lib/test/unit/notification.rb +129 -0
  108. data/test-unit/lib/test/unit/omission.rb +191 -0
  109. data/test-unit/lib/test/unit/pending.rb +150 -0
  110. data/test-unit/lib/test/unit/priority.rb +180 -0
  111. data/test-unit/lib/test/unit/runner/console.rb +52 -0
  112. data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
  113. data/test-unit/lib/test/unit/runner/tap.rb +8 -0
  114. data/test-unit/lib/test/unit/testcase.rb +476 -0
  115. data/test-unit/lib/test/unit/testresult.rb +89 -0
  116. data/test-unit/lib/test/unit/testsuite.rb +110 -0
  117. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
  118. data/test-unit/lib/test/unit/ui/console/testrunner.rb +466 -0
  119. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +63 -0
  120. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +92 -0
  121. data/test-unit/lib/test/unit/ui/testrunner.rb +28 -0
  122. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
  123. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
  124. data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
  125. data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
  126. data/test-unit/lib/test/unit/util/observable.rb +90 -0
  127. data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
  128. data/test-unit/lib/test/unit/version.rb +7 -0
  129. data/test-unit/sample/adder.rb +13 -0
  130. data/test-unit/sample/subtracter.rb +12 -0
  131. data/test-unit/sample/test_adder.rb +20 -0
  132. data/test-unit/sample/test_subtracter.rb +20 -0
  133. data/test-unit/sample/test_user.rb +23 -0
  134. data/test-unit/test/collector/test-descendant.rb +133 -0
  135. data/test-unit/test/collector/test-load.rb +442 -0
  136. data/test-unit/test/collector/test_dir.rb +406 -0
  137. data/test-unit/test/collector/test_objectspace.rb +100 -0
  138. data/test-unit/test/run-test.rb +15 -0
  139. data/test-unit/test/test-attribute.rb +86 -0
  140. data/test-unit/test/test-color-scheme.rb +67 -0
  141. data/test-unit/test/test-color.rb +47 -0
  142. data/test-unit/test/test-diff.rb +518 -0
  143. data/test-unit/test/test-emacs-runner.rb +60 -0
  144. data/test-unit/test/test-fixture.rb +287 -0
  145. data/test-unit/test/test-notification.rb +33 -0
  146. data/test-unit/test/test-omission.rb +81 -0
  147. data/test-unit/test/test-pending.rb +70 -0
  148. data/test-unit/test/test-priority.rb +119 -0
  149. data/test-unit/test/test-testcase.rb +544 -0
  150. data/test-unit/test/test_assertions.rb +1151 -0
  151. data/test-unit/test/test_error.rb +26 -0
  152. data/test-unit/test/test_failure.rb +33 -0
  153. data/test-unit/test/test_testresult.rb +113 -0
  154. data/test-unit/test/test_testsuite.rb +129 -0
  155. data/test-unit/test/testunit-test-util.rb +14 -0
  156. data/test-unit/test/ui/test_testrunmediator.rb +20 -0
  157. data/test-unit/test/util/test-method-owner-finder.rb +38 -0
  158. data/test-unit/test/util/test_backtracefilter.rb +41 -0
  159. data/test-unit/test/util/test_observable.rb +102 -0
  160. data/test-unit/test/util/test_procwrapper.rb +36 -0
  161. data/test/.gitignore +1 -0
  162. data/test/groonga-test-utils.rb +134 -0
  163. data/test/run-test.rb +58 -0
  164. data/test/test-array.rb +90 -0
  165. data/test/test-column.rb +316 -0
  166. data/test/test-context-select.rb +93 -0
  167. data/test/test-context.rb +73 -0
  168. data/test/test-database.rb +113 -0
  169. data/test/test-encoding.rb +33 -0
  170. data/test/test-exception.rb +93 -0
  171. data/test/test-expression-builder.rb +217 -0
  172. data/test/test-expression.rb +134 -0
  173. data/test/test-fix-size-column.rb +65 -0
  174. data/test/test-gqtp.rb +72 -0
  175. data/test/test-hash.rb +305 -0
  176. data/test/test-index-column.rb +81 -0
  177. data/test/test-logger.rb +37 -0
  178. data/test/test-patricia-trie.rb +205 -0
  179. data/test/test-procedure.rb +37 -0
  180. data/test/test-query.rb +22 -0
  181. data/test/test-record.rb +243 -0
  182. data/test/test-remote.rb +54 -0
  183. data/test/test-schema-view.rb +90 -0
  184. data/test/test-schema.rb +459 -0
  185. data/test/test-snippet.rb +130 -0
  186. data/test/test-table-cursor.rb +153 -0
  187. data/test/test-table-offset-and-limit.rb +102 -0
  188. data/test/test-table-select-normalize.rb +53 -0
  189. data/test/test-table-select.rb +150 -0
  190. data/test/test-table.rb +594 -0
  191. data/test/test-type.rb +71 -0
  192. data/test/test-variable-size-column.rb +98 -0
  193. data/test/test-variable.rb +28 -0
  194. data/test/test-vector-column.rb +76 -0
  195. data/test/test-version.rb +31 -0
  196. data/test/test-view.rb +72 -0
  197. data/text/TUTORIAL.ja.rdoc +392 -0
  198. data/text/expression.rdoc +284 -0
  199. metadata +276 -0
@@ -0,0 +1,54 @@
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 RemoteTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ setup :before => :append
20
+ def setup_remote_connection
21
+ @process_id = nil
22
+
23
+ package_config = PKGConfig.package_config("groonga")
24
+ groonga = package_config.variable("groonga")
25
+
26
+ @host = "127.0.0.1"
27
+ @port = 12345
28
+ @remote_database_path = @tmp_dir + "remote-database"
29
+ @process_id = Process.fork do
30
+ exec(groonga,
31
+ "-i", @host,
32
+ "-p", @port.to_s,
33
+ "-s", "-n", @remote_database_path.to_s)
34
+ end
35
+ sleep(1)
36
+ end
37
+
38
+ teardown
39
+ def teardown_remote_connection
40
+ Process.kill(:TERM, @process_id) if @process_id
41
+ end
42
+
43
+ def test_send
44
+ _context = Groonga::Context.new
45
+ _context.connect(:host => @host, :port => @port)
46
+ assert_equal(0, _context.send("status"))
47
+ id, result = _context.receive
48
+ assert_equal(0, id)
49
+ status, values = JSON.load(result)
50
+ return_code, start_time, elapsed, = status
51
+ assert_equal([0, ["alloc_count", "starttime", "uptime", "version"]],
52
+ [return_code, values.keys.sort])
53
+ end
54
+ end
@@ -0,0 +1,90 @@
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 SchemaViewTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ setup :setup_database
20
+
21
+ def test_create_view
22
+ assert_nil(context["Entries"])
23
+ Groonga::Schema.create_view("Entries") do |view|
24
+ end
25
+ assert_not_nil(context["Entries"])
26
+ end
27
+
28
+ def test_create_view_force
29
+ Groonga::Schema.create_table("People") do |table|
30
+ table.string("name")
31
+ end
32
+ context["People"].add(:name => "morita")
33
+
34
+ Groonga::Schema.create_view("Entries") do |view|
35
+ view.add("People")
36
+ end
37
+ assert_equal(["morita"],
38
+ context["Entries"].collect {|entry| entry["name"]})
39
+
40
+ Groonga::Schema.create_view("People") do |view|
41
+ end
42
+ assert_equal(["morita"],
43
+ context["Entries"].collect {|entry| entry["name"]})
44
+
45
+ Groonga::Schema.create_view("Entries", :force => true) do |view|
46
+ end
47
+ assert_equal([],
48
+ context["Entries"].collect {|entry| entry["name"]})
49
+ end
50
+
51
+ def test_remove_view
52
+ Groonga::View.create(:name => "Entries")
53
+ assert_not_nil(context["Entries"])
54
+ Groonga::Schema.remove_view("Entries")
55
+ assert_nil(context["Entries"])
56
+ end
57
+
58
+ def test_add
59
+ Groonga::Schema.create_table("People") do |table|
60
+ table.string("name")
61
+ end
62
+ context["People"].add(:name => "morita")
63
+
64
+ Groonga::Schema.create_table("Dogs") do |table|
65
+ table.string("name")
66
+ end
67
+ context["Dogs"].add(:name => "pochi")
68
+
69
+ Groonga::Schema.create_view("Entries") do |view|
70
+ view.add("People")
71
+ view.add("Dogs")
72
+ end
73
+ assert_equal(["morita", "pochi"],
74
+ context["Entries"].collect {|entry| entry["name"]})
75
+ end
76
+
77
+ def test_define_lazy
78
+ assert_nothing_raised do
79
+ Groonga::Schema.define do |schema|
80
+ schema.create_table("People") do |table|
81
+ table.string("name")
82
+ end
83
+
84
+ schema.create_view("Entries") do |view|
85
+ view.add("People")
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,459 @@
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 SchemaTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ setup :setup_database
20
+
21
+ def test_create_table
22
+ assert_nil(context["Posts"])
23
+ Groonga::Schema.create_table("Posts") do |table|
24
+ end
25
+ assert_not_nil(context["Posts"])
26
+ end
27
+
28
+ def test_create_table_force
29
+ Groonga::Schema.create_table("Posts") do |table|
30
+ table.string("name")
31
+ end
32
+ assert_not_nil(context["Posts.name"])
33
+
34
+ Groonga::Schema.create_table("Posts") do |table|
35
+ end
36
+ assert_not_nil(context["Posts.name"])
37
+
38
+ Groonga::Schema.create_table("Posts", :force => true) do |table|
39
+ end
40
+ assert_nil(context["Posts.name"])
41
+ end
42
+
43
+ def test_remove_table
44
+ Groonga::Array.create(:name => "Posts")
45
+ assert_not_nil(context["Posts"])
46
+ Groonga::Schema.remove_table("Posts")
47
+ assert_nil(context["Posts"])
48
+ end
49
+
50
+ def test_define_hash
51
+ Groonga::Schema.create_table("Posts", :type => :hash) do |table|
52
+ end
53
+ assert_kind_of(Groonga::Hash, context["Posts"])
54
+ end
55
+
56
+ def test_define_hash_with_full_option
57
+ path = @tmp_dir + "hash.groonga"
58
+ tokenizer = context["TokenTrigram"]
59
+ Groonga::Schema.create_table("Posts",
60
+ :type => :hash,
61
+ :key_type => "integer",
62
+ :path => path.to_s,
63
+ :value_type => "UInt32",
64
+ :default_tokenizer => tokenizer) do |table|
65
+ end
66
+ table = context["Posts"]
67
+ assert_equal("#<Groonga::Hash " +
68
+ "id: <#{table.id}>, " +
69
+ "name: <Posts>, " +
70
+ "path: <#{path}>, " +
71
+ "domain: <Int32>, " +
72
+ "range: <UInt32>, " +
73
+ "flags: <>, " +
74
+ "encoding: <#{Groonga::Encoding.default.inspect}>, " +
75
+ "size: <0>>",
76
+ table.inspect)
77
+ assert_equal(tokenizer, table.default_tokenizer)
78
+ end
79
+
80
+ def test_define_patricia_trie
81
+ Groonga::Schema.create_table("Posts", :type => :patricia_trie) do |table|
82
+ end
83
+ assert_kind_of(Groonga::PatriciaTrie, context["Posts"])
84
+ end
85
+
86
+ def test_define_patricia_trie_with_full_option
87
+ path = @tmp_dir + "patricia-trie.groonga"
88
+ Groonga::Schema.create_table("Posts",
89
+ :type => :patricia_trie,
90
+ :key_type => "integer",
91
+ :path => path.to_s,
92
+ :value_type => "Float",
93
+ :default_tokenizer => "TokenBigram",
94
+ :key_normalize => true,
95
+ :key_with_sis => true) do |table|
96
+ end
97
+ table = context["Posts"]
98
+ assert_equal("#<Groonga::PatriciaTrie " +
99
+ "id: <#{table.id}>, " +
100
+ "name: <Posts>, " +
101
+ "path: <#{path}>, " +
102
+ "domain: <Int32>, " +
103
+ "range: <Float>, " +
104
+ "flags: <KEY_WITH_SIS|KEY_NORMALIZE|WITH_SECTION>, " +
105
+ "encoding: <#{Groonga::Encoding.default.inspect}>, " +
106
+ "size: <0>>",
107
+ table.inspect)
108
+ assert_equal(context["TokenBigram"], table.default_tokenizer)
109
+ end
110
+
111
+ def test_define_array
112
+ Groonga::Schema.create_table("Posts", :type => :array) do |table|
113
+ end
114
+ assert_kind_of(Groonga::Array, context["Posts"])
115
+ end
116
+
117
+ def test_define_array_with_full_option
118
+ path = @tmp_dir + "array.groonga"
119
+ Groonga::Schema.create_table("Posts",
120
+ :type => :array,
121
+ :path => path.to_s,
122
+ :value_type => "Int32") do |table|
123
+ end
124
+ table = context["Posts"]
125
+ assert_equal("#<Groonga::Array " +
126
+ "id: <#{table.id}>, " +
127
+ "name: <Posts>, " +
128
+ "path: <#{path}>, " +
129
+ "domain: <Int32>, " +
130
+ "range: <Int32>, " +
131
+ "flags: <>, " +
132
+ "size: <0>>",
133
+ table.inspect)
134
+ end
135
+
136
+ def test_column_with_full_option
137
+ path = @tmp_dir + "column.groonga"
138
+ type = Groonga::Type.new("Niku", :size => 29)
139
+ Groonga::Schema.create_table("Posts") do |table|
140
+ table.column("rate",
141
+ type,
142
+ :path => path.to_s,
143
+ :persistent => true,
144
+ :type => :vector,
145
+ :compress => :lzo)
146
+ end
147
+
148
+ column_name = "Posts.rate"
149
+ column = context[column_name]
150
+ assert_equal("#<Groonga::VariableSizeColumn " +
151
+ "id: <#{column.id}>, " +
152
+ "name: <#{column_name}>, " +
153
+ "path: <#{path}>, " +
154
+ "domain: <Posts>, " +
155
+ "range: <Niku>, " +
156
+ "flags: <COMPRESS_LZO>>",
157
+ column.inspect)
158
+ end
159
+
160
+ def test_integer32_column
161
+ assert_nil(context["Posts.rate"])
162
+ Groonga::Schema.create_table("Posts") do |table|
163
+ table.integer32 :rate
164
+ end
165
+ assert_equal(context["Int32"], context["Posts.rate"].range)
166
+ end
167
+
168
+ def test_integer64_column
169
+ assert_nil(context["Posts.rate"])
170
+ Groonga::Schema.create_table("Posts") do |table|
171
+ table.integer64 :rate
172
+ end
173
+ assert_equal(context["Int64"], context["Posts.rate"].range)
174
+ end
175
+
176
+ def test_unsigned_integer32_column
177
+ assert_nil(context["Posts.n_viewed"])
178
+ Groonga::Schema.create_table("Posts") do |table|
179
+ table.unsigned_integer32 :n_viewed
180
+ end
181
+ assert_equal(context["UInt32"], context["Posts.n_viewed"].range)
182
+ end
183
+
184
+ def test_unsigned_integer64_column
185
+ assert_nil(context["Posts.n_viewed"])
186
+ Groonga::Schema.create_table("Posts") do |table|
187
+ table.unsigned_integer64 :n_viewed
188
+ end
189
+ assert_equal(context["UInt64"], context["Posts.n_viewed"].range)
190
+ end
191
+
192
+ def test_float_column
193
+ assert_nil(context["Posts.rate"])
194
+ Groonga::Schema.create_table("Posts") do |table|
195
+ table.float :rate
196
+ end
197
+ assert_equal(context["Float"], context["Posts.rate"].range)
198
+ end
199
+
200
+ def test_time_column
201
+ assert_nil(context["Posts.last_modified"])
202
+ Groonga::Schema.create_table("Posts") do |table|
203
+ table.time :last_modified
204
+ end
205
+ assert_equal(context["Time"], context["Posts.last_modified"].range)
206
+ end
207
+
208
+ def test_short_text_column
209
+ assert_nil(context["Posts.title"])
210
+ Groonga::Schema.create_table("Posts") do |table|
211
+ table.short_text :title
212
+ end
213
+ assert_equal(context["ShortText"], context["Posts.title"].range)
214
+ end
215
+
216
+ def test_text_column
217
+ assert_nil(context["Posts.comment"])
218
+ Groonga::Schema.create_table("Posts") do |table|
219
+ table.text :comment
220
+ end
221
+ assert_equal(context["Text"], context["Posts.comment"].range)
222
+ end
223
+
224
+ def test_long_text_column
225
+ assert_nil(context["Posts.content"])
226
+ Groonga::Schema.create_table("Posts") do |table|
227
+ table.long_text :content
228
+ end
229
+ assert_equal(context["LongText"], context["Posts.content"].range)
230
+ end
231
+
232
+ def test_boolean_column
233
+ assert_nil(context["Posts.public"])
234
+ Groonga::Schema.create_table("Posts") do |table|
235
+ table.boolean :public
236
+ end
237
+ assert_equal(context["Bool"], context["Posts.public"].range)
238
+ end
239
+
240
+ def test_remove_column
241
+ Groonga::Schema.create_table("Posts") do |table|
242
+ table.long_text :content
243
+ end
244
+ assert_not_nil(context["Posts.content"])
245
+
246
+ Groonga::Schema.change_table("Posts") do |table|
247
+ table.remove_column("content")
248
+ end
249
+ assert_nil(context["Posts.content"])
250
+ end
251
+
252
+ def test_column_again
253
+ Groonga::Schema.create_table("Posts") do |table|
254
+ table.text :content
255
+ end
256
+
257
+ assert_nothing_raised do
258
+ Groonga::Schema.create_table("Posts") do |table|
259
+ table.text :content
260
+ end
261
+ end
262
+ end
263
+
264
+ def test_column_again_with_difference_type
265
+ Groonga::Schema.create_table("Posts") do |table|
266
+ table.text :content
267
+ end
268
+
269
+ assert_raise(ArgumentError) do
270
+ Groonga::Schema.create_table("Posts") do |table|
271
+ table.integer :content
272
+ end
273
+ end
274
+ end
275
+
276
+ def test_index
277
+ assert_nil(context["Terms.content"])
278
+ Groonga::Schema.create_table("Posts") do |table|
279
+ table.long_text :content
280
+ end
281
+ Groonga::Schema.create_table("Terms") do |table|
282
+ table.index "Posts.content"
283
+ end
284
+ assert_equal([context["Posts.content"]],
285
+ context["Terms.Posts_content"].sources)
286
+ end
287
+
288
+ def test_index_with_full_option
289
+ path = @tmp_dir + "index-column.groonga"
290
+ assert_nil(context["Terms.content"])
291
+ index_column_name = "Posts_index"
292
+
293
+ Groonga::Schema.create_table("Posts") do |table|
294
+ table.long_text :content
295
+ end
296
+ Groonga::Schema.create_table("Terms") do |table|
297
+ table.index("Posts.content",
298
+ :name => index_column_name,
299
+ :path => path.to_s,
300
+ :persistent => true,
301
+ :with_section => true,
302
+ :with_weight => true,
303
+ :with_position => true)
304
+ end
305
+
306
+ posts = context["Posts"]
307
+ terms = context["Terms"]
308
+ full_index_column_name = "Terms.#{index_column_name}"
309
+ index_column = context[full_index_column_name]
310
+ assert_equal("#<Groonga::IndexColumn " +
311
+ "id: <#{index_column.id}>, " +
312
+ "name: <#{full_index_column_name}>, " +
313
+ "path: <#{path}>, " +
314
+ "domain: <Terms>, " +
315
+ "range: <Posts>, " +
316
+ "flags: <WITH_SECTION|WITH_WEIGHT|WITH_POSITION>>",
317
+ index_column.inspect)
318
+ end
319
+
320
+ def test_index_again
321
+ Groonga::Schema.create_table("Posts") do |table|
322
+ table.long_text :content
323
+ end
324
+ Groonga::Schema.create_table("Terms") do |table|
325
+ table.index "Posts.content"
326
+ end
327
+
328
+ assert_nothing_raised do
329
+ Groonga::Schema.create_table("Terms") do |table|
330
+ table.index "Posts.content"
331
+ end
332
+ end
333
+ end
334
+
335
+ def test_index_again_with_difference_source
336
+ Groonga::Schema.create_table("Posts") do |table|
337
+ table.long_text :content
338
+ table.short_text :name
339
+ end
340
+ Groonga::Schema.create_table("Terms") do |table|
341
+ table.index "Posts.content"
342
+ end
343
+
344
+ assert_raise(ArgumentError) do
345
+ Groonga::Schema.create_table("Terms") do |table|
346
+ table.index "Posts.name", :name => "Posts_content"
347
+ end
348
+ end
349
+ end
350
+
351
+ def test_index_key
352
+ Groonga::Schema.create_table("Posts",
353
+ :type => :hash,
354
+ :key_type => "ShortText") do |table|
355
+ end
356
+ Groonga::Schema.create_table("Terms") do |table|
357
+ table.index "Posts._key", :with_position => true
358
+ end
359
+
360
+ full_index_column_name = "Terms.Posts__key"
361
+ index_column = context[full_index_column_name]
362
+ assert_equal("#<Groonga::IndexColumn " +
363
+ "id: <#{index_column.id}>, " +
364
+ "name: <#{full_index_column_name}>, " +
365
+ "path: <#{index_column.path}>, " +
366
+ "domain: <Terms>, " +
367
+ "range: <Posts>, " +
368
+ "flags: <WITH_POSITION>>",
369
+ index_column.inspect)
370
+ end
371
+
372
+ def test_index_key_again
373
+ Groonga::Schema.create_table("Posts",
374
+ :type => :hash,
375
+ :key_type => "ShortText") do |table|
376
+ end
377
+ Groonga::Schema.create_table("Terms") do |table|
378
+ table.index "Posts._key", :with_position => true
379
+ end
380
+
381
+ assert_nothing_raised do
382
+ Groonga::Schema.create_table("Terms") do |table|
383
+ table.index "Posts._key"
384
+ end
385
+ end
386
+ end
387
+
388
+ def test_dump
389
+ Groonga::Schema.define do |schema|
390
+ schema.create_table("Posts") do |table|
391
+ table.short_text :title
392
+ end
393
+ end
394
+ assert_equal(<<-EOS, Groonga::Schema.dump)
395
+ create_table("Posts") do |table|
396
+ table.short_text("title")
397
+ end
398
+ EOS
399
+ end
400
+
401
+ def test_reference_dump
402
+ Groonga::Schema.define do |schema|
403
+ schema.create_table("Items") do |table|
404
+ table.short_text("title")
405
+ end
406
+
407
+ schema.create_table("Users") do |table|
408
+ table.short_text("name")
409
+ end
410
+
411
+ schema.create_table("Comments") do |table|
412
+ table.reference("item", "Items")
413
+ table.reference("author", "Users")
414
+ table.text("content")
415
+ table.time("issued")
416
+ end
417
+ end
418
+
419
+ assert_equal(<<-EOS, Groonga::Schema.dump)
420
+ create_table("Comments") do |table|
421
+ table.text("content")
422
+ table.time("issued")
423
+ end
424
+
425
+ create_table("Items") do |table|
426
+ table.short_text("title")
427
+ end
428
+
429
+ create_table("Users") do |table|
430
+ table.short_text("name")
431
+ end
432
+
433
+ change_table("Comments") do |table|
434
+ table.reference("author", "Users")
435
+ table.reference("item", "Items")
436
+ end
437
+ EOS
438
+ end
439
+
440
+ def test_explicit_context_create_table
441
+ context = Groonga::Context.default
442
+ Groonga::Context.default = nil
443
+
444
+ Groonga::Schema.define(:context => context) do |schema|
445
+ schema.create_table('Items', :type => :hash) do |table|
446
+ table.text("text")
447
+ end
448
+ schema.create_table("TermsText",
449
+ :type => :patricia_trie,
450
+ :key_normalize => true,
451
+ :default_tokenizer => "TokenBigram") do |table|
452
+ table.index('Items.text')
453
+ end
454
+ end
455
+
456
+ assert_not_nil(context["Items.text"])
457
+ assert_not_nil(context["TermsText.Items_text"])
458
+ end
459
+ end