groonga 0.0.1

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.
Files changed (148) hide show
  1. data/AUTHORS +1 -0
  2. data/NEWS.ja.rdoc +5 -0
  3. data/NEWS.rdoc +5 -0
  4. data/README.ja.rdoc +53 -0
  5. data/README.rdoc +54 -0
  6. data/Rakefile +209 -0
  7. data/TUTORIAL.ja.rdoc +160 -0
  8. data/benchmark/small-many-items.rb +175 -0
  9. data/example/bookmark.rb +38 -0
  10. data/ext/.gitignore +2 -0
  11. data/ext/rb-grn-accessor.c +52 -0
  12. data/ext/rb-grn-array-cursor.c +28 -0
  13. data/ext/rb-grn-array.c +168 -0
  14. data/ext/rb-grn-column.c +273 -0
  15. data/ext/rb-grn-context.c +333 -0
  16. data/ext/rb-grn-database.c +128 -0
  17. data/ext/rb-grn-encoding.c +163 -0
  18. data/ext/rb-grn-exception.c +1014 -0
  19. data/ext/rb-grn-hash-cursor.c +30 -0
  20. data/ext/rb-grn-hash.c +40 -0
  21. data/ext/rb-grn-logger.c +277 -0
  22. data/ext/rb-grn-object.c +985 -0
  23. data/ext/rb-grn-patricia-trie-cursor.c +30 -0
  24. data/ext/rb-grn-patricia-trie.c +40 -0
  25. data/ext/rb-grn-procedure.c +52 -0
  26. data/ext/rb-grn-query.c +207 -0
  27. data/ext/rb-grn-record.c +33 -0
  28. data/ext/rb-grn-snippet.c +274 -0
  29. data/ext/rb-grn-table-cursor-key-support.c +55 -0
  30. data/ext/rb-grn-table-cursor.c +294 -0
  31. data/ext/rb-grn-table-key-support.c +299 -0
  32. data/ext/rb-grn-table.c +706 -0
  33. data/ext/rb-grn-type.c +114 -0
  34. data/ext/rb-grn-utils.c +578 -0
  35. data/ext/rb-grn.h +346 -0
  36. data/ext/rb-groonga.c +98 -0
  37. data/extconf.rb +171 -0
  38. data/html/bar.svg +153 -0
  39. data/html/developer.html +121 -0
  40. data/html/developer.svg +469 -0
  41. data/html/download.svg +253 -0
  42. data/html/footer.html.erb +28 -0
  43. data/html/head.html.erb +4 -0
  44. data/html/header.html.erb +17 -0
  45. data/html/index.html +153 -0
  46. data/html/install.svg +636 -0
  47. data/html/logo.xcf +0 -0
  48. data/html/ranguba.css +248 -0
  49. data/html/tutorial.svg +559 -0
  50. data/lib/groonga.rb +50 -0
  51. data/lib/groonga/record.rb +98 -0
  52. data/license/GPL +340 -0
  53. data/license/LGPL +504 -0
  54. data/license/RUBY +59 -0
  55. data/pkg-config.rb +328 -0
  56. data/test-unit/Rakefile +35 -0
  57. data/test-unit/TODO +5 -0
  58. data/test-unit/bin/testrb +5 -0
  59. data/test-unit/html/classic.html +15 -0
  60. data/test-unit/html/index.html +25 -0
  61. data/test-unit/html/index.html.ja +27 -0
  62. data/test-unit/lib/test/unit.rb +342 -0
  63. data/test-unit/lib/test/unit/assertionfailederror.rb +14 -0
  64. data/test-unit/lib/test/unit/assertions.rb +1149 -0
  65. data/test-unit/lib/test/unit/attribute.rb +125 -0
  66. data/test-unit/lib/test/unit/autorunner.rb +306 -0
  67. data/test-unit/lib/test/unit/collector.rb +43 -0
  68. data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
  69. data/test-unit/lib/test/unit/collector/dir.rb +108 -0
  70. data/test-unit/lib/test/unit/collector/load.rb +135 -0
  71. data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
  72. data/test-unit/lib/test/unit/color-scheme.rb +86 -0
  73. data/test-unit/lib/test/unit/color.rb +96 -0
  74. data/test-unit/lib/test/unit/diff.rb +538 -0
  75. data/test-unit/lib/test/unit/error.rb +124 -0
  76. data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
  77. data/test-unit/lib/test/unit/failure.rb +110 -0
  78. data/test-unit/lib/test/unit/fixture.rb +176 -0
  79. data/test-unit/lib/test/unit/notification.rb +125 -0
  80. data/test-unit/lib/test/unit/omission.rb +143 -0
  81. data/test-unit/lib/test/unit/pending.rb +146 -0
  82. data/test-unit/lib/test/unit/priority.rb +161 -0
  83. data/test-unit/lib/test/unit/runner/console.rb +52 -0
  84. data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
  85. data/test-unit/lib/test/unit/testcase.rb +360 -0
  86. data/test-unit/lib/test/unit/testresult.rb +89 -0
  87. data/test-unit/lib/test/unit/testsuite.rb +110 -0
  88. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
  89. data/test-unit/lib/test/unit/ui/console/testrunner.rb +220 -0
  90. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +49 -0
  91. data/test-unit/lib/test/unit/ui/testrunner.rb +20 -0
  92. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
  93. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
  94. data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
  95. data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
  96. data/test-unit/lib/test/unit/util/observable.rb +90 -0
  97. data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
  98. data/test-unit/lib/test/unit/version.rb +7 -0
  99. data/test-unit/sample/adder.rb +13 -0
  100. data/test-unit/sample/subtracter.rb +12 -0
  101. data/test-unit/sample/tc_adder.rb +18 -0
  102. data/test-unit/sample/tc_subtracter.rb +18 -0
  103. data/test-unit/sample/test_user.rb +22 -0
  104. data/test-unit/sample/ts_examples.rb +7 -0
  105. data/test-unit/test/collector/test-descendant.rb +135 -0
  106. data/test-unit/test/collector/test-load.rb +333 -0
  107. data/test-unit/test/collector/test_dir.rb +406 -0
  108. data/test-unit/test/collector/test_objectspace.rb +98 -0
  109. data/test-unit/test/run-test.rb +13 -0
  110. data/test-unit/test/test-attribute.rb +86 -0
  111. data/test-unit/test/test-color-scheme.rb +56 -0
  112. data/test-unit/test/test-color.rb +47 -0
  113. data/test-unit/test/test-diff.rb +477 -0
  114. data/test-unit/test/test-emacs-runner.rb +60 -0
  115. data/test-unit/test/test-fixture.rb +287 -0
  116. data/test-unit/test/test-notification.rb +33 -0
  117. data/test-unit/test/test-omission.rb +81 -0
  118. data/test-unit/test/test-pending.rb +70 -0
  119. data/test-unit/test/test-priority.rb +119 -0
  120. data/test-unit/test/test_assertions.rb +1082 -0
  121. data/test-unit/test/test_error.rb +26 -0
  122. data/test-unit/test/test_failure.rb +33 -0
  123. data/test-unit/test/test_testcase.rb +478 -0
  124. data/test-unit/test/test_testresult.rb +113 -0
  125. data/test-unit/test/test_testsuite.rb +129 -0
  126. data/test-unit/test/testunit-test-util.rb +14 -0
  127. data/test-unit/test/ui/test_testrunmediator.rb +20 -0
  128. data/test-unit/test/util/test-method-owner-finder.rb +38 -0
  129. data/test-unit/test/util/test_backtracefilter.rb +41 -0
  130. data/test-unit/test/util/test_observable.rb +102 -0
  131. data/test-unit/test/util/test_procwrapper.rb +36 -0
  132. data/test/.gitignore +1 -0
  133. data/test/groonga-test-utils.rb +90 -0
  134. data/test/run-test.rb +54 -0
  135. data/test/test-column.rb +190 -0
  136. data/test/test-context.rb +90 -0
  137. data/test/test-database.rb +62 -0
  138. data/test/test-encoding.rb +33 -0
  139. data/test/test-exception.rb +85 -0
  140. data/test/test-procedure.rb +35 -0
  141. data/test/test-query.rb +22 -0
  142. data/test/test-record.rb +188 -0
  143. data/test/test-snippet.rb +121 -0
  144. data/test/test-table-cursor.rb +51 -0
  145. data/test/test-table.rb +447 -0
  146. data/test/test-type.rb +52 -0
  147. data/test/test-version.rb +31 -0
  148. metadata +213 -0
@@ -0,0 +1,36 @@
1
+ # Author:: Nathaniel Talbott.
2
+ # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
3
+ # License:: Ruby license.
4
+
5
+ require 'test/unit'
6
+ require 'test/unit/util/procwrapper'
7
+
8
+ module Test
9
+ module Unit
10
+ module Util
11
+ class TC_ProcWrapper < TestCase
12
+ def munge_proc(&a_proc)
13
+ return a_proc
14
+ end
15
+ def setup
16
+ @original = proc {}
17
+ @munged = munge_proc(&@original)
18
+ @wrapped_original = ProcWrapper.new(@original)
19
+ @wrapped_munged = ProcWrapper.new(@munged)
20
+ end
21
+ def test_wrapping
22
+ assert_same(@original, @wrapped_original.to_proc, "The wrapper should return what was wrapped")
23
+ end
24
+ def test_hashing
25
+
26
+ assert_equal(@wrapped_original.hash, @wrapped_munged.hash, "The original and munged should have the same hash when wrapped")
27
+ assert_equal(@wrapped_original, @wrapped_munged, "The wrappers should be equivalent")
28
+
29
+ a_hash = {@wrapped_original => @original}
30
+ assert(a_hash[@wrapped_original], "Should be able to access the wrapper in the hash")
31
+ assert_equal(a_hash[@wrapped_original], @original, "Should be able to access the wrapper in the hash")
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
data/test/.gitignore ADDED
@@ -0,0 +1 @@
1
+ /.test-result
@@ -0,0 +1,90 @@
1
+ # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 2.1 as published by the Free Software Foundation.
6
+ #
7
+ # This library is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public
13
+ # License along with this library; if not, write to the Free Software
14
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
+
16
+ require 'fileutils'
17
+ require 'pathname'
18
+
19
+ require 'groonga'
20
+
21
+ module GroongaTestUtils
22
+ class << self
23
+ def included(base)
24
+ base.setup :setup_sandbox, :before => :prepend
25
+ base.teardown :teardown_sandbox, :after => :append
26
+ end
27
+ end
28
+
29
+ def setup_sandbox
30
+ setup_tmp_directory
31
+ setup_tables_directory
32
+ setup_columns_directory
33
+
34
+ setup_encoding
35
+ setup_context
36
+ end
37
+
38
+ def setup_tmp_directory
39
+ @tmp_dir = Pathname(File.dirname(__FILE__)) + "tmp"
40
+ FileUtils.rm_rf(@tmp_dir.to_s)
41
+ FileUtils.mkdir_p(@tmp_dir.to_s)
42
+ end
43
+
44
+ def setup_tables_directory
45
+ @tables_dir = @tmp_dir + "tables"
46
+ FileUtils.mkdir_p(@tables_dir.to_s)
47
+ end
48
+
49
+ def setup_columns_directory
50
+ @columns_dir = @tmp_dir + "columns"
51
+ FileUtils.mkdir_p(@columns_dir.to_s)
52
+ end
53
+
54
+ def setup_encoding
55
+ Groonga::Encoding.default = nil
56
+ end
57
+
58
+ def setup_context
59
+ Groonga::Context.default = nil
60
+ Groonga::Context.default_options = nil
61
+ end
62
+
63
+ def context
64
+ Groonga::Context.default
65
+ end
66
+
67
+ def encoding
68
+ Groonga::Encoding.default
69
+ end
70
+
71
+ def setup_logger
72
+ Groonga::Logger.register(:level => :dump) do |level, time, title, message, location|
73
+ p [level, time, title, message, location]
74
+ end
75
+ end
76
+
77
+ def setup_database
78
+ @database_path = @tmp_dir + "database"
79
+ @database = Groonga::Database.create(:path => @database_path.to_s)
80
+ end
81
+
82
+ def teardown_sandbox
83
+ teardown_tmp_directory
84
+ GC.start
85
+ end
86
+
87
+ def teardown_tmp_directory
88
+ FileUtils.rm_rf(@tmp_dir.to_s)
89
+ end
90
+ end
data/test/run-test.rb ADDED
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License version 2.1 as published by the Free Software Foundation.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+
18
+ $VERBOSE = true
19
+
20
+ $KCODE = "u" if RUBY_VERSION < "1.9"
21
+
22
+ base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
23
+ test_unit_dir = File.join(base_dir, "test-unit", "lib")
24
+ ext_dir = File.join(base_dir, "ext")
25
+ lib_dir = File.join(base_dir, "lib")
26
+ test_dir = File.join(base_dir, "test")
27
+
28
+ make = nil
29
+ if system("which gmake > /dev/null")
30
+ make = "gmake"
31
+ elsif system("which make > /dev/null")
32
+ make = "make"
33
+ end
34
+ if make
35
+ system("cd #{base_dir.dump} && #{make} > /dev/null") or exit(1)
36
+ end
37
+
38
+ $LOAD_PATH.unshift(test_unit_dir)
39
+
40
+ require 'test/unit'
41
+
42
+ ARGV.unshift("--priority-mode")
43
+
44
+ $LOAD_PATH.unshift(ext_dir)
45
+ $LOAD_PATH.unshift(lib_dir)
46
+
47
+ $LOAD_PATH.unshift(test_dir)
48
+ require 'groonga-test-utils'
49
+
50
+ Dir.glob("test/**/test{_,-}*.rb") do |file|
51
+ require file.sub(/\.rb$/, '')
52
+ end
53
+
54
+ exit Test::Unit::AutoRunner.run(false)
@@ -0,0 +1,190 @@
1
+ # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 2.1 as published by the Free Software Foundation.
6
+ #
7
+ # This library is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public
13
+ # License along with this library; if not, write to the Free Software
14
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
+
16
+ class ColumnTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ def setup
20
+ setup_database
21
+
22
+ setup_users_table
23
+ setup_bookmarks_table
24
+ setup_indexes
25
+ end
26
+
27
+ def setup_users_table
28
+ @users_path = @tables_dir + "users"
29
+ @users = Groonga::Array.create(:name => "users",
30
+ :path => @users_path.to_s)
31
+
32
+ @users_name_column_path = @columns_dir + "name"
33
+ @users_name_column =
34
+ @users.define_column("name", "<shorttext>",
35
+ :path => @users_name_column_path.to_s)
36
+ end
37
+
38
+ def setup_bookmarks_table
39
+ @bookmarks_path = @tables_dir + "bookmarks"
40
+ @bookmarks = Groonga::Array.create(:name => "bookmarks",
41
+ :path => @bookmarks_path.to_s)
42
+
43
+ @uri_column_path = @columns_dir + "uri"
44
+ @bookmarks_uri = @bookmarks.define_column("uri", "<shorttext>",
45
+ :path => @uri_column_path.to_s)
46
+
47
+ @comment_column_path = @columns_dir + "comment"
48
+ @bookmarks_comment =
49
+ @bookmarks.define_column("comment", "<text>",
50
+ :path => @comment_column_path.to_s)
51
+
52
+ @content_column_path = @columns_dir + "content"
53
+ @bookmarks_content = @bookmarks.define_column("content", "<longtext>")
54
+
55
+ @user_column_path = @columns_dir + "user"
56
+ @bookmarks_user = @bookmarks.define_column("user", @users)
57
+ end
58
+
59
+ def setup_indexes
60
+ @bookmarks_index_path = @tables_dir + "bookmarks-index"
61
+ @bookmarks_index =
62
+ Groonga::PatriciaTrie.create(:name => "bookmarks-index",
63
+ :path => @bookmarks_index_path.to_s,
64
+ :key_type => "<shorttext>")
65
+ @content_index_column_path = @columns_dir + "content-index"
66
+ @bookmarks_index_content =
67
+ @bookmarks_index.define_column("<index:content>", @bookmarks,
68
+ :type => "index",
69
+ :with_section => true,
70
+ :with_weight => true,
71
+ :with_position => true,
72
+ :path => @content_index_column_path.to_s)
73
+
74
+ @uri_index_column_path = @columns_dir + "uri-index"
75
+ @bookmarks_index_uri =
76
+ @bookmarks_index.define_column("<index:uri>", @bookmarks,
77
+ :type => "index",
78
+ :path => @uri_index_column_path.to_s)
79
+ end
80
+
81
+ def test_source_info
82
+ @bookmarks_index_content.sources = [@bookmarks_content]
83
+
84
+ groonga = @bookmarks.add
85
+ groonga["content"] = "<html><body>groonga</body></html>"
86
+
87
+ ruby = @bookmarks.add
88
+ ruby["content"] = "<html><body>ruby</body></html>"
89
+
90
+ assert_content_search([groonga], "groonga")
91
+ assert_content_search([groonga, ruby], "html")
92
+
93
+ assert_equal([@bookmarks_content], @bookmarks_index_content.sources)
94
+ end
95
+
96
+ def test_update_index_column
97
+ groonga = @bookmarks.add
98
+ groonga["content"] = "<html><body>groonga</body></html>"
99
+
100
+ ruby = @bookmarks.add
101
+ ruby["content"] = "<html><body>ruby</body></html>"
102
+
103
+ @bookmarks_index_content[groonga.id] = groonga["content"]
104
+ @bookmarks_index_content[ruby.id] = ruby["content"]
105
+
106
+ assert_content_search([groonga], "groonga")
107
+ assert_content_search([groonga, ruby], "html")
108
+ end
109
+
110
+ def test_range
111
+ assert_equal(context[Groonga::Type::SHORT_TEXT], @bookmarks_uri.range)
112
+ assert_equal(context[Groonga::Type::TEXT], @bookmarks_comment.range)
113
+ assert_equal(context[Groonga::Type::LONG_TEXT], @bookmarks_content.range)
114
+ assert_equal(@users, @bookmarks_user.range)
115
+ assert_equal(@bookmarks, @bookmarks_index_content.range)
116
+ assert_equal(@bookmarks, @bookmarks_index_uri.range)
117
+ end
118
+
119
+ def test_accessor
120
+ posts = Groonga::Hash.create(:name => "<posts>", :key_type => "<shorttext>")
121
+ posts.define_column("body", "<text>")
122
+ comments = Groonga::Hash.create(:name => "<comments>",
123
+ :key_type => "<shorttext>")
124
+ content = comments.define_column("content", "<shorttext>")
125
+ comments.define_column("post", posts)
126
+
127
+ index = Groonga::PatriciaTrie.create(:name => "<terms>",
128
+ :key_type => "<shorttext>")
129
+ content_index = index.define_column("content_index", comments,
130
+ :type => "index",
131
+ :with_position => true)
132
+ content_index.source = content
133
+
134
+ first_post = posts.add("Hello!")
135
+ first_post["body"] = "World"
136
+ hobby = posts.add("My Hobby")
137
+ hobby["body"] = "Drive and Eat"
138
+
139
+ friend = comments.add("Me too")
140
+ friend["content"] = "I'm also like drive"
141
+ friend["post"] = hobby
142
+
143
+ result = content_index.search("drive")
144
+ assert_equal([["I'm also like drive", "My Hobby"]],
145
+ result.records.collect do |record|
146
+ [record[".content"], record[".post.:key"]]
147
+ end)
148
+ end
149
+
150
+ def test_accessor_reference
151
+ bookmark = @bookmarks.add
152
+ assert_nil(@bookmarks_user[bookmark.id])
153
+
154
+ daijiro = @users.add
155
+ daijiro["name"] = "daijiro"
156
+ @bookmarks_user[bookmark.id] = daijiro
157
+ assert_equal(daijiro, @bookmarks_user[bookmark.id])
158
+ end
159
+
160
+ def test_inspect
161
+ assert_equal("#<Groonga::VarSizeColumn " +
162
+ "id: <#{@users_name_column.id}>, " +
163
+ "name: <users.name>, " +
164
+ "path: <#{@users_name_column_path}>, " +
165
+ "domain: <#{@users.inspect}>, " +
166
+ "range: <#{context['<shorttext>'].inspect}>" +
167
+ ">",
168
+ @users_name_column.inspect)
169
+ end
170
+
171
+ def test_domain
172
+ assert_equal(@users, @users_name_column.domain)
173
+ end
174
+
175
+ def test_table
176
+ assert_equal(@users, @users_name_column.table)
177
+ end
178
+
179
+ private
180
+ def assert_content_search(expected_records, term)
181
+ records = @bookmarks_index_content.search(term).records
182
+ expected_contents = expected_records.collect do |record|
183
+ record["content"]
184
+ end
185
+ actual_contents = records.collect do |record|
186
+ record.key["content"]
187
+ end
188
+ assert_equal(expected_contents, actual_contents)
189
+ end
190
+ end
@@ -0,0 +1,90 @@
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 ContextTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ def test_default
20
+ context = Groonga::Context.default
21
+ assert_not_predicate(context, :use_ql?)
22
+ assert_not_predicate(context, :batch_mode?)
23
+ assert_equal(Groonga::Encoding.default, context.encoding)
24
+ end
25
+
26
+ def test_default_options
27
+ Groonga::Context.default_options = {
28
+ :use_ql => true,
29
+ :batch_mode => true,
30
+ :encoding => :utf8,
31
+ }
32
+ context = Groonga::Context.default
33
+ assert_predicate(context, :use_ql?)
34
+ assert_predicate(context, :batch_mode?)
35
+ assert_equal(Groonga::Encoding::UTF8, context.encoding)
36
+ end
37
+
38
+ def test_use_ql?
39
+ context = Groonga::Context.new
40
+ assert_not_predicate(context, :use_ql?)
41
+
42
+ context = Groonga::Context.new(:use_ql => true)
43
+ assert_predicate(context, :use_ql?)
44
+ end
45
+
46
+ def test_batch_mode?
47
+ context = Groonga::Context.new
48
+ assert_not_predicate(context, :batch_mode?)
49
+
50
+ context = Groonga::Context.new(:batch_mode => true)
51
+ assert_predicate(context, :batch_mode?)
52
+ end
53
+
54
+ def test_encoding
55
+ context = Groonga::Context.new
56
+ assert_equal(Groonga::Encoding.default, context.encoding)
57
+
58
+ context = Groonga::Context.new(:encoding => :utf8)
59
+ assert_equal(Groonga::Encoding::UTF8, context.encoding)
60
+ end
61
+
62
+ def test_inspect
63
+ context = Groonga::Context.new(:use_ql => true,
64
+ :batch_mode => true,
65
+ :encoding => Groonga::Encoding::UTF8)
66
+ assert_equal("#<Groonga::Context " +
67
+ "use_ql: <true>, " +
68
+ "batch_mode: <true>, " +
69
+ "encoding: <:utf8>, " +
70
+ "database: <nil>>",
71
+ context.inspect)
72
+ end
73
+
74
+ def test_inspect_with_database
75
+ db = Groonga::Database.create
76
+ context = Groonga::Context.default
77
+ assert_equal("#<Groonga::Context " +
78
+ "use_ql: <false>, " +
79
+ "batch_mode: <false>, " +
80
+ "encoding: <#{Groonga::Encoding.default.inspect}>, " +
81
+ "database: <#{db.inspect}>>",
82
+ context.inspect)
83
+ end
84
+
85
+ def test_array_reference
86
+ Groonga::Database.create
87
+ context = Groonga::Context.default
88
+ assert_equal("<int>", context["<int>"].name)
89
+ end
90
+ end