rroonga 1.1.0 → 1.2.0

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 (64) hide show
  1. data/NEWS.ja.rdoc +18 -0
  2. data/NEWS.rdoc +18 -0
  3. data/bin/grndump +71 -0
  4. data/ext/groonga/rb-grn-accessor.c +64 -1
  5. data/ext/groonga/rb-grn-context.c +40 -1
  6. data/ext/groonga/rb-grn-database.c +47 -5
  7. data/ext/groonga/rb-grn-index-column.c +77 -7
  8. data/ext/groonga/rb-grn-object.c +8 -4
  9. data/ext/groonga/rb-grn-table-cursor.c +56 -1
  10. data/ext/groonga/rb-grn-table-key-support.c +2 -2
  11. data/ext/groonga/rb-grn-table.c +10 -38
  12. data/ext/groonga/rb-grn.h +11 -1
  13. data/html/index.html +6 -6
  14. data/html/ranguba.css +8 -1
  15. data/lib/groonga.rb +1 -0
  16. data/lib/groonga/dumper.rb +481 -0
  17. data/lib/groonga/schema.rb +54 -181
  18. data/rroonga-build.rb +1 -1
  19. data/test-unit-notify/Rakefile +47 -0
  20. data/test-unit-notify/lib/test/unit/notify.rb +104 -0
  21. data/test-unit/COPYING +56 -0
  22. data/test-unit/GPL +340 -0
  23. data/test-unit/PSFL +271 -0
  24. data/test-unit/Rakefile +18 -5
  25. data/test-unit/html/bar.svg +153 -0
  26. data/test-unit/html/developer.svg +469 -0
  27. data/test-unit/html/favicon.ico +0 -0
  28. data/test-unit/html/favicon.svg +82 -0
  29. data/test-unit/html/heading-mark.svg +393 -0
  30. data/test-unit/html/index.html +235 -13
  31. data/test-unit/html/index.html.ja +258 -15
  32. data/test-unit/html/install.svg +636 -0
  33. data/test-unit/html/logo.svg +483 -0
  34. data/test-unit/html/test-unit.css +339 -0
  35. data/test-unit/html/tutorial.svg +559 -0
  36. data/test-unit/lib/test/unit.rb +6 -1
  37. data/test-unit/lib/test/unit/assertions.rb +115 -11
  38. data/test-unit/lib/test/unit/autorunner.rb +5 -2
  39. data/test-unit/lib/test/unit/collector/load.rb +1 -1
  40. data/test-unit/lib/test/unit/color-scheme.rb +6 -2
  41. data/test-unit/lib/test/unit/diff.rb +17 -1
  42. data/test-unit/lib/test/unit/testcase.rb +7 -0
  43. data/test-unit/lib/test/unit/testresult.rb +34 -2
  44. data/test-unit/lib/test/unit/ui/console/testrunner.rb +9 -45
  45. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +2 -12
  46. data/test-unit/lib/test/unit/ui/testrunner.rb +25 -0
  47. data/test-unit/lib/test/unit/util/backtracefilter.rb +1 -0
  48. data/test-unit/lib/test/unit/util/output.rb +31 -0
  49. data/test-unit/lib/test/unit/version.rb +1 -1
  50. data/test-unit/test/test-color-scheme.rb +4 -2
  51. data/test-unit/test/test_assertions.rb +51 -5
  52. data/test-unit/test/ui/test_tap.rb +33 -0
  53. data/test-unit/test/util/test-output.rb +11 -0
  54. data/test/groonga-test-utils.rb +1 -0
  55. data/test/test-accessor.rb +32 -0
  56. data/test/test-context.rb +7 -1
  57. data/test/test-database-dumper.rb +156 -0
  58. data/test/test-index-column.rb +67 -1
  59. data/test/test-schema-dumper.rb +181 -0
  60. data/test/test-schema.rb +53 -97
  61. data/test/test-table-dumper.rb +83 -0
  62. metadata +48 -11
  63. data/ext/groonga/mkmf.log +0 -99
  64. data/test-unit/html/classic.html +0 -15
@@ -1,7 +1,7 @@
1
1
  #--
2
2
  #
3
3
  # Author:: Kouhei Sutou.
4
- # Copyright:: Copyright (c) 2009 Kouhei Sutou <kou@clear-code.com>.
4
+ # Copyright:: Copyright (c) 2009-2010 Kouhei Sutou <kou@clear-code.com>.
5
5
  # License:: Ruby license.
6
6
 
7
7
  require 'test/unit/ui/testrunner'
@@ -24,8 +24,7 @@ module Test
24
24
 
25
25
  # Begins the test run.
26
26
  def start
27
- setup_mediator
28
- result = start_mediator
27
+ result = super
29
28
  def result.passed?
30
29
  true # for prove commend :<
31
30
  end
@@ -33,11 +32,6 @@ module Test
33
32
  end
34
33
 
35
34
  private
36
- def setup_mediator
37
- @mediator = TestRunnerMediator.new(@suite)
38
- attach_to_mediator
39
- end
40
-
41
35
  def attach_to_mediator
42
36
  @mediator.add_listener(TestResult::FAULT, &method(:add_fault))
43
37
  @mediator.add_listener(TestRunnerMediator::STARTED, &method(:started))
@@ -46,10 +40,6 @@ module Test
46
40
  @mediator.add_listener(TestCase::FINISHED, &method(:test_finished))
47
41
  end
48
42
 
49
- def start_mediator
50
- @mediator.run_suite
51
- end
52
-
53
43
  def add_fault(fault)
54
44
  puts("not ok #{@n_tests} - #{fault.short_display}")
55
45
  fault.long_display.each_line do |line|
@@ -6,6 +6,7 @@ module Test
6
6
  class TestRunner
7
7
  extend TestRunnerUtilities
8
8
 
9
+ attr_reader :listeners
9
10
  def initialize(suite, options={})
10
11
  if suite.respond_to?(:suite)
11
12
  @suite = suite.suite
@@ -13,6 +14,30 @@ module Test
13
14
  @suite = suite
14
15
  end
15
16
  @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
16
41
  end
17
42
 
18
43
  def diff_target_string?(string)
@@ -9,6 +9,7 @@ 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"]
12
13
  split_p = if(prefix)
13
14
  prefix.split(TESTUNIT_FILE_SEPARATORS)
14
15
  else
@@ -0,0 +1,31 @@
1
+ module Test
2
+ module Unit
3
+ module Util
4
+ module Output
5
+ ##
6
+ # Returns output for standard output and standard
7
+ # error as string.
8
+ #
9
+ # Example:
10
+ # capture_output do
11
+ # puts("stdout")
12
+ # warn("stderr")
13
+ # end # -> ["stdout\n", "stderr\n"]
14
+ def capture_output
15
+ require 'stringio'
16
+
17
+ output = StringIO.new
18
+ error = StringIO.new
19
+ stdout_save, stderr_save = $stdout, $stderr
20
+ $stdout, $stderr = output, error
21
+ begin
22
+ yield
23
+ [output.string, error.string]
24
+ ensure
25
+ $stdout, $stderr = stdout_save, stderr_save
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -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.0.8'
5
+ VERSION = '2.1.2'
6
6
  end
7
7
  end
@@ -1,8 +1,10 @@
1
1
  class TestUnitColorScheme < Test::Unit::TestCase
2
2
  def test_default
3
3
  assert_equal({
4
- "success" => color("green", :bold => true),
5
- "failure" => color("red", :bold => true),
4
+ "pass" => color("green", :foreground => false) +
5
+ color("white", :bold => true),
6
+ "failure" => color("red", :foreground => false) +
7
+ color("white", :bold => true),
6
8
  "pending" => color("magenta", :bold => true),
7
9
  "omission" => color("blue", :bold => true),
8
10
  "notification" => color("cyan", :bold => true),
@@ -1,6 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
1
3
  # Author:: Nathaniel Talbott.
2
4
  # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
3
- # Copyright (c) 2009 Kouhei Sutou.
5
+ # Copyright (c) 2009-2010 Kouhei Sutou. All rights reserved.
4
6
  # License:: Ruby license.
5
7
 
6
8
  require 'test/unit'
@@ -311,6 +313,21 @@ EOM
311
313
  end
312
314
  end
313
315
 
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
+
314
331
  def test_assert_raise_success
315
332
  return_value = nil
316
333
  check_nothing_fails(true) do
@@ -811,13 +828,19 @@ EOM
811
828
  end
812
829
  assert_in_delta(0.1, float_thing, 0.1)
813
830
  }
814
- check_fails("message.\n<0.5> and\n<0.4> expected to be within\n<0.05> of each other.") {
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)>") {
815
837
  assert_in_delta(0.5, 0.4, 0.05, "message")
816
838
  }
817
839
  object = Object.new
840
+ inspected_object = AssertionMessage.convert(object)
818
841
  check_fails("The arguments must respond to to_f; " +
819
842
  "the first float did not.\n" +
820
- "<#{object.inspect}>.respond_to?(:to_f) expected\n" +
843
+ "<#{inspected_object}>.respond_to?(:to_f) expected\n" +
821
844
  "(Class: <Object>)") {
822
845
  assert_in_delta(object, 0.4, 0.1)
823
846
  }
@@ -1121,17 +1144,40 @@ EOM
1121
1144
  assert_alias_method(object, :other, :original_method)
1122
1145
  end
1123
1146
 
1124
- check_fails("<#{object.inspect}>.nonexistent doesn't exist\n" +
1147
+ inspected_object = AssertionMessage.convert(object)
1148
+ check_fails("<#{inspected_object}>.nonexistent doesn't exist\n" +
1125
1149
  "(Class: <Object>)") do
1126
1150
  assert_alias_method(object, :nonexistent, :original_method)
1127
1151
  end
1128
1152
 
1129
- check_fails("<#{object.inspect}>.nonexistent doesn't exist\n" +
1153
+ check_fails("<#{inspected_object}>.nonexistent doesn't exist\n" +
1130
1154
  "(Class: <Object>)") do
1131
1155
  assert_alias_method(object, :alias_method, :nonexistent)
1132
1156
  end
1133
1157
  end
1134
1158
 
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
+
1135
1181
  private
1136
1182
  def add_failure(message, location=caller, options=nil)
1137
1183
  unless @catch_assertions
@@ -0,0 +1,33 @@
1
+ require 'stringio'
2
+ require 'test/unit/ui/tap/testrunner'
3
+
4
+ class TestTap < Test::Unit::TestCase
5
+ def test_run
6
+ fail_line = nil
7
+ test_case = Class.new(Test::Unit::TestCase) do
8
+ def test_success
9
+ assert_equal(3, 1 + 2)
10
+ end
11
+
12
+ def test_fail; assert_equal(3, 1 - 2); end; fail_line = __LINE__
13
+ end
14
+ output = StringIO.new
15
+ runner = Test::Unit::UI::Tap::TestRunner.new(test_case.suite,
16
+ :output => output)
17
+ result = runner.start; start_line = __LINE__
18
+ assert_equal(<<-EOR, output.string.gsub(/[\d\.]+ seconds/, "0.001 seconds"))
19
+ 1..2
20
+ not ok 1 - test_fail(): <3> expected but was
21
+ # Failure:
22
+ # test_fail()
23
+ # [#{__FILE__}:#{fail_line}:in `test_fail'
24
+ # #{__FILE__}:#{start_line}:in `test_run']:
25
+ # <3> expected but was
26
+ # <-1>.
27
+ ok 2 - test_success()
28
+ # Finished in 0.001 seconds.
29
+ # 2 tests, 2 assertions, 1 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
30
+ EOR
31
+ assert_true(result.passed?)
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ require 'test/unit'
2
+
3
+ class TestUnitOutput < Test::Unit::TestCase
4
+ def test_capture_output
5
+ assert_equal(["stdout\n", "stderr\n"],
6
+ capture_output do
7
+ puts("stdout")
8
+ warn("stderr")
9
+ end)
10
+ end
11
+ end
@@ -17,6 +17,7 @@ require 'fileutils'
17
17
  require 'pathname'
18
18
  require 'time'
19
19
  require 'erb'
20
+ require 'stringio'
20
21
  begin
21
22
  require 'json'
22
23
  rescue LoadError
@@ -0,0 +1,32 @@
1
+ # Copyright (C) 2011 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 AccessorTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ def setup
20
+ setup_database
21
+ @posts = Groonga::Hash.create(:name => "Posts", :key_type => "ShortText")
22
+ @id = @posts.column("_id")
23
+ end
24
+
25
+ def test_name
26
+ assert_nil(@id.name)
27
+ end
28
+
29
+ def test_local_name
30
+ assert_equal("_id", @id.local_name)
31
+ end
32
+ end
data/test/test-context.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009 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
@@ -114,4 +114,10 @@ class ContextTest < Test::Unit::TestCase
114
114
  def test_support_lzo?
115
115
  assert_boolean(Groonga::Context.default.support_lzo?)
116
116
  end
117
+
118
+ def test_match_escalation_threshold
119
+ assert_equal(0, context.match_escalation_threshold)
120
+ context.match_escalation_threshold = -1
121
+ assert_equal(-1, context.match_escalation_threshold)
122
+ end
117
123
  end
@@ -0,0 +1,156 @@
1
+ # Copyright (C) 2011 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 DatabaseDumperTest < Test::Unit::TestCase
17
+ include GroongaTestUtils
18
+
19
+ setup :setup_database, :before => :append
20
+
21
+ setup
22
+ def setup_tables
23
+ Groonga::Schema.define do |schema|
24
+ schema.create_table("Users",
25
+ :type => :hash,
26
+ :key_type => "ShortText") do |table|
27
+ table.text("name")
28
+ end
29
+
30
+ schema.create_table("Posts") do |table|
31
+ table.text("title")
32
+ table.reference("author", "Users")
33
+ table.integer("rank")
34
+ table.unsigned_integer("n_goods")
35
+ table.text("tags", :type => :vector)
36
+ table.boolean("published")
37
+ table.time("created_at")
38
+ end
39
+
40
+ schema.change_table("Users") do |table|
41
+ table.index("Posts.author")
42
+ end
43
+ end
44
+ end
45
+
46
+ private
47
+ def dump(options={})
48
+ Groonga::DatabaseDumper.new(options).dump
49
+ end
50
+
51
+ def posts
52
+ context["Posts"]
53
+ end
54
+
55
+ def dumped_schema
56
+ <<-EOS
57
+ table_create Posts TABLE_NO_KEY
58
+ column_create Posts created_at COLUMN_SCALAR Time
59
+ column_create Posts n_goods COLUMN_SCALAR UInt32
60
+ column_create Posts published COLUMN_SCALAR Bool
61
+ column_create Posts rank COLUMN_SCALAR Int32
62
+ column_create Posts tags COLUMN_VECTOR Text
63
+ column_create Posts title COLUMN_SCALAR Text
64
+
65
+ table_create Users TABLE_HASH_KEY --key_type ShortText
66
+ column_create Users name COLUMN_SCALAR Text
67
+
68
+ column_create Posts author COLUMN_SCALAR Users
69
+
70
+ column_create Users Posts_author COLUMN_INDEX Posts author
71
+ EOS
72
+ end
73
+
74
+ class EmptyTest < DatabaseDumperTest
75
+ def test_default
76
+ assert_equal(dumped_schema, dump)
77
+ end
78
+ end
79
+
80
+ class HaveDataTest < DatabaseDumperTest
81
+ setup
82
+ def setup_data
83
+ posts.add(:author => "mori",
84
+ :created_at => Time.parse("2010-03-08 16:52 JST"),
85
+ :n_goods => 4,
86
+ :published => true,
87
+ :rank => 10,
88
+ :tags => ["search", "mori"],
89
+ :title => "Why search engine find?")
90
+ end
91
+
92
+ def test_default
93
+ assert_equal(<<-EOS, dump)
94
+ #{dumped_schema.chomp}
95
+
96
+ load --table Posts
97
+ [
98
+ ["_id","author","created_at","n_goods","published","rank","tags","title"],
99
+ [1,"mori",1268034720.0,4,true,10,["search","mori"],"Why search engine find?"]
100
+ ]
101
+
102
+ load --table Users
103
+ [
104
+ ["_key","name"],
105
+ ["mori",""]
106
+ ]
107
+ EOS
108
+ end
109
+
110
+ def test_limit_tables
111
+ assert_equal(<<-EOS, dump(:tables => ["Posts"]))
112
+ #{dumped_schema.chomp}
113
+
114
+ load --table Posts
115
+ [
116
+ ["_id","author","created_at","n_goods","published","rank","tags","title"],
117
+ [1,"mori",1268034720.0,4,true,10,["search","mori"],"Why search engine find?"]
118
+ ]
119
+ EOS
120
+ end
121
+
122
+ def test_limit_tables_with_regexp
123
+ assert_equal(<<-EOS, dump(:tables => [/Posts?/]))
124
+ #{dumped_schema.chomp}
125
+
126
+ load --table Posts
127
+ [
128
+ ["_id","author","created_at","n_goods","published","rank","tags","title"],
129
+ [1,"mori",1268034720.0,4,true,10,["search","mori"],"Why search engine find?"]
130
+ ]
131
+ EOS
132
+ end
133
+
134
+ def test_no_schema
135
+ assert_equal(<<-EOS, dump(:dump_schema => false))
136
+ load --table Posts
137
+ [
138
+ ["_id","author","created_at","n_goods","published","rank","tags","title"],
139
+ [1,"mori",1268034720.0,4,true,10,["search","mori"],"Why search engine find?"]
140
+ ]
141
+
142
+ load --table Users
143
+ [
144
+ ["_key","name"],
145
+ ["mori",""]
146
+ ]
147
+ EOS
148
+ end
149
+
150
+ def test_no_tables
151
+ assert_equal(<<-EOS, dump(:dump_tables => false))
152
+ #{dumped_schema.chomp}
153
+ EOS
154
+ end
155
+ end
156
+ end