summaryrefslogtreecommitdiff
path: root/src/testdir/test_autocmd.vim
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2022-05-27 18:05:33 +0100
committerBram Moolenaar <Bram@vim.org>2022-05-27 18:05:33 +0100
commite0ff3a7de6030b73d94121626deb8229e66e82b2 (patch)
treead08f28abf01c743f8bae5892920c6c45603c00a /src/testdir/test_autocmd.vim
parentcfe456543e840d133399551f8626d985e1fb1958 (diff)
downloadvim-git-e0ff3a7de6030b73d94121626deb8229e66e82b2.tar.gz
patch 8.2.5030: autocmd_add() can only handle one event and patternv8.2.5030
Problem: autocmd_add() can only handle one event and pattern. Solution: Support a list of events and patterns. (Yegappan Lakshmanan, closes #10483)
Diffstat (limited to 'src/testdir/test_autocmd.vim')
-rw-r--r--src/testdir/test_autocmd.vim77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index e3df115a6..0aaa968c8 100644
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -3429,6 +3429,83 @@ func Test_autocmd_add()
\ cmd: 'echo "bufadd"'}]
call assert_fails('call autocmd_add(l)', 'E216:')
+ " Test for using a list of events and patterns
+ call autocmd_delete([#{group: 'TestAcSet'}])
+ let l = [#{group: 'TestAcSet', event: ['BufEnter', 'BufLeave'],
+ \ pattern: ['*.py', '*.sh'], cmd: 'echo "bufcmds"'}]
+ call autocmd_add(l)
+ call assert_equal([
+ \ #{cmd: 'echo "bufcmds"', group: 'TestAcSet', pattern: '*.py',
+ \ nested: v:false, once: v:false, event: 'BufEnter'},
+ \ #{cmd: 'echo "bufcmds"', group: 'TestAcSet', pattern: '*.sh',
+ \ nested: v:false, once: v:false, event: 'BufEnter'},
+ \ #{cmd: 'echo "bufcmds"', group: 'TestAcSet', pattern: '*.py',
+ \ nested: v:false, once: v:false, event: 'BufLeave'},
+ \ #{cmd: 'echo "bufcmds"', group: 'TestAcSet', pattern: '*.sh',
+ \ nested: v:false, once: v:false, event: 'BufLeave'}],
+ \ autocmd_get(#{group: 'TestAcSet'}))
+
+ " Test for invalid values for 'event' item
+ call autocmd_delete([#{group: 'TestAcSet'}])
+ let l = [#{group: 'TestAcSet', event: test_null_string(),
+ \ pattern: "*.py", cmd: 'echo "bufcmds"'}]
+ call assert_fails('call autocmd_add(l)', 'E928:')
+ let l = [#{group: 'TestAcSet', event: test_null_list(),
+ \ pattern: "*.py", cmd: 'echo "bufcmds"'}]
+ call assert_fails('call autocmd_add(l)', 'E714:')
+ let l = [#{group: 'TestAcSet', event: {},
+ \ pattern: "*.py", cmd: 'echo "bufcmds"'}]
+ call assert_fails('call autocmd_add(l)', 'E777:')
+ let l = [#{group: 'TestAcSet', event: [{}],
+ \ pattern: "*.py", cmd: 'echo "bufcmds"'}]
+ call assert_fails('call autocmd_add(l)', 'E928:')
+ let l = [#{group: 'TestAcSet', event: [test_null_string()],
+ \ pattern: "*.py", cmd: 'echo "bufcmds"'}]
+ call assert_fails('call autocmd_add(l)', 'E928:')
+ let l = [#{group: 'TestAcSet', event: 'BufEnter,BufLeave',
+ \ pattern: '*.py', cmd: 'echo "bufcmds"'}]
+ call assert_fails('call autocmd_add(l)', 'E216:')
+ let l = [#{group: 'TestAcSet', event: [],
+ \ pattern: "*.py", cmd: 'echo "bufcmds"'}]
+ call autocmd_add(l)
+ let l = [#{group: 'TestAcSet', event: [""],
+ \ pattern: "*.py", cmd: 'echo "bufcmds"'}]
+ call assert_fails('call autocmd_add(l)', 'E216:')
+ let l = [#{group: 'TestAcSet', event: "",
+ \ pattern: "*.py", cmd: 'echo "bufcmds"'}]
+ call autocmd_add(l)
+ call assert_equal([], autocmd_get(#{group: 'TestAcSet'}))
+
+ " Test for invalid values for 'pattern' item
+ let l = [#{group: 'TestAcSet', event: "BufEnter",
+ \ pattern: test_null_string(), cmd: 'echo "bufcmds"'}]
+ let l = [#{group: 'TestAcSet', event: "BufEnter",
+ \ pattern: test_null_list(), cmd: 'echo "bufcmds"'}]
+ call assert_fails('call autocmd_add(l)', 'E714:')
+ let l = [#{group: 'TestAcSet', event: "BufEnter",
+ \ pattern: {}, cmd: 'echo "bufcmds"'}]
+ call assert_fails('call autocmd_add(l)', 'E777:')
+ let l = [#{group: 'TestAcSet', event: "BufEnter",
+ \ pattern: [{}], cmd: 'echo "bufcmds"'}]
+ call assert_fails('call autocmd_add(l)', 'E928:')
+ let l = [#{group: 'TestAcSet', event: "BufEnter",
+ \ pattern: [test_null_string()], cmd: 'echo "bufcmds"'}]
+ call assert_fails('call autocmd_add(l)', 'E928:')
+ let l = [#{group: 'TestAcSet', event: "BufEnter",
+ \ pattern: [], cmd: 'echo "bufcmds"'}]
+ call autocmd_add(l)
+ let l = [#{group: 'TestAcSet', event: "BufEnter",
+ \ pattern: [""], cmd: 'echo "bufcmds"'}]
+ call autocmd_add(l)
+ let l = [#{group: 'TestAcSet', event: "BufEnter",
+ \ pattern: "", cmd: 'echo "bufcmds"'}]
+ call autocmd_add(l)
+ call assert_equal([], autocmd_get(#{group: 'TestAcSet'}))
+
+ let l = [#{group: 'TestAcSet', event: 'BufEnter,abc,BufLeave',
+ \ pattern: '*.py', cmd: 'echo "bufcmds"'}]
+ call assert_fails('call autocmd_add(l)', 'E216:')
+
call assert_fails("call autocmd_add({})", 'E1211:')
call assert_equal(v:false, autocmd_add(test_null_list()))
call assert_true(autocmd_add([[]]))