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:
parent
287d2adab0
commit
3ac0ec4ecd
45 changed files with 532 additions and 510 deletions
|
@ -42,7 +42,7 @@ module Emoji
|
|||
def test_encoding_name
|
||||
%w(UTF8-DoCoMo
|
||||
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
|
||||
|
||||
|
@ -126,7 +126,7 @@ module Emoji
|
|||
SJIS-KDDI
|
||||
ISO-2022-JP-KDDI
|
||||
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
|
||||
|
||||
|
@ -250,7 +250,7 @@ module Emoji
|
|||
def test_encoding_name
|
||||
%w(UTF8-SoftBank
|
||||
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
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ EOT
|
|||
|
||||
def test_sym_eq
|
||||
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
|
||||
|
||||
def test_compatible
|
||||
|
@ -253,10 +253,10 @@ EOT
|
|||
|
||||
def test_succ
|
||||
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")
|
||||
assert(s.succ.valid_encoding?, "#{encdump s}.succ.valid_encoding?")
|
||||
assert_predicate(s.succ, :valid_encoding?, "#{encdump s}.succ.valid_encoding?")
|
||||
end
|
||||
|
||||
def test_regexp_union
|
||||
|
@ -366,7 +366,7 @@ EOT
|
|||
def test_regexp_escape
|
||||
s = "\0*".force_encoding("UTF-16BE")
|
||||
r = Regexp.new(Regexp.escape(s))
|
||||
assert(r =~ s, "#{encdump(r)} =~ #{encdump(s)}")
|
||||
assert_match(r, s, "#{encdump(r)} =~ #{encdump(s)}")
|
||||
end
|
||||
|
||||
def test_casecmp2
|
||||
|
|
|
@ -41,13 +41,14 @@ class TestArray < Test::Unit::TestCase
|
|||
assert_equal([1, 2, 3], x[1,3])
|
||||
|
||||
x[0, 2] = 10
|
||||
assert(x[0] == 10 && x[1] == 2)
|
||||
assert_equal([10, 2, 3, 4, 5], x)
|
||||
|
||||
x[0, 0] = -1
|
||||
assert(x[0] == -1 && x[1] == 10)
|
||||
assert_equal([-1, 10, 2, 3, 4, 5], x)
|
||||
|
||||
x[-1, 1] = 20
|
||||
assert(x[-1] == 20 && x.pop == 20)
|
||||
assert_equal(20, x[-1])
|
||||
assert_equal(20, x.pop)
|
||||
end
|
||||
|
||||
def test_array_andor_0
|
||||
|
@ -97,7 +98,7 @@ class TestArray < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
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([["1a"], ["2b"], ["3c"]], "1a2b3c".scan(/(\d.)/))
|
||||
# non-greedy match
|
||||
|
@ -1209,6 +1210,7 @@ class TestArray < Test::Unit::TestCase
|
|||
a = @cls[]
|
||||
i = 0
|
||||
a.reverse_each { |e|
|
||||
i += 1
|
||||
assert(false, "Never get here")
|
||||
}
|
||||
assert_equal(0, i)
|
||||
|
@ -1710,7 +1712,7 @@ class TestArray < Test::Unit::TestCase
|
|||
|
||||
a = []
|
||||
[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
|
||||
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
def test_take
|
||||
|
|
|
@ -499,19 +499,19 @@ class Complex_Test < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_eqeq
|
||||
assert(Complex(1,0) == Complex(1))
|
||||
assert(Complex(-1,0) == Complex(-1))
|
||||
assert_equal(Complex(1), Complex(1,0))
|
||||
assert_equal(Complex(-1), Complex(-1,0))
|
||||
|
||||
assert_equal(false, Complex(2,1) == Complex(1))
|
||||
assert_equal(true, Complex(2,1) != Complex(1))
|
||||
assert_equal(false, Complex(1) == nil)
|
||||
assert_equal(false, Complex(1) == '')
|
||||
assert_not_equal(Complex(1), Complex(2,1))
|
||||
assert_operator(Complex(2,1), :!=, Complex(1))
|
||||
assert_not_equal(nil, Complex(1))
|
||||
assert_not_equal('', Complex(1))
|
||||
|
||||
nan = 0.0 / 0
|
||||
if nan.nan? && nan != nan
|
||||
assert_equal(false, Complex(nan, 0) == Complex(nan, 0))
|
||||
assert_equal(false, Complex(0, nan) == Complex(0, nan))
|
||||
assert_equal(false, Complex(nan, nan) == Complex(nan, nan))
|
||||
assert_not_equal(Complex(nan, 0), Complex(nan, 0))
|
||||
assert_not_equal(Complex(0, nan), Complex(0, nan))
|
||||
assert_not_equal(Complex(nan, nan), Complex(nan, nan))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -660,7 +660,7 @@ class Complex_Test < Test::Unit::TestCase
|
|||
bug3656 = '[ruby-core:31622]'
|
||||
c = Complex(1,2)
|
||||
c.freeze
|
||||
assert(c.frozen?)
|
||||
assert_predicate(c, :frozen?)
|
||||
result = c.marshal_load([2,3]) rescue :fail
|
||||
assert_equal(:fail, result, bug3656)
|
||||
assert_equal(Complex(1,2), c)
|
||||
|
@ -972,9 +972,9 @@ class Complex_Test < Test::Unit::TestCase
|
|||
|
||||
if (0.0/0).nan?
|
||||
nan = 0.0/0
|
||||
assert(nan.arg.equal?(nan))
|
||||
assert(nan.angle.equal?(nan))
|
||||
assert(nan.phase.equal?(nan))
|
||||
assert_same(nan, nan.arg)
|
||||
assert_same(nan, nan.angle)
|
||||
assert_same(nan, nan.phase)
|
||||
end
|
||||
|
||||
assert_equal(Math::PI, -1.arg)
|
||||
|
|
|
@ -74,8 +74,8 @@ class ComplexRational_Test < Test::Unit::TestCase
|
|||
|
||||
assert_equal(0, Rational(2,3) <=> SimpleRat(2,3))
|
||||
assert_equal(0, SimpleRat(2,3) <=> Rational(2,3))
|
||||
assert(Rational(2,3) == SimpleRat(2,3))
|
||||
assert(SimpleRat(2,3) == Rational(2,3))
|
||||
assert_equal(Rational(2,3), SimpleRat(2,3))
|
||||
assert_equal(SimpleRat(2,3), Rational(2,3))
|
||||
|
||||
assert_equal(SimpleRat, (c + 0).class)
|
||||
assert_equal(SimpleRat, (c - 0).class)
|
||||
|
@ -168,10 +168,10 @@ class ComplexRational_Test < Test::Unit::TestCase
|
|||
assert_equal([Float,Float],
|
||||
(cc ** c).instance_eval{[real.class, imag.class]})
|
||||
|
||||
assert(Complex(SimpleRat(2,3),SimpleRat(3,2)) ==
|
||||
Complex(Rational(2,3),Rational(3,2)))
|
||||
assert(Complex(Rational(2,3),Rational(3,2)) ==
|
||||
Complex(SimpleRat(2,3),SimpleRat(3,2)))
|
||||
assert_equal(Complex(SimpleRat(2,3),SimpleRat(3,2)),
|
||||
Complex(Rational(2,3),Rational(3,2)))
|
||||
assert_equal(Complex(Rational(2,3),Rational(3,2)),
|
||||
Complex(SimpleRat(2,3),SimpleRat(3,2)))
|
||||
|
||||
assert_equal([SimpleRat,SimpleRat],
|
||||
(c + 0).instance_eval{[real.class, imag.class]})
|
||||
|
|
|
@ -86,8 +86,8 @@ class TestEncodingConverter < Test::Unit::TestCase
|
|||
}
|
||||
|
||||
encoding_list = Encoding.list.map {|e| e.name }
|
||||
assert(!encoding_list.include?(name1))
|
||||
assert(!encoding_list.include?(name2))
|
||||
assert_not_include(encoding_list, name1)
|
||||
assert_not_include(encoding_list, name2)
|
||||
end
|
||||
|
||||
def test_newline_converter_with_ascii_incompatible
|
||||
|
|
|
@ -22,7 +22,7 @@ class TestEncoding < Test::Unit::TestCase
|
|||
aliases.each do |a, en|
|
||||
e = Encoding.find(a)
|
||||
assert_equal(e.name, en)
|
||||
assert(e.names.include?(a))
|
||||
assert_include(e.names, a)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -85,8 +85,8 @@ class TestEncoding < Test::Unit::TestCase
|
|||
def test_aliases
|
||||
assert_instance_of(Hash, Encoding.aliases)
|
||||
Encoding.aliases.each do |k, v|
|
||||
assert(Encoding.name_list.include?(k))
|
||||
assert(Encoding.name_list.include?(v))
|
||||
assert_include(Encoding.name_list, k)
|
||||
assert_include(Encoding.name_list, v)
|
||||
assert_instance_of(String, k)
|
||||
assert_instance_of(String, v)
|
||||
end
|
||||
|
|
|
@ -291,10 +291,10 @@ class TestFiber < Test::Unit::TestCase
|
|||
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))
|
||||
|
||||
assert(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(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_vm_stack_size], :>, h_0[:fiber_vm_stack_size])
|
||||
assert_operator(h_default[:fiber_vm_stack_size], :<, h_large[:fiber_vm_stack_size])
|
||||
assert_operator(h_default[:fiber_machine_stack_size], :>=, h_0[:fiber_machine_stack_size])
|
||||
assert_operator(h_default[:fiber_machine_stack_size], :<=, h_large[:fiber_machine_stack_size])
|
||||
|
||||
# check VM machine stack size
|
||||
script = '$stdout.sync=true; def rec; print "."; rec; end; Fiber.new{rec}.resume'
|
||||
|
|
|
@ -326,9 +326,9 @@ class TestFile < Test::Unit::TestCase
|
|||
File.open(tmp, :mode => IO::RDWR | IO::CREAT | IO::BINARY,
|
||||
:encoding => Encoding::ASCII_8BIT) do |x|
|
||||
|
||||
assert x.autoclose?
|
||||
assert_predicate(x, :autoclose?)
|
||||
assert_equal Encoding::ASCII_8BIT, x.external_encoding
|
||||
assert x.write 'hello'
|
||||
x.write 'hello'
|
||||
|
||||
x.seek 0, IO::SEEK_SET
|
||||
|
||||
|
|
|
@ -63,11 +63,16 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def assert_integer(n)
|
||||
assert(n.is_a?(Integer), n.inspect + " is not Fixnum.")
|
||||
assert_kind_of(Integer, n)
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def test_stat
|
||||
|
@ -131,42 +136,42 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
end if /mswin|mingw|cygwin/ =~ RUBY_PLATFORM
|
||||
|
||||
def test_directory_p
|
||||
assert(File.directory?(@dir))
|
||||
assert(!(File.directory?(@dir+"/...")))
|
||||
assert(!(File.directory?(@file)))
|
||||
assert(!(File.directory?(@nofile)))
|
||||
assert_file.directory?(@dir)
|
||||
assert_file.not_directory?(@dir+"/...")
|
||||
assert_file.not_directory?(@file)
|
||||
assert_file.not_directory?(@nofile)
|
||||
end
|
||||
|
||||
def test_pipe_p ## xxx
|
||||
assert(!(File.pipe?(@dir)))
|
||||
assert(!(File.pipe?(@file)))
|
||||
assert(!(File.pipe?(@nofile)))
|
||||
assert_file.not_pipe?(@dir)
|
||||
assert_file.not_pipe?(@file)
|
||||
assert_file.not_pipe?(@nofile)
|
||||
end
|
||||
|
||||
def test_symlink_p
|
||||
assert(!(File.symlink?(@dir)))
|
||||
assert(!(File.symlink?(@file)))
|
||||
assert(File.symlink?(@symlinkfile)) if @symlinkfile
|
||||
assert(!(File.symlink?(@hardlinkfile))) if @hardlinkfile
|
||||
assert(!(File.symlink?(@nofile)))
|
||||
assert_file.not_symlink?(@dir)
|
||||
assert_file.not_symlink?(@file)
|
||||
assert_file.symlink?(@symlinkfile) if @symlinkfile
|
||||
assert_file.not_symlink?(@hardlinkfile) if @hardlinkfile
|
||||
assert_file.not_symlink?(@nofile)
|
||||
end
|
||||
|
||||
def test_socket_p ## xxx
|
||||
assert(!(File.socket?(@dir)))
|
||||
assert(!(File.socket?(@file)))
|
||||
assert(!(File.socket?(@nofile)))
|
||||
assert_file.not_socket?(@dir)
|
||||
assert_file.not_socket?(@file)
|
||||
assert_file.not_socket?(@nofile)
|
||||
end
|
||||
|
||||
def test_blockdev_p ## xxx
|
||||
assert(!(File.blockdev?(@dir)))
|
||||
assert(!(File.blockdev?(@file)))
|
||||
assert(!(File.blockdev?(@nofile)))
|
||||
assert_file.not_blockdev?(@dir)
|
||||
assert_file.not_blockdev?(@file)
|
||||
assert_file.not_blockdev?(@nofile)
|
||||
end
|
||||
|
||||
def test_chardev_p ## xxx
|
||||
assert(!(File.chardev?(@dir)))
|
||||
assert(!(File.chardev?(@file)))
|
||||
assert(!(File.chardev?(@nofile)))
|
||||
assert_file.not_chardev?(@dir)
|
||||
assert_file.not_chardev?(@file)
|
||||
assert_file.not_chardev?(@nofile)
|
||||
end
|
||||
|
||||
def test_exist_p
|
||||
|
@ -179,119 +184,119 @@ class TestFileExhaustive < Test::Unit::TestCase
|
|||
return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM
|
||||
return if Process.euid == 0
|
||||
File.chmod(0200, @file)
|
||||
assert(!(File.readable?(@file)))
|
||||
assert_file.not_readable?(@file)
|
||||
File.chmod(0600, @file)
|
||||
assert(File.readable?(@file))
|
||||
assert(!(File.readable?(@nofile)))
|
||||
assert_file.readable?(@file)
|
||||
assert_file.not_readable?(@nofile)
|
||||
end
|
||||
|
||||
def test_readable_real_p
|
||||
return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM
|
||||
return if Process.euid == 0
|
||||
File.chmod(0200, @file)
|
||||
assert(!(File.readable_real?(@file)))
|
||||
assert_file.not_readable_real?(@file)
|
||||
File.chmod(0600, @file)
|
||||
assert(File.readable_real?(@file))
|
||||
assert(!(File.readable_real?(@nofile)))
|
||||
assert_file.readable_real?(@file)
|
||||
assert_file.not_readable_real?(@nofile)
|
||||
end
|
||||
|
||||
def test_world_readable_p
|
||||
return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM
|
||||
File.chmod(0006, @file)
|
||||
assert(File.world_readable?(@file))
|
||||
assert_file.world_readable?(@file)
|
||||
File.chmod(0060, @file)
|
||||
assert(!(File.world_readable?(@file)))
|
||||
assert_file.not_world_readable?(@file)
|
||||
File.chmod(0600, @file)
|
||||
assert(!(File.world_readable?(@file)))
|
||||
assert(!(File.world_readable?(@nofile)))
|
||||
assert_file.not_world_readable?(@file)
|
||||
assert_file.not_world_readable?(@nofile)
|
||||
end
|
||||
|
||||
def test_writable_p
|
||||
return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM
|
||||
return if Process.euid == 0
|
||||
File.chmod(0400, @file)
|
||||
assert(!(File.writable?(@file)))
|
||||
assert_file.not_writable?(@file)
|
||||
File.chmod(0600, @file)
|
||||
assert(File.writable?(@file))
|
||||
assert(!(File.writable?(@nofile)))
|
||||
assert_file.writable?(@file)
|
||||
assert_file.not_writable?(@nofile)
|
||||
end
|
||||
|
||||
def test_writable_real_p
|
||||
return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM
|
||||
return if Process.euid == 0
|
||||
File.chmod(0400, @file)
|
||||
assert(!(File.writable_real?(@file)))
|
||||
assert_file.not_writable_real?(@file)
|
||||
File.chmod(0600, @file)
|
||||
assert(File.writable_real?(@file))
|
||||
assert(!(File.writable_real?(@nofile)))
|
||||
assert_file.writable_real?(@file)
|
||||
assert_file.not_writable_real?(@nofile)
|
||||
end
|
||||
|
||||
def test_world_writable_p
|
||||
return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM
|
||||
File.chmod(0006, @file)
|
||||
assert(File.world_writable?(@file))
|
||||
assert_file.world_writable?(@file)
|
||||
File.chmod(0060, @file)
|
||||
assert(!(File.world_writable?(@file)))
|
||||
assert_file.not_world_writable?(@file)
|
||||
File.chmod(0600, @file)
|
||||
assert(!(File.world_writable?(@file)))
|
||||
assert(!(File.world_writable?(@nofile)))
|
||||
assert_file.not_world_writable?(@file)
|
||||
assert_file.not_world_writable?(@nofile)
|
||||
end
|
||||
|
||||
def test_executable_p
|
||||
return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM
|
||||
File.chmod(0100, @file)
|
||||
assert(File.executable?(@file))
|
||||
assert_file.executable?(@file)
|
||||
File.chmod(0600, @file)
|
||||
assert(!(File.executable?(@file)))
|
||||
assert(!(File.executable?(@nofile)))
|
||||
assert_file.not_executable?(@file)
|
||||
assert_file.not_executable?(@nofile)
|
||||
end
|
||||
|
||||
def test_executable_real_p
|
||||
return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM
|
||||
File.chmod(0100, @file)
|
||||
assert(File.executable_real?(@file))
|
||||
assert_file.executable_real?(@file)
|
||||
File.chmod(0600, @file)
|
||||
assert(!(File.executable_real?(@file)))
|
||||
assert(!(File.executable_real?(@nofile)))
|
||||
assert_file.not_executable_real?(@file)
|
||||
assert_file.not_executable_real?(@nofile)
|
||||
end
|
||||
|
||||
def test_file_p
|
||||
assert(!(File.file?(@dir)))
|
||||
assert(File.file?(@file))
|
||||
assert(!(File.file?(@nofile)))
|
||||
assert_file.not_file?(@dir)
|
||||
assert_file.file?(@file)
|
||||
assert_file.not_file?(@nofile)
|
||||
end
|
||||
|
||||
def test_zero_p
|
||||
assert_nothing_raised { File.zero?(@dir) }
|
||||
assert(!(File.zero?(@file)))
|
||||
assert(File.zero?(@zerofile))
|
||||
assert(!(File.zero?(@nofile)))
|
||||
assert_file.not_zero?(@file)
|
||||
assert_file.zero?(@zerofile)
|
||||
assert_file.not_zero?(@nofile)
|
||||
end
|
||||
|
||||
def test_size_p
|
||||
assert_nothing_raised { File.size?(@dir) }
|
||||
assert_equal(3, File.size?(@file))
|
||||
assert(!(File.size?(@zerofile)))
|
||||
assert(!(File.size?(@nofile)))
|
||||
assert_file.not_size?(@zerofile)
|
||||
assert_file.not_size?(@nofile)
|
||||
end
|
||||
|
||||
def test_owned_p ## xxx
|
||||
return if /cygwin|mswin|bccwin|mingw|emx/ =~ RUBY_PLATFORM
|
||||
assert(File.owned?(@file))
|
||||
assert(File.grpowned?(@file))
|
||||
assert_file.owned?(@file)
|
||||
assert_file.grpowned?(@file)
|
||||
end
|
||||
|
||||
def test_suid_sgid_sticky ## xxx
|
||||
assert(!(File.setuid?(@file)))
|
||||
assert(!(File.setgid?(@file)))
|
||||
assert(!(File.sticky?(@file)))
|
||||
assert_file.not_setuid?(@file)
|
||||
assert_file.not_setgid?(@file)
|
||||
assert_file.not_sticky?(@file)
|
||||
end
|
||||
|
||||
def test_identical_p
|
||||
assert(File.identical?(@file, @file))
|
||||
assert(!(File.identical?(@file, @zerofile)))
|
||||
assert(!(File.identical?(@file, @nofile)))
|
||||
assert(!(File.identical?(@nofile, @file)))
|
||||
assert_file.identical?(@file, @file)
|
||||
assert_file.not_identical?(@file, @zerofile)
|
||||
assert_file.not_identical?(@file, @nofile)
|
||||
assert_file.not_identical?(@nofile, @file)
|
||||
end
|
||||
|
||||
def test_s_size
|
||||
|
|
|
@ -87,8 +87,14 @@ class TestFixnum < Test::Unit::TestCase
|
|||
next if b == 0
|
||||
q, r = a.divmod(b)
|
||||
assert_equal(a, b*q+r)
|
||||
assert(r.abs < b.abs)
|
||||
assert(0 < b ? (0 <= r && r < b) : (b < r && r <= 0))
|
||||
assert_operator(r.abs, :<, b.abs)
|
||||
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.div(b))
|
||||
assert_equal(r, a%b)
|
||||
|
@ -195,40 +201,40 @@ class TestFixnum < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_cmp
|
||||
assert(1 != nil)
|
||||
assert_operator(1, :!=, nil)
|
||||
|
||||
assert_equal(0, 1 <=> 1)
|
||||
assert_equal(-1, 1 <=> 4294967296)
|
||||
assert_equal(0, 1 <=> 1.0)
|
||||
assert_nil(1 <=> nil)
|
||||
|
||||
assert(1.send(:>, 0))
|
||||
assert(!(1.send(:>, 1)))
|
||||
assert(!(1.send(:>, 2)))
|
||||
assert(!(1.send(:>, 4294967296)))
|
||||
assert(1.send(:>, 0.0))
|
||||
assert_raise(ArgumentError) { 1.send(:>, nil) }
|
||||
assert_operator(1, :>, 0)
|
||||
assert_not_operator(1, :>, 1)
|
||||
assert_not_operator(1, :>, 2)
|
||||
assert_not_operator(1, :>, 4294967296)
|
||||
assert_operator(1, :>, 0.0)
|
||||
assert_raise(ArgumentError) { 1 > nil }
|
||||
|
||||
assert(1.send(:>=, 0))
|
||||
assert(1.send(:>=, 1))
|
||||
assert(!(1.send(:>=, 2)))
|
||||
assert(!(1.send(:>=, 4294967296)))
|
||||
assert(1.send(:>=, 0.0))
|
||||
assert_raise(ArgumentError) { 1.send(:>=, nil) }
|
||||
assert_operator(1, :>=, 0)
|
||||
assert_operator(1, :>=, 1)
|
||||
assert_not_operator(1, :>=, 2)
|
||||
assert_not_operator(1, :>=, 4294967296)
|
||||
assert_operator(1, :>=, 0.0)
|
||||
assert_raise(ArgumentError) { 1 >= nil }
|
||||
|
||||
assert(!(1.send(:<, 0)))
|
||||
assert(!(1.send(:<, 1)))
|
||||
assert(1.send(:<, 2))
|
||||
assert(1.send(:<, 4294967296))
|
||||
assert(!(1.send(:<, 0.0)))
|
||||
assert_raise(ArgumentError) { 1.send(:<, nil) }
|
||||
assert_not_operator(1, :<, 0)
|
||||
assert_not_operator(1, :<, 1)
|
||||
assert_operator(1, :<, 2)
|
||||
assert_operator(1, :<, 4294967296)
|
||||
assert_not_operator(1, :<, 0.0)
|
||||
assert_raise(ArgumentError) { 1 < nil }
|
||||
|
||||
assert(!(1.send(:<=, 0)))
|
||||
assert(1.send(:<=, 1))
|
||||
assert(1.send(:<=, 2))
|
||||
assert(1.send(:<=, 4294967296))
|
||||
assert(!(1.send(:<=, 0.0)))
|
||||
assert_raise(ArgumentError) { 1.send(:<=, nil) }
|
||||
assert_not_operator(1, :<=, 0)
|
||||
assert_operator(1, :<=, 1)
|
||||
assert_operator(1, :<=, 2)
|
||||
assert_operator(1, :<=, 4294967296)
|
||||
assert_not_operator(1, :<=, 0.0)
|
||||
assert_raise(ArgumentError) { 1 <= nil }
|
||||
end
|
||||
|
||||
class DummyNumeric < Numeric
|
||||
|
|
|
@ -13,18 +13,18 @@ class TestFloat < Test::Unit::TestCase
|
|||
assert_equal(-2, (-2.6).truncate)
|
||||
assert_equal(3, 2.6.round)
|
||||
assert_equal(-2, (-2.4).truncate)
|
||||
assert((13.4 % 1 - 0.4).abs < 0.0001)
|
||||
assert_in_delta(13.4 % 1, 0.4, 0.0001)
|
||||
assert_equal(36893488147419111424,
|
||||
36893488147419107329.0.to_i)
|
||||
end
|
||||
|
||||
def nan_test(x,y)
|
||||
extend Test::Unit::Assertions
|
||||
assert(x != y)
|
||||
assert_equal(false, (x < y))
|
||||
assert_equal(false, (x > y))
|
||||
assert_equal(false, (x <= y))
|
||||
assert_equal(false, (x >= y))
|
||||
assert_operator(x, :!=, y)
|
||||
assert_not_operator(x, :<, y)
|
||||
assert_not_operator(x, :>, y)
|
||||
assert_not_operator(x, :<=, y)
|
||||
assert_not_operator(x, :>=, y)
|
||||
end
|
||||
def test_nan
|
||||
nan = Float::NAN
|
||||
|
@ -108,25 +108,25 @@ class TestFloat < Test::Unit::TestCase
|
|||
|
||||
def test_strtod
|
||||
a = Float("0")
|
||||
assert(a.abs < Float::EPSILON)
|
||||
assert_in_delta(a, 0, Float::EPSILON)
|
||||
a = Float("0.0")
|
||||
assert(a.abs < Float::EPSILON)
|
||||
assert_in_delta(a, 0, Float::EPSILON)
|
||||
a = Float("+0.0")
|
||||
assert(a.abs < Float::EPSILON)
|
||||
assert_in_delta(a, 0, Float::EPSILON)
|
||||
a = Float("-0.0")
|
||||
assert(a.abs < Float::EPSILON)
|
||||
assert_in_delta(a, 0, Float::EPSILON)
|
||||
a = Float("0.0000000000000000001")
|
||||
assert(a != 0.0)
|
||||
assert_not_equal(0.0, a)
|
||||
a = Float("+0.0000000000000000001")
|
||||
assert(a != 0.0)
|
||||
assert_not_equal(0.0, a)
|
||||
a = Float("-0.0000000000000000001")
|
||||
assert(a != 0.0)
|
||||
assert_not_equal(0.0, a)
|
||||
a = Float(".0")
|
||||
assert(a.abs < Float::EPSILON)
|
||||
assert_in_delta(a, 0, Float::EPSILON)
|
||||
a = Float("+.0")
|
||||
assert(a.abs < Float::EPSILON)
|
||||
assert_in_delta(a, 0, Float::EPSILON)
|
||||
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.")}
|
||||
|
@ -281,15 +281,15 @@ class TestFloat < Test::Unit::TestCase
|
|||
def test_eql
|
||||
inf = Float::INFINITY
|
||||
nan = Float::NAN
|
||||
assert(1.0.eql?(1.0))
|
||||
assert(inf.eql?(inf))
|
||||
assert(!(nan.eql?(nan)))
|
||||
assert(!(1.0.eql?(nil)))
|
||||
assert_operator(1.0, :eql?, 1.0)
|
||||
assert_operator(inf, :eql?, inf)
|
||||
assert_not_operator(nan, :eql?, nan)
|
||||
assert_not_operator(1.0, :eql?, nil)
|
||||
|
||||
assert(1.0 == 1)
|
||||
assert(1.0 != 2**32)
|
||||
assert(1.0 != nan)
|
||||
assert(1.0 != nil)
|
||||
assert_equal(1.0, 1)
|
||||
assert_not_equal(1.0, 2**32)
|
||||
assert_not_equal(1.0, nan)
|
||||
assert_not_equal(1.0, nil)
|
||||
end
|
||||
|
||||
def test_cmp
|
||||
|
@ -334,8 +334,8 @@ class TestFloat < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_zero_p
|
||||
assert(0.0.zero?)
|
||||
assert(!(1.0.zero?))
|
||||
assert_predicate(0.0, :zero?)
|
||||
assert_not_predicate(1.0, :zero?)
|
||||
end
|
||||
|
||||
def test_infinite_p
|
||||
|
@ -347,9 +347,9 @@ class TestFloat < Test::Unit::TestCase
|
|||
|
||||
def test_finite_p
|
||||
inf = Float::INFINITY
|
||||
assert(!(inf.finite?))
|
||||
assert(!((-inf).finite?))
|
||||
assert(1.0.finite?)
|
||||
assert_not_predicate(inf, :finite?)
|
||||
assert_not_predicate(-inf, :finite?)
|
||||
assert_predicate(1.0, :finite?)
|
||||
end
|
||||
|
||||
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, "0.1_2_5__".to_f, 0.00001)
|
||||
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_equal(15.9375, Float('0xf.fp0'))
|
||||
assert_raise(ArgumentError) { Float('0x') }
|
||||
|
@ -549,7 +549,7 @@ class TestFloat < Test::Unit::TestCase
|
|||
assert_raise(TypeError) { Float(nil) }
|
||||
o = Object.new
|
||||
def o.to_f; inf = Float::INFINITY; inf/inf; end
|
||||
assert(Float(o).nan?)
|
||||
assert_predicate(Float(o), :nan?)
|
||||
end
|
||||
|
||||
def test_invalid_str
|
||||
|
|
|
@ -256,7 +256,7 @@ class TestGc < Test::Unit::TestCase
|
|||
a = []
|
||||
(base_length * 500).times{ a << 'a'; nil }
|
||||
GC.start
|
||||
assert base_length < GC.stat[:heap_eden_page_length]
|
||||
assert_operator base_length, :<, GC.stat[:heap_eden_page_length]
|
||||
eom
|
||||
end
|
||||
|
||||
|
|
|
@ -492,7 +492,7 @@ class TestHash < Test::Unit::TestCase
|
|||
|
||||
h = @cls[ 'a' => 1, 'b' => 2, 'c' => 1].invert
|
||||
assert_equal(2, h.length)
|
||||
assert(h[1] == 'a' || h[1] == 'c')
|
||||
assert_include(%w[a c], h[1])
|
||||
assert_equal('b', h[2])
|
||||
end
|
||||
|
||||
|
@ -787,7 +787,7 @@ class TestHash < Test::Unit::TestCase
|
|||
assert_nil(h.default_proc = nil)
|
||||
assert_nil(h.default_proc)
|
||||
h.default_proc = ->(h, k){ true }
|
||||
assert(h[:nope])
|
||||
assert_equal(true, h[:nope])
|
||||
h = @cls[]
|
||||
assert_nil(h.default_proc)
|
||||
end
|
||||
|
|
|
@ -35,9 +35,9 @@ class TestInteger < Test::Unit::TestCase
|
|||
|
||||
def test_rshift
|
||||
# assert_equal(bdsize(0x40000001), (1 >> -0x40000001).size)
|
||||
assert((1 >> 0x80000000).zero?)
|
||||
assert((1 >> 0xffffffff).zero?)
|
||||
assert((1 >> 0x100000000).zero?)
|
||||
assert_predicate((1 >> 0x80000000), :zero?)
|
||||
assert_predicate((1 >> 0xffffffff), :zero?)
|
||||
assert_predicate((1 >> 0x100000000), :zero?)
|
||||
# assert_equal((1 << 0x40000000), (1 >> -0x40000000))
|
||||
# assert_equal((1 << 0x40000001), (1 >> -0x40000001))
|
||||
end
|
||||
|
@ -100,8 +100,8 @@ class TestInteger < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_int_p
|
||||
assert(!(1.0.integer?))
|
||||
assert(1.integer?)
|
||||
assert_not_predicate(1.0, :integer?)
|
||||
assert_predicate(1, :integer?)
|
||||
end
|
||||
|
||||
def test_odd_p_even_p
|
||||
|
@ -111,10 +111,10 @@ class TestInteger < Test::Unit::TestCase
|
|||
remove_method :odd?, :even?
|
||||
end
|
||||
|
||||
assert(1.odd?)
|
||||
assert(!(2.odd?))
|
||||
assert(!(1.even?))
|
||||
assert(2.even?)
|
||||
assert_predicate(1, :odd?)
|
||||
assert_not_predicate(2, :odd?)
|
||||
assert_not_predicate(1, :even?)
|
||||
assert_predicate(2, :even?)
|
||||
|
||||
ensure
|
||||
Fixnum.class_eval do
|
||||
|
|
|
@ -206,8 +206,14 @@ class TestIntegerComb < Test::Unit::TestCase
|
|||
check_class(q)
|
||||
check_class(r)
|
||||
assert_equal(a, b*q+r)
|
||||
assert(r.abs < b.abs)
|
||||
assert(0 < b ? (0 <= r && r < b) : (b < r && r <= 0))
|
||||
assert_operator(r.abs, :<, b.abs)
|
||||
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.div(b))
|
||||
assert_equal(r, a%b)
|
||||
|
|
|
@ -122,13 +122,13 @@ class TestIO < Test::Unit::TestCase
|
|||
assert_equal("abc", r.read)
|
||||
end
|
||||
].each{|thr| thr.join}
|
||||
assert(!r.closed?)
|
||||
assert(w.closed?)
|
||||
assert_not_predicate(r, :closed?)
|
||||
assert_predicate(w, :closed?)
|
||||
:foooo
|
||||
}
|
||||
assert_equal(:foooo, ret)
|
||||
assert(x[0].closed?)
|
||||
assert(x[1].closed?)
|
||||
assert_predicate(x[0], :closed?)
|
||||
assert_predicate(x[1], :closed?)
|
||||
end
|
||||
|
||||
def test_pipe_block_close
|
||||
|
@ -139,8 +139,8 @@ class TestIO < Test::Unit::TestCase
|
|||
r.close if (i&1) == 0
|
||||
w.close if (i&2) == 0
|
||||
}
|
||||
assert(x[0].closed?)
|
||||
assert(x[1].closed?)
|
||||
assert_predicate(x[0], :closed?)
|
||||
assert_predicate(x[1], :closed?)
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -775,7 +775,7 @@ class TestIO < Test::Unit::TestCase
|
|||
s1.close
|
||||
_, status = Process.waitpid2(pid) if pid
|
||||
end
|
||||
assert status.success?, status.inspect
|
||||
assert_predicate(status, :success?)
|
||||
end
|
||||
}
|
||||
}
|
||||
|
@ -1297,7 +1297,7 @@ class TestIO < Test::Unit::TestCase
|
|||
buf = "buf"
|
||||
value = r.read_nonblock(4096, buf, exception: false)
|
||||
assert_equal value, "HI!\n"
|
||||
assert buf.equal?(value)
|
||||
assert_same(buf, value)
|
||||
w.close
|
||||
assert_equal nil, r.read_nonblock(4096, "", exception: false)
|
||||
}
|
||||
|
@ -2276,8 +2276,8 @@ End
|
|||
|
||||
def test_tainted
|
||||
make_tempfile {|t|
|
||||
assert(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.read(t.path, 4), :tainted?, '[ruby-dev:38826]')
|
||||
assert_predicate(File.open(t.path) {|f| f.read(4)}, :tainted?, '[ruby-dev:38826]')
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -2631,25 +2631,25 @@ End
|
|||
def test_cloexec
|
||||
return unless defined? Fcntl::FD_CLOEXEC
|
||||
open(__FILE__) {|f|
|
||||
assert(f.close_on_exec?)
|
||||
assert_predicate(f, :close_on_exec?)
|
||||
g = f.dup
|
||||
begin
|
||||
assert(g.close_on_exec?)
|
||||
assert_predicate(g, :close_on_exec?)
|
||||
f.reopen(g)
|
||||
assert(f.close_on_exec?)
|
||||
assert_predicate(f, :close_on_exec?)
|
||||
ensure
|
||||
g.close
|
||||
end
|
||||
g = IO.new(f.fcntl(Fcntl::F_DUPFD))
|
||||
begin
|
||||
assert(g.close_on_exec?)
|
||||
assert_predicate(g, :close_on_exec?)
|
||||
ensure
|
||||
g.close
|
||||
end
|
||||
}
|
||||
IO.pipe {|r,w|
|
||||
assert(r.close_on_exec?)
|
||||
assert(w.close_on_exec?)
|
||||
assert_predicate(r, :close_on_exec?)
|
||||
assert_predicate(w, :close_on_exec?)
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -2099,7 +2099,7 @@ EOT
|
|||
open("ff", "w") {|f| }
|
||||
open("ff", "rt") {|f|
|
||||
f.ungetc "a"
|
||||
assert(!f.eof?, "[ruby-dev:40506] (3)")
|
||||
assert_not_predicate(f, :eof?, "[ruby-dev:40506] (3)")
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
|
@ -103,7 +103,7 @@ class TestISeq < Test::Unit::TestCase
|
|||
iseq = ISeq.of(method(:test_location))
|
||||
|
||||
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.base_label)
|
||||
assert_equal(LINE_OF_HERE+1, iseq.first_lineno)
|
||||
|
@ -111,7 +111,7 @@ class TestISeq < Test::Unit::TestCase
|
|||
line = __LINE__
|
||||
iseq = ISeq.of(Proc.new{})
|
||||
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("block in test_location", iseq.label)
|
||||
assert_equal(line+1, iseq.first_lineno)
|
||||
|
|
|
@ -25,7 +25,7 @@ class TestM17N < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
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|
|
||||
# "\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) }
|
||||
|
@ -33,7 +33,7 @@ class TestM17N < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
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|
|
||||
enc = Encoding.find(ename)
|
||||
if enc == r.encoding
|
||||
|
@ -107,7 +107,7 @@ class TestM17N < Test::Unit::TestCase
|
|||
elsif !s2.ascii_only?
|
||||
assert_equal(s2.encoding, t.encoding)
|
||||
else
|
||||
assert([s1.encoding, s2.encoding].include?(t.encoding))
|
||||
assert_include([s1.encoding, s2.encoding], t.encoding)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -360,15 +360,15 @@ class TestM17N < Test::Unit::TestCase
|
|||
].each {|pat2|
|
||||
s = [pat2.gsub(/ /, "")].pack("B*").force_encoding("utf-8")
|
||||
if pat2 <= bits_0x10ffff
|
||||
assert(s.valid_encoding?, "#{pat2}")
|
||||
assert_predicate(s, :valid_encoding?, "#{pat2}")
|
||||
else
|
||||
assert(!s.valid_encoding?, "#{pat2}")
|
||||
assert_not_predicate(s, :valid_encoding?, "#{pat2}")
|
||||
end
|
||||
}
|
||||
if / / =~ pat0
|
||||
pat3 = pat1.gsub(/X/, "0")
|
||||
s = [pat3.gsub(/ /, "")].pack("B*").force_encoding("utf-8")
|
||||
assert(!s.valid_encoding?, "#{pat3}")
|
||||
assert_not_predicate(s, :valid_encoding?, "#{pat3}")
|
||||
end
|
||||
}
|
||||
}
|
||||
|
@ -388,12 +388,12 @@ class TestM17N < Test::Unit::TestCase
|
|||
pat0.gsub(/x/, '1'),
|
||||
].each {|pat1|
|
||||
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|
|
||||
s = [pat.gsub(/ /, "")].pack("B*").force_encoding("utf-8")
|
||||
assert(s.valid_encoding?, "#{pat}")
|
||||
assert_predicate(s, :valid_encoding?, "#{pat}")
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -592,38 +592,38 @@ class TestM17N < Test::Unit::TestCase
|
|||
assert_nothing_raised {
|
||||
r = Regexp.new(s)
|
||||
}
|
||||
assert(r.fixed_encoding?)
|
||||
assert_predicate(r, :fixed_encoding?)
|
||||
assert_match(r, "\xa4\xa2".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"))
|
||||
|
||||
r = /\p{Hiragana}/e
|
||||
assert(r.fixed_encoding?)
|
||||
assert_predicate(r, :fixed_encoding?)
|
||||
assert_match(r, "\xa4\xa2".force_encoding("euc-jp"))
|
||||
|
||||
r = /\p{AsciI}/e
|
||||
assert(r.fixed_encoding?)
|
||||
assert_predicate(r, :fixed_encoding?)
|
||||
assert_match(r, "a".force_encoding("euc-jp"))
|
||||
|
||||
r = /\p{hiraganA}/e
|
||||
assert(r.fixed_encoding?)
|
||||
assert_predicate(r, :fixed_encoding?)
|
||||
assert_match(r, "\xa4\xa2".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)
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
def test_regexp_embed_preprocess
|
||||
r1 = /\xa4\xa2/e
|
||||
r2 = /#{r1}/
|
||||
assert(r2.source.include?(r1.source))
|
||||
assert_include(r2.source, r1.source)
|
||||
end
|
||||
|
||||
def test_begin_end_offset
|
||||
|
@ -668,10 +668,10 @@ class TestM17N < Test::Unit::TestCase
|
|||
def test_union_0
|
||||
r = Regexp.union
|
||||
assert_regexp_generic_ascii(r)
|
||||
assert(r !~ a(""))
|
||||
assert(r !~ e(""))
|
||||
assert(r !~ s(""))
|
||||
assert(r !~ u(""))
|
||||
assert_not_match(r, a(""))
|
||||
assert_not_match(r, e(""))
|
||||
assert_not_match(r, s(""))
|
||||
assert_not_match(r, u(""))
|
||||
end
|
||||
|
||||
def test_union_1_asciionly_string
|
||||
|
@ -894,9 +894,9 @@ class TestM17N < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_str_lt
|
||||
assert(a("a") < a("\xa1"))
|
||||
assert(a("a") < s("\xa1"))
|
||||
assert(s("a") < a("\xa1"))
|
||||
assert_operator(a("a"), :<, a("\xa1"))
|
||||
assert_operator(a("a"), :<, s("\xa1"))
|
||||
assert_operator(s("a"), :<, a("\xa1"))
|
||||
end
|
||||
|
||||
def test_str_multiply
|
||||
|
@ -1069,15 +1069,15 @@ class TestM17N < Test::Unit::TestCase
|
|||
s = "\x80".force_encoding("ASCII-8BIT")
|
||||
r = Regexp.new("\x80".force_encoding("ASCII-8BIT"))
|
||||
s2 = s.sub(r, "")
|
||||
assert(s2.empty?)
|
||||
assert(s2.ascii_only?)
|
||||
assert_empty(s2)
|
||||
assert_predicate(s2, :ascii_only?)
|
||||
end
|
||||
|
||||
def test_sub3
|
||||
repl = "\x81".force_encoding("sjis")
|
||||
assert_equal(false, repl.valid_encoding?)
|
||||
s = "a@".sub(/a/, repl)
|
||||
assert(s.valid_encoding?)
|
||||
assert_predicate(s, :valid_encoding?)
|
||||
end
|
||||
|
||||
def test_insert
|
||||
|
@ -1459,8 +1459,8 @@ class TestM17N < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_force_encoding
|
||||
assert(("".center(1, "\x80".force_encoding("utf-8")); true),
|
||||
"moved from btest/knownbug, [ruby-dev:33807]")
|
||||
assert_equal(u("\x80"), "".center(1, u("\x80")),
|
||||
"moved from btest/knownbug, [ruby-dev:33807]")
|
||||
a = "".force_encoding("ascii-8bit") << 0xC3 << 0xB6
|
||||
assert_equal(1, a.force_encoding("utf-8").size, '[ruby-core:22437]')
|
||||
b = "".force_encoding("ascii-8bit") << 0xC3.chr << 0xB6.chr
|
||||
|
|
|
@ -124,7 +124,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
elsif !s2.ascii_only?
|
||||
assert_equal(s2.encoding, t.encoding)
|
||||
else
|
||||
assert([s1.encoding, s2.encoding].include?(t.encoding))
|
||||
assert_include([s1.encoding, s2.encoding], t.encoding)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -211,7 +211,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
assert_raise(Encoding::CompatibilityError) { s1 + s2 }
|
||||
else
|
||||
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_str_enc_propagation(t, s1, s2)
|
||||
end
|
||||
|
@ -222,7 +222,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
STRINGS.each {|s|
|
||||
[0,1,2].each {|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)
|
||||
}
|
||||
}
|
||||
|
@ -240,16 +240,16 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
|
||||
def test_str_eq_reflexive
|
||||
STRINGS.each {|s|
|
||||
assert(s == s, "#{encdump s} == #{encdump s}")
|
||||
assert_equal(s, s, "#{encdump s} == #{encdump s}")
|
||||
}
|
||||
end
|
||||
|
||||
def test_str_eq_symmetric
|
||||
combination(STRINGS, STRINGS) {|s1, s2|
|
||||
if s1 == s2
|
||||
assert(s2 == s1, "#{encdump s2} == #{encdump s1}")
|
||||
assert_equal(s2, s1, "#{encdump s2} == #{encdump s1}")
|
||||
else
|
||||
assert(!(s2 == s1), "!(#{encdump s2} == #{encdump s1})")
|
||||
assert_not_equal(s2, s1, "!(#{encdump s2} == #{encdump s1})")
|
||||
end
|
||||
}
|
||||
end
|
||||
|
@ -257,7 +257,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
def test_str_eq_transitive
|
||||
combination(STRINGS, STRINGS, STRINGS) {|s1, 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
|
||||
|
@ -268,15 +268,15 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
if b(s1) == b(s2) and
|
||||
(s1.ascii_only? && s2.ascii_only? or
|
||||
s1.encoding == s2.encoding) then
|
||||
assert(s1 == s2, desc_eq)
|
||||
assert(!(s1 != s2))
|
||||
assert_operator(s1, :==, s2, desc_eq)
|
||||
assert_not_operator(s1, :!=, s2)
|
||||
assert_equal(0, s1 <=> s2)
|
||||
assert(s1.eql?(s2), desc_eq)
|
||||
assert_operator(s1, :eql?, s2, desc_eq)
|
||||
else
|
||||
assert(!(s1 == s2), "!(#{desc_eq})")
|
||||
assert(s1 != s2)
|
||||
assert_not_operator(s1, :==, s2, "!(#{desc_eq})")
|
||||
assert_operator(s1, :!=, s2)
|
||||
assert_not_equal(0, s1 <=> s2)
|
||||
assert(!s1.eql?(s2))
|
||||
assert_not_operator(s1, :eql?, s2)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
@ -286,7 +286,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
s = s1.dup
|
||||
if s1.ascii_only? || s2.ascii_only? || s1.encoding == s2.encoding
|
||||
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_str_enc_propagation(s, s1, s2)
|
||||
else
|
||||
|
@ -300,7 +300,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
t = ''.force_encoding(s.encoding)
|
||||
0.upto(s.length-1) {|i|
|
||||
u = s[i]
|
||||
assert(u.valid_encoding?) if s.valid_encoding?
|
||||
assert_predicate(u, :valid_encoding?) if s.valid_encoding?
|
||||
t << u
|
||||
}
|
||||
assert_equal(t, s)
|
||||
|
@ -312,7 +312,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
t = ''.force_encoding(s.encoding)
|
||||
0.upto(s.length-1) {|i|
|
||||
u = s[i,1]
|
||||
assert(u.valid_encoding?) if s.valid_encoding?
|
||||
assert_predicate(u, :valid_encoding?) if s.valid_encoding?
|
||||
t << u
|
||||
}
|
||||
assert_equal(t, s)
|
||||
|
@ -322,7 +322,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
t = ''.force_encoding(s.encoding)
|
||||
0.step(s.length-1, 2) {|i|
|
||||
u = s[i,2]
|
||||
assert(u.valid_encoding?) if s.valid_encoding?
|
||||
assert_predicate(u, :valid_encoding?) if s.valid_encoding?
|
||||
t << u
|
||||
}
|
||||
assert_equal(t, s)
|
||||
|
@ -334,7 +334,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
if s1.ascii_only? || s2.ascii_only? || s1.encoding == s2.encoding
|
||||
t = enccall(s1, :[], s2)
|
||||
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_match(/#{Regexp.escape(b(s2))}/, b(s1))
|
||||
if s1.valid_encoding?
|
||||
|
@ -362,7 +362,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
assert_nil(t, desc)
|
||||
next
|
||||
end
|
||||
assert(t.valid_encoding?) if s.valid_encoding?
|
||||
assert_predicate(t, :valid_encoding?) if s.valid_encoding?
|
||||
if last < 0
|
||||
last += s.length
|
||||
end
|
||||
|
@ -393,7 +393,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
if last < 0
|
||||
last += s.length
|
||||
end
|
||||
assert(t.valid_encoding?) if s.valid_encoding?
|
||||
assert_predicate(t, :valid_encoding?) if s.valid_encoding?
|
||||
t2 = ''
|
||||
first.upto(last-1) {|i|
|
||||
c = s[i]
|
||||
|
@ -412,8 +412,8 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
assert_raise(IndexError) { t[i] = s2 }
|
||||
else
|
||||
t[i] = s2
|
||||
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
|
||||
assert(b(t).index(b(s2)))
|
||||
assert_predicate(t, :valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
|
||||
assert_send([b(t), :index, b(s2)])
|
||||
if s1.valid_encoding? && s2.valid_encoding?
|
||||
if i == s1.length && s2.empty?
|
||||
assert_nil(t[i])
|
||||
|
@ -440,9 +440,9 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
if i < -s1.length || s1.length < i
|
||||
assert_raise(IndexError) { t[i,len] = s2 }
|
||||
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
|
||||
assert(b(t).index(b(s2)))
|
||||
assert_send([b(t), :index, b(s2)])
|
||||
if s1.valid_encoding? && s2.valid_encoding?
|
||||
if i == s1.length && s2.empty?
|
||||
assert_nil(t[i])
|
||||
|
@ -486,7 +486,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
if !t[s2]
|
||||
else
|
||||
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
|
||||
}
|
||||
|
@ -500,8 +500,8 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
assert_raise(RangeError) { t[first..last] = s2 }
|
||||
else
|
||||
enccall(t, :[]=, first..last, s2)
|
||||
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
|
||||
assert(b(t).index(b(s2)))
|
||||
assert_predicate(t, :valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
|
||||
assert_send([b(t), :index, b(s2)])
|
||||
if s1.valid_encoding? && s2.valid_encoding?
|
||||
if first < 0
|
||||
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 }
|
||||
else
|
||||
enccall(t, :[]=, first...last, s2)
|
||||
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
|
||||
assert(b(t).index(b(s2)))
|
||||
assert_predicate(t, :valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
|
||||
assert_send([b(t), :index, b(s2)])
|
||||
if s1.valid_encoding? && s2.valid_encoding?
|
||||
if first < 0
|
||||
assert_equal(s2, t[s1.length+first, s2.length])
|
||||
|
@ -563,11 +563,11 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
begin
|
||||
t1 = s.capitalize
|
||||
rescue ArgumentError
|
||||
assert(!s.valid_encoding?)
|
||||
assert_not_predicate(s, :valid_encoding?)
|
||||
next
|
||||
end
|
||||
assert(t1.valid_encoding?) if s.valid_encoding?
|
||||
assert(t1.casecmp(s))
|
||||
assert_predicate(t1, :valid_encoding?) if s.valid_encoding?
|
||||
assert_operator(t1, :casecmp, s)
|
||||
t2 = s.dup
|
||||
t2.capitalize!
|
||||
assert_equal(t1, t2)
|
||||
|
@ -589,7 +589,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
def test_str_center
|
||||
combination(STRINGS, [0,1,2,3,10]) {|s1, 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|
|
||||
if s2.empty?
|
||||
|
@ -601,8 +601,8 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
next
|
||||
end
|
||||
t = enccall(s1, :center, width, s2)
|
||||
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
|
||||
assert(b(t).index(b(s1)))
|
||||
assert_predicate(t, :valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
|
||||
assert_send([b(t), :index, b(s1)])
|
||||
assert_str_enc_propagation(t, s1, s2) if (t != s1)
|
||||
}
|
||||
end
|
||||
|
@ -610,7 +610,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
def test_str_ljust
|
||||
combination(STRINGS, [0,1,2,3,10]) {|s1, 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|
|
||||
if s2.empty?
|
||||
|
@ -622,8 +622,8 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
next
|
||||
end
|
||||
t = enccall(s1, :ljust, width, s2)
|
||||
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
|
||||
assert(b(t).index(b(s1)))
|
||||
assert_predicate(t, :valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
|
||||
assert_send([b(t), :index, b(s1)])
|
||||
assert_str_enc_propagation(t, s1, s2) if (t != s1)
|
||||
}
|
||||
end
|
||||
|
@ -631,7 +631,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
def test_str_rjust
|
||||
combination(STRINGS, [0,1,2,3,10]) {|s1, 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|
|
||||
if s2.empty?
|
||||
|
@ -643,8 +643,8 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
next
|
||||
end
|
||||
t = enccall(s1, :rjust, width, s2)
|
||||
assert(t.valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
|
||||
assert(b(t).index(b(s1)))
|
||||
assert_predicate(t, :valid_encoding?) if s1.valid_encoding? && s2.valid_encoding?
|
||||
assert_send([b(t), :index, b(s1)])
|
||||
assert_str_enc_propagation(t, s1, s2) if (t != s1)
|
||||
}
|
||||
end
|
||||
|
@ -658,7 +658,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
next
|
||||
end
|
||||
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)
|
||||
t2 = s1.dup
|
||||
t2.chomp!(s2)
|
||||
|
@ -672,8 +672,8 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
desc = "#{encdump s}.chop"
|
||||
t = nil
|
||||
assert_nothing_raised(desc) { t = s.chop }
|
||||
assert(t.valid_encoding?) if s.valid_encoding?
|
||||
assert(b(s).index(b(t)))
|
||||
assert_predicate(t, :valid_encoding?) if s.valid_encoding?
|
||||
assert_send([b(s), :index, b(t)])
|
||||
t2 = s.dup
|
||||
t2.chop!
|
||||
assert_equal(t, t2)
|
||||
|
@ -684,8 +684,8 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
STRINGS.each {|s|
|
||||
t = s.dup
|
||||
t.clear
|
||||
assert(t.valid_encoding?)
|
||||
assert(t.empty?)
|
||||
assert_predicate(t, :valid_encoding?)
|
||||
assert_empty(t)
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -761,7 +761,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
next
|
||||
end
|
||||
t = enccall(s1, :delete, s2)
|
||||
assert(t.valid_encoding?)
|
||||
assert_predicate(t, :valid_encoding?)
|
||||
assert_equal(t.encoding, s1.encoding)
|
||||
assert_operator(t.length, :<=, s1.length)
|
||||
t2 = s1.dup
|
||||
|
@ -777,9 +777,9 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
next
|
||||
end
|
||||
t = s.downcase
|
||||
assert(t.valid_encoding?)
|
||||
assert_predicate(t, :valid_encoding?)
|
||||
assert_equal(t.encoding, s.encoding)
|
||||
assert(t.casecmp(s))
|
||||
assert_operator(t, :casecmp, s)
|
||||
t2 = s.dup
|
||||
t2.downcase!
|
||||
assert_equal(t, t2)
|
||||
|
@ -789,8 +789,8 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
def test_str_dump
|
||||
STRINGS.each {|s|
|
||||
t = s.dump
|
||||
assert(t.valid_encoding?)
|
||||
assert(t.ascii_only?)
|
||||
assert_predicate(t, :valid_encoding?)
|
||||
assert_predicate(t, :ascii_only?)
|
||||
u = eval(t)
|
||||
assert_equal(b(s), b(u))
|
||||
}
|
||||
|
@ -829,9 +829,9 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
def test_str_empty?
|
||||
STRINGS.each {|s|
|
||||
if s.length == 0
|
||||
assert(s.empty?)
|
||||
assert_empty(s)
|
||||
else
|
||||
assert(!s.empty?)
|
||||
assert_not_empty(s)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
@ -854,12 +854,12 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
end
|
||||
t = enccall(s1, :include?, s2)
|
||||
if t
|
||||
assert(b(s1).include?(b(s2)))
|
||||
assert(s1.index(s2))
|
||||
assert(s1.rindex(s2))
|
||||
assert_include(b(s1), b(s2))
|
||||
assert_send([s1, :index, s2])
|
||||
assert_send([s1, :rindex, s2])
|
||||
else
|
||||
assert(!s1.index(s2))
|
||||
assert(!s1.rindex(s2), "!#{encdump(s1)}.rindex(#{encdump(s2)})")
|
||||
assert_not_send([s1, :index, s2])
|
||||
assert_not_send([s1, :rindex, s2], "!#{encdump(s1)}.rindex(#{encdump(s2)})")
|
||||
end
|
||||
if s2.empty?
|
||||
assert_equal(true, t)
|
||||
|
@ -935,7 +935,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
end
|
||||
if 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 += s1.length if pos < 0
|
||||
re = /\A(.{0,#{pos2}})#{Regexp.escape(s2)}/m
|
||||
|
@ -1093,8 +1093,8 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
"#{encdump s}.slice!#{encdumpargs args}.encoding")
|
||||
end
|
||||
if [s, *args].all? {|o| !(String === o) || o.valid_encoding? }
|
||||
assert(r.valid_encoding?)
|
||||
assert(t.valid_encoding?)
|
||||
assert_predicate(r, :valid_encoding?)
|
||||
assert_predicate(t, :valid_encoding?)
|
||||
assert_equal(s.length, r.length + t.length)
|
||||
end
|
||||
}
|
||||
|
@ -1116,13 +1116,13 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
end
|
||||
t = enccall(s1, :split, s2)
|
||||
t.each {|r|
|
||||
assert(b(s1).include?(b(r)))
|
||||
assert_include(b(s1), b(r))
|
||||
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?
|
||||
t.each {|r|
|
||||
assert(r.valid_encoding?)
|
||||
assert_predicate(r, :valid_encoding?)
|
||||
}
|
||||
end
|
||||
}
|
||||
|
@ -1184,8 +1184,8 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
next
|
||||
end
|
||||
t1 = s.swapcase
|
||||
assert(t1.valid_encoding?) if s.valid_encoding?
|
||||
assert(t1.casecmp(s))
|
||||
assert_predicate(t1, :valid_encoding?) if s.valid_encoding?
|
||||
assert_operator(t1, :casecmp, s)
|
||||
t2 = s.dup
|
||||
t2.swapcase!
|
||||
assert_equal(t1, t2)
|
||||
|
@ -1298,8 +1298,8 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
next
|
||||
end
|
||||
t1 = s.upcase
|
||||
assert(t1.valid_encoding?)
|
||||
assert(t1.casecmp(s))
|
||||
assert_predicate(t1, :valid_encoding?)
|
||||
assert_operator(t1, :casecmp, s)
|
||||
t2 = s.dup
|
||||
t2.upcase!
|
||||
assert_equal(t1, t2)
|
||||
|
@ -1321,7 +1321,7 @@ class TestM17NComb < Test::Unit::TestCase
|
|||
#puts encdump(s)
|
||||
t = s.succ
|
||||
if s.valid_encoding?
|
||||
assert(t.valid_encoding?, "#{encdump s}.succ.valid_encoding?")
|
||||
assert_predicate(t, :valid_encoding?, "#{encdump s}.succ.valid_encoding?")
|
||||
end
|
||||
s = t
|
||||
}
|
||||
|
|
|
@ -484,10 +484,10 @@ class TestMarshal < Test::Unit::TestCase
|
|||
def test_marshal_load_should_not_taint_classes
|
||||
bug7325 = '[ruby-core:49198]'
|
||||
for c in [TestClass, TestModule]
|
||||
assert(!c.tainted?)
|
||||
assert_not_predicate(c, :tainted?)
|
||||
c2 = Marshal.load(Marshal.dump(c).taint)
|
||||
assert_same(c, c2)
|
||||
assert(!c.tainted?, bug7325)
|
||||
assert_not_predicate(c, :tainted?, bug7325)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -3,12 +3,12 @@ require 'test/unit'
|
|||
class TestMath < Test::Unit::TestCase
|
||||
def assert_infinity(a, *rest)
|
||||
rest = ["not infinity: #{a.inspect}"] if rest.empty?
|
||||
assert(!a.finite?, *rest)
|
||||
assert_not_predicate(a, :finite?, *rest)
|
||||
end
|
||||
|
||||
def assert_nan(a, *rest)
|
||||
rest = ["not nan: #{a.inspect}"] if rest.empty?
|
||||
assert(a.nan?, *rest)
|
||||
assert_predicate(a, :nan?, *rest)
|
||||
end
|
||||
|
||||
def check(a, b)
|
||||
|
@ -49,9 +49,9 @@ class TestMath < Test::Unit::TestCase
|
|||
def test_tan
|
||||
check(0.0, Math.tan(0 * 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))
|
||||
assert(Math.tan(6 * Math::PI / 4).abs > 1024)
|
||||
assert_operator(Math.tan(6 * Math::PI / 4).abs, :>, 1024)
|
||||
end
|
||||
|
||||
def test_acos
|
||||
|
|
|
@ -391,14 +391,16 @@ class TestMethod < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_default_accessibility
|
||||
assert T.public_instance_methods.include?(:normal_method), 'normal methods are public by default'
|
||||
assert !T.public_instance_methods.include?(:initialize), '#initialize is private'
|
||||
assert !T.public_instance_methods.include?(:initialize_copy), '#initialize_copy is private'
|
||||
assert !T.public_instance_methods.include?(:initialize_clone), '#initialize_clone is private'
|
||||
assert !T.public_instance_methods.include?(:initialize_dup), '#initialize_dup is private'
|
||||
assert !T.public_instance_methods.include?(:respond_to_missing?), '#respond_to_missing? is private'
|
||||
assert !M.public_instance_methods.include?(:func), 'module methods are private by default'
|
||||
assert M.public_instance_methods.include?(:meth), 'normal methods are public by default'
|
||||
tmethods = T.public_instance_methods
|
||||
assert_include tmethods, :normal_method, 'normal methods are public by default'
|
||||
assert_not_include tmethods, :initialize, '#initialize is private'
|
||||
assert_not_include tmethods, :initialize_copy, '#initialize_copy is private'
|
||||
assert_not_include tmethods, :initialize_clone, '#initialize_clone is private'
|
||||
assert_not_include tmethods, :initialize_dup, '#initialize_dup is private'
|
||||
assert_not_include tmethods, :respond_to_missing?, '#respond_to_missing? is private'
|
||||
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
|
||||
|
||||
define_method(:pm0) {||}
|
||||
|
@ -579,7 +581,7 @@ class TestMethod < Test::Unit::TestCase
|
|||
end
|
||||
assert_equal(c, x.method(:foo).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
|
||||
|
||||
def test_included
|
||||
|
|
|
@ -151,50 +151,50 @@ class TestModule < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_GE # '>='
|
||||
assert(Mixin >= User)
|
||||
assert(Mixin >= Mixin)
|
||||
assert(!(User >= Mixin))
|
||||
assert_operator(Mixin, :>=, User)
|
||||
assert_operator(Mixin, :>=, Mixin)
|
||||
assert_not_operator(User, :>=, Mixin)
|
||||
|
||||
assert(Object >= String)
|
||||
assert(String >= String)
|
||||
assert(!(String >= Object))
|
||||
assert_operator(Object, :>=, String)
|
||||
assert_operator(String, :>=, String)
|
||||
assert_not_operator(String, :>=, Object)
|
||||
end
|
||||
|
||||
def test_GT # '>'
|
||||
assert(Mixin > User)
|
||||
assert(!(Mixin > Mixin))
|
||||
assert(!(User > Mixin))
|
||||
assert_operator(Mixin, :>, User)
|
||||
assert_not_operator(Mixin, :>, Mixin)
|
||||
assert_not_operator(User, :>, Mixin)
|
||||
|
||||
assert(Object > String)
|
||||
assert(!(String > String))
|
||||
assert(!(String > Object))
|
||||
assert_operator(Object, :>, String)
|
||||
assert_not_operator(String, :>, String)
|
||||
assert_not_operator(String, :>, Object)
|
||||
end
|
||||
|
||||
def test_LE # '<='
|
||||
assert(User <= Mixin)
|
||||
assert(Mixin <= Mixin)
|
||||
assert(!(Mixin <= User))
|
||||
assert_operator(User, :<=, Mixin)
|
||||
assert_operator(Mixin, :<=, Mixin)
|
||||
assert_not_operator(Mixin, :<=, User)
|
||||
|
||||
assert(String <= Object)
|
||||
assert(String <= String)
|
||||
assert(!(Object <= String))
|
||||
assert_operator(String, :<=, Object)
|
||||
assert_operator(String, :<=, String)
|
||||
assert_not_operator(Object, :<=, String)
|
||||
end
|
||||
|
||||
def test_LT # '<'
|
||||
assert(User < Mixin)
|
||||
assert(!(Mixin < Mixin))
|
||||
assert(!(Mixin < User))
|
||||
assert_operator(User, :<, Mixin)
|
||||
assert_not_operator(Mixin, :<, Mixin)
|
||||
assert_not_operator(Mixin, :<, User)
|
||||
|
||||
assert(String < Object)
|
||||
assert(!(String < String))
|
||||
assert(!(Object < String))
|
||||
assert_operator(String, :<, Object)
|
||||
assert_not_operator(String, :<, String)
|
||||
assert_not_operator(Object, :<, String)
|
||||
end
|
||||
|
||||
def test_VERY_EQUAL # '==='
|
||||
assert(Object === self)
|
||||
assert(Test::Unit::TestCase === self)
|
||||
assert(TestModule === self)
|
||||
assert(!(String === self))
|
||||
assert_operator(Object, :===, self)
|
||||
assert_operator(Test::Unit::TestCase, :===, self)
|
||||
assert_operator(TestModule, :===, self)
|
||||
assert_not_operator(String, :===, self)
|
||||
end
|
||||
|
||||
def test_ancestors
|
||||
|
@ -214,7 +214,7 @@ class TestModule < Test::Unit::TestCase
|
|||
def test_class_eval
|
||||
Other.class_eval("CLASS_EVAL = 1")
|
||||
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 })
|
||||
|
||||
Other.class_eval("@@class_eval = 'a'")
|
||||
|
@ -234,10 +234,10 @@ class TestModule < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_const_defined?
|
||||
assert(Math.const_defined?(:PI))
|
||||
assert(Math.const_defined?("PI"))
|
||||
assert(!Math.const_defined?(:IP))
|
||||
assert(!Math.const_defined?("IP"))
|
||||
assert_operator(Math, :const_defined?, :PI)
|
||||
assert_operator(Math, :const_defined?, "PI")
|
||||
assert_not_operator(Math, :const_defined?, :IP)
|
||||
assert_not_operator(Math, :const_defined?, "IP")
|
||||
end
|
||||
|
||||
def test_bad_constants
|
||||
|
@ -304,9 +304,9 @@ class TestModule < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_const_set
|
||||
assert(!Other.const_defined?(:KOALA))
|
||||
assert_not_operator(Other, :const_defined?, :KOALA)
|
||||
Other.const_set(:KOALA, 99)
|
||||
assert(Other.const_defined?(:KOALA))
|
||||
assert_operator(Other, :const_defined?, :KOALA)
|
||||
assert_equal(99, Other::KOALA)
|
||||
Other.const_set("WOMBAT", "Hi")
|
||||
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.count; @count; 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)
|
||||
assert_equal(1, n.count)
|
||||
n.count = 0
|
||||
|
@ -350,7 +350,7 @@ class TestModule < Test::Unit::TestCase
|
|||
|
||||
b = a.dup
|
||||
|
||||
refute_equal original, b.inspect, bug6454
|
||||
assert_not_equal original, b.inspect, bug6454
|
||||
end
|
||||
|
||||
def test_public_include
|
||||
|
@ -437,9 +437,9 @@ class TestModule < Test::Unit::TestCase
|
|||
def test_module_eval
|
||||
User.module_eval("MODULE_EVAL = 1")
|
||||
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)")
|
||||
assert(!User.constants.include?(:MODULE_EVAL))
|
||||
assert_not_include(User.constants, :MODULE_EVAL)
|
||||
end
|
||||
|
||||
def test_name
|
||||
|
@ -1264,7 +1264,7 @@ class TestModule < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_constants_with_private_constant
|
||||
assert(!(::TestModule).constants.include?(:PrivateClass))
|
||||
assert_not_include(::TestModule.constants, :PrivateClass)
|
||||
end
|
||||
|
||||
def test_toplevel_private_constant
|
||||
|
|
|
@ -32,7 +32,7 @@ class TestNumeric < Test::Unit::TestCase
|
|||
end
|
||||
assert_equal(2, 1 + a)
|
||||
assert_equal(0, 1 <=> a)
|
||||
assert(1 <= a)
|
||||
assert_operator(1, :<=, a)
|
||||
|
||||
DummyNumeric.class_eval do
|
||||
remove_method :coerce
|
||||
|
@ -93,11 +93,11 @@ class TestNumeric < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_real_p
|
||||
assert(Numeric.new.real?)
|
||||
assert_predicate(Numeric.new, :real?)
|
||||
end
|
||||
|
||||
def test_integer_p
|
||||
assert(!Numeric.new.integer?)
|
||||
assert_not_predicate(Numeric.new, :integer?)
|
||||
end
|
||||
|
||||
def test_abs
|
||||
|
@ -127,7 +127,7 @@ class TestNumeric < Test::Unit::TestCase
|
|||
def ==(x); true; end
|
||||
end
|
||||
|
||||
assert(DummyNumeric.new.zero?)
|
||||
assert_predicate(DummyNumeric.new, :zero?)
|
||||
|
||||
ensure
|
||||
DummyNumeric.class_eval do
|
||||
|
@ -274,8 +274,8 @@ class TestNumeric < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_eql
|
||||
assert(1 == 1.0)
|
||||
assert(!(1.eql?(1.0)))
|
||||
assert(!(1.eql?(2)))
|
||||
assert_equal(1, 1.0)
|
||||
assert_not_operator(1, :eql?, 1.0)
|
||||
assert_not_operator(1, :eql?, 2)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -411,8 +411,8 @@ class TestObject < Test::Unit::TestCase
|
|||
assert_equal([:foo], foo.foobar);
|
||||
assert_equal([:foo, 1], foo.foobar(1));
|
||||
assert_equal([:foo, 1, 2, 3, 4, 5], foo.foobar(1, 2, 3, 4, 5));
|
||||
assert(foo.respond_to?(:foobar))
|
||||
assert_equal(false, foo.respond_to?(:foobarbaz))
|
||||
assert_respond_to(foo, :foobar)
|
||||
assert_not_respond_to(foo, :foobarbaz)
|
||||
assert_raise(NoMethodError) do
|
||||
foo.foobarbaz
|
||||
end
|
||||
|
|
|
@ -39,13 +39,13 @@ End
|
|||
h = {}
|
||||
ObjectSpace.count_objects(h)
|
||||
assert_kind_of(Hash, h)
|
||||
assert(h.keys.all? {|x| x.is_a?(Symbol) || x.is_a?(Integer) })
|
||||
assert(h.values.all? {|x| x.is_a?(Integer) })
|
||||
assert_empty(h.keys.delete_if {|x| x.is_a?(Symbol) || x.is_a?(Integer) })
|
||||
assert_empty(h.values.delete_if {|x| x.is_a?(Integer) })
|
||||
|
||||
h = ObjectSpace.count_objects
|
||||
assert_kind_of(Hash, h)
|
||||
assert(h.keys.all? {|x| x.is_a?(Symbol) || x.is_a?(Integer) })
|
||||
assert(h.values.all? {|x| x.is_a?(Integer) })
|
||||
assert_empty(h.keys.delete_if {|x| x.is_a?(Symbol) || x.is_a?(Integer) })
|
||||
assert_empty(h.values.delete_if {|x| x.is_a?(Integer) })
|
||||
|
||||
assert_raise(TypeError) { ObjectSpace.count_objects(1) }
|
||||
|
||||
|
|
|
@ -826,7 +826,7 @@ x = __ENCODING__
|
|||
def test_all_symbols
|
||||
x = Symbol.all_symbols
|
||||
assert_kind_of(Array, x)
|
||||
assert(x.all? {|s| s.is_a?(Symbol) })
|
||||
assert_empty(x.reject {|s| s.is_a?(Symbol) })
|
||||
end
|
||||
|
||||
def test_is_class_id
|
||||
|
|
|
@ -415,9 +415,9 @@ class TestRubyPrimitive < Test::Unit::TestCase
|
|||
end
|
||||
x.to_a_called = false
|
||||
[0, *x]
|
||||
assert(x.to_a_called, bug3658)
|
||||
assert_predicate(x, :to_a_called, bug3658)
|
||||
x.to_a_called = false
|
||||
[0, *x, 2]
|
||||
assert(x.to_a_called, bug3658)
|
||||
assert_predicate(x, :to_a_called, bug3658)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1112,7 +1112,7 @@ class TestProc < Test::Unit::TestCase
|
|||
assert_match(/^#<Proc:0x\h+ \(lambda\)>$/, method(:p).to_proc.to_s)
|
||||
x = proc {}
|
||||
x.taint
|
||||
assert(x.to_s.tainted?)
|
||||
assert_predicate(x.to_s, :tainted?)
|
||||
end
|
||||
|
||||
@@line_of_source_location_test = __LINE__ + 1
|
||||
|
|
|
@ -473,7 +473,7 @@ class TestProcess < Test::Unit::TestCase
|
|||
# problem occur with valgrind
|
||||
#Process.wait Process.spawn(*ECHO["a"], STDOUT=>:close, STDERR=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644])
|
||||
#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])
|
||||
assert_equal("c", File.read("out").chomp)
|
||||
File.open("out", "w") {|f|
|
||||
|
@ -885,7 +885,7 @@ class TestProcess < Test::Unit::TestCase
|
|||
ret = system(str)
|
||||
status = $?
|
||||
assert_equal(false, ret)
|
||||
assert(status.exited?)
|
||||
assert_predicate(status, :exited?)
|
||||
assert_equal(5, status.exitstatus)
|
||||
assert_equal("haha pid=#{status.pid} ppid=#{$$}", File.read("result"))
|
||||
}
|
||||
|
@ -902,7 +902,7 @@ class TestProcess < Test::Unit::TestCase
|
|||
Process.wait pid
|
||||
status = $?
|
||||
assert_equal(pid, status.pid)
|
||||
assert(status.exited?)
|
||||
assert_predicate(status, :exited?)
|
||||
assert_equal(6, status.exitstatus)
|
||||
assert_equal("hihi pid=#{status.pid} ppid=#{$$}", File.read("result"))
|
||||
}
|
||||
|
@ -921,7 +921,7 @@ class TestProcess < Test::Unit::TestCase
|
|||
io.close
|
||||
status = $?
|
||||
assert_equal(pid, status.pid)
|
||||
assert(status.exited?)
|
||||
assert_predicate(status, :exited?)
|
||||
assert_equal(7, status.exitstatus)
|
||||
assert_equal("fufu pid=#{status.pid} ppid=#{$$}", result)
|
||||
}
|
||||
|
@ -940,7 +940,7 @@ class TestProcess < Test::Unit::TestCase
|
|||
io.close
|
||||
status = $?
|
||||
assert_equal(pid, status.pid)
|
||||
assert(status.exited?)
|
||||
assert_predicate(status, :exited?)
|
||||
assert_equal(7, status.exitstatus)
|
||||
assert_equal("fufumm pid=#{status.pid} ppid=#{$$}", result)
|
||||
}
|
||||
|
@ -966,7 +966,7 @@ class TestProcess < Test::Unit::TestCase
|
|||
Process.wait pid
|
||||
status = $?
|
||||
assert_equal(pid, status.pid)
|
||||
assert(status.exited?)
|
||||
assert_predicate(status, :exited?)
|
||||
assert_equal(6, status.exitstatus)
|
||||
if windows?
|
||||
expected = "hehe ppid=#{status.pid}"
|
||||
|
@ -990,7 +990,7 @@ class TestProcess < Test::Unit::TestCase
|
|||
ret = system("#{RUBY} script1 || #{RUBY} script2")
|
||||
status = $?
|
||||
assert_equal(false, ret)
|
||||
assert(status.exited?)
|
||||
assert_predicate(status, :exited?)
|
||||
result1 = File.read("result1")
|
||||
result2 = File.read("result2")
|
||||
assert_match(/\Ataka pid=\d+ ppid=\d+\z/, result1)
|
||||
|
@ -1021,8 +1021,8 @@ class TestProcess < Test::Unit::TestCase
|
|||
pid = spawn("#{RUBY} script1 || #{RUBY} script2")
|
||||
Process.wait pid
|
||||
status = $?
|
||||
assert(status.exited?)
|
||||
assert(!status.success?)
|
||||
assert_predicate(status, :exited?)
|
||||
assert_not_predicate(status, :success?)
|
||||
result1 = File.read("result1")
|
||||
result2 = File.read("result2")
|
||||
assert_match(/\Ataku pid=\d+ ppid=\d+\z/, result1)
|
||||
|
@ -1035,14 +1035,14 @@ class TestProcess < Test::Unit::TestCase
|
|||
pid = spawn(bat, "foo 'bar'")
|
||||
Process.wait pid
|
||||
status = $?
|
||||
assert(status.exited?)
|
||||
assert(status.success?)
|
||||
assert_predicate(status, :exited?)
|
||||
assert_predicate(status, :success?)
|
||||
assert_equal(%["foo 'bar'"\n], File.read("out"), '[ruby-core:22960]')
|
||||
pid = spawn(%[#{bat.dump} "foo 'bar'"])
|
||||
Process.wait pid
|
||||
status = $?
|
||||
assert(status.exited?)
|
||||
assert(status.success?)
|
||||
assert_predicate(status, :exited?)
|
||||
assert_predicate(status, :success?)
|
||||
assert_equal(%["foo 'bar'"\n], File.read("out"), '[ruby-core:22960]')
|
||||
end
|
||||
}
|
||||
|
@ -1062,8 +1062,8 @@ class TestProcess < Test::Unit::TestCase
|
|||
result = io.read
|
||||
io.close
|
||||
status = $?
|
||||
assert(status.exited?)
|
||||
assert(!status.success?)
|
||||
assert_predicate(status, :exited?)
|
||||
assert_not_predicate(status, :success?)
|
||||
assert_match(/\Atako pid=\d+ ppid=\d+\ntika pid=\d+ ppid=\d+\n\z/, result)
|
||||
assert_not_equal(result[/\d+/].to_i, status.pid)
|
||||
|
||||
|
@ -1095,8 +1095,8 @@ class TestProcess < Test::Unit::TestCase
|
|||
pid = spawn RUBY, "s"
|
||||
Process.wait pid
|
||||
status = $?
|
||||
assert(status.exited?)
|
||||
assert(!status.success?)
|
||||
assert_predicate(status, :exited?)
|
||||
assert_not_predicate(status, :success?)
|
||||
result1 = File.read("result1")
|
||||
result2 = File.read("result2")
|
||||
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("t") { Process.wait spawn([RUBY, "edc"]) }
|
||||
assert($?.success?)
|
||||
assert_predicate($?, :success?)
|
||||
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) } }
|
||||
assert($?.success?)
|
||||
assert_predicate($?, :success?)
|
||||
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'])"
|
||||
assert(status.success?)
|
||||
assert_predicate(status, :success?)
|
||||
status = run_in_child "STDIN.reopen('f'); exec([#{RUBY.dump}, 'ik,'])"
|
||||
assert(!status.success?)
|
||||
assert_not_predicate(status, :success?)
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -1306,22 +1306,22 @@ class TestProcess < Test::Unit::TestCase
|
|||
|
||||
def test_uid_re_exchangeable_p
|
||||
r = Process::UID.re_exchangeable?
|
||||
assert(true == r || false == r)
|
||||
assert_include([true, false], r)
|
||||
end
|
||||
|
||||
def test_gid_re_exchangeable_p
|
||||
r = Process::GID.re_exchangeable?
|
||||
assert(true == r || false == r)
|
||||
assert_include([true, false], r)
|
||||
end
|
||||
|
||||
def test_uid_sid_available?
|
||||
r = Process::UID.sid_available?
|
||||
assert(true == r || false == r)
|
||||
assert_include([true, false], r)
|
||||
end
|
||||
|
||||
def test_gid_sid_available?
|
||||
r = Process::GID.sid_available?
|
||||
assert(true == r || false == r)
|
||||
assert_include([true, false], r)
|
||||
end
|
||||
|
||||
def test_pst_inspect
|
||||
|
@ -1360,7 +1360,7 @@ class TestProcess < Test::Unit::TestCase
|
|||
system({"RUBYLIB"=>nil}, RUBY, "--disable-gems", "-e", "exit true")
|
||||
status = $?
|
||||
}
|
||||
assert(status.success?, "[ruby-dev:38105]")
|
||||
assert_predicate(status, :success?, "[ruby-dev:38105]")
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -1514,7 +1514,7 @@ class TestProcess < Test::Unit::TestCase
|
|||
def test_popen_cloexec
|
||||
return unless defined? Fcntl::FD_CLOEXEC
|
||||
IO.popen([RUBY, "-e", ""]) {|io|
|
||||
assert(io.close_on_exec?)
|
||||
assert_predicate(io, :close_on_exec?)
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -405,14 +405,14 @@ END
|
|||
|
||||
def test_random_equal
|
||||
r = Random.new(0)
|
||||
assert(r == r)
|
||||
assert(r == r.dup)
|
||||
assert_equal(r, r)
|
||||
assert_equal(r, r.dup)
|
||||
r1 = r.dup
|
||||
r2 = r.dup
|
||||
r1.rand(0x100)
|
||||
assert(r1 != r2)
|
||||
assert_not_equal(r1, r2)
|
||||
r2.rand(0x100)
|
||||
assert(r1 == r2)
|
||||
assert_equal(r1, r2)
|
||||
end
|
||||
|
||||
def test_fork_shuffle
|
||||
|
@ -421,7 +421,7 @@ END
|
|||
raise 'default seed is not set' if srand == 0
|
||||
end
|
||||
p2, st = Process.waitpid2(pid)
|
||||
assert(st.success?, "#{st.inspect}")
|
||||
assert_predicate(st, :success?, "#{st.inspect}")
|
||||
rescue NotImplementedError, ArgumentError
|
||||
end
|
||||
|
||||
|
|
|
@ -97,36 +97,36 @@ class TestRange < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_exclude_end
|
||||
assert(!((0..1).exclude_end?))
|
||||
assert((0...1).exclude_end?)
|
||||
assert_not_predicate(0..1, :exclude_end?)
|
||||
assert_predicate(0...1, :exclude_end?)
|
||||
end
|
||||
|
||||
def test_eq
|
||||
r = (0..1)
|
||||
assert(r == r)
|
||||
assert(r == (0..1))
|
||||
assert(r != 0)
|
||||
assert(r != (1..2))
|
||||
assert(r != (0..2))
|
||||
assert(r != (0...1))
|
||||
assert_equal(r, r)
|
||||
assert_equal(r, (0..1))
|
||||
assert_not_equal(r, 0)
|
||||
assert_not_equal(r, (1..2))
|
||||
assert_not_equal(r, (0..2))
|
||||
assert_not_equal(r, (0...1))
|
||||
subclass = Class.new(Range)
|
||||
assert(r == subclass.new(0,1))
|
||||
assert_equal(r, subclass.new(0,1))
|
||||
end
|
||||
|
||||
def test_eql
|
||||
r = (0..1)
|
||||
assert(r.eql?(r))
|
||||
assert(r.eql?(0..1))
|
||||
assert(!r.eql?(0))
|
||||
assert(!r.eql?(1..2))
|
||||
assert(!r.eql?(0..2))
|
||||
assert(!r.eql?(0...1))
|
||||
assert_operator(r, :eql?, r)
|
||||
assert_operator(r, :eql?, 0..1)
|
||||
assert_not_operator(r, :eql?, 0)
|
||||
assert_not_operator(r, :eql?, 1..2)
|
||||
assert_not_operator(r, :eql?, 0..2)
|
||||
assert_not_operator(r, :eql?, 0...1)
|
||||
subclass = Class.new(Range)
|
||||
assert(r.eql?(subclass.new(0,1)))
|
||||
assert_operator(r, :eql?, subclass.new(0,1))
|
||||
end
|
||||
|
||||
def test_hash
|
||||
assert((0..1).hash.is_a?(Fixnum))
|
||||
assert_kind_of(Fixnum, (0..1).hash)
|
||||
end
|
||||
|
||||
def test_step
|
||||
|
@ -274,25 +274,25 @@ class TestRange < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_eqq
|
||||
assert((0..10) === 5)
|
||||
assert(!((0..10) === 11))
|
||||
assert_operator(0..10, :===, 5)
|
||||
assert_not_operator(0..10, :===, 11)
|
||||
end
|
||||
|
||||
def test_include
|
||||
assert(("a".."z").include?("c"))
|
||||
assert(!(("a".."z").include?("5")))
|
||||
assert(("a"..."z").include?("y"))
|
||||
assert(!(("a"..."z").include?("z")))
|
||||
assert(!(("a".."z").include?("cc")))
|
||||
assert((0...10).include?(5))
|
||||
assert_include("a".."z", "c")
|
||||
assert_not_include("a".."z", "5")
|
||||
assert_include("a"..."z", "y")
|
||||
assert_not_include("a"..."z", "z")
|
||||
assert_not_include("a".."z", "cc")
|
||||
assert_include(0...10, 5)
|
||||
end
|
||||
|
||||
def test_cover
|
||||
assert(("a".."z").cover?("c"))
|
||||
assert(!(("a".."z").cover?("5")))
|
||||
assert(("a"..."z").cover?("y"))
|
||||
assert(!(("a"..."z").cover?("z")))
|
||||
assert(("a".."z").cover?("cc"))
|
||||
assert_operator("a".."z", :cover?, "c")
|
||||
assert_not_operator("a".."z", :cover?, "5")
|
||||
assert_operator("a"..."z", :cover?, "y")
|
||||
assert_not_operator("a"..."z", :cover?, "z")
|
||||
assert_operator("a".."z", :cover?, "cc")
|
||||
end
|
||||
|
||||
def test_beg_len
|
||||
|
@ -332,14 +332,14 @@ class TestRange < Test::Unit::TestCase
|
|||
x = CyclicRange.allocate; x.send(:initialize, x, 1)
|
||||
y = CyclicRange.allocate; y.send(:initialize, y, 1)
|
||||
Timeout.timeout(1) {
|
||||
assert x == y
|
||||
assert x.eql? y
|
||||
assert_equal x, y
|
||||
assert_operator x, :eql?, y
|
||||
}
|
||||
|
||||
z = CyclicRange.allocate; z.send(:initialize, z, :another)
|
||||
Timeout.timeout(1) {
|
||||
assert x != z
|
||||
assert !x.eql?(z)
|
||||
assert_not_equal x, z
|
||||
assert_not_operator x, :eql?, z
|
||||
}
|
||||
|
||||
x = CyclicRange.allocate
|
||||
|
@ -347,8 +347,8 @@ class TestRange < Test::Unit::TestCase
|
|||
x.send(:initialize, y, 1)
|
||||
y.send(:initialize, x, 1)
|
||||
Timeout.timeout(1) {
|
||||
assert x == y
|
||||
assert x.eql?(y)
|
||||
assert_equal x, y
|
||||
assert_operator x, :eql?, y
|
||||
}
|
||||
|
||||
x = CyclicRange.allocate
|
||||
|
@ -356,8 +356,8 @@ class TestRange < Test::Unit::TestCase
|
|||
x.send(:initialize, z, 1)
|
||||
z.send(:initialize, x, :other)
|
||||
Timeout.timeout(1) {
|
||||
assert x != z
|
||||
assert !x.eql?(z)
|
||||
assert_not_equal x, z
|
||||
assert_not_operator x, :eql?, z
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -484,7 +484,7 @@ class TestRange < Test::Unit::TestCase
|
|||
when Float then 65
|
||||
when Integer then Math.log(to-from+(range.exclude_end? ? 0 : 1), 2).to_i + 1
|
||||
end
|
||||
assert yielded.size <= max
|
||||
assert_operator yielded.size, :<=, max
|
||||
|
||||
# (2) coverage test
|
||||
expect = if search < from
|
||||
|
@ -502,22 +502,23 @@ class TestRange < Test::Unit::TestCase
|
|||
# (4) end of range test
|
||||
case
|
||||
when range.exclude_end?
|
||||
assert !yielded.include?(to)
|
||||
assert r != to
|
||||
assert_not_include yielded, to
|
||||
assert_not_equal r, to
|
||||
when search >= to
|
||||
assert yielded.include?(to)
|
||||
assert_include yielded, to
|
||||
assert_equal search == to ? to : nil, r
|
||||
end
|
||||
|
||||
# start of range test
|
||||
if search <= from
|
||||
assert yielded.include?(from)
|
||||
assert_include yielded, from
|
||||
assert_equal from, r
|
||||
end
|
||||
|
||||
# (5) out of range test
|
||||
yielded.each do |val|
|
||||
assert from <= val && val.send(cmp, to)
|
||||
assert_operator from, :<=, val
|
||||
assert_send [val, cmp, to]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -299,7 +299,7 @@ class Rational_Test < Test::Unit::TestCase
|
|||
assert_raise(ZeroDivisionError){Rational(1, 3) / Rational(0)}
|
||||
|
||||
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
|
||||
|
||||
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.0))
|
||||
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
|
||||
|
||||
def test_expt
|
||||
|
@ -708,8 +708,8 @@ class Rational_Test < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_eqeq
|
||||
assert(Rational(1,1) == Rational(1))
|
||||
assert(Rational(-1,1) == Rational(-1))
|
||||
assert_equal(Rational(1,1), Rational(1))
|
||||
assert_equal(Rational(-1,1), Rational(-1))
|
||||
|
||||
assert_equal(false, 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]'
|
||||
c = Rational(1,2)
|
||||
c.freeze
|
||||
assert(c.frozen?)
|
||||
assert_predicate(c, :frozen?)
|
||||
result = c.marshal_load([2,3]) rescue :fail
|
||||
assert_equal(:fail, result, bug3656)
|
||||
end
|
||||
|
@ -1121,7 +1121,7 @@ class Rational_Test < Test::Unit::TestCase
|
|||
assert_equal(0.5, 1.0.quo(2))
|
||||
assert_equal(Rational(1,4), Rational(1,2).quo(2))
|
||||
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(5000000000.0, 10000000000.fdiv(2))
|
||||
|
|
|
@ -152,7 +152,7 @@ class TestRegexp < Test::Unit::TestCase
|
|||
|
||||
def test_assign_named_capture_to_reserved_word
|
||||
/(?<nil>.)/ =~ "a"
|
||||
assert(!local_variables.include?(:nil), "[ruby-dev:32675]")
|
||||
assert_not_include(local_variables, :nil, "[ruby-dev:32675]")
|
||||
end
|
||||
|
||||
def test_match_regexp
|
||||
|
@ -554,11 +554,11 @@ class TestRegexp < Test::Unit::TestCase
|
|||
$SAFE = 3
|
||||
/foo/.match("foo")
|
||||
end.value
|
||||
assert(m.tainted?)
|
||||
assert_predicate(m, :tainted?)
|
||||
assert_nothing_raised('[ruby-core:26137]') {
|
||||
m = proc {$SAFE = 3; %r"#{ }"o}.call
|
||||
}
|
||||
assert(m.tainted?)
|
||||
assert_predicate(m, :tainted?)
|
||||
end
|
||||
|
||||
def check(re, ss, fs = [], msg = nil)
|
||||
|
@ -1052,6 +1052,6 @@ class TestRegexp < Test::Unit::TestCase
|
|||
"Expected #{re.inspect} to\n" +
|
||||
errs.map {|str, match| "\t#{'not ' unless match}match #{str.inspect}"}.join(",\n")
|
||||
}
|
||||
assert(errs.empty?, msg)
|
||||
assert_empty(errs, msg)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -477,7 +477,7 @@ class TestRequire < Test::Unit::TestCase
|
|||
$: << tmp
|
||||
open(File.join(tmp, "foo.rb"), "w") {}
|
||||
require "foo"
|
||||
assert(Encoding.compatible?(tmp, $"[0]), bug6377)
|
||||
assert_send([Encoding, :compatible?, tmp, $"[0]], bug6377)
|
||||
}
|
||||
ensure
|
||||
$:.replace(loadpath)
|
||||
|
|
|
@ -186,7 +186,7 @@ class TestRubyOptions < Test::Unit::TestCase
|
|||
|
||||
d = Dir.tmpdir
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -320,7 +320,7 @@ class TestSprintf < Test::Unit::TestCase
|
|||
s2 = sprintf("%0x", -0x40000001)
|
||||
b1 = (/\.\./ =~ s1) != nil
|
||||
b2 = (/\.\./ =~ s2) != nil
|
||||
assert(b1 == b2, "[ruby-dev:33224]")
|
||||
assert_equal(b1, b2, "[ruby-dev:33224]")
|
||||
end
|
||||
|
||||
def test_named_untyped
|
||||
|
|
|
@ -4,14 +4,14 @@ class TestStringchar < Test::Unit::TestCase
|
|||
def test_string
|
||||
assert_equal("abcd", "abcd")
|
||||
assert_match(/abcd/, "abcd")
|
||||
assert("abcd" === "abcd")
|
||||
assert_operator("abcd", :===, "abcd")
|
||||
# compile time string concatenation
|
||||
assert_equal("abcd", "ab" "cd")
|
||||
assert_equal("22aacd44", "#{22}aa" "cd#{44}")
|
||||
assert_equal("22aacd445566", "#{22}aa" "cd#{44}" "55" "#{66}")
|
||||
assert("abc" !~ /^$/)
|
||||
assert("abc\n" !~ /^$/)
|
||||
assert("abc" !~ /^d*$/)
|
||||
assert_operator("abc", :!~, /^$/)
|
||||
assert_operator("abc\n", :!~, /^$/)
|
||||
assert_operator("abc", :!~, /^d*$/)
|
||||
assert_equal(3, ("abc" =~ /d*$/))
|
||||
assert("" =~ /^$/)
|
||||
assert("\n" =~ /^$/)
|
||||
|
|
|
@ -189,14 +189,14 @@ module TestStruct
|
|||
o1 = klass1.new(1)
|
||||
o2 = klass1.new(1)
|
||||
o3 = klass2.new(1)
|
||||
assert(o1.==(o2))
|
||||
assert(o1 != o3)
|
||||
assert_equal(o1, o2)
|
||||
assert_not_equal(o1, o3)
|
||||
end
|
||||
|
||||
def test_hash
|
||||
klass = @Struct.new(:a)
|
||||
o = klass.new(1)
|
||||
assert(o.hash.is_a?(Fixnum))
|
||||
assert_kind_of(Fixnum, o.hash)
|
||||
end
|
||||
|
||||
def test_eql
|
||||
|
@ -205,8 +205,8 @@ module TestStruct
|
|||
o1 = klass1.new(1)
|
||||
o2 = klass1.new(1)
|
||||
o3 = klass2.new(1)
|
||||
assert(o1.eql?(o2))
|
||||
assert(!(o1.eql?(o3)))
|
||||
assert_operator(o1, :eql?, o2)
|
||||
assert_not_operator(o1, :eql?, o3)
|
||||
end
|
||||
|
||||
def test_size
|
||||
|
@ -255,26 +255,26 @@ module TestStruct
|
|||
x = klass1.new(1, 2, nil); x.c = x
|
||||
y = klass1.new(1, 2, nil); y.c = y
|
||||
Timeout.timeout(1) {
|
||||
assert x == y
|
||||
assert x.eql? y
|
||||
assert_equal x, y
|
||||
assert_operator x, :eql?, y
|
||||
}
|
||||
|
||||
z = klass1.new(:something, :other, nil); z.c = z
|
||||
Timeout.timeout(1) {
|
||||
assert x != z
|
||||
assert !x.eql?(z)
|
||||
assert_not_equal x, z
|
||||
assert_not_operator x, :eql?, z
|
||||
}
|
||||
|
||||
x.c = y; y.c = x
|
||||
Timeout.timeout(1) {
|
||||
assert x == y
|
||||
assert x.eql?(y)
|
||||
assert_equal x, y
|
||||
assert_operator x, :eql?, y
|
||||
}
|
||||
|
||||
x.c = z; z.c = x
|
||||
Timeout.timeout(1) {
|
||||
assert x != z
|
||||
assert !x.eql?(z)
|
||||
assert_not_equal x, z
|
||||
assert_not_operator x, :eql?, z
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -64,14 +64,14 @@ class TestThread < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
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 {
|
||||
Thread.current.thread_variable_set("foo", "bar")
|
||||
}.join
|
||||
|
||||
assert t.thread_variable?("foo")
|
||||
assert t.thread_variable?(:foo)
|
||||
refute t.thread_variable?(:bar)
|
||||
assert_send([t, :thread_variable?, "foo"])
|
||||
assert_send([t, :thread_variable?, :foo])
|
||||
assert_not_send([t, :thread_variable?, :bar])
|
||||
end
|
||||
|
||||
def test_thread_variable_strings_and_symbols_are_the_same_key
|
||||
|
@ -140,7 +140,7 @@ class TestThread < Test::Unit::TestCase
|
|||
end
|
||||
t1.kill
|
||||
t2.kill
|
||||
assert_operator(c1, :>, c2, "[ruby-dev:33124]") # not guaranteed
|
||||
assert_send([c1, :>, c2], "[ruby-dev:33124]") # not guaranteed
|
||||
end
|
||||
|
||||
def test_new
|
||||
|
|
|
@ -56,14 +56,14 @@ class TestTime < Test::Unit::TestCase
|
|||
Time.utc(2000, 3, 21, 0, 30))
|
||||
assert_equal(0, (Time.at(1.1) + 0.9).usec)
|
||||
|
||||
assert((Time.utc(2000, 4, 1) + 24).utc?)
|
||||
assert(!(Time.local(2000, 4, 1) + 24).utc?)
|
||||
assert_predicate((Time.utc(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
|
||||
assert(!t.utc?)
|
||||
assert_not_predicate(t, :utc?)
|
||||
assert_equal(3600, t.utc_offset)
|
||||
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)
|
||||
end
|
||||
|
||||
|
@ -418,14 +418,14 @@ class TestTime < Test::Unit::TestCase
|
|||
|
||||
def test_eql
|
||||
t2000 = get_t2000
|
||||
assert(t2000.eql?(t2000))
|
||||
assert(!t2000.eql?(Time.gm(2001)))
|
||||
assert_operator(t2000, :eql?, t2000)
|
||||
assert_not_operator(t2000, :eql?, Time.gm(2001))
|
||||
end
|
||||
|
||||
def test_utc_p
|
||||
assert(Time.gm(2000).gmt?)
|
||||
assert(!Time.local(2000).gmt?)
|
||||
assert(!Time.at(0).gmt?)
|
||||
assert_predicate(Time.gm(2000), :gmt?)
|
||||
assert_not_predicate(Time.local(2000), :gmt?)
|
||||
assert_not_predicate(Time.at(0), :gmt?)
|
||||
end
|
||||
|
||||
def test_hash
|
||||
|
@ -453,15 +453,15 @@ class TestTime < Test::Unit::TestCase
|
|||
def test_localtime_gmtime
|
||||
assert_nothing_raised do
|
||||
t = Time.gm(2000)
|
||||
assert(t.gmt?)
|
||||
assert_predicate(t, :gmt?)
|
||||
t.localtime
|
||||
assert(!t.gmt?)
|
||||
assert_not_predicate(t, :gmt?)
|
||||
t.localtime
|
||||
assert(!t.gmt?)
|
||||
assert_not_predicate(t, :gmt?)
|
||||
t.gmtime
|
||||
assert(t.gmt?)
|
||||
assert_predicate(t, :gmt?)
|
||||
t.gmtime
|
||||
assert(t.gmt?)
|
||||
assert_predicate(t, :gmt?)
|
||||
end
|
||||
|
||||
t1 = Time.gm(2000)
|
||||
|
@ -554,13 +554,13 @@ class TestTime < Test::Unit::TestCase
|
|||
assert_equal("UTC", t2000.zone)
|
||||
assert_equal(Encoding.find("locale"), t2000.zone.encoding)
|
||||
assert_equal(0, t2000.gmt_offset)
|
||||
assert(!t2000.sunday?)
|
||||
assert(!t2000.monday?)
|
||||
assert(!t2000.tuesday?)
|
||||
assert(!t2000.wednesday?)
|
||||
assert(!t2000.thursday?)
|
||||
assert(!t2000.friday?)
|
||||
assert(t2000.saturday?)
|
||||
assert_not_predicate(t2000, :sunday?)
|
||||
assert_not_predicate(t2000, :monday?)
|
||||
assert_not_predicate(t2000, :tuesday?)
|
||||
assert_not_predicate(t2000, :wednesday?)
|
||||
assert_not_predicate(t2000, :thursday?)
|
||||
assert_not_predicate(t2000, :friday?)
|
||||
assert_predicate(t2000, :saturday?)
|
||||
assert_equal([0, 0, 0, 1, 1, 2000, 6, 1, false, "UTC"], t2000.to_a)
|
||||
|
||||
t = Time.at(946684800).getlocal
|
||||
|
|
|
@ -22,7 +22,7 @@ class TestWhileuntil < Test::Unit::TestCase
|
|||
break if /vt100/ =~ line
|
||||
end
|
||||
|
||||
assert(!tmp.eof?)
|
||||
assert_not_predicate(tmp, :eof?)
|
||||
assert_match(/vt100/, line)
|
||||
tmp.close
|
||||
|
||||
|
@ -31,7 +31,7 @@ class TestWhileuntil < Test::Unit::TestCase
|
|||
next if /vt100/ =~ line
|
||||
assert_no_match(/vt100/, line)
|
||||
end
|
||||
assert(tmp.eof?)
|
||||
assert_predicate(tmp, :eof?)
|
||||
assert_no_match(/vt100/, line)
|
||||
tmp.close
|
||||
|
||||
|
@ -46,7 +46,7 @@ class TestWhileuntil < Test::Unit::TestCase
|
|||
assert_no_match(/vt100/, line)
|
||||
assert_no_match(/VT100/, line)
|
||||
end
|
||||
assert(tmp.eof?)
|
||||
assert_predicate(tmp, :eof?)
|
||||
tmp.close
|
||||
|
||||
sum=0
|
||||
|
@ -78,6 +78,6 @@ class TestWhileuntil < Test::Unit::TestCase
|
|||
until i>4
|
||||
i+=1
|
||||
end
|
||||
assert(i>4)
|
||||
assert_operator(i, :>, 4)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -86,13 +86,13 @@ module TestEOF
|
|||
def test_eof_2
|
||||
open_file("") {|f|
|
||||
assert_equal("", f.read)
|
||||
assert(f.eof?)
|
||||
assert_predicate(f, :eof?)
|
||||
}
|
||||
end
|
||||
|
||||
def test_eof_3
|
||||
open_file("") {|f|
|
||||
assert(f.eof?)
|
||||
assert_predicate(f, :eof?)
|
||||
}
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue