summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-02-23 07:59:54 +0000
committeraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-02-23 07:59:54 +0000
commitf52fd2165bae52154e2069dd35811441c6eaecac (patch)
treeefb6bbd9b691f66c19c803cd00d9a4b7274c7ea7
parent3207cd3897cd40d7801c7e8f422942b7fadb6807 (diff)
* test/ruby/test_assignment.rb: merge yarvtest/test_massign.
* yarvtest/test_massign.rb: removed (merged to test_assignment.rb). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11830 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--test/ruby/test_assignment.rb94
-rw-r--r--yarvtest/test_massign.rb417
3 files changed, 94 insertions, 424 deletions
diff --git a/ChangeLog b/ChangeLog
index e2f6c6e105..15780c65f7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Fri Feb 23 16:59:39 2007 Minero Aoki <aamine@loveruby.net>
+
+ * test/ruby/test_assignment.rb: merge yarvtest/test_massign.
+
+ * yarvtest/test_massign.rb: removed (merged to
+ test_assignment.rb).
+
Fri Feb 23 15:58:20 2007 NAKAMURA Usaku <usa@ruby-lang.org>
* signal.c (sighandler): need to re-install sighandler on some
diff --git a/test/ruby/test_assignment.rb b/test/ruby/test_assignment.rb
index ba3b9a7094..69db708187 100644
--- a/test/ruby/test_assignment.rb
+++ b/test/ruby/test_assignment.rb
@@ -203,6 +203,10 @@ class TestAssignment < Test::Unit::TestCase
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 1, *[]; end; a,b = r(); assert_equal([1,nil], [a,b]); undef r
+ def r; return 1,2,*[1]; end; a,b = r(); assert_equal([1,2], [a,b]); undef r
+ def r; return 1,2,3,*[1,2]; end; a,b = r(); assert_equal([1,2], [a,b]); undef r
end
def test_lambda
@@ -378,26 +382,57 @@ class TestAssignment < Test::Unit::TestCase
undef r
end
- def test_assign2
+ def test_massign
a = nil
assert(defined?(a))
assert_nil(a)
# multiple asignment
a, b = 1, 2
- assert(a == 1 && b == 2)
+ assert_equal 1, a
+ assert_equal 2, b
+
+ a, b, c = 1, 2, 3
+ assert_equal 1, a
+ assert_equal 2, b
+ assert_equal 3, c
+ a = 1
+ b = 2
a, b = b, a
- assert(a == 2 && b == 1)
+ assert_equal 2, a
+ assert_equal 1, b
- a, = 1,2
- assert_equal(1, a)
+ a, = 1, 2
+ assert_equal 1, a
+
+ a, = 1, 2, 3
+ assert_equal 1, a
+
+ a, * = 1, 2, 3
+ assert_equal 1, a
a, *b = 1, 2, 3
- assert(a == 1 && b == [2, 3])
+ assert_equal 1, a
+ assert_equal [2, 3], b
+
+ # not supported yet
+ #a, *b, c = 1, 2, 3, 4
+ #assert_equal 1, a
+ #assert_equal [2,3], b
+ #assert_equal 4, c
+
+ a = 1, 2
+ assert_equal [1, 2], a
+
+ a = [1, 2], [3, 4]
+ assert_equal [[1,2], [3,4]], a
a, (b, c), d = 1, [2, 3], 4
- assert(a == 1 && b == 2 && c == 3 && d == 4)
+ assert_equal 1, a
+ assert_equal 2, b
+ assert_equal 3, c
+ assert_equal 4, d
*a = 1, 2, 3
assert_equal([1, 2, 3], a)
@@ -407,5 +442,50 @@ class TestAssignment < Test::Unit::TestCase
*a = nil
assert_equal([nil], a)
+
+ a, b = 1
+ assert_equal 1, a
+ assert_nil b
+
+ a, b = [1, 2]
+ assert_equal 1, a
+ assert_equal 2, b
+ end
+
+ def test_nested_massign
+ (a, b), c = [[1, 2], 3]; assert_equal [1,2,3], [a,b,c]
+ a, (b, c) = [[1, 2], 3]; assert_equal [[1,2], 3, nil], [a,b,c]
+ a, (b, c) = [1, [2, 3]]; assert_equal [1,2,3], [a,b,c]
+ (a, b), *c = [[1, 2], 3]; assert_equal [1,2,[3]], [a,b,c]
+ (a,b),c,(d,e) = [[1,2],3,[4,5]]; assert_equal [1,2,3,4,5],[a,b,c,d,e]
+ (a,*b),c,(d,e,*) = [[1,2],3,[4,5]]; assert_equal [1,[2],3,4,5],[a,b,c,d,e]
+ (a,b),c,(d,*e) = [[1,2,3],4,[5,6,7,8]]; assert_equal [1,2,4,5,[6,7,8]],[a,b,c,d,e]
+ (a,(b1,b2)),c,(d,e) = [[1,2],3,[4,5]]; assert_equal [1,2,nil,3,4,5],[a,b1,b2,c,d,e]
+ (a,(b1,b2)),c,(d,e) = [[1,[21,22]],3,[4,5]]; assert_equal [1,21,22,3,4,5],[a,b1,b2,c,d,e]
+ end
+
+ class MyObj
+ def to_ary
+ [[1,2],[3,4]]
+ end
+ end
+
+ def test_to_ary_splat
+ a, b = MyObj.new
+ assert_equal [[1,2],[3,4]], [a,b]
+ end
+
+ A = 1
+ B = 2
+ X, Y = A, B
+ class Base
+ A = 3
+ B = 4
+ end
+
+ def test_const_massign
+ assert_equal [1,2], [X,Y]
+ a, b = Base::A, Base::B
+ assert_equal [3,4], [a,b]
end
end
diff --git a/yarvtest/test_massign.rb b/yarvtest/test_massign.rb
deleted file mode 100644
index 0b253f7665..0000000000
--- a/yarvtest/test_massign.rb
+++ /dev/null
@@ -1,417 +0,0 @@
-require 'yarvtest/yarvtest'
-
-# test of syntax
-class TestMassign < YarvTestBase
- def test_simle
- ae %q{
- a = :a; b = :b; c = :c
- x, y = a, b
- [x, y]
- }
- ae %q{
- a = :a; b = :b; c = :c
- x, y, z = a, b, c
- [x, y, z]
- }
- end
-
- def test_diff_elems
- ae %q{
- a = :a ; b = :b ; c = :c
- x, y, z = a, b
- [x, y, z]
- }
- ae %q{
- a = :a; b = :b; c = :c
- x, y = a, b, c
- [x, y]
- }
- end
-
- def test_single_l
- ae %q{
- a = :a; b = :b
- x = a, b
- x
- }
- ae %q{
- a = [1, 2]; b = [3, 4]
- x = a, b
- x
- }
- end
-
- def test_single_r
- ae %q{
- a = :a
- x, y = a
- [x, y]
- }
- ae %q{
- a = [1, 2]
- x, y = a
- [x, y]
- }
- ae %q{
- a = [1, 2, 3]
- x, y = a
- [x, y]
- }
- end
-
- def test_splat_l
- ae %q{
- a = :a; b = :b; c = :c
- *x = a, b
- [x]
- }
- ae %q{
- a = :a; b = :b; c = :c
- *x = a, b
- [x]
- }
- ae %q{
- a = :a; b = :b; c = :c
- x, * = a, b
- [x]
- }
- ae %q{
- a = :a; b = :b; c = :c
- x, *y = a, b
- [x, y]
- }
- ae %q{
- a = :a; b = :b; c = :c
- x, y, *z = a, b
- [x, y]
- }
- ae %q{ # only one item on rhs
- *x = :x
- x
- }
- ae %q{ # nil on rhs
- *x = nil
- x
- }
- end
-
- def test_splat_r
- if false
- ae %q{
- a = :a; b = :b; c = :c
- x, y = *a
- [x, y]
- }
- ae %q{
- a = :a; b = :b; c = :c
- x, y = a, *b
- [x, y]
- }
- ae %q{
- a = :a; b = :b; c = :c
- x, y = a, b, *c
- [x, y]
- }
- ae %q{
- x=*nil
- x
- }
- end
-
- ae %q{
- a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
- x, y = *a
- [x, y]
- }
- ae %q{
- a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
- x, y = a, *b
- [x, y]
- }
- ae %q{
- a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
- x, y = a, b, *c
- [x, y]
- }
- end
-
- def test_splat_b1
- if false
- # error
- ae %q{
- a = :a; b = :b; c = :c
- x, *y = *a
- [x, y]
- }
- ae %q{
- a = :a; b = :b; c = :c
- x, *y = a, *b
- [x, y]
- }
- ae %q{
- a = :a; b = :b; c = :c
- x, *y = a, b, *c
- [x, y]
- }
- end
-
- ae %q{
- a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
- x, *y = *a
- [x, y]
- }
- ae %q{
- a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
- x, *y = a, *b
- [x, y]
- }
- ae %q{
- a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
- x, *y = a, b, *c
- [x, y]
- }
- end
-
- def test_splat_b2
- if false
- # error
- ae %q{
- a = :a; b = :b; c = :c
- *x = *a
- x
- }
- ae %q{
- a = :a; b = :b; c = :c
- *x = a, *b
- x
- }
- ae %q{
- a = :a; b = :b; c = :c
- *x = a, b, *c
- x
- }
- end
-
- ae %q{
- a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
- *x = *a
- x
- }
- ae %q{
- a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
- *x = a, *b
- x
- }
- ae %q{
- a = [:a, :a2]; b = [:b, :b2]; c = [:c, :c2]
- *x = a, b, *c
- x
- }
- end
-
- def test_toary
- ae %q{
- x, y = :a
- [x, y]
- }
- ae %q{
- x, y = [1, 2]
- [x, y]
- }
- ae %q{
- x, y = [1, 2, 3]
- [x, y]
- }
- end
-
- def test_swap
- ae %q{
- a = 1; b = 2
- a, b = b, a
- [a, b]
- }
- end
-
- def test_mret
- ae %q{
- def m
- return 1, 2
- end
-
- a, b = m
- [a, b]
- }
- ae %q{
- def m
- return 1, 2
- end
-
- a = m
- [a]
- }
- ae %q{
- def m
- return 1
- end
-
- a, b = m
- [a, b]
- }
- end
-
- def test_mret_splat
- if false
- ae %q{
- def m
- return *1
- end
- a, b = m
- [a, b]
- }
- end
-
- ae %q{
- def m
- return *[]
- end
- a, b = m
- [a, b]
- }
- ae %q{
- def m
- return *[1]
- end
- a, b = m
- [a, b]
- }
- ae %q{
- def m
- return *[1,2]
- end
- a, b = m
- [a, b]
- }
- ae %q{
- def m
- return *[1,2,3]
- end
- a, b = m
- [a, b]
- }
- ae %q{
- def m
- return *[1]
- end
- a = m
- }
- end
-
- def test_mret_argscat
- ae %q{
- def m
- return 1, *[]
- end
- a, b = m
- [a, b]
- }
- ae %q{
- def m
- return 1, 2, *[1]
- end
- a, b = m
- [a, b]
- }
- ae %q{
- def m
- return 1, 2, 3, *[1,2]
- end
- a, b = m
- [a, b]
- }
- end
-
- def test_nested_massign
- ae %q{
- (a, b), c = [[1, 2], 3]
- [a, b, c]
- }
- ae %q{
- a, (b, c) = [[1, 2], 3]
- [a, b, c]
- }
- ae %q{
- a, (b, c) = [1, [2, 3]]
- [a, b, c]
- }
- ae %q{
- (a, b), *c = [[1, 2], 3]
- [a, b, c]
- }
- ae %q{
- (a, b), c, (d, e) = [[1, 2], 3, [4, 5]]
- [a, b, c, d, e]
- }
- ae %q{
- (a, *b), c, (d, e, *) = [[1, 2], 3, [4, 5]]
- [a, b, c, d, e]
- }
- ae %q{
- (a, b), c, (d, *e) = [[1, 2, 3], 3, [4, 5, 6, 7]]
- [a, b, c, d, e]
- }
- ae %q{
- (a, (b1, b2)), c, (d, e) = [[1, 2], 3, [4, 5]]
- [a, b1, b2, c, d, e]
- }
- ae %q{
- (a, (b1, b2)), c, (d, e) = [[1, [21, 22]], 3, [4, 5]]
- [a, b1, b2, c, d, e]
- }
- end
-
- # ignore
- def _test_massign_value
- # Value of this massign statement should be [1, 2, 3]
- ae %q{
- a, b, c = [1, 2, 3]
- }
- end
-
- def test_nested_splat
- # Somewhat obscure nested splat
- ae %q{
- a = *[*[1]]
- a
- }
- end
-
- def test_calls_to_a
- # Should be result of calling to_a on arg, ie [[1, 2], [3, 4]]
- ae %q{
- x=*{1=>2,3=>4}
- x
- }
- end
-
- def test_const_massign
- ae %q{
- class C
- class D
- end
- end
-
- X, Y = 1, 2
- Z, C::Const, C::D::Const, ::C::Const2 = 3, 4, 5, 6
- [X, Y, Z, C::Const, C::D::Const, ::C::Const2]
- }
- end
-
- def test_massign_values
- ae %q{
- ary = [1, 2].partition {|n| n == 1 }
- a, b = ary
- [a, b]
- }
- end
-end
-