diff options
Diffstat (limited to 'sample/test.rb')
-rw-r--r-- | sample/test.rb | 122 |
1 files changed, 121 insertions, 1 deletions
diff --git a/sample/test.rb b/sample/test.rb index 10ae5e5301..ed2ebcf15a 100644 --- a/sample/test.rb +++ b/sample/test.rb @@ -42,6 +42,126 @@ cc = 5 cc &&=44 test_ok(cc == 44) +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 = [*[]]; test_ok(a == []) +a = [*[1]]; test_ok(a == [1]) +a = [*[1,2]]; test_ok(a == [1,2]) + +a = *nil; test_ok(a == nil) +a = *1; test_ok(a == 1) +a = *[]; test_ok(a == nil) +a = *[1]; test_ok(a == 1) +a = *[nil]; test_ok(a == nil) +a = *[[]]; test_ok(a == []) +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 = 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 = [*[]]; test_ok(a == []) +*a = [*[1]]; test_ok(a == [1]) +*a = [*[1,2]]; test_ok(a == [1,2]) + +*a = *nil; test_ok(a == []) +*a = *1; test_ok(a == [1]) +*a = *[]; test_ok(a == []) +*a = *[1]; test_ok(a == [1]) +*a = *[nil]; test_ok(a == []) +*a = *[[]]; test_ok(a == []) +*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, []]) + +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 == [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| test_ok(a == nil)} +def f; yield *1; end; f {|a| test_ok(a == 1)} +def f; yield *[]; end; f {|a| test_ok(a == nil)} +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 *[*[]]; 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 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 == [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| test_ok(a == [])} +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 *[[]]; 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, []])} + test_check "condition" $x = '0'; @@ -768,7 +888,7 @@ test_ok(a == [1, 2, 3]) test_ok(a == [4]) *a = nil -test_ok(a == [nil]) +test_ok(a == []) test_check "call" def aaa(a, b=100, *rest) |