" Test that the system menu can be loaded. source check.vim CheckFeature menu func Test_load_menu() try source $VIMRUNTIME/menu.vim catch call assert_report('error while loading menus: ' . v:exception) endtry call assert_match('browse confirm w', execute(':menu File.Save')) let v:errmsg = '' doautocmd LoadBufferMenu VimEnter call assert_equal('', v:errmsg) source $VIMRUNTIME/delmenu.vim call assert_equal('', v:errmsg) endfunc func Test_buffer_menu_special_buffers() " Load in runtime menus try source $VIMRUNTIME/menu.vim catch call assert_report('error while loading menus: ' . v:exception) endtry let v:errmsg = '' doautocmd LoadBufferMenu VimEnter call assert_equal('', v:errmsg) let orig_buffer_menus = execute("nmenu Buffers") " Test that regular new buffer results in a new buffer menu item. new let new_buffer_menus = execute('nmenu Buffers') call assert_equal(len(split(orig_buffer_menus, "\n")) + 2, len(split(new_buffer_menus, "\n"))) bwipe! call assert_equal(orig_buffer_menus, execute("nmenu Buffers")) " Make a new command-line window, test that it does not create a new buffer " menu. call feedkeys("q::let cmdline_buffer_menus=execute('nmenu Buffers')\:q\", 'ntx') call assert_equal(len(split(orig_buffer_menus, "\n")) + 2, len(split(cmdline_buffer_menus, "\n"))) call assert_equal(orig_buffer_menus, execute("nmenu Buffers")) if has('terminal') " Open a terminal window and test that it does not create a buffer menu " item. terminal let term_buffer_menus = execute('nmenu Buffers') call assert_equal(len(split(orig_buffer_menus, "\n")) + 2, len(split(term_buffer_menus, "\n"))) bwipe! call assert_equal(orig_buffer_menus, execute("nmenu Buffers")) endif " Remove menus to clean up source $VIMRUNTIME/delmenu.vim call assert_equal('', v:errmsg) endfunc func Test_translate_menu() if !has('multi_lang') return endif if !filereadable($VIMRUNTIME . '/lang/menu_de_de.latin1.vim') throw 'Skipped: translated menu not found' endif " First delete any English menus. source $VIMRUNTIME/delmenu.vim set langmenu=de_de source $VIMRUNTIME/menu.vim call assert_match('browse confirm w', execute(':menu Datei.Speichern')) source $VIMRUNTIME/delmenu.vim endfunc func Test_menu_commands() nmenu 2 Test.FooBar :let g:did_menu = 'normal' vmenu 2 Test.FooBar :let g:did_menu = 'visual' smenu 2 Test.FooBar :let g:did_menu = 'select' omenu 2 Test.FooBar :let g:did_menu = 'op-pending' tlmenu 2 Test.FooBar :let g:did_menu = 'terminal' imenu 2 Test.FooBar :let g:did_menu = 'insert' cmenu 2 Test.FooBar :let g:did_menu = 'cmdline' emenu n Test.FooBar call feedkeys(":menu Test.FooB\\\"\", 'tx') call assert_equal('"menu Test.FooBar', @:) call assert_equal('normal', g:did_menu) emenu v Test.FooBar call assert_equal('visual', g:did_menu) emenu s Test.FooBar call assert_equal('select', g:did_menu) emenu o Test.FooBar call assert_equal('op-pending', g:did_menu) emenu t Test.FooBar call assert_equal('terminal', g:did_menu) emenu i Test.FooBar call assert_equal('insert', g:did_menu) emenu c Test.FooBar call assert_equal('cmdline', g:did_menu) nunmenu Test.FooBar call assert_fails('emenu n Test.FooBar', 'E335: Menu not defined for Normal mode') vunmenu Test.FooBar call assert_fails('emenu v Test.FooBar', 'E335: Menu not defined for Visual mode') vmenu 2 Test.FooBar :let g:did_menu = 'visual' sunmenu Test.FooBar call assert_fails('emenu s Test.FooBar', 'E335: Menu not defined for Select mode') ounmenu Test.FooBar call assert_fails('emenu o Test.FooBar', 'E335: Menu not defined for Op-pending mode') iunmenu Test.FooBar call assert_fails('emenu i Test.FooBar', 'E335: Menu not defined for Insert mode') cunmenu Test.FooBar call assert_fails('emenu c Test.FooBar', 'E335: Menu not defined for Cmdline mode') tlunmenu Test.FooBar call assert_fails('emenu t Test.FooBar', 'E335: Menu not defined for Terminal mode') aunmenu Test.FooBar call assert_fails('emenu n Test.FooBar', 'E334:') nmenu 2 Test.FooBar.Child :let g:did_menu = 'foobar' call assert_fails('emenu n Test.FooBar', 'E333:') nunmenu Test.FooBar.Child unlet g:did_menu endfun " Test various menu related errors func Test_menu_errors() menu Test.Foo :version " Error cases call assert_fails('menu .Test.Foo :ls', 'E475:') call assert_fails('menu Test. :ls', 'E330:') call assert_fails('menu Foo. :ls', 'E331:') call assert_fails('unmenu Test.Foo abc', 'E488:') call assert_fails('menu :ls :ls', 'E792:') call assert_fails('menu Test.:ls :ls', 'E792:') call assert_fails('menu Test.Foo.Bar :ls', 'E327:') call assert_fails('menu Test.-Sep-.Baz :ls', 'E332:') call assert_fails('menu Foo.Bar.--.Baz :ls', 'E332:') call assert_fails('menu disable Test.Foo.Bar', 'E327:') call assert_fails('menu disable T.Foo', 'E329:') call assert_fails('unmenu Test.Foo.Bar', 'E327:') call assert_fails('cunmenu Test.Foo', 'E328:') call assert_fails('unmenu Test.Bar', 'E329:') call assert_fails('menu Test.Foo.Bar', 'E327:') call assert_fails('cmenu Test.Foo', 'E328:') call assert_fails('emenu x Test.Foo', 'E475:') call assert_fails('emenu Test.Foo.Bar', 'E327:') call assert_fails('menutranslate Test', 'E474:') silent! unmenu Foo unmenu Test endfunc " Test for menu item completion in command line func Test_menu_expand() " Create the menu itmes for test menu Dummy.Nothing lll for i in range(1, 4) let m = 'menu Xmenu.A' .. i .. '.A' .. i for j in range(1, 4) exe m .. 'B' .. j .. ' :echo "A' .. i .. 'B' .. j .. '"' .. "" endfor endfor set wildmenu " Test for selecting a submenu call feedkeys(":emenu Xmenu.A\\\x\\\"\", 'xt') call assert_equal('"emenu Xmenu.A1.A1B2', @:) " Test for selecting a submenu call feedkeys(":emenu Xmenu.A\\\\" .. \ "\\\"\", 'xt') call assert_equal('"emenu Xmenu.A3.A3B1 A3B2 A3B3 A3B4', @:) " Test for to go up a submenu call feedkeys(":emenu Xmenu.A\\\\\" .. \ "\\\\\"\", 'xt') call assert_equal('"emenu Xmenu.A2.A2B1 A2B2 A2B3 A2B4', @:) " Test for to go up a menu call feedkeys(":emenu Xmenu.A\\\\\" .. \ "\\\"\", 'xt') call assert_equal('"emenu Dummy. Xmenu.', @:) " Test for expanding only submenus call feedkeys(":popup Xmenu.\\\"\", 'xt') call assert_equal('"popup Xmenu.A1 A2 A3 A4', @:) " Test for expanding menus after enable/disable call feedkeys(":menu enable Xmenu.\\\"\", 'xt') call assert_equal('"menu enable Xmenu.A1. A2. A3. A4.', @:) call feedkeys(":menu disable Xmenu.\\\"\", 'xt') call assert_equal('"menu disable Xmenu.A1. A2. A3. A4.', @:) " Test for expanding non-existing menu path call feedkeys(":menu xyz.\\\"\", 'xt') call assert_equal('"menu xyz.', @:) call feedkeys(":menu Xmenu.A1.A1B1.xyz.\\\"\", 'xt') call assert_equal('"menu Xmenu.A1.A1B1.xyz.', @:) set wildmenu& unmenu Xmenu unmenu Dummy " Test for expanding popup menus with some hidden items menu Xmenu.foo.A1 a1 menu Xmenu.]bar bar menu Xmenu.]baz.B1 b1 menu Xmenu.-sep- : call feedkeys(":popup Xmenu.\\\"\", 'xt') call assert_equal('"popup Xmenu.foo', @:) unmenu Xmenu endfunc " Test for the menu_info() function func Test_menu_info() " Define menus with various attributes 10nnoremenu 10.10 T&est.F&oo :echo 'foo' 10nmenu 10.20 T&est.B&ar:bar :echo 'bar' 10nmenu