vim-patch:8.0.1770: assert functions don't return anything

Problem:    Assert functions don't return anything.
Solution:   Return non-zero when the assertion fails.
65a5464985
This commit is contained in:
Jan Edmund Lazo
2019-09-16 22:26:41 -04:00
parent 792c290343
commit 8db9e82e3e
4 changed files with 113 additions and 73 deletions

View File

@@ -47,18 +47,18 @@ describe('assert function:', function()
end)
it('should not change v:errors when expected is equal to actual', function()
call('assert_equal', '', '')
call('assert_equal', 'string', 'string')
eq(0, call('assert_equal', '', ''))
eq(0, call('assert_equal', 'string', 'string'))
expected_empty()
end)
it('should change v:errors when expected is not equal to actual', function()
call('assert_equal', 0, {0})
eq(1, call('assert_equal', 0, {0}))
expected_errors({'Expected 0 but got [0]'})
end)
it('should change v:errors when expected is not equal to actual', function()
call('assert_equal', 0, "0")
eq(1, call('assert_equal', 0, "0"))
expected_errors({"Expected 0 but got '0'"})
end)
@@ -96,13 +96,13 @@ describe('assert function:', function()
-- assert_notequal({expected}, {actual}[, {msg}])
describe('assert_notequal', function()
it('should not change v:errors when expected differs from actual', function()
call('assert_notequal', 'foo', 4)
call('assert_notequal', {1, 2, 3}, 'foo')
eq(0, call('assert_notequal', 'foo', 4))
eq(0, call('assert_notequal', {1, 2, 3}, 'foo'))
expected_empty()
end)
it('should change v:errors when expected is equal to actual', function()
call('assert_notequal', 'foo', 'foo')
eq(1, call('assert_notequal', 'foo', 'foo'))
expected_errors({"Expected not equal to 'foo'"})
end)
end)
@@ -110,13 +110,13 @@ describe('assert function:', function()
-- assert_false({actual}, [, {msg}])
describe('assert_false', function()
it('should not change v:errors when actual is false', function()
call('assert_false', 0)
call('assert_false', false)
eq(0, call('assert_false', 0))
eq(0, call('assert_false', false))
expected_empty()
end)
it('should change v:errors when actual is not false', function()
call('assert_false', 1)
eq(1, call('assert_false', 1))
expected_errors({'Expected False but got 1'})
end)
@@ -129,14 +129,14 @@ describe('assert function:', function()
-- assert_true({actual}, [, {msg}])
describe('assert_true', function()
it('should not change v:errors when actual is true', function()
call('assert_true', 1)
call('assert_true', -1) -- In Vim script, non-zero Numbers are TRUE.
call('assert_true', true)
eq(0, call('assert_true', 1))
eq(0, call('assert_true', -1)) -- In Vim script, non-zero Numbers are TRUE.
eq(0, call('assert_true', true))
expected_empty()
end)
it('should change v:errors when actual is not true', function()
call('assert_true', 1.5)
eq(1, call('assert_true', 1.5))
expected_errors({'Expected True but got 1.5'})
end)
end)
@@ -277,7 +277,7 @@ describe('assert function:', function()
-- assert_report({msg})
describe('assert_report()', function()
it('should add a message to v:errors', function()
command("call assert_report('something is wrong')")
eq(1, call('assert_report', 'something is wrong'))
command("call assert_match('something is wrong', v:errors[0])")
command('call remove(v:errors, 0)')
expected_empty()
@@ -291,7 +291,7 @@ describe('assert function:', function()
try
nocommand
catch
call assert_exception('E492')
call assert_equal(0, assert_exception('E492'))
endtry
]])
expected_empty()
@@ -304,9 +304,9 @@ describe('assert function:', function()
catch
try
" illegal argument, get NULL for error
call assert_exception([])
call assert_equal(1, assert_exception([]))
catch
call assert_exception('E730')
call assert_equal(0, assert_exception('E730'))
endtry
endtry
]])