xref: /vim-8.2.3635/src/testdir/test_maparg.vim (revision 2a953fcf)
1" Tests for maparg().
2" Also test utf8 map with a 0x80 byte.
3
4function s:SID()
5  return str2nr(matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$'))
6endfun
7
8function Test_maparg()
9  new
10  set cpo-=<
11  set encoding=utf8
12  " Test maparg() with a string result
13  let sid = s:SID()
14  let lnum = expand('<sflnum>')
15  map foo<C-V> is<F4>foo
16  vnoremap <script> <buffer> <expr> <silent> bar isbar
17  call assert_equal("is<F4>foo", maparg('foo<C-V>'))
18  call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'foo<C-V>',
19        \ 'mode': ' ', 'nowait': 0, 'expr': 0, 'sid': sid, 'lnum': lnum + 1,
20	\ 'rhs': 'is<F4>foo', 'buffer': 0},
21	\ maparg('foo<C-V>', '', 0, 1))
22  call assert_equal({'silent': 1, 'noremap': 1, 'lhs': 'bar', 'mode': 'v',
23        \ 'nowait': 0, 'expr': 1, 'sid': sid, 'lnum': lnum + 2,
24	\ 'rhs': 'isbar', 'buffer': 1},
25        \ maparg('bar', '', 0, 1))
26  let lnum = expand('<sflnum>')
27  map <buffer> <nowait> foo bar
28  call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'foo', 'mode': ' ',
29        \ 'nowait': 1, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, 'rhs': 'bar',
30	\ 'buffer': 1},
31        \ maparg('foo', '', 0, 1))
32
33  map abc x<char-114>x
34  call assert_equal("xrx", maparg('abc'))
35  map abc y<S-char-114>y
36  call assert_equal("yRy", maparg('abc'))
37
38  map abc <Nop>
39  call assert_equal("<Nop>", maparg('abc'))
40  unmap abc
41endfunction
42
43function Test_range_map()
44  new
45  " Outside of the range, minimum
46  inoremap <Char-0x1040> a
47  execute "normal a\u1040\<Esc>"
48  " Inside of the range, minimum
49  inoremap <Char-0x103f> b
50  execute "normal a\u103f\<Esc>"
51  " Inside of the range, maximum
52  inoremap <Char-0xf03f> c
53  execute "normal a\uf03f\<Esc>"
54  " Outside of the range, maximum
55  inoremap <Char-0xf040> d
56  execute "normal a\uf040\<Esc>"
57  call assert_equal("abcd", getline(1))
58endfunction
59