rroonga 1.0.8 → 1.0.9

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 (70) hide show
  1. data/NEWS.ja.rdoc +47 -0
  2. data/NEWS.rdoc +48 -0
  3. data/README.ja.rdoc +1 -0
  4. data/README.rdoc +1 -0
  5. data/Rakefile +32 -13
  6. data/benchmark/create-wikipedia-database.rb +212 -0
  7. data/benchmark/repeat-load.rb +213 -0
  8. data/benchmark/select.rb +1052 -0
  9. data/ext/groonga/mkmf.log +99 -0
  10. data/ext/groonga/rb-grn-column.c +57 -6
  11. data/ext/groonga/rb-grn-context.c +15 -9
  12. data/ext/groonga/rb-grn-expression.c +7 -7
  13. data/ext/groonga/{rb-grn-operation.c → rb-grn-operator.c} +89 -87
  14. data/ext/groonga/rb-grn-patricia-trie.c +5 -5
  15. data/ext/groonga/rb-grn-query.c +4 -4
  16. data/ext/groonga/rb-grn-table.c +16 -19
  17. data/ext/groonga/rb-grn.h +3 -3
  18. data/ext/groonga/rb-groonga.c +1 -1
  19. data/html/index.html +4 -4
  20. data/lib/groonga/context.rb +34 -0
  21. data/lib/groonga/expression-builder.rb +34 -2
  22. data/lib/groonga/record.rb +8 -6
  23. data/lib/groonga/schema.rb +40 -4
  24. data/rroonga-build.rb +2 -2
  25. data/test-unit/Rakefile +5 -18
  26. data/test-unit/html/classic.html +15 -0
  27. data/test-unit/html/index.html +13 -235
  28. data/test-unit/html/index.html.ja +15 -258
  29. data/test-unit/lib/test/unit.rb +1 -6
  30. data/test-unit/lib/test/unit/assertions.rb +11 -115
  31. data/test-unit/lib/test/unit/autorunner.rb +2 -5
  32. data/test-unit/lib/test/unit/collector/load.rb +1 -1
  33. data/test-unit/lib/test/unit/color-scheme.rb +2 -6
  34. data/test-unit/lib/test/unit/diff.rb +1 -17
  35. data/test-unit/lib/test/unit/testcase.rb +0 -7
  36. data/test-unit/lib/test/unit/testresult.rb +2 -34
  37. data/test-unit/lib/test/unit/ui/console/testrunner.rb +45 -9
  38. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +12 -2
  39. data/test-unit/lib/test/unit/ui/testrunner.rb +0 -25
  40. data/test-unit/lib/test/unit/util/backtracefilter.rb +0 -1
  41. data/test-unit/lib/test/unit/version.rb +1 -1
  42. data/test-unit/test/test-color-scheme.rb +2 -4
  43. data/test-unit/test/test_assertions.rb +5 -51
  44. data/test/test-column.rb +31 -1
  45. data/test/test-context-select.rb +45 -14
  46. data/test/test-context.rb +36 -0
  47. data/test/test-database.rb +13 -0
  48. data/test/test-expression-builder.rb +32 -5
  49. data/test/test-record.rb +34 -1
  50. data/test/test-schema.rb +52 -2
  51. data/test/test-table-select-weight.rb +20 -1
  52. data/test/test-table.rb +58 -0
  53. metadata +13 -41
  54. data/test-unit-notify/Rakefile +0 -47
  55. data/test-unit-notify/lib/test/unit/notify.rb +0 -104
  56. data/test-unit/COPYING +0 -56
  57. data/test-unit/GPL +0 -340
  58. data/test-unit/PSFL +0 -271
  59. data/test-unit/html/bar.svg +0 -153
  60. data/test-unit/html/developer.svg +0 -469
  61. data/test-unit/html/favicon.ico +0 -0
  62. data/test-unit/html/favicon.svg +0 -82
  63. data/test-unit/html/heading-mark.svg +0 -393
  64. data/test-unit/html/install.svg +0 -636
  65. data/test-unit/html/logo.svg +0 -483
  66. data/test-unit/html/test-unit.css +0 -339
  67. data/test-unit/html/tutorial.svg +0 -559
  68. data/test-unit/lib/test/unit/util/output.rb +0 -31
  69. data/test-unit/test/ui/test_tap.rb +0 -33
  70. data/test-unit/test/util/test-output.rb +0 -11
@@ -1,7 +1,7 @@
1
1
  #--
2
2
  #
3
3
  # Author:: Kouhei Sutou.
4
- # Copyright:: Copyright (c) 2009-2010 Kouhei Sutou <kou@clear-code.com>.
4
+ # Copyright:: Copyright (c) 2009 Kouhei Sutou <kou@clear-code.com>.
5
5
  # License:: Ruby license.
6
6
 
7
7
  require 'test/unit/ui/testrunner'
@@ -24,7 +24,8 @@ module Test
24
24
 
25
25
  # Begins the test run.
26
26
  def start
27
- result = super
27
+ setup_mediator
28
+ result = start_mediator
28
29
  def result.passed?
29
30
  true # for prove commend :<
30
31
  end
@@ -32,6 +33,11 @@ module Test
32
33
  end
33
34
 
34
35
  private
36
+ def setup_mediator
37
+ @mediator = TestRunnerMediator.new(@suite)
38
+ attach_to_mediator
39
+ end
40
+
35
41
  def attach_to_mediator
36
42
  @mediator.add_listener(TestResult::FAULT, &method(:add_fault))
37
43
  @mediator.add_listener(TestRunnerMediator::STARTED, &method(:started))
@@ -40,6 +46,10 @@ module Test
40
46
  @mediator.add_listener(TestCase::FINISHED, &method(:test_finished))
41
47
  end
42
48
 
49
+ def start_mediator
50
+ @mediator.run_suite
51
+ end
52
+
43
53
  def add_fault(fault)
44
54
  puts("not ok #{@n_tests} - #{fault.short_display}")
45
55
  fault.long_display.each_line do |line|
@@ -6,7 +6,6 @@ module Test
6
6
  class TestRunner
7
7
  extend TestRunnerUtilities
8
8
 
9
- attr_reader :listeners
10
9
  def initialize(suite, options={})
11
10
  if suite.respond_to?(:suite)
12
11
  @suite = suite.suite
@@ -14,30 +13,6 @@ module Test
14
13
  @suite = suite
15
14
  end
16
15
  @options = options
17
- @listeners = @options[:listeners] || []
18
- end
19
-
20
- # Begins the test run.
21
- def start
22
- setup_mediator
23
- attach_to_mediator
24
- attach_listeners
25
- start_mediator
26
- end
27
-
28
- private
29
- def setup_mediator
30
- @mediator = TestRunnerMediator.new(@suite)
31
- end
32
-
33
- def attach_listeners
34
- @listeners.each do |listener|
35
- listener.attach_to_mediator(@mediator)
36
- end
37
- end
38
-
39
- def start_mediator
40
- @mediator.run_suite
41
16
  end
42
17
 
43
18
  def diff_target_string?(string)
@@ -9,7 +9,6 @@ module Test
9
9
  module_function
10
10
  def filter_backtrace(backtrace, prefix=nil)
11
11
  return ["No backtrace"] unless(backtrace)
12
- return backtrace if ENV["TEST_UNIT_ALL_BACKTRACE"]
13
12
  split_p = if(prefix)
14
13
  prefix.split(TESTUNIT_FILE_SEPARATORS)
15
14
  else
@@ -2,6 +2,6 @@
2
2
  # HACK: quick and dirty to get integrated into the new project - ryan
3
3
  module Test
4
4
  module Unit
5
- VERSION = '2.1.2'
5
+ VERSION = '2.0.8'
6
6
  end
7
7
  end
@@ -1,10 +1,8 @@
1
1
  class TestUnitColorScheme < Test::Unit::TestCase
2
2
  def test_default
3
3
  assert_equal({
4
- "pass" => color("green", :foreground => false) +
5
- color("white", :bold => true),
6
- "failure" => color("red", :foreground => false) +
7
- color("white", :bold => true),
4
+ "success" => color("green", :bold => true),
5
+ "failure" => color("red", :bold => true),
8
6
  "pending" => color("magenta", :bold => true),
9
7
  "omission" => color("blue", :bold => true),
10
8
  "notification" => color("cyan", :bold => true),
@@ -1,8 +1,6 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
1
  # Author:: Nathaniel Talbott.
4
2
  # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
5
- # Copyright (c) 2009-2010 Kouhei Sutou. All rights reserved.
3
+ # Copyright (c) 2009 Kouhei Sutou.
6
4
  # License:: Ruby license.
7
5
 
8
6
  require 'test/unit'
@@ -313,21 +311,6 @@ EOM
313
311
  end
314
312
  end
315
313
 
316
- def test_assert_equal_with_different_encoding
317
- utf8_string = "こんにちは"
318
- unless utf8_string.respond_to?(:force_encoding)
319
- omit("encoding test is for Ruby >= 1.9")
320
- end
321
- ascii_8bit_string = utf8_string.dup.force_encoding("ascii-8bit")
322
- message = <<-EOM.chomp
323
- <"こんにちは">("UTF-8") expected but was
324
- <#{ascii_8bit_string.inspect}>("ASCII-8BIT").
325
- EOM
326
- check_fails(message) do
327
- assert_equal(utf8_string, ascii_8bit_string)
328
- end
329
- end
330
-
331
314
  def test_assert_raise_success
332
315
  return_value = nil
333
316
  check_nothing_fails(true) do
@@ -828,19 +811,13 @@ EOM
828
811
  end
829
812
  assert_in_delta(0.1, float_thing, 0.1)
830
813
  }
831
- check_fails("message.\n" +
832
- "<0.5> expected but was\n" +
833
- "<0.4> (tolerance <0.05>).\n" +
834
- "\n" +
835
- "Relation:\n" +
836
- "<<0.4> < <0.5>-<0.05>(0.45) <= <0.5>+<0.05>(0.55)>") {
814
+ check_fails("message.\n<0.5> and\n<0.4> expected to be within\n<0.05> of each other.") {
837
815
  assert_in_delta(0.5, 0.4, 0.05, "message")
838
816
  }
839
817
  object = Object.new
840
- inspected_object = AssertionMessage.convert(object)
841
818
  check_fails("The arguments must respond to to_f; " +
842
819
  "the first float did not.\n" +
843
- "<#{inspected_object}>.respond_to?(:to_f) expected\n" +
820
+ "<#{object.inspect}>.respond_to?(:to_f) expected\n" +
844
821
  "(Class: <Object>)") {
845
822
  assert_in_delta(object, 0.4, 0.1)
846
823
  }
@@ -1144,40 +1121,17 @@ EOM
1144
1121
  assert_alias_method(object, :other, :original_method)
1145
1122
  end
1146
1123
 
1147
- inspected_object = AssertionMessage.convert(object)
1148
- check_fails("<#{inspected_object}>.nonexistent doesn't exist\n" +
1124
+ check_fails("<#{object.inspect}>.nonexistent doesn't exist\n" +
1149
1125
  "(Class: <Object>)") do
1150
1126
  assert_alias_method(object, :nonexistent, :original_method)
1151
1127
  end
1152
1128
 
1153
- check_fails("<#{inspected_object}>.nonexistent doesn't exist\n" +
1129
+ check_fails("<#{object.inspect}>.nonexistent doesn't exist\n" +
1154
1130
  "(Class: <Object>)") do
1155
1131
  assert_alias_method(object, :alias_method, :nonexistent)
1156
1132
  end
1157
1133
  end
1158
1134
 
1159
- def test_assert_path_exist
1160
- check_nothing_fails do
1161
- assert_path_exist(__FILE__)
1162
- end
1163
-
1164
- nonexistent_file = __FILE__ + ".nonexistent"
1165
- check_fails("<#{nonexistent_file.inspect}> expected to exist") do
1166
- assert_path_exist(nonexistent_file)
1167
- end
1168
- end
1169
-
1170
- def test_assert_path_not_exist
1171
- nonexistent_file = __FILE__ + ".nonexistent"
1172
- check_nothing_fails do
1173
- assert_path_not_exist(nonexistent_file)
1174
- end
1175
-
1176
- check_fails("<#{__FILE__.inspect}> expected to not exist") do
1177
- assert_path_not_exist(__FILE__)
1178
- end
1179
- end
1180
-
1181
1135
  private
1182
1136
  def add_failure(message, location=caller, options=nil)
1183
1137
  unless @catch_assertions
data/test/test-column.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2010 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2009-2011 Kouhei Sutou <kou@clear-code.com>
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -286,6 +286,36 @@ class ColumnTest < Test::Unit::TestCase
286
286
  assert_false(post["hidden"])
287
287
  end
288
288
 
289
+ def test_indexes
290
+ Groonga::Schema.define do |schema|
291
+ schema.create_table("Comments") do |table|
292
+ table.short_text("title")
293
+ end
294
+ end
295
+ title = Groonga["Comments.title"]
296
+ assert_equal([], title.indexes)
297
+
298
+ Groonga::Schema.define do |schema|
299
+ schema.create_table("Terms",
300
+ :type => :patricia_trie,
301
+ :default_tokenizer => "TokenBigram") do |table|
302
+ table.index("Comments.title")
303
+ end
304
+ end
305
+ assert_equal([Groonga["Terms.Comments_title"]],
306
+ title.indexes)
307
+
308
+ Groonga::Schema.define do |schema|
309
+ schema.create_table("Titles",
310
+ :type => :hash) do |table|
311
+ table.index("Comments.title")
312
+ end
313
+ end
314
+ assert_equal([Groonga["Titles.Comments_title"],
315
+ Groonga["Terms.Comments_title"]],
316
+ title.indexes)
317
+ end
318
+
289
319
  private
290
320
  def assert_content_search(expected_records, term)
291
321
  records = @bookmarks_index_content.search(term).records
@@ -19,35 +19,58 @@ class ContextSelectTest < Test::Unit::TestCase
19
19
  setup :setup_database
20
20
  setup
21
21
  def setup_data
22
- @books = Groonga::Hash.create(:name => "Books", :key_type => "ShortText")
23
- @books.define_column("published", "Time")
24
- @users = Groonga::Hash.create(:name => "Users", :key_type => "ShortText")
25
- @users.define_column("book", "Books")
22
+ Groonga::Schema.define do |schema|
23
+ schema.create_table("Books",
24
+ :type => :hash, :key_type => "ShortText") do |table|
25
+ table.time("published")
26
+ end
27
+
28
+ schema.create_table("Users",
29
+ :type => :hash, :key_type => "ShortText") do |table|
30
+ table.reference("book", "Books")
31
+ end
32
+
33
+ schema.create_table("Bigram",
34
+ :type => :patricia_trie,
35
+ :key_type => "ShortText",
36
+ :default_tokenizer => "TokenBigramSplitSymbolAlpha") do |table|
37
+ table.index("Books._key")
38
+ end
39
+ end
40
+
41
+ @books = Groonga["Books"]
42
+ @users = Groonga["Users"]
26
43
 
27
44
  @books.add("the groonga book", :published => Time.parse("2010/04/01"))
45
+ @books.add("the groonga book (2)", :published => Time.parse("2011/04/01"))
46
+
28
47
  @users.add("morita", :book => "the groonga book")
29
48
  @users.add("gunyara-kun", :book => "the groonga book")
30
49
  @users.add("yu")
50
+ @users.add("ryoqun", :book => "the groonga book (2)")
31
51
  end
32
52
 
33
53
  def test_no_option
34
54
  result = context.select(@users)
35
- assert_equal([3,
55
+ assert_equal([4,
36
56
  [{"_id" => 1, "_key" => "morita",
37
57
  "book" => "the groonga book"},
38
58
  {"_id" => 2, "_key" => "gunyara-kun",
39
59
  "book" => "the groonga book"},
40
60
  {"_id" => 3, "_key" => "yu",
41
- "book" => ""}]],
61
+ "book" => ""},
62
+ {"_id" => 4, "_key" => "ryoqun",
63
+ "book" => "the groonga book (2)"}]],
42
64
  [result.n_hits, result.records])
43
65
  end
44
66
 
45
67
  def test_output_columns
46
68
  result = context.select(@users, :output_columns => ["_key"])
47
- assert_equal([3,
69
+ assert_equal([4,
48
70
  [{"_key" => "morita"},
49
71
  {"_key" => "gunyara-kun"},
50
- {"_key" => "yu"}]],
72
+ {"_key" => "yu"},
73
+ {"_key" => "ryoqun"}]],
51
74
  [result.n_hits, result.records])
52
75
  end
53
76
 
@@ -58,15 +81,18 @@ class ContextSelectTest < Test::Unit::TestCase
58
81
  :drill_down_output_columns => "_key",
59
82
  :drill_down_limit => 10)
60
83
  drill_down = normalize_drill_down(result.drill_down)
61
- assert_equal([3,
84
+ assert_equal([4,
62
85
  [{"_key" => "morita"},
63
86
  {"_key" => "gunyara-kun"},
64
- {"_key" => "yu"}],
87
+ {"_key" => "yu"},
88
+ {"_key" => "ryoqun"}],
65
89
  {
66
- "_key" => [3, [{"_key" => "morita"},
90
+ "_key" => [4, [{"_key" => "morita"},
67
91
  {"_key" => "gunyara-kun"},
68
- {"_key" => "yu"}]],
69
- "book" => [1, [{"_key" => "the groonga book"}]],
92
+ {"_key" => "yu"},
93
+ {"_key" => "ryoqun"}]],
94
+ "book" => [2, [{"_key" => "the groonga book"},
95
+ {"_key" => "the groonga book (2)"}]],
70
96
  },
71
97
  ],
72
98
  [result.n_hits, result.records, drill_down])
@@ -95,11 +121,16 @@ class ContextSelectTest < Test::Unit::TestCase
95
121
  "_id" => 1,
96
122
  "_key" => "the groonga book",
97
123
  "published" => Time.parse("2010/04/01"),
124
+ },
125
+ {
126
+ "_id" => 2,
127
+ "_key" => "the groonga book (2)",
128
+ "published" => Time.parse("2011/04/01"),
98
129
  }],
99
130
  result.records)
100
131
  end
101
132
 
102
- def test_invalid_select
133
+ def test_invalid
103
134
  assert_raise(Groonga::SyntaxError) do
104
135
  context.select(@books, :query => "<")
105
136
  end
data/test/test-context.rb CHANGED
@@ -29,6 +29,42 @@ class ContextTest < Test::Unit::TestCase
29
29
  assert_equal(Groonga::Encoding::UTF8, context.encoding)
30
30
  end
31
31
 
32
+ def test_create_database
33
+ db_path = @tmp_dir + "db"
34
+ assert_not_predicate(db_path, :exist?)
35
+ context = Groonga::Context.new
36
+ assert_equal(nil, context.database)
37
+ database = context.create_database(db_path.to_s)
38
+ assert_predicate(db_path, :exist?)
39
+ assert_not_predicate(database, :closed?)
40
+ assert_equal(database, context.database)
41
+ end
42
+
43
+ def test_create_temporary_database
44
+ before_files = @tmp_dir.children
45
+ context = Groonga::Context.new
46
+ database = context.create_database
47
+ assert_nil(database.name)
48
+ assert_equal(before_files, @tmp_dir.children)
49
+ end
50
+
51
+ def test_open_database
52
+ db_path = @tmp_dir + "db"
53
+ database = Groonga::Database.create(:path => db_path.to_s)
54
+ database.close
55
+
56
+ assert_predicate(database, :closed?)
57
+ called = false
58
+ context = Groonga::Context.new
59
+ context.open_database(db_path.to_s) do |_database|
60
+ database = _database
61
+ assert_not_predicate(database, :closed?)
62
+ called = true
63
+ end
64
+ assert_true(called)
65
+ assert_predicate(database, :closed?)
66
+ end
67
+
32
68
  def test_encoding
33
69
  context = Groonga::Context.new
34
70
  assert_equal(Groonga::Encoding.default, context.encoding)
@@ -38,7 +38,9 @@ class DatabaseTest < Test::Unit::TestCase
38
38
  def test_open
39
39
  db_path = @tmp_dir + "db"
40
40
  database = Groonga::Database.create(:path => db_path.to_s)
41
+ database.close
41
42
 
43
+ assert_predicate(database, :closed?)
42
44
  called = false
43
45
  Groonga::Database.open(db_path.to_s) do |_database|
44
46
  database = _database
@@ -49,6 +51,17 @@ class DatabaseTest < Test::Unit::TestCase
49
51
  assert_predicate(database, :closed?)
50
52
  end
51
53
 
54
+ def test_close
55
+ db_path = @tmp_dir + "db"
56
+ database = Groonga::Database.create(:path => db_path.to_s)
57
+ database.close
58
+
59
+ database = Groonga::Database.open(db_path.to_s)
60
+ assert_not_predicate(database, :closed?)
61
+ database.close
62
+ assert_predicate(database, :closed?)
63
+ end
64
+
52
65
  def test_new
53
66
  db_path = @tmp_dir + "db"
54
67
  assert_raise(Groonga::NoSuchFileOrDirectory) do
@@ -24,30 +24,41 @@ class ExpressionBuilderTest < Test::Unit::TestCase
24
24
  @pets = Groonga::Hash.create(:name => "Pets", :key_type => "ShortText")
25
25
  @pets.define_column("name", "ShortText")
26
26
 
27
+ @sections = Groonga::PatriciaTrie.create(:name => "Sections",
28
+ :key_type => "ShortText")
29
+
27
30
  @users = Groonga::Hash.create(:name => "Users", :key_type => "ShortText")
28
31
  @name = @users.define_column("name", "ShortText")
29
32
  @hp = @users.define_column("hp", "UInt32")
30
- @users.define_column("pet", @pets)
33
+ @user_pet = @users.define_column("pet", @pets)
34
+ @user_section = @users.define_column("section", @sections)
31
35
 
32
36
  @terms = Groonga::PatriciaTrie.create(:name => "Terms",
33
- :default_tokenizer => "TokenBigram")
37
+ :default_tokenizer => "TokenBigram",
38
+ :key_type => "ShortText")
34
39
  @terms.define_index_column("user_name", @users, :source => @name)
35
40
 
36
41
  @bookmarks = Groonga::Array.create(:name => "Bookmarks")
37
42
  @bookmarks.define_column("user", @users)
38
43
  @bookmarks.define_column("uri", "ShortText")
44
+
45
+ @sections.define_index_column("user_section", @users,
46
+ :source => @user_section)
39
47
  end
40
48
 
41
49
  def setup_data
42
50
  @morita = @users.add("morita",
43
51
  :name => "mori daijiro",
44
- :hp => 100)
52
+ :hp => 100,
53
+ :section => "search/core")
45
54
  @gunyara_kun = @users.add("gunyara-kun",
46
55
  :name => "Tasuku SUENAGA",
47
- :hp => 150)
56
+ :hp => 150,
57
+ :section => "suggest/all")
48
58
  @yu = @users.add("yu",
49
59
  :name => "Yutaro Shimamura",
50
- :hp => 200)
60
+ :hp => 200,
61
+ :section => "search/all")
51
62
 
52
63
  @groonga = @bookmarks.add(:user => @morita, :uri => "http://groonga.org/")
53
64
  @ruby = @bookmarks.add(:user => @morita, :uri => "http://ruby-lang.org/")
@@ -118,6 +129,22 @@ class ExpressionBuilderTest < Test::Unit::TestCase
118
129
  result.collect {|record| record.key.key})
119
130
  end
120
131
 
132
+ def test_prefix_saerch
133
+ result = @users.select do |record|
134
+ record.section.prefix_search("search")
135
+ end
136
+ assert_equal(["morita", "yu"].sort,
137
+ result.collect {|record| record.key.key}.sort)
138
+ end
139
+
140
+ def test_suffix_search
141
+ result = @users.select do |record|
142
+ record.name.suffix_search("jiro")
143
+ end
144
+ assert_equal(["morita"].sort,
145
+ result.collect {|record| record.key.key}.sort)
146
+ end
147
+
121
148
  def test_query_string
122
149
  result = @users.select("name:@ro")
123
150
  assert_equal(["morita", "yu"],