aboutsummaryrefslogtreecommitdiff
path: root/test/functional/legacy/assert_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/legacy/assert_spec.lua')
-rw-r--r--test/functional/legacy/assert_spec.lua124
1 files changed, 123 insertions, 1 deletions
diff --git a/test/functional/legacy/assert_spec.lua b/test/functional/legacy/assert_spec.lua
index 1ce665360d..8a042be7f7 100644
--- a/test/functional/legacy/assert_spec.lua
+++ b/test/functional/legacy/assert_spec.lua
@@ -1,7 +1,8 @@
-local helpers = require('test.functional.helpers')
+local helpers = require('test.functional.helpers')(after_each)
local nvim, call = helpers.meths, helpers.call
local clear, eq = helpers.clear, helpers.eq
local source, execute = helpers.source, helpers.execute
+local exc_exec = helpers.exc_exec
local function expected_errors(errors)
eq(errors, nvim.get_vvar('errors'))
@@ -62,6 +63,34 @@ describe('assert function:', function()
call('assert_equal', 'true', 'false')
expected_errors({"Expected 'true' but got 'false'"})
end)
+
+ it('should change v:errors when expected is not equal to actual', function()
+ source([[
+ function CheckAssert()
+ let s:v = {}
+ let s:x = {"a": s:v}
+ let s:v["b"] = s:x
+ let s:w = {"c": s:x, "d": ''}
+ call assert_equal(s:w, '')
+ endfunction
+ ]])
+ eq('Vim(call):E724: unable to correctly dump variable with self-referencing container',
+ exc_exec('call CheckAssert()'))
+ end)
+ end)
+
+ -- 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')
+ expected_empty()
+ end)
+
+ it('should change v:errors when expected is equal to actual', function()
+ call('assert_notequal', 'foo', 'foo')
+ expected_errors({"Expected 'foo' differs from 'foo'"})
+ end)
end)
-- assert_false({actual}, [, {msg}])
@@ -141,5 +170,98 @@ describe('assert function:', function()
tmpname_two .. " line 1: 'file two'",
})
end)
+
+ it('is reset to a list by assert functions', function()
+ source([[
+ let save_verrors = v:errors
+ let v:['errors'] = {'foo': 3}
+ call assert_equal('yes', 'no')
+ let verrors = v:errors
+ let v:errors = save_verrors
+ call assert_equal(type([]), type(verrors))
+ ]])
+ expected_empty()
+ end)
+ end)
+
+ -- assert_match({pat}, {text}[, {msg}])
+ describe('assert_match', function()
+ it('should not change v:errors when pat matches text', function()
+ call('assert_match', '^f.*b.*r$', 'foobar')
+ expected_empty()
+ end)
+
+ it('should change v:errors when pat does not match text', function()
+ call('assert_match', 'bar.*foo', 'foobar')
+ expected_errors({"Pattern 'bar.*foo' does not match 'foobar'"})
+ end)
+
+ it('should set v:errors to msg when given and match fails', function()
+ call('assert_match', 'bar.*foo', 'foobar', 'wrong')
+ expected_errors({"'wrong'"})
+ end)
+ end)
+
+ -- assert_notmatch({pat}, {text}[, {msg}])
+ describe('assert_notmatch', function()
+ it('should not change v:errors when pat does not match text', function()
+ call('assert_notmatch', 'foo', 'bar')
+ call('assert_notmatch', '^foobar$', 'foobars')
+ expected_empty()
+ end)
+
+ it('should change v:errors when pat matches text', function()
+ call('assert_notmatch', 'foo', 'foobar')
+ expected_errors({"Pattern 'foo' does match 'foobar'"})
+ end)
+ end)
+
+ -- assert_fails({cmd}, [, {error}])
+ describe('assert_fails', function()
+ it('should change v:errors when error does not match v:errmsg', function()
+ execute([[call assert_fails('xxx', {})]])
+ execute([[call assert_match("Expected {} but got 'E731:", v:errors[0])]])
+ expected_errors({"Expected {} but got 'E731: using Dictionary as a String'"})
+ end)
+
+ it('should not change v:errors when cmd errors', function()
+ call('assert_fails', 'NonexistentCmd')
+ expected_empty()
+ end)
+
+ it('should change v:errors when cmd succeeds', function()
+ call('assert_fails', 'call empty("")')
+ expected_errors({'command did not fail: call empty("")'})
+ end)
+ end)
+
+ -- assert_exception({cmd}, [, {error}])
+ describe('assert_exception()', function()
+ it('should assert thrown exceptions properly', function()
+ source([[
+ try
+ nocommand
+ catch
+ call assert_exception('E492')
+ endtry
+ ]])
+ expected_empty()
+ end)
+
+ it('should work properly when nested', function()
+ source([[
+ try
+ nocommand
+ catch
+ try
+ " illegal argument, get NULL for error
+ call assert_exception([])
+ catch
+ call assert_exception('E730')
+ endtry
+ endtry
+ ]])
+ expected_empty()
+ end)
end)
end)