summaryrefslogtreecommitdiff
path: root/src/testdir/test_map_functions.vim
diff options
context:
space:
mode:
authorErnie Rael <errael@raelity.com>2022-05-04 15:40:22 +0100
committerBram Moolenaar <Bram@vim.org>2022-05-04 15:40:22 +0100
commit51d04d16f21e19d6eded98f9530d84089102f925 (patch)
tree20bb53da9296e31af0101070f69c689724c04f61 /src/testdir/test_map_functions.vim
parent05cf63e9bdca1ac070df3e7d9c6dfc45e68ac916 (diff)
downloadvim-git-51d04d16f21e19d6eded98f9530d84089102f925.tar.gz
patch 8.2.4861: it is not easy to restore saved mappingsv8.2.4861
Problem: It is not easy to restore saved mappings. Solution: Make mapset() accept a dict argument. (Ernie Rael, closes #10295)
Diffstat (limited to 'src/testdir/test_map_functions.vim')
-rw-r--r--src/testdir/test_map_functions.vim165
1 files changed, 160 insertions, 5 deletions
diff --git a/src/testdir/test_map_functions.vim b/src/testdir/test_map_functions.vim
index 66f347903..21c899048 100644
--- a/src/testdir/test_map_functions.vim
+++ b/src/testdir/test_map_functions.vim
@@ -19,13 +19,13 @@ func Test_maparg()
\ 'lhsraw': "foo\x80\xfc\x04V", 'lhsrawalt': "foo\x16",
\ 'mode': ' ', 'nowait': 0, 'expr': 0, 'sid': sid, 'scriptversion': 1,
\ 'lnum': lnum + 1,
- \ 'rhs': 'is<F4>foo', 'buffer': 0},
+ \ 'rhs': 'is<F4>foo', 'buffer': 0, 'abbr': 0},
\ maparg('foo<C-V>', '', 0, 1))
call assert_equal({'silent': 1, 'noremap': 1, 'script': 1, 'lhs': 'bar',
\ 'lhsraw': 'bar', 'mode': 'v',
\ 'nowait': 0, 'expr': 1, 'sid': sid, 'scriptversion': 1,
\ 'lnum': lnum + 2,
- \ 'rhs': 'isbar', 'buffer': 1},
+ \ 'rhs': 'isbar', 'buffer': 1, 'abbr': 0},
\ 'bar'->maparg('', 0, 1))
let lnum = expand('<sflnum>')
map <buffer> <nowait> foo bar
@@ -33,7 +33,7 @@ func Test_maparg()
\ 'lhsraw': 'foo', 'mode': ' ',
\ 'nowait': 1, 'expr': 0, 'sid': sid, 'scriptversion': 1,
\ 'lnum': lnum + 1, 'rhs': 'bar',
- \ 'buffer': 1},
+ \ 'buffer': 1, 'abbr': 0},
\ maparg('foo', '', 0, 1))
let lnum = expand('<sflnum>')
tmap baz foo
@@ -41,8 +41,17 @@ func Test_maparg()
\ 'lhsraw': 'baz', 'mode': 't',
\ 'nowait': 0, 'expr': 0, 'sid': sid, 'scriptversion': 1,
\ 'lnum': lnum + 1, 'rhs': 'foo',
- \ 'buffer': 0},
+ \ 'buffer': 0, 'abbr': 0},
\ maparg('baz', 't', 0, 1))
+ let lnum = expand('<sflnum>')
+ iab A B
+ call assert_equal({'silent': 0, 'noremap': 0, 'script': 0, 'lhs': 'A',
+ \ 'lhsraw': 'A', 'mode': 'i',
+ \ 'nowait': 0, 'expr': 0, 'sid': sid, 'scriptversion': 1,
+ \ 'lnum': lnum + 1, 'rhs': 'B',
+ \ 'buffer': 0, 'abbr': 1},
+ \ maparg('A', 'i', 1, 1))
+ iuna A
map abc x<char-114>x
call assert_equal("xrx", maparg('abc'))
@@ -250,10 +259,156 @@ func Test_mapset()
bwipe!
call assert_fails('call mapset([], v:false, {})', 'E730:')
- call assert_fails('call mapset("i", 0, "")', 'E716:')
+ call assert_fails('call mapset("i", 0, "")', 'E715:')
call assert_fails('call mapset("i", 0, {})', 'E460:')
endfunc
+def Test_mapset_arg1_dir()
+ # This test is mostly about get_map_mode_string.
+ # Once the code gets past that, it's common with the 3 arg mapset.
+
+ # GetModes() return list of modes for 'XZ' lhs using maplist.
+ # There is one list item per mapping
+ def GetModes(abbr: bool = false): list<string>
+ return maplist(abbr)->filter((_, m) => m.lhs == 'XZ')
+ ->mapnew((_, m) => m.mode)
+ enddef
+
+ const unmap_cmds = [ 'unmap', 'unmap!', 'tunmap', 'lunmap' ]
+ def UnmapAll(lhs: string)
+ for cmd in unmap_cmds
+ try | execute(cmd .. ' ' .. lhs) | catch /E31/ | endtry
+ endfor
+ enddef
+
+ var tmap: dict<any>
+
+ # some mapset(mode, abbr, dict) tests using get_map_mode_str
+ map XZ x
+ tmap = maplist()->filter((_, m) => m.lhs == 'XZ')[0]->copy()
+ # this splits the mapping into 2 mappings
+ mapset('ox', false, tmap)
+ assert_equal(2, len(GetModes()))
+ mapset('o', false, tmap)
+ assert_equal(3, len(GetModes()))
+ # test that '' acts like ' ', and that the 3 mappings become 1
+ mapset('', false, tmap)
+ assert_equal([' '], GetModes())
+ # dict's mode/abbr are ignored
+ UnmapAll('XZ')
+ tmap.mode = '!'
+ tmap.abbr = true
+ mapset('o', false, tmap)
+ assert_equal(['o'], GetModes())
+
+ # test the 3 arg version handles bad mode string, dict not used
+ assert_fails("mapset('vi', false, {})", 'E1276:')
+
+
+ # get the abbreviations out of the way
+ abbreviate XZ ZX
+ tmap = maplist(true)->filter((_, m) => m.lhs == 'XZ')[0]->copy()
+
+ abclear
+ # 'ic' is the default ab command, shows up as '!'
+ tmap.mode = 'ic'
+ mapset(tmap)
+ assert_equal(['!'], GetModes(true))
+
+ abclear
+ tmap.mode = 'i'
+ mapset(tmap)
+ assert_equal(['i'], GetModes(true))
+
+ abclear
+ tmap.mode = 'c'
+ mapset(tmap)
+ assert_equal(['c'], GetModes(true))
+
+ abclear
+ tmap.mode = '!'
+ mapset(tmap)
+ assert_equal(['!'], GetModes(true))
+
+ assert_fails("mapset({mode: ' !', abbr: 1})", 'E1276:')
+ assert_fails("mapset({mode: 'cl', abbr: 1})", 'E1276:')
+ assert_fails("mapset({mode: 'in', abbr: 1})", 'E1276:')
+
+ # the map commands
+ map XZ x
+ tmap = maplist()->filter((_, m) => m.lhs == 'XZ')[0]->copy()
+
+ # try the combos
+ UnmapAll('XZ')
+ # 'nxso' is ' ', the unadorned :map
+ tmap.mode = 'nxso'
+ mapset(tmap)
+ assert_equal([' '], GetModes())
+
+ UnmapAll('XZ')
+ # 'ic' is '!'
+ tmap.mode = 'ic'
+ mapset(tmap)
+ assert_equal(['!'], GetModes())
+
+ UnmapAll('XZ')
+ # 'xs' is really 'v'
+ tmap.mode = 'xs'
+ mapset(tmap)
+ assert_equal(['v'], GetModes())
+
+ # try the individual modes
+ UnmapAll('XZ')
+ tmap.mode = 'n'
+ mapset(tmap)
+ assert_equal(['n'], GetModes())
+
+ UnmapAll('XZ')
+ tmap.mode = 'x'
+ mapset(tmap)
+ assert_equal(['x'], GetModes())
+
+ UnmapAll('XZ')
+ tmap.mode = 's'
+ mapset(tmap)
+ assert_equal(['s'], GetModes())
+
+ UnmapAll('XZ')
+ tmap.mode = 'o'
+ mapset(tmap)
+ assert_equal(['o'], GetModes())
+
+ UnmapAll('XZ')
+ tmap.mode = 'i'
+ mapset(tmap)
+ assert_equal(['i'], GetModes())
+
+ UnmapAll('XZ')
+ tmap.mode = 'c'
+ mapset(tmap)
+ assert_equal(['c'], GetModes())
+
+ UnmapAll('XZ')
+ tmap.mode = 't'
+ mapset(tmap)
+ assert_equal(['t'], GetModes())
+
+ UnmapAll('XZ')
+ tmap.mode = 'l'
+ mapset(tmap)
+ assert_equal(['l'], GetModes())
+
+ UnmapAll('XZ')
+
+ # get errors for modes that can't be in one mapping
+ assert_fails("mapset({mode: 'nxsoi', abbr: 0})", 'E1276:')
+ assert_fails("mapset({mode: ' !', abbr: 0})", 'E1276:')
+ assert_fails("mapset({mode: 'ix', abbr: 0})", 'E1276:')
+ assert_fails("mapset({mode: 'tl', abbr: 0})", 'E1276:')
+ assert_fails("mapset({mode: ' l', abbr: 0})", 'E1276:')
+ assert_fails("mapset({mode: ' t', abbr: 0})", 'E1276:')
+enddef
+
func Check_ctrlb_map(d, check_alt)
call assert_equal('<C-B>', a:d.lhs)
if a:check_alt