mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Add assert_same and assert_not_same
This commit is contained in:
@@ -124,6 +124,32 @@ def assert_not_equal(arg1, arg2 = nil, arg3 = nil)
|
||||
assert_false(exp == act, msg, diff)
|
||||
end
|
||||
|
||||
def assert_same(arg1, arg2 = nil, arg3 = nil)
|
||||
if block_given?
|
||||
exp, act, msg = arg1, yield, arg2
|
||||
else
|
||||
exp, act, msg = arg1, arg2, arg3
|
||||
end
|
||||
|
||||
msg ||= "Expected #{act.inspect} to be the same object as #{exp.inspect}"
|
||||
diff = " Expected: #{exp.inspect} (class=#{exp.class}, oid=#{exp.__id__})\n" +
|
||||
" Actual: #{act.inspect} (class=#{act.class}, oid=#{act.__id__})"
|
||||
assert_true(exp.equal?(act), msg, diff)
|
||||
end
|
||||
|
||||
def assert_not_same(arg1, arg2 = nil, arg3 = nil)
|
||||
if block_given?
|
||||
exp, act, msg = arg1, yield, arg2
|
||||
else
|
||||
exp, act, msg = arg1, arg2, arg3
|
||||
end
|
||||
|
||||
msg ||= "Expected #{act.inspect} to not be the same object as #{exp.inspect}"
|
||||
diff = " Expected: #{exp.inspect} (class=#{exp.class}, oid=#{exp.__id__})\n" +
|
||||
" Actual: #{act.inspect} (class=#{act.class}, oid=#{act.__id__})"
|
||||
assert_false(exp.equal?(act), msg, diff)
|
||||
end
|
||||
|
||||
def assert_nil(obj, msg = nil)
|
||||
msg = "Expected #{obj.inspect} to be nil" unless msg
|
||||
diff = assertion_diff(nil, obj)
|
||||
|
||||
+1
-1
@@ -157,7 +157,7 @@ assert('&obj call to_proc if defined') do
|
||||
def mock(&b)
|
||||
b
|
||||
end
|
||||
assert_equal pr.object_id, mock(&pr).object_id
|
||||
assert_same pr, mock(&pr)
|
||||
assert_equal pr, mock(&pr)
|
||||
|
||||
obj = Object.new
|
||||
|
||||
+1
-1
@@ -579,7 +579,7 @@ assert('String#sub', '15.2.10.5.36') do
|
||||
str = "abc"
|
||||
miss = str.sub("X", "Z")
|
||||
assert_equal str, miss
|
||||
assert_not_equal str.object_id, miss.object_id
|
||||
assert_not_same str, miss
|
||||
|
||||
a = []
|
||||
assert_equal '.abc', "abc".sub("") { |i| a << i; "." }
|
||||
|
||||
Reference in New Issue
Block a user