rroonga 0.9.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/NEWS.ja.rdoc +13 -0
  2. data/NEWS.rdoc +13 -0
  3. data/README.ja.rdoc +2 -2
  4. data/README.rdoc +2 -2
  5. data/ext/groonga/rb-grn-exception.c +14 -0
  6. data/ext/groonga/rb-grn-index-column.c +13 -1
  7. data/ext/groonga/rb-grn-object.c +2 -2
  8. data/ext/groonga/rb-grn-patricia-trie.c +393 -0
  9. data/ext/groonga/rb-grn-table.c +26 -2
  10. data/ext/groonga/rb-grn.h +3 -3
  11. data/html/index.html +1 -1
  12. data/lib/groonga/schema.rb +1 -1
  13. data/rroonga-build.rb +3 -3
  14. data/test-unit-notify/Rakefile +47 -0
  15. data/test-unit-notify/lib/test/unit/notify.rb +104 -0
  16. data/test-unit/COPYING +56 -0
  17. data/test-unit/GPL +340 -0
  18. data/test-unit/PSFL +271 -0
  19. data/test-unit/Rakefile +18 -5
  20. data/test-unit/html/bar.svg +153 -0
  21. data/test-unit/html/developer.svg +469 -0
  22. data/test-unit/html/favicon.ico +0 -0
  23. data/test-unit/html/favicon.svg +82 -0
  24. data/test-unit/html/heading-mark.svg +393 -0
  25. data/test-unit/html/index.html +235 -13
  26. data/test-unit/html/index.html.ja +258 -15
  27. data/test-unit/html/install.svg +636 -0
  28. data/test-unit/html/logo.svg +483 -0
  29. data/test-unit/html/test-unit.css +339 -0
  30. data/test-unit/html/tutorial.svg +559 -0
  31. data/test-unit/lib/test/unit.rb +6 -1
  32. data/test-unit/lib/test/unit/assertions.rb +115 -11
  33. data/test-unit/lib/test/unit/autorunner.rb +5 -2
  34. data/test-unit/lib/test/unit/collector/load.rb +1 -1
  35. data/test-unit/lib/test/unit/color-scheme.rb +6 -2
  36. data/test-unit/lib/test/unit/diff.rb +17 -1
  37. data/test-unit/lib/test/unit/testcase.rb +7 -0
  38. data/test-unit/lib/test/unit/testresult.rb +34 -2
  39. data/test-unit/lib/test/unit/ui/console/testrunner.rb +9 -45
  40. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +2 -12
  41. data/test-unit/lib/test/unit/ui/testrunner.rb +25 -0
  42. data/test-unit/lib/test/unit/util/backtracefilter.rb +1 -0
  43. data/test-unit/lib/test/unit/util/output.rb +31 -0
  44. data/test-unit/lib/test/unit/version.rb +1 -1
  45. data/test-unit/test/test-color-scheme.rb +4 -2
  46. data/test-unit/test/test_assertions.rb +51 -5
  47. data/test-unit/test/ui/test_tap.rb +33 -0
  48. data/test-unit/test/util/test-output.rb +11 -0
  49. data/test/test-patricia-trie.rb +161 -0
  50. data/test/test-remote.rb +2 -1
  51. data/test/test-table-cursor.rb +35 -1
  52. metadata +26 -10
  53. 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
@@ -202,4 +202,165 @@ class PatriciaTrieTest < Test::Unit::TestCase
202
202
  assert_equal([],
203
203
  records.records.collect {|record| record["._key"]})
204
204
  end
205
+
206
+
207
+ def test_prefix_cursor
208
+ paths = Groonga::PatriciaTrie.create(:name => "Paths",
209
+ :key_type => 'ShortText')
210
+ root_path = paths.add('/')
211
+ tmp_path = paths.add('/tmp')
212
+ usr_bin_path = paths.add('/usr/bin')
213
+ usr_local_bin_path = paths.add('/usr/local/bin')
214
+
215
+ assert_prefix_cursor(["/usr/local/bin", "/usr/bin", "/tmp", "/"],
216
+ paths, "/", {:order => :desc})
217
+ assert_prefix_cursor(["/", "/tmp", "/usr/bin", "/usr/local/bin"],
218
+ paths, "/")
219
+ assert_prefix_cursor(["/usr/local/bin", "/usr/bin"],
220
+ paths, "/usr/local",
221
+ {:key_bytes => "/usr".size, :order => :desc})
222
+ assert_prefix_cursor(["/tmp", "/usr/bin"],
223
+ paths, "/",
224
+ {:offset => 1, :limit => 2})
225
+ end
226
+
227
+ def assert_prefix_cursor(expected, tables, prefix, options={})
228
+ actual = []
229
+ tables.open_prefix_cursor(prefix, options) do |cursor|
230
+ cursor.each do |record|
231
+ actual << record.key
232
+ end
233
+ end
234
+ assert_equal(expected, actual)
235
+ end
236
+
237
+ def test_rk_cursor
238
+ terms = Groonga::PatriciaTrie.create(:name => "Terms",
239
+ :key_type => 'ShortText')
240
+ ["インデックス",
241
+ "エヌグラム",
242
+ "エンジン",
243
+ "カネソナエタ",
244
+ "カノウ",
245
+ "キノウ",
246
+ "キョウカ",
247
+ "クミコミ",
248
+ "クミコム",
249
+ "グルンガ",
250
+ "ケンサク",
251
+ "ケンサクヨウキュウ",
252
+ "ゲンゴ",
253
+ "コウセイド",
254
+ "コウソク",
255
+ "コンパクト",
256
+ "サクセイ",
257
+ "ショリ",
258
+ "ショリケイ",
259
+ "ジッソウ",
260
+ "ジュンスイ",
261
+ "スクリプト",
262
+ "セッケイ",
263
+ "ゼンブン",
264
+ "タイプ",
265
+ "タンゴ",
266
+ "ダイキボ",
267
+ "テンチ",
268
+ "ディービーエムエス",
269
+ "トウ",
270
+ "トクチョウ",
271
+ "ブンショリョウ",
272
+ "ヨウキュウ"].each do |term|
273
+ terms.add(term)
274
+ end
275
+
276
+ assert_rk_cursor(["カネソナエタ",
277
+ "カノウ",
278
+ "キノウ",
279
+ "キョウカ",
280
+ "クミコミ",
281
+ "クミコム",
282
+ "ケンサク",
283
+ "ケンサクヨウキュウ",
284
+ "コウセイド",
285
+ "コウソク",
286
+ "コンパクト"],
287
+ terms, "k")
288
+ end
289
+
290
+ def assert_rk_cursor(expected, tables, prefix, options={})
291
+ actual = []
292
+ tables.open_rk_cursor(prefix, options) do |cursor|
293
+ cursor.each do |record|
294
+ actual << record.key
295
+ end
296
+ end
297
+ assert_equal(expected, actual.sort)
298
+ end
299
+
300
+ def test_near_cursor
301
+ points = Groonga::PatriciaTrie.create(:name => "Points",
302
+ :key_type => 'WGS84GeoPoint')
303
+ ["130322053x504985073",
304
+ "130285021x504715091",
305
+ "130117012x504390088",
306
+ "130335016x504662007",
307
+ "130308044x504536008",
308
+ "130306053x504530043",
309
+ "130205016x505331054",
310
+ "130222054x505270050",
311
+ "130255017x504266011",
312
+ "130239038x504251015",
313
+ "129885039x503653023",
314
+ "129809022x504597055",
315
+ "130015001x504266057",
316
+ "130089012x505045070",
317
+ "130208017x504315098",
318
+ "130347036x504325073",
319
+ "130380061x505202034",
320
+ "129903045x504648034",
321
+ "130094061x505025099",
322
+ "130133052x505120058",
323
+ "130329069x505188046",
324
+ "130226001x503769013",
325
+ "129866001x504328017",
326
+ "129786048x504792049",
327
+ "129845056x504853081",
328
+ "130055008x504968095",
329
+ "130086003x504480071",
330
+ "129680021x504441006",
331
+ "129855010x504452003",
332
+ "130280013x505208029",
333
+ "129721099x504685024",
334
+ "129690039x504418033",
335
+ "130019020x505027021",
336
+ "130046026x505082073",
337
+ "130038025x505066028",
338
+ "129917001x504675017"].each do |point|
339
+ points.add(point)
340
+ end
341
+
342
+ assert_near_cursor(["129680021x504441006",
343
+ "129690039x504418033",
344
+ "129721099x504685024",
345
+ "129786048x504792049",
346
+ "129809022x504597055",
347
+ "129845056x504853081",
348
+ "129855010x504452003",
349
+ "129866001x504328017",
350
+ "129885039x503653023",
351
+ "129903045x504648034"],
352
+ points,
353
+ "129786048x504792049",
354
+ {:limit => 10})
355
+ end
356
+
357
+ def assert_near_cursor(expected, tables, prefix, options={})
358
+ actual = []
359
+ tables.open_near_cursor(prefix, options) do |cursor|
360
+ cursor.each do |record|
361
+ actual << record.key
362
+ end
363
+ end
364
+ assert_equal(expected, actual)
365
+ end
205
366
  end