yarv-diff:166
From: ko1 atdot.net
Date: 25 Dec 2005 17:07:45 -0000
Subject: [yarv-diff:166] r325 - in trunk: . test test/ruby
Author: aamine
Date: 2005-12-26 02:07:45 +0900 (Mon, 26 Dec 2005)
New Revision: 325
Added:
trunk/test/ruby/
trunk/test/ruby/test_alias.rb
trunk/test/ruby/test_assignment.rb
trunk/test/ruby/test_bignum.rb
trunk/test/ruby/test_call.rb
trunk/test/ruby/test_case.rb
trunk/test/ruby/test_clone.rb
trunk/test/ruby/test_condition.rb
trunk/test/ruby/test_const.rb
trunk/test/ruby/test_defined.rb
trunk/test/ruby/test_eval.rb
trunk/test/ruby/test_exception.rb
trunk/test/ruby/test_gc.rb
trunk/test/ruby/test_ifunless.rb
trunk/test/ruby/test_iterator.rb
trunk/test/ruby/test_lambda.rb
trunk/test/ruby/test_method.rb
trunk/test/ruby/test_proc.rb
trunk/test/ruby/test_super.rb
trunk/test/ruby/test_trace.rb
trunk/test/ruby/test_variable.rb
trunk/test/ruby/test_whileuntil.rb
trunk/test/runner.rb
Modified:
trunk/ChangeLog
Log:
* test/runner.rb: new file.
* test/ruby/OFF.test_symbol.rb: new file.
* test/ruby/SEGV.test_alias.rb: new file.
* test/ruby/SEGV.test_clone.rb: new file.
* test/ruby/SEGV.test_eval.rb: new file.
* test/ruby/SEGV.test_iterator.rb: new file.
* test/ruby/SEGV.test_lambda.rb: new file.
* test/ruby/SEGV.test_proc.rb: new file.
* test/ruby/SEGV.test_super.rb: new file.
* test/ruby/UNIMPL.test_settracefunc.rb: new file.
* test/ruby/test_assignment.rb: new file.
* test/ruby/test_bignum.rb: new file.
* test/ruby/test_call.rb: new file.
* test/ruby/test_case.rb: new file.
* test/ruby/test_condition.rb: new file.
* test/ruby/test_const.rb: new file.
* test/ruby/test_defined.rb: new file.
* test/ruby/test_exception.rb: new file.
* test/ruby/test_gc.rb: new file.
* test/ruby/test_ifunless.rb: new file.
* test/ruby/test_method.rb: new file.
* test/ruby/test_trace.rb: new file.
* test/ruby/test_variable.rb: new file.
* test/ruby/test_whileuntil.rb: new file.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2005-12-24 22:44:12 UTC (rev 324)
+++ trunk/ChangeLog 2005-12-25 17:07:45 UTC (rev 325)
@@ -4,6 +4,53 @@
# from Mon, 03 May 2004 01:24:19 +0900
#
+2005-12-26(Mon) 02:00:11 +0900 Minero Aoki <aamine loveruby.net>
+
+ * test/runner.rb: new file.
+
+ * test/ruby/test_alias.rb: new file.
+
+ * test/ruby/test_clone.rb: new file.
+
+ * test/ruby/test_eval.rb: new file.
+
+ * test/ruby/test_iterator.rb: new file.
+
+ * test/ruby/test_lambda.rb: new file.
+
+ * test/ruby/test_proc.rb: new file.
+
+ * test/ruby/test_super.rb: new file.
+
+ * test/ruby/test_assignment.rb: new file.
+
+ * test/ruby/test_bignum.rb: new file.
+
+ * test/ruby/test_call.rb: new file.
+
+ * test/ruby/test_case.rb: new file.
+
+ * test/ruby/test_condition.rb: new file.
+
+ * test/ruby/test_const.rb: new file.
+
+ * test/ruby/test_defined.rb: new file.
+
+ * test/ruby/test_exception.rb: new file.
+
+ * test/ruby/test_gc.rb: new file.
+
+ * test/ruby/test_ifunless.rb: new file.
+
+ * test/ruby/test_method.rb: new file.
+
+ * test/ruby/test_trace.rb: new file.
+
+ * test/ruby/test_variable.rb: new file.
+
+ * test/ruby/test_whileuntil.rb: new file.
+
+
2005-12-25(Sun) 07:40:08 +0900 Koichi Sasada <ko1 atdot.net>
* blockinlining.c, compile.c : fix block inlining
Added: trunk/test/ruby/test_alias.rb
===================================================================
--- trunk/test/ruby/test_alias.rb 2005-12-24 22:44:12 UTC (rev 324)
+++ trunk/test/ruby/test_alias.rb 2005-12-25 17:07:45 UTC (rev 325)
@@ -0,0 +1,40 @@
+require 'test/unit'
+
+class TestAlias < Test::Unit::TestCase
+ class Alias0
+ def foo; "foo" end
+ end
+ class Alias1<Alias0
+ alias bar foo
+ def foo; "foo+" + super end
+ end
+ class Alias2<Alias1
+ alias baz foo
+ undef foo
+ end
+ class Alias3<Alias2
+ def foo
+ defined? super
+ end
+ def bar
+ defined? super
+ end
+ def quux
+ defined? super
+ end
+ end
+
+ def test_alias
+ x = Alias2.new
+ assert_equal("foo", x.bar)
+ assert_equal("foo+foo", x.baz)
+
+ # test_check for cache
+ assert_equal("foo+foo", x.baz)
+
+ x = Alias3.new
+ assert(!x.foo)
+ assert(x.bar)
+ assert(!x.quux)
+ end
+end
Added: trunk/test/ruby/test_assignment.rb
===================================================================
--- trunk/test/ruby/test_assignment.rb 2005-12-24 22:44:12 UTC (rev 324)
+++ trunk/test/ruby/test_assignment.rb 2005-12-25 17:07:45 UTC (rev 325)
@@ -0,0 +1,411 @@
+require 'test/unit'
+
+class TestAssignment < Test::Unit::TestCase
+ def test_assign
+ a=[]; a[0] ||= "bar";
+ assert_equal("bar", a[0])
+ h={}; h["foo"] ||= "bar";
+ assert_equal("bar", h["foo"])
+
+ aa = 5
+ aa ||= 25
+ assert_equal(5, aa)
+ bb ||= 25
+ assert_equal(25, bb)
+ cc &&=33
+ assert_nil(cc)
+ cc = 5
+ cc &&=44
+ assert_equal(44, cc)
+
+ a = nil; assert_nil(a)
+ a = 1; assert_equal(1, a)
+ a = []; assert_equal([], a)
+ a = [1]; assert_equal([1], a)
+ a = [nil]; assert_equal([nil], a)
+ a = [[]]; assert_equal([[]], a)
+ a = [1,2]; assert_equal([1,2], a)
+ a = [*[]]; assert_equal([], a)
+ a = [*[1]]; assert_equal([1], a)
+ a = [*[1,2]]; assert_equal([1,2], a)
+
+ a = *[]; assert_nil(a)
+ a = *[1]; assert_equal(1, a)
+ a = *[nil]; assert_nil(a)
+ a = *[[]]; assert_equal([], a)
+ a = *[1,2]; assert_equal([1,2], a)
+ a = *[*[]]; assert_nil(a)
+ a = *[*[1]]; assert_equal(1, a)
+ a = *[*[1,2]]; assert_equal([1,2], a)
+
+ *a = nil; assert_equal([nil], a)
+ *a = 1; assert_equal([1], a)
+ *a = []; assert_equal([[]], a)
+ *a = [1]; assert_equal([[1]], a)
+ *a = [nil]; assert_equal([[nil]], a)
+ *a = [[]]; assert_equal([[[]]], a)
+ *a = [1,2]; assert_equal([[1,2]], a)
+ *a = [*[]]; assert_equal([[]], a)
+ *a = [*[1]]; assert_equal([[1]], a)
+ *a = [*[1,2]]; assert_equal([[1,2]], a)
+
+ *a = *[]; assert_equal([], a)
+ *a = *[1]; assert_equal([1], a)
+ *a = *[nil]; assert_equal([nil], a)
+ *a = *[[]]; assert_equal([[]], a)
+ *a = *[1,2]; assert_equal([1,2], a)
+ *a = *[*[]]; assert_equal([], a)
+ *a = *[*[1]]; assert_equal([1], a)
+ *a = *[*[1,2]]; assert_equal([1,2], a)
+
+ a,b,*c = nil; assert_equal([nil,nil,[]], [a,b,c])
+ a,b,*c = 1; assert_equal([1,nil,[]], [a,b,c])
+ a,b,*c = []; assert_equal([nil,nil,[]], [a,b,c])
+ a,b,*c = [1]; assert_equal([1,nil,[]], [a,b,c])
+ a,b,*c = [nil]; assert_equal([nil,nil,[]], [a,b,c])
+ a,b,*c = [[]]; assert_equal([[],nil,[]], [a,b,c])
+ a,b,*c = [1,2]; assert_equal([1,2,[]], [a,b,c])
+ a,b,*c = [*[]]; assert_equal([nil,nil,[]], [a,b,c])
+ a,b,*c = [*[1]]; assert_equal([1,nil,[]], [a,b,c])
+ a,b,*c = [*[1,2]]; assert_equal([1,2,[]], [a,b,c])
+
+ a,b,*c = *[]; assert_equal([nil,nil,[]], [a,b,c])
+ a,b,*c = *[1]; assert_equal([1,nil,[]], [a,b,c])
+ a,b,*c = *[nil]; assert_equal([nil,nil,[]], [a,b,c])
+ a,b,*c = *[[]]; assert_equal([[],nil,[]], [a,b,c])
+ a,b,*c = *[1,2]; assert_equal([1,2,[]], [a,b,c])
+ a,b,*c = *[*[]]; assert_equal([nil,nil,[]], [a,b,c])
+ a,b,*c = *[*[1]]; assert_equal([1,nil,[]], [a,b,c])
+ a,b,*c = *[*[1,2]]; assert_equal([1,2,[]], [a,b,c])
+ end
+
+ def test_yield
+ def f; yield(nil); end; f {|a| assert_nil(a)}; undef f
+ def f; yield(1); end; f {|a| assert_equal(1, a)}; undef f
+ def f; yield([]); end; f {|a| assert_equal([], a)}; undef f
+ def f; yield([1]); end; f {|a| assert_equal([1], a)}; undef f
+ def f; yield([nil]); end; f {|a| assert_equal([nil], a)}; undef f
+ def f; yield([[]]); end; f {|a| assert_equal([[]], a)}; undef f
+ def f; yield([*[]]); end; f {|a| assert_equal([], a)}; undef f
+ def f; yield([*[1]]); end; f {|a| assert_equal([1], a)}; undef f
+ def f; yield([*[1,2]]); end; f {|a| assert_equal([1,2], a)}; undef f
+
+ def f; yield(*[1]); end; f {|a| assert_equal(1, a)}; undef f
+ def f; yield(*[nil]); end; f {|a| assert_nil(a)}; undef f
+ def f; yield(*[[]]); end; f {|a| assert_equal([], a)}; undef f
+ def f; yield(*[*[1]]); end; f {|a| assert_equal(1, a)}; undef f
+
+ def f; yield; end; f {|*a| assert_equal([], a)}; undef f
+ def f; yield(nil); end; f {|*a| assert_equal([nil], a)}; undef f
+ def f; yield(1); end; f {|*a| assert_equal([1], a)}; undef f
+ def f; yield([]); end; f {|*a| assert_equal([[]], a)}; undef f
+ def f; yield([1]); end; f {|*a| assert_equal([[1]], a)}; undef f
+ def f; yield([nil]); end; f {|*a| assert_equal([[nil]], a)}; undef f
+ def f; yield([[]]); end; f {|*a| assert_equal([[[]]], a)}; undef f
+ def f; yield([1,2]); end; f {|*a| assert_equal([[1,2]], a)}; undef f
+ def f; yield([*[]]); end; f {|*a| assert_equal([[]], a)}; undef f
+ def f; yield([*[1]]); end; f {|*a| assert_equal([[1]], a)}; undef f
+ def f; yield([*[1,2]]); end; f {|*a| assert_equal([[1,2]], a)}; undef f
+
+ def f; yield(*[]); end; f {|*a| assert_equal([], a)}; undef f
+ def f; yield(*[1]); end; f {|*a| assert_equal([1], a)}; undef f
+ def f; yield(*[nil]); end; f {|*a| assert_equal([nil], a)}; undef f
+ def f; yield(*[[]]); end; f {|*a| assert_equal([[]], a)}; undef f
+ def f; yield(*[*[]]); end; f {|*a| assert_equal([], a)}; undef f
+ def f; yield(*[*[1]]); end; f {|*a| assert_equal([1], a)}; undef f
+ def f; yield(*[*[1,2]]); end; f {|*a| assert_equal([1,2], a)}; undef f
+
+ def f; yield; end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}; undef f
+ def f; yield(nil); end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}; undef f
+ def f; yield(1); end; f {|a,b,*c| assert_equal([1,nil,[]], [a,b,c])}; undef f
+ def f; yield([]); end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}; undef f
+ def f; yield([1]); end; f {|a,b,*c| assert_equal([1,nil,[]], [a,b,c])}; undef f
+ def f; yield([nil]); end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}; undef f
+ def f; yield([[]]); end; f {|a,b,*c| assert_equal([[],nil,[]], [a,b,c])}; undef f
+ def f; yield([*[]]); end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}; undef f
+ def f; yield([*[1]]); end; f {|a,b,*c| assert_equal([1,nil,[]], [a,b,c])}; undef f
+ def f; yield([*[1,2]]); end; f {|a,b,*c| assert_equal([1,2,[]], [a,b,c])}; undef f
+
+ def f; yield(*[]); end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}; undef f
+ def f; yield(*[1]); end; f {|a,b,*c| assert_equal([1,nil,[]], [a,b,c])}; undef f
+ def f; yield(*[nil]); end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}; undef f
+ def f; yield(*[[]]); end; f {|a,b,*c| assert_equal([[],nil,[]], [a,b,c])}; undef f
+ def f; yield(*[*[]]); end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}; undef f
+ def f; yield(*[*[1]]); end; f {|a,b,*c| assert_equal([1,nil,[]], [a,b,c])}; undef f
+ def f; yield(*[*[1,2]]); end; f {|a,b,*c| assert_equal([1,2,[]], [a,b,c])}; undef f
+ end
+
+ def test_return
+ def r; return; end; a = r(); assert_nil(a); undef r
+ def r; return nil; end; a = r(); assert_nil(a); undef r
+ def r; return 1; end; a = r(); assert_equal(1, a); undef r
+ def r; return []; end; a = r(); assert_equal([], a); undef r
+ def r; return [1]; end; a = r(); assert_equal([1], a); undef r
+ def r; return [nil]; end; a = r(); assert_equal([nil], a); undef r
+ def r; return [[]]; end; a = r(); assert_equal([[]], a); undef r
+ def r; return [*[]]; end; a = r(); assert_equal([], a); undef r
+ def r; return [*[1]]; end; a = r(); assert_equal([1], a); undef r
+ def r; return [*[1,2]]; end; a = r(); assert_equal([1,2], a); undef r
+
+ def r; return *[]; end; a = r(); assert_nil(a); undef r
+ def r; return *[1]; end; a = r(); assert_equal(1, a); undef r
+ def r; return *[nil]; end; a = r(); assert_nil(a); undef r
+ def r; return *[[]]; end; a = r(); assert_equal([], a); undef r
+ def r; return *[*[]]; end; a = r(); assert_nil(a); undef r
+ def r; return *[*[1]]; end; a = r(); assert_equal(1, a); undef r
+ def r; return *[*[1,2]]; end; a = r(); assert_equal([1,2], a); undef r
+
+ def r; return *[[]]; end; a = *r(); assert_nil(a); undef r
+ def r; return *[*[1,2]]; end; a = *r(); assert_equal([1,2], a); undef r
+
+ def r; return; end; *a = r(); assert_equal([nil], a); undef r
+ def r; return nil; end; *a = r(); assert_equal([nil], a); undef r
+ def r; return 1; end; *a = r(); assert_equal([1], a); undef r
+ def r; return []; end; *a = r(); assert_equal([[]], a); undef r
+ def r; return [1]; end; *a = r(); assert_equal([[1]], a); undef r
+ def r; return [nil]; end; *a = r(); assert_equal([[nil]], a); undef r
+ def r; return [[]]; end; *a = r(); assert_equal([[[]]], a); undef r
+ def r; return [1,2]; end; *a = r(); assert_equal([[1,2]], a); undef r
+ def r; return [*[]]; end; *a = r(); assert_equal([[]], a); undef r
+ def r; return [*[1]]; end; *a = r(); assert_equal([[1]], a); undef r
+ def r; return [*[1,2]]; end; *a = r(); assert_equal([[1,2]], a); undef r
+
+ def r; return *[]; end; *a = r(); assert_equal([nil], a); undef r
+ def r; return *[1]; end; *a = r(); assert_equal([1], a); undef r
+ def r; return *[nil]; end; *a = r(); assert_equal([nil], a); undef r
+ def r; return *[[]]; end; *a = r(); assert_equal([[]], a); undef r
+ def r; return *[1,2]; end; *a = r(); assert_equal([[1,2]], a); undef r
+ def r; return *[*[]]; end; *a = r(); assert_equal([nil], a); undef r
+ def r; return *[*[1]]; end; *a = r(); assert_equal([1], a); undef r
+ def r; return *[*[1,2]]; end; *a = r(); assert_equal([[1,2]], a); undef r
+
+ def r; return *[[]]; end; *a = *r(); assert_equal([], a); undef r
+ def r; return *[1,2]; end; *a = *r(); assert_equal([1,2], a); undef r
+ def r; return *[*[1,2]]; end; *a = *r(); assert_equal([1,2], a); undef r
+
+ def r; return; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c]); undef r
+ def r; return nil; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c]); undef r
+ def r; return 1; end; a,b,*c = r(); assert_equal([1,nil,[]], [a,b,c]); undef r
+ def r; return []; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c]); undef r
+ def r; return [1]; end; a,b,*c = r(); assert_equal([1,nil,[]], [a,b,c]); undef r
+ def r; return [nil]; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c]); undef r
+ def r; return [[]]; end; a,b,*c = r(); assert_equal([[],nil,[]], [a,b,c]); undef r
+ def r; return [1,2]; end; a,b,*c = r(); assert_equal([1,2,[]], [a,b,c]); undef r
+ def r; return [*[]]; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c]); undef r
+ def r; return [*[1]]; end; a,b,*c = r(); assert_equal([1,nil,[]], [a,b,c]); undef r
+ def r; return [*[1,2]]; end; a,b,*c = r(); assert_equal([1,2,[]], [a,b,c]); undef r
+
+ def r; return *[]; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c]); undef r
+ def r; return *[1]; end; a,b,*c = r(); assert_equal([1,nil,[]], [a,b,c]); undef r
+ def r; return *[nil]; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c]); undef r
+ def r; return *[[]]; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c]); undef r
+ def r; return *[1,2]; end; a,b,*c = r(); assert_equal([1,2,[]], [a,b,c]); undef r
+ def r; return *[*[]]; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c]); undef r
+ def r; return *[*[1]]; end; a,b,*c = r(); assert_equal([1,nil,[]], [a,b,c]); undef r
+ def r; return *[*[1,2]]; end; a,b,*c = r(); assert_equal([1,2,[]], [a,b,c]); undef r
+ end
+
+ def test_lambda
+ f = lambda {|r,| assert_equal([], r)}
+ f.call([], *[])
+
+ f = lambda {|r,*l| assert_equal([], r); assert_equal([1], l)}
+ f.call([], *[1])
+
+ f = lambda{|x| x}
+ assert_equal(42, f.call(42))
+ assert_equal([42], f.call([42]))
+ assert_equal([[42]], f.call([[42]]))
+ assert_equal([42,55], f.call([42,55]))
+
+ f = lambda{|x,| x}
+ assert_equal(42, f.call(42))
+ assert_equal([42], f.call([42]))
+ assert_equal([[42]], f.call([[42]]))
+ assert_equal([42,55], f.call([42,55]))
+
+ f = lambda{|*x| x}
+ assert_equal([42], f.call(42))
+ assert_equal([[42]], f.call([42]))
+ assert_equal([[[42]]], f.call([[42]]))
+ assert_equal([[42,55]], f.call([42,55]))
+ assert_equal([42,55], f.call(42,55))
+ end
+
+ def test_multi
+ a,=*[1]
+ assert_equal(1, a)
+ a,=*[[1]]
+ assert_equal([1], a)
+ a,=*[[[1]]]
+ assert_equal([[1]], a)
+
+ x, (y, z) = 1, 2, 3
+ assert_equal([1,2,nil], [x,y,z])
+ x, (y, z) = 1, [2,3]
+ assert_equal([1,2,3], [x,y,z])
+ x, (y, z) = 1, [2]
+ assert_equal([1,2,nil], [x,y,z])
+ end
+
+ def test_break
+ a = loop do break; end; assert_nil(a)
+ a = loop do break nil; end; assert_nil(a)
+ a = loop do break 1; end; assert_equal(1, a)
+ a = loop do break []; end; assert_equal([], a)
+ a = loop do break [1]; end; assert_equal([1], a)
+ a = loop do break [nil]; end; assert_equal([nil], a)
+ a = loop do break [[]]; end; assert_equal([[]], a)
+ a = loop do break [*[]]; end; assert_equal([], a)
+ a = loop do break [*[1]]; end; assert_equal([1], a)
+ a = loop do break [*[1,2]]; end; assert_equal([1,2], a)
+
+ a = loop do break *[]; end; assert_nil(a)
+ a = loop do break *[1]; end; assert_equal(1, a)
+ a = loop do break *[nil]; end; assert_nil(a)
+ a = loop do break *[[]]; end; assert_equal([], a)
+ a = loop do break *[*[]]; end; assert_nil(a)
+ a = loop do break *[*[1]]; end; assert_equal(1, a)
+ a = loop do break *[*[1,2]]; end; assert_equal([1,2], a)
+
+ *a = loop do break; end; assert_equal([nil], a)
+ *a = loop do break nil; end; assert_equal([nil], a)
+ *a = loop do break 1; end; assert_equal([1], a)
+ *a = loop do break []; end; assert_equal([[]], a)
+ *a = loop do break [1]; end; assert_equal([[1]], a)
+ *a = loop do break [nil]; end; assert_equal([[nil]], a)
+ *a = loop do break [[]]; end; assert_equal([[[]]], a)
+ *a = loop do break [1,2]; end; assert_equal([[1,2]], a)
+ *a = loop do break [*[]]; end; assert_equal([[]], a)
+ *a = loop do break [*[1]]; end; assert_equal([[1]], a)
+ *a = loop do break [*[1,2]]; end; assert_equal([[1,2]], a)
+
+ *a = loop do break *[]; end; assert_equal([nil], a)
+ *a = loop do break *[1]; end; assert_equal([1], a)
+ *a = loop do break *[nil]; end; assert_equal([nil], a)
+ *a = loop do break *[[]]; end; assert_equal([[]], a)
+ *a = loop do break *[1,2]; end; assert_equal([[1,2]], a)
+ *a = loop do break *[*[]]; end; assert_equal([nil], a)
+ *a = loop do break *[*[1]]; end; assert_equal([1], a)
+ *a = loop do break *[*[1,2]]; end; assert_equal([[1,2]], a)
+
+ *a = *loop do break *[[]]; end; assert_equal([], a)
+ *a = *loop do break *[1,2]; end; assert_equal([1,2], a)
+ *a = *loop do break *[*[1,2]]; end; assert_equal([1,2], a)
+
+ a,b,*c = loop do break; end; assert_equal([nil,nil,[]], [a,b,c])
+ a,b,*c = loop do break nil; end; assert_equal([nil,nil,[]], [a,b,c])
+ a,b,*c = loop do break 1; end; assert_equal([1,nil,[]], [a,b,c])
+ a,b,*c = loop do break []; end; assert_equal([nil,nil,[]], [a,b,c])
+ a,b,*c = loop do break [1]; end; assert_equal([1,nil,[]], [a,b,c])
+ a,b,*c = loop do break [nil]; end; assert_equal([nil,nil,[]], [a,b,c])
+ a,b,*c = loop do break [[]]; end; assert_equal([[],nil,[]], [a,b,c])
+ a,b,*c = loop do break [1,2]; end; assert_equal([1,2,[]], [a,b,c])
+ a,b,*c = loop do break [*[]]; end; assert_equal([nil,nil,[]], [a,b,c])
+ a,b,*c = loop do break [*[1]]; end; assert_equal([1,nil,[]], [a,b,c])
+ a,b,*c = loop do break [*[1,2]]; end; assert_equal([1,2,[]], [a,b,c])
+
+ a,b,*c = loop do break *[]; end; assert_equal([nil,nil,[]], [a,b,c])
+ a,b,*c = loop do break *[1]; end; assert_equal([1,nil,[]], [a,b,c])
+ a,b,*c = loop do break *[nil]; end; assert_equal([nil,nil,[]], [a,b,c])
+ a,b,*c = loop do break *[[]]; end; assert_equal([nil,nil,[]], [a,b,c])
+ a,b,*c = loop do break *[1,2]; end; assert_equal([1,2,[]], [a,b,c])
+ a,b,*c = loop do break *[*[]]; end; assert_equal([nil,nil,[]], [a,b,c])
+ a,b,*c = loop do break *[*[1]]; end; assert_equal([1,nil,[]], [a,b,c])
+ a,b,*c = loop do break *[*[1,2]]; end; assert_equal([1,2,[]], [a,b,c])
+ end
+
+ def test_next
+ def r(val); a = yield(); assert_equal(val, a); end
+ r(nil){next}
+ r(nil){next nil}
+ r(1){next 1}
+ r([]){next []}
+ r([1]){next [1]}
+ r([nil]){next [nil]}
+ r([[]]){next [[]]}
+ r([]){next [*[]]}
+ r([1]){next [*[1]]}
+ r([1,2]){next [*[1,2]]}
+
+ r(nil){next *[]}
+ r(1){next *[1]}
+ r(nil){next *[nil]}
+ r([]){next *[[]]}
+ r(nil){next *[*[]]}
+ r(1){next *[*[1]]}
+ r([1,2]){next *[*[1,2]]}
+ undef r
+
+ def r(val); *a = yield(); assert_equal(val, a); end
+ r([nil]){next}
+ r([nil]){next nil}
+ r([1]){next 1}
+ r([[]]){next []}
+ r([[1]]){next [1]}
+ r([[nil]]){next [nil]}
+ r([[[]]]){next [[]]}
+ r([[1,2]]){next [1,2]}
+ r([[]]){next [*[]]}
+ r([[1]]){next [*[1]]}
+ r([[1,2]]){next [*[1,2]]}
+ undef r
+
+ def r(val); *a = *yield(); assert_equal(val, a); end
+ r([]){next *[[]]}
+ r([1,2]){next *[1,2]}
+ r([1,2]){next *[*[1,2]]}
+ undef r
+
+ def r(val); a,b,*c = yield(); assert_equal(val, [a,b,c]); end
+ r([nil,nil,[]]){next}
+ r([nil,nil,[]]){next nil}
+ r([1,nil,[]]){next 1}
+ r([nil,nil,[]]){next []}
+ r([1,nil,[]]){next [1]}
+ r([nil,nil,[]]){next [nil]}
+ r([[],nil,[]]){next [[]]}
+ r([1,2,[]]){next [1,2]}
+ r([nil,nil,[]]){next [*[]]}
+ r([1,nil,[]]){next [*[1]]}
+ r([1,2,[]]){next [*[1,2]]}
+ undef r
+
+ def r(val); a,b,*c = *yield(); assert_equal(val, [a,b,c]); end
+ r([nil,nil,[]]){next *[[]]}
+ r([1,2,[]]){next *[1,2]}
+ r([1,2,[]]){next *[*[1,2]]}
+ undef r
+ end
+
+ def test_assign2
+ a = nil
+ assert(defined?(a))
+ assert_nil(a)
+
+ # multiple asignment
+ a, b = 1, 2
+ assert(a == 1 && b == 2)
+
+ a, b = b, a
+ assert(a == 2 && b == 1)
+
+ a, = 1,2
+ assert_equal(1, a)
+
+ a, *b = 1, 2, 3
+ assert(a == 1 && b == [2, 3])
+
+ a, (b, c), d = 1, [2, 3], 4
+ assert(a == 1 && b == 2 && c == 3 && d == 4)
+
+ *a = 1, 2, 3
+ assert_equal([1, 2, 3], a)
+
+ *a = 4
+ assert_equal([4], a)
+
+ *a = nil
+ assert_equal([nil], a)
+ end
+end
Added: trunk/test/ruby/test_bignum.rb
===================================================================
--- trunk/test/ruby/test_bignum.rb 2005-12-24 22:44:12 UTC (rev 324)
+++ trunk/test/ruby/test_bignum.rb 2005-12-25 17:07:45 UTC (rev 325)
@@ -0,0 +1,87 @@
+require 'test/unit'
+
+class TestBignum < Test::Unit::TestCase
+ def fact(n)
+ return 1 if n == 0
+ f = 1
+ while n>0
+ f *= n
+ n -= 1
+ end
+ return f
+ end
+
+ def test_bignum
+ $x = fact(40)
+ assert_equal($x, $x)
+ assert_equal($x, fact(40))
+ assert($x < $x+2)
+ assert($x > $x-2)
+ assert_equal(815915283247897734345611269596115894272000000000, $x)
+ assert_not_equal(815915283247897734345611269596115894272000000001, $x)
+ assert_equal(815915283247897734345611269596115894272000000001, $x+1)
+ assert_equal(335367096786357081410764800000, $x/fact(20))
+ $x = -$x
+ assert_equal(-815915283247897734345611269596115894272000000000, $x)
+ assert_equal(2-(2**32), -(2**32-2))
+ assert_equal(2**32 - 5, (2**32-3)-2)
+
+ for i in 1000..1014
+ assert_equal(2 ** i, 1 << i)
+ end
+
+ n1 = 1 << 1000
+ for i in 1000..1014
+ assert_equal(n1, 1 << i)
+ n1 *= 2
+ end
+
+ n2=n1
+ for i in 1..10
+ n1 = n1 / 2
+ n2 = n2 >> 1
+ assert_equal(n1, n2)
+ end
+
+ for i in 4000..4096
+ n1 = 1 << i;
+ assert_equal(n1-1, (n1**2-1) / (n1+1))
+ end
+ end
+
+ def test_calc
+ b = 10**80
+ a = b * 9 + 7
+ assert_equal(7, a.modulo(b))
+ assert_equal(-b + 7, a.modulo(-b))
+ assert_equal(b + -7, (-a).modulo(b))
+ assert_equal(-7, (-a).modulo(-b))
+ assert_equal(7, a.remainder(b))
+ assert_equal(7, a.remainder(-b))
+ assert_equal(-7, (-a).remainder(b))
+ assert_equal(-7, (-a).remainder(-b))
+
+ assert_equal(10000000000000000000100000000000000000000, 10**40+10**20)
+ assert_equal(100000000000000000000, 10**40/10**20)
+
+ a = 677330545177305025495135714080
+ b = 14269972710765292560
+ assert_equal(0, a % b)
+ assert_equal(0, -a % b)
+ end
+
+ def shift_test(a)
+ b = a / (2 ** 32)
+ c = a >> 32
+ assert_equal(b, c)
+
+ b = a * (2 ** 32)
+ c = a << 32
+ assert_equal(b, c)
+ end
+
+ def test_shift
+ shift_test(-4518325415524767873)
+ shift_test(-0xfffffffffffffffff)
+ end
+end
Added: trunk/test/ruby/test_call.rb
===================================================================
--- trunk/test/ruby/test_call.rb 2005-12-24 22:44:12 UTC (rev 324)
+++ trunk/test/ruby/test_call.rb 2005-12-25 17:07:45 UTC (rev 325)
@@ -0,0 +1,19 @@
+require 'test/unit'
+
+class TestCall < Test::Unit::TestCase
+ def aaa(a, b=100, *rest)
+ res = [a, b]
+ res += rest if rest
+ return res
+ end
+
+ def test_call
+ assert_raises(ArgumentError) {aaa()}
+ assert_raises(ArgumentError) {aaa}
+
+ assert_equal([1, 100], aaa(1))
+ assert_equal([1, 2], aaa(1, 2))
+ assert_equal([1, 2, 3, 4], aaa(1, 2, 3, 4))
+ assert_equal([1, 2, 3, 4], aaa(1, *[2, 3, 4]))
+ end
+end
Added: trunk/test/ruby/test_case.rb
===================================================================
--- trunk/test/ruby/test_case.rb 2005-12-24 22:44:12 UTC (rev 324)
+++ trunk/test/ruby/test_case.rb 2005-12-25 17:07:45 UTC (rev 325)
@@ -0,0 +1,49 @@
+require 'test/unit'
+
+class TestCase < Test::Unit::TestCase
+ def test_case
+ case 5
+ when 1, 2, 3, 4, 6, 7, 8
+ assert(false)
+ when 5
+ assert(true)
+ end
+
+ case 5
+ when 5
+ assert(true)
+ when 1..10
+ assert(false)
+ end
+
+ case 5
+ when 1..10
+ assert(true)
+ else
+ assert(false)
+ end
+
+ case 5
+ when 5
+ assert(true)
+ else
+ assert(false)
+ end
+
+ case "foobar"
+ when /^f.*r$/
+ assert(true)
+ else
+ assert(false)
+ end
+
+ case
+ when true
+ assert(true)
+ when false, nil
+ assert(false)
+ else
+ assert(false)
+ end
+ end
+end
Added: trunk/test/ruby/test_clone.rb
===================================================================
--- trunk/test/ruby/test_clone.rb 2005-12-24 22:44:12 UTC (rev 324)
+++ trunk/test/ruby/test_clone.rb 2005-12-25 17:07:45 UTC (rev 325)
@@ -0,0 +1,28 @@
+require 'test/unit'
+
+class TestClone < Test::Unit::TestCase
+ module M001; end
+ module M002; end
+ module M003; include M002; end
+ module M002; include M001; end
+ module M003; include M002; end
+
+ def test_clone
+ foo = Object.new
+ def foo.test
+ "test"
+ end
+ bar = foo.clone
+ def bar.test2
+ "test2"
+ end
+
+ assert_equal("test2", bar.test2)
+ assert_equal("test", bar.test)
+ assert_equal("test", foo.test)
+
+ assert_raises(NoMethodError) {foo.test2}
+
+ assert_equal([M003, M002, M001], M003.ancestors)
+ end
+end
Added: trunk/test/ruby/test_condition.rb
===================================================================
--- trunk/test/ruby/test_condition.rb 2005-12-24 22:44:12 UTC (rev 324)
+++ trunk/test/ruby/test_condition.rb 2005-12-25 17:07:45 UTC (rev 325)
@@ -0,0 +1,16 @@
+require 'test/unit'
+
+class TestCondition < Test::Unit::TestCase
+
+ # [should] first test to see if we can run the tests.
+
+ def test_condition
+ $x = '0';
+
+ $x == $x && assert(true)
+ $x != $x && assert(false)
+ $x == $x || assert(false)
+ $x != $x || assert(true)
+
+ end
+end
Added: trunk/test/ruby/test_const.rb
===================================================================
--- trunk/test/ruby/test_const.rb 2005-12-24 22:44:12 UTC (rev 324)
+++ trunk/test/ruby/test_const.rb 2005-12-25 17:07:45 UTC (rev 325)
@@ -0,0 +1,33 @@
+require 'test/unit'
+
+class TestConst < Test::Unit::TestCase
+ TEST1 = 1
+ TEST2 = 2
+
+ module Const
+ TEST3 = 3
+ TEST4 = 4
+ end
+
+ module Const2
+ TEST3 = 6
+ TEST4 = 8
+ end
+
+ def test_const
+ self.class.class_eval {
+ include Const
+ }
+ assert_equal([1,2,3,4], [TEST1,TEST2,TEST3,TEST4])
+
+ self.class.class_eval {
+ include Const2
+ }
+ STDERR.print "intentionally redefines TEST3, TEST4\n" if $VERBOSE
+ assert_equal([1,2,6,8], [TEST1,TEST2,TEST3,TEST4])
+
+ assert_equal(-1, (String <=> Object))
+ assert_equal(1, (Object <=> String))
+ assert_equal(nil, (Array <=> String))
+ end
+end
Added: trunk/test/ruby/test_defined.rb
===================================================================
--- trunk/test/ruby/test_defined.rb 2005-12-24 22:44:12 UTC (rev 324)
+++ trunk/test/ruby/test_defined.rb 2005-12-25 17:07:45 UTC (rev 325)
@@ -0,0 +1,43 @@
+require 'test/unit'
+
+class TestDefined < Test::Unit::TestCase
+ class Foo
+ def foo
+ p :foo
+ end
+ protected :foo
+ def bar(f)
+ yield(defined?(self.foo))
+ yield(defined?(f.foo))
+ end
+ end
+
+ def defined_test
+ return !defined?(yield)
+ end
+
+ def test_defined
+ $x = nil
+
+ assert(defined?($x)) # global variable
+ assert_equal('global-variable', defined?($x))# returns description
+
+ assert_nil(defined?(foo)) # undefined
+ foo=5
+ assert(defined?(foo)) # local variable
+
+ assert(defined?(Array)) # constant
+ assert(defined?(::Array)) # toplevel constant
+ assert(defined?(File::Constants)) # nested constant
+ assert(defined?(Object.new)) # method
+ assert(!defined?(Object.print)) # private method
+ assert(defined?(1 == 2)) # operator expression
+
+ f = Foo.new
+ assert_nil(defined?(f.foo))
+ f.bar(f) { |v| assert(v) }
+
+ assert(defined_test) # not iterator
+ assert(!defined_test{}) # called as iterator
+ end
+end
Added: trunk/test/ruby/test_eval.rb
===================================================================
--- trunk/test/ruby/test_eval.rb 2005-12-24 22:44:12 UTC (rev 324)
+++ trunk/test/ruby/test_eval.rb 2005-12-25 17:07:45 UTC (rev 325)
@@ -0,0 +1,157 @@
+require 'test/unit'
+
+class TestEval < Test::Unit::TestCase
+ # eval with binding
+ def test_ev
+ local1 = "local1"
+ lambda {
+ local2 = "local2"
+ return binding
+ }.call
+ end
+
+ def test_eval
+ assert_nil(eval(""))
+ $bad=false
+ eval 'while false; $bad = true; print "foo\n" end'
+ assert(!$bad)
+
+ assert(eval('TRUE'))
+ assert(eval('true'))
+ assert(!eval('NIL'))
+ assert(!eval('nil'))
+ assert(!eval('FALSE'))
+ assert(!eval('false'))
+
+ $foo = 'assert(true)'
+ begin
+ eval $foo
+ rescue
+ assert(false)
+ end
+
+ assert_equal('assert(true)', eval("$foo"))
+ assert_equal(true, eval("true"))
+ i = 5
+ assert(eval("i == 5"))
+ assert_equal(5, eval("i"))
+ assert(eval("defined? i"))
+
+ $x = test_ev
+ assert_equal("local1", eval("local1", $x)) # normal local var
+ assert_equal("local2", eval("local2", $x)) # nested local var
+ $bad = true
+ begin
+ p eval("local1")
+ rescue NameError # must raise error
+ $bad = false
+ end
+ assert(!$bad)
+
+ # !! use class_eval to avoid nested definition
+ self.class.class_eval %q(
+ module EvTest
+ EVTEST1 = 25
+ evtest2 = 125
+ $x = binding
+ end
+ )
+ assert_equal(25, eval("EVTEST1", $x)) # constant in module
+ assert_equal(125, eval("evtest2", $x)) # local var in module
+ $bad = true
+ begin
+ eval("EVTEST1")
+ rescue NameError # must raise error
+ $bad = false
+ end
+ assert(!$bad)
+
+ x = proc{}
+ eval "i4 = 1", x
+ assert_equal(1, eval("i4", x))
+ x = proc{proc{}}.call
+ eval "i4 = 22", x
+ assert_equal(22, eval("i4", x))
+ $x = []
+ x = proc{proc{}}.call
+ eval "(0..9).each{|i5| $x[i5] = proc{i5*2}}", x
+ assert_equal(8, $x[4].call)
+
+ x = binding
+ eval "i = 1", x
+ assert_equal(1, eval("i", x))
+ x = proc{binding}.call
+ eval "i = 22", x
+ assert_equal(22, eval("i", x))
+ $x = []
+ x = proc{binding}.call
+ eval "(0..9).each{|i5| $x[i5] = proc{i5*2}}", x
+ assert_equal(8, $x[4].call)
+ x = proc{binding}.call
+ eval "for i6 in 1..1; j6=i6; end", x
+ assert(eval("defined? i6", x))
+ assert(eval("defined? j6", x))
+
+ proc {
+ p = binding
+ eval "foo11 = 1", p
+ foo22 = 5
+ proc{foo11=22}.call
+ proc{foo22=55}.call
+ assert_equal(eval("foo11"), eval("foo11", p))
+ assert_equal(1, eval("foo11"))
+ assert_equal(eval("foo22"), eval("foo22", p))
+ assert_equal(55, eval("foo22"))
+ }.call
+
+ p1 = proc{i7 = 0; proc{i7}}.call
+ assert_equal(0, p1.call)
+ eval "i7=5", p1
+ assert_equal(5, p1.call)
+ assert(!defined?(i7))
+
+ p1 = proc{i7 = 0; proc{i7}}.call
+ i7 = nil
+ assert_equal(0, p1.call)
+ eval "i7=1", p1
+ assert_equal(1, p1.call)
+ eval "i7=5", p1
+ assert_equal(5, p1.call)
+ assert_nil(i7)
+ end
+
+ def test_nil_instance_eval_cvar # [ruby-dev:24103]
+ def nil.test_binding
+ binding
+ end
+ bb = eval("nil.instance_eval \"binding\"", nil.test_binding)
+ assert_raise(NameError) { eval("@@a", bb) }
+ class << nil
+ remove_method :test_binding
+ end
+ end
+
+ def test_fixnum_instance_eval_cvar # [ruby-dev:24213]
+ assert_raise(NameError) { 1.instance_eval "@@a" }
+ end
+
+ def test_cvar_scope_with_instance_eval # [ruby-dev:24223]
+ Fixnum.class_eval "@@test_cvar_scope_with_instance_eval = 1" # depends on [ruby-dev:24229]
+ @@test_cvar_scope_with_instance_eval = 4
+ assert_equal(4, 1.instance_eval("@@test_cvar_scope_with_instance_eval"))
+ Fixnum.__send__(:remove_class_variable, :@@test_cvar_scope_with_instance_eval)
+ end
+
+ def test_eval_and_define_method # [ruby-dev:24228]
+ assert_nothing_raised {
+ def temporally_method_for_test_eval_and_define_method(&block)
+ lambda {
+ class << Object.new; self end.funcall(:define_method, :zzz, &block)
+ }
+ end
+ v = eval("temporally_method_for_test_eval_and_define_method {}")
+ {}[0] = {}
+ v.call
+ }
+ end
+end
Added: trunk/test/ruby/test_exception.rb
===================================================================
--- trunk/test/ruby/test_exception.rb 2005-12-24 22:44:12 UTC (rev 324)
+++ trunk/test/ruby/test_exception.rb 2005-12-25 17:07:45 UTC (rev 325)
@@ -0,0 +1,187 @@
+require 'test/unit'
+
+class TestException < Test::Unit::TestCase
+ def test_exception
+ begin
+ raise "this must be handled"
+ assert(false)
+ rescue
+ assert(true)
+ end
+
+ $bad = true
+ begin
+ raise "this must be handled no.2"
+ rescue
+ if $bad
+ $bad = false
+ retry
+ assert(false)
+ end
+ end
+ assert(true)
+
+ # exception in rescue clause
+ $string = "this must be handled no.3"
+ e = assert_raises(RuntimeError) do
+ begin
+ raise "exception in rescue clause"
+ rescue
+ raise $string
+ end
+ assert(false)
+ end
+ assert_equal($string, e.message)
+
+ # exception in ensure clause
+ $string = "exception in ensure clause"
+ e = assert_raises(RuntimeError) do
+ begin
+ raise "this must be handled no.4"
+ ensure
+ assert_instance_of(RuntimeError, $!)
+ assert_equal("this must be handled no.4", $!.message)
+ raise "exception in ensure clause"
+ end
+ assert(false)
+ end
+ assert_equal($string, e.message)
+
+ $bad = true
+ begin
+ begin
+ raise "this must be handled no.5"
+ ensure
+ $bad = false
+ end
+ rescue
+ end
+ assert(!$bad)
+
+ $bad = true
+ begin
+ begin
+ raise "this must be handled no.6"
+ ensure
+ $bad = false
+ end
+ rescue
+ end
+ assert(!$bad)
+
+ $bad = true
+ while true
+ begin
+ break
+ ensure
+ $bad = false
+ end
+ end
+ assert(!$bad)
+
+ assert(catch(:foo) {
+ loop do
+ loop do
+ throw :foo, true
+ break
+ end
+ break
+ assert(false) # should no reach here
+ end
+ false
+ })
+
+ end
+
+ def test_else
+ begin
+ assert(true)
+ rescue
+ assert(false)
+ else
+ assert(true)
+ end
+
+ begin
+ assert(true)
+ raise
+ assert(false)
+ rescue
+ assert(true)
+ else
+ assert(false)
+ end
+
+ begin
+ assert(true)
+ begin
+ assert(true)
+ rescue
+ assert(false)
+ else
+ assert(true)
+ end
+ assert(true)
+ rescue
+ assert(false)
+ else
+ assert(true)
+ end
+
+ begin
+ assert(true)
+ begin
+ assert(true)
+ raise
+ assert(false)
+ rescue
+ assert(true)
+ else
+ assert(false)
+ end
+ assert(true)
+ rescue
+ assert(false)
+ else
+ assert(true)
+ end
+
+ begin
+ assert(true)
+ begin
+ assert(true)
+ rescue
+ assert(false)
+ else
+ assert(true)
+ end
+ assert(true)
+ raise
+ assert(false)
+ rescue
+ assert(true)
+ else
+ assert(false)
+ end
+
+ begin
+ assert(true)
+ begin
+ assert(true)
+ raise
+ assert(false)
+ rescue
+ assert(true)
+ else
+ assert(false)
+ end
+ assert(true)
+ raise
+ assert(false)
+ rescue
+ assert(true)
+ else
+ assert(false)
+ end
+ end
+end
Added: trunk/test/ruby/test_gc.rb
===================================================================
--- trunk/test/ruby/test_gc.rb 2005-12-24 22:44:12 UTC (rev 324)
+++ trunk/test/ruby/test_gc.rb 2005-12-25 17:07:45 UTC (rev 325)
@@ -0,0 +1,30 @@
+require 'test/unit'
+
+class TestGc < Test::Unit::TestCase
+ class S
+ def initialize(a)
+ @a = a
+ end
+ end
+
+ def test_gc
+ assert_nothing_raised do
+ 1.upto(10000) {
+ tmp = [0,1,2,3,4,5,6,7,8,9]
+ }
+ tmp = nil
+ end
+ l=nil
+ 100000.times {
+ l = S.new(l)
+ }
+ GC.start
+ assert true # reach here or dumps core
+ l = []
+ 100000.times {
+ l.push([l])
+ }
+ GC.start
+ assert true # reach here or dumps core
+ end
+end
Added: trunk/test/ruby/test_ifunless.rb
===================================================================
--- trunk/test/ruby/test_ifunless.rb 2005-12-24 22:44:12 UTC (rev 324)
+++ trunk/test/ruby/test_ifunless.rb 2005-12-25 17:07:45 UTC (rev 325)
@@ -0,0 +1,14 @@
+require 'test/unit'
+
+class TestIfunless < Test::Unit::TestCase
+ def test_if_unless
+ $x = 'test';
+ assert(if $x == $x then true else false end)
+ $bad = false
+ unless $x == $x
+ $bad = true
+ end
+ assert(!$bad)
+ assert(unless $x != $x then true else false end)
+ end
+end
Added: trunk/test/ruby/test_iterator.rb
===================================================================
--- trunk/test/ruby/test_iterator.rb 2005-12-24 22:44:12 UTC (rev 324)
+++ trunk/test/ruby/test_iterator.rb 2005-12-25 17:07:45 UTC (rev 325)
@@ -0,0 +1,470 @@
+require 'test/unit'
+
+class Array
+ def iter_test1
+ collect{|e| [e, yield(e)]}.sort{|a,b|a[1]<=>b[1]}
+ end
+ def iter_test2
+ a = collect{|e| [e, yield(e)]}
+ a.sort{|a,b|a[1]<=>b[1]}
+ end
+end
+
+class TestIterator < Test::Unit::TestCase
+ def ttt
+ assert(iterator?)
+ end
+
+ def test_iterator
+ assert(!iterator?)
+
+ ttt{}
+
+ # yield at top level !! here's not toplevel
+ assert(!defined?(yield))
+ end
+
+ def test_array
+ $x = [1, 2, 3, 4]
+ $y = []
+
+ # iterator over array
+ for i in $x
+ $y.push i
+ end
+ assert_equal($x, $y)
+ end
+
+ def tt
+ 1.upto(10) {|i|
+ yield i
+ }
+ end
+
+ def tt2(dummy)
+ yield 1
+ end
+
+ def tt3(&block)
+ tt2(raise(ArgumentError,""),&block)
+ end
+
+ def test_nested_iterator
+ i = 0
+ tt{|i| break if i == 5}
+ assert_equal(5, i)
+
+ assert_raises(ArgumentError) do
+ tt3{}
+ end
+ end
+
+ def tt4 &block
+ tt2(raise(ArgumentError,""),&block)
+ end
+
+ def test_block_argument_without_paren
+ assert_raises(ArgumentError) do
+ tt4{}
+ end
+ end
+
+ # iterator break/redo/next/retry
+ def test_break
+ done = true
+ loop{
+ break
+ done = false # should not reach here
+ }
+ assert(done)
+
+ done = false
+ $bad = false
+ loop {
+ break if done
+ done = true
+ next
+ $bad = true # should not reach here
+ }
+ assert(!$bad)
+
+ done = false
+ $bad = false
+ loop {
+ break if done
+ done = true
+ redo
+ $bad = true # should not reach here
+ }
+ assert(!$bad)
+
+ $x = []
+ for i in 1 .. 7
+ $x.push i
+ end
+ assert_equal(7, $x.size)
+ assert_equal([1, 2, 3, 4, 5, 6, 7], $x)
+
+ $done = false
+ $x = []
+ for i in 1 .. 7 # see how retry works in iterator loop
+ if i == 4 and not $done
+ $done = true
+ retry
+ end
+ $x.push(i)
+ end
+ assert_equal(10, $x.size)
+ assert_equal([1, 2, 3, 1, 2, 3, 4, 5, 6, 7], $x)
+ end
+
+ def test_append_method_to_built_in_class
+ $x = [[1,2],[3,4],[5,6]]
+ assert_equal($x.iter_test1{|x|x}, $x.iter_test2{|x|x})
+ end
+
+ class IterTest
+ def initialize(e); @body = e; end
+
+ def each0(&block); @body.each(&block); end
+ def each1(&block); @body.each {|*x| block.call(*x) } end
+ def each2(&block); @body.each {|*x| block.call(x) } end
+ def each3(&block); @body.each {|x| block.call(*x) } end
+ def each4(&block); @body.each {|x| block.call(x) } end
+ def each5; @body.each {|*x| yield(*x) } end
+ def each6; @body.each {|*x| yield(x) } end
+ def each7; @body.each {|x| yield(*x) } end
+ def each8; @body.each {|x| yield(x) } end
+
+ def f(a)
+ a
+ end
+ end
+
+ def test_itertest
+ assert_equal([1], IterTest.new(nil).method(:f).to_proc.call([1]))
+ m = /\w+/.match("abc")
+ assert_equal([m], IterTest.new(nil).method(:f).to_proc.call([m]))
+
+ IterTest.new([0]).each0 {|x| assert_equal(0, x)}
+ IterTest.new([1]).each1 {|x| assert_equal(1, x)}
+ IterTest.new([2]).each2 {|x| assert_equal([2], x)}
+ IterTest.new([4]).each4 {|x| assert_equal(4, x)}
+ IterTest.new([5]).each5 {|x| assert_equal(5, x)}
+ IterTest.new([6]).each6 {|x| assert_equal([6], x)}
+ IterTest.new([8]).each8 {|x| assert_equal(8, x)}
+
+ IterTest.new([[0]]).each0 {|x| assert_equal([0], x)}
+ IterTest.new([[1]]).each1 {|x| assert_equal([1], x)}
+ IterTest.new([[2]]).each2 {|x| assert_equal([[2]], x)}
+ IterTest.new([[3]]).each3 {|x| assert_equal(3, x)}
+ IterTest.new([[4]]).each4 {|x| assert_equal([4], x)}
+ IterTest.new([[5]]).each5 {|x| assert_equal([5], x)}
+ IterTest.new([[6]]).each6 {|x| assert_equal([[6]], x)}
+ IterTest.new([[7]]).each7 {|x| assert_equal(7, x)}
+ IterTest.new([[8]]).each8 {|x| assert_equal([8], x)}
+
+ IterTest.new([[0,0]]).each0 {|x| assert_equal([0,0], x)}
+ IterTest.new([[8,8]]).each8 {|x| assert_equal([8,8], x)}
+ end
+
+ def m(var)
+ var
+ end
+
+ def m1
+ m(block_given?)
+ end
+
+ def m2
+ m(block_given?,&proc{})
+ end
+
+ def test_block_given
+ assert(m1{p 'test'})
+ assert(m2{p 'test'})
+ assert(!m1())
+ assert(!m2())
+ end
+
+ def m3(var, &block)
+ m(yield(var), &block)
+ end
+
+ def m4(&block)
+ m(m1(), &block)
+ end
+
+ def test_block_passing
+ assert(!m4())
+ assert(!m4 {})
+ assert_equal(100, m3(10) {|x|x*x})
+ end
+
+ class C
+ include Enumerable
+ def initialize
+ @a = [1,2,3]
+ end
+ def each(&block)
+ @a.each(&block)
+ end
+ end
+
+ def test_collect
+ assert_equal([1,2,3], C.new.collect{|n| n})
+ end
+
+ def test_proc
+ assert_instance_of(Proc, lambda{})
+ assert_instance_of(Proc, Proc.new{})
+ lambda{|a|assert_equal(a, 1)}.call(1)
+ end
+
+ def test_block
+ assert_instance_of(NilClass, get_block)
+ assert_instance_of(Proc, get_block{})
+ end
+
+ def test_argument
+ assert_nothing_raised {lambda{||}.call}
+ assert_raises(ArgumentError) {lambda{||}.call(1)}
+ assert_nothing_raised {lambda{|a,|}.call(1)}
+ assert_raises(ArgumentError) {lambda{|a,|}.call()}
+ assert_raises(ArgumentError) {lambda{|a,|}.call(1,2)}
+ end
+
+ def get_block(&block)
+ block
+ end
+
+ def test_get_block
+ assert_instance_of(Proc, get_block{})
+ assert_nothing_raised {get_block{||}.call()}
+ assert_nothing_raised {get_block{||}.call(1)}
+ assert_nothing_raised {get_block{|a,|}.call(1)}
+ assert_nothing_raised {get_block{|a,|}.call()}
+ assert_nothing_raised {get_block{|a,|}.call(1,2)}
+
+ assert_nothing_raised {get_block(&lambda{||}).call()}
+ assert_raises(ArgumentError) {get_block(&lambda{||}).call(1)}
+ assert_nothing_raised {get_block(&lambda{|a,|}).call(1)}
+ assert_raises(ArgumentError) {get_block(&lambda{|a,|}).call(1,2)}
+
+ block = get_block{11}
+ assert_instance_of(Proc, block)
+ assert_instance_of(Proc, block.to_proc)
+ assert_equal(block.clone.call, 11)
+ assert_instance_of(Proc, get_block(&block))
+
+ lmd = lambda{44}
+ assert_instance_of(Proc, lmd)
+ assert_instance_of(Proc, lmd.to_proc)
+ assert_equal(lmd.clone.call, 44)
+ assert_instance_of(Proc, get_block(&lmd))
+
+ assert_equal(1, Proc.new{|a,| a}.call(1,2,3))
+ assert_nothing_raised {Proc.new{|a,|}.call(1,2)}
+ end
+
+ def return1_test
+ Proc.new {
+ return 55
+ }.call + 5
+ end
+
+ def test_return1
+ assert_equal(55, return1_test())
+ end
+
+ def return2_test
+ lambda {
+ return 55
+ }.call + 5
+ end
+
+ def test_return2
+ assert_equal(60, return2_test())
+ end
+
+ def proc_call(&b)
+ b.call
+ end
+ def proc_yield()
+ yield
+ end
+ def proc_return1
+ proc_call{return 42}+1
+ end
+
+ def test_proc_return1
+ assert_equal(42, proc_return1())
+ end
+
+ def proc_return2
+ proc_yield{return 42}+1
+ end
+
+ def test_proc_return2
+ assert_equal(42, proc_return2())
+ end
+
+ def test_ljump
+ assert_raises(LocalJumpError) {get_block{break}.call}
+
+ # cannot use assert_nothing_raised due to passing block.
+ begin
+ val = lambda{break 11}.call
+ rescue LocalJumpError
+ assert(false, "LocalJumpError occurred from break in lambda")
+ else
+ assert(11, val)
+ end
+
+ block = get_block{11}
+ lmd = lambda{44}
+ assert_equal(0, block.arity)
+ assert_equal(0, lmd.arity)
+ assert_equal(0, lambda{||}.arity)
+ assert_equal(1, lambda{|a|}.arity)
+ assert_equal(1, lambda{|a,|}.arity)
+ assert_equal(2, lambda{|a,b|}.arity)
+ end
+
+ def marity_test(m)
+ mobj = method(m)
+ assert_equal(mobj.arity, mobj.to_proc.arity)
+ end
+
+ def test_marity
+ marity_test(:assert)
+ marity_test(:marity_test)
+ marity_test(:p)
+
+ lambda(&method(:assert)).call(true)
+ lambda(&get_block{|a,n| assert(a,n)}).call(true, "marity")
+ end
+
+ def foo
+ yield([:key, :value])
+ end
+ def bar(&blk)
+ blk.call([:key, :value])
+ end
+
+ def test_yield_vs_call
+ foo{|k,v| assert_equal([:key, :value], [k,v])}
+ bar{|k,v| assert_equal([:key, :value], [k,v])}
+ end
+
+ class H
+ def each
+ yield [:key, :value]
+ end
+ end
+
+ def test_assoc_yield
+ [{:key=>:value}, H.new].each {|h|
+ h.each{|a| assert_equal([:key, :value], a)}
+ h.each{|*a| assert_equal([[:key, :value]], a)}
+ h.each{|k,v| assert_equal([:key, :value], [k,v])}
+ }
+ end
+
+ class ITER_TEST1
+ def a
+ block_given?
+ end
+ end
+
+ class ITER_TEST2 < ITER_TEST1
+ include Test::Unit::Assertions
+ def a
+ assert(super)
+ super
+ end
+ end
+
+ def test_iter_test2
+ assert(ITER_TEST2.new.a {})
+ end
+
+ class ITER_TEST3
+ def foo x
+ return yield if block_given?
+ x
+ end
+ end
+
+ class ITER_TEST4 < ITER_TEST3
+ include Test::Unit::Assertions
+ def foo x
+ assert_equal(super, yield)
+ assert_equal(x, super(x, &nil))
+ end
+ end
+
+ def test_iter4
+ ITER_TEST4.new.foo(44){55}
+ end
+
+ def test_break__nested_loop1
+ _test_break__nested_loop1 do
+ break
+ end
+ end
+
+ def _test_break__nested_loop1
+ while true
+ yield
+ end
+ assert(false, "must not reach here")
+ end
+
+ def test_break__nested_loop2
+ _test_break__nested_loop2 do
+ break
+ end
+ end
+
+ def _test_break__nested_loop2
+ until false
+ yield
+ end
+ assert(false, "must not reach here")
+ end
+
+ def test_break__nested_loop3
+ _test_break__nested_loop3 do
+ break
+ end
+ end
+
+ def _test_break__nested_loop3
+ loop do
+ yield
+ end
+ assert(false, "must not reach here")
+ end
+
+ def test_break_from_enum
+ result = ["a"].inject("ng") {|x,y| break "ok"}
+ assert_equal("ok", result)
+ end
+
+ def _test_return_trace_func(x)
+ set_trace_func(proc {})
+ [].fetch(2) {return x}
+ ensure
+ set_trace_func(nil)
+ end
+
+ def test_return_trace_func
+ ok = "returned gracefully"
+ result = "skipped"
+ result = _test_return_trace_func(ok)
+ ensure
+ assert_equal(ok, result)
+ return
+ end
+end
Added: trunk/test/ruby/test_lambda.rb
===================================================================
--- trunk/test/ruby/test_lambda.rb 2005-12-24 22:44:12 UTC (rev 324)
+++ trunk/test/ruby/test_lambda.rb 2005-12-25 17:07:45 UTC (rev 325)
@@ -0,0 +1,53 @@
+require 'test/unit'
+
+class TestLambdaParameters < Test::Unit::TestCase
+ def test_call_simple
+ assert_equal(1, ->(a){ a }.call(1))
+ assert_equal([1,2], ->(a,b){ [a,b] }.call(1,2))
+ assert_raises(ArgumentError) { ->(a){ }.call(1,2) }
+ assert_raises(ArgumentError) { ->(a){ }.call() }
+ assert_raises(ArgumentError) { ->(){ }.call(1) }
+ assert_raises(ArgumentError) { ->(a,b){ }.call(1,2,3) }
+ end
+
+ def test_call_rest_args
+ assert_equal([1,2], ->(*a){ a }.call(1,2))
+ assert_equal([1,2,[]], ->(a,b,*c){ [a,b,c] }.call(1,2))
+ assert_raises(ArgumentError){ ->(a,*b){ }.call() }
+ end
+
+ def test_call_opt_args
+ assert_equal([1,2,3,4], ->(a,b,c=3,d=4){ [a,b,c,d] }.call(1,2))
+ assert_equal([1,2,3,4], ->(a,b,c=0,d=4){ [a,b,c,d] }.call(1,2,3))
+ assert_raises(ArgumentError){ ->(a,b=1){ }.call() }
+ assert_raises(ArgumentError){ ->(a,b=1){ }.call(1,2,3) }
+ end
+
+ def test_call_rest_and_opt
+ assert_equal([1,2,3,[]], ->(a,b=2,c=3,*d){ [a,b,c,d] }.call(1))
+ assert_equal([1,2,3,[]], ->(a,b=0,c=3,*d){ [a,b,c,d] }.call(1,2))
+ assert_equal([1,2,3,[4,5,6]], ->(a,b=0,c=0,*d){ [a,b,c,d] }.call(1,2,3,4,5,6))
+ assert_raises(ArgumentError){ ->(a,b=1,*c){ }.call() }
+ end
+
+ def test_call_with_block
+ f = ->(a,b,c=3,*d,&e){ [a,b,c,d,e.call(d + [a,b,c])] }
+ assert_equal([1,2,3,[],6], f.call(1,2){|z| z.inject{|s,x| s+x} } )
+ assert_equal(nil, ->(&b){ b }.call)
+ foo { puts "bogus block " }
+ assert_equal(1, ->(&b){ b.call }.call { 1 })
+ b = nil
+ assert_equal(1, ->(&b){ b.call }.call { 1 })
+ assert_nil(b)
+ end
+
+ def foo
+ assert_equal(nil, ->(&b){ b }.call)
+ end
+
+ def test_lambda_as_iterator
+ a = 0
+ 2.times ->(_){ a += 1 }
+ assert_equal(a, 2)
+ end
+end
Added: trunk/test/ruby/test_method.rb
===================================================================
--- trunk/test/ruby/test_method.rb 2005-12-24 22:44:12 UTC (rev 324)
+++ trunk/test/ruby/test_method.rb 2005-12-25 17:07:45 UTC (rev 325)
@@ -0,0 +1,42 @@
+require 'test/unit'
+
+class TestMethod < Test::Unit::TestCase
+ def m0() end
+ def m1(a) end
+ def m2(a, b) end
+ def mo1(a = nil, &b) end
+ def mo2(a, b = nil) end
+ def mo3(*a) end
+ def mo4(a, *b, &c) end
+
+ class Base
+ def foo() :base end
+ end
+ class Derived < Base
+ def foo() :derived end
+ end
+
+ def test_arity
+ assert_equal(0, method(:m0).arity)
+ assert_equal(1, method(:m1).arity)
+ assert_equal(2, method(:m2).arity)
+ assert_equal(-1, method(:mo1).arity)
+ assert_equal(-2, method(:mo2).arity)
+ assert_equal(-1, method(:mo3).arity)
+ assert_equal(-2, method(:mo4).arity)
+ end
+
+ def test_unbind
+ assert_equal(:derived, Derived.new.foo)
+ um = Derived.new.method(:foo).unbind
+ assert_instance_of(UnboundMethod, um)
+ Derived.class_eval do
+ def foo() :changed end
+ end
+ assert_equal(:changed, Derived.new.foo)
+ assert_equal(:derived, um.bind(Derived.new).call)
+ assert_raise(TypeError) do
+ um.bind(Base.new)
+ end
+ end
+end
Added: trunk/test/ruby/test_proc.rb
===================================================================
--- trunk/test/ruby/test_proc.rb 2005-12-24 22:44:12 UTC (rev 324)
+++ trunk/test/ruby/test_proc.rb 2005-12-25 17:07:45 UTC (rev 325)
@@ -0,0 +1,125 @@
+require 'test/unit'
+
+class TestProc < Test::Unit::TestCase
+ def test_proc
+ p1 = proc{|i| i}
+ assert_equal(2, p1.call(2))
+ assert_equal(3, p1.call(3))
+
+ p1 = proc{|i| i*2}
+ assert_equal(4, p1.call(2))
+ assert_equal(6, p1.call(3))
+
+ p2 = nil
+ x=0
+
+ proc{
+ iii=5 # nested local variable
+ p1 = proc{|i|
+ iii = i
+ }
+ p2 = proc {
+ x = iii # nested variables shared by procs
+ }
+ # scope of nested variables
+ assert(defined?(iii))
+ }.call
+ assert(!defined?(iii)) # out of scope
+
+ loop{iii=5; assert(eval("defined? iii")); break}
+ loop {
+ iii = 10
+ def self.dyna_var_check
+ loop {
+ assert(!defined?(iii))
+ break
+ }
+ end
+ dyna_var_check
+ break
+ }
+ p1.call(5)
+ p2.call
+ assert_equal(5, x)
+ end
+
+ def assert_arity(n)
+ meta = class << self; self; end
+ meta.class_eval {define_method(:foo, Proc.new)}
+ assert_equal(n, method(:foo).arity)
+ end
+
+ def test_arity
+ assert_equal(0, proc{}.arity)
+ assert_equal(0, proc{||}.arity)
+ assert_equal(1, proc{|x|}.arity)
+ assert_equal(2, proc{|x, y|}.arity)
+ assert_equal(-2, proc{|x, *y|}.arity)
+ assert_equal(-1, proc{|*x|}.arity)
+ assert_equal(-1, proc{|*|}.arity)
+
+ assert_arity(0) {}
+ assert_arity(0) {||}
+ assert_arity(1) {|x|}
+ assert_arity(2) {|x, y|}
+ assert_arity(-2) {|x, *y|}
+ assert_arity(-1) {|*x|}
+ assert_arity(-1) {|*|}
+ end
+
+ # [ruby-dev:22592]
+ def m(x)
+ lambda { x }
+ end
+ def test_eq
+ # [ruby-dev:22592]
+ a = m(1)
+ b = m(2)
+ assert_not_equal(a, b)
+ assert_not_equal(a.call, b.call)
+
+ # [ruby-dev:22599]
+ assert_not_equal(proc {||}, proc {|x,y|})
+
+ # [ruby-dev:22601]
+ a = lambda {|x| lambda {} }.call(1)
+ b = lambda {}
+ assert_not_equal(a, b)
+ end
+
+ def test_block_par
+ assert_equal(10, Proc.new{|&b| b.call(10)}.call {|x| x})
+ assert_equal(12, Proc.new{|a,&b| b.call(a)}.call(12) {|x| x})
+ end
+
+ def test_safe
+ safe = $SAFE
+ c = Class.new
+ x = c.new
+
+ p = proc {
+ $SAFE += 1
+ proc {$SAFE}
+ }.call
+ assert_equal(safe, $SAFE)
+ assert_equal(safe + 1, p.call)
+ assert_equal(safe, $SAFE)
+
+ c.class_eval {define_method(:safe, p)}
+ assert_equal(safe, x.safe)
+ assert_equal(safe, x.method(:safe).call)
+ assert_equal(safe, x.method(:safe).to_proc.call)
+
+ p = proc {$SAFE += 1}
+ assert_equal(safe + 1, p.call)
+ assert_equal(safe, $SAFE)
+
+ c.class_eval {define_method(:inc, p)}
+ assert_equal(safe + 1, proc {x.inc; $SAFE}.call)
+ assert_equal(safe, $SAFE)
+ assert_equal(safe + 1, proc {x.method(:inc).call; $SAFE}.call)
+ assert_equal(safe, $SAFE)
+ assert_equal(safe + 1, proc {x.method(:inc).to_proc.call; $SAFE}.call)
+ assert_equal(safe, $SAFE)
+ end
+end
Added: trunk/test/ruby/test_super.rb
===================================================================
--- trunk/test/ruby/test_super.rb 2005-12-24 22:44:12 UTC (rev 324)
+++ trunk/test/ruby/test_super.rb 2005-12-25 17:07:45 UTC (rev 325)
@@ -0,0 +1,117 @@
+require 'test/unit'
+
+class TestSuper < Test::Unit::TestCase
+ class Base
+ def single(a) a end
+ def double(a, b) [a,b] end
+ def array(*a) a end
+ def optional(a = 0) a end
+ end
+ class Single1 < Base
+ def single(*) super end
+ end
+ class Single2 < Base
+ def single(a,*) super end
+ end
+ class Double1 < Base
+ def double(*) super end
+ end
+ class Double2 < Base
+ def double(a,*) super end
+ end
+ class Double3 < Base
+ def double(a,b,*) super end
+ end
+ class Array1 < Base
+ def array(*) super end
+ end
+ class Array2 < Base
+ def array(a,*) super end
+ end
+ class Array3 < Base
+ def array(a,b,*) super end
+ end
+ class Array4 < Base
+ def array(a,b,c,*) super end
+ end
+ class Optional1 < Base
+ def optional(a = 1) super end
+ end
+ class Optional2 < Base
+ def optional(a, b = 1) super end
+ end
+ class Optional3 < Base
+ def single(a = 1) super end
+ end
+
+ def test_single1
+ assert_equal(1, Single1.new.single(1))
+ end
+ def test_single2
+ assert_equal(1, Single2.new.single(1))
+ end
+ def test_double1
+ assert_equal([1, 2], Double1.new.double(1, 2))
+ end
+ def test_double2
+ assert_equal([1, 2], Double2.new.double(1, 2))
+ end
+ def test_double3
+ assert_equal([1, 2], Double3.new.double(1, 2))
+ end
+ def test_array1
+ assert_equal([], Array1.new.array())
+ assert_equal([1], Array1.new.array(1))
+ end
+ def test_array2
+ assert_equal([1], Array2.new.array(1))
+ assert_equal([1,2], Array2.new.array(1, 2))
+ end
+ def test_array3
+ assert_equal([1,2], Array3.new.array(1, 2))
+ assert_equal([1,2,3], Array3.new.array(1, 2, 3))
+ end
+ def test_array4
+ assert_equal([1,2,3], Array4.new.array(1, 2, 3))
+ assert_equal([1,2,3,4], Array4.new.array(1, 2, 3, 4))
+ end
+ def test_optional1
+ assert_equal(9, Optional1.new.optional(9))
+ assert_equal(1, Optional1.new.optional)
+ end
+ def test_optional2
+ assert_raise(ArgumentError) do
+ # call Base#optional with 2 arguments; the 2nd arg is supplied
+ assert_equal(9, Optional2.new.optional(9))
+ end
+ assert_raise(ArgumentError) do
+ # call Base#optional with 2 arguments
+ assert_equal(9, Optional2.new.optional(9, 2))
+ end
+ end
+ def test_optional3
+ assert_equal(9, Optional3.new.single(9))
+ # call Base#single with 1 argument; the arg is supplied
+ assert_equal(1, Optional3.new.single)
+ end
+
+ class A
+ def tt(aa)
+ "A#tt"
+ end
+
+ def uu(a)
+ class << self
+ define_method(:tt) do |sym|
+ super
+ end
+ end
+ end
+ end
+
+ def test_define_method # [ruby-core:03856]
+ a = A.new
+ a.uu(12)
+ assert_equal("A#tt", a.tt(12))
+ end
+end
Added: trunk/test/ruby/test_trace.rb
===================================================================
--- trunk/test/ruby/test_trace.rb 2005-12-24 22:44:12 UTC (rev 324)
+++ trunk/test/ruby/test_trace.rb 2005-12-25 17:07:45 UTC (rev 325)
@@ -0,0 +1,21 @@
+require 'test/unit'
+
+class TestTrace < Test::Unit::TestCase
+ def test_trace
+ $x = 1234
+ $y = 0
+ trace_var :$x, proc{$y = $x}
+ $x = 40414
+ assert_equal($x, $y)
+
+ untrace_var :$x
+ $x = 19660208
+ assert_not_equal($x, $y)
+
+ trace_var :$x, proc{$x *= 2}
+ $x = 5
+ assert_equal(10, $x)
+
+ untrace_var :$x
+ end
+end
Added: trunk/test/ruby/test_variable.rb
===================================================================
--- trunk/test/ruby/test_variable.rb 2005-12-24 22:44:12 UTC (rev 324)
+++ trunk/test/ruby/test_variable.rb 2005-12-25 17:07:45 UTC (rev 325)
@@ -0,0 +1,57 @@
+require 'test/unit'
+
+class TestVariable < Test::Unit::TestCase
+ class Gods
+ @@rule = "Uranus"
+ def ruler0
+ @@rule
+ end
+
+ def self.ruler1 # <= per method definition style
+ @@rule
+ end
+ class << self # <= multiple method definition style
+ def ruler2
+ @@rule
+ end
+ end
+ end
+
+ module Olympians
+ @@rule ="Zeus"
+ def ruler3
+ @@rule
+ end
+ end
+
+ class Titans < Gods
+ @@rule = "Cronus" # do not affect @@rule in Gods
+ include Olympians
+ def ruler4
+ @@rule
+ end
+ end
+
+ def test_variable
+ assert_instance_of(Fixnum, $$)
+
+ # read-only variable
+ assert_raises(NameError) do
+ $$ = 5
+ end
+
+ foobar = "foobar"
+ $_ = foobar
+ assert_equal(foobar, $_)
+
+ assert_equal("Uranus", Gods.new.ruler0)
+ assert_equal("Uranus", Gods.ruler1)
+ assert_equal("Uranus", Gods.ruler2)
+ assert_equal("Uranus", Titans.ruler1)
+ assert_equal("Uranus", Titans.ruler2)
+ atlas = Titans.new
+ assert_equal("Uranus", atlas.ruler0)
+ assert_equal("Zeus", atlas.ruler3)
+ assert_equal("Cronus", atlas.ruler4)
+ end
+end
Added: trunk/test/ruby/test_whileuntil.rb
===================================================================
--- trunk/test/ruby/test_whileuntil.rb 2005-12-24 22:44:12 UTC (rev 324)
+++ trunk/test/ruby/test_whileuntil.rb 2005-12-25 17:07:45 UTC (rev 325)
@@ -0,0 +1,77 @@
+require 'test/unit'
+
+class TestWhileuntil < Test::Unit::TestCase
+ def test_while
+ tmp = open("while_tmp", "w")
+ tmp.print "tvi925\n";
+ tmp.print "tvi920\n";
+ tmp.print "vt100\n";
+ tmp.print "Amiga\n";
+ tmp.print "paper\n";
+ tmp.close
+
+ tmp = open("while_tmp", "r")
+ assert_instance_of(File, tmp)
+
+ while line = tmp.gets()
+ break if /vt100/ =~ line
+ end
+
+ assert(!tmp.eof?)
+ assert_match(/vt100/, line)
+ tmp.close
+
+ tmp = open("while_tmp", "r")
+ while line = tmp.gets()
+ next if /vt100/ =~ line
+ assert_no_match(/vt100/, line)
+ end
+ assert(tmp.eof?)
+ assert_no_match(/vt100/, line)
+ tmp.close
+
+ tmp = open("while_tmp", "r")
+ while tmp.gets()
+ line = $_
+ gsub(/vt100/, 'VT100')
+ if $_ != line
+ $_.gsub!('VT100', 'Vt100')
+ redo
+ end
+ assert_no_match(/vt100/, $_)
+ assert_no_match(/VT100/, $_)
+ end
+ assert(tmp.eof?)
+ tmp.close
+
+ sum=0
+ for i in 1..10
+ sum += i
+ i -= 1
+ if i > 0
+ redo
+ end
+ end
+ assert_equal(220, sum)
+
+ tmp = open("while_tmp", "r")
+ while line = tmp.gets()
+ break if 3
+ assert_no_match(/vt100/, line)
+ assert_no_match(/Amiga/, line)
+ assert_no_match(/paper/, line)
+ end
+ tmp.close
+
+ File.unlink "while_tmp" or `/bin/rm -f "while_tmp"`
+ assert(!File.exist?("while_tmp"))
+ end
+
+ def test_until
+ i = 0
+ until i>4
+ i+=1
+ end
+ assert(i>4)
+ end
+end
Added: trunk/test/runner.rb
===================================================================
--- trunk/test/runner.rb 2005-12-24 22:44:12 UTC (rev 324)
+++ trunk/test/runner.rb 2005-12-25 17:07:45 UTC (rev 325)
@@ -0,0 +1,9 @@
+require 'rbconfig'
+exit if CROSS_COMPILING
+require 'test/unit'
+
+rcsid = %w$Id: runner.rb,v 1.14 2005/02/17 04:50:49 ntalbott Exp $
+Version = rcsid[2].scan(/\d+/).collect!(&method(:Integer)).freeze
+Release = rcsid[3].freeze
+
+exit Test::Unit::AutoRunner.run(true, File.dirname($0))
--
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml