mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
test_string.rb: refine assertions
* test/ruby/test_string.rb: refine assertions, instead of mere assert. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43792 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5ff5938120
commit
f229f6e32c
1 changed files with 30 additions and 29 deletions
|
@ -187,18 +187,18 @@ class TestString < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_EQUAL # '=='
|
def test_EQUAL # '=='
|
||||||
assert_equal(false, S("foo") == :foo)
|
assert_not_equal(:foo, S("foo"))
|
||||||
assert(S("abcdef") == S("abcdef"))
|
assert_equal(S("abcdef"), S("abcdef"))
|
||||||
|
|
||||||
pre_1_7_1 do
|
pre_1_7_1 do
|
||||||
$= = true
|
$= = true
|
||||||
assert(S("CAT") == S('cat'))
|
assert_equal(S("CAT"), S('cat'))
|
||||||
assert(S("CaT") == S('cAt'))
|
assert_equal(S("CaT"), S('cAt'))
|
||||||
$= = false
|
$= = false
|
||||||
end
|
end
|
||||||
|
|
||||||
assert(S("CAT") != S('cat'))
|
assert_not_equal(S("CAT"), S('cat'))
|
||||||
assert(S("CaT") != S('cAt'))
|
assert_not_equal(S("CaT"), S('cAt'))
|
||||||
|
|
||||||
o = Object.new
|
o = Object.new
|
||||||
def o.to_str; end
|
def o.to_str; end
|
||||||
|
@ -280,11 +280,12 @@ class TestString < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def casetest(a, b, rev=false)
|
def casetest(a, b, rev=false)
|
||||||
|
msg = proc {"#{a} should#{' not' if rev} match #{b}"}
|
||||||
case a
|
case a
|
||||||
when b
|
when b
|
||||||
assert(!rev)
|
assert(!rev, msg)
|
||||||
else
|
else
|
||||||
assert(rev)
|
assert(rev, msg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -458,7 +459,7 @@ class TestString < Test::Unit::TestCase
|
||||||
b = a.clone
|
b = a.clone
|
||||||
|
|
||||||
assert_equal(a, b)
|
assert_equal(a, b)
|
||||||
assert(a.__id__ != b.__id__)
|
assert_not_same(a, b)
|
||||||
assert_equal(a.frozen?, b.frozen?)
|
assert_equal(a.frozen?, b.frozen?)
|
||||||
assert_equal(a.tainted?, b.tainted?)
|
assert_equal(a.tainted?, b.tainted?)
|
||||||
end
|
end
|
||||||
|
@ -502,7 +503,7 @@ class TestString < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_crypt
|
def test_crypt
|
||||||
assert_equal(S('aaGUC/JkO9/Sc'), S("mypassword").crypt(S("aa")))
|
assert_equal(S('aaGUC/JkO9/Sc'), S("mypassword").crypt(S("aa")))
|
||||||
assert(S('aaGUC/JkO9/Sc') != S("mypassword").crypt(S("ab")))
|
assert_not_equal(S('aaGUC/JkO9/Sc'), S("mypassword").crypt(S("ab")))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_delete
|
def test_delete
|
||||||
|
@ -591,8 +592,8 @@ class TestString < Test::Unit::TestCase
|
||||||
b = a.dup
|
b = a.dup
|
||||||
|
|
||||||
assert_equal(a, b)
|
assert_equal(a, b)
|
||||||
assert(a.__id__ != b.__id__)
|
assert_not_same(a, b)
|
||||||
assert(!b.frozen?)
|
assert_not_predicate(b, :frozen?)
|
||||||
assert_equal(a.tainted?, b.tainted?)
|
assert_equal(a.tainted?, b.tainted?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -780,8 +781,8 @@ class TestString < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_empty?
|
def test_empty?
|
||||||
assert(S("").empty?)
|
assert_empty(S(""))
|
||||||
assert(!S("not").empty?)
|
assert_not_empty(S("not"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_end_with?
|
def test_end_with?
|
||||||
|
@ -795,8 +796,8 @@ class TestString < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_eql?
|
def test_eql?
|
||||||
a = S("hello")
|
a = S("hello")
|
||||||
assert(a.eql?(S("hello")))
|
assert_operator(a, :eql?, S("hello"))
|
||||||
assert(a.eql?(a))
|
assert_operator(a, :eql?, a)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_gsub
|
def test_gsub
|
||||||
|
@ -809,7 +810,7 @@ class TestString < Test::Unit::TestCase
|
||||||
|
|
||||||
a = S("hello")
|
a = S("hello")
|
||||||
a.taint
|
a.taint
|
||||||
assert(a.gsub(/./, S('X')).tainted?)
|
assert_predicate(a.gsub(/./, S('X')), :tainted?)
|
||||||
|
|
||||||
assert_equal("z", "abc".gsub(/./, "a" => "z"), "moved from btest/knownbug")
|
assert_equal("z", "abc".gsub(/./, "a" => "z"), "moved from btest/knownbug")
|
||||||
|
|
||||||
|
@ -853,7 +854,7 @@ class TestString < Test::Unit::TestCase
|
||||||
r = S('X')
|
r = S('X')
|
||||||
r.taint
|
r.taint
|
||||||
a.gsub!(/./, r)
|
a.gsub!(/./, r)
|
||||||
assert(a.tainted?)
|
assert_predicate(a, :tainted?)
|
||||||
|
|
||||||
a = S("hello")
|
a = S("hello")
|
||||||
assert_nil(a.sub!(S('X'), S('Y')))
|
assert_nil(a.sub!(S('X'), S('Y')))
|
||||||
|
@ -881,7 +882,7 @@ class TestString < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_hash
|
def test_hash
|
||||||
assert_equal(S("hello").hash, S("hello").hash)
|
assert_equal(S("hello").hash, S("hello").hash)
|
||||||
assert(S("hello").hash != S("helLO").hash)
|
assert_not_equal(S("hello").hash, S("helLO").hash)
|
||||||
bug4104 = '[ruby-core:33500]'
|
bug4104 = '[ruby-core:33500]'
|
||||||
assert_not_equal(S("a").hash, S("a\0").hash, bug4104)
|
assert_not_equal(S("a").hash, S("a\0").hash, bug4104)
|
||||||
end
|
end
|
||||||
|
@ -909,10 +910,10 @@ class TestString < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_include?
|
def test_include?
|
||||||
assert( S("foobar").include?(?f))
|
assert_include(S("foobar"), ?f)
|
||||||
assert( S("foobar").include?(S("foo")))
|
assert_include(S("foobar"), S("foo"))
|
||||||
assert(!S("foobar").include?(S("baz")))
|
assert_not_include(S("foobar"), S("baz"))
|
||||||
assert(!S("foobar").include?(?z))
|
assert_not_include(S("foobar"), ?z)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_index
|
def test_index
|
||||||
|
@ -957,7 +958,7 @@ class TestString < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_intern
|
def test_intern
|
||||||
assert_equal(:koala, S("koala").intern)
|
assert_equal(:koala, S("koala").intern)
|
||||||
assert(:koala != S("Koala").intern)
|
assert_not_equal(:koala, S("Koala").intern)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_length
|
def test_length
|
||||||
|
@ -1044,7 +1045,7 @@ class TestString < Test::Unit::TestCase
|
||||||
a.taint
|
a.taint
|
||||||
b = a.replace(S("xyz"))
|
b = a.replace(S("xyz"))
|
||||||
assert_equal(S("xyz"), b)
|
assert_equal(S("xyz"), b)
|
||||||
assert(b.tainted?)
|
assert_predicate(b, :tainted?)
|
||||||
|
|
||||||
s = "foo" * 100
|
s = "foo" * 100
|
||||||
s2 = ("bar" * 100).dup
|
s2 = ("bar" * 100).dup
|
||||||
|
@ -1140,7 +1141,7 @@ class TestString < Test::Unit::TestCase
|
||||||
a.taint
|
a.taint
|
||||||
res = []
|
res = []
|
||||||
a.scan(/./) { |w| res << w }
|
a.scan(/./) { |w| res << w }
|
||||||
assert(res[0].tainted?, '[ruby-core:33338] #4087')
|
assert_predicate(res[0], :tainted?, '[ruby-core:33338] #4087')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_size
|
def test_size
|
||||||
|
@ -1435,7 +1436,7 @@ class TestString < Test::Unit::TestCase
|
||||||
a = S("hello")
|
a = S("hello")
|
||||||
a.taint
|
a.taint
|
||||||
x = a.sub(/./, S('X'))
|
x = a.sub(/./, S('X'))
|
||||||
assert(x.tainted?)
|
assert_predicate(x, :tainted?)
|
||||||
|
|
||||||
o = Object.new
|
o = Object.new
|
||||||
def o.to_str; "bar"; end
|
def o.to_str; "bar"; end
|
||||||
|
@ -1477,7 +1478,7 @@ class TestString < Test::Unit::TestCase
|
||||||
r = S('X')
|
r = S('X')
|
||||||
r.taint
|
r.taint
|
||||||
a.sub!(/./, r)
|
a.sub!(/./, r)
|
||||||
assert(a.tainted?)
|
assert_predicate(a, :tainted?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_succ
|
def test_succ
|
||||||
|
@ -1551,7 +1552,7 @@ class TestString < Test::Unit::TestCase
|
||||||
n += S("\001")
|
n += S("\001")
|
||||||
assert_equal(16, n.sum(17))
|
assert_equal(16, n.sum(17))
|
||||||
n[0] = 2.chr
|
n[0] = 2.chr
|
||||||
assert(15 != n.sum)
|
assert_not_equal(15, n.sum)
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_sum(str, bits=16)
|
def check_sum(str, bits=16)
|
||||||
|
|
Loading…
Reference in a new issue