1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

add tests.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15669 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-03-01 16:16:46 +00:00
parent 655fd2dc37
commit 601616d6ff

View file

@ -184,4 +184,58 @@ class TestRubyLiteral < Test::Unit::TestCase
assert_equal __LINE__, __LINE__
end
def test_integer
head = ['', '0x', '0o', '0b', '0d', '-', '+']
chars = ['0', '1', '_', '9', 'f']
head.each {|h|
4.times {|len|
a = [h]
len.times { a = a.product(chars).map {|x| x.join('') } }
a.each {|s|
next if s.empty?
begin
r1 = Integer(s)
rescue ArgumentError
r1 = :err
end
begin
r2 = eval(s)
rescue NameError, SyntaxError
r2 = :err
end
assert_equal(r1, r2, "Integer(#{s.inspect}) != eval(#{s.inspect})")
}
}
}
end
def test_float
head = ['', '-', '+']
chars = ['0', '1', '_', '9', 'f', '.']
head.each {|h|
6.times {|len|
a = [h]
len.times { a = a.product(chars).map {|x| x.join('') } }
a.each {|s|
next if s.empty?
next if /\.\z/ =~ s
next if /\A[-+]?\./ =~ s
next if /\A[-+]?0/ =~ s
begin
r1 = Float(s)
rescue ArgumentError
r1 = :err
end
begin
r2 = eval(s)
rescue NameError, SyntaxError
r2 = :err
end
r2 = :err if Range === r2
assert_equal(r1, r2, "Float(#{s.inspect}) != eval(#{s.inspect})")
}
}
}
end
end