xref: /vim-8.2.3635/src/testdir/test_maparg.vim (revision 2387773d)
1" Tests for maparg().
2" Also test utf8 map with a 0x80 byte.
3" Also test mapcheck()
4
5function s:SID()
6  return str2nr(matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$'))
7endfun
8
9function Test_maparg()
10  new
11  set cpo-=<
12  set encoding=utf8
13  " Test maparg() with a string result
14  let sid = s:SID()
15  let lnum = expand('<sflnum>')
16  map foo<C-V> is<F4>foo
17  vnoremap <script> <buffer> <expr> <silent> bar isbar
18  call assert_equal("is<F4>foo", maparg('foo<C-V>'))
19  call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'foo<C-V>',
20        \ 'mode': ' ', 'nowait': 0, 'expr': 0, 'sid': sid, 'lnum': lnum + 1,
21	\ 'rhs': 'is<F4>foo', 'buffer': 0},
22	\ maparg('foo<C-V>', '', 0, 1))
23  call assert_equal({'silent': 1, 'noremap': 1, 'lhs': 'bar', 'mode': 'v',
24        \ 'nowait': 0, 'expr': 1, 'sid': sid, 'lnum': lnum + 2,
25	\ 'rhs': 'isbar', 'buffer': 1},
26        \ 'bar'->maparg('', 0, 1))
27  let lnum = expand('<sflnum>')
28  map <buffer> <nowait> foo bar
29  call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'foo', 'mode': ' ',
30        \ 'nowait': 1, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, 'rhs': 'bar',
31	\ 'buffer': 1},
32        \ maparg('foo', '', 0, 1))
33  let lnum = expand('<sflnum>')
34  tmap baz foo
35  call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'baz', 'mode': 't',
36        \ 'nowait': 0, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, 'rhs': 'foo',
37	\ 'buffer': 0},
38        \ maparg('baz', 't', 0, 1))
39
40  map abc x<char-114>x
41  call assert_equal("xrx", maparg('abc'))
42  map abc y<S-char-114>y
43  call assert_equal("yRy", maparg('abc'))
44
45  omap { w
46  let d = maparg('{', 'o', 0, 1)
47  call assert_equal(['{', 'w', 'o'], [d.lhs, d.rhs, d.mode])
48  ounmap {
49
50  map abc <Nop>
51  call assert_equal("<Nop>", maparg('abc'))
52  unmap abc
53endfunction
54
55func Test_mapcheck()
56  call assert_equal('', mapcheck('a'))
57  call assert_equal('', mapcheck('abc'))
58  call assert_equal('', mapcheck('ax'))
59  call assert_equal('', mapcheck('b'))
60
61  map a something
62  call assert_equal('something', mapcheck('a'))
63  call assert_equal('something', mapcheck('a', 'n'))
64  call assert_equal('', mapcheck('a', 'c'))
65  call assert_equal('', mapcheck('a', 'i'))
66  call assert_equal('something', 'abc'->mapcheck())
67  call assert_equal('something', 'ax'->mapcheck())
68  call assert_equal('', mapcheck('b'))
69  unmap a
70
71  map ab foobar
72  call assert_equal('foobar', mapcheck('a'))
73  call assert_equal('foobar', mapcheck('abc'))
74  call assert_equal('', mapcheck('ax'))
75  call assert_equal('', mapcheck('b'))
76  unmap ab
77
78  map abc barfoo
79  call assert_equal('barfoo', mapcheck('a'))
80  call assert_equal('barfoo', mapcheck('a', 'n', 0))
81  call assert_equal('', mapcheck('a', 'n', 1))
82  call assert_equal('barfoo', mapcheck('abc'))
83  call assert_equal('', mapcheck('ax'))
84  call assert_equal('', mapcheck('b'))
85  unmap abc
86
87  abbr ab abbrev
88  call assert_equal('abbrev', mapcheck('a', 'i', 1))
89  call assert_equal('', mapcheck('a', 'n', 1))
90  call assert_equal('', mapcheck('a', 'i', 0))
91  unabbr ab
92endfunc
93
94function Test_range_map()
95  new
96  " Outside of the range, minimum
97  inoremap <Char-0x1040> a
98  execute "normal a\u1040\<Esc>"
99  " Inside of the range, minimum
100  inoremap <Char-0x103f> b
101  execute "normal a\u103f\<Esc>"
102  " Inside of the range, maximum
103  inoremap <Char-0xf03f> c
104  execute "normal a\uf03f\<Esc>"
105  " Outside of the range, maximum
106  inoremap <Char-0xf040> d
107  execute "normal a\uf040\<Esc>"
108  call assert_equal("abcd", getline(1))
109endfunction
110
111" vim: shiftwidth=2 sts=2 expandtab
112