groonga 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,62 @@
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 DatabaseTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ def test_create
20
+ assert_nil(Groonga::Context.default.database)
21
+
22
+ db_path = @tmp_dir + "db"
23
+ assert_not_predicate(db_path, :exist?)
24
+ database = Groonga::Database.create(:path => db_path.to_s)
25
+ assert_predicate(db_path, :exist?)
26
+ assert_not_predicate(database, :closed?)
27
+
28
+ assert_equal(database, Groonga::Context.default.database)
29
+ end
30
+
31
+ def test_temporary
32
+ before_files = @tmp_dir.children
33
+ database = Groonga::Database.create
34
+ assert_nil(database.name)
35
+ assert_equal(before_files, @tmp_dir.children)
36
+ end
37
+
38
+ def test_open
39
+ db_path = @tmp_dir + "db"
40
+ database = Groonga::Database.create(:path => db_path.to_s)
41
+
42
+ called = false
43
+ Groonga::Database.open(db_path.to_s) do |_database|
44
+ database = _database
45
+ assert_not_predicate(database, :closed?)
46
+ called = true
47
+ end
48
+ assert_true(called)
49
+ assert_predicate(database, :closed?)
50
+ end
51
+
52
+ def test_new
53
+ db_path = @tmp_dir + "db"
54
+ assert_raise(Groonga::NoMemoryAvailable) do
55
+ Groonga::Database.new(db_path.to_s)
56
+ end
57
+
58
+ database = Groonga::Database.create(:path => db_path.to_s)
59
+
60
+ assert_not_predicate(Groonga::Database.new(db_path.to_s), :closed?)
61
+ end
62
+ end
@@ -0,0 +1,33 @@
1
+ # Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License version 2.1 as published by the Free Software Foundation.
6
+ #
7
+ # This library is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ # Lesser General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU Lesser General Public
13
+ # License along with this library; if not, write to the Free Software
14
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
+
16
+ class EncodingTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ def test_constants
20
+ assert_equal(:default, Groonga::Encoding::DEFAULT)
21
+ assert_equal(:none, Groonga::Encoding::NONE)
22
+ assert_equal(:euc_jp, Groonga::Encoding::EUC_JP)
23
+ assert_equal(:sjis, Groonga::Encoding::SJIS)
24
+ assert_equal(:utf8, Groonga::Encoding::UTF8)
25
+ assert_equal(:latin1, Groonga::Encoding::LATIN1)
26
+ assert_equal(:koi8r, Groonga::Encoding::KOI8R)
27
+ end
28
+
29
+ def test_default
30
+ Groonga::Encoding.default = :utf8
31
+ assert_equal(:utf8, Groonga::Encoding.default)
32
+ end
33
+ end
@@ -0,0 +1,85 @@
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 ExceptionTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ def test_defined
20
+ assert_not_const_defined(Groonga, :Success)
21
+
22
+ assert_const_defined(Groonga, :EndOfData)
23
+ assert_const_defined(Groonga, :UnknownError)
24
+ assert_const_defined(Groonga, :OperationNotPermitted)
25
+ assert_const_defined(Groonga, :NoSuchFileOrDirectory)
26
+ assert_const_defined(Groonga, :NoSuchProcess)
27
+ assert_const_defined(Groonga, :InterruptedFunctionCall)
28
+ assert_const_defined(Groonga, :InputOutputError)
29
+ assert_const_defined(Groonga, :NoSuchDeviceOrAddress)
30
+ assert_const_defined(Groonga, :ArgumentListTooLong)
31
+ assert_const_defined(Groonga, :ExecFormatError)
32
+ assert_const_defined(Groonga, :BadFileDescriptor)
33
+ assert_const_defined(Groonga, :NoChildProcesses)
34
+ assert_const_defined(Groonga, :ResourceTemporarilyUnavailable)
35
+ assert_const_defined(Groonga, :NotEnoughSpace)
36
+ assert_const_defined(Groonga, :PermissionDenied)
37
+ assert_const_defined(Groonga, :BadAddress)
38
+ assert_const_defined(Groonga, :ResourceBusy)
39
+ assert_const_defined(Groonga, :FileExists)
40
+ assert_const_defined(Groonga, :ImproperLink)
41
+ assert_const_defined(Groonga, :NoSuchDevice)
42
+ assert_const_defined(Groonga, :NotADirectory)
43
+ assert_const_defined(Groonga, :IsADirectory)
44
+ assert_const_defined(Groonga, :InvalidArgument)
45
+ assert_const_defined(Groonga, :TooManyOpenFilesInSystem)
46
+ assert_const_defined(Groonga, :TooManyOpenFiles)
47
+ assert_const_defined(Groonga, :InappropriateIOControlOperation)
48
+ assert_const_defined(Groonga, :FileTooLarge)
49
+ assert_const_defined(Groonga, :NoSpaceLeftOnDevice)
50
+ assert_const_defined(Groonga, :InvalidSeek)
51
+ assert_const_defined(Groonga, :ReadOnlyFileSystem)
52
+ assert_const_defined(Groonga, :TooManyLinks)
53
+ assert_const_defined(Groonga, :BrokenPipe)
54
+ assert_const_defined(Groonga, :DomainError)
55
+ assert_const_defined(Groonga, :ResultTooLarge)
56
+ assert_const_defined(Groonga, :ResourceDeadlockAvoided)
57
+ assert_const_defined(Groonga, :NoMemoryAvailable)
58
+ assert_const_defined(Groonga, :FilenameTooLong)
59
+ assert_const_defined(Groonga, :NoLocksAvailable)
60
+ assert_const_defined(Groonga, :FunctionNotImplemented)
61
+ assert_const_defined(Groonga, :DirectoryNotEmpty)
62
+ assert_const_defined(Groonga, :IllegalByteSequence)
63
+ assert_const_defined(Groonga, :SocketNotInitialized)
64
+ assert_const_defined(Groonga, :OperationWouldBlock)
65
+ assert_const_defined(Groonga, :AddressIsNotAvailable)
66
+ assert_const_defined(Groonga, :NetworkIsDown)
67
+ assert_const_defined(Groonga, :NoBuffer)
68
+ assert_const_defined(Groonga, :SocketIsAlreadyConnected)
69
+ assert_const_defined(Groonga, :SocketIsNotConnected)
70
+ assert_const_defined(Groonga, :SocketIsAlreadyShutdowned)
71
+ assert_const_defined(Groonga, :OperationTimeout)
72
+ assert_const_defined(Groonga, :ConnectionRefused)
73
+ assert_const_defined(Groonga, :RangeError)
74
+ assert_const_defined(Groonga, :TokenizerError)
75
+ assert_const_defined(Groonga, :FileCorrupt)
76
+ assert_const_defined(Groonga, :InvalidFormat)
77
+ assert_const_defined(Groonga, :ObjectCorrupt)
78
+ assert_const_defined(Groonga, :TooManySymbolicLinks)
79
+ assert_const_defined(Groonga, :NotSocket)
80
+ assert_const_defined(Groonga, :OperationNotSupported)
81
+ assert_const_defined(Groonga, :AddressIsInUse)
82
+ assert_const_defined(Groonga, :ZLibError)
83
+ assert_const_defined(Groonga, :LZOError)
84
+ end
85
+ end
@@ -0,0 +1,35 @@
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 ProcedureTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ setup :setup_database
20
+
21
+ def test_builtins
22
+ assert_equal_procedure("<token:delimit>", Groonga::Procedure::DELIMIT)
23
+ assert_equal_procedure("<token:unigram>", Groonga::Procedure::UNIGRAM)
24
+ assert_equal_procedure("<token:bigram>", Groonga::Procedure::BIGRAM)
25
+ assert_equal_procedure("<token:trigram>", Groonga::Procedure::TRIGRAM)
26
+ assert_equal_procedure("<token:mecab>", Groonga::Procedure::MECAB)
27
+ end
28
+
29
+ private
30
+ def assert_equal_procedure(expected_name, id)
31
+ procedure = Groonga::Context.default[id]
32
+ assert_equal(expected_name,
33
+ procedure ? procedure.name : procedure)
34
+ end
35
+ end
@@ -0,0 +1,22 @@
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 QueryTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ def test_new
20
+ Groonga::Query.new("groonga text")
21
+ end
22
+ end
@@ -0,0 +1,188 @@
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 RecordTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ def setup
20
+ setup_database
21
+
22
+ setup_addresses_table
23
+ setup_users_table
24
+ setup_bookmarks_table
25
+ setup_indexes
26
+ end
27
+
28
+ def setup_addresses_table
29
+ @addresses_path = @tables_dir + "addresses"
30
+ @addresses = Groonga::Array.create(:name => "addresses",
31
+ :path => @addresses_path.to_s)
32
+
33
+ @addresses_mail_column_path = @columns_dir + "mail"
34
+ @addresses_mail_column =
35
+ @addresses.define_column("mail", "<shorttext>",
36
+ :path => @addresses_mail_column_path.to_s)
37
+ end
38
+
39
+ def setup_users_table
40
+ @users_path = @tables_dir + "users"
41
+ @users = Groonga::Array.create(:name => "users",
42
+ :path => @users_path.to_s)
43
+
44
+ @users_name_column_path = @columns_dir + "name"
45
+ @users_name_column =
46
+ @users.define_column("name", "<shorttext>",
47
+ :path => @users_name_column_path.to_s)
48
+
49
+ @users_addresses_column_path = @columns_dir + "addresses"
50
+ @users_addresses_column =
51
+ @users.define_column("addresses", @addresses,
52
+ :path => @users_addresses_column_path.to_s,
53
+ :type => "vector")
54
+ end
55
+
56
+ def setup_bookmarks_table
57
+ @bookmarks_path = @tables_dir + "bookmarks"
58
+ @bookmarks = Groonga::Array.create(:name => "bookmarks",
59
+ :value_size => 512,
60
+ :path => @bookmarks_path.to_s)
61
+
62
+ @uri_column_path = @columns_dir + "uri"
63
+ @bookmarks_uri = @bookmarks.define_column("uri", "<shorttext>",
64
+ :path => @uri_column_path.to_s)
65
+
66
+ @comment_column_path = @columns_dir + "comment"
67
+ @bookmarks_comment =
68
+ @bookmarks.define_column("comment", "<text>",
69
+ :path => @comment_column_path.to_s)
70
+
71
+ @content_column_path = @columns_dir + "content"
72
+ @bookmarks_content = @bookmarks.define_column("content", "<longtext>")
73
+
74
+ @user_column_path = @columns_dir + "user"
75
+ @bookmarks_user = @bookmarks.define_column("user", @users)
76
+ end
77
+
78
+ def setup_indexes
79
+ @bookmarks_index_path = @tables_dir + "bookmarks-index"
80
+ @bookmarks_index =
81
+ Groonga::PatriciaTrie.create(:name => "bookmarks-index",
82
+ :path => @bookmarks_index_path.to_s)
83
+ @content_index_column_path = @columns_dir + "content-index"
84
+ @bookmarks_content_index =
85
+ @bookmarks_index.define_column("<index:content>", @bookmarks,
86
+ :type => "index",
87
+ :with_section => true,
88
+ :with_weight => true,
89
+ :with_position => true,
90
+ :path => @content_index_column_path.to_s)
91
+ @bookmarks_content_index.source = @bookmarks_content
92
+
93
+ @uri_index_column_path = @columns_dir + "uri-index"
94
+ @bookmarks_uri_index =
95
+ @bookmarks_index.define_column("<index:uri>", @bookmarks,
96
+ :type => "index",
97
+ :with_position => true,
98
+ :path => @uri_index_column_path.to_s)
99
+ @bookmarks_uri_index.source = @bookmarks_uri
100
+ end
101
+
102
+ def test_column_accessor
103
+ groonga = @bookmarks.add
104
+
105
+ groonga["uri"] = "http://groonga.org/"
106
+ assert_equal("http://groonga.org/", groonga["uri"])
107
+
108
+ groonga["comment"] = "fulltext search engine"
109
+ assert_equal("fulltext search engine", groonga["comment"])
110
+ end
111
+
112
+ def test_have_column?
113
+ groonga = @bookmarks.add
114
+ assert_true(groonga.have_column?(:uri))
115
+ assert_false(groonga.have_column?(:nonexistent))
116
+ end
117
+
118
+ def test_get_nonexistent_column
119
+ groonga = @bookmarks.add
120
+ assert_nil(groonga["nonexistent"])
121
+ end
122
+
123
+ def test_set_nonexistent_column
124
+ groonga = @bookmarks.add
125
+ assert_raise(Groonga::Error) do
126
+ groonga["nonexistent"] = "value"
127
+ end
128
+ end
129
+
130
+ def test_set_object_id
131
+ groonga = @bookmarks.add
132
+ daijiro = @users.add
133
+ daijiro["name"] = "daijiro"
134
+ assert_nil(groonga["user"])
135
+ groonga["user"] = daijiro.id
136
+ assert_equal(daijiro, groonga["user"])
137
+ end
138
+
139
+ def test_set_nil
140
+ groonga = @bookmarks.add
141
+ groonga["content"] = nil
142
+ assert_nil(groonga["content"])
143
+ end
144
+
145
+ def test_delete
146
+ bookmark1 = @bookmarks.add
147
+ bookmark2 = @bookmarks.add
148
+ bookmark3 = @bookmarks.add
149
+
150
+ assert_equal(3, @bookmarks.size)
151
+ bookmark2.delete
152
+ assert_equal(2, @bookmarks.size)
153
+ end
154
+
155
+ def test_key
156
+ documents = Groonga::PatriciaTrie.create(:name => "<documents>",
157
+ :key_type => "<shorttext>")
158
+ reference = documents.add("reference")
159
+ assert_equal("reference", reference.key)
160
+ end
161
+
162
+ def test_value
163
+ bookmark = @bookmarks.add
164
+ assert_equal("", bookmark.value.split(/\0/, 2)[0])
165
+ bookmark.value = "http://groonga.org/\0"
166
+ assert_equal("http://groonga.org/", bookmark.value.split(/\0/, 2)[0])
167
+ end
168
+
169
+ def test_reference_column?
170
+ bookmark = @bookmarks.add
171
+ assert_false(bookmark.reference_column?("uri"))
172
+ assert_true(bookmark.reference_column?("user"))
173
+ end
174
+
175
+ def test_score
176
+ groonga = @bookmarks.add
177
+ groonga["content"] = "full text search search search engine."
178
+
179
+ google = @bookmarks.add
180
+ google["content"] = "Web search engine."
181
+
182
+ results = @bookmarks_content_index.search("search")
183
+ assert_equal([[groonga.id, 3], [google.id, 1]],
184
+ results.collect do |record|
185
+ [record.id, record.score]
186
+ end)
187
+ end
188
+ end
@@ -0,0 +1,121 @@
1
+ # -*- coding: utf-8 -*-
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
+ class SnippetTest < Test::Unit::TestCase
19
+ include GroongaTestUtils
20
+
21
+ def setup_encoding
22
+ Groonga::Encoding.default = :utf8
23
+ end
24
+
25
+ def test_new_without_arguments
26
+ assert_nothing_raised do
27
+ Groonga::Snippet.new
28
+ end
29
+ end
30
+
31
+ def test_execute
32
+ snippet = Groonga::Snippet.new
33
+ snippet.add_keyword("検索", :open_tag => "[[", :close_tag => "]]")
34
+ assert_equal(["groonga は組み込み型の全文[[検索]]エンジンライブラリです。DBMSやスクリプト",
35
+ "組み込むことによって、その全文[[検索]]機能を強化することができます。ま"],
36
+ snippet.execute(text))
37
+ end
38
+
39
+ def test_invalid_encoding
40
+ Groonga::Context.default.encoding = :shift_jis
41
+ snippet = Groonga::Snippet.new
42
+ snippet.add_keyword("検索")
43
+ assert_equal([], snippet.execute(text))
44
+ end
45
+
46
+ def test_default_tag
47
+ snippet = Groonga::Snippet.new(:default_open_tag => "<<",
48
+ :default_close_tag => ">>")
49
+ snippet.add_keyword("全文")
50
+ assert_equal(["groonga は組み込み型の<<全文>>検索エンジンライブラリです。DBMSやスクリプト",
51
+ "等に組み込むことによって、その<<全文>>検索機能を強化することができます"],
52
+ snippet.execute(text))
53
+ end
54
+
55
+ def test_width
56
+ snippet = Groonga::Snippet.new(:width => 30,
57
+ :default_open_tag => "{",
58
+ :default_close_tag => "}")
59
+ snippet.add_keyword("データ")
60
+ assert_equal(["基づく{データ}ストア機",
61
+ "高速\nな{データ}ストア"],
62
+ snippet.execute(text))
63
+ end
64
+
65
+ def test_max_results
66
+ snippet = Groonga::Snippet.new(:width => 30,
67
+ :max_results => 1,
68
+ :default_open_tag => "{",
69
+ :default_close_tag => "}")
70
+ snippet.add_keyword("データ")
71
+ assert_equal(["基づく{データ}ストア機"],
72
+ snippet.execute(text))
73
+ end
74
+
75
+ def test_normalize
76
+ options_without_normalize = {
77
+ :width => 30,
78
+ :default_open_tag => "{",
79
+ :default_close_tag => "}",
80
+ }
81
+ snippet = Groonga::Snippet.new(options_without_normalize)
82
+ snippet.add_keyword("処理系等")
83
+ assert_equal([], snippet.execute(text))
84
+
85
+ options_with_normalize = options_without_normalize.merge(:normalize => true)
86
+ snippet = Groonga::Snippet.new(options_with_normalize)
87
+ snippet.add_keyword("処理系等")
88
+ assert_equal(["ト言語{処理\n系等}に組"],
89
+ snippet.execute(text))
90
+ end
91
+
92
+ def test_html_escape
93
+ text = "groonga は組み込み型の全文検索エンジン&データストアライブラリです。"
94
+ options_without_html_escape = {
95
+ :width => 30,
96
+ :default_open_tag => "<",
97
+ :default_close_tag => ">",
98
+ }
99
+ snippet = Groonga::Snippet.new(options_without_html_escape)
100
+ snippet.add_keyword("エンジン")
101
+ assert_equal(["文検索<エンジン>&デー"],
102
+ snippet.execute(text))
103
+
104
+ options_with_html_escape =
105
+ options_without_html_escape.merge(:html_escape => true)
106
+ snippet = Groonga::Snippet.new(options_with_html_escape)
107
+ snippet.add_keyword("エンジン")
108
+ assert_equal(["文検索<エンジン>&amp;デー"],
109
+ snippet.execute(text))
110
+ end
111
+
112
+ private
113
+ def text
114
+ <<-EOT
115
+ groonga は組み込み型の全文検索エンジンライブラリです。DBMSやスクリプト言語処理
116
+ 系等に組み込むことによって、その全文検索機能を強化することができます。また、リ
117
+ レーショナルモデルに基づくデータストア機能を内包しており、groonga単体でも高速
118
+ なデータストアサーバとして使用することができます。
119
+ EOT
120
+ end
121
+ end