From fce7467e601e76d64a175929f2f14f89cfd450dd Mon Sep 17 00:00:00 2001 From: akr Date: Tue, 21 Jan 2003 05:51:41 +0000 Subject: [PATCH] * lib/pp.rb: Use Test::Unit. * lib/prettyprint.rb: Ditto * lib/time.rb: Ditto * lib/tsort.rb: Ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3383 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 10 ++++ lib/pp.rb | 43 ++++++++++++---- lib/prettyprint.rb | 19 +++---- lib/time.rb | 122 ++++++++++++++++++++++----------------------- lib/tsort.rb | 8 ++- 5 files changed, 113 insertions(+), 89 deletions(-) diff --git a/ChangeLog b/ChangeLog index e64ec0c33a..b889af8da8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Tue Jan 21 14:46:12 2003 Tanaka Akira + + * lib/pp.rb: Use Test::Unit. + + * lib/prettyprint.rb: Ditto + + * lib/time.rb: Ditto + + * lib/tsort.rb: Ditto + Tue Jan 21 04:15:50 2003 Tanaka Akira * lib/pp.rb: Use redefined `to_s' as well as `inspect'. diff --git a/lib/pp.rb b/lib/pp.rb index 94a5aa18b5..b14611ff05 100644 --- a/lib/pp.rb +++ b/lib/pp.rb @@ -423,10 +423,9 @@ end } if __FILE__ == $0 - require 'runit/testcase' - require 'runit/cui/testrunner' + require 'test/unit' - class PPTest < RUNIT::TestCase + class PPTest < Test::Unit::TestCase def test_list0123_12 assert_equal("[0, 1, 2, 3]\n", PP.pp([0,1,2,3], '', 12)) end @@ -474,7 +473,15 @@ if __FILE__ == $0 end end - class PPInspectTest < RUNIT::TestCase + class PrettyPrintInspect < HasPrettyPrint + alias inspect pretty_print_inspect + end + + class PrettyPrintInspectWithoutPrettyPrint + alias inspect pretty_print_inspect + end + + class PPInspectTest < Test::Unit::TestCase def test_hasinspect a = HasInspect.new(1) assert_equal("\n", PP.pp(a, '')) @@ -489,9 +496,21 @@ if __FILE__ == $0 a = HasBoth.new(1) assert_equal("\n", PP.pp(a, '')) end + + def test_pretty_print_inspect + a = PrettyPrintInspect.new(1) + assert_equal("", a.inspect) + a = PrettyPrintInspectWithoutPrettyPrint.new + assert_raises(RuntimeError) { a.inspect } + end + + def test_proc + a = proc {1} + assert_equal("#{a.inspect}\n", PP.pp(a, '')) + end end - class PPCycleTest < RUNIT::TestCase + class PPCycleTest < Test::Unit::TestCase def test_array a = [] a << a @@ -522,9 +541,15 @@ if __FILE__ == $0 a << HasInspect.new(a) assert_equal("[]\n", PP.pp(a, '')) end - end - RUNIT::CUI::TestRunner.run(PPTest.suite) - RUNIT::CUI::TestRunner.run(PPInspectTest.suite) - RUNIT::CUI::TestRunner.run(PPCycleTest.suite) + def test_share_nil + begin + PP.sharing_detection = true + a = [nil, nil] + assert_equal("[nil, nil]\n", PP.pp(a, '')) + ensure + PP.sharing_detection = false + end + end + end end diff --git a/lib/prettyprint.rb b/lib/prettyprint.rb index 7f1497b541..f7b9bbdf5f 100644 --- a/lib/prettyprint.rb +++ b/lib/prettyprint.rb @@ -392,10 +392,9 @@ class PrettyPrint end if __FILE__ == $0 - require 'runit/testcase' - require 'runit/cui/testrunner' + require 'test/unit' - class WadlerExample < RUNIT::TestCase + class WadlerExample < Test::Unit::TestCase def setup @tree = Tree.new("aaaa", Tree.new("bbbbb", Tree.new("ccc"), Tree.new("dd")), @@ -632,7 +631,7 @@ End end end - class StrictPrettyExample < RUNIT::TestCase + class StrictPrettyExample < Test::Unit::TestCase def prog(width) PrettyPrint.format('', width) {|pp| pp.group { @@ -777,7 +776,7 @@ End end - class TailGroup < RUNIT::TestCase + class TailGroup < Test::Unit::TestCase def test_1 out = PrettyPrint.format('', 10) {|pp| pp.group { @@ -797,7 +796,7 @@ End end end - class NonString < RUNIT::TestCase + class NonString < Test::Unit::TestCase def format(width) PrettyPrint.format([], width, 'newline', lambda {|n| "#{n} spaces"}) {|pp| pp.text(3, 3) @@ -816,7 +815,7 @@ End end - class Fill < RUNIT::TestCase + class Fill < Test::Unit::TestCase def format(width) PrettyPrint.format('', width) {|pp| pp.group { @@ -907,10 +906,4 @@ End end end - - RUNIT::CUI::TestRunner.run(WadlerExample.suite) - RUNIT::CUI::TestRunner.run(StrictPrettyExample.suite) - RUNIT::CUI::TestRunner.run(TailGroup.suite) - RUNIT::CUI::TestRunner.run(NonString.suite) - RUNIT::CUI::TestRunner.run(Fill.suite) end diff --git a/lib/time.rb b/lib/time.rb index bc1147104b..ac0d36cad6 100644 --- a/lib/time.rb +++ b/lib/time.rb @@ -388,10 +388,9 @@ class Time end if __FILE__ == $0 - require 'runit/testcase' - require 'runit/cui/testrunner' + require 'test/unit' - class TimeExtentionTest < RUNIT::TestCase + class TimeExtentionTest < Test::Unit::TestCase def test_rfc822 assert_equal(Time.utc(1976, 8, 26, 14, 30) + 4 * 3600, Time.rfc2822("26 Aug 76 14:30 EDT")) @@ -423,7 +422,7 @@ if __FILE__ == $0 Time.rfc2822("21 Nov 97 09:55:06 GMT")) assert_equal(Time.utc(1997, 11, 21, 9, 55, 6) + 6 * 3600, Time.rfc2822("Fri, 21 Nov 1997 09 : 55 : 06 -0600")) - assert_exception(ArgumentError) { + assert_raises(ArgumentError) { # inner comment is not supported. Time.rfc2822("Fri, 21 Nov 1997 09(comment): 55 : 06 -0600") } @@ -548,67 +547,66 @@ if __FILE__ == $0 def test_invalid # They were actually used in some web sites. - assert_exception(ArgumentError) { Time.httpdate("1 Dec 2001 10:23:57 GMT") } - assert_exception(ArgumentError) { Time.httpdate("Sat, 1 Dec 2001 10:25:42 GMT") } - assert_exception(ArgumentError) { Time.httpdate("Sat, 1-Dec-2001 10:53:55 GMT") } - assert_exception(ArgumentError) { Time.httpdate("Saturday, 01-Dec-2001 10:15:34 GMT") } - assert_exception(ArgumentError) { Time.httpdate("Saturday, 01-Dec-101 11:10:07 GMT") } - assert_exception(ArgumentError) { Time.httpdate("Fri, 30 Nov 2001 21:30:00 JST") } + assert_raises(ArgumentError) { Time.httpdate("1 Dec 2001 10:23:57 GMT") } + assert_raises(ArgumentError) { Time.httpdate("Sat, 1 Dec 2001 10:25:42 GMT") } + assert_raises(ArgumentError) { Time.httpdate("Sat, 1-Dec-2001 10:53:55 GMT") } + assert_raises(ArgumentError) { Time.httpdate("Saturday, 01-Dec-2001 10:15:34 GMT") } + assert_raises(ArgumentError) { Time.httpdate("Saturday, 01-Dec-101 11:10:07 GMT") } + assert_raises(ArgumentError) { Time.httpdate("Fri, 30 Nov 2001 21:30:00 JST") } # They were actually used in some mails. - assert_exception(ArgumentError) { Time.rfc2822("01-5-20") } - assert_exception(ArgumentError) { Time.rfc2822("7/21/00") } - assert_exception(ArgumentError) { Time.rfc2822("2001-8-28") } - assert_exception(ArgumentError) { Time.rfc2822("00-5-6 1:13:06") } - assert_exception(ArgumentError) { Time.rfc2822("2001-9-27 9:36:49") } - assert_exception(ArgumentError) { Time.rfc2822("2000-12-13 11:01:11") } - assert_exception(ArgumentError) { Time.rfc2822("2001/10/17 04:29:55") } - assert_exception(ArgumentError) { Time.rfc2822("9/4/2001 9:23:19 PM") } - assert_exception(ArgumentError) { Time.rfc2822("01 Nov 2001 09:04:31") } - assert_exception(ArgumentError) { Time.rfc2822("13 Feb 2001 16:4 GMT") } - assert_exception(ArgumentError) { Time.rfc2822("01 Oct 00 5:41:19 PM") } - assert_exception(ArgumentError) { Time.rfc2822("2 Jul 00 00:51:37 JST") } - assert_exception(ArgumentError) { Time.rfc2822("01 11 2001 06:55:57 -0500") } - assert_exception(ArgumentError) { Time.rfc2822("18 \343\366\356\341\370 2000") } - assert_exception(ArgumentError) { Time.rfc2822("Fri, Oct 2001 18:53:32") } - assert_exception(ArgumentError) { Time.rfc2822("Fri, 2 Nov 2001 03:47:54") } - assert_exception(ArgumentError) { Time.rfc2822("Fri, 27 Jul 2001 11.14.14 +0200") } - assert_exception(ArgumentError) { Time.rfc2822("Thu, 2 Nov 2000 04:13:53 -600") } - assert_exception(ArgumentError) { Time.rfc2822("Wed, 5 Apr 2000 22:57:09 JST") } - assert_exception(ArgumentError) { Time.rfc2822("Mon, 11 Sep 2000 19:47:33 00000") } - assert_exception(ArgumentError) { Time.rfc2822("Fri, 28 Apr 2000 20:40:47 +-900") } - assert_exception(ArgumentError) { Time.rfc2822("Fri, 19 Jan 2001 8:15:36 AM -0500") } - assert_exception(ArgumentError) { Time.rfc2822("Thursday, Sep 27 2001 7:42:35 AM EST") } - assert_exception(ArgumentError) { Time.rfc2822("3/11/2001 1:31:57 PM Pacific Daylight Time") } - assert_exception(ArgumentError) { Time.rfc2822("Mi, 28 Mrz 2001 11:51:36") } - assert_exception(ArgumentError) { Time.rfc2822("P, 30 sept 2001 23:03:14") } - assert_exception(ArgumentError) { Time.rfc2822("fr, 11 aug 2000 18:39:22") } - assert_exception(ArgumentError) { Time.rfc2822("Fr, 21 Sep 2001 17:44:03 -1000") } - assert_exception(ArgumentError) { Time.rfc2822("Mo, 18 Jun 2001 19:21:40 -1000") } - assert_exception(ArgumentError) { Time.rfc2822("l\366, 12 aug 2000 18:53:20") } - assert_exception(ArgumentError) { Time.rfc2822("l\366, 26 maj 2001 00:15:58") } - assert_exception(ArgumentError) { Time.rfc2822("Dom, 30 Sep 2001 17:36:30") } - assert_exception(ArgumentError) { Time.rfc2822("%&, 31 %2/ 2000 15:44:47 -0500") } - assert_exception(ArgumentError) { Time.rfc2822("dom, 26 ago 2001 03:57:07 -0300") } - assert_exception(ArgumentError) { Time.rfc2822("ter, 04 set 2001 16:27:58 -0300") } - assert_exception(ArgumentError) { Time.rfc2822("Wen, 3 oct 2001 23:17:49 -0400") } - assert_exception(ArgumentError) { Time.rfc2822("Wen, 3 oct 2001 23:17:49 -0400") } - assert_exception(ArgumentError) { Time.rfc2822("ele, 11 h: 2000 12:42:15 -0500") } - assert_exception(ArgumentError) { Time.rfc2822("Tue, 14 Aug 2001 3:55:3 +0200") } - assert_exception(ArgumentError) { Time.rfc2822("Fri, 25 Aug 2000 9:3:48 +0800") } - assert_exception(ArgumentError) { Time.rfc2822("Fri, 1 Dec 2000 0:57:50 EST") } - assert_exception(ArgumentError) { Time.rfc2822("Mon, 7 May 2001 9:39:51 +0200") } - assert_exception(ArgumentError) { Time.rfc2822("Wed, 1 Aug 2001 16:9:15 +0200") } - assert_exception(ArgumentError) { Time.rfc2822("Wed, 23 Aug 2000 9:17:36 +0800") } - assert_exception(ArgumentError) { Time.rfc2822("Fri, 11 Aug 2000 10:4:42 +0800") } - assert_exception(ArgumentError) { Time.rfc2822("Sat, 15 Sep 2001 13:22:2 +0300") } - assert_exception(ArgumentError) { Time.rfc2822("Wed,16 \276\305\324\302 2001 20:06:25 +0800") } - assert_exception(ArgumentError) { Time.rfc2822("Wed,7 \312\256\322\273\324\302 2001 23:47:22 +0800") } - assert_exception(ArgumentError) { Time.rfc2822("=?iso-8859-1?Q?(=C5=DA),?= 10 2 2001 23:32:26 +0900 (JST)") } - assert_exception(ArgumentError) { Time.rfc2822("\307\341\314\343\332\311, 30 \344\346\335\343\310\321 2001 10:01:06") } - assert_exception(ArgumentError) { Time.rfc2822("=?iso-8859-1?Q?(=BF=E5),?= 12 =?iso-8859-1?Q?9=B7=EE?= 2001 14:52:41\n+0900 (JST)") } + assert_raises(ArgumentError) { Time.rfc2822("01-5-20") } + assert_raises(ArgumentError) { Time.rfc2822("7/21/00") } + assert_raises(ArgumentError) { Time.rfc2822("2001-8-28") } + assert_raises(ArgumentError) { Time.rfc2822("00-5-6 1:13:06") } + assert_raises(ArgumentError) { Time.rfc2822("2001-9-27 9:36:49") } + assert_raises(ArgumentError) { Time.rfc2822("2000-12-13 11:01:11") } + assert_raises(ArgumentError) { Time.rfc2822("2001/10/17 04:29:55") } + assert_raises(ArgumentError) { Time.rfc2822("9/4/2001 9:23:19 PM") } + assert_raises(ArgumentError) { Time.rfc2822("01 Nov 2001 09:04:31") } + assert_raises(ArgumentError) { Time.rfc2822("13 Feb 2001 16:4 GMT") } + assert_raises(ArgumentError) { Time.rfc2822("01 Oct 00 5:41:19 PM") } + assert_raises(ArgumentError) { Time.rfc2822("2 Jul 00 00:51:37 JST") } + assert_raises(ArgumentError) { Time.rfc2822("01 11 2001 06:55:57 -0500") } + assert_raises(ArgumentError) { Time.rfc2822("18 \343\366\356\341\370 2000") } + assert_raises(ArgumentError) { Time.rfc2822("Fri, Oct 2001 18:53:32") } + assert_raises(ArgumentError) { Time.rfc2822("Fri, 2 Nov 2001 03:47:54") } + assert_raises(ArgumentError) { Time.rfc2822("Fri, 27 Jul 2001 11.14.14 +0200") } + assert_raises(ArgumentError) { Time.rfc2822("Thu, 2 Nov 2000 04:13:53 -600") } + assert_raises(ArgumentError) { Time.rfc2822("Wed, 5 Apr 2000 22:57:09 JST") } + assert_raises(ArgumentError) { Time.rfc2822("Mon, 11 Sep 2000 19:47:33 00000") } + assert_raises(ArgumentError) { Time.rfc2822("Fri, 28 Apr 2000 20:40:47 +-900") } + assert_raises(ArgumentError) { Time.rfc2822("Fri, 19 Jan 2001 8:15:36 AM -0500") } + assert_raises(ArgumentError) { Time.rfc2822("Thursday, Sep 27 2001 7:42:35 AM EST") } + assert_raises(ArgumentError) { Time.rfc2822("3/11/2001 1:31:57 PM Pacific Daylight Time") } + assert_raises(ArgumentError) { Time.rfc2822("Mi, 28 Mrz 2001 11:51:36") } + assert_raises(ArgumentError) { Time.rfc2822("P, 30 sept 2001 23:03:14") } + assert_raises(ArgumentError) { Time.rfc2822("fr, 11 aug 2000 18:39:22") } + assert_raises(ArgumentError) { Time.rfc2822("Fr, 21 Sep 2001 17:44:03 -1000") } + assert_raises(ArgumentError) { Time.rfc2822("Mo, 18 Jun 2001 19:21:40 -1000") } + assert_raises(ArgumentError) { Time.rfc2822("l\366, 12 aug 2000 18:53:20") } + assert_raises(ArgumentError) { Time.rfc2822("l\366, 26 maj 2001 00:15:58") } + assert_raises(ArgumentError) { Time.rfc2822("Dom, 30 Sep 2001 17:36:30") } + assert_raises(ArgumentError) { Time.rfc2822("%&, 31 %2/ 2000 15:44:47 -0500") } + assert_raises(ArgumentError) { Time.rfc2822("dom, 26 ago 2001 03:57:07 -0300") } + assert_raises(ArgumentError) { Time.rfc2822("ter, 04 set 2001 16:27:58 -0300") } + assert_raises(ArgumentError) { Time.rfc2822("Wen, 3 oct 2001 23:17:49 -0400") } + assert_raises(ArgumentError) { Time.rfc2822("Wen, 3 oct 2001 23:17:49 -0400") } + assert_raises(ArgumentError) { Time.rfc2822("ele, 11 h: 2000 12:42:15 -0500") } + assert_raises(ArgumentError) { Time.rfc2822("Tue, 14 Aug 2001 3:55:3 +0200") } + assert_raises(ArgumentError) { Time.rfc2822("Fri, 25 Aug 2000 9:3:48 +0800") } + assert_raises(ArgumentError) { Time.rfc2822("Fri, 1 Dec 2000 0:57:50 EST") } + assert_raises(ArgumentError) { Time.rfc2822("Mon, 7 May 2001 9:39:51 +0200") } + assert_raises(ArgumentError) { Time.rfc2822("Wed, 1 Aug 2001 16:9:15 +0200") } + assert_raises(ArgumentError) { Time.rfc2822("Wed, 23 Aug 2000 9:17:36 +0800") } + assert_raises(ArgumentError) { Time.rfc2822("Fri, 11 Aug 2000 10:4:42 +0800") } + assert_raises(ArgumentError) { Time.rfc2822("Sat, 15 Sep 2001 13:22:2 +0300") } + assert_raises(ArgumentError) { Time.rfc2822("Wed,16 \276\305\324\302 2001 20:06:25 +0800") } + assert_raises(ArgumentError) { Time.rfc2822("Wed,7 \312\256\322\273\324\302 2001 23:47:22 +0800") } + assert_raises(ArgumentError) { Time.rfc2822("=?iso-8859-1?Q?(=C5=DA),?= 10 2 2001 23:32:26 +0900 (JST)") } + assert_raises(ArgumentError) { Time.rfc2822("\307\341\314\343\332\311, 30 \344\346\335\343\310\321 2001 10:01:06") } + assert_raises(ArgumentError) { Time.rfc2822("=?iso-8859-1?Q?(=BF=E5),?= 12 =?iso-8859-1?Q?9=B7=EE?= 2001 14:52:41\n+0900 (JST)") } end end - RUNIT::CUI::TestRunner.run(TimeExtentionTest.suite) end diff --git a/lib/tsort.rb b/lib/tsort.rb index 21adeaabfe..7832030792 100644 --- a/lib/tsort.rb +++ b/lib/tsort.rb @@ -245,8 +245,7 @@ module TSort end if __FILE__ == $0 - require 'runit/testcase' - require 'runit/cui/testrunner' + require 'test/unit' class Hash include TSort @@ -264,7 +263,7 @@ if __FILE__ == $0 end end - class TSortTest < RUNIT::TestCase + class TSortTest < Test::Unit::TestCase def test_dag h = {1=>[2, 3], 2=>[3], 3=>[]} assert_equal([3, 2, 1], h.tsort) @@ -275,7 +274,7 @@ if __FILE__ == $0 h = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]} assert_equal([[4], [2, 3], [1]], h.strongly_connected_components.map {|nodes| nodes.sort}) - assert_exception(TSort::Cyclic) { h.tsort } + assert_raises(TSort::Cyclic) { h.tsort } end def test_array @@ -289,6 +288,5 @@ if __FILE__ == $0 end end - RUNIT::CUI::TestRunner.run(TSortTest.suite) end