summaryrefslogtreecommitdiff
path: root/sample/test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'sample/test.rb')
-rw-r--r--sample/test.rb74
1 files changed, 54 insertions, 20 deletions
diff --git a/sample/test.rb b/sample/test.rb
index 8b8354a..7e96f01 100644
--- a/sample/test.rb
+++ b/sample/test.rb
@@ -71,10 +71,10 @@ a = *[*[1,2]]; test_ok(a == [1,2])
*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 = [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 = [*[1,2]]; test_ok(a == [[1,2]])
*a = *nil; test_ok(a == [nil])
*a = *1; test_ok(a == [1])
@@ -103,7 +103,7 @@ 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,[]])
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,[]])
@@ -133,10 +133,10 @@ 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 == [[nil]])}
def f; yield [[]]; end; f {|*a| test_ok(a == [[[]]])}
-def f; yield [1,2]; end; f {|*a| test_ok(a == [1,2])}
+def f; yield [1,2]; end; f {|*a| test_ok(a == [[1,2]])}
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 [*[1,2]]; end; f {|*a| test_ok(a == [[1,2]])}
def f; yield *nil; end; f {|*a| test_ok(a == [nil])}
def f; yield *1; end; f {|*a| test_ok(a == [1])}
@@ -164,7 +164,7 @@ 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,[]])}
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,[]])}
@@ -190,6 +190,16 @@ def r; return *[*[]]; end; a = r(); test_ok(a == nil)
def r; return *[*[1]]; end; a = r(); test_ok(a == 1)
def r; return *[*[1,2]]; end; a = r(); test_ok(a == [1,2])
+def r; return *nil; end; a = *r(); test_ok(a == nil)
+def r; return *1; end; a = *r(); test_ok(a == 1)
+def r; return *[]; end; a = *r(); test_ok(a == nil)
+def r; return *[1]; end; a = *r(); test_ok(a == 1)
+def r; return *[nil]; end; a = *r(); test_ok(a == nil)
+def r; return *[[]]; end; a = *r(); test_ok(a == nil)
+def r; return *[*[]]; end; a = *r(); test_ok(a == nil)
+def r; return *[*[1]]; end; a = *r(); test_ok(a == 1)
+def r; return *[*[1,2]]; end; a = *r(); test_ok(a == [1,2])
+
def r; return; end; *a = r(); test_ok(a == [nil])
def r; return nil; end; *a = r(); test_ok(a == [nil])
def r; return 1; end; *a = r(); test_ok(a == [1])
@@ -197,10 +207,10 @@ def r; return []; end; *a = r(); test_ok(a == [[]])
def r; return [1]; end; *a = r(); test_ok(a == [[1]])
def r; return [nil]; end; *a = r(); test_ok(a == [[nil]])
def r; return [[]]; end; *a = r(); test_ok(a == [[[]]])
-def r; return [1,2]; end; *a = r(); test_ok(a == [1,2])
+def r; return [1,2]; end; *a = r(); test_ok(a == [[1,2]])
def r; return [*[]]; end; *a = r(); test_ok(a == [[]])
def r; return [*[1]]; end; *a = r(); test_ok(a == [[1]])
-def r; return [*[1,2]]; end; *a = r(); test_ok(a == [1,2])
+def r; return [*[1,2]]; end; *a = r(); test_ok(a == [[1,2]])
def r; return *nil; end; *a = r(); test_ok(a == [nil])
def r; return *1; end; *a = r(); test_ok(a == [1])
@@ -208,10 +218,21 @@ def r; return *[]; end; *a = r(); test_ok(a == [nil])
def r; return *[1]; end; *a = r(); test_ok(a == [1])
def r; return *[nil]; end; *a = r(); test_ok(a == [nil])
def r; return *[[]]; end; *a = r(); test_ok(a == [[]])
-def r; return *[1,2]; end; *a = r(); test_ok(a == [1,2])
+def r; return *[1,2]; end; *a = r(); test_ok(a == [[1,2]])
def r; return *[*[]]; end; *a = r(); test_ok(a == [nil])
def r; return *[*[1]]; end; *a = r(); test_ok(a == [1])
-def r; return *[*[1,2]]; end; *a = r(); test_ok(a == [1,2])
+def r; return *[*[1,2]]; end; *a = r(); test_ok(a == [[1,2]])
+
+def r; return *nil; end; *a = *r(); test_ok(a == [nil])
+def r; return *1; end; *a = *r(); test_ok(a == [1])
+def r; return *[]; end; *a = *r(); test_ok(a == [nil])
+def r; return *[1]; end; *a = *r(); test_ok(a == [1])
+def r; return *[nil]; end; *a = *r(); test_ok(a == [nil])
+def r; return *[[]]; end; *a = *r(); test_ok(a == [])
+def r; return *[1,2]; end; *a = *r(); test_ok(a == [1,2])
+def r; return *[*[]]; end; *a = *r(); test_ok(a == [nil])
+def r; return *[*[1]]; end; *a = *r(); test_ok(a == [1])
+def r; return *[*[1,2]]; end; *a = *r(); test_ok(a == [1,2])
def r; return; end; a,b,*c = r(); test_ok([a,b,c] == [nil,nil,[]])
def r; return nil; end; a,b,*c = r(); test_ok([a,b,c] == [nil,nil,[]])
@@ -264,9 +285,9 @@ test_ok(f.call(42,55) == [42,55])
a,=*[1]
test_ok(a == 1)
a,=*[[1]]
-test_ok(a == 1)
-a,=*[[[1]]]
test_ok(a == [1])
+a,=*[[[1]]]
+test_ok(a == [[1]])
x, (y, z) = 1, 2, 3
test_ok([1,2,nil] == [x,y,z])
@@ -303,10 +324,10 @@ a = loop do break *[*[1,2]]; end; test_ok(a == [1,2])
*a = loop do break [1]; end; test_ok(a == [[1]])
*a = loop do break [nil]; end; test_ok(a == [[nil]])
*a = loop do break [[]]; end; test_ok(a == [[[]]])
-*a = loop do break [1,2]; end; test_ok(a == [1,2])
+*a = loop do break [1,2]; end; test_ok(a == [[1,2]])
*a = loop do break [*[]]; end; test_ok(a == [[]])
*a = loop do break [*[1]]; end; test_ok(a == [[1]])
-*a = loop do break [*[1,2]]; end; test_ok(a == [1,2])
+*a = loop do break [*[1,2]]; end; test_ok(a == [[1,2]])
*a = loop do break *nil; end; test_ok(a == [nil])
*a = loop do break *1; end; test_ok(a == [1])
@@ -314,10 +335,21 @@ a = loop do break *[*[1,2]]; end; test_ok(a == [1,2])
*a = loop do break *[1]; end; test_ok(a == [1])
*a = loop do break *[nil]; end; test_ok(a == [nil])
*a = loop do break *[[]]; end; test_ok(a == [[]])
-*a = loop do break *[1,2]; end; test_ok(a == [1,2])
+*a = loop do break *[1,2]; end; test_ok(a == [[1,2]])
*a = loop do break *[*[]]; end; test_ok(a == [nil])
*a = loop do break *[*[1]]; end; test_ok(a == [1])
-*a = loop do break *[*[1,2]]; end; test_ok(a == [1,2])
+*a = loop do break *[*[1,2]]; end; test_ok(a == [[1,2]])
+
+*a = *loop do break *nil; end; test_ok(a == [nil])
+*a = *loop do break *1; end; test_ok(a == [1])
+*a = *loop do break *[]; end; test_ok(a == [nil])
+*a = *loop do break *[1]; end; test_ok(a == [1])
+*a = *loop do break *[nil]; end; test_ok(a == [nil])
+*a = *loop do break *[[]]; end; test_ok(a == [])
+*a = *loop do break *[1,2]; end; test_ok(a == [1,2])
+*a = *loop do break *[*[]]; end; test_ok(a == [nil])
+*a = *loop do break *[*[1]]; end; test_ok(a == [1])
+*a = *loop do break *[*[1,2]]; end; test_ok(a == [1,2])
a,b,*c = loop do break; end; test_ok([a,b,c] == [nil,nil,[]])
a,b,*c = loop do break nil; end; test_ok([a,b,c] == [nil,nil,[]])
@@ -372,17 +404,18 @@ r([[]]){next []}
r([[1]]){next [1]}
r([[nil]]){next [nil]}
r([[[]]]){next [[]]}
-r([1,2]){next [1,2]}
+r([[1,2]]){next [1,2]}
r([[]]){next [*[]]}
r([[1]]){next [*[1]]}
-r([1,2]){next [*[1,2]]}
+r([[1,2]]){next [*[1,2]]}
+def r(val); *a = *yield(); test_ok(a == val); end
r([nil]){next *nil}
r([1]){next *1}
r([nil]){next *[]}
r([1]){next *[1]}
r([nil]){next *[nil]}
-r([[]]){next *[[]]}
+r([]){next *[[]]}
r([1,2]){next *[1,2]}
r([nil]){next *[*[]]}
r([1]){next *[*[1]]}
@@ -401,6 +434,7 @@ r([nil,nil,[]]){next [*[]]}
r([1,nil,[]]){next [*[1]]}
r([1,2,[]]){next [*[1,2]]}
+def r(val); a,b,*c = *yield(); test_ok([a,b,c] == val); end
r([nil,nil,[]]){next *nil}
r([1,nil,[]]){next *1}
r([nil,nil,[]]){next *[]}
@@ -716,7 +750,7 @@ test_ok(($x * 5).join(":") == '1:1:1:1:1')
test_ok(($x * 1).join(":") == '1')
test_ok(($x * 0).join(":") == '')
-*$x = (1..7).to_a
+*$x = *(1..7).to_a
test_ok($x.size == 7)
test_ok($x == [1, 2, 3, 4, 5, 6, 7])