summaryrefslogtreecommitdiff
path: root/sample/test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'sample/test.rb')
-rw-r--r--sample/test.rb165
1 files changed, 77 insertions, 88 deletions
diff --git a/sample/test.rb b/sample/test.rb
index b16d7779c1..f8a3eb447e 100644
--- a/sample/test.rb
+++ b/sample/test.rb
@@ -48,6 +48,7 @@ a = []; test_ok(a == [])
a = [1]; test_ok(a == [1])
a = [nil]; test_ok(a == [nil])
a = [[]]; test_ok(a == [[]])
+a = [1,2]; test_ok(a == [1,2])
a = [*[]]; test_ok(a == [])
a = [*[1]]; test_ok(a == [1])
a = [*[1,2]]; test_ok(a == [1,2])
@@ -58,50 +59,56 @@ a = *[]; test_ok(a == nil)
a = *[1]; test_ok(a == 1)
a = *[nil]; test_ok(a == nil)
a = *[[]]; test_ok(a == [])
+a = *[1,2]; test_ok(a == [1,2])
a = *[*[]]; test_ok(a == nil)
a = *[*[1]]; test_ok(a == 1)
a = *[*[1,2]]; test_ok(a == [1,2])
-*a = nil; test_ok(a == [])
+*a = nil; test_ok(a == [nil])
*a = 1; test_ok(a == [1])
*a = []; test_ok(a == [])
*a = [1]; test_ok(a == [1])
*a = [nil]; test_ok(a == [nil])
*a = [[]]; test_ok(a == [[]])
+*a = [1,2]; test_ok(a == [1,2])
*a = [*[]]; test_ok(a == [])
*a = [*[1]]; test_ok(a == [1])
*a = [*[1,2]]; test_ok(a == [1,2])
-*a = *nil; test_ok(a == [])
+*a = *nil; test_ok(a == [nil])
*a = *1; test_ok(a == [1])
*a = *[]; test_ok(a == [])
*a = *[1]; test_ok(a == [1])
-*a = *[nil]; test_ok(a == [])
+*a = *[nil]; test_ok(a == [nil])
*a = *[[]]; test_ok(a == [])
+*a = *[1,2]; test_ok(a == [1,2])
*a = *[*[]]; test_ok(a == [])
*a = *[*[1]]; test_ok(a == [1])
*a = *[*[1,2]]; test_ok(a == [1,2])
-a,b,*c = nil; test_ok([a,b,c] == [nil, nil, []])
-a,b,*c = 1; test_ok([a,b,c] == [1, nil, []])
-a,b,*c = []; test_ok([a,b,c] == [nil, nil, []])
-a,b,*c = [1]; test_ok([a,b,c] == [1, nil, []])
-a,b,*c = [nil]; test_ok([a,b,c] == [nil, nil, []])
-a,b,*c = [[]]; test_ok([a,b,c] == [[], nil, []])
-a,b,*c = [*[]]; test_ok([a,b,c] == [nil, nil, []])
-a,b,*c = [*[1]]; test_ok([a,b,c] == [1, nil, []])
-a,b,*c = [*[1,2]]; test_ok([a,b,c] == [1, 2, []])
-
-a,b,*c = *nil; test_ok([a,b,c] == [nil, nil, []])
-a,b,*c = *1; test_ok([a,b,c] == [1, nil, []])
-a,b,*c = *[]; test_ok([a,b,c] == [nil, nil, []])
-a,b,*c = *[1]; test_ok([a,b,c] == [1, nil, []])
-a,b,*c = *[nil]; test_ok([a,b,c] == [nil, nil, []])
-a,b,*c = *[[]]; test_ok([a,b,c] == [nil, nil, []])
-a,b,*c = *[*[]]; test_ok([a,b,c] == [nil, nil, []])
-a,b,*c = *[*[1]]; test_ok([a,b,c] == [1, nil, []])
-a,b,*c = *[*[1,2]]; test_ok([a,b,c] == [1, 2, []])
-
+a,b,*c = nil; test_ok([a,b,c] == [nil,nil,[]])
+a,b,*c = 1; test_ok([a,b,c] == [1,nil,[]])
+a,b,*c = []; test_ok([a,b,c] == [nil,nil,[]])
+a,b,*c = [1]; test_ok([a,b,c] == [1,nil,[]])
+a,b,*c = [nil]; test_ok([a,b,c] == [nil,nil,[]])
+a,b,*c = [[]]; test_ok([a,b,c] == [[],nil,[]])
+a,b,*c = [1,2]; test_ok([a,b,c] == [1,2,[]])
+a,b,*c = [*[]]; test_ok([a,b,c] == [nil,nil,[]])
+a,b,*c = [*[1]]; test_ok([a,b,c] == [1,nil,[]])
+a,b,*c = [*[1,2]]; test_ok([a,b,c] == [1,2,[]])
+
+a,b,*c = *nil; test_ok([a,b,c] == [nil,nil,[]])
+a,b,*c = *1; test_ok([a,b,c] == [1,nil,[]])
+a,b,*c = *[]; test_ok([a,b,c] == [nil,nil,[]])
+a,b,*c = *[1]; test_ok([a,b,c] == [1,nil,[]])
+a,b,*c = *[nil]; test_ok([a,b,c] == [nil,nil,[]])
+a,b,*c = *[[]]; test_ok([a,b,c] == [nil,nil,[]])
+a,b,*c = *[1,2]; test_ok([a,b,c] == [1,2,[]])
+a,b,*c = *[*[]]; test_ok([a,b,c] == [nil,nil,[]])
+a,b,*c = *[*[1]]; test_ok([a,b,c] == [1,nil,[]])
+a,b,*c = *[*[1,2]]; test_ok([a,b,c] == [1,2,[]])
+
+def f; yield; end; f {|a| test_ok(a == nil)}
def f; yield nil; end; f {|a| test_ok(a == nil)}
def f; yield 1; end; f {|a| test_ok(a == 1)}
def f; yield []; end; f {|a| test_ok(a == [])}
@@ -122,7 +129,8 @@ def f; yield *[*[]]; end; f {|a| test_ok(a == nil)}
def f; yield *[*[1]]; end; f {|a| test_ok(a == 1)}
def f; yield *[*[1,2]]; end; f {|a| test_ok(a == [1,2])}
-def f; yield nil; end; f {|*a| test_ok(a == [])}
+def f; yield; end; f {|*a| test_ok(a == [])}
+def f; yield nil; end; f {|*a| test_ok(a == [nil])}
def f; yield 1; end; f {|*a| test_ok(a == [1])}
def f; yield []; end; f {|*a| test_ok(a == [])}
def f; yield [1]; end; f {|*a| test_ok(a == [1])}
@@ -132,35 +140,36 @@ def f; yield [*[]]; end; f {|*a| test_ok(a == [])}
def f; yield [*[1]]; end; f {|*a| test_ok(a == [1])}
def f; yield [*[1,2]]; end; f {|*a| test_ok(a == [1,2])}
-def f; yield *nil; end; f {|*a| test_ok(a == [])}
+def f; yield *nil; end; f {|*a| test_ok(a == [nil])}
def f; yield *1; end; f {|*a| test_ok(a == [1])}
def f; yield *[]; end; f {|*a| test_ok(a == [])}
def f; yield *[1]; end; f {|*a| test_ok(a == [1])}
-def f; yield *[nil]; end; f {|*a| test_ok(a == [])}
+def f; yield *[nil]; end; f {|*a| test_ok(a == [nil])}
def f; yield *[[]]; end; f {|*a| test_ok(a == [])}
def f; yield *[*[]]; end; f {|*a| test_ok(a == [])}
def f; yield *[*[1]]; end; f {|*a| test_ok(a == [1])}
def f; yield *[*[1,2]]; end; f {|*a| test_ok(a == [1,2])}
-def f; yield nil; end; f {|a,b,*c| test_ok([a,b,c] == [nil, nil, []])}
-def f; yield 1; end; f {|a,b,*c| test_ok([a,b,c] == [1, nil, []])}
-def f; yield []; end; f {|a,b,*c| test_ok([a,b,c] == [nil, nil, []])}
-def f; yield [1]; end; f {|a,b,*c| test_ok([a,b,c] == [1, nil, []])}
-def f; yield [nil]; end; f {|a,b,*c| test_ok([a,b,c] == [nil, nil, []])}
-def f; yield [[]]; end; f {|a,b,*c| test_ok([a,b,c] == [[], nil, []])}
-def f; yield [*[]]; end; f {|a,b,*c| test_ok([a,b,c] == [nil, nil, []])}
-def f; yield [*[1]]; end; f {|a,b,*c| test_ok([a,b,c] == [1, nil, []])}
-def f; yield [*[1,2]]; end; f {|a,b,*c| test_ok([a,b,c] == [1, 2, []])}
-
-def f; yield *nil; end; f {|a,b,*c| test_ok([a,b,c] == [nil, nil, []])}
-def f; yield *1; end; f {|a,b,*c| test_ok([a,b,c] == [1, nil, []])}
-def f; yield *[]; end; f {|a,b,*c| test_ok([a,b,c] == [nil, nil, []])}
-def f; yield *[1]; end; f {|a,b,*c| test_ok([a,b,c] == [1, nil, []])}
-def f; yield *[nil]; end; f {|a,b,*c| test_ok([a,b,c] == [nil, nil, []])}
-def f; yield *[[]]; end; f {|a,b,*c| test_ok([a,b,c] == [nil, nil, []])}
-def f; yield *[*[]]; end; f {|a,b,*c| test_ok([a,b,c] == [nil, nil, []])}
-def f; yield *[*[1]]; end; f {|a,b,*c| test_ok([a,b,c] == [1, nil, []])}
-def f; yield *[*[1,2]]; end; f {|a,b,*c| test_ok([a,b,c] == [1, 2, []])}
+def f; yield; end; f {|a,b,*c| test_ok([a,b,c] == [nil,nil,[]])}
+def f; yield nil; end; f {|a,b,*c| test_ok([a,b,c] == [nil,nil,[]])}
+def f; yield 1; end; f {|a,b,*c| test_ok([a,b,c] == [1,nil,[]])}
+def f; yield []; end; f {|a,b,*c| test_ok([a,b,c] == [nil,nil,[]])}
+def f; yield [1]; end; f {|a,b,*c| test_ok([a,b,c] == [1,nil,[]])}
+def f; yield [nil]; end; f {|a,b,*c| test_ok([a,b,c] == [nil,nil,[]])}
+def f; yield [[]]; end; f {|a,b,*c| test_ok([a,b,c] == [[],nil,[]])}
+def f; yield [*[]]; end; f {|a,b,*c| test_ok([a,b,c] == [nil,nil,[]])}
+def f; yield [*[1]]; end; f {|a,b,*c| test_ok([a,b,c] == [1,nil,[]])}
+def f; yield [*[1,2]]; end; f {|a,b,*c| test_ok([a,b,c] == [1,2,[]])}
+
+def f; yield *nil; end; f {|a,b,*c| test_ok([a,b,c] == [nil,nil,[]])}
+def f; yield *1; end; f {|a,b,*c| test_ok([a,b,c] == [1,nil,[]])}
+def f; yield *[]; end; f {|a,b,*c| test_ok([a,b,c] == [nil,nil,[]])}
+def f; yield *[1]; end; f {|a,b,*c| test_ok([a,b,c] == [1,nil,[]])}
+def f; yield *[nil]; end; f {|a,b,*c| test_ok([a,b,c] == [nil,nil,[]])}
+def f; yield *[[]]; end; f {|a,b,*c| test_ok([a,b,c] == [nil,nil,[]])}
+def f; yield *[*[]]; end; f {|a,b,*c| test_ok([a,b,c] == [nil,nil,[]])}
+def f; yield *[*[1]]; end; f {|a,b,*c| test_ok([a,b,c] == [1,nil,[]])}
+def f; yield *[*[1,2]]; end; f {|a,b,*c| test_ok([a,b,c] == [1,2,[]])}
test_check "condition"
@@ -679,48 +688,28 @@ class IterTest
end
IterTest.new(nil).method(:f).to_proc.call([1])
-IterTest.new([0]).each0 { |x| $x = x }
-test_ok($x == 0)
-IterTest.new([1]).each1 { |x| $x = x }
-test_ok($x == 1)
-IterTest.new([2]).each2 { |x| $x = x }
-test_ok($x == [2])
-IterTest.new([3]).each3 { |x| $x = x }
-test_ok($x == 3)
-IterTest.new([4]).each4 { |x| $x = x }
-test_ok($x == 4)
-IterTest.new([5]).each5 { |x| $x = x }
-test_ok($x == 5)
-IterTest.new([6]).each6 { |x| $x = x }
-test_ok($x == [6])
-IterTest.new([7]).each7 { |x| $x = x }
-test_ok($x == 7)
-IterTest.new([8]).each8 { |x| $x = x }
-test_ok($x == 8)
-
-IterTest.new([[0]]).each0 { |x| $x = x }
-test_ok($x == [0])
-IterTest.new([[1]]).each1 { |x| $x = x }
-test_ok($x == 1)
-IterTest.new([[2]]).each2 { |x| $x = x }
-test_ok($x == [2])
-IterTest.new([[3]]).each3 { |x| $x = x }
-test_ok($x == 3)
-IterTest.new([[4]]).each4 { |x| $x = x }
-test_ok($x == [4])
-IterTest.new([[5]]).each5 { |x| $x = x }
-test_ok($x == 5)
-IterTest.new([[6]]).each6 { |x| $x = x }
-test_ok($x == [6])
-IterTest.new([[7]]).each7 { |x| $x = x }
-test_ok($x == 7)
-IterTest.new([[8]]).each8 { |x| $x = x }
-test_ok($x == [8])
-
-IterTest.new([[0,0]]).each0 { |x| $x = x }
-test_ok($x == [0,0])
-IterTest.new([[8,8]]).each8 { |x| $x = x }
-test_ok($x == [8,8])
+IterTest.new([0]).each0 { |x| test_ok(x == 0)}
+IterTest.new([1]).each1 { |x| test_ok(x == 1)}
+IterTest.new([2]).each2 { |x| test_ok(x == [2])}
+IterTest.new([3]).each3 { |x| test_ok(x == 3)}
+IterTest.new([4]).each4 { |x| test_ok(x == 4)}
+IterTest.new([5]).each5 { |x| test_ok(x == 5)}
+IterTest.new([6]).each6 { |x| test_ok(x == [6])}
+IterTest.new([7]).each7 { |x| test_ok(x == 7)}
+IterTest.new([8]).each8 { |x| test_ok(x == 8)}
+
+IterTest.new([[0]]).each0 { |x| test_ok(x == [0])}
+IterTest.new([[1]]).each1 { |x| test_ok(x == 1)}
+IterTest.new([[2]]).each2 { |x| test_ok(x == [2])}
+IterTest.new([[3]]).each3 { |x| test_ok(x == 3)}
+IterTest.new([[4]]).each4 { |x| test_ok(x == [4])}
+IterTest.new([[5]]).each5 { |x| test_ok(x == 5)}
+IterTest.new([[6]]).each6 { |x| test_ok(x == [6])}
+IterTest.new([[7]]).each7 { |x| test_ok(x == 7)}
+IterTest.new([[8]]).each8 { |x| test_ok(x == [8])}
+
+IterTest.new([[0,0]]).each0 { |x| test_ok(x == [0,0])}
+IterTest.new([[8,8]]).each8 { |x| test_ok(x == [8,8])}
test_check "float"
test_ok(2.6.floor == 2)
@@ -948,7 +937,7 @@ test_ok(a == [1, 2, 3])
test_ok(a == [4])
*a = nil
-test_ok(a == [])
+test_ok(a == [nil])
test_check "call"
def aaa(a, b=100, *rest)