* lib/optparse.rb (OptionParser#order, #permute, #parse): allow an

array as argument.

* test/ruby/test_*.rb: moved invariants to left side in
  assert_equal, and use assert_nil, assert_raises and so on.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4516 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2003-09-05 15:15:43 +00:00
Родитель 01e3a55648
Коммит 44785befea
32 изменённых файлов: 789 добавлений и 803 удалений

Просмотреть файл

@ -1,3 +1,11 @@
Sat Sep 6 00:15:09 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/optparse.rb (OptionParser#order, #permute, #parse): allow an
array as argument.
* test/ruby/test_*.rb: moved invariants to left side in
assert_equal, and use assert_nil, assert_raises and so on.
Sat Sep 6 00:00:20 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/mkmf.rb (have_library, find_library): configure by library

Просмотреть файл

@ -801,6 +801,14 @@ Default options, which never appear in option summary.
end
end
def warn(mesg = $!)
super(program_name + ': ' + mesg)
end
def abort(mesg = $!)
super(program_name + ': ' + mesg)
end
=begin
--- OptionParser#top
Subject of ((<on>))/((<on_head>)), ((<accept>))/((<reject>)).
@ -1120,7 +1128,10 @@ Default options, which never appear in option summary.
: (({block}))
called with each non-option argument.
=end #'#"#`#
def order(*argv, &block) order!(argv, &block) end
def order(*argv, &block)
argv = argv[0].dup if argv.size == 1 and Array === argv[0]
order!(argv, &block)
end
def order!(argv = ARGV, &nonopt)
opt, arg, sw, val, rest = nil
@ -1198,6 +1209,7 @@ Default options, which never appear in option summary.
command line arguments to be parsed.
=end #'#"#`#
def permute(*argv)
argv = argv[0].dup if argv.size == 1 and Array === argv[0]
permute!(argv)
end
@ -1223,6 +1235,7 @@ Default options, which never appear in option summary.
command line arguments to be parsed.
=end #'#"#`#
def parse(*argv)
argv = argv[0].dup if argv.size == 1 and Array === argv[0]
parse!(argv)
end
@ -1607,7 +1620,7 @@ Extends command line arguments array to parse itself.
begin
yield @optparse
rescue ParseError
warn @optparse.program_name + ': ' + $!
@optparse.warn $!
nil
end
end

Просмотреть файл

@ -257,7 +257,7 @@ public
r = CSV::Row[d(nil, true), d(2), d(3)]
assert_equal([nil, '2', '3'], r.to_a, 'Null in data')
r = CSV::Row[d(nil, true), d(nil, true), d(nil, true)]
assert_equal([nil, nil, nil], r.to_a, 'Nulls')
@ -270,7 +270,7 @@ public
#### CSV::Reader unit test
def test_Reader_each
file = File.open(@infile, "rb")
begin
@ -441,7 +441,7 @@ public
#### CSV::Writer unit test
def test_Writer_s_new
assert_raises(RuntimeError) do
CSV::Writer.new(nil)
@ -1139,8 +1139,10 @@ public
end
def setBufSize(size)
CSV::StreamBuf.module_eval('remove_const("BufSize")')
CSV::StreamBuf.module_eval("BufSize = #{ size }")
CSV::StreamBuf.module_eval do
remove_const(:BufSize)
const_set(:BufSize, size)
end
end
class StrBuf < CSV::StreamBuf
@ -1282,7 +1284,7 @@ public
# At first, check ruby's behaviour.
assert_equal("", "abc"[3, 1])
assert_equal(nil, "abc"[4, 1])
setupInputStream(22, 1024) do |s|
[0, 1, 9, 10, 19, 20, 21].each do |idx|
assert_equal(expStr(idx, 1), s[idx, 1], idx.to_s)
@ -1346,7 +1348,7 @@ public
assert_equal(nil, s.get(-1))
end
end
def test_StreamBuf_get_n
setupInputStream(22, 1024) do |s|
[0, 1, 9, 10, 19, 20, 21].each do |idx|

Просмотреть файл

@ -28,12 +28,12 @@ class TestAlias < Test::Unit::TestCase
def test_alias
x = Alias2.new
assert_equal(x.bar, "foo")
assert_equal(x.baz, "foo+foo")
assert_equal("foo", x.bar)
assert_equal("foo+foo", x.baz)
# test_check for cache
assert_equal(x.baz, "foo+foo")
assert_equal("foo+foo", x.baz)
x = Alias3.new
assert(!x.foo)
assert(x.bar)

Просмотреть файл

@ -4,47 +4,47 @@ $KCODE = 'none'
class TestArray < Test::Unit::TestCase
def test_array
assert_equal([1, 2] + [3, 4], [1, 2, 3, 4])
assert_equal([1, 2] * 2, [1, 2, 1, 2])
assert_equal([1, 2] * ":", "1:2")
assert_equal([1, 2, 3, 4], [1, 2] + [3, 4])
assert_equal([1, 2, 1, 2], [1, 2] * 2)
assert_equal("1:2", [1, 2] * ":")
assert_equal([1, 2].hash, [1, 2].hash)
assert_equal([1,2,3] & [2,3,4], [2,3])
assert_equal([1,2,3] | [2,3,4], [1,2,3,4])
assert_equal([2,3], [1,2,3] & [2,3,4])
assert_equal([1,2,3,4], [1,2,3] | [2,3,4])
assert_equal([1,2,3] - [2,3], [1])
$x = [0, 1, 2, 3, 4, 5]
assert_equal($x[2], 2)
assert_equal($x[1..3], [1, 2, 3])
assert_equal($x[1,3], [1, 2, 3])
assert_equal(2, $x[2])
assert_equal([1, 2, 3], $x[1..3])
assert_equal([1, 2, 3], $x[1,3])
$x[0, 2] = 10
assert($x[0] == 10 && $x[1] == 2)
$x[0, 0] = -1
assert($x[0] == -1 && $x[1] == 10)
$x[-1, 1] = 20
assert($x[-1] == 20 && $x.pop == 20)
end
def test_array_andor
assert_equal(([1,2,3]&[2,4,6]), [2])
assert_equal(([1,2,3]|[2,4,6]), [1,2,3,4,6])
assert_equal([2], ([1,2,3]&[2,4,6]))
assert_equal([1,2,3,4,6], ([1,2,3]|[2,4,6]))
end
def test_compact
$x = [nil, 1, nil, nil, 5, nil, nil]
$x.compact!
assert_equal($x, [1, 5])
assert_equal([1, 5], $x)
end
def test_uniq
$x = [1, 1, 4, 2, 5, 4, 5, 1, 2]
$x.uniq!
assert_equal($x, [1, 4, 2, 5])
assert_equal([1, 4, 2, 5], $x)
# empty?
assert(!$x.empty?)
$x = []
@ -54,50 +54,50 @@ class TestArray < Test::Unit::TestCase
def test_sort
$x = ["it", "came", "to", "pass", "that", "..."]
$x = $x.sort.join(" ")
assert_equal($x, "... came it pass that to")
assert_equal("... came it pass that to", $x)
$x = [2,5,3,1,7]
$x.sort!{|a,b| a<=>b} # sort with condition
assert_equal($x, [1,2,3,5,7])
assert_equal([1,2,3,5,7], $x)
$x.sort!{|a,b| b-a} # reverse sort
assert_equal($x, [7,5,3,2,1])
assert_equal([7,5,3,2,1], $x)
end
def test_split
$x = "The Boassert of Mormon"
assert_equal($x.split(//).reverse!.join, $x.reverse)
assert_equal($x.reverse, $x.split(//).reverse!.join)
assert_equal($x.reverse, $x.reverse!)
assert_equal("1 byte string".split(//).reverse.join(":"), "g:n:i:r:t:s: :e:t:y:b: :1")
assert_equal("g:n:i:r:t:s: :e:t:y:b: :1", "1 byte string".split(//).reverse.join(":"))
$x = "a b c d"
assert_equal($x.split, ['a', 'b', 'c', 'd'])
assert_equal($x.split(' '), ['a', 'b', 'c', 'd'])
assert_equal(['a', 'b', 'c', 'd'], $x.split)
assert_equal(['a', 'b', 'c', 'd'], $x.split(' '))
end
def test_misc
assert(defined? "a".chomp)
assert_equal("abc".scan(/./), ["a", "b", "c"])
assert_equal("1a2b3c".scan(/(\d.)/), [["1a"], ["2b"], ["3c"]])
assert_equal(["a", "b", "c"], "abc".scan(/./))
assert_equal([["1a"], ["2b"], ["3c"]], "1a2b3c".scan(/(\d.)/))
# non-greedy match
assert_equal("a=12;b=22".scan(/(.*?)=(\d*);?/), [["a", "12"], ["b", "22"]])
assert_equal([["a", "12"], ["b", "22"]], "a=12;b=22".scan(/(.*?)=(\d*);?/))
$x = [1]
assert_equal(($x * 5).join(":"), '1:1:1:1:1')
assert_equal(($x * 1).join(":"), '1')
assert_equal(($x * 0).join(":"), '')
assert_equal('1:1:1:1:1', ($x * 5).join(":"))
assert_equal('1', ($x * 1).join(":"))
assert_equal('', ($x * 0).join(":"))
*$x = *(1..7).to_a
assert_equal($x.size, 7)
assert_equal($x, [1, 2, 3, 4, 5, 6, 7])
assert_equal(7, $x.size)
assert_equal([1, 2, 3, 4, 5, 6, 7], $x)
$x = [1,2,3]
$x[1,0] = $x
assert_equal($x, [1,1,2,3,2,3])
assert_equal([1,1,2,3,2,3], $x)
$x = [1,2,3]
$x[-1,0] = $x
assert_equal($x, [1,2,1,2,3,3])
assert_equal([1,2,1,2,3,3], $x)
$x = [1,2,3]
$x.concat($x)
assert_equal($x, [1,2,3,1,2,3])
assert_equal([1,2,3,1,2,3], $x)
end
end

Просмотреть файл

@ -5,275 +5,275 @@ $KCODE = 'none'
class TestAssignment < Test::Unit::TestCase
def test_assign
a=[]; a[0] ||= "bar";
assert_equal(a[0], "bar")
assert_equal("bar", a[0])
h={}; h["foo"] ||= "bar";
assert_equal(h["foo"], "bar")
assert_equal("bar", h["foo"])
aa = 5
aa ||= 25
assert_equal(aa, 5)
assert_equal(5, aa)
bb ||= 25
assert_equal(bb, 25)
assert_equal(25, bb)
cc &&=33
assert_equal(cc, nil)
assert_nil(cc)
cc = 5
cc &&=44
assert_equal(cc, 44)
a = nil; assert_equal(a, nil)
a = 1; assert_equal(a, 1)
a = []; assert_equal(a, [])
a = [1]; assert_equal(a, [1])
a = [nil]; assert_equal(a, [nil])
a = [[]]; assert_equal(a, [[]])
a = [1,2]; assert_equal(a, [1,2])
a = [*[]]; assert_equal(a, [])
a = [*[1]]; assert_equal(a, [1])
a = [*[1,2]]; assert_equal(a, [1,2])
a = *nil; assert_equal(a, nil)
a = *1; assert_equal(a, 1)
a = *[]; assert_equal(a, nil)
a = *[1]; assert_equal(a, 1)
a = *[nil]; assert_equal(a, nil)
a = *[[]]; assert_equal(a, [])
a = *[1,2]; assert_equal(a, [1,2])
a = *[*[]]; assert_equal(a, nil)
a = *[*[1]]; assert_equal(a, 1)
a = *[*[1,2]]; assert_equal(a, [1,2])
*a = nil; assert_equal(a, [nil])
*a = 1; assert_equal(a, [1])
*a = []; assert_equal(a, [[]])
*a = [1]; assert_equal(a, [[1]])
*a = [nil]; assert_equal(a, [[nil]])
*a = [[]]; assert_equal(a, [[[]]])
*a = [1,2]; assert_equal(a, [[1,2]])
*a = [*[]]; assert_equal(a, [[]])
*a = [*[1]]; assert_equal(a, [[1]])
*a = [*[1,2]]; assert_equal(a, [[1,2]])
*a = *nil; assert_equal(a, [nil])
*a = *1; assert_equal(a, [1])
*a = *[]; assert_equal(a, [])
*a = *[1]; assert_equal(a, [1])
*a = *[nil]; assert_equal(a, [nil])
*a = *[[]]; assert_equal(a, [[]])
*a = *[1,2]; assert_equal(a, [1,2])
*a = *[*[]]; assert_equal(a, [])
*a = *[*[1]]; assert_equal(a, [1])
*a = *[*[1,2]]; assert_equal(a, [1,2])
a,b,*c = nil; assert_equal([a,b,c], [nil,nil,[]])
a,b,*c = 1; assert_equal([a,b,c], [1,nil,[]])
a,b,*c = []; assert_equal([a,b,c], [nil,nil,[]])
a,b,*c = [1]; assert_equal([a,b,c], [1,nil,[]])
a,b,*c = [nil]; assert_equal([a,b,c], [nil,nil,[]])
a,b,*c = [[]]; assert_equal([a,b,c], [[],nil,[]])
a,b,*c = [1,2]; assert_equal([a,b,c], [1,2,[]])
a,b,*c = [*[]]; assert_equal([a,b,c], [nil,nil,[]])
a,b,*c = [*[1]]; assert_equal([a,b,c], [1,nil,[]])
a,b,*c = [*[1,2]]; assert_equal([a,b,c], [1,2,[]])
a,b,*c = *nil; assert_equal([a,b,c], [nil,nil,[]])
a,b,*c = *1; assert_equal([a,b,c], [1,nil,[]])
a,b,*c = *[]; assert_equal([a,b,c], [nil,nil,[]])
a,b,*c = *[1]; assert_equal([a,b,c], [1,nil,[]])
a,b,*c = *[nil]; assert_equal([a,b,c], [nil,nil,[]])
a,b,*c = *[[]]; assert_equal([a,b,c], [[],nil,[]])
a,b,*c = *[1,2]; assert_equal([a,b,c], [1,2,[]])
a,b,*c = *[*[]]; assert_equal([a,b,c], [nil,nil,[]])
a,b,*c = *[*[1]]; assert_equal([a,b,c], [1,nil,[]])
a,b,*c = *[*[1,2]]; assert_equal([a,b,c], [1,2,[]])
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 = *nil; assert_nil(a)
a = *1; assert_equal(1, 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 = *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,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 = *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])
end
def test_yield
def f; yield nil; end; f {|a| assert_equal(a, nil)}
def f; yield 1; end; f {|a| assert_equal(a, 1)}
def f; yield []; end; f {|a| assert_equal(a, [])}
def f; yield [1]; end; f {|a| assert_equal(a, [1])}
def f; yield [nil]; end; f {|a| assert_equal(a, [nil])}
def f; yield [[]]; end; f {|a| assert_equal(a, [[]])}
def f; yield [*[]]; end; f {|a| assert_equal(a, [])}
def f; yield [*[1]]; end; f {|a| assert_equal(a, [1])}
def f; yield [*[1,2]]; end; f {|a| assert_equal(a, [1,2])}
def f; yield *nil; end; f {|a| assert_equal(a, nil)}
def f; yield *1; end; f {|a| assert_equal(a, 1)}
def f; yield *[1]; end; f {|a| assert_equal(a, 1)}
def f; yield *[nil]; end; f {|a| assert_equal(a, nil)}
def f; yield *[[]]; end; f {|a| assert_equal(a, [])}
def f; yield *[*[1]]; end; f {|a| assert_equal(a, 1)}
def f; yield; end; f {|*a| assert_equal(a, [])}
def f; yield nil; end; f {|*a| assert_equal(a, [nil])}
def f; yield 1; end; f {|*a| assert_equal(a, [1])}
def f; yield []; end; f {|*a| assert_equal(a, [[]])}
def f; yield [1]; end; f {|*a| assert_equal(a, [[1]])}
def f; yield [nil]; end; f {|*a| assert_equal(a, [[nil]])}
def f; yield [[]]; end; f {|*a| assert_equal(a, [[[]]])}
def f; yield [1,2]; end; f {|*a| assert_equal(a, [[1,2]])}
def f; yield [*[]]; end; f {|*a| assert_equal(a, [[]])}
def f; yield [*[1]]; end; f {|*a| assert_equal(a, [[1]])}
def f; yield [*[1,2]]; end; f {|*a| assert_equal(a, [[1,2]])}
def f; yield *nil; end; f {|*a| assert_equal(a, [nil])}
def f; yield *1; end; f {|*a| assert_equal(a, [1])}
def f; yield *[]; end; f {|*a| assert_equal(a, [])}
def f; yield *[1]; end; f {|*a| assert_equal(a, [1])}
def f; yield *[nil]; end; f {|*a| assert_equal(a, [nil])}
def f; yield *[[]]; end; f {|*a| assert_equal(a, [[]])}
def f; yield *[*[]]; end; f {|*a| assert_equal(a, [])}
def f; yield *[*[1]]; end; f {|*a| assert_equal(a, [1])}
def f; yield *[*[1,2]]; end; f {|*a| assert_equal(a, [1,2])}
def f; yield; end; f {|a,b,*c| assert_equal([a,b,c], [nil,nil,[]])}
def f; yield nil; end; f {|a,b,*c| assert_equal([a,b,c], [nil,nil,[]])}
def f; yield 1; end; f {|a,b,*c| assert_equal([a,b,c], [1,nil,[]])}
def f; yield []; end; f {|a,b,*c| assert_equal([a,b,c], [nil,nil,[]])}
def f; yield [1]; end; f {|a,b,*c| assert_equal([a,b,c], [1,nil,[]])}
def f; yield [nil]; end; f {|a,b,*c| assert_equal([a,b,c], [nil,nil,[]])}
def f; yield [[]]; end; f {|a,b,*c| assert_equal([a,b,c], [[],nil,[]])}
def f; yield [*[]]; end; f {|a,b,*c| assert_equal([a,b,c], [nil,nil,[]])}
def f; yield [*[1]]; end; f {|a,b,*c| assert_equal([a,b,c], [1,nil,[]])}
def f; yield [*[1,2]]; end; f {|a,b,*c| assert_equal([a,b,c], [1,2,[]])}
def f; yield *nil; end; f {|a,b,*c| assert_equal([a,b,c], [nil,nil,[]])}
def f; yield *1; end; f {|a,b,*c| assert_equal([a,b,c], [1,nil,[]])}
def f; yield *[]; end; f {|a,b,*c| assert_equal([a,b,c], [nil,nil,[]])}
def f; yield *[1]; end; f {|a,b,*c| assert_equal([a,b,c], [1,nil,[]])}
def f; yield *[nil]; end; f {|a,b,*c| assert_equal([a,b,c], [nil,nil,[]])}
def f; yield *[[]]; end; f {|a,b,*c| assert_equal([a,b,c], [[],nil,[]])}
def f; yield *[*[]]; end; f {|a,b,*c| assert_equal([a,b,c], [nil,nil,[]])}
def f; yield *[*[1]]; end; f {|a,b,*c| assert_equal([a,b,c], [1,nil,[]])}
def f; yield *[*[1,2]]; end; f {|a,b,*c| assert_equal([a,b,c], [1,2,[]])}
def f; yield nil; end; f {|a| assert_nil(a)}
def f; yield 1; end; f {|a| assert_equal(1, a)}
def f; yield []; end; f {|a| assert_equal([], a)}
def f; yield [1]; end; f {|a| assert_equal([1], a)}
def f; yield [nil]; end; f {|a| assert_equal([nil], a)}
def f; yield [[]]; end; f {|a| assert_equal([[]], a)}
def f; yield [*[]]; end; f {|a| assert_equal([], a)}
def f; yield [*[1]]; end; f {|a| assert_equal([1], a)}
def f; yield [*[1,2]]; end; f {|a| assert_equal([1,2], a)}
def f; yield *nil; end; f {|a| assert_nil(a)}
def f; yield *1; end; f {|a| assert_equal(1, a)}
def f; yield *[1]; end; f {|a| assert_equal(1, a)}
def f; yield *[nil]; end; f {|a| assert_nil(a)}
def f; yield *[[]]; end; f {|a| assert_equal([], a)}
def f; yield *[*[1]]; end; f {|a| assert_equal(1, a)}
def f; yield; end; f {|*a| assert_equal([], a)}
def f; yield nil; end; f {|*a| assert_equal([nil], a)}
def f; yield 1; end; f {|*a| assert_equal([1], a)}
def f; yield []; end; f {|*a| assert_equal([[]], a)}
def f; yield [1]; end; f {|*a| assert_equal([[1]], a)}
def f; yield [nil]; end; f {|*a| assert_equal([[nil]], a)}
def f; yield [[]]; end; f {|*a| assert_equal([[[]]], a)}
def f; yield [1,2]; end; f {|*a| assert_equal([[1,2]], a)}
def f; yield [*[]]; end; f {|*a| assert_equal([[]], a)}
def f; yield [*[1]]; end; f {|*a| assert_equal([[1]], a)}
def f; yield [*[1,2]]; end; f {|*a| assert_equal([[1,2]], a)}
def f; yield *nil; end; f {|*a| assert_equal([nil], a)}
def f; yield *1; end; f {|*a| assert_equal([1], a)}
def f; yield *[]; end; f {|*a| assert_equal([], a)}
def f; yield *[1]; end; f {|*a| assert_equal([1], a)}
def f; yield *[nil]; end; f {|*a| assert_equal([nil], a)}
def f; yield *[[]]; end; f {|*a| assert_equal([[]], a)}
def f; yield *[*[]]; end; f {|*a| assert_equal([], a)}
def f; yield *[*[1]]; end; f {|*a| assert_equal([1], a)}
def f; yield *[*[1,2]]; end; f {|*a| assert_equal([1,2], a)}
def f; yield; end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}
def f; yield nil; end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}
def f; yield 1; end; f {|a,b,*c| assert_equal([1,nil,[]], [a,b,c])}
def f; yield []; end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}
def f; yield [1]; end; f {|a,b,*c| assert_equal([1,nil,[]], [a,b,c])}
def f; yield [nil]; end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}
def f; yield [[]]; end; f {|a,b,*c| assert_equal([[],nil,[]], [a,b,c])}
def f; yield [*[]]; end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}
def f; yield [*[1]]; end; f {|a,b,*c| assert_equal([1,nil,[]], [a,b,c])}
def f; yield [*[1,2]]; end; f {|a,b,*c| assert_equal([1,2,[]], [a,b,c])}
def f; yield *nil; end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}
def f; yield *1; end; f {|a,b,*c| assert_equal([1,nil,[]], [a,b,c])}
def f; yield *[]; end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}
def f; yield *[1]; end; f {|a,b,*c| assert_equal([1,nil,[]], [a,b,c])}
def f; yield *[nil]; end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}
def f; yield *[[]]; end; f {|a,b,*c| assert_equal([[],nil,[]], [a,b,c])}
def f; yield *[*[]]; end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}
def f; yield *[*[1]]; end; f {|a,b,*c| assert_equal([1,nil,[]], [a,b,c])}
def f; yield *[*[1,2]]; end; f {|a,b,*c| assert_equal([1,2,[]], [a,b,c])}
end
def test_return
def r; return; end; a = r(); assert_equal(a, nil)
def r; return nil; end; a = r(); assert_equal(a, nil)
def r; return 1; end; a = r(); assert_equal(a, 1)
def r; return []; end; a = r(); assert_equal(a, [])
def r; return [1]; end; a = r(); assert_equal(a, [1])
def r; return [nil]; end; a = r(); assert_equal(a, [nil])
def r; return [[]]; end; a = r(); assert_equal(a, [[]])
def r; return [*[]]; end; a = r(); assert_equal(a, [])
def r; return [*[1]]; end; a = r(); assert_equal(a, [1])
def r; return [*[1,2]]; end; a = r(); assert_equal(a, [1,2])
def r; return *nil; end; a = r(); assert_equal(a, nil)
def r; return *1; end; a = r(); assert_equal(a, 1)
def r; return *[]; end; a = r(); assert_equal(a, nil)
def r; return *[1]; end; a = r(); assert_equal(a, 1)
def r; return *[nil]; end; a = r(); assert_equal(a, nil)
def r; return *[[]]; end; a = r(); assert_equal(a, [])
def r; return *[*[]]; end; a = r(); assert_equal(a, nil)
def r; return *[*[1]]; end; a = r(); assert_equal(a, 1)
def r; return *[*[1,2]]; end; a = r(); assert_equal(a, [1,2])
def r; return *nil; end; a = *r(); assert_equal(a, nil)
def r; return *1; end; a = *r(); assert_equal(a, 1)
def r; return *[]; end; a = *r(); assert_equal(a, nil)
def r; return *[1]; end; a = *r(); assert_equal(a, 1)
def r; return *[nil]; end; a = *r(); assert_equal(a, nil)
def r; return *[[]]; end; a = *r(); assert_equal(a, nil)
def r; return *[*[]]; end; a = *r(); assert_equal(a, nil)
def r; return *[*[1]]; end; a = *r(); assert_equal(a, 1)
def r; return *[*[1,2]]; end; a = *r(); assert_equal(a, [1,2])
def r; return; end; *a = r(); assert_equal(a, [nil])
def r; return nil; end; *a = r(); assert_equal(a, [nil])
def r; return 1; end; *a = r(); assert_equal(a, [1])
def r; return []; end; *a = r(); assert_equal(a, [[]])
def r; return [1]; end; *a = r(); assert_equal(a, [[1]])
def r; return [nil]; end; *a = r(); assert_equal(a, [[nil]])
def r; return [[]]; end; *a = r(); assert_equal(a, [[[]]])
def r; return [1,2]; end; *a = r(); assert_equal(a, [[1,2]])
def r; return [*[]]; end; *a = r(); assert_equal(a, [[]])
def r; return [*[1]]; end; *a = r(); assert_equal(a, [[1]])
def r; return [*[1,2]]; end; *a = r(); assert_equal(a, [[1,2]])
def r; return *nil; end; *a = r(); assert_equal(a, [nil])
def r; return *1; end; *a = r(); assert_equal(a, [1])
def r; return *[]; end; *a = r(); assert_equal(a, [nil])
def r; return *[1]; end; *a = r(); assert_equal(a, [1])
def r; return *[nil]; end; *a = r(); assert_equal(a, [nil])
def r; return *[[]]; end; *a = r(); assert_equal(a, [[]])
def r; return *[1,2]; end; *a = r(); assert_equal(a, [[1,2]])
def r; return *[*[]]; end; *a = r(); assert_equal(a, [nil])
def r; return *[*[1]]; end; *a = r(); assert_equal(a, [1])
def r; return *[*[1,2]]; end; *a = r(); assert_equal(a, [[1,2]])
def r; return *nil; end; *a = *r(); assert_equal(a, [nil])
def r; return *1; end; *a = *r(); assert_equal(a, [1])
def r; return *[]; end; *a = *r(); assert_equal(a, [nil])
def r; return *[1]; end; *a = *r(); assert_equal(a, [1])
def r; return *[nil]; end; *a = *r(); assert_equal(a, [nil])
def r; return *[[]]; end; *a = *r(); assert_equal(a, [])
def r; return *[1,2]; end; *a = *r(); assert_equal(a, [1,2])
def r; return *[*[]]; end; *a = *r(); assert_equal(a, [nil])
def r; return *[*[1]]; end; *a = *r(); assert_equal(a, [1])
def r; return *[*[1,2]]; end; *a = *r(); assert_equal(a, [1,2])
def r; return; end; a,b,*c = r(); assert_equal([a,b,c], [nil,nil,[]])
def r; return nil; end; a,b,*c = r(); assert_equal([a,b,c], [nil,nil,[]])
def r; return 1; end; a,b,*c = r(); assert_equal([a,b,c], [1,nil,[]])
def r; return []; end; a,b,*c = r(); assert_equal([a,b,c], [nil,nil,[]])
def r; return [1]; end; a,b,*c = r(); assert_equal([a,b,c], [1,nil,[]])
def r; return [nil]; end; a,b,*c = r(); assert_equal([a,b,c], [nil,nil,[]])
def r; return [[]]; end; a,b,*c = r(); assert_equal([a,b,c], [[],nil,[]])
def r; return [1,2]; end; a,b,*c = r(); assert_equal([a,b,c], [1,2,[]])
def r; return [*[]]; end; a,b,*c = r(); assert_equal([a,b,c], [nil,nil,[]])
def r; return [*[1]]; end; a,b,*c = r(); assert_equal([a,b,c], [1,nil,[]])
def r; return [*[1,2]]; end; a,b,*c = r(); assert_equal([a,b,c], [1,2,[]])
def r; return *nil; end; a,b,*c = r(); assert_equal([a,b,c], [nil,nil,[]])
def r; return *1; end; a,b,*c = r(); assert_equal([a,b,c], [1,nil,[]])
def r; return *[]; end; a,b,*c = r(); assert_equal([a,b,c], [nil,nil,[]])
def r; return *[1]; end; a,b,*c = r(); assert_equal([a,b,c], [1,nil,[]])
def r; return *[nil]; end; a,b,*c = r(); assert_equal([a,b,c], [nil,nil,[]])
def r; return *[[]]; end; a,b,*c = r(); assert_equal([a,b,c], [nil,nil,[]])
def r; return *[1,2]; end; a,b,*c = r(); assert_equal([a,b,c], [1,2,[]])
def r; return *[*[]]; end; a,b,*c = r(); assert_equal([a,b,c], [nil,nil,[]])
def r; return *[*[1]]; end; a,b,*c = r(); assert_equal([a,b,c], [1,nil,[]])
def r; return *[*[1,2]]; end; a,b,*c = r(); assert_equal([a,b,c], [1,2,[]])
def r; return; end; a = r(); assert_nil(a)
def r; return nil; end; a = r(); assert_nil(a)
def r; return 1; end; a = r(); assert_equal(1, a)
def r; return []; end; a = r(); assert_equal([], a)
def r; return [1]; end; a = r(); assert_equal([1], a)
def r; return [nil]; end; a = r(); assert_equal([nil], a)
def r; return [[]]; end; a = r(); assert_equal([[]], a)
def r; return [*[]]; end; a = r(); assert_equal([], a)
def r; return [*[1]]; end; a = r(); assert_equal([1], a)
def r; return [*[1,2]]; end; a = r(); assert_equal([1,2], a)
def r; return *nil; end; a = r(); assert_nil(a)
def r; return *1; end; a = r(); assert_equal(1, a)
def r; return *[]; end; a = r(); assert_nil(a)
def r; return *[1]; end; a = r(); assert_equal(1, a)
def r; return *[nil]; end; a = r(); assert_nil(a)
def r; return *[[]]; end; a = r(); assert_equal([], a)
def r; return *[*[]]; end; a = r(); assert_nil(a)
def r; return *[*[1]]; end; a = r(); assert_equal(1, a)
def r; return *[*[1,2]]; end; a = r(); assert_equal([1,2], a)
def r; return *nil; end; a = *r(); assert_nil(a)
def r; return *1; end; a = *r(); assert_equal(1, a)
def r; return *[]; end; a = *r(); assert_nil(a)
def r; return *[1]; end; a = *r(); assert_equal(1, a)
def r; return *[nil]; end; a = *r(); assert_nil(a)
def r; return *[[]]; end; a = *r(); assert_nil(a)
def r; return *[*[]]; end; a = *r(); assert_nil(a)
def r; return *[*[1]]; end; a = *r(); assert_equal(1, a)
def r; return *[*[1,2]]; end; a = *r(); assert_equal([1,2], a)
def r; return; end; *a = r(); assert_equal([nil], a)
def r; return nil; end; *a = r(); assert_equal([nil], a)
def r; return 1; end; *a = r(); assert_equal([1], a)
def r; return []; end; *a = r(); assert_equal([[]], a)
def r; return [1]; end; *a = r(); assert_equal([[1]], a)
def r; return [nil]; end; *a = r(); assert_equal([[nil]], a)
def r; return [[]]; end; *a = r(); assert_equal([[[]]], a)
def r; return [1,2]; end; *a = r(); assert_equal([[1,2]], a)
def r; return [*[]]; end; *a = r(); assert_equal([[]], a)
def r; return [*[1]]; end; *a = r(); assert_equal([[1]], a)
def r; return [*[1,2]]; end; *a = r(); assert_equal([[1,2]], a)
def r; return *nil; end; *a = r(); assert_equal([nil], a)
def r; return *1; end; *a = r(); assert_equal([1], a)
def r; return *[]; end; *a = r(); assert_equal([nil], a)
def r; return *[1]; end; *a = r(); assert_equal([1], a)
def r; return *[nil]; end; *a = r(); assert_equal([nil], a)
def r; return *[[]]; end; *a = r(); assert_equal([[]], a)
def r; return *[1,2]; end; *a = r(); assert_equal([[1,2]], a)
def r; return *[*[]]; end; *a = r(); assert_equal([nil], a)
def r; return *[*[1]]; end; *a = r(); assert_equal([1], a)
def r; return *[*[1,2]]; end; *a = r(); assert_equal([[1,2]], a)
def r; return *nil; end; *a = *r(); assert_equal([nil], a)
def r; return *1; end; *a = *r(); assert_equal([1], a)
def r; return *[]; end; *a = *r(); assert_equal([nil], a)
def r; return *[1]; end; *a = *r(); assert_equal([1], a)
def r; return *[nil]; end; *a = *r(); assert_equal([nil], a)
def r; return *[[]]; end; *a = *r(); assert_equal([], a)
def r; return *[1,2]; end; *a = *r(); assert_equal([1,2], a)
def r; return *[*[]]; end; *a = *r(); assert_equal([nil], a)
def r; return *[*[1]]; end; *a = *r(); assert_equal([1], a)
def r; return *[*[1,2]]; end; *a = *r(); assert_equal([1,2], a)
def r; return; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c])
def r; return nil; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c])
def r; return 1; end; a,b,*c = r(); assert_equal([1,nil,[]], [a,b,c])
def r; return []; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c])
def r; return [1]; end; a,b,*c = r(); assert_equal([1,nil,[]], [a,b,c])
def r; return [nil]; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c])
def r; return [[]]; end; a,b,*c = r(); assert_equal([[],nil,[]], [a,b,c])
def r; return [1,2]; end; a,b,*c = r(); assert_equal([1,2,[]], [a,b,c])
def r; return [*[]]; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c])
def r; return [*[1]]; end; a,b,*c = r(); assert_equal([1,nil,[]], [a,b,c])
def r; return [*[1,2]]; end; a,b,*c = r(); assert_equal([1,2,[]], [a,b,c])
def r; return *nil; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c])
def r; return *1; end; a,b,*c = r(); assert_equal([1,nil,[]], [a,b,c])
def r; return *[]; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c])
def r; return *[1]; end; a,b,*c = r(); assert_equal([1,nil,[]], [a,b,c])
def r; return *[nil]; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c])
def r; return *[[]]; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c])
def r; return *[1,2]; end; a,b,*c = r(); assert_equal([1,2,[]], [a,b,c])
def r; return *[*[]]; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c])
def r; return *[*[1]]; end; a,b,*c = r(); assert_equal([1,nil,[]], [a,b,c])
def r; return *[*[1,2]]; end; a,b,*c = r(); assert_equal([1,2,[]], [a,b,c])
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(f.call(42), 42)
assert_equal(f.call([42]), [42])
assert_equal(f.call([[42]]), [[42]])
assert_equal(f.call([42,55]), [42,55])
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(f.call(42), 42)
assert_equal(f.call([42]), [42])
assert_equal(f.call([[42]]), [[42]])
assert_equal(f.call([42,55]), [42,55])
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(f.call(42), [42])
assert_equal(f.call([42]), [[42]])
assert_equal(f.call([[42]]), [[[42]]])
assert_equal(f.call([42,55]), [[42,55]])
assert_equal(f.call(42,55), [42,55])
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(a, 1)
assert_equal(1, a)
a,=*[[1]]
assert_equal(a, [1])
assert_equal([1], a)
a,=*[[[1]]]
assert_equal(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]
@ -283,87 +283,87 @@ class TestAssignment < Test::Unit::TestCase
end
def test_break
a = loop do break; end; assert_equal(a, nil)
a = loop do break nil; end; assert_equal(a, nil)
a = loop do break 1; end; assert_equal(a, 1)
a = loop do break []; end; assert_equal(a, [])
a = loop do break [1]; end; assert_equal(a, [1])
a = loop do break [nil]; end; assert_equal(a, [nil])
a = loop do break [[]]; end; assert_equal(a, [[]])
a = loop do break [*[]]; end; assert_equal(a, [])
a = loop do break [*[1]]; end; assert_equal(a, [1])
a = loop do break [*[1,2]]; end; assert_equal(a, [1,2])
a = loop do break *nil; end; assert_equal(a, nil)
a = loop do break *1; end; assert_equal(a, 1)
a = loop do break *[]; end; assert_equal(a, nil)
a = loop do break *[1]; end; assert_equal(a, 1)
a = loop do break *[nil]; end; assert_equal(a, nil)
a = loop do break *[[]]; end; assert_equal(a, [])
a = loop do break *[*[]]; end; assert_equal(a, nil)
a = loop do break *[*[1]]; end; assert_equal(a, 1)
a = loop do break *[*[1,2]]; end; assert_equal(a, [1,2])
*a = loop do break; end; assert_equal(a, [nil])
*a = loop do break nil; end; assert_equal(a, [nil])
*a = loop do break 1; end; assert_equal(a, [1])
*a = loop do break []; end; assert_equal(a, [[]])
*a = loop do break [1]; end; assert_equal(a, [[1]])
*a = loop do break [nil]; end; assert_equal(a, [[nil]])
*a = loop do break [[]]; end; assert_equal(a, [[[]]])
*a = loop do break [1,2]; end; assert_equal(a, [[1,2]])
*a = loop do break [*[]]; end; assert_equal(a, [[]])
*a = loop do break [*[1]]; end; assert_equal(a, [[1]])
*a = loop do break [*[1,2]]; end; assert_equal(a, [[1,2]])
*a = loop do break *nil; end; assert_equal(a, [nil])
*a = loop do break *1; end; assert_equal(a, [1])
*a = loop do break *[]; end; assert_equal(a, [nil])
*a = loop do break *[1]; end; assert_equal(a, [1])
*a = loop do break *[nil]; end; assert_equal(a, [nil])
*a = loop do break *[[]]; end; assert_equal(a, [[]])
*a = loop do break *[1,2]; end; assert_equal(a, [[1,2]])
*a = loop do break *[*[]]; end; assert_equal(a, [nil])
*a = loop do break *[*[1]]; end; assert_equal(a, [1])
*a = loop do break *[*[1,2]]; end; assert_equal(a, [[1,2]])
*a = *loop do break *nil; end; assert_equal(a, [nil])
*a = *loop do break *1; end; assert_equal(a, [1])
*a = *loop do break *[]; end; assert_equal(a, [nil])
*a = *loop do break *[1]; end; assert_equal(a, [1])
*a = *loop do break *[nil]; end; assert_equal(a, [nil])
*a = *loop do break *[[]]; end; assert_equal(a, [])
*a = *loop do break *[1,2]; end; assert_equal(a, [1,2])
*a = *loop do break *[*[]]; end; assert_equal(a, [nil])
*a = *loop do break *[*[1]]; end; assert_equal(a, [1])
*a = *loop do break *[*[1,2]]; end; assert_equal(a, [1,2])
a,b,*c = loop do break; end; assert_equal([a,b,c], [nil,nil,[]])
a,b,*c = loop do break nil; end; assert_equal([a,b,c], [nil,nil,[]])
a,b,*c = loop do break 1; end; assert_equal([a,b,c], [1,nil,[]])
a,b,*c = loop do break []; end; assert_equal([a,b,c], [nil,nil,[]])
a,b,*c = loop do break [1]; end; assert_equal([a,b,c], [1,nil,[]])
a,b,*c = loop do break [nil]; end; assert_equal([a,b,c], [nil,nil,[]])
a,b,*c = loop do break [[]]; end; assert_equal([a,b,c], [[],nil,[]])
a,b,*c = loop do break [1,2]; end; assert_equal([a,b,c], [1,2,[]])
a,b,*c = loop do break [*[]]; end; assert_equal([a,b,c], [nil,nil,[]])
a,b,*c = loop do break [*[1]]; end; assert_equal([a,b,c], [1,nil,[]])
a,b,*c = loop do break [*[1,2]]; end; assert_equal([a,b,c], [1,2,[]])
a,b,*c = loop do break *nil; end; assert_equal([a,b,c], [nil,nil,[]])
a,b,*c = loop do break *1; end; assert_equal([a,b,c], [1,nil,[]])
a,b,*c = loop do break *[]; end; assert_equal([a,b,c], [nil,nil,[]])
a,b,*c = loop do break *[1]; end; assert_equal([a,b,c], [1,nil,[]])
a,b,*c = loop do break *[nil]; end; assert_equal([a,b,c], [nil,nil,[]])
a,b,*c = loop do break *[[]]; end; assert_equal([a,b,c], [nil,nil,[]])
a,b,*c = loop do break *[1,2]; end; assert_equal([a,b,c], [1,2,[]])
a,b,*c = loop do break *[*[]]; end; assert_equal([a,b,c], [nil,nil,[]])
a,b,*c = loop do break *[*[1]]; end; assert_equal([a,b,c], [1,nil,[]])
a,b,*c = loop do break *[*[1,2]]; end; assert_equal([a,b,c], [1,2,[]])
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 *nil; end; assert_nil(a)
a = loop do break *1; end; assert_equal(1, 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 *nil; end; assert_equal([nil], a)
*a = loop do break *1; end; assert_equal([1], 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 *nil; end; assert_equal([nil], a)
*a = *loop do break *1; end; assert_equal([1], 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,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 *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,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(a, val); end
def r(val); a = yield(); assert_equal(val, a); end
r(nil){next}
r(nil){next nil}
r(1){next 1}
@ -374,7 +374,7 @@ class TestAssignment < Test::Unit::TestCase
r([]){next [*[]]}
r([1]){next [*[1]]}
r([1,2]){next [*[1,2]]}
r(nil){next *nil}
r(1){next *1}
r(nil){next *[]}
@ -384,8 +384,8 @@ class TestAssignment < Test::Unit::TestCase
r(nil){next *[*[]]}
r(1){next *[*[1]]}
r([1,2]){next *[*[1,2]]}
def r(val); *a = yield(); assert_equal(a, val); end
def r(val); *a = yield(); assert_equal(val, a); end
r([nil]){next}
r([nil]){next nil}
r([1]){next 1}
@ -397,8 +397,8 @@ class TestAssignment < Test::Unit::TestCase
r([[]]){next [*[]]}
r([[1]]){next [*[1]]}
r([[1,2]]){next [*[1,2]]}
def r(val); *a = *yield(); assert_equal(a, val); end
def r(val); *a = *yield(); assert_equal(val, a); end
r([nil]){next *nil}
r([1]){next *1}
r([nil]){next *[]}
@ -409,8 +409,8 @@ class TestAssignment < Test::Unit::TestCase
r([nil]){next *[*[]]}
r([1]){next *[*[1]]}
r([1,2]){next *[*[1,2]]}
def r(val); a,b,*c = yield(); assert_equal([a,b,c], val); end
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}
@ -422,8 +422,8 @@ class TestAssignment < Test::Unit::TestCase
r([nil,nil,[]]){next [*[]]}
r([1,nil,[]]){next [*[1]]}
r([1,2,[]]){next [*[1,2]]}
def r(val); a,b,*c = *yield(); assert_equal([a,b,c], val); end
def r(val); a,b,*c = *yield(); assert_equal(val, [a,b,c]); end
r([nil,nil,[]]){next *nil}
r([1,nil,[]]){next *1}
r([nil,nil,[]]){next *[]}
@ -439,31 +439,31 @@ class TestAssignment < Test::Unit::TestCase
def test_assign2
a = nil
assert(defined?(a))
assert_equal(a, nil)
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(a, 1)
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(a, [1, 2, 3])
assert_equal([1, 2, 3], a)
*a = 4
assert_equal(a, [4])
assert_equal([4], a)
*a = nil
assert_equal(a, [nil])
assert_equal([nil], a)
end
end

Просмотреть файл

@ -19,47 +19,36 @@ class TestBignum < Test::Unit::TestCase
assert_equal($x, fact(40))
assert($x < $x+2)
assert($x > $x-2)
assert_equal($x, 815915283247897734345611269596115894272000000000)
assert_not_equal($x, 815915283247897734345611269596115894272000000001)
assert_equal($x+1, 815915283247897734345611269596115894272000000001)
assert_equal($x/fact(20), 335367096786357081410764800000)
assert_equal(815915283247897734345611269596115894272000000000, $x)
assert_not_equal(815915283247897734345611269596115894272000000001, $x)
assert_equal(815915283247897734345611269596115894272000000001, $x+1)
assert_equal(335367096786357081410764800000, $x/fact(20))
$x = -$x
assert_equal($x, -815915283247897734345611269596115894272000000000)
assert_equal(-815915283247897734345611269596115894272000000000, $x)
assert_equal(2-(2**32), -(2**32-2))
assert_equal(2**32 - 5, (2**32-3)-2)
$good = true;
for i in 1000..1014
$good = false if ((1<<i) != (2**i))
assert_equal(2 ** i, 1 << i)
end
assert($good)
$good = true;
n1=1<<1000
n1 = 1 << 1000
for i in 1000..1014
$good = false if ((1<<i) != n1)
assert_equal(n1, 1 << i)
n1 *= 2
end
assert($good)
$good = true;
n2=n1
for i in 1..10
n1 = n1 / 2
n2 = n2 >> 1
$good = false if (n1 != n2)
assert_equal(n1, n2)
end
assert($good)
$good = true;
for i in 4000..4096
n1 = 1 << i;
if (n1**2-1) / (n1+1) != (n1-1)
p i
$good = false
end
assert_equal(n1-1, (n1**2-1) / (n1+1))
end
assert($good)
end
def test_calc
@ -73,14 +62,14 @@ class TestBignum < Test::Unit::TestCase
assert_equal(7, a.remainder(-b))
assert_equal(-7, (-a).remainder(b))
assert_equal(-7, (-a).remainder(-b))
assert_equal(10**40+10**20, 10000000000000000000100000000000000000000)
assert_equal(10**40/10**20, 100000000000000000000)
assert_equal(10000000000000000000100000000000000000000, 10**40+10**20)
assert_equal(100000000000000000000, 10**40/10**20)
a = 677330545177305025495135714080
b = 14269972710765292560
assert_equal(a % b, 0)
assert_equal(-a % b, 0)
assert_equal(0, a % b)
assert_equal(0, -a % b)
end
def test_shift
@ -88,12 +77,12 @@ class TestBignum < Test::Unit::TestCase
b = a / (2 ** 32)
c = a >> 32
assert_equal(b, c)
b = a * (2 ** 32)
c = a << 32
assert_equal(b, c)
end
shift_test(-4518325415524767873)
shift_test(-0xfffffffffffffffff)
end

Просмотреть файл

@ -10,23 +10,12 @@ class TestCall < Test::Unit::TestCase
end
def test_call
begin
aaa() # need at least 1 arg
assert(false)
rescue
assert(true)
end
begin
aaa # no arg given (exception raised)
assert(false)
rescue
assert(true)
end
assert_equal(aaa(1), [1, 100])
assert_equal(aaa(1, 2), [1, 2])
assert_equal(aaa(1, 2, 3, 4), [1, 2, 3, 4])
assert_equal(aaa(1, *[2, 3, 4]), [1, 2, 3, 4])
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

Просмотреть файл

@ -10,28 +10,28 @@ class TestCase < Test::Unit::TestCase
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)

Просмотреть файл

@ -8,7 +8,7 @@ class TestClone < Test::Unit::TestCase
module M003; include M002; end
module M002; include M001; end
module M003; include M002; end
def test_clone
foo = Object.new
def foo.test
@ -18,18 +18,13 @@ class TestClone < Test::Unit::TestCase
def bar.test2
"test2"
end
assert_equal(bar.test2, "test2")
assert_equal(bar.test, "test")
assert_equal(foo.test, "test")
begin
foo.test2
assert false
rescue NoMethodError
assert true
end
assert_equal(M003.ancestors, [M003, M002, M001])
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

Просмотреть файл

@ -8,11 +8,11 @@ class TestCondition < Test::Unit::TestCase
def test_condition
$x = '0';
$x == $x && assert(true)
$x != $x && assert(false)
$x == $x || assert(false)
$x != $x || assert(true)
end
end

Просмотреть файл

@ -5,31 +5,31 @@ $KCODE = 'none'
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([TEST1,TEST2,TEST3,TEST4], [1,2,3,4])
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([TEST1,TEST2,TEST3,TEST4], [1,2,6,8])
assert_equal((String <=> Object), -1)
assert_equal((Object <=> String), 1)
assert_equal((Array <=> String), nil)
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

Просмотреть файл

@ -22,20 +22,20 @@ class TestDefined < Test::Unit::TestCase
$x = nil
assert(defined?($x)) # global variable
assert_equal(defined?($x), 'global-variable')# returns description
assert_equal('global-variable', defined?($x))# returns description
foo=5
assert(defined?(foo)) # local variable
assert(defined?(::Array)) # constant !! Array -> ::Array
assert(defined?(Object.new)) # method
assert(!defined?(Object.print)) # private method
assert(defined?(1 == 2)) # operator expression
f = Foo.new
assert_equal(defined?(f.foo), nil)
assert_nil(defined?(f.foo))
f.bar(f) { |v| assert(v) }
assert(defined_test) # not iterator
assert(!defined_test{}) # called as iterator
end

Просмотреть файл

@ -13,35 +13,35 @@ class TestEval < Test::Unit::TestCase
end
def test_eval
assert_equal(eval(""), nil)
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(eval("$foo"), 'assert(true)')
assert_equal(eval("true"), true)
assert_equal('assert(true)', eval("$foo"))
assert_equal(true, eval("true"))
i = 5
assert(eval("i == 5"))
assert_equal(eval("i"), 5)
assert_equal(5, eval("i"))
assert(eval("defined? i"))
$x = test_ev
assert_equal(eval("local1", $x), "local1") # normal local var
assert_equal(eval("local2", $x), "local2") # nested local var
assert_equal("local1", eval("local1", $x)) # normal local var
assert_equal("local2", eval("local2", $x)) # nested local var
$bad = true
begin
p eval("local1")
@ -49,7 +49,7 @@ class TestEval < Test::Unit::TestCase
$bad = false
end
assert(!$bad)
# !! use class_eval to avoid nested definition
self.class.class_eval %q(
module EvTest
@ -58,8 +58,8 @@ class TestEval < Test::Unit::TestCase
$x = binding
end
)
assert_equal(eval("EVTEST1", $x), 25) # constant in module
assert_equal(eval("evtest2", $x), 125) # local var in module
assert_equal(25, eval("EVTEST1", $x)) # constant in module
assert_equal(125, eval("evtest2", $x)) # local var in module
$bad = true
begin
eval("EVTEST1")
@ -67,58 +67,58 @@ class TestEval < Test::Unit::TestCase
$bad = false
end
assert(!$bad)
x = proc{}
eval "i4 = 1", x
assert_equal(eval("i4", x), 1)
assert_equal(1, eval("i4", x))
x = proc{proc{}}.call
eval "i4 = 22", x
assert_equal(eval("i4", x), 22)
assert_equal(22, eval("i4", x))
$x = []
x = proc{proc{}}.call
eval "(0..9).each{|i5| $x[i5] = proc{i5*2}}", x
assert_equal($x[4].call, 8)
assert_equal(8, $x[4].call)
x = binding
eval "i = 1", x
assert_equal(eval("i", x), 1)
assert_equal(1, eval("i", x))
x = proc{binding}.call
eval "i = 22", x
assert_equal(eval("i", x), 22)
assert_equal(22, eval("i", x))
$x = []
x = proc{binding}.call
eval "(0..9).each{|i5| $x[i5] = proc{i5*2}}", x
assert_equal($x[4].call, 8)
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", p), eval("foo11"))
assert_equal(eval("foo11"), 1)
assert_equal(eval("foo22", p), eval("foo22"))
assert_equal(eval("foo22"), 55)
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(p1.call, 0)
assert_equal(0, p1.call)
eval "i7=5", p1
assert_equal(p1.call, 5)
assert_equal(5, p1.call)
assert(!defined?(i7))
p1 = proc{i7 = 0; proc{i7}}.call
i7 = nil
assert_equal(p1.call, 0)
assert_equal(0, p1.call)
eval "i7=1", p1
assert_equal(p1.call, 1)
assert_equal(1, p1.call)
eval "i7=5", p1
assert_equal(p1.call, 5)
assert_equal(i7, nil)
assert_equal(5, p1.call)
assert_nil(i7)
end
end

Просмотреть файл

@ -10,7 +10,7 @@ class TestException < Test::Unit::TestCase
rescue
assert(true)
end
$bad = true
begin
raise "this must be handled no.2"
@ -22,32 +22,33 @@ class TestException < Test::Unit::TestCase
end
end
assert(true)
# exception in rescue clause
$string = "this must be handled no.3"
begin
e = assert_raises(RuntimeError) do
begin
raise "exception in rescue clause"
rescue
rescue
raise $string
end
assert(false)
rescue
assert(true) if $! == $string
end
assert_equal($string, e.message)
# exception in ensure clause
begin
$string = "exception in ensure clause"
e = assert_raises(RuntimeError) do
begin
raise "this must be handled no.4"
ensure
ensure
assert_instance_of(RuntimeError, $!)
assert_equal("this must be handled no.4", $!.message)
raise "exception in ensure clause"
end
assert(false)
rescue
assert(true)
end
assert_equal($string, e.message)
$bad = true
begin
begin
@ -58,7 +59,7 @@ class TestException < Test::Unit::TestCase
rescue
end
assert(!$bad)
$bad = true
begin
begin
@ -69,7 +70,7 @@ class TestException < Test::Unit::TestCase
rescue
end
assert(!$bad)
$bad = true
while true
begin
@ -79,7 +80,7 @@ class TestException < Test::Unit::TestCase
end
end
assert(!$bad)
assert(catch(:foo) {
loop do
loop do
@ -91,6 +92,6 @@ class TestException < Test::Unit::TestCase
end
false
})
end
end

Просмотреть файл

@ -4,23 +4,23 @@ $KCODE = 'none'
class TestFloat < Test::Unit::TestCase
def test_float
assert_equal(2.6.floor, 2)
assert_equal((-2.6).floor, -3)
assert_equal(2.6.ceil, 3)
assert_equal((-2.6).ceil, -2)
assert_equal(2.6.truncate, 2)
assert_equal((-2.6).truncate, -2)
assert_equal(2.6.round, 3)
assert_equal((-2.4).truncate, -2)
assert_equal(2, 2.6.floor)
assert_equal(-3, (-2.6).floor)
assert_equal(3, 2.6.ceil)
assert_equal(-2, (-2.6).ceil)
assert_equal(2, 2.6.truncate)
assert_equal(-2, (-2.6).truncate)
assert_equal(3, 2.6.round)
assert_equal(-2, (-2.4).truncate)
assert((13.4 % 1 - 0.4).abs < 0.0001)
nan = 0.0/0
def nan.test(v)
extend Test::Unit::Assertions
assert(self != v)
assert_equal((self < v), false)
assert_equal((self > v), false)
assert_equal((self <= v), false)
assert_equal((self >= v), false)
assert_equal(false, (self < v))
assert_equal(false, (self > v))
assert_equal(false, (self <= v))
assert_equal(false, (self >= v))
end
nan.test(nan)
nan.test(0)
@ -36,7 +36,7 @@ class TestFloat < Test::Unit::TestCase
nan.test(-0.001);
nan.test(1.0/0);
nan.test(-1.0/0);
#s = "3.7517675036461267e+17"
#assert(s == sprintf("%.16e", s.to_f))
f = 3.7517675036461267e+17

Просмотреть файл

@ -10,14 +10,11 @@ class TestGc < Test::Unit::TestCase
end
def test_gc
begin
assert_nothing_raised do
1.upto(10000) {
tmp = [0,1,2,3,4,5,6,7,8,9]
}
tmp = nil
assert true
rescue
assert false
end
l=nil
100000.times {

Просмотреть файл

@ -6,10 +6,10 @@ class TestHash < Test::Unit::TestCase
def test_hash
$x = {1=>2, 2=>4, 3=>6}
$y = {1, 2, 2, 4, 3, 6}
assert_equal($x[1], 2)
assert(begin
assert_equal(2, $x[1])
assert(begin
for k,v in $y
raise if k*2 != v
end
@ -17,60 +17,60 @@ class TestHash < Test::Unit::TestCase
rescue
false
end)
assert_equal($x.length, 3)
assert_equal(3, $x.length)
assert($x.has_key?(1))
assert($x.has_value?(4))
assert_equal($x.values_at(2,3), [4,6])
assert_equal($x, {1=>2, 2=>4, 3=>6})
assert_equal([4,6], $x.values_at(2,3))
assert_equal({1=>2, 2=>4, 3=>6}, $x)
$z = $y.keys.join(":")
assert_equal($z, "1:2:3")
assert_equal("1:2:3", $z)
$z = $y.values.join(":")
assert_equal($z, "2:4:6")
assert_equal("2:4:6", $z)
assert_equal($x, $y)
$y.shift
assert_equal($y.length, 2)
assert_equal(2, $y.length)
$z = [1,2]
$y[$z] = 256
assert_equal($y[$z], 256)
assert_equal(256, $y[$z])
$x = Hash.new(0)
$x[1] = 1
assert_equal($x[1], 1)
assert_equal($x[2], 0)
assert_equal(1, $x[1])
assert_equal(0, $x[2])
$x = Hash.new([])
assert_equal($x[22], [])
assert_equal([], $x[22])
assert($x[22].equal?($x[22]))
$x = Hash.new{[]}
assert_equal($x[22], [])
assert_equal([], $x[22])
assert(!$x[22].equal?($x[22]))
$x = Hash.new{|h,k| $z = k; h[k] = k*2}
$z = 0
assert_equal($x[22], 44)
assert_equal($z, 22)
assert_equal(44, $x[22])
assert_equal(22, $z)
$z = 0
assert_equal($x[22], 44)
assert_equal($z, 0)
assert_equal(44, $x[22])
assert_equal(0, $z)
$x.default = 5
assert_equal($x[23], 5)
assert_equal(5, $x[23])
$x = Hash.new
def $x.default(k)
$z = k
self[k] = k*2
end
$z = 0
assert_equal($x[22], 44)
assert_equal($z, 22)
assert_equal(44, $x[22])
assert_equal(22, $z)
$z = 0
assert_equal($x[22], 44)
assert_equal($z, 0)
assert_equal(44, $x[22])
assert_equal(0, $z)
end
end

Просмотреть файл

@ -182,8 +182,8 @@ class TestIterator < Test::Unit::TestCase
def test_block_in_arg
assert(m1{p 'test'})
assert(m2{p 'test'})
assert(!m1)
assert(!m2)
assert(!m1())
assert(!m2())
end
class C
@ -356,6 +356,6 @@ class TestIterator < Test::Unit::TestCase
end
def test_iter4
ITER_TEST4.new.foo(44){55}
ITER_TEST4.new.foo(44){55}
end
end

Просмотреть файл

@ -20,7 +20,7 @@ class TestMarshal < Test::Unit::TestCase
$y = Marshal.dump($x)
assert_equal($x, Marshal.load($y))
assert_equal(Marshal.load(Marshal.dump(StrClone.new("abc"))).class, StrClone)
assert_instance_of(StrClone, Marshal.load(Marshal.dump(StrClone.new("abc"))))
[[1,2,3,4], [81, 2, 118, 3146]].each { |w,x,y,z|
a = (x.to_f + y.to_f / z.to_f) * Math.exp(w.to_f / (x.to_f + y.to_f / z.to_f))

Просмотреть файл

@ -4,11 +4,11 @@ $KCODE = 'none'
class TestMath < Test::Unit::TestCase
def test_math
assert_equal(Math.sqrt(4), 2)
assert_equal(2, Math.sqrt(4))
self.class.class_eval {
include Math
}
assert_equal(sqrt(4), 2)
assert_equal(2, sqrt(4))
end
end

Просмотреть файл

@ -10,12 +10,12 @@ class TestPack < Test::Unit::TestCase
ary = [1,-100,127,128,32767,987.654321098 / 100.0,12345,123456,-32767,-123456,"abcdef"]
$x = ary.pack($format)
ary2 = $x.unpack($format)
assert_equal(ary.length, ary2.length)
assert_equal(ary.join(':'), ary2.join(':'))
assert($x =~ /def/)
$x = [-1073741825]
assert_equal($x.pack("q").unpack("q"), $x)
assert_equal($x, $x.pack("q").unpack("q"))
end
end

Просмотреть файл

@ -4,45 +4,45 @@ $KCODE = 'none'
class TestPath < Test::Unit::TestCase
def test_path
assert_equal(File.basename("a"), "a")
assert_equal(File.basename("a/b"), "b")
assert_equal(File.basename("a/b/"), "b")
assert_equal(File.basename("/"), "/")
assert_equal(File.basename("//"), "/")
assert_equal(File.basename("///"), "/")
assert_equal(File.basename("a/b////"), "b")
assert_equal(File.basename("a.rb", ".rb"), "a")
assert_equal(File.basename("a.rb///", ".rb"), "a")
assert_equal(File.basename("a.rb///", ".*"), "a")
assert_equal(File.basename("a.rb///", ".c"), "a.rb")
assert_equal(File.dirname("a"), ".")
assert_equal(File.dirname("/"), "/")
assert_equal(File.dirname("/a"), "/")
assert_equal(File.dirname("a/b"), "a")
assert_equal(File.dirname("a/b/c"), "a/b")
assert_equal(File.dirname("/a/b/c"), "/a/b")
assert_equal(File.dirname("/a/b/"), "/a")
assert_equal(File.dirname("/a/b///"), "/a")
assert_equal("a", File.basename("a"))
assert_equal("b", File.basename("a/b"))
assert_equal("b", File.basename("a/b/"))
assert_equal("/", File.basename("/"))
assert_equal("/", File.basename("//"))
assert_equal("/", File.basename("///"))
assert_equal("b", File.basename("a/b////"))
assert_equal("a", File.basename("a.rb", ".rb"))
assert_equal("a", File.basename("a.rb///", ".rb"))
assert_equal("a", File.basename("a.rb///", ".*"))
assert_equal("a.rb", File.basename("a.rb///", ".c"))
assert_equal(".", File.dirname("a"))
assert_equal("/", File.dirname("/"))
assert_equal("/", File.dirname("/a"))
assert_equal("a", File.dirname("a/b"))
assert_equal("a/b", File.dirname("a/b/c"))
assert_equal("/a/b", File.dirname("/a/b/c"))
assert_equal("/a", File.dirname("/a/b/"))
assert_equal("/a", File.dirname("/a/b///"))
case Dir.pwd
when %r'\A\w:'
assert(/\A\w:\/\z/ =~ File.expand_path(".", "/"))
assert(/\A\w:\/a\z/ =~ File.expand_path("a", "/"))
assert_match(/\A\w:\/\z/, File.expand_path(".", "/"))
assert_match(/\A\w:\/a\z/, File.expand_path("a", "/"))
dosish = true
when %r'\A//'
assert(%r'\A//[^/]+/[^/]+\z' =~ File.expand_path(".", "/"))
assert(%r'\A//[^/]+/[^/]+/a\z' =~ File.expand_path(".", "/"))
assert_match(%r'\A//[^/]+/[^/]+\z', File.expand_path(".", "/"))
assert_match(%r'\A//[^/]+/[^/]+/a\z', File.expand_path(".", "/"))
dosish = true
else
assert_equal(File.expand_path(".", "/"), "/")
assert_equal(File.expand_path("sub", "/"), "/sub")
assert_equal("/", File.expand_path(".", "/"))
assert_equal("/sub", File.expand_path("sub", "/"))
end
if dosish
assert_equal(File.expand_path("/", "//machine/share/sub"), "//machine/share")
assert_equal(File.expand_path("/dir", "//machine/share/sub"), "//machine/share/dir")
assert_equal(File.expand_path("/", "z:/sub"), "z:/")
assert_equal(File.expand_path("/dir", "z:/sub"), "z:/dir")
assert_equal("//machine/share", File.expand_path("/", "//machine/share/sub"))
assert_equal("//machine/share/dir", File.expand_path("/dir", "//machine/share/sub"))
assert_equal("z:/", File.expand_path("/", "z:/sub"))
assert_equal("z:/dir", File.expand_path("/dir", "z:/sub"))
end
assert_equal(File.expand_path(".", "//"), "//")
assert_equal(File.expand_path("sub", "//"), "//sub")
assert_equal("//", File.expand_path(".", "//"))
assert_equal("//sub", File.expand_path("sub", "//"))
end
end

Просмотреть файл

@ -5,13 +5,13 @@ $KCODE = 'none'
class TestProc < Test::Unit::TestCase
def test_proc
$proc = proc{|i| i}
assert_equal($proc.call(2), 2)
assert_equal($proc.call(3), 3)
assert_equal(2, $proc.call(2))
assert_equal(3, $proc.call(3))
$proc = proc{|i| i*2}
assert_equal($proc.call(2), 4)
assert_equal($proc.call(3), 6)
assert_equal(4, $proc.call(2))
assert_equal(6, $proc.call(3))
proc{
iii=5 # nested local variable
$proc = proc{|i|
@ -24,11 +24,11 @@ class TestProc < Test::Unit::TestCase
assert(defined?(iii))
}.call
assert(!defined?(iii)) # out of scope
loop{iii=5; assert(eval("defined? iii")); break}
loop {
iii = 10
def dyna_var_check
def self.dyna_var_check
loop {
assert(!defined?(iii))
break
@ -40,6 +40,6 @@ class TestProc < Test::Unit::TestCase
$x=0
$proc.call(5)
$proc2.call
assert_equal($x, 5)
assert_equal(5, $x)
end
end

Просмотреть файл

@ -9,18 +9,16 @@ class TestSignal < Test::Unit::TestCase
trap "SIGINT", proc{|sig| $x = 2}
Process.kill "SIGINT", $$
sleep 0.1
assert_equal($x, 2)
assert_equal(2, $x)
trap "SIGINT", proc{raise "Interrupt"}
x = false
begin
x = assert_raises(RuntimeError) do
Process.kill "SIGINT", $$
sleep 0.1
rescue
x = $!
end
assert(x && /Interrupt/ =~ x.message)
assert(x)
assert_match(/Interrupt/, x.message)
end
end
end

Просмотреть файл

@ -8,78 +8,78 @@ class TestStringchar < Test::Unit::TestCase
assert("abcd" =~ /abcd/)
assert("abcd" === "abcd")
# compile time string concatenation
assert_equal("ab" "cd", "abcd")
assert_equal("#{22}aa" "cd#{44}", "22aacd44")
assert_equal("#{22}aa" "cd#{44}" "55" "#{66}", "22aacd445566")
assert_equal("abcd", "ab" "cd")
assert_equal("22aacd44", "#{22}aa" "cd#{44}")
assert_equal("22aacd445566", "#{22}aa" "cd#{44}" "55" "#{66}")
assert("abc" !~ /^$/)
assert("abc\n" !~ /^$/)
assert("abc" !~ /^d*$/)
assert_equal(("abc" =~ /d*$/), 3)
assert_equal(3, ("abc" =~ /d*$/))
assert("" =~ /^$/)
assert("\n" =~ /^$/)
assert("a\n\n" =~ /^$/)
assert("abcabc" =~ /.*a/ && $& == "abca")
assert("abcabc" =~ /.*c/ && $& == "abcabc")
assert("abcabc" =~ /.*?a/ && $& == "a")
assert("abcabc" =~ /.*?c/ && $& == "abc")
assert(/(.|\n)*?\n(b|\n)/ =~ "a\nb\n\n" && $& == "a\nb")
assert(/^(ab+)+b/ =~ "ababb" && $& == "ababb")
assert(/^(?:ab+)+b/ =~ "ababb" && $& == "ababb")
assert(/^(ab+)+/ =~ "ababb" && $& == "ababb")
assert(/^(?:ab+)+/ =~ "ababb" && $& == "ababb")
assert(/(\s+\d+){2}/ =~ " 1 2" && $& == " 1 2")
assert(/(?:\s+\d+){2}/ =~ " 1 2" && $& == " 1 2")
assert("abcabc" =~ /.*a/); assert_equal("abca", $&)
assert("abcabc" =~ /.*c/); assert_equal("abcabc", $&)
assert("abcabc" =~ /.*?a/); assert_equal("a", $&)
assert("abcabc" =~ /.*?c/); assert_equal("abc", $&)
assert(/(.|\n)*?\n(b|\n)/ =~ "a\nb\n\n"); assert_equal("a\nb", $&)
assert(/^(ab+)+b/ =~ "ababb"); assert_equal("ababb", $&)
assert(/^(?:ab+)+b/ =~ "ababb"); assert_equal("ababb", $&)
assert(/^(ab+)+/ =~ "ababb"); assert_equal("ababb", $&)
assert(/^(?:ab+)+/ =~ "ababb"); assert_equal("ababb", $&)
assert(/(\s+\d+){2}/ =~ " 1 2"); assert_equal(" 1 2", $&)
assert(/(?:\s+\d+){2}/ =~ " 1 2"); assert_equal(" 1 2", $&)
$x = <<END;
ABCD
ABCD
END
$x.gsub!(/((.|\n)*?)B((.|\n)*?)D/){$1+$3}
assert_equal($x, "AC\nAC\n")
assert_equal("AC\nAC\n", $x)
assert("foobar" =~ /foo(?=(bar)|(baz))/)
assert("foobaz" =~ /foo(?=(bar)|(baz))/)
$foo = "abc"
assert_equal("#$foo = abc", "abc = abc")
assert_equal("#{$foo} = abc", "abc = abc")
assert_equal("abc = abc", "#$foo = abc")
assert_equal("abc = abc", "#{$foo} = abc")
foo = "abc"
assert_equal("#{foo} = abc", "abc = abc")
assert_equal('-' * 5, '-----')
assert_equal('-' * 1, '-')
assert_equal('-' * 0, '')
assert_equal("abc = abc", "#{foo} = abc")
assert_equal('-----', '-' * 5)
assert_equal('-', '-' * 1)
assert_equal('', '-' * 0)
foo = '-'
assert_equal(foo * 5, '-----')
assert_equal(foo * 1, '-')
assert_equal(foo * 0, '')
assert_equal('-----', foo * 5)
assert_equal('-', foo * 1)
assert_equal('', foo * 0)
$x = "a.gif"
assert_equal($x.sub(/.*\.([^\.]+)$/, '\1'), "gif")
assert_equal($x.sub(/.*\.([^\.]+)$/, 'b.\1'), "b.gif")
assert_equal($x.sub(/.*\.([^\.]+)$/, '\2'), "")
assert_equal($x.sub(/.*\.([^\.]+)$/, 'a\2b'), "ab")
assert_equal($x.sub(/.*\.([^\.]+)$/, '<\&>'), "<a.gif>")
assert_equal("gif", $x.sub(/.*\.([^\.]+)$/, '\1'))
assert_equal("b.gif", $x.sub(/.*\.([^\.]+)$/, 'b.\1'))
assert_equal("", $x.sub(/.*\.([^\.]+)$/, '\2'))
assert_equal("ab", $x.sub(/.*\.([^\.]+)$/, 'a\2b'))
assert_equal("<a.gif>", $x.sub(/.*\.([^\.]+)$/, '<\&>'))
end
def test_char
# character constants(assumes ASCII)
assert_equal("a"[0], ?a)
assert_equal(?a, "a"[0])
assert_equal(?a, ?a)
assert_equal(?\C-a, 1)
assert_equal(?\M-a, 225)
assert_equal(?\M-\C-a, 129)
assert_equal("a".upcase![0], ?A)
assert_equal("A".downcase![0], ?a)
assert_equal("abc".tr!("a-z", "A-Z"), "ABC")
assert_equal("aabbcccc".tr_s!("a-z", "A-Z"), "ABC")
assert_equal("abcc".squeeze!("a-z"), "abc")
assert_equal("abcd".delete!("bc"), "ad")
assert_equal(1, ?\C-a)
assert_equal(225, ?\M-a)
assert_equal(129, ?\M-\C-a)
assert_equal(?A, "a".upcase![0])
assert_equal(?a, "A".downcase![0])
assert_equal("ABC", "abc".tr!("a-z", "A-Z"))
assert_equal("ABC", "aabbcccc".tr_s!("a-z", "A-Z"))
assert_equal("abc", "abcc".squeeze!("a-z"))
assert_equal("ad", "abcd".delete!("bc"))
$x = "abcdef"
$y = [ ?a, ?b, ?c, ?d, ?e, ?f ]
$bad = false
@ -90,29 +90,29 @@ END
end
}
assert(!$bad)
s = "a string"
s[0..s.size]="another string"
assert_equal(s, "another string")
assert_equal("another string", s)
s = <<EOS
#{
[1,2,3].join(",")
}
EOS
assert_equal(s, "1,2,3\n")
assert_equal("Just".to_i(36), 926381)
assert_equal("-another".to_i(36), -23200231779)
assert_equal(1299022.to_s(36), "ruby")
assert_equal(-1045307475.to_s(36), "-hacker")
assert_equal("Just_another_Ruby_hacker".to_i(36), 265419172580680477752431643787347)
assert_equal(-265419172580680477752431643787347.to_s(36), "-justanotherrubyhacker")
assert_equal("1,2,3\n", s)
assert_equal(926381, "Just".to_i(36))
assert_equal(-23200231779, "-another".to_i(36))
assert_equal("ruby", 1299022.to_s(36))
assert_equal("-hacker", -1045307475.to_s(36))
assert_equal(265419172580680477752431643787347, "Just_another_Ruby_hacker".to_i(36))
assert_equal("-justanotherrubyhacker", -265419172580680477752431643787347.to_s(36))
a = []
(0..255).each {|n|
ch = [n].pack("C")
a.push ch if /a#{Regexp.quote ch}b/x =~ "ab"
ch = [n].pack("C")
a.push ch if /a#{Regexp.quote ch}b/x =~ "ab"
}
assert_equal(a.size, 0)
assert_equal(0, a.size)
end
end

Просмотреть файл

@ -5,19 +5,22 @@ $KCODE = 'none'
class TestStruct < Test::Unit::TestCase
def test_struct
struct_test = Struct.new("Test", :foo, :bar)
assert_equal(struct_test, Struct::Test)
assert_equal(Struct::Test, struct_test)
test = struct_test.new(1, 2)
assert(test.foo == 1 && test.bar == 2)
assert(test[0] == 1 && test[1] == 2)
assert_equal(1, test.foo)
assert_equal(2, test.bar)
assert_equal(1, test[0])
assert_equal(2, test[1])
a, b = test.to_a
assert(a == 1 && b == 2)
assert_equal(1, a)
assert_equal(2, b)
test[0] = 22
assert_equal(test.foo, 22)
assert_equal(22, test.foo)
test.bar = 47
assert_equal(test.bar, 47)
end
assert_equal(47, test.bar)
end
end

Просмотреть файл

@ -3,29 +3,33 @@ require 'test/unit'
$KCODE = 'none'
class TestSystem < Test::Unit::TestCase
def valid_syntax?(code, fname)
eval("BEGIN {return true}\n#{code}", nil, fname, 0)
end
def test_system
if File.exist? "miniruby" or File.exist? "miniruby.exe"
ruby = "./miniruby"
else
ruby = "ruby"
end
assert_equal(`echo foobar`, "foobar\n")
assert_equal(`#{ruby} -e 'print "foobar"'`, 'foobar')
assert_equal("foobar\n", `echo foobar`)
assert_equal('foobar', `#{ruby} -e 'print "foobar"'`)
tmp = open("script_tmp", "w")
tmp.print "print $zzz\n";
tmp.close
assert_equal(`#{ruby} -s script_tmp -zzz`, 'true')
assert_equal(`#{ruby} -s script_tmp -zzz=555`, '555')
assert_equal('true', `#{ruby} -s script_tmp -zzz`)
assert_equal('555', `#{ruby} -s script_tmp -zzz=555`)
tmp = open("script_tmp", "w")
tmp.print "#! /usr/local/bin/ruby -s\n";
tmp.print "print $zzz\n";
tmp.close
assert_equal(`#{ruby} script_tmp -zzz=678`, '678')
assert_equal('678', `#{ruby} script_tmp -zzz=678`)
tmp = open("script_tmp", "w")
tmp.print "this is a leading junk\n";
tmp.print "#! /usr/local/bin/ruby -s\n";
@ -33,50 +37,37 @@ class TestSystem < Test::Unit::TestCase
tmp.print "__END__\n";
tmp.print "this is a trailing junk\n";
tmp.close
assert_equal(`#{ruby} -x script_tmp`, 'nil')
assert_equal(`#{ruby} -x script_tmp -zzz=555`, '555')
assert_equal('nil', `#{ruby} -x script_tmp`)
assert_equal('555', `#{ruby} -x script_tmp -zzz=555`)
tmp = open("script_tmp", "w")
for i in 1..5
tmp.print i, "\n"
end
tmp.close
`#{ruby} -i.bak -pe 'sub(/^[0-9]+$/){$&.to_i * 5}' script_tmp`
done = true
tmp = open("script_tmp", "r")
while tmp.gets
if $_.to_i % 5 != 0
done = false
break
end
assert_equal(0, $_.to_i % 5)
end
tmp.close
assert(done)
File.unlink "script_tmp" or `/bin/rm -f "script_tmp"`
File.unlink "script_tmp.bak" or `/bin/rm -f "script_tmp.bak"`
$bad = false
if (dir = File.dirname(File.dirname($0))) == '.'
dir = ""
else
dir << "/"
end
def valid_syntax?(code, fname)
eval("BEGIN {return true}\n#{code}", nil, fname, 0)
rescue Exception
puts $!.message
false
end
for script in Dir["#{dir}{lib,sample,ext}/**/*.rb"]
unless valid_syntax? IO::read(script), script
$bad = true
assert_nothing_raised(Exception) do
valid_syntax? IO::read(script), script
end
end
assert(!$bad)
end
end
end

Просмотреть файл

@ -8,16 +8,16 @@ class TestTrace < Test::Unit::TestCase
$y = 0
trace_var :$x, proc{$y = $x}
$x = 40414
assert_equal($y, $x)
assert_equal($x, $y)
untrace_var :$x
$x = 19660208
assert($y != $x)
trace_var :$x, proc{$x *= 2}
$x = 5
assert_equal($x, 10)
assert_equal(10, $x)
untrace_var :$x
end
end
end

Просмотреть файл

@ -11,7 +11,7 @@ class TestVariable < Test::Unit::TestCase
def self.ruler1 # <= per method definition style
@@rule
end
end
class << self # <= multiple method definition style
def ruler2
@@rule
@ -33,7 +33,7 @@ class TestVariable < Test::Unit::TestCase
def test_variable
assert($$.instance_of?(Fixnum))
# read-only variable
begin
$$ = 5
@ -41,18 +41,18 @@ class TestVariable < Test::Unit::TestCase
rescue NameError
assert true
end
foobar = "foobar"
$_ = foobar
assert_equal($_, foobar)
assert_equal(foobar, $_)
assert_equal(Gods.new.ruler0, "Cronus")
assert_equal(Gods.ruler1, "Cronus")
assert_equal(Gods.ruler2, "Cronus")
assert_equal(Titans.ruler1, "Cronus")
assert_equal(Titans.ruler2, "Cronus")
assert_equal("Cronus", Gods.new.ruler0)
assert_equal("Cronus", Gods.ruler1)
assert_equal("Cronus", Gods.ruler2)
assert_equal("Cronus", Titans.ruler1)
assert_equal("Cronus", Titans.ruler2)
atlas = Titans.new
assert_equal(atlas.ruler0, "Cronus")
assert_equal(atlas.ruler3, "Zeus")
assert_equal("Cronus", atlas.ruler0)
assert_equal("Zeus", atlas.ruler3)
end
end

Просмотреть файл

@ -13,25 +13,25 @@ class TestWhileuntil < Test::Unit::TestCase
tmp.close
tmp = open("while_tmp", "r")
assert(tmp.kind_of?(File))
assert_kind_of(File, tmp)
while line = tmp.gets()
break if /vt100/ =~ line
end
assert(!tmp.eof? && /vt100/ =~ line)
assert(!tmp.eof?)
assert_match(/vt100/, line)
tmp.close
$bad = false
tmp = open("while_tmp", "r")
while line = tmp.gets()
next if /vt100/ =~ line
$bad = 1 if /vt100/ =~ line
assert_no_match(/vt100/, line)
end
assert(!(!tmp.eof? || /vt100/ =~ line || $bad))
assert(tmp.eof?)
assert_no_match(/vt100/, line)
tmp.close
$bad = false
tmp = open("while_tmp", "r")
while tmp.gets()
line = $_
@ -40,12 +40,12 @@ class TestWhileuntil < Test::Unit::TestCase
$_.gsub!('VT100', 'Vt100')
redo
end
$bad = 1 if /vt100/ =~ $_
$bad = 1 if /VT100/ =~ $_
assert_no_match(/vt100/, $_)
assert_no_match(/VT100/, $_)
end
assert(tmp.eof? && !$bad)
assert(tmp.eof?)
tmp.close
sum=0
for i in 1..10
sum += i
@ -54,20 +54,17 @@ class TestWhileuntil < Test::Unit::TestCase
redo
end
end
assert_equal(sum, 220)
$bad = false
assert_equal(220, sum)
tmp = open("while_tmp", "r")
while line = tmp.gets()
break if 3
case line
when /vt100/, /Amiga/, /paper/
$bad = true
end
assert_no_match(/vt100/, line)
assert_no_match(/Amiga/, line)
assert_no_match(/paper/, line)
end
assert(!$bad)
tmp.close
File.unlink "while_tmp" or `/bin/rm -f "while_tmp"`
assert(!File.exist?("while_tmp"))
end

Просмотреть файл

@ -33,20 +33,23 @@ runners_map = {
}
runner = 'console'
ARGV.options do |opt|
opt.program_name = $0
opt.banner << " [tests...]"
opt.on("--runner=mode", runners_map.keys, "UI mode (console, gtk,fox)") do |arg|
runner = arg
end
opt.parse!
end or abort(ARGV.options.help)
if ARGV.empty?
ARGV.replace(Dir.glob(File.join(File.dirname(__FILE__), "**", "test_*.rb")).sort)
opt = OptionParser.new
opt.program_name = $0
opt.banner << " [tests...]"
opt.on("--runner=mode", runners_map.keys, "UI mode (console, gtk,fox)") do |arg|
runner = arg
end
begin
argv = opt.parse(*ARGV)
rescue OptionParser::ParseError
opt.abort($!)
end
ARGV.each do |tc_name|
if argv.empty?
argv = Dir.glob(File.join(File.dirname(__FILE__), "**", "test_*.rb")).sort
end
argv.each do |tc_name|
require tc_name
end