diff src/testdir/test_maparg.vim @ 20506:aee0b72ca6d6 v8.2.0807

patch 8.2.0807: cannot easily restore a mapping Commit: https://github.com/vim/vim/commit/4c9243f9fb708c9010867d3cc8e928f36b58509a Author: Bram Moolenaar <Bram@vim.org> Date: Fri May 22 13:10:44 2020 +0200 patch 8.2.0807: cannot easily restore a mapping Problem: Cannot easily restore a mapping. Solution: Add mapset().
author Bram Moolenaar <Bram@vim.org>
date Fri, 22 May 2020 13:15:04 +0200
parents 658248b68f7c
children d9e3fdf26cb9
line wrap: on
line diff
--- a/src/testdir/test_maparg.vim
+++ b/src/testdir/test_maparg.vim
@@ -1,12 +1,12 @@
-" Tests for maparg().
+" Tests for maparg(), mapcheck() and mapset().
 " Also test utf8 map with a 0x80 byte.
 " Also test mapcheck()
 
-function s:SID()     
+func s:SID()     
   return str2nr(matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$'))
-endfun
+endfunc
 
-function Test_maparg()
+funct Test_maparg()
   new
   set cpo-=<
   set encoding=utf8
@@ -18,23 +18,23 @@ function Test_maparg()
   call assert_equal("is<F4>foo", maparg('foo<C-V>'))
   call assert_equal({'silent': 0, 'noremap': 0, 'script': 0, 'lhs': 'foo<C-V>',
         \ 'mode': ' ', 'nowait': 0, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, 
-	\ 'rhs': 'is<F4>foo', 'buffer': 0},
+	\ 'simplified': 1, 'rhs': 'is<F4>foo', 'buffer': 0},
 	\ maparg('foo<C-V>', '', 0, 1))
   call assert_equal({'silent': 1, 'noremap': 1, 'script': 1, 'lhs': 'bar', 'mode': 'v',
         \ 'nowait': 0, 'expr': 1, 'sid': sid, 'lnum': lnum + 2,
-	\ 'rhs': 'isbar', 'buffer': 1},
+	\ 'simplified': 0, 'rhs': 'isbar', 'buffer': 1},
         \ 'bar'->maparg('', 0, 1))
   let lnum = expand('<sflnum>')
   map <buffer> <nowait> foo bar
   call assert_equal({'silent': 0, 'noremap': 0, 'script': 0, 'lhs': 'foo', 'mode': ' ',
         \ 'nowait': 1, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, 'rhs': 'bar',
-	\ 'buffer': 1},
+	\ 'simplified': 0, 'buffer': 1},
         \ maparg('foo', '', 0, 1))
   let lnum = expand('<sflnum>')
   tmap baz foo
   call assert_equal({'silent': 0, 'noremap': 0, 'script': 0, 'lhs': 'baz', 'mode': 't',
         \ 'nowait': 0, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, 'rhs': 'foo',
-	\ 'buffer': 0},
+	\ 'simplified': 0, 'buffer': 0},
         \ maparg('baz', 't', 0, 1))
 
   map abc x<char-114>x
@@ -75,7 +75,7 @@ function Test_maparg()
   let d = maparg('esc', 'i', 1, 1)
   call assert_equal(['esc', "\<C-V>\<C-V>\<Esc>", '!'], [d.lhs, d.rhs, d.mode])
   abclear
-endfunction
+endfunc
 
 func Test_mapcheck()
   call assert_equal('', mapcheck('a'))
@@ -116,7 +116,7 @@ func Test_mapcheck()
   unabbr ab
 endfunc
 
-function Test_range_map()
+func Test_range_map()
   new
   " Outside of the range, minimum
   inoremap <Char-0x1040> a
@@ -131,6 +131,31 @@ function Test_range_map()
   inoremap <Char-0xf040> d
   execute "normal a\uf040\<Esc>"
   call assert_equal("abcd", getline(1))
-endfunction
+endfunc
+
+func One_mapset_test(keys)
+  exe 'nnoremap ' .. a:keys .. ' original<CR>'
+  let orig = maparg(a:keys, 'n', 0, 1)
+  call assert_equal(a:keys, orig.lhs)
+  call assert_equal('original<CR>', orig.rhs)
+  call assert_equal('n', orig.mode)
+
+  exe 'nunmap ' .. a:keys
+  let d = maparg(a:keys, 'n', 0, 1)
+  call assert_equal({}, d)
+
+  call mapset('n', 0, orig)
+  let d = maparg(a:keys, 'n', 0, 1)
+  call assert_equal(a:keys, d.lhs)
+  call assert_equal('original<CR>', d.rhs)
+  call assert_equal('n', d.mode)
+
+  exe 'nunmap ' .. a:keys
+endfunc
+
+func Test_mapset()
+  call One_mapset_test('K')
+  call One_mapset_test('<F3>')
+endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab