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

test/ruby: better assertions

* test/ruby: use better assertions instead of mere assert.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44173 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-12-13 09:18:05 +00:00
parent 287d2adab0
commit 3ac0ec4ecd
45 changed files with 532 additions and 510 deletions

View file

@ -42,7 +42,7 @@ module Emoji
def test_encoding_name def test_encoding_name
%w(UTF8-DoCoMo %w(UTF8-DoCoMo
SJIS-DoCoMo).each do |n| SJIS-DoCoMo).each do |n|
assert Encoding.name_list.include?(n), "encoding not found: #{n}" assert_include Encoding.name_list, n, "encoding not found: #{n}"
end end
end end
@ -126,7 +126,7 @@ module Emoji
SJIS-KDDI SJIS-KDDI
ISO-2022-JP-KDDI ISO-2022-JP-KDDI
stateless-ISO-2022-JP-KDDI).each do |n| stateless-ISO-2022-JP-KDDI).each do |n|
assert Encoding.name_list.include?(n), "encoding not found: #{n}" assert_include Encoding.name_list, n, "encoding not found: #{n}"
end end
end end
@ -250,7 +250,7 @@ module Emoji
def test_encoding_name def test_encoding_name
%w(UTF8-SoftBank %w(UTF8-SoftBank
SJIS-SoftBank).each do |n| SJIS-SoftBank).each do |n|
assert Encoding.name_list.include?(n), "encoding not found: #{n}" assert_include Encoding.name_list, n, "encoding not found: #{n}"
end end
end end

View file

@ -122,7 +122,7 @@ EOT
def test_sym_eq def test_sym_eq
s = "aa".force_encoding("utf-16le") s = "aa".force_encoding("utf-16le")
assert(s.intern != :aa, "#{encdump s}.intern != :aa") assert_not_equal(:aa, s.intern, "#{encdump s}.intern != :aa")
end end
def test_compatible def test_compatible
@ -253,10 +253,10 @@ EOT
def test_succ def test_succ
s = "\xff\xff".force_encoding("utf-16be") s = "\xff\xff".force_encoding("utf-16be")
assert(s.succ.valid_encoding?, "#{encdump s}.succ.valid_encoding?") assert_predicate(s.succ, :valid_encoding?, "#{encdump s}.succ.valid_encoding?")
s = "\xdb\xff\xdf\xff".force_encoding("utf-16be") s = "\xdb\xff\xdf\xff".force_encoding("utf-16be")
assert(s.succ.valid_encoding?, "#{encdump s}.succ.valid_encoding?") assert_predicate(s.succ, :valid_encoding?, "#{encdump s}.succ.valid_encoding?")
end end
def test_regexp_union def test_regexp_union
@ -366,7 +366,7 @@ EOT
def test_regexp_escape def test_regexp_escape
s = "\0*".force_encoding("UTF-16BE") s = "\0*".force_encoding("UTF-16BE")
r = Regexp.new(Regexp.escape(s)) r = Regexp.new(Regexp.escape(s))
assert(r =~ s, "#{encdump(r)} =~ #{encdump(s)}") assert_match(r, s, "#{encdump(r)} =~ #{encdump(s)}")
end end
def test_casecmp2 def test_casecmp2

View file

@ -41,13 +41,14 @@ class TestArray < Test::Unit::TestCase
assert_equal([1, 2, 3], x[1,3]) assert_equal([1, 2, 3], x[1,3])
x[0, 2] = 10 x[0, 2] = 10
assert(x[0] == 10 && x[1] == 2) assert_equal([10, 2, 3, 4, 5], x)
x[0, 0] = -1 x[0, 0] = -1
assert(x[0] == -1 && x[1] == 10) assert_equal([-1, 10, 2, 3, 4, 5], x)
x[-1, 1] = 20 x[-1, 1] = 20
assert(x[-1] == 20 && x.pop == 20) assert_equal(20, x[-1])
assert_equal(20, x.pop)
end end
def test_array_andor_0 def test_array_andor_0
@ -97,7 +98,7 @@ class TestArray < Test::Unit::TestCase
end end
def test_misc_0 def test_misc_0
assert(defined? "a".chomp) assert(defined? "a".chomp, '"a".chomp is not defined')
assert_equal(["a", "b", "c"], "abc".scan(/./)) assert_equal(["a", "b", "c"], "abc".scan(/./))
assert_equal([["1a"], ["2b"], ["3c"]], "1a2b3c".scan(/(\d.)/)) assert_equal([["1a"], ["2b"], ["3c"]], "1a2b3c".scan(/(\d.)/))
# non-greedy match # non-greedy match
@ -1209,6 +1210,7 @@ class TestArray < Test::Unit::TestCase
a = @cls[] a = @cls[]
i = 0 i = 0
a.reverse_each { |e| a.reverse_each { |e|
i += 1
assert(false, "Never get here") assert(false, "Never get here")
} }
assert_equal(0, i) assert_equal(0, i)
@ -1710,7 +1712,7 @@ class TestArray < Test::Unit::TestCase
a = [] a = []
[1, 2].product([0, 1, 2, 3, 4][1, 4]) {|x| a << x } [1, 2].product([0, 1, 2, 3, 4][1, 4]) {|x| a << x }
assert(a.all?{|x| !x.include?(0) }) a.all? {|x| assert_not_include(x, 0)}
end end
def test_permutation def test_permutation
@ -1759,7 +1761,7 @@ class TestArray < Test::Unit::TestCase
assert_equal(@cls[1, 2, 3, 4].repeated_permutation(4).to_a, b) assert_equal(@cls[1, 2, 3, 4].repeated_permutation(4).to_a, b)
a = @cls[0, 1, 2, 3, 4][1, 4].repeated_permutation(2) a = @cls[0, 1, 2, 3, 4][1, 4].repeated_permutation(2)
assert(a.all?{|x| !x.include?(0) }) assert_empty(a.reject {|x| !x.include?(0)})
end end
def test_repeated_combination def test_repeated_combination
@ -1788,7 +1790,7 @@ class TestArray < Test::Unit::TestCase
assert_equal(@cls[1, 2, 3, 4].repeated_combination(4).to_a, b) assert_equal(@cls[1, 2, 3, 4].repeated_combination(4).to_a, b)
a = @cls[0, 1, 2, 3, 4][1, 4].repeated_combination(2) a = @cls[0, 1, 2, 3, 4][1, 4].repeated_combination(2)
assert(a.all?{|x| !x.include?(0) }) assert_empty(a.reject {|x| !x.include?(0)})
end end
def test_take def test_take

View file

@ -499,19 +499,19 @@ class Complex_Test < Test::Unit::TestCase
end end
def test_eqeq def test_eqeq
assert(Complex(1,0) == Complex(1)) assert_equal(Complex(1), Complex(1,0))
assert(Complex(-1,0) == Complex(-1)) assert_equal(Complex(-1), Complex(-1,0))
assert_equal(false, Complex(2,1) == Complex(1)) assert_not_equal(Complex(1), Complex(2,1))
assert_equal(true, Complex(2,1) != Complex(1)) assert_operator(Complex(2,1), :!=, Complex(1))
assert_equal(false, Complex(1) == nil) assert_not_equal(nil, Complex(1))
assert_equal(false, Complex(1) == '') assert_not_equal('', Complex(1))
nan = 0.0 / 0 nan = 0.0 / 0
if nan.nan? && nan != nan if nan.nan? && nan != nan
assert_equal(false, Complex(nan, 0) == Complex(nan, 0)) assert_not_equal(Complex(nan, 0), Complex(nan, 0))
assert_equal(false, Complex(0, nan) == Complex(0, nan)) assert_not_equal(Complex(0, nan), Complex(0, nan))
assert_equal(false, Complex(nan, nan) == Complex(nan, nan)) assert_not_equal(Complex(nan, nan), Complex(nan, nan))
end end
end end
@ -660,7 +660,7 @@ class Complex_Test < Test::Unit::TestCase
bug3656 = '[ruby-core:31622]' bug3656 = '[ruby-core:31622]'
c = Complex(1,2) c = Complex(1,2)
c.freeze c.freeze
assert(c.frozen?) assert_predicate(c, :frozen?)
result = c.marshal_load([2,3]) rescue :fail result = c.marshal_load([2,3]) rescue :fail
assert_equal(:fail, result, bug3656) assert_equal(:fail, result, bug3656)
assert_equal(Complex(1,2), c) assert_equal(Complex(1,2), c)
@ -972,9 +972,9 @@ class Complex_Test < Test::Unit::TestCase
if (0.0/0).nan? if (0.0/0).nan?
nan = 0.0/0 nan = 0.0/0
assert(nan.arg.equal?(nan)) assert_same(nan, nan.arg)
assert(nan.angle.equal?(nan)) assert_same(nan, nan.angle)
assert(nan.phase.equal?(nan)) assert_same(nan, nan.phase)
end end
assert_equal(Math::PI, -1.arg) assert_equal(Math::PI, -1.arg)

View file

@ -74,8 +74,8 @@ class ComplexRational_Test < Test::Unit::TestCase
assert_equal(0, Rational(2,3) <=> SimpleRat(2,3)) assert_equal(0, Rational(2,3) <=> SimpleRat(2,3))
assert_equal(0, SimpleRat(2,3) <=> Rational(2,3)) assert_equal(0, SimpleRat(2,3) <=> Rational(2,3))
assert(Rational(2,3) == SimpleRat(2,3)) assert_equal(Rational(2,3), SimpleRat(2,3))
assert(SimpleRat(2,3) == Rational(2,3)) assert_equal(SimpleRat(2,3), Rational(2,3))
assert_equal(SimpleRat, (c + 0).class) assert_equal(SimpleRat, (c + 0).class)
assert_equal(SimpleRat, (c - 0).class) assert_equal(SimpleRat, (c - 0).class)
@ -168,9 +168,9 @@ class ComplexRational_Test < Test::Unit::TestCase
assert_equal([Float,Float], assert_equal([Float,Float],
(cc ** c).instance_eval{[real.class, imag.class]}) (cc ** c).instance_eval{[real.class, imag.class]})
assert(Complex(SimpleRat(2,3),SimpleRat(3,2)) == assert_equal(Complex(SimpleRat(2,3),SimpleRat(3,2)),
Complex(Rational(2,3),Rational(3,2))) Complex(Rational(2,3),Rational(3,2)))
assert(Complex(Rational(2,3),Rational(3,2)) == assert_equal(Complex(Rational(2,3),Rational(3,2)),
Complex(SimpleRat(2,3),SimpleRat(3,2))) Complex(SimpleRat(2,3),SimpleRat(3,2)))
assert_equal([SimpleRat,SimpleRat], assert_equal([SimpleRat,SimpleRat],

View file

@ -86,8 +86,8 @@ class TestEncodingConverter < Test::Unit::TestCase
} }
encoding_list = Encoding.list.map {|e| e.name } encoding_list = Encoding.list.map {|e| e.name }
assert(!encoding_list.include?(name1)) assert_not_include(encoding_list, name1)
assert(!encoding_list.include?(name2)) assert_not_include(encoding_list, name2)
end end
def test_newline_converter_with_ascii_incompatible def test_newline_converter_with_ascii_incompatible

View file

@ -22,7 +22,7 @@ class TestEncoding < Test::Unit::TestCase
aliases.each do |a, en| aliases.each do |a, en|
e = Encoding.find(a) e = Encoding.find(a)
assert_equal(e.name, en) assert_equal(e.name, en)
assert(e.names.include?(a)) assert_include(e.names, a)
end end
end end
@ -85,8 +85,8 @@ class TestEncoding < Test::Unit::TestCase
def test_aliases def test_aliases
assert_instance_of(Hash, Encoding.aliases) assert_instance_of(Hash, Encoding.aliases)
Encoding.aliases.each do |k, v| Encoding.aliases.each do |k, v|
assert(Encoding.name_list.include?(k)) assert_include(Encoding.name_list, k)
assert(Encoding.name_list.include?(v)) assert_include(Encoding.name_list, v)
assert_instance_of(String, k) assert_instance_of(String, k)
assert_instance_of(String, v) assert_instance_of(String, v)
end end

View file

@ -291,10 +291,10 @@ class TestFiber < Test::Unit::TestCase
h_0 = eval(invoke_rec('p RubyVM::DEFAULT_PARAMS', 0, 0, false)) h_0 = eval(invoke_rec('p RubyVM::DEFAULT_PARAMS', 0, 0, false))
h_large = eval(invoke_rec('p RubyVM::DEFAULT_PARAMS', 1024 * 1024 * 10, 1024 * 1024 * 10, false)) h_large = eval(invoke_rec('p RubyVM::DEFAULT_PARAMS', 1024 * 1024 * 10, 1024 * 1024 * 10, false))
assert(h_default[:fiber_vm_stack_size] > h_0[:fiber_vm_stack_size]) assert_operator(h_default[:fiber_vm_stack_size], :>, h_0[:fiber_vm_stack_size])
assert(h_default[:fiber_vm_stack_size] < h_large[:fiber_vm_stack_size]) assert_operator(h_default[:fiber_vm_stack_size], :<, h_large[:fiber_vm_stack_size])
assert(h_default[:fiber_machine_stack_size] >= h_0[:fiber_machine_stack_size]) assert_operator(h_default[:fiber_machine_stack_size], :>=, h_0[:fiber_machine_stack_size])
assert(h_default[:fiber_machine_stack_size] <= h_large[:fiber_machine_stack_size]) assert_operator(h_default[:fiber_machine_stack_size], :<=, h_large[:fiber_machine_stack_size])
# check VM machine stack size # check VM machine stack size
script = '$stdout.sync=true; def rec; print "."; rec; end; Fiber.new{rec}.resume' script = '$stdout.sync=true; def rec; print "."; rec; end; Fiber.new{rec}.resume'

View file

@ -326,9 +326,9 @@ class TestFile < Test::Unit::TestCase
File.open(tmp, :mode => IO::RDWR | IO::CREAT | IO::BINARY, File.open(tmp, :mode => IO::RDWR | IO::CREAT | IO::BINARY,
:encoding => Encoding::ASCII_8BIT) do |x| :encoding => Encoding::ASCII_8BIT) do |x|
assert x.autoclose? assert_predicate(x, :autoclose?)
assert_equal Encoding::ASCII_8BIT, x.external_encoding assert_equal Encoding::ASCII_8BIT, x.external_encoding
assert x.write 'hello' x.write 'hello'
x.seek 0, IO::SEEK_SET x.seek 0, IO::SEEK_SET

View file

@ -63,11 +63,16 @@ class TestFileExhaustive < Test::Unit::TestCase
end end
def assert_integer(n) def assert_integer(n)
assert(n.is_a?(Integer), n.inspect + " is not Fixnum.") assert_kind_of(Integer, n)
end end
def assert_integer_or_nil(n) def assert_integer_or_nil(n)
assert(n.is_a?(Integer) || n.equal?(nil), n.inspect + " is neither Fixnum nor nil.") msg = ->{"#{n.inspect} is neither Fixnum nor nil."}
if n
assert_kind_of(Integer, n, msg)
else
assert_nil(n, msg)
end
end end
def test_stat def test_stat
@ -131,42 +136,42 @@ class TestFileExhaustive < Test::Unit::TestCase
end if /mswin|mingw|cygwin/ =~ RUBY_PLATFORM end if /mswin|mingw|cygwin/ =~ RUBY_PLATFORM
def test_directory_p def test_directory_p
assert(File.directory?(@dir)) assert_file.directory?(@dir)
assert(!(File.directory?(@dir+"/..."))) assert_file.not_directory?(@dir+"/...")
assert(!(File.directory?(@file))) assert_file.not_directory?(@file)
assert(!(File.directory?(@nofile))) assert_file.not_directory?(@nofile)
end end
def test_pipe_p ## xxx def test_pipe_p ## xxx
assert(!(File.pipe?(@dir))) assert_file.not_pipe?(@dir)
assert(!(File.pipe?(@file))) assert_file.not_pipe?(@file)
assert(!(File.pipe?(@nofile))) assert_file.not_pipe?(@nofile)
end end
def test_symlink_p def test_symlink_p
assert(!(File.symlink?(@dir))) assert_file.not_symlink?(@dir)
assert(!(File.symlink?(@file))) assert_file.not_symlink?(@file)
assert(File.symlink?(@symlinkfile)) if @symlinkfile assert_file.symlink?(@symlinkfile) if @symlinkfile
assert(!(File.symlink?(@hardlinkfile))) if @hardlinkfile assert_file.not_symlink?(@hardlinkfile) if @hardlinkfile
assert(!(File.symlink?(@nofile))) assert_file.not_symlink?(@nofile)
end end
def test_socket_p ## xxx def test_socket_p ## xxx
assert(!(File.socket?(@dir))) assert_file.not_socket?(@dir)
assert(!(File.socket?(@file))) assert_file.not_socket?(@file)
assert(!(File.socket?(@nofile))) assert_file.not_socket?(@nofile)
end end
def test_blockdev_p ## xxx def test_blockdev_p ## xxx
assert(!(File.blockdev?(@dir))) assert_file.not_blockdev?(@dir)
assert(!(File.blockdev?(@file))) assert_file.not_blockdev?(@file)
assert(!(File.blockdev?(@nofile))) assert_file.not_blockdev?(@nofile)
end end
def test_chardev_p ## xxx def test_chardev_p ## xxx
assert(!(File.chardev?(@dir))) assert_file.not_chardev?(@dir)
assert(!(File.chardev?(@file))) assert_file.not_chardev?(@file)
assert(!(File.chardev?(@nofile))) assert_file.not_chardev?(@nofile)
end end
def test_exist_p def test_exist_p
@ -179,119 +184,119 @@ class TestFileExhaustive < Test::Unit::TestCase
return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM
return if Process.euid == 0 return if Process.euid == 0
File.chmod(0200, @file) File.chmod(0200, @file)
assert(!(File.readable?(@file))) assert_file.not_readable?(@file)
File.chmod(0600, @file) File.chmod(0600, @file)
assert(File.readable?(@file)) assert_file.readable?(@file)
assert(!(File.readable?(@nofile))) assert_file.not_readable?(@nofile)
end end
def test_readable_real_p def test_readable_real_p
return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM
return if Process.euid == 0 return if Process.euid == 0
File.chmod(0200, @file) File.chmod(0200, @file)
assert(!(File.readable_real?(@file))) assert_file.not_readable_real?(@file)
File.chmod(0600, @file) File.chmod(0600, @file)
assert(File.readable_real?(@file)) assert_file.readable_real?(@file)
assert(!(File.readable_real?(@nofile))) assert_file.not_readable_real?(@nofile)
end end
def test_world_readable_p def test_world_readable_p
return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM
File.chmod(0006, @file) File.chmod(0006, @file)
assert(File.world_readable?(@file)) assert_file.world_readable?(@file)
File.chmod(0060, @file) File.chmod(0060, @file)
assert(!(File.world_readable?(@file))) assert_file.not_world_readable?(@file)
File.chmod(0600, @file) File.chmod(0600, @file)
assert(!(File.world_readable?(@file))) assert_file.not_world_readable?(@file)
assert(!(File.world_readable?(@nofile))) assert_file.not_world_readable?(@nofile)
end end
def test_writable_p def test_writable_p
return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM
return if Process.euid == 0 return if Process.euid == 0
File.chmod(0400, @file) File.chmod(0400, @file)
assert(!(File.writable?(@file))) assert_file.not_writable?(@file)
File.chmod(0600, @file) File.chmod(0600, @file)
assert(File.writable?(@file)) assert_file.writable?(@file)
assert(!(File.writable?(@nofile))) assert_file.not_writable?(@nofile)
end end
def test_writable_real_p def test_writable_real_p
return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM
return if Process.euid == 0 return if Process.euid == 0
File.chmod(0400, @file) File.chmod(0400, @file)
assert(!(File.writable_real?(@file))) assert_file.not_writable_real?(@file)
File.chmod(0600, @file) File.chmod(0600, @file)
assert(File.writable_real?(@file)) assert_file.writable_real?(@file)
assert(!(File.writable_real?(@nofile))) assert_file.not_writable_real?(@nofile)
end end
def test_world_writable_p def test_world_writable_p
return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM
File.chmod(0006, @file) File.chmod(0006, @file)
assert(File.world_writable?(@file)) assert_file.world_writable?(@file)
File.chmod(0060, @file) File.chmod(0060, @file)
assert(!(File.world_writable?(@file))) assert_file.not_world_writable?(@file)
File.chmod(0600, @file) File.chmod(0600, @file)
assert(!(File.world_writable?(@file))) assert_file.not_world_writable?(@file)
assert(!(File.world_writable?(@nofile))) assert_file.not_world_writable?(@nofile)
end end
def test_executable_p def test_executable_p
return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM
File.chmod(0100, @file) File.chmod(0100, @file)
assert(File.executable?(@file)) assert_file.executable?(@file)
File.chmod(0600, @file) File.chmod(0600, @file)
assert(!(File.executable?(@file))) assert_file.not_executable?(@file)
assert(!(File.executable?(@nofile))) assert_file.not_executable?(@nofile)
end end
def test_executable_real_p def test_executable_real_p
return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM
File.chmod(0100, @file) File.chmod(0100, @file)
assert(File.executable_real?(@file)) assert_file.executable_real?(@file)
File.chmod(0600, @file) File.chmod(0600, @file)
assert(!(File.executable_real?(@file))) assert_file.not_executable_real?(@file)
assert(!(File.executable_real?(@nofile))) assert_file.not_executable_real?(@nofile)
end end
def test_file_p def test_file_p
assert(!(File.file?(@dir))) assert_file.not_file?(@dir)
assert(File.file?(@file)) assert_file.file?(@file)
assert(!(File.file?(@nofile))) assert_file.not_file?(@nofile)
end end
def test_zero_p def test_zero_p
assert_nothing_raised { File.zero?(@dir) } assert_nothing_raised { File.zero?(@dir) }
assert(!(File.zero?(@file))) assert_file.not_zero?(@file)
assert(File.zero?(@zerofile)) assert_file.zero?(@zerofile)
assert(!(File.zero?(@nofile))) assert_file.not_zero?(@nofile)
end end
def test_size_p def test_size_p
assert_nothing_raised { File.size?(@dir) } assert_nothing_raised { File.size?(@dir) }
assert_equal(3, File.size?(@file)) assert_equal(3, File.size?(@file))
assert(!(File.size?(@zerofile))) assert_file.not_size?(@zerofile)
assert(!(File.size?(@nofile))) assert_file.not_size?(@nofile)
end end
def test_owned_p ## xxx def test_owned_p ## xxx
return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM
assert(File.owned?(@file)) assert_file.owned?(@file)
assert(File.grpowned?(@file)) assert_file.grpowned?(@file)
end end
def test_suid_sgid_sticky ## xxx def test_suid_sgid_sticky ## xxx
assert(!(File.setuid?(@file))) assert_file.not_setuid?(@file)
assert(!(File.setgid?(@file))) assert_file.not_setgid?(@file)
assert(!(File.sticky?(@file))) assert_file.not_sticky?(@file)
end end
def test_identical_p def test_identical_p
assert(File.identical?(@file, @file)) assert_file.identical?(@file, @file)
assert(!(File.identical?(@file, @zerofile))) assert_file.not_identical?(@file, @zerofile)
assert(!(File.identical?(@file, @nofile))) assert_file.not_identical?(@file, @nofile)
assert(!(File.identical?(@nofile, @file))) assert_file.not_identical?(@nofile, @file)
end end
def test_s_size def test_s_size

View file

@ -87,8 +87,14 @@ class TestFixnum < Test::Unit::TestCase
next if b == 0 next if b == 0
q, r = a.divmod(b) q, r = a.divmod(b)
assert_equal(a, b*q+r) assert_equal(a, b*q+r)
assert(r.abs < b.abs) assert_operator(r.abs, :<, b.abs)
assert(0 < b ? (0 <= r && r < b) : (b < r && r <= 0)) if 0 < b
assert_operator(r, :>=, 0)
assert_operator(r, :<, b)
else
assert_operator(r, :>, b)
assert_operator(r, :<=, 0)
end
assert_equal(q, a/b) assert_equal(q, a/b)
assert_equal(q, a.div(b)) assert_equal(q, a.div(b))
assert_equal(r, a%b) assert_equal(r, a%b)
@ -195,40 +201,40 @@ class TestFixnum < Test::Unit::TestCase
end end
def test_cmp def test_cmp
assert(1 != nil) assert_operator(1, :!=, nil)
assert_equal(0, 1 <=> 1) assert_equal(0, 1 <=> 1)
assert_equal(-1, 1 <=> 4294967296) assert_equal(-1, 1 <=> 4294967296)
assert_equal(0, 1 <=> 1.0) assert_equal(0, 1 <=> 1.0)
assert_nil(1 <=> nil) assert_nil(1 <=> nil)
assert(1.send(:>, 0)) assert_operator(1, :>, 0)
assert(!(1.send(:>, 1))) assert_not_operator(1, :>, 1)
assert(!(1.send(:>, 2))) assert_not_operator(1, :>, 2)
assert(!(1.send(:>, 4294967296))) assert_not_operator(1, :>, 4294967296)
assert(1.send(:>, 0.0)) assert_operator(1, :>, 0.0)
assert_raise(ArgumentError) { 1.send(:>, nil) } assert_raise(ArgumentError) { 1 > nil }
assert(1.send(:>=, 0)) assert_operator(1, :>=, 0)
assert(1.send(:>=, 1)) assert_operator(1, :>=, 1)
assert(!(1.send(:>=, 2))) assert_not_operator(1, :>=, 2)
assert(!(1.send(:>=, 4294967296))) assert_not_operator(1, :>=, 4294967296)
assert(1.send(:>=, 0.0)) assert_operator(1, :>=, 0.0)
assert_raise(ArgumentError) { 1.send(:>=, nil) } assert_raise(ArgumentError) { 1 >= nil }
assert(!(1.send(:<, 0))) assert_not_operator(1, :<, 0)
assert(!(1.send(:<, 1))) assert_not_operator(1, :<, 1)
assert(1.send(:<, 2)) assert_operator(1, :<, 2)
assert(1.send(:<, 4294967296)) assert_operator(1, :<, 4294967296)
assert(!(1.send(:<, 0.0))) assert_not_operator(1, :<, 0.0)
assert_raise(ArgumentError) { 1.send(:<, nil) } assert_raise(ArgumentError) { 1 < nil }
assert(!(1.send(:<=, 0))) assert_not_operator(1, :<=, 0)
assert(1.send(:<=, 1)) assert_operator(1, :<=, 1)
assert(1.send(:<=, 2)) assert_operator(1, :<=, 2)
assert(1.send(:<=, 4294967296)) assert_operator(1, :<=, 4294967296)
assert(!(1.send(:<=, 0.0))) assert_not_operator(1, :<=, 0.0)
assert_raise(ArgumentError) { 1.send(:<=, nil) } assert_raise(ArgumentError) { 1 <= nil }
end end
class DummyNumeric < Numeric class DummyNumeric < Numeric

View file

@ -13,18 +13,18 @@ class TestFloat < Test::Unit::TestCase
assert_equal(-2, (-2.6).truncate) assert_equal(-2, (-2.6).truncate)
assert_equal(3, 2.6.round) assert_equal(3, 2.6.round)
assert_equal(-2, (-2.4).truncate) assert_equal(-2, (-2.4).truncate)
assert((13.4 % 1 - 0.4).abs < 0.0001) assert_in_delta(13.4 % 1, 0.4, 0.0001)
assert_equal(36893488147419111424, assert_equal(36893488147419111424,
36893488147419107329.0.to_i) 36893488147419107329.0.to_i)
end end
def nan_test(x,y) def nan_test(x,y)
extend Test::Unit::Assertions extend Test::Unit::Assertions
assert(x != y) assert_operator(x, :!=, y)
assert_equal(false, (x < y)) assert_not_operator(x, :<, y)
assert_equal(false, (x > y)) assert_not_operator(x, :>, y)
assert_equal(false, (x <= y)) assert_not_operator(x, :<=, y)
assert_equal(false, (x >= y)) assert_not_operator(x, :>=, y)
end end
def test_nan def test_nan
nan = Float::NAN nan = Float::NAN
@ -108,25 +108,25 @@ class TestFloat < Test::Unit::TestCase
def test_strtod def test_strtod
a = Float("0") a = Float("0")
assert(a.abs < Float::EPSILON) assert_in_delta(a, 0, Float::EPSILON)
a = Float("0.0") a = Float("0.0")
assert(a.abs < Float::EPSILON) assert_in_delta(a, 0, Float::EPSILON)
a = Float("+0.0") a = Float("+0.0")
assert(a.abs < Float::EPSILON) assert_in_delta(a, 0, Float::EPSILON)
a = Float("-0.0") a = Float("-0.0")
assert(a.abs < Float::EPSILON) assert_in_delta(a, 0, Float::EPSILON)
a = Float("0.0000000000000000001") a = Float("0.0000000000000000001")
assert(a != 0.0) assert_not_equal(0.0, a)
a = Float("+0.0000000000000000001") a = Float("+0.0000000000000000001")
assert(a != 0.0) assert_not_equal(0.0, a)
a = Float("-0.0000000000000000001") a = Float("-0.0000000000000000001")
assert(a != 0.0) assert_not_equal(0.0, a)
a = Float(".0") a = Float(".0")
assert(a.abs < Float::EPSILON) assert_in_delta(a, 0, Float::EPSILON)
a = Float("+.0") a = Float("+.0")
assert(a.abs < Float::EPSILON) assert_in_delta(a, 0, Float::EPSILON)
a = Float("-.0") a = Float("-.0")
assert(a.abs < Float::EPSILON) assert_in_delta(a, 0, Float::EPSILON)
assert_raise(ArgumentError){Float("0.")} assert_raise(ArgumentError){Float("0.")}
assert_raise(ArgumentError){Float("+0.")} assert_raise(ArgumentError){Float("+0.")}
assert_raise(ArgumentError){Float("-0.")} assert_raise(ArgumentError){Float("-0.")}
@ -281,15 +281,15 @@ class TestFloat < Test::Unit::TestCase
def test_eql def test_eql
inf = Float::INFINITY inf = Float::INFINITY
nan = Float::NAN nan = Float::NAN
assert(1.0.eql?(1.0)) assert_operator(1.0, :eql?, 1.0)
assert(inf.eql?(inf)) assert_operator(inf, :eql?, inf)
assert(!(nan.eql?(nan))) assert_not_operator(nan, :eql?, nan)
assert(!(1.0.eql?(nil))) assert_not_operator(1.0, :eql?, nil)
assert(1.0 == 1) assert_equal(1.0, 1)
assert(1.0 != 2**32) assert_not_equal(1.0, 2**32)
assert(1.0 != nan) assert_not_equal(1.0, nan)
assert(1.0 != nil) assert_not_equal(1.0, nil)
end end
def test_cmp def test_cmp
@ -334,8 +334,8 @@ class TestFloat < Test::Unit::TestCase
end end
def test_zero_p def test_zero_p
assert(0.0.zero?) assert_predicate(0.0, :zero?)
assert(!(1.0.zero?)) assert_not_predicate(1.0, :zero?)
end end
def test_infinite_p def test_infinite_p
@ -347,9 +347,9 @@ class TestFloat < Test::Unit::TestCase
def test_finite_p def test_finite_p
inf = Float::INFINITY inf = Float::INFINITY
assert(!(inf.finite?)) assert_not_predicate(inf, :finite?)
assert(!((-inf).finite?)) assert_not_predicate(-inf, :finite?)
assert(1.0.finite?) assert_predicate(1.0, :finite?)
end end
def test_floor_ceil_round_truncate def test_floor_ceil_round_truncate
@ -532,7 +532,7 @@ class TestFloat < Test::Unit::TestCase
assert_in_delta(0.125, Float("0.1_2_5"), 0.00001) assert_in_delta(0.125, Float("0.1_2_5"), 0.00001)
assert_in_delta(0.125, "0.1_2_5__".to_f, 0.00001) assert_in_delta(0.125, "0.1_2_5__".to_f, 0.00001)
assert_equal(1, suppress_warning {Float(([1] * 10000).join)}.infinite?) assert_equal(1, suppress_warning {Float(([1] * 10000).join)}.infinite?)
assert(!Float(([1] * 10000).join("_")).infinite?) # is it really OK? assert_not_predicate(Float(([1] * 10000).join("_")), :infinite?) # is it really OK?
assert_raise(ArgumentError) { Float("1.0\x001") } assert_raise(ArgumentError) { Float("1.0\x001") }
assert_equal(15.9375, Float('0xf.fp0')) assert_equal(15.9375, Float('0xf.fp0'))
assert_raise(ArgumentError) { Float('0x') } assert_raise(ArgumentError) { Float('0x') }
@ -549,7 +549,7 @@ class TestFloat < Test::Unit::TestCase
assert_raise(TypeError) { Float(nil) } assert_raise(TypeError) { Float(nil) }
o = Object.new o = Object.new
def o.to_f; inf = Float::INFINITY; inf/inf; end def o.to_f; inf = Float::INFINITY; inf/inf; end
assert(Float(o).nan?) assert_predicate(Float(o), :nan?)
end end
def test_invalid_str def test_invalid_str

View file

@ -256,7 +256,7 @@ class TestGc < Test::Unit::TestCase
a = [] a = []
(base_length * 500).times{ a << 'a'; nil } (base_length * 500).times{ a << 'a'; nil }
GC.start GC.start
assert base_length < GC.stat[:heap_eden_page_length] assert_operator base_length, :<, GC.stat[:heap_eden_page_length]
eom eom
end end

View file

@ -492,7 +492,7 @@ class TestHash < Test::Unit::TestCase
h = @cls[ 'a' => 1, 'b' => 2, 'c' => 1].invert h = @cls[ 'a' => 1, 'b' => 2, 'c' => 1].invert
assert_equal(2, h.length) assert_equal(2, h.length)
assert(h[1] == 'a' || h[1] == 'c') assert_include(%w[a c], h[1])
assert_equal('b', h[2]) assert_equal('b', h[2])
end end
@ -787,7 +787,7 @@ class TestHash < Test::Unit::TestCase
assert_nil(h.default_proc = nil) assert_nil(h.default_proc = nil)
assert_nil(h.default_proc) assert_nil(h.default_proc)
h.default_proc = ->(h, k){ true } h.default_proc = ->(h, k){ true }
assert(h[:nope]) assert_equal(true, h[:nope])
h = @cls[] h = @cls[]
assert_nil(h.default_proc) assert_nil(h.default_proc)
end end

View file

@ -35,9 +35,9 @@ class TestInteger < Test::Unit::TestCase
def test_rshift def test_rshift
# assert_equal(bdsize(0x40000001), (1 >> -0x40000001).size) # assert_equal(bdsize(0x40000001), (1 >> -0x40000001).size)
assert((1 >> 0x80000000).zero?) assert_predicate((1 >> 0x80000000), :zero?)
assert((1 >> 0xffffffff).zero?) assert_predicate((1 >> 0xffffffff), :zero?)
assert((1 >> 0x100000000).zero?) assert_predicate((1 >> 0x100000000), :zero?)
# assert_equal((1 << 0x40000000), (1 >> -0x40000000)) # assert_equal((1 << 0x40000000), (1 >> -0x40000000))
# assert_equal((1 << 0x40000001), (1 >> -0x40000001)) # assert_equal((1 << 0x40000001), (1 >> -0x40000001))
end end
@ -100,8 +100,8 @@ class TestInteger < Test::Unit::TestCase
end end
def test_int_p def test_int_p
assert(!(1.0.integer?)) assert_not_predicate(1.0, :integer?)
assert(1.integer?) assert_predicate(1, :integer?)
end end
def test_odd_p_even_p def test_odd_p_even_p
@ -111,10 +111,10 @@ class TestInteger < Test::Unit::TestCase
remove_method :odd?, :even? remove_method :odd?, :even?
end end
assert(1.odd?) assert_predicate(1, :odd?)
assert(!(2.odd?)) assert_not_predicate(2, :odd?)
assert(!(1.even?)) assert_not_predicate(1, :even?)
assert(2.even?) assert_predicate(2, :even?)
ensure ensure
Fixnum.class_eval do Fixnum.class_eval do

View file

@ -206,8 +206,14 @@ class TestIntegerComb < Test::Unit::TestCase
check_class(q) check_class(q)
check_class(r) check_class(r)
assert_equal(a, b*q+r) assert_equal(a, b*q+r)
assert(r.abs < b.abs) assert_operator(r.abs, :<, b.abs)
assert(0 < b ? (0 <= r && r < b) : (b < r && r <= 0)) if 0 < b
assert_operator(r, :>=, 0)
assert_operator(r, :<, b)
else
assert_operator(r, :>, b)
assert_operator(r, :<=, 0)
end
assert_equal(q, a/b) assert_equal(q, a/b)
assert_equal(q, a.div(b)) assert_equal(q, a.div(b))
assert_equal(r, a%b) assert_equal(r, a%b)

View file

@ -122,13 +122,13 @@ class TestIO < Test::Unit::TestCase
assert_equal("abc", r.read) assert_equal("abc", r.read)
end end
].each{|thr| thr.join} ].each{|thr| thr.join}
assert(!r.closed?) assert_not_predicate(r, :closed?)
assert(w.closed?) assert_predicate(w, :closed?)
:foooo :foooo
} }
assert_equal(:foooo, ret) assert_equal(:foooo, ret)
assert(x[0].closed?) assert_predicate(x[0], :closed?)
assert(x[1].closed?) assert_predicate(x[1], :closed?)
end end
def test_pipe_block_close def test_pipe_block_close
@ -139,8 +139,8 @@ class TestIO < Test::Unit::TestCase
r.close if (i&1) == 0 r.close if (i&1) == 0
w.close if (i&2) == 0 w.close if (i&2) == 0
} }
assert(x[0].closed?) assert_predicate(x[0], :closed?)
assert(x[1].closed?) assert_predicate(x[1], :closed?)
} }
end end
@ -775,7 +775,7 @@ class TestIO < Test::Unit::TestCase
s1.close s1.close
_, status = Process.waitpid2(pid) if pid _, status = Process.waitpid2(pid) if pid
end end
assert status.success?, status.inspect assert_predicate(status, :success?)
end end
} }
} }
@ -1297,7 +1297,7 @@ class TestIO < Test::Unit::TestCase
buf = "buf" buf = "buf"
value = r.read_nonblock(4096, buf, exception: false) value = r.read_nonblock(4096, buf, exception: false)
assert_equal value, "HI!\n" assert_equal value, "HI!\n"
assert buf.equal?(value) assert_same(buf, value)
w.close w.close
assert_equal nil, r.read_nonblock(4096, "", exception: false) assert_equal nil, r.read_nonblock(4096, "", exception: false)
} }
@ -2276,8 +2276,8 @@ End
def test_tainted def test_tainted
make_tempfile {|t| make_tempfile {|t|
assert(File.read(t.path, 4).tainted?, '[ruby-dev:38826]') assert_predicate(File.read(t.path, 4), :tainted?, '[ruby-dev:38826]')
assert(File.open(t.path) {|f| f.read(4)}.tainted?, '[ruby-dev:38826]') assert_predicate(File.open(t.path) {|f| f.read(4)}, :tainted?, '[ruby-dev:38826]')
} }
end end
@ -2631,25 +2631,25 @@ End
def test_cloexec def test_cloexec
return unless defined? Fcntl::FD_CLOEXEC return unless defined? Fcntl::FD_CLOEXEC
open(__FILE__) {|f| open(__FILE__) {|f|
assert(f.close_on_exec?) assert_predicate(f, :close_on_exec?)
g = f.dup g = f.dup
begin begin
assert(g.close_on_exec?) assert_predicate(g, :close_on_exec?)
f.reopen(g) f.reopen(g)
assert(f.close_on_exec?) assert_predicate(f, :close_on_exec?)
ensure ensure
g.close g.close
end end
g = IO.new(f.fcntl(Fcntl::F_DUPFD)) g = IO.new(f.fcntl(Fcntl::F_DUPFD))
begin begin
assert(g.close_on_exec?) assert_predicate(g, :close_on_exec?)
ensure ensure
g.close g.close
end end
} }
IO.pipe {|r,w| IO.pipe {|r,w|
assert(r.close_on_exec?) assert_predicate(r, :close_on_exec?)
assert(w.close_on_exec?) assert_predicate(w, :close_on_exec?)
} }
end end

View file

@ -2099,7 +2099,7 @@ EOT
open("ff", "w") {|f| } open("ff", "w") {|f| }
open("ff", "rt") {|f| open("ff", "rt") {|f|
f.ungetc "a" f.ungetc "a"
assert(!f.eof?, "[ruby-dev:40506] (3)") assert_not_predicate(f, :eof?, "[ruby-dev:40506] (3)")
} }
} }
end end

View file

@ -103,7 +103,7 @@ class TestISeq < Test::Unit::TestCase
iseq = ISeq.of(method(:test_location)) iseq = ISeq.of(method(:test_location))
assert_equal(__FILE__, iseq.path) assert_equal(__FILE__, iseq.path)
assert(/#{__FILE__}/ =~ iseq.absolute_path) assert_match(/#{__FILE__}/, iseq.absolute_path)
assert_equal("test_location", iseq.label) assert_equal("test_location", iseq.label)
assert_equal("test_location", iseq.base_label) assert_equal("test_location", iseq.base_label)
assert_equal(LINE_OF_HERE+1, iseq.first_lineno) assert_equal(LINE_OF_HERE+1, iseq.first_lineno)
@ -111,7 +111,7 @@ class TestISeq < Test::Unit::TestCase
line = __LINE__ line = __LINE__
iseq = ISeq.of(Proc.new{}) iseq = ISeq.of(Proc.new{})
assert_equal(__FILE__, iseq.path) assert_equal(__FILE__, iseq.path)
assert(/#{__FILE__}/ =~ iseq.absolute_path) assert_match(/#{__FILE__}/, iseq.absolute_path)
assert_equal("test_location", iseq.base_label) assert_equal("test_location", iseq.base_label)
assert_equal("block in test_location", iseq.label) assert_equal("block in test_location", iseq.label)
assert_equal(line+1, iseq.first_lineno) assert_equal(line+1, iseq.first_lineno)

View file

@ -25,7 +25,7 @@ class TestM17N < Test::Unit::TestCase
end end
def assert_regexp_generic_encoding(r) def assert_regexp_generic_encoding(r)
assert(!r.fixed_encoding?) assert_not_predicate(r, :fixed_encoding?)
%w[ASCII-8BIT EUC-JP Windows-31J UTF-8].each {|ename| %w[ASCII-8BIT EUC-JP Windows-31J UTF-8].each {|ename|
# "\xc2\xa1" is a valid sequence for ASCII-8BIT, EUC-JP, Windows-31J and UTF-8. # "\xc2\xa1" is a valid sequence for ASCII-8BIT, EUC-JP, Windows-31J and UTF-8.
assert_nothing_raised { r =~ "\xc2\xa1".force_encoding(ename) } assert_nothing_raised { r =~ "\xc2\xa1".force_encoding(ename) }
@ -33,7 +33,7 @@ class TestM17N < Test::Unit::TestCase
end end
def assert_regexp_fixed_encoding(r) def assert_regexp_fixed_encoding(r)
assert(r.fixed_encoding?) assert_predicate(r, :fixed_encoding?)
%w[ASCII-8BIT EUC-JP Windows-31J UTF-8].each {|ename| %w[ASCII-8BIT EUC-JP Windows-31J UTF-8].each {|ename|
enc = Encoding.find(ename) enc = Encoding.find(ename)
if enc == r.encoding if enc == r.encoding
@ -107,7 +107,7 @@ class TestM17N < Test::Unit::TestCase
elsif !s2.ascii_only? elsif !s2.ascii_only?
assert_equal(s2.encoding, t.encoding) assert_equal(s2.encoding, t.encoding)
else else
assert([s1.encoding, s2.encoding].include?(t.encoding)) assert_include([s1.encoding, s2.encoding], t.encoding)
end end
end end
@ -360,15 +360,15 @@ class TestM17N < Test::Unit::TestCase
].each {|pat2| ].each {|pat2|
s = [pat2.gsub(/ /, "")].pack("B*").force_encoding("utf-8") s = [pat2.gsub(/ /, "")].pack("B*").force_encoding("utf-8")
if pat2 <= bits_0x10ffff if pat2 <= bits_0x10ffff
assert(s.valid_encoding?, "#{pat2}") assert_predicate(s, :valid_encoding?, "#{pat2}")
else else
assert(!s.valid_encoding?, "#{pat2}") assert_not_predicate(s, :valid_encoding?, "#{pat2}")
end end
} }
if / / =~ pat0 if / / =~ pat0
pat3 = pat1.gsub(/X/, "0") pat3 = pat1.gsub(/X/, "0")
s = [pat3.gsub(/ /, "")].pack("B*").force_encoding("utf-8") s = [pat3.gsub(/ /, "")].pack("B*").force_encoding("utf-8")
assert(!s.valid_encoding?, "#{pat3}") assert_not_predicate(s, :valid_encoding?, "#{pat3}")
end end
} }
} }
@ -388,12 +388,12 @@ class TestM17N < Test::Unit::TestCase
pat0.gsub(/x/, '1'), pat0.gsub(/x/, '1'),
].each {|pat1| ].each {|pat1|
s = [pat1.gsub(/ /, "")].pack("B*").force_encoding("utf-8") s = [pat1.gsub(/ /, "")].pack("B*").force_encoding("utf-8")
assert(!s.valid_encoding?, "#{pat1}") assert_not_predicate(s, :valid_encoding?, "#{pat1}")
} }
} }
pats.values_at(0,3).each {|pat| pats.values_at(0,3).each {|pat|
s = [pat.gsub(/ /, "")].pack("B*").force_encoding("utf-8") s = [pat.gsub(/ /, "")].pack("B*").force_encoding("utf-8")
assert(s.valid_encoding?, "#{pat}") assert_predicate(s, :valid_encoding?, "#{pat}")
} }
end end
@ -592,38 +592,38 @@ class TestM17N < Test::Unit::TestCase
assert_nothing_raised { assert_nothing_raised {
r = Regexp.new(s) r = Regexp.new(s)
} }
assert(r.fixed_encoding?) assert_predicate(r, :fixed_encoding?)
assert_match(r, "\xa4\xa2".force_encoding("euc-jp")) assert_match(r, "\xa4\xa2".force_encoding("euc-jp"))
r = eval('/\p{Hiragana}/'.force_encoding("euc-jp")) r = eval('/\p{Hiragana}/'.force_encoding("euc-jp"))
assert(r.fixed_encoding?) assert_predicate(r, :fixed_encoding?)
assert_match(r, "\xa4\xa2".force_encoding("euc-jp")) assert_match(r, "\xa4\xa2".force_encoding("euc-jp"))
r = /\p{Hiragana}/e r = /\p{Hiragana}/e
assert(r.fixed_encoding?) assert_predicate(r, :fixed_encoding?)
assert_match(r, "\xa4\xa2".force_encoding("euc-jp")) assert_match(r, "\xa4\xa2".force_encoding("euc-jp"))
r = /\p{AsciI}/e r = /\p{AsciI}/e
assert(r.fixed_encoding?) assert_predicate(r, :fixed_encoding?)
assert_match(r, "a".force_encoding("euc-jp")) assert_match(r, "a".force_encoding("euc-jp"))
r = /\p{hiraganA}/e r = /\p{hiraganA}/e
assert(r.fixed_encoding?) assert_predicate(r, :fixed_encoding?)
assert_match(r, "\xa4\xa2".force_encoding("euc-jp")) assert_match(r, "\xa4\xa2".force_encoding("euc-jp"))
r = eval('/\u{3042}\p{Hiragana}/'.force_encoding("euc-jp")) r = eval('/\u{3042}\p{Hiragana}/'.force_encoding("euc-jp"))
assert(r.fixed_encoding?) assert_predicate(r, :fixed_encoding?)
assert_equal(Encoding::UTF_8, r.encoding) assert_equal(Encoding::UTF_8, r.encoding)
r = eval('/\p{Hiragana}\u{3042}/'.force_encoding("euc-jp")) r = eval('/\p{Hiragana}\u{3042}/'.force_encoding("euc-jp"))
assert(r.fixed_encoding?) assert_predicate(r, :fixed_encoding?)
assert_equal(Encoding::UTF_8, r.encoding) assert_equal(Encoding::UTF_8, r.encoding)
end end
def test_regexp_embed_preprocess def test_regexp_embed_preprocess
r1 = /\xa4\xa2/e r1 = /\xa4\xa2/e
r2 = /#{r1}/ r2 = /#{r1}/
assert(r2.source.include?(r1.source)) assert_include(r2.source, r1.source)
end end
def test_begin_end_offset def test_begin_end_offset
@ -668,10 +668,10 @@ class TestM17N < Test::Unit::TestCase
def test_union_0 def test_union_0
r = Regexp.union r = Regexp.union
assert_regexp_generic_ascii(r) assert_regexp_generic_ascii(r)
assert(r !~ a("")) assert_not_match(r, a(""))
assert(r !~ e("")) assert_not_match(r, e(""))
assert(r !~ s("")) assert_not_match(r, s(""))
assert(r !~ u("")) assert_not_match(r, u(""))
end end
def test_union_1_asciionly_string def test_union_1_asciionly_string
@ -894,9 +894,9 @@ class TestM17N < Test::Unit::TestCase
end end
def test_str_lt def test_str_lt
assert(a("a") < a("\xa1")) assert_operator(a("a"), :<, a("\xa1"))
assert(a("a") < s("\xa1")) assert_operator(a("a"), :<, s("\xa1"))
assert(s("a") < a("\xa1")) assert_operator(s("a"), :<, a("\xa1"))
end end
def test_str_multiply def test_str_multiply
@ -1069,15 +1069,15 @@ class TestM17N < Test::Unit::TestCase
s = "\x80".force_encoding("ASCII-8BIT") s = "\x80".force_encoding("ASCII-8BIT")
r = Regexp.new("\x80".force_encoding("ASCII-8BIT")) r = Regexp.new("\x80".force_encoding("ASCII-8BIT"))
s2 = s.sub(r, "") s2 = s.sub(r, "")
assert(s2.empty?) assert_empty(s2)
assert(s2.ascii_only?) assert_predicate(s2, :ascii_only?)
end end
def test_sub3 def test_sub3
repl = "\x81".force_encoding("sjis") repl = "\x81".force_encoding("sjis")
assert_equal(false, repl.valid_encoding?) assert_equal(false, repl.valid_encoding?)
s = "a@".sub(/a/, repl) s = "a@".sub(/a/, repl)
assert(s.valid_encoding?) assert_predicate(s, :valid_encoding?)
end end
def test_insert def test_insert
@ -1459,7 +1459,7 @@ class TestM17N < Test::Unit::TestCase
end end
def test_force_encoding def test_force_encoding
assert(("".center(1, "\x80".force_encoding("utf-8")); true), assert_equal(u("\x80"), "".center(1, u("\x80")),
"moved from btest/knownbug, [ruby-dev:33807]") "moved from btest/knownbug, [ruby-dev:33807]")
a = "".force_encoding("ascii-8bit") << 0xC3 << 0xB6 a = "".force_encoding("ascii-8bit") << 0xC3 << 0xB6
assert_equal(1, a.force_encoding("utf-8").size, '[ruby-core:22437]') assert_equal(1, a.force_encoding("utf-8").size, '[ruby-core:22437]')

View file

@ -124,7 +124,7 @@ class TestM17NComb < Test::Unit::TestCase
elsif !s2.ascii_only? elsif !s2.ascii_only?
assert_equal(s2.encoding, t.encoding) assert_equal(s2.encoding, t.encoding)
else else
assert([s1.encoding, s2.encoding].include?(t.encoding)) assert_include([s1.encoding, s2.encoding], t.encoding)
end end
end end
@ -211,7 +211,7 @@ class TestM17NComb < Test::Unit::TestCase
assert_raise(Encoding::CompatibilityError) { s1 + s2 } assert_raise(Encoding::CompatibilityError) { s1 + s2 }
else else
t = enccall(s1, :+, s2) t = enccall(s1, :+, s2)
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding? assert_predicate(t, :valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
assert_equal(b(s1) + b(s2), b(t)) assert_equal(b(s1) + b(s2), b(t))
assert_str_enc_propagation(t, s1, s2) assert_str_enc_propagation(t, s1, s2)
end end
@ -222,7 +222,7 @@ class TestM17NComb < Test::Unit::TestCase
STRINGS.each {|s| STRINGS.each {|s|
[0,1,2].each {|n| [0,1,2].each {|n|
t = s * n t = s * n
assert(t.valid_encoding?) if s.valid_encoding? assert_predicate(t, :valid_encoding?) if s.valid_encoding?
assert_strenc(b(s) * n, s.encoding, t) assert_strenc(b(s) * n, s.encoding, t)
} }
} }
@ -240,16 +240,16 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_eq_reflexive def test_str_eq_reflexive
STRINGS.each {|s| STRINGS.each {|s|
assert(s == s, "#{encdump s} == #{encdump s}") assert_equal(s, s, "#{encdump s} == #{encdump s}")
} }
end end
def test_str_eq_symmetric def test_str_eq_symmetric
combination(STRINGS, STRINGS) {|s1, s2| combination(STRINGS, STRINGS) {|s1, s2|
if s1 == s2 if s1 == s2
assert(s2 == s1, "#{encdump s2} == #{encdump s1}") assert_equal(s2, s1, "#{encdump s2} == #{encdump s1}")
else else
assert(!(s2 == s1), "!(#{encdump s2} == #{encdump s1})") assert_not_equal(s2, s1, "!(#{encdump s2} == #{encdump s1})")
end end
} }
end end
@ -257,7 +257,7 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_eq_transitive def test_str_eq_transitive
combination(STRINGS, STRINGS, STRINGS) {|s1, s2, s3| combination(STRINGS, STRINGS, STRINGS) {|s1, s2, s3|
if s1 == s2 && s2 == s3 if s1 == s2 && s2 == s3
assert(s1 == s3, "transitive: #{encdump s1} == #{encdump s2} == #{encdump s3}") assert_equal(s1, s3, "transitive: #{encdump s1} == #{encdump s2} == #{encdump s3}")
end end
} }
end end
@ -268,15 +268,15 @@ class TestM17NComb < Test::Unit::TestCase
if b(s1) == b(s2) and if b(s1) == b(s2) and
(s1.ascii_only? && s2.ascii_only? or (s1.ascii_only? && s2.ascii_only? or
s1.encoding == s2.encoding) then s1.encoding == s2.encoding) then
assert(s1 == s2, desc_eq) assert_operator(s1, :==, s2, desc_eq)
assert(!(s1 != s2)) assert_not_operator(s1, :!=, s2)
assert_equal(0, s1 <=> s2) assert_equal(0, s1 <=> s2)
assert(s1.eql?(s2), desc_eq) assert_operator(s1, :eql?, s2, desc_eq)
else else
assert(!(s1 == s2), "!(#{desc_eq})") assert_not_operator(s1, :==, s2, "!(#{desc_eq})")
assert(s1 != s2) assert_operator(s1, :!=, s2)
assert_not_equal(0, s1 <=> s2) assert_not_equal(0, s1 <=> s2)
assert(!s1.eql?(s2)) assert_not_operator(s1, :eql?, s2)
end end
} }
end end
@ -286,7 +286,7 @@ class TestM17NComb < Test::Unit::TestCase
s = s1.dup s = s1.dup
if s1.ascii_only? || s2.ascii_only? || s1.encoding == s2.encoding if s1.ascii_only? || s2.ascii_only? || s1.encoding == s2.encoding
s << s2 s << s2
assert(s.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding? assert_predicate(s, :valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
assert_equal(b(s), b(s1) + b(s2)) assert_equal(b(s), b(s1) + b(s2))
assert_str_enc_propagation(s, s1, s2) assert_str_enc_propagation(s, s1, s2)
else else
@ -300,7 +300,7 @@ class TestM17NComb < Test::Unit::TestCase
t = ''.force_encoding(s.encoding) t = ''.force_encoding(s.encoding)
0.upto(s.length-1) {|i| 0.upto(s.length-1) {|i|
u = s[i] u = s[i]
assert(u.valid_encoding?) if s.valid_encoding? assert_predicate(u, :valid_encoding?) if s.valid_encoding?
t << u t << u
} }
assert_equal(t, s) assert_equal(t, s)
@ -312,7 +312,7 @@ class TestM17NComb < Test::Unit::TestCase
t = ''.force_encoding(s.encoding) t = ''.force_encoding(s.encoding)
0.upto(s.length-1) {|i| 0.upto(s.length-1) {|i|
u = s[i,1] u = s[i,1]
assert(u.valid_encoding?) if s.valid_encoding? assert_predicate(u, :valid_encoding?) if s.valid_encoding?
t << u t << u
} }
assert_equal(t, s) assert_equal(t, s)
@ -322,7 +322,7 @@ class TestM17NComb < Test::Unit::TestCase
t = ''.force_encoding(s.encoding) t = ''.force_encoding(s.encoding)
0.step(s.length-1, 2) {|i| 0.step(s.length-1, 2) {|i|
u = s[i,2] u = s[i,2]
assert(u.valid_encoding?) if s.valid_encoding? assert_predicate(u, :valid_encoding?) if s.valid_encoding?
t << u t << u
} }
assert_equal(t, s) assert_equal(t, s)
@ -334,7 +334,7 @@ class TestM17NComb < Test::Unit::TestCase
if s1.ascii_only? || s2.ascii_only? || s1.encoding == s2.encoding if s1.ascii_only? || s2.ascii_only? || s1.encoding == s2.encoding
t = enccall(s1, :[], s2) t = enccall(s1, :[], s2)
if t != nil if t != nil
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding? assert_predicate(t, :valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
assert_equal(s2, t) assert_equal(s2, t)
assert_match(/#{Regexp.escape(b(s2))}/, b(s1)) assert_match(/#{Regexp.escape(b(s2))}/, b(s1))
if s1.valid_encoding? if s1.valid_encoding?
@ -362,7 +362,7 @@ class TestM17NComb < Test::Unit::TestCase
assert_nil(t, desc) assert_nil(t, desc)
next next
end end
assert(t.valid_encoding?) if s.valid_encoding? assert_predicate(t, :valid_encoding?) if s.valid_encoding?
if last < 0 if last < 0
last += s.length last += s.length
end end
@ -393,7 +393,7 @@ class TestM17NComb < Test::Unit::TestCase
if last < 0 if last < 0
last += s.length last += s.length
end end
assert(t.valid_encoding?) if s.valid_encoding? assert_predicate(t, :valid_encoding?) if s.valid_encoding?
t2 = '' t2 = ''
first.upto(last-1) {|i| first.upto(last-1) {|i|
c = s[i] c = s[i]
@ -412,8 +412,8 @@ class TestM17NComb < Test::Unit::TestCase
assert_raise(IndexError) { t[i] = s2 } assert_raise(IndexError) { t[i] = s2 }
else else
t[i] = s2 t[i] = s2
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding? assert_predicate(t, :valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
assert(b(t).index(b(s2))) assert_send([b(t), :index, b(s2)])
if s1.valid_encoding? && s2.valid_encoding? if s1.valid_encoding? && s2.valid_encoding?
if i == s1.length && s2.empty? if i == s1.length && s2.empty?
assert_nil(t[i]) assert_nil(t[i])
@ -440,9 +440,9 @@ class TestM17NComb < Test::Unit::TestCase
if i < -s1.length || s1.length < i if i < -s1.length || s1.length < i
assert_raise(IndexError) { t[i,len] = s2 } assert_raise(IndexError) { t[i,len] = s2 }
else else
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding? assert_predicate(t, :valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
t[i,len] = s2 t[i,len] = s2
assert(b(t).index(b(s2))) assert_send([b(t), :index, b(s2)])
if s1.valid_encoding? && s2.valid_encoding? if s1.valid_encoding? && s2.valid_encoding?
if i == s1.length && s2.empty? if i == s1.length && s2.empty?
assert_nil(t[i]) assert_nil(t[i])
@ -486,7 +486,7 @@ class TestM17NComb < Test::Unit::TestCase
if !t[s2] if !t[s2]
else else
enccall(t, :[]=, s2, s3) enccall(t, :[]=, s2, s3)
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding? && s3.valid_encoding? assert_predicate(t, :valid_encoding?) if s1.valid_encoding? && s2.valid_encoding? && s3.valid_encoding?
end end
end end
} }
@ -500,8 +500,8 @@ class TestM17NComb < Test::Unit::TestCase
assert_raise(RangeError) { t[first..last] = s2 } assert_raise(RangeError) { t[first..last] = s2 }
else else
enccall(t, :[]=, first..last, s2) enccall(t, :[]=, first..last, s2)
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding? assert_predicate(t, :valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
assert(b(t).index(b(s2))) assert_send([b(t), :index, b(s2)])
if s1.valid_encoding? && s2.valid_encoding? if s1.valid_encoding? && s2.valid_encoding?
if first < 0 if first < 0
assert_equal(s2, t[s1.length+first, s2.length]) assert_equal(s2, t[s1.length+first, s2.length])
@ -527,8 +527,8 @@ class TestM17NComb < Test::Unit::TestCase
assert_raise(RangeError) { t[first...last] = s2 } assert_raise(RangeError) { t[first...last] = s2 }
else else
enccall(t, :[]=, first...last, s2) enccall(t, :[]=, first...last, s2)
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding? assert_predicate(t, :valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
assert(b(t).index(b(s2))) assert_send([b(t), :index, b(s2)])
if s1.valid_encoding? && s2.valid_encoding? if s1.valid_encoding? && s2.valid_encoding?
if first < 0 if first < 0
assert_equal(s2, t[s1.length+first, s2.length]) assert_equal(s2, t[s1.length+first, s2.length])
@ -563,11 +563,11 @@ class TestM17NComb < Test::Unit::TestCase
begin begin
t1 = s.capitalize t1 = s.capitalize
rescue ArgumentError rescue ArgumentError
assert(!s.valid_encoding?) assert_not_predicate(s, :valid_encoding?)
next next
end end
assert(t1.valid_encoding?) if s.valid_encoding? assert_predicate(t1, :valid_encoding?) if s.valid_encoding?
assert(t1.casecmp(s)) assert_operator(t1, :casecmp, s)
t2 = s.dup t2 = s.dup
t2.capitalize! t2.capitalize!
assert_equal(t1, t2) assert_equal(t1, t2)
@ -589,7 +589,7 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_center def test_str_center
combination(STRINGS, [0,1,2,3,10]) {|s1, width| combination(STRINGS, [0,1,2,3,10]) {|s1, width|
t = s1.center(width) t = s1.center(width)
assert(b(t).index(b(s1))) assert_send([b(t), :index, b(s1)])
} }
combination(STRINGS, [0,1,2,3,10], STRINGS) {|s1, width, s2| combination(STRINGS, [0,1,2,3,10], STRINGS) {|s1, width, s2|
if s2.empty? if s2.empty?
@ -601,8 +601,8 @@ class TestM17NComb < Test::Unit::TestCase
next next
end end
t = enccall(s1, :center, width, s2) t = enccall(s1, :center, width, s2)
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding? assert_predicate(t, :valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
assert(b(t).index(b(s1))) assert_send([b(t), :index, b(s1)])
assert_str_enc_propagation(t, s1, s2) if (t != s1) assert_str_enc_propagation(t, s1, s2) if (t != s1)
} }
end end
@ -610,7 +610,7 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_ljust def test_str_ljust
combination(STRINGS, [0,1,2,3,10]) {|s1, width| combination(STRINGS, [0,1,2,3,10]) {|s1, width|
t = s1.ljust(width) t = s1.ljust(width)
assert(b(t).index(b(s1))) assert_send([b(t), :index, b(s1)])
} }
combination(STRINGS, [0,1,2,3,10], STRINGS) {|s1, width, s2| combination(STRINGS, [0,1,2,3,10], STRINGS) {|s1, width, s2|
if s2.empty? if s2.empty?
@ -622,8 +622,8 @@ class TestM17NComb < Test::Unit::TestCase
next next
end end
t = enccall(s1, :ljust, width, s2) t = enccall(s1, :ljust, width, s2)
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding? assert_predicate(t, :valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
assert(b(t).index(b(s1))) assert_send([b(t), :index, b(s1)])
assert_str_enc_propagation(t, s1, s2) if (t != s1) assert_str_enc_propagation(t, s1, s2) if (t != s1)
} }
end end
@ -631,7 +631,7 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_rjust def test_str_rjust
combination(STRINGS, [0,1,2,3,10]) {|s1, width| combination(STRINGS, [0,1,2,3,10]) {|s1, width|
t = s1.rjust(width) t = s1.rjust(width)
assert(b(t).index(b(s1))) assert_send([b(t), :index, b(s1)])
} }
combination(STRINGS, [0,1,2,3,10], STRINGS) {|s1, width, s2| combination(STRINGS, [0,1,2,3,10], STRINGS) {|s1, width, s2|
if s2.empty? if s2.empty?
@ -643,8 +643,8 @@ class TestM17NComb < Test::Unit::TestCase
next next
end end
t = enccall(s1, :rjust, width, s2) t = enccall(s1, :rjust, width, s2)
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding? assert_predicate(t, :valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
assert(b(t).index(b(s1))) assert_send([b(t), :index, b(s1)])
assert_str_enc_propagation(t, s1, s2) if (t != s1) assert_str_enc_propagation(t, s1, s2) if (t != s1)
} }
end end
@ -658,7 +658,7 @@ class TestM17NComb < Test::Unit::TestCase
next next
end end
t = enccall(s1, :chomp, s2) t = enccall(s1, :chomp, s2)
assert(t.valid_encoding?, "#{encdump(s1)}.chomp(#{encdump(s2)})") if s1.valid_encoding? && s2.valid_encoding? assert_predicate(t, :valid_encoding?, "#{encdump(s1)}.chomp(#{encdump(s2)})") if s1.valid_encoding? && s2.valid_encoding?
assert_equal(s1.encoding, t.encoding) assert_equal(s1.encoding, t.encoding)
t2 = s1.dup t2 = s1.dup
t2.chomp!(s2) t2.chomp!(s2)
@ -672,8 +672,8 @@ class TestM17NComb < Test::Unit::TestCase
desc = "#{encdump s}.chop" desc = "#{encdump s}.chop"
t = nil t = nil
assert_nothing_raised(desc) { t = s.chop } assert_nothing_raised(desc) { t = s.chop }
assert(t.valid_encoding?) if s.valid_encoding? assert_predicate(t, :valid_encoding?) if s.valid_encoding?
assert(b(s).index(b(t))) assert_send([b(s), :index, b(t)])
t2 = s.dup t2 = s.dup
t2.chop! t2.chop!
assert_equal(t, t2) assert_equal(t, t2)
@ -684,8 +684,8 @@ class TestM17NComb < Test::Unit::TestCase
STRINGS.each {|s| STRINGS.each {|s|
t = s.dup t = s.dup
t.clear t.clear
assert(t.valid_encoding?) assert_predicate(t, :valid_encoding?)
assert(t.empty?) assert_empty(t)
} }
end end
@ -761,7 +761,7 @@ class TestM17NComb < Test::Unit::TestCase
next next
end end
t = enccall(s1, :delete, s2) t = enccall(s1, :delete, s2)
assert(t.valid_encoding?) assert_predicate(t, :valid_encoding?)
assert_equal(t.encoding, s1.encoding) assert_equal(t.encoding, s1.encoding)
assert_operator(t.length, :<=, s1.length) assert_operator(t.length, :<=, s1.length)
t2 = s1.dup t2 = s1.dup
@ -777,9 +777,9 @@ class TestM17NComb < Test::Unit::TestCase
next next
end end
t = s.downcase t = s.downcase
assert(t.valid_encoding?) assert_predicate(t, :valid_encoding?)
assert_equal(t.encoding, s.encoding) assert_equal(t.encoding, s.encoding)
assert(t.casecmp(s)) assert_operator(t, :casecmp, s)
t2 = s.dup t2 = s.dup
t2.downcase! t2.downcase!
assert_equal(t, t2) assert_equal(t, t2)
@ -789,8 +789,8 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_dump def test_str_dump
STRINGS.each {|s| STRINGS.each {|s|
t = s.dump t = s.dump
assert(t.valid_encoding?) assert_predicate(t, :valid_encoding?)
assert(t.ascii_only?) assert_predicate(t, :ascii_only?)
u = eval(t) u = eval(t)
assert_equal(b(s), b(u)) assert_equal(b(s), b(u))
} }
@ -829,9 +829,9 @@ class TestM17NComb < Test::Unit::TestCase
def test_str_empty? def test_str_empty?
STRINGS.each {|s| STRINGS.each {|s|
if s.length == 0 if s.length == 0
assert(s.empty?) assert_empty(s)
else else
assert(!s.empty?) assert_not_empty(s)
end end
} }
end end
@ -854,12 +854,12 @@ class TestM17NComb < Test::Unit::TestCase
end end
t = enccall(s1, :include?, s2) t = enccall(s1, :include?, s2)
if t if t
assert(b(s1).include?(b(s2))) assert_include(b(s1), b(s2))
assert(s1.index(s2)) assert_send([s1, :index, s2])
assert(s1.rindex(s2)) assert_send([s1, :rindex, s2])
else else
assert(!s1.index(s2)) assert_not_send([s1, :index, s2])
assert(!s1.rindex(s2), "!#{encdump(s1)}.rindex(#{encdump(s2)})") assert_not_send([s1, :rindex, s2], "!#{encdump(s1)}.rindex(#{encdump(s2)})")
end end
if s2.empty? if s2.empty?
assert_equal(true, t) assert_equal(true, t)
@ -935,7 +935,7 @@ class TestM17NComb < Test::Unit::TestCase
end end
if t if t
#puts "#{encdump s1}.rindex(#{encdump s2}, #{pos}) => #{t}" #puts "#{encdump s1}.rindex(#{encdump s2}, #{pos}) => #{t}"
assert(b(s1).index(b(s2))) assert_send([b(s1), :index, b(s2)])
pos2 = pos pos2 = pos
pos2 += s1.length if pos < 0 pos2 += s1.length if pos < 0
re = /\A(.{0,#{pos2}})#{Regexp.escape(s2)}/m re = /\A(.{0,#{pos2}})#{Regexp.escape(s2)}/m
@ -1093,8 +1093,8 @@ class TestM17NComb < Test::Unit::TestCase
"#{encdump s}.slice!#{encdumpargs args}.encoding") "#{encdump s}.slice!#{encdumpargs args}.encoding")
end end
if [s, *args].all? {|o| !(String === o) || o.valid_encoding? } if [s, *args].all? {|o| !(String === o) || o.valid_encoding? }
assert(r.valid_encoding?) assert_predicate(r, :valid_encoding?)
assert(t.valid_encoding?) assert_predicate(t, :valid_encoding?)
assert_equal(s.length, r.length + t.length) assert_equal(s.length, r.length + t.length)
end end
} }
@ -1116,13 +1116,13 @@ class TestM17NComb < Test::Unit::TestCase
end end
t = enccall(s1, :split, s2) t = enccall(s1, :split, s2)
t.each {|r| t.each {|r|
assert(b(s1).include?(b(r))) assert_include(b(s1), b(r))
assert_equal(s1.encoding, r.encoding) assert_equal(s1.encoding, r.encoding)
} }
assert(b(s1).include?(t.map {|u| b(u) }.join(b(s2)))) assert_include(b(s1), t.map {|u| b(u) }.join(b(s2)))
if s1.valid_encoding? && s2.valid_encoding? if s1.valid_encoding? && s2.valid_encoding?
t.each {|r| t.each {|r|
assert(r.valid_encoding?) assert_predicate(r, :valid_encoding?)
} }
end end
} }
@ -1184,8 +1184,8 @@ class TestM17NComb < Test::Unit::TestCase
next next
end end
t1 = s.swapcase t1 = s.swapcase
assert(t1.valid_encoding?) if s.valid_encoding? assert_predicate(t1, :valid_encoding?) if s.valid_encoding?
assert(t1.casecmp(s)) assert_operator(t1, :casecmp, s)
t2 = s.dup t2 = s.dup
t2.swapcase! t2.swapcase!
assert_equal(t1, t2) assert_equal(t1, t2)
@ -1298,8 +1298,8 @@ class TestM17NComb < Test::Unit::TestCase
next next
end end
t1 = s.upcase t1 = s.upcase
assert(t1.valid_encoding?) assert_predicate(t1, :valid_encoding?)
assert(t1.casecmp(s)) assert_operator(t1, :casecmp, s)
t2 = s.dup t2 = s.dup
t2.upcase! t2.upcase!
assert_equal(t1, t2) assert_equal(t1, t2)
@ -1321,7 +1321,7 @@ class TestM17NComb < Test::Unit::TestCase
#puts encdump(s) #puts encdump(s)
t = s.succ t = s.succ
if s.valid_encoding? if s.valid_encoding?
assert(t.valid_encoding?, "#{encdump s}.succ.valid_encoding?") assert_predicate(t, :valid_encoding?, "#{encdump s}.succ.valid_encoding?")
end end
s = t s = t
} }

View file

@ -484,10 +484,10 @@ class TestMarshal < Test::Unit::TestCase
def test_marshal_load_should_not_taint_classes def test_marshal_load_should_not_taint_classes
bug7325 = '[ruby-core:49198]' bug7325 = '[ruby-core:49198]'
for c in [TestClass, TestModule] for c in [TestClass, TestModule]
assert(!c.tainted?) assert_not_predicate(c, :tainted?)
c2 = Marshal.load(Marshal.dump(c).taint) c2 = Marshal.load(Marshal.dump(c).taint)
assert_same(c, c2) assert_same(c, c2)
assert(!c.tainted?, bug7325) assert_not_predicate(c, :tainted?, bug7325)
end end
end end

View file

@ -3,12 +3,12 @@ require 'test/unit'
class TestMath < Test::Unit::TestCase class TestMath < Test::Unit::TestCase
def assert_infinity(a, *rest) def assert_infinity(a, *rest)
rest = ["not infinity: #{a.inspect}"] if rest.empty? rest = ["not infinity: #{a.inspect}"] if rest.empty?
assert(!a.finite?, *rest) assert_not_predicate(a, :finite?, *rest)
end end
def assert_nan(a, *rest) def assert_nan(a, *rest)
rest = ["not nan: #{a.inspect}"] if rest.empty? rest = ["not nan: #{a.inspect}"] if rest.empty?
assert(a.nan?, *rest) assert_predicate(a, :nan?, *rest)
end end
def check(a, b) def check(a, b)
@ -49,9 +49,9 @@ class TestMath < Test::Unit::TestCase
def test_tan def test_tan
check(0.0, Math.tan(0 * Math::PI / 4)) check(0.0, Math.tan(0 * Math::PI / 4))
check(1.0, Math.tan(1 * Math::PI / 4)) check(1.0, Math.tan(1 * Math::PI / 4))
assert(Math.tan(2 * Math::PI / 4).abs > 1024) assert_operator(Math.tan(2 * Math::PI / 4).abs, :>, 1024)
check(0.0, Math.tan(4 * Math::PI / 4)) check(0.0, Math.tan(4 * Math::PI / 4))
assert(Math.tan(6 * Math::PI / 4).abs > 1024) assert_operator(Math.tan(6 * Math::PI / 4).abs, :>, 1024)
end end
def test_acos def test_acos

View file

@ -391,14 +391,16 @@ class TestMethod < Test::Unit::TestCase
end end
def test_default_accessibility def test_default_accessibility
assert T.public_instance_methods.include?(:normal_method), 'normal methods are public by default' tmethods = T.public_instance_methods
assert !T.public_instance_methods.include?(:initialize), '#initialize is private' assert_include tmethods, :normal_method, 'normal methods are public by default'
assert !T.public_instance_methods.include?(:initialize_copy), '#initialize_copy is private' assert_not_include tmethods, :initialize, '#initialize is private'
assert !T.public_instance_methods.include?(:initialize_clone), '#initialize_clone is private' assert_not_include tmethods, :initialize_copy, '#initialize_copy is private'
assert !T.public_instance_methods.include?(:initialize_dup), '#initialize_dup is private' assert_not_include tmethods, :initialize_clone, '#initialize_clone is private'
assert !T.public_instance_methods.include?(:respond_to_missing?), '#respond_to_missing? is private' assert_not_include tmethods, :initialize_dup, '#initialize_dup is private'
assert !M.public_instance_methods.include?(:func), 'module methods are private by default' assert_not_include tmethods, :respond_to_missing?, '#respond_to_missing? is private'
assert M.public_instance_methods.include?(:meth), 'normal methods are public by default' mmethods = M.public_instance_methods
assert_not_include mmethods, :func, 'module methods are private by default'
assert_include mmethods, :meth, 'normal methods are public by default'
end end
define_method(:pm0) {||} define_method(:pm0) {||}
@ -579,7 +581,7 @@ class TestMethod < Test::Unit::TestCase
end end
assert_equal(c, x.method(:foo).owner) assert_equal(c, x.method(:foo).owner)
assert_equal(x.singleton_class, x.method(:bar).owner) assert_equal(x.singleton_class, x.method(:bar).owner)
assert(x.method(:foo) != x.method(:bar), bug7613) assert_not_equal(x.method(:foo), x.method(:bar), bug7613)
end end
def test_included def test_included

View file

@ -151,50 +151,50 @@ class TestModule < Test::Unit::TestCase
end end
def test_GE # '>=' def test_GE # '>='
assert(Mixin >= User) assert_operator(Mixin, :>=, User)
assert(Mixin >= Mixin) assert_operator(Mixin, :>=, Mixin)
assert(!(User >= Mixin)) assert_not_operator(User, :>=, Mixin)
assert(Object >= String) assert_operator(Object, :>=, String)
assert(String >= String) assert_operator(String, :>=, String)
assert(!(String >= Object)) assert_not_operator(String, :>=, Object)
end end
def test_GT # '>' def test_GT # '>'
assert(Mixin > User) assert_operator(Mixin, :>, User)
assert(!(Mixin > Mixin)) assert_not_operator(Mixin, :>, Mixin)
assert(!(User > Mixin)) assert_not_operator(User, :>, Mixin)
assert(Object > String) assert_operator(Object, :>, String)
assert(!(String > String)) assert_not_operator(String, :>, String)
assert(!(String > Object)) assert_not_operator(String, :>, Object)
end end
def test_LE # '<=' def test_LE # '<='
assert(User <= Mixin) assert_operator(User, :<=, Mixin)
assert(Mixin <= Mixin) assert_operator(Mixin, :<=, Mixin)
assert(!(Mixin <= User)) assert_not_operator(Mixin, :<=, User)
assert(String <= Object) assert_operator(String, :<=, Object)
assert(String <= String) assert_operator(String, :<=, String)
assert(!(Object <= String)) assert_not_operator(Object, :<=, String)
end end
def test_LT # '<' def test_LT # '<'
assert(User < Mixin) assert_operator(User, :<, Mixin)
assert(!(Mixin < Mixin)) assert_not_operator(Mixin, :<, Mixin)
assert(!(Mixin < User)) assert_not_operator(Mixin, :<, User)
assert(String < Object) assert_operator(String, :<, Object)
assert(!(String < String)) assert_not_operator(String, :<, String)
assert(!(Object < String)) assert_not_operator(Object, :<, String)
end end
def test_VERY_EQUAL # '===' def test_VERY_EQUAL # '==='
assert(Object === self) assert_operator(Object, :===, self)
assert(Test::Unit::TestCase === self) assert_operator(Test::Unit::TestCase, :===, self)
assert(TestModule === self) assert_operator(TestModule, :===, self)
assert(!(String === self)) assert_not_operator(String, :===, self)
end end
def test_ancestors def test_ancestors
@ -214,7 +214,7 @@ class TestModule < Test::Unit::TestCase
def test_class_eval def test_class_eval
Other.class_eval("CLASS_EVAL = 1") Other.class_eval("CLASS_EVAL = 1")
assert_equal(1, Other::CLASS_EVAL) assert_equal(1, Other::CLASS_EVAL)
assert(Other.constants.include?(:CLASS_EVAL)) assert_include(Other.constants, :CLASS_EVAL)
assert_equal(2, Other.class_eval { CLASS_EVAL }) assert_equal(2, Other.class_eval { CLASS_EVAL })
Other.class_eval("@@class_eval = 'a'") Other.class_eval("@@class_eval = 'a'")
@ -234,10 +234,10 @@ class TestModule < Test::Unit::TestCase
end end
def test_const_defined? def test_const_defined?
assert(Math.const_defined?(:PI)) assert_operator(Math, :const_defined?, :PI)
assert(Math.const_defined?("PI")) assert_operator(Math, :const_defined?, "PI")
assert(!Math.const_defined?(:IP)) assert_not_operator(Math, :const_defined?, :IP)
assert(!Math.const_defined?("IP")) assert_not_operator(Math, :const_defined?, "IP")
end end
def test_bad_constants def test_bad_constants
@ -304,9 +304,9 @@ class TestModule < Test::Unit::TestCase
end end
def test_const_set def test_const_set
assert(!Other.const_defined?(:KOALA)) assert_not_operator(Other, :const_defined?, :KOALA)
Other.const_set(:KOALA, 99) Other.const_set(:KOALA, 99)
assert(Other.const_defined?(:KOALA)) assert_operator(Other, :const_defined?, :KOALA)
assert_equal(99, Other::KOALA) assert_equal(99, Other::KOALA)
Other.const_set("WOMBAT", "Hi") Other.const_set("WOMBAT", "Hi")
assert_equal("Hi", Other::WOMBAT) assert_equal("Hi", Other::WOMBAT)
@ -315,7 +315,7 @@ class TestModule < Test::Unit::TestCase
def n.to_str; @count = defined?(@count) ? @count + 1 : 1; "HOGE"; end def n.to_str; @count = defined?(@count) ? @count + 1 : 1; "HOGE"; end
def n.count; @count; end def n.count; @count; end
def n.count=(v); @count=v; end def n.count=(v); @count=v; end
assert(!Other.const_defined?(:HOGE)) assert_not_operator(Other, :const_defined?, :HOGE)
Other.const_set(n, 999) Other.const_set(n, 999)
assert_equal(1, n.count) assert_equal(1, n.count)
n.count = 0 n.count = 0
@ -350,7 +350,7 @@ class TestModule < Test::Unit::TestCase
b = a.dup b = a.dup
refute_equal original, b.inspect, bug6454 assert_not_equal original, b.inspect, bug6454
end end
def test_public_include def test_public_include
@ -437,9 +437,9 @@ class TestModule < Test::Unit::TestCase
def test_module_eval def test_module_eval
User.module_eval("MODULE_EVAL = 1") User.module_eval("MODULE_EVAL = 1")
assert_equal(1, User::MODULE_EVAL) assert_equal(1, User::MODULE_EVAL)
assert(User.constants.include?(:MODULE_EVAL)) assert_include(User.constants, :MODULE_EVAL)
User.instance_eval("remove_const(:MODULE_EVAL)") User.instance_eval("remove_const(:MODULE_EVAL)")
assert(!User.constants.include?(:MODULE_EVAL)) assert_not_include(User.constants, :MODULE_EVAL)
end end
def test_name def test_name
@ -1264,7 +1264,7 @@ class TestModule < Test::Unit::TestCase
end end
def test_constants_with_private_constant def test_constants_with_private_constant
assert(!(::TestModule).constants.include?(:PrivateClass)) assert_not_include(::TestModule.constants, :PrivateClass)
end end
def test_toplevel_private_constant def test_toplevel_private_constant

View file

@ -32,7 +32,7 @@ class TestNumeric < Test::Unit::TestCase
end end
assert_equal(2, 1 + a) assert_equal(2, 1 + a)
assert_equal(0, 1 <=> a) assert_equal(0, 1 <=> a)
assert(1 <= a) assert_operator(1, :<=, a)
DummyNumeric.class_eval do DummyNumeric.class_eval do
remove_method :coerce remove_method :coerce
@ -93,11 +93,11 @@ class TestNumeric < Test::Unit::TestCase
end end
def test_real_p def test_real_p
assert(Numeric.new.real?) assert_predicate(Numeric.new, :real?)
end end
def test_integer_p def test_integer_p
assert(!Numeric.new.integer?) assert_not_predicate(Numeric.new, :integer?)
end end
def test_abs def test_abs
@ -127,7 +127,7 @@ class TestNumeric < Test::Unit::TestCase
def ==(x); true; end def ==(x); true; end
end end
assert(DummyNumeric.new.zero?) assert_predicate(DummyNumeric.new, :zero?)
ensure ensure
DummyNumeric.class_eval do DummyNumeric.class_eval do
@ -274,8 +274,8 @@ class TestNumeric < Test::Unit::TestCase
end end
def test_eql def test_eql
assert(1 == 1.0) assert_equal(1, 1.0)
assert(!(1.eql?(1.0))) assert_not_operator(1, :eql?, 1.0)
assert(!(1.eql?(2))) assert_not_operator(1, :eql?, 2)
end end
end end

View file

@ -411,8 +411,8 @@ class TestObject < Test::Unit::TestCase
assert_equal([:foo], foo.foobar); assert_equal([:foo], foo.foobar);
assert_equal([:foo, 1], foo.foobar(1)); assert_equal([:foo, 1], foo.foobar(1));
assert_equal([:foo, 1, 2, 3, 4, 5], foo.foobar(1, 2, 3, 4, 5)); assert_equal([:foo, 1, 2, 3, 4, 5], foo.foobar(1, 2, 3, 4, 5));
assert(foo.respond_to?(:foobar)) assert_respond_to(foo, :foobar)
assert_equal(false, foo.respond_to?(:foobarbaz)) assert_not_respond_to(foo, :foobarbaz)
assert_raise(NoMethodError) do assert_raise(NoMethodError) do
foo.foobarbaz foo.foobarbaz
end end

View file

@ -39,13 +39,13 @@ End
h = {} h = {}
ObjectSpace.count_objects(h) ObjectSpace.count_objects(h)
assert_kind_of(Hash, h) assert_kind_of(Hash, h)
assert(h.keys.all? {|x| x.is_a?(Symbol) || x.is_a?(Integer) }) assert_empty(h.keys.delete_if {|x| x.is_a?(Symbol) || x.is_a?(Integer) })
assert(h.values.all? {|x| x.is_a?(Integer) }) assert_empty(h.values.delete_if {|x| x.is_a?(Integer) })
h = ObjectSpace.count_objects h = ObjectSpace.count_objects
assert_kind_of(Hash, h) assert_kind_of(Hash, h)
assert(h.keys.all? {|x| x.is_a?(Symbol) || x.is_a?(Integer) }) assert_empty(h.keys.delete_if {|x| x.is_a?(Symbol) || x.is_a?(Integer) })
assert(h.values.all? {|x| x.is_a?(Integer) }) assert_empty(h.values.delete_if {|x| x.is_a?(Integer) })
assert_raise(TypeError) { ObjectSpace.count_objects(1) } assert_raise(TypeError) { ObjectSpace.count_objects(1) }

View file

@ -826,7 +826,7 @@ x = __ENCODING__
def test_all_symbols def test_all_symbols
x = Symbol.all_symbols x = Symbol.all_symbols
assert_kind_of(Array, x) assert_kind_of(Array, x)
assert(x.all? {|s| s.is_a?(Symbol) }) assert_empty(x.reject {|s| s.is_a?(Symbol) })
end end
def test_is_class_id def test_is_class_id

View file

@ -415,9 +415,9 @@ class TestRubyPrimitive < Test::Unit::TestCase
end end
x.to_a_called = false x.to_a_called = false
[0, *x] [0, *x]
assert(x.to_a_called, bug3658) assert_predicate(x, :to_a_called, bug3658)
x.to_a_called = false x.to_a_called = false
[0, *x, 2] [0, *x, 2]
assert(x.to_a_called, bug3658) assert_predicate(x, :to_a_called, bug3658)
end end
end end

View file

@ -1112,7 +1112,7 @@ class TestProc < Test::Unit::TestCase
assert_match(/^#<Proc:0x\h+ \(lambda\)>$/, method(:p).to_proc.to_s) assert_match(/^#<Proc:0x\h+ \(lambda\)>$/, method(:p).to_proc.to_s)
x = proc {} x = proc {}
x.taint x.taint
assert(x.to_s.tainted?) assert_predicate(x.to_s, :tainted?)
end end
@@line_of_source_location_test = __LINE__ + 1 @@line_of_source_location_test = __LINE__ + 1

View file

@ -473,7 +473,7 @@ class TestProcess < Test::Unit::TestCase
# problem occur with valgrind # problem occur with valgrind
#Process.wait Process.spawn(*ECHO["a"], STDOUT=>:close, STDERR=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644]) #Process.wait Process.spawn(*ECHO["a"], STDOUT=>:close, STDERR=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644])
#p File.read("out") #p File.read("out")
#assert(!File.read("out").empty?) # error message such as "-e:1:in `flush': Bad file descriptor (Errno::EBADF)" #assert_not_empty(File.read("out")) # error message such as "-e:1:in `flush': Bad file descriptor (Errno::EBADF)"
Process.wait Process.spawn(*ECHO["c"], STDERR=>STDOUT, STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644]) Process.wait Process.spawn(*ECHO["c"], STDERR=>STDOUT, STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644])
assert_equal("c", File.read("out").chomp) assert_equal("c", File.read("out").chomp)
File.open("out", "w") {|f| File.open("out", "w") {|f|
@ -885,7 +885,7 @@ class TestProcess < Test::Unit::TestCase
ret = system(str) ret = system(str)
status = $? status = $?
assert_equal(false, ret) assert_equal(false, ret)
assert(status.exited?) assert_predicate(status, :exited?)
assert_equal(5, status.exitstatus) assert_equal(5, status.exitstatus)
assert_equal("haha pid=#{status.pid} ppid=#{$$}", File.read("result")) assert_equal("haha pid=#{status.pid} ppid=#{$$}", File.read("result"))
} }
@ -902,7 +902,7 @@ class TestProcess < Test::Unit::TestCase
Process.wait pid Process.wait pid
status = $? status = $?
assert_equal(pid, status.pid) assert_equal(pid, status.pid)
assert(status.exited?) assert_predicate(status, :exited?)
assert_equal(6, status.exitstatus) assert_equal(6, status.exitstatus)
assert_equal("hihi pid=#{status.pid} ppid=#{$$}", File.read("result")) assert_equal("hihi pid=#{status.pid} ppid=#{$$}", File.read("result"))
} }
@ -921,7 +921,7 @@ class TestProcess < Test::Unit::TestCase
io.close io.close
status = $? status = $?
assert_equal(pid, status.pid) assert_equal(pid, status.pid)
assert(status.exited?) assert_predicate(status, :exited?)
assert_equal(7, status.exitstatus) assert_equal(7, status.exitstatus)
assert_equal("fufu pid=#{status.pid} ppid=#{$$}", result) assert_equal("fufu pid=#{status.pid} ppid=#{$$}", result)
} }
@ -940,7 +940,7 @@ class TestProcess < Test::Unit::TestCase
io.close io.close
status = $? status = $?
assert_equal(pid, status.pid) assert_equal(pid, status.pid)
assert(status.exited?) assert_predicate(status, :exited?)
assert_equal(7, status.exitstatus) assert_equal(7, status.exitstatus)
assert_equal("fufumm pid=#{status.pid} ppid=#{$$}", result) assert_equal("fufumm pid=#{status.pid} ppid=#{$$}", result)
} }
@ -966,7 +966,7 @@ class TestProcess < Test::Unit::TestCase
Process.wait pid Process.wait pid
status = $? status = $?
assert_equal(pid, status.pid) assert_equal(pid, status.pid)
assert(status.exited?) assert_predicate(status, :exited?)
assert_equal(6, status.exitstatus) assert_equal(6, status.exitstatus)
if windows? if windows?
expected = "hehe ppid=#{status.pid}" expected = "hehe ppid=#{status.pid}"
@ -990,7 +990,7 @@ class TestProcess < Test::Unit::TestCase
ret = system("#{RUBY} script1 || #{RUBY} script2") ret = system("#{RUBY} script1 || #{RUBY} script2")
status = $? status = $?
assert_equal(false, ret) assert_equal(false, ret)
assert(status.exited?) assert_predicate(status, :exited?)
result1 = File.read("result1") result1 = File.read("result1")
result2 = File.read("result2") result2 = File.read("result2")
assert_match(/\Ataka pid=\d+ ppid=\d+\z/, result1) assert_match(/\Ataka pid=\d+ ppid=\d+\z/, result1)
@ -1021,8 +1021,8 @@ class TestProcess < Test::Unit::TestCase
pid = spawn("#{RUBY} script1 || #{RUBY} script2") pid = spawn("#{RUBY} script1 || #{RUBY} script2")
Process.wait pid Process.wait pid
status = $? status = $?
assert(status.exited?) assert_predicate(status, :exited?)
assert(!status.success?) assert_not_predicate(status, :success?)
result1 = File.read("result1") result1 = File.read("result1")
result2 = File.read("result2") result2 = File.read("result2")
assert_match(/\Ataku pid=\d+ ppid=\d+\z/, result1) assert_match(/\Ataku pid=\d+ ppid=\d+\z/, result1)
@ -1035,14 +1035,14 @@ class TestProcess < Test::Unit::TestCase
pid = spawn(bat, "foo 'bar'") pid = spawn(bat, "foo 'bar'")
Process.wait pid Process.wait pid
status = $? status = $?
assert(status.exited?) assert_predicate(status, :exited?)
assert(status.success?) assert_predicate(status, :success?)
assert_equal(%["foo 'bar'"\n], File.read("out"), '[ruby-core:22960]') assert_equal(%["foo 'bar'"\n], File.read("out"), '[ruby-core:22960]')
pid = spawn(%[#{bat.dump} "foo 'bar'"]) pid = spawn(%[#{bat.dump} "foo 'bar'"])
Process.wait pid Process.wait pid
status = $? status = $?
assert(status.exited?) assert_predicate(status, :exited?)
assert(status.success?) assert_predicate(status, :success?)
assert_equal(%["foo 'bar'"\n], File.read("out"), '[ruby-core:22960]') assert_equal(%["foo 'bar'"\n], File.read("out"), '[ruby-core:22960]')
end end
} }
@ -1062,8 +1062,8 @@ class TestProcess < Test::Unit::TestCase
result = io.read result = io.read
io.close io.close
status = $? status = $?
assert(status.exited?) assert_predicate(status, :exited?)
assert(!status.success?) assert_not_predicate(status, :success?)
assert_match(/\Atako pid=\d+ ppid=\d+\ntika pid=\d+ ppid=\d+\n\z/, result) assert_match(/\Atako pid=\d+ ppid=\d+\ntika pid=\d+ ppid=\d+\n\z/, result)
assert_not_equal(result[/\d+/].to_i, status.pid) assert_not_equal(result[/\d+/].to_i, status.pid)
@ -1095,8 +1095,8 @@ class TestProcess < Test::Unit::TestCase
pid = spawn RUBY, "s" pid = spawn RUBY, "s"
Process.wait pid Process.wait pid
status = $? status = $?
assert(status.exited?) assert_predicate(status, :exited?)
assert(!status.success?) assert_not_predicate(status, :success?)
result1 = File.read("result1") result1 = File.read("result1")
result2 = File.read("result2") result2 = File.read("result2")
assert_match(/\Atiki pid=\d+ ppid=\d+\z/, result1) assert_match(/\Atiki pid=\d+ ppid=\d+\z/, result1)
@ -1150,19 +1150,19 @@ class TestProcess < Test::Unit::TestCase
with_stdin("f") { assert_equal(false, system([RUBY, "wsx"])) } with_stdin("f") { assert_equal(false, system([RUBY, "wsx"])) }
with_stdin("t") { Process.wait spawn([RUBY, "edc"]) } with_stdin("t") { Process.wait spawn([RUBY, "edc"]) }
assert($?.success?) assert_predicate($?, :success?)
with_stdin("f") { Process.wait spawn([RUBY, "rfv"]) } with_stdin("f") { Process.wait spawn([RUBY, "rfv"]) }
assert(!$?.success?) assert_not_predicate($?, :success?)
with_stdin("t") { IO.popen([[RUBY, "tgb"]]) {|io| assert_equal("", io.read) } } with_stdin("t") { IO.popen([[RUBY, "tgb"]]) {|io| assert_equal("", io.read) } }
assert($?.success?) assert_predicate($?, :success?)
with_stdin("f") { IO.popen([[RUBY, "yhn"]]) {|io| assert_equal("", io.read) } } with_stdin("f") { IO.popen([[RUBY, "yhn"]]) {|io| assert_equal("", io.read) } }
assert(!$?.success?) assert_not_predicate($?, :success?)
status = run_in_child "STDIN.reopen('t'); exec([#{RUBY.dump}, 'ujm'])" status = run_in_child "STDIN.reopen('t'); exec([#{RUBY.dump}, 'ujm'])"
assert(status.success?) assert_predicate(status, :success?)
status = run_in_child "STDIN.reopen('f'); exec([#{RUBY.dump}, 'ik,'])" status = run_in_child "STDIN.reopen('f'); exec([#{RUBY.dump}, 'ik,'])"
assert(!status.success?) assert_not_predicate(status, :success?)
} }
end end
@ -1306,22 +1306,22 @@ class TestProcess < Test::Unit::TestCase
def test_uid_re_exchangeable_p def test_uid_re_exchangeable_p
r = Process::UID.re_exchangeable? r = Process::UID.re_exchangeable?
assert(true == r || false == r) assert_include([true, false], r)
end end
def test_gid_re_exchangeable_p def test_gid_re_exchangeable_p
r = Process::GID.re_exchangeable? r = Process::GID.re_exchangeable?
assert(true == r || false == r) assert_include([true, false], r)
end end
def test_uid_sid_available? def test_uid_sid_available?
r = Process::UID.sid_available? r = Process::UID.sid_available?
assert(true == r || false == r) assert_include([true, false], r)
end end
def test_gid_sid_available? def test_gid_sid_available?
r = Process::GID.sid_available? r = Process::GID.sid_available?
assert(true == r || false == r) assert_include([true, false], r)
end end
def test_pst_inspect def test_pst_inspect
@ -1360,7 +1360,7 @@ class TestProcess < Test::Unit::TestCase
system({"RUBYLIB"=>nil}, RUBY, "--disable-gems", "-e", "exit true") system({"RUBYLIB"=>nil}, RUBY, "--disable-gems", "-e", "exit true")
status = $? status = $?
} }
assert(status.success?, "[ruby-dev:38105]") assert_predicate(status, :success?, "[ruby-dev:38105]")
} }
end end
@ -1514,7 +1514,7 @@ class TestProcess < Test::Unit::TestCase
def test_popen_cloexec def test_popen_cloexec
return unless defined? Fcntl::FD_CLOEXEC return unless defined? Fcntl::FD_CLOEXEC
IO.popen([RUBY, "-e", ""]) {|io| IO.popen([RUBY, "-e", ""]) {|io|
assert(io.close_on_exec?) assert_predicate(io, :close_on_exec?)
} }
end end

View file

@ -405,14 +405,14 @@ END
def test_random_equal def test_random_equal
r = Random.new(0) r = Random.new(0)
assert(r == r) assert_equal(r, r)
assert(r == r.dup) assert_equal(r, r.dup)
r1 = r.dup r1 = r.dup
r2 = r.dup r2 = r.dup
r1.rand(0x100) r1.rand(0x100)
assert(r1 != r2) assert_not_equal(r1, r2)
r2.rand(0x100) r2.rand(0x100)
assert(r1 == r2) assert_equal(r1, r2)
end end
def test_fork_shuffle def test_fork_shuffle
@ -421,7 +421,7 @@ END
raise 'default seed is not set' if srand == 0 raise 'default seed is not set' if srand == 0
end end
p2, st = Process.waitpid2(pid) p2, st = Process.waitpid2(pid)
assert(st.success?, "#{st.inspect}") assert_predicate(st, :success?, "#{st.inspect}")
rescue NotImplementedError, ArgumentError rescue NotImplementedError, ArgumentError
end end

View file

@ -97,36 +97,36 @@ class TestRange < Test::Unit::TestCase
end end
def test_exclude_end def test_exclude_end
assert(!((0..1).exclude_end?)) assert_not_predicate(0..1, :exclude_end?)
assert((0...1).exclude_end?) assert_predicate(0...1, :exclude_end?)
end end
def test_eq def test_eq
r = (0..1) r = (0..1)
assert(r == r) assert_equal(r, r)
assert(r == (0..1)) assert_equal(r, (0..1))
assert(r != 0) assert_not_equal(r, 0)
assert(r != (1..2)) assert_not_equal(r, (1..2))
assert(r != (0..2)) assert_not_equal(r, (0..2))
assert(r != (0...1)) assert_not_equal(r, (0...1))
subclass = Class.new(Range) subclass = Class.new(Range)
assert(r == subclass.new(0,1)) assert_equal(r, subclass.new(0,1))
end end
def test_eql def test_eql
r = (0..1) r = (0..1)
assert(r.eql?(r)) assert_operator(r, :eql?, r)
assert(r.eql?(0..1)) assert_operator(r, :eql?, 0..1)
assert(!r.eql?(0)) assert_not_operator(r, :eql?, 0)
assert(!r.eql?(1..2)) assert_not_operator(r, :eql?, 1..2)
assert(!r.eql?(0..2)) assert_not_operator(r, :eql?, 0..2)
assert(!r.eql?(0...1)) assert_not_operator(r, :eql?, 0...1)
subclass = Class.new(Range) subclass = Class.new(Range)
assert(r.eql?(subclass.new(0,1))) assert_operator(r, :eql?, subclass.new(0,1))
end end
def test_hash def test_hash
assert((0..1).hash.is_a?(Fixnum)) assert_kind_of(Fixnum, (0..1).hash)
end end
def test_step def test_step
@ -274,25 +274,25 @@ class TestRange < Test::Unit::TestCase
end end
def test_eqq def test_eqq
assert((0..10) === 5) assert_operator(0..10, :===, 5)
assert(!((0..10) === 11)) assert_not_operator(0..10, :===, 11)
end end
def test_include def test_include
assert(("a".."z").include?("c")) assert_include("a".."z", "c")
assert(!(("a".."z").include?("5"))) assert_not_include("a".."z", "5")
assert(("a"..."z").include?("y")) assert_include("a"..."z", "y")
assert(!(("a"..."z").include?("z"))) assert_not_include("a"..."z", "z")
assert(!(("a".."z").include?("cc"))) assert_not_include("a".."z", "cc")
assert((0...10).include?(5)) assert_include(0...10, 5)
end end
def test_cover def test_cover
assert(("a".."z").cover?("c")) assert_operator("a".."z", :cover?, "c")
assert(!(("a".."z").cover?("5"))) assert_not_operator("a".."z", :cover?, "5")
assert(("a"..."z").cover?("y")) assert_operator("a"..."z", :cover?, "y")
assert(!(("a"..."z").cover?("z"))) assert_not_operator("a"..."z", :cover?, "z")
assert(("a".."z").cover?("cc")) assert_operator("a".."z", :cover?, "cc")
end end
def test_beg_len def test_beg_len
@ -332,14 +332,14 @@ class TestRange < Test::Unit::TestCase
x = CyclicRange.allocate; x.send(:initialize, x, 1) x = CyclicRange.allocate; x.send(:initialize, x, 1)
y = CyclicRange.allocate; y.send(:initialize, y, 1) y = CyclicRange.allocate; y.send(:initialize, y, 1)
Timeout.timeout(1) { Timeout.timeout(1) {
assert x == y assert_equal x, y
assert x.eql? y assert_operator x, :eql?, y
} }
z = CyclicRange.allocate; z.send(:initialize, z, :another) z = CyclicRange.allocate; z.send(:initialize, z, :another)
Timeout.timeout(1) { Timeout.timeout(1) {
assert x != z assert_not_equal x, z
assert !x.eql?(z) assert_not_operator x, :eql?, z
} }
x = CyclicRange.allocate x = CyclicRange.allocate
@ -347,8 +347,8 @@ class TestRange < Test::Unit::TestCase
x.send(:initialize, y, 1) x.send(:initialize, y, 1)
y.send(:initialize, x, 1) y.send(:initialize, x, 1)
Timeout.timeout(1) { Timeout.timeout(1) {
assert x == y assert_equal x, y
assert x.eql?(y) assert_operator x, :eql?, y
} }
x = CyclicRange.allocate x = CyclicRange.allocate
@ -356,8 +356,8 @@ class TestRange < Test::Unit::TestCase
x.send(:initialize, z, 1) x.send(:initialize, z, 1)
z.send(:initialize, x, :other) z.send(:initialize, x, :other)
Timeout.timeout(1) { Timeout.timeout(1) {
assert x != z assert_not_equal x, z
assert !x.eql?(z) assert_not_operator x, :eql?, z
} }
end end
@ -484,7 +484,7 @@ class TestRange < Test::Unit::TestCase
when Float then 65 when Float then 65
when Integer then Math.log(to-from+(range.exclude_end? ? 0 : 1), 2).to_i + 1 when Integer then Math.log(to-from+(range.exclude_end? ? 0 : 1), 2).to_i + 1
end end
assert yielded.size <= max assert_operator yielded.size, :<=, max
# (2) coverage test # (2) coverage test
expect = if search < from expect = if search < from
@ -502,22 +502,23 @@ class TestRange < Test::Unit::TestCase
# (4) end of range test # (4) end of range test
case case
when range.exclude_end? when range.exclude_end?
assert !yielded.include?(to) assert_not_include yielded, to
assert r != to assert_not_equal r, to
when search >= to when search >= to
assert yielded.include?(to) assert_include yielded, to
assert_equal search == to ? to : nil, r assert_equal search == to ? to : nil, r
end end
# start of range test # start of range test
if search <= from if search <= from
assert yielded.include?(from) assert_include yielded, from
assert_equal from, r assert_equal from, r
end end
# (5) out of range test # (5) out of range test
yielded.each do |val| yielded.each do |val|
assert from <= val && val.send(cmp, to) assert_operator from, :<=, val
assert_send [val, cmp, to]
end end
end end

View file

@ -299,7 +299,7 @@ class Rational_Test < Test::Unit::TestCase
assert_raise(ZeroDivisionError){Rational(1, 3) / Rational(0)} assert_raise(ZeroDivisionError){Rational(1, 3) / Rational(0)}
assert_equal(0, Rational(1, 3) / Float::INFINITY) assert_equal(0, Rational(1, 3) / Float::INFINITY)
assert((Rational(1, 3) / 0.0).infinite?, '[ruby-core:31626]') assert_predicate(Rational(1, 3) / 0.0, :infinite?, '[ruby-core:31626]')
end end
def assert_eql(exp, act, *args) def assert_eql(exp, act, *args)
@ -550,7 +550,7 @@ class Rational_Test < Test::Unit::TestCase
assert_equal(0.25, c.fdiv(2)) assert_equal(0.25, c.fdiv(2))
assert_equal(0.25, c.fdiv(2.0)) assert_equal(0.25, c.fdiv(2.0))
assert_equal(0, c.fdiv(Float::INFINITY)) assert_equal(0, c.fdiv(Float::INFINITY))
assert(c.fdiv(0).infinite?, '[ruby-core:31626]') assert_predicate(c.fdiv(0), :infinite?, '[ruby-core:31626]')
end end
def test_expt def test_expt
@ -708,8 +708,8 @@ class Rational_Test < Test::Unit::TestCase
end end
def test_eqeq def test_eqeq
assert(Rational(1,1) == Rational(1)) assert_equal(Rational(1,1), Rational(1))
assert(Rational(-1,1) == Rational(-1)) assert_equal(Rational(-1,1), Rational(-1))
assert_equal(false, Rational(2,1) == Rational(1)) assert_equal(false, Rational(2,1) == Rational(1))
assert_equal(true, Rational(2,1) != Rational(1)) assert_equal(true, Rational(2,1) != Rational(1))
@ -830,7 +830,7 @@ class Rational_Test < Test::Unit::TestCase
bug3656 = '[ruby-core:31622]' bug3656 = '[ruby-core:31622]'
c = Rational(1,2) c = Rational(1,2)
c.freeze c.freeze
assert(c.frozen?) assert_predicate(c, :frozen?)
result = c.marshal_load([2,3]) rescue :fail result = c.marshal_load([2,3]) rescue :fail
assert_equal(:fail, result, bug3656) assert_equal(:fail, result, bug3656)
end end
@ -1121,7 +1121,7 @@ class Rational_Test < Test::Unit::TestCase
assert_equal(0.5, 1.0.quo(2)) assert_equal(0.5, 1.0.quo(2))
assert_equal(Rational(1,4), Rational(1,2).quo(2)) assert_equal(Rational(1,4), Rational(1,2).quo(2))
assert_equal(0, Rational(1,2).quo(Float::INFINITY)) assert_equal(0, Rational(1,2).quo(Float::INFINITY))
assert(Rational(1,2).quo(0.0).infinite?, '[ruby-core:31626]') assert_predicate(Rational(1,2).quo(0.0), :infinite?, '[ruby-core:31626]')
assert_equal(0.5, 1.fdiv(2)) assert_equal(0.5, 1.fdiv(2))
assert_equal(5000000000.0, 10000000000.fdiv(2)) assert_equal(5000000000.0, 10000000000.fdiv(2))

View file

@ -152,7 +152,7 @@ class TestRegexp < Test::Unit::TestCase
def test_assign_named_capture_to_reserved_word def test_assign_named_capture_to_reserved_word
/(?<nil>.)/ =~ "a" /(?<nil>.)/ =~ "a"
assert(!local_variables.include?(:nil), "[ruby-dev:32675]") assert_not_include(local_variables, :nil, "[ruby-dev:32675]")
end end
def test_match_regexp def test_match_regexp
@ -554,11 +554,11 @@ class TestRegexp < Test::Unit::TestCase
$SAFE = 3 $SAFE = 3
/foo/.match("foo") /foo/.match("foo")
end.value end.value
assert(m.tainted?) assert_predicate(m, :tainted?)
assert_nothing_raised('[ruby-core:26137]') { assert_nothing_raised('[ruby-core:26137]') {
m = proc {$SAFE = 3; %r"#{ }"o}.call m = proc {$SAFE = 3; %r"#{ }"o}.call
} }
assert(m.tainted?) assert_predicate(m, :tainted?)
end end
def check(re, ss, fs = [], msg = nil) def check(re, ss, fs = [], msg = nil)
@ -1052,6 +1052,6 @@ class TestRegexp < Test::Unit::TestCase
"Expected #{re.inspect} to\n" + "Expected #{re.inspect} to\n" +
errs.map {|str, match| "\t#{'not ' unless match}match #{str.inspect}"}.join(",\n") errs.map {|str, match| "\t#{'not ' unless match}match #{str.inspect}"}.join(",\n")
} }
assert(errs.empty?, msg) assert_empty(errs, msg)
end end
end end

View file

@ -477,7 +477,7 @@ class TestRequire < Test::Unit::TestCase
$: << tmp $: << tmp
open(File.join(tmp, "foo.rb"), "w") {} open(File.join(tmp, "foo.rb"), "w") {}
require "foo" require "foo"
assert(Encoding.compatible?(tmp, $"[0]), bug6377) assert_send([Encoding, :compatible?, tmp, $"[0]], bug6377)
} }
ensure ensure
$:.replace(loadpath) $:.replace(loadpath)

View file

@ -186,7 +186,7 @@ class TestRubyOptions < Test::Unit::TestCase
d = Dir.tmpdir d = Dir.tmpdir
assert_in_out_err(["-C", d, "-e", "puts Dir.pwd"]) do |r, e| assert_in_out_err(["-C", d, "-e", "puts Dir.pwd"]) do |r, e|
assert(File.identical?(r.join, d)) assert_file.identical?(r.join, d)
assert_equal([], e) assert_equal([], e)
end end
end end

View file

@ -320,7 +320,7 @@ class TestSprintf < Test::Unit::TestCase
s2 = sprintf("%0x", -0x40000001) s2 = sprintf("%0x", -0x40000001)
b1 = (/\.\./ =~ s1) != nil b1 = (/\.\./ =~ s1) != nil
b2 = (/\.\./ =~ s2) != nil b2 = (/\.\./ =~ s2) != nil
assert(b1 == b2, "[ruby-dev:33224]") assert_equal(b1, b2, "[ruby-dev:33224]")
end end
def test_named_untyped def test_named_untyped

View file

@ -4,14 +4,14 @@ class TestStringchar < Test::Unit::TestCase
def test_string def test_string
assert_equal("abcd", "abcd") assert_equal("abcd", "abcd")
assert_match(/abcd/, "abcd") assert_match(/abcd/, "abcd")
assert("abcd" === "abcd") assert_operator("abcd", :===, "abcd")
# compile time string concatenation # compile time string concatenation
assert_equal("abcd", "ab" "cd") assert_equal("abcd", "ab" "cd")
assert_equal("22aacd44", "#{22}aa" "cd#{44}") assert_equal("22aacd44", "#{22}aa" "cd#{44}")
assert_equal("22aacd445566", "#{22}aa" "cd#{44}" "55" "#{66}") assert_equal("22aacd445566", "#{22}aa" "cd#{44}" "55" "#{66}")
assert("abc" !~ /^$/) assert_operator("abc", :!~, /^$/)
assert("abc\n" !~ /^$/) assert_operator("abc\n", :!~, /^$/)
assert("abc" !~ /^d*$/) assert_operator("abc", :!~, /^d*$/)
assert_equal(3, ("abc" =~ /d*$/)) assert_equal(3, ("abc" =~ /d*$/))
assert("" =~ /^$/) assert("" =~ /^$/)
assert("\n" =~ /^$/) assert("\n" =~ /^$/)

View file

@ -189,14 +189,14 @@ module TestStruct
o1 = klass1.new(1) o1 = klass1.new(1)
o2 = klass1.new(1) o2 = klass1.new(1)
o3 = klass2.new(1) o3 = klass2.new(1)
assert(o1.==(o2)) assert_equal(o1, o2)
assert(o1 != o3) assert_not_equal(o1, o3)
end end
def test_hash def test_hash
klass = @Struct.new(:a) klass = @Struct.new(:a)
o = klass.new(1) o = klass.new(1)
assert(o.hash.is_a?(Fixnum)) assert_kind_of(Fixnum, o.hash)
end end
def test_eql def test_eql
@ -205,8 +205,8 @@ module TestStruct
o1 = klass1.new(1) o1 = klass1.new(1)
o2 = klass1.new(1) o2 = klass1.new(1)
o3 = klass2.new(1) o3 = klass2.new(1)
assert(o1.eql?(o2)) assert_operator(o1, :eql?, o2)
assert(!(o1.eql?(o3))) assert_not_operator(o1, :eql?, o3)
end end
def test_size def test_size
@ -255,26 +255,26 @@ module TestStruct
x = klass1.new(1, 2, nil); x.c = x x = klass1.new(1, 2, nil); x.c = x
y = klass1.new(1, 2, nil); y.c = y y = klass1.new(1, 2, nil); y.c = y
Timeout.timeout(1) { Timeout.timeout(1) {
assert x == y assert_equal x, y
assert x.eql? y assert_operator x, :eql?, y
} }
z = klass1.new(:something, :other, nil); z.c = z z = klass1.new(:something, :other, nil); z.c = z
Timeout.timeout(1) { Timeout.timeout(1) {
assert x != z assert_not_equal x, z
assert !x.eql?(z) assert_not_operator x, :eql?, z
} }
x.c = y; y.c = x x.c = y; y.c = x
Timeout.timeout(1) { Timeout.timeout(1) {
assert x == y assert_equal x, y
assert x.eql?(y) assert_operator x, :eql?, y
} }
x.c = z; z.c = x x.c = z; z.c = x
Timeout.timeout(1) { Timeout.timeout(1) {
assert x != z assert_not_equal x, z
assert !x.eql?(z) assert_not_operator x, :eql?, z
} }
end end

View file

@ -64,14 +64,14 @@ class TestThread < Test::Unit::TestCase
end end
def test_thread_variable? def test_thread_variable?
refute Thread.new { Thread.current.thread_variable?("foo") }.join.value Thread.new { assert_not_send([Thread.current, :thread_variable?, "foo"]) }.value
t = Thread.new { t = Thread.new {
Thread.current.thread_variable_set("foo", "bar") Thread.current.thread_variable_set("foo", "bar")
}.join }.join
assert t.thread_variable?("foo") assert_send([t, :thread_variable?, "foo"])
assert t.thread_variable?(:foo) assert_send([t, :thread_variable?, :foo])
refute t.thread_variable?(:bar) assert_not_send([t, :thread_variable?, :bar])
end end
def test_thread_variable_strings_and_symbols_are_the_same_key def test_thread_variable_strings_and_symbols_are_the_same_key
@ -140,7 +140,7 @@ class TestThread < Test::Unit::TestCase
end end
t1.kill t1.kill
t2.kill t2.kill
assert_operator(c1, :>, c2, "[ruby-dev:33124]") # not guaranteed assert_send([c1, :>, c2], "[ruby-dev:33124]") # not guaranteed
end end
def test_new def test_new

View file

@ -56,14 +56,14 @@ class TestTime < Test::Unit::TestCase
Time.utc(2000, 3, 21, 0, 30)) Time.utc(2000, 3, 21, 0, 30))
assert_equal(0, (Time.at(1.1) + 0.9).usec) assert_equal(0, (Time.at(1.1) + 0.9).usec)
assert((Time.utc(2000, 4, 1) + 24).utc?) assert_predicate((Time.utc(2000, 4, 1) + 24), :utc?)
assert(!(Time.local(2000, 4, 1) + 24).utc?) assert_not_predicate((Time.local(2000, 4, 1) + 24), :utc?)
t = Time.new(2000, 4, 1, 0, 0, 0, "+01:00") + 24 t = Time.new(2000, 4, 1, 0, 0, 0, "+01:00") + 24
assert(!t.utc?) assert_not_predicate(t, :utc?)
assert_equal(3600, t.utc_offset) assert_equal(3600, t.utc_offset)
t = Time.new(2000, 4, 1, 0, 0, 0, "+02:00") + 24 t = Time.new(2000, 4, 1, 0, 0, 0, "+02:00") + 24
assert(!t.utc?) assert_not_predicate(t, :utc?)
assert_equal(7200, t.utc_offset) assert_equal(7200, t.utc_offset)
end end
@ -418,14 +418,14 @@ class TestTime < Test::Unit::TestCase
def test_eql def test_eql
t2000 = get_t2000 t2000 = get_t2000
assert(t2000.eql?(t2000)) assert_operator(t2000, :eql?, t2000)
assert(!t2000.eql?(Time.gm(2001))) assert_not_operator(t2000, :eql?, Time.gm(2001))
end end
def test_utc_p def test_utc_p
assert(Time.gm(2000).gmt?) assert_predicate(Time.gm(2000), :gmt?)
assert(!Time.local(2000).gmt?) assert_not_predicate(Time.local(2000), :gmt?)
assert(!Time.at(0).gmt?) assert_not_predicate(Time.at(0), :gmt?)
end end
def test_hash def test_hash
@ -453,15 +453,15 @@ class TestTime < Test::Unit::TestCase
def test_localtime_gmtime def test_localtime_gmtime
assert_nothing_raised do assert_nothing_raised do
t = Time.gm(2000) t = Time.gm(2000)
assert(t.gmt?) assert_predicate(t, :gmt?)
t.localtime t.localtime
assert(!t.gmt?) assert_not_predicate(t, :gmt?)
t.localtime t.localtime
assert(!t.gmt?) assert_not_predicate(t, :gmt?)
t.gmtime t.gmtime
assert(t.gmt?) assert_predicate(t, :gmt?)
t.gmtime t.gmtime
assert(t.gmt?) assert_predicate(t, :gmt?)
end end
t1 = Time.gm(2000) t1 = Time.gm(2000)
@ -554,13 +554,13 @@ class TestTime < Test::Unit::TestCase
assert_equal("UTC", t2000.zone) assert_equal("UTC", t2000.zone)
assert_equal(Encoding.find("locale"), t2000.zone.encoding) assert_equal(Encoding.find("locale"), t2000.zone.encoding)
assert_equal(0, t2000.gmt_offset) assert_equal(0, t2000.gmt_offset)
assert(!t2000.sunday?) assert_not_predicate(t2000, :sunday?)
assert(!t2000.monday?) assert_not_predicate(t2000, :monday?)
assert(!t2000.tuesday?) assert_not_predicate(t2000, :tuesday?)
assert(!t2000.wednesday?) assert_not_predicate(t2000, :wednesday?)
assert(!t2000.thursday?) assert_not_predicate(t2000, :thursday?)
assert(!t2000.friday?) assert_not_predicate(t2000, :friday?)
assert(t2000.saturday?) assert_predicate(t2000, :saturday?)
assert_equal([0, 0, 0, 1, 1, 2000, 6, 1, false, "UTC"], t2000.to_a) assert_equal([0, 0, 0, 1, 1, 2000, 6, 1, false, "UTC"], t2000.to_a)
t = Time.at(946684800).getlocal t = Time.at(946684800).getlocal

View file

@ -22,7 +22,7 @@ class TestWhileuntil < Test::Unit::TestCase
break if /vt100/ =~ line break if /vt100/ =~ line
end end
assert(!tmp.eof?) assert_not_predicate(tmp, :eof?)
assert_match(/vt100/, line) assert_match(/vt100/, line)
tmp.close tmp.close
@ -31,7 +31,7 @@ class TestWhileuntil < Test::Unit::TestCase
next if /vt100/ =~ line next if /vt100/ =~ line
assert_no_match(/vt100/, line) assert_no_match(/vt100/, line)
end end
assert(tmp.eof?) assert_predicate(tmp, :eof?)
assert_no_match(/vt100/, line) assert_no_match(/vt100/, line)
tmp.close tmp.close
@ -46,7 +46,7 @@ class TestWhileuntil < Test::Unit::TestCase
assert_no_match(/vt100/, line) assert_no_match(/vt100/, line)
assert_no_match(/VT100/, line) assert_no_match(/VT100/, line)
end end
assert(tmp.eof?) assert_predicate(tmp, :eof?)
tmp.close tmp.close
sum=0 sum=0
@ -78,6 +78,6 @@ class TestWhileuntil < Test::Unit::TestCase
until i>4 until i>4
i+=1 i+=1
end end
assert(i>4) assert_operator(i, :>, 4)
end end
end end

View file

@ -86,13 +86,13 @@ module TestEOF
def test_eof_2 def test_eof_2
open_file("") {|f| open_file("") {|f|
assert_equal("", f.read) assert_equal("", f.read)
assert(f.eof?) assert_predicate(f, :eof?)
} }
end end
def test_eof_3 def test_eof_3
open_file("") {|f| open_file("") {|f|
assert(f.eof?) assert_predicate(f, :eof?)
} }
end end