• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Révisionad40333f2ec0ea76b2cbcec6ff93886287d91551 (tree)
l'heure2020-01-24 00:30:04
AuteurBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Message de Log

patch 8.2.0144: some mapping code is not fully tested

Commit: https://github.com/vim/vim/commit/c2a60ae10e7badad9186de59a9994fc8c9f539e0
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jan 23 16:19:54 2020 +0100

patch 8.2.0144: some mapping code is not fully tested
Problem: Some mapping code is not fully tested.
Solution: Add more test cases. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5519)

Change Summary

Modification

diff -r cc6d4aa341fd -r ad40333f2ec0 src/testdir/test_langmap.vim
--- a/src/testdir/test_langmap.vim Thu Jan 23 16:00:04 2020 +0100
+++ b/src/testdir/test_langmap.vim Thu Jan 23 16:30:04 2020 +0100
@@ -23,5 +23,32 @@
2323 silent! call feedkeys("gg0}%}\<C-G>}^\<Esc>00", 'tx')
2424 call assert_equal('a}^de', getline(1))
2525
26+ " Error cases
27+ call assert_fails('set langmap=aA,b', 'E357:')
28+ call assert_fails('set langmap=z;y;y;z', 'E358:')
29+
30+ " Map character > 256
31+ enew!
32+ set langmap=āx,ăl,āx
33+ call setline(1, ['abcde'])
34+ call feedkeys('gg2lā', 'tx')
35+ call assert_equal('abde', getline(1))
36+
37+ " special characters in langmap
38+ enew!
39+ call setline(1, ['Hello World'])
40+ set langmap=\\;\\,,\\,\\;
41+ call feedkeys('ggfo,', 'tx')
42+ call assert_equal(8, col('.'))
43+ call feedkeys(';', 'tx')
44+ call assert_equal(5, col('.'))
45+ set langmap&
46+ set langmap=\\;\\,;\\,\\;
47+ call feedkeys('ggfo,', 'tx')
48+ call assert_equal(8, col('.'))
49+ call feedkeys(';', 'tx')
50+ call assert_equal(5, col('.'))
51+
52+ set langmap&
2653 quit!
2754 endfunc
diff -r cc6d4aa341fd -r ad40333f2ec0 src/testdir/test_maparg.vim
--- a/src/testdir/test_maparg.vim Thu Jan 23 16:00:04 2020 +0100
+++ b/src/testdir/test_maparg.vim Thu Jan 23 16:30:04 2020 +0100
@@ -47,9 +47,34 @@
4747 call assert_equal(['{', 'w', 'o'], [d.lhs, d.rhs, d.mode])
4848 ounmap {
4949
50+ lmap { w
51+ let d = maparg('{', 'l', 0, 1)
52+ call assert_equal(['{', 'w', 'l'], [d.lhs, d.rhs, d.mode])
53+ lunmap {
54+
55+ nmap { w
56+ let d = maparg('{', 'n', 0, 1)
57+ call assert_equal(['{', 'w', 'n'], [d.lhs, d.rhs, d.mode])
58+ nunmap {
59+
60+ xmap { w
61+ let d = maparg('{', 'x', 0, 1)
62+ call assert_equal(['{', 'w', 'x'], [d.lhs, d.rhs, d.mode])
63+ xunmap {
64+
65+ smap { w
66+ let d = maparg('{', 's', 0, 1)
67+ call assert_equal(['{', 'w', 's'], [d.lhs, d.rhs, d.mode])
68+ sunmap {
69+
5070 map abc <Nop>
5171 call assert_equal("<Nop>", maparg('abc'))
5272 unmap abc
73+
74+ call feedkeys(":abbr esc \<C-V>\<C-V>\<C-V>\<C-V>\<C-V>\<Esc>\<CR>", "xt")
75+ let d = maparg('esc', 'i', 1, 1)
76+ call assert_equal(['esc', "\<C-V>\<C-V>\<Esc>", '!'], [d.lhs, d.rhs, d.mode])
77+ abclear
5378 endfunction
5479
5580 func Test_mapcheck()
diff -r cc6d4aa341fd -r ad40333f2ec0 src/testdir/test_mapping.vim
--- a/src/testdir/test_mapping.vim Thu Jan 23 16:00:04 2020 +0100
+++ b/src/testdir/test_mapping.vim Thu Jan 23 16:30:04 2020 +0100
@@ -461,6 +461,22 @@
461461 call assert_equal(['i <S-/> * ShiftSlash'], execute('imap')->trim()->split("\n"))
462462 iunmap <S-/>
463463 call assert_equal(['No mapping found'], execute('imap')->trim()->split("\n"))
464+
465+ " List global, buffer local and script local mappings
466+ nmap ,f /^\k\+ (<CR>
467+ nmap <buffer> ,f /^\k\+ (<CR>
468+ nmap <script> ,fs /^\k\+ (<CR>
469+ call assert_equal(['n ,f @/^\k\+ (<CR>',
470+ \ 'n ,fs & /^\k\+ (<CR>',
471+ \ 'n ,f /^\k\+ (<CR>'],
472+ \ execute('nmap ,f')->trim()->split("\n"))
473+
474+ " List <Nop> mapping
475+ nmap ,n <Nop>
476+ call assert_equal(['n ,n <Nop>'],
477+ \ execute('nmap ,n')->trim()->split("\n"))
478+
479+ nmapclear
464480 endfunc
465481
466482 func Test_expr_map_restore_cursor()
@@ -518,6 +534,15 @@
518534
519535 call assert_fails('mapclear abc', 'E474:')
520536 call assert_fails('abclear abc', 'E474:')
537+ call assert_fails('abbr $xyz abc', 'E474:')
538+
539+ " space character in an abbreviation
540+ call assert_fails('abbr ab<space> ABC', 'E474:')
541+
542+ " invalid <expr> map
543+ map <expr> ,f abc
544+ call assert_fails('normal ,f', 'E121:')
545+ unmap <expr> ,f
521546 endfunc
522547
523548 " Test for <special> key mapping
@@ -544,11 +569,66 @@
544569 " Test for hasmapto()
545570 func Test_hasmapto()
546571 call assert_equal(0, hasmapto('/^\k\+ ('))
572+ map ,f /^\k\+ (<CR>
573+ call assert_equal(1, hasmapto('/^\k\+ ('))
574+ unmap ,f
575+
576+ " Insert mode mapping
577+ call assert_equal(0, hasmapto('/^\k\+ (', 'i'))
578+ imap ,f /^\k\+ (<CR>
579+ call assert_equal(1, hasmapto('/^\k\+ (', 'i'))
580+ iunmap ,f
581+
582+ " Normal mode mapping
547583 call assert_equal(0, hasmapto('/^\k\+ (', 'n'))
548584 nmap ,f /^\k\+ (<CR>
549585 call assert_equal(1, hasmapto('/^\k\+ ('))
550586 call assert_equal(1, hasmapto('/^\k\+ (', 'n'))
587+ nunmap ,f
588+
589+ " Visual and Select mode mapping
551590 call assert_equal(0, hasmapto('/^\k\+ (', 'v'))
591+ call assert_equal(0, hasmapto('/^\k\+ (', 'x'))
592+ call assert_equal(0, hasmapto('/^\k\+ (', 's'))
593+ vmap ,f /^\k\+ (<CR>
594+ call assert_equal(1, hasmapto('/^\k\+ (', 'v'))
595+ call assert_equal(1, hasmapto('/^\k\+ (', 'x'))
596+ call assert_equal(1, hasmapto('/^\k\+ (', 's'))
597+ vunmap ,f
598+
599+ " Visual mode mapping
600+ call assert_equal(0, hasmapto('/^\k\+ (', 'x'))
601+ xmap ,f /^\k\+ (<CR>
602+ call assert_equal(1, hasmapto('/^\k\+ (', 'v'))
603+ call assert_equal(1, hasmapto('/^\k\+ (', 'x'))
604+ call assert_equal(0, hasmapto('/^\k\+ (', 's'))
605+ xunmap ,f
606+
607+ " Select mode mapping
608+ call assert_equal(0, hasmapto('/^\k\+ (', 's'))
609+ smap ,f /^\k\+ (<CR>
610+ call assert_equal(1, hasmapto('/^\k\+ (', 'v'))
611+ call assert_equal(0, hasmapto('/^\k\+ (', 'x'))
612+ call assert_equal(1, hasmapto('/^\k\+ (', 's'))
613+ sunmap ,f
614+
615+ " Operator-pending mode mapping
616+ call assert_equal(0, hasmapto('/^\k\+ (', 'o'))
617+ omap ,f /^\k\+ (<CR>
618+ call assert_equal(1, hasmapto('/^\k\+ (', 'o'))
619+ ounmap ,f
620+
621+ " Language mapping
622+ call assert_equal(0, hasmapto('/^\k\+ (', 'l'))
623+ lmap ,f /^\k\+ (<CR>
624+ call assert_equal(1, hasmapto('/^\k\+ (', 'l'))
625+ lunmap ,f
626+
627+ " Cmdline mode mapping
628+ call assert_equal(0, hasmapto('/^\k\+ (', 'c'))
629+ cmap ,f /^\k\+ (<CR>
630+ call assert_equal(1, hasmapto('/^\k\+ (', 'c'))
631+ cunmap ,f
552632
553633 call assert_equal(0, hasmapto('/^\k\+ (', 'n', 1))
554634 endfunc
@@ -560,8 +640,176 @@
560640 \ getcompletion('', 'mapping'))
561641 call assert_equal([], getcompletion(',d', 'mapping'))
562642
643+ call feedkeys(":unmap <buf\<C-A>\<C-B>\"\<CR>", 'tx')
644+ call assert_equal('"unmap <buffer>', @:)
645+
646+ call feedkeys(":unabbr <buf\<C-A>\<C-B>\"\<CR>", 'tx')
647+ call assert_equal('"unabbr <buffer>', @:)
648+
563649 call feedkeys(":abbr! \<C-A>\<C-B>\"\<CR>", 'tx')
564- call assert_match("abbr! \x01", @:)
650+ call assert_equal("\"abbr! \x01", @:)
651+
652+ " Multiple matches for a map
653+ nmap ,f /H<CR>
654+ omap ,f /H<CR>
655+ call feedkeys(":map ,\<C-A>\<C-B>\"\<CR>", 'tx')
656+ call assert_equal('"map ,f', @:)
657+ mapclear
658+endfunc
659+
660+" Test for <expr> in abbreviation
661+func Test_expr_abbr()
662+ new
663+ iabbr <expr> teh "the"
664+ call feedkeys("iteh ", "tx")
665+ call assert_equal('the ', getline(1))
666+ iabclear
667+ call setline(1, '')
668+
669+ " invalid <expr> abbreviation
670+ abbr <expr> hte GetAbbr()
671+ call assert_fails('normal ihte ', 'E117:')
672+ call assert_equal(' ', getline(1))
673+ unabbr <expr> hte
674+
675+ close!
676+endfunc
677+
678+" Test for storing mappings in different modes in a vimrc file
679+func Test_mkvimrc_mapmodes()
680+ map a1 /a1
681+ nmap a2 /a2
682+ vmap a3 /a3
683+ smap a4 /a4
684+ xmap a5 /a5
685+ omap a6 /a6
686+ map! a7 /a7
687+ imap a8 /a8
688+ lmap a9 /a9
689+ cmap a10 /a10
690+ tmap a11 /a11
691+ " Normal + Visual map
692+ map a12 /a12
693+ sunmap a12
694+ ounmap a12
695+ " Normal + Selectmode map
696+ map a13 /a13
697+ xunmap a13
698+ ounmap a13
699+ " Normal + OpPending map
700+ map a14 /a14
701+ vunmap a14
702+ " Visual + Selectmode map
703+ map a15 /a15
704+ nunmap a15
705+ ounmap a15
706+ " Visual + OpPending map
707+ map a16 /a16
708+ nunmap a16
709+ sunmap a16
710+ " Selectmode + OpPending map
711+ map a17 /a17
712+ nunmap a17
713+ xunmap a17
714+ " Normal + Visual + Selectmode map
715+ map a18 /a18
716+ ounmap a18
717+ " Normal + Visual + OpPending map
718+ map a19 /a19
719+ sunmap a19
720+ " Normal + Selectmode + OpPending map
721+ map a20 /a20
722+ xunmap a20
723+ " Visual + Selectmode + OpPending map
724+ map a21 /a21
725+ nunmap a21
726+ " Mapping to Nop
727+ map a22 <Nop>
728+ " Script local mapping
729+ map <script> a23 /a23
730+
731+ " Newline in {lhs} and {rhs} of a map
732+ exe "map a24\<C-V>\<C-J> ia24\<C-V>\<C-J><Esc>"
733+
734+ " Abbreviation
735+ abbr a25 A25
736+ cabbr a26 A26
737+ iabbr a27 A27
738+
739+ mkvimrc! Xvimrc
740+ let l = readfile('Xvimrc')
741+ call assert_equal(['map a1 /a1'], filter(copy(l), 'v:val =~ " a1 "'))
742+ call assert_equal(['nmap a2 /a2'], filter(copy(l), 'v:val =~ " a2 "'))
743+ call assert_equal(['vmap a3 /a3'], filter(copy(l), 'v:val =~ " a3 "'))
744+ call assert_equal(['smap a4 /a4'], filter(copy(l), 'v:val =~ " a4 "'))
745+ call assert_equal(['xmap a5 /a5'], filter(copy(l), 'v:val =~ " a5 "'))
746+ call assert_equal(['omap a6 /a6'], filter(copy(l), 'v:val =~ " a6 "'))
747+ call assert_equal(['map! a7 /a7'], filter(copy(l), 'v:val =~ " a7 "'))
748+ call assert_equal(['imap a8 /a8'], filter(copy(l), 'v:val =~ " a8 "'))
749+ call assert_equal(['lmap a9 /a9'], filter(copy(l), 'v:val =~ " a9 "'))
750+ call assert_equal(['cmap a10 /a10'], filter(copy(l), 'v:val =~ " a10 "'))
751+ call assert_equal(['tmap a11 /a11'], filter(copy(l), 'v:val =~ " a11 "'))
752+ call assert_equal(['nmap a12 /a12', 'xmap a12 /a12'],
753+ \ filter(copy(l), 'v:val =~ " a12 "'))
754+ call assert_equal(['nmap a13 /a13', 'smap a13 /a13'],
755+ \ filter(copy(l), 'v:val =~ " a13 "'))
756+ call assert_equal(['nmap a14 /a14', 'omap a14 /a14'],
757+ \ filter(copy(l), 'v:val =~ " a14 "'))
758+ call assert_equal(['vmap a15 /a15'], filter(copy(l), 'v:val =~ " a15 "'))
759+ call assert_equal(['xmap a16 /a16', 'omap a16 /a16'],
760+ \ filter(copy(l), 'v:val =~ " a16 "'))
761+ call assert_equal(['smap a17 /a17', 'omap a17 /a17'],
762+ \ filter(copy(l), 'v:val =~ " a17 "'))
763+ call assert_equal(['nmap a18 /a18', 'vmap a18 /a18'],
764+ \ filter(copy(l), 'v:val =~ " a18 "'))
765+ call assert_equal(['nmap a19 /a19', 'xmap a19 /a19', 'omap a19 /a19'],
766+ \ filter(copy(l), 'v:val =~ " a19 "'))
767+ call assert_equal(['nmap a20 /a20', 'smap a20 /a20', 'omap a20 /a20'],
768+ \ filter(copy(l), 'v:val =~ " a20 "'))
769+ call assert_equal(['vmap a21 /a21', 'omap a21 /a21'],
770+ \ filter(copy(l), 'v:val =~ " a21 "'))
771+ call assert_equal(['map a22 <Nop>'], filter(copy(l), 'v:val =~ " a22 "'))
772+ call assert_equal([], filter(copy(l), 'v:val =~ " a23 "'))
773+ call assert_equal(["map a24<NL> ia24<NL>\x16\e"],
774+ \ filter(copy(l), 'v:val =~ " a24"'))
775+
776+ call assert_equal(['abbr a25 A25'], filter(copy(l), 'v:val =~ " a25 "'))
777+ call assert_equal(['cabbr a26 A26'], filter(copy(l), 'v:val =~ " a26 "'))
778+ call assert_equal(['iabbr a27 A27'], filter(copy(l), 'v:val =~ " a27 "'))
779+ call delete('Xvimrc')
780+
781+ mapclear
782+ nmapclear
783+ vmapclear
784+ xmapclear
785+ smapclear
786+ omapclear
787+ imapclear
788+ lmapclear
789+ cmapclear
790+ tmapclear
791+endfunc
792+
793+" Test for recursive mapping ('maxmapdepth')
794+func Test_map_recursive()
795+ map x y
796+ map y x
797+ call assert_fails('normal x', 'E223:')
798+ unmap x
799+ unmap y
800+endfunc
801+
802+" Test for removing an abbreviation using {rhs} and with space after {lhs}
803+func Test_abbr_remove()
804+ abbr foo bar
805+ let d = maparg('foo', 'i', 1, 1)
806+ call assert_equal(['foo', 'bar', '!'], [d.lhs, d.rhs, d.mode])
807+ unabbr bar
808+ call assert_equal({}, maparg('foo', 'i', 1, 1))
809+
810+ abbr foo bar
811+ unabbr foo<space><tab>
812+ call assert_equal({}, maparg('foo', 'i', 1, 1))
565813 endfunc
566814
567815 " vim: shiftwidth=2 sts=2 expandtab
diff -r cc6d4aa341fd -r ad40333f2ec0 src/version.c
--- a/src/version.c Thu Jan 23 16:00:04 2020 +0100
+++ b/src/version.c Thu Jan 23 16:30:04 2020 +0100
@@ -743,6 +743,8 @@
743743 static int included_patches[] =
744744 { /* Add new patch number below this line */
745745 /**/
746+ 144,
747+/**/
746748 143,
747749 /**/
748750 142,
Afficher sur ancien navigateur de dépôt.