mirror of
https://github.com/neovim/neovim.git
synced 2024-12-23 20:55:18 -07:00
vim-patch:8.1.1861: only some assert functions can be used as a method
Problem: Only some assert functions can be used as a method.
Solution: Allow using most assert functions as a method.
24278d2407
Port tests to assert_spec.lua.
This commit is contained in:
parent
f03dd22f0d
commit
287a77ef51
@ -53,6 +53,9 @@ assert_beeps({cmd}) *assert_beeps()*
|
||||
Also see |assert_fails()|, |assert_nobeep()| and
|
||||
|assert-return|.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
GetCmd()->assert_beeps()
|
||||
<
|
||||
*assert_equal()*
|
||||
assert_equal({expected}, {actual} [, {msg}])
|
||||
When {expected} and {actual} are not equal an error message is
|
||||
@ -100,6 +103,9 @@ assert_fails({cmd} [, {error} [, {msg}]]) *assert_fails()*
|
||||
Note that beeping is not considered an error, and some failing
|
||||
commands only beep. Use |assert_beeps()| for those.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
GetCmd()->assert_fails('E99:')
|
||||
|
||||
assert_false({actual} [, {msg}]) *assert_false()*
|
||||
When {actual} is not false an error message is added to
|
||||
|v:errors|, like with |assert_equal()|.
|
||||
@ -109,6 +115,9 @@ assert_false({actual} [, {msg}]) *assert_false()*
|
||||
When {msg} is omitted an error in the form
|
||||
"Expected False but got {actual}" is produced.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
GetResult()->assert_false()
|
||||
|
||||
assert_inrange({lower}, {upper}, {actual} [, {msg}]) *assert_inrange()*
|
||||
This asserts number and |Float| values. When {actual} is lower
|
||||
than {lower} or higher than {upper} an error message is added
|
||||
@ -137,6 +146,9 @@ assert_match({pattern}, {actual} [, {msg}])
|
||||
< Will result in a string to be added to |v:errors|:
|
||||
test.vim line 12: Pattern '^f.*o$' does not match 'foobar' ~
|
||||
|
||||
Can also be used as a |method|: >
|
||||
getFile()->assert_match('foo.*')
|
||||
<
|
||||
assert_nobeep({cmd}) *assert_nobeep()*
|
||||
Run {cmd} and add an error message to |v:errors| if it
|
||||
produces a beep or visual bell.
|
||||
@ -157,6 +169,9 @@ assert_notmatch({pattern}, {actual} [, {msg}])
|
||||
|v:errors| when {pattern} matches {actual}.
|
||||
Also see |assert-return|.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
getFile()->assert_notmatch('bar.*')
|
||||
|
||||
assert_report({msg}) *assert_report()*
|
||||
Report a test failure directly, using {msg}.
|
||||
Always returns one.
|
||||
@ -170,5 +185,8 @@ assert_true({actual} [, {msg}]) *assert_true()*
|
||||
When {msg} is omitted an error in the form "Expected True but
|
||||
got {actual}" is produced.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
GetResult()->assert_true()
|
||||
<
|
||||
|
||||
vim:tw=78:ts=8:noet:ft=help:norl:
|
||||
|
@ -33,19 +33,19 @@ return {
|
||||
arglistid={args={0, 2}},
|
||||
argv={args={0, 2}},
|
||||
asin={args=1, func="float_op_wrapper", data="&asin"}, -- WJMc
|
||||
assert_beeps={args={1}},
|
||||
assert_beeps={args={1}, base=1},
|
||||
assert_equal={args={2, 3}, base=2},
|
||||
assert_equalfile={args={2, 3}},
|
||||
assert_exception={args={1, 2}},
|
||||
assert_fails={args={1, 3}},
|
||||
assert_false={args={1, 2}},
|
||||
assert_inrange={args={3, 4}},
|
||||
assert_match={args={2, 3}},
|
||||
assert_fails={args={1, 3}, base=1},
|
||||
assert_false={args={1, 2}, base=1},
|
||||
assert_inrange={args={3, 4}, base=3},
|
||||
assert_match={args={2, 3}, base=2},
|
||||
assert_nobeep={args={1}},
|
||||
assert_notequal={args={2, 3}, base=2},
|
||||
assert_notmatch={args={2, 3}},
|
||||
assert_notmatch={args={2, 3}, base=2},
|
||||
assert_report={args=1},
|
||||
assert_true={args={1, 2}},
|
||||
assert_true={args={1, 2}, base=1},
|
||||
atan={args=1, func="float_op_wrapper", data="&atan"},
|
||||
atan2={args=2},
|
||||
browse={args=4},
|
||||
|
@ -26,6 +26,14 @@ describe('assert function:', function()
|
||||
call('assert_beeps', 'normal 0')
|
||||
expected_errors({'command did not beep: normal 0'})
|
||||
end)
|
||||
|
||||
it('can be used as a method', function()
|
||||
local tmpname = source [[
|
||||
call assert_equal(0, 'normal h'->assert_beeps())
|
||||
call assert_equal(1, 'normal 0'->assert_beeps())
|
||||
]]
|
||||
expected_errors({tmpname .. ' line 2: command did not beep: normal 0'})
|
||||
end)
|
||||
end)
|
||||
|
||||
-- assert_equal({expected}, {actual}, [, {msg}])
|
||||
@ -133,6 +141,14 @@ describe('assert function:', function()
|
||||
call('assert_false', {})
|
||||
expected_errors({'Expected False but got []'})
|
||||
end)
|
||||
|
||||
it('can be used as a method', function()
|
||||
local tmpname = source [[
|
||||
call assert_equal(0, v:false->assert_false())
|
||||
call assert_equal(1, 123->assert_false())
|
||||
]]
|
||||
expected_errors({tmpname .. ' line 2: Expected False but got 123'})
|
||||
end)
|
||||
end)
|
||||
|
||||
-- assert_true({actual}, [, {msg}])
|
||||
@ -148,6 +164,14 @@ describe('assert function:', function()
|
||||
eq(1, call('assert_true', 1.5))
|
||||
expected_errors({'Expected True but got 1.5'})
|
||||
end)
|
||||
|
||||
it('can be used as a method', function()
|
||||
local tmpname = source [[
|
||||
call assert_equal(0, v:true->assert_true())
|
||||
call assert_equal(1, 0->assert_true())
|
||||
]]
|
||||
expected_errors({tmpname .. ' line 2: Expected True but got 0'})
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('v:errors', function()
|
||||
@ -223,6 +247,15 @@ describe('assert function:', function()
|
||||
call('assert_match', 'bar.*foo', 'foobar', 'wrong')
|
||||
expected_errors({"wrong: Pattern 'bar.*foo' does not match 'foobar'"})
|
||||
end)
|
||||
|
||||
it('can be used as a method', function()
|
||||
local tmpname = source [[
|
||||
call assert_equal(1, 'foobar'->assert_match('bar.*foo', 'wrong'))
|
||||
]]
|
||||
expected_errors({
|
||||
tmpname .. " line 1: wrong: Pattern 'bar.*foo' does not match 'foobar'"
|
||||
})
|
||||
end)
|
||||
end)
|
||||
|
||||
-- assert_notmatch({pat}, {text}[, {msg}])
|
||||
@ -237,6 +270,13 @@ describe('assert function:', function()
|
||||
call('assert_notmatch', 'foo', 'foobar')
|
||||
expected_errors({"Pattern 'foo' does match 'foobar'"})
|
||||
end)
|
||||
|
||||
it('can be used as a method', function()
|
||||
local tmpname = source [[
|
||||
call assert_equal(1, 'foobar'->assert_notmatch('foo'))
|
||||
]]
|
||||
expected_errors({tmpname .. " line 1: Pattern 'foo' does match 'foobar'"})
|
||||
end)
|
||||
end)
|
||||
|
||||
-- assert_fails({cmd}, [, {error}])
|
||||
@ -267,6 +307,15 @@ describe('assert function:', function()
|
||||
eq(1, eval([[assert_fails('echo', '', 'echo command')]]))
|
||||
expected_errors({'command did not fail: echo command'})
|
||||
end)
|
||||
|
||||
it('can be used as a method', function()
|
||||
local tmpname = source [[
|
||||
call assert_equal(1, 'echo'->assert_fails('', 'echo command'))
|
||||
]]
|
||||
expected_errors({
|
||||
tmpname .. ' line 1: command did not fail: echo command'
|
||||
})
|
||||
end)
|
||||
end)
|
||||
|
||||
-- assert_inrange({lower}, {upper}, {actual}[, {msg}])
|
||||
@ -292,6 +341,15 @@ describe('assert function:', function()
|
||||
eq('Vim(call):E119: Not enough arguments for function: assert_inrange',
|
||||
exc_exec("call assert_inrange(1, 1)"))
|
||||
end)
|
||||
|
||||
it('can be used as a method', function()
|
||||
local tmpname = source [[
|
||||
call assert_equal(0, 5->assert_inrange(5, 7))
|
||||
call assert_equal(0, 7->assert_inrange(5, 7))
|
||||
call assert_equal(1, 8->assert_inrange(5, 7))
|
||||
]]
|
||||
expected_errors({tmpname .. ' line 3: Expected range 5 - 7, but got 8'})
|
||||
end)
|
||||
end)
|
||||
|
||||
-- assert_report({msg})
|
||||
|
Loading…
Reference in New Issue
Block a user