diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 02:44:24 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 02:44:24 +0000 |
commit | 8baab3c8d7a6f22888bd581cd5c6098fd2e4b5a8 (patch) | |
tree | 3537e168b860f2742f6029d70501b5ed7d15d345 /src/testdir | |
parent | Initial commit. (diff) | |
download | vim-upstream.tar.xz vim-upstream.zip |
Adding upstream version 2:8.1.0875.upstream/2%8.1.0875upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/testdir')
425 files changed, 88365 insertions, 0 deletions
diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak new file mode 100644 index 0000000..5857a22 --- /dev/null +++ b/src/testdir/Make_all.mak @@ -0,0 +1,418 @@ +# +# Common Makefile, defines the list of tests to run. +# + +# Options for protecting the tests against undesirable interaction with the +# environment +NO_PLUGINS = --noplugin --not-a-term +NO_INITS = -U NONE $(NO_PLUGINS) + +# The first script creates small.vim. +SCRIPTS_FIRST = \ + test1.out + +# Tests that run on all systems. +SCRIPTS_ALL = \ + test3.out \ + test14.out \ + test29.out \ + test37.out \ + test39.out \ + test42.out \ + test44.out \ + test48.out \ + test64.out \ + test69.out \ + test70.out \ + test88.out \ + test94.out \ + test95.out \ + test99.out \ + test108.out \ + test_eval.out + + +# Tests that run on most systems, but not on Amiga. +SCRIPTS_MORE1 = \ + test11.out \ + test52.out \ + test86.out \ + test87.out + + +# Tests that run on most systems, but not on Amiga and DOS/Windows. +SCRIPTS_MORE2 = \ + test49.out + + +# Tests that run on most systems, but not on VMS +SCRIPTS_MORE4 = \ + test17.out \ + test30.out \ + test59.out \ + test72.out \ + + +# Tests specifically for MS-Windows. +SCRIPTS_WIN32 = + + +# Tests for the GUI. +SCRIPTS_GUI = + +# Individual tests, including the ones part of test_alot. +# Please keep sorted up to test_alot. +NEW_TESTS = \ + test_arglist \ + test_arabic \ + test_assert \ + test_assign \ + test_autochdir \ + test_autocmd \ + test_autoload \ + test_backspace_opt \ + test_backup \ + test_behave \ + test_blob \ + test_blockedit \ + test_breakindent \ + test_bufline \ + test_bufwintabinfo \ + test_cd \ + test_cdo \ + test_changedtick \ + test_changelist \ + test_channel \ + test_charsearch \ + test_charsearch_utf8 \ + test_cindent \ + test_clientserver \ + test_close_count \ + test_cmdline \ + test_command_count \ + test_comparators \ + test_compiler \ + test_conceal \ + test_crypt \ + test_cscope \ + test_cursor_func \ + test_curswant \ + test_delete \ + test_diffmode \ + test_digraph \ + test_display \ + test_edit \ + test_erasebackword \ + test_escaped_glob \ + test_eval_stuff \ + test_ex_equal \ + test_ex_undo \ + test_ex_z \ + test_exit \ + test_exec_while_if \ + test_execute_func \ + test_exists \ + test_exists_autocmd \ + test_expand \ + test_expand_dllpath \ + test_expand_func \ + test_expr \ + test_expr_utf8 \ + test_farsi \ + test_feedkeys \ + test_file_perm \ + test_file_size \ + test_filechanged \ + test_fileformat \ + test_filetype \ + test_filter_cmd \ + test_filter_map \ + test_find_complete \ + test_findfile \ + test_fixeol \ + test_float_func \ + test_fnameescape \ + test_fnamemodify \ + test_fold \ + test_functions \ + test_ga \ + test_getcwd \ + test_getvar \ + test_gf \ + test_glob2regpat \ + test_global \ + test_gn \ + test_goto \ + test_gui \ + test_gui_init \ + test_hardcopy \ + test_help \ + test_help_tagjump \ + test_hide \ + test_highlight \ + test_history \ + test_hlsearch \ + test_iminsert \ + test_increment \ + test_increment_dbcs \ + test_ins_complete \ + test_job_fails \ + test_join \ + test_json \ + test_jumplist \ + test_jumps \ + test_lambda \ + test_langmap \ + test_largefile \ + test_let \ + test_lineending \ + test_lispwords \ + test_listchars \ + test_listdict \ + test_listlbr \ + test_listlbr_utf8 \ + test_lua \ + test_makeencoding \ + test_man \ + test_maparg \ + test_mapping \ + test_marks \ + test_match \ + test_matchadd_conceal \ + test_matchadd_conceal_utf8 \ + test_menu \ + test_messages \ + test_mksession \ + test_mksession_utf8 \ + test_modeline \ + test_move \ + test_nested_function \ + test_netbeans \ + test_normal \ + test_number \ + test_options \ + test_packadd \ + test_partial \ + test_paste \ + test_perl \ + test_plus_arg_edit \ + test_popup \ + test_preview \ + test_profile \ + test_prompt_buffer \ + test_put \ + test_python2 \ + test_python3 \ + test_pyx2 \ + test_pyx3 \ + test_quickfix \ + test_quotestar \ + test_recover \ + test_regex_char_classes \ + test_regexp_latin \ + test_regexp_utf8 \ + test_registers \ + test_reltime \ + test_retab \ + test_ruby \ + test_scriptnames \ + test_scroll_opt \ + test_scrollbind \ + test_search \ + test_searchpos \ + test_set \ + test_sha256 \ + test_signs \ + test_smartindent \ + test_sort \ + test_source \ + test_source_utf8 \ + test_spell \ + test_startup \ + test_startup_utf8 \ + test_stat \ + test_statusline \ + test_substitute \ + test_suspend \ + test_swap \ + test_syn_attr \ + test_syntax \ + test_system \ + test_tab \ + test_tabline \ + test_tabpage \ + test_tagcase \ + test_tagjump \ + test_taglist \ + test_tcl \ + test_termencoding \ + test_terminal \ + test_terminal_fail \ + test_textformat \ + test_textobjects \ + test_textprop \ + test_timers \ + test_true_false \ + test_undo \ + test_unlet \ + test_usercommands \ + test_utf8 \ + test_utf8_comparisons \ + test_vartabs \ + test_viminfo \ + test_vimscript \ + test_virtualedit \ + test_visual \ + test_winbar \ + test_winbuf_close \ + test_window_cmd \ + test_window_id \ + test_windows_home \ + test_wordcount \ + test_writefile \ + test_xxd \ + test_alot_latin \ + test_alot_utf8 \ + test_alot + + +# Test targets that use runtest.vim. +# Keep test_alot*.res as the last one, sort the others. +# test_largefile.res is omitted, it uses too much resources to run on CI. +NEW_TESTS_RES = \ + test_arabic.res \ + test_arglist.res \ + test_assert.res \ + test_autochdir.res \ + test_autocmd.res \ + test_autoload.res \ + test_backspace_opt.res \ + test_blob.res \ + test_blockedit.res \ + test_breakindent.res \ + test_bufwintabinfo.res \ + test_cdo.res \ + test_changelist.res \ + test_channel.res \ + test_charsearch.res \ + test_cindent.res \ + test_clientserver.res \ + test_close_count.res \ + test_cmdline.res \ + test_command_count.res \ + test_comparators.res \ + test_conceal.res \ + test_crypt.res \ + test_cscope.res \ + test_curswant.res \ + test_diffmode.res \ + test_digraph.res \ + test_display.res \ + test_edit.res \ + test_erasebackword.res \ + test_escaped_glob.res \ + test_eval_stuff.res \ + test_exec_while_if.res \ + test_exists.res \ + test_exists_autocmd.res \ + test_exit.res \ + test_farsi.res \ + test_file_size.res \ + test_filechanged.res \ + test_find_complete.res \ + test_fixeol.res \ + test_fnameescape.res \ + test_fold.res \ + test_getcwd.res \ + test_getvar.res \ + test_gf.res \ + test_gn.res \ + test_gui.res \ + test_gui_init.res \ + test_hardcopy.res \ + test_help.res \ + test_hide.res \ + test_highlight.res \ + test_history.res \ + test_hlsearch.res \ + test_iminsert.res \ + test_increment.res \ + test_increment_dbcs.res \ + test_ins_complete.res \ + test_job_fails.res \ + test_json.res \ + test_jumplist.res \ + test_langmap.res \ + test_let.res \ + test_lineending.res \ + test_listchars.res \ + test_listdict.res \ + test_listlbr.res \ + test_lua.res \ + test_makeencoding.res \ + test_man.res \ + test_maparg.res \ + test_marks.res \ + test_matchadd_conceal.res \ + test_mksession.res \ + test_nested_function.res \ + test_netbeans.res \ + test_normal.res \ + test_number.res \ + test_options.res \ + test_packadd.res \ + test_paste.res \ + test_perl.res \ + test_plus_arg_edit.res \ + test_preview.res \ + test_profile.res \ + test_prompt_buffer.res \ + test_python2.res \ + test_python3.res \ + test_pyx2.res \ + test_pyx3.res \ + test_quickfix.res \ + test_quotestar.res \ + test_regex_char_classes.res \ + test_registers.res \ + test_retab.res \ + test_ruby.res \ + test_scriptnames.res \ + test_scrollbind.res \ + test_search.res \ + test_shortpathname.res \ + test_signs.res \ + test_smartindent.res \ + test_source.res \ + test_spell.res \ + test_startup.res \ + test_stat.res \ + test_substitute.res \ + test_swap.res \ + test_syntax.res \ + test_system.res \ + test_tab.res \ + test_tcl.res \ + test_termencoding.res \ + test_terminal.res \ + test_terminal_fail.res \ + test_textformat.res \ + test_textobjects.res \ + test_textprop.res \ + test_undo.res \ + test_user_func.res \ + test_usercommands.res \ + test_vartabs.res \ + test_viminfo.res \ + test_vimscript.res \ + test_visual.res \ + test_winbar.res \ + test_winbuf_close.res \ + test_window_id.res \ + test_windows_home.res \ + test_wordcount.res \ + test_writefile.res \ + test_xxd.res \ + test_alot_latin.res \ + test_alot_utf8.res \ + test_alot.res diff --git a/src/testdir/Make_amiga.mak b/src/testdir/Make_amiga.mak new file mode 100644 index 0000000..b71b220 --- /dev/null +++ b/src/testdir/Make_amiga.mak @@ -0,0 +1,45 @@ +# +# Makefile to run all tests for Vim, on Amiga +# +# Requires "rm", "csh" and "diff"! + +VIMPROG = /vim + +default: nongui + +include Make_all.mak + +# These tests don't work (yet): +# test2 "\\tmp" doesn't work +# test10 'errorformat' is different +# test11 "cat" doesn't work properly +# test52 only for Win32 +# test86, 87 no Python interface + +SCRIPTS = $(SCRIPTS_ALL) $(SCRIPTS_MORE4) + +# Must run test1 first to create small.vim. +$(SCRIPTS) $(SCRIPTS_GUI) $(NEW_TESTS_RES): $(SCRIPTS_FIRST) + +.SUFFIXES: .in .out + +nongui: /tmp $(SCRIPTS_FIRST) $(SCRIPTS) + csh -c echo ALL DONE + +clean: + csh -c \rm -rf *.out /tmp/* Xdotest small.vim tiny.vim mbyte.vim test.ok viminfo + +.in.out: + copy $*.ok test.ok + $(VIMPROG) -u amiga.vim -U NONE --noplugin --not-a-term -s dotest.in $*.in + diff test.out $*.ok + rename test.out $*.out + -delete X#? ALL QUIET + -delete test.ok + +# Create a directory for temp files +/tmp: + makedir /tmp + +# Manx requires all dependencies, but we stopped updating them. +# Delete the .out file(s) to run test(s). diff --git a/src/testdir/Make_dos.mak b/src/testdir/Make_dos.mak new file mode 100644 index 0000000..5776a79 --- /dev/null +++ b/src/testdir/Make_dos.mak @@ -0,0 +1,138 @@ +# +# Makefile to run all tests for Vim, on Dos-like machines. +# +# Requires a set of Unix tools: echo, diff, etc. + +VIMPROG = ..\\vim + +default: nongui + +!include Make_all.mak + +# Omitted: +# test2 "\\tmp" doesn't work. +# test10 'errorformat' is different +# test49 fails in various ways +# test97 \{ and \$ are not escaped characters. + +SCRIPTS = $(SCRIPTS_ALL) $(SCRIPTS_MORE1) $(SCRIPTS_MORE4) + +TEST_OUTFILES = $(SCRIPTS_FIRST) $(SCRIPTS) $(SCRIPTS_WIN32) $(SCRIPTS_GUI) +DOSTMP = dostmp +DOSTMP_OUTFILES = $(TEST_OUTFILES:test=dostmp\test) +DOSTMP_INFILES = $(DOSTMP_OUTFILES:.out=.in) + +.SUFFIXES: .in .out .res .vim + +nongui: nolog $(SCRIPTS_FIRST) $(SCRIPTS) newtests report + +small: nolog report + +gui: nolog $(SCRIPTS_FIRST) $(SCRIPTS) $(SCRIPTS_GUI) newtests report + +win32: nolog $(SCRIPTS_FIRST) $(SCRIPTS) $(SCRIPTS_WIN32) newtests report + +# Copy the input files to dostmp, changing the fileformat to dos. +$(DOSTMP_INFILES): $(*B).in + if not exist $(DOSTMP)\NUL md $(DOSTMP) + if exist $@ del $@ + $(VIMPROG) -u dos.vim $(NO_INITS) "+set ff=dos|f $@|wq" $(*B).in + +# For each input file dostmp/test99.in run the tests. +# This moves test99.in to test99.in.bak temporarily. +$(TEST_OUTFILES): $(DOSTMP)\$(*B).in + -@if exist test.out DEL test.out + -@if exist $(DOSTMP)\$(*B).out DEL $(DOSTMP)\$(*B).out + move $(*B).in $(*B).in.bak > nul + copy $(DOSTMP)\$(*B).in $(*B).in > nul + copy $(*B).ok test.ok > nul + $(VIMPROG) -u dos.vim $(NO_INITS) -s dotest.in $(*B).in + -@if exist test.out MOVE /y test.out $(DOSTMP)\$(*B).out > nul + -@if exist $(*B).in.bak move /y $(*B).in.bak $(*B).in > nul + -@if exist test.ok del test.ok + -@if exist Xdir1 rd /s /q Xdir1 + -@if exist Xfind rd /s /q Xfind + -@if exist XfakeHOME rd /s /q XfakeHOME + -@del X* + -@if exist viminfo del viminfo + $(VIMPROG) -u dos.vim $(NO_INITS) "+set ff=unix|f test.out|wq" \ + $(DOSTMP)\$(*B).out + @diff test.out $*.ok & if errorlevel 1 \ + ( move /y test.out $*.failed > nul \ + & del $(DOSTMP)\$(*B).out \ + & echo $* FAILED >> test.log ) \ + else ( move /y test.out $*.out > nul ) + +# Must run test1 first to create small.vim. +# This rule must come after the one that copies the input files to dostmp to +# allow for running an individual test. +$(SCRIPTS) $(SCRIPTS_GUI) $(SCRIPTS_WIN32) $(NEW_TESTS_RES): $(SCRIPTS_FIRST) + +report: + @echo "" + @echo Test results: + @if exist test.log ( type test.log & echo TEST FAILURE & exit /b 1 ) \ + else ( echo ALL DONE ) + +clean: + -del *.out + -del *.failed + -del *.res + -if exist $(DOSTMP) rd /s /q $(DOSTMP) + -if exist test.in del test.in + -if exist test.ok del test.ok + -if exist small.vim del small.vim + -if exist tiny.vim del tiny.vim + -if exist mbyte.vim del mbyte.vim + -if exist mzscheme.vim del mzscheme.vim + -if exist Xdir1 rd /s /q Xdir1 + -if exist Xfind rd /s /q Xfind + -if exist XfakeHOME rd /s /q XfakeHOME + -del X* + -for /d %i in (X*) do @rmdir /s/q %i + -if exist viminfo del viminfo + -if exist test.log del test.log + -if exist messages del messages + -if exist benchmark.out del benchmark.out + -if exist opt_test.vim del opt_test.vim + +nolog: + -if exist test.log del test.log + -if exist messages del messages + +benchmark: + bench_re_freeze.out + +bench_re_freeze.out: bench_re_freeze.vim + -if exist benchmark.out del benchmark.out + $(VIMPROG) -u dos.vim $(NO_INITS) $*.in + @IF EXIST benchmark.out ( type benchmark.out ) + +# New style of tests uses Vim script with assert calls. These are easier +# to write and a lot easier to read and debug. +# Limitation: Only works with the +eval feature. + +newtests: newtestssilent + @if exist messages (findstr "SKIPPED FAILED" messages > nul) && type messages + +newtestssilent: $(NEW_TESTS_RES) + +.vim.res: + @echo $(VIMPROG) > vimcmd + $(VIMPROG) -u NONE $(NO_INITS) -S runtest.vim $*.vim + @del vimcmd + +test_gui.res: test_gui.vim + @echo $(VIMPROG) > vimcmd + $(VIMPROG) -u NONE $(NO_INITS) -S runtest.vim $*.vim + @del vimcmd + +test_gui_init.res: test_gui_init.vim + @echo $(VIMPROG) > vimcmd + $(VIMPROG) -u gui_preinit.vim -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $*.vim + @del vimcmd + +test_options.res test_alot.res: opt_test.vim + +opt_test.vim: ../option.c gen_opt_test.vim + $(VIMPROG) -u NONE -S gen_opt_test.vim --noplugin --not-a-term ../option.c diff --git a/src/testdir/Make_ming.mak b/src/testdir/Make_ming.mak new file mode 100644 index 0000000..2ad34b9 --- /dev/null +++ b/src/testdir/Make_ming.mak @@ -0,0 +1,142 @@ +# +# Makefile to run all tests for Vim, on Dos-like machines +# with sh.exe or zsh.exe in the path or not. +# +# Author: Bill McCarthy +# +# Requires a set of Unix tools: echo, diff, etc. + +ifneq (sh.exe, $(SHELL)) +DEL = rm -f +DELDIR = rm -rf +MV = mv +CP = cp +CAT = cat +DIRSLASH = / +else +DEL = del +DELDIR = rd /s /q +MV = rename +CP = copy +CAT = type +DIRSLASH = \\ +endif + +VIMPROG = ..$(DIRSLASH)vim + +default: vimall + +include Make_all.mak + +# Omitted: +# test2 "\\tmp" doesn't work. +# test10 'errorformat' is different +# test97 \{ and \$ are not escaped characters + +SCRIPTS = $(SCRIPTS_ALL) $(SCRIPTS_MORE1) $(SCRIPTS_MORE4) $(SCRIPTS_WIN32) + +SCRIPTS_BENCH = bench_re_freeze.out + +# Must run test1 first to create small.vim. +$(SCRIPTS) $(SCRIPTS_GUI) $(SCRIPTS_WIN32) $(NEW_TESTS_RES): $(SCRIPTS_FIRST) + +.SUFFIXES: .in .out .res .vim + +vimall: fixff $(SCRIPTS_FIRST) $(SCRIPTS) $(SCRIPTS_GUI) $(SCRIPTS_WIN32) newtests + @echo ALL DONE + +nongui: fixff nolog $(SCRIPTS_FIRST) $(SCRIPTS) newtests + @echo ALL DONE + +benchmark: $(SCRIPTS_BENCH) + +small: nolog + @echo ALL DONE + +gui: fixff nolog $(SCRIPTS_FIRST) $(SCRIPTS) $(SCRIPTS_GUI) newtests + @echo ALL DONE + +win32: fixff nolog $(SCRIPTS_FIRST) $(SCRIPTS) $(SCRIPTS_WIN32) newtests + @echo ALL DONE + +# TODO: find a way to avoid changing the distributed files. +fixff: + -$(VIMPROG) -u dos.vim $(NO_INITS) "+argdo set ff=dos|upd" +q *.in *.ok + -$(VIMPROG) -u dos.vim $(NO_INITS) "+argdo set ff=unix|upd" +q \ + dotest.in + +clean: + -@if exist *.out $(DEL) *.out + -@if exist *.failed $(DEL) *.failed + -@if exist *.res $(DEL) *.res + -@if exist test.in $(DEL) test.in + -@if exist test.ok $(DEL) test.ok + -@if exist small.vim $(DEL) small.vim + -@if exist tiny.vim $(DEL) tiny.vim + -@if exist mbyte.vim $(DEL) mbyte.vim + -@if exist mzscheme.vim $(DEL) mzscheme.vim + -@if exist Xdir1 $(DELDIR) Xdir1 + -@if exist Xfind $(DELDIR) Xfind + -@if exist XfakeHOME $(DELDIR) XfakeHOME + -@if exist X* $(DEL) X* + -@if exist viminfo $(DEL) viminfo + -@if exist test.log $(DEL) test.log + -@if exist messages $(DEL) messages + -@if exist opt_test.vim $(DEL) opt_test.vim + +test1.out: test1.in + -@if exist wrongtermsize $(DEL) wrongtermsize + $(VIMPROG) -u dos.vim $(NO_INITS) -s dotest.in test1.in + -@if exist wrongtermsize ( \ + echo Vim window too small- must be 80x25 or larger && exit 1 \ + ) + -@if exist test.out $(DEL) test.out + -@if exist viminfo $(DEL) viminfo + +.in.out: + -@if exist $*.ok $(CP) $*.ok test.ok + $(VIMPROG) -u dos.vim $(NO_INITS) -s dotest.in $*.in + @diff test.out $*.ok + -@if exist $*.out $(DEL) $*.out + @$(MV) test.out $*.out + -@if exist Xdir1 $(DELDIR) Xdir1 + -@if exist Xfind $(DELDIR) Xfind + -@if exist XfakeHOME $(DELDIR) XfakeHOME + -@if exist X* $(DEL) X* + -@if exist test.ok $(DEL) test.ok + -@if exist viminfo $(DEL) viminfo + +nolog: + -@if exist test.log $(DEL) test.log + -@if exist messages $(DEL) messages + +bench_re_freeze.out: bench_re_freeze.vim + -$(DEL) benchmark.out + $(VIMPROG) -u dos.vim $(NO_INITS) $*.in + $(CAT) benchmark.out + +# New style of tests uses Vim script with assert calls. These are easier +# to write and a lot easier to read and debug. +# Limitation: Only works with the +eval feature. + +newtests: $(NEW_TESTS_RES) + +.vim.res: + @echo $(VIMPROG) > vimcmd + $(VIMPROG) -u NONE $(NO_INITS) -S runtest.vim $*.vim + @$(DEL) vimcmd + +test_gui.res: test_gui.vim + @echo $(VIMPROG) > vimcmd + $(VIMPROG) -u NONE $(NO_INITS) -S runtest.vim $< + @$(DEL) vimcmd + +test_gui_init.res: test_gui_init.vim + @echo $(VIMPROG) > vimcmd + $(VIMPROG) -u gui_preinit.vim -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $< + @$(DEL) vimcmd + +test_options.res test_alot.res: opt_test.vim + +opt_test.vim: ../option.c gen_opt_test.vim + $(VIMPROG) -u NONE -S gen_opt_test.vim --noplugin --not-a-term ../option.c diff --git a/src/testdir/Make_vms.mms b/src/testdir/Make_vms.mms new file mode 100644 index 0000000..f14f6bc --- /dev/null +++ b/src/testdir/Make_vms.mms @@ -0,0 +1,212 @@ +# +# Makefile to run all tests for Vim on VMS +# +# Authors: Zoltan Arpadffy, <arpadffy@polarhome.com> +# Sandor Kopanyi, <sandor.kopanyi@mailbox.hu> +# +# Last change: 2016 Nov 04 +# +# This has been tested on VMS 6.2 to 8.3 on DEC Alpha, VAX and IA64. +# Edit the lines in the Configuration section below to select. +# +# Execute with: +# mms/descrip=Make_vms.mms +# Cleanup with: +# mms/descrip=Make_vms.mms clean +# +# Make files are MMK compatible. +# +# NOTE: You can run this script just in X/Window environment. It will +# create a new terminals, therefore you have to set up your DISPLAY +# logical. More info in VMS documentation or with: help set disp. +# +####################################################################### +# Configuration section. +####################################################################### + +# Uncomment if you want tests in GUI mode. Terminal mode is default. +# WANT_GUI = YES + +# Comment out if you want to run Unix specific tests as well, but please +# be aware, that on OpenVMS will fail, because of cat, rm, etc commands +# and directory handling. +# WANT_UNIX = YES + +# Comment out if you want to run Win32 specific tests as well, but please +# be aware, that on OpenVMS will fail, because of cat, rm, etc commands +# and directory handling. +# WANT_WIN = YES + +# Comment out if you want to run spell checker tests. +# They fail because VMS does not support file names. +# WANT_SPELL = YES + +# Comment out if you want to run mzschema tests. +# It fails because VMS does not support this feature yet. +# WANT_MZSCH = YES + +# Comment out if you have ODS-5 file system +# HAVE_ODS5 = YES + +# Comment out if you have gzip on your system +# HAVE_GZIP = YES + +# Comment out if you have GNU compatible diff on your system +# HAVE_GDIFF = YES + +# Comment out if you have ICONV support +# HAVE_ICONV = YES + +# Comment out if you have LUA support +# HAVE_LUA = YES + +# Comment out if you have PYTHON support +# HAVE_PYTHON = YES + +####################################################################### +# End of configuration section. +# +# Please, do not change anything below without programming experience. +####################################################################### + +VIMPROG = <->vim.exe + +.SUFFIXES : .out .in + +SCRIPT = test1.out test3.out \ + test14.out \ + test29.out \ + test30.out test37.out test39.out \ + test42.out test44.out test48.out test49.out \ + test64.out test69.out \ + test72.out test77a.out test88.out \ + test94.out test95.out test99.out test108.out \ + test_eval.out + +# Known problems: +# test17: ? +# +# test30: bug, most probably - a problem around mac format +# +# test59: Failed/Hangs - VMS does not support spell files (file names +# with too many dots). +# +# test72: bug - Vim hangs at :rename (while rename works well otherwise) +# test78: bug - Vim dies at :recover Xtest +# test89: bug - findfile() does not work on VMS (just in the current directory) +# test102: Just ODS-5 supports space and special chars in the filename. +# On ODS-2 tests fail. + +.IFDEF WANT_GUI +SCRIPT_GUI = test16.out +GUI_OPTION = -g +.ENDIF + +.IFDEF WANT_UNIX +SCRIPT_UNIX = test10.out test17.out test27.out test49.out +.ENDIF + +.IFDEF WANT_WIN +SCRIPT_WIN = test52.out +.ENDIF + +.IFDEF WANT_SPELL +SCRIPT_SPELL = test59.out +.ENDIF + +.IFDEF WANT_MZSCH +SCRIPT_MZSCH = test70.out +.ENDIF + +.IFDEF HAVE_ODS5 +SCRIPT_ODS5 = test102.out +.ENDIF + +.IFDEF HAVE_GZIP +SCRIPT_GZIP = test11.out +.ENDIF + +.IFDEF HAVE_GDIFF +SCRIPT_GDIFF = test47.out +.ENDIF + +.IFDEF HAVE_PYTHON +SCRIPT_PYTHON = test86.out test87.out +.ENDIF + +.in.out : + -@ !clean up before doing the test + -@ if "''F$SEARCH("test.out.*")'" .NES. "" then delete/noconfirm/nolog test.out.* + -@ if "''F$SEARCH("$*.out.*")'" .NES. "" then delete/noconfirm/nolog $*.out.* + -@ ! define TMP if not set - some tests use it + -@ if "''F$TRNLNM("TMP")'" .EQS. "" then define/nolog TMP [] + -@ write sys$output " " + -@ write sys$output "-----------------------------------------------" + -@ write sys$output " "$*" " + -@ write sys$output "-----------------------------------------------" + -@ !run the test + -@ create/term/wait/nodetach mcr $(VIMPROG) $(GUI_OPTION) -u vms.vim --noplugin -s dotest.in $*.in + -@ !analyse the result + -@ directory /size/date test.out + -@ if "''F$SEARCH("test.out.*")'" .NES. "" then rename/nolog test.out $*.out + -@ if "''F$SEARCH("$*.out.*")'" .NES. "" then differences /par $*.out $*.ok; + -@ !clean up after the test + -@ if "''F$SEARCH("Xdotest.*")'" .NES. "" then delete/noconfirm/nolog Xdotest.*.* + -@ if "''F$SEARCH("Xtest.*")'" .NES. "" then delete/noconfirm/nolog Xtest.*.* + +all : clean nolog $(START_WITH) $(SCRIPT) $(SCRIPT_GUI) $(SCRIPT_UNIX) $(SCRIPT_WIN) $(SCRIPT_SPELL) $(SCRIPT_ODS5) $(SCRIPT_GZIP) \ + $(SCRIPT_GDIFF) $(SCRIPT_MZSCH) $(SCRIPT_LUA) $(SCRIPT_PYTHON) nolog + -@ write sys$output " " + -@ write sys$output "-----------------------------------------------" + -@ write sys$output " All done" + -@ write sys$output "-----------------------------------------------" + -@ deassign sys$output + -@ delete/noconfirm/nolog x*.*.* + -@ type test.log + +nolog : + -@ define sys$output test.log + -@ write sys$output "-----------------------------------------------" + -@ write sys$output " Standard VIM test cases" + -@ write sys$output "-----------------------------------------------" + -@ write sys$output " OpenVMS version: ''F$GETSYI("VERSION")'" + -@ write sys$output " Vim version:" + -@ mcr $(VIMPROG) --version + -@ write sys$output " Test date:" + -@ show time + -@ write sys$output "-----------------------------------------------" + -@ write sys$output " Test results:" + -@ write sys$output "-----------------------------------------------" + -@ write sys$output "MAKE_VMS.MMS options:" + -@ write sys$output " WANT_GUI = ""$(WANT_GUI)"" " + -@ write sys$output " WANT_UNIX = ""$(WANT_UNIX)"" " + -@ write sys$output " WANT_WIN = ""$(WANT_WIN)"" " + -@ write sys$output " WANT_SPELL = ""$(WANT_SPELL)"" " + -@ write sys$output " WANT_MZSCH = ""$(WANT_MZSCH)"" " + -@ write sys$output " HAVE_ODS5 = ""$(HAVE_ODS5)"" " + -@ write sys$output " HAVE_GZIP = ""$(HAVE_GZIP)"" " + -@ write sys$output " HAVE_GDIFF = ""$(HAVE_GDIFF)"" " + -@ write sys$output " HAVE_ICONV = ""$(HAVE_ICONV)"" " + -@ write sys$output " HAVE_LUA = ""$(HAVE_LUA)"" " + -@ write sys$output " HAVE_PYTHON= ""$(HAVE_PYTHON)"" " + -@ write sys$output "Default vimrc file is VMS.VIM:" + -@ write sys$output "-----------------------------------------------" + -@ type VMS.VIM + +clean : + -@ if "''F$SEARCH("*.out")'" .NES. "" then delete/noconfirm/nolog *.out.* + -@ if "''F$SEARCH("test.log")'" .NES. "" then delete/noconfirm/nolog test.log.* + -@ if "''F$SEARCH("test.ok")'" .NES. "" then delete/noconfirm/nolog test.ok.* + -@ if "''F$SEARCH("Xdotest.*")'" .NES. "" then delete/noconfirm/nolog Xdotest.*.* + -@ if "''F$SEARCH("Xtest*.*")'" .NES. "" then delete/noconfirm/nolog Xtest*.*.* + -@ if "''F$SEARCH("XX*.*")'" .NES. "" then delete/noconfirm/nolog XX*.*.* + -@ if "''F$SEARCH("_un_*.*")'" .NES. "" then delete/noconfirm/nolog _un_*.*.* + -@ if "''F$SEARCH("*.*_sw*")'" .NES. "" then delete/noconfirm/nolog *.*_sw*.* + -@ if "''F$SEARCH("*.failed")'" .NES. "" then delete/noconfirm/nolog *.failed.* + -@ if "''F$SEARCH("*.rej")'" .NES. "" then delete/noconfirm/nolog *.rej.* + -@ if "''F$SEARCH("tiny.vim")'" .NES. "" then delete/noconfirm/nolog tiny.vim.* + -@ if "''F$SEARCH("small.vim")'" .NES. "" then delete/noconfirm/nolog small.vim.* + -@ if "''F$SEARCH("mbyte.vim")'" .NES. "" then delete/noconfirm/nolog mbyte.vim.* + -@ if "''F$SEARCH("mzscheme.vim")'" .NES. "" then delete/noconfirm/nolog mzscheme.vim.* + -@ if "''F$SEARCH("viminfo.*")'" .NES. "" then delete/noconfirm/nolog viminfo.*.* + diff --git a/src/testdir/Makefile b/src/testdir/Makefile new file mode 100644 index 0000000..c3ba8ab --- /dev/null +++ b/src/testdir/Makefile @@ -0,0 +1,173 @@ +# +# Makefile to run all tests for Vim +# + +# Use console or GUI. +VIMPROG = ../vim +XXDPROG = ../xxd/xxd +# VIMPROG = ../gvim + +SCRIPTSOURCE = ../../runtime + +# Comment out this line to see the verbose output of tests. +# +# Catches SwapExists to avoid hanging at the ATTENTION prompt. +REDIR_TEST_TO_NULL = --cmd 'au SwapExists * let v:swapchoice = "e"' > /dev/null + +# Uncomment this line to use valgrind for memory leaks and extra warnings. +# The output goes into a file "valgrind.testN" +# Vim should be compiled with EXITFREE to avoid false warnings. +# This will make testing about 10 times as slow. +# VALGRIND = valgrind --tool=memcheck --leak-check=yes --num-callers=25 --log-file=valgrind.$* + +default: nongui + +# The list of tests is common to all systems. +# This defines NEW_TESTS, NEW_TESTS_RES, SCRIPTS_ALL, SCRIPTS_MORE* and +# SCRIPTS_GUI. +include Make_all.mak + + +SCRIPTS = $(SCRIPTS_ALL) \ + $(SCRIPTS_MORE1) \ + $(SCRIPTS_MORE2) \ + $(SCRIPTS_MORE4) + +# Explicit dependencies. +test49.out: test49.vim + +test_options.res test_alot.res: opt_test.vim + +SCRIPTS_BENCH = bench_re_freeze.out + +.SUFFIXES: .in .out .res .vim + +nongui: nolog $(SCRIPTS_FIRST) $(SCRIPTS) newtests report + +gui: nolog $(SCRIPTS_FIRST) $(SCRIPTS) $(SCRIPTS_GUI) newtests report + +benchmark: $(SCRIPTS_BENCH) + +report: + @echo + @echo 'Test results:' + @/bin/sh -c "if test -f test.log; \ + then cat test.log; echo TEST FAILURE; exit 1; \ + else echo ALL DONE; \ + fi" + +$(SCRIPTS_FIRST) $(SCRIPTS) $(SCRIPTS_GUI) $(NEW_TESTS_RES): $(VIMPROG) + +# Must run test1 first to create small.vim. +$(SCRIPTS) $(SCRIPTS_GUI) $(NEW_TESTS_RES): $(SCRIPTS_FIRST) + + +# Execute an individual new style test, e.g.: +# make test_largefile +$(NEW_TESTS): + rm -f $@.res test.log messages + $(MAKE) -f Makefile $@.res + @if test -f test.log; then \ + cat test.log; \ + fi + cat messages + +RM_ON_RUN = test.out X* viminfo +RM_ON_START = tiny.vim small.vim mbyte.vim mzscheme.vim test.ok benchmark.out +RUN_VIM = VIMRUNTIME=$(SCRIPTSOURCE); export VIMRUNTIME; $(VALGRIND) $(VIMPROG) -f $(GUI_FLAG) -u unix.vim $(NO_INITS) -s dotest.in + +clean: + -rm -rf *.out *.failed *.res *.rej *.orig opt_test.vim test.log messages $(RM_ON_RUN) $(RM_ON_START) valgrind.* + +test1.out: test1.in + -rm -rf $*.failed $(RM_ON_RUN) $(RM_ON_START) wrongtermsize + $(RUN_VIM) $*.in $(REDIR_TEST_TO_NULL) + @/bin/sh -c "if test -f wrongtermsize; \ + then echo; \ + echo test1 FAILED - terminal size must be 80x24 or larger; \ + echo; exit 1; \ + elif diff test.out $*.ok; \ + then mv -f test.out $*.out; \ + else echo; \ + echo test1 FAILED - Something basic is wrong; \ + echo; exit 1; fi" + -rm -rf X* viminfo + +.in.out: + -rm -rf $*.failed test.ok $(RM_ON_RUN) + cp $*.ok test.ok + # Sleep a moment to avoid that the xterm title is messed up. + # 200 msec is sufficient, but only modern sleep supports a fraction of + # a second, fall back to a second if it fails. + @-/bin/sh -c "sleep .2 > /dev/null 2>&1 || sleep 1" + $(RUN_VIM) $*.in $(REDIR_TEST_TO_NULL) + + # For flaky tests retry one time. No tests at the moment. + #@/bin/sh -c "if test -f test.out -a $* = test61; then \ + # if diff test.out $*.ok; \ + # then echo flaky test ok first time; \ + # else rm -rf $*.failed $(RM_ON_RUN); \ + # $(RUN_VIM) $*.in; \ + # fi \ + # fi" + + # Check if the test.out file matches test.ok. + @/bin/sh -c "if test -f test.out; then \ + if diff test.out $*.ok; \ + then mv -f test.out $*.out; \ + else echo $* FAILED >>test.log; mv -f test.out $*.failed; \ + fi \ + else echo $* NO OUTPUT >>test.log; \ + fi" + @/bin/sh -c "if test -f valgrind; then\ + mv -f valgrind valgrind.$*; \ + fi" + -rm -rf X* test.ok viminfo + +bench_re_freeze.out: bench_re_freeze.vim + -rm -rf benchmark.out $(RM_ON_RUN) + # Sleep a moment to avoid that the xterm title is messed up. + # 200 msec is sufficient, but only modern sleep supports a fraction of + # a second, fall back to a second if it fails. + @-/bin/sh -c "sleep .2 > /dev/null 2>&1 || sleep 1" + $(RUN_VIM) $*.in $(REDIR_TEST_TO_NULL) + @/bin/sh -c "if test -f benchmark.out; then cat benchmark.out; fi" + +nolog: + -rm -f test.log messages + + +# New style of tests uses Vim script with assert calls. These are easier +# to write and a lot easier to read and debug. +# Limitation: Only works with the +eval feature. +RUN_VIMTEST = VIMRUNTIME=$(SCRIPTSOURCE); export VIMRUNTIME; $(VALGRIND) $(VIMPROG) -f $(GUI_FLAG) -u unix.vim + +newtests: newtestssilent + @/bin/sh -c "if test -f messages && grep -q 'SKIPPED\|FAILED' messages; then cat messages; fi" + +newtestssilent: $(NEW_TESTS_RES) + + +.vim.res: writevimcmd + @echo "$(VIMPROG)" > vimcmd + @echo "$(RUN_VIMTEST)" >> vimcmd + $(RUN_VIMTEST) $(NO_INITS) -S runtest.vim $*.vim $(REDIR_TEST_TO_NULL) + @rm vimcmd + +test_gui.res: test_gui.vim + @echo "$(VIMPROG)" > vimcmd + @echo "$(RUN_GVIMTEST)" >> vimcmd + $(RUN_VIMTEST) -u NONE $(NO_INITS) -S runtest.vim $< + @rm vimcmd + +test_gui_init.res: test_gui_init.vim + @echo "$(VIMPROG)" > vimcmd + @echo "$(RUN_GVIMTEST_WITH_GVIMRC)" >> vimcmd + $(RUN_VIMTEST) -u gui_preinit.vim -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $< + @rm vimcmd + +opt_test.vim: ../option.c gen_opt_test.vim + $(VIMPROG) -u NONE -S gen_opt_test.vim --noplugin --not-a-term ../option.c + +test_xxd.res: + XXD=$(XXDPROG); export XXD; $(RUN_VIMTEST) $(NO_INITS) -S runtest.vim test_xxd.vim diff --git a/src/testdir/README.txt b/src/testdir/README.txt new file mode 100644 index 0000000..f4486e3 --- /dev/null +++ b/src/testdir/README.txt @@ -0,0 +1,73 @@ +This directory contains tests for various Vim features. +For testing an indent script see runtime/indent/testdir/README.txt. + +If it makes sense, add a new test method to an already existing file. You may +want to separate it from other tests with comment lines. + +The numbered tests are older, we have switched to named tests. Don't add any +more numbered tests. + +And then you can choose between a new style test, which is a Vim script, or an +old style test, which uses Normal mode commands. Use a new style test if you +can. Use an old style test when it needs to run without the +eval feature. + + +TO ADD A NEW STYLE TEST: + +1) Create a test_<subject>.vim file. +2) Add test_<subject>.res to NEW_TESTS_RES in Make_all.mak in alphabetical + order. +3) Also add an entry "test_<subject>" to NEW_TESTS in Make_all.mak. +4) Use make test_<subject> to run a single test. + +At 2), instead of running the test separately, it can be included in +"test_alot". Do this for quick tests without side effects. The test runs a +bit faster, because Vim doesn't have to be started, one Vim instance runs many +tests. + + +What you can use (see test_assert.vim for an example): + +- Call assert_equal(), assert_true(), assert_false(), etc. + +- Use assert_fails() to check for expected errors. + +- Use try/catch to avoid an exception aborts the test. + +- Use alloc_fail() to have memory allocation fail. This makes it possible to + check memory allocation failures are handled gracefully. You need to change + +- the source code to add an ID to the allocation. Update LAST_ID_USED above + alloc_id() to the highest ID used. + +- Use test_override() to make Vim behave differently, e.g. if char_avail() + must return FALSE for a while. E.g. to trigger the CursorMovedI autocommand + event. + +- See test_cursor_func.vim for an example. + +- If the bug that is being tested isn't fixed yet, you can throw an exception + with "Skipped" so that it's clear this still needs work. E.g.: throw + "Skipped: Bug with <c-e> and popupmenu not fixed yet" + +- See the start of runtest.vim for more help. + + +TO ADD A SCREEN DUMP TEST: + +Mostly the same as writing a new style test. Additionally, see help on +"terminal-dumptest". Put the reference dump in "dumps/Test_func_name.dump". + + +TO ADD AN OLD STYLE TEST: + +1) Create test_<subject>.in and test_<subject>.ok files. +2) Add test_<subject>.out to SCRIPTS_ALL in Make_all.mak in alphabetical order. +3) Use make test_<subject>.out to run a single test in src/testdir/. + Use make test_<subject> to run a single test in src/. +4) Also add an entry in src/Makefile. + +Keep in mind that the files are used as if everything was typed: +- To add comments use: :" (that's an Ex command comment) +- A line break is like pressing Enter. If that happens on the last line + you'll hear a beep! diff --git a/src/testdir/amiga.vim b/src/testdir/amiga.vim new file mode 100644 index 0000000..79956d7 --- /dev/null +++ b/src/testdir/amiga.vim @@ -0,0 +1,6 @@ +" Settings for test script execution +set shell=csh +map! /tmp t: +cmap !rm !Delete all + +source setup.vim diff --git a/src/testdir/bench_re_freeze.in b/src/testdir/bench_re_freeze.in new file mode 100644 index 0000000..7b1bfa3 --- /dev/null +++ b/src/testdir/bench_re_freeze.in @@ -0,0 +1,13 @@ +Test for Benchmarking RE engine + +STARTTEST +:so small.vim +:if !has("reltime") | qa! | endif +:set nocp cpo&vim +:so bench_re_freeze.vim +:call Measure('samples/re.freeze.txt', '\s\+\%#\@<!$', '+5') +:/^" Benchmark/,$w! benchmark.out +:qa! +ENDTEST + +" Benchmark_results: diff --git a/src/testdir/bench_re_freeze.vim b/src/testdir/bench_re_freeze.vim new file mode 100644 index 0000000..ee84438 --- /dev/null +++ b/src/testdir/bench_re_freeze.vim @@ -0,0 +1,13 @@ +"Test for benchmarking the RE engine + +so small.vim +if !has("reltime") | finish | endif +func! Measure(file, pattern, arg) + for re in range(3) + let sstart=reltime() + let cmd=printf("../vim -u NONE -N --cmd ':set re=%d'". + \ " -c 'call search(\"%s\", \"\", \"\", 10000)' -c ':q!' %s", re, escape(a:pattern, '\\'), empty(a:arg) ? '' : a:arg) + call system(cmd. ' '. a:file) + $put =printf('file: %s, re: %d, time: %s', a:file, re, reltimestr(reltime(sstart))) + endfor +endfunc diff --git a/src/testdir/color_ramp.vim b/src/testdir/color_ramp.vim new file mode 100644 index 0000000..0219f3f --- /dev/null +++ b/src/testdir/color_ramp.vim @@ -0,0 +1,41 @@ +" Script to generate a file that shows al 256 xterm colors + +new +call setline(1, 'ANSI') + +" ANSI colors +let s = '' +for nr in range(0, 7) + let s .= "\033[4" . nr . "m " +endfor +for nr in range(8, 15) + let s .= "\033[10" . (nr - 8) . "m " +endfor +" Add | in original color pair to see white background. +let s .= "\033[m|" +call setline(2, s) + +" 6 x 6 x 6 color cube +call setline(3, 'color cube') +for high in range(0, 5) + let s = '' + for low in range(0, 35) + let nr = low + high * 36 + let s .= "\033[48;5;" . (nr + 16) . "m " + endfor + let s .= "\033[m|" + call setline(high + 4, s) +endfor + +" 24 shades of grey +call setline(10, 'grey ramp') +let s = '' +for nr in range(0, 23) + let s .= "\033[48;5;" . (nr + 232) . "m " +endfor +let s .= "\033[m|" +call setline(11, s) + +set binary +write! <sfile>:h/color_ramp.txt +quit diff --git a/src/testdir/dos.vim b/src/testdir/dos.vim new file mode 100644 index 0000000..3ea6ab2 --- /dev/null +++ b/src/testdir/dos.vim @@ -0,0 +1,9 @@ +" Settings for test script execution +" Always use "COMMAND.COM", don't use the value of "$SHELL". +set shell=c:\COMMAND.COM shellquote= shellxquote= shellcmdflag=/c shellredir=> +" This is used only when the +eval feature is available. +if executable("cmd.exe") + set shell=cmd.exe +endif + +source setup.vim diff --git a/src/testdir/dotest.in b/src/testdir/dotest.in new file mode 100644 index 0000000..b2a0e1a --- /dev/null +++ b/src/testdir/dotest.in @@ -0,0 +1,3 @@ +:set cp +:map dotest /^STARTTEST
j:set ff=unix cpo-=A
:.,/ENDTEST/-1w! Xdotest
:set ff& cpo+=A
nj0:so! Xdotest
dotest +dotest diff --git a/src/testdir/dumps/Test_conceal_cul_01.dump b/src/testdir/dumps/Test_conceal_cul_01.dump new file mode 100644 index 0000000..6d698d1 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_cul_01.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| @71 +|t|w|o| @71 +>t+8&&|h|r|e@1| @69 +|f+0&&|o|u|r| @70 +|f|i|v|e| @70 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1| @11|A|l@1 +| +0&&@74 +|t+8&&|h|i|s| |i|s| |a| |t|e|s|t| @60 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|4| @10|A|l@1 +| +0&&@74 diff --git a/src/testdir/dumps/Test_conceal_cul_02.dump b/src/testdir/dumps/Test_conceal_cul_02.dump new file mode 100644 index 0000000..46b296c --- /dev/null +++ b/src/testdir/dumps/Test_conceal_cul_02.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| @71 +|t|w|o| @71 +|t+8&&|h|r|e@1| @69 +|f+0&&|o|u|r| @70 +|f|i|v|e| @70 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1| @11|A|l@1 +| +0&&@74 +|t+8&&|h|i|s| |i|s| |a| |t|e|s>t| @60 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|4| @10|A|l@1 +|:+0&&|w|i|n|c|m|d| |w| @65 diff --git a/src/testdir/dumps/Test_conceal_cul_03.dump b/src/testdir/dumps/Test_conceal_cul_03.dump new file mode 100644 index 0000000..275f35c --- /dev/null +++ b/src/testdir/dumps/Test_conceal_cul_03.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| @71 +|t|w|o| @71 +|t+8&&|h|r|e@1| @69 +|f+0&&|o|u|r| @70 +|f|i|v|e| @70 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1| @11|A|l@1 +> +8&&@74 +|t+0&&|h|i|s| |i|s| |a| |t|e|s|t| @60 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|1|,|0|-|1| @9|A|l@1 +|:+0&&|w|i|n|c|m|d| |w| @65 diff --git a/src/testdir/dumps/Test_conceal_two_windows_01.dump b/src/testdir/dumps/Test_conceal_two_windows_01.dump new file mode 100644 index 0000000..0a70677 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_01.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1>h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|4| @10|A|l@1 +|/+0&&|h|e|r|e| @69 diff --git a/src/testdir/dumps/Test_conceal_two_windows_02.dump b/src/testdir/dumps/Test_conceal_two_windows_02.dump new file mode 100644 index 0000000..367149f --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_02.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o>n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|1|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|4| @10|A|l@1 +|/+0&&|h|e|r|e| @69 diff --git a/src/testdir/dumps/Test_conceal_two_windows_03.dump b/src/testdir/dumps/Test_conceal_two_windows_03.dump new file mode 100644 index 0000000..27242eb --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_03.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| |||h|i|d@1|e|n||| >h|e|r|e| @57 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|4| @10|A|l@1 +|:+0&&|s|e|t| |c|o|n|c|e|a|l|c|u|r|s|o|r|=| @55 diff --git a/src/testdir/dumps/Test_conceal_two_windows_04.dump b/src/testdir/dumps/Test_conceal_two_windows_04.dump new file mode 100644 index 0000000..ff52320 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_04.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| |||h|i|d@1|e|n>|| |t|h|r|e@1| @54 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|4| @10|A|l@1 +|:+0&&|s|e|t| |c|o|n|c|e|a|l|c|u|r|s|o|r|=| @55 diff --git a/src/testdir/dumps/Test_conceal_two_windows_05.dump b/src/testdir/dumps/Test_conceal_two_windows_05.dump new file mode 100644 index 0000000..68904d0 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_05.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| |||h|i|d@1|e|n||| >h|e|r|e| @57 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|4| @10|A|l@1 +|:+0&&|s|e|t| |c|o|n|c|e|a|l|c|u|r|s|o|r|=| @55 diff --git a/src/testdir/dumps/Test_conceal_two_windows_06c.dump b/src/testdir/dumps/Test_conceal_two_windows_06c.dump new file mode 100644 index 0000000..b3869f9 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_06c.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| |||h|i|d@1|e|n||| |h|e+1&&|r+0&&|e| @57 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|5| @10|A|l@1 +|/+0&&|e> @72 diff --git a/src/testdir/dumps/Test_conceal_two_windows_06i.dump b/src/testdir/dumps/Test_conceal_two_windows_06i.dump new file mode 100644 index 0000000..c2325b9 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_06i.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| |||h|i|d@1|e|n||| |h>e|r|e| @57 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|5| @10|A|l@1 +|-+2&&@1| |I|N|S|E|R|T| |-@1| +0&&@62 diff --git a/src/testdir/dumps/Test_conceal_two_windows_06n.dump b/src/testdir/dumps/Test_conceal_two_windows_06n.dump new file mode 100644 index 0000000..a147249 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_06n.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1>h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|4| @10|A|l@1 +|:+0&&|s|e|t| |c|o|n|c|e|a|l|c|u|r|s|o|r|=|n| @54 diff --git a/src/testdir/dumps/Test_conceal_two_windows_06v.dump b/src/testdir/dumps/Test_conceal_two_windows_06v.dump new file mode 100644 index 0000000..7456625 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_06v.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| |||h|i|d@1|e|n||| >h|e|r|e| @57 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|4| @10|A|l@1 +|-+2&&@1| |V|I|S|U|A|L| |-@1| +0&&@51|1| @9 diff --git a/src/testdir/dumps/Test_conceal_two_windows_07c.dump b/src/testdir/dumps/Test_conceal_two_windows_07c.dump new file mode 100644 index 0000000..b3869f9 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_07c.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| |||h|i|d@1|e|n||| |h|e+1&&|r+0&&|e| @57 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|5| @10|A|l@1 +|/+0&&|e> @72 diff --git a/src/testdir/dumps/Test_conceal_two_windows_07i.dump b/src/testdir/dumps/Test_conceal_two_windows_07i.dump new file mode 100644 index 0000000..f1cd232 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_07i.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h>e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|5| @10|A|l@1 +|-+2&&@1| |I|N|S|E|R|T| |-@1| +0&&@62 diff --git a/src/testdir/dumps/Test_conceal_two_windows_07n.dump b/src/testdir/dumps/Test_conceal_two_windows_07n.dump new file mode 100644 index 0000000..9ed71a6 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_07n.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| |||h|i|d@1|e|n||| >h|e|r|e| @57 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|4| @10|A|l@1 +|:+0&&|s|e|t| |c|o|n|c|e|a|l|c|u|r|s|o|r|=|i| @54 diff --git a/src/testdir/dumps/Test_conceal_two_windows_07v.dump b/src/testdir/dumps/Test_conceal_two_windows_07v.dump new file mode 100644 index 0000000..7456625 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_07v.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| |||h|i|d@1|e|n||| >h|e|r|e| @57 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|4| @10|A|l@1 +|-+2&&@1| |V|I|S|U|A|L| |-@1| +0&&@51|1| @9 diff --git a/src/testdir/dumps/Test_conceal_two_windows_08c.dump b/src/testdir/dumps/Test_conceal_two_windows_08c.dump new file mode 100644 index 0000000..2d12a9c --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_08c.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e+1&&|r+0&&|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|5| @10|A|l@1 +|/+0&&|e> @72 diff --git a/src/testdir/dumps/Test_conceal_two_windows_08i.dump b/src/testdir/dumps/Test_conceal_two_windows_08i.dump new file mode 100644 index 0000000..c2325b9 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_08i.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| |||h|i|d@1|e|n||| |h>e|r|e| @57 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|5| @10|A|l@1 +|-+2&&@1| |I|N|S|E|R|T| |-@1| +0&&@62 diff --git a/src/testdir/dumps/Test_conceal_two_windows_08n.dump b/src/testdir/dumps/Test_conceal_two_windows_08n.dump new file mode 100644 index 0000000..13e8141 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_08n.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| |||h|i|d@1|e|n||| >h|e|r|e| @57 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|4| @10|A|l@1 +|:+0&&|s|e|t| |c|o|n|c|e|a|l|c|u|r|s|o|r|=|c| @54 diff --git a/src/testdir/dumps/Test_conceal_two_windows_08v.dump b/src/testdir/dumps/Test_conceal_two_windows_08v.dump new file mode 100644 index 0000000..7456625 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_08v.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| |||h|i|d@1|e|n||| >h|e|r|e| @57 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|4| @10|A|l@1 +|-+2&&@1| |V|I|S|U|A|L| |-@1| +0&&@51|1| @9 diff --git a/src/testdir/dumps/Test_conceal_two_windows_09c.dump b/src/testdir/dumps/Test_conceal_two_windows_09c.dump new file mode 100644 index 0000000..b3869f9 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_09c.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| |||h|i|d@1|e|n||| |h|e+1&&|r+0&&|e| @57 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|5| @10|A|l@1 +|/+0&&|e> @72 diff --git a/src/testdir/dumps/Test_conceal_two_windows_09i.dump b/src/testdir/dumps/Test_conceal_two_windows_09i.dump new file mode 100644 index 0000000..c2325b9 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_09i.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| |||h|i|d@1|e|n||| |h>e|r|e| @57 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|5| @10|A|l@1 +|-+2&&@1| |I|N|S|E|R|T| |-@1| +0&&@62 diff --git a/src/testdir/dumps/Test_conceal_two_windows_09n.dump b/src/testdir/dumps/Test_conceal_two_windows_09n.dump new file mode 100644 index 0000000..e00c814 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_09n.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| |||h|i|d@1|e|n||| >h|e|r|e| @57 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|4| @10|A|l@1 +|:+0&&|s|e|t| |c|o|n|c|e|a|l|c|u|r|s|o|r|=|v| @54 diff --git a/src/testdir/dumps/Test_conceal_two_windows_09v.dump b/src/testdir/dumps/Test_conceal_two_windows_09v.dump new file mode 100644 index 0000000..8d6cb4b --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_09v.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1>h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|4| @10|A|l@1 +|-+2&&@1| |V|I|S|U|A|L| |-@1| +0&&@51|1| @9 diff --git a/src/testdir/dumps/Test_conceal_two_windows_10.dump b/src/testdir/dumps/Test_conceal_two_windows_10.dump new file mode 100644 index 0000000..c2325b9 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_10.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| |||h|i|d@1|e|n||| |h>e|r|e| @57 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|2|,|1|5| @10|A|l@1 +|-+2&&@1| |I|N|S|E|R|T| |-@1| +0&&@62 diff --git a/src/testdir/dumps/Test_conceal_two_windows_11.dump b/src/testdir/dumps/Test_conceal_two_windows_11.dump new file mode 100644 index 0000000..42a3fd5 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_11.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| |||h|i|d@1|e|n||> |t|h|r|e@1| @54 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1|5| @10|A|l@1 +|-+2&&@1| |I|N|S|E|R|T| |-@1| +0&&@62 diff --git a/src/testdir/dumps/Test_conceal_two_windows_12.dump b/src/testdir/dumps/Test_conceal_two_windows_12.dump new file mode 100644 index 0000000..63861a1 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_12.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| |||h|i|d@1|e|n>|| |t|h|r|e@1| @54 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1|4| @10|A|l@1 +| +0&&@74 diff --git a/src/testdir/dumps/Test_conceal_two_windows_13.dump b/src/testdir/dumps/Test_conceal_two_windows_13.dump new file mode 100644 index 0000000..2f93e31 --- /dev/null +++ b/src/testdir/dumps/Test_conceal_two_windows_13.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +|S|e|c|o|n|d| |w|i|n|d|o|w| @61 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|3|,|1|4| @10|A|l@1 +|o+0&&|n|e| |o|n|e| |o|n|e| |o|n|e| |o|n|e| @55 +|t|w|o| @1|h|e|r|e| @65 +|t|h|r|e@1| @1|t|h|r|e@1| @62 +> @74 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|4|,|1| @11|A|l@1 +|-+2&&@1| |I|N|S|E|R|T| |-@1| +0&&@62 diff --git a/src/testdir/dumps/Test_cursorline_yank_01.dump b/src/testdir/dumps/Test_cursorline_yank_01.dump new file mode 100644 index 0000000..3de1bff --- /dev/null +++ b/src/testdir/dumps/Test_cursorline_yank_01.dump @@ -0,0 +1,8 @@ +| +0#af5f00255#ffffff0@1|3| | +0#0000000&@70 +| +0#af5f00255&@1|2| |1+0#0000000&| @69 +| +0#af5f00255&@1|1| |2+0#0000000&| @69 +| +0#af5f00255&@1|0| >3+8#0000000&| @69 +| +0#af5f00255&@1|1| | +0#0000000&@70 +|~+0#4040ff13&| @73 +|~| @73 +|4+0#0000000&| |l|i|n|e|s| |y|a|n|k|e|d| @42|4|,|1| @10|A|l@1| diff --git a/src/testdir/dumps/Test_diff_01.dump b/src/testdir/dumps/Test_diff_01.dump new file mode 100644 index 0000000..0dbce1f --- /dev/null +++ b/src/testdir/dumps/Test_diff_01.dump @@ -0,0 +1,20 @@ +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|0+0#0000000#5fd7ff255| @33 +| +0#0000e05#a8a8a8255@1|1+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|1+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|2+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|2+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|3+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|3+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|4+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|4+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|5+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|5+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|6+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|6+0#0000000#ffffff0| @33 +|++0#0000e05#a8a8a8255| |+|-@1| @1|4| |l|i|n|e|s|:| |7|-@19||+1#0000000#ffffff0|++0#0000e05#a8a8a8255| |+|-@1| @1|4| |l|i|n|e|s|:| |7|-@19 +| @1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +|X+3#0000000&|f|i|l|e|1| @12|1|,|1| @11|A|l@1| |X+1&&|f|i|l|e|2| @12|1|,|1| @11|A|l@1 +|:+0&&> @73 diff --git a/src/testdir/dumps/Test_diff_02.dump b/src/testdir/dumps/Test_diff_02.dump new file mode 100644 index 0000000..78f7978 --- /dev/null +++ b/src/testdir/dumps/Test_diff_02.dump @@ -0,0 +1,20 @@ +| +0#0000e05#a8a8a8255@1|0+0#0000000#5fd7ff255| @33||+1&#ffffff0| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34 +| +0#0000e05#a8a8a8255@1|1+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|1+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|2+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|2+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|3+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|3+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|4+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|4+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|5+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|5+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|6+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|6+0#0000000#ffffff0| @33 +|++0#0000e05#a8a8a8255| |+|-@1| @1|4| |l|i|n|e|s|:| |7|-@19||+1#0000000#ffffff0|++0#0000e05#a8a8a8255| |+|-@1| @1|4| |l|i|n|e|s|:| |7|-@19 +| @1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +|X+3#0000000&|f|i|l|e|1| @12|1|,|1| @11|A|l@1| |X+1&&|f|i|l|e|2| @12|1|,|1| @11|A|l@1 +|:+0&&> @73 diff --git a/src/testdir/dumps/Test_diff_03.dump b/src/testdir/dumps/Test_diff_03.dump new file mode 100644 index 0000000..60916a8 --- /dev/null +++ b/src/testdir/dumps/Test_diff_03.dump @@ -0,0 +1,20 @@ +|++0#0000e05#a8a8a8255| |+|-@1| @1|4| |l|i|n|e|s|:| |1|-@19||+1#0000000#ffffff0|++0#0000e05#a8a8a8255| |+|-@1| @1|4| |l|i|n|e|s|:| |1|-@19 +| @1|5+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|5+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|6+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|6+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|7+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|7+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|8+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|8+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|9+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|9+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|1+0#0000000#ffffff0|0| @32||+1&&| +0#0000e05#a8a8a8255@1|1+0#0000000#ffffff0|0| @32 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|1+0#0000000#5fd7ff255@1| @32 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +|X+3#0000000&|f|i|l|e|1| @12|1|,|1| @11|A|l@1| |X+1&&|f|i|l|e|2| @12|1|,|1| @11|A|l@1 +|:+0&&> @73 diff --git a/src/testdir/dumps/Test_diff_04.dump b/src/testdir/dumps/Test_diff_04.dump new file mode 100644 index 0000000..ba9cdd8 --- /dev/null +++ b/src/testdir/dumps/Test_diff_04.dump @@ -0,0 +1,20 @@ +|++0#0000e05#a8a8a8255| |+|-@1| @1|4| |l|i|n|e|s|:| |1|-@19||+1#0000000#ffffff0|++0#0000e05#a8a8a8255| |+|-@1| @1|4| |l|i|n|e|s|:| |1|-@19 +| @1|5+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|5+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|6+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|6+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|7+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|7+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|8+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|8+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|9+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|9+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|1+0#0000000#ffffff0|0| @32||+1&&| +0#0000e05#a8a8a8255@1|1+0#0000000#ffffff0|0| @32 +| +0#0000e05#a8a8a8255@1|1+0#0000000#5fd7ff255@1| @32||+1&#ffffff0| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +|X+3#0000000&|f|i|l|e|1| @12|1|,|1| @11|A|l@1| |X+1&&|f|i|l|e|2| @12|1|,|1| @11|A|l@1 +|:+0&&> @73 diff --git a/src/testdir/dumps/Test_diff_05.dump b/src/testdir/dumps/Test_diff_05.dump new file mode 100644 index 0000000..7a5d540 --- /dev/null +++ b/src/testdir/dumps/Test_diff_05.dump @@ -0,0 +1,20 @@ +| +0#0000e05#a8a8a8255@1|1+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|1+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|2+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|2+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|3+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|3+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|4+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|4+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|4+0#0000000#5fd7ff255| @33 +| +0#0000e05#a8a8a8255@1|5+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|5+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|6+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|6+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|7+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|7+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|8+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|8+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|9+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|9+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|1+0#0000000#ffffff0|0| @32||+1&&| +0#0000e05#a8a8a8255@1|1+0#0000000#ffffff0|0| @32 +| +0#0000e05#a8a8a8255@1|1+0#0000000#5fd7ff255@1| @32||+1&#ffffff0| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +|X+3#0000000&|f|i|l|e|1| @12|1|,|1| @11|A|l@1| |X+1&&|f|i|l|e|2| @12|1|,|1| @11|A|l@1 +|:+0&&> @73 diff --git a/src/testdir/dumps/Test_diff_06.dump b/src/testdir/dumps/Test_diff_06.dump new file mode 100644 index 0000000..8cd68fd --- /dev/null +++ b/src/testdir/dumps/Test_diff_06.dump @@ -0,0 +1,20 @@ +| +0#0000e05#a8a8a8255@1|1+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|1+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|2+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|2+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|3+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|3+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|4+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|4+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|4+0#0000000#5fd7ff255| @33||+1&#ffffff0| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34 +| +0#0000e05#a8a8a8255@1|5+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|5+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|6+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|6+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|7+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|7+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|8+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|8+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|9+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|9+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|1+0#0000000#ffffff0|0| @32||+1&&| +0#0000e05#a8a8a8255@1|1+0#0000000#ffffff0|0| @32 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|1+0#0000000#5fd7ff255@1| @32 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +|X+3#0000000&|f|i|l|e|1| @12|1|,|1| @11|A|l@1| |X+1&&|f|i|l|e|2| @12|1|,|1| @11|A|l@1 +|:+0&&> @73 diff --git a/src/testdir/dumps/Test_diff_07.dump b/src/testdir/dumps/Test_diff_07.dump new file mode 100644 index 0000000..97864c6 --- /dev/null +++ b/src/testdir/dumps/Test_diff_07.dump @@ -0,0 +1,20 @@ +| +0#0000e05#a8a8a8255@1>#+0#0000000#ffffff0|i|n|c|l|u|d|e| |<|s|t|d|i|o|.|h|>| @16||+1&&| +0#0000e05#a8a8a8255@1|#+0#0000000#ffffff0|i|n|c|l|u|d|e| |<|s|t|d|i|o|.|h|>| @16 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@34||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@34 +| +0#0000e05#a8a8a8255@1|/+2#0000000#ff404010@1| |F|r|o|b|s| |f|o@1| |h|e|a|r|t|i|l|y| +0&#ffd7ff255@13||+1&#ffffff0| +0#0000e05#a8a8a8255@1|i+2#0000000#ff404010|n|t| |f|i|b|(|i|n|t| |n|)| +0&#ffd7ff255@20 +| +0#0000e05#a8a8a8255@1|i+0#0000000#5fd7ff255|n|t| |f|r|o|b|n|i|t|z|(|i|n|t| |f|o@1|)| @13||+1&#ffffff0| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34 +| +0#0000e05#a8a8a8255@1|{+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|{+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffd7ff255@3|i|n+2&#ff404010|t| |i|;| +0&#ffd7ff255@24||+1&#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#ffd7ff255@3|i|f+2&#ff404010|(|n| |>| |2|)| +0&#ffd7ff255@21 +| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@3|f|o|r|(|i| |=| |0|;| |i| |<| |1|0|;| |i|+@1|)| @7||+1&#ffffff0| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@3|{| @29||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@3|{| @29 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffd7ff255@7|p+2&#ff404010|r|i|n|t|f|(|"|Y|o|u|r| |a|n|s|w|e|r| |i|s|:| |"|)+0&#ffd7ff255|;||+1&#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#ffd7ff255@7|r+2&#ff404010|e|t|u|r|n| |f|i|b|(|n|-|1|)| |+| |f|i|b|(|n|-|2|)+0&#ffd7ff255|; +| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@7|p|r|i|n|t|f|(|"|%|d|\|n|"|,| |f|o@1|)|;| @6||+1&#ffffff0| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@3|}| @29||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@3|}| @29 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@3|r|e|t|u|r|n| |1|;| @21 +| +0#0000e05#a8a8a8255@1|}+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|}+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@34||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@34 +| +0#0000e05#a8a8a8255@1|i+2#0000000#ff404010|n|t| |f|a|c|t|(|i|n|t| |n|)| +0&#ffd7ff255@19||+1&#ffffff0| +0#0000e05#a8a8a8255@1|/+2#0000000#ff404010@1| |F|r|o|b|s| |f|o@1| |h|e|a|r|t|i|l|y| +0&#ffd7ff255@13 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|i+0#0000000#5fd7ff255|n|t| |f|r|o|b|n|i|t|z|(|i|n|t| |f|o@1|)| @13 +| +0#0000e05#a8a8a8255@1|{+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|{+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffd7ff255@3|i|f+2&#ff404010|(|n| |>| |1|)| +0&#ffd7ff255@21||+1&#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#ffd7ff255@3|i|n+2&#ff404010|t| |i|;| +0&#ffd7ff255@24 +|X+3&#ffffff0|f|i|l|e|1| @12|1|,|1| @11|T|o|p| |X+1&&|f|i|l|e|2| @12|1|,|1| @11|T|o|p +|:+0&&|s|e|t| |d|i|f@1|o|p|t|+|=|i|n|t|e|r|n|a|l| @52 diff --git a/src/testdir/dumps/Test_diff_08.dump b/src/testdir/dumps/Test_diff_08.dump new file mode 100644 index 0000000..6445a57 --- /dev/null +++ b/src/testdir/dumps/Test_diff_08.dump @@ -0,0 +1,20 @@ +| +0#0000e05#a8a8a8255@1>#+0#0000000#ffffff0|i|n|c|l|u|d|e| |<|s|t|d|i|o|.|h|>| @16||+1&&| +0#0000e05#a8a8a8255@1|#+0#0000000#ffffff0|i|n|c|l|u|d|e| |<|s|t|d|i|o|.|h|>| @16 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@34||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@34 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|i+0#0000000#5fd7ff255|n|t| |f|i|b|(|i|n|t| |n|)| @20 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|{+0#0000000#5fd7ff255| @33 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@3|i|f|(|n| |>| |2|)| @21 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@3|{| @29 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@7|r|e|t|u|r|n| |f|i|b|(|n|-|1|)| |+| |f|i|b|(|n|-|2|)|; +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@3|}| @29 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@3|r|e|t|u|r|n| |1|;| @21 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|}+0#0000000#5fd7ff255| @33 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@34 +| +0#0000e05#a8a8a8255@1|/+0#0000000#ffffff0@1| |F|r|o|b|s| |f|o@1| |h|e|a|r|t|i|l|y| @13||+1&&| +0#0000e05#a8a8a8255@1|/+0#0000000#ffffff0@1| |F|r|o|b|s| |f|o@1| |h|e|a|r|t|i|l|y| @13 +| +0#0000e05#a8a8a8255@1|i+0#0000000#ffffff0|n|t| |f|r|o|b|n|i|t|z|(|i|n|t| |f|o@1|)| @13||+1&&| +0#0000e05#a8a8a8255@1|i+0#0000000#ffffff0|n|t| |f|r|o|b|n|i|t|z|(|i|n|t| |f|o@1|)| @13 +| +0#0000e05#a8a8a8255@1|{+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|{+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@3|i|n|t| |i|;| @24||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@3|i|n|t| |i|;| @24 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@3|f|o|r|(|i| |=| |0|;| |i| |<| |1|0|;| |i|+@1|)| @7||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@3|f|o|r|(|i| |=| |0|;| |i| |<| |1|0|;| |i|+@1|)| @7 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@3|{| @29||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@3|{| @29 +| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@7|p|r|i|n|t|f|(|"|Y|o|u|r| |a|n|s|w|e|r| |i|s|:| |"|)|;||+1&#ffffff0| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34 +|X+3#0000000#ffffff0|f|i|l|e|1| @12|1|,|1| @11|T|o|p| |X+1&&|f|i|l|e|2| @12|1|,|1| @11|T|o|p +|:+0&&|s|e|t| |d|i|f@1|o|p|t|+|=|a|l|g|o|r|i|t|h|m|:|p|a|t|i|e|n|c|e| @42 diff --git a/src/testdir/dumps/Test_diff_09.dump b/src/testdir/dumps/Test_diff_09.dump new file mode 100644 index 0000000..95692b6 --- /dev/null +++ b/src/testdir/dumps/Test_diff_09.dump @@ -0,0 +1,20 @@ +| +0#0000e05#a8a8a8255@1>#+0#0000000#ffffff0|i|n|c|l|u|d|e| |<|s|t|d|i|o|.|h|>| @16||+1&&| +0#0000e05#a8a8a8255@1|#+0#0000000#ffffff0|i|n|c|l|u|d|e| |<|s|t|d|i|o|.|h|>| @16 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@34||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@34 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|i+0#0000000#5fd7ff255|n|t| |f|i|b|(|i|n|t| |n|)| @20 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|{+0#0000000#5fd7ff255| @33 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@3|i|f|(|n| |>| |2|)| @21 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@3|{| @29 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@7|r|e|t|u|r|n| |f|i|b|(|n|-|1|)| |+| |f|i|b|(|n|-|2|)|; +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@3|}| @29 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@3|r|e|t|u|r|n| |1|;| @21 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|}+0#0000000#5fd7ff255| @33 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@34 +| +0#0000e05#a8a8a8255@1|/+0#0000000#ffffff0@1| |F|r|o|b|s| |f|o@1| |h|e|a|r|t|i|l|y| @13||+1&&| +0#0000e05#a8a8a8255@1|/+0#0000000#ffffff0@1| |F|r|o|b|s| |f|o@1| |h|e|a|r|t|i|l|y| @13 +| +0#0000e05#a8a8a8255@1|i+0#0000000#ffffff0|n|t| |f|r|o|b|n|i|t|z|(|i|n|t| |f|o@1|)| @13||+1&&| +0#0000e05#a8a8a8255@1|i+0#0000000#ffffff0|n|t| |f|r|o|b|n|i|t|z|(|i|n|t| |f|o@1|)| @13 +| +0#0000e05#a8a8a8255@1|{+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|{+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@3|i|n|t| |i|;| @24||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@3|i|n|t| |i|;| @24 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@3|f|o|r|(|i| |=| |0|;| |i| |<| |1|0|;| |i|+@1|)| @7||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@3|f|o|r|(|i| |=| |0|;| |i| |<| |1|0|;| |i|+@1|)| @7 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@3|{| @29||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@3|{| @29 +| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@7|p|r|i|n|t|f|(|"|Y|o|u|r| |a|n|s|w|e|r| |i|s|:| |"|)|;||+1&#ffffff0| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34 +|X+3#0000000#ffffff0|f|i|l|e|1| @12|1|,|1| @11|T|o|p| |X+1&&|f|i|l|e|2| @12|1|,|1| @11|T|o|p +|:+0&&|s|e|t| |d|i|f@1|o|p|t|+|=|a|l|g|o|r|i|t|h|m|:|h|i|s|t|o|g|r|a|m| @41 diff --git a/src/testdir/dumps/Test_diff_10.dump b/src/testdir/dumps/Test_diff_10.dump new file mode 100644 index 0000000..70b9c82 --- /dev/null +++ b/src/testdir/dumps/Test_diff_10.dump @@ -0,0 +1,20 @@ +| +0#0000e05#a8a8a8255@1> +0#0000000#ffffff0@34||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@34 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@1|d|e|f| |f|i|n|a|l|i|z|e|(|v|a|l|u|e|s|)| @12||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@1|d|e|f| |f|i|n|a|l|i|z|e|(|v|a|l|u|e|s|)| @12 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@34||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@34 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@3|v|a|l|u|e|s|.|e|a|c|h| |d|o| |||v||| @12||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@3|v|a|l|u|e|s|.|e|a|c|h| |d|o| |||v||| @12 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@5|v|.|p|r|e|p|a|r|e| @19 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@3|e|n|d| @27 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@34 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@3|v|a|l|u|e|s|.|e|a|c|h| |d|o| |||v||| @12 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@5|v|.|f|i|n|a|l|i|z|e| @18||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@5|v|.|f|i|n|a|l|i|z|e| @18 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@3|e|n|d| @27||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@3|e|n|d| @27 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +|X+3#0000000&|f|i|l|e|1| @12|1|,|0|-|1| @9|A|l@1| |X+1&&|f|i|l|e|2| @12|1|,|0|-|1| @9|A|l@1 +|:+0&&|s|e|t| |d|i|f@1|o|p|t|+|=|i|n|t|e|r|n|a|l| @52 diff --git a/src/testdir/dumps/Test_diff_11.dump b/src/testdir/dumps/Test_diff_11.dump new file mode 100644 index 0000000..3b24ebb --- /dev/null +++ b/src/testdir/dumps/Test_diff_11.dump @@ -0,0 +1,20 @@ +| +0#0000e05#a8a8a8255@1> +0#0000000#ffffff0@34||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@34 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@1|d|e|f| |f|i|n|a|l|i|z|e|(|v|a|l|u|e|s|)| @12||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@1|d|e|f| |f|i|n|a|l|i|z|e|(|v|a|l|u|e|s|)| @12 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@34||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@34 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@3|v|a|l|u|e|s|.|e|a|c|h| |d|o| |||v||| @12 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@5|v|.|p|r|e|p|a|r|e| @19 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@3|e|n|d| @27 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@34 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@3|v|a|l|u|e|s|.|e|a|c|h| |d|o| |||v||| @12||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@3|v|a|l|u|e|s|.|e|a|c|h| |d|o| |||v||| @12 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@5|v|.|f|i|n|a|l|i|z|e| @18||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@5|v|.|f|i|n|a|l|i|z|e| @18 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@3|e|n|d| @27||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@3|e|n|d| @27 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +|X+3#0000000&|f|i|l|e|1| @12|1|,|0|-|1| @9|A|l@1| |X+1&&|f|i|l|e|2| @12|1|,|0|-|1| @9|A|l@1 +|:+0&&| @73 diff --git a/src/testdir/dumps/Test_diff_12.dump b/src/testdir/dumps/Test_diff_12.dump new file mode 100644 index 0000000..0ed4f91 --- /dev/null +++ b/src/testdir/dumps/Test_diff_12.dump @@ -0,0 +1,20 @@ +|++0#0000e05#a8a8a8255| |+|-@1| |1|0| |l|i|n|e|s|:| |1|-@19||+1#0000000#ffffff0|++0#0000e05#a8a8a8255| |+|-@1| |1|0| |l|i|n|e|s|:| |1|-@19 +| @1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +|X+3#0000000&|f|i|l|e|1| @12|1|,|1| @11|A|l@1| |X+1&&|f|i|l|e|2| @12|1|,|1| @11|A|l@1 +|:+0&&> @73 diff --git a/src/testdir/dumps/Test_diff_13.dump b/src/testdir/dumps/Test_diff_13.dump new file mode 100644 index 0000000..cc1f1ad --- /dev/null +++ b/src/testdir/dumps/Test_diff_13.dump @@ -0,0 +1,20 @@ +|-+0#0000e05#a8a8a8255| | +0#0000000#ffffff0@34||+1&&|-+0#0000e05#a8a8a8255| | +0#0000000#ffffff0@34 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +|X+3#0000000&|f|i|l|e|1| @12|0|,|0|-|1| @9|A|l@1| |X+1&&|f|i|l|e|2| @12|0|,|0|-|1| @9|A|l@1 +|:+0&&> @73 diff --git a/src/testdir/dumps/Test_diff_14.dump b/src/testdir/dumps/Test_diff_14.dump new file mode 100644 index 0000000..5f9b75f --- /dev/null +++ b/src/testdir/dumps/Test_diff_14.dump @@ -0,0 +1,20 @@ +| +0#0000e05#a8a8a8255@1|a+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|A+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|b+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|b+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|c+0#0000000#ffd7ff255|d| @32||+1&#ffffff0| +0#0000e05#a8a8a8255@1|c+0#0000000#ffd7ff255|D|e+2&#ff404010| +0&#ffd7ff255@31 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +|X+3#0000000&|f|i|l|e|1| @12|1|,|1| @11|A|l@1| |X+1&&|f|i|l|e|2| @12|1|,|1| @11|A|l@1 +|:+0&&> @73 diff --git a/src/testdir/dumps/Test_diff_15.dump b/src/testdir/dumps/Test_diff_15.dump new file mode 100644 index 0000000..0eb1813 --- /dev/null +++ b/src/testdir/dumps/Test_diff_15.dump @@ -0,0 +1,20 @@ +| +0#0000e05#a8a8a8255@1>i+0#0000000#ffffff0|n|t| |m|a|i|n|(|)| @24||+1&&| +0#0000e05#a8a8a8255@1|i+0#0000000#ffffff0|n|t| |m|a|i|n|(|)| @24 +| +0#0000e05#a8a8a8255@1|{+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|{+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@2|i|f| |(|0|)| @25 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@2|{| @30 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@2|p|r|i|n|t|f|(|"|H|e|l@1|o|,| |W|o|r|l|d|!|"|)|;| @7||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@5|p|r|i|n|t|f|(|"|H|e|l@1|o|,| |W|o|r|l|d|!|"|)|;| @4 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@2|r|e|t|u|r|n| |0|;| @22||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@5|r|e|t|u|r|n| |0|;| @19 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@2|}| @30 +| +0#0000e05#a8a8a8255@1|}+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|}+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +|X+3#0000000&|f|i|l|e|1| @12|1|,|1| @11|A|l@1| |X+1&&|f|i|l|e|2| @12|1|,|1| @11|A|l@1 +|:+0&&|s|e|t| |d|i|f@1|o|p|t|&|v|i|m| |d|i|f@1|o|p|t|+|=|f|i|l@1|e|r| |d|i|f@1|o|p|t|+|=|i|w|h|i|t|e| @26 diff --git a/src/testdir/dumps/Test_diff_16.dump b/src/testdir/dumps/Test_diff_16.dump new file mode 100644 index 0000000..74ad5b6 --- /dev/null +++ b/src/testdir/dumps/Test_diff_16.dump @@ -0,0 +1,20 @@ +| +0#0000e05#a8a8a8255@1>i+0#0000000#ffffff0|n|t| |m|a|i|n|(|)| @24||+1&&| +0#0000e05#a8a8a8255@1|i+0#0000000#ffffff0|n|t| |m|a|i|n|(|)| @24 +| +0#0000e05#a8a8a8255@1|{+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|{+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@2|i|f| |(|0|)| @25 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@2|{| @30 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@2|p|r|i|n|t|f|(|"|H|e|l@1|o|,| |W|o|r|l|d|!|"|)|;| @7||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@5|p|r|i|n|t|f|(|"|H|e|l@1|o|,| |W|o|r|l|d|!|"|)|;| @4 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@2|r|e|t|u|r|n| |0|;| @22||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@5|r|e|t|u|r|n| |0|;| @19 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@2|}| @30 +| +0#0000e05#a8a8a8255@1|}+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|}+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +|X+3#0000000&|f|i|l|e|1| @12|1|,|1| @11|A|l@1| |X+1&&|f|i|l|e|2| @12|1|,|1| @11|A|l@1 +|:+0&&|s|e|t| |d|i|f@1|o|p|t|+|=|i|n|t|e|r|n|a|l| @52 diff --git a/src/testdir/dumps/Test_diff_17.dump b/src/testdir/dumps/Test_diff_17.dump new file mode 100644 index 0000000..101df35 --- /dev/null +++ b/src/testdir/dumps/Test_diff_17.dump @@ -0,0 +1,20 @@ +| +0#0000e05#a8a8a8255@1|a+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|a+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@34||+1&#ffffff0| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34 +| +0#0000e05#a8a8a8255@1|c+0#0000000#ffffff0|d| @32||+1&&| +0#0000e05#a8a8a8255@1|c+0#0000000#ffffff0|d| @32 +| +0#0000e05#a8a8a8255@1|e+0#0000000#ffffff0|f| @32||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@34 +| +0#0000e05#a8a8a8255@1|x+2#0000000#ff404010@2| +0&#ffd7ff255@31||+1&#ffffff0| +0#0000e05#a8a8a8255@1|e+0#0000000#ffffff0|f| @32 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|y+2#0000000#ff404010@2| +0&#ffd7ff255@31 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +|X+3#0000000&|f|i|l|e|1| @12|1|,|1| @11|A|l@1| |X+1&&|f|i|l|e|2| @12|1|,|1| @11|A|l@1 +|:+0&&> @73 diff --git a/src/testdir/dumps/Test_diff_18.dump b/src/testdir/dumps/Test_diff_18.dump new file mode 100644 index 0000000..7f17531 --- /dev/null +++ b/src/testdir/dumps/Test_diff_18.dump @@ -0,0 +1,20 @@ +| +0#0000e05#a8a8a8255@1|a+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|a+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@34||+1&&| +0#0000e05#a8a8a8255@1|c+0#0000000#ffffff0|d| @32 +| +0#0000e05#a8a8a8255@1|c+0#0000000#ffffff0|d| @32||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@34 +| +0#0000e05#a8a8a8255@1|e+0#0000000#ffffff0|f| @32||+1&&| +0#0000e05#a8a8a8255@1|e+0#0000000#ffffff0|f| @32 +| +0#0000e05#a8a8a8255@1|x+2#0000000#ff404010@2| +0&#ffd7ff255@31||+1&#ffffff0| +0#0000e05#a8a8a8255@1|y+2#0000000#ff404010@2| +0&#ffd7ff255@31 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +|X+3#0000000&|f|i|l|e|1| @12|1|,|1| @11|A|l@1| |X+1&&|f|i|l|e|2| @12|1|,|1| @11|A|l@1 +|:+0&&> @73 diff --git a/src/testdir/dumps/Test_diff_19.dump b/src/testdir/dumps/Test_diff_19.dump new file mode 100644 index 0000000..f2d0611 --- /dev/null +++ b/src/testdir/dumps/Test_diff_19.dump @@ -0,0 +1,20 @@ +| +0#0000e05#a8a8a8255@1|a+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|a+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|x+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|x+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|c+0#0000000#ffd7ff255|d| @32||+1&#ffffff0| +0#0000e05#a8a8a8255@1|c+0#0000000#ffd7ff255| +2&#ff404010|d+0&#ffd7ff255| @31 +| +0#0000e05#a8a8a8255@1|e+0#0000000#ffd7ff255|f| @32||+1&#ffffff0| +0#0000e05#a8a8a8255@1| +2#0000000#ff404010|e+0&#ffd7ff255|f| @31 +| +0#0000e05#a8a8a8255@1|x+0#0000000#ffd7ff255@1| | +2&#ff404010|x+0&#ffd7ff255@1| @28||+1&#ffffff0| +0#0000e05#a8a8a8255@1|x+0#0000000#ffd7ff255@1| |x@1| @29 +| +0#0000e05#a8a8a8255@1|f+0#0000000#ffffff0|o@1| @31||+1&&| +0#0000e05#a8a8a8255@1|f+0#0000000#ffffff0|o@1| @31 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@34 +| +0#0000e05#a8a8a8255@1|b+0#0000000#ffffff0|a|r| @31||+1&&| +0#0000e05#a8a8a8255@1|b+0#0000000#ffffff0|a|r| @31 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +|X+3#0000000&|f|i|l|e|1| @12|1|,|1| @11|A|l@1| |X+1&&|f|i|l|e|2| @12|1|,|1| @11|A|l@1 +|:+0&&> @73 diff --git a/src/testdir/dumps/Test_diff_20.dump b/src/testdir/dumps/Test_diff_20.dump new file mode 100644 index 0000000..1dbd07c --- /dev/null +++ b/src/testdir/dumps/Test_diff_20.dump @@ -0,0 +1,20 @@ +| +0#0000e05#a8a8a8255@1|a+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|a+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|x+0#0000000#ffffff0| @33||+1&&| +0#0000e05#a8a8a8255@1|x+0#0000000#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|c+0#0000000#ffffff0|d| @32||+1&&| +0#0000e05#a8a8a8255@1|c+0#0000000#ffffff0| |d| @31 +| +0#0000e05#a8a8a8255@1|e+0#0000000#ffffff0|f| @32||+1&&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0|e|f| @31 +| +0#0000e05#a8a8a8255@1|x+0#0000000#ffffff0@1| @1|x@1| @28||+1&&| +0#0000e05#a8a8a8255@1|x+0#0000000#ffffff0@1| |x@1| @29 +| +0#0000e05#a8a8a8255@1|f+0#0000000#ffffff0|o@1| @31||+1&&| +0#0000e05#a8a8a8255@1|f+0#0000000#ffffff0|o@1| @31 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1| +0#0000000#5fd7ff255@34 +| +0#0000e05#a8a8a8255@1|b+0#0000000#ffffff0|a|r| @31||+1&&| +0#0000e05#a8a8a8255@1|b+0#0000000#ffffff0|a|r| @31 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +|X+3#0000000&|f|i|l|e|1| @12|1|,|1| @11|A|l@1| |X+1&&|f|i|l|e|2| @12|1|,|1| @11|A|l@1 +|:+0&&> @73 diff --git a/src/testdir/dumps/Test_diff_of_diff_01.dump b/src/testdir/dumps/Test_diff_of_diff_01.dump new file mode 100644 index 0000000..0e47a86 --- /dev/null +++ b/src/testdir/dumps/Test_diff_of_diff_01.dump @@ -0,0 +1,20 @@ +| +0#0000e05#a8a8a8255@1|a+0#0000000#ffffff0@1| @32||+1&&| +0#0000e05#a8a8a8255@1>a+0#0000000#ffffff0@1| @32 +| +0#0000e05#a8a8a8255@1|b+0#0000000#ffffff0@1| @32||+1&&| +0#0000e05#a8a8a8255@1|b+0#0000000#ffffff0@1| @32 +| +0#0000e05#a8a8a8255@1|c+0#0000000#ffffff0@1| @32||+1&&| +0#0000e05#a8a8a8255@1|c+0#0000000#ffffff0@1| @32 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|@+0#0000000#5fd7ff255@1| |-|3|,|2| |+|5|,|7| |@@1| @19 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|d+0#0000000#5fd7ff255@1| @32 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|e+0#0000000#5fd7ff255@1| @32 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|f+0#0000000#5fd7ff255@1| @32 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @5|1|,|1| @11|A|l@1| |[+3&&|N|o| |N|a|m|e|]| |[|+|]| @5|1|,|1| @11|A|l@1 +| +0&&@74 diff --git a/src/testdir/dumps/Test_diff_with_cursorline_01.dump b/src/testdir/dumps/Test_diff_with_cursorline_01.dump new file mode 100644 index 0000000..96fa357 --- /dev/null +++ b/src/testdir/dumps/Test_diff_with_cursorline_01.dump @@ -0,0 +1,20 @@ +| +0#0000e05#a8a8a8255@1|b+8#ffffff16#ff404010|e@1| @31||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34 +| +0#0000e05#a8a8a8255@1|f+0#0000000#ffffff0|o@1| @31||+1&&| +0#0000e05#a8a8a8255@1>f+8#ffffff16#ff404010|o@1| @31 +| +0#0000e05#a8a8a8255@1|f+0#0000000#ffffff0|o@1| @31||+1&&| +0#0000e05#a8a8a8255@1|f+0#0000000#ffffff0|o@1| @31 +| +0#0000e05#a8a8a8255@1|b+2#0000000#ff404010|a|z| +0&#ffd7ff255@31||+1&#ffffff0| +0#0000e05#a8a8a8255@1|f+2#0000000#ff404010|o@1| +0&#ffd7ff255@31 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|b+0#0000000#5fd7ff255|a|r| @31 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @5|1|,|1| @11|A|l@1| |[+3&&|N|o| |N|a|m|e|]| |[|+|]| @5|1|,|1| @11|A|l@1 +| +0&&@74 diff --git a/src/testdir/dumps/Test_diff_with_cursorline_02.dump b/src/testdir/dumps/Test_diff_with_cursorline_02.dump new file mode 100644 index 0000000..1ba44e6 --- /dev/null +++ b/src/testdir/dumps/Test_diff_with_cursorline_02.dump @@ -0,0 +1,20 @@ +| +0#0000e05#a8a8a8255@1|b+0#0000000#5fd7ff255|e@1| @31||+1&#ffffff0| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34 +| +0#0000e05#a8a8a8255@1|f+0#0000000#ffffff0|o@1| @31||+1&&| +0#0000e05#a8a8a8255@1|f+0#0000000#ffffff0|o@1| @31 +| +0#0000e05#a8a8a8255@1|f+8#ffffff16#ff404010|o@1| @31||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1>f+8#ffffff16#ff404010|o@1| @31 +| +0#0000e05#a8a8a8255@1|b+2#0000000#ff404010|a|z| +0&#ffd7ff255@31||+1&#ffffff0| +0#0000e05#a8a8a8255@1|f+2#0000000#ff404010|o@1| +0&#ffd7ff255@31 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|b+0#0000000#5fd7ff255|a|r| @31 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @5|3|,|1| @11|A|l@1| |[+3&&|N|o| |N|a|m|e|]| |[|+|]| @5|2|,|1| @11|A|l@1 +| +0&&@74 diff --git a/src/testdir/dumps/Test_diff_with_cursorline_03.dump b/src/testdir/dumps/Test_diff_with_cursorline_03.dump new file mode 100644 index 0000000..8dbb414 --- /dev/null +++ b/src/testdir/dumps/Test_diff_with_cursorline_03.dump @@ -0,0 +1,20 @@ +| +0#0000e05#a8a8a8255@1|b+0#0000000#5fd7ff255|e@1| @31||+1&#ffffff0| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34 +| +0#0000e05#a8a8a8255@1|f+0#0000000#ffffff0|o@1| @31||+1&&| +0#0000e05#a8a8a8255@1|f+0#0000000#ffffff0|o@1| @31 +| +0#0000e05#a8a8a8255@1|f+0#0000000#ffffff0|o@1| @31||+1&&| +0#0000e05#a8a8a8255@1|f+0#0000000#ffffff0|o@1| @31 +| +0#0000e05#a8a8a8255@1|b+10#ffffff16#ff404010|a|z| +8&&@31||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1>f+10#ffffff16#ff404010|o@1| +8&&@31 +| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|b+0#0000000#5fd7ff255|a|r| @31 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33||+1#0000000&| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @33 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @5|4|,|1| @11|A|l@1| |[+3&&|N|o| |N|a|m|e|]| |[|+|]| @5|3|,|1| @11|A|l@1 +| +0&&@74 diff --git a/src/testdir/dumps/Test_folds_with_rnu_01.dump b/src/testdir/dumps/Test_folds_with_rnu_01.dump new file mode 100644 index 0000000..15a44d1 --- /dev/null +++ b/src/testdir/dumps/Test_folds_with_rnu_01.dump @@ -0,0 +1,20 @@ +|++0#0000e05#a8a8a8255| @2|0| >+|-@1| @1|2| |l|i|n|e|s|:| |-@54 +|+| @2|1| |+|-@1| @1|2| |l|i|n|e|s|:| |-@54 +| @1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000000&@56|1|,|1| @10|A|l@1| diff --git a/src/testdir/dumps/Test_folds_with_rnu_02.dump b/src/testdir/dumps/Test_folds_with_rnu_02.dump new file mode 100644 index 0000000..60d4eb3 --- /dev/null +++ b/src/testdir/dumps/Test_folds_with_rnu_02.dump @@ -0,0 +1,20 @@ +|++0#0000e05#a8a8a8255| @2|1| |+|-@1| @1|2| |l|i|n|e|s|:| |-@54 +|+| @2|0| >+|-@1| @1|2| |l|i|n|e|s|:| |-@54 +| @1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000e05#a8a8a8255@1|~+0#4040ff13#ffffff0| @71 +| +0#0000000&@56|3|,|1| @10|A|l@1| diff --git a/src/testdir/dumps/Test_incsearch_scrolling_01.dump b/src/testdir/dumps/Test_incsearch_scrolling_01.dump new file mode 100644 index 0000000..c133d5f --- /dev/null +++ b/src/testdir/dumps/Test_incsearch_scrolling_01.dump @@ -0,0 +1,9 @@ +|.+0&#ffffff0@69 +@50| @19 +|.@69 +@50| @19 +@70 +|t+1&&|a|r|g|e+0&&|t| @63 +|@+0#4040ff13&@2| @66 +|/+0#0000000&|t|a|r|g> @64 +@70 diff --git a/src/testdir/dumps/Test_incsearch_search_01.dump b/src/testdir/dumps/Test_incsearch_search_01.dump new file mode 100644 index 0000000..324abfe --- /dev/null +++ b/src/testdir/dumps/Test_incsearch_search_01.dump @@ -0,0 +1,9 @@ +|f+0&#ffff4012|o|o+0&#ffffff0| |1| @64 +|f+0&#ffff4012|o|o+0&#ffffff0| |2| @64 +|f+0&#ffff4012|o|o+0&#ffffff0| |3| @64 +|f+1&&|o|o+0&&| |4| @64 +|f+0&#ffff4012|o|o+0&#ffffff0| |5| @64 +|f+0&#ffff4012|o|o+0&#ffffff0| |6| @64 +|f+0&#ffff4012|o|o+0&#ffffff0| |7| @64 +|f+0&#ffff4012|o|o+0&#ffffff0| |8| @64 +|/|f|o> @66 diff --git a/src/testdir/dumps/Test_incsearch_search_02.dump b/src/testdir/dumps/Test_incsearch_search_02.dump new file mode 100644 index 0000000..6c1b743 --- /dev/null +++ b/src/testdir/dumps/Test_incsearch_search_02.dump @@ -0,0 +1,9 @@ +|f+0&#ffffff0|o@1| |1| @64 +|f|o@1| |2| @64 +|f|o+1&&|o+0&&| |3| @64 +|f|o@1| |4| @64 +|f|o@1| |5| @64 +|f|o@1| |6| @64 +|f|o@1| |7| @64 +|f|o@1| |8| @64 +|/|\|v> @66 diff --git a/src/testdir/dumps/Test_incsearch_sort_01.dump b/src/testdir/dumps/Test_incsearch_sort_01.dump new file mode 100644 index 0000000..6c003af --- /dev/null +++ b/src/testdir/dumps/Test_incsearch_sort_01.dump @@ -0,0 +1,9 @@ +|a+0&#ffffff0|n|o|t|h|e|r| |o+1&&|n|e+0&&| |2| @56 +|t|h|a|t| |o+0&#ffff4012|n|e+0&#ffffff0| |3| @59 +|t|h|e| |o+0&#ffff4012|n|e+0&#ffffff0| |1| @60 +|~+0#4040ff13&| @68 +|~| @68 +|~| @68 +|~| @68 +|~| @68 +|:+0#0000000&|s|o|r|t| |n|i| |u| |/|o|n> @55 diff --git a/src/testdir/dumps/Test_incsearch_substitute_01.dump b/src/testdir/dumps/Test_incsearch_substitute_01.dump new file mode 100644 index 0000000..63886f5 --- /dev/null +++ b/src/testdir/dumps/Test_incsearch_substitute_01.dump @@ -0,0 +1,9 @@ +|f+0&#ffffff0|o@1| |1| @64 +|f|o@1| |2| @64 +|f+1&&|o@1| +0&&|3| @64 +|f+0&#ffff4012|o@1| +0&#ffffff0|4| @64 +|f+0&#ffff4012|o@1| +0&#ffffff0|5| @64 +|f|o@1| |6| @64 +|f|o@1| |7| @64 +|f|o@1| |8| @64 +|:|.|,|.|+|2|s|/|f|o@1> @58 diff --git a/src/testdir/dumps/Test_incsearch_substitute_02.dump b/src/testdir/dumps/Test_incsearch_substitute_02.dump new file mode 100644 index 0000000..fd1f912 --- /dev/null +++ b/src/testdir/dumps/Test_incsearch_substitute_02.dump @@ -0,0 +1,9 @@ +|f+0&#ffffff0|o@1| |1| @64 +|f|o@1| |2| @64 +|f|o@1| |3| @64 +|f+1&&|o@1| +0&&|4| @64 +|f+0&#ffff4012|o@1| +0&#ffffff0|5| @64 +|f+0&#ffff4012|o@1| +0&#ffffff0|6| @64 +|f|o@1| |7| @64 +|f|o@1| |8| @64 +|:|.|,|.|+|2|s|/@1> @60 diff --git a/src/testdir/dumps/Test_incsearch_substitute_03.dump b/src/testdir/dumps/Test_incsearch_substitute_03.dump new file mode 100644 index 0000000..5d7afa0 --- /dev/null +++ b/src/testdir/dumps/Test_incsearch_substitute_03.dump @@ -0,0 +1,9 @@ +|f+0&#ffff4012|o@1| +0&#ffffff0|1| @64 +|f+0&#ffff4012|o@1| +0&#ffffff0|2| @64 +|f+0&#ffff4012|o@1| +0&#ffffff0|3| @64 +|f+0&#ffff4012|o@1| +0&#ffffff0|4| @64 +|f+0&#ffff4012|o@1| +0&#ffffff0|5| @64 +|f+0&#ffff4012|o@1| +0&#ffffff0|6| @64 +|f+0&#ffff4012|o@1| +0&#ffffff0|7| @64 +|f+0&#ffff4012|o@1| +0&#ffffff0|8| @64 +|:|.|,|.|+|2|s|/> @61 diff --git a/src/testdir/dumps/Test_incsearch_substitute_04.dump b/src/testdir/dumps/Test_incsearch_substitute_04.dump new file mode 100644 index 0000000..bae6c7b --- /dev/null +++ b/src/testdir/dumps/Test_incsearch_substitute_04.dump @@ -0,0 +1,9 @@ +|f+0&#ffffff0|o@1| |1| @64 +|f+1&&|o@1| +0&&|2| @64 +|f+0&#ffff4012|o@1| +0&#ffffff0|3| @64 +|f+0&#ffff4012|o@1| +0&#ffffff0|4| @64 +|f+0&#ffff4012|o@1| +0&#ffffff0|5| @64 +|f|o@1| |6| @64 +|f|o@1| |7| @64 +|f|o@1| |8| @64 +|:|5|,|2|s|/|f|o@1> @60 diff --git a/src/testdir/dumps/Test_incsearch_substitute_05.dump b/src/testdir/dumps/Test_incsearch_substitute_05.dump new file mode 100644 index 0000000..6ec8ea3 --- /dev/null +++ b/src/testdir/dumps/Test_incsearch_substitute_05.dump @@ -0,0 +1,9 @@ +|f+0&#ffffff0|o@1| |1| @64 +|f+1&&|o|o+0&&| |2| @64 +|f+0&#ffff4012|o|o+0&#ffffff0| |3| @64 +|f|o@1| |4| @64 +|f|o@1| |5| @64 +|f|o@1| |6| @64 +|f|o@1| |7| @64 +|f|o@1| |8| @64 +|:|2|,|3|s|u|b| @1|/|f|o> @57 diff --git a/src/testdir/dumps/Test_incsearch_substitute_06.dump b/src/testdir/dumps/Test_incsearch_substitute_06.dump new file mode 100644 index 0000000..8a66620 --- /dev/null +++ b/src/testdir/dumps/Test_incsearch_substitute_06.dump @@ -0,0 +1,9 @@ +|f+0&#ffffff0|o@1| |3| @64 +|f+1&&|o@1| +0&&|4| @64 +|f+0&#ffff4012|o@1| +0&#ffffff0|5| @64 +|f|o@1| |6| @64 +|f|o@1| |7| @64 +|f|o@1| |8| @64 +|:|a|b|o|v|e| |b|e|l|o|w| |b|r|o|w|s|e| |b|o|t|r| |c|o|n|f|i|r|m| |k|e@1|p|m|a|r| |k|e@1|p|a|l|t| |k|e@1|p@1|a|t| |k|e@1|p|j|u|m| |f|i|l|t|e +|r| |x@2| |h|i|d|e| |l|o|c|k|m| |l|e|f|t|a|b|o|v|e| |n|o|a|u| |n|o|s|w|a|p| |r|i|g|h|t|b|e|l| |s|a|n|d|b|o|x| |s|i|l|e|n|t| |s|i|l|e|n|t|! +| |$|t|a|b| |t|o|p| |u|n|s|i|l| |v|e|r|t| |v|e|r|b|o|s|e| |4|,|5|s|/|f|o|.> @32 diff --git a/src/testdir/dumps/Test_incsearch_substitute_07.dump b/src/testdir/dumps/Test_incsearch_substitute_07.dump new file mode 100644 index 0000000..7b4dc6e --- /dev/null +++ b/src/testdir/dumps/Test_incsearch_substitute_07.dump @@ -0,0 +1,9 @@ +|f+0&#ffffff0|o@1| |4| @64 +|f|o@1| |5| @64 +|f|o@1| |6| @64 +|f|o@1| |7| @64 +|f|o@1| |8| @64 +|f|o@1| |9| @64 +|f|o@1| |1|0| @63 +|b+9&&|a|r| +8&&|1@1| @63 +|:+0&&|9|,|1@1|s|/|b|a|r> @59 diff --git a/src/testdir/dumps/Test_incsearch_substitute_08.dump b/src/testdir/dumps/Test_incsearch_substitute_08.dump new file mode 100644 index 0000000..d87e507 --- /dev/null +++ b/src/testdir/dumps/Test_incsearch_substitute_08.dump @@ -0,0 +1,9 @@ +|f+0&#ffffff0|o@1| |4| @64 +|f|o@1| |5| @64 +|f|o@1| |6| @64 +|f|o@1| |7| @64 +|f|o@1| |8| @64 +|f+8&&|o@1| |9| @64 +|f+0&&|o@1| |1|0| @63 +|b|a|r| |1@1| @63 +|:|9|,|1|0|s|/|b|a|r> @59 diff --git a/src/testdir/dumps/Test_incsearch_substitute_09.dump b/src/testdir/dumps/Test_incsearch_substitute_09.dump new file mode 100644 index 0000000..633e7d8 --- /dev/null +++ b/src/testdir/dumps/Test_incsearch_substitute_09.dump @@ -0,0 +1,9 @@ +|f+0&#ffffff0|o@1| |3| @64 +|f+8&&|o@1| |4| @64 +|f+0&&|o@1| |5| @64 +|f|o@1| |6| @64 +|f|o@1| |7| @64 +|f|o@1| |8| @64 +|f|o@1| |9| @64 +|f|o@1| |1|0| @63 +|:|6|,|7|s|/|\|v> @61 diff --git a/src/testdir/dumps/Test_incsearch_substitute_10.dump b/src/testdir/dumps/Test_incsearch_substitute_10.dump new file mode 100644 index 0000000..f98e046 --- /dev/null +++ b/src/testdir/dumps/Test_incsearch_substitute_10.dump @@ -0,0 +1,9 @@ +|f+0&#ffff4012|o@1| +0&#ffffff0|1| @64 +>f+0&#ffff4012|o@1| +0&#ffffff0|2| @64 +|f+0&#ffff4012|o@1| +0&#ffffff0|3| @64 +|f+0&#ffff4012|o@1| +0&#ffffff0|4| @64 +|f+0&#ffff4012|o@1| +0&#ffffff0|5| @64 +|f+0&#ffff4012|o@1| +0&#ffffff0|6| @64 +|f+0&#ffff4012|o@1| +0&#ffffff0|7| @64 +|f+0&#ffff4012|o@1| +0&#ffffff0|8| @64 +@52|2|,|1| @10|T|o|p| diff --git a/src/testdir/dumps/Test_incsearch_substitute_11.dump b/src/testdir/dumps/Test_incsearch_substitute_11.dump new file mode 100644 index 0000000..0ec409f --- /dev/null +++ b/src/testdir/dumps/Test_incsearch_substitute_11.dump @@ -0,0 +1,9 @@ +|f+1&#ffffff0|o+0&#ffff4012@1| |1| +0&#ffffff0@64 +|f+0&#ffff4012|o@1| |2| +0&#ffffff0@64 +|f+0&#ffff4012|o@1| |3| +0&#ffffff0@64 +|[+3&&|N|o| |N|a|m|e|]| |[|+|]| @38|1|,|1| @11|T|o|p +|f+0&#ffff4012|o@1| |1| +0&#ffffff0@64 +|f+0&#ffff4012|o@1| |2| +0&#ffffff0@64 +|f+0&#ffff4012|o@1| |3| +0&#ffffff0@64 +|[+1&&|N|o| |N|a|m|e|]| |[|+|]| @38|2|,|1| @11|T|o|p +|:+0&&|%|s|/|.> @64 diff --git a/src/testdir/dumps/Test_incsearch_substitute_12.dump b/src/testdir/dumps/Test_incsearch_substitute_12.dump new file mode 100644 index 0000000..02b7335 --- /dev/null +++ b/src/testdir/dumps/Test_incsearch_substitute_12.dump @@ -0,0 +1,9 @@ +|f+0&#ffffff0|o@1| |1| @64 +|f|o@1| |2| @64 +|f|o@1| |3| @64 +|[+3&&|N|o| |N|a|m|e|]| |[|+|]| @38|1|,|1| @11|T|o|p +|f+0&&|o@1| |1| @64 +|f|o@1| |2| @64 +|f|o@1| |3| @64 +|[+1&&|N|o| |N|a|m|e|]| |[|+|]| @38|2|,|1| @11|T|o|p +|:+0&&|%|s|/> @65 diff --git a/src/testdir/dumps/Test_incsearch_substitute_13.dump b/src/testdir/dumps/Test_incsearch_substitute_13.dump new file mode 100644 index 0000000..be3abb7 --- /dev/null +++ b/src/testdir/dumps/Test_incsearch_substitute_13.dump @@ -0,0 +1,9 @@ +|f+0&#ffffff0|o@1| |1| @64 +>f|o@1| |2| @64 +|f|o@1| |3| @64 +|[+3&&|N|o| |N|a|m|e|]| |[|+|]| @38|2|,|1| @11|T|o|p +|f+0&&|o@1| |1| @64 +|f|o@1| |2| @64 +|f|o@1| |3| @64 +|[+1&&|N|o| |N|a|m|e|]| |[|+|]| @38|2|,|1| @11|T|o|p +| +0&&@69 diff --git a/src/testdir/dumps/Test_incsearch_vimgrep_01.dump b/src/testdir/dumps/Test_incsearch_vimgrep_01.dump new file mode 100644 index 0000000..955d030 --- /dev/null +++ b/src/testdir/dumps/Test_incsearch_vimgrep_01.dump @@ -0,0 +1,9 @@ +|a+0&#ffffff0|n|o|t|h|e|r| |o+1&&|n|e+0&&| |2| @56 +|t|h|a|t| |o+0&#ffff4012|n|e+0&#ffffff0| |3| @59 +|t|h|e| |o+0&#ffff4012|n|e+0&#ffffff0| |1| @60 +|~+0#4040ff13&| @68 +|~| @68 +|~| @68 +|~| @68 +|~| @68 +|:+0#0000000&|v|i|m|g|r|e|p| |o|n> @58 diff --git a/src/testdir/dumps/Test_incsearch_vimgrep_02.dump b/src/testdir/dumps/Test_incsearch_vimgrep_02.dump new file mode 100644 index 0000000..a5d94ea --- /dev/null +++ b/src/testdir/dumps/Test_incsearch_vimgrep_02.dump @@ -0,0 +1,9 @@ +|a+0&#ffffff0|n|o|t|h|e|r| |o+1&&|n|e+0&&| |2| @56 +|t|h|a|t| |o+0&#ffff4012|n|e+0&#ffffff0| |3| @59 +|t|h|e| |o+0&#ffff4012|n|e+0&#ffffff0| |1| @60 +|~+0#4040ff13&| @68 +|~| @68 +|~| @68 +|~| @68 +|~| @68 +|:+0#0000000&|v|i|m|g| |/|o|n|/| |*|.|t|x|t> @53 diff --git a/src/testdir/dumps/Test_incsearch_vimgrep_03.dump b/src/testdir/dumps/Test_incsearch_vimgrep_03.dump new file mode 100644 index 0000000..038ceb9 --- /dev/null +++ b/src/testdir/dumps/Test_incsearch_vimgrep_03.dump @@ -0,0 +1,9 @@ +|a+0&#ffffff0|n|o|t|h|e|r| |o+1&&|n|e+0&&| |2| @56 +|t|h|a|t| |o+0&#ffff4012|n|e+0&#ffffff0| |3| @59 +|t|h|e| |o+0&#ffff4012|n|e+0&#ffffff0| |1| @60 +|~+0#4040ff13&| @68 +|~| @68 +|~| @68 +|~| @68 +|~| @68 +|:+0#0000000&|v|i|m|g|r|e|p|a|d@1| |"|\|<|o|n> @52 diff --git a/src/testdir/dumps/Test_incsearch_vimgrep_04.dump b/src/testdir/dumps/Test_incsearch_vimgrep_04.dump new file mode 100644 index 0000000..92dd78d --- /dev/null +++ b/src/testdir/dumps/Test_incsearch_vimgrep_04.dump @@ -0,0 +1,9 @@ +|a+0&#ffffff0|n|o|t|h|e|r| |o|n|e| |2| @56 +|t+1&&|h|a|t+0&&| |o|n|e| |3| @59 +|t|h|e| |o|n|e| |1| @60 +|~+0#4040ff13&| @68 +|~| @68 +|~| @68 +|~| @68 +|~| @68 +|:+0#0000000&|l|v| |"|t|h|a> @61 diff --git a/src/testdir/dumps/Test_incsearch_vimgrep_05.dump b/src/testdir/dumps/Test_incsearch_vimgrep_05.dump new file mode 100644 index 0000000..e11ff57 --- /dev/null +++ b/src/testdir/dumps/Test_incsearch_vimgrep_05.dump @@ -0,0 +1,9 @@ +|a+0&#ffffff0|n|o|t+1&&|h|e|r+0&&| |o|n|e| |2| @56 +|t|h|a|t| |o|n|e| |3| @59 +|t+0&#ffff4012|h|e| +0&#ffffff0|o|n|e| |1| @60 +|~+0#4040ff13&| @68 +|~| @68 +|~| @68 +|~| @68 +|~| @68 +|:+0#0000000&|l|v|i|m|g|r|e|p|a| |"|t|h|e|"| |*@1|/|*|.|t|x|t> @44 diff --git a/src/testdir/dumps/Test_popup_and_previewwindow_01.dump b/src/testdir/dumps/Test_popup_and_previewwindow_01.dump new file mode 100644 index 0000000..71ff399 --- /dev/null +++ b/src/testdir/dumps/Test_popup_and_previewwindow_01.dump @@ -0,0 +1,20 @@ +|a+0&#ffffff0|b|0| @71 +|a|b|1| @71 +|a|b|2| @71 +|a|b|3| @71 +|a|b|4| @71 +|a|b|5| @71 +|a|b|6| @71 +|a|b|7| @71 +|a|b|8| @71 +|a+0#0000001#e0e0e08|b|0| @11| +0#0000000#0000001|e+1&#ffffff0|w|]|[|+|]| @34|1|,|1| @11|T|o|p +|a+0#0000001#ffd7ff255|b|1| @11| +0#0000000#0000001| +0&#ffffff0@58 +|a+0#0000001#ffd7ff255|b|2| @11| +0#0000000#0000001| +0&#ffffff0@58 +|a+0#0000001#ffd7ff255|b|3| @11| +0#0000000#0000001| +0&#ffffff0@58 +|a+0#0000001#ffd7ff255|b|4| @11| +0#0000000#a8a8a8255| +0&#ffffff0@58 +|a+0#0000001#ffd7ff255|b|5| @11| +0#0000000#a8a8a8255| +0&#ffffff0@58 +|a+0#0000001#ffd7ff255|b|6| @11| +0#0000000#a8a8a8255| +0&#ffffff0@58 +|a|b|0> @71 +|~+0#4040ff13&| @73 +|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|1|0|,|1| @10|B|o|t +|-+2&&@1| |K|e|y|w|o|r|d| |L|o|c|a|l| |c|o|m|p|l|e|t|i|o|n| |(|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |1| |o|f| |1|0| +0#0000000&@26 diff --git a/src/testdir/dumps/Test_popup_command_01.dump b/src/testdir/dumps/Test_popup_command_01.dump new file mode 100644 index 0000000..8d0cd9c --- /dev/null +++ b/src/testdir/dumps/Test_popup_command_01.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |t|w|o| |t|h|r|e@1| |f|o|u|r| |f|i|v|e| @51 +|a|n|d| |o|n|e| |t|w|o| >X|t|h|r|e@1| |f|o|u|r| |f|i|v|e| @46 +|o|n|e| |m|o|r|e| |t|w| +0#0000001#ffd7ff255|U|n|d|o| @12| +0#0000000#ffffff0@45 +|~+0#4040ff13&| @9| +0#0000001#ffd7ff255@17| +0#4040ff13#ffffff0@45 +|~| @9| +0#0000001#ffd7ff255|P|a|s|t|e| @11| +0#4040ff13#ffffff0@45 +|~| @9| +0#0000001#ffd7ff255@17| +0#4040ff13#ffffff0@45 +|~| @9| +0#0000001#ffd7ff255|S|e|l|e|c|t| |W|o|r|d| @5| +0#4040ff13#ffffff0@45 +|~| @9| +0#0000001#ffd7ff255|S|e|l|e|c|t| |S|e|n|t|e|n|c|e| @1| +0#4040ff13#ffffff0@45 +|~| @9| +0#0000001#ffd7ff255|S|e|l|e|c|t| |P|a|r|a|g|r|a|p|h| | +0#4040ff13#ffffff0@45 +|~| @9| +0#0000001#ffd7ff255|S|e|l|e|c|t| |L|i|n|e| @5| +0#4040ff13#ffffff0@45 +|~| @9| +0#0000001#ffd7ff255|S|e|l|e|c|t| |B|l|o|c|k| @4| +0#4040ff13#ffffff0@45 +|~| @9| +0#0000001#ffd7ff255|S|e|l|e|c|t| |A|l@1| @6| +0#4040ff13#ffffff0@45 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|:+0#0000000&|p|o|p|u|p| |P|o|p|U|p| @62 diff --git a/src/testdir/dumps/Test_popup_command_02.dump b/src/testdir/dumps/Test_popup_command_02.dump new file mode 100644 index 0000000..e33ea4d --- /dev/null +++ b/src/testdir/dumps/Test_popup_command_02.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |t|w|o| |t|h|r|e@1| |f|o|u|r| |f|i|v|e| @51 +|a|n|d| |o|n|e| |t|w|o| >X|t|h|r|e@1| |f|o|u|r| |f|i|v|e| @46 +|o|n|e| |m|o|r|e| |t|w| +0#0000001#ffd7ff255|U|n|d|o| @12| +0#0000000#ffffff0@45 +|~+0#4040ff13&| @9| +0#0000001#ffd7ff255@17| +0#4040ff13#ffffff0@45 +|~| @9| +0#0000001#e0e0e08|P|a|s|t|e| @11| +0#4040ff13#ffffff0@45 +|~| @9| +0#0000001#ffd7ff255@17| +0#4040ff13#ffffff0@45 +|~| @9| +0#0000001#ffd7ff255|S|e|l|e|c|t| |W|o|r|d| @5| +0#4040ff13#ffffff0@45 +|~| @9| +0#0000001#ffd7ff255|S|e|l|e|c|t| |S|e|n|t|e|n|c|e| @1| +0#4040ff13#ffffff0@45 +|~| @9| +0#0000001#ffd7ff255|S|e|l|e|c|t| |P|a|r|a|g|r|a|p|h| | +0#4040ff13#ffffff0@45 +|~| @9| +0#0000001#ffd7ff255|S|e|l|e|c|t| |L|i|n|e| @5| +0#4040ff13#ffffff0@45 +|~| @9| +0#0000001#ffd7ff255|S|e|l|e|c|t| |B|l|o|c|k| @4| +0#4040ff13#ffffff0@45 +|~| @9| +0#0000001#ffd7ff255|S|e|l|e|c|t| |A|l@1| @6| +0#4040ff13#ffffff0@45 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|:+0#0000000&|p|o|p|u|p| |P|o|p|U|p| @62 diff --git a/src/testdir/dumps/Test_popup_command_03.dump b/src/testdir/dumps/Test_popup_command_03.dump new file mode 100644 index 0000000..fa2ac70 --- /dev/null +++ b/src/testdir/dumps/Test_popup_command_03.dump @@ -0,0 +1,20 @@ +|o+0&#ffffff0|n|e| |t|w|o| |t|h|r|e@1| |f|o|u|r| |f|i|v|e| @51 +|a|n|d| |o|n|e| |t|w|o| |X+0&#e0e0e08|t|h|r|e@1> +0&#ffffff0|f|o|u|r| |f|i|v|e| @46 +|o|n|e| |m|o|r|e| |t|w|o| |t|h|r|e@1| |f|o|u|r| |f|i|v|e| @46 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|~| @73 +|-+2#0000000&@1| |V|I|S|U|A|L| |-@1| +0&&@34|7| @8|2|,|1|9| @9|A|l@1| diff --git a/src/testdir/dumps/Test_popup_position_01.dump b/src/testdir/dumps/Test_popup_position_01.dump new file mode 100644 index 0000000..43900fb --- /dev/null +++ b/src/testdir/dumps/Test_popup_position_01.dump @@ -0,0 +1,8 @@ +|1+0&#ffffff0|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|a| @5||+1&&|1+0&&|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|a| @5 +|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|b| @5||+1&&|1+0&&|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|b| @5 +@12|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5||+1&&| +0&&@11|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5 +|6|7|8|9|_|a> @30||+1&&|6+0&&|7|8|9|_|a| @30 +|~+0#4040ff13&| @9| +0#0000001#e0e0e08|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|a| | +0#4040ff13#ffffff0@30 +|~| @9| +0#0000001#ffd7ff255|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|b| | +0#4040ff13#ffffff0@30 +|~| @35||+1#0000000&|~+0#4040ff13&| @35 +|~| @35||+1#0000000&|~+0#4040ff13&| @35 diff --git a/src/testdir/dumps/Test_popup_position_02.dump b/src/testdir/dumps/Test_popup_position_02.dump new file mode 100644 index 0000000..c3613c3 --- /dev/null +++ b/src/testdir/dumps/Test_popup_position_02.dump @@ -0,0 +1,8 @@ +|1+0&#ffffff0|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|a| @5||+1&&|1+0&&|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|a| @5 +|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|b| @5||+1&&|1+0&&|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|b| @5 +@12|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5||+1&&| +0&&@11|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5 +|6|7|8|9|_|a| @30||+1&&|6+0&&|7|8|9|_|a> @30 +|~+0#4040ff13&| @35||+1#0000000&|~+0#4040ff13&| @9| +0#0000001#e0e0e08|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5 +|~+0#4040ff13#ffffff0| @35||+1#0000000&|~+0#4040ff13&| @9| +0#0000001#ffd7ff255|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5 +|~+0#4040ff13#ffffff0| @35||+1#0000000&|~+0#4040ff13&| @35 +|~| @35||+1#0000000&|~+0#4040ff13&| @35 diff --git a/src/testdir/dumps/Test_popup_position_03.dump b/src/testdir/dumps/Test_popup_position_03.dump new file mode 100644 index 0000000..650cb7f --- /dev/null +++ b/src/testdir/dumps/Test_popup_position_03.dump @@ -0,0 +1,8 @@ +|1+0&#ffffff0|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|a| @5||+1&&|1+0&&|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|a| @5 +|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|b| @5||+1&&|1+0&&|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|b| @5 +@12|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5||+1&&| +0&&@11|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5 +|6|7|8|9|_|a| @30||+1&&|6+0&&|7|8|9|_|a> @30 +|~+0#4040ff13&| @35||+1#0000000&|~+0#4040ff13&| @4| +0#0000001#e0e0e08|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_ +|~+0#4040ff13#ffffff0| @35||+1#0000000&|~+0#4040ff13&| @4| +0#0000001#ffd7ff255|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_ +|~+0#4040ff13#ffffff0| @35||+1#0000000&|~+0#4040ff13&| @35 +|~| @35||+1#0000000&|~+0#4040ff13&| @35 diff --git a/src/testdir/dumps/Test_popup_position_04.dump b/src/testdir/dumps/Test_popup_position_04.dump new file mode 100644 index 0000000..1793b23 --- /dev/null +++ b/src/testdir/dumps/Test_popup_position_04.dump @@ -0,0 +1,10 @@ +|1+0&#ffffff0|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7||+1&&|1+0&&|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7 +|8|9|_|a| @32||+1&&|8+0&&|9|_|a| @32 +|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7||+1&&|1+0&&|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7 +|8|9|_|b| @32||+1&&|8+0&&|9|_|b| @32 +@12|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5||+1&&| +0&&@11|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5 +|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|a| @20||+1&&|6+0&&|7|8|9|_|1|2|3|4|5|6|7|8|9|_|a> @20 +|~+0#4040ff13&| @35||+1#0000000&|~+0#4040ff13&| @9| +0#0000001#e0e0e08|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5 +|~+0#4040ff13#ffffff0| @35||+1#0000000&|~+0#4040ff13&| @9| +0#0000001#ffd7ff255|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5|6|7|8|9|_|1|2|3|4|5 +|~+0#4040ff13#ffffff0| @35||+1#0000000&|~+0#4040ff13&| @35 +|~| @35||+1#0000000&|~+0#4040ff13&| @35 diff --git a/src/testdir/dumps/Test_syntax_c_01.dump b/src/testdir/dumps/Test_syntax_c_01.dump new file mode 100644 index 0000000..2fea5d6 --- /dev/null +++ b/src/testdir/dumps/Test_syntax_c_01.dump @@ -0,0 +1,20 @@ +>/+0#0000e05#ffffff0|*| |c|o|m@1|e|n|t| |l|i|n|e| |a|t| |t|h|e| |t|o|p| |*|/| +0#0000000&@45 +@2|i+0#00e0003&|n|t| +0#0000000&@69 +|m|a|i|n|(|i+0#00e0003&|n|t| +0#0000000&|a|r|g|c|,| |c+0#00e0003&|h|a|r| +0#0000000&|*@1|a|r|g|v|)|/+0#0000e05&@1| |a|n|o|t|h|e|r| |c|o|m@1|e|n|t| +0#0000000&@29 +|{| @73 +|#+0#e000e06&|i|f| |0| +0#0000000&@69 +| +0#0000e05&@2|i|n|t| @2|n|o|t|_|u|s|e|d|;| +0#0000000&@56 +|#+0#e000e06&|e|l|s|e| +0#0000000&@69 +@3|i+0#00e0003&|n|t| +0#0000000&@2|u|s|e|d|;| @60 +|#+0#e000e06&|e|n|d|i|f| +0#0000000&@68 +@3|p|r|i|n|t|f|(|"+0#e000002&|J|u|s|t| |a|n| |e|x|a|m|p|l|e| |p|i|e|c|e| |o|f| |C| |c|o|d|e|\+0#e000e06&|n|"+0#e000002&|)+0#0000000&|;| @27 +@3|r+0#af5f00255&|e|t|u|r|n| +0#0000000&|0+0#e000002&|x|0|f@1|;+0#0000000&| @58 +|}| @73 +@3|s+0#00e0003&|t|a|t|i|c| +0#0000000&|v+0#00e0003&|o|i|d| +0#0000000&@60 +|m|y|F|u|n|c|t|i|o|n|(|c+0#00e0003&|o|n|s|t| +0#0000000&|d+0#00e0003&|o|u|b|l|e| +0#0000000&|c|o|u|n|t|,| |s+0#00e0003&|t|r|u|c|t| +0#0000000&|n|o|t|h|i|n|g|,| |l+0#00e0003&|o|n|g| +0#0000000&|t|h|e|r|e|)| |{| @14 +@2|/+0#0000e05&@1| |1+0#e000002&|2|3|:+0#0000e05&| |n|o|t|h|i|n|g| |t|o| |r|e|a|d| |h|e|r|e| +0#0000000&@44 +@2|f+0#af5f00255&|o|r| +0#0000000&|(|i+0#00e0003&|n|t| +0#0000000&|i| |=| |0+0#e000002&|;+0#0000000&| |i| |<| |c|o|u|n|t|;| |+@1|i|)| |{| @39 +@4|b+0#af5f00255&|r|e|a|k|;+0#0000000&| @64 +@2|}| @71 +|}| @73 +|"|X|t|e|s|t|.|c|"| |1|9|L|,| |3|6|4|C| @37|1|,|1| @10|A|l@1| diff --git a/src/testdir/dumps/Test_tenc_euc_jp_01.dump b/src/testdir/dumps/Test_tenc_euc_jp_01.dump new file mode 100644 index 0000000..14a4313 --- /dev/null +++ b/src/testdir/dumps/Test_tenc_euc_jp_01.dump @@ -0,0 +1,10 @@ +>E+0&#ffffff0|8|9|:| |バ*&|ッ|フ|ァ| +&|%|l|d| |の*&|変|更|は|保|存|さ|れ|て|い|ま|せ|ん| +&|(|!| |で*&|変|更|を|破|棄|)+&| @13 +|~+0#4040ff13&| @73 +|~| @73 +|~| @73 +|X+3#0000000&|e|u|c|_|j|p|.|t|x|t| @45|1|,|1| @11|A|l@1 +|E+0&&|8|3|:| |バ*&|ッ|フ|ァ|を|作|成|で|き|な|い|の|で|、|他|の|を|使|用|し|ま|す|.+&@2| @22 +|~+0#4040ff13&| @73 +|~| @73 +|[+1#0000000&|N|o| |N|a|m|e|]| |[|+|]| @43|1|,|5|2| @10|A|l@1 +| +0&&@74 diff --git a/src/testdir/dumps/Test_textprop_01.dump b/src/testdir/dumps/Test_textprop_01.dump new file mode 100644 index 0000000..8687a0a --- /dev/null +++ b/src/testdir/dumps/Test_textprop_01.dump @@ -0,0 +1,6 @@ +| +0#af5f00255#ffffff0@1|1| |O+0#0000000&|n|e| +0&#ffff4012|t|w|o| +0&#ffffff0@63 +| +0#af5f00255&@1|2| |N+0#0000000#ffff4012|u|m|b|é|r| |1+0#4040ff13&|2|3| +0#0000000&|ä|n|d| |t|h|œ|n| |4+0#4040ff13&|¾|7|.+0#0000000&| +0&#ffffff0@46 +| +0#af5f00255&@1|3| >-+0#0000000#ffff4012|x+0&#ffffff0|a+0#4040ff13&@1|x+0#0000000&|-@1|x+0#4040ff13&|b@1|x+0#0000000&|-@1|x|c+0#4040ff13&@1|x|-+0#0000000&@1|x+0#4040ff13&|d@1|x|-+0#0000000&@1| @45 +|~+0#4040ff13&| @73 +|~| @73 +| +0#0000000&@56|3|,|1| @10|A|l@1| diff --git a/src/testdir/gen_opt_test.vim b/src/testdir/gen_opt_test.vim new file mode 100644 index 0000000..8c75d37 --- /dev/null +++ b/src/testdir/gen_opt_test.vim @@ -0,0 +1,226 @@ +" Script to generate testdir/opt_test.vim from option.c + +set cpo=&vim + +" Only do this when build with the +eval feature. +if 1 + +set nomore + +" The terminal size is restored at the end. +" Clear out t_WS, we don't want to resize the actual terminal. +let script = [ + \ 'let save_columns = &columns', + \ 'let save_lines = &lines', + \ 'let save_term = &term', + \ 'set t_WS=', + \ ] + +/#define p_term +let end = line('.') + +" font name that works everywhere (hopefully) +let fontname = has('win32') ? 'fixedsys' : 'fixed' + +" Two lists with values: values that work and values that fail. +" When not listed, "othernum" or "otherstring" is used. +let test_values = { + \ 'cmdheight': [[1, 2, 10], [-1, 0]], + \ 'cmdwinheight': [[1, 2, 10], [-1, 0]], + \ 'columns': [[12, 80], [-1, 0, 10]], + \ 'conceallevel': [[0, 1, 2, 3], [-1, 4, 99]], + \ 'foldcolumn': [[0, 1, 4, 12], [-1, 13, 999]], + \ 'helpheight': [[0, 10, 100], [-1]], + \ 'history': [[0, 1, 100], [-1, 10001]], + \ 'iminsert': [[0, 1], [-1, 3, 999]], + \ 'imsearch': [[-1, 0, 1], [-2, 3, 999]], + \ 'imstyle': [[0, 1], [-1, 2, 999]], + \ 'lines': [[2, 24], [-1, 0, 1]], + \ 'linespace': [[0, 2, 4], ['']], + \ 'numberwidth': [[1, 4, 8, 10], [-1, 0, 11]], + \ 'regexpengine': [[0, 1, 2], [-1, 3, 999]], + \ 'report': [[0, 1, 2, 9999], [-1]], + \ 'scroll': [[0, 1, 2, 20], [-1]], + \ 'scrolljump': [[-50, -1, 0, 1, 2, 20], [999]], + \ 'scrolloff': [[0, 1, 2, 20], [-1]], + \ 'shiftwidth': [[0, 1, 8, 999], [-1]], + \ 'sidescroll': [[0, 1, 8, 999], [-1]], + \ 'sidescrolloff': [[0, 1, 8, 999], [-1]], + \ 'tabstop': [[1, 4, 8, 12], [-1, 0]], + \ 'textwidth': [[0, 1, 8, 99], [-1]], + \ 'timeoutlen': [[0, 8, 99999], [-1]], + \ 'titlelen': [[0, 1, 8, 9999], [-1]], + \ 'updatecount': [[0, 1, 8, 9999], [-1]], + \ 'updatetime': [[0, 1, 8, 9999], [-1]], + \ 'verbose': [[-1, 0, 1, 8, 9999], []], + \ 'wildcharm': [[-1, 0, 100], []], + \ 'winheight': [[1, 10, 999], [-1, 0]], + \ 'winminheight': [[0, 1], [-1]], + \ 'winminwidth': [[0, 1, 10], [-1]], + \ 'winwidth': [[1, 10, 999], [-1, 0]], + \ + \ 'ambiwidth': [['', 'single'], ['xxx']], + \ 'background': [['', 'light', 'dark'], ['xxx']], + \ 'backspace': [[0, 2, '', 'eol', 'eol,start'], ['xxx']], + \ 'backupcopy': [['yes', 'auto'], ['', 'xxx', 'yes,no']], + \ 'backupext': [['xxx'], ['']], + \ 'belloff': [['', 'all', 'copy,error'], ['xxx']], + \ 'breakindentopt': [['', 'min:3', 'sbr'], ['xxx', 'min', 'min:x']], + \ 'browsedir': [['', 'last', '/'], ['xxx']], + \ 'bufhidden': [['', 'hide', 'wipe'], ['xxx', 'hide,wipe']], + \ 'buftype': [['', 'help', 'nofile'], ['xxx', 'help,nofile']], + \ 'casemap': [['', 'internal'], ['xxx']], + \ 'cedit': [['', '\<Esc>'], ['xxx', 'f']], + \ 'clipboard': [['', 'unnamed', 'autoselect,unnamed'], ['xxx']], + \ 'colorcolumn': [['', '8', '+2'], ['xxx']], + \ 'comments': [['', 'b:#'], ['xxx']], + \ 'commentstring': [['', '/*%s*/'], ['xxx']], + \ 'complete': [['', 'w,b'], ['xxx']], + \ 'concealcursor': [['', 'n', 'nvic'], ['xxx']], + \ 'completeopt': [['', 'menu', 'menu,longest'], ['xxx', 'menu,,,longest,']], + \ 'cryptmethod': [['', 'zip'], ['xxx']], + \ 'cscopequickfix': [['', 's-', 's-,c+,e0'], ['xxx', 's,g,d']], + \ 'debug': [['', 'msg', 'msg', 'beep'], ['xxx']], + \ 'diffopt': [['', 'filler', 'icase,iwhite'], ['xxx', 'algorithm:xxx', 'algorithm:']], + \ 'display': [['', 'lastline', 'lastline,uhex'], ['xxx']], + \ 'eadirection': [['', 'both', 'ver'], ['xxx', 'ver,hor']], + \ 'encoding': [['latin1'], ['xxx', '']], + \ 'eventignore': [['', 'WinEnter', 'WinLeave,winenter'], ['xxx']], + \ 'fileencoding': [['', 'latin1', 'xxx'], []], + \ 'fileformat': [['', 'dos', 'unix'], ['xxx']], + \ 'fileformats': [['', 'dos', 'dos,unix'], ['xxx']], + \ 'fillchars': [['', 'vert:x'], ['xxx']], + \ 'foldclose': [['', 'all'], ['xxx']], + \ 'foldmethod': [['manual', 'indent'], ['', 'xxx', 'expr,diff']], + \ 'foldopen': [['', 'all', 'hor,jump'], ['xxx']], + \ 'foldmarker': [['((,))'], ['', 'xxx']], + \ 'formatoptions': [['', 'vt', 'v,t'], ['xxx']], + \ 'guicursor': [['', 'n:block-Cursor'], ['xxx']], + \ 'guifont': [['', fontname], []], + \ 'guifontwide': [['', fontname], []], + \ 'guifontset': [['', fontname], []], + \ 'helplang': [['', 'de', 'de,it'], ['xxx']], + \ 'highlight': [['', 'e:Error'], ['xxx']], + \ 'imactivatekey': [['', 'S-space'], ['xxx']], + \ 'isfname': [['', '@', '@,48-52'], ['xxx', '@48']], + \ 'isident': [['', '@', '@,48-52'], ['xxx', '@48']], + \ 'iskeyword': [['', '@', '@,48-52'], ['xxx', '@48']], + \ 'isprint': [['', '@', '@,48-52'], ['xxx', '@48']], + \ 'keymap': [['', 'accents'], ['xxx']], + \ 'keymodel': [['', 'startsel', 'startsel,stopsel'], ['xxx']], + \ 'langmap': [['', 'xX', 'aA,bB'], ['xxx']], + \ 'listchars': [['', 'eol:x', 'eol:x,space:y'], ['xxx']], + \ 'matchpairs': [['', '(:)', '(:),<:>'], ['xxx']], + \ 'mkspellmem': [['10000,100,12'], ['', 'xxx']], + \ 'mouse': [['', 'a', 'nvi'], ['xxx', 'n,v,i']], + \ 'mousemodel': [['', 'popup'], ['xxx']], + \ 'mouseshape': [['', 'n:arrow'], ['xxx']], + \ 'nrformats': [['', 'alpha', 'alpha,hex,bin'], ['xxx']], + \ 'printmbfont': [['', 'r:some', 'b:Bold,c:yes'], ['xxx']], + \ 'printoptions': [['', 'header:0', 'left:10pc,top:5pc'], ['xxx']], + \ 'scrollopt': [['', 'ver', 'ver,hor'], ['xxx']], + \ 'renderoptions': [['', 'type:directx'], ['xxx']], + \ 'selection': [['old', 'inclusive'], ['', 'xxx']], + \ 'selectmode': [['', 'mouse', 'key,cmd'], ['xxx']], + \ 'sessionoptions': [['', 'blank', 'help,options,slash'], ['xxx']], + \ 'signcolumn': [['', 'auto', 'no'], ['xxx', 'no,yes']], + \ 'spellfile': [['', 'file.en.add'], ['xxx', '/tmp/file']], + \ 'spellsuggest': [['', 'best', 'double,33'], ['xxx']], + \ 'switchbuf': [['', 'useopen', 'split,newtab'], ['xxx']], + \ 'tagcase': [['smart', 'match'], ['', 'xxx', 'smart,match']], + \ 'term': [[], []], + \ 'termguicolors': [[], []], + \ 'termencoding': [has('gui_gtk') ? [] : ['', 'utf-8'], ['xxx']], + \ 'termmode': [['', 'winpty', 'conpty'], ['xxx']], + \ 'termwinsize': [['', '24x80', '0x80', '32x0', '0x0'], ['xxx', '80', '8ax9', '24x80b']], + \ 'toolbar': [['', 'icons', 'text'], ['xxx']], + \ 'toolbariconsize': [['', 'tiny', 'huge'], ['xxx']], + \ 'ttymouse': [['', 'xterm'], ['xxx']], + \ 'ttytype': [[], []], + \ 'varsofttabstop': [['8', '4,8,16,32'], ['xxx', '-1', '4,-1,20']], + \ 'vartabstop': [['8', '4,8,16,32'], ['xxx', '-1', '4,-1,20']], + \ 'viewoptions': [['', 'cursor', 'unix,slash'], ['xxx']], + \ 'viminfo': [['', '''50', '"30'], ['xxx']], + \ 'virtualedit': [['', 'all', 'all,block'], ['xxx']], + \ 'whichwrap': [['', 'b,s', 'bs'], ['xxx']], + \ 'wildmode': [['', 'full', 'list:full', 'full,longest'], ['xxx']], + \ 'wildoptions': [['', 'tagfile'], ['xxx']], + \ 'winaltkeys': [['menu', 'no'], ['', 'xxx']], + \ + \ 'luadll': [[], []], + \ 'perldll': [[], []], + \ 'pythondll': [[], []], + \ 'pythonthreedll': [[], []], + \ 'pyxversion': [[], []], + \ 'rubydll': [[], []], + \ 'tcldll': [[], []], + \ + \ 'othernum': [[-1, 0, 100], ['']], + \ 'otherstring': [['', 'xxx'], []], + \} + +1 +/struct vimoption options +while 1 + /{" + if line('.') > end + break + endif + let line = getline('.') + let name = substitute(line, '.*{"\([^"]*\)".*', '\1', '') + let shortname = substitute(line, '.*"\([^"]*\)".*', '\1', '') + + if has_key(test_values, name) + let a = test_values[name] + elseif line =~ 'P_NUM' + let a = test_values['othernum'] + else + let a = test_values['otherstring'] + endif + if len(a[0]) > 0 || len(a[1]) > 0 + if line =~ 'P_BOOL' + call add(script, 'set ' . name) + call add(script, 'set ' . shortname) + call add(script, 'set no' . name) + call add(script, 'set no' . shortname) + else + for val in a[0] + call add(script, 'set ' . name . '=' . val) + call add(script, 'set ' . shortname . '=' . val) + endfor + + " setting an option can only fail when it's implemented. + call add(script, "if exists('+" . name . "')") + for val in a[1] + call add(script, "call assert_fails('set " . name . "=" . val . "')") + call add(script, "call assert_fails('set " . shortname . "=" . val . "')") + endfor + call add(script, "endif") + endif + + " cannot change 'termencoding' in GTK + if name != 'termencoding' || !has('gui_gtk') + call add(script, 'set ' . name . '&') + call add(script, 'set ' . shortname . '&') + endif + if name == 'verbosefile' + call add(script, 'call delete("xxx")') + endif + + if name == 'more' + call add(script, 'set nomore') + elseif name == 'lines' + call add(script, 'let &lines = save_lines') + endif + endif +endwhile + +call add(script, 'let &term = save_term') +call add(script, 'let &columns = save_columns') +call add(script, 'let &lines = save_lines') + +call writefile(script, 'opt_test.vim') + +endif + +qa! diff --git a/src/testdir/gui_init.vim b/src/testdir/gui_init.vim new file mode 100644 index 0000000..42b2bca --- /dev/null +++ b/src/testdir/gui_init.vim @@ -0,0 +1,6 @@ +" gvimrc for test_gui_init.vim + +if has('gui_athena') || has('gui_motif') || has('gui_gtk2') || has('gui_gtk3') + set guiheadroom=0 + set guioptions+=p +endif diff --git a/src/testdir/gui_preinit.vim b/src/testdir/gui_preinit.vim new file mode 100644 index 0000000..c351b72 --- /dev/null +++ b/src/testdir/gui_preinit.vim @@ -0,0 +1,7 @@ +" vimrc for test_gui_init.vim + +" Note that this flag must be added in the .vimrc file, before switching on +" syntax or filetype recognition (when the |gvimrc| file is sourced the system +" menu has already been loaded; the ":syntax on" and ":filetype on" commands +" load the menu too). +set guioptions+=M diff --git a/src/testdir/if_ver-1.vim b/src/testdir/if_ver-1.vim new file mode 100644 index 0000000..3c94c9e --- /dev/null +++ b/src/testdir/if_ver-1.vim @@ -0,0 +1,26 @@ +" Print all interface versions and write the result into if_ver.txt. +" For Ubuntu. Part 1. + +redir! > if_ver.txt +if 1 + echo "*** Interface versions ***" + echo "\nLua:" + lua print(_VERSION) + " echo "\nLuaJIT:" + " lua print(jit.version) + if has('mzscheme') + echo "\nMzScheme:" + mzscheme (display (version)) + endif + echo "\nPerl:" + perl print $^V + echo "\nRuby:" + ruby print RUBY_VERSION + if has('tcl') + echo "\nTcl:" + tcl puts [info patchlevel] + endif + echo "\nPython 2:" + python import sys; print sys.version +endif +redir END diff --git a/src/testdir/if_ver-2.vim b/src/testdir/if_ver-2.vim new file mode 100644 index 0000000..a6fedb5 --- /dev/null +++ b/src/testdir/if_ver-2.vim @@ -0,0 +1,10 @@ +" Print py3 interface version and write the result into if_ver.txt. +" For Ubuntu. Part 2. + +redir! >> if_ver.txt +if 1 + echo "\nPython 3:" + python3 import sys; print(sys.version) + echo "\n" +endif +redir END diff --git a/src/testdir/lsan-suppress.txt b/src/testdir/lsan-suppress.txt new file mode 100644 index 0000000..5166fbf --- /dev/null +++ b/src/testdir/lsan-suppress.txt @@ -0,0 +1,3 @@ +# Suppress leaks from X libraries on Ubuntu trusty. +leak:libX11.so.6 +leak:libXt.so.6 diff --git a/src/testdir/python2/module.py b/src/testdir/python2/module.py new file mode 100644 index 0000000..e90106a --- /dev/null +++ b/src/testdir/python2/module.py @@ -0,0 +1,2 @@ +import before_1 +dir = '2' diff --git a/src/testdir/python3/module.py b/src/testdir/python3/module.py new file mode 100644 index 0000000..24bd036 --- /dev/null +++ b/src/testdir/python3/module.py @@ -0,0 +1,2 @@ +import before_1 +dir = '3' diff --git a/src/testdir/python_after/after.py b/src/testdir/python_after/after.py new file mode 100644 index 0000000..5cf8fa4 --- /dev/null +++ b/src/testdir/python_after/after.py @@ -0,0 +1,2 @@ +import before_2 +dir = "after" diff --git a/src/testdir/python_before/before.py b/src/testdir/python_before/before.py new file mode 100644 index 0000000..531e81a --- /dev/null +++ b/src/testdir/python_before/before.py @@ -0,0 +1 @@ +dir = "before" diff --git a/src/testdir/python_before/before_1.py b/src/testdir/python_before/before_1.py new file mode 100644 index 0000000..fa81ada --- /dev/null +++ b/src/testdir/python_before/before_1.py @@ -0,0 +1 @@ +# empty file diff --git a/src/testdir/python_before/before_2.py b/src/testdir/python_before/before_2.py new file mode 100644 index 0000000..fa81ada --- /dev/null +++ b/src/testdir/python_before/before_2.py @@ -0,0 +1 @@ +# empty file diff --git a/src/testdir/pythonx/failing.py b/src/testdir/pythonx/failing.py new file mode 100644 index 0000000..30e73a0 --- /dev/null +++ b/src/testdir/pythonx/failing.py @@ -0,0 +1 @@ +raise NotImplementedError diff --git a/src/testdir/pythonx/failing_import.py b/src/testdir/pythonx/failing_import.py new file mode 100644 index 0000000..511cae7 --- /dev/null +++ b/src/testdir/pythonx/failing_import.py @@ -0,0 +1 @@ +raise ImportError diff --git a/src/testdir/pythonx/module.py b/src/testdir/pythonx/module.py new file mode 100644 index 0000000..6bf5a64 --- /dev/null +++ b/src/testdir/pythonx/module.py @@ -0,0 +1 @@ +dir = 'x' diff --git a/src/testdir/pythonx/modulex.py b/src/testdir/pythonx/modulex.py new file mode 100644 index 0000000..ec6a706 --- /dev/null +++ b/src/testdir/pythonx/modulex.py @@ -0,0 +1 @@ +ddir = 'xx' diff --git a/src/testdir/pythonx/topmodule/__init__.py b/src/testdir/pythonx/topmodule/__init__.py new file mode 100644 index 0000000..792d600 --- /dev/null +++ b/src/testdir/pythonx/topmodule/__init__.py @@ -0,0 +1 @@ +# diff --git a/src/testdir/pythonx/topmodule/submodule/__init__.py b/src/testdir/pythonx/topmodule/submodule/__init__.py new file mode 100644 index 0000000..792d600 --- /dev/null +++ b/src/testdir/pythonx/topmodule/submodule/__init__.py @@ -0,0 +1 @@ +# diff --git a/src/testdir/pythonx/topmodule/submodule/subsubmodule/__init__.py b/src/testdir/pythonx/topmodule/submodule/subsubmodule/__init__.py new file mode 100644 index 0000000..792d600 --- /dev/null +++ b/src/testdir/pythonx/topmodule/submodule/subsubmodule/__init__.py @@ -0,0 +1 @@ +# diff --git a/src/testdir/pythonx/topmodule/submodule/subsubmodule/subsubsubmodule.py b/src/testdir/pythonx/topmodule/submodule/subsubmodule/subsubsubmodule.py new file mode 100644 index 0000000..792d600 --- /dev/null +++ b/src/testdir/pythonx/topmodule/submodule/subsubmodule/subsubsubmodule.py @@ -0,0 +1 @@ +# diff --git a/src/testdir/pyxfile/py2_magic.py b/src/testdir/pyxfile/py2_magic.py new file mode 100644 index 0000000..819892f --- /dev/null +++ b/src/testdir/pyxfile/py2_magic.py @@ -0,0 +1,4 @@ +# requires python 2.x + +import sys +print(sys.version) diff --git a/src/testdir/pyxfile/py2_shebang.py b/src/testdir/pyxfile/py2_shebang.py new file mode 100644 index 0000000..13bfc49 --- /dev/null +++ b/src/testdir/pyxfile/py2_shebang.py @@ -0,0 +1,4 @@ +#!/usr/bin/python2 + +import sys +print(sys.version) diff --git a/src/testdir/pyxfile/py3_magic.py b/src/testdir/pyxfile/py3_magic.py new file mode 100644 index 0000000..d4b7ee0 --- /dev/null +++ b/src/testdir/pyxfile/py3_magic.py @@ -0,0 +1,4 @@ +# requires python 3.x + +import sys +print(sys.version) diff --git a/src/testdir/pyxfile/py3_shebang.py b/src/testdir/pyxfile/py3_shebang.py new file mode 100644 index 0000000..ec05808 --- /dev/null +++ b/src/testdir/pyxfile/py3_shebang.py @@ -0,0 +1,4 @@ +#!/usr/bin/python3 + +import sys +print(sys.version) diff --git a/src/testdir/pyxfile/pyx.py b/src/testdir/pyxfile/pyx.py new file mode 100644 index 0000000..261a651 --- /dev/null +++ b/src/testdir/pyxfile/pyx.py @@ -0,0 +1,2 @@ +import sys +print(sys.version) diff --git a/src/testdir/runtest.vim b/src/testdir/runtest.vim new file mode 100644 index 0000000..3f49ccb --- /dev/null +++ b/src/testdir/runtest.vim @@ -0,0 +1,401 @@ +" This script is sourced while editing the .vim file with the tests. +" When the script is successful the .res file will be created. +" Errors are appended to the test.log file. +" +" To execute only specific test functions, add a second argument. It will be +" matched against the names of the Test_ funtion. E.g.: +" ../vim -u NONE -S runtest.vim test_channel.vim open_delay +" The output can be found in the "messages" file. +" +" The test script may contain anything, only functions that start with +" "Test_" are special. These will be invoked and should contain assert +" functions. See test_assert.vim for an example. +" +" It is possible to source other files that contain "Test_" functions. This +" can speed up testing, since Vim does not need to restart. But be careful +" that the tests do not interfere with each other. +" +" If an error cannot be detected properly with an assert function add the +" error to the v:errors list: +" call add(v:errors, 'test foo failed: Cannot find xyz') +" +" If preparation for each Test_ function is needed, define a SetUp function. +" It will be called before each Test_ function. +" +" If cleanup after each Test_ function is needed, define a TearDown function. +" It will be called after each Test_ function. +" +" When debugging a test it can be useful to add messages to v:errors: +" call add(v:errors, "this happened") + + +" Without the +eval feature we can't run these tests, bail out. +so small.vim + +" Check that the screen size is at least 24 x 80 characters. +if &lines < 24 || &columns < 80 + let error = 'Screen size too small! Tests require at least 24 lines with 80 characters' + echoerr error + split test.log + $put =error + w + cquit +endif + +" Common with all tests on all systems. +source setup.vim + +" For consistency run all tests with 'nocompatible' set. +" This also enables use of line continuation. +set nocp viminfo+=nviminfo + +" Use utf-8 by default, instead of whatever the system default happens to be. +" Individual tests can overrule this at the top of the file. +set encoding=utf-8 + +" REDIR_TEST_TO_NULL has a very permissive SwapExists autocommand which is for +" the test_name.vim file itself. Replace it here with a more restrictive one, +" so we still catch mistakes. +let s:test_script_fname = expand('%') +au! SwapExists * call HandleSwapExists() +func HandleSwapExists() + " Only ignore finding a swap file for the test script (the user might be + " editing it and do ":make test_name") and the output file. + if expand('<afile>') == 'messages' || expand('<afile>') =~ s:test_script_fname + let v:swapchoice = 'e' + endif +endfunc + +" Avoid stopping at the "hit enter" prompt +set nomore + +" Output all messages in English. +lang mess C + +" Always use forward slashes. +set shellslash + +let s:srcdir = expand('%:p:h:h') + +" Prepare for calling test_garbagecollect_now(). +let v:testing = 1 + +" Support function: get the alloc ID by name. +function GetAllocId(name) + exe 'split ' . s:srcdir . '/alloc.h' + let top = search('typedef enum') + if top == 0 + call add(v:errors, 'typedef not found in alloc.h') + endif + let lnum = search('aid_' . a:name . ',') + if lnum == 0 + call add(v:errors, 'Alloc ID ' . a:name . ' not defined') + endif + close + return lnum - top - 1 +endfunc + +func RunTheTest(test) + echo 'Executing ' . a:test + + " Avoid stopping at the "hit enter" prompt + set nomore + + " Avoid a three second wait when a message is about to be overwritten by the + " mode message. + set noshowmode + + " Clear any overrides. + call test_override('ALL', 0) + + " Some tests wipe out buffers. To be consistent, always wipe out all + " buffers. + %bwipe! + + " The test may change the current directory. Save and restore the + " directory after executing the test. + let save_cwd = getcwd() + + if exists("*SetUp") + try + call SetUp() + catch + call add(v:errors, 'Caught exception in SetUp() before ' . a:test . ': ' . v:exception . ' @ ' . v:throwpoint) + endtry + endif + + call add(s:messages, 'Executing ' . a:test) + let s:done += 1 + + if a:test =~ 'Test_nocatch_' + " Function handles errors itself. This avoids skipping commands after the + " error. + exe 'call ' . a:test + else + try + let s:test = a:test + au VimLeavePre * call EarlyExit(s:test) + exe 'call ' . a:test + au! VimLeavePre + catch /^\cskipped/ + call add(s:messages, ' Skipped') + call add(s:skipped, 'SKIPPED ' . a:test . ': ' . substitute(v:exception, '^\S*\s\+', '', '')) + catch + call add(v:errors, 'Caught exception in ' . a:test . ': ' . v:exception . ' @ ' . v:throwpoint) + endtry + endif + + " In case 'insertmode' was set and something went wrong, make sure it is + " reset to avoid trouble with anything else. + set noinsertmode + + if exists("*TearDown") + try + call TearDown() + catch + call add(v:errors, 'Caught exception in TearDown() after ' . a:test . ': ' . v:exception . ' @ ' . v:throwpoint) + endtry + endif + + " Clear any autocommands + au! + au SwapExists * call HandleSwapExists() + + " Close any extra tab pages and windows and make the current one not modified. + while tabpagenr('$') > 1 + quit! + endwhile + + while 1 + let wincount = winnr('$') + if wincount == 1 + break + endif + bwipe! + if wincount == winnr('$') + " Did not manage to close a window. + only! + break + endif + endwhile + + exe 'cd ' . save_cwd +endfunc + +func AfterTheTest() + if len(v:errors) > 0 + let s:fail += 1 + call add(s:errors, 'Found errors in ' . s:test . ':') + call extend(s:errors, v:errors) + let v:errors = [] + endif +endfunc + +func EarlyExit(test) + " It's OK for the test we use to test the quit detection. + if a:test != 'Test_zz_quit_detected()' + call add(v:errors, 'Test caused Vim to exit: ' . a:test) + endif + + call FinishTesting() +endfunc + +" This function can be called by a test if it wants to abort testing. +func FinishTesting() + call AfterTheTest() + + " Don't write viminfo on exit. + set viminfo= + + " Clean up files created by setup.vim + call delete('XfakeHOME', 'rf') + + if s:fail == 0 + " Success, create the .res file so that make knows it's done. + exe 'split ' . fnamemodify(g:testname, ':r') . '.res' + write + endif + + if len(s:errors) > 0 + " Append errors to test.log + split test.log + call append(line('$'), '') + call append(line('$'), 'From ' . g:testname . ':') + call append(line('$'), s:errors) + write + endif + + if s:done == 0 + let message = 'NO tests executed' + else + let message = 'Executed ' . s:done . (s:done > 1 ? ' tests' : ' test') + endif + echo message + call add(s:messages, message) + if s:fail > 0 + let message = s:fail . ' FAILED:' + echo message + call add(s:messages, message) + call extend(s:messages, s:errors) + endif + + " Add SKIPPED messages + call extend(s:messages, s:skipped) + + " Append messages to the file "messages" + split messages + call append(line('$'), '') + call append(line('$'), 'From ' . g:testname . ':') + call append(line('$'), s:messages) + write + + qall! +endfunc + +" Source the test script. First grab the file name, in case the script +" navigates away. g:testname can be used by the tests. +let g:testname = expand('%') +let s:done = 0 +let s:fail = 0 +let s:errors = [] +let s:messages = [] +let s:skipped = [] +if expand('%') =~ 'test_vimscript.vim' + " this test has intentional s:errors, don't use try/catch. + source % +else + try + source % + catch + let s:fail += 1 + call add(s:errors, 'Caught exception: ' . v:exception . ' @ ' . v:throwpoint) + endtry +endif + +" Names of flaky tests. +let s:flaky_tests = [ + \ 'Test_call()', + \ 'Test_channel_handler()', + \ 'Test_client_server()', + \ 'Test_close_and_exit_cb()', + \ 'Test_close_callback()', + \ 'Test_close_handle()', + \ 'Test_close_lambda()', + \ 'Test_close_output_buffer()', + \ 'Test_close_partial()', + \ 'Test_collapse_buffers()', + \ 'Test_communicate()', + \ 'Test_cwd()', + \ 'Test_diff_screen()', + \ 'Test_exit_callback()', + \ 'Test_exit_callback_interval()', + \ 'Test_nb_basic()', + \ 'Test_oneshot()', + \ 'Test_open_delay()', + \ 'Test_out_cb()', + \ 'Test_paused()', + \ 'Test_pipe_through_sort_all()', + \ 'Test_pipe_through_sort_some()', + \ 'Test_popup_and_window_resize()', + \ 'Test_quoteplus()', + \ 'Test_quotestar()', + \ 'Test_raw_one_time_callback()', + \ 'Test_reltime()', + \ 'Test_repeat_three()', + \ 'Test_server_crash()', + \ 'Test_terminal_ansicolors_default()', + \ 'Test_terminal_ansicolors_func()', + \ 'Test_terminal_ansicolors_global()', + \ 'Test_terminal_composing_unicode()', + \ 'Test_terminal_env()', + \ 'Test_terminal_hide_buffer()', + \ 'Test_terminal_make_change()', + \ 'Test_terminal_noblock()', + \ 'Test_terminal_redir_file()', + \ 'Test_terminal_response_to_control_sequence()', + \ 'Test_terminal_scrollback()', + \ 'Test_terminal_split_quit()', + \ 'Test_terminal_termwinkey()', + \ 'Test_terminal_termwinsize_mininmum()', + \ 'Test_terminal_termwinsize_option_fixed()', + \ 'Test_terminal_termwinsize_option_zero()', + \ 'Test_terminal_tmap()', + \ 'Test_terminal_wall()', + \ 'Test_terminal_wipe_buffer()', + \ 'Test_terminal_wqall()', + \ 'Test_two_channels()', + \ 'Test_unlet_handle()', + \ 'Test_with_partial_callback()', + \ 'Test_zero_reply()', + \ 'Test_zz1_terminal_in_gui()', + \ ] + +" Pattern indicating a common flaky test failure. +let s:flaky_errors_re = 'StopVimInTerminal\|VerifyScreenDump' + +" Locate Test_ functions and execute them. +redir @q +silent function /^Test_ +redir END +let s:tests = split(substitute(@q, 'function \(\k*()\)', '\1', 'g')) + +" If there is an extra argument filter the function names against it. +if argc() > 1 + let s:tests = filter(s:tests, 'v:val =~ argv(1)') +endif + +" Execute the tests in alphabetical order. +for s:test in sort(s:tests) + " Silence, please! + set belloff=all + let prev_error = '' + let total_errors = [] + let run_nr = 1 + + call RunTheTest(s:test) + + " Repeat a flaky test. Give up when: + " - it fails again with the same message + " - it fails five times (with a different mesage) + if len(v:errors) > 0 + \ && (index(s:flaky_tests, s:test) >= 0 + \ || v:errors[0] =~ s:flaky_errors_re) + while 1 + call add(s:messages, 'Found errors in ' . s:test . ':') + call extend(s:messages, v:errors) + + call add(total_errors, 'Run ' . run_nr . ':') + call extend(total_errors, v:errors) + + if run_nr == 5 || prev_error == v:errors[0] + call add(total_errors, 'Flaky test failed too often, giving up') + let v:errors = total_errors + break + endif + + call add(s:messages, 'Flaky test failed, running it again') + + " Flakiness is often caused by the system being very busy. Sleep a + " couple of seconds to have a higher chance of succeeding the second + " time. + sleep 2 + + let prev_error = v:errors[0] + let v:errors = [] + let run_nr += 1 + + call RunTheTest(s:test) + + if len(v:errors) == 0 + " Test passed on rerun. + break + endif + endwhile + endif + + call AfterTheTest() +endfor + +call FinishTesting() + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/samples/quickfix.txt b/src/testdir/samples/quickfix.txt new file mode 100644 index 0000000..2de3835 --- /dev/null +++ b/src/testdir/samples/quickfix.txt @@ -0,0 +1,4 @@ +samples/quickfix.txt:1:1:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +samples/quickfix.txt:2:1:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb +samples/quickfix.txt:3:1:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc +samples/quickfix.txt:4:1:dddddddddd diff --git a/src/testdir/samples/re.freeze.txt b/src/testdir/samples/re.freeze.txt new file mode 100644 index 0000000..d768c23 --- /dev/null +++ b/src/testdir/samples/re.freeze.txt @@ -0,0 +1,6 @@ +:set re=0 or 2 +Search for the pattern: /\s\+\%#\@<!$/ +vim should not freeze. + +<td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td><td style="border-bottom windowtext 0.5pt solid; border-left windowtext;" class=abc align=right><font face=arial><font color=#ff0000><b>5</b></font></font></td> + diff --git a/src/testdir/samples/test000 b/src/testdir/samples/test000 Binary files differnew file mode 100644 index 0000000..af8abe9 --- /dev/null +++ b/src/testdir/samples/test000 diff --git a/src/testdir/sautest/autoload/Test104.vim b/src/testdir/sautest/autoload/Test104.vim new file mode 100644 index 0000000..d1e0e17 --- /dev/null +++ b/src/testdir/sautest/autoload/Test104.vim @@ -0,0 +1 @@ +let Test104#numvar = 123 diff --git a/src/testdir/sautest/autoload/foo.vim b/src/testdir/sautest/autoload/foo.vim new file mode 100644 index 0000000..d7dcd5c --- /dev/null +++ b/src/testdir/sautest/autoload/foo.vim @@ -0,0 +1,7 @@ +let g:loaded_foo_vim += 1 + +let foo#bar = {} + +func foo#bar.echo() + let g:called_foo_bar_echo += 1 +endfunc diff --git a/src/testdir/sautest/autoload/footest.vim b/src/testdir/sautest/autoload/footest.vim new file mode 100644 index 0000000..1e78963 --- /dev/null +++ b/src/testdir/sautest/autoload/footest.vim @@ -0,0 +1,5 @@ +" Autoload script used by test_listdict.vim, test_exists.vim and test_let.vim +let footest#x = 1 +func footest#F() + return 0 +endfunc diff --git a/src/testdir/sautest/autoload/globone.vim b/src/testdir/sautest/autoload/globone.vim new file mode 100644 index 0000000..98c9a10 --- /dev/null +++ b/src/testdir/sautest/autoload/globone.vim @@ -0,0 +1 @@ +" used by Test_globpath() diff --git a/src/testdir/sautest/autoload/globtwo.vim b/src/testdir/sautest/autoload/globtwo.vim new file mode 100644 index 0000000..98c9a10 --- /dev/null +++ b/src/testdir/sautest/autoload/globtwo.vim @@ -0,0 +1 @@ +" used by Test_globpath() diff --git a/src/testdir/sautest/autoload/sourced.vim b/src/testdir/sautest/autoload/sourced.vim new file mode 100644 index 0000000..f69f00c --- /dev/null +++ b/src/testdir/sautest/autoload/sourced.vim @@ -0,0 +1,3 @@ +let g:loaded_sourced_vim += 1 +func! sourced#something() +endfunc diff --git a/src/testdir/screendump.vim b/src/testdir/screendump.vim new file mode 100644 index 0000000..b46a477 --- /dev/null +++ b/src/testdir/screendump.vim @@ -0,0 +1,130 @@ +" Functions shared by tests making screen dumps. + +" Only load this script once. +if exists('*CanRunVimInTerminal') + finish +endif + +" For most tests we need to be able to run terminal Vim with 256 colors. On +" MS-Windows the console only has 16 colors and the GUI can't run in a +" terminal. +func CanRunVimInTerminal() + return has('terminal') && !has('win32') +endfunc + +" Skip the rest if there is no terminal feature at all. +if !has('terminal') + finish +endif + +source shared.vim + +" Run Vim with "arguments" in a new terminal window. +" By default uses a size of 20 lines and 75 columns. +" Returns the buffer number of the terminal. +" +" Options is a dictionary, these items are recognized: +" "rows" - height of the terminal window (max. 20) +" "cols" - width of the terminal window (max. 78) +func RunVimInTerminal(arguments, options) + " If Vim doesn't exit a swap file remains, causing other tests to fail. + " Remove it here. + call delete(".swp") + + if exists('$COLORFGBG') + " Clear $COLORFGBG to avoid 'background' being set to "dark", which will + " only be corrected if the response to t_RB is received, which may be too + " late. + let $COLORFGBG = '' + endif + + " Make a horizontal and vertical split, so that we can get exactly the right + " size terminal window. Works only when the current window is full width. + call assert_equal(&columns, winwidth(0)) + split + vsplit + + " Always do this with 256 colors and a light background. + set t_Co=256 background=light + hi Normal ctermfg=NONE ctermbg=NONE + + " Make the window 20 lines high and 75 columns, unless told otherwise. + let rows = get(a:options, 'rows', 20) + let cols = get(a:options, 'cols', 75) + + let cmd = GetVimCommandClean() + + " Add -v to have gvim run in the terminal (if possible) + let cmd .= ' -v ' . a:arguments + let buf = term_start(cmd, {'curwin': 1, 'term_rows': rows, 'term_cols': cols}) + if &termwinsize == '' + " in the GUI we may end up with a different size, try to set it. + if term_getsize(buf) != [rows, cols] + call term_setsize(buf, rows, cols) + endif + call assert_equal([rows, cols], term_getsize(buf)) + else + let rows = term_getsize(buf)[0] + let cols = term_getsize(buf)[1] + endif + + " Wait for "All" or "Top" of the ruler to be shown in the last line or in + " the status line of the last window. This can be quite slow (e.g. when + " using valgrind). + " If it fails then show the terminal contents for debugging. + try + call WaitFor({-> len(term_getline(buf, rows)) >= cols - 1 || len(term_getline(buf, rows - 1)) >= cols - 1}) + catch /timed out after/ + let lines = map(range(1, rows), {key, val -> term_getline(buf, val)}) + call assert_report('RunVimInTerminal() failed, screen contents: ' . join(lines, "<NL>")) + endtry + + return buf +endfunc + +" Stop a Vim running in terminal buffer "buf". +func StopVimInTerminal(buf) + call assert_equal("running", term_getstatus(a:buf)) + + " CTRL-O : works both in Normal mode and Insert mode to start a command line. + " In Command-line it's inserted, the CTRL-U removes it again. + call term_sendkeys(a:buf, "\<C-O>:\<C-U>qa!\<cr>") + + call WaitForAssert({-> assert_equal("finished", term_getstatus(a:buf))}) + only! +endfunc + +" Verify that Vim running in terminal buffer "buf" matches the screen dump. +" "options" is passed to term_dumpwrite(). +" The file name used is "dumps/{filename}.dump". +" Optionally an extra argument can be passed which is prepended to the error +" message. Use this when using the same dump file with different options. +" Will wait for up to a second for the screen dump to match. +" Returns non-zero when verification fails. +func VerifyScreenDump(buf, filename, options, ...) + let reference = 'dumps/' . a:filename . '.dump' + let testfile = a:filename . '.dump.failed' + + let i = 0 + while 1 + " leave some time for updating the original window + sleep 10m + call delete(testfile) + call term_dumpwrite(a:buf, testfile, a:options) + if readfile(reference) == readfile(testfile) + call delete(testfile) + break + endif + if i == 100 + " Leave the test file around for inspection. + let msg = 'See dump file difference: call term_dumpdiff("' . testfile . '", "' . reference . '")' + if a:0 == 1 + let msg = a:1 . ': ' . msg + endif + call assert_report(msg) + return 1 + endif + let i += 1 + endwhile + return 0 +endfunc diff --git a/src/testdir/setup.vim b/src/testdir/setup.vim new file mode 100644 index 0000000..fca5194 --- /dev/null +++ b/src/testdir/setup.vim @@ -0,0 +1,33 @@ +" Common preparations for running tests. + +" Only load this once. +if 1 + if exists('s:did_load') + finish + endif + let s:did_load = 1 +endif + +" Make sure 'runtimepath' and 'packpath' does not include $HOME. +set rtp=$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after +if has('packages') + let &packpath = &rtp +endif + +" Only when the +eval feature is present. +if 1 + " Make sure the .Xauthority file can be found after changing $HOME. + if $XAUTHORITY == '' + let $XAUTHORITY = $HOME . '/.Xauthority' + endif + + " Avoid storing shell history. + let $HISTFILE = "" + + " Make sure $HOME does not get read or written. + " It must exist, gnome tries to create $HOME/.gnome2 + let $HOME = getcwd() . '/XfakeHOME' + if !isdirectory($HOME) + call mkdir($HOME) + endif +endif diff --git a/src/testdir/setup_gui.vim b/src/testdir/setup_gui.vim new file mode 100644 index 0000000..90ef1f1 --- /dev/null +++ b/src/testdir/setup_gui.vim @@ -0,0 +1,32 @@ +" Common preparations for running GUI tests. + +let g:x11_based_gui = has('gui_athena') || has('gui_motif') + \ || has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3') + +" Reasons for 'skipped'. +let g:not_supported = "Skipped: Feature/Option not supported by this GUI: " +let g:not_implemented = "Skipped: Test not implemented yet for this GUI" +let g:not_hosted = "Skipped: Test not hosted by the system/environment" + +" For KDE set a font, empty 'guifont' may cause a hang. +func GUISetUpCommon() + if has("gui_kde") + set guifont=Courier\ 10\ Pitch/8/-1/5/50/0/0/0/0/0 + endif + + " Gnome insists on creating $HOME/.gnome2/, set $HOME to avoid changing the + " actual home directory. But avoid triggering fontconfig by setting the + " cache directory. Only needed for Unix. + if $XDG_CACHE_HOME == '' && exists('g:tester_HOME') + let $XDG_CACHE_HOME = g:tester_HOME . '/.cache' + endif + call mkdir('Xhome') + let $HOME = fnamemodify('Xhome', ':p') +endfunc + +func GUITearDownCommon() + call delete('Xhome', 'rf') +endfunc + +" Ignore the "failed to create input context" error. +call test_ignore_error('E285') diff --git a/src/testdir/shared.vim b/src/testdir/shared.vim new file mode 100644 index 0000000..4546be7 --- /dev/null +++ b/src/testdir/shared.vim @@ -0,0 +1,357 @@ +" Functions shared by several tests. + +" Only load this script once. +if exists('*WaitFor') + finish +endif + +" Get the name of the Python executable. +" Also keeps it in s:python. +func PythonProg() + " This test requires the Python command to run the test server. + " This most likely only works on Unix and Windows. + if has('unix') + " We also need the job feature or the pkill command to make sure the server + " can be stopped. + if !(executable('python') && (has('job') || executable('pkill'))) + return '' + endif + let s:python = 'python' + elseif has('win32') + " Use Python Launcher for Windows (py.exe) if available. + if executable('py.exe') + let s:python = 'py.exe' + elseif executable('python.exe') + let s:python = 'python.exe' + else + return '' + endif + else + return '' + endif + return s:python +endfunc + +" Run "cmd". Returns the job if using a job. +func RunCommand(cmd) + let job = 0 + if has('job') + let job = job_start(a:cmd, {"stoponexit": "hup"}) + call job_setoptions(job, {"stoponexit": "kill"}) + elseif has('win32') + exe 'silent !start cmd /c start "test_channel" ' . a:cmd + else + exe 'silent !' . a:cmd . '&' + endif + return job +endfunc + +" Read the port number from the Xportnr file. +func GetPort() + let l = [] + " with 200 it sometimes failed + for i in range(400) + try + let l = readfile("Xportnr") + catch + endtry + if len(l) >= 1 + break + endif + sleep 10m + endfor + call delete("Xportnr") + + if len(l) == 0 + " Can't make the connection, give up. + return 0 + endif + return l[0] +endfunc + +" Run a Python server for "cmd" and call "testfunc". +" Always kills the server before returning. +func RunServer(cmd, testfunc, args) + " The Python program writes the port number in Xportnr. + call delete("Xportnr") + + if len(a:args) == 1 + let arg = ' ' . a:args[0] + else + let arg = '' + endif + let pycmd = s:python . " " . a:cmd . arg + + try + let g:currentJob = RunCommand(pycmd) + + " Wait for up to 2 seconds for the port number to be there. + let port = GetPort() + if port == 0 + call assert_false(1, "Can't start " . a:cmd) + return + endif + + call call(function(a:testfunc), [port]) + catch + call assert_false(1, 'Caught exception: "' . v:exception . '" in ' . v:throwpoint) + finally + call s:kill_server(a:cmd) + endtry +endfunc + +func s:kill_server(cmd) + if has('job') + if exists('g:currentJob') + call job_stop(g:currentJob) + unlet g:currentJob + endif + elseif has('win32') + let cmd = substitute(a:cmd, ".py", '', '') + call system('taskkill /IM ' . s:python . ' /T /F /FI "WINDOWTITLE eq ' . cmd . '"') + else + call system("pkill -f " . a:cmd) + endif +endfunc + +" Wait for up to five seconds for "expr" to become true. "expr" can be a +" stringified expression to evaluate, or a funcref without arguments. +" Using a lambda works best. Example: +" call WaitFor({-> status == "ok"}) +" +" A second argument can be used to specify a different timeout in msec. +" +" When successful the time slept is returned. +" When running into the timeout an exception is thrown, thus the function does +" not return. +func WaitFor(expr, ...) + let timeout = get(a:000, 0, 5000) + let slept = s:WaitForCommon(a:expr, v:null, timeout) + if slept < 0 + throw 'WaitFor() timed out after ' . timeout . ' msec' + endif + return slept +endfunc + +" Wait for up to five seconds for "assert" to return zero. "assert" must be a +" (lambda) function containing one assert function. Example: +" call WaitForAssert({-> assert_equal("dead", job_status(job)}) +" +" A second argument can be used to specify a different timeout in msec. +" +" Return zero for success, one for failure (like the assert function). +func WaitForAssert(assert, ...) + let timeout = get(a:000, 0, 5000) + if s:WaitForCommon(v:null, a:assert, timeout) < 0 + return 1 + endif + return 0 +endfunc + +" Common implementation of WaitFor() and WaitForAssert(). +" Either "expr" or "assert" is not v:null +" Return the waiting time for success, -1 for failure. +func s:WaitForCommon(expr, assert, timeout) + " using reltime() is more accurate, but not always available + let slept = 0 + if has('reltime') + let start = reltime() + endif + + while 1 + if type(a:expr) == v:t_func + let success = a:expr() + elseif type(a:assert) == v:t_func + let success = a:assert() == 0 + else + let success = eval(a:expr) + endif + if success + return slept + endif + + if slept >= a:timeout + break + endif + if type(a:assert) == v:t_func + " Remove the error added by the assert function. + call remove(v:errors, -1) + endif + + sleep 10m + if has('reltime') + let slept = float2nr(reltimefloat(reltime(start)) * 1000) + else + let slept += 10 + endif + endwhile + + return -1 " timed out +endfunc + + +" Wait for up to a given milliseconds. +" With the +timers feature this waits for key-input by getchar(), Resume() +" feeds key-input and resumes process. Return time waited in milliseconds. +" Without +timers it uses simply :sleep. +func Standby(msec) + if has('timers') + let start = reltime() + let g:_standby_timer = timer_start(a:msec, function('s:feedkeys')) + call getchar() + return float2nr(reltimefloat(reltime(start)) * 1000) + else + execute 'sleep ' a:msec . 'm' + return a:msec + endif +endfunc + +func Resume() + if exists('g:_standby_timer') + call timer_stop(g:_standby_timer) + call s:feedkeys(0) + unlet g:_standby_timer + endif +endfunc + +func s:feedkeys(timer) + call feedkeys('x', 'nt') +endfunc + +" Get $VIMPROG to run Vim executable. +" The Makefile writes it as the first line in the "vimcmd" file. +func GetVimProg() + if !filereadable('vimcmd') + " Assume the script was sourced instead of running "make". + return '../vim' + endif + return readfile('vimcmd')[0] +endfunc + +let g:valgrind_cnt = 1 + +" Get the command to run Vim, with -u NONE and --not-a-term arguments. +" If there is an argument use it instead of "NONE". +func GetVimCommand(...) + if !filereadable('vimcmd') + echo 'Cannot read the "vimcmd" file, falling back to ../vim.' + let lines = ['../vim'] + else + let lines = readfile('vimcmd') + endif + if a:0 == 0 + let name = 'NONE' + else + let name = a:1 + endif + " For Unix Makefile writes the command to use in the second line of the + " "vimcmd" file, including environment options. + " Other Makefiles just write the executable in the first line, so fall back + " to that if there is no second line or it is empty. + if len(lines) > 1 && lines[1] != '' + let cmd = lines[1] + else + let cmd = lines[0] + endif + + let cmd = substitute(cmd, '-u \f\+', '-u ' . name, '') + if cmd !~ '-u '. name + let cmd = cmd . ' -u ' . name + endif + let cmd .= ' --not-a-term' + let cmd = substitute(cmd, 'VIMRUNTIME=.*VIMRUNTIME;', '', '') + + " If using valgrind, make sure every run uses a different log file. + if cmd =~ 'valgrind.*--log-file=' + let cmd = substitute(cmd, '--log-file=\(^\s*\)', '--log-file=\1.' . g:valgrind_cnt, '') + let g:valgrind_cnt += 1 + endif + + return cmd +endfunc + +" Get the command to run Vim, with --clean. +func GetVimCommandClean() + let cmd = GetVimCommand() + let cmd = substitute(cmd, '-u NONE', '--clean', '') + let cmd = substitute(cmd, '--not-a-term', '', '') + + " Optionally run Vim under valgrind + " let cmd = 'valgrind --tool=memcheck --leak-check=yes --num-callers=25 --log-file=valgrind ' . cmd + + return cmd +endfunc + +" Run Vim, using the "vimcmd" file and "-u NORC". +" "before" is a list of Vim commands to be executed before loading plugins. +" "after" is a list of Vim commands to be executed after loading plugins. +" Plugins are not loaded, unless 'loadplugins' is set in "before". +" Return 1 if Vim could be executed. +func RunVim(before, after, arguments) + return RunVimPiped(a:before, a:after, a:arguments, '') +endfunc + +func RunVimPiped(before, after, arguments, pipecmd) + let cmd = GetVimCommand() + let args = '' + if len(a:before) > 0 + call writefile(a:before, 'Xbefore.vim') + let args .= ' --cmd "so Xbefore.vim"' + endif + if len(a:after) > 0 + call writefile(a:after, 'Xafter.vim') + let args .= ' -S Xafter.vim' + endif + + exe "silent !" . a:pipecmd . cmd . args . ' ' . a:arguments + + if len(a:before) > 0 + call delete('Xbefore.vim') + endif + if len(a:after) > 0 + call delete('Xafter.vim') + endif + return 1 +endfunc + +func CanRunGui() + return has('gui') && ($DISPLAY != "" || has('gui_running')) +endfunc + +func WorkingClipboard() + if !has('clipboard') + return 0 + endif + if has('x11') + return $DISPLAY != "" + endif + return 1 +endfunc + +" Get line "lnum" as displayed on the screen. +" Trailing white space is trimmed. +func! Screenline(lnum) + let chars = [] + for c in range(1, winwidth(0)) + call add(chars, nr2char(screenchar(a:lnum, c))) + endfor + let line = join(chars, '') + return matchstr(line, '^.\{-}\ze\s*$') +endfunc + +" Stops the shell running in terminal "buf". +func Stop_shell_in_terminal(buf) + call term_sendkeys(a:buf, "exit\r") + let job = term_getjob(a:buf) + call WaitFor({-> job_status(job) == "dead"}) +endfunc + +" Gets the text of a terminal line, using term_scrape() +func Get_terminal_text(bufnr, row) + let list = term_scrape(a:bufnr, a:row) + let text = '' + for item in list + let text .= item.chars + endfor + return text +endfunc diff --git a/src/testdir/test1.in b/src/testdir/test1.in new file mode 100644 index 0000000..8c0219e --- /dev/null +++ b/src/testdir/test1.in @@ -0,0 +1,52 @@ + +First a simple test to check if the test script works. + +If Vim was not compiled with the +eval feature, the small.vim script will be +set to copy the test.ok file to test.out, so that it looks like the test +succeeded. Otherwise an empty small.vim is written. small.vim is sourced by +tests that require the +eval feature or other features that are missing in the +small version. + +If Vim was not compiled with the +windows feature, the tiny.vim script will be +set like small.vim above. tiny.vim is sourced by tests that require the ++windows feature or other features that are missing in the tiny version. + +If Vim was not compiled with the +multi_byte feature, the mbyte.vim script will +be set like small.vim above. mbyte.vim is sourced by tests that require the ++multi_byte feature. +Similar logic is applied to the +mzscheme feature, using mzscheme.vim. + +STARTTEST +:" If columns or lines are too small, create wrongtermsize. +:" (Some tests will fail. When columns and/or lines are small) +:if &lines < 24 || &columns < 80 | sp another | w! wrongtermsize | qa! | endif +:" +:" Write a single line to test.out to check if testing works at all. +:%d +athis is a test:w! test.out +:" Create small.vim and tiny.vim empty, create mbyte.vim to skip the test. +0D:w! small.vim +:w! tiny.vim +ae! test.ok +w! test.out +qa! +:w! mbyte.vim +:w! mzscheme.vim +:" +:" If +multi_byte feature supported, make mbyte.vim empty. +:if has("multi_byte") | sp another | w! mbyte.vim | q | endif +:" +:" If +mzscheme feature supported, make mzscheme.vim empty. +:if has("mzscheme") | sp another | w! mzscheme.vim | q | endif +:" +:" If +eval feature supported quit here, leaving tiny.vim and small.vim empty. +:" Otherwise write small.vim to skip the test. +:if 1 | q! | endif +:w! small.vim +:" If +windows feature not supported :sp will fail and tiny.vim will be +:" written to skip the test. +:sp another +:wq! tiny.vim +:qa! +ENDTEST + diff --git a/src/testdir/test1.ok b/src/testdir/test1.ok new file mode 100644 index 0000000..90bfcb5 --- /dev/null +++ b/src/testdir/test1.ok @@ -0,0 +1 @@ +this is a test diff --git a/src/testdir/test108.in b/src/testdir/test108.in new file mode 100644 index 0000000..59c4dfc --- /dev/null +++ b/src/testdir/test108.in @@ -0,0 +1,88 @@ +Tests for backtrace debug commands. vim: set ft=vim : + +STARTTEST +:so small.vim +:lang mess C +:function! Foo() +: let var1 = 1 +: let var2 = Bar(var1) + 9 +: return var2 +:endfunction +: +:function! Bar(var) +: let var1 = 2 + a:var +: let var2 = Bazz(var1) + 4 +: return var2 +:endfunction +: +:function! Bazz(var) +: let var1 = 3 + a:var +: let var3 = "another var" +: return var1 +:endfunction +:new +:debuggreedy +:redir => out +:debug echo Foo() +step +step +step +step +step +step +echo "- show backtrace:\n" +backtrace +echo "\nshow variables on different levels:\n" +echo var1 +up +back +echo var1 +u +bt +echo var1 +echo "\n- undefined vars:\n" +step +frame 2 +echo "undefined var3 on former level:" +echo var3 +fr 0 +echo "here var3 is defined with \"another var\":" +echo var3 +step +step +step +up +echo "\nundefined var2 on former level" +echo var2 +down +echo "here var2 is defined with 10:" +echo var2 +echo "\n- backtrace movements:\n" +b +echo "\nnext command cannot go down, we are on bottom\n" +down +up +echo "\nnext command cannot go up, we are on top\n" +up +b +echo "fil is not frame or finish, it is file" +fil +echo "\n- relative backtrace movement\n" +fr -1 +frame +fra +1 +fram +echo "\n- go beyond limits does not crash\n" +fr 100 +fra +frame -40 +fram +echo "\n- final result 19:" +cont +:0debuggreedy +:redir END +:$put =out +:w! test.out +:qa! +ENDTEST + diff --git a/src/testdir/test108.ok b/src/testdir/test108.ok new file mode 100644 index 0000000..7a531dd --- /dev/null +++ b/src/testdir/test108.ok @@ -0,0 +1,82 @@ + + + +- show backtrace: + + 2 function Foo[2] + 1 Bar[2] +->0 Bazz +line 2: let var3 = "another var" + +show variables on different levels: + +6 + 2 function Foo[2] +->1 Bar[2] + 0 Bazz +line 2: let var3 = "another var" +3 +->2 function Foo[2] + 1 Bar[2] + 0 Bazz +line 2: let var3 = "another var" +1 + +- undefined vars: + +undefined var3 on former level: +Error detected while processing function Foo[2]..Bar[2]..Bazz: +line 3: +E121: Undefined variable: var3 +here var3 is defined with "another var": +another var + +undefined var2 on former level +Error detected while processing function Foo[2]..Bar: +line 3: +E121: Undefined variable: var2 +here var2 is defined with 10: +10 + +- backtrace movements: + + 1 function Foo[2] +->0 Bar +line 3: End of function + +next command cannot go down, we are on bottom + +frame is zero + +next command cannot go up, we are on top + +frame at highest level: 1 +->1 function Foo[2] + 0 Bar +line 3: End of function +fil is not frame or finish, it is file +"[No Name]" --No lines in buffer-- + +- relative backtrace movement + + 1 function Foo[2] +->0 Bar +line 3: End of function +->1 function Foo[2] + 0 Bar +line 3: End of function + +- go beyond limits does not crash + +frame at highest level: 1 +->1 function Foo[2] + 0 Bar +line 3: End of function +frame is zero + 1 function Foo[2] +->0 Bar +line 3: End of function + +- final result 19: +19 + diff --git a/src/testdir/test11.in b/src/testdir/test11.in new file mode 100644 index 0000000..9e9e257 --- /dev/null +++ b/src/testdir/test11.in @@ -0,0 +1,84 @@ +Tests for autocommands: +- FileWritePre writing a compressed file +- FileReadPost reading a compressed file +- BufNewFile reading a file template +- BufReadPre decompressing the file to be read +- FilterReadPre substituting characters in the temp file +- FilterReadPost substituting characters after filtering +- FileReadPre set options for decompression +- FileReadPost decompress the file + +Note: This test is skipped if "gzip" is not available. +$GZIP is made empty, "-v" would cause trouble. +Use a FileChangedShell autocommand to avoid a prompt for "Xtestfile.gz" being +modified outside of Vim (noticed on Solaris). + +STARTTEST +:so small.vim +:" drop out when there is no gzip program +:if !executable("gzip") +: e! test.ok +: w! test.out +: qa! +:endif +:let $GZIP = "" +:au FileChangedShell * echo "caught FileChangedShell" +:set bin +:au FileWritePre *.gz '[,']!gzip +:au FileWritePost *.gz undo +:/^start of testfile/,/^end of testfile/w! Xtestfile.gz +:au FileReadPost *.gz '[,']!gzip -d +:$r Xtestfile.gz " Read and decompress the testfile +:?startstart?,$w! test.out " Write contents of this file +:au BufNewFile *.c read Xtest.c +:/^start of test.c/+1,/^end of test.c/-1w! Xtest.c +:e! foo.c " Will load Xtest.c +:au FileAppendPre *.out '[,']s/new/NEW/ +:au FileAppendPost *.out !cat Xtest.c >>test.out +:w>>test.out " Append it to the output file +:au! FileAppendPre +:" setup autocommands to decompress before reading and re-compress afterwards +:au BufReadPre *.gz exe '!gzip -d ' . shellescape(expand("<afile>")) +:au BufReadPre *.gz call rename(expand("<afile>:r"), expand("<afile>")) +:au BufReadPost *.gz call rename(expand("<afile>"), expand("<afile>:r")) +:au BufReadPost *.gz exe '!gzip ' . shellescape(expand("<afile>:r")) +:e! Xtestfile.gz " Edit compressed file +:w>>test.out " Append it to the output file +:set shelltemp " need temp files here +:au FilterReadPre *.out call rename(expand("<afile>"), expand("<afile>") . ".t") +:au FilterReadPre *.out exe 'silent !sed s/e/E/ ' . shellescape(expand("<afile>")) . ".t >" . shellescape(expand("<afile>")) +:au FilterReadPre *.out exe 'silent !rm ' . shellescape(expand("<afile>")) . '.t' +:au FilterReadPost *.out '[,']s/x/X/g +:e! test.out " Edit the output file +:23,$!cat +:23,$s/\r$// " remove CR for when sed adds them +:au! FileReadPre *.gz exe 'silent !gzip -d ' . shellescape(expand("<afile>")) +:au FileReadPre *.gz call rename(expand("<afile>:r"), expand("<afile>")) +:au! FileReadPost *.gz '[,']s/l/L/ +:$r Xtestfile.gz " Read compressed file +:w " write it, after filtering +:au! " remove all autocommands +:e " Edit test.out again +:set nobin ff& " use the default fileformat for writing +:w +:qa! +ENDTEST + +startstart +start of testfile +line 2 Abcdefghijklmnopqrstuvwxyz +line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +line 4 Abcdefghijklmnopqrstuvwxyz +line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +line 6 Abcdefghijklmnopqrstuvwxyz +line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +line 8 Abcdefghijklmnopqrstuvwxyz +line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +line 10 Abcdefghijklmnopqrstuvwxyz +end of testfile + +start of test.c +/* + * Here is a new .c file + */ +end of test.c diff --git a/src/testdir/test11.ok b/src/testdir/test11.ok new file mode 100644 index 0000000..af8c5ce --- /dev/null +++ b/src/testdir/test11.ok @@ -0,0 +1,61 @@ +startstart +start of testfile +line 2 Abcdefghijklmnopqrstuvwxyz +line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +line 4 Abcdefghijklmnopqrstuvwxyz +line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +line 6 Abcdefghijklmnopqrstuvwxyz +line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +line 8 Abcdefghijklmnopqrstuvwxyz +line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +line 10 Abcdefghijklmnopqrstuvwxyz +end of testfile + +start of test.c +/* + * Here is a new .c file + */ +end of test.c +start of testfile +line 2 Abcdefghijklmnopqrstuvwxyz +line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +line 4 Abcdefghijklmnopqrstuvwxyz +linE 5 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +linE 6 AbcdefghijklmnopqrstuvwXyz +linE 7 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +linE 8 AbcdefghijklmnopqrstuvwXyz +linE 9 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +linE 10 AbcdefghijklmnopqrstuvwXyz +End of testfile + +/* + * HEre is a NEW .c file + */ +/* + * HEre is a new .c file + */ +start of tEstfile +linE 2 AbcdefghijklmnopqrstuvwXyz +linE 3 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +linE 4 AbcdefghijklmnopqrstuvwXyz +linE 5 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +linE 6 AbcdefghijklmnopqrstuvwXyz +linE 7 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +linE 8 AbcdefghijklmnopqrstuvwXyz +linE 9 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +linE 10 AbcdefghijklmnopqrstuvwXyz +End of testfile +/* + * HEre is a new .c file + */ +start of testfiLe +Line 2 Abcdefghijklmnopqrstuvwxyz +Line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +Line 4 Abcdefghijklmnopqrstuvwxyz +Line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +Line 6 Abcdefghijklmnopqrstuvwxyz +Line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +Line 8 Abcdefghijklmnopqrstuvwxyz +Line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +Line 10 Abcdefghijklmnopqrstuvwxyz +end of testfiLe diff --git a/src/testdir/test14.in b/src/testdir/test14.in new file mode 100644 index 0000000..3fc39fe --- /dev/null +++ b/src/testdir/test14.in @@ -0,0 +1,100 @@ +Tests for "vaBiB", end could be wrong. +Also test ":s/pat/sub/" with different ~s in sub. +Also test for ^Vxff and ^Vo123 in Insert mode. +Also test "[m", "]m", "[M" and "]M" +Also test search() + +STARTTEST +:so small.vim +:set belloff=all +/Start cursor here +vaBiBD:?Bug?,/Piece/-2w! test.out +/^- Bug +:s/u/~u~/ +:s/i/~u~/ +:s/o/~~~/ +:.w >>test.out +:if has("ebcdic") +: let tt = "o\<C-V>193\<C-V>xc2\<C-V>o303 \<C-V>90a\<C-V>xfg\<C-V>o578\<Esc>" +:else +: let tt = "o\<C-V>65\<C-V>x42\<C-V>o103 \<C-V>33a\<C-V>xfg\<C-V>o78\<Esc>" +:endif +:exe "normal " . tt +:unlet tt +:.w >>test.out +:set vb +/^Piece +2]maA:.w >>test.out +j]maB:.w >>test.out +]maC:.w >>test.out +[maD:.w >>test.out +k2[maE:.w >>test.out +3[maF:.w >>test.out +]MaG:.w >>test.out +j2]MaH:.w >>test.out +]M]MaI:.w >>test.out +2[MaJ:.w >>test.out +k[MaK:.w >>test.out +3[MaL:.w >>test.out +:" +/^foobar +:let startline = line('.') +:call search('foobar', 'c') +:call append(line('$'), line('.') - startline) +j:call search('^$', 'c') +:call append(line('$'), line('.') - startline) +:call search('^$', 'bc') +:call append(line('$'), line('.') - startline) +/two +:call search('.', 'c') +:call append(line('$'), getline('.')[col('.') - 1:]) +:" +/^substitute +:s/foo/bar/ +:$put =@/ +/^substitute +:keeppatterns s/asdf/xyz/ +:$put =@/ +/^substitute +Y:$put =@0 +/bar /e +:$put =@0 +-:keeppatterns /xyz +0dn:/^search()/,$w >>test.out +:qa! +ENDTEST + +- Bug in "vPPPP" on this text (Webb): + { + cmd; + { + cmd; /* <-- Start cursor here */ + { + } + } + } + +Piece of Java +{ + tt m1 { + t1; + } e1 + + tt m2 { + t2; + } e2 + + tt m3 { + if (x) + { + t3; + } + } e3 +} + +foobar + +substitute foo asdf + +one two +search() diff --git a/src/testdir/test14.ok b/src/testdir/test14.ok new file mode 100644 index 0000000..0aa2db3 --- /dev/null +++ b/src/testdir/test14.ok @@ -0,0 +1,26 @@ +- Bug in "vPPPP" on this text (Webb): + { + } +- Bug uuun "vPPPP" uuuuuuuuun this text (Webb): +ABC !ag8 + tt m1 {A + tt m2 {B + tt m3 {C + tt m3 {DC + tt m1 {EA +{F + }G e1 + }H e3 +}I + }JH e3 + }K e2 +{LF +search() +0 +1 +1 +two +foo +^substitute +substitute bar xyz +xyz diff --git a/src/testdir/test17.in b/src/testdir/test17.in new file mode 100644 index 0000000..59b57c2 --- /dev/null +++ b/src/testdir/test17.in @@ -0,0 +1,135 @@ +Tests for: +- "gf" on ${VAR}, +- ":checkpath!" with various 'include' settings. + +STARTTEST +:so small.vim +:if has("ebcdic") +: set isfname=@,240-249,/,.,-,_,+,,,$,:,~,{,} +:else +: set isfname=@,48-57,/,.,-,_,+,,,$,:,~,{,} +:endif +:" +:if has("unix") +:let $CDIR = "." +/CDIR +:else +:if has("amiga") +:let $TDIR = "/testdir" +:else +:let $TDIR = "." +:endif +/TDIR +:endif +:" Dummy writing for making that sure gf doesn't fail even if the current +:" file is modified. It can be occurred when executing the following command +:" directly on Windows without fixing the 'fileformat': +:" > nmake -f Make_dos.mak test17.out +:w! test.out +gf +:set ff=unix +:w! test.out +:brewind +ENDTEST + + ${CDIR}/test17a.in + $TDIR/test17a.in + +STARTTEST +:" check for 'include' without \zs or \ze +:lang C +:call delete("./Xbase.a") +:call delete("Xdir1", "rf") +:!mkdir Xdir1 +:!mkdir "Xdir1/dir2" +:e! Xdir1/dir2/foo.a +i#include "bar.a": +:w +:e Xdir1/dir2/bar.a +i#include "baz.a": +:w +:e Xdir1/dir2/baz.a +i#include "foo.a": +:w +:e Xbase.a +:set path=Xdir1/dir2 +i#include <foo.a>: +:w +:redir! >>test.out +:checkpath! +:redir END +:brewind +ENDTEST + +STARTTEST +:" check for 'include' with \zs and \ze +:call delete("./Xbase.b") +:call delete("Xdir1", "rf") +:!mkdir Xdir1 +:!mkdir "Xdir1/dir2" +:let &include='^\s*%inc\s*/\zs[^/]\+\ze' +:function! DotsToSlashes() +: return substitute(v:fname, '\.', '/', 'g') . '.b' +:endfunction +:let &includeexpr='DotsToSlashes()' +:e! Xdir1/dir2/foo.b +i%inc /bar/: +:w +:e Xdir1/dir2/bar.b +i%inc /baz/: +:w +:e Xdir1/dir2/baz.b +i%inc /foo/: +:w +:e Xbase.b +:set path=Xdir1/dir2 +i%inc /foo/: +:w +:redir! >>test.out +:checkpath! +:redir END +:brewind +ENDTEST + +STARTTEST +:" check for 'include' with \zs and no \ze +:call delete("./Xbase.c") +:call delete("Xdir1", "rf") +:!mkdir Xdir1 +:!mkdir "Xdir1/dir2" +:let &include='^\s*%inc\s*\%([[:upper:]][^[:space:]]*\s\+\)\?\zs\S\+\ze' +:function! StripNewlineChar() +: if v:fname =~ '\n$' +: return v:fname[:-2] +: endif +: return v:fname +:endfunction +:let &includeexpr='StripNewlineChar()' +:e! Xdir1/dir2/foo.c +i%inc bar.c: +:w +:e Xdir1/dir2/bar.c +i%inc baz.c: +:w +:e Xdir1/dir2/baz.c +i%inc foo.c: +:w +:e Xdir1/dir2/FALSE.c +i%inc foo.c: +:w +:e Xbase.c +:set path=Xdir1/dir2 +i%inc FALSE.c foo.c: +:w +:redir! >>test.out +:checkpath! +:redir END +:brewind +:" change "\" to "/" for Windows and fix 'fileformat' +:e test.out +:%s#\\#/#g +:set ff& +:w +:q +ENDTEST + diff --git a/src/testdir/test17.ok b/src/testdir/test17.ok new file mode 100644 index 0000000..b2a66d5 --- /dev/null +++ b/src/testdir/test17.ok @@ -0,0 +1,33 @@ +This file is just to test "gf" in test 17. +The contents is not important. +Just testing! + + +--- Included files in path --- +Xdir1/dir2/foo.a +Xdir1/dir2/foo.a --> + Xdir1/dir2/bar.a + Xdir1/dir2/bar.a --> + Xdir1/dir2/baz.a + Xdir1/dir2/baz.a --> + "foo.a" (Already listed) + + +--- Included files in path --- +Xdir1/dir2/foo.b +Xdir1/dir2/foo.b --> + Xdir1/dir2/bar.b + Xdir1/dir2/bar.b --> + Xdir1/dir2/baz.b + Xdir1/dir2/baz.b --> + foo (Already listed) + + +--- Included files in path --- +Xdir1/dir2/foo.c +Xdir1/dir2/foo.c --> + Xdir1/dir2/bar.c + Xdir1/dir2/bar.c --> + Xdir1/dir2/baz.c + Xdir1/dir2/baz.c --> + foo.c (Already listed) diff --git a/src/testdir/test17a.in b/src/testdir/test17a.in new file mode 100644 index 0000000..7e89364 --- /dev/null +++ b/src/testdir/test17a.in @@ -0,0 +1,3 @@ +This file is just to test "gf" in test 17. +The contents is not important. +Just testing! diff --git a/src/testdir/test29.in b/src/testdir/test29.in new file mode 100644 index 0000000..366a551 --- /dev/null +++ b/src/testdir/test29.in @@ -0,0 +1,231 @@ +Test for joining lines and marks in them + in compatible and nocompatible modes + and with 'joinspaces' set or not + and with 'cpoptions' flag 'j' set or not + +STARTTEST +:so small.vim +:set nocompatible viminfo+=nviminfo +:set nojoinspaces +:set cpoptions-=j +/firstline/ +j"td/^STARTTEST/-1 +PJjJjJjJjJjJjJjJjJjJjJjJjJjJj05lmx2j06lmy2k4Jy3l$p`xyl$p`yy2l$p:set cpoptions+=j +j05lmx2j06lmy2k4Jy3l$p`xyl$p`yy2l$p:set cpoptions-=j joinspaces +j"tpJjJjJjJjJjJjJjJjJjJjJjJjJjJj05lmx2j06lmy2k4Jy3l$p`xyl$p`yy2l$p:set cpoptions+=j +j05lmx2j06lmy2k4Jy3l$p`xyl$p`yy2l$p:set cpoptions-=j nojoinspaces compatible +j"tpJjJjJjJjJjJjJjJjJjJjJjJjJjJj4Jy3l$pjd/STARTTEST/-2 +ENDTEST + +firstline +asdfasdf. +asdf +asdfasdf. +asdf +asdfasdf. +asdf +asdfasdf. +asdf +asdfasdf. +asdf +asdfasdf. +asdf +asdfasdf. +asdf +asdfasdf +asdf +asdfasdf +asdf +asdfasdf +asdf +asdfasdf +asdf +asdfasdf +asdf +asdfasdf +asdf +asdfasdf +asdf +zx cvn. +as dfg? +hjkl iop! +ert +zx cvn. +as dfg? +hjkl iop! +ert + +STARTTEST +/^{/+1 +:set comments=s1:/*,mb:*,ex:*/,:// +:set nojoinspaces fo=j +:set backspace=eol,start +:.,+3join +j4J +:.,+2join +j3J +:.,+2join +j3J +:.,+2join +jj3J +ENDTEST + +{ + +/* + * Make sure the previous comment leader is not removed. + */ + +/* + * Make sure the previous comment leader is not removed. + */ + +// Should the next comment leader be left alone? +// Yes. + +// Should the next comment leader be left alone? +// Yes. + +/* Here the comment leader should be left intact. */ +// And so should this one. + +/* Here the comment leader should be left intact. */ +// And so should this one. + +if (condition) // Remove the next comment leader! + // OK, I will. + action(); + +if (condition) // Remove the next comment leader! + // OK, I will. + action(); +} + +STARTTEST +:" Test with backspace set to the non-compatible setting +:set belloff=all +/^\d\+ this +:set cp bs=2 +Avim1 +Avim2u +:set cpo-=< +:inoremap <c-u> <left><c-u> +Avim3 +:iunmap <c-u> +Avim4 +:" Test with backspace set to the compatible setting +:set backspace= visualbell +A vim5A +A vim6Azweiu +:inoremap <c-u> <left><c-u> +A vim7 +:set compatible novisualbell +ENDTEST +1 this shouldn't be deleted +2 this shouldn't be deleted +3 this shouldn't be deleted +4 this should be deleted +5 this shouldn't be deleted +6 this shouldn't be deleted +7 this shouldn't be deleted +8 this shouldn't be deleted (not touched yet) + +STARTTEST +/^{/+1 +:set comments=sO:*\ -,mO:*\ \ ,exO:*/ +:set comments+=s1:/*,mb:*,ex:*/,:// +:set comments+=s1:>#,mb:#,ex:#<,:< +:set cpoptions-=j joinspaces fo=j +:set backspace=eol,start +:.,+3join +j4J +:.,+8join +j9J +:.,+2join +j3J +:.,+2join +j3J +:.,+2join +jj3J +j:.,+2join +jj3J +j:.,+5join +j6J +oSome code!
// Make sure backspacing does not remove this comment leader.0i +ENDTEST + +{ + +/* + * Make sure the previous comment leader is not removed. + */ + +/* + * Make sure the previous comment leader is not removed. + */ + +/* List: + * - item1 + * foo bar baz + * foo bar baz + * - item2 + * foo bar baz + * foo bar baz + */ + +/* List: + * - item1 + * foo bar baz + * foo bar baz + * - item2 + * foo bar baz + * foo bar baz + */ + +// Should the next comment leader be left alone? +// Yes. + +// Should the next comment leader be left alone? +// Yes. + +/* Here the comment leader should be left intact. */ +// And so should this one. + +/* Here the comment leader should be left intact. */ +// And so should this one. + +if (condition) // Remove the next comment leader! + // OK, I will. + action(); + +if (condition) // Remove the next comment leader! + // OK, I will. + action(); + +int i = 7 /* foo *// 3 + // comment + ; + +int i = 7 /* foo *// 3 + // comment + ; + +># Note that the last character of the ending comment leader (left angle + # bracket) is a comment leader itself. Make sure that this comment leader is + # not removed from the next line #< +< On this line a new comment is opened which spans 2 lines. This comment should +< retain its comment leader. + +># Note that the last character of the ending comment leader (left angle + # bracket) is a comment leader itself. Make sure that this comment leader is + # not removed from the next line #< +< On this line a new comment is opened which spans 2 lines. This comment should +< retain its comment leader. + +} + +STARTTEST +:g/^STARTTEST/.,/^ENDTEST/d +:?firstline?+1,$w! test.out +:qa! +ENDTEST diff --git a/src/testdir/test29.ok b/src/testdir/test29.ok new file mode 100644 index 0000000..9dc07ed --- /dev/null +++ b/src/testdir/test29.ok @@ -0,0 +1,97 @@ +asdfasdf. asdf +asdfasdf. asdf +asdfasdf. asdf +asdfasdf. asdf +asdfasdf. asdf +asdfasdf. asdf +asdfasdf. asdf +asdfasdf asdf +asdfasdf asdf +asdfasdf asdf +asdfasdf asdf +asdfasdf asdf +asdfasdf asdf +asdfasdf asdf +zx cvn. as dfg? hjkl iop! ert ernop +zx cvn. as dfg? hjkl iop! ert ernop + +asdfasdf. asdf +asdfasdf. asdf +asdfasdf. asdf +asdfasdf. asdf +asdfasdf. asdf +asdfasdf. asdf +asdfasdf. asdf +asdfasdf asdf +asdfasdf asdf +asdfasdf asdf +asdfasdf asdf +asdfasdf asdf +asdfasdf asdf +asdfasdf asdf +zx cvn. as dfg? hjkl iop! ert enop +zx cvn. as dfg? hjkl iop! ert ernop + +asdfasdf. asdf +asdfasdf. asdf +asdfasdf. asdf +asdfasdf. asdf +asdfasdf. asdf +asdfasdf. asdf +asdfasdf. asdf +asdfasdf asdf +asdfasdf asdf +asdfasdf asdf +asdfasdf asdf +asdfasdf asdf +asdfasdf asdf +asdfasdf asdf +zx cvn. as dfg? hjkl iop! ert a + + +{ +/* Make sure the previous comment leader is not removed. */ +/* Make sure the previous comment leader is not removed. */ +// Should the next comment leader be left alone? Yes. +// Should the next comment leader be left alone? Yes. +/* Here the comment leader should be left intact. */ // And so should this one. +/* Here the comment leader should be left intact. */ // And so should this one. +if (condition) // Remove the next comment leader! OK, I will. + action(); +if (condition) // Remove the next comment leader! OK, I will. + action(); +} + +1 this shouldn't be deleted +2 this shouldn't be deleted +3 this shouldn't be deleted +4 this should be deleted3 + +6 this shouldn't be deleted vim5 +7 this shouldn't be deleted vim6 +8 this shouldn't be deleted (not touched yet) vim7 + + +{ +/* Make sure the previous comment leader is not removed. */ +/* Make sure the previous comment leader is not removed. */ +/* List: item1 foo bar baz foo bar baz item2 foo bar baz foo bar baz */ +/* List: item1 foo bar baz foo bar baz item2 foo bar baz foo bar baz */ +// Should the next comment leader be left alone? Yes. +// Should the next comment leader be left alone? Yes. +/* Here the comment leader should be left intact. */ // And so should this one. +/* Here the comment leader should be left intact. */ // And so should this one. +if (condition) // Remove the next comment leader! OK, I will. + action(); +if (condition) // Remove the next comment leader! OK, I will. + action(); +int i = 7 /* foo *// 3 // comment + ; +int i = 7 /* foo *// 3 // comment + ; +># Note that the last character of the ending comment leader (left angle bracket) is a comment leader itself. Make sure that this comment leader is not removed from the next line #< < On this line a new comment is opened which spans 2 lines. This comment should retain its comment leader. +># Note that the last character of the ending comment leader (left angle bracket) is a comment leader itself. Make sure that this comment leader is not removed from the next line #< < On this line a new comment is opened which spans 2 lines. This comment should retain its comment leader. + +Some code!// Make sure backspacing does not remove this comment leader. +} + diff --git a/src/testdir/test3.in b/src/testdir/test3.in new file mode 100644 index 0000000..646fbb3 --- /dev/null +++ b/src/testdir/test3.in @@ -0,0 +1,2354 @@ +/* vim: set cin ts=4 sw=4 : */ + +Test for 'cindent'. +For new tests, consider putting them in test_cindent.vim. + +STARTTEST +:so small.vim +:set nocompatible viminfo+=nviminfo modeline +:edit " read modeline +/start of AUTO +=/end of AUTO +ENDTEST + +/* start of AUTO matically checked vim: set ts=4 : */ +{ + if (test) + cmd1; + cmd2; +} + +{ + if (test) + cmd1; + else + cmd2; +} + +{ + if (test) + { + cmd1; + cmd2; + } +} + +{ + if (test) + { + cmd1; + else + } +} + +{ + while (this) + if (test) + cmd1; + cmd2; +} + +{ + while (this) + if (test) + cmd1; + else + cmd2; +} + +{ + if (test) + { + cmd; + } + + if (test) + cmd; +} + +{ + if (test) { + cmd; + } + + if (test) cmd; +} + +{ + cmd1; + for (blah) + while (this) + if (test) + cmd2; + cmd3; +} + +{ + cmd1; + for (blah) + while (this) + if (test) + cmd2; + cmd3; + + if (test) + { + cmd1; + cmd2; + cmd3; + } +} + + +/* Test for 'cindent' do/while mixed with if/else: */ + +{ + do + if (asdf) + asdfasd; + while (cond); + + do + if (asdf) + while (asdf) + asdf; + while (asdf); +} + +/* Test for 'cindent' with two ) on a continuation line */ +{ + if (asdfasdf;asldkfj asdlkfj as;ldkfj sal;d + aal;sdkjf ( ;asldfkja;sldfk + al;sdjfka ;slkdf ) sa;ldkjfsa dlk;) + line up here; +} + + +/* C++ tests: */ + +// foo() these three lines should remain in column 0 +// { +// } + +/* Test for continuation and unterminated lines: */ +{ + i = 99 + 14325 + + 21345 + + 21345 + + 21345 + ( 21345 + + 21345) + + 2345 + + 1234; + c = 1; +} + +/* + testje for indent with empty line + + here */ + +{ + if (testing && + not a joke || + line up here) + hay; + if (testing && + (not a joke || testing + )line up here) + hay; + if (testing && + (not a joke || testing + line up here)) + hay; +} + + +{ + switch (c) + { + case xx: + do + if (asdf) + do + asdfasdf; + while (asdf); + else + asdfasdf; + while (cond); + case yy: + case xx: + case zz: + testing; + } +} + +{ + if (cond) { + foo; + } + else + { + bar; + } +} + +{ + if (alskdfj ;alsdkfjal;skdjf (;sadlkfsa ;dlkf j;alksdfj ;alskdjf + alsdkfj (asldk;fj + awith cino=(0 ;lf this one goes to below the paren with == + ;laksjfd ;lsakdjf ;alskdf asd) + asdfasdf;))) + asdfasdf; +} + + int +func(a, b) + int a; + int c; +{ + if (c1 && (c2 || + c3)) + foo; + if (c1 && + (c2 || c3) + ) +} + +{ + while (asd) + { + if (asdf) + if (test) + if (that) + { + if (asdf) + do + cdasd; + while (as + df); + } + else + if (asdf) + asdf; + else + asdf; + asdf; + } +} + +{ + s = "/*"; b = ';' + s = "/*"; b = ';'; + a = b; +} + +{ + switch (a) + { + case a: + switch (t) + { + case 1: + cmd; + break; + case 2: + cmd; + break; + } + cmd; + break; + case b: + { + int i; + cmd; + } + break; + case c: { + int i; + cmd; + } + case d: if (cond && + test) { /* this line doesn't work right */ + int i; + cmd; + } + break; + } +} + +{ + if (!(vim_strchr(p_cpo, CPO_BUFOPTGLOB) != NULL && entering) && + (bp_to->b_p_initialized || + (!entering && vim_strchr(p_cpo, CPO_BUFOPT) != NULL))) + return; +label : + asdf = asdf ? + asdf : asdf; + asdf = asdf ? + asdf: asdf; +} + +/* Special Comments : This function has the added complexity (compared */ +/* : to addtolist) of having to check for a detail */ +/* : texture and add that to the list first. */ + +char *(array[100]) = { + "testje", + "foo", + "bar", +} + +enum soppie +{ +yes = 0, +no, +maybe +}; + +typedef enum soppie +{ +yes = 0, +no, +maybe +}; + +static enum +{ +yes = 0, +no, +maybe +} soppie; + +public static enum +{ +yes = 0, +no, +maybe +} soppie; + +static private enum +{ +yes = 0, +no, +maybe +} soppie; + +{ + int a, + b; +} + +{ + struct Type + { + int i; + char *str; + } var[] = + { + 0, "zero", + 1, "one", + 2, "two", + 3, "three" + }; + + float matrix[3][3] = + { + { + 0, + 1, + 2 + }, + { + 3, + 4, + 5 + }, + { + 6, + 7, + 8 + } + }; +} + +{ + /* blah ( blah */ + /* where does this go? */ + + /* blah ( blah */ + cmd; + + func(arg1, + /* comment */ + arg2); + a; + { + b; + { + c; /* Hey, NOW it indents?! */ + } + } + + { + func(arg1, + arg2, + arg3); + /* Hey, what am I doing here? Is this coz of the ","? */ + } +} + +main () +{ + if (cond) + { + a = b; + } + if (cond) { + a = c; + } + if (cond) + a = d; + return; +} + +{ + case 2: if (asdf && + asdfasdf) + aasdf; + a = 9; + case 3: if (asdf) + aasdf; + a = 9; + case 4: x = 1; + y = 2; + +label: if (asdf) + here; + +label: if (asdf && + asdfasdf) + { + } + +label: if (asdf && + asdfasdf) { + there; + } + +label: if (asdf && + asdfasdf) + there; +} + +{ + /* + hello with ":set comments= cino=c5" + */ + + /* + hello with ":set comments= cino=" + */ +} + + +{ + if (a < b) { + a = a + 1; + } else + a = a + 2; + + if (a) + do { + testing; + } while (asdfasdf); + a = b + 1; + asdfasdf +} + +{ +for ( int i = 0; + i < 10; i++ ) +{ +} + i = 0; +} + +class bob +{ + int foo() {return 1;} + int bar; +} + +main() +{ +while(1) +if (foo) +{ +bar; +} +else { +asdf; +} +misplacedline; +} + +{ + if (clipboard.state == SELECT_DONE + && ((row == clipboard.start.lnum + && col >= clipboard.start.col) + || row > clipboard.start.lnum)) +} + +{ +if (1) {i += 4;} +where_am_i; +return 0; +} + +{ +{ +} // sdf(asdf +if (asdf) +asd; +} + +{ +label1: +label2: +} + +{ +int fooRet = foo(pBar1, false /*fKB*/, + true /*fPTB*/, 3 /*nT*/, false /*fDF*/); +f() { +for ( i = 0; + i < m; + /* c */ i++ ) { +a = b; +} +} +} + +{ + f1(/*comment*/); + f2(); +} + +{ +do { +if (foo) { +} else +; +} while (foo); +foo(); // was wrong +} + +int x; // no extra indent because of the ; +void func() +{ +} + +char *tab[] = {"aaa", + "};", /* }; */ NULL} + int indented; +{} + +char *a[] = {"aaa", "bbb", + "ccc", NULL}; +// here + +char *tab[] = {"aaa", + "xx", /* xx */}; /* asdf */ +int not_indented; + +{ + do { + switch (bla) + { + case 1: if (foo) + bar; + } + } while (boo); + wrong; +} + +int foo, + bar; +int foo; + +#if defined(foo) \ + && defined(bar) +char * xx = "asdf\ + foo\ + bor"; +int x; + +char *foo = "asdf\ + asdf\ + asdf", + *bar; + +void f() +{ +#if defined(foo) \ + && defined(bar) +char *foo = "asdf\ + asdf\ + asdf", + *bar; + { + int i; +char *foo = "asdf\ + asdf\ + asdf", + *bar; + } +#endif +} +#endif + +int y; // comment + // comment + + // comment + +{ + Constructor(int a, + int b ) : BaseClass(a) + { + } +} + +void foo() +{ + char one, + two; + struct bla piet, + jan; + enum foo kees, + jannie; + static unsigned sdf, + krap; + unsigned int piet, + jan; + int + kees, + jan; +} + +{ + t(int f, + int d); // ) + d(); +} + +Constructor::Constructor(int a, + int b + ) : + BaseClass(a, + b, + c), + mMember(b), +{ +} + +Constructor::Constructor(int a, + int b ) : + BaseClass(a) +{ +} + +Constructor::Constructor(int a, + int b ) /*x*/ : /*x*/ BaseClass(a), + member(b) +{ +} + +A::A(int a, int b) +: aa(a), +bb(b), +cc(c) +{ +} + +class CAbc : + public BaseClass1, + protected BaseClass2 +{ + int Test() { return FALSE; } + int Test1() { return TRUE; } + + CAbc(int a, int b ) : + BaseClass(a) + { + switch(xxx) + { + case abc: + asdf(); + break; + + case 999: + baer(); + break; + } + } + +public: // <-- this was incoreectly indented before!! + void testfall(); +protected: + void testfall(); +}; + +class CAbc : public BaseClass1, + protected BaseClass2 +{ +}; + +static struct +{ + int a; + int b; +} variable[COUNT] = +{ + { + 123, + 456 + }, + { + 123, + 456 + } +}; + +static struct +{ + int a; + int b; +} variable[COUNT] = +{ + { 123, 456 }, + { 123, 456 } +}; + +void asdf() /* ind_maxparen may cause trouble here */ +{ + if ((0 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1)) break; +} + +foo() +{ + a = cond ? foo() : asdf + + asdf; + + a = cond ? + foo() : asdf + + asdf; +} + +int main(void) +{ + if (a) + if (b) + 2; + else 3; + next_line_of_code(); +} + +barry() +{ + Foo::Foo (int one, + int two) + : something(4) + {} +} + +barry() +{ + Foo::Foo (int one, int two) + : something(4) + {} +} + +Constructor::Constructor(int a, + int b + ) : + BaseClass(a, + b, + c), + mMember(b) +{ +} + int main () + { + if (lala) + do + ++(*lolo); + while (lili + && lele); + lulu; + } + +int main () +{ +switch (c) +{ +case 'c': if (cond) +{ +} +} +} + +main() +{ + (void) MyFancyFuasdfadsfnction( + argument); +} + +main() +{ + char foo[] = "/*"; + /* as + df */ + hello +} + +/* valid namespaces with normal indent */ +namespace +{ +{ + 111111111111; +} +} +namespace /* test */ +{ + 11111111111111111; +} +namespace // test +{ + 111111111111111111; +} +namespace +{ + 111111111111111111; +} +namespace test +{ + 111111111111111111; +} +namespace{ + 111111111111111111; +} +namespace test{ + 111111111111111111; +} +namespace { + 111111111111111111; +} +namespace test { + 111111111111111111; +namespace test2 { + 22222222222222222; +} +} + +/* invalid namespaces use block indent */ +namespace test test2 { + 111111111111111111111; +} +namespace11111111111 { + 111111111111; +} +namespace() { + 1111111111111; +} +namespace() +{ + 111111111111111111; +} +namespace test test2 +{ + 1111111111111111111; +} +namespace111111111 +{ + 111111111111111111; +} + +void getstring() { +/* Raw strings */ +const char* s = R"( + test { + # comment + field: 123 + } + )"; + } + +void getstring() { +const char* s = R"foo( + test { + # comment + field: 123 + } + )foo"; + } + +{ +int a[4] = { +[0] = 0, +[1] = 1, +[2] = 2, +[3] = 3, +}; +} + +{ +a = b[2] ++ 3; +} + +{ +if (1) +/* aaaaa +* bbbbb +*/ +a = 1; +} + +void func() +{ +switch (foo) +{ +case (bar): +if (baz()) +quux(); +break; +case (shmoo): +if (!bar) +{ +} +case (foo1): +switch (bar) +{ +case baz: +baz_f(); +break; +} +break; +default: +baz(); +baz(); +break; +} +} + +/* end of AUTO */ + +STARTTEST +:set tw=0 noai fo=croq +:let &wm = &columns - 20 +/serious/e +a about life, the universe, and the rest +ENDTEST + +{ + +/* this is + * a real serious important big + * comment + */ + /* insert " about life, the universe, and the rest" after "serious" */ +} + +STARTTEST +:set nocin +/comments +joabout life/happens +jothere/below +oline/this +Ohello +ENDTEST + +{ + /* + * Testing for comments, without 'cin' set + */ + +/* +* what happens here? +*/ + + /* + the end of the comment, try inserting a line below */ + + /* how about + this one */ +} + +STARTTEST +:set cin +/vec2 +== +ENDTEST + +{ + var = this + that + vec[0] * vec[0] + + vec[1] * vec[1] + + vec2[2] * vec[2]; +} + +STARTTEST +:set cin +:set cino=}4 +/testing1 +k2==/testing2 +k2== +ENDTEST + +{ + asdf asdflkajds f; + if (tes & ting) { + asdf asdf asdf ; + asdfa sdf asdf; + } + testing1; + if (tes & ting) + { + asdf asdf asdf ; + asdfa sdf asdf; + } + testing2; +} + +STARTTEST +:set cin +:set cino=(0,)20 +/main +=][ +ENDTEST + +main ( int first_par, /* + * Comment for + * first par + */ + int second_par /* + * Comment for + * second par + */ + ) +{ + func( first_par, /* + * Comment for + * first par + */ + second_par /* + * Comment for + * second par + */ + ); + +} + +STARTTEST +:set cin +:set cino=es,n0s +/main +=][ +ENDTEST + +main(void) +{ + /* Make sure that cino=X0s is not parsed like cino=Xs. */ + if (cond) + foo(); + else + { + bar(); + } +} + +STARTTEST +:set cin +:set cino= +]]=][ +ENDTEST + +{ + do + { + if () + { + if () + asdf; + else + asdf; + } + } while (); + cmd; /* this should go under the } */ +} + +STARTTEST +]]=][ +ENDTEST + +void f() +{ + if ( k() ) { + l(); + + } else { /* Start (two words) end */ + m(); + } + + n(); +} + +STARTTEST +:set cino={s,e-s +]]=][ +ENDTEST + +void f() +{ + if ( k() ) + { + l(); + } else { /* Start (two words) end */ + m(); + } + n(); /* should be under the if () */ +} + +STARTTEST +:set cino={s,fs +]]=/ foo +ENDTEST + +void bar(void) +{ + static array[2][2] = + { + { 1, 2 }, + { 3, 4 }, + } + + while (a) + { + foo(&a); + } + + { + int a; + { + a = a + 1; + } + } + b = a; + } + +void func(void) + { + a = 1; + { + b = 2; + } + c = 3; + d = 4; + } +/* foo */ + +STARTTEST +:set cino= +/while +ohere +ENDTEST + +a() +{ + do { + a = a + + a; + } while ( a ); /* add text under this line */ + if ( a ) + a; +} + +STARTTEST +:set cino= com= +/comment +olabel2: b();
label3 /* post */:
/* pre */ label4:
f(/*com*/);
if (/*com*/)
cmd(); +ENDTEST + +a() +{ +label1: + /* hmm */ + // comment +} + +STARTTEST +:set comments& comments^=s:/*,m:**,ex:*/ +/simple +=5j +ENDTEST + +/* + * A simple comment + */ + +/* + ** A different comment + */ + +STARTTEST +:set cino=c0 +:set comments& comments-=s1:/* comments^=s0:/* +2kdd]]=][ +ENDTEST + +void f() +{ + + /********* + A comment. +*********/ +} + +STARTTEST +:set cino=c0,C1 +:set comments& comments-=s1:/* comments^=s0:/* +2kdd]]=][ +ENDTEST + +void f() +{ + + /********* + A comment. +*********/ +} + +STARTTEST +:set cino= +]]=][ +ENDTEST + +void f() +{ + c = c1 && + ( + c2 || + c3 + ) && c4; +} + +STARTTEST +:set cino=(s +2kdd]]=][ +ENDTEST + +void f() +{ + c = c1 && + ( + c2 || + c3 + ) && c4; +} + +STARTTEST +:set cino=(s,U1 +2kdd]]=][ +ENDTEST + +void f() +{ + c = c1 && + ( + c2 || + c3 + ) && c4; +} + +STARTTEST +:set cino=(0 +2kdd]]=][ +ENDTEST + +void f() +{ + if ( c1 + && ( c2 + || c3)) + foo; +} + +STARTTEST +:set cino=(0,w1 +2kdd]]=][ +ENDTEST + +void f() +{ + if ( c1 + && ( c2 + || c3)) + foo; +} + +STARTTEST +:set cino=(s +2kdd]]=][ +ENDTEST + +void f() +{ + c = c1 && ( + c2 || + c3 + ) && c4; + if ( + c1 && c2 + ) + foo; +} + +STARTTEST +:set cino=(s,m1 +2kdd]]=][ +ENDTEST + +void f() +{ + c = c1 && ( + c2 || + c3 + ) && c4; + if ( + c1 && c2 + ) + foo; +} + +STARTTEST +:set cino=b1 +2kdd]]=][ +ENDTEST + +void f() +{ + switch (x) + { + case 1: + a = b; + break; + default: + a = 0; + break; + } +} + +STARTTEST +:set cino=(0,W5 +2kdd]]=][ +ENDTEST + +void f() +{ + invokeme( + argu, + ment); + invokeme( + argu, + ment + ); + invokeme(argu, + ment + ); +} + +STARTTEST +:set cino=/6 +2kdd]]=][ +ENDTEST + +void f() +{ + statement; + // comment 1 + // comment 2 +} + +STARTTEST +:set cino= +2kdd]]/comment 1/+1 +== +ENDTEST + +void f() +{ + statement; + // comment 1 + // comment 2 +} + +STARTTEST +:set cino=g0 +2kdd]]=][ +ENDTEST + +class CAbc +{ + int Test() { return FALSE; } + +public: // comment + void testfall(); +protected: + void testfall(); +}; + +STARTTEST +:set cino=(0,gs,hs +2kdd]]=][ +ENDTEST + +class Foo : public Bar +{ +public: +virtual void method1(void) = 0; +virtual void method2(int arg1, +int arg2, +int arg3) = 0; +}; + +STARTTEST +:set cino=+20 +2kdd]]=][ +ENDTEST + + void +foo() +{ + if (a) + { + } else + asdf; +} + +STARTTEST +:set cino=(0,W2s +2kdd]]=][ +ENDTEST + +{ + averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd( + asdasdf, + func(asdf, + asdfadsf), + asdfasdf + ); + + /* those are ugly, but consequent */ + + func()->asd(asdasdf, + averylongfunctionname( + abc, + dec)->averylongfunctionname( + asdfadsf, + asdfasdf, + asdfasdf, + ), + func(asdfadf, + asdfasdf + ), + asdasdf + ); + + averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf( + abc, + dec)->asdfasdfasdf( + asdfadsf, + asdfasdf, + asdfasdf, + ), + func(asdfadf, + asdfasdf), + asdasdf + ); +} + +STARTTEST +:set cino=M1 +2kdd]]=][ +ENDTEST + +int main () +{ + if (cond1 && + cond2 + ) + foo; +} + +STARTTEST +:set cino=(0,ts +2kdd2j=][ +ENDTEST + +void func(int a +#if defined(FOO) + , int b + , int c +#endif + ) +{ +} + +STARTTEST +:set cino=(0 +2kdd2j=][ +ENDTEST + +void +func(int a +#if defined(FOO) + , int b + , int c +#endif + ) +{ +} + +STARTTEST +:set cino& +2kdd2j=7][ +ENDTEST + +void func(void) +{ + if(x==y) + if(y==z) + foo=1; + else { bar=1; + baz=2; + } + printf("Foo!\n"); +} + +void func1(void) +{ + char* tab[] = {"foo", "bar", + "baz", "quux", + "this line used", "to be indented incorrectly"}; + foo(); +} + +void func2(void) +{ + int tab[] = + {1, 2, + 3, 4, + 5, 6}; + + printf("This line used to be indented incorrectly.\n"); +} + +int foo[] +#ifdef BAR + += { 1, 2, 3, + 4, 5, 6 } + +#endif +; + int baz; + +void func3(void) +{ + int tab[] = { + 1, 2, + 3, 4, + 5, 6}; + +printf("Don't you dare indent this line incorrectly!\n"); +} + +void +func4(a, b, + c) +int a; +int b; +int c; +{ +} + +void +func5( + int a, + int b) +{ +} + +void +func6( + int a) +{ +} + +STARTTEST +:set cino& +:set cino+=l1 +2kdd2j=][ +ENDTEST + +void func(void) +{ + int tab[] = + { + 1, 2, 3, + 4, 5, 6}; + + printf("Indent this line correctly!\n"); + + switch (foo) + { + case bar: + printf("bar"); + break; + case baz: { + printf("baz"); + break; + } + case quux: +printf("But don't break the indentation of this instruction\n"); +break; + } +} + +STARTTEST +:set cino& +2kdd2j=][ +ENDTEST + +void func(void) +{ + cout << "a" + << "b" + << ") :" + << "c"; +} + +STARTTEST +:set com=s1:/*,m:*,ex:*/ +]]3jofoo(); +ENDTEST + +void func(void) +{ + /* + * This is a comment. + */ +} + +STARTTEST +:set cino& +2kdd2j=][ +ENDTEST + +void func(void) +{ + for (int i = 0; i < 10; ++i) + if (i & 1) { + foo(1); + } else + foo(0); +baz(); +} + +STARTTEST +:set cino=k2s,(0 +2kdd3j=][ +ENDTEST + +void func(void) +{ + if (condition1 + && condition2) + action(); + function(argument1 + && argument2); + + if (c1 && (c2 || + c3)) + foo; + if (c1 && + (c2 || c3)) + { + } + + if ( c1 + && ( c2 + || c3)) + foo; + func( c1 + && ( c2 + || c3)) + foo; +} + +STARTTEST +:set cino=k2s,(s +2kdd3j=][ +ENDTEST + +void func(void) +{ + if (condition1 + && condition2) + action(); + function(argument1 + && argument2); + + if (c1 && (c2 || + c3)) + foo; + if (c1 && + (c2 || c3)) + { + } + + if ( c1 + && ( c2 + || c3)) + foo; + func( c1 + && ( c2 + || c3)) + foo; +} + +STARTTEST +:set cino=k2s,(s,U1 +2kdd3j=][ +ENDTEST + +void func(void) +{ + if (condition1 + && condition2) + action(); + function(argument1 + && argument2); + + if (c1 && (c2 || + c3)) + foo; + if (c1 && + (c2 || c3)) + { + } + if (c123456789 + && (c22345 + || c3)) + printf("foo\n"); + + c = c1 && + ( + c2 || + c3 + ) && c4; +} + +STARTTEST +:set cino=k2s,(0,W4 +2kdd3j=][ +ENDTEST + +void func(void) +{ + if (condition1 + && condition2) + action(); + function(argument1 + && argument2); + + if (c1 && (c2 || + c3)) + foo; + if (c1 && + (c2 || c3)) + { + } + if (c123456789 + && (c22345 + || c3)) + printf("foo\n"); + + if ( c1 + && ( c2 + || c3)) + foo; + + a_long_line( + argument, + argument); + a_short_line(argument, + argument); +} + +STARTTEST +:set cino=k2s,u2 +2kdd3j=][ +ENDTEST + +void func(void) +{ + if (condition1 + && condition2) + action(); + function(argument1 + && argument2); + + if (c1 && (c2 || + c3)) + foo; + if (c1 && + (c2 || c3)) + { + } + if (c123456789 + && (c22345 + || c3)) + printf("foo\n"); +} + +STARTTEST +:set cino=k2s,(0,w1 +2kdd3j=][ +ENDTEST + +void func(void) +{ + if (condition1 + && condition2) + action(); + function(argument1 + && argument2); + + if (c1 && (c2 || + c3)) + foo; + if (c1 && + (c2 || c3)) + { + } + if (c123456789 + && (c22345 + || c3)) + printf("foo\n"); + + if ( c1 + && ( c2 + || c3)) + foo; + func( c1 + && ( c2 + || c3)) + foo; +} + +STARTTEST +:set cino=k2,(s +2kdd3j=][ +ENDTEST + +void func(void) +{ + if (condition1 + && condition2) + action(); + function(argument1 + && argument2); + + if (c1 && (c2 || + c3)) + foo; + if (c1 && + (c2 || c3)) + { + } +} + +STARTTEST +:set cino=N-s +/^NAMESPACESTART +=/^NAMESPACEEND +ENDTEST + +NAMESPACESTART +/* valid namespaces with normal indent */ +namespace +{ + { + 111111111111; +} +} +namespace /* test */ +{ + 11111111111111111; +} +namespace // test +{ + 111111111111111111; +} +namespace +{ + 111111111111111111; +} +namespace test +{ + 111111111111111111; +} +namespace test::cpp17 +{ + 111111111111111111; +} +namespace ::incorrectcpp17 +{ + 111111111111111111; +} +namespace test::incorrectcpp17:: +{ + 111111111111111111; +} +namespace test:incorrectcpp17 +{ + 111111111111111111; +} +namespace test:::incorrectcpp17 +{ + 111111111111111111; +} +namespace{ + 111111111111111111; +} +namespace test{ + 111111111111111111; +} +namespace { + 111111111111111111; +} +namespace test { + 111111111111111111; +namespace test2 { + 22222222222222222; +} +} + +/* invalid namespaces use block indent */ +namespace test test2 { + 111111111111111111111; +} +namespace11111111111 { + 111111111111; +} +namespace() { + 1111111111111; +} +namespace() +{ + 111111111111111111; +} +namespace test test2 +{ + 1111111111111111111; +} +namespace111111111 +{ + 111111111111111111; +} +NAMESPACEEND + + +STARTTEST +:set cino=j1,J1 +/^JSSTART +=/^JSEND +ENDTEST + +JSSTART +var bar = { +foo: { +that: this, +some: ok, +}, +"bar":{ +a : 2, +b: "123abc", +x: 4, +"y": 5 +} +} +JSEND + +STARTTEST +:set cino=j1,J1 +/^JSSTART +=/^JSEND +ENDTEST + +JSSTART +var foo = [ +1, +2, +3 +]; +JSEND + +STARTTEST +:set cino=j1,J1 +/^JSSTART +=/^JSEND +ENDTEST + +JSSTART +function bar() { +var foo = [ +1, +2, +3 +]; +} +JSEND + +STARTTEST +:set cino=j1,J1 +/^JSSTART +=/^JSEND +ENDTEST + +JSSTART +(function($){ + +if (cond && +cond) { +stmt; +} +window.something.left = +(width - 50 + offset) + "px"; +var class_name='myclass'; + +function private_method() { +} + +var public_method={ +method: function(options,args){ +private_method(); +} +} + +function init(options) { + +$(this).data(class_name+'_public',$.extend({},{ +foo: 'bar', +bar: 2, +foobar: [ +1, +2, +3 +], +callback: function(){ +return true; +} +}, options||{})); +} + +$.fn[class_name]=function() { + +var _arguments=arguments; +return this.each(function(){ + +var options=$(this).data(class_name+'_public'); +if (!options) { +init.apply(this,_arguments); + +} else { +var method=public_method[_arguments[0]]; + +if (typeof(method)!='function') { +console.log(class_name+' has no method "'+_arguments[0]+'"'); +return false; +} +_arguments[0]=options; +method.apply(this,_arguments); +} +}); +} + +})(jQuery); +JSEND + +STARTTEST +:set cino=j1,J1 +/^JSSTART +=/^JSEND +ENDTEST + +JSSTART +function init(options) { +$(this).data(class_name+'_public',$.extend({},{ +foo: 'bar', +bar: 2, +foobar: [ +1, +2, +3 +], +callback: function(){ +return true; +} +}, options||{})); +} +JSEND + +STARTTEST +:set cino=j1,J1 +/^JSSTART +=/^JSEND +ENDTEST + +JSSTART +(function($){ +function init(options) { +$(this).data(class_name+'_public',$.extend({},{ +foo: 'bar', +bar: 2, +foobar: [ +1, +2, +3 +], +callback: function(){ +return true; +} +}, options||{})); +} +})(jQuery); +JSEND + +STARTTEST +:set cino=j1,J1,+2 +/^JSSTART +=/^JSEND +ENDTEST + +JSSTART +// Results of JavaScript indent +// 1 +(function(){ +var a = [ +'a', +'b', +'c', +'d', +'e', +'f', +'g', +'h', +'i' +]; +}()) + +// 2 +(function(){ +var a = [ +0 + +5 * +9 * +'a', +'b', +0 + +5 * +9 * +'c', +'d', +'e', +'f', +'g', +'h', +'i' +]; +}()) + +// 3 +(function(){ +var a = [ +0 + +// comment 1 +5 * +/* comment 2 */ +9 * +'a', +'b', +0 + +5 * +9 * +'c', +'d', +'e', +'f', +'g', +'h', +'i' +]; +}()) + +// 4 +{ +var a = [ +0, +1 +]; +var b; +var c; +} + +// 5 +{ +var a = [ +[ +0 +], +2, +3 +]; +} + +// 6 +{ +var a = [ +[ +0, +1 +], +2, +3 +]; +} + +// 7 +{ +var a = [ +// [ +0, +// 1 +// ], +2, +3 +]; +} + +// 8 +var x = [ +(function(){ +var a, +b, +c, +d, +e, +f, +g, +h, +i; +}) +]; + +// 9 +var a = [ +0 + +5 * +9 * +'a', +'b', +0 + +5 * +9 * +'c', +'d', +'e', +'f', +'g', +'h', +'i' +]; + +// 10 +var a, +b, +c, +d, +e, +f, +g, +h, +i; +JSEND + +STARTTEST +:set cin cino& +/start of define +=/end of define +ENDTEST + +/* start of define */ +{ +} +#define AAA \ +BBB\ +CCC + +#define CNT \ +1 + \ +2 + \ +4 +/* end of define */ + +STARTTEST +:set cin cino& +/a = second +ox +ENDTEST + +{ + a = second/*bug*/*line; +} + +STARTTEST +:g/^STARTTEST/.,/^ENDTEST/d +:1;/start of AUTO/,$wq! test.out +ENDTEST diff --git a/src/testdir/test3.ok b/src/testdir/test3.ok new file mode 100644 index 0000000..035ea39 --- /dev/null +++ b/src/testdir/test3.ok @@ -0,0 +1,2102 @@ +/* start of AUTO matically checked vim: set ts=4 : */ +{ + if (test) + cmd1; + cmd2; +} + +{ + if (test) + cmd1; + else + cmd2; +} + +{ + if (test) + { + cmd1; + cmd2; + } +} + +{ + if (test) + { + cmd1; + else + } +} + +{ + while (this) + if (test) + cmd1; + cmd2; +} + +{ + while (this) + if (test) + cmd1; + else + cmd2; +} + +{ + if (test) + { + cmd; + } + + if (test) + cmd; +} + +{ + if (test) { + cmd; + } + + if (test) cmd; +} + +{ + cmd1; + for (blah) + while (this) + if (test) + cmd2; + cmd3; +} + +{ + cmd1; + for (blah) + while (this) + if (test) + cmd2; + cmd3; + + if (test) + { + cmd1; + cmd2; + cmd3; + } +} + + +/* Test for 'cindent' do/while mixed with if/else: */ + +{ + do + if (asdf) + asdfasd; + while (cond); + + do + if (asdf) + while (asdf) + asdf; + while (asdf); +} + +/* Test for 'cindent' with two ) on a continuation line */ +{ + if (asdfasdf;asldkfj asdlkfj as;ldkfj sal;d + aal;sdkjf ( ;asldfkja;sldfk + al;sdjfka ;slkdf ) sa;ldkjfsa dlk;) + line up here; +} + + +/* C++ tests: */ + +// foo() these three lines should remain in column 0 +// { +// } + +/* Test for continuation and unterminated lines: */ +{ + i = 99 + 14325 + + 21345 + + 21345 + + 21345 + ( 21345 + + 21345) + + 2345 + + 1234; + c = 1; +} + +/* + testje for indent with empty line + + here */ + +{ + if (testing && + not a joke || + line up here) + hay; + if (testing && + (not a joke || testing + )line up here) + hay; + if (testing && + (not a joke || testing + line up here)) + hay; +} + + +{ + switch (c) + { + case xx: + do + if (asdf) + do + asdfasdf; + while (asdf); + else + asdfasdf; + while (cond); + case yy: + case xx: + case zz: + testing; + } +} + +{ + if (cond) { + foo; + } + else + { + bar; + } +} + +{ + if (alskdfj ;alsdkfjal;skdjf (;sadlkfsa ;dlkf j;alksdfj ;alskdjf + alsdkfj (asldk;fj + awith cino=(0 ;lf this one goes to below the paren with == + ;laksjfd ;lsakdjf ;alskdf asd) + asdfasdf;))) + asdfasdf; +} + + int +func(a, b) + int a; + int c; +{ + if (c1 && (c2 || + c3)) + foo; + if (c1 && + (c2 || c3) + ) +} + +{ + while (asd) + { + if (asdf) + if (test) + if (that) + { + if (asdf) + do + cdasd; + while (as + df); + } + else + if (asdf) + asdf; + else + asdf; + asdf; + } +} + +{ + s = "/*"; b = ';' + s = "/*"; b = ';'; + a = b; +} + +{ + switch (a) + { + case a: + switch (t) + { + case 1: + cmd; + break; + case 2: + cmd; + break; + } + cmd; + break; + case b: + { + int i; + cmd; + } + break; + case c: { + int i; + cmd; + } + case d: if (cond && + test) { /* this line doesn't work right */ + int i; + cmd; + } + break; + } +} + +{ + if (!(vim_strchr(p_cpo, CPO_BUFOPTGLOB) != NULL && entering) && + (bp_to->b_p_initialized || + (!entering && vim_strchr(p_cpo, CPO_BUFOPT) != NULL))) + return; +label : + asdf = asdf ? + asdf : asdf; + asdf = asdf ? + asdf: asdf; +} + +/* Special Comments : This function has the added complexity (compared */ +/* : to addtolist) of having to check for a detail */ +/* : texture and add that to the list first. */ + +char *(array[100]) = { + "testje", + "foo", + "bar", +} + +enum soppie +{ + yes = 0, + no, + maybe +}; + +typedef enum soppie +{ + yes = 0, + no, + maybe +}; + +static enum +{ + yes = 0, + no, + maybe +} soppie; + +public static enum +{ + yes = 0, + no, + maybe +} soppie; + +static private enum +{ + yes = 0, + no, + maybe +} soppie; + +{ + int a, + b; +} + +{ + struct Type + { + int i; + char *str; + } var[] = + { + 0, "zero", + 1, "one", + 2, "two", + 3, "three" + }; + + float matrix[3][3] = + { + { + 0, + 1, + 2 + }, + { + 3, + 4, + 5 + }, + { + 6, + 7, + 8 + } + }; +} + +{ + /* blah ( blah */ + /* where does this go? */ + + /* blah ( blah */ + cmd; + + func(arg1, + /* comment */ + arg2); + a; + { + b; + { + c; /* Hey, NOW it indents?! */ + } + } + + { + func(arg1, + arg2, + arg3); + /* Hey, what am I doing here? Is this coz of the ","? */ + } +} + +main () +{ + if (cond) + { + a = b; + } + if (cond) { + a = c; + } + if (cond) + a = d; + return; +} + +{ + case 2: if (asdf && + asdfasdf) + aasdf; + a = 9; + case 3: if (asdf) + aasdf; + a = 9; + case 4: x = 1; + y = 2; + +label: if (asdf) + here; + +label: if (asdf && + asdfasdf) + { + } + +label: if (asdf && + asdfasdf) { + there; + } + +label: if (asdf && + asdfasdf) + there; +} + +{ + /* + hello with ":set comments= cino=c5" + */ + + /* + hello with ":set comments= cino=" + */ +} + + +{ + if (a < b) { + a = a + 1; + } else + a = a + 2; + + if (a) + do { + testing; + } while (asdfasdf); + a = b + 1; + asdfasdf +} + +{ + for ( int i = 0; + i < 10; i++ ) + { + } + i = 0; +} + +class bob +{ + int foo() {return 1;} + int bar; +} + +main() +{ + while(1) + if (foo) + { + bar; + } + else { + asdf; + } + misplacedline; +} + +{ + if (clipboard.state == SELECT_DONE + && ((row == clipboard.start.lnum + && col >= clipboard.start.col) + || row > clipboard.start.lnum)) +} + +{ + if (1) {i += 4;} + where_am_i; + return 0; +} + +{ + { + } // sdf(asdf + if (asdf) + asd; +} + +{ +label1: +label2: +} + +{ + int fooRet = foo(pBar1, false /*fKB*/, + true /*fPTB*/, 3 /*nT*/, false /*fDF*/); + f() { + for ( i = 0; + i < m; + /* c */ i++ ) { + a = b; + } + } +} + +{ + f1(/*comment*/); + f2(); +} + +{ + do { + if (foo) { + } else + ; + } while (foo); + foo(); // was wrong +} + +int x; // no extra indent because of the ; +void func() +{ +} + +char *tab[] = {"aaa", + "};", /* }; */ NULL} + int indented; +{} + +char *a[] = {"aaa", "bbb", + "ccc", NULL}; +// here + +char *tab[] = {"aaa", + "xx", /* xx */}; /* asdf */ +int not_indented; + +{ + do { + switch (bla) + { + case 1: if (foo) + bar; + } + } while (boo); + wrong; +} + +int foo, + bar; +int foo; + +#if defined(foo) \ + && defined(bar) +char * xx = "asdf\ + foo\ + bor"; +int x; + +char *foo = "asdf\ + asdf\ + asdf", + *bar; + +void f() +{ +#if defined(foo) \ + && defined(bar) + char *foo = "asdf\ + asdf\ + asdf", + *bar; + { + int i; + char *foo = "asdf\ + asdf\ + asdf", + *bar; + } +#endif +} +#endif + +int y; // comment +// comment + +// comment + +{ + Constructor(int a, + int b ) : BaseClass(a) + { + } +} + +void foo() +{ + char one, + two; + struct bla piet, + jan; + enum foo kees, + jannie; + static unsigned sdf, + krap; + unsigned int piet, + jan; + int + kees, + jan; +} + +{ + t(int f, + int d); // ) + d(); +} + +Constructor::Constructor(int a, + int b + ) : + BaseClass(a, + b, + c), + mMember(b), +{ +} + +Constructor::Constructor(int a, + int b ) : + BaseClass(a) +{ +} + +Constructor::Constructor(int a, + int b ) /*x*/ : /*x*/ BaseClass(a), + member(b) +{ +} + +A::A(int a, int b) + : aa(a), + bb(b), + cc(c) +{ +} + +class CAbc : + public BaseClass1, + protected BaseClass2 +{ + int Test() { return FALSE; } + int Test1() { return TRUE; } + + CAbc(int a, int b ) : + BaseClass(a) + { + switch(xxx) + { + case abc: + asdf(); + break; + + case 999: + baer(); + break; + } + } + + public: // <-- this was incoreectly indented before!! + void testfall(); + protected: + void testfall(); +}; + +class CAbc : public BaseClass1, + protected BaseClass2 +{ +}; + +static struct +{ + int a; + int b; +} variable[COUNT] = +{ + { + 123, + 456 + }, + { + 123, + 456 + } +}; + +static struct +{ + int a; + int b; +} variable[COUNT] = +{ + { 123, 456 }, + { 123, 456 } +}; + +void asdf() /* ind_maxparen may cause trouble here */ +{ + if ((0 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1 + && 1)) break; +} + +foo() +{ + a = cond ? foo() : asdf + + asdf; + + a = cond ? + foo() : asdf + + asdf; +} + +int main(void) +{ + if (a) + if (b) + 2; + else 3; + next_line_of_code(); +} + +barry() +{ + Foo::Foo (int one, + int two) + : something(4) + {} +} + +barry() +{ + Foo::Foo (int one, int two) + : something(4) + {} +} + +Constructor::Constructor(int a, + int b + ) : + BaseClass(a, + b, + c), + mMember(b) +{ +} +int main () +{ + if (lala) + do + ++(*lolo); + while (lili + && lele); + lulu; +} + +int main () +{ + switch (c) + { + case 'c': if (cond) + { + } + } +} + +main() +{ + (void) MyFancyFuasdfadsfnction( + argument); +} + +main() +{ + char foo[] = "/*"; + /* as + df */ + hello +} + +/* valid namespaces with normal indent */ +namespace +{ + { + 111111111111; + } +} +namespace /* test */ +{ + 11111111111111111; +} +namespace // test +{ + 111111111111111111; +} +namespace +{ + 111111111111111111; +} +namespace test +{ + 111111111111111111; +} +namespace{ + 111111111111111111; +} +namespace test{ + 111111111111111111; +} +namespace { + 111111111111111111; +} +namespace test { + 111111111111111111; + namespace test2 { + 22222222222222222; + } +} + +/* invalid namespaces use block indent */ +namespace test test2 { + 111111111111111111111; +} +namespace11111111111 { + 111111111111; +} +namespace() { + 1111111111111; +} +namespace() +{ + 111111111111111111; +} +namespace test test2 +{ + 1111111111111111111; +} +namespace111111111 +{ + 111111111111111111; +} + +void getstring() { + /* Raw strings */ + const char* s = R"( + test { + # comment + field: 123 + } + )"; +} + +void getstring() { + const char* s = R"foo( + test { + # comment + field: 123 + } + )foo"; +} + +{ + int a[4] = { + [0] = 0, + [1] = 1, + [2] = 2, + [3] = 3, + }; +} + +{ + a = b[2] + + 3; +} + +{ + if (1) + /* aaaaa + * bbbbb + */ + a = 1; +} + +void func() +{ + switch (foo) + { + case (bar): + if (baz()) + quux(); + break; + case (shmoo): + if (!bar) + { + } + case (foo1): + switch (bar) + { + case baz: + baz_f(); + break; + } + break; + default: + baz(); + baz(); + break; + } +} + +/* end of AUTO */ + + +{ + +/* this is + * a real serious + * about life, the + * universe, and the + * rest important big + * comment + */ + /* insert " about life, the universe, and the rest" after "serious" */ +} + + +{ + /* + * Testing for comments, without 'cin' set + */ +about life + +/* +* what happens here? +*/ +there + + /* + the end of the comment, try inserting a line below */ +line + + /* how about +hello + this one */ +} + + +{ + var = this + that + vec[0] * vec[0] + + vec[1] * vec[1] + + vec2[2] * vec[2]; +} + + +{ + asdf asdflkajds f; + if (tes & ting) { + asdf asdf asdf ; + asdfa sdf asdf; + } + testing1; + if (tes & ting) + { + asdf asdf asdf ; + asdfa sdf asdf; + } + testing2; +} + + +main ( int first_par, /* + * Comment for + * first par + */ + int second_par /* + * Comment for + * second par + */ + ) +{ + func( first_par, /* + * Comment for + * first par + */ + second_par /* + * Comment for + * second par + */ + ); + +} + + +main(void) +{ + /* Make sure that cino=X0s is not parsed like cino=Xs. */ + if (cond) + foo(); + else + { + bar(); + } +} + + +{ + do + { + if () + { + if () + asdf; + else + asdf; + } + } while (); + cmd; /* this should go under the } */ +} + + +void f() +{ + if ( k() ) { + l(); + + } else { /* Start (two words) end */ + m(); + } + + n(); +} + + +void f() + { + if ( k() ) + { + l(); + } else { /* Start (two words) end */ + m(); + } + n(); /* should be under the if () */ +} + + +void bar(void) + { + static array[2][2] = + { + { 1, 2 }, + { 3, 4 }, + } + + while (a) + { + foo(&a); + } + + { + int a; + { + a = a + 1; + } + } + b = a; + } + +void func(void) + { + a = 1; + { + b = 2; + } + c = 3; + d = 4; + } +/* foo */ + + +a() +{ + do { + a = a + + a; + } while ( a ); /* add text under this line */ + here + if ( a ) + a; +} + + +a() +{ +label1: + /* hmm */ + // comment +label2: b(); +label3 /* post */: +/* pre */ label4: + f(/*com*/); + if (/*com*/) + cmd(); +} + + +/* + * A simple comment + */ + +/* +** A different comment +*/ + + +void f() +{ + + /********* + A comment. + *********/ +} + + +void f() +{ + + /********* + A comment. + *********/ +} + + +void f() +{ + c = c1 && + ( + c2 || + c3 + ) && c4; +} + + +void f() +{ + c = c1 && + ( + c2 || + c3 + ) && c4; +} + + +void f() +{ + c = c1 && + ( + c2 || + c3 + ) && c4; +} + + +void f() +{ + if ( c1 + && ( c2 + || c3)) + foo; +} + + +void f() +{ + if ( c1 + && ( c2 + || c3)) + foo; +} + + +void f() +{ + c = c1 && ( + c2 || + c3 + ) && c4; + if ( + c1 && c2 + ) + foo; +} + + +void f() +{ + c = c1 && ( + c2 || + c3 + ) && c4; + if ( + c1 && c2 + ) + foo; +} + + +void f() +{ + switch (x) + { + case 1: + a = b; + break; + default: + a = 0; + break; + } +} + + +void f() +{ + invokeme( + argu, + ment); + invokeme( + argu, + ment + ); + invokeme(argu, + ment + ); +} + + +void f() +{ + statement; + // comment 1 + // comment 2 +} + + +void f() +{ + statement; + // comment 1 + // comment 2 +} + + +class CAbc +{ + int Test() { return FALSE; } + +public: // comment + void testfall(); +protected: + void testfall(); +}; + + +class Foo : public Bar +{ + public: + virtual void method1(void) = 0; + virtual void method2(int arg1, + int arg2, + int arg3) = 0; +}; + + + void +foo() +{ + if (a) + { + } else + asdf; +} + + +{ + averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd( + asdasdf, + func(asdf, + asdfadsf), + asdfasdf + ); + + /* those are ugly, but consequent */ + + func()->asd(asdasdf, + averylongfunctionname( + abc, + dec)->averylongfunctionname( + asdfadsf, + asdfasdf, + asdfasdf, + ), + func(asdfadf, + asdfasdf + ), + asdasdf + ); + + averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf( + abc, + dec)->asdfasdfasdf( + asdfadsf, + asdfasdf, + asdfasdf, + ), + func(asdfadf, + asdfasdf), + asdasdf + ); +} + + +int main () +{ + if (cond1 && + cond2 + ) + foo; +} + + +void func(int a +#if defined(FOO) + , int b + , int c +#endif + ) +{ +} + + + void +func(int a +#if defined(FOO) + , int b + , int c +#endif + ) +{ +} + + +void func(void) +{ + if(x==y) + if(y==z) + foo=1; + else { bar=1; + baz=2; + } + printf("Foo!\n"); +} + +void func1(void) +{ + char* tab[] = {"foo", "bar", + "baz", "quux", + "this line used", "to be indented incorrectly"}; + foo(); +} + +void func2(void) +{ + int tab[] = + {1, 2, + 3, 4, + 5, 6}; + + printf("This line used to be indented incorrectly.\n"); +} + +int foo[] +#ifdef BAR + += { 1, 2, 3, + 4, 5, 6 } + +#endif + ; +int baz; + +void func3(void) +{ + int tab[] = { + 1, 2, + 3, 4, + 5, 6}; + + printf("Don't you dare indent this line incorrectly!\n"); +} + + void +func4(a, b, + c) + int a; + int b; + int c; +{ +} + + void +func5( + int a, + int b) +{ +} + + void +func6( + int a) +{ +} + + +void func(void) +{ + int tab[] = + { + 1, 2, 3, + 4, 5, 6}; + + printf("Indent this line correctly!\n"); + + switch (foo) + { + case bar: + printf("bar"); + break; + case baz: { + printf("baz"); + break; + } + case quux: + printf("But don't break the indentation of this instruction\n"); + break; + } +} + + +void func(void) +{ + cout << "a" + << "b" + << ") :" + << "c"; +} + + +void func(void) +{ + /* + * This is a comment. + */ + foo(); +} + + +void func(void) +{ + for (int i = 0; i < 10; ++i) + if (i & 1) { + foo(1); + } else + foo(0); + baz(); +} + + +void func(void) +{ + if (condition1 + && condition2) + action(); + function(argument1 + && argument2); + + if (c1 && (c2 || + c3)) + foo; + if (c1 && + (c2 || c3)) + { + } + + if ( c1 + && ( c2 + || c3)) + foo; + func( c1 + && ( c2 + || c3)) + foo; +} + + +void func(void) +{ + if (condition1 + && condition2) + action(); + function(argument1 + && argument2); + + if (c1 && (c2 || + c3)) + foo; + if (c1 && + (c2 || c3)) + { + } + + if ( c1 + && ( c2 + || c3)) + foo; + func( c1 + && ( c2 + || c3)) + foo; +} + + +void func(void) +{ + if (condition1 + && condition2) + action(); + function(argument1 + && argument2); + + if (c1 && (c2 || + c3)) + foo; + if (c1 && + (c2 || c3)) + { + } + if (c123456789 + && (c22345 + || c3)) + printf("foo\n"); + + c = c1 && + ( + c2 || + c3 + ) && c4; +} + + +void func(void) +{ + if (condition1 + && condition2) + action(); + function(argument1 + && argument2); + + if (c1 && (c2 || + c3)) + foo; + if (c1 && + (c2 || c3)) + { + } + if (c123456789 + && (c22345 + || c3)) + printf("foo\n"); + + if ( c1 + && ( c2 + || c3)) + foo; + + a_long_line( + argument, + argument); + a_short_line(argument, + argument); +} + + +void func(void) +{ + if (condition1 + && condition2) + action(); + function(argument1 + && argument2); + + if (c1 && (c2 || + c3)) + foo; + if (c1 && + (c2 || c3)) + { + } + if (c123456789 + && (c22345 + || c3)) + printf("foo\n"); +} + + +void func(void) +{ + if (condition1 + && condition2) + action(); + function(argument1 + && argument2); + + if (c1 && (c2 || + c3)) + foo; + if (c1 && + (c2 || c3)) + { + } + if (c123456789 + && (c22345 + || c3)) + printf("foo\n"); + + if ( c1 + && ( c2 + || c3)) + foo; + func( c1 + && ( c2 + || c3)) + foo; +} + + +void func(void) +{ + if (condition1 + && condition2) + action(); + function(argument1 + && argument2); + + if (c1 && (c2 || + c3)) + foo; + if (c1 && + (c2 || c3)) + { + } +} + + +NAMESPACESTART +/* valid namespaces with normal indent */ +namespace +{ +{ + 111111111111; +} +} +namespace /* test */ +{ +11111111111111111; +} +namespace // test +{ +111111111111111111; +} +namespace +{ +111111111111111111; +} +namespace test +{ +111111111111111111; +} +namespace test::cpp17 +{ +111111111111111111; +} +namespace ::incorrectcpp17 +{ + 111111111111111111; +} +namespace test::incorrectcpp17:: +{ + 111111111111111111; +} +namespace test:incorrectcpp17 +{ + 111111111111111111; +} +namespace test:::incorrectcpp17 +{ + 111111111111111111; +} +namespace{ +111111111111111111; +} +namespace test{ +111111111111111111; +} +namespace { +111111111111111111; +} +namespace test { +111111111111111111; +namespace test2 { +22222222222222222; +} +} + +/* invalid namespaces use block indent */ +namespace test test2 { + 111111111111111111111; +} +namespace11111111111 { + 111111111111; +} +namespace() { + 1111111111111; +} +namespace() +{ + 111111111111111111; +} +namespace test test2 +{ + 1111111111111111111; +} +namespace111111111 +{ + 111111111111111111; +} +NAMESPACEEND + + + +JSSTART +var bar = { + foo: { + that: this, + some: ok, + }, + "bar":{ + a : 2, + b: "123abc", + x: 4, + "y": 5 + } +} +JSEND + + +JSSTART +var foo = [ + 1, + 2, + 3 +]; +JSEND + + +JSSTART +function bar() { + var foo = [ + 1, + 2, + 3 + ]; +} +JSEND + + +JSSTART +(function($){ + + if (cond && + cond) { + stmt; + } + window.something.left = + (width - 50 + offset) + "px"; + var class_name='myclass'; + + function private_method() { + } + + var public_method={ + method: function(options,args){ + private_method(); + } + } + + function init(options) { + + $(this).data(class_name+'_public',$.extend({},{ + foo: 'bar', + bar: 2, + foobar: [ + 1, + 2, + 3 + ], + callback: function(){ + return true; + } + }, options||{})); + } + + $.fn[class_name]=function() { + + var _arguments=arguments; + return this.each(function(){ + + var options=$(this).data(class_name+'_public'); + if (!options) { + init.apply(this,_arguments); + + } else { + var method=public_method[_arguments[0]]; + + if (typeof(method)!='function') { + console.log(class_name+' has no method "'+_arguments[0]+'"'); + return false; + } + _arguments[0]=options; + method.apply(this,_arguments); + } + }); + } + +})(jQuery); +JSEND + + +JSSTART +function init(options) { + $(this).data(class_name+'_public',$.extend({},{ + foo: 'bar', + bar: 2, + foobar: [ + 1, + 2, + 3 + ], + callback: function(){ + return true; + } + }, options||{})); +} +JSEND + + +JSSTART +(function($){ + function init(options) { + $(this).data(class_name+'_public',$.extend({},{ + foo: 'bar', + bar: 2, + foobar: [ + 1, + 2, + 3 + ], + callback: function(){ + return true; + } + }, options||{})); + } +})(jQuery); +JSEND + + +JSSTART +// Results of JavaScript indent +// 1 +(function(){ + var a = [ + 'a', + 'b', + 'c', + 'd', + 'e', + 'f', + 'g', + 'h', + 'i' + ]; +}()) + +// 2 +(function(){ + var a = [ + 0 + + 5 * + 9 * + 'a', + 'b', + 0 + + 5 * + 9 * + 'c', + 'd', + 'e', + 'f', + 'g', + 'h', + 'i' + ]; +}()) + +// 3 +(function(){ + var a = [ + 0 + + // comment 1 + 5 * + /* comment 2 */ + 9 * + 'a', + 'b', + 0 + + 5 * + 9 * + 'c', + 'd', + 'e', + 'f', + 'g', + 'h', + 'i' + ]; +}()) + +// 4 +{ + var a = [ + 0, + 1 + ]; + var b; + var c; +} + +// 5 +{ + var a = [ + [ + 0 + ], + 2, + 3 + ]; +} + +// 6 +{ + var a = [ + [ + 0, + 1 + ], + 2, + 3 + ]; +} + +// 7 +{ + var a = [ + // [ + 0, + // 1 + // ], + 2, + 3 + ]; +} + +// 8 +var x = [ + (function(){ + var a, + b, + c, + d, + e, + f, + g, + h, + i; + }) +]; + +// 9 +var a = [ + 0 + + 5 * + 9 * + 'a', + 'b', + 0 + + 5 * + 9 * + 'c', + 'd', + 'e', + 'f', + 'g', + 'h', + 'i' +]; + +// 10 +var a, + b, + c, + d, + e, + f, + g, + h, + i; +JSEND + + +/* start of define */ +{ +} +#define AAA \ + BBB\ + CCC + +#define CNT \ + 1 + \ + 2 + \ + 4 +/* end of define */ + + +{ + a = second/*bug*/*line; + x +} + diff --git a/src/testdir/test30.in b/src/testdir/test30.in new file mode 100644 index 0000000..df49404 --- /dev/null +++ b/src/testdir/test30.in @@ -0,0 +1,238 @@ +Test for a lot of variations of the 'fileformats' option + +Note: This test will fail if "cat" is not available. + +STARTTEST +:so small.vim +:set belloff=all +:" first write three test files, one in each format +:set fileformat=unix +:set fileformats= +:/^unix/;/eof/-1w! XXUnix +:/^dos/;/eof/-1w! XXDos +:set bin noeol +:$w! XXMac +Gonoeol +:$w! XXEol +:set nobin eol +:enew! +:bwipe XXUnix XXDos XXMac +:" create mixed format files +:if has("vms") +: !copy XXUnix,XXDos XXUxDs. +: !copy XXUnix,XXMac XXUxMac. +: !copy XXDos,XXMac XXDosMac. +: !copy XXMac,XXEol XXMacEol. +: !copy XXUnix,XXDos,XXMac XXUxDsMc. +:elseif has("win32") +: !copy /b XXUnix+XXDos XXUxDs +: !copy /b XXUnix+XXMac XXUxMac +: !copy /b XXDos+XXMac XXDosMac +: !copy /b XXMac+XXEol XXMacEol +: !copy /b XXUnix+XXDos+XXMac XXUxDsMc +:else +: !cat XXUnix XXDos >XXUxDs +: !cat XXUnix XXMac >XXUxMac +: !cat XXDos XXMac >XXDosMac +: !cat XXMac XXEol >XXMacEol +: !cat XXUnix XXDos XXMac >XXUxDsMc +:endif +:" +:" try reading and writing with 'fileformats' empty +:set fileformat=unix +:e! XXUnix +:w! test.out +:e! XXDos +:w! XXtt01 +:e! XXMac +:w! XXtt02 +:bwipe XXUnix XXDos XXMac +:set fileformat=dos +:e! XXUnix +:w! XXtt11 +:e! XXDos +:w! XXtt12 +:e! XXMac +:w! XXtt13 +:bwipe XXUnix XXDos XXMac +:set fileformat=mac +:e! XXUnix +:w! XXtt21 +:e! XXDos +:w! XXtt22 +:e! XXMac +:w! XXtt23 +:bwipe XXUnix XXDos XXMac +:" +:" try reading and writing with 'fileformats' set to one format +:set fileformats=unix +:e! XXUxDsMc +:w! XXtt31 +:bwipe XXUxDsMc +:set fileformats=dos +:e! XXUxDsMc +:w! XXtt32 +:bwipe XXUxDsMc +:set fileformats=mac +:e! XXUxDsMc +:w! XXtt33 +:bwipe XXUxDsMc +:" +:" try reading and writing with 'fileformats' set to two formats +:set fileformats=unix,dos +:e! XXUxDsMc +:w! XXtt41 +:bwipe XXUxDsMc +:e! XXUxMac +:w! XXtt42 +:bwipe XXUxMac +:e! XXDosMac +:w! XXtt43 +:bwipe XXDosMac +:set fileformats=unix,mac +:e! XXUxDs +:w! XXtt51 +:bwipe XXUxDs +:e! XXUxDsMc +:w! XXtt52 +:bwipe XXUxDsMc +:e! XXDosMac +:w! XXtt53 +:bwipe XXDosMac +:e! XXEol +ggO=&ffs +:=&ff +:w! XXtt54 +:bwipe XXEol +:set fileformats=dos,mac +:e! XXUxDs +:w! XXtt61 +:bwipe XXUxDs +:e! XXUxMac +ggO=&ffs +:=&ff +:w! XXtt62 +:bwipe XXUxMac +:e! XXUxDsMc +:w! XXtt63 +:bwipe XXUxDsMc +:e! XXMacEol +ggO=&ffs +:=&ff +:w! XXtt64 +:bwipe XXMacEol +:" +:" try reading and writing with 'fileformats' set to three formats +:set fileformats=unix,dos,mac +:e! XXUxDsMc +:w! XXtt71 +:bwipe XXUxDsMc +:e! XXEol +ggO=&ffs +:=&ff +:w! XXtt72 +:bwipe XXEol +:set fileformats=mac,dos,unix +:e! XXUxDsMc +:w! XXtt81 +:bwipe XXUxDsMc +:e! XXEol +ggO=&ffs +:=&ff +:w! XXtt82 +:bwipe XXEol +:" try with 'binary' set +:set fileformats=mac,unix,dos +:set binary +:e! XXUxDsMc +:w! XXtt91 +:bwipe XXUxDsMc +:set fileformats=mac +:e! XXUxDsMc +:w! XXtt92 +:bwipe XXUxDsMc +:set fileformats=dos +:e! XXUxDsMc +:w! XXtt93 +:" +:" Append "END" to each file so that we can see what the last written char was. +:set fileformat=unix nobin +ggdGaEND:w >>XXtt01 +:w >>XXtt02 +:w >>XXtt11 +:w >>XXtt12 +:w >>XXtt13 +:w >>XXtt21 +:w >>XXtt22 +:w >>XXtt23 +:w >>XXtt31 +:w >>XXtt32 +:w >>XXtt33 +:w >>XXtt41 +:w >>XXtt42 +:w >>XXtt43 +:w >>XXtt51 +:w >>XXtt52 +:w >>XXtt53 +:w >>XXtt54 +:w >>XXtt61 +:w >>XXtt62 +:w >>XXtt63 +:w >>XXtt64 +:w >>XXtt71 +:w >>XXtt72 +:w >>XXtt81 +:w >>XXtt82 +:w >>XXtt91 +:w >>XXtt92 +:w >>XXtt93 +:" +:" Concatenate the results. +:" Make fileformat of test.out the native fileformat. +:" Add a newline at the end. +:set binary +:e! test.out +:$r XXtt01 +:$r XXtt02 +Go1:$r XXtt11 +:$r XXtt12 +:$r XXtt13 +Go2:$r XXtt21 +:$r XXtt22 +:$r XXtt23 +Go3:$r XXtt31 +:$r XXtt32 +:$r XXtt33 +Go4:$r XXtt41 +:$r XXtt42 +:$r XXtt43 +Go5:$r XXtt51 +:$r XXtt52 +:$r XXtt53 +:$r XXtt54 +Go6:$r XXtt61 +:$r XXtt62 +:$r XXtt63 +:$r XXtt64 +Go7:$r XXtt71 +:$r XXtt72 +Go8:$r XXtt81 +:$r XXtt82 +Go9:$r XXtt91 +:$r XXtt92 +:$r XXtt93 +Go10:$r XXUnix +:set nobinary ff& +:w +:qa! +ENDTEST + +unix +unix +eof + +dos
+dos
+eof + +mac
mac
diff --git a/src/testdir/test30.ok b/src/testdir/test30.ok new file mode 100644 index 0000000..b35f4f5 --- /dev/null +++ b/src/testdir/test30.ok @@ -0,0 +1,130 @@ +unix +unix +dos
+dos
+END +mac
mac
+END +1 +unix
+unix
+END +dos
+dos
+END +mac
mac
+END +2 +unix +unix +
END +dos
+dos
+
END +mac
mac
END +3 +unix +unix +dos
+dos
+mac
mac
+END +unix
+unix
+dos
+dos
+mac
mac
+END +unix +unix +dos
+dos
+mac
mac
END +4 +unix +unix +dos
+dos
+mac
mac
+END +unix +unix +mac
mac
+END +dos
+dos
+mac
mac
+END +5 +unix +unix +dos
+dos
+END +unix +unix +dos
+dos
+mac
mac
+END +dos
+dos
+mac
mac
END +unix,mac:unix +noeol +END +6 +unix
+unix
+dos
+dos
+END +dos,mac:dos
+unix
+unix
+mac
mac
+END +unix
+unix
+dos
+dos
+mac
mac
+END +dos,mac:mac
mac
mac
noeol
END +7 +unix +unix +dos
+dos
+mac
mac
+END +unix,dos,mac:unix +noeol +END +8 +unix +unix +dos
+dos
+mac
mac
+END +mac,dos,unix:mac
noeol
END +9 +unix +unix +dos
+dos
+mac
mac
END +unix +unix +dos
+dos
+mac
mac
END +unix +unix +dos
+dos
+mac
mac
END +10 +unix +unix diff --git a/src/testdir/test37.in b/src/testdir/test37.in new file mode 100644 index 0000000..8ca1125 --- /dev/null +++ b/src/testdir/test37.in @@ -0,0 +1,116 @@ +Test for 'scrollbind'. <eralston@computer.org> Do not add a line below! +STARTTEST +:so small.vim +:set noscrollbind +:set scrollopt=ver,jump +:set scrolloff=2 +:set nowrap +:set noequalalways +:set splitbelow +:" TEST using two windows open to one buffer, one extra empty window +:split +:new +t: +:resize 8 +/^start of window 1$/ +zt: +:set scrollbind +j: +:resize 7 +/^start of window 2$/ +zt: +:set scrollbind +:" -- start of tests -- +:" TEST scrolling down +L5jHyybpr0tHyybpr1tL6jHyybpr2kHyybpr3: +:" TEST scrolling up +tH4kjHtHyybpr4kHyybpr5k3ktHjHyybpr6tHyybpr7: +:" TEST horizontal scrolling +:set scrollopt+=hor +gg"zyyG"zpGt015zly$bp"zpGky$bp"zpG: +k10jH7zhg0y$bp"zpGtHg0y$bp"zpG: +:set scrollopt-=hor +:" ****** tests using two different buffers ***** +tj: +:close +t: +:set noscrollbind +:/^start of window 2$/,/^end of window 2$/y +:new +tj4"zpGp: +t/^start of window 1$/ +zt: +:set scrollbind +j: +/^start of window 2$/ +zt: +:set scrollbind +:" -- start of tests -- +:" TEST scrolling down +L5jHyybpr0tHyybpr1tL6jHyybpr2kHyybpr3: +:" TEST scrolling up +tH4kjHtHyybpr4kHyybpr5k3ktHjHyybpr6tHyybpr7: +:" TEST horizontal scrolling +:set scrollopt+=hor +gg"zyyG"zpGt015zly$bp"zpGky$bp"zpG: +k10jH7zhg0y$bp"zpGtHg0y$bp"zpG: +:set scrollopt-=hor +:" TEST syncbind +t:set noscb +ggLj:set noscb +ggL:set scb +t:set scb +GjG:syncbind +HktHjHyybptyybp: +t:set noscb +ggLj:set noscb +ggL:set scb +t:set scb +tGjGt:syncbind +HkjHtHyybptjyybp: +tH3kjHtHyybptjyybp: +:" ***** done with tests ***** +:w! test.out " Write contents of this file +:qa! +ENDTEST + + +start of window 1 +. line 01 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 01 +. line 02 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 02 +. line 03 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 03 +. line 04 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 04 +. line 05 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 05 +. line 06 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 06 +. line 07 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 07 +. line 08 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 08 +. line 09 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 09 +. line 10 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 10 +. line 11 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 11 +. line 12 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 12 +. line 13 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 13 +. line 14 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 14 +. line 15 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 15 +end of window 1 + + +start of window 2 +. line 01 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 01 +. line 02 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 02 +. line 03 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 03 +. line 04 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 04 +. line 05 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 05 +. line 06 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 06 +. line 07 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 07 +. line 08 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 08 +. line 09 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 09 +. line 10 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 10 +. line 11 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 11 +. line 12 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 12 +. line 13 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 13 +. line 14 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 14 +. line 15 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 15 +. line 16 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 16 +end of window 2 + +end of test37.in (please don't delete this line) diff --git a/src/testdir/test37.ok b/src/testdir/test37.ok new file mode 100644 index 0000000..d0b7485 --- /dev/null +++ b/src/testdir/test37.ok @@ -0,0 +1,33 @@ + +0 line 05 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 05 +1 line 05 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 05 +2 line 11 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 11 +3 line 11 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 11 +4 line 06 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 06 +5 line 06 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 06 +6 line 02 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 02 +7 line 02 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 02 +56789ABCDEFGHIJKLMNOPQRSTUVWXYZ 02 +UTSRQPONMLKJIHGREDCBA9876543210 02 +. line 11 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 11 +. line 11 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 11 + +0 line 05 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 05 +1 line 05 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 05 +2 line 11 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 11 +3 line 11 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 11 +4 line 06 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 06 +5 line 06 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 06 +6 line 02 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 02 +7 line 02 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 02 +56789ABCDEFGHIJKLMNOPQRSTUVWXYZ 02 +UTSRQPONMLKJIHGREDCBA9876543210 02 +. line 11 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 11 +. line 11 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 11 + +. line 16 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 16 +:set scrollbind +:set scrollbind +. line 16 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 16 +j: +. line 12 ZYXWVUTSRQPONMLKJIHGREDCBA9876543210 12 diff --git a/src/testdir/test39.in b/src/testdir/test39.in new file mode 100644 index 0000000..fcb935d --- /dev/null +++ b/src/testdir/test39.in @@ -0,0 +1,118 @@ + +Test Visual block mode commands +And test "U" in Visual mode, also on German sharp S. + +#define BO_ALL 0x0001 +#define BO_BS 0x0002 +#define BO_CRSR 0x0004 + +STARTTEST +:so small.vim +:so mbyte.vim +:" This only works when 'encoding' is "latin1", don't depend on the environment +:set enc=latin1 +/^abcde +:" Test shift-right of a block +jlllljj>wlljlll> +:" Test shift-left of a block +G$hhhhkk< +:" Test block-insert +GklkkkIxyz +:" Test block-replace +Gllllkkklllrq +:" Test block-change +G$khhhhhkkcmno +:$-4,$w! test.out +:" Test block-insert using cursor keys for movement +/^aaaa/ +:exe ":norm! l\<C-V>jjjlllI\<Right>\<Right> \<Esc>" +:/^aa/,/^$/w >> test.out +/xaaa$/ +:exe ":norm! \<C-V>jjjI<>\<Left>p\<Esc>" +:/xaaa$/,/^$/w >> test.out +:" Test for Visual block was created with the last <C-v>$ +/^A23$/ +:exe ":norm! l\<C-V>j$Aab\<Esc>" +:.,/^$/w >> test.out +:" Test for Visual block was created with the middle <C-v>$ (1) +/^B23$/ +:exe ":norm! l\<C-V>j$hAab\<Esc>" +:.,/^$/w >> test.out +:" Test for Visual block was created with the middle <C-v>$ (2) +/^C23$/ +:exe ":norm! l\<C-V>j$hhAab\<Esc>" +:.,/^$/w >> test.out +:" Test for Visual block insert when virtualedit=all and utf-8 encoding +:set ve=all enc=utf-8 +:/\t\tline +:exe ":norm! 07l\<C-V>jjIx\<Esc>" +:.,/^$/w >> test.out +:" Test for Visual block append when virtualedit=all +:exe ":norm! 012l\<C-v>jjAx\<Esc>" +:set ve= enc=latin1 +:.,/^$/w >> test.out +:" gUe must uppercase a whole word, also when changes to SS +Gothe youtueuu endYpk0wgUe +:" gUfx must uppercase until x, inclusive. +O- youtuexu -0fogUfx +:" VU must uppercase a whole line +YpkVU +:" same, when it's the last line in the buffer +YPGi111VUddP +:" Uppercase two lines +Oblah di +doh dutVkUj +:" Uppercase part of two lines +ddppi333k0i222fyllvjfuUk +:" visual replace using Enter or NL +G3o1234567892k05l2jr
G3o987652k02l2jr
+G3o1234567892k05l2jr +G3o987652k02l2jr +:" +:" Test cursor position. When ve=block and Visual block mode and $gj +:set ve=block +:exe ":norm! 2k\<C-V>$gj\<Esc>" +:let cpos=getpos("'>") +:$put ='col:'.cpos[2].' off:'.cpos[3] +:" +:" block_insert when replacing spaces in front of the block with tabs +:set ts=8 sts=4 sw=4 +:4,7y +Gp +:exe ":norm! f0\<C-V>2jI\<tab>\<esc>" +:/^the/,$w >> test.out +:qa! +ENDTEST + + line1 + line2 + line3 + +aaaaaa +bbbbbb +cccccc +dddddd + +xaaa +bbbb +cccc +dddd + +yaaa + +bbb + +A23 +4567 + +B23 +4567 + +C23 +4567 + +abcdefghijklm +abcdefghijklm +abcdefghijklm +abcdefghijklm +abcdefghijklm diff --git a/src/testdir/test39.ok b/src/testdir/test39.ok Binary files differnew file mode 100644 index 0000000..349d67f --- /dev/null +++ b/src/testdir/test39.ok diff --git a/src/testdir/test42.in b/src/testdir/test42.in Binary files differnew file mode 100644 index 0000000..c35569a --- /dev/null +++ b/src/testdir/test42.in diff --git a/src/testdir/test42.ok b/src/testdir/test42.ok Binary files differnew file mode 100644 index 0000000..183430d --- /dev/null +++ b/src/testdir/test42.ok diff --git a/src/testdir/test44.in b/src/testdir/test44.in new file mode 100644 index 0000000..7126392 --- /dev/null +++ b/src/testdir/test44.in @@ -0,0 +1,81 @@ +Tests for regexp with multi-byte encoding and various magic settings. +Test matchstr() with a count and multi-byte chars. +See test99 for exactly the same test with re=2. + +STARTTEST +:so mbyte.vim +:set nocompatible encoding=utf-8 termencoding=latin1 viminfo+=nviminfo +:set re=1 +/^1 +/a*b\{2}c\+/e +x/\Md\*e\{2}f\+/e +x:set nomagic +/g\*h\{2}i\+/e +x/\mj*k\{2}l\+/e +x/\vm*n{2}o+/e +x/\V^aa$ +x:set magic +/\v(a)(b)\2\1\1/e +x/\V[ab]\(\[xy]\)\1 +x:" Now search for multi-byte without composing char +/ม +x:" Now search for multi-byte with composing char +/ม่ +x:" find word by change of word class +/ち\<カヨ\>は +x:" Test \%u, [\u] and friends +:" c +/\%u20ac +x:" d +/[\u4f7f\u5929]\+ +x:" e +/\%U12345678 +x:" f +/[\U1234abcd\u1234\uabcd] +x:" g +/\%d21879b +x:" j Test backwards search from a multi-byte char +/x +x?. +x:" k +:let @w=':%s#comb[i]nations#œ̄ṣ́m̥̄ᾱ̆́#g' +:@w +:" +:" l Test what 7.3.192 fixed +/^l +:s/ \?/ /g +:?^1?,$w! test.out +:e! test.out +G:put =matchstr(\"אבגד\", \".\", 0, 2) " ב +:put =matchstr(\"אבגד\", \"..\", 0, 2) " בג +:put =matchstr(\"אבגד\", \".\", 0, 0) " א +:put =matchstr(\"אבגד\", \".\", 4, -1) " ג +:new +:$put =['dog(a', 'cat('] +/(/e+ +"ayn:bd! +:$put ='' +G"ap +:w! +:qa! +ENDTEST + +1 a aa abb abbccc +2 d dd dee deefff +3 g gg ghh ghhiii +4 j jj jkk jkklll +5 m mm mnn mnnooo +6 x ^aa$ x +7 (a)(b) abbaa +8 axx [ab]xx +9 หม่x อมx +a อมx หม่x +b ちカヨは +c x ¬€x +d 天使x +e y +f z +g a啷bb +j 0123❤x +k combinations +l äö üᾱ̆́ diff --git a/src/testdir/test44.ok b/src/testdir/test44.ok new file mode 100644 index 0000000..45774d7 --- /dev/null +++ b/src/testdir/test44.ok @@ -0,0 +1,25 @@ +1 a aa abb abbcc +2 d dd dee deeff +3 g gg ghh ghhii +4 j jj jkk jkkll +5 m mm mnn mnnoo +6 x aa$ x +7 (a)(b) abba +8 axx ab]xx +9 หม่x อx +a อมx หx +b カヨは +c x ¬x +d 使x +e y +f z +g abb +j 012❤ +k œ̄ṣ́m̥̄ᾱ̆́ + l ä ö ü ᾱ̆́ +ב +בג +א +ג +a +cat( diff --git a/src/testdir/test48.in b/src/testdir/test48.in new file mode 100644 index 0000000..d480f8c --- /dev/null +++ b/src/testdir/test48.in @@ -0,0 +1,83 @@ +This is a test of 'virtualedit'. + +STARTTEST +:so small.vim +:set noswf +:set ve=all +-dgg +:" +:" Insert "keyword keyw", ESC, C CTRL-N, shows "keyword ykeyword". +:" Repeating CTRL-N fixes it. (Mary Ellen Foster) +2/w +C +:" +:" Using "C" then then <CR> moves the last remaining character to the next +:" line. (Mary Ellen Foster) +j^/are +C
are belong to vim +:" +:" When past the end of a line that ends in a single character "b" skips +:" that word. +^$15lbC7 +:" +:" Make sure 'i' works +$4li<-- should be 3 ' ' +:" +:" Make sure 'C' works +$4lC<-- should be 3 ' ' +:" +:" Make sure 'a' works +$4la<-- should be 4 ' ' +:" +:" Make sure 'A' works +$4lA<-- should be 0 ' ' +:" +:" Make sure 'D' works +$4lDi<-- 'D' should be intact +:" +:" Test for yank bug reported by Mark Waggoner. +:set ve=block +^2w3jyGp +:" +:" Test "r" beyond the end of the line +:set ve=all +/^"r" +$5lrxa<-- should be 'x' +:" +:" Test "r" on a tab +:" Note that for this test, 'ts' must be 8 (the default). +^5lrxA<-- should be ' x ' +:" +:" Test to make sure 'x' can delete control characters +:set display=uhex +^xxxxxxi[This line should contain only the text between the brackets.] +:set display= +:" +:" Test for ^Y/^E due to bad w_virtcol value, reported by +:" Roy <royl@netropolis.net>. +^O3li4li4li <-- should show the name of a noted text editor +^o4li4li4li <-- and its version number-dd +:" +:" Test for yanking and pasting using the small delete register +gg/^foo +dewve"-p +:wq! test.out +ENDTEST +foo, bar +keyword keyw +all your base are belong to us +1 2 3 4 5 6 +'i' +'C' +'a' +'A' +'D' +this is a test +this is a test +this is a test +"r" +"r" +ab
sd +abcv6efi.him0kl + + diff --git a/src/testdir/test48.ok b/src/testdir/test48.ok new file mode 100644 index 0000000..14cd9b1 --- /dev/null +++ b/src/testdir/test48.ok @@ -0,0 +1,23 @@ +, foo +keyword keyword +all your base +are belong to vim +1 2 3 4 5 7 +'i' <-- should be 3 ' ' +'C' <-- should be 3 ' ' +'a' <-- should be 4 ' ' +'A'<-- should be 0 ' ' +'D' <-- 'D' should be intact +this is a test +this is a test +this is a test +"r" x<-- should be 'x' +"r" x <-- should be ' x ' +[This line should contain only the text between the brackets.] + v i m <-- should show the name of a noted text editor + 6 . 0 <-- and its version number + +a +a +a + diff --git a/src/testdir/test49.in b/src/testdir/test49.in new file mode 100644 index 0000000..79f13f6 --- /dev/null +++ b/src/testdir/test49.in @@ -0,0 +1,32 @@ +This is a test of the script language. + +If after adding a new test, the test output doesn't appear properly in +test49.failed, try to add one or more "G"s at the line ending in "test.out" + +STARTTEST +:so small.vim +:se nocp nomore viminfo+=nviminfo +:lang mess C +:so test49.vim +:" Go back to this file and append the results from register r. +:buf test49.in +G"rp:/^Results/,$w! test.out +:" +:" make valgrind happy +:redir => funclist +:silent func +:redir END +:for line in split(funclist, "\n") +: let name = matchstr(line, 'function \zs[A-Z]\w*\ze(') +: if name != '' +: exe "delfunc " . name +: endif +:endfor +:for v in keys(g:) +: silent! exe "unlet " . v +:endfor +:unlet v +:qa! +ENDTEST + +Results of test49.vim: diff --git a/src/testdir/test49.ok b/src/testdir/test49.ok new file mode 100644 index 0000000..50fc5d2 --- /dev/null +++ b/src/testdir/test49.ok @@ -0,0 +1,84 @@ +Results of test49.vim: +*** Test 16: OK (8722) +*** Test 17: OK (285127993) +*** Test 18: OK (67224583) +*** Test 19: OK (69275973) +*** Test 20: OK (1874575085) +*** Test 21: OK (147932225) +*** Test 22: OK (4161) +*** Test 23: OK (49) +*** Test 24: OK (41) +*** Test 25: OK (260177811) +*** Test 26: OK (1681500476) +*** Test 27: OK (1996459) +*** Test 28: OK (1996459) +*** Test 29: OK (170428555) +*** Test 30: OK (190905173) +*** Test 31: OK (190905173) +*** Test 32: OK (354833067) +--- Test 33: sum = 178275600 (ok) +*** Test 33: OK (1216907538) +*** Test 34: OK (2146584868) +*** Test 35: OK (2146584868) +*** Test 36: OK (1071644672) +*** Test 37: OK (1071644672) +*** Test 38: OK (357908480) +*** Test 39: OK (357908480) +*** Test 40: OK (357908480) +*** Test 41: OK (3076095) +*** Test 42: OK (1505155949) +*** Test 43: OK (1157763329) +*** Test 44: OK (1031761407) +*** Test 45: OK (1157763329) +*** Test 46: OK (739407) +*** Test 47: OK (371213935) +*** Test 48: OK (756255461) +*** Test 49: OK (179000669) +*** Test 50: OK (363550045) +*** Test 51: OK (40744667) +*** Test 52: OK (1247112011) +*** Test 53: OK (131071) +*** Test 54: OK (2047) +*** Test 55: OK (1023) +*** Test 56: OK (511) +*** Test 57: OK (2147450880) +*** Test 58: OK (624945) +*** Test 59: OK (2038431743) +*** Test 60: OK (311511339) +*** Test 61: OK (374889517) +*** Test 62: OK (286331153) +*** Test 63: OK (236978127) +*** Test 64: OK (1499645335) +*** Test 65: OK (70187) +*** Test 66: OK (5464) +*** Test 67: OK (212514423) +*** Test 68: OK (212514423) +*** Test 69: OK (8995471) +*** Test 70: OK (69544277) +*** Test 71: OK (34886997) +*** Test 72: OK (1789569365) +*** Test 73: OK (9032615) +*** Test 74: OK (224907669) +*** Test 75: OK (2000403408) +*** Test 76: OK (1610087935) +*** Test 77: OK (1388671) +*** Test 78: OK (134217728) +*** Test 79: OK (70288929) +*** Test 80: OK (17895765) +*** Test 81: OK (387) +*** Test 82: OK (8454401) +*** Test 83: OK (2835) +*** Test 84: OK (934782101) +*** Test 85: OK (198689) +--- Test 86: No Crash for vimgrep on BufUnload +*** Test 86: OK (0) +--- Test 87: 3 +--- Test 87: 5 +--- Test 87: abcdefghijk +--- Test 87: Successfully executed funcref Add2 +*** Test 87: OK (0) +--- Test 88: All tests were run with throwing exceptions on error. + The $VIMNOERRTHROW control is not configured. +--- Test 88: All tests were run with throwing exceptions on interrupt. + The $VIMNOINTTHROW control is not configured. +*** Test 88: OK (50443995) diff --git a/src/testdir/test49.vim b/src/testdir/test49.vim new file mode 100644 index 0000000..97088f0 --- /dev/null +++ b/src/testdir/test49.vim @@ -0,0 +1,9009 @@ +" Vim script language tests +" Author: Servatius Brandt <Servatius.Brandt@fujitsu-siemens.com> +" Last Change: 2019 Jan 13 + +"------------------------------------------------------------------------------- +" Test environment {{{1 +"------------------------------------------------------------------------------- + + +" Adding new tests easily. {{{2 +" +" Writing new tests is eased considerably with the following functions and +" abbreviations (see "Commands for recording the execution path", "Automatic +" argument generation"). +" +" To get the abbreviations, execute the command +" +" :let test49_set_env = 1 | source test49.vim +" +" To get them always (from src/testdir), put a line +" +" au! BufRead test49.vim let test49_set_env = 1 | source test49.vim +" +" into the local .vimrc file in the src/testdir directory. +" +if exists("test49_set_env") && test49_set_env + + " Automatic argument generation for the test environment commands. + + function! Xsum() + let addend = substitute(getline("."), '^.*"\s*X:\s*\|^.*', '', "") + " Evaluate arithmetic expression. + if addend != "" + exec "let g:Xsum = g:Xsum + " . addend + endif + endfunction + + function! Xcheck() + let g:Xsum=0 + ?XpathINIT?,.call Xsum() + exec "norm A " + return g:Xsum + endfunction + + iab Xcheck Xcheck<Space><C-R>=Xcheck()<CR><C-O>x + + function! Xcomment(num) + let str = "" + let tabwidth = &sts ? &sts : &ts + let tabs = (48+tabwidth - a:num - virtcol(".")) / tabwidth + while tabs > 0 + let str = str . "\t" + let tabs = tabs - 1 + endwhile + let str = str . '" X:' + return str + endfunction + + function! Xloop() + let back = line(".") . "|norm" . virtcol(".") . "|" + norm 0 + let last = search('X\(loop\|path\)INIT\|Xloop\>', "bW") + exec back + let theline = getline(last) + if theline =~ 'X\(loop\|path\)INIT' + let num = 1 + else + let num = 2 * substitute(theline, '.*Xloop\s*\(\d\+\).*', '\1', "") + endif + ?X\(loop\|path\)INIT? + \s/\(XloopINIT!\=\s*\d\+\s\+\)\@<=\(\d\+\)/\=2*submatch(2)/ + exec back + exec "norm a " + return num . Xcomment(strlen(num)) + endfunction + + iab Xloop Xloop<Space><C-R>=Xloop()<CR><C-O>x + + function! Xpath(loopinit) + let back = line(".") . "|norm" . virtcol(".") . "|" + norm 0 + let last = search('XpathINIT\|Xpath\>\|XloopINIT', "bW") + exec back + let theline = getline(last) + if theline =~ 'XpathINIT' + let num = 1 + elseif theline =~ 'Xpath\>' + let num = 2 * substitute(theline, '.*Xpath\s*\(\d\+\).*', '\1', "") + else + let pattern = '.*XloopINIT!\=\s*\(\d\+\)\s*\(\d\+\).*' + let num = substitute(theline, pattern, '\1', "") + let factor = substitute(theline, pattern, '\2', "") + " The "<C-O>x" from the "Xpath" iab and the character triggering its + " expansion are in the input buffer. Save and clear typeahead so + " that it is not read away by the call to "input()" below. Restore + " afterwards. + call inputsave() + let loops = input("Number of iterations in previous loop? ") + call inputrestore() + while (loops > 0) + let num = num * factor + let loops = loops - 1 + endwhile + endif + exec "norm a " + if a:loopinit + return num . " 1" + endif + return num . Xcomment(strlen(num)) + endfunction + + iab Xpath Xpath<Space><C-R>=Xpath(0)<CR><C-O>x + iab XloopINIT XloopINIT<Space><C-R>=Xpath(1)<CR><C-O>x + + " Also useful (see ExtraVim below): + aug ExtraVim + au! + au BufEnter <sfile> syn region ExtraVim + \ start=+^if\s\+ExtraVim(.*)+ end=+^endif+ + \ transparent keepend + au BufEnter <sfile> syn match ExtraComment /^"/ + \ contained containedin=ExtraVim + au BufEnter <sfile> hi link ExtraComment vimComment + aug END + + aug Xpath + au BufEnter <sfile> syn keyword Xpath + \ XpathINIT Xpath XloopINIT Xloop XloopNEXT Xcheck Xout + au BufEnter <sfile> hi link Xpath Special + aug END + + do BufEnter <sfile> + + " Do not execute the tests when sourcing this file for getting the functions + " and abbreviations above, which are intended for easily adding new test + " cases; they are not needed for test execution. Unlet the variable + " controlling this so that an explicit ":source" command for this file will + " execute the tests. + unlet test49_set_env + finish + +endif + + +" Commands for recording the execution path. {{{2 +" +" The Xpath/Xloop commands can be used for computing the eXecution path by +" adding (different) powers of 2 from those script lines, for which the +" execution should be checked. Xloop provides different addends for each +" execution of a loop. Permitted values are 2^0 to 2^30, so that 31 execution +" points (multiply counted inside loops) can be tested. +" +" Note that the arguments of the following commands can be generated +" automatically, see below. +" +" Usage: {{{3 +" +" - Use XpathINIT at the beginning of the test. +" +" - Use Xpath to check if a line is executed. +" Argument: power of 2 (decimal). +" +" - To check multiple execution of loops use Xloop for automatically +" computing Xpath values: +" +" - Use XloopINIT before the loop. +" Two arguments: +" - the first Xpath value (power of 2) to be used (Xnext), +" - factor for computing a new Xnext value when reexecuting a loop +" (by a ":continue" or ":endwhile"); this should be 2^n where +" n is the number of Xloop commands inside the loop. +" If XloopINIT! is used, the first execution of XloopNEXT is +" a no-operation. +" +" - Use Xloop inside the loop: +" One argument: +" The argument and the Xnext value are multiplied to build the +" next Xpath value. No new Xnext value is prepared. The argument +" should be 2^(n-1) for the nth Xloop command inside the loop. +" If the loop has only one Xloop command, the argument can be +" ommitted (default: 1). +" +" - Use XloopNEXT before ":continue" and ":endwhile". This computes a new +" Xnext value for the next execution of the loop by multiplying the old +" one with the factor specified in the XloopINIT command. No Argument. +" Alternatively, when XloopINIT! is used, a single XloopNEXT at the +" beginning of the loop can be used. +" +" Nested loops are not supported. +" +" - Use Xcheck at end of each test. It prints the test number, the expected +" execution path value, the test result ("OK" or "FAIL"), and, if the tests +" fails, the actual execution path. +" One argument: +" Expected Xpath/Xloop sum for the correct execution path. +" In order that this value can be computed automatically, do the +" following: For each line in the test with an Xpath and Xloop +" command, add a comment starting with "X:" and specifying an +" expression that evaluates to the value contributed by this line to +" the correct execution path. (For copying an Xpath argument of at +" least two digits into the comment, press <C-P>.) At the end of the +" test, just type "Xcheck" and press <Esc>. +" +" - In order to add additional information to the test output file, use the +" Xout command. Argument(s) like ":echo". +" +" Automatic argument generation: {{{3 +" +" The arguments of the Xpath, XloopINIT, Xloop, and Xcheck commands can be +" generated automatically, so that new tests can easily be written without +" mental arithmetic. The Xcheck argument is computed from the "X:" comments +" of the preceding Xpath and Xloop commands. See the commands and +" abbreviations at the beginning of this file. +" +" Implementation: {{{3 +" XpathINIT, Xpath, XloopINIT, Xloop, XloopNEXT, Xcheck, Xout. +" +" The variants for existing g:ExtraVimResult are needed when executing a script +" in an extra Vim process, see ExtraVim below. + +" EXTRA_VIM_START - do not change or remove this line. + +com! XpathINIT let g:Xpath = 0 + +if exists("g:ExtraVimResult") + com! -count -bar Xpath exec "!echo <count> >>" . g:ExtraVimResult +else + com! -count -bar Xpath let g:Xpath = g:Xpath + <count> +endif + +com! -count -nargs=1 -bang + \ XloopINIT let g:Xnext = <count> | + \ let g:Xfactor = <args> | + \ let g:Xskip = strlen("<bang>") + +if exists("g:ExtraVimResult") + com! -count=1 -bar Xloop exec "!echo " . (g:Xnext * <count>) . " >>" . + \ g:ExtraVimResult +else + com! -count=1 -bar Xloop let g:Xpath = g:Xpath + g:Xnext * <count> +endif + +com! XloopNEXT let g:Xnext = g:Xnext * + \ (g:Xskip ? 1 : g:Xfactor) | + \ let g:Xskip = 0 + +let @r = "" +let Xtest = 1 +com! -count Xcheck let Xresult = "*** Test " . + \ (Xtest<10?" ":Xtest<100?" ":"") . + \ Xtest . ": " . ( + \ (Xpath==<count>) ? "OK (".Xpath.")" : + \ "FAIL (".Xpath." instead of <count>)" + \ ) | + \ let @R = Xresult . "\n" | + \ echo Xresult | + \ let Xtest = Xtest + 1 + +if exists("g:ExtraVimResult") + com! -nargs=+ Xoutq exec "!echo @R:'" . + \ substitute(substitute(<q-args>, + \ "'", '&\\&&', "g"), "\n", "@NL@", "g") + \ . "' >>" . g:ExtraVimResult +else + com! -nargs=+ Xoutq let @R = "--- Test " . + \ (g:Xtest<10?" ":g:Xtest<100?" ":"") . + \ g:Xtest . ": " . substitute(<q-args>, + \ "\n", "&\t ", "g") . "\n" +endif +com! -nargs=+ Xout exec 'Xoutq' <args> + +" Switch off storing of lines for undoing changes. Speeds things up a little. +set undolevels=-1 + +" EXTRA_VIM_STOP - do not change or remove this line. + + +" ExtraVim() - Run a script file in an extra Vim process. {{{2 +" +" This is useful for testing immediate abortion of the script processing due to +" an error in a command dynamically enclosed by a :try/:tryend region or when an +" exception is thrown but not caught or when an interrupt occurs. It can also +" be used for testing :finish. +" +" An interrupt location can be specified by an "INTERRUPT" comment. A number +" telling how often this location is reached (in a loop or in several function +" calls) should be specified as argument. When missing, once per script +" invocation or function call is assumed. INTERRUPT locations are tested by +" setting a breakpoint in that line and using the ">quit" debug command when +" the breakpoint is reached. A function for which an INTERRUPT location is +" specified must be defined before calling it (or executing it as a script by +" using ExecAsScript below). +" +" This function is only called in normal modus ("g:ExtraVimResult" undefined). +" +" Tests to be executed as an extra script should be written as follows: +" +" column 1 column 1 +" | | +" v v +" +" XpathINIT XpathINIT +" if ExtraVim() if ExtraVim() +" ... " ... +" ... " ... +" endif endif +" Xcheck <number> Xcheck <number> +" +" Double quotes in column 1 are removed before the script is executed. +" They should be used if the test has unbalanced conditionals (:if/:endif, +" :while:/endwhile, :try/:endtry) or for a line with a syntax error. The +" extra script may use Xpath, XloopINIT, Xloop, XloopNEXT, and Xout as usual. +" +" A file name may be specified as argument. All messages of the extra Vim +" process are then redirected to the file. An existing file is overwritten. +" +let ExtraVimCount = 0 +let ExtraVimBase = expand("<sfile>") +let ExtraVimTestEnv = "" +" +function ExtraVim(...) + " Count how often this function is called. + let g:ExtraVimCount = g:ExtraVimCount + 1 + + " Disable folds to prevent that the ranges in the ":write" commands below + " are extended up to the end of a closed fold. This also speeds things up + " considerably. + set nofoldenable + + " Open a buffer for this test script and copy the test environment to + " a temporary file. Take account of parts relevant for the extra script + " execution only. + let current_buffnr = bufnr("%") + execute "view +1" g:ExtraVimBase + if g:ExtraVimCount == 1 + let g:ExtraVimTestEnv = tempname() + execute "/E" . "XTRA_VIM_START/+,/E" . "XTRA_VIM_STOP/-w" + \ g:ExtraVimTestEnv "|']+" + execute "/E" . "XTRA_VIM_START/+,/E" . "XTRA_VIM_STOP/-w >>" + \ g:ExtraVimTestEnv "|']+" + execute "/E" . "XTRA_VIM_START/+,/E" . "XTRA_VIM_STOP/-w >>" + \ g:ExtraVimTestEnv "|']+" + execute "/E" . "XTRA_VIM_START/+,/E" . "XTRA_VIM_STOP/-w >>" + \ g:ExtraVimTestEnv "|']+" + endif + + " Start the extra Vim script with a ":source" command for the test + " environment. The source line number where the extra script will be + " appended, needs to be passed as variable "ExtraVimBegin" to the script. + let extra_script = tempname() + exec "!echo 'source " . g:ExtraVimTestEnv . "' >" . extra_script + let extra_begin = 1 + + " Starting behind the test environment, skip over the first g:ExtraVimCount + " occurrences of "if ExtraVim()" and copy the following lines up to the + " matching "endif" to the extra Vim script. + execute "/E" . "ND_OF_TEST_ENVIRONMENT/" + exec 'norm ' . g:ExtraVimCount . '/^\s*if\s\+ExtraVim(.*)/+' . "\n" + execute ".,/^endif/-write >>" . extra_script + + " Open a buffer for the extra Vim script, delete all ^", and write the + " script if was actually modified. + execute "edit +" . (extra_begin + 1) extra_script + ,$s/^"//e + update + + " Count the INTERRUPTs and build the breakpoint and quit commands. + let breakpoints = "" + let debug_quits = "" + let in_func = 0 + exec extra_begin + while search( + \ '"\s*INTERRUPT\h\@!\|^\s*fu\%[nction]\>!\=\s*\%(\u\|s:\)\w*\s*(\|' + \ . '^\s*\\\|^\s*endf\%[unction]\>\|' + \ . '\%(^\s*fu\%[nction]!\=\s*\)\@<!\%(\u\|s:\)\w*\s*(\|' + \ . 'ExecAsScript\s\+\%(\u\|s:\)\w*', + \ "W") > 0 + let theline = getline(".") + if theline =~ '^\s*fu' + " Function definition. + let in_func = 1 + let func_start = line(".") + let func_name = substitute(theline, + \ '^\s*fu\%[nction]!\=\s*\(\%(\u\|s:\)\w*\).*', '\1', "") + elseif theline =~ '^\s*endf' + " End of function definition. + let in_func = 0 + else + let finding = substitute(theline, '.*\(\%' . col(".") . 'c.*\)', + \ '\1', "") + if finding =~ '^"\s*INTERRUPT\h\@!' + " Interrupt comment. Compose as many quit commands as + " specified. + let cnt = substitute(finding, + \ '^"\s*INTERRUPT\s*\(\d*\).*$', '\1', "") + let quits = "" + while cnt > 0 + " Use "\r" rather than "\n" to separate the quit commands. + " "\r" is not interpreted as command separator by the ":!" + " command below but works to separate commands in the + " external vim. + let quits = quits . "q\r" + let cnt = cnt - 1 + endwhile + if in_func + " Add the function breakpoint and note the number of quits + " to be used, if specified, or one for every call else. + let breakpoints = breakpoints . " -c 'breakadd func " . + \ (line(".") - func_start) . " " . + \ func_name . "'" + if quits != "" + let debug_quits = debug_quits . quits + elseif !exists("quits{func_name}") + let quits{func_name} = "q\r" + else + let quits{func_name} = quits{func_name} . "q\r" + endif + else + " Add the file breakpoint and the quits to be used for it. + let breakpoints = breakpoints . " -c 'breakadd file " . + \ line(".") . " " . extra_script . "'" + if quits == "" + let quits = "q\r" + endif + let debug_quits = debug_quits . quits + endif + else + " Add the quits to be used for calling the function or executing + " it as script file. + if finding =~ '^ExecAsScript' + " Sourcing function as script. + let finding = substitute(finding, + \ '^ExecAsScript\s\+\(\%(\u\|s:\)\w*\).*', '\1', "") + else + " Function call. + let finding = substitute(finding, + \ '^\(\%(\u\|s:\)\w*\).*', '\1', "") + endif + if exists("quits{finding}") + let debug_quits = debug_quits . quits{finding} + endif + endif + endif + endwhile + + " Close the buffer for the script and create an (empty) resultfile. + bwipeout + let resultfile = tempname() + exec "!>" . resultfile + + " Run the script in an extra vim. Switch to extra modus by passing the + " resultfile in ExtraVimResult. Redirect messages to the file specified as + " argument if any. Use ":debuggreedy" so that the commands provided on the + " pipe are consumed at the debug prompt. Use "-N" to enable command-line + " continuation ("C" in 'cpo'). Add "nviminfo" to 'viminfo' to avoid + " messing up the user's viminfo file. + let redirect = a:0 ? + \ " -c 'au VimLeave * redir END' -c 'redir\\! >" . a:1 . "'" : "" + exec "!echo '" . debug_quits . "q' | ../vim -u NONE -N -Xes" . redirect . + \ " -c 'debuggreedy|set viminfo+=nviminfo'" . + \ " -c 'let ExtraVimBegin = " . extra_begin . "'" . + \ " -c 'let ExtraVimResult = \"" . resultfile . "\"'" . breakpoints . + \ " -S " . extra_script + + " Build the resulting sum for resultfile and add it to g:Xpath. Add Xout + " information provided by the extra Vim process to the test output. + let sum = 0 + exec "edit" resultfile + let line = 1 + while line <= line("$") + let theline = getline(line) + if theline =~ '^@R:' + exec 'Xout "' . substitute(substitute( + \ escape(escape(theline, '"'), '\"'), + \ '^@R:', '', ""), '@NL@', "\n", "g") . '"' + else + let sum = sum + getline(line) + endif + let line = line + 1 + endwhile + bwipeout + let g:Xpath = g:Xpath + sum + + " Delete the extra script and the resultfile. + call delete(extra_script) + call delete(resultfile) + + " Switch back to the buffer that was active when this function was entered. + exec "buffer" current_buffnr + + " Return 0. This protects extra scripts from being run in the main Vim + " process. + return 0 +endfunction + + +" ExtraVimThrowpoint() - Relative throwpoint in ExtraVim script {{{2 +" +" Evaluates v:throwpoint and returns the throwpoint relative to the beginning of +" an ExtraVim script as passed by ExtraVim() in ExtraVimBegin. +" +" EXTRA_VIM_START - do not change or remove this line. +function ExtraVimThrowpoint() + if !exists("g:ExtraVimBegin") + Xout "ExtraVimThrowpoint() used outside ExtraVim() script." + return v:throwpoint + endif + + if v:throwpoint =~ '^function\>' + return v:throwpoint + endif + + return "line " . + \ (substitute(v:throwpoint, '.*, line ', '', "") - g:ExtraVimBegin) . + \ " of ExtraVim() script" +endfunction +" EXTRA_VIM_STOP - do not change or remove this line. + + +" MakeScript() - Make a script file from a function. {{{2 +" +" Create a script that consists of the body of the function a:funcname. +" Replace any ":return" by a ":finish", any argument variable by a global +" variable, and and every ":call" by a ":source" for the next following argument +" in the variable argument list. This function is useful if similar tests are +" to be made for a ":return" from a function call or a ":finish" in a script +" file. +" +" In order to execute a function specifying an INTERRUPT location (see ExtraVim) +" as a script file, use ExecAsScript below. +" +" EXTRA_VIM_START - do not change or remove this line. +function MakeScript(funcname, ...) + let script = tempname() + execute "redir! >" . script + execute "function" a:funcname + redir END + execute "edit" script + " Delete the "function" and the "endfunction" lines. Do not include the + " word "function" in the pattern since it might be translated if LANG is + " set. When MakeScript() is being debugged, this deletes also the debugging + " output of its line 3 and 4. + exec '1,/.*' . a:funcname . '(.*)/d' + /^\d*\s*endfunction\>/,$d + %s/^\d*//e + %s/return/finish/e + %s/\<a:\(\h\w*\)/g:\1/ge + normal gg0 + let cnt = 0 + while search('\<call\s*\%(\u\|s:\)\w*\s*(.*)', 'W') > 0 + let cnt = cnt + 1 + s/\<call\s*\%(\u\|s:\)\w*\s*(.*)/\='source ' . a:{cnt}/ + endwhile + g/^\s*$/d + write + bwipeout + return script +endfunction +" EXTRA_VIM_STOP - do not change or remove this line. + + +" ExecAsScript - Source a temporary script made from a function. {{{2 +" +" Make a temporary script file from the function a:funcname, ":source" it, and +" delete it afterwards. +" +" When inside ":if ExtraVim()", add a file breakpoint for each INTERRUPT +" location specified in the function. +" +" EXTRA_VIM_START - do not change or remove this line. +function ExecAsScript(funcname) + " Make a script from the function passed as argument. + let script = MakeScript(a:funcname) + + " When running in an extra Vim process, add a file breakpoint for each + " function breakpoint set when the extra Vim process was invoked by + " ExtraVim(). + if exists("g:ExtraVimResult") + let bplist = tempname() + execute "redir! >" . bplist + breaklist + redir END + execute "edit" bplist + " Get the line number from the function breakpoint. Works also when + " LANG is set. + execute 'v/^\s*\d\+\s\+func\s\+' . a:funcname . '\s.*/d' + %s/^\s*\d\+\s\+func\s\+\%(\u\|s:\)\w*\s\D*\(\d*\).*/\1/e + let cnt = 0 + while cnt < line("$") + let cnt = cnt + 1 + if getline(cnt) != "" + execute "breakadd file" getline(cnt) script + endif + endwhile + bwipeout! + call delete(bplist) + endif + + " Source and delete the script. + exec "source" script + call delete(script) +endfunction + +com! -nargs=1 -bar ExecAsScript call ExecAsScript(<f-args>) +" EXTRA_VIM_STOP - do not change or remove this line. + + +" END_OF_TEST_ENVIRONMENT - do not change or remove this line. + + +" Tests 1 to 15 were moved to test_vimscript.vim +let Xtest = 16 + +"------------------------------------------------------------------------------- +" Test 16: Double :else or :elseif after :else {{{1 +" +" Multiple :elses or an :elseif after an :else are forbidden. +"------------------------------------------------------------------------------- + +XpathINIT + +function! F() abort + if 0 + Xpath 1 " X: 0 + else + Xpath 2 " X: 2 + else " aborts function + Xpath 4 " X: 0 + endif +endfunction + +function! G() abort + if 0 + Xpath 8 " X: 0 + else + Xpath 16 " X: 16 + elseif 1 " aborts function + Xpath 32 " X: 0 + else + Xpath 64 " X: 0 + endif +endfunction + +function! H() abort + if 0 + Xpath 128 " X: 0 + elseif 0 + Xpath 256 " X: 0 + else + Xpath 512 " X: 512 + else " aborts function + Xpath 1024 " X: 0 + endif +endfunction + +function! I() abort + if 0 + Xpath 2048 " X: 0 + elseif 0 + Xpath 4096 " X: 0 + else + Xpath 8192 " X: 8192 + elseif 1 " aborts function + Xpath 16384 " X: 0 + else + Xpath 32768 " X: 0 + endif +endfunction + +call F() +call G() +call H() +call I() + +delfunction F +delfunction G +delfunction H +delfunction I + +Xcheck 8722 + + +"------------------------------------------------------------------------------- +" Test 17: Nesting of unmatched :if or :endif inside a :while {{{1 +" +" The :while/:endwhile takes precedence in nesting over an unclosed +" :if or an unopened :endif. +"------------------------------------------------------------------------------- + +XpathINIT + +function! MSG(enr, emsg) + let english = v:lang == "C" || v:lang =~ '^[Ee]n' + if a:enr == "" + Xout "TODO: Add message number for:" a:emsg + let v:errmsg = ":" . v:errmsg + endif + let match = 1 + if v:errmsg !~ '^'.a:enr.':' || (english && v:errmsg !~ a:emsg) + let match = 0 + if v:errmsg == "" + Xout "Message missing." + else + let v:errmsg = escape(v:errmsg, '"') + Xout "Unexpected message:" v:errmsg + endif + endif + return match +endfunction + +let messages = "" + +" While loops inside a function are continued on error. +function! F() + let v:errmsg = "" + XloopINIT 1 16 + let loops = 3 + while loops > 0 + let loops = loops - 1 " 2: 1: 0: + Xloop 1 " X: 1 + 1*16 + 1*16*16 + if (loops == 1) + Xloop 2 " X: 2*16 + XloopNEXT + continue + elseif (loops == 0) + Xloop 4 " X: 4*16*16 + break + elseif 1 + Xloop 8 " X: 8 + XloopNEXT + " endif missing! + endwhile " :endwhile after :if 1 + Xpath 4096 " X: 16*16*16 + if MSG('E171', "Missing :endif") + let g:messages = g:messages . "A" + endif + + let v:errmsg = "" + XloopINIT! 8192 4 + let loops = 2 + while loops > 0 " 2: 1: + XloopNEXT + let loops = loops - 1 + Xloop 1 " X: 8192 + 8192*4 + if 0 + Xloop 2 " X: 0 + " endif missing + endwhile " :endwhile after :if 0 + Xpath 131072 " X: 8192*4*4 + if MSG('E171', "Missing :endif") + let g:messages = g:messages . "B" + endif + + let v:errmsg = "" + XloopINIT 262144 4 + let loops = 2 + while loops > 0 " 2: 1: + let loops = loops - 1 + Xloop 1 " X: 262144 + 262144 * 4 + " if missing! + endif " :endif without :if in while + Xloop 2 " X: 524288 + 524288 * 4 + XloopNEXT + endwhile + Xpath 4194304 " X: 262144*4*4 + if MSG('E580', ":endif without :if") + let g:messages = g:messages . "C" + endif +endfunction + +call F() + +" Error continuation outside a function is at the outermost :endwhile or :endif. +let v:errmsg = "" +XloopINIT! 8388608 4 +let loops = 2 +while loops > 0 " 2: 1: + XloopNEXT + let loops = loops - 1 + Xloop 1 " X: 8388608 + 0 * 4 + if 0 + Xloop 2 " X: 0 + " endif missing! Following :endwhile fails. +endwhile | Xpath 134217728 " X: 0 +Xpath 268435456 " X: 2*8388608*4*4 +if MSG('E171', "Missing :endif") + let messages = g:messages . "D" +endif + +if messages != "ABCD" + Xpath 536870912 " X: 0 + Xout "messages is" messages "instead of ABCD" +endif + +unlet loops messages +delfunction F +delfunction MSG + +Xcheck 285127993 + + +"------------------------------------------------------------------------------- +" Test 18: Interrupt (Ctrl-C pressed) {{{1 +" +" On an interrupt, the script processing is terminated immediately. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + if 1 + Xpath 1 " X: 1 + while 1 + Xpath 2 " X: 2 + if 1 + Xpath 4 " X: 4 + "INTERRUPT + Xpath 8 " X: 0 + break + finish + endif | Xpath 16 " X: 0 + Xpath 32 " X: 0 + endwhile | Xpath 64 " X: 0 + Xpath 128 " X: 0 + endif | Xpath 256 " X: 0 + Xpath 512 " X: 0 +endif + +if ExtraVim() + try + Xpath 1024 " X: 1024 + "INTERRUPT + Xpath 2048 " X: 0 + endtry | Xpath 4096 " X: 0 + Xpath 8192 " X: 0 +endif + +if ExtraVim() + function! F() + if 1 + Xpath 16384 " X: 16384 + while 1 + Xpath 32768 " X: 32768 + if 1 + Xpath 65536 " X: 65536 + "INTERRUPT + Xpath 131072 " X: 0 + break + return + endif | Xpath 262144 " X: 0 + Xpath Xpath 524288 " X: 0 + endwhile | Xpath 1048576 " X: 0 + Xpath Xpath 2097152 " X: 0 + endif | Xpath Xpath 4194304 " X: 0 + Xpath Xpath 8388608 " X: 0 + endfunction + + call F() | Xpath 16777216 " X: 0 + Xpath 33554432 " X: 0 +endif + +if ExtraVim() + function! G() + try + Xpath 67108864 " X: 67108864 + "INTERRUPT + Xpath 134217728 " X: 0 + endtry | Xpath 268435456 " X: 0 + Xpath 536870912 " X: 0 + endfunction + + call G() | Xpath 1073741824 " X: 0 + " The Xpath command does not accept 2^31 (negative); display explicitly: + exec "!echo 2147483648 >>" . g:ExtraVimResult + " X: 0 +endif + +Xcheck 67224583 + + +"------------------------------------------------------------------------------- +" Test 19: Aborting on errors inside :try/:endtry {{{1 +" +" An error in a command dynamically enclosed in a :try/:endtry region +" aborts script processing immediately. It does not matter whether +" the failing command is outside or inside a function and whether a +" function has an "abort" attribute. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + function! F() abort + Xpath 1 " X: 1 + asdf + Xpath 2 " X: 0 + endfunction + + try + Xpath 4 " X: 4 + call F() + Xpath 8 " X: 0 + endtry | Xpath 16 " X: 0 + Xpath 32 " X: 0 +endif + +if ExtraVim() + function! G() + Xpath 64 " X: 64 + asdf + Xpath 128 " X: 0 + endfunction + + try + Xpath 256 " X: 256 + call G() + Xpath 512 " X: 0 + endtry | Xpath 1024 " X: 0 + Xpath 2048 " X: 0 +endif + +if ExtraVim() + try + Xpath 4096 " X: 4096 + asdf + Xpath 8192 " X: 0 + endtry | Xpath 16384 " X: 0 + Xpath 32768 " X: 0 +endif + +if ExtraVim() + if 1 + try + Xpath 65536 " X: 65536 + asdf + Xpath 131072 " X: 0 + endtry | Xpath 262144 " X: 0 + endif | Xpath 524288 " X: 0 + Xpath 1048576 " X: 0 +endif + +if ExtraVim() + let p = 1 + while p + let p = 0 + try + Xpath 2097152 " X: 2097152 + asdf + Xpath 4194304 " X: 0 + endtry | Xpath 8388608 " X: 0 + endwhile | Xpath 16777216 " X: 0 + Xpath 33554432 " X: 0 +endif + +if ExtraVim() + let p = 1 + while p + let p = 0 +" try + Xpath 67108864 " X: 67108864 + endwhile | Xpath 134217728 " X: 0 + Xpath 268435456 " X: 0 +endif + +Xcheck 69275973 +"------------------------------------------------------------------------------- +" Test 20: Aborting on errors after :try/:endtry {{{1 +" +" When an error occurs after the last active :try/:endtry region has +" been left, termination behavior is as if no :try/:endtry has been +" seen. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + let p = 1 + while p + let p = 0 + try + Xpath 1 " X: 1 + endtry + asdf + endwhile | Xpath 2 " X: 0 + Xpath 4 " X: 4 +endif + +if ExtraVim() + while 1 + try + Xpath 8 " X: 8 + break + Xpath 16 " X: 0 + endtry + endwhile + Xpath 32 " X: 32 + asdf + Xpath 64 " X: 64 +endif + +if ExtraVim() + while 1 + try + Xpath 128 " X: 128 + break + Xpath 256 " X: 0 + finally + Xpath 512 " X: 512 + endtry + endwhile + Xpath 1024 " X: 1024 + asdf + Xpath 2048 " X: 2048 +endif + +if ExtraVim() + while 1 + try + Xpath 4096 " X: 4096 + finally + Xpath 8192 " X: 8192 + break + Xpath 16384 " X: 0 + endtry + endwhile + Xpath 32768 " X: 32768 + asdf + Xpath 65536 " X: 65536 +endif + +if ExtraVim() + let p = 1 + while p + let p = 0 + try + Xpath 131072 " X: 131072 + continue + Xpath 262144 " X: 0 + endtry + endwhile + Xpath 524288 " X: 524288 + asdf + Xpath 1048576 " X: 1048576 +endif + +if ExtraVim() + let p = 1 + while p + let p = 0 + try + Xpath 2097152 " X: 2097152 + continue + Xpath 4194304 " X: 0 + finally + Xpath 8388608 " X: 8388608 + endtry + endwhile + Xpath 16777216 " X: 16777216 + asdf + Xpath 33554432 " X: 33554432 +endif + +if ExtraVim() + let p = 1 + while p + let p = 0 + try + Xpath 67108864 " X: 67108864 + finally + Xpath 134217728 " X: 134217728 + continue + Xpath 268435456 " X: 0 + endtry + endwhile + Xpath 536870912 " X: 536870912 + asdf + Xpath 1073741824 " X: 1073741824 +endif + +Xcheck 1874575085 + + +"------------------------------------------------------------------------------- +" Test 21: :finally for :try after :continue/:break/:return/:finish {{{1 +" +" If a :try conditional stays inactive due to a preceding :continue, +" :break, :return, or :finish, its :finally clause should not be +" executed. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + function F() + let loops = 2 + XloopINIT! 1 256 + while loops > 0 + XloopNEXT + let loops = loops - 1 + try + if loops == 1 + Xloop 1 " X: 1 + continue + Xloop 2 " X: 0 + elseif loops == 0 + Xloop 4 " X: 4*256 + break + Xloop 8 " X: 0 + endif + + try " inactive + Xloop 16 " X: 0 + finally + Xloop 32 " X: 0 + endtry + finally + Xloop 64 " X: 64 + 64*256 + endtry + Xloop 128 " X: 0 + endwhile + + try + Xpath 65536 " X: 65536 + return + Xpath 131072 " X: 0 + try " inactive + Xpath 262144 " X: 0 + finally + Xpath 524288 " X: 0 + endtry + finally + Xpath 1048576 " X: 1048576 + endtry + Xpath 2097152 " X: 0 + endfunction + + try + Xpath 4194304 " X: 4194304 + call F() + Xpath 8388608 " X: 8388608 + finish + Xpath 16777216 " X: 0 + try " inactive + Xpath 33554432 " X: 0 + finally + Xpath 67108864 " X: 0 + endtry + finally + Xpath 134217728 " X: 134217728 + endtry + Xpath 268435456 " X: 0 +endif + +Xcheck 147932225 + + +"------------------------------------------------------------------------------- +" Test 22: :finally for a :try after an error/interrupt/:throw {{{1 +" +" If a :try conditional stays inactive due to a preceding error or +" interrupt or :throw, its :finally clause should not be executed. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + function! Error() + try + asdf " aborting error, triggering error exception + endtry + endfunction + + Xpath 1 " X: 1 + call Error() + Xpath 2 " X: 0 + + if 1 " not active due to error + try " not active since :if inactive + Xpath 4 " X: 0 + finally + Xpath 8 " X: 0 + endtry + endif + + try " not active due to error + Xpath 16 " X: 0 + finally + Xpath 32 " X: 0 + endtry +endif + +if ExtraVim() + function! Interrupt() + try + "INTERRUPT " triggering interrupt exception + endtry + endfunction + + Xpath 64 " X: 64 + call Interrupt() + Xpath 128 " X: 0 + + if 1 " not active due to interrupt + try " not active since :if inactive + Xpath 256 " X: 0 + finally + Xpath 512 " X: 0 + endtry + endif + + try " not active due to interrupt + Xpath 1024 " X: 0 + finally + Xpath 2048 " X: 0 + endtry +endif + +if ExtraVim() + function! Throw() + throw "xyz" + endfunction + + Xpath 4096 " X: 4096 + call Throw() + Xpath 8192 " X: 0 + + if 1 " not active due to :throw + try " not active since :if inactive + Xpath 16384 " X: 0 + finally + Xpath 32768 " X: 0 + endtry + endif + + try " not active due to :throw + Xpath 65536 " X: 0 + finally + Xpath 131072 " X: 0 + endtry +endif + +Xcheck 4161 + + +"------------------------------------------------------------------------------- +" Test 23: :catch clauses for a :try after a :throw {{{1 +" +" If a :try conditional stays inactive due to a preceding :throw, +" none of its :catch clauses should be executed. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + try + Xpath 1 " X: 1 + throw "xyz" + Xpath 2 " X: 0 + + if 1 " not active due to :throw + try " not active since :if inactive + Xpath 4 " X: 0 + catch /xyz/ + Xpath 8 " X: 0 + endtry + endif + catch /xyz/ + Xpath 16 " X: 16 + endtry + + Xpath 32 " X: 32 + throw "abc" + Xpath 64 " X: 0 + + try " not active due to :throw + Xpath 128 " X: 0 + catch /abc/ + Xpath 256 " X: 0 + endtry +endif + +Xcheck 49 + + +"------------------------------------------------------------------------------- +" Test 24: :endtry for a :try after a :throw {{{1 +" +" If a :try conditional stays inactive due to a preceding :throw, +" its :endtry should not rethrow the exception to the next surrounding +" active :try conditional. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + try " try 1 + try " try 2 + Xpath 1 " X: 1 + throw "xyz" " makes try 2 inactive + Xpath 2 " X: 0 + + try " try 3 + Xpath 4 " X: 0 + endtry " no rethrow to try 1 + catch /xyz/ " should catch although try 2 inactive + Xpath 8 " X: 8 + endtry + catch /xyz/ " try 1 active, but exception already caught + Xpath 16 " X: 0 + endtry + Xpath 32 " X: 32 +endif + +Xcheck 41 + + +"------------------------------------------------------------------------------- +" Test 25: Executing :finally clauses on normal control flow {{{1 +" +" Control flow in a :try conditional should always fall through to its +" :finally clause. A :finally clause of a :try conditional inside an +" inactive conditional should never be executed. +"------------------------------------------------------------------------------- + +XpathINIT + +function! F() + let loops = 3 + XloopINIT 1 256 + while loops > 0 " 3: 2: 1: + Xloop 1 " X: 1 + 1*256 + 1*256*256 + if loops >= 2 + try + Xloop 2 " X: 2 + 2*256 + if loops == 2 + try + Xloop 4 " X: 4*256 + finally + Xloop 8 " X: 8*256 + endtry + endif + finally + Xloop 16 " X: 16 + 16*256 + if loops == 2 + try + Xloop 32 " X: 32*256 + finally + Xloop 64 " X: 64*256 + endtry + endif + endtry + endif + Xloop 128 " X: 128 + 128*256 + 128*256*256 + let loops = loops - 1 + XloopNEXT + endwhile + Xpath 16777216 " X: 16777216 +endfunction + +if 1 + try + Xpath 33554432 " X: 33554432 + call F() + Xpath 67108864 " X: 67108864 + finally + Xpath 134217728 " X: 134217728 + endtry +else + try + Xpath 268435456 " X: 0 + finally + Xpath 536870912 " X: 0 + endtry +endif + +delfunction F + +Xcheck 260177811 + + +"------------------------------------------------------------------------------- +" Test 26: Executing :finally clauses after :continue or :break {{{1 +" +" For a :continue or :break dynamically enclosed in a :try/:endtry +" region inside the next surrounding :while/:endwhile, if the +" :continue/:break is before the :finally, the :finally clause is +" executed first. If the :continue/:break is after the :finally, the +" :finally clause is broken (like an :if/:endif region). +"------------------------------------------------------------------------------- + +XpathINIT + +try + let loops = 3 + XloopINIT! 1 32 + while loops > 0 + XloopNEXT + try + try + if loops == 2 " 3: 2: 1: + Xloop 1 " X: 1*32 + let loops = loops - 1 + continue + elseif loops == 1 + Xloop 2 " X: 2*32*32 + break + finish + endif + Xloop 4 " X: 4 + endtry + finally + Xloop 8 " X: 8 + 8*32 + 8*32*32 + endtry + Xloop 16 " X: 16 + let loops = loops - 1 + endwhile + Xpath 32768 " X: 32768 +finally + Xpath 65536 " X: 65536 + let loops = 3 + XloopINIT 131072 16 + while loops > 0 + try + finally + try + if loops == 2 + Xloop 1 " X: 131072*16 + let loops = loops - 1 + XloopNEXT + continue + elseif loops == 1 + Xloop 2 " X: 131072*2*16*16 + break + finish + endif + endtry + Xloop 4 " X: 131072*4 + endtry + Xloop 8 " X: 131072*8 + let loops = loops - 1 + XloopNEXT + endwhile + Xpath 536870912 " X: 536870912 +endtry +Xpath 1073741824 " X: 1073741824 + +unlet loops + +Xcheck 1681500476 + + +"------------------------------------------------------------------------------- +" Test 27: Executing :finally clauses after :return {{{1 +" +" For a :return command dynamically enclosed in a :try/:endtry region, +" :finally clauses are executed and the called function is ended. +"------------------------------------------------------------------------------- + +XpathINIT + +function! F() + try + Xpath 1 " X: 1 + try + Xpath 2 " X: 2 + return + Xpath 4 " X: 0 + finally + Xpath 8 " X: 8 + endtry + Xpath 16 " X: 0 + finally + Xpath 32 " X: 32 + endtry + Xpath 64 " X: 0 +endfunction + +function! G() + try + Xpath 128 " X: 128 + return + Xpath 256 " X: 0 + finally + Xpath 512 " X: 512 + call F() + Xpath 1024 " X: 1024 + endtry + Xpath 2048 " X: 0 +endfunction + +function! H() + try + Xpath 4096 " X: 4096 + call G() + Xpath 8192 " X: 8192 + finally + Xpath 16384 " X: 16384 + return + Xpath 32768 " X: 0 + endtry + Xpath 65536 " X: 0 +endfunction + +try + Xpath 131072 " X: 131072 + call H() + Xpath 262144 " X: 262144 +finally + Xpath 524288 " X: 524288 +endtry +Xpath 1048576 " X: 1048576 + +Xcheck 1996459 + +" Leave F, G, and H for execution as scripts in the next test. + + +"------------------------------------------------------------------------------- +" Test 28: Executing :finally clauses after :finish {{{1 +" +" For a :finish command dynamically enclosed in a :try/:endtry region, +" :finally clauses are executed and the sourced file is finished. +" +" This test executes the bodies of the functions F, G, and H from the +" previous test as script files (:return replaced by :finish). +"------------------------------------------------------------------------------- + +XpathINIT + +let scriptF = MakeScript("F") " X: 1 + 2 + 8 + 32 +let scriptG = MakeScript("G", scriptF) " X: 128 + 512 + 1024 +let scriptH = MakeScript("H", scriptG) " X: 4096 + 8192 + 16384 + +try + Xpath 131072 " X: 131072 + exec "source" scriptH + Xpath 262144 " X: 262144 +finally + Xpath 524288 " X: 524288 +endtry +Xpath 1048576 " X: 1048576 + +call delete(scriptF) +call delete(scriptG) +call delete(scriptH) +unlet scriptF scriptG scriptH +delfunction F +delfunction G +delfunction H + +Xcheck 1996459 + + +"------------------------------------------------------------------------------- +" Test 29: Executing :finally clauses on errors {{{1 +" +" After an error in a command dynamically enclosed in a :try/:endtry +" region, :finally clauses are executed and the script processing is +" terminated. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + function! F() + while 1 + try + Xpath 1 " X: 1 + while 1 + try + Xpath 2 " X: 2 + asdf " error + Xpath 4 " X: 0 + finally + Xpath 8 " X: 8 + endtry | Xpath 16 " X: 0 + Xpath 32 " X: 0 + break + endwhile + Xpath 64 " X: 0 + finally + Xpath 128 " X: 128 + endtry | Xpath 256 " X: 0 + Xpath 512 " X: 0 + break + endwhile + Xpath 1024 " X: 0 + endfunction + + while 1 + try + Xpath 2048 " X: 2048 + while 1 + call F() + Xpath 4096 " X: 0 + break + endwhile | Xpath 8192 " X: 0 + Xpath 16384 " X: 0 + finally + Xpath 32768 " X: 32768 + endtry | Xpath 65536 " X: 0 + endwhile | Xpath 131072 " X: 0 + Xpath 262144 " X: 0 +endif + +if ExtraVim() + function! G() abort + if 1 + try + Xpath 524288 " X: 524288 + asdf " error + Xpath 1048576 " X: 0 + finally + Xpath 2097152 " X: 2097152 + endtry | Xpath 4194304 " X: 0 + endif | Xpath 8388608 " X: 0 + Xpath 16777216 " X: 0 + endfunction + + if 1 + try + Xpath 33554432 " X: 33554432 + call G() + Xpath 67108864 " X: 0 + finally + Xpath 134217728 " X: 134217728 + endtry | Xpath 268435456 " X: 0 + endif | Xpath 536870912 " X: 0 + Xpath 1073741824 " X: 0 +endif + +Xcheck 170428555 + + +"------------------------------------------------------------------------------- +" Test 30: Executing :finally clauses on interrupt {{{1 +" +" After an interrupt in a command dynamically enclosed in +" a :try/:endtry region, :finally clauses are executed and the +" script processing is terminated. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + XloopINIT 1 16 + + function! F() + try + Xloop 1 " X: 1 + 1*16 + "INTERRUPT + Xloop 2 " X: 0 + finally + Xloop 4 " X: 4 + 4*16 + endtry + Xloop 8 " X: 0 + endfunction + + try + Xpath 256 " X: 256 + try + Xpath 512 " X: 512 + "INTERRUPT + Xpath 1024 " X: 0 + finally + Xpath 2048 " X: 2048 + try + Xpath 4096 " X: 4096 + try + Xpath 8192 " X: 8192 + finally + Xpath 16384 " X: 16384 + try + Xpath 32768 " X: 32768 + "INTERRUPT + Xpath 65536 " X: 0 + endtry + Xpath 131072 " X: 0 + endtry + Xpath 262144 " X: 0 + endtry + Xpath 524288 " X: 0 + endtry + Xpath 1048576 " X: 0 + finally + Xpath 2097152 " X: 2097152 + try + Xpath 4194304 " X: 4194304 + call F() + Xpath 8388608 " X: 0 + finally + Xpath 16777216 " X: 16777216 + try + Xpath 33554432 " X: 33554432 + XloopNEXT + ExecAsScript F + Xpath 67108864 " X: 0 + finally + Xpath 134217728 " X: 134217728 + endtry + Xpath 268435456 " X: 0 + endtry + Xpath 536870912 " X: 0 + endtry + Xpath 1073741824 " X: 0 +endif + +Xcheck 190905173 + + +"------------------------------------------------------------------------------- +" Test 31: Executing :finally clauses after :throw {{{1 +" +" After a :throw dynamically enclosed in a :try/:endtry region, +" :finally clauses are executed and the script processing is +" terminated. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + XloopINIT 1 16 + + function! F() + try + Xloop 1 " X: 1 + 1*16 + throw "exception" + Xloop 2 " X: 0 + finally + Xloop 4 " X: 4 + 4*16 + endtry + Xloop 8 " X: 0 + endfunction + + try + Xpath 256 " X: 256 + try + Xpath 512 " X: 512 + throw "exception" + Xpath 1024 " X: 0 + finally + Xpath 2048 " X: 2048 + try + Xpath 4096 " X: 4096 + try + Xpath 8192 " X: 8192 + finally + Xpath 16384 " X: 16384 + try + Xpath 32768 " X: 32768 + throw "exception" + Xpath 65536 " X: 0 + endtry + Xpath 131072 " X: 0 + endtry + Xpath 262144 " X: 0 + endtry + Xpath 524288 " X: 0 + endtry + Xpath 1048576 " X: 0 + finally + Xpath 2097152 " X: 2097152 + try + Xpath 4194304 " X: 4194304 + call F() + Xpath 8388608 " X: 0 + finally + Xpath 16777216 " X: 16777216 + try + Xpath 33554432 " X: 33554432 + XloopNEXT + ExecAsScript F + Xpath 67108864 " X: 0 + finally + Xpath 134217728 " X: 134217728 + endtry + Xpath 268435456 " X: 0 + endtry + Xpath 536870912 " X: 0 + endtry + Xpath 1073741824 " X: 0 +endif + +Xcheck 190905173 + + +"------------------------------------------------------------------------------- +" Test 32: Remembering the :return value on :finally {{{1 +" +" If a :finally clause is executed due to a :return specifying +" a value, this is the value visible to the caller if not overwritten +" by a new :return in the :finally clause. A :return without a value +" in the :finally clause overwrites with value 0. +"------------------------------------------------------------------------------- + +XpathINIT + +function! F() + try + Xpath 1 " X: 1 + try + Xpath 2 " X: 2 + return "ABCD" + Xpath 4 " X: 0 + finally + Xpath 8 " X: 8 + endtry + Xpath 16 " X: 0 + finally + Xpath 32 " X: 32 + endtry + Xpath 64 " X: 0 +endfunction + +function! G() + try + Xpath 128 " X: 128 + return 8 + Xpath 256 " X: 0 + finally + Xpath 512 " X: 512 + return 16 + strlen(F()) + Xpath 1024 " X: 0 + endtry + Xpath 2048 " X: 0 +endfunction + +function! H() + try + Xpath 4096 " X: 4096 + return 32 + Xpath 8192 " X: 0 + finally + Xpath 16384 " X: 16384 + return + Xpath 32768 " X: 0 + endtry + Xpath 65536 " X: 0 +endfunction + +function! I() + try + Xpath 131072 " X: 131072 + finally + Xpath 262144 " X: 262144 + return G() + H() + 64 + Xpath 524288 " X: 0 + endtry + Xpath 1048576 " X: 0 +endfunction + +let retcode = I() +Xpath 2097152 " X: 2097152 + +if retcode < 0 + Xpath 4194304 " X: 0 +endif +if retcode % 4 + Xpath 8388608 " X: 0 +endif +if (retcode/4) % 2 + Xpath 16777216 " X: 16777216 +endif +if (retcode/8) % 2 + Xpath 33554432 " X: 0 +endif +if (retcode/16) % 2 + Xpath 67108864 " X: 67108864 +endif +if (retcode/32) % 2 + Xpath 134217728 " X: 0 +endif +if (retcode/64) % 2 + Xpath 268435456 " X: 268435456 +endif +if retcode/128 + Xpath 536870912 " X: 0 +endif + +unlet retcode +delfunction F +delfunction G +delfunction H +delfunction I + +Xcheck 354833067 + + +"------------------------------------------------------------------------------- +" Test 33: :return under :execute or user command and :finally {{{1 +" +" A :return command may be executed under an ":execute" or from +" a user command. Executing of :finally clauses and passing through +" the return code works also then. +"------------------------------------------------------------------------------- +XpathINIT + +command! -nargs=? RETURN + \ try | return <args> | finally | return <args> * 2 | endtry + +function! F() + try + RETURN 8 + Xpath 1 " X: 0 + finally + Xpath 2 " X: 2 + endtry + Xpath 4 " X: 0 +endfunction + +function! G() + try + RETURN 32 + Xpath 8 " X: 0 + finally + Xpath 16 " X: 16 + RETURN 128 + Xpath 32 " X: 0 + endtry + Xpath 64 " X: 0 +endfunction + +function! H() + try + execute "try | return 512 | finally | return 1024 | endtry" + Xpath 128 " X: 0 + finally + Xpath 256 " X: 256 + endtry + Xpath 512 " X: 0 +endfunction + +function! I() + try + execute "try | return 2048 | finally | return 4096 | endtry" + Xpath 1024 " X: 0 + finally + Xpath 2048 " X: 2048 + execute "try | return 8192 | finally | return 16384 | endtry" + Xpath 4096 " X: 0 + endtry + Xpath 8192 " X: 0 +endfunction + +function! J() + try + RETURN 32768 + Xpath 16384 " X: 0 + finally + Xpath 32768 " X: 32768 + return + Xpath 65536 " X: 0 + endtry + Xpath 131072 " X: 0 +endfunction + +function! K() + try + execute "try | return 131072 | finally | return 262144 | endtry" + Xpath 262144 " X: 0 + finally + Xpath 524288 " X: 524288 + execute "try | return 524288 | finally | return | endtry" + Xpath 1048576 " X: 0 + endtry + Xpath 2097152 " X: 0 +endfunction + +function! L() + try + return + Xpath 4194304 " X: 0 + finally + Xpath 8388608 " X: 8388608 + RETURN 1048576 + Xpath 16777216 " X: 0 + endtry + Xpath 33554432 " X: 0 +endfunction + +function! M() + try + return + Xpath 67108864 " X: 0 + finally + Xpath 134217728 " X: 134217728 + execute "try | return 4194304 | finally | return 8388608 | endtry" + Xpath 268435456 " X: 0 + endtry + Xpath 536870912 " X: 0 +endfunction + +function! N() + RETURN 16777216 +endfunction + +function! O() + execute "try | return 67108864 | finally | return 134217728 | endtry" +endfunction + +let sum = F() + G() + H() + I() + J() + K() + L() + M() +let expected = 16 + 256 + 1024 + 16384 + 0 + 0 + 2097152 + 8388608 +let sum = sum + N() + O() +let expected = expected + 33554432 + 134217728 + +if sum == expected + Xout "sum = " . sum . " (ok)" +else + Xout "sum = " . sum . ", expected: " . expected +endif + +Xpath 1073741824 " X: 1073741824 + +if sum != expected + " The Xpath command does not accept 2^31 (negative); add explicitly: + let Xpath = Xpath + 2147483648 " X: 0 +endif + +unlet sum expected +delfunction F +delfunction G +delfunction H +delfunction I +delfunction J +delfunction K +delfunction L +delfunction M +delfunction N +delfunction O + +Xcheck 1216907538 + + +"------------------------------------------------------------------------------- +" Test 34: :finally reason discarded by :continue {{{1 +" +" When a :finally clause is executed due to a :continue, :break, +" :return, :finish, error, interrupt or :throw, the jump reason is +" discarded by a :continue in the finally clause. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + + XloopINIT! 1 8 + + function! C(jump) + XloopNEXT + let loop = 0 + while loop < 2 + let loop = loop + 1 + if loop == 1 + try + if a:jump == "continue" + continue + elseif a:jump == "break" + break + elseif a:jump == "return" || a:jump == "finish" + return + elseif a:jump == "error" + asdf + elseif a:jump == "interrupt" + "INTERRUPT + let dummy = 0 + elseif a:jump == "throw" + throw "abc" + endif + finally + continue " discards jump that caused the :finally + Xloop 1 " X: 0 + endtry + Xloop 2 " X: 0 + elseif loop == 2 + Xloop 4 " X: 4*(1+8+64+512+4096+32768+262144) + endif + endwhile + endfunction + + call C("continue") + Xpath 2097152 " X: 2097152 + call C("break") + Xpath 4194304 " X: 4194304 + call C("return") + Xpath 8388608 " X: 8388608 + let g:jump = "finish" + ExecAsScript C + unlet g:jump + Xpath 16777216 " X: 16777216 + try + call C("error") + Xpath 33554432 " X: 33554432 + finally + Xpath 67108864 " X: 67108864 + try + call C("interrupt") + Xpath 134217728 " X: 134217728 + finally + Xpath 268435456 " X: 268435456 + call C("throw") + Xpath 536870912 " X: 536870912 + endtry + endtry + Xpath 1073741824 " X: 1073741824 + + delfunction C + +endif + +Xcheck 2146584868 + + +"------------------------------------------------------------------------------- +" Test 35: :finally reason discarded by :break {{{1 +" +" When a :finally clause is executed due to a :continue, :break, +" :return, :finish, error, interrupt or :throw, the jump reason is +" discarded by a :break in the finally clause. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + + XloopINIT! 1 8 + + function! B(jump) + XloopNEXT + let loop = 0 + while loop < 2 + let loop = loop + 1 + if loop == 1 + try + if a:jump == "continue" + continue + elseif a:jump == "break" + break + elseif a:jump == "return" || a:jump == "finish" + return + elseif a:jump == "error" + asdf + elseif a:jump == "interrupt" + "INTERRUPT + let dummy = 0 + elseif a:jump == "throw" + throw "abc" + endif + finally + break " discards jump that caused the :finally + Xloop 1 " X: 0 + endtry + elseif loop == 2 + Xloop 2 " X: 0 + endif + endwhile + Xloop 4 " X: 4*(1+8+64+512+4096+32768+262144) + endfunction + + call B("continue") + Xpath 2097152 " X: 2097152 + call B("break") + Xpath 4194304 " X: 4194304 + call B("return") + Xpath 8388608 " X: 8388608 + let g:jump = "finish" + ExecAsScript B + unlet g:jump + Xpath 16777216 " X: 16777216 + try + call B("error") + Xpath 33554432 " X: 33554432 + finally + Xpath 67108864 " X: 67108864 + try + call B("interrupt") + Xpath 134217728 " X: 134217728 + finally + Xpath 268435456 " X: 268435456 + call B("throw") + Xpath 536870912 " X: 536870912 + endtry + endtry + Xpath 1073741824 " X: 1073741824 + + delfunction B + +endif + +Xcheck 2146584868 + + +"------------------------------------------------------------------------------- +" Test 36: :finally reason discarded by :return {{{1 +" +" When a :finally clause is executed due to a :continue, :break, +" :return, :finish, error, interrupt or :throw, the jump reason is +" discarded by a :return in the finally clause. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + + XloopINIT! 1 8 + + function! R(jump, retval) abort + XloopNEXT + let loop = 0 + while loop < 2 + let loop = loop + 1 + if loop == 1 + try + if a:jump == "continue" + continue + elseif a:jump == "break" + break + elseif a:jump == "return" + return + elseif a:jump == "error" + asdf + elseif a:jump == "interrupt" + "INTERRUPT + let dummy = 0 + elseif a:jump == "throw" + throw "abc" + endif + finally + return a:retval " discards jump that caused the :finally + Xloop 1 " X: 0 + endtry + elseif loop == 2 + Xloop 2 " X: 0 + endif + endwhile + Xloop 4 " X: 0 + endfunction + + let sum = -R("continue", -8) + Xpath 2097152 " X: 2097152 + let sum = sum - R("break", -16) + Xpath 4194304 " X: 4194304 + let sum = sum - R("return", -32) + Xpath 8388608 " X: 8388608 + try + let sum = sum - R("error", -64) + Xpath 16777216 " X: 16777216 + finally + Xpath 33554432 " X: 33554432 + try + let sum = sum - R("interrupt", -128) + Xpath 67108864 " X: 67108864 + finally + Xpath 134217728 " X: 134217728 + let sum = sum - R("throw", -256) + Xpath 268435456 " X: 268435456 + endtry + endtry + Xpath 536870912 " X: 536870912 + + let expected = 8 + 16 + 32 + 64 + 128 + 256 + if sum != expected + Xpath 1073741824 " X: 0 + Xout "sum =" . sum . ", expected: " . expected + endif + + unlet sum expected + delfunction R + +endif + +Xcheck 1071644672 + + +"------------------------------------------------------------------------------- +" Test 37: :finally reason discarded by :finish {{{1 +" +" When a :finally clause is executed due to a :continue, :break, +" :return, :finish, error, interrupt or :throw, the jump reason is +" discarded by a :finish in the finally clause. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + + XloopINIT! 1 8 + + function! F(jump) " not executed as function, transformed to a script + XloopNEXT + let loop = 0 + while loop < 2 + let loop = loop + 1 + if loop == 1 + try + if a:jump == "continue" + continue + elseif a:jump == "break" + break + elseif a:jump == "finish" + finish + elseif a:jump == "error" + asdf + elseif a:jump == "interrupt" + "INTERRUPT + let dummy = 0 + elseif a:jump == "throw" + throw "abc" + endif + finally + finish " discards jump that caused the :finally + Xloop 1 " X: 0 + endtry + elseif loop == 2 + Xloop 2 " X: 0 + endif + endwhile + Xloop 4 " X: 0 + endfunction + + let scriptF = MakeScript("F") + delfunction F + + let g:jump = "continue" + exec "source" scriptF + Xpath 2097152 " X: 2097152 + let g:jump = "break" + exec "source" scriptF + Xpath 4194304 " X: 4194304 + let g:jump = "finish" + exec "source" scriptF + Xpath 8388608 " X: 8388608 + try + let g:jump = "error" + exec "source" scriptF + Xpath 16777216 " X: 16777216 + finally + Xpath 33554432 " X: 33554432 + try + let g:jump = "interrupt" + exec "source" scriptF + Xpath 67108864 " X: 67108864 + finally + Xpath 134217728 " X: 134217728 + try + let g:jump = "throw" + exec "source" scriptF + Xpath 268435456 " X: 268435456 + finally + Xpath 536870912 " X: 536870912 + endtry + endtry + endtry + unlet g:jump + + call delete(scriptF) + unlet scriptF + +endif + +Xcheck 1071644672 + + +"------------------------------------------------------------------------------- +" Test 38: :finally reason discarded by an error {{{1 +" +" When a :finally clause is executed due to a :continue, :break, +" :return, :finish, error, interrupt or :throw, the jump reason is +" discarded by an error in the finally clause. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + + XloopINIT! 1 4 + + function! E(jump) + XloopNEXT + let loop = 0 + while loop < 2 + let loop = loop + 1 + if loop == 1 + try + if a:jump == "continue" + continue + elseif a:jump == "break" + break + elseif a:jump == "return" || a:jump == "finish" + return + elseif a:jump == "error" + asdf + elseif a:jump == "interrupt" + "INTERRUPT + let dummy = 0 + elseif a:jump == "throw" + throw "abc" + endif + finally + asdf " error; discards jump that caused the :finally + endtry + elseif loop == 2 + Xloop 1 " X: 0 + endif + endwhile + Xloop 2 " X: 0 + endfunction + + try + Xpath 16384 " X: 16384 + call E("continue") + Xpath 32768 " X: 0 + finally + try + Xpath 65536 " X: 65536 + call E("break") + Xpath 131072 " X: 0 + finally + try + Xpath 262144 " X: 262144 + call E("return") + Xpath 524288 " X: 0 + finally + try + Xpath 1048576 " X: 1048576 + let g:jump = "finish" + ExecAsScript E + Xpath 2097152 " X: 0 + finally + unlet g:jump + try + Xpath 4194304 " X: 4194304 + call E("error") + Xpath 8388608 " X: 0 + finally + try + Xpath 16777216 " X: 16777216 + call E("interrupt") + Xpath 33554432 " X: 0 + finally + try + Xpath 67108864 " X: 67108864 + call E("throw") + Xpath 134217728 " X: 0 + finally + Xpath 268435456 " X: 268435456 + delfunction E + endtry + endtry + endtry + endtry + endtry + endtry + endtry + Xpath 536870912 " X: 0 + +endif + +Xcheck 357908480 + + +"------------------------------------------------------------------------------- +" Test 39: :finally reason discarded by an interrupt {{{1 +" +" When a :finally clause is executed due to a :continue, :break, +" :return, :finish, error, interrupt or :throw, the jump reason is +" discarded by an interrupt in the finally clause. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + + XloopINIT! 1 4 + + function! I(jump) + XloopNEXT + let loop = 0 + while loop < 2 + let loop = loop + 1 + if loop == 1 + try + if a:jump == "continue" + continue + elseif a:jump == "break" + break + elseif a:jump == "return" || a:jump == "finish" + return + elseif a:jump == "error" + asdf + elseif a:jump == "interrupt" + "INTERRUPT + let dummy = 0 + elseif a:jump == "throw" + throw "abc" + endif + finally + "INTERRUPT - discards jump that caused the :finally + let dummy = 0 + endtry + elseif loop == 2 + Xloop 1 " X: 0 + endif + endwhile + Xloop 2 " X: 0 + endfunction + + try + Xpath 16384 " X: 16384 + call I("continue") + Xpath 32768 " X: 0 + finally + try + Xpath 65536 " X: 65536 + call I("break") + Xpath 131072 " X: 0 + finally + try + Xpath 262144 " X: 262144 + call I("return") + Xpath 524288 " X: 0 + finally + try + Xpath 1048576 " X: 1048576 + let g:jump = "finish" + ExecAsScript I + Xpath 2097152 " X: 0 + finally + unlet g:jump + try + Xpath 4194304 " X: 4194304 + call I("error") + Xpath 8388608 " X: 0 + finally + try + Xpath 16777216 " X: 16777216 + call I("interrupt") + Xpath 33554432 " X: 0 + finally + try + Xpath 67108864 " X: 67108864 + call I("throw") + Xpath 134217728 " X: 0 + finally + Xpath 268435456 " X: 268435456 + delfunction I + endtry + endtry + endtry + endtry + endtry + endtry + endtry + Xpath 536870912 " X: 0 + +endif + +Xcheck 357908480 + + +"------------------------------------------------------------------------------- +" Test 40: :finally reason discarded by :throw {{{1 +" +" When a :finally clause is executed due to a :continue, :break, +" :return, :finish, error, interrupt or :throw, the jump reason is +" discarded by a :throw in the finally clause. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + + XloopINIT! 1 4 + + function! T(jump) + XloopNEXT + let loop = 0 + while loop < 2 + let loop = loop + 1 + if loop == 1 + try + if a:jump == "continue" + continue + elseif a:jump == "break" + break + elseif a:jump == "return" || a:jump == "finish" + return + elseif a:jump == "error" + asdf + elseif a:jump == "interrupt" + "INTERRUPT + let dummy = 0 + elseif a:jump == "throw" + throw "abc" + endif + finally + throw "xyz" " discards jump that caused the :finally + endtry + elseif loop == 2 + Xloop 1 " X: 0 + endif + endwhile + Xloop 2 " X: 0 + endfunction + + try + Xpath 16384 " X: 16384 + call T("continue") + Xpath 32768 " X: 0 + finally + try + Xpath 65536 " X: 65536 + call T("break") + Xpath 131072 " X: 0 + finally + try + Xpath 262144 " X: 262144 + call T("return") + Xpath 524288 " X: 0 + finally + try + Xpath 1048576 " X: 1048576 + let g:jump = "finish" + ExecAsScript T + Xpath 2097152 " X: 0 + finally + unlet g:jump + try + Xpath 4194304 " X: 4194304 + call T("error") + Xpath 8388608 " X: 0 + finally + try + Xpath 16777216 " X: 16777216 + call T("interrupt") + Xpath 33554432 " X: 0 + finally + try + Xpath 67108864 " X: 67108864 + call T("throw") + Xpath 134217728 " X: 0 + finally + Xpath 268435456 " X: 268435456 + delfunction T + endtry + endtry + endtry + endtry + endtry + endtry + endtry + Xpath 536870912 " X: 0 + +endif + +Xcheck 357908480 + + +"------------------------------------------------------------------------------- +" Test 41: Skipped :throw finding next command {{{1 +" +" A :throw in an inactive conditional must not hide a following +" command. +"------------------------------------------------------------------------------- + +XpathINIT + +function! F() + Xpath 1 " X: 1 + if 0 | throw "never" | endif | Xpath 2 " X: 2 + Xpath 4 " X: 4 +endfunction + +function! G() + Xpath 8 " X: 8 + while 0 | throw "never" | endwhile | Xpath 16 " X: 16 + Xpath 32 " X: 32 +endfunction + +function H() + Xpath 64 " X: 64 + if 0 | try | throw "never" | endtry | endif | Xpath 128 " X: 128 + Xpath 256 " X: 256 +endfunction + +Xpath 512 " X: 512 + +try + Xpath 1024 " X: 1024 + call F() + Xpath 2048 " X: 2048 +catch /.*/ + Xpath 4096 " X: 0 + Xout v:exception "in" v:throwpoint +endtry + +Xpath 8192 " X: 8192 + +try + Xpath 16384 " X: 16384 + call G() + Xpath 32768 " X: 32768 +catch /.*/ + Xpath 65536 " X: 0 + Xout v:exception "in" v:throwpoint +endtry + +Xpath 131072 " X: 131072 + +try + Xpath 262144 " X: 262144 + call H() + Xpath 524288 " X: 524288 +catch /.*/ + Xpath 1048576 " X: 0 + Xout v:exception "in" v:throwpoint +endtry + +Xpath 2097152 " X: 2097152 + +delfunction F +delfunction G +delfunction H + +Xcheck 3076095 + + +"------------------------------------------------------------------------------- +" Test 42: Catching number and string exceptions {{{1 +" +" When a number is thrown, it is converted to a string exception. +" Numbers and strings may be caught by specifying a regular exception +" as argument to the :catch command. +"------------------------------------------------------------------------------- + +XpathINIT + +try + + try + Xpath 1 " X: 1 + throw 4711 + Xpath 2 " X: 0 + catch /4711/ + Xpath 4 " X: 4 + endtry + + try + Xpath 8 " X: 8 + throw 4711 + Xpath 16 " X: 0 + catch /^4711$/ + Xpath 32 " X: 32 + endtry + + try + Xpath 64 " X: 64 + throw 4711 + Xpath 128 " X: 0 + catch /\d/ + Xpath 256 " X: 256 + endtry + + try + Xpath 512 " X: 512 + throw 4711 + Xpath 1024 " X: 0 + catch /^\d\+$/ + Xpath 2048 " X: 2048 + endtry + + try + Xpath 4096 " X: 4096 + throw "arrgh" + Xpath 8192 " X: 0 + catch /arrgh/ + Xpath 16384 " X: 16384 + endtry + + try + Xpath 32768 " X: 32768 + throw "arrgh" + Xpath 65536 " X: 0 + catch /^arrgh$/ + Xpath 131072 " X: 131072 + endtry + + try + Xpath 262144 " X: 262144 + throw "arrgh" + Xpath 524288 " X: 0 + catch /\l/ + Xpath 1048576 " X: 1048576 + endtry + + try + Xpath 2097152 " X: 2097152 + throw "arrgh" + Xpath 4194304 " X: 0 + catch /^\l\+$/ + Xpath 8388608 " X: 8388608 + endtry + + try + try + Xpath 16777216 " X: 16777216 + throw "ARRGH" + Xpath 33554432 " X: 0 + catch /^arrgh$/ + Xpath 67108864 " X: 0 + endtry + catch /^\carrgh$/ + Xpath 134217728 " X: 134217728 + endtry + + try + Xpath 268435456 " X: 268435456 + throw "" + Xpath 536870912 " X: 0 + catch /^$/ + Xpath 1073741824 " X: 1073741824 + endtry + +catch /.*/ + " The Xpath command does not accept 2^31 (negative); add explicitly: + let Xpath = Xpath + 2147483648 " X: 0 + Xout v:exception "in" v:throwpoint +endtry + +Xcheck 1505155949 + + +"------------------------------------------------------------------------------- +" Test 43: Selecting the correct :catch clause {{{1 +" +" When an exception is thrown and there are multiple :catch clauses, +" the first matching one is taken. +"------------------------------------------------------------------------------- + +XpathINIT + +XloopINIT 1 1024 +let loops = 3 +while loops > 0 + try + if loops == 3 + Xloop 1 " X: 1 + throw "a" + Xloop 2 " X: 0 + elseif loops == 2 + Xloop 4 " X: 4*1024 + throw "ab" + Xloop 8 " X: 0 + elseif loops == 1 + Xloop 16 " X: 16*1024*1024 + throw "abc" + Xloop 32 " X: 0 + endif + catch /abc/ + Xloop 64 " X: 64*1024*1024 + catch /ab/ + Xloop 128 " X: 128*1024 + catch /.*/ + Xloop 256 " X: 256 + catch /a/ + Xloop 512 " X: 0 + endtry + + let loops = loops - 1 + XloopNEXT +endwhile +Xpath 1073741824 " X: 1073741824 + +unlet loops + +Xcheck 1157763329 + + +"------------------------------------------------------------------------------- +" Test 44: Missing or empty :catch patterns {{{1 +" +" A missing or empty :catch pattern means the same as /.*/, that is, +" catches everything. To catch only empty exceptions, /^$/ must be +" used. A :catch with missing, empty, or /.*/ argument also works +" when followed by another command separated by a bar on the same +" line. :catch patterns cannot be specified between ||. But other +" pattern separators can be used instead of //. +"------------------------------------------------------------------------------- + +XpathINIT + +try + try + Xpath 1 " X: 1 + throw "" + catch /^$/ + Xpath 2 " X: 2 + endtry + + try + Xpath 4 " X: 4 + throw "" + catch /.*/ + Xpath 8 " X: 8 + endtry + + try + Xpath 16 " X: 16 + throw "" + catch // + Xpath 32 " X: 32 + endtry + + try + Xpath 64 " X: 64 + throw "" + catch + Xpath 128 " X: 128 + endtry + + try + Xpath 256 " X: 256 + throw "oops" + catch /^$/ + Xpath 512 " X: 0 + catch /.*/ + Xpath 1024 " X: 1024 + endtry + + try + Xpath 2048 " X: 2048 + throw "arrgh" + catch /^$/ + Xpath 4096 " X: 0 + catch // + Xpath 8192 " X: 8192 + endtry + + try + Xpath 16384 " X: 16384 + throw "brrr" + catch /^$/ + Xpath 32768 " X: 0 + catch + Xpath 65536 " X: 65536 + endtry + + try | Xpath 131072 | throw "x" | catch /.*/ | Xpath 262144 | endtry + " X: 131072 + 262144 + + try | Xpath 524288 | throw "y" | catch // | Xpath 1048576 | endtry + " X: 524288 + 1048576 + + while 1 + try + let caught = 0 + let v:errmsg = "" + " Extra try level: if ":catch" without arguments below raises + " a syntax error because it misinterprets the "Xpath" as a pattern, + " let it be caught by the ":catch /.*/" below. + try + try | Xpath 2097152 | throw "z" | catch | Xpath 4194304 | : + endtry " X: 2097152 + 4194304 + endtry + catch /.*/ + let caught = 1 + Xout v:exception "in" v:throwpoint + finally + if $VIMNOERRTHROW && v:errmsg != "" + Xout v:errmsg + endif + if caught || $VIMNOERRTHROW && v:errmsg != "" + Xpath 8388608 " X: 0 + endif + break " discard error for $VIMNOERRTHROW + endtry + endwhile + + let cologne = 4711 + try + try + Xpath 16777216 " X: 16777216 + throw "throw cologne" + " Next lines catches all and throws 4711: + catch |throw cologne| + Xpath 33554432 " X: 0 + endtry + catch /4711/ + Xpath 67108864 " X: 67108864 + endtry + + try + Xpath 134217728 " X: 134217728 + throw "plus" + catch +plus+ + Xpath 268435456 " X: 268435456 + endtry + + Xpath 536870912 " X: 536870912 +catch /.*/ + Xpath 1073741824 " X: 0 + Xout v:exception "in" v:throwpoint +endtry + +unlet! caught cologne + +Xcheck 1031761407 + + +"------------------------------------------------------------------------------- +" Test 45: Catching exceptions from nested :try blocks {{{1 +" +" When :try blocks are nested, an exception is caught by the innermost +" try conditional that has a matching :catch clause. +"------------------------------------------------------------------------------- + +XpathINIT + +XloopINIT 1 1024 +let loops = 3 +while loops > 0 + try + try + try + try + if loops == 3 + Xloop 1 " X: 1 + throw "a" + Xloop 2 " X: 0 + elseif loops == 2 + Xloop 4 " X: 4*1024 + throw "ab" + Xloop 8 " X: 0 + elseif loops == 1 + Xloop 16 " X: 16*1024*1024 + throw "abc" + Xloop 32 " X: 0 + endif + catch /abc/ + Xloop 64 " X: 64*1024*1024 + endtry + catch /ab/ + Xloop 128 " X: 128*1024 + endtry + catch /.*/ + Xloop 256 " X: 256 + endtry + catch /a/ + Xloop 512 " X: 0 + endtry + + let loops = loops - 1 + XloopNEXT +endwhile +Xpath 1073741824 " X: 1073741824 + +unlet loops + +Xcheck 1157763329 + + +"------------------------------------------------------------------------------- +" Test 46: Executing :finally after a :throw in nested :try {{{1 +" +" When an exception is thrown from within nested :try blocks, the +" :finally clauses of the non-catching try conditionals should be +" executed before the matching :catch of the next surrounding :try +" gets the control. If this also has a :finally clause, it is +" executed afterwards. +"------------------------------------------------------------------------------- + +XpathINIT + +let sum = 0 + +try + Xpath 1 " X: 1 + try + Xpath 2 " X: 2 + try + Xpath 4 " X: 4 + try + Xpath 8 " X: 8 + throw "ABC" + Xpath 16 " X: 0 + catch /xyz/ + Xpath 32 " X: 0 + finally + Xpath 64 " X: 64 + if sum != 0 + Xpath 128 " X: 0 + endif + let sum = sum + 1 + endtry + Xpath 256 " X: 0 + catch /123/ + Xpath 512 " X: 0 + catch /321/ + Xpath 1024 " X: 0 + finally + Xpath 2048 " X: 2048 + if sum != 1 + Xpath 4096 " X: 0 + endif + let sum = sum + 2 + endtry + Xpath 8192 " X: 0 + finally + Xpath 16384 " X: 16384 + if sum != 3 + Xpath 32768 " X: 0 + endif + let sum = sum + 4 + endtry + Xpath 65536 " X: 0 +catch /ABC/ + Xpath 131072 " X: 131072 + if sum != 7 + Xpath 262144 " X: 0 + endif + let sum = sum + 8 +finally + Xpath 524288 " X: 524288 + if sum != 15 + Xpath 1048576 " X: 0 + endif + let sum = sum + 16 +endtry +Xpath 65536 " X: 65536 +if sum != 31 + Xpath 131072 " X: 0 +endif + +unlet sum + +Xcheck 739407 + + +"------------------------------------------------------------------------------- +" Test 47: Throwing exceptions from a :catch clause {{{1 +" +" When an exception is thrown from a :catch clause, it should not be +" caught by a :catch of the same :try conditional. After executing +" the :finally clause (if present), surrounding try conditionals +" should be checked for a matching :catch. +"------------------------------------------------------------------------------- + +XpathINIT + +Xpath 1 " X: 1 +try + Xpath 2 " X: 2 + try + Xpath 4 " X: 4 + try + Xpath 8 " X: 8 + throw "x1" + Xpath 16 " X: 0 + catch /x1/ + Xpath 32 " X: 32 + try + Xpath 64 " X: 64 + throw "x2" + Xpath 128 " X: 0 + catch /x1/ + Xpath 256 " X: 0 + catch /x2/ + Xpath 512 " X: 512 + try + Xpath 1024 " X: 1024 + throw "x3" + Xpath 2048 " X: 0 + catch /x1/ + Xpath 4096 " X: 0 + catch /x2/ + Xpath 8192 " X: 0 + finally + Xpath 16384 " X: 16384 + endtry + Xpath 32768 " X: 0 + catch /x3/ + Xpath 65536 " X: 0 + endtry + Xpath 131072 " X: 0 + catch /x1/ + Xpath 262144 " X: 0 + catch /x2/ + Xpath 524288 " X: 0 + catch /x3/ + Xpath 1048576 " X: 0 + finally + Xpath 2097152 " X: 2097152 + endtry + Xpath 4194304 " X: 0 + catch /x1/ + Xpath 8388608 " X: 0 + catch /x2/ + Xpath 16777216 " X: 0 + catch /x3/ + Xpath 33554432 " X: 33554432 + endtry + Xpath 67108864 " X: 67108864 +catch /.*/ + Xpath 134217728 " X: 0 + Xout v:exception "in" v:throwpoint +endtry +Xpath 268435456 " X: 268435456 + +Xcheck 371213935 + + +"------------------------------------------------------------------------------- +" Test 48: Throwing exceptions from a :finally clause {{{1 +" +" When an exception is thrown from a :finally clause, it should not be +" caught by a :catch of the same :try conditional. Surrounding try +" conditionals should be checked for a matching :catch. A previously +" thrown exception is discarded. +"------------------------------------------------------------------------------- + +XpathINIT + +try + + try + try + Xpath 1 " X: 1 + catch /x1/ + Xpath 2 " X: 0 + finally + Xpath 4 " X: 4 + throw "x1" + Xpath 8 " X: 0 + endtry + Xpath 16 " X: 0 + catch /x1/ + Xpath 32 " X: 32 + endtry + Xpath 64 " X: 64 + + try + try + Xpath 128 " X: 128 + throw "x2" + Xpath 256 " X: 0 + catch /x2/ + Xpath 512 " X: 512 + catch /x3/ + Xpath 1024 " X: 0 + finally + Xpath 2048 " X: 2048 + throw "x3" + Xpath 4096 " X: 0 + endtry + Xpath 8192 " X: 0 + catch /x2/ + Xpath 16384 " X: 0 + catch /x3/ + Xpath 32768 " X: 32768 + endtry + Xpath 65536 " X: 65536 + + try + try + try + Xpath 131072 " X: 131072 + throw "x4" + Xpath 262144 " X: 0 + catch /x5/ + Xpath 524288 " X: 0 + finally + Xpath 1048576 " X: 1048576 + throw "x5" " discards "x4" + Xpath 2097152 " X: 0 + endtry + Xpath 4194304 " X: 0 + catch /x4/ + Xpath 8388608 " X: 0 + finally + Xpath 16777216 " X: 16777216 + endtry + Xpath 33554432 " X: 0 + catch /x5/ + Xpath 67108864 " X: 67108864 + endtry + Xpath 134217728 " X: 134217728 + +catch /.*/ + Xpath 268435456 " X: 0 + Xout v:exception "in" v:throwpoint +endtry +Xpath 536870912 " X: 536870912 + +Xcheck 756255461 + + +"------------------------------------------------------------------------------- +" Test 49: Throwing exceptions across functions {{{1 +" +" When an exception is thrown but not caught inside a function, the +" caller is checked for a matching :catch clause. +"------------------------------------------------------------------------------- + +XpathINIT + +function! C() + try + Xpath 1 " X: 1 + throw "arrgh" + Xpath 2 " X: 0 + catch /arrgh/ + Xpath 4 " X: 4 + endtry + Xpath 8 " X: 8 +endfunction + +XloopINIT! 16 16 + +function! T1() + XloopNEXT + try + Xloop 1 " X: 16 + 16*16 + throw "arrgh" + Xloop 2 " X: 0 + finally + Xloop 4 " X: 64 + 64*16 + endtry + Xloop 8 " X: 0 +endfunction + +function! T2() + try + Xpath 4096 " X: 4096 + call T1() + Xpath 8192 " X: 0 + finally + Xpath 16384 " X: 16384 + endtry + Xpath 32768 " X: 0 +endfunction + +try + Xpath 65536 " X: 65536 + call C() " throw and catch + Xpath 131072 " X: 131072 +catch /.*/ + Xpath 262144 " X: 0 + Xout v:exception "in" v:throwpoint +endtry + +try + Xpath 524288 " X: 524288 + call T1() " throw, one level + Xpath 1048576 " X: 0 +catch /arrgh/ + Xpath 2097152 " X: 2097152 +catch /.*/ + Xpath 4194304 " X: 0 + Xout v:exception "in" v:throwpoint +endtry + +try + Xpath 8388608 " X: 8388608 + call T2() " throw, two levels + Xpath 16777216 " X: 0 +catch /arrgh/ + Xpath 33554432 " X: 33554432 +catch /.*/ + Xpath 67108864 " X: 0 + Xout v:exception "in" v:throwpoint +endtry +Xpath 134217728 " X: 134217728 + +Xcheck 179000669 + +" Leave C, T1, and T2 for execution as scripts in the next test. + + +"------------------------------------------------------------------------------- +" Test 50: Throwing exceptions across script files {{{1 +" +" When an exception is thrown but not caught inside a script file, +" the sourcing script or function is checked for a matching :catch +" clause. +" +" This test executes the bodies of the functions C, T1, and T2 from +" the previous test as script files (:return replaced by :finish). +"------------------------------------------------------------------------------- + +XpathINIT + +let scriptC = MakeScript("C") " X: 1 + 4 + 8 +delfunction C + +XloopINIT! 16 16 + +let scriptT1 = MakeScript("T1") " X: 16 + 64 + 16*16 + 64*16 +delfunction T1 + +let scriptT2 = MakeScript("T2", scriptT1) " X: 4096 + 16384 +delfunction T2 + +function! F() + try + Xpath 65536 " X: 65536 + exec "source" g:scriptC + Xpath 131072 " X: 131072 + catch /.*/ + Xpath 262144 " X: 0 + Xout v:exception "in" v:throwpoint + endtry + + try + Xpath 524288 " X: 524288 + exec "source" g:scriptT1 + Xpath 1048576 " X: 0 + catch /arrgh/ + Xpath 2097152 " X: 2097152 + catch /.*/ + Xpath 4194304 " X: 0 + Xout v:exception "in" v:throwpoint + endtry +endfunction + +try + Xpath 8388608 " X: 8388608 + call F() + Xpath 16777216 " X: 16777216 + exec "source" scriptT2 + Xpath 33554432 " X: 0 +catch /arrgh/ + Xpath 67108864 " X: 67108864 +catch /.*/ + Xpath 134217728 " X: 0 + Xout v:exception "in" v:throwpoint +endtry +Xpath 268435456 " X: 268435456 + +call delete(scriptC) +call delete(scriptT1) +call delete(scriptT2) +unlet scriptC scriptT1 scriptT2 +delfunction F + +Xcheck 363550045 + + +"------------------------------------------------------------------------------- +" Test 51: Throwing exceptions across :execute and user commands {{{1 +" +" A :throw command may be executed under an ":execute" or from +" a user command. +"------------------------------------------------------------------------------- + +XpathINIT + +command! -nargs=? THROW1 throw <args> | throw 1 +command! -nargs=? THROW2 try | throw <args> | endtry | throw 2 +command! -nargs=? THROW3 try | throw 3 | catch /3/ | throw <args> | endtry +command! -nargs=? THROW4 try | throw 4 | finally | throw <args> | endtry + +try + + try + try + Xpath 1 " X: 1 + THROW1 "A" + catch /A/ + Xpath 2 " X: 2 + endtry + catch /1/ + Xpath 4 " X: 0 + endtry + + try + try + Xpath 8 " X: 8 + THROW2 "B" + catch /B/ + Xpath 16 " X: 16 + endtry + catch /2/ + Xpath 32 " X: 0 + endtry + + try + try + Xpath 64 " X: 64 + THROW3 "C" + catch /C/ + Xpath 128 " X: 128 + endtry + catch /3/ + Xpath 256 " X: 0 + endtry + + try + try + Xpath 512 " X: 512 + THROW4 "D" + catch /D/ + Xpath 1024 " X: 1024 + endtry + catch /4/ + Xpath 2048 " X: 0 + endtry + + try + try + Xpath 4096 " X: 4096 + execute 'throw "E" | throw 5' + catch /E/ + Xpath 8192 " X: 8192 + endtry + catch /5/ + Xpath 16384 " X: 0 + endtry + + try + try + Xpath 32768 " X: 32768 + execute 'try | throw "F" | endtry | throw 6' + catch /F/ + Xpath 65536 " X: 65536 + endtry + catch /6/ + Xpath 131072 " X: 0 + endtry + + try + try + Xpath 262144 " X: 262144 + execute'try | throw 7 | catch /7/ | throw "G" | endtry' + catch /G/ + Xpath 524288 " X: 524288 + endtry + catch /7/ + Xpath 1048576 " X: 0 + endtry + + try + try + Xpath 2097152 " X: 2097152 + execute 'try | throw 8 | finally | throw "H" | endtry' + catch /H/ + Xpath 4194304 " X: 4194304 + endtry + catch /8/ + Xpath 8388608 " X: 0 + endtry + +catch /.*/ + Xpath 16777216 " X: 0 + Xout v:exception "in" v:throwpoint +endtry + +Xpath 33554432 " X: 33554432 + +delcommand THROW1 +delcommand THROW2 +delcommand THROW3 +delcommand THROW4 + +Xcheck 40744667 + + +"------------------------------------------------------------------------------- +" Test 52: Uncaught exceptions {{{1 +" +" When an exception is thrown but not caught, an error message is +" displayed when the script is terminated. In case of an interrupt +" or error exception, the normal interrupt or error message(s) are +" displayed. +"------------------------------------------------------------------------------- + +XpathINIT + +let msgfile = tempname() + +function! MESSAGES(...) + try + exec "edit" g:msgfile + catch /^Vim(edit):/ + return 0 + endtry + + let english = v:lang == "C" || v:lang =~ '^[Ee]n' + let match = 1 + norm gg + + let num = a:0 / 2 + let cnt = 1 + while cnt <= num + let enr = a:{2*cnt - 1} + let emsg= a:{2*cnt} + let cnt = cnt + 1 + + if enr == "" + Xout "TODO: Add message number for:" emsg + elseif enr == "INT" + let enr = "" + endif + if enr == "" && !english + continue + endif + let pattern = (enr != "") ? enr . ':.*' : '' + if english + let pattern = pattern . emsg + endif + if !search(pattern, "W") + let match = 0 + Xout "No match for:" pattern + endif + norm $ + endwhile + + bwipeout! + return match +endfunction + +if ExtraVim(msgfile) + Xpath 1 " X: 1 + throw "arrgh" +endif + +Xpath 2 " X: 2 +if !MESSAGES('E605', "Exception not caught") + Xpath 4 " X: 0 +endif + +if ExtraVim(msgfile) + try + Xpath 8 " X: 8 + throw "oops" + catch /arrgh/ + Xpath 16 " X: 0 + endtry + Xpath 32 " X: 0 +endif + +Xpath 64 " X: 64 +if !MESSAGES('E605', "Exception not caught") + Xpath 128 " X: 0 +endif + +if ExtraVim(msgfile) + function! T() + throw "brrr" + endfunction + + try + Xpath 256 " X: 256 + throw "arrgh" + catch /.*/ + Xpath 512 " X: 512 + call T() + endtry + Xpath 1024 " X: 0 +endif + +Xpath 2048 " X: 2048 +if !MESSAGES('E605', "Exception not caught") + Xpath 4096 " X: 0 +endif + +if ExtraVim(msgfile) + try + Xpath 8192 " X: 8192 + throw "arrgh" + finally + Xpath 16384 " X: 16384 + throw "brrr" + endtry + Xpath 32768 " X: 0 +endif + +Xpath 65536 " X: 65536 +if !MESSAGES('E605', "Exception not caught") + Xpath 131072 " X: 0 +endif + +if ExtraVim(msgfile) + try + Xpath 262144 " X: 262144 + "INTERRUPT + endtry + Xpath 524288 " X: 0 +endif + +Xpath 1048576 " X: 1048576 +if !MESSAGES('INT', "Interrupted") + Xpath 2097152 " X: 0 +endif + +if ExtraVim(msgfile) + try + Xpath 4194304 " X: 4194304 + let x = novar " error E121; exception: E121 + catch /E15:/ " should not catch + Xpath 8388608 " X: 0 + endtry + Xpath 16777216 " X: 0 +endif + +Xpath 33554432 " X: 33554432 +if !MESSAGES('E121', "Undefined variable") + Xpath 67108864 " X: 0 +endif + +if ExtraVim(msgfile) + try + Xpath 134217728 " X: 134217728 +" unlet novar # " error E108/E488; exception: E488 + catch /E108:/ " should not catch + Xpath 268435456 " X: 0 + endtry + Xpath 536870912 " X: 0 +endif + +Xpath 1073741824 " X: 1073741824 +if !MESSAGES('E108', "No such variable", 'E488', "Trailing characters") + " The Xpath command does not accept 2^31 (negative); add explicitly: + let Xpath = Xpath + 2147483648 " X: 0 +endif + +call delete(msgfile) +unlet msgfile + +Xcheck 1247112011 + +" Leave MESSAGES() for the next tests. + + +"------------------------------------------------------------------------------- +" Test 53: Nesting errors: :endif/:else/:elseif {{{1 +" +" For nesting errors of :if conditionals the correct error messages +" should be given. +" +" This test reuses the function MESSAGES() from the previous test. +" This functions checks the messages in g:msgfile. +"------------------------------------------------------------------------------- + +XpathINIT + +let msgfile = tempname() + +if ExtraVim(msgfile) +" endif +endif +if MESSAGES('E580', ":endif without :if") + Xpath 1 " X: 1 +endif + +if ExtraVim(msgfile) +" while 1 +" endif +" endwhile +endif +if MESSAGES('E580', ":endif without :if") + Xpath 2 " X: 2 +endif + +if ExtraVim(msgfile) +" try +" finally +" endif +" endtry +endif +if MESSAGES('E580', ":endif without :if") + Xpath 4 " X: 4 +endif + +if ExtraVim(msgfile) +" try +" endif +" endtry +endif +if MESSAGES('E580', ":endif without :if") + Xpath 8 " X: 8 +endif + +if ExtraVim(msgfile) +" try +" throw "a" +" catch /a/ +" endif +" endtry +endif +if MESSAGES('E580', ":endif without :if") + Xpath 16 " X: 16 +endif + +if ExtraVim(msgfile) +" else +endif +if MESSAGES('E581', ":else without :if") + Xpath 32 " X: 32 +endif + +if ExtraVim(msgfile) +" while 1 +" else +" endwhile +endif +if MESSAGES('E581', ":else without :if") + Xpath 64 " X: 64 +endif + +if ExtraVim(msgfile) +" try +" finally +" else +" endtry +endif +if MESSAGES('E581', ":else without :if") + Xpath 128 " X: 128 +endif + +if ExtraVim(msgfile) +" try +" else +" endtry +endif +if MESSAGES('E581', ":else without :if") + Xpath 256 " X: 256 +endif + +if ExtraVim(msgfile) +" try +" throw "a" +" catch /a/ +" else +" endtry +endif +if MESSAGES('E581', ":else without :if") + Xpath 512 " X: 512 +endif + +if ExtraVim(msgfile) +" elseif +endif +if MESSAGES('E582', ":elseif without :if") + Xpath 1024 " X: 1024 +endif + +if ExtraVim(msgfile) +" while 1 +" elseif +" endwhile +endif +if MESSAGES('E582', ":elseif without :if") + Xpath 2048 " X: 2048 +endif + +if ExtraVim(msgfile) +" try +" finally +" elseif +" endtry +endif +if MESSAGES('E582', ":elseif without :if") + Xpath 4096 " X: 4096 +endif + +if ExtraVim(msgfile) +" try +" elseif +" endtry +endif +if MESSAGES('E582', ":elseif without :if") + Xpath 8192 " X: 8192 +endif + +if ExtraVim(msgfile) +" try +" throw "a" +" catch /a/ +" elseif +" endtry +endif +if MESSAGES('E582', ":elseif without :if") + Xpath 16384 " X: 16384 +endif + +if ExtraVim(msgfile) +" if 1 +" else +" else +" endif +endif +if MESSAGES('E583', "multiple :else") + Xpath 32768 " X: 32768 +endif + +if ExtraVim(msgfile) +" if 1 +" else +" elseif 1 +" endif +endif +if MESSAGES('E584', ":elseif after :else") + Xpath 65536 " X: 65536 +endif + +call delete(msgfile) +unlet msgfile + +Xcheck 131071 + +" Leave MESSAGES() for the next test. + + +"------------------------------------------------------------------------------- +" Test 54: Nesting errors: :while/:endwhile {{{1 +" +" For nesting errors of :while conditionals the correct error messages +" should be given. +" +" This test reuses the function MESSAGES() from the previous test. +" This functions checks the messages in g:msgfile. +"------------------------------------------------------------------------------- + +XpathINIT + +let msgfile = tempname() + +if ExtraVim(msgfile) +" endwhile +endif +if MESSAGES('E588', ":endwhile without :while") + Xpath 1 " X: 1 +endif + +if ExtraVim(msgfile) +" if 1 +" endwhile +" endif +endif +if MESSAGES('E588', ":endwhile without :while") + Xpath 2 " X: 2 +endif + +if ExtraVim(msgfile) +" while 1 +" if 1 +" endwhile +endif +if MESSAGES('E171', "Missing :endif") + Xpath 4 " X: 4 +endif + +if ExtraVim(msgfile) +" try +" finally +" endwhile +" endtry +endif +if MESSAGES('E588', ":endwhile without :while") + Xpath 8 " X: 8 +endif + +if ExtraVim(msgfile) +" while 1 +" try +" finally +" endwhile +endif +if MESSAGES('E600', "Missing :endtry") + Xpath 16 " X: 16 +endif + +if ExtraVim(msgfile) +" while 1 +" if 1 +" try +" finally +" endwhile +endif +if MESSAGES('E600', "Missing :endtry") + Xpath 32 " X: 32 +endif + +if ExtraVim(msgfile) +" while 1 +" try +" finally +" if 1 +" endwhile +endif +if MESSAGES('E171', "Missing :endif") + Xpath 64 " X: 64 +endif + +if ExtraVim(msgfile) +" try +" endwhile +" endtry +endif +if MESSAGES('E588', ":endwhile without :while") + Xpath 128 " X: 128 +endif + +if ExtraVim(msgfile) +" while 1 +" try +" endwhile +" endtry +" endwhile +endif +if MESSAGES('E588', ":endwhile without :while") + Xpath 256 " X: 256 +endif + +if ExtraVim(msgfile) +" try +" throw "a" +" catch /a/ +" endwhile +" endtry +endif +if MESSAGES('E588', ":endwhile without :while") + Xpath 512 " X: 512 +endif + +if ExtraVim(msgfile) +" while 1 +" try +" throw "a" +" catch /a/ +" endwhile +" endtry +" endwhile +endif +if MESSAGES('E588', ":endwhile without :while") + Xpath 1024 " X: 1024 +endif + + +call delete(msgfile) +unlet msgfile + +Xcheck 2047 + +" Leave MESSAGES() for the next test. + + +"------------------------------------------------------------------------------- +" Test 55: Nesting errors: :continue/:break {{{1 +" +" For nesting errors of :continue and :break commands the correct +" error messages should be given. +" +" This test reuses the function MESSAGES() from the previous test. +" This functions checks the messages in g:msgfile. +"------------------------------------------------------------------------------- + +XpathINIT + +let msgfile = tempname() + +if ExtraVim(msgfile) +" continue +endif +if MESSAGES('E586', ":continue without :while") + Xpath 1 " X: 1 +endif + +if ExtraVim(msgfile) +" if 1 +" continue +" endif +endif +if MESSAGES('E586', ":continue without :while") + Xpath 2 " X: 2 +endif + +if ExtraVim(msgfile) +" try +" finally +" continue +" endtry +endif +if MESSAGES('E586', ":continue without :while") + Xpath 4 " X: 4 +endif + +if ExtraVim(msgfile) +" try +" continue +" endtry +endif +if MESSAGES('E586', ":continue without :while") + Xpath 8 " X: 8 +endif + +if ExtraVim(msgfile) +" try +" throw "a" +" catch /a/ +" continue +" endtry +endif +if MESSAGES('E586', ":continue without :while") + Xpath 16 " X: 16 +endif + +if ExtraVim(msgfile) +" break +endif +if MESSAGES('E587', ":break without :while") + Xpath 32 " X: 32 +endif + +if ExtraVim(msgfile) +" if 1 +" break +" endif +endif +if MESSAGES('E587', ":break without :while") + Xpath 64 " X: 64 +endif + +if ExtraVim(msgfile) +" try +" finally +" break +" endtry +endif +if MESSAGES('E587', ":break without :while") + Xpath 128 " X: 128 +endif + +if ExtraVim(msgfile) +" try +" break +" endtry +endif +if MESSAGES('E587', ":break without :while") + Xpath 256 " X: 256 +endif + +if ExtraVim(msgfile) +" try +" throw "a" +" catch /a/ +" break +" endtry +endif +if MESSAGES('E587', ":break without :while") + Xpath 512 " X: 512 +endif + +call delete(msgfile) +unlet msgfile + +Xcheck 1023 + +" Leave MESSAGES() for the next test. + + +"------------------------------------------------------------------------------- +" Test 56: Nesting errors: :endtry {{{1 +" +" For nesting errors of :try conditionals the correct error messages +" should be given. +" +" This test reuses the function MESSAGES() from the previous test. +" This functions checks the messages in g:msgfile. +"------------------------------------------------------------------------------- + +XpathINIT + +let msgfile = tempname() + +if ExtraVim(msgfile) +" endtry +endif +if MESSAGES('E602', ":endtry without :try") + Xpath 1 " X: 1 +endif + +if ExtraVim(msgfile) +" if 1 +" endtry +" endif +endif +if MESSAGES('E602', ":endtry without :try") + Xpath 2 " X: 2 +endif + +if ExtraVim(msgfile) +" while 1 +" endtry +" endwhile +endif +if MESSAGES('E602', ":endtry without :try") + Xpath 4 " X: 4 +endif + +if ExtraVim(msgfile) +" try +" if 1 +" endtry +endif +if MESSAGES('E171', "Missing :endif") + Xpath 8 " X: 8 +endif + +if ExtraVim(msgfile) +" try +" while 1 +" endtry +endif +if MESSAGES('E170', "Missing :endwhile") + Xpath 16 " X: 16 +endif + +if ExtraVim(msgfile) +" try +" finally +" if 1 +" endtry +endif +if MESSAGES('E171', "Missing :endif") + Xpath 32 " X: 32 +endif + +if ExtraVim(msgfile) +" try +" finally +" while 1 +" endtry +endif +if MESSAGES('E170', "Missing :endwhile") + Xpath 64 " X: 64 +endif + +if ExtraVim(msgfile) +" try +" throw "a" +" catch /a/ +" if 1 +" endtry +endif +if MESSAGES('E171', "Missing :endif") + Xpath 128 " X: 128 +endif + +if ExtraVim(msgfile) +" try +" throw "a" +" catch /a/ +" while 1 +" endtry +endif +if MESSAGES('E170', "Missing :endwhile") + Xpath 256 " X: 256 +endif + +call delete(msgfile) +unlet msgfile + +delfunction MESSAGES + +Xcheck 511 + + +"------------------------------------------------------------------------------- +" Test 57: v:exception and v:throwpoint for user exceptions {{{1 +" +" v:exception evaluates to the value of the exception that was caught +" most recently and is not finished. (A caught exception is finished +" when the next ":catch", ":finally", or ":endtry" is reached.) +" v:throwpoint evaluates to the script/function name and line number +" where that exception has been thrown. +"------------------------------------------------------------------------------- + +XpathINIT + +function! FuncException() + let g:exception = v:exception +endfunction + +function! FuncThrowpoint() + let g:throwpoint = v:throwpoint +endfunction + +let scriptException = MakeScript("FuncException") +let scriptThrowPoint = MakeScript("FuncThrowpoint") + +command! CmdException let g:exception = v:exception +command! CmdThrowpoint let g:throwpoint = v:throwpoint + +XloopINIT! 1 2 + +function! CHECK(n, exception, throwname, throwline) + XloopNEXT + let error = 0 + if v:exception != a:exception + Xout a:n.": v:exception is" v:exception "instead of" a:exception + let error = 1 + endif + if v:throwpoint !~ a:throwname + let name = escape(a:throwname, '\') + Xout a:n.": v:throwpoint (".v:throwpoint.") does not match" name + let error = 1 + endif + if v:throwpoint !~ a:throwline + let line = escape(a:throwline, '\') + Xout a:n.": v:throwpoint (".v:throwpoint.") does not match" line + let error = 1 + endif + if error + Xloop 1 " X: 0 + endif +endfunction + +function! T(arg, line) + if a:line == 2 + throw a:arg " in line 2 + elseif a:line == 4 + throw a:arg " in line 4 + elseif a:line == 6 + throw a:arg " in line 6 + elseif a:line == 8 + throw a:arg " in line 8 + endif +endfunction + +function! G(arg, line) + call T(a:arg, a:line) +endfunction + +function! F(arg, line) + call G(a:arg, a:line) +endfunction + +let scriptT = MakeScript("T") +let scriptG = MakeScript("G", scriptT) +let scriptF = MakeScript("F", scriptG) + +try + Xpath 32768 " X: 32768 + call F("oops", 2) +catch /.*/ + Xpath 65536 " X: 65536 + let exception = v:exception + let throwpoint = v:throwpoint + call CHECK(1, "oops", '\<F\[1]\.\.G\[1]\.\.T\>', '\<2\>') + exec "let exception = v:exception" + exec "let throwpoint = v:throwpoint" + call CHECK(2, "oops", '\<F\[1]\.\.G\[1]\.\.T\>', '\<2\>') + CmdException + CmdThrowpoint + call CHECK(3, "oops", '\<F\[1]\.\.G\[1]\.\.T\>', '\<2\>') + call FuncException() + call FuncThrowpoint() + call CHECK(4, "oops", '\<F\[1]\.\.G\[1]\.\.T\>', '\<2\>') + exec "source" scriptException + exec "source" scriptThrowPoint + call CHECK(5, "oops", '\<F\[1]\.\.G\[1]\.\.T\>', '\<2\>') + try + Xpath 131072 " X: 131072 + call G("arrgh", 4) + catch /.*/ + Xpath 262144 " X: 262144 + let exception = v:exception + let throwpoint = v:throwpoint + call CHECK(6, "arrgh", '\<G\[1]\.\.T\>', '\<4\>') + try + Xpath 524288 " X: 524288 + let g:arg = "autsch" + let g:line = 6 + exec "source" scriptF + catch /.*/ + Xpath 1048576 " X: 1048576 + let exception = v:exception + let throwpoint = v:throwpoint + " Symbolic links in tempname()s are not resolved, whereas resolving + " is done for v:throwpoint. Resolve the temporary file name for + " scriptT, so that it can be matched against v:throwpoint. + call CHECK(7, "autsch", resolve(scriptT), '\<6\>') + finally + Xpath 2097152 " X: 2097152 + let exception = v:exception + let throwpoint = v:throwpoint + call CHECK(8, "arrgh", '\<G\[1]\.\.T\>', '\<4\>') + try + Xpath 4194304 " X: 4194304 + let g:arg = "brrrr" + let g:line = 8 + exec "source" scriptG + catch /.*/ + Xpath 8388608 " X: 8388608 + let exception = v:exception + let throwpoint = v:throwpoint + " Resolve scriptT for matching it against v:throwpoint. + call CHECK(9, "brrrr", resolve(scriptT), '\<8\>') + finally + Xpath 16777216 " X: 16777216 + let exception = v:exception + let throwpoint = v:throwpoint + call CHECK(10, "arrgh", '\<G\[1]\.\.T\>', '\<4\>') + endtry + Xpath 33554432 " X: 33554432 + let exception = v:exception + let throwpoint = v:throwpoint + call CHECK(11, "arrgh", '\<G\[1]\.\.T\>', '\<4\>') + endtry + Xpath 67108864 " X: 67108864 + let exception = v:exception + let throwpoint = v:throwpoint + call CHECK(12, "arrgh", '\<G\[1]\.\.T\>', '\<4\>') + finally + Xpath 134217728 " X: 134217728 + let exception = v:exception + let throwpoint = v:throwpoint + call CHECK(13, "oops", '\<F\[1]\.\.G\[1]\.\.T\>', '\<2\>') + endtry + Xpath 268435456 " X: 268435456 + let exception = v:exception + let throwpoint = v:throwpoint + call CHECK(14, "oops", '\<F\[1]\.\.G\[1]\.\.T\>', '\<2\>') +finally + Xpath 536870912 " X: 536870912 + let exception = v:exception + let throwpoint = v:throwpoint + call CHECK(15, "", '^$', '^$') +endtry + +Xpath 1073741824 " X: 1073741824 + +unlet exception throwpoint +delfunction FuncException +delfunction FuncThrowpoint +call delete(scriptException) +call delete(scriptThrowPoint) +unlet scriptException scriptThrowPoint +delcommand CmdException +delcommand CmdThrowpoint +delfunction T +delfunction G +delfunction F +call delete(scriptT) +call delete(scriptG) +call delete(scriptF) +unlet scriptT scriptG scriptF + +Xcheck 2147450880 + + +"------------------------------------------------------------------------------- +" +" Test 58: v:exception and v:throwpoint for error/interrupt exceptions {{{1 +" +" v:exception and v:throwpoint work also for error and interrupt +" exceptions. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + + function! T(line) + if a:line == 2 + delfunction T " error (function in use) in line 2 + elseif a:line == 4 + let dummy = 0 " INTERRUPT1 - interrupt in line 4 + endif + endfunction + + while 1 + try + Xpath 1 " X: 1 + let caught = 0 + call T(2) + catch /.*/ + let caught = 1 + if v:exception !~ 'Vim(delfunction):' + Xpath 2 " X: 0 + endif + if v:throwpoint !~ '\<T\>' + Xpath 4 " X: 0 + endif + if v:throwpoint !~ '\<2\>' + Xpath 8 " X: 0 + endif + finally + Xpath 16 " X: 16 + if caught || $VIMNOERRTHROW + Xpath 32 " X: 32 + endif + if v:exception != "" + Xpath 64 " X: 0 + endif + if v:throwpoint != "" + Xpath 128 " X: 0 + endif + break " discard error for $VIMNOERRTHROW + endtry + endwhile + + Xpath 256 " X: 256 + if v:exception != "" + Xpath 512 " X: 0 + endif + if v:throwpoint != "" + Xpath 1024 " X: 0 + endif + + while 1 + try + Xpath 2048 " X: 2048 + let caught = 0 + call T(4) + catch /.*/ + let caught = 1 + if v:exception != 'Vim:Interrupt' + Xpath 4096 " X: 0 + endif + if v:throwpoint !~ '\<T\>' + Xpath 8192 " X: 0 + endif + if v:throwpoint !~ '\<4\>' + Xpath 16384 " X: 0 + endif + finally + Xpath 32768 " X: 32768 + if caught || $VIMNOINTTHROW + Xpath 65536 " X: 65536 + endif + if v:exception != "" + Xpath 131072 " X: 0 + endif + if v:throwpoint != "" + Xpath 262144 " X: 0 + endif + break " discard error for $VIMNOERRTHROW + endtry + endwhile + + Xpath 524288 " X: 524288 + if v:exception != "" + Xpath 1048576 " X: 0 + endif + if v:throwpoint != "" + Xpath 2097152 " X: 0 + endif + +endif + +Xcheck 624945 + + +"------------------------------------------------------------------------------- +" +" Test 59: v:exception and v:throwpoint when discarding exceptions {{{1 +" +" When a :catch clause is left by a ":break" etc or an error or +" interrupt exception, v:exception and v:throwpoint are reset. They +" are not affected by an exception that is discarded before being +" caught. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + + XloopINIT! 1 2 + + let sfile = expand("<sfile>") + + function! LineNumber() + return substitute(substitute(v:throwpoint, g:sfile, '', ""), + \ '\D*\(\d*\).*', '\1', "") + endfunction + + command! -nargs=1 SetLineNumber + \ try | throw "line" | catch /.*/ | let <args> = LineNumber() | endtry + + " Check v:exception/v:throwpoint against second/fourth parameter if + " specified, check for being empty else. + function! CHECK(n, ...) + XloopNEXT + let exception = a:0 != 0 ? a:1 : "" " second parameter (optional) + let emsg = a:0 != 0 ? a:2 : "" " third parameter (optional) + let line = a:0 != 0 ? a:3 : 0 " fourth parameter (optional) + let error = 0 + if emsg != "" + " exception is the error number, emsg the English error message text + if exception !~ '^E\d\+$' + Xout "TODO: Add message number for:" emsg + elseif v:lang == "C" || v:lang =~ '^[Ee]n' + if exception == "E492" && emsg == "Not an editor command" + let exception = '^Vim:' . exception . ': ' . emsg + else + let exception = '^Vim(\a\+):' . exception . ': ' . emsg + endif + else + if exception == "E492" + let exception = '^Vim:' . exception + else + let exception = '^Vim(\a\+):' . exception + endif + endif + endif + if exception == "" && v:exception != "" + Xout a:n.": v:exception is set:" v:exception + let error = 1 + elseif exception != "" && v:exception !~ exception + Xout a:n.": v:exception (".v:exception.") does not match" exception + let error = 1 + endif + if line == 0 && v:throwpoint != "" + Xout a:n.": v:throwpoint is set:" v:throwpoint + let error = 1 + elseif line != 0 && v:throwpoint !~ '\<' . line . '\>' + Xout a:n.": v:throwpoint (".v:throwpoint.") does not match" line + let error = 1 + endif + if !error + Xloop 1 " X: 2097151 + endif + endfunction + + while 1 + try + throw "x1" + catch /.*/ + break + endtry + endwhile + call CHECK(1) + + while 1 + try + throw "x2" + catch /.*/ + break + finally + call CHECK(2) + endtry + break + endwhile + call CHECK(3) + + while 1 + try + let errcaught = 0 + try + try + throw "x3" + catch /.*/ + SetLineNumber line_before_error + asdf + endtry + catch /.*/ + let errcaught = 1 + call CHECK(4, 'E492', "Not an editor command", + \ line_before_error + 1) + endtry + finally + if !errcaught && $VIMNOERRTHROW + call CHECK(4) + endif + break " discard error for $VIMNOERRTHROW + endtry + endwhile + call CHECK(5) + + Xpath 2097152 " X: 2097152 + + while 1 + try + let intcaught = 0 + try + try + throw "x4" + catch /.*/ + SetLineNumber two_lines_before_interrupt + "INTERRUPT + let dummy = 0 + endtry + catch /.*/ + let intcaught = 1 + call CHECK(6, "Vim:Interrupt", '', + \ two_lines_before_interrupt + 2) + endtry + finally + if !intcaught && $VIMNOINTTHROW + call CHECK(6) + endif + break " discard interrupt for $VIMNOINTTHROW + endtry + endwhile + call CHECK(7) + + Xpath 4194304 " X: 4194304 + + while 1 + try + let errcaught = 0 + try + try +" if 1 + SetLineNumber line_before_throw + throw "x5" + " missing endif + catch /.*/ + Xpath 8388608 " X: 0 + endtry + catch /.*/ + let errcaught = 1 + call CHECK(8, 'E171', "Missing :endif", line_before_throw + 3) + endtry + finally + if !errcaught && $VIMNOERRTHROW + call CHECK(8) + endif + break " discard error for $VIMNOERRTHROW + endtry + endwhile + call CHECK(9) + + Xpath 16777216 " X: 16777216 + + try + while 1 + try + throw "x6" + finally + break + endtry + break + endwhile + catch /.*/ + Xpath 33554432 " X: 0 + endtry + call CHECK(10) + + try + while 1 + try + throw "x7" + finally + break + endtry + break + endwhile + catch /.*/ + Xpath 67108864 " X: 0 + finally + call CHECK(11) + endtry + call CHECK(12) + + while 1 + try + let errcaught = 0 + try + try + throw "x8" + finally + SetLineNumber line_before_error + asdf + endtry + catch /.*/ + let errcaught = 1 + call CHECK(13, 'E492', "Not an editor command", + \ line_before_error + 1) + endtry + finally + if !errcaught && $VIMNOERRTHROW + call CHECK(13) + endif + break " discard error for $VIMNOERRTHROW + endtry + endwhile + call CHECK(14) + + Xpath 134217728 " X: 134217728 + + while 1 + try + let intcaught = 0 + try + try + throw "x9" + finally + SetLineNumber two_lines_before_interrupt + "INTERRUPT + endtry + catch /.*/ + let intcaught = 1 + call CHECK(15, "Vim:Interrupt", '', + \ two_lines_before_interrupt + 2) + endtry + finally + if !intcaught && $VIMNOINTTHROW + call CHECK(15) + endif + break " discard interrupt for $VIMNOINTTHROW + endtry + endwhile + call CHECK(16) + + Xpath 268435456 " X: 268435456 + + while 1 + try + let errcaught = 0 + try + try +" if 1 + SetLineNumber line_before_throw + throw "x10" + " missing endif + finally + call CHECK(17) + endtry + catch /.*/ + let errcaught = 1 + call CHECK(18, 'E171', "Missing :endif", line_before_throw + 3) + endtry + finally + if !errcaught && $VIMNOERRTHROW + call CHECK(18) + endif + break " discard error for $VIMNOERRTHROW + endtry + endwhile + call CHECK(19) + + Xpath 536870912 " X: 536870912 + + while 1 + try + let errcaught = 0 + try + try +" if 1 + SetLineNumber line_before_throw + throw "x11" + " missing endif + endtry + catch /.*/ + let errcaught = 1 + call CHECK(20, 'E171', "Missing :endif", line_before_throw + 3) + endtry + finally + if !errcaught && $VIMNOERRTHROW + call CHECK(20) + endif + break " discard error for $VIMNOERRTHROW + endtry + endwhile + call CHECK(21) + + Xpath 1073741824 " X: 1073741824 + +endif + +Xcheck 2038431743 + + +"------------------------------------------------------------------------------- +" +" Test 60: (Re)throwing v:exception; :echoerr. {{{1 +" +" A user exception can be rethrown after catching by throwing +" v:exception. An error or interrupt exception cannot be rethrown +" because Vim exceptions cannot be faked. A Vim exception using the +" value of v:exception can, however, be triggered by the :echoerr +" command. +"------------------------------------------------------------------------------- + +XpathINIT + +try + try + Xpath 1 " X: 1 + throw "oops" + catch /oops/ + Xpath 2 " X: 2 + throw v:exception " rethrow user exception + catch /.*/ + Xpath 4 " X: 0 + endtry +catch /^oops$/ " catches rethrown user exception + Xpath 8 " X: 8 +catch /.*/ + Xpath 16 " X: 0 +endtry + +function! F() + try + let caught = 0 + try + Xpath 32 " X: 32 + write /n/o/n/w/r/i/t/a/b/l/e/_/f/i/l/e + Xpath 64 " X: 0 + Xout "did_emsg was reset before executing " . + \ "BufWritePost autocommands." + catch /^Vim(write):/ + let caught = 1 + throw v:exception " throw error: cannot fake Vim exception + catch /.*/ + Xpath 128 " X: 0 + finally + Xpath 256 " X: 256 + if !caught && !$VIMNOERRTHROW + Xpath 512 " X: 0 + endif + endtry + catch /^Vim(throw):/ " catches throw error + let caught = caught + 1 + catch /.*/ + Xpath 1024 " X: 0 + finally + Xpath 2048 " X: 2048 + if caught != 2 + if !caught && !$VIMNOERRTHROW + Xpath 4096 " X: 0 + elseif caught + Xpath 8192 " X: 0 + endif + return | " discard error for $VIMNOERRTHROW + endif + endtry +endfunction + +call F() +delfunction F + +function! G() + try + let caught = 0 + try + Xpath 16384 " X: 16384 + asdf + catch /^Vim/ " catch error exception + let caught = 1 + " Trigger Vim error exception with value specified after :echoerr + let value = substitute(v:exception, '^Vim\((.*)\)\=:', '', "") + echoerr value + catch /.*/ + Xpath 32768 " X: 0 + finally + Xpath 65536 " X: 65536 + if !caught + if !$VIMNOERRTHROW + Xpath 131072 " X: 0 + else + let value = "Error" + echoerr value + endif + endif + endtry + catch /^Vim(echoerr):/ + let caught = caught + 1 + if v:exception !~ value + Xpath 262144 " X: 0 + endif + catch /.*/ + Xpath 524288 " X: 0 + finally + Xpath 1048576 " X: 1048576 + if caught != 2 + if !caught && !$VIMNOERRTHROW + Xpath 2097152 " X: 0 + elseif caught + Xpath 4194304 " X: 0 + endif + return | " discard error for $VIMNOERRTHROW + endif + endtry +endfunction + +call G() +delfunction G + +unlet! value caught + +if ExtraVim() + try + let errcaught = 0 + try + Xpath 8388608 " X: 8388608 + let intcaught = 0 + "INTERRUPT + catch /^Vim:/ " catch interrupt exception + let intcaught = 1 + " Trigger Vim error exception with value specified after :echoerr + echoerr substitute(v:exception, '^Vim\((.*)\)\=:', '', "") + catch /.*/ + Xpath 16777216 " X: 0 + finally + Xpath 33554432 " X: 33554432 + if !intcaught + if !$VIMNOINTTHROW + Xpath 67108864 " X: 0 + else + echoerr "Interrupt" + endif + endif + endtry + catch /^Vim(echoerr):/ + let errcaught = 1 + if v:exception !~ "Interrupt" + Xpath 134217728 " X: 0 + endif + finally + Xpath 268435456 " X: 268435456 + if !errcaught && !$VIMNOERRTHROW + Xpath 536870912 " X: 0 + endif + endtry +endif + +Xcheck 311511339 + + +"------------------------------------------------------------------------------- +" Test 61: Catching interrupt exceptions {{{1 +" +" When an interrupt occurs inside a :try/:endtry region, an +" interrupt exception is thrown and can be caught. Its value is +" "Vim:Interrupt". If the interrupt occurs after an error or a :throw +" but before a matching :catch is reached, all following :catches of +" that try block are ignored, but the interrupt exception can be +" caught by the next surrounding try conditional. An interrupt is +" ignored when there is a previous interrupt that has not been caught +" or causes a :finally clause to be executed. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + + while 1 + try + try + Xpath 1 " X: 1 + let caught = 0 + "INTERRUPT + Xpath 2 " X: 0 + catch /^Vim:Interrupt$/ + let caught = 1 + finally + Xpath 4 " X: 4 + if caught || $VIMNOINTTHROW + Xpath 8 " X: 8 + endif + endtry + catch /.*/ + Xpath 16 " X: 0 + Xout v:exception "in" v:throwpoint + finally + break " discard interrupt for $VIMNOINTTHROW + endtry + endwhile + + while 1 + try + try + let caught = 0 + try + Xpath 32 " X: 32 + asdf + Xpath 64 " X: 0 + catch /do_not_catch/ + Xpath 128 " X: 0 + catch /.*/ "INTERRUPT - throw interrupt if !$VIMNOERRTHROW + Xpath 256 " X: 0 + catch /.*/ + Xpath 512 " X: 0 + finally "INTERRUPT - throw interrupt if $VIMNOERRTHROW + Xpath 1024 " X: 1024 + endtry + catch /^Vim:Interrupt$/ + let caught = 1 + finally + Xpath 2048 " X: 2048 + if caught || $VIMNOINTTHROW + Xpath 4096 " X: 4096 + endif + endtry + catch /.*/ + Xpath 8192 " X: 0 + Xout v:exception "in" v:throwpoint + finally + break " discard interrupt for $VIMNOINTTHROW + endtry + endwhile + + while 1 + try + try + let caught = 0 + try + Xpath 16384 " X: 16384 + throw "x" + Xpath 32768 " X: 0 + catch /do_not_catch/ + Xpath 65536 " X: 0 + catch /x/ "INTERRUPT + Xpath 131072 " X: 0 + catch /.*/ + Xpath 262144 " X: 0 + endtry + catch /^Vim:Interrupt$/ + let caught = 1 + finally + Xpath 524288 " X: 524288 + if caught || $VIMNOINTTHROW + Xpath 1048576 " X: 1048576 + endif + endtry + catch /.*/ + Xpath 2097152 " X: 0 + Xout v:exception "in" v:throwpoint + finally + break " discard interrupt for $VIMNOINTTHROW + endtry + endwhile + + while 1 + try + let caught = 0 + try + Xpath 4194304 " X: 4194304 + "INTERRUPT + Xpath 8388608 " X: 0 + catch /do_not_catch/ "INTERRUPT + Xpath 16777216 " X: 0 + catch /^Vim:Interrupt$/ + let caught = 1 + finally + Xpath 33554432 " X: 33554432 + if caught || $VIMNOINTTHROW + Xpath 67108864 " X: 67108864 + endif + endtry + catch /.*/ + Xpath 134217728 " X: 0 + Xout v:exception "in" v:throwpoint + finally + break " discard interrupt for $VIMNOINTTHROW + endtry + endwhile + + Xpath 268435456 " X: 268435456 + +endif + +Xcheck 374889517 + + +"------------------------------------------------------------------------------- +" Test 62: Catching error exceptions {{{1 +" +" An error inside a :try/:endtry region is converted to an exception +" and can be caught. The error exception has a "Vim(cmdname):" prefix +" where cmdname is the name of the failing command, or a "Vim:" prefix +" if no command name is known. The "Vim" prefixes cannot be faked. +"------------------------------------------------------------------------------- + +XpathINIT + +function! MSG(enr, emsg) + let english = v:lang == "C" || v:lang =~ '^[Ee]n' + if a:enr == "" + Xout "TODO: Add message number for:" a:emsg + let v:errmsg = ":" . v:errmsg + endif + let match = 1 + if v:errmsg !~ '^'.a:enr.':' || (english && v:errmsg !~ a:emsg) + let match = 0 + if v:errmsg == "" + Xout "Message missing." + else + let v:errmsg = escape(v:errmsg, '"') + Xout "Unexpected message:" v:errmsg + endif + endif + return match +endfunction + +while 1 + try + try + let caught = 0 + unlet novar + catch /^Vim(unlet):/ + let caught = 1 + let v:errmsg = substitute(v:exception, '^Vim(unlet):', '', "") + finally + Xpath 1 " X: 1 + if !caught && !$VIMNOERRTHROW + Xpath 2 " X: 0 + endif + if !MSG('E108', "No such variable") + Xpath 4 " X: 0 + endif + endtry + catch /.*/ + Xpath 8 " X: 0 + Xout v:exception "in" v:throwpoint + finally + break " discard error for $VIMNOERRTHROW + endtry +endwhile + +while 1 + try + try + let caught = 0 + throw novar " error in :throw + catch /^Vim(throw):/ + let caught = 1 + let v:errmsg = substitute(v:exception, '^Vim(throw):', '', "") + finally + Xpath 16 " X: 16 + if !caught && !$VIMNOERRTHROW + Xpath 32 " X: 0 + endif + if caught ? !MSG('E121', "Undefined variable") + \ : !MSG('E15', "Invalid expression") + Xpath 64 " X: 0 + endif + endtry + catch /.*/ + Xpath 128 " X: 0 + Xout v:exception "in" v:throwpoint + finally + break " discard error for $VIMNOERRTHROW + endtry +endwhile + +while 1 + try + try + let caught = 0 + throw "Vim:faked" " error: cannot fake Vim exception + catch /^Vim(throw):/ + let caught = 1 + let v:errmsg = substitute(v:exception, '^Vim(throw):', '', "") + finally + Xpath 256 " X: 256 + if !caught && !$VIMNOERRTHROW + Xpath 512 " X: 0 + endif + if !MSG('E608', "Cannot :throw exceptions with 'Vim' prefix") + Xpath 1024 " X: 0 + endif + endtry + catch /.*/ + Xpath 2048 " X: 0 + Xout v:exception "in" v:throwpoint + finally + break " discard error for $VIMNOERRTHROW + endtry +endwhile + +function! F() + while 1 + " Missing :endwhile +endfunction + +while 1 + try + try + let caught = 0 + call F() + catch /^Vim(endfunction):/ + let caught = 1 + let v:errmsg = substitute(v:exception, '^Vim(endfunction):', '', "") + finally + Xpath 4096 " X: 4096 + if !caught && !$VIMNOERRTHROW + Xpath 8192 " X: 0 + endif + if !MSG('E170', "Missing :endwhile") + Xpath 16384 " X: 0 + endif + endtry + catch /.*/ + Xpath 32768 " X: 0 + Xout v:exception "in" v:throwpoint + finally + break " discard error for $VIMNOERRTHROW + endtry +endwhile + +while 1 + try + try + let caught = 0 + ExecAsScript F + catch /^Vim:/ + let caught = 1 + let v:errmsg = substitute(v:exception, '^Vim:', '', "") + finally + Xpath 65536 " X: 65536 + if !caught && !$VIMNOERRTHROW + Xpath 131072 " X: 0 + endif + if !MSG('E170', "Missing :endwhile") + Xpath 262144 " X: 0 + endif + endtry + catch /.*/ + Xpath 524288 " X: 0 + Xout v:exception "in" v:throwpoint + finally + break " discard error for $VIMNOERRTHROW + endtry +endwhile + +function! G() + call G() +endfunction + +while 1 + try + let mfd_save = &mfd + set mfd=3 + try + let caught = 0 + call G() + catch /^Vim(call):/ + let caught = 1 + let v:errmsg = substitute(v:exception, '^Vim(call):', '', "") + finally + Xpath 1048576 " X: 1048576 + if !caught && !$VIMNOERRTHROW + Xpath 2097152 " X: 0 + endif + if !MSG('E132', "Function call depth is higher than 'maxfuncdepth'") + Xpath 4194304 " X: 0 + endif + endtry + catch /.*/ + Xpath 8388608 " X: 0 + Xout v:exception "in" v:throwpoint + finally + let &mfd = mfd_save + break " discard error for $VIMNOERRTHROW + endtry +endwhile + +function! H() + return H() +endfunction + +while 1 + try + let mfd_save = &mfd + set mfd=3 + try + let caught = 0 + call H() + catch /^Vim(return):/ + let caught = 1 + let v:errmsg = substitute(v:exception, '^Vim(return):', '', "") + finally + Xpath 16777216 " X: 16777216 + if !caught && !$VIMNOERRTHROW + Xpath 33554432 " X: 0 + endif + if !MSG('E132', "Function call depth is higher than 'maxfuncdepth'") + Xpath 67108864 " X: 0 + endif + endtry + catch /.*/ + Xpath 134217728 " X: 0 + Xout v:exception "in" v:throwpoint + finally + let &mfd = mfd_save + break " discard error for $VIMNOERRTHROW + endtry +endwhile + +unlet! caught mfd_save +delfunction F +delfunction G +delfunction H +Xpath 268435456 " X: 268435456 + +Xcheck 286331153 + +" Leave MSG() for the next test. + + +"------------------------------------------------------------------------------- +" Test 63: Suppressing error exceptions by :silent!. {{{1 +" +" A :silent! command inside a :try/:endtry region suppresses the +" conversion of errors to an exception and the immediate abortion on +" error. When the commands executed by the :silent! themselves open +" a new :try/:endtry region, conversion of errors to exception and +" immediate abortion is switched on again - until the next :silent! +" etc. The :silent! has the effect of setting v:errmsg to the error +" message text (without displaying it) and continuing with the next +" script line. +" +" When a command triggering autocommands is executed by :silent! +" inside a :try/:endtry, the autocommand execution is not suppressed +" on error. +" +" This test reuses the function MSG() from the previous test. +"------------------------------------------------------------------------------- + +XpathINIT + +XloopINIT! 1 4 + +let taken = "" + +function! S(n) abort + XloopNEXT + let g:taken = g:taken . "E" . a:n + let v:errmsg = "" + exec "asdf" . a:n + + " Check that ":silent!" continues: + Xloop 1 + + " Check that ":silent!" sets "v:errmsg": + if MSG('E492', "Not an editor command") + Xloop 2 + endif +endfunction + +function! Foo() + while 1 + try + try + let caught = 0 + " This is not silent: + call S(3) " X: 0 * 16 + catch /^Vim:/ + let caught = 1 + let errmsg3 = substitute(v:exception, '^Vim:', '', "") + silent! call S(4) " X: 3 * 64 + finally + if !caught + let errmsg3 = v:errmsg + " Do call S(4) here if not executed in :catch. + silent! call S(4) + endif + Xpath 1048576 " X: 1048576 + if !caught && !$VIMNOERRTHROW + Xpath 2097152 " X: 0 + endif + let v:errmsg = errmsg3 + if !MSG('E492', "Not an editor command") + Xpath 4194304 " X: 0 + endif + silent! call S(5) " X: 3 * 256 + " Break out of try conditionals that cover ":silent!". This also + " discards the aborting error when $VIMNOERRTHROW is non-zero. + break + endtry + catch /.*/ + Xpath 8388608 " X: 0 + Xout v:exception "in" v:throwpoint + endtry + endwhile + " This is a double ":silent!" (see caller). + silent! call S(6) " X: 3 * 1024 +endfunction + +function! Bar() + try + silent! call S(2) " X: 3 * 4 + " X: 3 * 4096 + silent! execute "call Foo() | call S(7)" + silent! call S(8) " X: 3 * 16384 + endtry " normal end of try cond that covers ":silent!" + " This has a ":silent!" from the caller: + call S(9) " X: 3 * 65536 +endfunction + +silent! call S(1) " X: 3 * 1 +silent! call Bar() +silent! call S(10) " X: 3 * 262144 + +let expected = "E1E2E3E4E5E6E7E8E9E10" +if taken != expected + Xpath 16777216 " X: 0 + Xout "'taken' is" taken "instead of" expected +endif + +augroup TMP + autocmd BufWritePost * Xpath 33554432 " X: 33554432 +augroup END + +Xpath 67108864 " X: 67108864 +write /i/m/p/o/s/s/i/b/l/e +Xpath 134217728 " X: 134217728 + +autocmd! TMP +unlet! caught errmsg3 taken expected +delfunction S +delfunction Foo +delfunction Bar +delfunction MSG + +Xcheck 236978127 + + +"------------------------------------------------------------------------------- +" Test 64: Error exceptions after error, interrupt or :throw {{{1 +" +" When an error occurs after an interrupt or a :throw but before +" a matching :catch is reached, all following :catches of that try +" block are ignored, but the error exception can be caught by the next +" surrounding try conditional. Any previous error exception is +" discarded. An error is ignored when there is a previous error that +" has not been caught. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + + while 1 + try + try + Xpath 1 " X: 1 + let caught = 0 + while 1 +" if 1 + " Missing :endif + endwhile " throw error exception + catch /^Vim(/ + let caught = 1 + finally + Xpath 2 " X: 2 + if caught || $VIMNOERRTHROW + Xpath 4 " X: 4 + endif + endtry + catch /.*/ + Xpath 8 " X: 0 + Xout v:exception "in" v:throwpoint + finally + break " discard error for $VIMNOERRTHROW + endtry + endwhile + + while 1 + try + try + Xpath 16 " X: 16 + let caught = 0 + try +" if 1 + " Missing :endif + catch /.*/ " throw error exception + Xpath 32 " X: 0 + catch /.*/ + Xpath 64 " X: 0 + endtry + catch /^Vim(/ + let caught = 1 + finally + Xpath 128 " X: 128 + if caught || $VIMNOERRTHROW + Xpath 256 " X: 256 + endif + endtry + catch /.*/ + Xpath 512 " X: 0 + Xout v:exception "in" v:throwpoint + finally + break " discard error for $VIMNOERRTHROW + endtry + endwhile + + while 1 + try + try + let caught = 0 + try + Xpath 1024 " X: 1024 + "INTERRUPT + catch /do_not_catch/ + Xpath 2048 " X: 0 +" if 1 + " Missing :endif + catch /.*/ " throw error exception + Xpath 4096 " X: 0 + catch /.*/ + Xpath 8192 " X: 0 + endtry + catch /^Vim(/ + let caught = 1 + finally + Xpath 16384 " X: 16384 + if caught || $VIMNOERRTHROW + Xpath 32768 " X: 32768 + endif + endtry + catch /.*/ + Xpath 65536 " X: 0 + Xout v:exception "in" v:throwpoint + finally + break " discard error for $VIMNOERRTHROW + endtry + endwhile + + while 1 + try + try + let caught = 0 + try + Xpath 131072 " X: 131072 + throw "x" + catch /do_not_catch/ + Xpath 262144 " X: 0 +" if 1 + " Missing :endif + catch /x/ " throw error exception + Xpath 524288 " X: 0 + catch /.*/ + Xpath 1048576 " X: 0 + endtry + catch /^Vim(/ + let caught = 1 + finally + Xpath 2097152 " X: 2097152 + if caught || $VIMNOERRTHROW + Xpath 4194304 " X: 4194304 + endif + endtry + catch /.*/ + Xpath 8388608 " X: 0 + Xout v:exception "in" v:throwpoint + finally + break " discard error for $VIMNOERRTHROW + endtry + endwhile + + while 1 + try + try + let caught = 0 + Xpath 16777216 " X: 16777216 +" endif " :endif without :if; throw error exception +" if 1 + " Missing :endif + catch /do_not_catch/ " ignore new error + Xpath 33554432 " X: 0 + catch /^Vim(endif):/ + let caught = 1 + catch /^Vim(/ + Xpath 67108864 " X: 0 + finally + Xpath 134217728 " X: 134217728 + if caught || $VIMNOERRTHROW + Xpath 268435456 " X: 268435456 + endif + endtry + catch /.*/ + Xpath 536870912 " X: 0 + Xout v:exception "in" v:throwpoint + finally + break " discard error for $VIMNOERRTHROW + endtry + endwhile + + Xpath 1073741824 " X: 1073741824 + +endif + +Xcheck 1499645335 + + +"------------------------------------------------------------------------------- +" Test 65: Errors in the /pattern/ argument of a :catch {{{1 +" +" On an error in the /pattern/ argument of a :catch, the :catch does +" not match. Any following :catches of the same :try/:endtry don't +" match either. Finally clauses are executed. +"------------------------------------------------------------------------------- + +XpathINIT + +function! MSG(enr, emsg) + let english = v:lang == "C" || v:lang =~ '^[Ee]n' + if a:enr == "" + Xout "TODO: Add message number for:" a:emsg + let v:errmsg = ":" . v:errmsg + endif + let match = 1 + if v:errmsg !~ '^'.a:enr.':' || (english && v:errmsg !~ a:emsg) + let match = 0 + if v:errmsg == "" + Xout "Message missing." + else + let v:errmsg = escape(v:errmsg, '"') + Xout "Unexpected message:" v:errmsg + endif + endif + return match +endfunction + +try + try + Xpath 1 " X: 1 + throw "oops" + catch /^oops$/ + Xpath 2 " X: 2 + catch /\)/ " not checked; exception has already been caught + Xpath 4 " X: 0 + endtry + Xpath 8 " X: 8 +catch /.*/ + Xpath 16 " X: 0 + Xout v:exception "in" v:throwpoint +endtry + +function! F() + try + let caught = 0 + try + try + Xpath 32 " X: 32 + throw "ab" + catch /abc/ " does not catch + Xpath 64 " X: 0 + catch /\)/ " error; discards exception + Xpath 128 " X: 0 + catch /.*/ " not checked + Xpath 256 " X: 0 + finally + Xpath 512 " X: 512 + endtry + Xpath 1024 " X: 0 + catch /^ab$/ " checked, but original exception is discarded + Xpath 2048 " X: 0 + catch /^Vim(catch):/ + let caught = 1 + let v:errmsg = substitute(v:exception, '^Vim(catch):', '', "") + finally + Xpath 4096 " X: 4096 + if !caught && !$VIMNOERRTHROW + Xpath 8192 " X: 0 + endif + if !MSG('E475', "Invalid argument") + Xpath 16384 " X: 0 + endif + if !caught + return | " discard error + endif + endtry + catch /.*/ + Xpath 32768 " X: 0 + Xout v:exception "in" v:throwpoint + endtry +endfunction + +call F() +Xpath 65536 " X: 65536 + +delfunction MSG +delfunction F +unlet! caught + +Xcheck 70187 + + +"------------------------------------------------------------------------------- +" Test 66: Stop range :call on error, interrupt, or :throw {{{1 +" +" When a function which is multiply called for a range since it +" doesn't handle the range itself has an error in a command +" dynamically enclosed by :try/:endtry or gets an interrupt or +" executes a :throw, no more calls for the remaining lines in the +" range are made. On an error in a command not dynamically enclosed +" by :try/:endtry, the function is executed again for the remaining +" lines in the range. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + + let file = tempname() + exec "edit" file + + insert +line 1 +line 2 +line 3 +. + + XloopINIT! 1 2 + + let taken = "" + let expected = "G1EF1E(1)F1E(2)F1E(3)G2EF2E(1)G3IF3I(1)G4TF4T(1)G5AF5A(1)" + + function! F(reason, n) abort + let g:taken = g:taken . "F" . a:n . + \ substitute(a:reason, '\(\l\).*', '\u\1', "") . + \ "(" . line(".") . ")" + + if a:reason == "error" + asdf + elseif a:reason == "interrupt" + "INTERRUPT + let dummy = 0 + elseif a:reason == "throw" + throw "xyz" + elseif a:reason == "aborting error" + XloopNEXT + if g:taken != g:expected + Xloop 1 " X: 0 + Xout "'taken' is" g:taken "instead of" g:expected + endif + try + bwipeout! + call delete(file) + asdf + endtry + endif + endfunction + + function! G(reason, n) + let g:taken = g:taken . "G" . a:n . + \ substitute(a:reason, '\(\l\).*', '\u\1', "") + 1,3call F(a:reason, a:n) + endfunction + + Xpath 8 " X: 8 + call G("error", 1) + try + Xpath 16 " X: 16 + try + call G("error", 2) + Xpath 32 " X: 0 + finally + Xpath 64 " X: 64 + try + call G("interrupt", 3) + Xpath 128 " X: 0 + finally + Xpath 256 " X: 256 + try + call G("throw", 4) + Xpath 512 " X: 0 + endtry + endtry + endtry + catch /xyz/ + Xpath 1024 " X: 1024 + catch /.*/ + Xpath 2048 " X: 0 + Xout v:exception "in" ExtraVimThrowpoint() + endtry + Xpath 4096 " X: 4096 + call G("aborting error", 5) + Xpath 8192 " X: 0 + Xout "'taken' is" taken "instead of" expected + +endif + +Xcheck 5464 + + +"------------------------------------------------------------------------------- +" Test 67: :throw across :call command {{{1 +" +" On a call command, an exception might be thrown when evaluating the +" function name, during evaluation of the arguments, or when the +" function is being executed. The exception can be caught by the +" caller. +"------------------------------------------------------------------------------- + +XpathINIT + +function! THROW(x, n) + if a:n == 1 + Xpath 1 " X: 1 + elseif a:n == 2 + Xpath 2 " X: 2 + elseif a:n == 3 + Xpath 4 " X: 4 + endif + throw a:x +endfunction + +function! NAME(x, n) + if a:n == 1 + Xpath 8 " X: 0 + elseif a:n == 2 + Xpath 16 " X: 16 + elseif a:n == 3 + Xpath 32 " X: 32 + elseif a:n == 4 + Xpath 64 " X: 64 + endif + return a:x +endfunction + +function! ARG(x, n) + if a:n == 1 + Xpath 128 " X: 0 + elseif a:n == 2 + Xpath 256 " X: 0 + elseif a:n == 3 + Xpath 512 " X: 512 + elseif a:n == 4 + Xpath 1024 " X: 1024 + endif + return a:x +endfunction + +function! F(x, n) + if a:n == 2 + Xpath 2048 " X: 0 + elseif a:n == 4 + Xpath 4096 " X: 4096 + endif +endfunction + +while 1 + try + let error = 0 + let v:errmsg = "" + + while 1 + try + Xpath 8192 " X: 8192 + call {NAME(THROW("name", 1), 1)}(ARG(4711, 1), 1) + Xpath 16384 " X: 0 + catch /^name$/ + Xpath 32768 " X: 32768 + catch /.*/ + let error = 1 + Xout "1:" v:exception "in" v:throwpoint + finally + if !error && $VIMNOERRTHROW && v:errmsg != "" + let error = 1 + Xout "1:" v:errmsg + endif + if error + Xpath 65536 " X: 0 + endif + let error = 0 + let v:errmsg = "" + break " discard error for $VIMNOERRTHROW + endtry + endwhile + + while 1 + try + Xpath 131072 " X: 131072 + call {NAME("F", 2)}(ARG(THROW("arg", 2), 2), 2) + Xpath 262144 " X: 0 + catch /^arg$/ + Xpath 524288 " X: 524288 + catch /.*/ + let error = 1 + Xout "2:" v:exception "in" v:throwpoint + finally + if !error && $VIMNOERRTHROW && v:errmsg != "" + let error = 1 + Xout "2:" v:errmsg + endif + if error + Xpath 1048576 " X: 0 + endif + let error = 0 + let v:errmsg = "" + break " discard error for $VIMNOERRTHROW + endtry + endwhile + + while 1 + try + Xpath 2097152 " X: 2097152 + call {NAME("THROW", 3)}(ARG("call", 3), 3) + Xpath 4194304 " X: 0 + catch /^call$/ + Xpath 8388608 " X: 8388608 + catch /^0$/ " default return value + Xpath 16777216 " X: 0 + Xout "3:" v:throwpoint + catch /.*/ + let error = 1 + Xout "3:" v:exception "in" v:throwpoint + finally + if !error && $VIMNOERRTHROW && v:errmsg != "" + let error = 1 + Xout "3:" v:errmsg + endif + if error + Xpath 33554432 " X: 0 + endif + let error = 0 + let v:errmsg = "" + break " discard error for $VIMNOERRTHROW + endtry + endwhile + + while 1 + try + Xpath 67108864 " X: 67108864 + call {NAME("F", 4)}(ARG(4711, 4), 4) + Xpath 134217728 " X: 134217728 + catch /.*/ + let error = 1 + Xout "4:" v:exception "in" v:throwpoint + finally + if !error && $VIMNOERRTHROW && v:errmsg != "" + let error = 1 + Xout "4:" v:errmsg + endif + if error + Xpath 268435456 " X: 0 + endif + let error = 0 + let v:errmsg = "" + break " discard error for $VIMNOERRTHROW + endtry + endwhile + + catch /^0$/ " default return value + Xpath 536870912 " X: 0 + Xout v:throwpoint + catch /.*/ + let error = 1 + Xout v:exception "in" v:throwpoint + finally + if !error && $VIMNOERRTHROW && v:errmsg != "" + let error = 1 + Xout v:errmsg + endif + if error + Xpath 1073741824 " X: 0 + endif + break " discard error for $VIMNOERRTHROW + endtry +endwhile + +unlet error +delfunction F + +Xcheck 212514423 + +" Leave THROW(), NAME(), and ARG() for the next test. + + +"------------------------------------------------------------------------------- +" Test 68: :throw across function calls in expressions {{{1 +" +" On a function call within an expression, an exception might be +" thrown when evaluating the function name, during evaluation of the +" arguments, or when the function is being executed. The exception +" can be caught by the caller. +" +" This test reuses the functions THROW(), NAME(), and ARG() from the +" previous test. +"------------------------------------------------------------------------------- + +XpathINIT + +function! F(x, n) + if a:n == 2 + Xpath 2048 " X: 0 + elseif a:n == 4 + Xpath 4096 " X: 4096 + endif + return a:x +endfunction + +unlet! var1 var2 var3 var4 + +while 1 + try + let error = 0 + let v:errmsg = "" + + while 1 + try + Xpath 8192 " X: 8192 + let var1 = {NAME(THROW("name", 1), 1)}(ARG(4711, 1), 1) + Xpath 16384 " X: 0 + catch /^name$/ + Xpath 32768 " X: 32768 + catch /.*/ + let error = 1 + Xout "1:" v:exception "in" v:throwpoint + finally + if !error && $VIMNOERRTHROW && v:errmsg != "" + let error = 1 + Xout "1:" v:errmsg + endif + if error + Xpath 65536 " X: 0 + endif + let error = 0 + let v:errmsg = "" + break " discard error for $VIMNOERRTHROW + endtry + endwhile + + while 1 + try + Xpath 131072 " X: 131072 + let var2 = {NAME("F", 2)}(ARG(THROW("arg", 2), 2), 2) + Xpath 262144 " X: 0 + catch /^arg$/ + Xpath 524288 " X: 524288 + catch /.*/ + let error = 1 + Xout "2:" v:exception "in" v:throwpoint + finally + if !error && $VIMNOERRTHROW && v:errmsg != "" + let error = 1 + Xout "2:" v:errmsg + endif + if error + Xpath 1048576 " X: 0 + endif + let error = 0 + let v:errmsg = "" + break " discard error for $VIMNOERRTHROW + endtry + endwhile + + while 1 + try + Xpath 2097152 " X: 2097152 + let var3 = {NAME("THROW", 3)}(ARG("call", 3), 3) + Xpath 4194304 " X: 0 + catch /^call$/ + Xpath 8388608 " X: 8388608 + catch /^0$/ " default return value + Xpath 16777216 " X: 0 + Xout "3:" v:throwpoint + catch /.*/ + let error = 1 + Xout "3:" v:exception "in" v:throwpoint + finally + if !error && $VIMNOERRTHROW && v:errmsg != "" + let error = 1 + Xout "3:" v:errmsg + endif + if error + Xpath 33554432 " X: 0 + endif + let error = 0 + let v:errmsg = "" + break " discard error for $VIMNOERRTHROW + endtry + endwhile + + while 1 + try + Xpath 67108864 " X: 67108864 + let var4 = {NAME("F", 4)}(ARG(4711, 4), 4) + Xpath 134217728 " X: 134217728 + catch /.*/ + let error = 1 + Xout "4:" v:exception "in" v:throwpoint + finally + if !error && $VIMNOERRTHROW && v:errmsg != "" + let error = 1 + Xout "4:" v:errmsg + endif + if error + Xpath 268435456 " X: 0 + endif + let error = 0 + let v:errmsg = "" + break " discard error for $VIMNOERRTHROW + endtry + endwhile + + catch /^0$/ " default return value + Xpath 536870912 " X: 0 + Xout v:throwpoint + catch /.*/ + let error = 1 + Xout v:exception "in" v:throwpoint + finally + if !error && $VIMNOERRTHROW && v:errmsg != "" + let error = 1 + Xout v:errmsg + endif + if error + Xpath 1073741824 " X: 0 + endif + break " discard error for $VIMNOERRTHROW + endtry +endwhile + +if exists("var1") || exists("var2") || exists("var3") || + \ !exists("var4") || var4 != 4711 + " The Xpath command does not accept 2^31 (negative); add explicitly: + let Xpath = Xpath + 2147483648 " X: 0 + if exists("var1") + Xout "var1 =" var1 + endif + if exists("var2") + Xout "var2 =" var2 + endif + if exists("var3") + Xout "var3 =" var3 + endif + if !exists("var4") + Xout "var4 unset" + elseif var4 != 4711 + Xout "var4 =" var4 + endif +endif + +unlet! error var1 var2 var3 var4 +delfunction THROW +delfunction NAME +delfunction ARG +delfunction F + +Xcheck 212514423 + + +"------------------------------------------------------------------------------- +" Test 69: :throw across :if, :elseif, :while {{{1 +" +" On an :if, :elseif, or :while command, an exception might be thrown +" during evaluation of the expression to test. The exception can be +" caught by the script. +"------------------------------------------------------------------------------- + +XpathINIT + +XloopINIT! 1 2 + +function! THROW(x) + XloopNEXT + Xloop 1 " X: 1 + 2 + 4 + throw a:x +endfunction + +try + + try + Xpath 8 " X: 8 + if 4711 == THROW("if") + 111 + Xpath 16 " X: 0 + else + Xpath 32 " X: 0 + endif + Xpath 64 " X: 0 + catch /^if$/ + Xpath 128 " X: 128 + catch /.*/ + Xpath 256 " X: 0 + Xout "if:" v:exception "in" v:throwpoint + endtry + + try + Xpath 512 " X: 512 + if 4711 == 4 + 7 + 1 + 1 + Xpath 1024 " X: 0 + elseif 4711 == THROW("elseif") + 222 + Xpath 2048 " X: 0 + else + Xpath 4096 " X: 0 + endif + Xpath 8192 " X: 0 + catch /^elseif$/ + Xpath 16384 " X: 16384 + catch /.*/ + Xpath 32768 " X: 0 + Xout "elseif:" v:exception "in" v:throwpoint + endtry + + try + Xpath 65536 " X: 65536 + while 4711 == THROW("while") + 4711 + Xpath 131072 " X: 0 + break + endwhile + Xpath 262144 " X: 0 + catch /^while$/ + Xpath 524288 " X: 524288 + catch /.*/ + Xpath 1048576 " X: 0 + Xout "while:" v:exception "in" v:throwpoint + endtry + +catch /^0$/ " default return value + Xpath 2097152 " X: 0 + Xout v:throwpoint +catch /.*/ + Xout v:exception "in" v:throwpoint + Xpath 4194304 " X: 0 +endtry + +Xpath 8388608 " X: 8388608 + +delfunction THROW + +Xcheck 8995471 + + +"------------------------------------------------------------------------------- +" Test 70: :throw across :return or :throw {{{1 +" +" On a :return or :throw command, an exception might be thrown during +" evaluation of the expression to return or throw, respectively. The +" exception can be caught by the script. +"------------------------------------------------------------------------------- + +XpathINIT + +let taken = "" + +function! THROW(x, n) + let g:taken = g:taken . "T" . a:n + throw a:x +endfunction + +function! F(x, y, n) + let g:taken = g:taken . "F" . a:n + return a:x + THROW(a:y, a:n) +endfunction + +function! G(x, y, n) + let g:taken = g:taken . "G" . a:n + throw a:x . THROW(a:y, a:n) + return a:x +endfunction + +try + try + Xpath 1 " X: 1 + call F(4711, "return", 1) + Xpath 2 " X: 0 + catch /^return$/ + Xpath 4 " X: 4 + catch /.*/ + Xpath 8 " X: 0 + Xout "return:" v:exception "in" v:throwpoint + endtry + + try + Xpath 16 " X: 16 + let var = F(4712, "return-var", 2) + Xpath 32 " X: 0 + catch /^return-var$/ + Xpath 64 " X: 64 + catch /.*/ + Xpath 128 " X: 0 + Xout "return-var:" v:exception "in" v:throwpoint + finally + unlet! var + endtry + + try + Xpath 256 " X: 256 + throw "except1" . THROW("throw1", 3) + Xpath 512 " X: 0 + catch /^except1/ + Xpath 1024 " X: 0 + catch /^throw1$/ + Xpath 2048 " X: 2048 + catch /.*/ + Xpath 4096 " X: 0 + Xout "throw1:" v:exception "in" v:throwpoint + endtry + + try + Xpath 8192 " X: 8192 + call G("except2", "throw2", 4) + Xpath 16384 " X: 0 + catch /^except2/ + Xpath 32768 " X: 0 + catch /^throw2$/ + Xpath 65536 " X: 65536 + catch /.*/ + Xpath 131072 " X: 0 + Xout "throw2:" v:exception "in" v:throwpoint + endtry + + try + Xpath 262144 " X: 262144 + let var = G("except3", "throw3", 5) + Xpath 524288 " X: 0 + catch /^except3/ + Xpath 1048576 " X: 0 + catch /^throw3$/ + Xpath 2097152 " X: 2097152 + catch /.*/ + Xpath 4194304 " X: 0 + Xout "throw3:" v:exception "in" v:throwpoint + finally + unlet! var + endtry + + let expected = "F1T1F2T2T3G4T4G5T5" + if taken != expected + Xpath 8388608 " X: 0 + Xout "'taken' is" taken "instead of" expected + endif + +catch /^0$/ " default return value + Xpath 16777216 " X: 0 + Xout v:throwpoint +catch /.*/ + Xpath 33554432 " X: 0 + Xout v:exception "in" v:throwpoint +endtry + +Xpath 67108864 " X: 67108864 + +unlet taken expected +delfunction THROW +delfunction F +delfunction G + +Xcheck 69544277 + + +"------------------------------------------------------------------------------- +" Test 71: :throw across :echo variants and :execute {{{1 +" +" On an :echo, :echon, :echomsg, :echoerr, or :execute command, an +" exception might be thrown during evaluation of the arguments to +" be displayed or executed as a command, respectively. Any following +" arguments are not evaluated, then. The exception can be caught by +" the script. +"------------------------------------------------------------------------------- + +XpathINIT + +let taken = "" + +function! THROW(x, n) + let g:taken = g:taken . "T" . a:n + throw a:x +endfunction + +function! F(n) + let g:taken = g:taken . "F" . a:n + return "F" . a:n +endfunction + +try + try + Xpath 1 " X: 1 + echo "echo" . THROW("echo-except", 1) F(1) + Xpath 2 " X: 0 + catch /^echo-except$/ + Xpath 4 " X: 4 + catch /.*/ + Xpath 8 " X: 0 + Xout "echo:" v:exception "in" v:throwpoint + endtry + + try + Xpath 16 " X: 16 + echon "echon" . THROW("echon-except", 2) F(2) + Xpath 32 " X: 0 + catch /^echon-except$/ + Xpath 64 " X: 64 + catch /.*/ + Xpath 128 " X: 0 + Xout "echon:" v:exception "in" v:throwpoint + endtry + + try + Xpath 256 " X: 256 + echomsg "echomsg" . THROW("echomsg-except", 3) F(3) + Xpath 512 " X: 0 + catch /^echomsg-except$/ + Xpath 1024 " X: 1024 + catch /.*/ + Xpath 2048 " X: 0 + Xout "echomsg:" v:exception "in" v:throwpoint + endtry + + try + Xpath 4096 " X: 4096 + echoerr "echoerr" . THROW("echoerr-except", 4) F(4) + Xpath 8192 " X: 0 + catch /^echoerr-except$/ + Xpath 16384 " X: 16384 + catch /Vim/ + Xpath 32768 " X: 0 + catch /echoerr/ + Xpath 65536 " X: 0 + catch /.*/ + Xpath 131072 " X: 0 + Xout "echoerr:" v:exception "in" v:throwpoint + endtry + + try + Xpath 262144 " X: 262144 + execute "echo 'execute" . THROW("execute-except", 5) F(5) "'" + Xpath 524288 " X: 0 + catch /^execute-except$/ + Xpath 1048576 " X: 1048576 + catch /.*/ + Xpath 2097152 " X: 0 + Xout "execute:" v:exception "in" v:throwpoint + endtry + + let expected = "T1T2T3T4T5" + if taken != expected + Xpath 4194304 " X: 0 + Xout "'taken' is" taken "instead of" expected + endif + +catch /^0$/ " default return value + Xpath 8388608 " X: 0 + Xout v:throwpoint +catch /.*/ + Xpath 16777216 " X: 0 + Xout v:exception "in" v:throwpoint +endtry + +Xpath 33554432 " X: 33554432 + +unlet taken expected +delfunction THROW +delfunction F + +Xcheck 34886997 + + +"------------------------------------------------------------------------------- +" Test 72: :throw across :let or :unlet {{{1 +" +" On a :let command, an exception might be thrown during evaluation +" of the expression to assign. On an :let or :unlet command, the +" evaluation of the name of the variable to be assigned or list or +" deleted, respectively, may throw an exception. Any following +" arguments are not evaluated, then. The exception can be caught by +" the script. +"------------------------------------------------------------------------------- + +XpathINIT + +let throwcount = 0 + +function! THROW(x) + let g:throwcount = g:throwcount + 1 + throw a:x +endfunction + +try + try + let $VAR = "old_value" + Xpath 1 " X: 1 + let $VAR = "let(" . THROW("var") . ")" + Xpath 2 " X: 0 + catch /^var$/ + Xpath 4 " X: 4 + finally + if $VAR != "old_value" + Xpath 8 " X: 0 + endif + endtry + + try + let @a = "old_value" + Xpath 16 " X: 16 + let @a = "let(" . THROW("reg") . ")" + Xpath 32 " X: 0 + catch /^reg$/ + try + Xpath 64 " X: 64 + let @A = "let(" . THROW("REG") . ")" + Xpath 128 " X: 0 + catch /^REG$/ + Xpath 256 " X: 256 + endtry + finally + if @a != "old_value" + Xpath 512 " X: 0 + endif + if @A != "old_value" + Xpath 1024 " X: 0 + endif + endtry + + try + let saved_gpath = &g:path + let saved_lpath = &l:path + Xpath 2048 " X: 2048 + let &path = "let(" . THROW("opt") . ")" + Xpath 4096 " X: 0 + catch /^opt$/ + try + Xpath 8192 " X: 8192 + let &g:path = "let(" . THROW("gopt") . ")" + Xpath 16384 " X: 0 + catch /^gopt$/ + try + Xpath 32768 " X: 32768 + let &l:path = "let(" . THROW("lopt") . ")" + Xpath 65536 " X: 0 + catch /^lopt$/ + Xpath 131072 " X: 131072 + endtry + endtry + finally + if &g:path != saved_gpath || &l:path != saved_lpath + Xpath 262144 " X: 0 + endif + let &g:path = saved_gpath + let &l:path = saved_lpath + endtry + + unlet! var1 var2 var3 + + try + Xpath 524288 " X: 524288 + let var1 = "let(" . THROW("var1") . ")" + Xpath 1048576 " X: 0 + catch /^var1$/ + Xpath 2097152 " X: 2097152 + finally + if exists("var1") + Xpath 4194304 " X: 0 + endif + endtry + + try + let var2 = "old_value" + Xpath 8388608 " X: 8388608 + let var2 = "let(" . THROW("var2"). ")" + Xpath 16777216 " X: 0 + catch /^var2$/ + Xpath 33554432 " X: 33554432 + finally + if var2 != "old_value" + Xpath 67108864 " X: 0 + endif + endtry + + try + Xpath 134217728 " X: 134217728 + let var{THROW("var3")} = 4711 + Xpath 268435456 " X: 0 + catch /^var3$/ + Xpath 536870912 " X: 536870912 + endtry + + let addpath = "" + + function ADDPATH(p) + let g:addpath = g:addpath . a:p + endfunction + + try + call ADDPATH("T1") + let var{THROW("var4")} var{ADDPATH("T2")} | call ADDPATH("T3") + call ADDPATH("T4") + catch /^var4$/ + call ADDPATH("T5") + endtry + + try + call ADDPATH("T6") + unlet var{THROW("var5")} var{ADDPATH("T7")} | call ADDPATH("T8") + call ADDPATH("T9") + catch /^var5$/ + call ADDPATH("T10") + endtry + + if addpath != "T1T5T6T10" || throwcount != 11 + throw "addpath: " . addpath . ", throwcount: " . throwcount + endif + + Xpath 1073741824 " X: 1073741824 + +catch /.*/ + " The Xpath command does not accept 2^31 (negative); add explicitly: + let Xpath = Xpath + 2147483648 " X: 0 + Xout v:exception "in" v:throwpoint +endtry + +unlet! var1 var2 var3 addpath throwcount +delfunction THROW + +Xcheck 1789569365 + + +"------------------------------------------------------------------------------- +" Test 73: :throw across :function, :delfunction {{{1 +" +" The :function and :delfunction commands may cause an expression +" specified in braces to be evaluated. During evaluation, an +" exception might be thrown. The exception can be caught by the +" script. +"------------------------------------------------------------------------------- + +XpathINIT + +let taken = "" + +function! THROW(x, n) + let g:taken = g:taken . "T" . a:n + throw a:x +endfunction + +function! EXPR(x, n) + let g:taken = g:taken . "E" . a:n + if a:n % 2 == 0 + call THROW(a:x, a:n) + endif + return 2 - a:n % 2 +endfunction + +try + try + " Define function. + Xpath 1 " X: 1 + function! F0() + endfunction + Xpath 2 " X: 2 + function! F{EXPR("function-def-ok", 1)}() + endfunction + Xpath 4 " X: 4 + function! F{EXPR("function-def", 2)}() + endfunction + Xpath 8 " X: 0 + catch /^function-def-ok$/ + Xpath 16 " X: 0 + catch /^function-def$/ + Xpath 32 " X: 32 + catch /.*/ + Xpath 64 " X: 0 + Xout "def:" v:exception "in" v:throwpoint + endtry + + try + " List function. + Xpath 128 " X: 128 + function F0 + Xpath 256 " X: 256 + function F{EXPR("function-lst-ok", 3)} + Xpath 512 " X: 512 + function F{EXPR("function-lst", 4)} + Xpath 1024 " X: 0 + catch /^function-lst-ok$/ + Xpath 2048 " X: 0 + catch /^function-lst$/ + Xpath 4096 " X: 4096 + catch /.*/ + Xpath 8192 " X: 0 + Xout "lst:" v:exception "in" v:throwpoint + endtry + + try + " Delete function + Xpath 16384 " X: 16384 + delfunction F0 + Xpath 32768 " X: 32768 + delfunction F{EXPR("function-del-ok", 5)} + Xpath 65536 " X: 65536 + delfunction F{EXPR("function-del", 6)} + Xpath 131072 " X: 0 + catch /^function-del-ok$/ + Xpath 262144 " X: 0 + catch /^function-del$/ + Xpath 524288 " X: 524288 + catch /.*/ + Xpath 1048576 " X: 0 + Xout "del:" v:exception "in" v:throwpoint + endtry + + let expected = "E1E2T2E3E4T4E5E6T6" + if taken != expected + Xpath 2097152 " X: 0 + Xout "'taken' is" taken "instead of" expected + endif + +catch /.*/ + Xpath 4194304 " X: 0 + Xout v:exception "in" v:throwpoint +endtry + +Xpath 8388608 " X: 8388608 + +unlet taken expected +delfunction THROW +delfunction EXPR + +Xcheck 9032615 + + +"------------------------------------------------------------------------------- +" Test 74: :throw across builtin functions and commands {{{1 +" +" Some functions like exists(), searchpair() take expression +" arguments, other functions or commands like substitute() or +" :substitute cause an expression (specified in the regular +" expression) to be evaluated. During evaluation an exception +" might be thrown. The exception can be caught by the script. +"------------------------------------------------------------------------------- + +XpathINIT + +let taken = "" + +function! THROW(x, n) + let g:taken = g:taken . "T" . a:n + throw a:x +endfunction + +function! EXPR(x, n) + let g:taken = g:taken . "E" . a:n + call THROW(a:x . a:n, a:n) + return "EXPR" +endfunction + +function! SKIP(x, n) + let g:taken = g:taken . "S" . a:n . "(" . line(".") + let theline = getline(".") + if theline =~ "skip" + let g:taken = g:taken . "s)" + return 1 + elseif theline =~ "throw" + let g:taken = g:taken . "t)" + call THROW(a:x . a:n, a:n) + else + let g:taken = g:taken . ")" + return 0 + endif +endfunction + +function! SUBST(x, n) + let g:taken = g:taken . "U" . a:n . "(" . line(".") + let theline = getline(".") + if theline =~ "not" " SUBST() should not be called for this line + let g:taken = g:taken . "n)" + call THROW(a:x . a:n, a:n) + elseif theline =~ "throw" + let g:taken = g:taken . "t)" + call THROW(a:x . a:n, a:n) + else + let g:taken = g:taken . ")" + return "replaced" + endif +endfunction + +try + try + Xpath 1 " X: 1 + let result = exists('*{EXPR("exists", 1)}') + Xpath 2 " X: 0 + catch /^exists1$/ + Xpath 4 " X: 4 + try + let result = exists('{EXPR("exists", 2)}') + Xpath 8 " X: 0 + catch /^exists2$/ + Xpath 16 " X: 16 + catch /.*/ + Xpath 32 " X: 0 + Xout "exists2:" v:exception "in" v:throwpoint + endtry + catch /.*/ + Xpath 64 " X: 0 + Xout "exists1:" v:exception "in" v:throwpoint + endtry + + try + let file = tempname() + exec "edit" file + insert +begin + xx +middle 3 + xx +middle 5 skip + xx +middle 7 throw + xx +end +. + normal! gg + Xpath 128 " X: 128 + let result = + \ searchpair("begin", "middle", "end", '', 'SKIP("searchpair", 3)') + Xpath 256 " X: 256 + let result = + \ searchpair("begin", "middle", "end", '', 'SKIP("searchpair", 4)') + Xpath 512 " X: 0 + let result = + \ searchpair("begin", "middle", "end", '', 'SKIP("searchpair", 5)') + Xpath 1024 " X: 0 + catch /^searchpair[35]$/ + Xpath 2048 " X: 0 + catch /^searchpair4$/ + Xpath 4096 " X: 4096 + catch /.*/ + Xpath 8192 " X: 0 + Xout "searchpair:" v:exception "in" v:throwpoint + finally + bwipeout! + call delete(file) + endtry + + try + let file = tempname() + exec "edit" file + insert +subst 1 +subst 2 +not +subst 4 +subst throw +subst 6 +. + normal! gg + Xpath 16384 " X: 16384 + 1,2substitute/subst/\=SUBST("substitute", 6)/ + try + Xpath 32768 " X: 32768 + try + let v:errmsg = "" + 3substitute/subst/\=SUBST("substitute", 7)/ + finally + if v:errmsg != "" + " If exceptions are not thrown on errors, fake the error + " exception in order to get the same execution path. + throw "faked Vim(substitute)" + endif + endtry + catch /Vim(substitute)/ " Pattern not found ('e' flag missing) + Xpath 65536 " X: 65536 + 3substitute/subst/\=SUBST("substitute", 8)/e + Xpath 131072 " X: 131072 + endtry + Xpath 262144 " X: 262144 + 4,6substitute/subst/\=SUBST("substitute", 9)/ + Xpath 524288 " X: 0 + catch /^substitute[678]/ + Xpath 1048576 " X: 0 + catch /^substitute9/ + Xpath 2097152 " X: 2097152 + finally + bwipeout! + call delete(file) + endtry + + try + Xpath 4194304 " X: 4194304 + let var = substitute("sub", "sub", '\=THROW("substitute()y", 10)', '') + Xpath 8388608 " X: 0 + catch /substitute()y/ + Xpath 16777216 " X: 16777216 + catch /.*/ + Xpath 33554432 " X: 0 + Xout "substitute()y:" v:exception "in" v:throwpoint + endtry + + try + Xpath 67108864 " X: 67108864 + let var = substitute("not", "sub", '\=THROW("substitute()n", 11)', '') + Xpath 134217728 " X: 134217728 + catch /substitute()n/ + Xpath 268435456 " X: 0 + catch /.*/ + Xpath 536870912 " X: 0 + Xout "substitute()n:" v:exception "in" v:throwpoint + endtry + + let expected = "E1T1E2T2S3(3)S4(5s)S4(7t)T4U6(1)U6(2)U9(4)U9(5t)T9T10" + if taken != expected + Xpath 1073741824 " X: 0 + Xout "'taken' is" taken "instead of" expected + endif + +catch /.*/ + " The Xpath command does not accept 2^31 (negative); add explicitly: + let Xpath = Xpath + 2147483648 " X: 0 + Xout v:exception "in" v:throwpoint +endtry + +unlet result var taken expected +delfunction THROW +delfunction EXPR +delfunction SKIP +delfunction SUBST + +Xcheck 224907669 + + +"------------------------------------------------------------------------------- +" Test 75: Errors in builtin functions. {{{1 +" +" On an error in a builtin function called inside a :try/:endtry +" region, the evaluation of the expression calling that function and +" the command containing that expression are abandoned. The error can +" be caught as an exception. +" +" A simple :call of the builtin function is a trivial case. If the +" builtin function is called in the argument list of another function, +" no further arguments are evaluated, and the other function is not +" executed. If the builtin function is called from the argument of +" a :return command, the :return command is not executed. If the +" builtin function is called from the argument of a :throw command, +" the :throw command is not executed. The evaluation of the +" expression calling the builtin function is abandoned. +"------------------------------------------------------------------------------- + +XpathINIT + +function! F1(arg1) + Xpath 1 " X: 0 +endfunction + +function! F2(arg1, arg2) + Xpath 2 " X: 0 +endfunction + +function! G() + Xpath 4 " X: 0 +endfunction + +function! H() + Xpath 8 " X: 0 +endfunction + +function! R() + while 1 + try + let caught = 0 + let v:errmsg = "" + Xpath 16 " X: 16 + return append(1, "s") + catch /E21/ + let caught = 1 + catch /.*/ + Xpath 32 " X: 0 + finally + Xpath 64 " X: 64 + if caught || $VIMNOERRTHROW && v:errmsg =~ 'E21' + Xpath 128 " X: 128 + endif + break " discard error for $VIMNOERRTHROW + endtry + endwhile + Xpath 256 " X: 256 +endfunction + +try + set noma " let append() fail with "E21" + + while 1 + try + let caught = 0 + let v:errmsg = "" + Xpath 512 " X: 512 + call append(1, "s") + catch /E21/ + let caught = 1 + catch /.*/ + Xpath 1024 " X: 0 + finally + Xpath 2048 " X: 2048 + if caught || $VIMNOERRTHROW && v:errmsg =~ 'E21' + Xpath 4096 " X: 4096 + endif + break " discard error for $VIMNOERRTHROW + endtry + endwhile + + while 1 + try + let caught = 0 + let v:errmsg = "" + Xpath 8192 " X: 8192 + call F1('x' . append(1, "s")) + catch /E21/ + let caught = 1 + catch /.*/ + Xpath 16384 " X: 0 + finally + Xpath 32768 " X: 32768 + if caught || $VIMNOERRTHROW && v:errmsg =~ 'E21' + Xpath 65536 " X: 65536 + endif + break " discard error for $VIMNOERRTHROW + endtry + endwhile + + while 1 + try + let caught = 0 + let v:errmsg = "" + Xpath 131072 " X: 131072 + call F2('x' . append(1, "s"), G()) + catch /E21/ + let caught = 1 + catch /.*/ + Xpath 262144 " X: 0 + finally + Xpath 524288 " X: 524288 + if caught || $VIMNOERRTHROW && v:errmsg =~ 'E21' + Xpath 1048576 " X: 1048576 + endif + break " discard error for $VIMNOERRTHROW + endtry + endwhile + + call R() + + while 1 + try + let caught = 0 + let v:errmsg = "" + Xpath 2097152 " X: 2097152 + throw "T" . append(1, "s") + catch /E21/ + let caught = 1 + catch /^T.*/ + Xpath 4194304 " X: 0 + catch /.*/ + Xpath 8388608 " X: 0 + finally + Xpath 16777216 " X: 16777216 + if caught || $VIMNOERRTHROW && v:errmsg =~ 'E21' + Xpath 33554432 " X: 33554432 + endif + break " discard error for $VIMNOERRTHROW + endtry + endwhile + + while 1 + try + let caught = 0 + let v:errmsg = "" + Xpath 67108864 " X: 67108864 + let x = "a" + let x = x . "b" . append(1, "s") . H() + catch /E21/ + let caught = 1 + catch /.*/ + Xpath 134217728 " X: 0 + finally + Xpath 268435456 " X: 268435456 + if caught || $VIMNOERRTHROW && v:errmsg =~ 'E21' + Xpath 536870912 " X: 536870912 + endif + if x == "a" + Xpath 1073741824 " X: 1073741824 + endif + break " discard error for $VIMNOERRTHROW + endtry + endwhile +catch /.*/ + " The Xpath command does not accept 2^31 (negative); add explicitly: + let Xpath = Xpath + 2147483648 " X: 0 + Xout v:exception "in" v:throwpoint +finally + set ma& +endtry + +unlet! caught x +delfunction F1 +delfunction F2 +delfunction G +delfunction H +delfunction R + +Xcheck 2000403408 + + +"------------------------------------------------------------------------------- +" Test 76: Errors, interrupts, :throw during expression evaluation {{{1 +" +" When a function call made during expression evaluation is aborted +" due to an error inside a :try/:endtry region or due to an interrupt +" or a :throw, the expression evaluation is aborted as well. No +" message is displayed for the cancelled expression evaluation. On an +" error not inside :try/:endtry, the expression evaluation continues. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + + let taken = "" + + function! ERR(n) + let g:taken = g:taken . "E" . a:n + asdf + endfunction + + function! ERRabort(n) abort + let g:taken = g:taken . "A" . a:n + asdf + endfunction " returns -1; may cause follow-up msg for illegal var/func name + + function! WRAP(n, arg) + let g:taken = g:taken . "W" . a:n + let g:saved_errmsg = v:errmsg + return arg + endfunction + + function! INT(n) + let g:taken = g:taken . "I" . a:n + "INTERRUPT9 + let dummy = 0 + endfunction + + function! THR(n) + let g:taken = g:taken . "T" . a:n + throw "should not be caught" + endfunction + + function! CONT(n) + let g:taken = g:taken . "C" . a:n + endfunction + + function! MSG(n) + let g:taken = g:taken . "M" . a:n + let errmsg = (a:n >= 37 && a:n <= 44) ? g:saved_errmsg : v:errmsg + let msgptn = (a:n >= 10 && a:n <= 27) ? "^$" : "asdf" + if errmsg !~ msgptn + let g:taken = g:taken . "x" + Xout "Expr" a:n.": Unexpected message:" v:errmsg + endif + let v:errmsg = "" + let g:saved_errmsg = "" + endfunction + + let v:errmsg = "" + + try + let t = 1 + XloopINIT 1 2 + while t <= 9 + Xloop 1 " X: 511 + try + if t == 1 + let v{ERR(t) + CONT(t)} = 0 + elseif t == 2 + let v{ERR(t) + CONT(t)} + elseif t == 3 + let var = exists('v{ERR(t) + CONT(t)}') + elseif t == 4 + unlet v{ERR(t) + CONT(t)} + elseif t == 5 + function F{ERR(t) + CONT(t)}() + endfunction + elseif t == 6 + function F{ERR(t) + CONT(t)} + elseif t == 7 + let var = exists('*F{ERR(t) + CONT(t)}') + elseif t == 8 + delfunction F{ERR(t) + CONT(t)} + elseif t == 9 + let var = ERR(t) + CONT(t) + endif + catch /asdf/ + " v:errmsg is not set when the error message is converted to an + " exception. Set it to the original error message. + let v:errmsg = substitute(v:exception, '^Vim:', '', "") + catch /^Vim\((\a\+)\)\=:/ + " An error exception has been thrown after the original error. + let v:errmsg = "" + finally + call MSG(t) + let t = t + 1 + XloopNEXT + continue " discard an aborting error + endtry + endwhile + catch /.*/ + Xpath 512 " X: 0 + Xout v:exception "in" ExtraVimThrowpoint() + endtry + + try + let t = 10 + XloopINIT 1024 2 + while t <= 18 + Xloop 1 " X: 1024 * 511 + try + if t == 10 + let v{INT(t) + CONT(t)} = 0 + elseif t == 11 + let v{INT(t) + CONT(t)} + elseif t == 12 + let var = exists('v{INT(t) + CONT(t)}') + elseif t == 13 + unlet v{INT(t) + CONT(t)} + elseif t == 14 + function F{INT(t) + CONT(t)}() + endfunction + elseif t == 15 + function F{INT(t) + CONT(t)} + elseif t == 16 + let var = exists('*F{INT(t) + CONT(t)}') + elseif t == 17 + delfunction F{INT(t) + CONT(t)} + elseif t == 18 + let var = INT(t) + CONT(t) + endif + catch /^Vim\((\a\+)\)\=:\(Interrupt\)\@!/ + " An error exception has been triggered after the interrupt. + let v:errmsg = substitute(v:exception, + \ '^Vim\((\a\+)\)\=:', '', "") + finally + call MSG(t) + let t = t + 1 + XloopNEXT + continue " discard interrupt + endtry + endwhile + catch /.*/ + Xpath 524288 " X: 0 + Xout v:exception "in" ExtraVimThrowpoint() + endtry + + try + let t = 19 + XloopINIT 1048576 2 + while t <= 27 + Xloop 1 " X: 1048576 * 511 + try + if t == 19 + let v{THR(t) + CONT(t)} = 0 + elseif t == 20 + let v{THR(t) + CONT(t)} + elseif t == 21 + let var = exists('v{THR(t) + CONT(t)}') + elseif t == 22 + unlet v{THR(t) + CONT(t)} + elseif t == 23 + function F{THR(t) + CONT(t)}() + endfunction + elseif t == 24 + function F{THR(t) + CONT(t)} + elseif t == 25 + let var = exists('*F{THR(t) + CONT(t)}') + elseif t == 26 + delfunction F{THR(t) + CONT(t)} + elseif t == 27 + let var = THR(t) + CONT(t) + endif + catch /^Vim\((\a\+)\)\=:/ + " An error exception has been triggered after the :throw. + let v:errmsg = substitute(v:exception, + \ '^Vim\((\a\+)\)\=:', '', "") + finally + call MSG(t) + let t = t + 1 + XloopNEXT + continue " discard exception + endtry + endwhile + catch /.*/ + Xpath 536870912 " X: 0 + Xout v:exception "in" ExtraVimThrowpoint() + endtry + + let v{ERR(28) + CONT(28)} = 0 + call MSG(28) + let v{ERR(29) + CONT(29)} + call MSG(29) + let var = exists('v{ERR(30) + CONT(30)}') + call MSG(30) + unlet v{ERR(31) + CONT(31)} + call MSG(31) + function F{ERR(32) + CONT(32)}() + endfunction + call MSG(32) + function F{ERR(33) + CONT(33)} + call MSG(33) + let var = exists('*F{ERR(34) + CONT(34)}') + call MSG(34) + delfunction F{ERR(35) + CONT(35)} + call MSG(35) + let var = ERR(36) + CONT(36) + call MSG(36) + + let saved_errmsg = "" + + let v{WRAP(37, ERRabort(37)) + CONT(37)} = 0 + call MSG(37) + let v{WRAP(38, ERRabort(38)) + CONT(38)} + call MSG(38) + let var = exists('v{WRAP(39, ERRabort(39)) + CONT(39)}') + call MSG(39) + unlet v{WRAP(40, ERRabort(40)) + CONT(40)} + call MSG(40) + function F{WRAP(41, ERRabort(41)) + CONT(41)}() + endfunction + call MSG(41) + function F{WRAP(42, ERRabort(42)) + CONT(42)} + call MSG(42) + let var = exists('*F{WRAP(43, ERRabort(43)) + CONT(43)}') + call MSG(43) + delfunction F{WRAP(44, ERRabort(44)) + CONT(44)} + call MSG(44) + let var = ERRabort(45) + CONT(45) + call MSG(45) + + Xpath 1073741824 " X: 1073741824 + + let expected = "" + \ . "E1M1E2M2E3M3E4M4E5M5E6M6E7M7E8M8E9M9" + \ . "I10M10I11M11I12M12I13M13I14M14I15M15I16M16I17M17I18M18" + \ . "T19M19T20M20T21M21T22M22T23M23T24M24T25M25T26M26T27M27" + \ . "E28C28M28E29C29M29E30C30M30E31C31M31E32C32M32E33C33M33" + \ . "E34C34M34E35C35M35E36C36M36" + \ . "A37W37C37M37A38W38C38M38A39W39C39M39A40W40C40M40A41W41C41M41" + \ . "A42W42C42M42A43W43C43M43A44W44C44M44A45C45M45" + + if taken != expected + " The Xpath command does not accept 2^31 (negative); display explicitly: + exec "!echo 2147483648 >>" . g:ExtraVimResult + " X: 0 + Xout "'taken' is" taken "instead of" expected + if substitute(taken, + \ '\(.*\)E3C3M3x\(.*\)E30C30M30x\(.*\)A39C39M39x\(.*\)', + \ '\1E3M3\2E30C30M30\3A39C39M39\4', + \ "") == expected + Xout "Is ++emsg_skip for var with expr_start non-NULL" + \ "in f_exists ok?" + endif + endif + + unlet! v var saved_errmsg taken expected + call delete(WA_t5) + call delete(WA_t14) + call delete(WA_t23) + unlet! WA_t5 WA_t14 WA_t23 + delfunction WA_t5 + delfunction WA_t14 + delfunction WA_t23 + +endif + +Xcheck 1610087935 + + +"------------------------------------------------------------------------------- +" Test 77: Errors, interrupts, :throw in name{brace-expression} {{{1 +" +" When a function call made during evaluation of an expression in +" braces as part of a function name after ":function" is aborted due +" to an error inside a :try/:endtry region or due to an interrupt or +" a :throw, the expression evaluation is aborted as well, and the +" function definition is ignored, skipping all commands to the +" ":endfunction". On an error not inside :try/:endtry, the expression +" evaluation continues and the function gets defined, and can be +" called and deleted. +"------------------------------------------------------------------------------- + +XpathINIT + +XloopINIT 1 4 + +function! ERR() abort + Xloop 1 " X: 1 + 4 + 16 + 64 + asdf +endfunction " returns -1 + +function! OK() + Xloop 2 " X: 2 * (1 + 4 + 16) + let v:errmsg = "" + return 0 +endfunction + +let v:errmsg = "" + +Xpath 4096 " X: 4096 +function! F{1 + ERR() + OK()}(arg) + " F0 should be defined. + if exists("a:arg") && a:arg == "calling" + Xpath 8192 " X: 8192 + else + Xpath 16384 " X: 0 + endif +endfunction +if v:errmsg != "" + Xpath 32768 " X: 0 +endif +XloopNEXT + +Xpath 65536 " X: 65536 +call F{1 + ERR() + OK()}("calling") +if v:errmsg != "" + Xpath 131072 " X: 0 +endif +XloopNEXT + +Xpath 262144 " X: 262144 +delfunction F{1 + ERR() + OK()} +if v:errmsg != "" + Xpath 524288 " X: 0 +endif +XloopNEXT + +try + while 1 + let caught = 0 + try + Xpath 1048576 " X: 1048576 + function! G{1 + ERR() + OK()}(arg) + " G0 should not be defined, and the function body should be + " skipped. + if exists("a:arg") && a:arg == "calling" + Xpath 2097152 " X: 0 + else + Xpath 4194304 " X: 0 + endif + " Use an unmatched ":finally" to check whether the body is + " skipped when an error occurs in ERR(). This works whether or + " not the exception is converted to an exception. + finally + Xpath 8388608 " X: 0 + Xout "Body of G{1 + ERR() + OK()}() not skipped" + " Discard the aborting error or exception, and break the + " while loop. + break + " End the try conditional and start a new one to avoid + " ":catch after :finally" errors. + endtry + try + Xpath 16777216 " X: 0 + endfunction + + " When the function was not defined, this won't be reached - whether + " the body was skipped or not. When the function was defined, it + " can be called and deleted here. + Xpath 33554432 " X: 0 + Xout "G0() has been defined" + XloopNEXT + try + call G{1 + ERR() + OK()}("calling") + catch /.*/ + Xpath 67108864 " X: 0 + endtry + Xpath 134217728 " X: 0 + XloopNEXT + try + delfunction G{1 + ERR() + OK()} + catch /.*/ + Xpath 268435456 " X: 0 + endtry + catch /asdf/ + " Jumped to when the function is not defined and the body is + " skipped. + let caught = 1 + catch /.*/ + Xpath 536870912 " X: 0 + finally + if !caught && !$VIMNOERRTHROW + Xpath 1073741824 " X: 0 + endif + break " discard error for $VIMNOERRTHROW + endtry " jumped to when the body is not skipped + endwhile +catch /.*/ + " The Xpath command does not accept 2^31 (negative); add explicitly: + let Xpath = Xpath + 2147483648 " X: 0 + Xout "Body of G{1 + ERR() + OK()}() not skipped, exception caught" + Xout v:exception "in" v:throwpoint +endtry + +Xcheck 1388671 + + +"------------------------------------------------------------------------------- +" Test 78: Messages on parsing errors in expression evaluation {{{1 +" +" When an expression evaluation detects a parsing error, an error +" message is given and converted to an exception, and the expression +" evaluation is aborted. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + + let taken = "" + + function! F(n) + let g:taken = g:taken . "F" . a:n + endfunction + + function! MSG(n, enr, emsg) + let g:taken = g:taken . "M" . a:n + let english = v:lang == "C" || v:lang =~ '^[Ee]n' + if a:enr == "" + Xout "TODO: Add message number for:" a:emsg + let v:errmsg = ":" . v:errmsg + endif + if v:errmsg !~ '^'.a:enr.':' || (english && v:errmsg !~ a:emsg) + if v:errmsg == "" + Xout "Expr" a:n.": Message missing." + let g:taken = g:taken . "x" + else + let v:errmsg = escape(v:errmsg, '"') + Xout "Expr" a:n.": Unexpected message:" v:errmsg + Xout "Expected: " . a:enr . ': ' . a:emsg + let g:taken = g:taken . "X" + endif + endif + endfunction + + function! CONT(n) + let g:taken = g:taken . "C" . a:n + endfunction + + let v:errmsg = "" + XloopINIT 1 2 + + try + let t = 1 + while t <= 14 + let g:taken = g:taken . "T" . t + let v:errmsg = "" + try + let caught = 0 + if t == 1 + let v{novar + CONT(t)} = 0 + elseif t == 2 + let v{novar + CONT(t)} + elseif t == 3 + let var = exists('v{novar + CONT(t)}') + elseif t == 4 + unlet v{novar + CONT(t)} + elseif t == 5 + function F{novar + CONT(t)}() + endfunction + elseif t == 6 + function F{novar + CONT(t)} + elseif t == 7 + let var = exists('*F{novar + CONT(t)}') + elseif t == 8 + delfunction F{novar + CONT(t)} + elseif t == 9 + echo novar + CONT(t) + elseif t == 10 + echo v{novar + CONT(t)} + elseif t == 11 + echo F{novar + CONT(t)} + elseif t == 12 + let var = novar + CONT(t) + elseif t == 13 + let var = v{novar + CONT(t)} + elseif t == 14 + let var = F{novar + CONT(t)}() + endif + catch /^Vim\((\a\+)\)\=:/ + " v:errmsg is not set when the error message is converted to an + " exception. Set it to the original error message. + let v:errmsg = substitute(v:exception, + \ '^Vim\((\a\+)\)\=:', '', "") + let caught = 1 + finally + if t <= 8 && t != 3 && t != 7 + call MSG(t, 'E475', 'Invalid argument\>') + else + if !caught " no error exceptions ($VIMNOERRTHROW set) + call MSG(t, 'E15', "Invalid expression") + else + call MSG(t, 'E121', "Undefined variable") + endif + endif + let t = t + 1 + XloopNEXT + continue " discard an aborting error + endtry + endwhile + catch /.*/ + Xloop 1 " X: 0 + Xout t.":" v:exception "in" ExtraVimThrowpoint() + endtry + + function! T(n, expr, enr, emsg) + try + let g:taken = g:taken . "T" . a:n + let v:errmsg = "" + try + let caught = 0 + execute "let var = " . a:expr + catch /^Vim\((\a\+)\)\=:/ + " v:errmsg is not set when the error message is converted to an + " exception. Set it to the original error message. + let v:errmsg = substitute(v:exception, + \ '^Vim\((\a\+)\)\=:', '', "") + let caught = 1 + finally + if !caught " no error exceptions ($VIMNOERRTHROW set) + call MSG(a:n, 'E15', "Invalid expression") + else + call MSG(a:n, a:enr, a:emsg) + endif + XloopNEXT + " Discard an aborting error: + return + endtry + catch /.*/ + Xloop 1 " X: 0 + Xout a:n.":" v:exception "in" ExtraVimThrowpoint() + endtry + endfunction + + call T(15, 'Nofunc() + CONT(15)', 'E117', "Unknown function") + call T(16, 'F(1 2 + CONT(16))', 'E116', "Invalid arguments") + call T(17, 'F(1, 2) + CONT(17)', 'E118', "Too many arguments") + call T(18, 'F() + CONT(18)', 'E119', "Not enough arguments") + call T(19, '{(1} + CONT(19)', 'E110', "Missing ')'") + call T(20, '("abc"[1) + CONT(20)', 'E111', "Missing ']'") + call T(21, '(1 +) + CONT(21)', 'E15', "Invalid expression") + call T(22, '1 2 + CONT(22)', 'E15', "Invalid expression") + call T(23, '(1 ? 2) + CONT(23)', 'E109', "Missing ':' after '?'") + call T(24, '("abc) + CONT(24)', 'E114', "Missing quote") + call T(25, "('abc) + CONT(25)", 'E115', "Missing quote") + call T(26, '& + CONT(26)', 'E112', "Option name missing") + call T(27, '&asdf + CONT(27)', 'E113', "Unknown option") + + Xpath 134217728 " X: 134217728 + + let expected = "" + \ . "T1M1T2M2T3M3T4M4T5M5T6M6T7M7T8M8T9M9T10M10T11M11T12M12T13M13T14M14" + \ . "T15M15T16M16T17M17T18M18T19M19T20M20T21M21T22M22T23M23T24M24T25M25" + \ . "T26M26T27M27" + + if taken != expected + Xpath 268435456 " X: 0 + Xout "'taken' is" taken "instead of" expected + if substitute(taken, '\(.*\)T3M3x\(.*\)', '\1T3M3\2', "") == expected + Xout "Is ++emsg_skip for var with expr_start non-NULL" + \ "in f_exists ok?" + endif + endif + + unlet! var caught taken expected + call delete(WA_t5) + unlet! WA_t5 + delfunction WA_t5 + +endif + +Xcheck 134217728 + + +"------------------------------------------------------------------------------- +" Test 79: Throwing one of several errors for the same command {{{1 +" +" When several errors appear in a row (for instance during expression +" evaluation), the first as the most specific one is used when +" throwing an error exception. If, however, a syntax error is +" detected afterwards, this one is used for the error exception. +" On a syntax error, the next command is not executed, on a normal +" error, however, it is (relevant only in a function without the +" "abort" flag). v:errmsg is not set. +" +" If throwing error exceptions is configured off, v:errmsg is always +" set to the latest error message, that is, to the more general +" message or the syntax error, respectively. +"------------------------------------------------------------------------------- + +XpathINIT + +XloopINIT 1 2 + +function! NEXT(cmd) + exec a:cmd . " | Xloop 1" +endfunction + +call NEXT('echo novar') " X: 1 * 1 (checks nextcmd) +XloopNEXT +call NEXT('let novar #') " X: 0 * 2 (skips nextcmd) +XloopNEXT +call NEXT('unlet novar #') " X: 0 * 4 (skips nextcmd) +XloopNEXT +call NEXT('let {novar}') " X: 0 * 8 (skips nextcmd) +XloopNEXT +call NEXT('unlet{ novar}') " X: 0 * 16 (skips nextcmd) + +function! EXEC(cmd) + exec a:cmd +endfunction + +function! MATCH(expected, msg, enr, emsg) + let msg = a:msg + if a:enr == "" + Xout "TODO: Add message number for:" a:emsg + let msg = ":" . msg + endif + let english = v:lang == "C" || v:lang =~ '^[Ee]n' + if msg !~ '^'.a:enr.':' || (english && msg !~ a:emsg) + let match = 0 + if a:expected " no match although expected + if a:msg == "" + Xout "Message missing." + else + let msg = escape(msg, '"') + Xout "Unexpected message:" msg + Xout "Expected:" a:enr . ": " . a:emsg + endif + endif + else + let match = 1 + if !a:expected " match although not expected + let msg = escape(msg, '"') + Xout "Unexpected message:" msg + Xout "Expected none." + endif + endif + return match +endfunction + +try + + while 1 " dummy loop + try + let v:errmsg = "" + let caught = 0 + let thrmsg = "" + call EXEC('echo novar') " normal error + catch /^Vim\((\a\+)\)\=:/ + let caught = 1 + let thrmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "") + finally + Xpath 32 " X: 32 + if !caught + if !$VIMNOERRTHROW + Xpath 64 " X: 0 + endif + elseif !MATCH(1, thrmsg, 'E121', "Undefined variable") + \ || v:errmsg != "" + Xpath 128 " X: 0 + endif + if !caught && !MATCH(1, v:errmsg, 'E15', "Invalid expression") + Xpath 256 " X: 0 + endif + break " discard error if $VIMNOERRTHROW == 1 + endtry + endwhile + + Xpath 512 " X: 512 + let cmd = "let" + XloopINIT 1024 32 + while cmd != "" + try + let v:errmsg = "" + let caught = 0 + let thrmsg = "" + call EXEC(cmd . ' novar #') " normal plus syntax error + catch /^Vim\((\a\+)\)\=:/ + let caught = 1 + let thrmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "") + finally + Xloop 1 " X: 1024 * (1 + 32) + if !caught + if !$VIMNOERRTHROW + Xloop 2 " X: 0 + endif + else + if cmd == "let" + let match = MATCH(0, thrmsg, 'E121', "Undefined variable") + elseif cmd == "unlet" + let match = MATCH(0, thrmsg, 'E108', "No such variable") + endif + if match " normal error + Xloop 4 " X: 0 + endif + if !MATCH(1, thrmsg, 'E488', "Trailing characters") + \|| v:errmsg != "" + " syntax error + Xloop 8 " X: 0 + endif + endif + if !caught && !MATCH(1, v:errmsg, 'E488', "Trailing characters") + " last error + Xloop 16 " X: 0 + endif + if cmd == "let" + let cmd = "unlet" + else + let cmd = "" + endif + XloopNEXT + continue " discard error if $VIMNOERRTHROW == 1 + endtry + endwhile + + Xpath 1048576 " X: 1048576 + let cmd = "let" + XloopINIT 2097152 32 + while cmd != "" + try + let v:errmsg = "" + let caught = 0 + let thrmsg = "" + call EXEC(cmd . ' {novar}') " normal plus syntax error + catch /^Vim\((\a\+)\)\=:/ + let caught = 1 + let thrmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "") + finally + Xloop 1 " X: 2097152 * (1 + 32) + if !caught + if !$VIMNOERRTHROW + Xloop 2 " X: 0 + endif + else + if MATCH(0, thrmsg, 'E121', "Undefined variable") " normal error + Xloop 4 " X: 0 + endif + if !MATCH(1, thrmsg, 'E475', 'Invalid argument\>') + \ || v:errmsg != "" " syntax error + Xloop 8 " X: 0 + endif + endif + if !caught && !MATCH(1, v:errmsg, 'E475', 'Invalid argument\>') + " last error + Xloop 16 " X: 0 + endif + if cmd == "let" + let cmd = "unlet" + else + let cmd = "" + endif + XloopNEXT + continue " discard error if $VIMNOERRTHROW == 1 + endtry + endwhile + +catch /.*/ + " The Xpath command does not accept 2^31 (negative); add explicitly: + let Xpath = Xpath + 2147483648 " X: 0 + Xout v:exception "in" v:throwpoint +endtry + +unlet! next_command thrmsg match +delfunction NEXT +delfunction EXEC +delfunction MATCH + +Xcheck 70288929 + + +"------------------------------------------------------------------------------- +" Test 80: Syntax error in expression for illegal :elseif {{{1 +" +" If there is a syntax error in the expression after an illegal +" :elseif, an error message is given (or an error exception thrown) +" for the illegal :elseif rather than the expression error. +"------------------------------------------------------------------------------- + +XpathINIT + +function! MSG(enr, emsg) + let english = v:lang == "C" || v:lang =~ '^[Ee]n' + if a:enr == "" + Xout "TODO: Add message number for:" a:emsg + let v:errmsg = ":" . v:errmsg + endif + let match = 1 + if v:errmsg !~ '^'.a:enr.':' || (english && v:errmsg !~ a:emsg) + let match = 0 + if v:errmsg == "" + Xout "Message missing." + else + let v:errmsg = escape(v:errmsg, '"') + Xout "Unexpected message:" v:errmsg + endif + endif + return match +endfunction + +let v:errmsg = "" +if 0 +else +elseif 1 ||| 2 +endif +Xpath 1 " X: 1 +if !MSG('E584', ":elseif after :else") + Xpath 2 " X: 0 +endif + +let v:errmsg = "" +if 1 +else +elseif 1 ||| 2 +endif +Xpath 4 " X: 4 +if !MSG('E584', ":elseif after :else") + Xpath 8 " X: 0 +endif + +let v:errmsg = "" +elseif 1 ||| 2 +Xpath 16 " X: 16 +if !MSG('E582', ":elseif without :if") + Xpath 32 " X: 0 +endif + +let v:errmsg = "" +while 1 + elseif 1 ||| 2 +endwhile +Xpath 64 " X: 64 +if !MSG('E582', ":elseif without :if") + Xpath 128 " X: 0 +endif + +while 1 + try + try + let v:errmsg = "" + let caught = 0 + if 0 + else + elseif 1 ||| 2 + endif + catch /^Vim\((\a\+)\)\=:/ + let caught = 1 + let v:errmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "") + finally + Xpath 256 " X: 256 + if !caught && !$VIMNOERRTHROW + Xpath 512 " X: 0 + endif + if !MSG('E584', ":elseif after :else") + Xpath 1024 " X: 0 + endif + endtry + catch /.*/ + Xpath 2048 " X: 0 + Xout v:exception "in" v:throwpoint + finally + break " discard error for $VIMNOERRTHROW + endtry +endwhile + +while 1 + try + try + let v:errmsg = "" + let caught = 0 + if 1 + else + elseif 1 ||| 2 + endif + catch /^Vim\((\a\+)\)\=:/ + let caught = 1 + let v:errmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "") + finally + Xpath 4096 " X: 4096 + if !caught && !$VIMNOERRTHROW + Xpath 8192 " X: 0 + endif + if !MSG('E584', ":elseif after :else") + Xpath 16384 " X: 0 + endif + endtry + catch /.*/ + Xpath 32768 " X: 0 + Xout v:exception "in" v:throwpoint + finally + break " discard error for $VIMNOERRTHROW + endtry +endwhile + +while 1 + try + try + let v:errmsg = "" + let caught = 0 + elseif 1 ||| 2 + catch /^Vim\((\a\+)\)\=:/ + let caught = 1 + let v:errmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "") + finally + Xpath 65536 " X: 65536 + if !caught && !$VIMNOERRTHROW + Xpath 131072 " X: 0 + endif + if !MSG('E582', ":elseif without :if") + Xpath 262144 " X: 0 + endif + endtry + catch /.*/ + Xpath 524288 " X: 0 + Xout v:exception "in" v:throwpoint + finally + break " discard error for $VIMNOERRTHROW + endtry +endwhile + +while 1 + try + try + let v:errmsg = "" + let caught = 0 + while 1 + elseif 1 ||| 2 + endwhile + catch /^Vim\((\a\+)\)\=:/ + let caught = 1 + let v:errmsg = substitute(v:exception, '^Vim\((\a\+)\)\=:', '', "") + finally + Xpath 1048576 " X: 1048576 + if !caught && !$VIMNOERRTHROW + Xpath 2097152 " X: 0 + endif + if !MSG('E582', ":elseif without :if") + Xpath 4194304 " X: 0 + endif + endtry + catch /.*/ + Xpath 8388608 " X: 0 + Xout v:exception "in" v:throwpoint + finally + break " discard error for $VIMNOERRTHROW + endtry +endwhile + +Xpath 16777216 " X: 16777216 + +unlet! caught +delfunction MSG + +Xcheck 17895765 + + +"------------------------------------------------------------------------------- +" Test 81: Discarding exceptions after an error or interrupt {{{1 +" +" When an exception is thrown from inside a :try conditional without +" :catch and :finally clauses and an error or interrupt occurs before +" the :endtry is reached, the exception is discarded. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + try + Xpath 1 " X: 1 + try + Xpath 2 " X: 2 + throw "arrgh" + Xpath 4 " X: 0 +" if 1 + Xpath 8 " X: 0 + " error after :throw: missing :endif + endtry + Xpath 16 " X: 0 + catch /arrgh/ + Xpath 32 " X: 0 + endtry + Xpath 64 " X: 0 +endif + +if ExtraVim() + try + Xpath 128 " X: 128 + try + Xpath 256 " X: 256 + throw "arrgh" + Xpath 512 " X: 0 + endtry " INTERRUPT + Xpath 1024 " X: 0 + catch /arrgh/ + Xpath 2048 " X: 0 + endtry + Xpath 4096 " X: 0 +endif + +Xcheck 387 + + +"------------------------------------------------------------------------------- +" Test 82: Ignoring :catch clauses after an error or interrupt {{{1 +" +" When an exception is thrown and an error or interrupt occurs before +" the matching :catch clause is reached, the exception is discarded +" and the :catch clause is ignored (also for the error or interrupt +" exception being thrown then). +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + try + try + Xpath 1 " X: 1 + throw "arrgh" + Xpath 2 " X: 0 +" if 1 + Xpath 4 " X: 0 + " error after :throw: missing :endif + catch /.*/ + Xpath 8 " X: 0 + Xout v:exception "in" ExtraVimThrowpoint() + catch /.*/ + Xpath 16 " X: 0 + Xout v:exception "in" ExtraVimThrowpoint() + endtry + Xpath 32 " X: 0 + catch /arrgh/ + Xpath 64 " X: 0 + endtry + Xpath 128 " X: 0 +endif + +if ExtraVim() + function! E() + try + try + Xpath 256 " X: 256 + throw "arrgh" + Xpath 512 " X: 0 +" if 1 + Xpath 1024 " X: 0 + " error after :throw: missing :endif + catch /.*/ + Xpath 2048 " X: 0 + Xout v:exception "in" ExtraVimThrowpoint() + catch /.*/ + Xpath 4096 " X: 0 + Xout v:exception "in" ExtraVimThrowpoint() + endtry + Xpath 8192 " X: 0 + catch /arrgh/ + Xpath 16384 " X: 0 + endtry + endfunction + + call E() + Xpath 32768 " X: 0 +endif + +if ExtraVim() + try + try + Xpath 65536 " X: 65536 + throw "arrgh" + Xpath 131072 " X: 0 + catch /.*/ "INTERRUPT + Xpath 262144 " X: 0 + Xout v:exception "in" ExtraVimThrowpoint() + catch /.*/ + Xpath 524288 " X: 0 + Xout v:exception "in" ExtraVimThrowpoint() + endtry + Xpath 1048576 " X: 0 + catch /arrgh/ + Xpath 2097152 " X: 0 + endtry + Xpath 4194304 " X: 0 +endif + +if ExtraVim() + function I() + try + try + Xpath 8388608 " X: 8388608 + throw "arrgh" + Xpath 16777216 " X: 0 + catch /.*/ "INTERRUPT + Xpath 33554432 " X: 0 + Xout v:exception "in" ExtraVimThrowpoint() + catch /.*/ + Xpath 67108864 " X: 0 + Xout v:exception "in" ExtraVimThrowpoint() + endtry + Xpath 134217728 " X: 0 + catch /arrgh/ + Xpath 268435456 " X: 0 + endtry + endfunction + + call I() + Xpath 536870912 " X: 0 +endif + +Xcheck 8454401 + + +"------------------------------------------------------------------------------- +" Test 83: Executing :finally clauses after an error or interrupt {{{1 +" +" When an exception is thrown and an error or interrupt occurs before +" the :finally of the innermost :try is reached, the exception is +" discarded and the :finally clause is executed. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + try + Xpath 1 " X: 1 + try + Xpath 2 " X: 2 + throw "arrgh" + Xpath 4 " X: 0 +" if 1 + Xpath 8 " X: 0 + " error after :throw: missing :endif + finally + Xpath 16 " X: 16 + endtry + Xpath 32 " X: 0 + catch /arrgh/ + Xpath 64 " X: 0 + endtry + Xpath 128 " X: 0 +endif + +if ExtraVim() + try + Xpath 256 " X: 256 + try + Xpath 512 " X: 512 + throw "arrgh" + Xpath 1024 " X: 0 + finally "INTERRUPT + Xpath 2048 " X: 2048 + endtry + Xpath 4096 " X: 0 + catch /arrgh/ + Xpath 8192 " X: 0 + endtry + Xpath 16384 " X: 0 +endif + +Xcheck 2835 + + +"------------------------------------------------------------------------------- +" Test 84: Exceptions in autocommand sequences. {{{1 +" +" When an exception occurs in a sequence of autocommands for +" a specific event, the rest of the sequence is not executed. The +" command that triggered the autocommand execution aborts, and the +" exception is propagated to the caller. +" +" For the FuncUndefined event under a function call expression or +" :call command, the function is not executed, even when it has +" been defined by the autocommands before the exception occurred. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + + function! INT() + "INTERRUPT + let dummy = 0 + endfunction + + aug TMP + autocmd! + + autocmd User x1 Xpath 1 " X: 1 + autocmd User x1 throw "x1" + autocmd User x1 Xpath 2 " X: 0 + + autocmd User x2 Xpath 4 " X: 4 + autocmd User x2 asdf + autocmd User x2 Xpath 8 " X: 0 + + autocmd User x3 Xpath 16 " X: 16 + autocmd User x3 call INT() + autocmd User x3 Xpath 32 " X: 0 + + autocmd FuncUndefined U1 function! U1() + autocmd FuncUndefined U1 Xpath 64 " X: 0 + autocmd FuncUndefined U1 endfunction + autocmd FuncUndefined U1 Xpath 128 " X: 128 + autocmd FuncUndefined U1 throw "U1" + autocmd FuncUndefined U1 Xpath 256 " X: 0 + + autocmd FuncUndefined U2 function! U2() + autocmd FuncUndefined U2 Xpath 512 " X: 0 + autocmd FuncUndefined U2 endfunction + autocmd FuncUndefined U2 Xpath 1024 " X: 1024 + autocmd FuncUndefined U2 ASDF + autocmd FuncUndefined U2 Xpath 2048 " X: 0 + + autocmd FuncUndefined U3 function! U3() + autocmd FuncUndefined U3 Xpath 4096 " X: 0 + autocmd FuncUndefined U3 endfunction + autocmd FuncUndefined U3 Xpath 8192 " X: 8192 + autocmd FuncUndefined U3 call INT() + autocmd FuncUndefined U3 Xpath 16384 " X: 0 + aug END + + try + try + Xpath 32768 " X: 32768 + doautocmd User x1 + catch /x1/ + Xpath 65536 " X: 65536 + endtry + + while 1 + try + Xpath 131072 " X: 131072 + let caught = 0 + doautocmd User x2 + catch /asdf/ + let caught = 1 + finally + Xpath 262144 " X: 262144 + if !caught && !$VIMNOERRTHROW + Xpath 524288 " X: 0 + " Propagate uncaught error exception, + else + " ... but break loop for caught error exception, + " or discard error and break loop if $VIMNOERRTHROW + break + endif + endtry + endwhile + + while 1 + try + Xpath 1048576 " X: 1048576 + let caught = 0 + doautocmd User x3 + catch /Vim:Interrupt/ + let caught = 1 + finally + Xpath 2097152 " X: 2097152 + if !caught && !$VIMNOINTTHROW + Xpath 4194304 " X: 0 + " Propagate uncaught interrupt exception, + else + " ... but break loop for caught interrupt exception, + " or discard interrupt and break loop if $VIMNOINTTHROW + break + endif + endtry + endwhile + + if exists("*U1") | delfunction U1 | endif + if exists("*U2") | delfunction U2 | endif + if exists("*U3") | delfunction U3 | endif + + try + Xpath 8388608 " X: 8388608 + call U1() + catch /U1/ + Xpath 16777216 " X: 16777216 + endtry + + while 1 + try + Xpath 33554432 " X: 33554432 + let caught = 0 + call U2() + catch /ASDF/ + let caught = 1 + finally + Xpath 67108864 " X: 67108864 + if !caught && !$VIMNOERRTHROW + Xpath 134217728 " X: 0 + " Propagate uncaught error exception, + else + " ... but break loop for caught error exception, + " or discard error and break loop if $VIMNOERRTHROW + break + endif + endtry + endwhile + + while 1 + try + Xpath 268435456 " X: 268435456 + let caught = 0 + call U3() + catch /Vim:Interrupt/ + let caught = 1 + finally + Xpath 536870912 " X: 536870912 + if !caught && !$VIMNOINTTHROW + Xpath 1073741824 " X: 0 + " Propagate uncaught interrupt exception, + else + " ... but break loop for caught interrupt exception, + " or discard interrupt and break loop if $VIMNOINTTHROW + break + endif + endtry + endwhile + catch /.*/ + " The Xpath command does not accept 2^31 (negative); display explicitly: + exec "!echo 2147483648 >>" . g:ExtraVimResult + Xout "Caught" v:exception "in" v:throwpoint + endtry + + unlet caught + delfunction INT + delfunction U1 + delfunction U2 + delfunction U3 + au! TMP + aug! TMP +endif + +Xcheck 934782101 + + +"------------------------------------------------------------------------------- +" Test 85: Error exceptions in autocommands for I/O command events {{{1 +" +" When an I/O command is inside :try/:endtry, autocommands to be +" executed after it should be skipped on an error (exception) in the +" command itself or in autocommands to be executed before the command. +" In the latter case, the I/O command should not be executed either. +" Example 1: BufWritePre, :write, BufWritePost +" Example 2: FileReadPre, :read, FileReadPost. +"------------------------------------------------------------------------------- + +XpathINIT + +function! MSG(enr, emsg) + let english = v:lang == "C" || v:lang =~ '^[Ee]n' + if a:enr == "" + Xout "TODO: Add message number for:" a:emsg + let v:errmsg = ":" . v:errmsg + endif + let match = 1 + if v:errmsg !~ '^'.a:enr.':' || (english && v:errmsg !~ a:emsg) + let match = 0 + if v:errmsg == "" + Xout "Message missing." + else + let v:errmsg = escape(v:errmsg, '"') + Xout "Unexpected message:" v:errmsg + endif + endif + return match +endfunction + +" Remove the autocommands for the events specified as arguments in all used +" autogroups. +function Delete_autocommands(...) + let augfile = tempname() + while 1 + try + exec "redir >" . augfile + aug + redir END + exec "edit" augfile + g/^$/d + norm G$ + let wrap = "w" + while search('\%( \|^\)\@<=.\{-}\%( \)\@=', wrap) > 0 + let wrap = "W" + exec "norm y/ \n" + let argno = 1 + while argno <= a:0 + exec "au!" escape(@", " ") a:{argno} + let argno = argno + 1 + endwhile + endwhile + catch /.*/ + finally + bwipeout! + call delete(augfile) + break " discard errors for $VIMNOERRTHROW + endtry + endwhile +endfunction + +call Delete_autocommands("BufWritePre", "BufWritePost") + +while 1 + try + try + let post = 0 + aug TMP + au! BufWritePost * let post = 1 + aug END + let caught = 0 + write /n/o/n/e/x/i/s/t/e/n/t + catch /^Vim(write):/ + let caught = 1 + let v:errmsg = substitute(v:exception, '^Vim(write):', '', "") + finally + Xpath 1 " X: 1 + if !caught && !$VIMNOERRTHROW + Xpath 2 " X: 0 + endif + let v:errmsg = substitute(v:errmsg, '^"/n/o/n/e/x/i/s/t/e/n/t" ', + \ '', "") + if !MSG('E212', "Can't open file for writing") + Xpath 4 " X: 0 + endif + if post + Xpath 8 " X: 0 + Xout "BufWritePost commands executed after write error" + endif + au! TMP + aug! TMP + endtry + catch /.*/ + Xpath 16 " X: 0 + Xout v:exception "in" v:throwpoint + finally + break " discard error for $VIMNOERRTHROW + endtry +endwhile + +while 1 + try + try + let post = 0 + aug TMP + au! BufWritePre * asdf + au! BufWritePost * let post = 1 + aug END + let tmpfile = tempname() + let caught = 0 + exec "write" tmpfile + catch /^Vim\((write)\)\=:/ + let caught = 1 + let v:errmsg = substitute(v:exception, '^Vim\((write)\)\=:', '', "") + finally + Xpath 32 " X: 32 + if !caught && !$VIMNOERRTHROW + Xpath 64 " X: 0 + endif + let v:errmsg = substitute(v:errmsg, '^"'.tmpfile.'" ', '', "") + if !MSG('E492', "Not an editor command") + Xpath 128 " X: 0 + endif + if filereadable(tmpfile) + Xpath 256 " X: 0 + Xout ":write command not suppressed after BufWritePre error" + endif + if post + Xpath 512 " X: 0 + Xout "BufWritePost commands executed after BufWritePre error" + endif + au! TMP + aug! TMP + endtry + catch /.*/ + Xpath 1024 " X: 0 + Xout v:exception "in" v:throwpoint + finally + break " discard error for $VIMNOERRTHROW + endtry +endwhile + +call delete(tmpfile) + +call Delete_autocommands("BufWritePre", "BufWritePost", + \ "BufReadPre", "BufReadPost", "FileReadPre", "FileReadPost") + +while 1 + try + try + let post = 0 + aug TMP + au! FileReadPost * let post = 1 + aug END + let caught = 0 + read /n/o/n/e/x/i/s/t/e/n/t + catch /^Vim(read):/ + let caught = 1 + let v:errmsg = substitute(v:exception, '^Vim(read):', '', "") + finally + Xpath 2048 " X: 2048 + if !caught && !$VIMNOERRTHROW + Xpath 4096 " X: 0 + endif + let v:errmsg = substitute(v:errmsg, ' /n/o/n/e/x/i/s/t/e/n/t$', + \ '', "") + if !MSG('E484', "Can't open file") + Xpath 8192 " X: 0 + endif + if post + Xpath 16384 " X: 0 + Xout "FileReadPost commands executed after write error" + endif + au! TMP + aug! TMP + endtry + catch /.*/ + Xpath 32768 " X: 0 + Xout v:exception "in" v:throwpoint + finally + break " discard error for $VIMNOERRTHROW + endtry +endwhile + +while 1 + try + let infile = tempname() + let tmpfile = tempname() + exec "!echo XYZ >" . infile + exec "edit" tmpfile + try + Xpath 65536 " X: 65536 + try + let post = 0 + aug TMP + au! FileReadPre * asdf + au! FileReadPost * let post = 1 + aug END + let caught = 0 + exec "0read" infile + catch /^Vim\((read)\)\=:/ + let caught = 1 + let v:errmsg = substitute(v:exception, '^Vim\((read)\)\=:', '', + \ "") + finally + Xpath 131072 " X: 131072 + if !caught && !$VIMNOERRTHROW + Xpath 262144 " X: 0 + endif + let v:errmsg = substitute(v:errmsg, ' '.infile.'$', '', "") + if !MSG('E492', "Not an editor command") + Xpath 524288 " X: 0 + endif + if getline("1") == "XYZ" + Xpath 1048576 " X: 0 + Xout ":read command not suppressed after FileReadPre error" + endif + if post + Xpath 2097152 " X: 0 + Xout "FileReadPost commands executed after " . + \ "FileReadPre error" + endif + au! TMP + aug! TMP + endtry + finally + bwipeout! + endtry + catch /.*/ + Xpath 4194304 " X: 0 + Xout v:exception "in" v:throwpoint + finally + break " discard error for $VIMNOERRTHROW + endtry +endwhile + +call delete(infile) +call delete(tmpfile) +unlet! caught post infile tmpfile +delfunction MSG +delfunction Delete_autocommands + +Xcheck 198689 + +"------------------------------------------------------------------------------- +" Test 86: setloclist crash {{{1 +" +" Executing a setloclist() on BufUnload shouldn't crash Vim +"------------------------------------------------------------------------------- + +func F + au BufUnload * :call setloclist(0, [{'bufnr':1, 'lnum':1, 'col':1, 'text': 'tango down'}]) + + :lvimgrep /.*/ *.mak +endfunc + +XpathINIT + +ExecAsScript F + +delfunction F +Xout "No Crash for vimgrep on BufUnload" +Xcheck 0 + +"------------------------------------------------------------------------------- +" Test 87 using (expr) ? funcref : funcref {{{1 +" +" Vim needs to correctly parse the funcref and even when it does +" not execute the funcref, it needs to consume the trailing () +"------------------------------------------------------------------------------- + +XpathINIT + +func Add2(x1, x2) + return a:x1 + a:x2 +endfu + +func GetStr() + return "abcdefghijklmnopqrstuvwxyp" +endfu + +echo function('Add2')(2,3) + +Xout 1 ? function('Add2')(1,2) : function('Add2')(2,3) +Xout 0 ? function('Add2')(1,2) : function('Add2')(2,3) +" Make sure, GetStr() still works. +Xout GetStr()[0:10] + + +delfunction GetStr +delfunction Add2 +Xout "Successfully executed funcref Add2" + +Xcheck 0 + +"------------------------------------------------------------------------------- +" Test 88: $VIMNOERRTHROW and $VIMNOINTTHROW support {{{1 +" +" It is possible to configure Vim for throwing exceptions on error +" or interrupt, controlled by variables $VIMNOERRTHROW and +" $VIMNOINTTHROW. This is just for increasing the number of tests. +" All tests here should run for all four combinations of setting +" these variables to 0 or 1. The variables are intended for the +" development phase only. In the final release, Vim should be +" configured to always use error and interrupt exceptions. +" +" The test result is "OK", +" +" - if the $VIMNOERRTHROW and the $VIMNOINTTHROW control are not +" configured and exceptions are thrown on error and on +" interrupt. +" +" - if the $VIMNOERRTHROW or the $VIMNOINTTHROW control is +" configured and works as intended. +" +" What actually happens, is shown in the test output. +" +" Otherwise, the test result is "FAIL", and the test output describes +" the problem. +" +" IMPORTANT: This must be the last test because it sets $VIMNOERRTHROW and +" $VIMNOINTTHROW. +"------------------------------------------------------------------------------- + +XpathINIT + +if ExtraVim() + + function! ThrowOnError() + XloopNEXT + let caught = 0 + try + Xloop 1 " X: 1 + 8 + 64 + asdf + catch /.*/ + let caught = 1 " error exception caught + finally + Xloop 2 " X: 2 + 16 + 128 + return caught " discard aborting error + endtry + Xloop 4 " X: 0 + endfunction + + let quits_skipped = 0 + + function! ThrowOnInterrupt() + XloopNEXT + let caught = 0 + try + Xloop 1 " X: (1 + 8 + 64) * 512 + "INTERRUPT3 + let dummy = 0 + let g:quits_skipped = g:quits_skipped + 1 + catch /.*/ + let caught = 1 " interrupt exception caught + finally + Xloop 2 " X: (2 + 16 + 128) * 512 + return caught " discard interrupt + endtry + Xloop 4 " X: 0 + endfunction + + function! CheckThrow(Type) + execute 'return ThrowOn' . a:Type . '()' + endfunction + + function! CheckConfiguration(type) " type is "error" or "interrupt" + + let type = a:type + let Type = substitute(type, '.*', '\u&', "") + let VAR = '$VIMNO' . substitute(type, '\(...\).*', '\U\1', "") . 'THROW' + + if type == "error" + XloopINIT! 1 8 + elseif type == "interrupt" + XloopINIT! 512 8 + endif + + exec 'let requested_for_tests = exists(VAR) && ' . VAR . ' == 0' + exec 'let suppressed_for_tests = ' . VAR . ' != 0' + let used_in_tests = CheckThrow(Type) + + exec 'let ' . VAR . ' = 0' + let request_works = CheckThrow(Type) + + exec 'let ' . VAR . ' = 1' + let suppress_works = !CheckThrow(Type) + + if type == "error" + XloopINIT! 262144 8 + elseif type == "interrupt" + XloopINIT! 2097152 8 + + if g:quits_skipped != 0 + Xloop 1 " X: 0*2097152 + Xout "Test environment error. Interrupt breakpoints skipped: " + \ . g:quits_skipped . ".\n" + \ . "Cannot check whether interrupt exceptions are thrown." + return + endif + endif + + let failure = + \ !suppressed_for_tests && !used_in_tests + \ || !request_works + + let contradiction = + \ used_in_tests + \ ? suppressed_for_tests && !request_works + \ : !suppressed_for_tests + + if failure + " Failure in configuration. + Xloop 2 " X: 0 * 2* (262144 + 2097152) + elseif contradiction + " Failure in test logic. Should not happen. + Xloop 4 " X: 0 * 4 * (262144 + 2097152) + endif + + let var_control_configured = + \ request_works != used_in_tests + \ || suppress_works == used_in_tests + + let var_control_not_configured = + \ requested_for_tests || suppressed_for_tests + \ ? request_works && !suppress_works + \ : request_works == used_in_tests + \ && suppress_works != used_in_tests + + let with = used_in_tests ? "with" : "without" + + let set = suppressed_for_tests ? "non-zero" : + \ requested_for_tests ? "0" : "unset" + + let although = contradiction && !var_control_not_configured + \ ? ",\nalthough " + \ : ".\n" + + let output = "All tests were run " . with . " throwing exceptions on " + \ . type . although + + if !var_control_not_configured + let output = output . VAR . " was " . set . "." + + if !request_works && !requested_for_tests + let output = output . + \ "\n" . Type . " exceptions are not thrown when " . VAR . + \ " is\nset to 0." + endif + + if !suppress_works && (!used_in_tests || + \ !request_works && + \ !requested_for_tests && !suppressed_for_tests) + let output = output . + \ "\n" . Type . " exceptions are thrown when " . VAR . + \ " is set to 1." + endif + + if !failure && var_control_configured + let output = output . + \ "\nRun tests also with " . substitute(VAR, '^\$', '', "") + \ . "=" . used_in_tests . "." + \ . "\nThis is for testing in the development phase only." + \ . " Remove the \n" + \ . VAR . " control in the final release." + endif + else + let output = output . + \ "The " . VAR . " control is not configured." + endif + + Xout output + endfunction + + call CheckConfiguration("error") + Xpath 16777216 " X: 16777216 + call CheckConfiguration("interrupt") + Xpath 33554432 " X: 33554432 +endif + +Xcheck 50443995 + +" IMPORTANT: No test should be added after this test because it changes +" $VIMNOERRTHROW and $VIMNOINTTHROW. + + +"------------------------------------------------------------------------------- +" Modelines {{{1 +" vim: ts=8 sw=4 tw=80 fdm=marker +" vim: fdt=substitute(substitute(foldtext(),\ '\\%(^+--\\)\\@<=\\(\\s*\\)\\(.\\{-}\\)\:\ \\%(\"\ \\)\\=\\(Test\ \\d*\\)\:\\s*',\ '\\3\ (\\2)\:\ \\1',\ \"\"),\ '\\(Test\\s*\\)\\(\\d\\)\\D\\@=',\ '\\1\ \\2',\ "") +"------------------------------------------------------------------------------- diff --git a/src/testdir/test52.in b/src/testdir/test52.in new file mode 100644 index 0000000..206b65a --- /dev/null +++ b/src/testdir/test52.in @@ -0,0 +1,65 @@ +Tests for reading and writing files with conversion for Win32. + +STARTTEST +:so mbyte.vim +:" make this a dummy test for non-Win32 systems +:if !has("win32") | e! test.ok | wq! test.out | endif +:" +:" write tests: +:" combine three values for 'encoding' with three values for 'fileencoding' +:" also write files for read tests +/^1 +:set encoding=utf-8 +:.w! ++enc=utf-8 test.out +:.w ++enc=cp1251 >>test.out +:.w ++enc=cp866 >>test.out +:.w! ++enc=utf-8 Xutf8 +/^2 +:set encoding=cp1251 +:.w ++enc=utf-8 >>test.out +:.w ++enc=cp1251 >>test.out +:.w ++enc=cp866 >>test.out +:.w! ++enc=cp1251 Xcp1251 +/^3 +:set encoding=cp866 +:.w ++enc=utf-8 >>test.out +:.w ++enc=cp1251 >>test.out +:.w ++enc=cp866 >>test.out +:.w! ++enc=cp866 Xcp866 +:" +:" read three 'fileencoding's with utf-8 'encoding' +:set encoding=utf-8 fencs=utf-8,cp1251 +:e Xutf8 +:.w ++enc=utf-8 >>test.out +:e Xcp1251 +:.w ++enc=utf-8 >>test.out +:set fencs=utf-8,cp866 +:e Xcp866 +:.w ++enc=utf-8 >>test.out +:" +:" read three 'fileencoding's with cp1251 'encoding' +:set encoding=utf-8 fencs=utf-8,cp1251 +:e Xutf8 +:.w ++enc=cp1251 >>test.out +:e Xcp1251 +:.w ++enc=cp1251 >>test.out +:set fencs=utf-8,cp866 +:e Xcp866 +:.w ++enc=cp1251 >>test.out +:" +:" read three 'fileencoding's with cp866 'encoding' +:set encoding=cp866 fencs=utf-8,cp1251 +:e Xutf8 +:.w ++enc=cp866 >>test.out +:e Xcp1251 +:.w ++enc=cp866 >>test.out +:set fencs=utf-8,cp866 +:e Xcp866 +:.w ++enc=cp866 >>test.out +:" +:qa! +ENDTEST + +1 utf-8 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01 +2 cp1251 text: Vim version 6.2. : 1970 Jan 01 +3 cp866 text: Vim version 6.2. : 1970 Jan 01 diff --git a/src/testdir/test52.ok b/src/testdir/test52.ok new file mode 100644 index 0000000..90b5165 --- /dev/null +++ b/src/testdir/test52.ok @@ -0,0 +1,18 @@ +1 utf-8 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01 +1 utf-8 text: Vim version 6.2. : 1970 Jan 01 +1 utf-8 text: Vim version 6.2. : 1970 Jan 01 +2 cp1251 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01 +2 cp1251 text: Vim version 6.2. : 1970 Jan 01 +2 cp1251 text: Vim version 6.2. : 1970 Jan 01 +3 cp866 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01 +3 cp866 text: Vim version 6.2. : 1970 Jan 01 +3 cp866 text: Vim version 6.2. : 1970 Jan 01 +1 utf-8 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01 +2 cp1251 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01 +3 cp866 text: Для Vim version 6.2. Последнее изменение: 1970 Jan 01 +1 utf-8 text: Vim version 6.2. : 1970 Jan 01 +2 cp1251 text: Vim version 6.2. : 1970 Jan 01 +3 cp866 text: Vim version 6.2. : 1970 Jan 01 +1 utf-8 text: Vim version 6.2. : 1970 Jan 01 +2 cp1251 text: Vim version 6.2. : 1970 Jan 01 +3 cp866 text: Vim version 6.2. : 1970 Jan 01 diff --git a/src/testdir/test59.in b/src/testdir/test59.in new file mode 100644 index 0000000..dcdb62b --- /dev/null +++ b/src/testdir/test59.in @@ -0,0 +1,626 @@ +Tests for spell checking with 'encoding' set to "utf-8". vim: set ft=vim : + +STARTTEST +:so small.vim +:so mbyte.vim +:" +:" Don't want to depend on the locale from the environment. The .aff and .dic +:" text is in latin1, the test text is utf-8. +:set enc=latin1 +:e! +:set enc=utf-8 +:set fenc= +:" +:" Function to test .aff/.dic with list of good and bad words. +:func TestOne(aff, dic) + set spellfile= + $put ='' + $put ='test '. a:aff . '-' . a:dic + " Generate a .spl file from a .dic and .aff file. + exe '1;/^' . a:aff . 'affstart/+1,/^' . a:aff . 'affend/-1w! Xtest.aff' + exe '1;/^' . a:dic . 'dicstart/+1,/^' . a:dic . 'dicend/-1w! Xtest.dic' + mkspell! Xtest Xtest + " use that spell file + set spl=Xtest.utf-8.spl spell + " list all valid words + spelldump + %yank + quit + $put + $put ='-------' + " find all bad words and suggestions for them + exe '1;/^' . a:aff . 'good:' + normal 0f:]s + let prevbad = '' + while 1 + let [bad, a] = spellbadword() + if bad == '' || bad == prevbad || bad == 'badend' + break + endif + let prevbad = bad + let lst = spellsuggest(bad, 3) + normal mm + $put =bad + $put =string(lst) + normal `m]s + endwhile +endfunc +:" +:call TestOne('1', '1') +:$put =soundfold('goobledygoook') +:$put =soundfold('kóopërÿnôven') +:$put =soundfold('oeverloos gezwets edale') +:" +:" +:" and now with SAL instead of SOFO items; test automatic reloading +gg:/^affstart_sal/+1,/^affend_sal/-1w! Xtest.aff +:mkspell! Xtest Xtest +:$put =soundfold('goobledygoook') +:$put =soundfold('kóopërÿnôven') +:$put =soundfold('oeverloos gezwets edale') +:" +:" also use an addition file +gg:/^addstart/+1,/^addend/-1w! Xtest.utf-8.add +:mkspell! Xtest.utf-8.add.spl Xtest.utf-8.add +:set spellfile=Xtest.utf-8.add +/^test2: +]s:let [str, a] = spellbadword() +:$put =str +:set spl=Xtest_us.utf-8.spl +/^test2: +]smm:let [str, a] = spellbadword() +:$put =str +`m]s:let [str, a] = spellbadword() +:$put =str +:set spl=Xtest_gb.utf-8.spl +/^test2: +]smm:let [str, a] = spellbadword() +:$put =str +`m]s:let [str, a] = spellbadword() +:$put =str +:set spl=Xtest_nz.utf-8.spl +/^test2: +]smm:let [str, a] = spellbadword() +:$put =str +`m]s:let [str, a] = spellbadword() +:$put =str +:set spl=Xtest_ca.utf-8.spl +/^test2: +]smm:let [str, a] = spellbadword() +:$put =str +`m]s:let [str, a] = spellbadword() +:$put =str +:unlet str a +:" +:" Postponed prefixes +:call TestOne('2', '1') +:" +:" Compound words +:call TestOne('3', '3') +:call TestOne('4', '4') +:call TestOne('5', '5') +:call TestOne('6', '6') +:call TestOne('7', '7') +:" +:" clean up for valgrind +:delfunc TestOne +:set spl= enc=latin1 +:" +gg:/^test output:/,$wq! test.out +ENDTEST + +1affstart +SET ISO8859-1 +TRY esianrtolcdugmphbyfvkwjkqxz-'ESIANRTOLCDUGMPHBYFVKWJKQXZ + +FOL +LOW +UPP + +SOFOFROM abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ +SOFOTO ebctefghejklnnepkrstevvkesebctefghejklnnepkrstevvkeseeeeeeeceeeeeeeedneeeeeeeeeeepseeeeeeeeceeeeeeeedneeeeeeeeeeep? + +MIDWORD '- + +KEP = +RAR ? +BAD ! + +#NOSPLITSUGS + +PFX I N 1 +PFX I 0 in . + +PFX O Y 1 +PFX O 0 out . + +SFX S Y 2 +SFX S 0 s [^s] +SFX S 0 es s + +SFX N N 3 +SFX N 0 en [^n] +SFX N 0 nen n +SFX N 0 n . + +REP 3 +REP g ch +REP ch g +REP svp s.v.p. + +MAP 9 +MAP a +MAP e +MAP i +MAP o +MAP u +MAP n +MAP c +MAP y +MAP s +1affend + +affstart_sal +SET ISO8859-1 +TRY esianrtolcdugmphbyfvkwjkqxz-'ESIANRTOLCDUGMPHBYFVKWJKQXZ + +FOL +LOW +UPP + +MIDWORD '- + +KEP = +RAR ? +BAD ! + +#NOSPLITSUGS + +PFX I N 1 +PFX I 0 in . + +PFX O Y 1 +PFX O 0 out . + +SFX S Y 2 +SFX S 0 s [^s] +SFX S 0 es s + +SFX N N 3 +SFX N 0 en [^n] +SFX N 0 nen n +SFX N 0 n . + +REP 3 +REP g ch +REP ch g +REP svp s.v.p. + +MAP 9 +MAP a +MAP e +MAP i +MAP o +MAP u +MAP n +MAP c +MAP y +MAP s + +SAL AH(AEIOUY)-^ *H +SAL AR(AEIOUY)-^ *R +SAL A(HR)^ * +SAL A^ * +SAL AH(AEIOUY)- H +SAL AR(AEIOUY)- R +SAL A(HR) _ +SAL ^ * +SAL ^ * +SAL BB- _ +SAL B B +SAL CQ- _ +SAL CIA X +SAL CH X +SAL C(EIY)- S +SAL CK K +SAL COUGH^ KF +SAL CC< C +SAL C K +SAL DG(EIY) K +SAL DD- _ +SAL D T +SAL < E +SAL EH(AEIOUY)-^ *H +SAL ER(AEIOUY)-^ *R +SAL E(HR)^ * +SAL ENOUGH^$ *NF +SAL E^ * +SAL EH(AEIOUY)- H +SAL ER(AEIOUY)- R +SAL E(HR) _ +SAL FF- _ +SAL F F +SAL GN^ N +SAL GN$ N +SAL GNS$ NS +SAL GNED$ N +SAL GH(AEIOUY)- K +SAL GH _ +SAL GG9 K +SAL G K +SAL H H +SAL IH(AEIOUY)-^ *H +SAL IR(AEIOUY)-^ *R +SAL I(HR)^ * +SAL I^ * +SAL ING6 N +SAL IH(AEIOUY)- H +SAL IR(AEIOUY)- R +SAL I(HR) _ +SAL J K +SAL KN^ N +SAL KK- _ +SAL K K +SAL LAUGH^ LF +SAL LL- _ +SAL L L +SAL MB$ M +SAL MM M +SAL M M +SAL NN- _ +SAL N N +SAL OH(AEIOUY)-^ *H +SAL OR(AEIOUY)-^ *R +SAL O(HR)^ * +SAL O^ * +SAL OH(AEIOUY)- H +SAL OR(AEIOUY)- R +SAL O(HR) _ +SAL PH F +SAL PN^ N +SAL PP- _ +SAL P P +SAL Q K +SAL RH^ R +SAL ROUGH^ RF +SAL RR- _ +SAL R R +SAL SCH(EOU)- SK +SAL SC(IEY)- S +SAL SH X +SAL SI(AO)- X +SAL SS- _ +SAL S S +SAL TI(AO)- X +SAL TH @ +SAL TCH-- _ +SAL TOUGH^ TF +SAL TT- _ +SAL T T +SAL UH(AEIOUY)-^ *H +SAL UR(AEIOUY)-^ *R +SAL U(HR)^ * +SAL U^ * +SAL UH(AEIOUY)- H +SAL UR(AEIOUY)- R +SAL U(HR) _ +SAL V^ W +SAL V F +SAL WR^ R +SAL WH^ W +SAL W(AEIOU)- W +SAL X^ S +SAL X KS +SAL Y(AEIOU)- Y +SAL ZZ- _ +SAL Z S +affend_sal + +2affstart +SET ISO8859-1 + +FOL +LOW +UPP + +PFXPOSTPONE + +MIDWORD '- + +KEP = +RAR ? +BAD ! + +#NOSPLITSUGS + +PFX I N 1 +PFX I 0 in . + +PFX O Y 1 +PFX O 0 out [a-z] + +SFX S Y 2 +SFX S 0 s [^s] +SFX S 0 es s + +SFX N N 3 +SFX N 0 en [^n] +SFX N 0 nen n +SFX N 0 n . + +REP 3 +REP g ch +REP ch g +REP svp s.v.p. + +MAP 9 +MAP a +MAP e +MAP i +MAP o +MAP u +MAP n +MAP c +MAP y +MAP s +2affend + +1dicstart +123456 +test/NO +# comment +wrong +Comment +OK +uk +put/ISO +the end +deol +dr +1dicend + +addstart +/regions=usgbnz +elequint/2 +elekwint/3 +addend + +1good: wrong OK puts. Test the end +bad: inputs comment ok Ok. test déôl end the +badend + +2good: puts +bad: inputs comment ok Ok end the. test déôl +badend + +Test rules for compounding. + +3affstart +SET ISO8859-1 + +COMPOUNDMIN 3 +COMPOUNDRULE m* +NEEDCOMPOUND x +3affend + +3dicstart +1234 +foo/m +bar/mx +m/m +la/mx +3dicend + +3good: foo mï foobar foofoobar barfoo barbarfoo +bad: bar la foomï barmï mïfoo mïbar mïmï lala mïla lamï foola labar +badend + + +Tests for compounding. + +4affstart +SET ISO8859-1 + +FOL +LOW +UPP + +COMPOUNDRULE m+ +COMPOUNDRULE sm*e +COMPOUNDRULE sm+ +COMPOUNDMIN 3 +COMPOUNDWORDMAX 3 +COMPOUNDFORBIDFLAG t + +COMPOUNDSYLMAX 5 +SYLLABLE aeiouy/aa/au/ea/ee/ei/ie/oa/oe/oo/ou/uu/ui + +MAP 9 +MAP a +MAP e +MAP i +MAP o +MAP u +MAP n +MAP c +MAP y +MAP s + +NEEDAFFIX x + +PFXPOSTPONE + +MIDWORD '- + +SFX q N 1 +SFX q 0 -ok . + +SFX a Y 2 +SFX a 0 s . +SFX a 0 ize/t . + +PFX p N 1 +PFX p 0 pre . + +PFX P N 1 +PFX P 0 nou . +4affend + +4dicstart +1234 +word/mP +util/am +pro/xq +tomato/m +bork/mp +start/s +end/e +4dicend + +4good: word util bork prebork start end wordutil wordutils pro-ok + bork borkbork borkborkbork borkborkborkbork borkborkborkborkbork + tomato tomatotomato startend startword startwordword startwordend + startwordwordend startwordwordwordend prebork preborkbork + preborkborkbork + nouword +bad: wordutilize pro borkborkborkborkborkbork tomatotomatotomato + endstart endend startstart wordend wordstart + preborkprebork preborkpreborkbork + startwordwordwordwordend borkpreborkpreborkbork + utilsbork startnouword +badend + +test2: +elequint test elekwint test elekwent asdf + +Test affix flags with two characters + +5affstart +SET ISO8859-1 + +FLAG long + +NEEDAFFIX !! + +COMPOUNDRULE ssmm*ee + +NEEDCOMPOUND xx +COMPOUNDPERMITFLAG pp + +SFX 13 Y 1 +SFX 13 0 bork . + +SFX a1 Y 1 +SFX a1 0 a1 . + +SFX a Y 1 +SFX a 0 a . + +PFX zz Y 1 +PFX zz 0 pre/pp . + +PFX yy Y 1 +PFX yy 0 nou . +5affend + +5dicstart +1234 +foo/a1a!! +bar/zz13ee +start/ss +end/eeyy +middle/mmxx +5dicend + +5good: fooa1 fooaé bar prebar barbork prebarbork startprebar + start end startend startmiddleend nouend +bad: foo fooa2 prabar probarbirk middle startmiddle middleend endstart + startprobar startnouend +badend + +6affstart +SET ISO8859-1 + +FLAG caplong + +NEEDAFFIX A! + +COMPOUNDRULE sMm*Ee + +NEEDCOMPOUND Xx + +COMPOUNDPERMITFLAG p + +SFX N3 Y 1 +SFX N3 0 bork . + +SFX A1 Y 1 +SFX A1 0 a1 . + +SFX A Y 1 +SFX A 0 a . + +PFX Zz Y 1 +PFX Zz 0 pre/p . +6affend + +6dicstart +1234 +mee/A1AA! +bar/ZzN3Ee +lead/s +end/Ee +middle/MmXx +6dicend + +6good: meea1 meeaé bar prebar barbork prebarbork leadprebar + lead end leadend leadmiddleend +bad: mee meea2 prabar probarbirk middle leadmiddle middleend endlead + leadprobar +badend + +7affstart +SET ISO8859-1 + +FOL +LOW +UPP + +FLAG num + +NEEDAFFIX 9999 + +COMPOUNDRULE 2,77*123 + +NEEDCOMPOUND 1 +COMPOUNDPERMITFLAG 432 + +SFX 61003 Y 1 +SFX 61003 0 meat . + +SFX 391 Y 1 +SFX 391 0 a1 . + +SFX 111 Y 1 +SFX 111 0 a . + +PFX 17 Y 1 +PFX 17 0 pre/432 . +7affend + +7dicstart +1234 +mee/391,111,9999 +bar/17,61003,123 +lead/2 +tail/123 +middle/77,1 +7dicend + +7good: meea1 meeaé bar prebar barmeat prebarmeat leadprebar + lead tail leadtail leadmiddletail +bad: mee meea2 prabar probarmaat middle leadmiddle middletail taillead + leadprobar +badend + +test output: diff --git a/src/testdir/test59.ok b/src/testdir/test59.ok new file mode 100644 index 0000000..931cdd9 --- /dev/null +++ b/src/testdir/test59.ok @@ -0,0 +1,270 @@ +test output: + +test 1-1 +# file: Xtest.utf-8.spl +Comment +deol +déôr +input +OK +output +outputs +outtest +put +puts +test +testen +testn +the end +uk +wrong +------- +bad +['put', 'uk', 'OK'] +inputs +['input', 'puts', 'outputs'] +comment +['Comment', 'outtest', 'the end'] +ok +['OK', 'uk', 'put'] +Ok +['OK', 'Uk', 'Put'] +test +['Test', 'testn', 'testen'] +déôl +['deol', 'déôr', 'test'] +end +['put', 'uk', 'test'] +the +['put', 'uk', 'test'] +gebletegek +kepereneven +everles gesvets etele +kbltykk +kprnfn +*fls kswts tl +elekwent +elequint +elekwint +elekwint +elekwent +elequint +elekwent +elequint +elekwint + +test 2-1 +# file: Xtest.utf-8.spl +Comment +deol +déôr +OK +put +input +output +puts +outputs +test +outtest +testen +testn +the end +uk +wrong +------- +bad +['put', 'uk', 'OK'] +inputs +['input', 'puts', 'outputs'] +comment +['Comment'] +ok +['OK', 'uk', 'put'] +Ok +['OK', 'Uk', 'Put'] +end +['put', 'uk', 'deol'] +the +['put', 'uk', 'test'] +test +['Test', 'testn', 'testen'] +déôl +['deol', 'déôr', 'test'] + +test 3-3 +# file: Xtest.utf-8.spl +foo +mï +------- +bad +['foo', 'mï'] +bar +['barfoo', 'foobar', 'foo'] +la +['mï', 'foo'] +foomï +['foo mï', 'foo', 'foofoo'] +barmï +['barfoo', 'mï', 'barbar'] +mïfoo +['mï foo', 'foo', 'foofoo'] +mïbar +['foobar', 'barbar', 'mï'] +mïmï +['mï mï', 'mï'] +lala +[] +mïla +['mï', 'mï mï'] +lamï +['mï', 'mï mï'] +foola +['foo', 'foobar', 'foofoo'] +labar +['barbar', 'foobar'] + +test 4-4 +# file: Xtest.utf-8.spl +bork +prebork +end +pro-ok +start +tomato +util +utilize +utils +word +nouword +------- +bad +['end', 'bork', 'word'] +wordutilize +['word utilize', 'wordutils', 'wordutil'] +pro +['bork', 'word', 'end'] +borkborkborkborkborkbork +['bork borkborkborkborkbork', 'borkbork borkborkborkbork', 'borkborkbork borkborkbork'] +tomatotomatotomato +['tomato tomatotomato', 'tomatotomato tomato', 'tomato tomato tomato'] +endstart +['end start', 'start'] +endend +['end end', 'end'] +startstart +['start start'] +wordend +['word end', 'word', 'wordword'] +wordstart +['word start', 'bork start'] +preborkprebork +['prebork prebork', 'preborkbork', 'preborkborkbork'] +preborkpreborkbork +['prebork preborkbork', 'preborkborkbork', 'preborkborkborkbork'] +startwordwordwordwordend +['startwordwordwordword end', 'startwordwordwordword', 'start wordwordwordword end'] +borkpreborkpreborkbork +['bork preborkpreborkbork', 'bork prebork preborkbork', 'bork preborkprebork bork'] +utilsbork +['utilbork', 'utils bork', 'util bork'] +startnouword +['start nouword', 'startword', 'startborkword'] + +test 5-5 +# file: Xtest.utf-8.spl +bar +barbork +end +fooa1 +fooaé +nouend +prebar +prebarbork +start +------- +bad +['bar', 'end', 'fooa1'] +foo +['fooa1', 'fooaé', 'bar'] +fooa2 +['fooa1', 'fooaé', 'bar'] +prabar +['prebar', 'bar', 'bar bar'] +probarbirk +['prebarbork'] +middle +[] +startmiddle +['startmiddleend', 'startmiddlebar'] +middleend +[] +endstart +['end start', 'start'] +startprobar +['startprebar', 'start prebar', 'startbar'] +startnouend +['start nouend', 'startend'] + +test 6-6 +# file: Xtest.utf-8.spl +bar +barbork +end +lead +meea1 +meeaé +prebar +prebarbork +------- +bad +['bar', 'end', 'lead'] +mee +['meea1', 'meeaé', 'bar'] +meea2 +['meea1', 'meeaé', 'lead'] +prabar +['prebar', 'bar', 'leadbar'] +probarbirk +['prebarbork'] +middle +[] +leadmiddle +['leadmiddleend', 'leadmiddlebar'] +middleend +[] +endlead +['end lead', 'lead', 'end end'] +leadprobar +['leadprebar', 'lead prebar', 'leadbar'] + +test 7-7 +# file: Xtest.utf-8.spl +bar +barmeat +lead +meea1 +meeaé +prebar +prebarmeat +tail +------- +bad +['bar', 'lead', 'tail'] +mee +['meea1', 'meeaé', 'bar'] +meea2 +['meea1', 'meeaé', 'lead'] +prabar +['prebar', 'bar', 'leadbar'] +probarmaat +['prebarmeat'] +middle +[] +leadmiddle +['leadmiddlebar'] +middletail +[] +taillead +['tail lead', 'tail'] +leadprobar +['leadprebar', 'lead prebar', 'leadbar'] diff --git a/src/testdir/test64.in b/src/testdir/test64.in new file mode 100644 index 0000000..360418c --- /dev/null +++ b/src/testdir/test64.in @@ -0,0 +1,654 @@ +Test for regexp patterns without multi-byte support. +See test95 for multi-byte tests. + +A pattern that gives the expected result produces OK, so that we know it was +actually tried. + +STARTTEST +:so small.vim +:" tl is a List of Lists with: +:" regexp engine +:" regexp pattern +:" text to test the pattern on +:" expected match (optional) +:" expected submatch 1 (optional) +:" expected submatch 2 (optional) +:" etc. +:" When there is no match use only the first two items. +:let tl = [] +:" +:"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +:"""" Previously written tests """""""""""""""""""""""""""""""" +:"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +:" +:call add(tl, [2, 'ab', 'aab', 'ab']) +:call add(tl, [2, 'b', 'abcdef', 'b']) +:call add(tl, [2, 'bc*', 'abccccdef', 'bcccc']) +:call add(tl, [2, 'bc\{-}', 'abccccdef', 'b']) +:call add(tl, [2, 'bc\{-}\(d\)', 'abccccdef', 'bccccd', 'd']) +:call add(tl, [2, 'bc*', 'abbdef', 'b']) +:call add(tl, [2, 'c*', 'ccc', 'ccc']) +:call add(tl, [2, 'bc*', 'abdef', 'b']) +:call add(tl, [2, 'c*', 'abdef', '']) +:call add(tl, [2, 'bc\+', 'abccccdef', 'bcccc']) +:call add(tl, [2, 'bc\+', 'abdef']) "no match +:" +:"operator \| +:call add(tl, [2, 'a\|ab', 'cabd', 'a']) "alternation is ordered +:" +:call add(tl, [2, 'c\?', 'ccb', 'c']) +:call add(tl, [2, 'bc\?', 'abd', 'b']) +:call add(tl, [2, 'bc\?', 'abccd', 'bc']) +:" +:call add(tl, [2, '\va{1}', 'ab', 'a']) +:" +:call add(tl, [2, '\va{2}', 'aa', 'aa']) +:call add(tl, [2, '\va{2}', 'caad', 'aa']) +:call add(tl, [2, '\va{2}', 'aba']) +:call add(tl, [2, '\va{2}', 'ab']) +:call add(tl, [2, '\va{2}', 'abaa', 'aa']) +:call add(tl, [2, '\va{2}', 'aaa', 'aa']) +:" +:call add(tl, [2, '\vb{1}', 'abca', 'b']) +:call add(tl, [2, '\vba{2}', 'abaa', 'baa']) +:call add(tl, [2, '\vba{3}', 'aabaac']) +:" +:call add(tl, [2, '\v(ab){1}', 'ab', 'ab', 'ab']) +:call add(tl, [2, '\v(ab){1}', 'dabc', 'ab', 'ab']) +:call add(tl, [2, '\v(ab){1}', 'acb']) +:" +:call add(tl, [2, '\v(ab){0,2}', 'acb', "", ""]) +:call add(tl, [2, '\v(ab){0,2}', 'ab', 'ab', 'ab']) +:call add(tl, [2, '\v(ab){1,2}', 'ab', 'ab', 'ab']) +:call add(tl, [2, '\v(ab){1,2}', 'ababc', 'abab', 'ab']) +:call add(tl, [2, '\v(ab){2,4}', 'ababcab', 'abab', 'ab']) +:call add(tl, [2, '\v(ab){2,4}', 'abcababa', 'abab', 'ab']) +:" +:call add(tl, [2, '\v(ab){2}', 'abab', 'abab', 'ab']) +:call add(tl, [2, '\v(ab){2}', 'cdababe', 'abab', 'ab']) +:call add(tl, [2, '\v(ab){2}', 'abac']) +:call add(tl, [2, '\v(ab){2}', 'abacabab', 'abab', 'ab']) +:call add(tl, [2, '\v((ab){2}){2}', 'abababab', 'abababab', 'abab', 'ab']) +:call add(tl, [2, '\v((ab){2}){2}', 'abacabababab', 'abababab', 'abab', 'ab']) +:" +:call add(tl, [2, '\v(a{1}){1}', 'a', 'a', 'a']) +:call add(tl, [2, '\v(a{2}){1}', 'aa', 'aa', 'aa']) +:call add(tl, [2, '\v(a{2}){1}', 'aaac', 'aa', 'aa']) +:call add(tl, [2, '\v(a{2}){1}', 'daaac', 'aa', 'aa']) +:call add(tl, [2, '\v(a{1}){2}', 'daaac', 'aa', 'a']) +:call add(tl, [2, '\v(a{1}){2}', 'aaa', 'aa', 'a']) +:call add(tl, [2, '\v(a{2})+', 'adaac', 'aa', 'aa']) +:call add(tl, [2, '\v(a{2})+', 'aa', 'aa', 'aa']) +:call add(tl, [2, '\v(a{2}){1}', 'aa', 'aa', 'aa']) +:call add(tl, [2, '\v(a{1}){2}', 'aa', 'aa', 'a']) +:call add(tl, [2, '\v(a{1}){1}', 'a', 'a', 'a']) +:call add(tl, [2, '\v(a{2}){2}', 'aaaa', 'aaaa', 'aa']) +:call add(tl, [2, '\v(a{2}){2}', 'aaabaaaa', 'aaaa', 'aa']) +:" +:call add(tl, [2, '\v(a+){2}', 'dadaac', 'aa', 'a']) +:call add(tl, [2, '\v(a{3}){2}', 'aaaaaaa', 'aaaaaa', 'aaa']) +:" +:call add(tl, [2, '\v(a{1,2}){2}', 'daaac', 'aaa', 'a']) +:call add(tl, [2, '\v(a{1,3}){2}', 'daaaac', 'aaaa', 'a']) +:call add(tl, [2, '\v(a{1,3}){2}', 'daaaaac', 'aaaaa', 'aa']) +:call add(tl, [2, '\v(a{1,3}){3}', 'daac']) +:call add(tl, [2, '\v(a{1,2}){2}', 'dac']) +:call add(tl, [2, '\v(a+)+', 'daac', 'aa', 'aa']) +:call add(tl, [2, '\v(a+)+', 'aaa', 'aaa', 'aaa']) +:call add(tl, [2, '\v(a+){1,2}', 'aaa', 'aaa', 'aaa']) +:call add(tl, [2, '\v(a+)(a+)', 'aaa', 'aaa', 'aa', 'a']) +:call add(tl, [2, '\v(a{3})+', 'daaaac', 'aaa', 'aaa']) +:call add(tl, [2, '\v(a|b|c)+', 'aacb', 'aacb', 'b']) +:call add(tl, [2, '\v(a|b|c){2}', 'abcb', 'ab', 'b']) +:call add(tl, [2, '\v(abc){2}', 'abcabd', ]) +:call add(tl, [2, '\v(abc){2}', 'abdabcabc','abcabc', 'abc']) +:" +:call add(tl, [2, 'a*', 'cc', '']) +:call add(tl, [2, '\v(a*)+', 'cc', '']) +:call add(tl, [2, '\v((ab)+)+', 'ab', 'ab', 'ab', 'ab']) +:call add(tl, [2, '\v(((ab)+)+)+', 'ab', 'ab', 'ab', 'ab', 'ab']) +:call add(tl, [2, '\v(((ab)+)+)+', 'dababc', 'abab', 'abab', 'abab', 'ab']) +:call add(tl, [2, '\v(a{0,2})+', 'cc', '']) +:call add(tl, [2, '\v(a*)+', '', '']) +:call add(tl, [2, '\v((a*)+)+', '', '']) +:call add(tl, [2, '\v((ab)*)+', '', '']) +:call add(tl, [2, '\va{1,3}', 'aab', 'aa']) +:call add(tl, [2, '\va{2,3}', 'abaa', 'aa']) +:" +:call add(tl, [2, '\v((ab)+|c*)+', 'abcccaba', 'abcccab', '', 'ab']) +:call add(tl, [2, '\v(a{2})|(b{3})', 'bbabbbb', 'bbb', '', 'bbb']) +:call add(tl, [2, '\va{2}|b{2}', 'abab']) +:call add(tl, [2, '\v(a)+|(c)+', 'bbacbaacbbb', 'a', 'a']) +:call add(tl, [2, '\vab{2,3}c', 'aabbccccccccccccc', 'abbc']) +:call add(tl, [2, '\vab{2,3}c', 'aabbbccccccccccccc', 'abbbc']) +:call add(tl, [2, '\vab{2,3}cd{2,3}e', 'aabbbcddee', 'abbbcdde']) +:call add(tl, [2, '\va(bc){2}d', 'aabcbfbc' ]) +:call add(tl, [2, '\va*a{2}', 'a', ]) +:call add(tl, [2, '\va*a{2}', 'aa', 'aa' ]) +:call add(tl, [2, '\va*a{2}', 'aaa', 'aaa' ]) +:call add(tl, [2, '\va*a{2}', 'bbbabcc', ]) +:call add(tl, [2, '\va*b*|a*c*', 'a', 'a']) +:call add(tl, [2, '\va{1}b{1}|a{1}b{1}', '']) +:" +:"submatches +:call add(tl, [2, '\v(a)', 'ab', 'a', 'a']) +:call add(tl, [2, '\v(a)(b)', 'ab', 'ab', 'a', 'b']) +:call add(tl, [2, '\v(ab)(b)(c)', 'abbc', 'abbc', 'ab', 'b', 'c']) +:call add(tl, [2, '\v((a)(b))', 'ab', 'ab', 'ab', 'a', 'b']) +:call add(tl, [2, '\v(a)|(b)', 'ab', 'a', 'a']) +:" +:call add(tl, [2, '\v(a*)+', 'aaaa', 'aaaa', '']) +:call add(tl, [2, 'x', 'abcdef']) +:" +:"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +:""""" Simple tests """"""""""""""""""""""""""""""""""""""""""" +:"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +:" +:" Search single groups +:call add(tl, [2, 'ab', 'aab', 'ab']) +:call add(tl, [2, 'ab', 'baced']) +:call add(tl, [2, 'ab', ' ab ', 'ab']) +:" +:" Search multi-modifiers +:call add(tl, [2, 'x*', 'xcd', 'x']) +:call add(tl, [2, 'x*', 'xxxxxxxxxxxxxxxxsofijiojgf', 'xxxxxxxxxxxxxxxx']) +:" empty match is good +:call add(tl, [2, 'x*', 'abcdoij', '']) +:" no match here +:call add(tl, [2, 'x\+', 'abcdoin']) +:call add(tl, [2, 'x\+', 'abcdeoijdfxxiuhfij', 'xx']) +:call add(tl, [2, 'x\+', 'xxxxx', 'xxxxx']) +:call add(tl, [2, 'x\+', 'abc x siufhiush xxxxxxxxx', 'x']) +:call add(tl, [2, 'x\=', 'x sdfoij', 'x']) +:call add(tl, [2, 'x\=', 'abc sfoij', '']) " empty match is good +:call add(tl, [2, 'x\=', 'xxxxxxxxx c', 'x']) +:call add(tl, [2, 'x\?', 'x sdfoij', 'x']) +:" empty match is good +:call add(tl, [2, 'x\?', 'abc sfoij', '']) +:call add(tl, [2, 'x\?', 'xxxxxxxxxx c', 'x']) +:" +:call add(tl, [2, 'a\{0,0}', 'abcdfdoij', '']) +:" same thing as 'a?' +:call add(tl, [2, 'a\{0,1}', 'asiubid axxxaaa', 'a']) +:" same thing as 'a\{0,1}' +:call add(tl, [2, 'a\{1,0}', 'asiubid axxxaaa', 'a']) +:call add(tl, [2, 'a\{3,6}', 'aa siofuh']) +:call add(tl, [2, 'a\{3,6}', 'aaaaa asfoij afaa', 'aaaaa']) +:call add(tl, [2, 'a\{3,6}', 'aaaaaaaa', 'aaaaaa']) +:call add(tl, [2, 'a\{0}', 'asoiuj', '']) +:call add(tl, [2, 'a\{2}', 'aaaa', 'aa']) +:call add(tl, [2, 'a\{2}', 'iuash fiusahfliusah fiushfilushfi uhsaifuh askfj nasfvius afg aaaa sfiuhuhiushf', 'aa']) +:call add(tl, [2, 'a\{2}', 'abcdefghijklmnopqrestuvwxyz1234567890']) +:" same thing as 'a*' +:call add(tl, [2, 'a\{0,}', 'oij sdigfusnf', '']) +:call add(tl, [2, 'a\{0,}', 'aaaaa aa', 'aaaaa']) +:call add(tl, [2, 'a\{2,}', 'sdfiougjdsafg']) +:call add(tl, [2, 'a\{2,}', 'aaaaasfoij ', 'aaaaa']) +:call add(tl, [2, 'a\{5,}', 'xxaaaaxxx ']) +:call add(tl, [2, 'a\{5,}', 'xxaaaaaxxx ', 'aaaaa']) +:call add(tl, [2, 'a\{,0}', 'oidfguih iuhi hiu aaaa', '']) +:call add(tl, [2, 'a\{,5}', 'abcd', 'a']) +:call add(tl, [2, 'a\{,5}', 'aaaaaaaaaa', 'aaaaa']) +:" leading star as normal char when \{} follows +:call add(tl, [2, '^*\{4,}$', '***']) +:call add(tl, [2, '^*\{4,}$', '****', '****']) +:call add(tl, [2, '^*\{4,}$', '*****', '*****']) +:" same thing as 'a*' +:call add(tl, [2, 'a\{}', 'bbbcddiuhfcd', '']) +:call add(tl, [2, 'a\{}', 'aaaaioudfh coisf jda', 'aaaa']) +:" +:call add(tl, [2, 'a\{-0,0}', 'abcdfdoij', '']) +:" anti-greedy version of 'a?' +:call add(tl, [2, 'a\{-0,1}', 'asiubid axxxaaa', '']) +:call add(tl, [2, 'a\{-3,6}', 'aa siofuh']) +:call add(tl, [2, 'a\{-3,6}', 'aaaaa asfoij afaa', 'aaa']) +:call add(tl, [2, 'a\{-3,6}', 'aaaaaaaa', 'aaa']) +:call add(tl, [2, 'a\{-0}', 'asoiuj', '']) +:call add(tl, [2, 'a\{-2}', 'aaaa', 'aa']) +:call add(tl, [2, 'a\{-2}', 'abcdefghijklmnopqrestuvwxyz1234567890']) +:call add(tl, [2, 'a\{-0,}', 'oij sdigfusnf', '']) +:call add(tl, [2, 'a\{-0,}', 'aaaaa aa', '']) +:call add(tl, [2, 'a\{-2,}', 'sdfiougjdsafg']) +:call add(tl, [2, 'a\{-2,}', 'aaaaasfoij ', 'aa']) +:call add(tl, [2, 'a\{-,0}', 'oidfguih iuhi hiu aaaa', '']) +:call add(tl, [2, 'a\{-,5}', 'abcd', '']) +:call add(tl, [2, 'a\{-,5}', 'aaaaaaaaaa', '']) +:" anti-greedy version of 'a*' +:call add(tl, [2, 'a\{-}', 'bbbcddiuhfcd', '']) +:call add(tl, [2, 'a\{-}', 'aaaaioudfh coisf jda', '']) +:" +:" Test groups of characters and submatches +:call add(tl, [2, '\(abc\)*', 'abcabcabc', 'abcabcabc', 'abc']) +:call add(tl, [2, '\(ab\)\+', 'abababaaaaa', 'ababab', 'ab']) +:call add(tl, [2, '\(abaaaaa\)*cd', 'cd', 'cd', '']) +:call add(tl, [2, '\(test1\)\? \(test2\)\?', 'test1 test3', 'test1 ', 'test1', '']) +:call add(tl, [2, '\(test1\)\= \(test2\) \(test4443\)\=', ' test2 test4443 yupiiiiiiiiiii', ' test2 test4443', '', 'test2', 'test4443']) +:call add(tl, [2, '\(\(sub1\) hello \(sub 2\)\)', 'asterix sub1 hello sub 2 obelix', 'sub1 hello sub 2', 'sub1 hello sub 2', 'sub1', 'sub 2']) +:call add(tl, [2, '\(\(\(yyxxzz\)\)\)', 'abcdddsfiusfyyzzxxyyxxzz', 'yyxxzz', 'yyxxzz', 'yyxxzz', 'yyxxzz']) +:call add(tl, [2, '\v((ab)+|c+)+', 'abcccaba', 'abcccab', 'ab', 'ab']) +:call add(tl, [2, '\v((ab)|c*)+', 'abcccaba', 'abcccab', '', 'ab']) +:call add(tl, [2, '\v(a(c*)+b)+', 'acbababaaa', 'acbabab', 'ab', '']) +:call add(tl, [2, '\v(a|b*)+', 'aaaa', 'aaaa', '']) +:call add(tl, [2, '\p*', 'aá ', 'aá ']) +:" +:" Test greedy-ness and lazy-ness +:call add(tl, [2, 'a\{-2,7}','aaaaaaaaaaaaa', 'aa']) +:call add(tl, [2, 'a\{-2,7}x','aaaaaaaaax', 'aaaaaaax']) +:call add(tl, [2, 'a\{2,7}','aaaaaaaaaaaaaaaaaaaa', 'aaaaaaa']) +:call add(tl, [2, 'a\{2,7}x','aaaaaaaaax', 'aaaaaaax']) +:call add(tl, [2, '\vx(.{-,8})yz(.*)','xayxayzxayzxayz','xayxayzxayzxayz','ayxa','xayzxayz']) +:call add(tl, [2, '\vx(.*)yz(.*)','xayxayzxayzxayz','xayxayzxayzxayz', 'ayxayzxayzxa','']) +:call add(tl, [2, '\v(a{1,2}){-2,3}','aaaaaaa','aaaa','aa']) +:call add(tl, [2, '\v(a{-1,3})+', 'aa', 'aa', 'a']) +:call add(tl, [2, '^\s\{-}\zs\( x\|x$\)', ' x', ' x', ' x']) +:call add(tl, [2, '^\s\{-}\zs\(x\| x$\)', ' x', ' x', ' x']) +:call add(tl, [2, '^\s\{-}\ze\(x\| x$\)', ' x', '', ' x']) +:call add(tl, [2, '^\(\s\{-}\)\(x\| x$\)', ' x', ' x', '', ' x']) +:" +:" Test Character classes +:call add(tl, [2, '\d\+e\d\d','test 10e23 fd','10e23']) +:" +:" Test collections and character range [] +:call add(tl, [2, '\v[a]', 'abcd', 'a']) +:call add(tl, [2, 'a[bcd]', 'abcd', 'ab']) +:call add(tl, [2, 'a[b-d]', 'acbd', 'ac']) +:call add(tl, [2, '[a-d][e-f][x-x]d', 'cexdxx', 'cexd']) +:call add(tl, [2, '\v[[:alpha:]]+', 'abcdefghijklmnopqrstuvwxyz6','abcdefghijklmnopqrstuvwxyz']) +:call add(tl, [2, '[[:alpha:]\+]', '6x8','x']) +:call add(tl, [2, '[^abc]\+','abcabcabc']) +:call add(tl, [2, '[^abc]','defghiasijvoinasoiunbvb','d']) +:call add(tl, [2, '[^abc]\+','ddddddda','ddddddd']) +:call add(tl, [2, '[^a-d]\+','aaaAAAZIHFNCddd','AAAZIHFNC']) +:call add(tl, [2, '[a-f]*','iiiiiiii','']) +:call add(tl, [2, '[a-f]*','abcdefgh','abcdef']) +:call add(tl, [2, '[^a-f]\+','abcdefgh','gh']) +:call add(tl, [2, '[a-c]\{-3,6}','abcabc','abc']) +:call add(tl, [2, '[^[:alpha:]]\+','abcccadfoij7787ysf287yrnccdu','7787']) +:call add(tl, [2, '[-a]', '-', '-']) +:call add(tl, [2, '[a-]', '-', '-']) +:call add(tl, [2, '[a-f]*\c','ABCDEFGH','ABCDEF']) +:call add(tl, [2, '[abc][xyz]\c','-af-AF-BY--','BY']) +:" filename regexp +:call add(tl, [2, '[-./[:alnum:]_~]\+', 'log13.file', 'log13.file']) +:" special chars +:call add(tl, [2, '[\]\^\-\\]\+', '\^\\\-\---^', '\^\\\-\---^']) +:" collation elem +:call add(tl, [2, '[[.a.]]\+', 'aa', 'aa']) +:" middle of regexp +:call add(tl, [2, 'abc[0-9]*ddd', 'siuhabc ii']) +:call add(tl, [2, 'abc[0-9]*ddd', 'adf abc44482ddd oijs', 'abc44482ddd']) +:call add(tl, [2, '\_[0-9]\+', 'asfi9888u', '9888']) +:call add(tl, [2, '[0-9\n]\+', 'asfi9888u', '9888']) +:call add(tl, [2, '\_[0-9]\+', "asfi\n9888u", "\n9888"]) +:call add(tl, [2, '\_f', " \na ", "\n"]) +:call add(tl, [2, '\_f\+', " \na ", "\na"]) +:call add(tl, [2, '[0-9A-Za-z-_.]\+', " @0_a.A-{ ", "0_a.A-"]) +:" +:"""" Test start/end of line, start/end of file +:call add(tl, [2, '^a.', "a_\nb ", "a_"]) +:call add(tl, [2, '^a.', "b a \na_"]) +:call add(tl, [2, '.a$', " a\n "]) +:call add(tl, [2, '.a$', " a b\n_a", "_a"]) +:call add(tl, [2, '\%^a.', "a a\na", "a "]) +:call add(tl, [2, '\%^a', " a \na "]) +:call add(tl, [2, '.a\%$', " a\n "]) +:call add(tl, [2, '.a\%$', " a\n_a", "_a"]) +:" +:"""" Test recognition of character classes +:call add(tl, [2, '[0-7]\+', 'x0123456789x', '01234567']) +:call add(tl, [2, '[^0-7]\+', '0a;X+% 897', 'a;X+% 89']) +:call add(tl, [2, '[0-9]\+', 'x0123456789x', '0123456789']) +:call add(tl, [2, '[^0-9]\+', '0a;X+% 9', 'a;X+% ']) +:call add(tl, [2, '[0-9a-fA-F]\+', 'x0189abcdefg', '0189abcdef']) +:call add(tl, [2, '[^0-9A-Fa-f]\+', '0189g;X+% ab', 'g;X+% ']) +:call add(tl, [2, '[a-z_A-Z0-9]\+', ';+aso_SfOij ', 'aso_SfOij']) +:call add(tl, [2, '[^a-z_A-Z0-9]\+', 'aSo_;+% sfOij', ';+% ']) +:call add(tl, [2, '[a-z_A-Z]\+', '0abyz_ABYZ;', 'abyz_ABYZ']) +:call add(tl, [2, '[^a-z_A-Z]\+', 'abAB_09;+% yzYZ', '09;+% ']) +:call add(tl, [2, '[a-z]\+', '0abcxyz1', 'abcxyz']) +:call add(tl, [2, '[a-z]\+', 'AabxyzZ', 'abxyz']) +:call add(tl, [2, '[^a-z]\+', 'a;X09+% x', ';X09+% ']) +:call add(tl, [2, '[^a-z]\+', 'abX0;%yz', 'X0;%']) +:call add(tl, [2, '[a-zA-Z]\+', '0abABxzXZ9', 'abABxzXZ']) +:call add(tl, [2, '[^a-zA-Z]\+', 'ab09_;+ XZ', '09_;+ ']) +:call add(tl, [2, '[A-Z]\+', 'aABXYZz', 'ABXYZ']) +:call add(tl, [2, '[^A-Z]\+', 'ABx0;%YZ', 'x0;%']) +:call add(tl, [2, '[a-z]\+\c', '0abxyzABXYZ;', 'abxyzABXYZ']) +:call add(tl, [2, '[A-Z]\+\c', '0abABxzXZ9', 'abABxzXZ']) +:call add(tl, [2, '\c[^a-z]\+', 'ab09_;+ XZ', '09_;+ ']) +:call add(tl, [2, '\c[^A-Z]\+', 'ab09_;+ XZ', '09_;+ ']) +:call add(tl, [2, '\C[^A-Z]\+', 'ABCOIJDEOIFNSD jsfoij sa', ' jsfoij sa']) +:" +:"""" Tests for \z features +:" match ends at \ze +:call add(tl, [2, 'xx \ze test', 'xx ']) +:call add(tl, [2, 'abc\zeend', 'oij abcend', 'abc']) +:call add(tl, [2, 'aa\zebb\|aaxx', ' aabb ', 'aa']) +:call add(tl, [2, 'aa\zebb\|aaxx', ' aaxx ', 'aaxx']) +:call add(tl, [2, 'aabb\|aa\zebb', ' aabb ', 'aabb']) +:call add(tl, [2, 'aa\zebb\|aaebb', ' aabb ', 'aa']) +:" match starts at \zs +:call add(tl, [2, 'abc\zsdd', 'ddabcddxyzt', 'dd']) +:call add(tl, [2, 'aa \zsax', ' ax']) +:call add(tl, [2, 'abc \zsmatch\ze abc', 'abc abc abc match abc abc', 'match']) +:call add(tl, [2, '\v(a \zsif .*){2}', 'a if then a if last', 'if last', 'a if last']) +:call add(tl, [2, '\>\zs.', 'aword. ', '.']) +:call add(tl, [2, '\s\+\ze\[/\|\s\zs\s\+', 'is [a t', ' ']) +:" +:"""" Tests for \@= and \& features +:call add(tl, [2, 'abc\@=', 'abc', 'ab']) +:call add(tl, [2, 'abc\@=cd', 'abcd', 'abcd']) +:call add(tl, [2, 'abc\@=', 'ababc', 'ab']) +:" will never match, no matter the input text +:call add(tl, [2, 'abcd\@=e', 'abcd']) +:" will never match +:call add(tl, [2, 'abcd\@=e', 'any text in here ... ']) +:call add(tl, [2, '\v(abc)@=..', 'xabcd', 'ab', 'abc']) +:call add(tl, [2, '\(.*John\)\@=.*Bob', 'here is John, and here is B']) +:call add(tl, [2, '\(John.*\)\@=.*Bob', 'John is Bobs friend', 'John is Bob', 'John is Bobs friend']) +:call add(tl, [2, '\<\S\+\())\)\@=', '$((i=i+1))', 'i=i+1', '))']) +:call add(tl, [2, '.*John\&.*Bob', 'here is John, and here is B']) +:call add(tl, [2, '.*John\&.*Bob', 'John is Bobs friend', 'John is Bob']) +:call add(tl, [2, '\v(test1)@=.*yep', 'this is a test1, yep it is', 'test1, yep', 'test1']) +:call add(tl, [2, 'foo\(bar\)\@!', 'foobar']) +:call add(tl, [2, 'foo\(bar\)\@!', 'foo bar', 'foo']) +:call add(tl, [2, 'if \(\(then\)\@!.\)*$', ' if then else']) +:call add(tl, [2, 'if \(\(then\)\@!.\)*$', ' if else ', 'if else ', ' ']) +:call add(tl, [2, '\(foo\)\@!bar', 'foobar', 'bar']) +:call add(tl, [2, '\(foo\)\@!...bar', 'foobar']) +:call add(tl, [2, '^\%(.*bar\)\@!.*\zsfoo', ' bar foo ']) +:call add(tl, [2, '^\%(.*bar\)\@!.*\zsfoo', ' foo bar ']) +:call add(tl, [2, '^\%(.*bar\)\@!.*\zsfoo', ' foo xxx ', 'foo']) +:call add(tl, [2, '[ ]\@!\p\%([ ]\@!\p\)*:', 'implicit mappings:', 'mappings:']) +:call add(tl, [2, '[ ]\@!\p\([ ]\@!\p\)*:', 'implicit mappings:', 'mappings:', 's']) +:call add(tl, [2, 'm\k\+_\@=\%(_\@!\k\)\@<=\k\+e', 'mx__xe', 'mx__xe']) +:call add(tl, [2, '\%(\U\@<=S\k*\|S\l\)R', 'SuR', 'SuR']) +:" +:"""" Combining different tests and features +:call add(tl, [2, '[[:alpha:]]\{-2,6}', '787abcdiuhsasiuhb4', 'ab']) +:call add(tl, [2, '', 'abcd', '']) +:call add(tl, [2, '\v(())', 'any possible text', '']) +:call add(tl, [2, '\v%(ab(xyz)c)', ' abxyzc ', 'abxyzc', 'xyz']) +:call add(tl, [2, '\v(test|)empty', 'tesempty', 'empty', '']) +:call add(tl, [2, '\v(a|aa)(a|aa)', 'aaa', 'aa', 'a', 'a']) +:" +:"""" \%u and friends +:call add(tl, [2, '\%d32', 'yes no', ' ']) +:call add(tl, [2, '\%o40', 'yes no', ' ']) +:call add(tl, [2, '\%x20', 'yes no', ' ']) +:call add(tl, [2, '\%u0020', 'yes no', ' ']) +:call add(tl, [2, '\%U00000020', 'yes no', ' ']) +:call add(tl, [2, '\%d0', "yes\x0ano", "\x0a"]) +:" +:""""" \%[abc] +:call add(tl, [2, 'foo\%[bar]', 'fobar']) +:call add(tl, [2, 'foo\%[bar]', 'foobar', 'foobar']) +:call add(tl, [2, 'foo\%[bar]', 'fooxx', 'foo']) +:call add(tl, [2, 'foo\%[bar]', 'foobxx', 'foob']) +:call add(tl, [2, 'foo\%[bar]', 'foobaxx', 'fooba']) +:call add(tl, [2, 'foo\%[bar]', 'foobarxx', 'foobar']) +:call add(tl, [2, 'foo\%[bar]x', 'foobxx', 'foobx']) +:call add(tl, [2, 'foo\%[bar]x', 'foobarxx', 'foobarx']) +:call add(tl, [2, '\%[bar]x', 'barxx', 'barx']) +:call add(tl, [2, '\%[bar]x', 'bxx', 'bx']) +:call add(tl, [2, '\%[bar]x', 'xxx', 'x']) +:call add(tl, [2, 'b\%[[ao]r]', 'bar bor', 'bar']) +:call add(tl, [2, 'b\%[[]]r]', 'b]r bor', 'b]r']) +:call add(tl, [2, '@\%[\w\-]*', '<http://john.net/pandoc/>[@pandoc]', '@pandoc']) +:" +:"""" Alternatives, must use first longest match +:call add(tl, [2, 'goo\|go', 'google', 'goo']) +:call add(tl, [2, '\<goo\|\<go', 'google', 'goo']) +:call add(tl, [2, '\<goo\|go', 'google', 'goo']) +:" +:"""" Back references +:call add(tl, [2, '\(\i\+\) \1', ' abc abc', 'abc abc', 'abc']) +:call add(tl, [2, '\(\i\+\) \1', 'xgoo goox', 'goo goo', 'goo']) +:call add(tl, [2, '\(a\)\(b\)\(c\)\(dd\)\(e\)\(f\)\(g\)\(h\)\(i\)\1\2\3\4\5\6\7\8\9', 'xabcddefghiabcddefghix', 'abcddefghiabcddefghi', 'a', 'b', 'c', 'dd', 'e', 'f', 'g', 'h', 'i']) +:call add(tl, [2, '\(\d*\)a \1b', ' a b ', 'a b', '']) +:call add(tl, [2, '^.\(.\).\_..\1.', "aaa\naaa\nb", "aaa\naaa", 'a']) +:call add(tl, [2, '^.*\.\(.*\)/.\+\(\1\)\@<!$', 'foo.bat/foo.com', 'foo.bat/foo.com', 'bat']) +:call add(tl, [2, '^.*\.\(.*\)/.\+\(\1\)\@<!$', 'foo.bat/foo.bat']) +:call add(tl, [2, '^.*\.\(.*\)/.\+\(\1\)\@<=$', 'foo.bat/foo.bat', 'foo.bat/foo.bat', 'bat', 'bat']) +:call add(tl, [2, '\\\@<!\${\(\d\+\%(:.\{-}\)\?\\\@<!\)}', '2013-06-27${0}', '${0}', '0']) +:call add(tl, [2, '^\(a*\)\1$', 'aaaaaaaa', 'aaaaaaaa', 'aaaa']) +:call add(tl, [2, '^\(a\{-2,}\)\1\+$', 'aaaaaaaaa', 'aaaaaaaaa', 'aaa']) +:" +:"""" Look-behind with limit +:call add(tl, [2, '<\@<=span.', 'xxspanxx<spanyyy', 'spany']) +:call add(tl, [2, '<\@1<=span.', 'xxspanxx<spanyyy', 'spany']) +:call add(tl, [2, '<\@2<=span.', 'xxspanxx<spanyyy', 'spany']) +:call add(tl, [2, '\(<<\)\@<=span.', 'xxspanxxxx<spanxx<<spanyyy', 'spany', '<<']) +:call add(tl, [2, '\(<<\)\@1<=span.', 'xxspanxxxx<spanxx<<spanyyy']) +:call add(tl, [2, '\(<<\)\@2<=span.', 'xxspanxxxx<spanxx<<spanyyy', 'spany', '<<']) +:call add(tl, [2, '\(foo\)\@<!bar.', 'xx foobar1 xbar2 xx', 'bar2']) +:" +:" look-behind match in front of a zero-width item +:call add(tl, [2, '\v\C%(<Last Changed:\s+)@<=.*$', '" test header']) +:call add(tl, [2, '\v\C%(<Last Changed:\s+)@<=.*$', '" Last Changed: 1970', '1970']) +:call add(tl, [2, '\(foo\)\@<=\>', 'foobar']) +:call add(tl, [2, '\(foo\)\@<=\>', 'barfoo', '', 'foo']) +:call add(tl, [2, '\(foo\)\@<=.*', 'foobar', 'bar', 'foo']) +:" +:" complicated look-behind match +:call add(tl, [2, '\(r\@<=\|\w\@<!\)\/', 'x = /word/;', '/']) +:call add(tl, [2, '^[a-z]\+\ze \&\(asdf\)\@<!', 'foo bar', 'foo']) +:" +:""""" \@> +:call add(tl, [2, '\(a*\)\@>a', 'aaaa']) +:call add(tl, [2, '\(a*\)\@>b', 'aaab', 'aaab', 'aaa']) +:call add(tl, [2, '^\(.\{-}b\)\@>.', ' abcbd', ' abc', ' ab']) +:call add(tl, [2, '\(.\{-}\)\(\)\@>$', 'abc', 'abc', 'abc', '']) +:" TODO: BT engine does not restore submatch after failure +:call add(tl, [1, '\(a*\)\@>a\|a\+', 'aaaa', 'aaaa']) +:" +:"""" "\_" prepended negated collection matches EOL +:call add(tl, [2, '\_[^8-9]\+', "asfi\n9888", "asfi\n"]) +:call add(tl, [2, '\_[^a]\+', "asfi\n9888", "sfi\n9888"]) +:" +:"""" Requiring lots of states. +:call add(tl, [2, '[0-9a-zA-Z]\{8}-\([0-9a-zA-Z]\{4}-\)\{3}[0-9a-zA-Z]\{12}', " 12345678-1234-1234-1234-123456789012 ", "12345678-1234-1234-1234-123456789012", "1234-"]) +:" +:"""" Skip adding state twice +:call add(tl, [2, '^\%(\%(^\s*#\s*if\>\|#\s*if\)\)\(\%>1c.*$\)\@=', "#if FOO", "#if", ' FOO']) +:" +:""" Test \%V atom +:call add(tl, [2, '\%>70vGesamt', 'Jean-Michel Charlier & Victor Hubinon\Gesamtausgabe [Salleck] Buck Danny {Jean-Michel Charlier & Victor Hubinon}\Gesamtausgabe', 'Gesamt']) +:" +:"""" Run the tests +:" +:for t in tl +: let re = t[0] +: let pat = t[1] +: let text = t[2] +: let matchidx = 3 +: for engine in [0, 1, 2] +: if engine == 2 && re == 0 || engine == 1 && re == 1 +: continue +: endif +: let ®expengine = engine +: try +: let l = matchlist(text, pat) +: catch +: $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", caused an exception: \"' . v:exception . '\"' +: endtry +:" check the match itself +: if len(l) == 0 && len(t) > matchidx +: $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", did not match, expected: \"' . t[matchidx] . '\"' +: elseif len(l) > 0 && len(t) == matchidx +: $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", match: \"' . l[0] . '\", expected no match' +: elseif len(t) > matchidx && l[0] != t[matchidx] +: $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", match: \"' . l[0] . '\", expected: \"' . t[matchidx] . '\"' +: else +: $put ='OK ' . engine . ' - ' . pat +: endif +: if len(l) > 0 +:" check all the nine submatches +: for i in range(1, 9) +: if len(t) <= matchidx + i +: let e = '' +: else +: let e = t[matchidx + i] +: endif +: if l[i] != e +: $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", submatch ' . i . ': \"' . l[i] . '\", expected: \"' . e . '\"' +: endif +: endfor +: unlet i +: endif +: endfor +:endfor +:unlet t tl e l +:" +:"""""" multi-line tests """""""""""""""""""" +:let tl = [] +:" +:"""" back references +:call add(tl, [2, '^.\(.\).\_..\1.', ['aaa', 'aaa', 'b'], ['XX', 'b']]) +:call add(tl, [2, '\v.*\/(.*)\n.*\/\1$', ['./Dir1/Dir2/zyxwvuts.txt', './Dir1/Dir2/abcdefgh.bat', '', './Dir1/Dir2/file1.txt', './OtherDir1/OtherDir2/file1.txt'], ['./Dir1/Dir2/zyxwvuts.txt', './Dir1/Dir2/abcdefgh.bat', '', 'XX']]) +:" +:"""" line breaks +:call add(tl, [2, '\S.*\nx', ['abc', 'def', 'ghi', 'xjk', 'lmn'], ['abc', 'def', 'XXjk', 'lmn']]) +:" +:" Check that \_[0-9] matching EOL does not break a following \> +:call add(tl, [2, '\<\(\(25\_[0-5]\|2\_[0-4]\_[0-9]\|\_[01]\?\_[0-9]\_[0-9]\?\)\.\)\{3\}\(25\_[0-5]\|2\_[0-4]\_[0-9]\|\_[01]\?\_[0-9]\_[0-9]\?\)\>', ['', 'localnet/192.168.0.1', ''], ['', 'localnet/XX', '']]) +:" +:" Check a pattern with a line break and ^ and $ +:call add(tl, [2, 'a\n^b$\n^c', ['a', 'b', 'c'], ['XX']]) +:" +:call add(tl, [2, '\(^.\+\n\)\1', [' dog', ' dog', 'asdf'], ['XXasdf']]) +:" +:"""" Run the multi-line tests +:" +:$put ='multi-line tests' +:for t in tl +: let re = t[0] +: let pat = t[1] +: let before = t[2] +: let after = t[3] +: for engine in [0, 1, 2] +: if engine == 2 && re == 0 || engine == 1 && re ==1 +: continue +: endif +: let ®expengine = engine +: new +: call setline(1, before) +: exe '%s/' . pat . '/XX/' +: let result = getline(1, '$') +: q! +: if result != after +: $put ='ERROR: pat: \"' . pat . '\", text: \"' . string(before) . '\", expected: \"' . string(after) . '\", got: \"' . string(result) . '\"' +: else +: $put ='OK ' . engine . ' - ' . pat +: endif +: endfor +:endfor +:unlet t tl +:" +:" Check that using a pattern on two lines doesn't get messed up by using +:" matchstr() with \ze in between. +:set re=0 +/^Substitute here +:.+1,.+2s/""/\='"'.matchstr(getline("."), '\d\+\ze<').'"' +/^Substitute here +:.+1,.+2yank +Gop:" +:" +:" Check a pattern with a look beind crossing a line boundary +/^Behind: +/\(<\_[xy]\+\)\@3<=start +:.yank +Gop:" +:" +:" Check matching Visual area +/^Visual: +jfxvfx:s/\%Ve/E/g +jV:s/\%Va/A/g +jfxfxj:s/\%Vo/O/g +:/^Visual/+1,/^Visual/+4yank +Gop:" +:" +:" Check matching marks +/^Marks: +jfSmsfEme:.-4,.+6s/.\%>'s.*\%<'e../here/ +jfSmsj0fEme:.-4,.+6s/.\%>'s\_.*\%<'e../again/ +:/^Marks:/+1,/^Marks:/+3yank +Gop:" +:" +:" Check patterns matching cursor position. +:func! Postest() + new + call setline(1, ['ffooooo', 'boboooo', 'zoooooo', 'koooooo', 'moooooo', "\t\t\tfoo", 'abababababababfoo', 'bababababababafoo', '********_', ' xxxxxxxxxxxx xxxx xxxxxx xxxxxxx x xxxxxxxxx xx xxxxxx xxxxxx xxxxx xxxxxxx xx xxxx xxxxxxxx xxxx xxxxxxxxxxx xxx xxxxxxx xxxxxxxxx xx xxxxxx xx xxxxxxx xxxxxxxxxxxxxxxx xxxxxxxxx xxx xxxxxxxx xxxxxxxxx xxxx xxx xxxx xxx xxx xxxxx xxxxxxxxxxxx xxxx xxxxxxxxx xxxxxxxxxxx xx xxxxx xxx xxxxxxxx xxxxxx xxx xxx xxxxxxxxx xxxxxxx x xxxxxxxxx xx xxxxxx xxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxx xxx xxx xxxxxxxx xxxxxxx xxxx xxx xxxxxx xxxxx xxxxx xx xxxxxx xxxxxxx xxx xxxxxxxxxxxx xxxx xxxxxxxxx xxxxxx xxxxxx xxxxx xxx xxxxxxx xxxxxxxxxxxxxxxx xxxxxxxxx xxxxxxxxxx xxxx xx xxxxxxxx xxx xxxxxxxxxxx xxxxx']) + call setpos('.', [0, 1, 0, 0]) + s/\%>3c.//g + call setpos('.', [0, 2, 4, 0]) + s/\%#.*$//g + call setpos('.', [0, 3, 0, 0]) + s/\%<3c./_/g + %s/\%4l\%>5c./_/g + %s/\%6l\%>25v./_/g + %s/\%>6l\%3c./!/g + %s/\%>7l\%12c./?/g + %s/\%>7l\%<9l\%>5v\%<8v./#/g + $s/\%(|\u.*\)\@<=[^|\t]\+$//ge + 1,$yank + quit! +endfunc +Go-0-:set re=0 +:call Postest() +:put +o-1-:set re=1 +:call Postest() +:put +o-2-:set re=2 +:call Postest() +:put +:" +:" start and end of buffer +/\%^ +yeGop:" +50%/\%^.. +yeGopA END:" +50%/\%$ +"ayb20gg/..\%$ +"bybGo"apo"bp:" +:" +:" Check for detecting error +:set regexpengine=2 +:for pat in [' \ze*', ' \zs*'] +: try +: let l = matchlist('x x', pat) +: $put ='E888 NOT detected for ' . pat +: catch +: $put ='E888 detected for ' . pat +: endtry +:endfor +:" +:""""" Write the results """"""""""""" +:/\%#=1^Results/,$wq! test.out +ENDTEST + +Substitute here: +<T="">Ta 5</Title> +<T="">Ac 7</Title> + +Behind: +asdfasd<yyy +xxstart1 +asdfasd<yy +xxxstart2 +asdfasd<yy +xxstart3 + +Visual: +thexe the thexethe +andaxand andaxand +oooxofor foroxooo +oooxofor foroxooo + +Marks: +asdfSasdfsadfEasdf +asdfSas +dfsadfEasdf + +Results of test64: diff --git a/src/testdir/test64.ok b/src/testdir/test64.ok new file mode 100644 index 0000000..c218f8e --- /dev/null +++ b/src/testdir/test64.ok @@ -0,0 +1,1107 @@ +Results of test64: +OK 0 - ab +OK 1 - ab +OK 2 - ab +OK 0 - b +OK 1 - b +OK 2 - b +OK 0 - bc* +OK 1 - bc* +OK 2 - bc* +OK 0 - bc\{-} +OK 1 - bc\{-} +OK 2 - bc\{-} +OK 0 - bc\{-}\(d\) +OK 1 - bc\{-}\(d\) +OK 2 - bc\{-}\(d\) +OK 0 - bc* +OK 1 - bc* +OK 2 - bc* +OK 0 - c* +OK 1 - c* +OK 2 - c* +OK 0 - bc* +OK 1 - bc* +OK 2 - bc* +OK 0 - c* +OK 1 - c* +OK 2 - c* +OK 0 - bc\+ +OK 1 - bc\+ +OK 2 - bc\+ +OK 0 - bc\+ +OK 1 - bc\+ +OK 2 - bc\+ +OK 0 - a\|ab +OK 1 - a\|ab +OK 2 - a\|ab +OK 0 - c\? +OK 1 - c\? +OK 2 - c\? +OK 0 - bc\? +OK 1 - bc\? +OK 2 - bc\? +OK 0 - bc\? +OK 1 - bc\? +OK 2 - bc\? +OK 0 - \va{1} +OK 1 - \va{1} +OK 2 - \va{1} +OK 0 - \va{2} +OK 1 - \va{2} +OK 2 - \va{2} +OK 0 - \va{2} +OK 1 - \va{2} +OK 2 - \va{2} +OK 0 - \va{2} +OK 1 - \va{2} +OK 2 - \va{2} +OK 0 - \va{2} +OK 1 - \va{2} +OK 2 - \va{2} +OK 0 - \va{2} +OK 1 - \va{2} +OK 2 - \va{2} +OK 0 - \va{2} +OK 1 - \va{2} +OK 2 - \va{2} +OK 0 - \vb{1} +OK 1 - \vb{1} +OK 2 - \vb{1} +OK 0 - \vba{2} +OK 1 - \vba{2} +OK 2 - \vba{2} +OK 0 - \vba{3} +OK 1 - \vba{3} +OK 2 - \vba{3} +OK 0 - \v(ab){1} +OK 1 - \v(ab){1} +OK 2 - \v(ab){1} +OK 0 - \v(ab){1} +OK 1 - \v(ab){1} +OK 2 - \v(ab){1} +OK 0 - \v(ab){1} +OK 1 - \v(ab){1} +OK 2 - \v(ab){1} +OK 0 - \v(ab){0,2} +OK 1 - \v(ab){0,2} +OK 2 - \v(ab){0,2} +OK 0 - \v(ab){0,2} +OK 1 - \v(ab){0,2} +OK 2 - \v(ab){0,2} +OK 0 - \v(ab){1,2} +OK 1 - \v(ab){1,2} +OK 2 - \v(ab){1,2} +OK 0 - \v(ab){1,2} +OK 1 - \v(ab){1,2} +OK 2 - \v(ab){1,2} +OK 0 - \v(ab){2,4} +OK 1 - \v(ab){2,4} +OK 2 - \v(ab){2,4} +OK 0 - \v(ab){2,4} +OK 1 - \v(ab){2,4} +OK 2 - \v(ab){2,4} +OK 0 - \v(ab){2} +OK 1 - \v(ab){2} +OK 2 - \v(ab){2} +OK 0 - \v(ab){2} +OK 1 - \v(ab){2} +OK 2 - \v(ab){2} +OK 0 - \v(ab){2} +OK 1 - \v(ab){2} +OK 2 - \v(ab){2} +OK 0 - \v(ab){2} +OK 1 - \v(ab){2} +OK 2 - \v(ab){2} +OK 0 - \v((ab){2}){2} +OK 1 - \v((ab){2}){2} +OK 2 - \v((ab){2}){2} +OK 0 - \v((ab){2}){2} +OK 1 - \v((ab){2}){2} +OK 2 - \v((ab){2}){2} +OK 0 - \v(a{1}){1} +OK 1 - \v(a{1}){1} +OK 2 - \v(a{1}){1} +OK 0 - \v(a{2}){1} +OK 1 - \v(a{2}){1} +OK 2 - \v(a{2}){1} +OK 0 - \v(a{2}){1} +OK 1 - \v(a{2}){1} +OK 2 - \v(a{2}){1} +OK 0 - \v(a{2}){1} +OK 1 - \v(a{2}){1} +OK 2 - \v(a{2}){1} +OK 0 - \v(a{1}){2} +OK 1 - \v(a{1}){2} +OK 2 - \v(a{1}){2} +OK 0 - \v(a{1}){2} +OK 1 - \v(a{1}){2} +OK 2 - \v(a{1}){2} +OK 0 - \v(a{2})+ +OK 1 - \v(a{2})+ +OK 2 - \v(a{2})+ +OK 0 - \v(a{2})+ +OK 1 - \v(a{2})+ +OK 2 - \v(a{2})+ +OK 0 - \v(a{2}){1} +OK 1 - \v(a{2}){1} +OK 2 - \v(a{2}){1} +OK 0 - \v(a{1}){2} +OK 1 - \v(a{1}){2} +OK 2 - \v(a{1}){2} +OK 0 - \v(a{1}){1} +OK 1 - \v(a{1}){1} +OK 2 - \v(a{1}){1} +OK 0 - \v(a{2}){2} +OK 1 - \v(a{2}){2} +OK 2 - \v(a{2}){2} +OK 0 - \v(a{2}){2} +OK 1 - \v(a{2}){2} +OK 2 - \v(a{2}){2} +OK 0 - \v(a+){2} +OK 1 - \v(a+){2} +OK 2 - \v(a+){2} +OK 0 - \v(a{3}){2} +OK 1 - \v(a{3}){2} +OK 2 - \v(a{3}){2} +OK 0 - \v(a{1,2}){2} +OK 1 - \v(a{1,2}){2} +OK 2 - \v(a{1,2}){2} +OK 0 - \v(a{1,3}){2} +OK 1 - \v(a{1,3}){2} +OK 2 - \v(a{1,3}){2} +OK 0 - \v(a{1,3}){2} +OK 1 - \v(a{1,3}){2} +OK 2 - \v(a{1,3}){2} +OK 0 - \v(a{1,3}){3} +OK 1 - \v(a{1,3}){3} +OK 2 - \v(a{1,3}){3} +OK 0 - \v(a{1,2}){2} +OK 1 - \v(a{1,2}){2} +OK 2 - \v(a{1,2}){2} +OK 0 - \v(a+)+ +OK 1 - \v(a+)+ +OK 2 - \v(a+)+ +OK 0 - \v(a+)+ +OK 1 - \v(a+)+ +OK 2 - \v(a+)+ +OK 0 - \v(a+){1,2} +OK 1 - \v(a+){1,2} +OK 2 - \v(a+){1,2} +OK 0 - \v(a+)(a+) +OK 1 - \v(a+)(a+) +OK 2 - \v(a+)(a+) +OK 0 - \v(a{3})+ +OK 1 - \v(a{3})+ +OK 2 - \v(a{3})+ +OK 0 - \v(a|b|c)+ +OK 1 - \v(a|b|c)+ +OK 2 - \v(a|b|c)+ +OK 0 - \v(a|b|c){2} +OK 1 - \v(a|b|c){2} +OK 2 - \v(a|b|c){2} +OK 0 - \v(abc){2} +OK 1 - \v(abc){2} +OK 2 - \v(abc){2} +OK 0 - \v(abc){2} +OK 1 - \v(abc){2} +OK 2 - \v(abc){2} +OK 0 - a* +OK 1 - a* +OK 2 - a* +OK 0 - \v(a*)+ +OK 1 - \v(a*)+ +OK 2 - \v(a*)+ +OK 0 - \v((ab)+)+ +OK 1 - \v((ab)+)+ +OK 2 - \v((ab)+)+ +OK 0 - \v(((ab)+)+)+ +OK 1 - \v(((ab)+)+)+ +OK 2 - \v(((ab)+)+)+ +OK 0 - \v(((ab)+)+)+ +OK 1 - \v(((ab)+)+)+ +OK 2 - \v(((ab)+)+)+ +OK 0 - \v(a{0,2})+ +OK 1 - \v(a{0,2})+ +OK 2 - \v(a{0,2})+ +OK 0 - \v(a*)+ +OK 1 - \v(a*)+ +OK 2 - \v(a*)+ +OK 0 - \v((a*)+)+ +OK 1 - \v((a*)+)+ +OK 2 - \v((a*)+)+ +OK 0 - \v((ab)*)+ +OK 1 - \v((ab)*)+ +OK 2 - \v((ab)*)+ +OK 0 - \va{1,3} +OK 1 - \va{1,3} +OK 2 - \va{1,3} +OK 0 - \va{2,3} +OK 1 - \va{2,3} +OK 2 - \va{2,3} +OK 0 - \v((ab)+|c*)+ +OK 1 - \v((ab)+|c*)+ +OK 2 - \v((ab)+|c*)+ +OK 0 - \v(a{2})|(b{3}) +OK 1 - \v(a{2})|(b{3}) +OK 2 - \v(a{2})|(b{3}) +OK 0 - \va{2}|b{2} +OK 1 - \va{2}|b{2} +OK 2 - \va{2}|b{2} +OK 0 - \v(a)+|(c)+ +OK 1 - \v(a)+|(c)+ +OK 2 - \v(a)+|(c)+ +OK 0 - \vab{2,3}c +OK 1 - \vab{2,3}c +OK 2 - \vab{2,3}c +OK 0 - \vab{2,3}c +OK 1 - \vab{2,3}c +OK 2 - \vab{2,3}c +OK 0 - \vab{2,3}cd{2,3}e +OK 1 - \vab{2,3}cd{2,3}e +OK 2 - \vab{2,3}cd{2,3}e +OK 0 - \va(bc){2}d +OK 1 - \va(bc){2}d +OK 2 - \va(bc){2}d +OK 0 - \va*a{2} +OK 1 - \va*a{2} +OK 2 - \va*a{2} +OK 0 - \va*a{2} +OK 1 - \va*a{2} +OK 2 - \va*a{2} +OK 0 - \va*a{2} +OK 1 - \va*a{2} +OK 2 - \va*a{2} +OK 0 - \va*a{2} +OK 1 - \va*a{2} +OK 2 - \va*a{2} +OK 0 - \va*b*|a*c* +OK 1 - \va*b*|a*c* +OK 2 - \va*b*|a*c* +OK 0 - \va{1}b{1}|a{1}b{1} +OK 1 - \va{1}b{1}|a{1}b{1} +OK 2 - \va{1}b{1}|a{1}b{1} +OK 0 - \v(a) +OK 1 - \v(a) +OK 2 - \v(a) +OK 0 - \v(a)(b) +OK 1 - \v(a)(b) +OK 2 - \v(a)(b) +OK 0 - \v(ab)(b)(c) +OK 1 - \v(ab)(b)(c) +OK 2 - \v(ab)(b)(c) +OK 0 - \v((a)(b)) +OK 1 - \v((a)(b)) +OK 2 - \v((a)(b)) +OK 0 - \v(a)|(b) +OK 1 - \v(a)|(b) +OK 2 - \v(a)|(b) +OK 0 - \v(a*)+ +OK 1 - \v(a*)+ +OK 2 - \v(a*)+ +OK 0 - x +OK 1 - x +OK 2 - x +OK 0 - ab +OK 1 - ab +OK 2 - ab +OK 0 - ab +OK 1 - ab +OK 2 - ab +OK 0 - ab +OK 1 - ab +OK 2 - ab +OK 0 - x* +OK 1 - x* +OK 2 - x* +OK 0 - x* +OK 1 - x* +OK 2 - x* +OK 0 - x* +OK 1 - x* +OK 2 - x* +OK 0 - x\+ +OK 1 - x\+ +OK 2 - x\+ +OK 0 - x\+ +OK 1 - x\+ +OK 2 - x\+ +OK 0 - x\+ +OK 1 - x\+ +OK 2 - x\+ +OK 0 - x\+ +OK 1 - x\+ +OK 2 - x\+ +OK 0 - x\= +OK 1 - x\= +OK 2 - x\= +OK 0 - x\= +OK 1 - x\= +OK 2 - x\= +OK 0 - x\= +OK 1 - x\= +OK 2 - x\= +OK 0 - x\? +OK 1 - x\? +OK 2 - x\? +OK 0 - x\? +OK 1 - x\? +OK 2 - x\? +OK 0 - x\? +OK 1 - x\? +OK 2 - x\? +OK 0 - a\{0,0} +OK 1 - a\{0,0} +OK 2 - a\{0,0} +OK 0 - a\{0,1} +OK 1 - a\{0,1} +OK 2 - a\{0,1} +OK 0 - a\{1,0} +OK 1 - a\{1,0} +OK 2 - a\{1,0} +OK 0 - a\{3,6} +OK 1 - a\{3,6} +OK 2 - a\{3,6} +OK 0 - a\{3,6} +OK 1 - a\{3,6} +OK 2 - a\{3,6} +OK 0 - a\{3,6} +OK 1 - a\{3,6} +OK 2 - a\{3,6} +OK 0 - a\{0} +OK 1 - a\{0} +OK 2 - a\{0} +OK 0 - a\{2} +OK 1 - a\{2} +OK 2 - a\{2} +OK 0 - a\{2} +OK 1 - a\{2} +OK 2 - a\{2} +OK 0 - a\{2} +OK 1 - a\{2} +OK 2 - a\{2} +OK 0 - a\{0,} +OK 1 - a\{0,} +OK 2 - a\{0,} +OK 0 - a\{0,} +OK 1 - a\{0,} +OK 2 - a\{0,} +OK 0 - a\{2,} +OK 1 - a\{2,} +OK 2 - a\{2,} +OK 0 - a\{2,} +OK 1 - a\{2,} +OK 2 - a\{2,} +OK 0 - a\{5,} +OK 1 - a\{5,} +OK 2 - a\{5,} +OK 0 - a\{5,} +OK 1 - a\{5,} +OK 2 - a\{5,} +OK 0 - a\{,0} +OK 1 - a\{,0} +OK 2 - a\{,0} +OK 0 - a\{,5} +OK 1 - a\{,5} +OK 2 - a\{,5} +OK 0 - a\{,5} +OK 1 - a\{,5} +OK 2 - a\{,5} +OK 0 - ^*\{4,}$ +OK 1 - ^*\{4,}$ +OK 2 - ^*\{4,}$ +OK 0 - ^*\{4,}$ +OK 1 - ^*\{4,}$ +OK 2 - ^*\{4,}$ +OK 0 - ^*\{4,}$ +OK 1 - ^*\{4,}$ +OK 2 - ^*\{4,}$ +OK 0 - a\{} +OK 1 - a\{} +OK 2 - a\{} +OK 0 - a\{} +OK 1 - a\{} +OK 2 - a\{} +OK 0 - a\{-0,0} +OK 1 - a\{-0,0} +OK 2 - a\{-0,0} +OK 0 - a\{-0,1} +OK 1 - a\{-0,1} +OK 2 - a\{-0,1} +OK 0 - a\{-3,6} +OK 1 - a\{-3,6} +OK 2 - a\{-3,6} +OK 0 - a\{-3,6} +OK 1 - a\{-3,6} +OK 2 - a\{-3,6} +OK 0 - a\{-3,6} +OK 1 - a\{-3,6} +OK 2 - a\{-3,6} +OK 0 - a\{-0} +OK 1 - a\{-0} +OK 2 - a\{-0} +OK 0 - a\{-2} +OK 1 - a\{-2} +OK 2 - a\{-2} +OK 0 - a\{-2} +OK 1 - a\{-2} +OK 2 - a\{-2} +OK 0 - a\{-0,} +OK 1 - a\{-0,} +OK 2 - a\{-0,} +OK 0 - a\{-0,} +OK 1 - a\{-0,} +OK 2 - a\{-0,} +OK 0 - a\{-2,} +OK 1 - a\{-2,} +OK 2 - a\{-2,} +OK 0 - a\{-2,} +OK 1 - a\{-2,} +OK 2 - a\{-2,} +OK 0 - a\{-,0} +OK 1 - a\{-,0} +OK 2 - a\{-,0} +OK 0 - a\{-,5} +OK 1 - a\{-,5} +OK 2 - a\{-,5} +OK 0 - a\{-,5} +OK 1 - a\{-,5} +OK 2 - a\{-,5} +OK 0 - a\{-} +OK 1 - a\{-} +OK 2 - a\{-} +OK 0 - a\{-} +OK 1 - a\{-} +OK 2 - a\{-} +OK 0 - \(abc\)* +OK 1 - \(abc\)* +OK 2 - \(abc\)* +OK 0 - \(ab\)\+ +OK 1 - \(ab\)\+ +OK 2 - \(ab\)\+ +OK 0 - \(abaaaaa\)*cd +OK 1 - \(abaaaaa\)*cd +OK 2 - \(abaaaaa\)*cd +OK 0 - \(test1\)\? \(test2\)\? +OK 1 - \(test1\)\? \(test2\)\? +OK 2 - \(test1\)\? \(test2\)\? +OK 0 - \(test1\)\= \(test2\) \(test4443\)\= +OK 1 - \(test1\)\= \(test2\) \(test4443\)\= +OK 2 - \(test1\)\= \(test2\) \(test4443\)\= +OK 0 - \(\(sub1\) hello \(sub 2\)\) +OK 1 - \(\(sub1\) hello \(sub 2\)\) +OK 2 - \(\(sub1\) hello \(sub 2\)\) +OK 0 - \(\(\(yyxxzz\)\)\) +OK 1 - \(\(\(yyxxzz\)\)\) +OK 2 - \(\(\(yyxxzz\)\)\) +OK 0 - \v((ab)+|c+)+ +OK 1 - \v((ab)+|c+)+ +OK 2 - \v((ab)+|c+)+ +OK 0 - \v((ab)|c*)+ +OK 1 - \v((ab)|c*)+ +OK 2 - \v((ab)|c*)+ +OK 0 - \v(a(c*)+b)+ +OK 1 - \v(a(c*)+b)+ +OK 2 - \v(a(c*)+b)+ +OK 0 - \v(a|b*)+ +OK 1 - \v(a|b*)+ +OK 2 - \v(a|b*)+ +OK 0 - \p* +OK 1 - \p* +OK 2 - \p* +OK 0 - a\{-2,7} +OK 1 - a\{-2,7} +OK 2 - a\{-2,7} +OK 0 - a\{-2,7}x +OK 1 - a\{-2,7}x +OK 2 - a\{-2,7}x +OK 0 - a\{2,7} +OK 1 - a\{2,7} +OK 2 - a\{2,7} +OK 0 - a\{2,7}x +OK 1 - a\{2,7}x +OK 2 - a\{2,7}x +OK 0 - \vx(.{-,8})yz(.*) +OK 1 - \vx(.{-,8})yz(.*) +OK 2 - \vx(.{-,8})yz(.*) +OK 0 - \vx(.*)yz(.*) +OK 1 - \vx(.*)yz(.*) +OK 2 - \vx(.*)yz(.*) +OK 0 - \v(a{1,2}){-2,3} +OK 1 - \v(a{1,2}){-2,3} +OK 2 - \v(a{1,2}){-2,3} +OK 0 - \v(a{-1,3})+ +OK 1 - \v(a{-1,3})+ +OK 2 - \v(a{-1,3})+ +OK 0 - ^\s\{-}\zs\( x\|x$\) +OK 1 - ^\s\{-}\zs\( x\|x$\) +OK 2 - ^\s\{-}\zs\( x\|x$\) +OK 0 - ^\s\{-}\zs\(x\| x$\) +OK 1 - ^\s\{-}\zs\(x\| x$\) +OK 2 - ^\s\{-}\zs\(x\| x$\) +OK 0 - ^\s\{-}\ze\(x\| x$\) +OK 1 - ^\s\{-}\ze\(x\| x$\) +OK 2 - ^\s\{-}\ze\(x\| x$\) +OK 0 - ^\(\s\{-}\)\(x\| x$\) +OK 1 - ^\(\s\{-}\)\(x\| x$\) +OK 2 - ^\(\s\{-}\)\(x\| x$\) +OK 0 - \d\+e\d\d +OK 1 - \d\+e\d\d +OK 2 - \d\+e\d\d +OK 0 - \v[a] +OK 1 - \v[a] +OK 2 - \v[a] +OK 0 - a[bcd] +OK 1 - a[bcd] +OK 2 - a[bcd] +OK 0 - a[b-d] +OK 1 - a[b-d] +OK 2 - a[b-d] +OK 0 - [a-d][e-f][x-x]d +OK 1 - [a-d][e-f][x-x]d +OK 2 - [a-d][e-f][x-x]d +OK 0 - \v[[:alpha:]]+ +OK 1 - \v[[:alpha:]]+ +OK 2 - \v[[:alpha:]]+ +OK 0 - [[:alpha:]\+] +OK 1 - [[:alpha:]\+] +OK 2 - [[:alpha:]\+] +OK 0 - [^abc]\+ +OK 1 - [^abc]\+ +OK 2 - [^abc]\+ +OK 0 - [^abc] +OK 1 - [^abc] +OK 2 - [^abc] +OK 0 - [^abc]\+ +OK 1 - [^abc]\+ +OK 2 - [^abc]\+ +OK 0 - [^a-d]\+ +OK 1 - [^a-d]\+ +OK 2 - [^a-d]\+ +OK 0 - [a-f]* +OK 1 - [a-f]* +OK 2 - [a-f]* +OK 0 - [a-f]* +OK 1 - [a-f]* +OK 2 - [a-f]* +OK 0 - [^a-f]\+ +OK 1 - [^a-f]\+ +OK 2 - [^a-f]\+ +OK 0 - [a-c]\{-3,6} +OK 1 - [a-c]\{-3,6} +OK 2 - [a-c]\{-3,6} +OK 0 - [^[:alpha:]]\+ +OK 1 - [^[:alpha:]]\+ +OK 2 - [^[:alpha:]]\+ +OK 0 - [-a] +OK 1 - [-a] +OK 2 - [-a] +OK 0 - [a-] +OK 1 - [a-] +OK 2 - [a-] +OK 0 - [a-f]*\c +OK 1 - [a-f]*\c +OK 2 - [a-f]*\c +OK 0 - [abc][xyz]\c +OK 1 - [abc][xyz]\c +OK 2 - [abc][xyz]\c +OK 0 - [-./[:alnum:]_~]\+ +OK 1 - [-./[:alnum:]_~]\+ +OK 2 - [-./[:alnum:]_~]\+ +OK 0 - [\]\^\-\\]\+ +OK 1 - [\]\^\-\\]\+ +OK 2 - [\]\^\-\\]\+ +OK 0 - [[.a.]]\+ +OK 1 - [[.a.]]\+ +OK 2 - [[.a.]]\+ +OK 0 - abc[0-9]*ddd +OK 1 - abc[0-9]*ddd +OK 2 - abc[0-9]*ddd +OK 0 - abc[0-9]*ddd +OK 1 - abc[0-9]*ddd +OK 2 - abc[0-9]*ddd +OK 0 - \_[0-9]\+ +OK 1 - \_[0-9]\+ +OK 2 - \_[0-9]\+ +OK 0 - [0-9\n]\+ +OK 1 - [0-9\n]\+ +OK 2 - [0-9\n]\+ +OK 0 - \_[0-9]\+ +OK 1 - \_[0-9]\+ +OK 2 - \_[0-9]\+ +OK 0 - \_f +OK 1 - \_f +OK 2 - \_f +OK 0 - \_f\+ +OK 1 - \_f\+ +OK 2 - \_f\+ +OK 0 - [0-9A-Za-z-_.]\+ +OK 1 - [0-9A-Za-z-_.]\+ +OK 2 - [0-9A-Za-z-_.]\+ +OK 0 - ^a. +OK 1 - ^a. +OK 2 - ^a. +OK 0 - ^a. +OK 1 - ^a. +OK 2 - ^a. +OK 0 - .a$ +OK 1 - .a$ +OK 2 - .a$ +OK 0 - .a$ +OK 1 - .a$ +OK 2 - .a$ +OK 0 - \%^a. +OK 1 - \%^a. +OK 2 - \%^a. +OK 0 - \%^a +OK 1 - \%^a +OK 2 - \%^a +OK 0 - .a\%$ +OK 1 - .a\%$ +OK 2 - .a\%$ +OK 0 - .a\%$ +OK 1 - .a\%$ +OK 2 - .a\%$ +OK 0 - [0-7]\+ +OK 1 - [0-7]\+ +OK 2 - [0-7]\+ +OK 0 - [^0-7]\+ +OK 1 - [^0-7]\+ +OK 2 - [^0-7]\+ +OK 0 - [0-9]\+ +OK 1 - [0-9]\+ +OK 2 - [0-9]\+ +OK 0 - [^0-9]\+ +OK 1 - [^0-9]\+ +OK 2 - [^0-9]\+ +OK 0 - [0-9a-fA-F]\+ +OK 1 - [0-9a-fA-F]\+ +OK 2 - [0-9a-fA-F]\+ +OK 0 - [^0-9A-Fa-f]\+ +OK 1 - [^0-9A-Fa-f]\+ +OK 2 - [^0-9A-Fa-f]\+ +OK 0 - [a-z_A-Z0-9]\+ +OK 1 - [a-z_A-Z0-9]\+ +OK 2 - [a-z_A-Z0-9]\+ +OK 0 - [^a-z_A-Z0-9]\+ +OK 1 - [^a-z_A-Z0-9]\+ +OK 2 - [^a-z_A-Z0-9]\+ +OK 0 - [a-z_A-Z]\+ +OK 1 - [a-z_A-Z]\+ +OK 2 - [a-z_A-Z]\+ +OK 0 - [^a-z_A-Z]\+ +OK 1 - [^a-z_A-Z]\+ +OK 2 - [^a-z_A-Z]\+ +OK 0 - [a-z]\+ +OK 1 - [a-z]\+ +OK 2 - [a-z]\+ +OK 0 - [a-z]\+ +OK 1 - [a-z]\+ +OK 2 - [a-z]\+ +OK 0 - [^a-z]\+ +OK 1 - [^a-z]\+ +OK 2 - [^a-z]\+ +OK 0 - [^a-z]\+ +OK 1 - [^a-z]\+ +OK 2 - [^a-z]\+ +OK 0 - [a-zA-Z]\+ +OK 1 - [a-zA-Z]\+ +OK 2 - [a-zA-Z]\+ +OK 0 - [^a-zA-Z]\+ +OK 1 - [^a-zA-Z]\+ +OK 2 - [^a-zA-Z]\+ +OK 0 - [A-Z]\+ +OK 1 - [A-Z]\+ +OK 2 - [A-Z]\+ +OK 0 - [^A-Z]\+ +OK 1 - [^A-Z]\+ +OK 2 - [^A-Z]\+ +OK 0 - [a-z]\+\c +OK 1 - [a-z]\+\c +OK 2 - [a-z]\+\c +OK 0 - [A-Z]\+\c +OK 1 - [A-Z]\+\c +OK 2 - [A-Z]\+\c +OK 0 - \c[^a-z]\+ +OK 1 - \c[^a-z]\+ +OK 2 - \c[^a-z]\+ +OK 0 - \c[^A-Z]\+ +OK 1 - \c[^A-Z]\+ +OK 2 - \c[^A-Z]\+ +OK 0 - \C[^A-Z]\+ +OK 1 - \C[^A-Z]\+ +OK 2 - \C[^A-Z]\+ +OK 0 - xx \ze test +OK 1 - xx \ze test +OK 2 - xx \ze test +OK 0 - abc\zeend +OK 1 - abc\zeend +OK 2 - abc\zeend +OK 0 - aa\zebb\|aaxx +OK 1 - aa\zebb\|aaxx +OK 2 - aa\zebb\|aaxx +OK 0 - aa\zebb\|aaxx +OK 1 - aa\zebb\|aaxx +OK 2 - aa\zebb\|aaxx +OK 0 - aabb\|aa\zebb +OK 1 - aabb\|aa\zebb +OK 2 - aabb\|aa\zebb +OK 0 - aa\zebb\|aaebb +OK 1 - aa\zebb\|aaebb +OK 2 - aa\zebb\|aaebb +OK 0 - abc\zsdd +OK 1 - abc\zsdd +OK 2 - abc\zsdd +OK 0 - aa \zsax +OK 1 - aa \zsax +OK 2 - aa \zsax +OK 0 - abc \zsmatch\ze abc +OK 1 - abc \zsmatch\ze abc +OK 2 - abc \zsmatch\ze abc +OK 0 - \v(a \zsif .*){2} +OK 1 - \v(a \zsif .*){2} +OK 2 - \v(a \zsif .*){2} +OK 0 - \>\zs. +OK 1 - \>\zs. +OK 2 - \>\zs. +OK 0 - \s\+\ze\[/\|\s\zs\s\+ +OK 1 - \s\+\ze\[/\|\s\zs\s\+ +OK 2 - \s\+\ze\[/\|\s\zs\s\+ +OK 0 - abc\@= +OK 1 - abc\@= +OK 2 - abc\@= +OK 0 - abc\@=cd +OK 1 - abc\@=cd +OK 2 - abc\@=cd +OK 0 - abc\@= +OK 1 - abc\@= +OK 2 - abc\@= +OK 0 - abcd\@=e +OK 1 - abcd\@=e +OK 2 - abcd\@=e +OK 0 - abcd\@=e +OK 1 - abcd\@=e +OK 2 - abcd\@=e +OK 0 - \v(abc)@=.. +OK 1 - \v(abc)@=.. +OK 2 - \v(abc)@=.. +OK 0 - \(.*John\)\@=.*Bob +OK 1 - \(.*John\)\@=.*Bob +OK 2 - \(.*John\)\@=.*Bob +OK 0 - \(John.*\)\@=.*Bob +OK 1 - \(John.*\)\@=.*Bob +OK 2 - \(John.*\)\@=.*Bob +OK 0 - \<\S\+\())\)\@= +OK 1 - \<\S\+\())\)\@= +OK 2 - \<\S\+\())\)\@= +OK 0 - .*John\&.*Bob +OK 1 - .*John\&.*Bob +OK 2 - .*John\&.*Bob +OK 0 - .*John\&.*Bob +OK 1 - .*John\&.*Bob +OK 2 - .*John\&.*Bob +OK 0 - \v(test1)@=.*yep +OK 1 - \v(test1)@=.*yep +OK 2 - \v(test1)@=.*yep +OK 0 - foo\(bar\)\@! +OK 1 - foo\(bar\)\@! +OK 2 - foo\(bar\)\@! +OK 0 - foo\(bar\)\@! +OK 1 - foo\(bar\)\@! +OK 2 - foo\(bar\)\@! +OK 0 - if \(\(then\)\@!.\)*$ +OK 1 - if \(\(then\)\@!.\)*$ +OK 2 - if \(\(then\)\@!.\)*$ +OK 0 - if \(\(then\)\@!.\)*$ +OK 1 - if \(\(then\)\@!.\)*$ +OK 2 - if \(\(then\)\@!.\)*$ +OK 0 - \(foo\)\@!bar +OK 1 - \(foo\)\@!bar +OK 2 - \(foo\)\@!bar +OK 0 - \(foo\)\@!...bar +OK 1 - \(foo\)\@!...bar +OK 2 - \(foo\)\@!...bar +OK 0 - ^\%(.*bar\)\@!.*\zsfoo +OK 1 - ^\%(.*bar\)\@!.*\zsfoo +OK 2 - ^\%(.*bar\)\@!.*\zsfoo +OK 0 - ^\%(.*bar\)\@!.*\zsfoo +OK 1 - ^\%(.*bar\)\@!.*\zsfoo +OK 2 - ^\%(.*bar\)\@!.*\zsfoo +OK 0 - ^\%(.*bar\)\@!.*\zsfoo +OK 1 - ^\%(.*bar\)\@!.*\zsfoo +OK 2 - ^\%(.*bar\)\@!.*\zsfoo +OK 0 - [ ]\@!\p\%([ ]\@!\p\)*: +OK 1 - [ ]\@!\p\%([ ]\@!\p\)*: +OK 2 - [ ]\@!\p\%([ ]\@!\p\)*: +OK 0 - [ ]\@!\p\([ ]\@!\p\)*: +OK 1 - [ ]\@!\p\([ ]\@!\p\)*: +OK 2 - [ ]\@!\p\([ ]\@!\p\)*: +OK 0 - m\k\+_\@=\%(_\@!\k\)\@<=\k\+e +OK 1 - m\k\+_\@=\%(_\@!\k\)\@<=\k\+e +OK 2 - m\k\+_\@=\%(_\@!\k\)\@<=\k\+e +OK 0 - \%(\U\@<=S\k*\|S\l\)R +OK 1 - \%(\U\@<=S\k*\|S\l\)R +OK 2 - \%(\U\@<=S\k*\|S\l\)R +OK 0 - [[:alpha:]]\{-2,6} +OK 1 - [[:alpha:]]\{-2,6} +OK 2 - [[:alpha:]]\{-2,6} +OK 0 - +OK 1 - +OK 2 - +OK 0 - \v(()) +OK 1 - \v(()) +OK 2 - \v(()) +OK 0 - \v%(ab(xyz)c) +OK 1 - \v%(ab(xyz)c) +OK 2 - \v%(ab(xyz)c) +OK 0 - \v(test|)empty +OK 1 - \v(test|)empty +OK 2 - \v(test|)empty +OK 0 - \v(a|aa)(a|aa) +OK 1 - \v(a|aa)(a|aa) +OK 2 - \v(a|aa)(a|aa) +OK 0 - \%d32 +OK 1 - \%d32 +OK 2 - \%d32 +OK 0 - \%o40 +OK 1 - \%o40 +OK 2 - \%o40 +OK 0 - \%x20 +OK 1 - \%x20 +OK 2 - \%x20 +OK 0 - \%u0020 +OK 1 - \%u0020 +OK 2 - \%u0020 +OK 0 - \%U00000020 +OK 1 - \%U00000020 +OK 2 - \%U00000020 +OK 0 - \%d0 +OK 1 - \%d0 +OK 2 - \%d0 +OK 0 - foo\%[bar] +OK 1 - foo\%[bar] +OK 2 - foo\%[bar] +OK 0 - foo\%[bar] +OK 1 - foo\%[bar] +OK 2 - foo\%[bar] +OK 0 - foo\%[bar] +OK 1 - foo\%[bar] +OK 2 - foo\%[bar] +OK 0 - foo\%[bar] +OK 1 - foo\%[bar] +OK 2 - foo\%[bar] +OK 0 - foo\%[bar] +OK 1 - foo\%[bar] +OK 2 - foo\%[bar] +OK 0 - foo\%[bar] +OK 1 - foo\%[bar] +OK 2 - foo\%[bar] +OK 0 - foo\%[bar]x +OK 1 - foo\%[bar]x +OK 2 - foo\%[bar]x +OK 0 - foo\%[bar]x +OK 1 - foo\%[bar]x +OK 2 - foo\%[bar]x +OK 0 - \%[bar]x +OK 1 - \%[bar]x +OK 2 - \%[bar]x +OK 0 - \%[bar]x +OK 1 - \%[bar]x +OK 2 - \%[bar]x +OK 0 - \%[bar]x +OK 1 - \%[bar]x +OK 2 - \%[bar]x +OK 0 - b\%[[ao]r] +OK 1 - b\%[[ao]r] +OK 2 - b\%[[ao]r] +OK 0 - b\%[[]]r] +OK 1 - b\%[[]]r] +OK 2 - b\%[[]]r] +OK 0 - @\%[\w\-]* +OK 1 - @\%[\w\-]* +OK 2 - @\%[\w\-]* +OK 0 - goo\|go +OK 1 - goo\|go +OK 2 - goo\|go +OK 0 - \<goo\|\<go +OK 1 - \<goo\|\<go +OK 2 - \<goo\|\<go +OK 0 - \<goo\|go +OK 1 - \<goo\|go +OK 2 - \<goo\|go +OK 0 - \(\i\+\) \1 +OK 1 - \(\i\+\) \1 +OK 2 - \(\i\+\) \1 +OK 0 - \(\i\+\) \1 +OK 1 - \(\i\+\) \1 +OK 2 - \(\i\+\) \1 +OK 0 - \(a\)\(b\)\(c\)\(dd\)\(e\)\(f\)\(g\)\(h\)\(i\)\1\2\3\4\5\6\7\8\9 +OK 1 - \(a\)\(b\)\(c\)\(dd\)\(e\)\(f\)\(g\)\(h\)\(i\)\1\2\3\4\5\6\7\8\9 +OK 2 - \(a\)\(b\)\(c\)\(dd\)\(e\)\(f\)\(g\)\(h\)\(i\)\1\2\3\4\5\6\7\8\9 +OK 0 - \(\d*\)a \1b +OK 1 - \(\d*\)a \1b +OK 2 - \(\d*\)a \1b +OK 0 - ^.\(.\).\_..\1. +OK 1 - ^.\(.\).\_..\1. +OK 2 - ^.\(.\).\_..\1. +OK 0 - ^.*\.\(.*\)/.\+\(\1\)\@<!$ +OK 1 - ^.*\.\(.*\)/.\+\(\1\)\@<!$ +OK 2 - ^.*\.\(.*\)/.\+\(\1\)\@<!$ +OK 0 - ^.*\.\(.*\)/.\+\(\1\)\@<!$ +OK 1 - ^.*\.\(.*\)/.\+\(\1\)\@<!$ +OK 2 - ^.*\.\(.*\)/.\+\(\1\)\@<!$ +OK 0 - ^.*\.\(.*\)/.\+\(\1\)\@<=$ +OK 1 - ^.*\.\(.*\)/.\+\(\1\)\@<=$ +OK 2 - ^.*\.\(.*\)/.\+\(\1\)\@<=$ +OK 0 - \\\@<!\${\(\d\+\%(:.\{-}\)\?\\\@<!\)} +OK 1 - \\\@<!\${\(\d\+\%(:.\{-}\)\?\\\@<!\)} +OK 2 - \\\@<!\${\(\d\+\%(:.\{-}\)\?\\\@<!\)} +OK 0 - ^\(a*\)\1$ +OK 1 - ^\(a*\)\1$ +OK 2 - ^\(a*\)\1$ +OK 0 - ^\(a\{-2,}\)\1\+$ +OK 1 - ^\(a\{-2,}\)\1\+$ +OK 2 - ^\(a\{-2,}\)\1\+$ +OK 0 - <\@<=span. +OK 1 - <\@<=span. +OK 2 - <\@<=span. +OK 0 - <\@1<=span. +OK 1 - <\@1<=span. +OK 2 - <\@1<=span. +OK 0 - <\@2<=span. +OK 1 - <\@2<=span. +OK 2 - <\@2<=span. +OK 0 - \(<<\)\@<=span. +OK 1 - \(<<\)\@<=span. +OK 2 - \(<<\)\@<=span. +OK 0 - \(<<\)\@1<=span. +OK 1 - \(<<\)\@1<=span. +OK 2 - \(<<\)\@1<=span. +OK 0 - \(<<\)\@2<=span. +OK 1 - \(<<\)\@2<=span. +OK 2 - \(<<\)\@2<=span. +OK 0 - \(foo\)\@<!bar. +OK 1 - \(foo\)\@<!bar. +OK 2 - \(foo\)\@<!bar. +OK 0 - \v\C%(<Last Changed:\s+)@<=.*$ +OK 1 - \v\C%(<Last Changed:\s+)@<=.*$ +OK 2 - \v\C%(<Last Changed:\s+)@<=.*$ +OK 0 - \v\C%(<Last Changed:\s+)@<=.*$ +OK 1 - \v\C%(<Last Changed:\s+)@<=.*$ +OK 2 - \v\C%(<Last Changed:\s+)@<=.*$ +OK 0 - \(foo\)\@<=\> +OK 1 - \(foo\)\@<=\> +OK 2 - \(foo\)\@<=\> +OK 0 - \(foo\)\@<=\> +OK 1 - \(foo\)\@<=\> +OK 2 - \(foo\)\@<=\> +OK 0 - \(foo\)\@<=.* +OK 1 - \(foo\)\@<=.* +OK 2 - \(foo\)\@<=.* +OK 0 - \(r\@<=\|\w\@<!\)\/ +OK 1 - \(r\@<=\|\w\@<!\)\/ +OK 2 - \(r\@<=\|\w\@<!\)\/ +OK 0 - ^[a-z]\+\ze \&\(asdf\)\@<! +OK 1 - ^[a-z]\+\ze \&\(asdf\)\@<! +OK 2 - ^[a-z]\+\ze \&\(asdf\)\@<! +OK 0 - \(a*\)\@>a +OK 1 - \(a*\)\@>a +OK 2 - \(a*\)\@>a +OK 0 - \(a*\)\@>b +OK 1 - \(a*\)\@>b +OK 2 - \(a*\)\@>b +OK 0 - ^\(.\{-}b\)\@>. +OK 1 - ^\(.\{-}b\)\@>. +OK 2 - ^\(.\{-}b\)\@>. +OK 0 - \(.\{-}\)\(\)\@>$ +OK 1 - \(.\{-}\)\(\)\@>$ +OK 2 - \(.\{-}\)\(\)\@>$ +OK 0 - \(a*\)\@>a\|a\+ +OK 2 - \(a*\)\@>a\|a\+ +OK 0 - \_[^8-9]\+ +OK 1 - \_[^8-9]\+ +OK 2 - \_[^8-9]\+ +OK 0 - \_[^a]\+ +OK 1 - \_[^a]\+ +OK 2 - \_[^a]\+ +OK 0 - [0-9a-zA-Z]\{8}-\([0-9a-zA-Z]\{4}-\)\{3}[0-9a-zA-Z]\{12} +OK 1 - [0-9a-zA-Z]\{8}-\([0-9a-zA-Z]\{4}-\)\{3}[0-9a-zA-Z]\{12} +OK 2 - [0-9a-zA-Z]\{8}-\([0-9a-zA-Z]\{4}-\)\{3}[0-9a-zA-Z]\{12} +OK 0 - ^\%(\%(^\s*#\s*if\>\|#\s*if\)\)\(\%>1c.*$\)\@= +OK 1 - ^\%(\%(^\s*#\s*if\>\|#\s*if\)\)\(\%>1c.*$\)\@= +OK 2 - ^\%(\%(^\s*#\s*if\>\|#\s*if\)\)\(\%>1c.*$\)\@= +OK 0 - \%>70vGesamt +OK 1 - \%>70vGesamt +OK 2 - \%>70vGesamt +multi-line tests +OK 0 - ^.\(.\).\_..\1. +OK 1 - ^.\(.\).\_..\1. +OK 2 - ^.\(.\).\_..\1. +OK 0 - \v.*\/(.*)\n.*\/\1$ +OK 1 - \v.*\/(.*)\n.*\/\1$ +OK 2 - \v.*\/(.*)\n.*\/\1$ +OK 0 - \S.*\nx +OK 1 - \S.*\nx +OK 2 - \S.*\nx +OK 0 - \<\(\(25\_[0-5]\|2\_[0-4]\_[0-9]\|\_[01]\?\_[0-9]\_[0-9]\?\)\.\)\{3\}\(25\_[0-5]\|2\_[0-4]\_[0-9]\|\_[01]\?\_[0-9]\_[0-9]\?\)\> +OK 1 - \<\(\(25\_[0-5]\|2\_[0-4]\_[0-9]\|\_[01]\?\_[0-9]\_[0-9]\?\)\.\)\{3\}\(25\_[0-5]\|2\_[0-4]\_[0-9]\|\_[01]\?\_[0-9]\_[0-9]\?\)\> +OK 2 - \<\(\(25\_[0-5]\|2\_[0-4]\_[0-9]\|\_[01]\?\_[0-9]\_[0-9]\?\)\.\)\{3\}\(25\_[0-5]\|2\_[0-4]\_[0-9]\|\_[01]\?\_[0-9]\_[0-9]\?\)\> +OK 0 - a\n^b$\n^c +OK 1 - a\n^b$\n^c +OK 2 - a\n^b$\n^c +OK 0 - \(^.\+\n\)\1 +OK 1 - \(^.\+\n\)\1 +OK 2 - \(^.\+\n\)\1 + +<T="5">Ta 5</Title> +<T="7">Ac 7</Title> + +xxstart3 + +thexE thE thExethe +AndAxAnd AndAxAnd +oooxOfOr fOrOxooo +oooxOfOr fOrOxooo + +asdfhereasdf +asdfagainasdf + +-0- +ffo +bob +__ooooo +koooo__ +moooooo + f__ +ab!babababababfoo +ba!ab##abab?bafoo +**!*****_ + ! xxx?xxxxxxxx xxxx xxxxxx xxxxxxx x xxxxxxxxx xx xxxxxx xxxxxx xxxxx xxxxxxx xx xxxx xxxxxxxx xxxx xxxxxxxxxxx xxx xxxxxxx xxxxxxxxx xx xxxxxx xx xxxxxxx xxxxxxxxxxxxxxxx xxxxxxxxx xxx xxxxxxxx xxxxxxxxx xxxx xxx xxxx xxx xxx xxxxx xxxxxxxxxxxx xxxx xxxxxxxxx xxxxxxxxxxx xx xxxxx xxx xxxxxxxx xxxxxx xxx xxx xxxxxxxxx xxxxxxx x xxxxxxxxx xx xxxxxx xxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxx xxx xxx xxxxxxxx xxxxxxx xxxx xxx xxxxxx xxxxx xxxxx xx xxxxxx xxxxxxx xxx xxxxxxxxxxxx xxxx xxxxxxxxx xxxxxx xxxxxx xxxxx xxx xxxxxxx xxxxxxxxxxxxxxxx xxxxxxxxx xxxxxxxxxx xxxx xx xxxxxxxx xxx xxxxxxxxxxx xxxxx +-1- +ffo +bob +__ooooo +koooo__ +moooooo + f__ +ab!babababababfoo +ba!ab##abab?bafoo +**!*****_ + ! xxx?xxxxxxxx xxxx xxxxxx xxxxxxx x xxxxxxxxx xx xxxxxx xxxxxx xxxxx xxxxxxx xx xxxx xxxxxxxx xxxx xxxxxxxxxxx xxx xxxxxxx xxxxxxxxx xx xxxxxx xx xxxxxxx xxxxxxxxxxxxxxxx xxxxxxxxx xxx xxxxxxxx xxxxxxxxx xxxx xxx xxxx xxx xxx xxxxx xxxxxxxxxxxx xxxx xxxxxxxxx xxxxxxxxxxx xx xxxxx xxx xxxxxxxx xxxxxx xxx xxx xxxxxxxxx xxxxxxx x xxxxxxxxx xx xxxxxx xxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxx xxx xxx xxxxxxxx xxxxxxx xxxx xxx xxxxxx xxxxx xxxxx xx xxxxxx xxxxxxx xxx xxxxxxxxxxxx xxxx xxxxxxxxx xxxxxx xxxxxx xxxxx xxx xxxxxxx xxxxxxxxxxxxxxxx xxxxxxxxx xxxxxxxxxx xxxx xx xxxxxxxx xxx xxxxxxxxxxx xxxxx +-2- +ffo +bob +__ooooo +koooo__ +moooooo + f__ +ab!babababababfoo +ba!ab##abab?bafoo +**!*****_ + ! xxx?xxxxxxxx xxxx xxxxxx xxxxxxx x xxxxxxxxx xx xxxxxx xxxxxx xxxxx xxxxxxx xx xxxx xxxxxxxx xxxx xxxxxxxxxxx xxx xxxxxxx xxxxxxxxx xx xxxxxx xx xxxxxxx xxxxxxxxxxxxxxxx xxxxxxxxx xxx xxxxxxxx xxxxxxxxx xxxx xxx xxxx xxx xxx xxxxx xxxxxxxxxxxx xxxx xxxxxxxxx xxxxxxxxxxx xx xxxxx xxx xxxxxxxx xxxxxx xxx xxx xxxxxxxxx xxxxxxx x xxxxxxxxx xx xxxxxx xxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxx xxx xxx xxxxxxxx xxxxxxx xxxx xxx xxxxxx xxxxx xxxxx xx xxxxxx xxxxxxx xxx xxxxxxxxxxxx xxxx xxxxxxxxx xxxxxx xxxxxx xxxxx xxx xxxxxxx xxxxxxxxxxxxxxxx xxxxxxxxx xxxxxxxxxx xxxx xx xxxxxxxx xxx xxxxxxxxxxx xxxxx +Test +Test END +EN +E +E888 detected for \ze* +E888 detected for \zs* diff --git a/src/testdir/test69.in b/src/testdir/test69.in new file mode 100644 index 0000000..2510c12 --- /dev/null +++ b/src/testdir/test69.in @@ -0,0 +1,192 @@ +Test for multi-byte text formatting. +Also test, that 'mps' with multibyte chars works. +And test "ra" on multi-byte characters. +Also test byteidx() and byteidxcomp() + +STARTTEST +:so mbyte.vim +:set encoding=utf-8 +ENDTEST + +Results of test69: + +STARTTEST +/^{/+1 +:set tw=2 fo=t +gqgqjgqgqo +XYZ +abc XYZ +ENDTEST + +{ +XYZ +abc XYZ +} + +STARTTEST +/^{/+1 +:set tw=1 fo=tm +gqgqjgqgqjgqgqjgqgqjgqgqo +X +Xa +X a +XY +X Y +ENDTEST + +{ +X +Xa +X a +XY +X Y +} + +STARTTEST +/^{/+1 +:set tw=2 fo=tm +gqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqo +X +Xa +X a +XY +X Y +aX +abX +abcX +abX c +abXY +ENDTEST + +{ +X +Xa +X a +XY +X Y +aX +abX +abcX +abX c +abXY +} + +STARTTEST +/^{/+1 +:set ai tw=2 fo=tm +gqgqjgqgqo +X +Xa +ENDTEST + +{ + X + Xa +} + +STARTTEST +/^{/+1 +:set noai tw=2 fo=tm +gqgqjgqgqo + X + Xa +ENDTEST + +{ + X + Xa +} + +STARTTEST +/^{/+1 +:set tw=2 fo=cqm comments=n:X +gqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqo +X +Xa +XaY +XY +XYZ +X Y +X YZ +XX +XXa +XXY +ENDTEST + +{ +X +Xa +XaY +XY +XYZ +X Y +X YZ +XX +XXa +XXY +} + +STARTTEST +/^{/+1 +:set tw=2 fo=tm +RXa +ENDTEST + +{ + +} + +STARTTEST +/^{/+1 +:set mps+=u2018:u2019 +d% +ENDTEST + +{ +‘ two three ’ four +} +STARTTEST +/^ra test +jVjra +ENDTEST + +ra test +abba +aab + +STARTTEST +:set whichwrap+=h +/^x +dh +:set whichwrap-=h +ENDTEST + +á +x + +STARTTEST +:let a = '.é.' " one char of two bytes +:let b = '.é.' " normal e with composing char +/^byteidx +:put =string([byteidx(a, 0), byteidx(a, 1), byteidx(a, 2), byteidx(a, 3), byteidx(a, 4)]) +:put =string([byteidx(b, 0), byteidx(b, 1), byteidx(b, 2), byteidx(b, 3), byteidx(b, 4)]) +/^byteidxcomp +:put =string([byteidxcomp(a, 0), byteidxcomp(a, 1), byteidxcomp(a, 2), byteidxcomp(a, 3), byteidxcomp(a, 4)]) +:let b = '.é.' +:put =string([byteidxcomp(b, 0), byteidxcomp(b, 1), byteidxcomp(b, 2), byteidxcomp(b, 3), byteidxcomp(b, 4), byteidxcomp(b, 5)]) +ENDTEST + +byteidx +byteidxcomp + +STARTTEST +/^substitute +:let y = substitute('123', '\zs', 'a', 'g') | put =y +ENDTEST + +substitute + +STARTTEST +:g/^STARTTEST/.,/^ENDTEST/d +:1;/^Results/,$wq! test.out +ENDTEST diff --git a/src/testdir/test69.ok b/src/testdir/test69.ok new file mode 100644 index 0000000..af8befb --- /dev/null +++ b/src/testdir/test69.ok @@ -0,0 +1,166 @@ +Results of test69: + + +{ +XYZ +abc +XYZ + +XYZ +abc +XYZ +} + + +{ +X +X +a +X +a +X +Y +X +Y + +X +X +a +X +a +X +Y +X +Y +} + + +{ +X +X +a +X +a +X +Y +X +Y +a +X +ab +X +abc +X +ab +X +c +ab +X +Y + +X +X +a +X +a +X +Y +X +Y +a +X +ab +X +abc +X +ab +X +c +ab +X +Y +} + + +{ + X + X + a + + X + X + a +} + + +{ + X + X +a + + X + X +a +} + + +{ +X +Xa +Xa +XY +XY +XY +XZ +X Y +X Y +X Z +XX +XXa +XXY + +X +Xa +Xa +XY +XY +XY +XZ +X Y +X Y +X Z +XX +XXa +XXY +} + + +{ +X +a +} + + +{ + four +} + +ra test +aaaa +aaa + + +áx + + +byteidx +[0, 1, 3, 4, -1] +[0, 1, 4, 5, -1] +byteidxcomp +[0, 1, 3, 4, -1] +[0, 1, 2, 4, 5, -1] + + +substitute +a1a2a3a + diff --git a/src/testdir/test70.in b/src/testdir/test70.in new file mode 100644 index 0000000..9fbe818 --- /dev/null +++ b/src/testdir/test70.in @@ -0,0 +1,63 @@ +Smoke test for MzScheme interface and mzeval() function + +STARTTEST +:so mzscheme.vim +:set nocompatible viminfo+=nviminfo +:function! MzRequire() +:redir => l:mzversion +:mz (version) +:redir END +:if strpart(l:mzversion, 1, 1) < "4" +:" MzScheme versions < 4.x: +:mz (require (prefix vim- vimext)) +:else +:" newer versions: +:mz (require (prefix-in vim- 'vimext)) +:mz (require r5rs) +:endif +:endfunction +:silent call MzRequire() +:mz (define l '("item0" "dictionary with list OK" "item2")) +:mz (define h (make-hash)) +:mz (hash-set! h "list" l) +/^1 +:" change buffer contents +:mz (vim-set-buff-line (vim-eval "line('.')") "1 changed line 1") +:" scalar test +:let tmp_string = mzeval('"string"') +:let tmp_1000 = mzeval('1000') +:if tmp_string . tmp_1000 == "string1000" +:let scalar_res = "OK" +:else +:let scalar_res = "FAILED" +:endif +:call append(search("^1"), "scalar test " . scalar_res) +:" dictionary containing a list +:let tmp = mzeval("h")["list"][1] +:/^2/put =tmp +:" circular list (at the same time test lists containing lists) +:mz (set-car! (cddr l) l) +:let l2 = mzeval("h")["list"] +:if l2[2] == l2 +:let res = "OK" +:else +:let res = "FAILED: " . l2[2] +:endif +:call setline(search("^3"), "circular test " . res) +:" funcrefs +:mz (define vim:max (vim-eval "function('max')")) +:mz (define m (vim:max '(1 100 8))) +:let m = mzeval('m') +:if m == 100 +:let fref_res = "OK" +:else +:let fref_res = "FAILED: " . m +:end +:call append(line('$'), 'funcrefs '. fref_res) +:?^1?,$w! test.out +:qa! +ENDTEST + +1 line 1 +2 line 2 +3 line 3 diff --git a/src/testdir/test70.ok b/src/testdir/test70.ok new file mode 100644 index 0000000..9c82a86 --- /dev/null +++ b/src/testdir/test70.ok @@ -0,0 +1,6 @@ +1 changed line 1 +scalar test OK +2 line 2 +dictionary with list OK +circular test OK +funcrefs OK diff --git a/src/testdir/test72.in b/src/testdir/test72.in new file mode 100644 index 0000000..961df4c --- /dev/null +++ b/src/testdir/test72.in @@ -0,0 +1,146 @@ +Tests for undo file. +Since this script is sourced we need to explicitly break changes up in +undo-able pieces. Do that by setting 'undolevels'. + +STARTTEST +:so small.vim +:set belloff=all +:" +:" Test 'undofile': first a simple one-line change. +:set nocompatible viminfo+=nviminfo visualbell +:set ul=100 undofile nomore +:e! Xtestfile +ggdGithis is one line:set ul=100 +:s/one/ONE/ +:set ul=100 +:w +:bwipe! +:e Xtestfile +u:.w! test.out +:" +:" Test 'undofile', change in original file fails check +:set noundofile +:e! Xtestfile +:s/line/Line/ +:w +:set undofile +:bwipe! +:e Xtestfile +u:.w >>test.out +:" +:" Test 'undofile', add 10 lines, delete 6 lines, undo 3 +:set undofile +ggdGione +two +three +four +five +six +seven +eight +nine +ten:set ul=100 +3Gdd:set ul=100 +dd:set ul=100 +dd:set ul=100 +dd:set ul=100 +dd:set ul=100 +dd:set ul=100 +:w +:bwipe! +:e Xtestfile +uuu:w >>test.out +:" +:" Test that reading the undofiles when setting undofile works +:set noundofile ul=0 +i +u:e! Xtestfile +:set undofile ul=100 +uuuuuu:w >>test.out +:" And now with encryption, cryptmethod=zip +:e! Xtestfile +:set undofile cm=zip +ggdGimonday +tuesday +wednesday +thursday +friday:set ul=100 +kkkdd:set ul=100 +dd:set ul=100 +dd:set ul=100 +:X +foobar +foobar +:w! +:bwipe! +:e Xtestfile +foobar +:set key= +uu:w >>test.out +:" +:" +:" With encryption, cryptmethod=blowfish +:e! Xtestfile +rubbish +:set undofile cm=blowfish ff& +ggdGijan +feb +mar +apr +jun:set ul=100 +kk0ifoo :set ul=100 +dd:set ul=100 +ibar :set ul=100 +:X +foobar +foobar +:w! +:bwipe! +:e Xtestfile +foobar +:set key= +/bar +:.w >>test.out +u:.w >>test.out +u:.w >>test.out +u:.w >>test.out +:" +:" With encryption, cryptmethod=blowfish2 +:e! Xtestfile +rubbish +:set undofile cm=blowfish2 ff& +ggdGijan +feb +mar +apr +jun:set ul=100 +kk0ifoo :set ul=100 +dd:set ul=100 +ibar :set ul=100 +:X +foo2bar +foo2bar +:w! +:bwipe! +:e Xtestfile +foo2bar +:set key= +/bar +:.w >>test.out +u:.w >>test.out +u:.w >>test.out +u:.w >>test.out +:" +:" Rename the undo file so that it gets cleaned up. +:if has("vms") +: call rename("_un_Xtestfile", "Xtestundo") +:else +: call rename(".Xtestfile.un~", "Xtestundo") +:endif +:qa! +ENDTEST + +1111 ----- +2222 ----- + +123456789 diff --git a/src/testdir/test72.ok b/src/testdir/test72.ok new file mode 100644 index 0000000..8d30ba1 --- /dev/null +++ b/src/testdir/test72.ok @@ -0,0 +1,31 @@ +this is one line +this is ONE Line +one +two +six +seven +eight +nine +ten +one +two +three +four +five +six +seven +eight +nine +ten +monday +wednesday +thursday +friday +bar apr +apr +foo mar +mar +bar apr +apr +foo mar +mar diff --git a/src/testdir/test77a.com b/src/testdir/test77a.com new file mode 100644 index 0000000..ef74a4c --- /dev/null +++ b/src/testdir/test77a.com @@ -0,0 +1,8 @@ +$! test77a - help file creating checksum on VMS +$! Created by Zoltan Arpadffy +$ +$ IF P1 .NES. "" +$ THEN +$ checksum 'P1' +$ show symb CHECKSUM$CHECKSUM +$ ENDIF diff --git a/src/testdir/test77a.in b/src/testdir/test77a.in new file mode 100644 index 0000000..052e29a --- /dev/null +++ b/src/testdir/test77a.in @@ -0,0 +1,31 @@ +Inserts 2 million lines with consecutive integers starting from 1 +(essentially, the output of GNU's seq 1 2000000), writes them to Xtest +and writes its cksum to test.out. + +We need 2 million lines to trigger a call to mf_hash_grow(). If it would mess +up the lines the checksum would differ. + +cksum is part of POSIX and so should be available on most Unixes. +If it isn't available then the test will be skipped. + +VMS does not have CKSUM but has a built in CHECKSUM - it should be used +STARTTEST +:so small.vim +:if !has("vms") +: e! test.ok +: w! test.out +: qa! +:endif +:set fileformat=unix undolevels=-1 +ggdG +:let i = 1 +:while i <= 2000000 | call append(i, range(i, i + 99)) | let i += 100 | endwhile +ggdd +:w! Xtest. +:r !@test77a.com Xtest. +:s/\s/ /g +:set fileformat& +:.w! test.out +:qa! +ENDTEST + diff --git a/src/testdir/test77a.ok b/src/testdir/test77a.ok new file mode 100644 index 0000000..41ec157 --- /dev/null +++ b/src/testdir/test77a.ok @@ -0,0 +1 @@ + CHECKSUM$CHECKSUM = "844110470" diff --git a/src/testdir/test83-tags2 b/src/testdir/test83-tags2 new file mode 100644 index 0000000..7f9f21b --- /dev/null +++ b/src/testdir/test83-tags2 @@ -0,0 +1,2 @@ +!_TAG_FILE_ENCODING cp932 // +`ab Xtags2.txt /`ab diff --git a/src/testdir/test83-tags3 b/src/testdir/test83-tags3 new file mode 100644 index 0000000..0cb6591 --- /dev/null +++ b/src/testdir/test83-tags3 @@ -0,0 +1,102 @@ +!_TAG_FILE_SORTED 1 // +!_TAG_FILE_ENCODING cp932 // +abc1 Xtags3.txt /`ab +abc2 Xtags3.txt /`ab +abc3 Xtags3.txt /`ab +abc4 Xtags3.txt /`ab +abc5 Xtags3.txt /`ab +abc6 Xtags3.txt /`ab +abc7 Xtags3.txt /`ab +abc8 Xtags3.txt /`ab +abc9 Xtags3.txt /`ab +abc10 Xtags3.txt /`ab +abc11 Xtags3.txt /`ab +abc12 Xtags3.txt /`ab +abc13 Xtags3.txt /`ab +abc14 Xtags3.txt /`ab +abc15 Xtags3.txt /`ab +abc16 Xtags3.txt /`ab +abc17 Xtags3.txt /`ab +abc18 Xtags3.txt /`ab +abc19 Xtags3.txt /`ab +abc20 Xtags3.txt /`ab +abc21 Xtags3.txt /`ab +abc22 Xtags3.txt /`ab +abc23 Xtags3.txt /`ab +abc24 Xtags3.txt /`ab +abc25 Xtags3.txt /`ab +abc26 Xtags3.txt /`ab +abc27 Xtags3.txt /`ab +abc28 Xtags3.txt /`ab +abc29 Xtags3.txt /`ab +abc30 Xtags3.txt /`ab +abc31 Xtags3.txt /`ab +abc32 Xtags3.txt /`ab +abc33 Xtags3.txt /`ab +abc34 Xtags3.txt /`ab +abc35 Xtags3.txt /`ab +abc36 Xtags3.txt /`ab +abc37 Xtags3.txt /`ab +abc38 Xtags3.txt /`ab +abc39 Xtags3.txt /`ab +abc40 Xtags3.txt /`ab +abc41 Xtags3.txt /`ab +abc42 Xtags3.txt /`ab +abc43 Xtags3.txt /`ab +abc44 Xtags3.txt /`ab +abc45 Xtags3.txt /`ab +abc46 Xtags3.txt /`ab +abc47 Xtags3.txt /`ab +abc48 Xtags3.txt /`ab +abc49 Xtags3.txt /`ab +abc50 Xtags3.txt /`ab +abc51 Xtags3.txt /`ab +abc52 Xtags3.txt /`ab +abc53 Xtags3.txt /`ab +abc54 Xtags3.txt /`ab +abc55 Xtags3.txt /`ab +abc56 Xtags3.txt /`ab +abc57 Xtags3.txt /`ab +abc58 Xtags3.txt /`ab +abc59 Xtags3.txt /`ab +abc60 Xtags3.txt /`ab +abc61 Xtags3.txt /`ab +abc62 Xtags3.txt /`ab +abc63 Xtags3.txt /`ab +abc64 Xtags3.txt /`ab +abc65 Xtags3.txt /`ab +abc66 Xtags3.txt /`ab +abc67 Xtags3.txt /`ab +abc68 Xtags3.txt /`ab +abc69 Xtags3.txt /`ab +abc70 Xtags3.txt /`ab +abc71 Xtags3.txt /`ab +abc72 Xtags3.txt /`ab +abc73 Xtags3.txt /`ab +abc74 Xtags3.txt /`ab +abc75 Xtags3.txt /`ab +abc76 Xtags3.txt /`ab +abc77 Xtags3.txt /`ab +abc78 Xtags3.txt /`ab +abc79 Xtags3.txt /`ab +abc80 Xtags3.txt /`ab +abc81 Xtags3.txt /`ab +abc82 Xtags3.txt /`ab +abc83 Xtags3.txt /`ab +abc84 Xtags3.txt /`ab +abc85 Xtags3.txt /`ab +abc86 Xtags3.txt /`ab +abc87 Xtags3.txt /`ab +abc88 Xtags3.txt /`ab +abc89 Xtags3.txt /`ab +abc90 Xtags3.txt /`ab +abc91 Xtags3.txt /`ab +abc92 Xtags3.txt /`ab +abc93 Xtags3.txt /`ab +abc94 Xtags3.txt /`ab +abc95 Xtags3.txt /`ab +abc96 Xtags3.txt /`ab +abc97 Xtags3.txt /`ab +abc98 Xtags3.txt /`ab +abc99 Xtags3.txt /`ab +abc100 Xtags3.txt /`ab diff --git a/src/testdir/test85.ok b/src/testdir/test85.ok new file mode 100644 index 0000000..4753483 --- /dev/null +++ b/src/testdir/test85.ok @@ -0,0 +1,7 @@ +1 changed line 1 +scalar test OK +2 line 2 +dictionary with list OK +circular test OK +[123.0, 'abc', [1, 2, 3], {'a': 1, 'b': 2, 'c': 3}] +{'4': 123.0, '5': 'abc', '6': [1, 2, 3], '7': {'a': 1, 'b': 2, 'c': 3}} diff --git a/src/testdir/test86.in b/src/testdir/test86.in new file mode 100644 index 0000000..71dd9f1 --- /dev/null +++ b/src/testdir/test86.in @@ -0,0 +1,1711 @@ +Tests for various python features. vim: set ft=vim : + +NOTE: This will cause errors when run under valgrind. +This would require recompiling Python with: + ./configure --without-pymalloc +See http://svn.python.org/view/python/trunk/Misc/README.valgrind?view=markup + +STARTTEST +:so small.vim +:set encoding=latin1 +:set noswapfile +:if !has('python') | e! test.ok | wq! test.out | endif +:lang C +:fun Test() +:py import vim +:py cb = vim.current.buffer +:let l = [] +:py l=vim.bindeval('l') +:py f=vim.bindeval('function("strlen")') +:" Extending List directly with different types +:py l.extend([1, "as'd", [1, 2, f, {'a': 1}]]) +:$put =string(l) +:$put =string(l[-1]) +:try +: $put =string(l[-4]) +:catch +: $put =v:exception[:13] +:endtry +:" List assignment +:py l[0]=0 +:$put =string(l) +:py l[-2]=f +:$put =string(l) +:" +:" Extending Dictionary directly with different types +:let d = {} +:fun d.f() +: return 1 +:endfun +py << EOF +d=vim.bindeval('d') +d['1']='asd' +d.update() # Must not do anything, including throwing errors +d.update(b=[1, 2, f]) +d.update((('-1', {'a': 1}),)) +d.update({'0': -1}) +dk = d.keys() +dv = d.values() +di = d.items() +cmpfun = lambda a, b: cmp(repr(a), repr(b)) +dk.sort(cmpfun) +dv.sort(cmpfun) +di.sort(cmpfun) +EOF +:$put =pyeval('d[''f''](self={})') +:$put =pyeval('repr(dk)') +:$put =substitute(pyeval('repr(dv)'),'0x\x\+','','g') +:$put =substitute(pyeval('repr(di)'),'0x\x\+','','g') +:for [key, Val] in sort(items(d)) +: $put =string(key) . ' : ' . string(Val) +: unlet key Val +:endfor +:py del dk +:py del di +:py del dv +:" +:" removing items with del +:py del l[2] +:$put =string(l) +:let l = range(8) +:py l=vim.bindeval('l') +:try +: py del l[:3] +: py del l[1:] +:catch +: $put =v:exception +:endtry +:$put =string(l) +:" +:py del d['-1'] +:py del d['f'] +:$put =string(pyeval('d.get(''b'', 1)')) +:$put =string(pyeval('d.pop(''b'')')) +:$put =string(pyeval('d.get(''b'', 1)')) +:$put =string(pyeval('d.pop(''1'', 2)')) +:$put =string(pyeval('d.pop(''1'', 2)')) +:$put =pyeval('repr(d.has_key(''0''))') +:$put =pyeval('repr(d.has_key(''1''))') +:$put =pyeval('repr(''0'' in d)') +:$put =pyeval('repr(''1'' in d)') +:$put =pyeval('repr(list(iter(d)))') +:$put =string(d) +:$put =pyeval('repr(d.popitem())') +:$put =pyeval('repr(d.get(''0''))') +:$put =pyeval('repr(list(iter(d)))') +:" +:" removing items out of range: silently skip items that don't exist +:let l = [0, 1, 2, 3] +:py l=vim.bindeval('l') +:" The following two ranges delete nothing as they match empty list: +:py del l[2:1] +:$put =string(l) +:py del l[2:2] +:$put =string(l) +:py del l[2:3] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py l=vim.bindeval('l') +:py del l[2:4] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py l=vim.bindeval('l') +:py del l[2:5] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py l=vim.bindeval('l') +:py del l[2:6] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py l=vim.bindeval('l') +:" The following two ranges delete nothing as they match empty list: +:py del l[-1:2] +:$put =string(l) +:py del l[-2:2] +:$put =string(l) +:py del l[-3:2] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py l=vim.bindeval('l') +:py del l[-4:2] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py l=vim.bindeval('l') +:py del l[-5:2] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py l=vim.bindeval('l') +:py del l[-6:2] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py l=vim.bindeval('l') +:py del l[::2] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py l=vim.bindeval('l') +:py del l[3:0:-2] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py l=vim.bindeval('l') +:py del l[2:4:-2] +:$put =string(l) +:" +:" Slice assignment to a list +:let l = [0, 1, 2, 3] +:py l=vim.bindeval('l') +:py l[0:0]=['a'] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py l=vim.bindeval('l') +:py l[1:2]=['b'] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py l=vim.bindeval('l') +:py l[2:4]=['c'] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py l=vim.bindeval('l') +:py l[4:4]=['d'] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py l=vim.bindeval('l') +:py l[-1:2]=['e'] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py l=vim.bindeval('l') +:py l[-10:2]=['f'] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py l=vim.bindeval('l') +:py l[2:-10]=['g'] +:$put =string(l) +:let l = [] +:py l=vim.bindeval('l') +:py l[0:0]=['h'] +:$put =string(l) +:let l = range(8) +:py l=vim.bindeval('l') +:py l[2:6:2] = [10, 20] +:$put =string(l) +:let l = range(8) +:py l=vim.bindeval('l') +:py l[6:2:-2] = [10, 20] +:$put =string(l) +:let l = range(8) +:py l=vim.bindeval('l') +:py l[6:2] = () +:$put =string(l) +:let l = range(8) +:py l=vim.bindeval('l') +:py l[6:2:1] = () +:$put =string(l) +:let l = range(8) +:py l=vim.bindeval('l') +:py l[2:2:1] = () +:$put =string(l) +:" +:" Locked variables +:let l = [0, 1, 2, 3] +:py l=vim.bindeval('l') +:lockvar! l +py << EOF +def emsg(ei): + return ei[0].__name__ + ':' + repr(ei[1].args) + +try: + l[2]='i' +except vim.error: + cb.append('l[2] threw vim.error: ' + emsg(sys.exc_info())) +EOF +:$put =string(l) +:unlockvar! l +:" +:" Function calls +py << EOF +import sys +def ee(expr, g=globals(), l=locals()): + try: + exec(expr, g, l) + except: + ei = sys.exc_info() + msg = emsg(ei) + msg = msg.replace('TypeError:(\'argument 1 ', 'TypeError:(\'') + if expr.find('None') > -1: + msg = msg.replace('TypeError:(\'iteration over non-sequence\',)', + 'TypeError:("\'NoneType\' object is not iterable",)') + if expr.find('FailingNumber') > -1: + msg = msg.replace(', not \'FailingNumber\'', '').replace('"', '\'') + msg = msg.replace('TypeError:(\'iteration over non-sequence\',)', + 'TypeError:("\'FailingNumber\' object is not iterable",)') + if msg.find('(\'\'') > -1 or msg.find('(\'can\'t') > -1: + msg = msg.replace('(\'', '("').replace('\',)', '",)') + # Some Python versions say can't, others cannot. + if msg.find('can\'t') > -1: + msg = msg.replace('can\'t', 'cannot') + # Some Python versions use single quote, some double quote + if msg.find('"cannot ') > -1: + msg = msg.replace('"cannot ', '\'cannot ') + if msg.find(' attributes"') > -1: + msg = msg.replace(' attributes"', ' attributes\'') + if expr == 'fd(self=[])': + # HACK: PyMapping_Check changed meaning + msg = msg.replace('AttributeError:(\'keys\',)', + 'TypeError:(\'unable to convert list to vim dictionary\',)') + vim.current.buffer.append(expr + ':' + msg) + else: + vim.current.buffer.append(expr + ':NOT FAILED') +EOF +:fun New(...) +: return ['NewStart']+a:000+['NewEnd'] +:endfun +:fun DictNew(...) dict +: return ['DictNewStart']+a:000+['DictNewEnd', self] +:endfun +:let l=[function('New'), function('DictNew')] +:py l=vim.bindeval('l') +:py l.extend(list(l[0](1, 2, 3))) +:$put =string(l) +:py l.extend(list(l[1](1, 2, 3, self={'a': 'b'}))) +:$put =string(l) +:py l.extend([l[0].name]) +:$put =string(l) +:py ee('l[1](1, 2, 3)') +:py f=l[0] +:delfunction New +:py ee('f(1, 2, 3)') +:if has('float') +: let l=[0.0] +: py l=vim.bindeval('l') +: py l.extend([0.0]) +: $put =string(l) +:else +: $put ='[0.0, 0.0]' +:endif +:let messages=[] +:delfunction DictNew +py <<EOF +d=vim.bindeval('{}') +m=vim.bindeval('messages') +def em(expr, g=globals(), l=locals()): + try: + exec(expr, g, l) + except: + m.extend([sys.exc_type.__name__]) + +em('d["abc1"]') +em('d["abc1"]="\\0"') +em('d["abc1"]=vim') +em('d[""]=1') +em('d["a\\0b"]=1') +em('d[u"a\\0b"]=1') + +em('d.pop("abc1")') +em('d.popitem()') +del em +del m +EOF +:$put =messages +:unlet messages +:" locked and scope attributes +:let d={} | let dl={} | lockvar dl +:for s in split("d dl v: g:") +: let name=tr(s, ':', 's') +: execute 'py '.name.'=vim.bindeval("'.s.'")' +: let toput=s.' : '.join(map(['locked', 'scope'], 'v:val.":".pyeval(name.".".v:val)'), ';') +: $put =toput +:endfor +:silent! let d.abc2=1 +:silent! let dl.abc3=1 +:py d.locked=True +:py dl.locked=False +:silent! let d.def=1 +:silent! let dl.def=1 +:put ='d:'.string(d) +:put ='dl:'.string(dl) +:unlet d dl +: +:let l=[] | let ll=[] | lockvar ll +:for s in split("l ll") +: let name=tr(s, ':', 's') +: execute 'py '.name.'=vim.bindeval("'.s.'")' +: let toput=s.' : locked:'.pyeval(name.'.locked') +: $put =toput +:endfor +:silent! call extend(l, [0]) +:silent! call extend(ll, [0]) +:py l.locked=True +:py ll.locked=False +:silent! call extend(l, [1]) +:silent! call extend(ll, [1]) +:put ='l:'.string(l) +:put ='ll:'.string(ll) +:unlet l ll +:" +:" pyeval() +:let l=pyeval('range(3)') +:$put =string(l) +:let d=pyeval('{"a": "b", "c": 1, "d": ["e"]}') +:$put =sort(items(d)) +:let v:errmsg = '' +:$put ='pyeval(\"None\") = ' . pyeval('None') . v:errmsg +:if has('float') +: let f=pyeval('0.0') +: $put =string(f) +:else +: $put ='0.0' +:endif +:" Invalid values: +:for e in ['"\0"', '{"\0": 1}', 'undefined_name', 'vim'] +: try +: let v=pyeval(e) +: catch +: let toput=e.":\t".v:exception[:13] +: $put =toput +: endtry +:endfor +:" +:" threading +:let l = [0] +:py l=vim.bindeval('l') +py <<EOF +import threading +import time + +class T(threading.Thread): + def __init__(self): + threading.Thread.__init__(self) + self.t = 0 + self.running = True + + def run(self): + while self.running: + self.t += 1 + time.sleep(0.1) + +t = T() +del T +t.start() +EOF +:sleep 1 +:py t.running = False +:py t.join() +:" Check if the background thread is working. Count should be 10, but on a +:" busy system (AppVeyor) it can be much lower. +:py l[0] = t.t > 4 +:py del time +:py del threading +:py del t +:$put =string(l) +:" +:" settrace +:let l = [] +:py l=vim.bindeval('l') +py <<EOF +import sys + +def traceit(frame, event, arg): + global l + if event == "line": + l.extend([frame.f_lineno]) + return traceit + +def trace_main(): + for i in range(5): + pass +EOF +:py sys.settrace(traceit) +:py trace_main() +:py sys.settrace(None) +:py del traceit +:py del trace_main +:$put =string(l) +:" +:" Slice +:py ll = vim.bindeval('[0, 1, 2, 3, 4, 5]') +:py l = ll[:4] +:$put =string(pyeval('l')) +:py l = ll[2:] +:$put =string(pyeval('l')) +:py l = ll[:-4] +:$put =string(pyeval('l')) +:py l = ll[-2:] +:$put =string(pyeval('l')) +:py l = ll[2:4] +:$put =string(pyeval('l')) +:py l = ll[4:2] +:$put =string(pyeval('l')) +:py l = ll[-4:-2] +:$put =string(pyeval('l')) +:py l = ll[-2:-4] +:$put =string(pyeval('l')) +:py l = ll[:] +:$put =string(pyeval('l')) +:py l = ll[0:6] +:$put =string(pyeval('l')) +:py l = ll[-10:10] +:$put =string(pyeval('l')) +:py l = ll[4:2:-1] +:$put =string(pyeval('l')) +:py l = ll[::2] +:$put =string(pyeval('l')) +:py l = ll[4:2:1] +:$put =string(pyeval('l')) +:py del l +:" +:" Vars +:let g:foo = 'bac' +:let w:abc3 = 'def' +:let b:baz = 'bar' +:let t:bar = 'jkl' +:try +: throw "Abc" +:catch +: put =pyeval('vim.vvars[''exception'']') +:endtry +:put =pyeval('vim.vars[''foo'']') +:put =pyeval('vim.current.window.vars[''abc3'']') +:put =pyeval('vim.current.buffer.vars[''baz'']') +:put =pyeval('vim.current.tabpage.vars[''bar'']') +:" +:" Options +:" paste: boolean, global +:" previewheight number, global +:" operatorfunc: string, global +:" number: boolean, window-local +:" numberwidth: number, window-local +:" colorcolumn: string, window-local +:" statusline: string, window-local/global +:" autoindent: boolean, buffer-local +:" shiftwidth: number, buffer-local +:" omnifunc: string, buffer-local +:" preserveindent: boolean, buffer-local/global +:" path: string, buffer-local/global +:let g:bufs=[bufnr('%')] +:new +:let g:bufs+=[bufnr('%')] +:vnew +:let g:bufs+=[bufnr('%')] +:wincmd j +:vnew +:let g:bufs+=[bufnr('%')] +:wincmd l +:fun RecVars(opt) +: let gval =string(eval('&g:'.a:opt)) +: let wvals=join(map(range(1, 4), 'v:val.":".string(getwinvar(v:val, "&".a:opt))')) +: let bvals=join(map(copy(g:bufs), 'v:val.":".string(getbufvar(v:val, "&".a:opt))')) +: put =' G: '.gval +: put =' W: '.wvals +: put =' B: '.wvals +:endfun +py << EOF +def e(s, g=globals(), l=locals()): + try: + exec(s, g, l) + except: + vim.command('return ' + repr(sys.exc_type.__name__)) + +def ev(s, g=globals(), l=locals()): + try: + return eval(s, g, l) + except: + vim.command('let exc=' + repr(sys.exc_type.__name__)) + return 0 +EOF +:fun E(s) +: python e(vim.eval('a:s')) +:endfun +:fun Ev(s) +: let r=pyeval('ev(vim.eval("a:s"))') +: if exists('exc') +: throw exc +: endif +: return r +:endfun +:py gopts1=vim.options +:py wopts1=vim.windows[2].options +:py wopts2=vim.windows[0].options +:py wopts3=vim.windows[1].options +:py bopts1=vim.buffers[vim.bindeval("g:bufs")[2]].options +:py bopts2=vim.buffers[vim.bindeval("g:bufs")[1]].options +:py bopts3=vim.buffers[vim.bindeval("g:bufs")[0]].options +:$put ='wopts iters equal: '.pyeval('list(wopts1) == list(wopts2)') +:$put ='bopts iters equal: '.pyeval('list(bopts1) == list(bopts2)') +:py gset=set(iter(gopts1)) +:py wset=set(iter(wopts1)) +:py bset=set(iter(bopts1)) +:set path=.,..,, +:let lst=[] +:let lst+=[['paste', 1, 0, 1, 2, 1, 1, 0 ]] +:let lst+=[['previewheight', 5, 1, 6, 'a', 0, 1, 0 ]] +:let lst+=[['operatorfunc', 'A', 'B', 'C', 2, 0, 1, 0 ]] +:let lst+=[['number', 0, 1, 1, 0, 1, 0, 1 ]] +:let lst+=[['numberwidth', 2, 3, 5, -100, 0, 0, 1 ]] +:let lst+=[['colorcolumn', '+1', '+2', '+3', 'abc4', 0, 0, 1 ]] +:let lst+=[['statusline', '1', '2', '4', 0, 0, 1, 1 ]] +:let lst+=[['autoindent', 0, 1, 1, 2, 1, 0, 2 ]] +:let lst+=[['shiftwidth', 0, 2, 1, 3, 0, 0, 2 ]] +:let lst+=[['omnifunc', 'A', 'B', 'C', 1, 0, 0, 2 ]] +:let lst+=[['preserveindent', 0, 1, 1, 2, 1, 1, 2 ]] +:let lst+=[['path', '.,,', ',,', '.', 0, 0, 1, 2 ]] +:for [oname, oval1, oval2, oval3, invval, bool, global, local] in lst +: py oname=vim.eval('oname') +: py oval1=vim.bindeval('oval1') +: py oval2=vim.bindeval('oval2') +: py oval3=vim.bindeval('oval3') +: if invval is 0 || invval is 1 +: py invval=bool(vim.bindeval('invval')) +: else +: py invval=vim.bindeval('invval') +: endif +: if bool +: py oval1=bool(oval1) +: py oval2=bool(oval2) +: py oval3=bool(oval3) +: endif +: put ='>>> '.oname +: $put =' g/w/b:'.pyeval('oname in gset').'/'.pyeval('oname in wset').'/'.pyeval('oname in bset') +: $put =' g/w/b (in):'.pyeval('oname in gopts1').'/'.pyeval('oname in wopts1').'/'.pyeval('oname in bopts1') +: for v in ['gopts1', 'wopts1', 'bopts1'] +: try +: put =' p/'.v.': '.Ev('repr('.v.'['''.oname.'''])') +: catch +: put =' p/'.v.'! '.v:exception +: endtry +: let r=E(v.'['''.oname.''']=invval') +: if r isnot 0 +: put =' inv: '.string(invval).'! '.r +: endif +: for vv in (v is# 'gopts1' ? [v] : [v, v[:-2].'2', v[:-2].'3']) +: let val=substitute(vv, '^.opts', 'oval', '') +: let r=E(vv.'['''.oname.''']='.val) +: if r isnot 0 +: put =' '.vv.'! '.r +: endif +: endfor +: endfor +: call RecVars(oname) +: for v in ['wopts3', 'bopts3'] +: let r=E('del '.v.'["'.oname.'"]') +: if r isnot 0 +: put =' del '.v.'! '.r +: endif +: endfor +: call RecVars(oname) +:endfor +:delfunction RecVars +:delfunction E +:delfunction Ev +:py del ev +:py del e +:only +:for buf in g:bufs[1:] +: execute 'bwipeout!' buf +:endfor +:py del gopts1 +:py del wopts1 +:py del wopts2 +:py del wopts3 +:py del bopts1 +:py del bopts2 +:py del bopts3 +:py del oval1 +:py del oval2 +:py del oval3 +:py del oname +:py del invval +:" +:" Test buffer object +:vnew +:put ='First line' +:put ='Second line' +:put ='Third line' +:1 delete _ +:py b=vim.current.buffer +:wincmd w +:mark a +:augroup BUFS +: autocmd BufFilePost * python cb.append(vim.eval('expand("<abuf>")') + ':BufFilePost:' + vim.eval('bufnr("%")')) +: autocmd BufFilePre * python cb.append(vim.eval('expand("<abuf>")') + ':BufFilePre:' + vim.eval('bufnr("%")')) +:augroup END +py << EOF +# Tests BufferAppend and BufferItem +cb.append(b[0]) +# Tests BufferSlice and BufferAssSlice +cb.append('abc5') # Will be overwritten +cb[-1:] = b[:-2] +# Test BufferLength and BufferAssSlice +cb.append('def') # Will not be overwritten +cb[len(cb):] = b[:] +# Test BufferAssItem and BufferMark +cb.append('ghi') # Will be overwritten +cb[-1] = repr((len(cb) - cb.mark('a')[0], cb.mark('a')[1])) +# Test BufferRepr +cb.append(repr(cb) + repr(b)) +# Modify foreign buffer +b.append('foo') +b[0]='bar' +b[0:0]=['baz'] +vim.command('call append("$", getbufline(%i, 1, "$"))' % b.number) +# Test assigning to name property +import os +old_name = cb.name +cb.name = 'foo' +cb.append(cb.name[-11:].replace(os.path.sep, '/')) +b.name = 'bar' +cb.append(b.name[-11:].replace(os.path.sep, '/')) +cb.name = old_name +cb.append(cb.name[-17:].replace(os.path.sep, '/')) +del old_name +# Test CheckBuffer +for _b in vim.buffers: + if _b is not cb: + vim.command('bwipeout! ' + str(_b.number)) +del _b +cb.append('valid: b:%s, cb:%s' % (repr(b.valid), repr(cb.valid))) +for expr in ('b[1]','b[:] = ["A", "B"]','b[:]','b.append("abc6")', 'b.name = "!"'): + try: + exec(expr) + except vim.error: + pass + else: + # Usually a SEGV here + # Should not happen in any case + cb.append('No exception for ' + expr) +vim.command('cd .') +del b +EOF +:augroup BUFS +: autocmd! +:augroup END +:augroup! BUFS +:" +:" Test vim.buffers object +:set hidden +:edit a +:buffer # +:edit b +:buffer # +:edit c +:buffer # +py << EOF +try: + from __builtin__ import next +except ImportError: + next = lambda o: o.next() +# Check GCing iterator that was not fully exhausted +i = iter(vim.buffers) +cb.append('i:' + str(next(i))) +# and also check creating more than one iterator at a time +i2 = iter(vim.buffers) +cb.append('i2:' + str(next(i2))) +cb.append('i:' + str(next(i))) +# The following should trigger GC and not cause any problems +del i +del i2 +i3 = iter(vim.buffers) +cb.append('i3:' + str(next(i3))) +del i3 + +prevnum = 0 +for b in vim.buffers: + # Check buffer order + if prevnum >= b.number: + cb.append('!!! Buffer numbers not in strictly ascending order') + # Check indexing: vim.buffers[number].number == number + cb.append(str(b.number) + ':' + repr(vim.buffers[b.number]) + '=' + repr(b)) + prevnum = b.number +del prevnum + +cb.append(str(len(vim.buffers))) + +bnums = list(map(lambda b: b.number, vim.buffers))[1:] + +# Test wiping out buffer with existing iterator +i4 = iter(vim.buffers) +cb.append('i4:' + str(next(i4))) +vim.command('bwipeout! ' + str(bnums.pop(0))) +try: + next(i4) +except vim.error: + pass +else: + cb.append('!!!! No vim.error') +i4 = iter(vim.buffers) +vim.command('bwipeout! ' + str(bnums.pop(-1))) +vim.command('bwipeout! ' + str(bnums.pop(-1))) +cb.append('i4:' + str(next(i4))) +try: + next(i4) +except StopIteration: + cb.append('StopIteration') +del i4 +del bnums +EOF +:" +:" Test vim.{tabpage,window}list and vim.{tabpage,window} objects +:tabnew 0 +:tabnew 1 +:vnew a.1 +:tabnew 2 +:vnew a.2 +:vnew b.2 +:vnew c.2 +py << EOF +cb.append('Number of tabs: ' + str(len(vim.tabpages))) +cb.append('Current tab pages:') +def W(w): + if repr(w).find('(unknown)') != -1: + return '<window object (unknown)>' + else: + return repr(w) + +start = len(cb) + +def Cursor(w): + if w.buffer is cb: + return repr((start - w.cursor[0], w.cursor[1])) + else: + return repr(w.cursor) + +for t in vim.tabpages: + cb.append(' ' + repr(t) + '(' + str(t.number) + ')' + ': ' + str(len(t.windows)) + ' windows, current is ' + W(t.window)) + cb.append(' Windows:') + for w in t.windows: + cb.append(' ' + W(w) + '(' + str(w.number) + ')' + ': displays buffer ' + repr(w.buffer) + '; cursor is at ' + Cursor(w)) + # Other values depend on the size of the terminal, so they are checked partly: + for attr in ('height', 'row', 'width', 'col'): + try: + aval = getattr(w, attr) + if type(aval) is not long: + raise TypeError + if aval < 0: + raise ValueError + except Exception: + cb.append('!!!!!! Error while getting attribute ' + attr + ': ' + sys.exc_type.__name__) + del aval + del attr + w.cursor = (len(w.buffer), 0) +del W +del Cursor +cb.append('Number of windows in current tab page: ' + str(len(vim.windows))) +if list(vim.windows) != list(vim.current.tabpage.windows): + cb.append('!!!!!! Windows differ') +EOF +:" +:" Test vim.current +py << EOF +def H(o): + return repr(o) +cb.append('Current tab page: ' + repr(vim.current.tabpage)) +cb.append('Current window: ' + repr(vim.current.window) + ': ' + H(vim.current.window) + ' is ' + H(vim.current.tabpage.window)) +cb.append('Current buffer: ' + repr(vim.current.buffer) + ': ' + H(vim.current.buffer) + ' is ' + H(vim.current.window.buffer)+ ' is ' + H(vim.current.tabpage.window.buffer)) +del H +# Assigning: fails +try: + vim.current.window = vim.tabpages[0].window +except ValueError: + cb.append('ValueError at assigning foreign tab window') + +for attr in ('window', 'tabpage', 'buffer'): + try: + setattr(vim.current, attr, None) + except TypeError: + cb.append('Type error at assigning None to vim.current.' + attr) +del attr + +# Assigning: success +vim.current.tabpage = vim.tabpages[-2] +vim.current.buffer = cb +vim.current.window = vim.windows[0] +vim.current.window.cursor = (len(vim.current.buffer), 0) +cb.append('Current tab page: ' + repr(vim.current.tabpage)) +cb.append('Current window: ' + repr(vim.current.window)) +cb.append('Current buffer: ' + repr(vim.current.buffer)) +cb.append('Current line: ' + repr(vim.current.line)) +ws = list(vim.windows) +ts = list(vim.tabpages) +for b in vim.buffers: + if b is not cb: + vim.command('bwipeout! ' + str(b.number)) +del b +cb.append('w.valid: ' + repr([w.valid for w in ws])) +cb.append('t.valid: ' + repr([t.valid for t in ts])) +del w +del t +del ts +del ws +EOF +:tabonly! +:only! +:" +:" Test types +py << EOF +for expr, attr in ( + ('vim.vars', 'Dictionary'), + ('vim.options', 'Options'), + ('vim.bindeval("{}")', 'Dictionary'), + ('vim.bindeval("[]")', 'List'), + ('vim.bindeval("function(\'tr\')")', 'Function'), + ('vim.current.buffer', 'Buffer'), + ('vim.current.range', 'Range'), + ('vim.current.window', 'Window'), + ('vim.current.tabpage', 'TabPage'), +): + cb.append(expr + ':' + attr + ':' + repr(type(eval(expr)) is getattr(vim, attr))) +del expr +del attr +EOF +:" +:" Test __dir__() method +py << EOF +for name, o in ( + ('current', vim.current), + ('buffer', vim.current.buffer), + ('window', vim.current.window), + ('tabpage', vim.current.tabpage), + ('range', vim.current.range), + ('dictionary', vim.bindeval('{}')), + ('list', vim.bindeval('[]')), + ('function', vim.bindeval('function("tr")')), + ('output', sys.stdout), + ): + cb.append(name + ':' + ','.join(dir(o))) +del name +del o +EOF +:" +:" Test vim.*.__new__ +:$put =string(pyeval('vim.Dictionary({})')) +:$put =string(pyeval('vim.Dictionary(a=1)')) +:$put =string(pyeval('vim.Dictionary(((''a'', 1),))')) +:$put =string(pyeval('vim.List()')) +:$put =string(pyeval('vim.List(iter(''abc7''))')) +:$put =string(pyeval('vim.Function(''tr'')')) +:$put =string(pyeval('vim.Function(''tr'', args=[123, 3, 4])')) +:$put =string(pyeval('vim.Function(''tr'', args=[])')) +:$put =string(pyeval('vim.Function(''tr'', self={})')) +:$put =string(pyeval('vim.Function(''tr'', args=[123, 3, 4], self={})')) +:$put ='auto_rebind' +:$put =string(pyeval('vim.Function(''tr'', auto_rebind=False)')) +:$put =string(pyeval('vim.Function(''tr'', args=[123, 3, 4], auto_rebind=False)')) +:$put =string(pyeval('vim.Function(''tr'', args=[], auto_rebind=False)')) +:$put =string(pyeval('vim.Function(''tr'', self={}, auto_rebind=False)')) +:$put =string(pyeval('vim.Function(''tr'', args=[123, 3, 4], self={}, auto_rebind=False)')) +:" +:" Test vim.Function +:function Args(...) +: return a:000 +:endfunction +:function SelfArgs(...) dict +: return [a:000, self] +:endfunction +:" The following four lines should not crash +:let Pt = function('tr', [[]], {'l': []}) +:py Pt = vim.bindeval('Pt') +:unlet Pt +:py del Pt +py << EOF +def ecall(out_prefix, func, *args, **kwargs): + line = out_prefix + ': ' + try: + ret = func(*args, **kwargs) + except Exception: + line += '!exception: ' + emsg(sys.exc_info()) + else: + line += '!result: ' + vim.Function('string')(ret) + cb.append(line) +a = vim.Function('Args') +pa1 = vim.Function('Args', args=['abcArgsPA1']) +pa2 = vim.Function('Args', args=[]) +pa3 = vim.Function('Args', args=['abcArgsPA3'], self={'abcSelfPA3': 'abcSelfPA3Val'}) +pa4 = vim.Function('Args', self={'abcSelfPA4': 'abcSelfPA4Val'}) +cb.append('a: ' + repr(a)) +cb.append('pa1: ' + repr(pa1)) +cb.append('pa2: ' + repr(pa2)) +cb.append('pa3: ' + repr(pa3)) +cb.append('pa4: ' + repr(pa4)) +sa = vim.Function('SelfArgs') +psa1 = vim.Function('SelfArgs', args=['abcArgsPSA1']) +psa2 = vim.Function('SelfArgs', args=[]) +psa3 = vim.Function('SelfArgs', args=['abcArgsPSA3'], self={'abcSelfPSA3': 'abcSelfPSA3Val'}) +psa4 = vim.Function('SelfArgs', self={'abcSelfPSA4': 'abcSelfPSA4Val'}) +psa5 = vim.Function('SelfArgs', self={'abcSelfPSA5': 'abcSelfPSA5Val'}, auto_rebind=0) +psa6 = vim.Function('SelfArgs', args=['abcArgsPSA6'], self={'abcSelfPSA6': 'abcSelfPSA6Val'}, auto_rebind=()) +psa7 = vim.Function('SelfArgs', args=['abcArgsPSA7'], auto_rebind=[]) +psa8 = vim.Function('SelfArgs', auto_rebind=False) +psa9 = vim.Function('SelfArgs', self={'abcSelfPSA9': 'abcSelfPSA9Val'}, auto_rebind=True) +psaA = vim.Function('SelfArgs', args=['abcArgsPSAA'], self={'abcSelfPSAA': 'abcSelfPSAAVal'}, auto_rebind=1) +psaB = vim.Function('SelfArgs', args=['abcArgsPSAB'], auto_rebind={'abcARPSAB': 'abcARPSABVal'}) +psaC = vim.Function('SelfArgs', auto_rebind=['abcARPSAC']) +cb.append('sa: ' + repr(sa)) +cb.append('psa1: ' + repr(psa1)) +cb.append('psa2: ' + repr(psa2)) +cb.append('psa3: ' + repr(psa3)) +cb.append('psa4: ' + repr(psa4)) +cb.append('psa5: ' + repr(psa5)) +cb.append('psa6: ' + repr(psa6)) +cb.append('psa7: ' + repr(psa7)) +cb.append('psa8: ' + repr(psa8)) +cb.append('psa9: ' + repr(psa9)) +cb.append('psaA: ' + repr(psaA)) +cb.append('psaB: ' + repr(psaB)) +cb.append('psaC: ' + repr(psaC)) + +psar = vim.Function('SelfArgs', args=[{'abcArgsPSAr': 'abcArgsPSArVal'}], self={'abcSelfPSAr': 'abcSelfPSArVal'}) +psar.args[0]['abcArgsPSAr2'] = [psar.self, psar.args[0]] +psar.self['rec'] = psar +psar.self['self'] = psar.self +psar.self['args'] = psar.args + +try: + cb.append('psar: ' + repr(psar)) +except Exception: + cb.append('!!!!!!!! Caught exception: ' + emsg(sys.exc_info())) +EOF +:$put ='s(a): '.string(pyeval('a')) +:$put ='s(pa1): '.string(pyeval('pa1')) +:$put ='s(pa2): '.string(pyeval('pa2')) +:$put ='s(pa3): '.string(pyeval('pa3')) +:$put ='s(pa4): '.string(pyeval('pa4')) +:$put ='s(sa): '.string(pyeval('sa')) +:$put ='s(psa1): '.string(pyeval('psa1')) +:$put ='s(psa2): '.string(pyeval('psa2')) +:$put ='s(psa3): '.string(pyeval('psa3')) +:$put ='s(psa4): '.string(pyeval('psa4')) +:$put ='s(psa5): '.string(pyeval('psa5')) +:$put ='s(psa6): '.string(pyeval('psa6')) +:$put ='s(psa7): '.string(pyeval('psa7')) +:$put ='s(psa8): '.string(pyeval('psa8')) +:$put ='s(psa9): '.string(pyeval('psa9')) +:$put ='s(psaA): '.string(pyeval('psaA')) +:$put ='s(psaB): '.string(pyeval('psaB')) +:$put ='s(psaC): '.string(pyeval('psaC')) +: +:for v in ['sa', 'psa1', 'psa2', 'psa3', 'psa4', 'psa5', 'psa6', 'psa7', 'psa8', 'psa9', 'psaA', 'psaB', 'psaC'] +: let d = {'f': pyeval(v)} +: $put ='d.'.v.'(): '.string(d.f()) +:endfor +: +:py ecall('a()', a, ) +:py ecall('pa1()', pa1, ) +:py ecall('pa2()', pa2, ) +:py ecall('pa3()', pa3, ) +:py ecall('pa4()', pa4, ) +:py ecall('sa()', sa, ) +:py ecall('psa1()', psa1, ) +:py ecall('psa2()', psa2, ) +:py ecall('psa3()', psa3, ) +:py ecall('psa4()', psa4, ) +: +:py ecall('a(42, 43)', a, 42, 43) +:py ecall('pa1(42, 43)', pa1, 42, 43) +:py ecall('pa2(42, 43)', pa2, 42, 43) +:py ecall('pa3(42, 43)', pa3, 42, 43) +:py ecall('pa4(42, 43)', pa4, 42, 43) +:py ecall('sa(42, 43)', sa, 42, 43) +:py ecall('psa1(42, 43)', psa1, 42, 43) +:py ecall('psa2(42, 43)', psa2, 42, 43) +:py ecall('psa3(42, 43)', psa3, 42, 43) +:py ecall('psa4(42, 43)', psa4, 42, 43) +: +:py ecall('a(42, self={"20": 1})', a, 42, self={'20': 1}) +:py ecall('pa1(42, self={"20": 1})', pa1, 42, self={'20': 1}) +:py ecall('pa2(42, self={"20": 1})', pa2, 42, self={'20': 1}) +:py ecall('pa3(42, self={"20": 1})', pa3, 42, self={'20': 1}) +:py ecall('pa4(42, self={"20": 1})', pa4, 42, self={'20': 1}) +:py ecall('sa(42, self={"20": 1})', sa, 42, self={'20': 1}) +:py ecall('psa1(42, self={"20": 1})', psa1, 42, self={'20': 1}) +:py ecall('psa2(42, self={"20": 1})', psa2, 42, self={'20': 1}) +:py ecall('psa3(42, self={"20": 1})', psa3, 42, self={'20': 1}) +:py ecall('psa4(42, self={"20": 1})', psa4, 42, self={'20': 1}) +: +:py ecall('a(self={"20": 1})', a, self={'20': 1}) +:py ecall('pa1(self={"20": 1})', pa1, self={'20': 1}) +:py ecall('pa2(self={"20": 1})', pa2, self={'20': 1}) +:py ecall('pa3(self={"20": 1})', pa3, self={'20': 1}) +:py ecall('pa4(self={"20": 1})', pa4, self={'20': 1}) +:py ecall('sa(self={"20": 1})', sa, self={'20': 1}) +:py ecall('psa1(self={"20": 1})', psa1, self={'20': 1}) +:py ecall('psa2(self={"20": 1})', psa2, self={'20': 1}) +:py ecall('psa3(self={"20": 1})', psa3, self={'20': 1}) +:py ecall('psa4(self={"20": 1})', psa4, self={'20': 1}) +py << EOF +def s(v): + if v is None: + return repr(v) + else: + return vim.Function('string')(v) + +cb.append('a.args: ' + s(a.args)) +cb.append('pa1.args: ' + s(pa1.args)) +cb.append('pa2.args: ' + s(pa2.args)) +cb.append('pa3.args: ' + s(pa3.args)) +cb.append('pa4.args: ' + s(pa4.args)) +cb.append('sa.args: ' + s(sa.args)) +cb.append('psa1.args: ' + s(psa1.args)) +cb.append('psa2.args: ' + s(psa2.args)) +cb.append('psa3.args: ' + s(psa3.args)) +cb.append('psa4.args: ' + s(psa4.args)) + +cb.append('a.self: ' + s(a.self)) +cb.append('pa1.self: ' + s(pa1.self)) +cb.append('pa2.self: ' + s(pa2.self)) +cb.append('pa3.self: ' + s(pa3.self)) +cb.append('pa4.self: ' + s(pa4.self)) +cb.append('sa.self: ' + s(sa.self)) +cb.append('psa1.self: ' + s(psa1.self)) +cb.append('psa2.self: ' + s(psa2.self)) +cb.append('psa3.self: ' + s(psa3.self)) +cb.append('psa4.self: ' + s(psa4.self)) + +cb.append('a.name: ' + s(a.name)) +cb.append('pa1.name: ' + s(pa1.name)) +cb.append('pa2.name: ' + s(pa2.name)) +cb.append('pa3.name: ' + s(pa3.name)) +cb.append('pa4.name: ' + s(pa4.name)) +cb.append('sa.name: ' + s(sa.name)) +cb.append('psa1.name: ' + s(psa1.name)) +cb.append('psa2.name: ' + s(psa2.name)) +cb.append('psa3.name: ' + s(psa3.name)) +cb.append('psa4.name: ' + s(psa4.name)) + +cb.append('a.auto_rebind: ' + s(a.auto_rebind)) +cb.append('pa1.auto_rebind: ' + s(pa1.auto_rebind)) +cb.append('pa2.auto_rebind: ' + s(pa2.auto_rebind)) +cb.append('pa3.auto_rebind: ' + s(pa3.auto_rebind)) +cb.append('pa4.auto_rebind: ' + s(pa4.auto_rebind)) +cb.append('sa.auto_rebind: ' + s(sa.auto_rebind)) +cb.append('psa1.auto_rebind: ' + s(psa1.auto_rebind)) +cb.append('psa2.auto_rebind: ' + s(psa2.auto_rebind)) +cb.append('psa3.auto_rebind: ' + s(psa3.auto_rebind)) +cb.append('psa4.auto_rebind: ' + s(psa4.auto_rebind)) +cb.append('psa5.auto_rebind: ' + s(psa5.auto_rebind)) +cb.append('psa6.auto_rebind: ' + s(psa6.auto_rebind)) +cb.append('psa7.auto_rebind: ' + s(psa7.auto_rebind)) +cb.append('psa8.auto_rebind: ' + s(psa8.auto_rebind)) +cb.append('psa9.auto_rebind: ' + s(psa9.auto_rebind)) +cb.append('psaA.auto_rebind: ' + s(psaA.auto_rebind)) +cb.append('psaB.auto_rebind: ' + s(psaB.auto_rebind)) +cb.append('psaC.auto_rebind: ' + s(psaC.auto_rebind)) + +del s + +del a +del pa1 +del pa2 +del pa3 +del pa4 +del sa +del psa1 +del psa2 +del psa3 +del psa4 +del psa5 +del psa6 +del psa7 +del psa8 +del psa9 +del psaA +del psaB +del psaC +del psar + +del ecall +EOF +:" +:" Test stdout/stderr +:redir => messages +:py sys.stdout.write('abc8') ; sys.stdout.write('def') +:py sys.stderr.write('abc9') ; sys.stderr.write('def') +:py sys.stdout.writelines(iter('abcA')) +:py sys.stderr.writelines(iter('abcB')) +:redir END +:$put =string(substitute(messages, '\d\+', '', 'g')) +:" Test subclassing +:fun Put(...) +: $put =string(a:000) +: return a:000 +:endfun +py << EOF +class DupDict(vim.Dictionary): + def __setitem__(self, key, value): + super(DupDict, self).__setitem__(key, value) + super(DupDict, self).__setitem__('dup_' + key, value) +dd = DupDict() +dd['a'] = 'b' + +class DupList(vim.List): + def __getitem__(self, idx): + return [super(DupList, self).__getitem__(idx)] * 2 + +dl = DupList() +dl2 = DupList(iter('abcC')) +dl.extend(dl2[0]) + +class DupFun(vim.Function): + def __call__(self, arg): + return super(DupFun, self).__call__(arg, arg) + +df = DupFun('Put') +EOF +:$put =string(sort(keys(pyeval('dd')))) +:$put =string(pyeval('dl')) +:$put =string(pyeval('dl2')) +:$put =string(pyeval('df(2)')) +:$put =string(pyeval('dl') is# pyeval('dl')) +:$put =string(pyeval('dd') is# pyeval('dd')) +:$put =string(pyeval('df')) +:delfunction Put +py << EOF +del DupDict +del DupList +del DupFun +del dd +del dl +del dl2 +del df +EOF +:" +:" Test chdir +py << EOF +import os +fnamemodify = vim.Function('fnamemodify') +cb.append(fnamemodify('.', ':p:h:t')) +cb.append(vim.eval('@%')) +os.chdir('..') +path = fnamemodify('.', ':p:h:t') +if path != 'src': + # Running tests from a shadow directory, so move up another level + # This will result in @% looking like shadow/testdir/test86.in, hence the + # extra fnamemodify + os.chdir('..') + cb.append(fnamemodify('.', ':p:h:t')) + cb.append(fnamemodify(vim.eval('@%'), ':s?^%s.??' % path).replace(os.path.sep, '/')) + os.chdir(path) + del path +else: + cb.append(fnamemodify('.', ':p:h:t')) + cb.append(vim.eval('@%').replace(os.path.sep, '/')) +os.chdir('testdir') +cb.append(fnamemodify('.', ':p:h:t')) +cb.append(vim.eval('@%')) +del fnamemodify +EOF +:" +:" Test errors +:fun F() dict +:endfun +:fun D() +:endfun +py << EOF +d = vim.Dictionary() +ned = vim.Dictionary(foo='bar', baz='abcD') +dl = vim.Dictionary(a=1) +dl.locked = True +l = vim.List() +ll = vim.List('abcE') +ll.locked = True +nel = vim.List('abcO') +f = vim.Function('string') +fd = vim.Function('F') +fdel = vim.Function('D') +vim.command('delfunction D') + +def subexpr_test(expr, name, subexprs): + cb.append('>>> Testing %s using %s' % (name, expr)) + for subexpr in subexprs: + ee(expr % subexpr) + cb.append('<<< Finished') + +def stringtochars_test(expr): + return subexpr_test(expr, 'StringToChars', ( + '1', # Fail type checks + 'u"\\0"', # Fail PyString_AsStringAndSize(bytes, , NULL) check + '"\\0"', # Fail PyString_AsStringAndSize(object, , NULL) check + )) + +class Mapping(object): + def __init__(self, d): + self.d = d + + def __getitem__(self, key): + return self.d[key] + + def keys(self): + return self.d.keys() + + def items(self): + return self.d.items() + +def convertfrompyobject_test(expr, recurse=True): + # pydict_to_tv + stringtochars_test(expr % '{%s : 1}') + if recurse: + convertfrompyobject_test(expr % '{"abcF" : %s}', False) + # pymap_to_tv + stringtochars_test(expr % 'Mapping({%s : 1})') + if recurse: + convertfrompyobject_test(expr % 'Mapping({"abcG" : %s})', False) + # pyseq_to_tv + iter_test(expr) + return subexpr_test(expr, 'ConvertFromPyObject', ( + 'None', # Not conversible + '{"": 1}', # Empty key not allowed + '{u"": 1}', # Same, but with unicode object + 'FailingMapping()', # + 'FailingMappingKey()', # + 'FailingNumber()', # + )) + +def convertfrompymapping_test(expr): + convertfrompyobject_test(expr) + return subexpr_test(expr, 'ConvertFromPyMapping', ( + '[]', + )) + +def iter_test(expr): + return subexpr_test(expr, '*Iter*', ( + 'FailingIter()', + 'FailingIterNext()', + )) + +def number_test(expr, natural=False, unsigned=False): + if natural: + unsigned = True + return subexpr_test(expr, 'NumberToLong', ( + '[]', + 'None', + ) + (unsigned and ('-1',) or ()) + + (natural and ('0',) or ())) + +class FailingTrue(object): + def __nonzero__(self): + raise NotImplementedError('bool') + +class FailingIter(object): + def __iter__(self): + raise NotImplementedError('iter') + +class FailingIterNext(object): + def __iter__(self): + return self + + def next(self): + raise NotImplementedError('next') + +class FailingIterNextN(object): + def __init__(self, n): + self.n = n + + def __iter__(self): + return self + + def next(self): + if self.n: + self.n -= 1 + return 1 + else: + raise NotImplementedError('next N') + +class FailingMappingKey(object): + def __getitem__(self, item): + raise NotImplementedError('getitem:mappingkey') + + def keys(self): + return list("abcH") + +class FailingMapping(object): + def __getitem__(self): + raise NotImplementedError('getitem:mapping') + + def keys(self): + raise NotImplementedError('keys') + +class FailingList(list): + def __getitem__(self, idx): + if i == 2: + raise NotImplementedError('getitem:list') + else: + return super(FailingList, self).__getitem__(idx) + +class NoArgsCall(object): + def __call__(self): + pass + +class FailingCall(object): + def __call__(self, path): + raise NotImplementedError('call') + +class FailingNumber(object): + def __int__(self): + raise NotImplementedError('int') + +cb.append("> Output") +cb.append(">> OutputSetattr") +ee('del sys.stdout.softspace') +number_test('sys.stdout.softspace = %s', unsigned=True) +number_test('sys.stderr.softspace = %s', unsigned=True) +ee('assert sys.stdout.isatty()==False') +ee('assert sys.stdout.seekable()==False') +ee('sys.stdout.close()') +ee('sys.stdout.flush()') +ee('assert sys.stderr.isatty()==False') +ee('assert sys.stderr.seekable()==False') +ee('sys.stderr.close()') +ee('sys.stderr.flush()') +ee('sys.stdout.attr = None') +cb.append(">> OutputWrite") +ee('assert sys.stdout.writable()==True') +ee('assert sys.stdout.readable()==False') +ee('assert sys.stderr.writable()==True') +ee('assert sys.stderr.readable()==False') +ee('assert sys.stdout.closed()==False') +ee('assert sys.stderr.closed()==False') +ee('assert sys.stdout.errors=="strict"') +ee('assert sys.stderr.errors=="strict"') +ee('assert sys.stdout.encoding==sys.stderr.encoding') +ee('sys.stdout.write(None)') +cb.append(">> OutputWriteLines") +ee('sys.stdout.writelines(None)') +ee('sys.stdout.writelines([1])') +iter_test('sys.stdout.writelines(%s)') +cb.append("> VimCommand") +stringtochars_test('vim.command(%s)') +ee('vim.command("", 2)') +#! Not checked: vim->python exceptions translating: checked later +cb.append("> VimToPython") +#! Not checked: everything: needs errors in internal python functions +cb.append("> VimEval") +stringtochars_test('vim.eval(%s)') +ee('vim.eval("", FailingTrue())') +#! Not checked: everything: needs errors in internal python functions +cb.append("> VimEvalPy") +stringtochars_test('vim.bindeval(%s)') +ee('vim.eval("", 2)') +#! Not checked: vim->python exceptions translating: checked later +cb.append("> VimStrwidth") +stringtochars_test('vim.strwidth(%s)') +cb.append("> VimForeachRTP") +ee('vim.foreach_rtp(None)') +ee('vim.foreach_rtp(NoArgsCall())') +ee('vim.foreach_rtp(FailingCall())') +ee('vim.foreach_rtp(int, 2)') +cb.append('> import') +old_rtp = vim.options['rtp'] +vim.options['rtp'] = os.getcwd().replace('\\', '\\\\').replace(',', '\\,') +ee('import xxx_no_such_module_xxx') +ee('import failing_import') +ee('import failing') +vim.options['rtp'] = old_rtp +del old_rtp +cb.append("> Options") +cb.append(">> OptionsItem") +ee('vim.options["abcQ"]') +ee('vim.options[""]') +stringtochars_test('vim.options[%s]') +cb.append(">> OptionsContains") +stringtochars_test('%s in vim.options') +cb.append("> Dictionary") +cb.append(">> DictionaryConstructor") +ee('vim.Dictionary("abcI")') +##! Not checked: py_dict_alloc failure +cb.append(">> DictionarySetattr") +ee('del d.locked') +ee('d.locked = FailingTrue()') +ee('vim.vvars.locked = False') +ee('d.scope = True') +ee('d.xxx = True') +cb.append(">> _DictionaryItem") +ee('d.get("a", 2, 3)') +stringtochars_test('d.get(%s)') +ee('d.pop("a")') +ee('dl.pop("a")') +cb.append(">> DictionaryContains") +ee('"" in d') +ee('0 in d') +cb.append(">> DictionaryIterNext") +ee('for i in ned: ned["a"] = 1') +del i +cb.append(">> DictionaryAssItem") +ee('dl["b"] = 1') +stringtochars_test('d[%s] = 1') +convertfrompyobject_test('d["a"] = %s') +cb.append(">> DictionaryUpdate") +cb.append(">>> kwargs") +cb.append(">>> iter") +ee('d.update(FailingMapping())') +ee('d.update([FailingIterNext()])') +ee('d.update([FailingIterNextN(1)])') +iter_test('d.update(%s)') +convertfrompyobject_test('d.update(%s)') +stringtochars_test('d.update(((%s, 0),))') +convertfrompyobject_test('d.update((("a", %s),))') +cb.append(">> DictionaryPopItem") +ee('d.popitem(1, 2)') +cb.append(">> DictionaryHasKey") +ee('d.has_key()') +cb.append("> List") +cb.append(">> ListConstructor") +ee('vim.List(1, 2)') +ee('vim.List(a=1)') +iter_test('vim.List(%s)') +convertfrompyobject_test('vim.List([%s])') +cb.append(">> ListItem") +ee('l[1000]') +cb.append(">> ListAssItem") +ee('ll[1] = 2') +ee('l[1000] = 3') +cb.append(">> ListAssSlice") +ee('ll[1:100] = "abcJ"') +iter_test('l[:] = %s') +ee('nel[1:10:2] = "abcK"') +cb.append(repr(tuple(nel))) +ee('nel[1:10:2] = "a"') +cb.append(repr(tuple(nel))) +ee('nel[1:1:-1] = "a"') +cb.append(repr(tuple(nel))) +ee('nel[:] = FailingIterNextN(2)') +cb.append(repr(tuple(nel))) +convertfrompyobject_test('l[:] = [%s]') +cb.append(">> ListConcatInPlace") +iter_test('l.extend(%s)') +convertfrompyobject_test('l.extend([%s])') +cb.append(">> ListSetattr") +ee('del l.locked') +ee('l.locked = FailingTrue()') +ee('l.xxx = True') +cb.append("> Function") +cb.append(">> FunctionConstructor") +cb.append(">>> FunctionConstructor") +ee('vim.Function("123")') +ee('vim.Function("xxx_non_existent_function_xxx")') +ee('vim.Function("xxx#non#existent#function#xxx")') +ee('vim.Function("xxx_non_existent_function_xxx2", args=[])') +ee('vim.Function("xxx_non_existent_function_xxx3", self={})') +ee('vim.Function("xxx_non_existent_function_xxx4", args=[], self={})') +cb.append(">>> FunctionNew") +ee('vim.Function("tr", self="abcFuncSelf")') +ee('vim.Function("tr", args=427423)') +ee('vim.Function("tr", self="abcFuncSelf2", args="abcFuncArgs2")') +ee('vim.Function(self="abcFuncSelf2", args="abcFuncArgs2")') +ee('vim.Function("tr", "", self="abcFuncSelf2", args="abcFuncArgs2")') +ee('vim.Function("tr", "")') +cb.append(">> FunctionCall") +convertfrompyobject_test('f(%s)') +convertfrompymapping_test('fd(self=%s)') +cb.append("> TabPage") +cb.append(">> TabPageAttr") +ee('vim.current.tabpage.xxx') +cb.append("> TabList") +cb.append(">> TabListItem") +ee('vim.tabpages[1000]') +cb.append("> Window") +cb.append(">> WindowAttr") +ee('vim.current.window.xxx') +cb.append(">> WindowSetattr") +ee('vim.current.window.buffer = 0') +ee('vim.current.window.cursor = (100000000, 100000000)') +ee('vim.current.window.cursor = True') +number_test('vim.current.window.height = %s', unsigned=True) +number_test('vim.current.window.width = %s', unsigned=True) +ee('vim.current.window.xxxxxx = True') +cb.append("> WinList") +cb.append(">> WinListItem") +ee('vim.windows[1000]') +cb.append("> Buffer") +cb.append(">> StringToLine (indirect)") +ee('vim.current.buffer[0] = u"\\na"') +ee('vim.current.buffer[0] = "\\na"') +cb.append(">> SetBufferLine (indirect)") +ee('vim.current.buffer[0] = True') +cb.append(">> SetBufferLineList (indirect)") +ee('vim.current.buffer[:] = True') +ee('vim.current.buffer[:] = ["\\na", "bc"]') +cb.append(">> InsertBufferLines (indirect)") +ee('vim.current.buffer.append(None)') +ee('vim.current.buffer.append(["\\na", "bc"])') +ee('vim.current.buffer.append("\\nbc")') +cb.append(">> RBItem") +ee('vim.current.buffer[100000000]') +cb.append(">> RBAsItem") +ee('vim.current.buffer[100000000] = ""') +cb.append(">> BufferAttr") +ee('vim.current.buffer.xxx') +cb.append(">> BufferSetattr") +ee('vim.current.buffer.name = True') +ee('vim.current.buffer.xxx = True') +cb.append(">> BufferMark") +ee('vim.current.buffer.mark(0)') +ee('vim.current.buffer.mark("abcM")') +ee('vim.current.buffer.mark("!")') +cb.append(">> BufferRange") +ee('vim.current.buffer.range(1, 2, 3)') +cb.append("> BufMap") +cb.append(">> BufMapItem") +ee('vim.buffers[100000000]') +number_test('vim.buffers[%s]', natural=True) +cb.append("> Current") +cb.append(">> CurrentGetattr") +ee('vim.current.xxx') +cb.append(">> CurrentSetattr") +ee('vim.current.line = True') +ee('vim.current.buffer = True') +ee('vim.current.window = True') +ee('vim.current.tabpage = True') +ee('vim.current.xxx = True') +del d +del ned +del dl +del l +del ll +del nel +del f +del fd +del fdel +del subexpr_test +del stringtochars_test +del Mapping +del convertfrompyobject_test +del convertfrompymapping_test +del iter_test +del number_test +del FailingTrue +del FailingIter +del FailingIterNext +del FailingIterNextN +del FailingMapping +del FailingMappingKey +del FailingList +del NoArgsCall +del FailingCall +del FailingNumber +EOF +:delfunction F +:" +:" Test import +py << EOF +sys.path.insert(0, os.path.join(os.getcwd(), 'python_before')) +sys.path.append(os.path.join(os.getcwd(), 'python_after')) +vim.options['rtp'] = os.getcwd().replace(',', '\\,').replace('\\', '\\\\') +l = [] +def callback(path): + l.append(path[-len('/testdir'):].replace(os.path.sep, '/')) +vim.foreach_rtp(callback) +cb.append(repr(l)) +del l +def callback(path): + return path[-len('/testdir'):].replace(os.path.sep, '/') +cb.append(repr(vim.foreach_rtp(callback))) +del callback +from module import dir as d +from modulex import ddir +cb.append(d + ',' + ddir) +import before +cb.append(before.dir) +import after +cb.append(after.dir) +import topmodule as tm +import topmodule.submodule as tms +import topmodule.submodule.subsubmodule.subsubsubmodule as tmsss +cb.append(tm.__file__.replace('.pyc', '.py').replace(os.path.sep, '/')[-len('modulex/topmodule/__init__.py'):]) +cb.append(tms.__file__.replace('.pyc', '.py').replace(os.path.sep, '/')[-len('modulex/topmodule/submodule/__init__.py'):]) +cb.append(tmsss.__file__.replace('.pyc', '.py').replace(os.path.sep, '/')[-len('modulex/topmodule/submodule/subsubmodule/subsubsubmodule.py'):]) +del before +del after +del d +del ddir +del tm +del tms +del tmsss +EOF +:" +:" Test exceptions +:fun Exe(e) +: execute a:e +:endfun +py << EOF +Exe = vim.bindeval('function("Exe")') +ee('vim.command("throw \'abcN\'")') +ee('Exe("throw \'def\'")') +ee('vim.eval("Exe(\'throw \'\'ghi\'\'\')")') +ee('vim.eval("Exe(\'echoerr \'\'jkl\'\'\')")') +ee('vim.eval("Exe(\'xxx_non_existent_command_xxx\')")') +ee('vim.eval("xxx_unknown_function_xxx()")') +ee('vim.bindeval("Exe(\'xxx_non_existent_command_xxx\')")') +del Exe +EOF +:delfunction Exe +:" +:" Regression: interrupting vim.command propagates to next vim.command +py << EOF +def test_keyboard_interrupt(): + try: + vim.command('while 1 | endwhile') + except KeyboardInterrupt: + cb.append('Caught KeyboardInterrupt') + except Exception: + cb.append('!!!!!!!! Caught exception: ' + emsg(sys.exc_info())) + else: + cb.append('!!!!!!!! No exception') + try: + vim.command('$ put =\'Running :put\'') + except KeyboardInterrupt: + cb.append('!!!!!!!! Caught KeyboardInterrupt') + except Exception: + cb.append('!!!!!!!! Caught exception: ' + emsg(sys.exc_info())) + else: + cb.append('No exception') +EOF +:debuggreedy +:call inputsave() +:call feedkeys("s\ns\ns\ns\nq\n") +:redir => output +:debug silent! py test_keyboard_interrupt() +:redir END +:0 debuggreedy +:call inputrestore() +:silent $put =output +:unlet output +:py del test_keyboard_interrupt +:" +:" Cleanup +py << EOF +del cb +del ee +del emsg +del sys +del os +del vim +EOF +:endfun +:" +:fun RunTest() +:let checkrefs = !empty($PYTHONDUMPREFS) +:let start = getline(1, '$') +:for i in range(checkrefs ? 10 : 1) +: if i != 0 +: %d _ +: call setline(1, start) +: endif +: call Test() +: if i == 0 +: let result = getline(1, '$') +: endif +:endfor +:if checkrefs +: %d _ +: call setline(1, result) +:endif +:endfun +:" +:call RunTest() +:delfunction RunTest +:delfunction Test +:call garbagecollect(1) +:" +:/^start:/,$wq! test.out +:" vim: et ts=4 isk-=\: +:while getchar(0) isnot 0|endwhile +ENDTEST + +start: diff --git a/src/testdir/test86.ok b/src/testdir/test86.ok new file mode 100644 index 0000000..24d3fd4 --- /dev/null +++ b/src/testdir/test86.ok @@ -0,0 +1,1445 @@ +start: +[1, 'as''d', [1, 2, function('strlen'), {'a': 1}]] +[1, 2, function('strlen'), {'a': 1}] +Vim(put):E684: +[0, 'as''d', [1, 2, function('strlen'), {'a': 1}]] +[0, function('strlen'), [1, 2, function('strlen'), {'a': 1}]] +1 +['-1', '0', '1', 'b', 'f'] +['asd', -1L, <vim.Function '1'>, <vim.dictionary object at >, <vim.list object at >] +[('-1', <vim.dictionary object at >), ('0', -1L), ('1', 'asd'), ('b', <vim.list object at >), ('f', <vim.Function '1'>)] +'-1' : {'a': 1} +'0' : -1 +'1' : 'asd' +'b' : [1, 2, function('strlen')] +'f' : function('1') +[0, function('strlen')] +[3] +[1, 2, function('strlen')] +[1, 2, function('strlen')] +1 +'asd' +2 +True +False +True +False +['0'] +{'0': -1} +('0', -1L) +None +[] +[0, 1, 2, 3] +[0, 1, 2, 3] +[0, 1, 3] +[0, 1] +[0, 1] +[0, 1] +[0, 1, 2, 3] +[0, 1, 2, 3] +[0, 2, 3] +[2, 3] +[2, 3] +[2, 3] +[1, 3] +[0, 2] +[0, 1, 2, 3] +['a', 0, 1, 2, 3] +[0, 'b', 2, 3] +[0, 1, 'c'] +[0, 1, 2, 3, 'd'] +[0, 1, 2, 'e', 3] +['f', 2, 3] +[0, 1, 'g', 2, 3] +['h'] +[0, 1, 10, 3, 20, 5, 6, 7] +[0, 1, 2, 3, 20, 5, 10, 7] +[0, 1, 2, 3, 4, 5, 6, 7] +[0, 1, 2, 3, 4, 5, 6, 7] +[0, 1, 2, 3, 4, 5, 6, 7] +l[2] threw vim.error: error:('list is locked',) +[0, 1, 2, 3] +[function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd'] +[function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd', 'DictNewStart', 1, 2, 3, 'DictNewEnd', {'a': 'b'}] +[function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd', 'DictNewStart', 1, 2, 3, 'DictNewEnd', {'a': 'b'}, 'New'] +l[1](1, 2, 3):error:('Vim:E725: Calling dict function without Dictionary: DictNew',) +f(1, 2, 3):error:('Vim:E117: Unknown function: New',) +[0.0, 0.0] +KeyError +TypeError +TypeError +ValueError +TypeError +TypeError +KeyError +KeyError +d : locked:0;scope:0 +dl : locked:1;scope:0 +v: : locked:2;scope:1 +g: : locked:0;scope:2 +d:{'abc2': 1} +dl:{'def': 1} +l : locked:0 +ll : locked:1 +l:[0] +ll:[1] +[0, 1, 2] +['a', 'b'] +['c', 1] +['d', ['e']] +pyeval("None") = v:none +0.0 +"\0": Vim(let):E859: +{"\0": 1}: Vim(let):E859: +undefined_name: Vim(let):Trace +vim: Vim(let):E859: +[1] +[1, 10, 11, 10, 11, 10, 11, 10, 11, 10, 11, 10, 1] +[0, 1, 2, 3] +[2, 3, 4, 5] +[0, 1] +[4, 5] +[2, 3] +[] +[2, 3] +[] +[0, 1, 2, 3, 4, 5] +[0, 1, 2, 3, 4, 5] +[0, 1, 2, 3, 4, 5] +[4, 3] +[0, 2, 4] +[] +Abc +bac +def +bar +jkl +wopts iters equal: 1 +bopts iters equal: 1 +>>> paste + g/w/b:1/0/0 + g/w/b (in):1/0/0 + p/gopts1: False + p/wopts1! KeyError + inv: 2! KeyError + wopts1! KeyError + wopts2! KeyError + wopts3! KeyError + p/bopts1! KeyError + inv: 2! KeyError + bopts1! KeyError + bopts2! KeyError + bopts3! KeyError + G: 1 + W: 1:1 2:1 3:1 4:1 + B: 1:1 2:1 3:1 4:1 + del wopts3! KeyError + del bopts3! KeyError + G: 1 + W: 1:1 2:1 3:1 4:1 + B: 1:1 2:1 3:1 4:1 +>>> previewheight + g/w/b:1/0/0 + g/w/b (in):1/0/0 + p/gopts1: 12 + inv: 'a'! TypeError + p/wopts1! KeyError + inv: 'a'! KeyError + wopts1! KeyError + wopts2! KeyError + wopts3! KeyError + p/bopts1! KeyError + inv: 'a'! KeyError + bopts1! KeyError + bopts2! KeyError + bopts3! KeyError + G: 5 + W: 1:5 2:5 3:5 4:5 + B: 1:5 2:5 3:5 4:5 + del wopts3! KeyError + del bopts3! KeyError + G: 5 + W: 1:5 2:5 3:5 4:5 + B: 1:5 2:5 3:5 4:5 +>>> operatorfunc + g/w/b:1/0/0 + g/w/b (in):1/0/0 + p/gopts1: '' + inv: 2! TypeError + p/wopts1! KeyError + inv: 2! KeyError + wopts1! KeyError + wopts2! KeyError + wopts3! KeyError + p/bopts1! KeyError + inv: 2! KeyError + bopts1! KeyError + bopts2! KeyError + bopts3! KeyError + G: 'A' + W: 1:'A' 2:'A' 3:'A' 4:'A' + B: 1:'A' 2:'A' 3:'A' 4:'A' + del wopts3! KeyError + del bopts3! KeyError + G: 'A' + W: 1:'A' 2:'A' 3:'A' 4:'A' + B: 1:'A' 2:'A' 3:'A' 4:'A' +>>> number + g/w/b:0/1/0 + g/w/b (in):0/1/0 + p/gopts1! KeyError + inv: 0! KeyError + gopts1! KeyError + p/wopts1: False + p/bopts1! KeyError + inv: 0! KeyError + bopts1! KeyError + bopts2! KeyError + bopts3! KeyError + G: 0 + W: 1:1 2:1 3:0 4:0 + B: 1:1 2:1 3:0 4:0 + del wopts3! ValueError + del bopts3! KeyError + G: 0 + W: 1:1 2:1 3:0 4:0 + B: 1:1 2:1 3:0 4:0 +>>> numberwidth + g/w/b:0/1/0 + g/w/b (in):0/1/0 + p/gopts1! KeyError + inv: -100! KeyError + gopts1! KeyError + p/wopts1: 8 + inv: -100! error + p/bopts1! KeyError + inv: -100! KeyError + bopts1! KeyError + bopts2! KeyError + bopts3! KeyError + G: 8 + W: 1:3 2:5 3:2 4:8 + B: 1:3 2:5 3:2 4:8 + del wopts3! ValueError + del bopts3! KeyError + G: 8 + W: 1:3 2:5 3:2 4:8 + B: 1:3 2:5 3:2 4:8 +>>> colorcolumn + g/w/b:0/1/0 + g/w/b (in):0/1/0 + p/gopts1! KeyError + inv: 'abc4'! KeyError + gopts1! KeyError + p/wopts1: '' + inv: 'abc4'! error + p/bopts1! KeyError + inv: 'abc4'! KeyError + bopts1! KeyError + bopts2! KeyError + bopts3! KeyError + G: '' + W: 1:'+2' 2:'+3' 3:'+1' 4:'' + B: 1:'+2' 2:'+3' 3:'+1' 4:'' + del wopts3! ValueError + del bopts3! KeyError + G: '' + W: 1:'+2' 2:'+3' 3:'+1' 4:'' + B: 1:'+2' 2:'+3' 3:'+1' 4:'' +>>> statusline + g/w/b:1/1/0 + g/w/b (in):1/1/0 + p/gopts1: '' + inv: 0! TypeError + p/wopts1: None + inv: 0! TypeError + p/bopts1! KeyError + inv: 0! KeyError + bopts1! KeyError + bopts2! KeyError + bopts3! KeyError + G: '1' + W: 1:'2' 2:'4' 3:'1' 4:'1' + B: 1:'2' 2:'4' 3:'1' 4:'1' + del bopts3! KeyError + G: '1' + W: 1:'2' 2:'1' 3:'1' 4:'1' + B: 1:'2' 2:'1' 3:'1' 4:'1' +>>> autoindent + g/w/b:0/0/1 + g/w/b (in):0/0/1 + p/gopts1! KeyError + inv: 2! KeyError + gopts1! KeyError + p/wopts1! KeyError + inv: 2! KeyError + wopts1! KeyError + wopts2! KeyError + wopts3! KeyError + p/bopts1: False + G: 0 + W: 1:0 2:1 3:0 4:1 + B: 1:0 2:1 3:0 4:1 + del wopts3! KeyError + del bopts3! ValueError + G: 0 + W: 1:0 2:1 3:0 4:1 + B: 1:0 2:1 3:0 4:1 +>>> shiftwidth + g/w/b:0/0/1 + g/w/b (in):0/0/1 + p/gopts1! KeyError + inv: 3! KeyError + gopts1! KeyError + p/wopts1! KeyError + inv: 3! KeyError + wopts1! KeyError + wopts2! KeyError + wopts3! KeyError + p/bopts1: 8 + G: 8 + W: 1:0 2:2 3:8 4:1 + B: 1:0 2:2 3:8 4:1 + del wopts3! KeyError + del bopts3! ValueError + G: 8 + W: 1:0 2:2 3:8 4:1 + B: 1:0 2:2 3:8 4:1 +>>> omnifunc + g/w/b:0/0/1 + g/w/b (in):0/0/1 + p/gopts1! KeyError + inv: 1! KeyError + gopts1! KeyError + p/wopts1! KeyError + inv: 1! KeyError + wopts1! KeyError + wopts2! KeyError + wopts3! KeyError + p/bopts1: '' + inv: 1! TypeError + G: '' + W: 1:'A' 2:'B' 3:'' 4:'C' + B: 1:'A' 2:'B' 3:'' 4:'C' + del wopts3! KeyError + del bopts3! ValueError + G: '' + W: 1:'A' 2:'B' 3:'' 4:'C' + B: 1:'A' 2:'B' 3:'' 4:'C' +>>> preserveindent + g/w/b:0/0/1 + g/w/b (in):0/0/1 + p/gopts1! KeyError + inv: 2! KeyError + gopts1! KeyError + p/wopts1! KeyError + inv: 2! KeyError + wopts1! KeyError + wopts2! KeyError + wopts3! KeyError + p/bopts1: False + G: 0 + W: 1:0 2:1 3:0 4:1 + B: 1:0 2:1 3:0 4:1 + del wopts3! KeyError + del bopts3! ValueError + G: 0 + W: 1:0 2:1 3:0 4:1 + B: 1:0 2:1 3:0 4:1 +>>> path + g/w/b:1/0/1 + g/w/b (in):1/0/1 + p/gopts1: '.,..,,' + inv: 0! TypeError + p/wopts1! KeyError + inv: 0! KeyError + wopts1! KeyError + wopts2! KeyError + wopts3! KeyError + p/bopts1: None + inv: 0! TypeError + G: '.,,' + W: 1:'.,,' 2:',,' 3:'.,,' 4:'.' + B: 1:'.,,' 2:',,' 3:'.,,' 4:'.' + del wopts3! KeyError + G: '.,,' + W: 1:'.,,' 2:',,' 3:'.,,' 4:'.,,' + B: 1:'.,,' 2:',,' 3:'.,,' 4:'.,,' +First line +First line +def +First line +Second line +Third line +(7, 2) +<buffer test86.in><buffer > +baz +bar +Second line +Third line +foo +1:BufFilePre:1 +1:BufFilePost:1 +testdir/foo +5:BufFilePre:5 +5:BufFilePost:5 +testdir/bar +1:BufFilePre:1 +1:BufFilePost:1 +testdir/test86.in +valid: b:False, cb:True +i:<buffer test86.in> +i2:<buffer test86.in> +i:<buffer a> +i3:<buffer test86.in> +1:<buffer test86.in>=<buffer test86.in> +8:<buffer a>=<buffer a> +9:<buffer b>=<buffer b> +10:<buffer c>=<buffer c> +4 +i4:<buffer test86.in> +i4:<buffer test86.in> +StopIteration +Number of tabs: 4 +Current tab pages: + <tabpage 0>(1): 1 windows, current is <window object (unknown)> + Windows: + <window object (unknown)>(1): displays buffer <buffer test86.in>; cursor is at (37, 0) + <tabpage 1>(2): 1 windows, current is <window object (unknown)> + Windows: + <window object (unknown)>(1): displays buffer <buffer 0>; cursor is at (1, 0) + <tabpage 2>(3): 2 windows, current is <window object (unknown)> + Windows: + <window object (unknown)>(1): displays buffer <buffer a.1>; cursor is at (1, 0) + <window object (unknown)>(2): displays buffer <buffer 1>; cursor is at (1, 0) + <tabpage 3>(4): 4 windows, current is <window 0> + Windows: + <window 0>(1): displays buffer <buffer c.2>; cursor is at (1, 0) + <window 1>(2): displays buffer <buffer b.2>; cursor is at (1, 0) + <window 2>(3): displays buffer <buffer a.2>; cursor is at (1, 0) + <window 3>(4): displays buffer <buffer 2>; cursor is at (1, 0) +Number of windows in current tab page: 4 +Current tab page: <tabpage 3> +Current window: <window 0>: <window 0> is <window 0> +Current buffer: <buffer c.2>: <buffer c.2> is <buffer c.2> is <buffer c.2> +ValueError at assigning foreign tab window +Type error at assigning None to vim.current.window +Type error at assigning None to vim.current.tabpage +Type error at assigning None to vim.current.buffer +Current tab page: <tabpage 2> +Current window: <window 0> +Current buffer: <buffer test86.in> +Current line: 'Type error at assigning None to vim.current.buffer' +w.valid: [True, False] +t.valid: [True, False, True, False] +vim.vars:Dictionary:True +vim.options:Options:True +vim.bindeval("{}"):Dictionary:True +vim.bindeval("[]"):List:True +vim.bindeval("function('tr')"):Function:True +vim.current.buffer:Buffer:True +vim.current.range:Range:True +vim.current.window:Window:True +vim.current.tabpage:TabPage:True +current:__dir__,__members__,buffer,line,range,tabpage,window +buffer:__dir__,__members__,append,mark,name,number,options,range,valid,vars +window:__dir__,__members__,buffer,col,cursor,height,number,options,row,tabpage,valid,vars,width +tabpage:__dir__,__members__,number,valid,vars,window,windows +range:__dir__,__members__,append,end,start +dictionary:__dir__,__members__,get,has_key,items,keys,locked,pop,popitem,scope,update,values +list:__dir__,__members__,extend,locked +function:__dir__,__members__,args,auto_rebind,self,softspace +output:__dir__,__members__,close,closed,flush,isatty,readable,seekable,softspace,writable,write,writelines +{} +{'a': 1} +{'a': 1} +[] +['a', 'b', 'c', '7'] +function('tr') +function('tr', [123, 3, 4]) +function('tr') +function('tr', {}) +function('tr', [123, 3, 4], {}) +auto_rebind +function('tr') +function('tr', [123, 3, 4]) +function('tr') +function('tr', {}) +function('tr', [123, 3, 4], {}) +a: <vim.Function 'Args'> +pa1: <vim.Function 'Args', args=['abcArgsPA1']> +pa2: <vim.Function 'Args'> +pa3: <vim.Function 'Args', args=['abcArgsPA3'], self={'abcSelfPA3': 'abcSelfPA3Val'}> +pa4: <vim.Function 'Args', self={'abcSelfPA4': 'abcSelfPA4Val'}> +sa: <vim.Function 'SelfArgs'> +psa1: <vim.Function 'SelfArgs', args=['abcArgsPSA1']> +psa2: <vim.Function 'SelfArgs'> +psa3: <vim.Function 'SelfArgs', args=['abcArgsPSA3'], self={'abcSelfPSA3': 'abcSelfPSA3Val'}> +psa4: <vim.Function 'SelfArgs', self={'abcSelfPSA4': 'abcSelfPSA4Val'}> +psa5: <vim.Function 'SelfArgs', self={'abcSelfPSA5': 'abcSelfPSA5Val'}> +psa6: <vim.Function 'SelfArgs', args=['abcArgsPSA6'], self={'abcSelfPSA6': 'abcSelfPSA6Val'}> +psa7: <vim.Function 'SelfArgs', args=['abcArgsPSA7']> +psa8: <vim.Function 'SelfArgs'> +psa9: <vim.Function 'SelfArgs', self={'abcSelfPSA9': 'abcSelfPSA9Val'}, auto_rebind=True> +psaA: <vim.Function 'SelfArgs', args=['abcArgsPSAA'], self={'abcSelfPSAA': 'abcSelfPSAAVal'}, auto_rebind=True> +psaB: <vim.Function 'SelfArgs', args=['abcArgsPSAB']> +psaC: <vim.Function 'SelfArgs'> +psar: <vim.Function 'SelfArgs', args=[{'abcArgsPSAr2': [{'rec': function('SelfArgs', [{...}], {...}), 'self': {...}, 'abcSelfPSAr': 'abcSelfPSArVal', 'args': [{...}]}, {...}], 'abcArgsPSAr': 'abcArgsPSArVal'}], self={'rec': function('SelfArgs', [{'abcArgsPSAr2': [{...}, {...}], 'abcArgsPSAr': 'abcArgsPSArVal'}], {...}), 'self': {...}, 'abcSelfPSAr': 'abcSelfPSArVal', 'args': [{'abcArgsPSAr2': [{...}, {...}], 'abcArgsPSAr': 'abcArgsPSArVal'}]}> +s(a): function('Args') +s(pa1): function('Args', ['abcArgsPA1']) +s(pa2): function('Args') +s(pa3): function('Args', ['abcArgsPA3'], {'abcSelfPA3': 'abcSelfPA3Val'}) +s(pa4): function('Args', {'abcSelfPA4': 'abcSelfPA4Val'}) +s(sa): function('SelfArgs') +s(psa1): function('SelfArgs', ['abcArgsPSA1']) +s(psa2): function('SelfArgs') +s(psa3): function('SelfArgs', ['abcArgsPSA3'], {'abcSelfPSA3': 'abcSelfPSA3Val'}) +s(psa4): function('SelfArgs', {'abcSelfPSA4': 'abcSelfPSA4Val'}) +s(psa5): function('SelfArgs', {'abcSelfPSA5': 'abcSelfPSA5Val'}) +s(psa6): function('SelfArgs', ['abcArgsPSA6'], {'abcSelfPSA6': 'abcSelfPSA6Val'}) +s(psa7): function('SelfArgs', ['abcArgsPSA7']) +s(psa8): function('SelfArgs') +s(psa9): function('SelfArgs', {'abcSelfPSA9': 'abcSelfPSA9Val'}) +s(psaA): function('SelfArgs', ['abcArgsPSAA'], {'abcSelfPSAA': 'abcSelfPSAAVal'}) +s(psaB): function('SelfArgs', ['abcArgsPSAB']) +s(psaC): function('SelfArgs') +d.sa(): [[], {'f': function('SelfArgs')}] +d.psa1(): [['abcArgsPSA1'], {'f': function('SelfArgs', ['abcArgsPSA1'])}] +d.psa2(): [[], {'f': function('SelfArgs')}] +d.psa3(): [['abcArgsPSA3'], {'abcSelfPSA3': 'abcSelfPSA3Val'}] +d.psa4(): [[], {'abcSelfPSA4': 'abcSelfPSA4Val'}] +d.psa5(): [[], {'abcSelfPSA5': 'abcSelfPSA5Val'}] +d.psa6(): [['abcArgsPSA6'], {'abcSelfPSA6': 'abcSelfPSA6Val'}] +d.psa7(): [['abcArgsPSA7'], {'f': function('SelfArgs', ['abcArgsPSA7'])}] +d.psa8(): [[], {'f': function('SelfArgs')}] +d.psa9(): [[], {'f': function('SelfArgs', {'abcSelfPSA9': 'abcSelfPSA9Val'})}] +d.psaA(): [['abcArgsPSAA'], {'f': function('SelfArgs', ['abcArgsPSAA'], {'abcSelfPSAA': 'abcSelfPSAAVal'})}] +d.psaB(): [['abcArgsPSAB'], {'f': function('SelfArgs', ['abcArgsPSAB'])}] +d.psaC(): [[], {'f': function('SelfArgs')}] +a(): !result: [] +pa1(): !result: ['abcArgsPA1'] +pa2(): !result: [] +pa3(): !result: ['abcArgsPA3'] +pa4(): !result: [] +sa(): !exception: error:('Vim:E725: Calling dict function without Dictionary: SelfArgs',) +psa1(): !exception: error:('Vim:E725: Calling dict function without Dictionary: SelfArgs',) +psa2(): !exception: error:('Vim:E725: Calling dict function without Dictionary: SelfArgs',) +psa3(): !result: [['abcArgsPSA3'], {'abcSelfPSA3': 'abcSelfPSA3Val'}] +psa4(): !result: [[], {'abcSelfPSA4': 'abcSelfPSA4Val'}] +a(42, 43): !result: [42, 43] +pa1(42, 43): !result: ['abcArgsPA1', 42, 43] +pa2(42, 43): !result: [42, 43] +pa3(42, 43): !result: ['abcArgsPA3', 42, 43] +pa4(42, 43): !result: [42, 43] +sa(42, 43): !exception: error:('Vim:E725: Calling dict function without Dictionary: SelfArgs',) +psa1(42, 43): !exception: error:('Vim:E725: Calling dict function without Dictionary: SelfArgs',) +psa2(42, 43): !exception: error:('Vim:E725: Calling dict function without Dictionary: SelfArgs',) +psa3(42, 43): !result: [['abcArgsPSA3', 42, 43], {'abcSelfPSA3': 'abcSelfPSA3Val'}] +psa4(42, 43): !result: [[42, 43], {'abcSelfPSA4': 'abcSelfPSA4Val'}] +a(42, self={"20": 1}): !result: [42] +pa1(42, self={"20": 1}): !result: ['abcArgsPA1', 42] +pa2(42, self={"20": 1}): !result: [42] +pa3(42, self={"20": 1}): !result: ['abcArgsPA3', 42] +pa4(42, self={"20": 1}): !result: [42] +sa(42, self={"20": 1}): !result: [[42], {'20': 1}] +psa1(42, self={"20": 1}): !result: [['abcArgsPSA1', 42], {'20': 1}] +psa2(42, self={"20": 1}): !result: [[42], {'20': 1}] +psa3(42, self={"20": 1}): !result: [['abcArgsPSA3', 42], {'20': 1}] +psa4(42, self={"20": 1}): !result: [[42], {'20': 1}] +a(self={"20": 1}): !result: [] +pa1(self={"20": 1}): !result: ['abcArgsPA1'] +pa2(self={"20": 1}): !result: [] +pa3(self={"20": 1}): !result: ['abcArgsPA3'] +pa4(self={"20": 1}): !result: [] +sa(self={"20": 1}): !result: [[], {'20': 1}] +psa1(self={"20": 1}): !result: [['abcArgsPSA1'], {'20': 1}] +psa2(self={"20": 1}): !result: [[], {'20': 1}] +psa3(self={"20": 1}): !result: [['abcArgsPSA3'], {'20': 1}] +psa4(self={"20": 1}): !result: [[], {'20': 1}] +a.args: None +pa1.args: ['abcArgsPA1'] +pa2.args: None +pa3.args: ['abcArgsPA3'] +pa4.args: None +sa.args: None +psa1.args: ['abcArgsPSA1'] +psa2.args: None +psa3.args: ['abcArgsPSA3'] +psa4.args: None +a.self: None +pa1.self: None +pa2.self: None +pa3.self: {'abcSelfPA3': 'abcSelfPA3Val'} +pa4.self: {'abcSelfPA4': 'abcSelfPA4Val'} +sa.self: None +psa1.self: None +psa2.self: None +psa3.self: {'abcSelfPSA3': 'abcSelfPSA3Val'} +psa4.self: {'abcSelfPSA4': 'abcSelfPSA4Val'} +a.name: 'Args' +pa1.name: 'Args' +pa2.name: 'Args' +pa3.name: 'Args' +pa4.name: 'Args' +sa.name: 'SelfArgs' +psa1.name: 'SelfArgs' +psa2.name: 'SelfArgs' +psa3.name: 'SelfArgs' +psa4.name: 'SelfArgs' +a.auto_rebind: 1 +pa1.auto_rebind: 1 +pa2.auto_rebind: 1 +pa3.auto_rebind: 0 +pa4.auto_rebind: 0 +sa.auto_rebind: 1 +psa1.auto_rebind: 1 +psa2.auto_rebind: 1 +psa3.auto_rebind: 0 +psa4.auto_rebind: 0 +psa5.auto_rebind: 0 +psa6.auto_rebind: 0 +psa7.auto_rebind: 1 +psa8.auto_rebind: 1 +psa9.auto_rebind: 1 +psaA.auto_rebind: 1 +psaB.auto_rebind: 1 +psaC.auto_rebind: 1 +' +abcdef +Error detected while processing function RunTest[]..Test: +line : +abcdef +abcA +line : +abcB' +['a', 'dup_a'] +['a', 'a'] +['a', 'b', 'c', 'C'] +[2, 2] +[2, 2] +1 +1 +function('Put') +testdir +test86.in +src +testdir/test86.in +testdir +test86.in +> Output +>> OutputSetattr +del sys.stdout.softspace:AttributeError:('cannot delete OutputObject attributes',) +>>> Testing NumberToLong using sys.stdout.softspace = %s +sys.stdout.softspace = []:TypeError:('expected int(), long() or something supporting coercing to long(), but got list',) +sys.stdout.softspace = None:TypeError:('expected int(), long() or something supporting coercing to long(), but got NoneType',) +sys.stdout.softspace = -1:ValueError:('number must be greater or equal to zero',) +<<< Finished +>>> Testing NumberToLong using sys.stderr.softspace = %s +sys.stderr.softspace = []:TypeError:('expected int(), long() or something supporting coercing to long(), but got list',) +sys.stderr.softspace = None:TypeError:('expected int(), long() or something supporting coercing to long(), but got NoneType',) +sys.stderr.softspace = -1:ValueError:('number must be greater or equal to zero',) +<<< Finished +assert sys.stdout.isatty()==False:NOT FAILED +assert sys.stdout.seekable()==False:NOT FAILED +sys.stdout.close():NOT FAILED +sys.stdout.flush():NOT FAILED +assert sys.stderr.isatty()==False:NOT FAILED +assert sys.stderr.seekable()==False:NOT FAILED +sys.stderr.close():NOT FAILED +sys.stderr.flush():NOT FAILED +sys.stdout.attr = None:AttributeError:('invalid attribute: attr',) +>> OutputWrite +assert sys.stdout.writable()==True:NOT FAILED +assert sys.stdout.readable()==False:NOT FAILED +assert sys.stderr.writable()==True:NOT FAILED +assert sys.stderr.readable()==False:NOT FAILED +assert sys.stdout.closed()==False:NOT FAILED +assert sys.stderr.closed()==False:NOT FAILED +assert sys.stdout.errors=="strict":NOT FAILED +assert sys.stderr.errors=="strict":NOT FAILED +assert sys.stdout.encoding==sys.stderr.encoding:NOT FAILED +sys.stdout.write(None):TypeError:('coercing to Unicode: need string or buffer, NoneType found',) +>> OutputWriteLines +sys.stdout.writelines(None):TypeError:("'NoneType' object is not iterable",) +sys.stdout.writelines([1]):TypeError:('coercing to Unicode: need string or buffer, int found',) +>>> Testing *Iter* using sys.stdout.writelines(%s) +sys.stdout.writelines(FailingIter()):NotImplementedError:('iter',) +sys.stdout.writelines(FailingIterNext()):NotImplementedError:('next',) +<<< Finished +> VimCommand +>>> Testing StringToChars using vim.command(%s) +vim.command(1):TypeError:('expected str() or unicode() instance, but got int',) +vim.command(u"\0"):TypeError:('expected string without null bytes',) +vim.command("\0"):TypeError:('expected string without null bytes',) +<<< Finished +vim.command("", 2):TypeError:('command() takes exactly one argument (2 given)',) +> VimToPython +> VimEval +>>> Testing StringToChars using vim.eval(%s) +vim.eval(1):TypeError:('expected str() or unicode() instance, but got int',) +vim.eval(u"\0"):TypeError:('expected string without null bytes',) +vim.eval("\0"):TypeError:('expected string without null bytes',) +<<< Finished +vim.eval("", FailingTrue()):TypeError:('function takes exactly 1 argument (2 given)',) +> VimEvalPy +>>> Testing StringToChars using vim.bindeval(%s) +vim.bindeval(1):TypeError:('expected str() or unicode() instance, but got int',) +vim.bindeval(u"\0"):TypeError:('expected string without null bytes',) +vim.bindeval("\0"):TypeError:('expected string without null bytes',) +<<< Finished +vim.eval("", 2):TypeError:('function takes exactly 1 argument (2 given)',) +> VimStrwidth +>>> Testing StringToChars using vim.strwidth(%s) +vim.strwidth(1):TypeError:('expected str() or unicode() instance, but got int',) +vim.strwidth(u"\0"):TypeError:('expected string without null bytes',) +vim.strwidth("\0"):TypeError:('expected string without null bytes',) +<<< Finished +> VimForeachRTP +vim.foreach_rtp(None):TypeError:("'NoneType' object is not callable",) +vim.foreach_rtp(NoArgsCall()):TypeError:('__call__() takes exactly 1 argument (2 given)',) +vim.foreach_rtp(FailingCall()):NotImplementedError:('call',) +vim.foreach_rtp(int, 2):TypeError:('foreach_rtp() takes exactly one argument (2 given)',) +> import +import xxx_no_such_module_xxx:ImportError:('No module named xxx_no_such_module_xxx',) +import failing_import:ImportError:() +import failing:NotImplementedError:() +> Options +>> OptionsItem +vim.options["abcQ"]:KeyError:('abcQ',) +vim.options[""]:ValueError:('empty keys are not allowed',) +>>> Testing StringToChars using vim.options[%s] +vim.options[1]:TypeError:('expected str() or unicode() instance, but got int',) +vim.options[u"\0"]:TypeError:('expected string without null bytes',) +vim.options["\0"]:TypeError:('expected string without null bytes',) +<<< Finished +>> OptionsContains +>>> Testing StringToChars using %s in vim.options +1 in vim.options:TypeError:('expected str() or unicode() instance, but got int',) +u"\0" in vim.options:TypeError:('expected string without null bytes',) +"\0" in vim.options:TypeError:('expected string without null bytes',) +<<< Finished +> Dictionary +>> DictionaryConstructor +vim.Dictionary("abcI"):ValueError:('expected sequence element of size 2, but got sequence of size 1',) +>> DictionarySetattr +del d.locked:AttributeError:('cannot delete vim.Dictionary attributes',) +d.locked = FailingTrue():NotImplementedError:('bool',) +vim.vvars.locked = False:TypeError:('cannot modify fixed dictionary',) +d.scope = True:AttributeError:('cannot set attribute scope',) +d.xxx = True:AttributeError:('cannot set attribute xxx',) +>> _DictionaryItem +d.get("a", 2, 3):TypeError:('function takes at most 2 arguments (3 given)',) +>>> Testing StringToChars using d.get(%s) +d.get(1):TypeError:('expected str() or unicode() instance, but got int',) +d.get(u"\0"):TypeError:('expected string without null bytes',) +d.get("\0"):TypeError:('expected string without null bytes',) +<<< Finished +d.pop("a"):KeyError:('a',) +dl.pop("a"):error:('dictionary is locked',) +>> DictionaryContains +"" in d:ValueError:('empty keys are not allowed',) +0 in d:TypeError:('expected str() or unicode() instance, but got int',) +>> DictionaryIterNext +for i in ned: ned["a"] = 1:RuntimeError:('hashtab changed during iteration',) +>> DictionaryAssItem +dl["b"] = 1:error:('dictionary is locked',) +>>> Testing StringToChars using d[%s] = 1 +d[1] = 1:TypeError:('expected str() or unicode() instance, but got int',) +d[u"\0"] = 1:TypeError:('expected string without null bytes',) +d["\0"] = 1:TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using d["a"] = {%s : 1} +d["a"] = {1 : 1}:TypeError:('expected str() or unicode() instance, but got int',) +d["a"] = {u"\0" : 1}:TypeError:('expected string without null bytes',) +d["a"] = {"\0" : 1}:TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using d["a"] = {"abcF" : {%s : 1}} +d["a"] = {"abcF" : {1 : 1}}:TypeError:('expected str() or unicode() instance, but got int',) +d["a"] = {"abcF" : {u"\0" : 1}}:TypeError:('expected string without null bytes',) +d["a"] = {"abcF" : {"\0" : 1}}:TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using d["a"] = {"abcF" : Mapping({%s : 1})} +d["a"] = {"abcF" : Mapping({1 : 1})}:TypeError:('expected str() or unicode() instance, but got int',) +d["a"] = {"abcF" : Mapping({u"\0" : 1})}:TypeError:('expected string without null bytes',) +d["a"] = {"abcF" : Mapping({"\0" : 1})}:TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing *Iter* using d["a"] = {"abcF" : %s} +d["a"] = {"abcF" : FailingIter()}:TypeError:('unable to convert FailingIter to vim structure',) +d["a"] = {"abcF" : FailingIterNext()}:NotImplementedError:('next',) +<<< Finished +>>> Testing ConvertFromPyObject using d["a"] = {"abcF" : %s} +d["a"] = {"abcF" : None}:NOT FAILED +d["a"] = {"abcF" : {"": 1}}:ValueError:('empty keys are not allowed',) +d["a"] = {"abcF" : {u"": 1}}:ValueError:('empty keys are not allowed',) +d["a"] = {"abcF" : FailingMapping()}:NotImplementedError:('keys',) +d["a"] = {"abcF" : FailingMappingKey()}:NotImplementedError:('getitem:mappingkey',) +d["a"] = {"abcF" : FailingNumber()}:TypeError:('long() argument must be a string or a number',) +<<< Finished +>>> Testing StringToChars using d["a"] = Mapping({%s : 1}) +d["a"] = Mapping({1 : 1}):TypeError:('expected str() or unicode() instance, but got int',) +d["a"] = Mapping({u"\0" : 1}):TypeError:('expected string without null bytes',) +d["a"] = Mapping({"\0" : 1}):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using d["a"] = Mapping({"abcG" : {%s : 1}}) +d["a"] = Mapping({"abcG" : {1 : 1}}):TypeError:('expected str() or unicode() instance, but got int',) +d["a"] = Mapping({"abcG" : {u"\0" : 1}}):TypeError:('expected string without null bytes',) +d["a"] = Mapping({"abcG" : {"\0" : 1}}):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using d["a"] = Mapping({"abcG" : Mapping({%s : 1})}) +d["a"] = Mapping({"abcG" : Mapping({1 : 1})}):TypeError:('expected str() or unicode() instance, but got int',) +d["a"] = Mapping({"abcG" : Mapping({u"\0" : 1})}):TypeError:('expected string without null bytes',) +d["a"] = Mapping({"abcG" : Mapping({"\0" : 1})}):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing *Iter* using d["a"] = Mapping({"abcG" : %s}) +d["a"] = Mapping({"abcG" : FailingIter()}):TypeError:('unable to convert FailingIter to vim structure',) +d["a"] = Mapping({"abcG" : FailingIterNext()}):NotImplementedError:('next',) +<<< Finished +>>> Testing ConvertFromPyObject using d["a"] = Mapping({"abcG" : %s}) +d["a"] = Mapping({"abcG" : None}):NOT FAILED +d["a"] = Mapping({"abcG" : {"": 1}}):ValueError:('empty keys are not allowed',) +d["a"] = Mapping({"abcG" : {u"": 1}}):ValueError:('empty keys are not allowed',) +d["a"] = Mapping({"abcG" : FailingMapping()}):NotImplementedError:('keys',) +d["a"] = Mapping({"abcG" : FailingMappingKey()}):NotImplementedError:('getitem:mappingkey',) +d["a"] = Mapping({"abcG" : FailingNumber()}):TypeError:('long() argument must be a string or a number',) +<<< Finished +>>> Testing *Iter* using d["a"] = %s +d["a"] = FailingIter():TypeError:('unable to convert FailingIter to vim structure',) +d["a"] = FailingIterNext():NotImplementedError:('next',) +<<< Finished +>>> Testing ConvertFromPyObject using d["a"] = %s +d["a"] = None:NOT FAILED +d["a"] = {"": 1}:ValueError:('empty keys are not allowed',) +d["a"] = {u"": 1}:ValueError:('empty keys are not allowed',) +d["a"] = FailingMapping():NotImplementedError:('keys',) +d["a"] = FailingMappingKey():NotImplementedError:('getitem:mappingkey',) +d["a"] = FailingNumber():TypeError:('long() argument must be a string or a number',) +<<< Finished +>> DictionaryUpdate +>>> kwargs +>>> iter +d.update(FailingMapping()):NotImplementedError:('keys',) +d.update([FailingIterNext()]):NotImplementedError:('next',) +d.update([FailingIterNextN(1)]):NotImplementedError:('next N',) +>>> Testing *Iter* using d.update(%s) +d.update(FailingIter()):NotImplementedError:('iter',) +d.update(FailingIterNext()):NotImplementedError:('next',) +<<< Finished +>>> Testing StringToChars using d.update({%s : 1}) +d.update({1 : 1}):TypeError:('expected str() or unicode() instance, but got int',) +d.update({u"\0" : 1}):TypeError:('expected string without null bytes',) +d.update({"\0" : 1}):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using d.update({"abcF" : {%s : 1}}) +d.update({"abcF" : {1 : 1}}):TypeError:('expected str() or unicode() instance, but got int',) +d.update({"abcF" : {u"\0" : 1}}):TypeError:('expected string without null bytes',) +d.update({"abcF" : {"\0" : 1}}):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using d.update({"abcF" : Mapping({%s : 1})}) +d.update({"abcF" : Mapping({1 : 1})}):TypeError:('expected str() or unicode() instance, but got int',) +d.update({"abcF" : Mapping({u"\0" : 1})}):TypeError:('expected string without null bytes',) +d.update({"abcF" : Mapping({"\0" : 1})}):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing *Iter* using d.update({"abcF" : %s}) +d.update({"abcF" : FailingIter()}):TypeError:('unable to convert FailingIter to vim structure',) +d.update({"abcF" : FailingIterNext()}):NotImplementedError:('next',) +<<< Finished +>>> Testing ConvertFromPyObject using d.update({"abcF" : %s}) +d.update({"abcF" : None}):NOT FAILED +d.update({"abcF" : {"": 1}}):ValueError:('empty keys are not allowed',) +d.update({"abcF" : {u"": 1}}):ValueError:('empty keys are not allowed',) +d.update({"abcF" : FailingMapping()}):NotImplementedError:('keys',) +d.update({"abcF" : FailingMappingKey()}):NotImplementedError:('getitem:mappingkey',) +d.update({"abcF" : FailingNumber()}):TypeError:('long() argument must be a string or a number',) +<<< Finished +>>> Testing StringToChars using d.update(Mapping({%s : 1})) +d.update(Mapping({1 : 1})):TypeError:('expected str() or unicode() instance, but got int',) +d.update(Mapping({u"\0" : 1})):TypeError:('expected string without null bytes',) +d.update(Mapping({"\0" : 1})):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using d.update(Mapping({"abcG" : {%s : 1}})) +d.update(Mapping({"abcG" : {1 : 1}})):TypeError:('expected str() or unicode() instance, but got int',) +d.update(Mapping({"abcG" : {u"\0" : 1}})):TypeError:('expected string without null bytes',) +d.update(Mapping({"abcG" : {"\0" : 1}})):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using d.update(Mapping({"abcG" : Mapping({%s : 1})})) +d.update(Mapping({"abcG" : Mapping({1 : 1})})):TypeError:('expected str() or unicode() instance, but got int',) +d.update(Mapping({"abcG" : Mapping({u"\0" : 1})})):TypeError:('expected string without null bytes',) +d.update(Mapping({"abcG" : Mapping({"\0" : 1})})):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing *Iter* using d.update(Mapping({"abcG" : %s})) +d.update(Mapping({"abcG" : FailingIter()})):TypeError:('unable to convert FailingIter to vim structure',) +d.update(Mapping({"abcG" : FailingIterNext()})):NotImplementedError:('next',) +<<< Finished +>>> Testing ConvertFromPyObject using d.update(Mapping({"abcG" : %s})) +d.update(Mapping({"abcG" : None})):NOT FAILED +d.update(Mapping({"abcG" : {"": 1}})):ValueError:('empty keys are not allowed',) +d.update(Mapping({"abcG" : {u"": 1}})):ValueError:('empty keys are not allowed',) +d.update(Mapping({"abcG" : FailingMapping()})):NotImplementedError:('keys',) +d.update(Mapping({"abcG" : FailingMappingKey()})):NotImplementedError:('getitem:mappingkey',) +d.update(Mapping({"abcG" : FailingNumber()})):TypeError:('long() argument must be a string or a number',) +<<< Finished +>>> Testing *Iter* using d.update(%s) +d.update(FailingIter()):NotImplementedError:('iter',) +d.update(FailingIterNext()):NotImplementedError:('next',) +<<< Finished +>>> Testing ConvertFromPyObject using d.update(%s) +d.update(None):TypeError:("'NoneType' object is not iterable",) +d.update({"": 1}):ValueError:('empty keys are not allowed',) +d.update({u"": 1}):ValueError:('empty keys are not allowed',) +d.update(FailingMapping()):NotImplementedError:('keys',) +d.update(FailingMappingKey()):NotImplementedError:('getitem:mappingkey',) +d.update(FailingNumber()):TypeError:("'FailingNumber' object is not iterable",) +<<< Finished +>>> Testing StringToChars using d.update(((%s, 0),)) +d.update(((1, 0),)):TypeError:('expected str() or unicode() instance, but got int',) +d.update(((u"\0", 0),)):TypeError:('expected string without null bytes',) +d.update((("\0", 0),)):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using d.update((("a", {%s : 1}),)) +d.update((("a", {1 : 1}),)):TypeError:('expected str() or unicode() instance, but got int',) +d.update((("a", {u"\0" : 1}),)):TypeError:('expected string without null bytes',) +d.update((("a", {"\0" : 1}),)):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using d.update((("a", {"abcF" : {%s : 1}}),)) +d.update((("a", {"abcF" : {1 : 1}}),)):TypeError:('expected str() or unicode() instance, but got int',) +d.update((("a", {"abcF" : {u"\0" : 1}}),)):TypeError:('expected string without null bytes',) +d.update((("a", {"abcF" : {"\0" : 1}}),)):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using d.update((("a", {"abcF" : Mapping({%s : 1})}),)) +d.update((("a", {"abcF" : Mapping({1 : 1})}),)):TypeError:('expected str() or unicode() instance, but got int',) +d.update((("a", {"abcF" : Mapping({u"\0" : 1})}),)):TypeError:('expected string without null bytes',) +d.update((("a", {"abcF" : Mapping({"\0" : 1})}),)):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing *Iter* using d.update((("a", {"abcF" : %s}),)) +d.update((("a", {"abcF" : FailingIter()}),)):TypeError:('unable to convert FailingIter to vim structure',) +d.update((("a", {"abcF" : FailingIterNext()}),)):NotImplementedError:('next',) +<<< Finished +>>> Testing ConvertFromPyObject using d.update((("a", {"abcF" : %s}),)) +d.update((("a", {"abcF" : None}),)):error:("failed to add key 'a' to dictionary",) +d.update((("a", {"abcF" : {"": 1}}),)):ValueError:('empty keys are not allowed',) +d.update((("a", {"abcF" : {u"": 1}}),)):ValueError:('empty keys are not allowed',) +d.update((("a", {"abcF" : FailingMapping()}),)):NotImplementedError:('keys',) +d.update((("a", {"abcF" : FailingMappingKey()}),)):NotImplementedError:('getitem:mappingkey',) +d.update((("a", {"abcF" : FailingNumber()}),)):TypeError:('long() argument must be a string or a number',) +<<< Finished +>>> Testing StringToChars using d.update((("a", Mapping({%s : 1})),)) +d.update((("a", Mapping({1 : 1})),)):TypeError:('expected str() or unicode() instance, but got int',) +d.update((("a", Mapping({u"\0" : 1})),)):TypeError:('expected string without null bytes',) +d.update((("a", Mapping({"\0" : 1})),)):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using d.update((("a", Mapping({"abcG" : {%s : 1}})),)) +d.update((("a", Mapping({"abcG" : {1 : 1}})),)):TypeError:('expected str() or unicode() instance, but got int',) +d.update((("a", Mapping({"abcG" : {u"\0" : 1}})),)):TypeError:('expected string without null bytes',) +d.update((("a", Mapping({"abcG" : {"\0" : 1}})),)):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using d.update((("a", Mapping({"abcG" : Mapping({%s : 1})})),)) +d.update((("a", Mapping({"abcG" : Mapping({1 : 1})})),)):TypeError:('expected str() or unicode() instance, but got int',) +d.update((("a", Mapping({"abcG" : Mapping({u"\0" : 1})})),)):TypeError:('expected string without null bytes',) +d.update((("a", Mapping({"abcG" : Mapping({"\0" : 1})})),)):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing *Iter* using d.update((("a", Mapping({"abcG" : %s})),)) +d.update((("a", Mapping({"abcG" : FailingIter()})),)):TypeError:('unable to convert FailingIter to vim structure',) +d.update((("a", Mapping({"abcG" : FailingIterNext()})),)):NotImplementedError:('next',) +<<< Finished +>>> Testing ConvertFromPyObject using d.update((("a", Mapping({"abcG" : %s})),)) +d.update((("a", Mapping({"abcG" : None})),)):error:("failed to add key 'a' to dictionary",) +d.update((("a", Mapping({"abcG" : {"": 1}})),)):ValueError:('empty keys are not allowed',) +d.update((("a", Mapping({"abcG" : {u"": 1}})),)):ValueError:('empty keys are not allowed',) +d.update((("a", Mapping({"abcG" : FailingMapping()})),)):NotImplementedError:('keys',) +d.update((("a", Mapping({"abcG" : FailingMappingKey()})),)):NotImplementedError:('getitem:mappingkey',) +d.update((("a", Mapping({"abcG" : FailingNumber()})),)):TypeError:('long() argument must be a string or a number',) +<<< Finished +>>> Testing *Iter* using d.update((("a", %s),)) +d.update((("a", FailingIter()),)):TypeError:('unable to convert FailingIter to vim structure',) +d.update((("a", FailingIterNext()),)):NotImplementedError:('next',) +<<< Finished +>>> Testing ConvertFromPyObject using d.update((("a", %s),)) +d.update((("a", None),)):error:("failed to add key 'a' to dictionary",) +d.update((("a", {"": 1}),)):ValueError:('empty keys are not allowed',) +d.update((("a", {u"": 1}),)):ValueError:('empty keys are not allowed',) +d.update((("a", FailingMapping()),)):NotImplementedError:('keys',) +d.update((("a", FailingMappingKey()),)):NotImplementedError:('getitem:mappingkey',) +d.update((("a", FailingNumber()),)):TypeError:('long() argument must be a string or a number',) +<<< Finished +>> DictionaryPopItem +d.popitem(1, 2):TypeError:('popitem() takes no arguments (2 given)',) +>> DictionaryHasKey +d.has_key():TypeError:('has_key() takes exactly one argument (0 given)',) +> List +>> ListConstructor +vim.List(1, 2):TypeError:('function takes at most 1 argument (2 given)',) +vim.List(a=1):TypeError:('list constructor does not accept keyword arguments',) +>>> Testing *Iter* using vim.List(%s) +vim.List(FailingIter()):NotImplementedError:('iter',) +vim.List(FailingIterNext()):NotImplementedError:('next',) +<<< Finished +>>> Testing StringToChars using vim.List([{%s : 1}]) +vim.List([{1 : 1}]):TypeError:('expected str() or unicode() instance, but got int',) +vim.List([{u"\0" : 1}]):TypeError:('expected string without null bytes',) +vim.List([{"\0" : 1}]):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using vim.List([{"abcF" : {%s : 1}}]) +vim.List([{"abcF" : {1 : 1}}]):TypeError:('expected str() or unicode() instance, but got int',) +vim.List([{"abcF" : {u"\0" : 1}}]):TypeError:('expected string without null bytes',) +vim.List([{"abcF" : {"\0" : 1}}]):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using vim.List([{"abcF" : Mapping({%s : 1})}]) +vim.List([{"abcF" : Mapping({1 : 1})}]):TypeError:('expected str() or unicode() instance, but got int',) +vim.List([{"abcF" : Mapping({u"\0" : 1})}]):TypeError:('expected string without null bytes',) +vim.List([{"abcF" : Mapping({"\0" : 1})}]):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing *Iter* using vim.List([{"abcF" : %s}]) +vim.List([{"abcF" : FailingIter()}]):TypeError:('unable to convert FailingIter to vim structure',) +vim.List([{"abcF" : FailingIterNext()}]):NotImplementedError:('next',) +<<< Finished +>>> Testing ConvertFromPyObject using vim.List([{"abcF" : %s}]) +vim.List([{"abcF" : None}]):NOT FAILED +vim.List([{"abcF" : {"": 1}}]):ValueError:('empty keys are not allowed',) +vim.List([{"abcF" : {u"": 1}}]):ValueError:('empty keys are not allowed',) +vim.List([{"abcF" : FailingMapping()}]):NotImplementedError:('keys',) +vim.List([{"abcF" : FailingMappingKey()}]):NotImplementedError:('getitem:mappingkey',) +vim.List([{"abcF" : FailingNumber()}]):TypeError:('long() argument must be a string or a number',) +<<< Finished +>>> Testing StringToChars using vim.List([Mapping({%s : 1})]) +vim.List([Mapping({1 : 1})]):TypeError:('expected str() or unicode() instance, but got int',) +vim.List([Mapping({u"\0" : 1})]):TypeError:('expected string without null bytes',) +vim.List([Mapping({"\0" : 1})]):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using vim.List([Mapping({"abcG" : {%s : 1}})]) +vim.List([Mapping({"abcG" : {1 : 1}})]):TypeError:('expected str() or unicode() instance, but got int',) +vim.List([Mapping({"abcG" : {u"\0" : 1}})]):TypeError:('expected string without null bytes',) +vim.List([Mapping({"abcG" : {"\0" : 1}})]):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using vim.List([Mapping({"abcG" : Mapping({%s : 1})})]) +vim.List([Mapping({"abcG" : Mapping({1 : 1})})]):TypeError:('expected str() or unicode() instance, but got int',) +vim.List([Mapping({"abcG" : Mapping({u"\0" : 1})})]):TypeError:('expected string without null bytes',) +vim.List([Mapping({"abcG" : Mapping({"\0" : 1})})]):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing *Iter* using vim.List([Mapping({"abcG" : %s})]) +vim.List([Mapping({"abcG" : FailingIter()})]):TypeError:('unable to convert FailingIter to vim structure',) +vim.List([Mapping({"abcG" : FailingIterNext()})]):NotImplementedError:('next',) +<<< Finished +>>> Testing ConvertFromPyObject using vim.List([Mapping({"abcG" : %s})]) +vim.List([Mapping({"abcG" : None})]):NOT FAILED +vim.List([Mapping({"abcG" : {"": 1}})]):ValueError:('empty keys are not allowed',) +vim.List([Mapping({"abcG" : {u"": 1}})]):ValueError:('empty keys are not allowed',) +vim.List([Mapping({"abcG" : FailingMapping()})]):NotImplementedError:('keys',) +vim.List([Mapping({"abcG" : FailingMappingKey()})]):NotImplementedError:('getitem:mappingkey',) +vim.List([Mapping({"abcG" : FailingNumber()})]):TypeError:('long() argument must be a string or a number',) +<<< Finished +>>> Testing *Iter* using vim.List([%s]) +vim.List([FailingIter()]):TypeError:('unable to convert FailingIter to vim structure',) +vim.List([FailingIterNext()]):NotImplementedError:('next',) +<<< Finished +>>> Testing ConvertFromPyObject using vim.List([%s]) +vim.List([None]):NOT FAILED +vim.List([{"": 1}]):ValueError:('empty keys are not allowed',) +vim.List([{u"": 1}]):ValueError:('empty keys are not allowed',) +vim.List([FailingMapping()]):NotImplementedError:('keys',) +vim.List([FailingMappingKey()]):NotImplementedError:('getitem:mappingkey',) +vim.List([FailingNumber()]):TypeError:('long() argument must be a string or a number',) +<<< Finished +>> ListItem +l[1000]:IndexError:('list index out of range',) +>> ListAssItem +ll[1] = 2:error:('list is locked',) +l[1000] = 3:IndexError:('list index out of range',) +>> ListAssSlice +ll[1:100] = "abcJ":error:('list is locked',) +>>> Testing *Iter* using l[:] = %s +l[:] = FailingIter():NotImplementedError:('iter',) +l[:] = FailingIterNext():NotImplementedError:('next',) +<<< Finished +nel[1:10:2] = "abcK":ValueError:('attempt to assign sequence of size greater than 2 to extended slice',) +('a', 'b', 'c', 'O') +nel[1:10:2] = "a":ValueError:('attempt to assign sequence of size 1 to extended slice of size 2',) +('a', 'b', 'c', 'O') +nel[1:1:-1] = "a":ValueError:('attempt to assign sequence of size greater than 0 to extended slice',) +('a', 'b', 'c', 'O') +nel[:] = FailingIterNextN(2):NotImplementedError:('next N',) +('a', 'b', 'c', 'O') +>>> Testing StringToChars using l[:] = [{%s : 1}] +l[:] = [{1 : 1}]:TypeError:('expected str() or unicode() instance, but got int',) +l[:] = [{u"\0" : 1}]:TypeError:('expected string without null bytes',) +l[:] = [{"\0" : 1}]:TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using l[:] = [{"abcF" : {%s : 1}}] +l[:] = [{"abcF" : {1 : 1}}]:TypeError:('expected str() or unicode() instance, but got int',) +l[:] = [{"abcF" : {u"\0" : 1}}]:TypeError:('expected string without null bytes',) +l[:] = [{"abcF" : {"\0" : 1}}]:TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using l[:] = [{"abcF" : Mapping({%s : 1})}] +l[:] = [{"abcF" : Mapping({1 : 1})}]:TypeError:('expected str() or unicode() instance, but got int',) +l[:] = [{"abcF" : Mapping({u"\0" : 1})}]:TypeError:('expected string without null bytes',) +l[:] = [{"abcF" : Mapping({"\0" : 1})}]:TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing *Iter* using l[:] = [{"abcF" : %s}] +l[:] = [{"abcF" : FailingIter()}]:TypeError:('unable to convert FailingIter to vim structure',) +l[:] = [{"abcF" : FailingIterNext()}]:NotImplementedError:('next',) +<<< Finished +>>> Testing ConvertFromPyObject using l[:] = [{"abcF" : %s}] +l[:] = [{"abcF" : None}]:NOT FAILED +l[:] = [{"abcF" : {"": 1}}]:ValueError:('empty keys are not allowed',) +l[:] = [{"abcF" : {u"": 1}}]:ValueError:('empty keys are not allowed',) +l[:] = [{"abcF" : FailingMapping()}]:NotImplementedError:('keys',) +l[:] = [{"abcF" : FailingMappingKey()}]:NotImplementedError:('getitem:mappingkey',) +l[:] = [{"abcF" : FailingNumber()}]:TypeError:('long() argument must be a string or a number',) +<<< Finished +>>> Testing StringToChars using l[:] = [Mapping({%s : 1})] +l[:] = [Mapping({1 : 1})]:TypeError:('expected str() or unicode() instance, but got int',) +l[:] = [Mapping({u"\0" : 1})]:TypeError:('expected string without null bytes',) +l[:] = [Mapping({"\0" : 1})]:TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using l[:] = [Mapping({"abcG" : {%s : 1}})] +l[:] = [Mapping({"abcG" : {1 : 1}})]:TypeError:('expected str() or unicode() instance, but got int',) +l[:] = [Mapping({"abcG" : {u"\0" : 1}})]:TypeError:('expected string without null bytes',) +l[:] = [Mapping({"abcG" : {"\0" : 1}})]:TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using l[:] = [Mapping({"abcG" : Mapping({%s : 1})})] +l[:] = [Mapping({"abcG" : Mapping({1 : 1})})]:TypeError:('expected str() or unicode() instance, but got int',) +l[:] = [Mapping({"abcG" : Mapping({u"\0" : 1})})]:TypeError:('expected string without null bytes',) +l[:] = [Mapping({"abcG" : Mapping({"\0" : 1})})]:TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing *Iter* using l[:] = [Mapping({"abcG" : %s})] +l[:] = [Mapping({"abcG" : FailingIter()})]:TypeError:('unable to convert FailingIter to vim structure',) +l[:] = [Mapping({"abcG" : FailingIterNext()})]:NotImplementedError:('next',) +<<< Finished +>>> Testing ConvertFromPyObject using l[:] = [Mapping({"abcG" : %s})] +l[:] = [Mapping({"abcG" : None})]:NOT FAILED +l[:] = [Mapping({"abcG" : {"": 1}})]:ValueError:('empty keys are not allowed',) +l[:] = [Mapping({"abcG" : {u"": 1}})]:ValueError:('empty keys are not allowed',) +l[:] = [Mapping({"abcG" : FailingMapping()})]:NotImplementedError:('keys',) +l[:] = [Mapping({"abcG" : FailingMappingKey()})]:NotImplementedError:('getitem:mappingkey',) +l[:] = [Mapping({"abcG" : FailingNumber()})]:TypeError:('long() argument must be a string or a number',) +<<< Finished +>>> Testing *Iter* using l[:] = [%s] +l[:] = [FailingIter()]:TypeError:('unable to convert FailingIter to vim structure',) +l[:] = [FailingIterNext()]:NotImplementedError:('next',) +<<< Finished +>>> Testing ConvertFromPyObject using l[:] = [%s] +l[:] = [None]:NOT FAILED +l[:] = [{"": 1}]:ValueError:('empty keys are not allowed',) +l[:] = [{u"": 1}]:ValueError:('empty keys are not allowed',) +l[:] = [FailingMapping()]:NotImplementedError:('keys',) +l[:] = [FailingMappingKey()]:NotImplementedError:('getitem:mappingkey',) +l[:] = [FailingNumber()]:TypeError:('long() argument must be a string or a number',) +<<< Finished +>> ListConcatInPlace +>>> Testing *Iter* using l.extend(%s) +l.extend(FailingIter()):NotImplementedError:('iter',) +l.extend(FailingIterNext()):NotImplementedError:('next',) +<<< Finished +>>> Testing StringToChars using l.extend([{%s : 1}]) +l.extend([{1 : 1}]):TypeError:('expected str() or unicode() instance, but got int',) +l.extend([{u"\0" : 1}]):TypeError:('expected string without null bytes',) +l.extend([{"\0" : 1}]):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using l.extend([{"abcF" : {%s : 1}}]) +l.extend([{"abcF" : {1 : 1}}]):TypeError:('expected str() or unicode() instance, but got int',) +l.extend([{"abcF" : {u"\0" : 1}}]):TypeError:('expected string without null bytes',) +l.extend([{"abcF" : {"\0" : 1}}]):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using l.extend([{"abcF" : Mapping({%s : 1})}]) +l.extend([{"abcF" : Mapping({1 : 1})}]):TypeError:('expected str() or unicode() instance, but got int',) +l.extend([{"abcF" : Mapping({u"\0" : 1})}]):TypeError:('expected string without null bytes',) +l.extend([{"abcF" : Mapping({"\0" : 1})}]):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing *Iter* using l.extend([{"abcF" : %s}]) +l.extend([{"abcF" : FailingIter()}]):TypeError:('unable to convert FailingIter to vim structure',) +l.extend([{"abcF" : FailingIterNext()}]):NotImplementedError:('next',) +<<< Finished +>>> Testing ConvertFromPyObject using l.extend([{"abcF" : %s}]) +l.extend([{"abcF" : None}]):NOT FAILED +l.extend([{"abcF" : {"": 1}}]):ValueError:('empty keys are not allowed',) +l.extend([{"abcF" : {u"": 1}}]):ValueError:('empty keys are not allowed',) +l.extend([{"abcF" : FailingMapping()}]):NotImplementedError:('keys',) +l.extend([{"abcF" : FailingMappingKey()}]):NotImplementedError:('getitem:mappingkey',) +l.extend([{"abcF" : FailingNumber()}]):TypeError:('long() argument must be a string or a number',) +<<< Finished +>>> Testing StringToChars using l.extend([Mapping({%s : 1})]) +l.extend([Mapping({1 : 1})]):TypeError:('expected str() or unicode() instance, but got int',) +l.extend([Mapping({u"\0" : 1})]):TypeError:('expected string without null bytes',) +l.extend([Mapping({"\0" : 1})]):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using l.extend([Mapping({"abcG" : {%s : 1}})]) +l.extend([Mapping({"abcG" : {1 : 1}})]):TypeError:('expected str() or unicode() instance, but got int',) +l.extend([Mapping({"abcG" : {u"\0" : 1}})]):TypeError:('expected string without null bytes',) +l.extend([Mapping({"abcG" : {"\0" : 1}})]):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using l.extend([Mapping({"abcG" : Mapping({%s : 1})})]) +l.extend([Mapping({"abcG" : Mapping({1 : 1})})]):TypeError:('expected str() or unicode() instance, but got int',) +l.extend([Mapping({"abcG" : Mapping({u"\0" : 1})})]):TypeError:('expected string without null bytes',) +l.extend([Mapping({"abcG" : Mapping({"\0" : 1})})]):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing *Iter* using l.extend([Mapping({"abcG" : %s})]) +l.extend([Mapping({"abcG" : FailingIter()})]):TypeError:('unable to convert FailingIter to vim structure',) +l.extend([Mapping({"abcG" : FailingIterNext()})]):NotImplementedError:('next',) +<<< Finished +>>> Testing ConvertFromPyObject using l.extend([Mapping({"abcG" : %s})]) +l.extend([Mapping({"abcG" : None})]):NOT FAILED +l.extend([Mapping({"abcG" : {"": 1}})]):ValueError:('empty keys are not allowed',) +l.extend([Mapping({"abcG" : {u"": 1}})]):ValueError:('empty keys are not allowed',) +l.extend([Mapping({"abcG" : FailingMapping()})]):NotImplementedError:('keys',) +l.extend([Mapping({"abcG" : FailingMappingKey()})]):NotImplementedError:('getitem:mappingkey',) +l.extend([Mapping({"abcG" : FailingNumber()})]):TypeError:('long() argument must be a string or a number',) +<<< Finished +>>> Testing *Iter* using l.extend([%s]) +l.extend([FailingIter()]):TypeError:('unable to convert FailingIter to vim structure',) +l.extend([FailingIterNext()]):NotImplementedError:('next',) +<<< Finished +>>> Testing ConvertFromPyObject using l.extend([%s]) +l.extend([None]):NOT FAILED +l.extend([{"": 1}]):ValueError:('empty keys are not allowed',) +l.extend([{u"": 1}]):ValueError:('empty keys are not allowed',) +l.extend([FailingMapping()]):NotImplementedError:('keys',) +l.extend([FailingMappingKey()]):NotImplementedError:('getitem:mappingkey',) +l.extend([FailingNumber()]):TypeError:('long() argument must be a string or a number',) +<<< Finished +>> ListSetattr +del l.locked:AttributeError:('cannot delete vim.List attributes',) +l.locked = FailingTrue():NotImplementedError:('bool',) +l.xxx = True:AttributeError:('cannot set attribute xxx',) +> Function +>> FunctionConstructor +>>> FunctionConstructor +vim.Function("123"):ValueError:('unnamed function 123 does not exist',) +vim.Function("xxx_non_existent_function_xxx"):ValueError:('function xxx_non_existent_function_xxx does not exist',) +vim.Function("xxx#non#existent#function#xxx"):NOT FAILED +vim.Function("xxx_non_existent_function_xxx2", args=[]):ValueError:('function xxx_non_existent_function_xxx2 does not exist',) +vim.Function("xxx_non_existent_function_xxx3", self={}):ValueError:('function xxx_non_existent_function_xxx3 does not exist',) +vim.Function("xxx_non_existent_function_xxx4", args=[], self={}):ValueError:('function xxx_non_existent_function_xxx4 does not exist',) +>>> FunctionNew +vim.Function("tr", self="abcFuncSelf"):TypeError:('unable to convert str to vim dictionary',) +vim.Function("tr", args=427423):TypeError:('unable to convert int to vim list',) +vim.Function("tr", self="abcFuncSelf2", args="abcFuncArgs2"):TypeError:('unable to convert str to vim dictionary',) +vim.Function(self="abcFuncSelf2", args="abcFuncArgs2"):TypeError:('unable to convert str to vim dictionary',) +vim.Function("tr", "", self="abcFuncSelf2", args="abcFuncArgs2"):TypeError:('unable to convert str to vim dictionary',) +vim.Function("tr", ""):TypeError:('function takes exactly 1 argument (2 given)',) +>> FunctionCall +>>> Testing StringToChars using f({%s : 1}) +f({1 : 1}):TypeError:('expected str() or unicode() instance, but got int',) +f({u"\0" : 1}):TypeError:('expected string without null bytes',) +f({"\0" : 1}):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using f({"abcF" : {%s : 1}}) +f({"abcF" : {1 : 1}}):TypeError:('expected str() or unicode() instance, but got int',) +f({"abcF" : {u"\0" : 1}}):TypeError:('expected string without null bytes',) +f({"abcF" : {"\0" : 1}}):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using f({"abcF" : Mapping({%s : 1})}) +f({"abcF" : Mapping({1 : 1})}):TypeError:('expected str() or unicode() instance, but got int',) +f({"abcF" : Mapping({u"\0" : 1})}):TypeError:('expected string without null bytes',) +f({"abcF" : Mapping({"\0" : 1})}):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing *Iter* using f({"abcF" : %s}) +f({"abcF" : FailingIter()}):TypeError:('unable to convert FailingIter to vim structure',) +f({"abcF" : FailingIterNext()}):NotImplementedError:('next',) +<<< Finished +>>> Testing ConvertFromPyObject using f({"abcF" : %s}) +f({"abcF" : None}):NOT FAILED +f({"abcF" : {"": 1}}):ValueError:('empty keys are not allowed',) +f({"abcF" : {u"": 1}}):ValueError:('empty keys are not allowed',) +f({"abcF" : FailingMapping()}):NotImplementedError:('keys',) +f({"abcF" : FailingMappingKey()}):NotImplementedError:('getitem:mappingkey',) +f({"abcF" : FailingNumber()}):TypeError:('long() argument must be a string or a number',) +<<< Finished +>>> Testing StringToChars using f(Mapping({%s : 1})) +f(Mapping({1 : 1})):TypeError:('expected str() or unicode() instance, but got int',) +f(Mapping({u"\0" : 1})):TypeError:('expected string without null bytes',) +f(Mapping({"\0" : 1})):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using f(Mapping({"abcG" : {%s : 1}})) +f(Mapping({"abcG" : {1 : 1}})):TypeError:('expected str() or unicode() instance, but got int',) +f(Mapping({"abcG" : {u"\0" : 1}})):TypeError:('expected string without null bytes',) +f(Mapping({"abcG" : {"\0" : 1}})):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using f(Mapping({"abcG" : Mapping({%s : 1})})) +f(Mapping({"abcG" : Mapping({1 : 1})})):TypeError:('expected str() or unicode() instance, but got int',) +f(Mapping({"abcG" : Mapping({u"\0" : 1})})):TypeError:('expected string without null bytes',) +f(Mapping({"abcG" : Mapping({"\0" : 1})})):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing *Iter* using f(Mapping({"abcG" : %s})) +f(Mapping({"abcG" : FailingIter()})):TypeError:('unable to convert FailingIter to vim structure',) +f(Mapping({"abcG" : FailingIterNext()})):NotImplementedError:('next',) +<<< Finished +>>> Testing ConvertFromPyObject using f(Mapping({"abcG" : %s})) +f(Mapping({"abcG" : None})):NOT FAILED +f(Mapping({"abcG" : {"": 1}})):ValueError:('empty keys are not allowed',) +f(Mapping({"abcG" : {u"": 1}})):ValueError:('empty keys are not allowed',) +f(Mapping({"abcG" : FailingMapping()})):NotImplementedError:('keys',) +f(Mapping({"abcG" : FailingMappingKey()})):NotImplementedError:('getitem:mappingkey',) +f(Mapping({"abcG" : FailingNumber()})):TypeError:('long() argument must be a string or a number',) +<<< Finished +>>> Testing *Iter* using f(%s) +f(FailingIter()):TypeError:('unable to convert FailingIter to vim structure',) +f(FailingIterNext()):NotImplementedError:('next',) +<<< Finished +>>> Testing ConvertFromPyObject using f(%s) +f(None):NOT FAILED +f({"": 1}):ValueError:('empty keys are not allowed',) +f({u"": 1}):ValueError:('empty keys are not allowed',) +f(FailingMapping()):NotImplementedError:('keys',) +f(FailingMappingKey()):NotImplementedError:('getitem:mappingkey',) +f(FailingNumber()):TypeError:('long() argument must be a string or a number',) +<<< Finished +>>> Testing StringToChars using fd(self={%s : 1}) +fd(self={1 : 1}):TypeError:('expected str() or unicode() instance, but got int',) +fd(self={u"\0" : 1}):TypeError:('expected string without null bytes',) +fd(self={"\0" : 1}):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using fd(self={"abcF" : {%s : 1}}) +fd(self={"abcF" : {1 : 1}}):TypeError:('expected str() or unicode() instance, but got int',) +fd(self={"abcF" : {u"\0" : 1}}):TypeError:('expected string without null bytes',) +fd(self={"abcF" : {"\0" : 1}}):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using fd(self={"abcF" : Mapping({%s : 1})}) +fd(self={"abcF" : Mapping({1 : 1})}):TypeError:('expected str() or unicode() instance, but got int',) +fd(self={"abcF" : Mapping({u"\0" : 1})}):TypeError:('expected string without null bytes',) +fd(self={"abcF" : Mapping({"\0" : 1})}):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing *Iter* using fd(self={"abcF" : %s}) +fd(self={"abcF" : FailingIter()}):TypeError:('unable to convert FailingIter to vim structure',) +fd(self={"abcF" : FailingIterNext()}):NotImplementedError:('next',) +<<< Finished +>>> Testing ConvertFromPyObject using fd(self={"abcF" : %s}) +fd(self={"abcF" : None}):NOT FAILED +fd(self={"abcF" : {"": 1}}):ValueError:('empty keys are not allowed',) +fd(self={"abcF" : {u"": 1}}):ValueError:('empty keys are not allowed',) +fd(self={"abcF" : FailingMapping()}):NotImplementedError:('keys',) +fd(self={"abcF" : FailingMappingKey()}):NotImplementedError:('getitem:mappingkey',) +fd(self={"abcF" : FailingNumber()}):TypeError:('long() argument must be a string or a number',) +<<< Finished +>>> Testing StringToChars using fd(self=Mapping({%s : 1})) +fd(self=Mapping({1 : 1})):TypeError:('expected str() or unicode() instance, but got int',) +fd(self=Mapping({u"\0" : 1})):TypeError:('expected string without null bytes',) +fd(self=Mapping({"\0" : 1})):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using fd(self=Mapping({"abcG" : {%s : 1}})) +fd(self=Mapping({"abcG" : {1 : 1}})):TypeError:('expected str() or unicode() instance, but got int',) +fd(self=Mapping({"abcG" : {u"\0" : 1}})):TypeError:('expected string without null bytes',) +fd(self=Mapping({"abcG" : {"\0" : 1}})):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing StringToChars using fd(self=Mapping({"abcG" : Mapping({%s : 1})})) +fd(self=Mapping({"abcG" : Mapping({1 : 1})})):TypeError:('expected str() or unicode() instance, but got int',) +fd(self=Mapping({"abcG" : Mapping({u"\0" : 1})})):TypeError:('expected string without null bytes',) +fd(self=Mapping({"abcG" : Mapping({"\0" : 1})})):TypeError:('expected string without null bytes',) +<<< Finished +>>> Testing *Iter* using fd(self=Mapping({"abcG" : %s})) +fd(self=Mapping({"abcG" : FailingIter()})):TypeError:('unable to convert FailingIter to vim structure',) +fd(self=Mapping({"abcG" : FailingIterNext()})):NotImplementedError:('next',) +<<< Finished +>>> Testing ConvertFromPyObject using fd(self=Mapping({"abcG" : %s})) +fd(self=Mapping({"abcG" : None})):NOT FAILED +fd(self=Mapping({"abcG" : {"": 1}})):ValueError:('empty keys are not allowed',) +fd(self=Mapping({"abcG" : {u"": 1}})):ValueError:('empty keys are not allowed',) +fd(self=Mapping({"abcG" : FailingMapping()})):NotImplementedError:('keys',) +fd(self=Mapping({"abcG" : FailingMappingKey()})):NotImplementedError:('getitem:mappingkey',) +fd(self=Mapping({"abcG" : FailingNumber()})):TypeError:('long() argument must be a string or a number',) +<<< Finished +>>> Testing *Iter* using fd(self=%s) +fd(self=FailingIter()):TypeError:('unable to convert FailingIter to vim dictionary',) +fd(self=FailingIterNext()):TypeError:('unable to convert FailingIterNext to vim dictionary',) +<<< Finished +>>> Testing ConvertFromPyObject using fd(self=%s) +fd(self=None):TypeError:('unable to convert NoneType to vim dictionary',) +fd(self={"": 1}):ValueError:('empty keys are not allowed',) +fd(self={u"": 1}):ValueError:('empty keys are not allowed',) +fd(self=FailingMapping()):NotImplementedError:('keys',) +fd(self=FailingMappingKey()):NotImplementedError:('getitem:mappingkey',) +fd(self=FailingNumber()):TypeError:('unable to convert FailingNumber to vim dictionary',) +<<< Finished +>>> Testing ConvertFromPyMapping using fd(self=%s) +fd(self=[]):TypeError:('unable to convert list to vim dictionary',) +<<< Finished +> TabPage +>> TabPageAttr +vim.current.tabpage.xxx:AttributeError:('xxx',) +> TabList +>> TabListItem +vim.tabpages[1000]:IndexError:('no such tab page',) +> Window +>> WindowAttr +vim.current.window.xxx:AttributeError:('xxx',) +>> WindowSetattr +vim.current.window.buffer = 0:TypeError:('readonly attribute: buffer',) +vim.current.window.cursor = (100000000, 100000000):error:('cursor position outside buffer',) +vim.current.window.cursor = True:TypeError:('argument must be 2-item sequence, not bool',) +>>> Testing NumberToLong using vim.current.window.height = %s +vim.current.window.height = []:TypeError:('expected int(), long() or something supporting coercing to long(), but got list',) +vim.current.window.height = None:TypeError:('expected int(), long() or something supporting coercing to long(), but got NoneType',) +vim.current.window.height = -1:ValueError:('number must be greater or equal to zero',) +<<< Finished +>>> Testing NumberToLong using vim.current.window.width = %s +vim.current.window.width = []:TypeError:('expected int(), long() or something supporting coercing to long(), but got list',) +vim.current.window.width = None:TypeError:('expected int(), long() or something supporting coercing to long(), but got NoneType',) +vim.current.window.width = -1:ValueError:('number must be greater or equal to zero',) +<<< Finished +vim.current.window.xxxxxx = True:AttributeError:('xxxxxx',) +> WinList +>> WinListItem +vim.windows[1000]:IndexError:('no such window',) +> Buffer +>> StringToLine (indirect) +vim.current.buffer[0] = u"\na":error:('string cannot contain newlines',) +vim.current.buffer[0] = "\na":error:('string cannot contain newlines',) +>> SetBufferLine (indirect) +vim.current.buffer[0] = True:TypeError:('bad argument type for built-in operation',) +>> SetBufferLineList (indirect) +vim.current.buffer[:] = True:TypeError:('bad argument type for built-in operation',) +vim.current.buffer[:] = ["\na", "bc"]:error:('string cannot contain newlines',) +>> InsertBufferLines (indirect) +vim.current.buffer.append(None):TypeError:('bad argument type for built-in operation',) +vim.current.buffer.append(["\na", "bc"]):error:('string cannot contain newlines',) +vim.current.buffer.append("\nbc"):error:('string cannot contain newlines',) +>> RBItem +vim.current.buffer[100000000]:IndexError:('line number out of range',) +>> RBAsItem +vim.current.buffer[100000000] = "":IndexError:('line number out of range',) +>> BufferAttr +vim.current.buffer.xxx:AttributeError:('xxx',) +>> BufferSetattr +vim.current.buffer.name = True:TypeError:('expected str() or unicode() instance, but got bool',) +vim.current.buffer.xxx = True:AttributeError:('xxx',) +>> BufferMark +vim.current.buffer.mark(0):TypeError:('expected str() or unicode() instance, but got int',) +vim.current.buffer.mark("abcM"):ValueError:('mark name must be a single character',) +vim.current.buffer.mark("!"):error:('invalid mark name',) +>> BufferRange +vim.current.buffer.range(1, 2, 3):TypeError:('function takes exactly 2 arguments (3 given)',) +> BufMap +>> BufMapItem +vim.buffers[100000000]:KeyError:(100000000,) +>>> Testing NumberToLong using vim.buffers[%s] +vim.buffers[[]]:TypeError:('expected int(), long() or something supporting coercing to long(), but got list',) +vim.buffers[None]:TypeError:('expected int(), long() or something supporting coercing to long(), but got NoneType',) +vim.buffers[-1]:ValueError:('number must be greater than zero',) +vim.buffers[0]:ValueError:('number must be greater than zero',) +<<< Finished +> Current +>> CurrentGetattr +vim.current.xxx:AttributeError:('xxx',) +>> CurrentSetattr +vim.current.line = True:TypeError:('bad argument type for built-in operation',) +vim.current.buffer = True:TypeError:('expected vim.Buffer object, but got bool',) +vim.current.window = True:TypeError:('expected vim.Window object, but got bool',) +vim.current.tabpage = True:TypeError:('expected vim.TabPage object, but got bool',) +vim.current.xxx = True:AttributeError:('xxx',) +['/testdir'] +'/testdir' +2,xx +before +after +pythonx/topmodule/__init__.py +pythonx/topmodule/submodule/__init__.py +pythonx/topmodule/submodule/subsubmodule/subsubsubmodule.py +vim.command("throw 'abcN'"):error:('abcN',) +Exe("throw 'def'"):error:('def',) +vim.eval("Exe('throw ''ghi''')"):error:('ghi',) +vim.eval("Exe('echoerr ''jkl''')"):error:('Vim(echoerr):jkl',) +vim.eval("Exe('xxx_non_existent_command_xxx')"):error:('Vim:E492: Not an editor command: xxx_non_existent_command_xxx',) +vim.eval("xxx_unknown_function_xxx()"):error:('Vim:E117: Unknown function: xxx_unknown_function_xxx',) +vim.bindeval("Exe('xxx_non_existent_command_xxx')"):error:('Vim:E492: Not an editor command: xxx_non_existent_command_xxx',) +Caught KeyboardInterrupt +Running :put +No exception + diff --git a/src/testdir/test87.in b/src/testdir/test87.in new file mode 100644 index 0000000..31de37b --- /dev/null +++ b/src/testdir/test87.in @@ -0,0 +1,1725 @@ +Tests for various python features. vim: set ft=vim : + +STARTTEST +:so small.vim +:set noswapfile +:if !has('python3') | e! test.ok | wq! test.out | endif +:lang C +:fun Test() +:py3 import vim +:py3 cb = vim.current.buffer +:let l = [] +:py3 l=vim.bindeval('l') +:py3 f=vim.bindeval('function("strlen")') +:" Extending List directly with different types +:py3 l+=[1, "as'd", [1, 2, f, {'a': 1}]] +:$put =string(l) +:$put =string(l[-1]) +:try +: $put =string(l[-4]) +:catch +: $put =v:exception[:13] +:endtry +:" List assignment +:py3 l[0]=0 +:$put =string(l) +:py3 l[-2]=f +:$put =string(l) +:" +:" Extending Dictionary directly with different types +:let d = {} +:fun d.f() +: return 1 +:endfun +py3 << EOF +d=vim.bindeval('d') +d['1']='asd' +d.update() # Must not do anything, including throwing errors +d.update(b=[1, 2, f]) +d.update((('-1', {'a': 1}),)) +d.update({'0': -1}) +dk = d.keys() +dv = d.values() +di = d.items() +dk.sort(key=repr) +dv.sort(key=repr) +di.sort(key=repr) +EOF +:$put =py3eval('d[''f''](self={})') +:$put =py3eval('repr(dk)') +:$put =substitute(py3eval('repr(dv)'),'0x\x\+','','g') +:$put =substitute(py3eval('repr(di)'),'0x\x\+','','g') +:for [key, Val] in sort(items(d)) +: $put =string(key) . ' : ' . string(Val) +: unlet key Val +:endfor +:py3 del dk +:py3 del di +:py3 del dv +:" +:" removing items with del +:py3 del l[2] +:$put =string(l) +:let l = range(8) +:py3 l=vim.bindeval('l') +:try +: py3 del l[:3] +: py3 del l[1:] +:catch +: $put =v:exception +:endtry +:$put =string(l) +:" +:py3 del d['-1'] +:py3 del d['f'] +:$put =string(py3eval('d.get(''b'', 1)')) +:$put =string(py3eval('d.pop(''b'')')) +:$put =string(py3eval('d.get(''b'', 1)')) +:$put =string(py3eval('d.pop(''1'', 2)')) +:$put =string(py3eval('d.pop(''1'', 2)')) +:$put =py3eval('repr(d.has_key(''0''))') +:$put =py3eval('repr(d.has_key(''1''))') +:$put =py3eval('repr(''0'' in d)') +:$put =py3eval('repr(''1'' in d)') +:$put =py3eval('repr(list(iter(d)))') +:$put =string(d) +:$put =py3eval('repr(d.popitem())') +:$put =py3eval('repr(d.get(''0''))') +:$put =py3eval('repr(list(iter(d)))') +:" +:" removing items out of range: silently skip items that don't exist +:let l = [0, 1, 2, 3] +:py3 l=vim.bindeval('l') +:" The following two ranges delete nothing as they match empty list: +:py3 del l[2:1] +:$put =string(l) +:py3 del l[2:2] +:$put =string(l) +:py3 del l[2:3] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py3 l=vim.bindeval('l') +:py3 del l[2:4] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py3 l=vim.bindeval('l') +:py3 del l[2:5] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py3 l=vim.bindeval('l') +:py3 del l[2:6] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py3 l=vim.bindeval('l') +:" The following two ranges delete nothing as they match empty list: +:py3 del l[-1:2] +:$put =string(l) +:py3 del l[-2:2] +:$put =string(l) +:py3 del l[-3:2] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py3 l=vim.bindeval('l') +:py3 del l[-4:2] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py3 l=vim.bindeval('l') +:py3 del l[-5:2] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py3 l=vim.bindeval('l') +:py3 del l[-6:2] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py3 l=vim.bindeval('l') +:py3 del l[::2] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py3 l=vim.bindeval('l') +:py3 del l[3:0:-2] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py3 l=vim.bindeval('l') +:py3 del l[2:4:-2] +:$put =string(l) +:" +:" Slice assignment to a list +:let l = [0, 1, 2, 3] +:py3 l=vim.bindeval('l') +:py3 l[0:0]=['a'] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py3 l=vim.bindeval('l') +:py3 l[1:2]=['b'] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py3 l=vim.bindeval('l') +:py3 l[2:4]=['c'] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py3 l=vim.bindeval('l') +:py3 l[4:4]=['d'] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py3 l=vim.bindeval('l') +:py3 l[-1:2]=['e'] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py3 l=vim.bindeval('l') +:py3 l[-10:2]=['f'] +:$put =string(l) +:let l = [0, 1, 2, 3] +:py3 l=vim.bindeval('l') +:py3 l[2:-10]=['g'] +:$put =string(l) +:let l = [] +:py3 l=vim.bindeval('l') +:py3 l[0:0]=['h'] +:$put =string(l) +:let l = range(8) +:py3 l=vim.bindeval('l') +:py3 l[2:6:2] = [10, 20] +:$put =string(l) +:let l = range(8) +:py3 l=vim.bindeval('l') +:py3 l[6:2:-2] = [10, 20] +:$put =string(l) +:let l = range(8) +:py3 l=vim.bindeval('l') +:py3 l[6:2] = () +:$put =string(l) +:let l = range(8) +:py3 l=vim.bindeval('l') +:py3 l[6:2:1] = () +:$put =string(l) +:let l = range(8) +:py3 l=vim.bindeval('l') +:py3 l[2:2:1] = () +:$put =string(l) +:" +:" Locked variables +:let l = [0, 1, 2, 3] +:py3 l=vim.bindeval('l') +:lockvar! l +py3 << EOF +def emsg(ei): + return ei[0].__name__ + ':' + repr(ei[1].args) + +try: + l[2]='i' +except vim.error: + cb.append('l[2] threw vim.error: ' + emsg(sys.exc_info())) +EOF +:$put =string(l) +:unlockvar! l +:" +:" Function calls +py3 << EOF +import sys +import re + +py33_type_error_pattern = re.compile('^__call__\(\) takes (\d+) positional argument but (\d+) were given$') +py37_exception_repr = re.compile(r'([^\(\),])(\)+)$') + +def ee(expr, g=globals(), l=locals()): + cb = vim.current.buffer + try: + try: + exec(expr, g, l) + except Exception as e: + if sys.version_info >= (3, 3) and e.__class__ is AttributeError and str(e).find('has no attribute')>=0 and not str(e).startswith("'vim."): + msg = repr((e.__class__, AttributeError(str(e)[str(e).rfind(" '") + 2:-1]))) + elif sys.version_info >= (3, 3) and e.__class__ is ImportError and str(e).find('No module named \'') >= 0: + msg = repr((e.__class__, ImportError(str(e).replace("'", '')))) + elif sys.version_info >= (3, 6) and e.__class__ is ModuleNotFoundError: + # Python 3.6 gives ModuleNotFoundError, change it to an ImportError + msg = repr((ImportError, ImportError(str(e).replace("'", '')))) + elif sys.version_info >= (3, 3) and e.__class__ is TypeError: + m = py33_type_error_pattern.search(str(e)) + if m: + msg = '__call__() takes exactly {0} positional argument ({1} given)'.format(m.group(1), m.group(2)) + msg = repr((e.__class__, TypeError(msg))) + else: + msg = repr((e.__class__, e)) + # Messages changed with Python 3.6, change new to old. + newmsg1 = """'argument must be str, bytes or bytearray, not None'""" + oldmsg1 = '''"Can't convert 'NoneType' object to str implicitly"''' + if msg.find(newmsg1) > -1: + msg = msg.replace(newmsg1, oldmsg1) + newmsg2 = """'argument must be str, bytes or bytearray, not int'""" + oldmsg2 = '''"Can't convert 'int' object to str implicitly"''' + if msg.find(newmsg2) > -1: + msg = msg.replace(newmsg2, oldmsg2) + elif sys.version_info >= (3, 5) and e.__class__ is ValueError and str(e) == 'embedded null byte': + msg = repr((TypeError, TypeError('expected bytes with no null'))) + else: + msg = repr((e.__class__, e)) + # Some Python versions say can't, others cannot. + if msg.find('can\'t') > -1: + msg = msg.replace('can\'t', 'cannot') + # Some Python versions use single quote, some double quote + if msg.find('"cannot ') > -1: + msg = msg.replace('"cannot ', '\'cannot ') + if msg.find(' attributes"') > -1: + msg = msg.replace(' attributes"', ' attributes\'') + if sys.version_info >= (3, 7): + msg = py37_exception_repr.sub(r'\1,\2', msg) + cb.append(expr + ':' + msg) + else: + cb.append(expr + ':NOT FAILED') + except Exception as e: + msg = repr((e.__class__, e)) + if sys.version_info >= (3, 7): + msg = py37_exception_repr.sub(r'\1,\2', msg) + cb.append(expr + '::' + msg) +EOF +:fun New(...) +: return ['NewStart']+a:000+['NewEnd'] +:endfun +:fun DictNew(...) dict +: return ['DictNewStart']+a:000+['DictNewEnd', self] +:endfun +:let l=[function('New'), function('DictNew')] +:py3 l=vim.bindeval('l') +:py3 l.extend(list(l[0](1, 2, 3))) +:$put =string(l) +:py3 l.extend(list(l[1](1, 2, 3, self={'a': 'b'}))) +:$put =string(l) +:py3 l+=[l[0].name] +:$put =string(l) +:py3 ee('l[1](1, 2, 3)') +:py3 f=l[0] +:delfunction New +:py3 ee('f(1, 2, 3)') +:if has('float') +: let l=[0.0] +: py3 l=vim.bindeval('l') +: py3 l.extend([0.0]) +: $put =string(l) +:else +: $put ='[0.0, 0.0]' +:endif +:let messages=[] +:delfunction DictNew +py3 <<EOF +import sys +d=vim.bindeval('{}') +m=vim.bindeval('messages') +def em(expr, g=globals(), l=locals()): + try: + exec(expr, g, l) + except Exception as e: + if sys.version_info >= (3, 5) and e.__class__ is ValueError and str(e) == 'embedded null byte': + m.extend([TypeError.__name__]) + else: + m.extend([e.__class__.__name__]) + +em('d["abc1"]') +em('d["abc1"]="\\0"') +em('d["abc1"]=vim') +em('d[""]=1') +em('d["a\\0b"]=1') +em('d[b"a\\0b"]=1') + +em('d.pop("abc1")') +em('d.popitem()') +del em +del m +EOF +:$put =messages +:unlet messages +:" locked and scope attributes +:let d={} | let dl={} | lockvar dl +:for s in split("d dl v: g:") +: let name=tr(s, ':', 's') +: execute 'py3 '.name.'=vim.bindeval("'.s.'")' +: let toput=s.' : '.join(map(['locked', 'scope'], 'v:val.":".py3eval(name.".".v:val)'), ';') +: $put =toput +:endfor +:silent! let d.abc2=1 +:silent! let dl.abc3=1 +:py3 d.locked=True +:py3 dl.locked=False +:silent! let d.def=1 +:silent! let dl.def=1 +:put ='d:'.string(d) +:put ='dl:'.string(dl) +:unlet d dl +: +:let l=[] | let ll=[] | lockvar ll +:for s in split("l ll") +: let name=tr(s, ':', 's') +: execute 'py3 '.name.'=vim.bindeval("'.s.'")' +: let toput=s.' : locked:'.py3eval(name.'.locked') +: $put =toput +:endfor +:silent! call extend(l, [0]) +:silent! call extend(ll, [0]) +:py3 l.locked=True +:py3 ll.locked=False +:silent! call extend(l, [1]) +:silent! call extend(ll, [1]) +:put ='l:'.string(l) +:put ='ll:'.string(ll) +:unlet l ll +:" +:" py3eval() +:let l=py3eval('[0, 1, 2]') +:$put =string(l) +:let d=py3eval('{"a": "b", "c": 1, "d": ["e"]}') +:$put =sort(items(d)) +:let v:errmsg = '' +:$put ='py3eval(\"None\") = ' . py3eval('None') . v:errmsg +:if has('float') +: let f=py3eval('0.0') +: $put =string(f) +:else +: $put ='0.0' +:endif +:" Invalid values: +:for e in ['"\0"', '{"\0": 1}', 'undefined_name', 'vim'] +: try +: let v=py3eval(e) +: catch +: let toput=e.":\t".v:exception[:13] +: $put =toput +: endtry +:endfor +:" +:" threading +:let l = [0] +:py3 l=vim.bindeval('l') +py3 <<EOF +import threading +import time + +class T(threading.Thread): + def __init__(self): + threading.Thread.__init__(self) + self.t = 0 + self.running = True + + def run(self): + while self.running: + self.t += 1 + time.sleep(0.1) + +t = T() +del T +t.start() +EOF +:sleep 1 +:py3 t.running = False +:py3 t.join() +:" Check if the background thread is working. Count should be 10, but on a +:" busy system (AppVeyor) it can be much lower. +:py3 l[0] = t.t > 4 +:py3 del time +:py3 del threading +:py3 del t +:$put =string(l) +:" +:" settrace +:let l = [] +:py3 l=vim.bindeval('l') +py3 <<EOF +import sys + +def traceit(frame, event, arg): + global l + if event == "line": + l += [frame.f_lineno] + return traceit + +def trace_main(): + for i in range(5): + pass +EOF +:py3 sys.settrace(traceit) +:py3 trace_main() +:py3 sys.settrace(None) +:py3 del traceit +:py3 del trace_main +:$put =string(l) +:" +:" Slice +:py3 ll = vim.bindeval('[0, 1, 2, 3, 4, 5]') +:py3 l = ll[:4] +:$put =string(py3eval('l')) +:py3 l = ll[2:] +:$put =string(py3eval('l')) +:py3 l = ll[:-4] +:$put =string(py3eval('l')) +:py3 l = ll[-2:] +:$put =string(py3eval('l')) +:py3 l = ll[2:4] +:$put =string(py3eval('l')) +:py3 l = ll[4:2] +:$put =string(py3eval('l')) +:py3 l = ll[-4:-2] +:$put =string(py3eval('l')) +:py3 l = ll[-2:-4] +:$put =string(py3eval('l')) +:py3 l = ll[:] +:$put =string(py3eval('l')) +:py3 l = ll[0:6] +:$put =string(py3eval('l')) +:py3 l = ll[-10:10] +:$put =string(py3eval('l')) +:py3 l = ll[4:2:-1] +:$put =string(py3eval('l')) +:py3 l = ll[::2] +:$put =string(py3eval('l')) +:py3 l = ll[4:2:1] +:$put =string(py3eval('l')) +:py3 del l +:" +:" Vars +:let g:foo = 'bac' +:let w:abc3 = 'def' +:let b:baz = 'bar' +:let t:bar = 'jkl' +:try +: throw "Abc" +:catch +: put =py3eval('vim.vvars[''exception'']') +:endtry +:put =py3eval('vim.vars[''foo'']') +:put =py3eval('vim.current.window.vars[''abc3'']') +:put =py3eval('vim.current.buffer.vars[''baz'']') +:put =py3eval('vim.current.tabpage.vars[''bar'']') +:" +:" Options +:" paste: boolean, global +:" previewheight number, global +:" operatorfunc: string, global +:" number: boolean, window-local +:" numberwidth: number, window-local +:" colorcolumn: string, window-local +:" statusline: string, window-local/global +:" autoindent: boolean, buffer-local +:" shiftwidth: number, buffer-local +:" omnifunc: string, buffer-local +:" preserveindent: boolean, buffer-local/global +:" path: string, buffer-local/global +:let g:bufs=[bufnr('%')] +:new +:let g:bufs+=[bufnr('%')] +:vnew +:let g:bufs+=[bufnr('%')] +:wincmd j +:vnew +:let g:bufs+=[bufnr('%')] +:wincmd l +:fun RecVars(opt) +: let gval =string(eval('&g:'.a:opt)) +: let wvals=join(map(range(1, 4), 'v:val.":".string(getwinvar(v:val, "&".a:opt))')) +: let bvals=join(map(copy(g:bufs), 'v:val.":".string(getbufvar(v:val, "&".a:opt))')) +: put =' G: '.gval +: put =' W: '.wvals +: put =' B: '.wvals +:endfun +py3 << EOF +def e(s, g=globals(), l=locals()): + try: + exec(s, g, l) + except Exception as e: + vim.command('return ' + repr(e.__class__.__name__)) + +def ev(s, g=globals(), l=locals()): + try: + return eval(s, g, l) + except Exception as e: + vim.command('let exc=' + repr(e.__class__.__name__)) + return 0 +EOF +:fun E(s) +: python3 e(vim.eval('a:s')) +:endfun +:fun Ev(s) +: let r=py3eval('ev(vim.eval("a:s"))') +: if exists('exc') +: throw exc +: endif +: return r +:endfun +:py3 gopts1=vim.options +:py3 wopts1=vim.windows[2].options +:py3 wopts2=vim.windows[0].options +:py3 wopts3=vim.windows[1].options +:py3 bopts1=vim.buffers[vim.bindeval("g:bufs")[2]].options +:py3 bopts2=vim.buffers[vim.bindeval("g:bufs")[1]].options +:py3 bopts3=vim.buffers[vim.bindeval("g:bufs")[0]].options +:$put ='wopts iters equal: '.py3eval('list(wopts1) == list(wopts2)') +:$put ='bopts iters equal: '.py3eval('list(bopts1) == list(bopts2)') +:py3 gset=set(iter(gopts1)) +:py3 wset=set(iter(wopts1)) +:py3 bset=set(iter(bopts1)) +:set path=.,..,, +:let lst=[] +:let lst+=[['paste', 1, 0, 1, 2, 1, 1, 0 ]] +:let lst+=[['previewheight', 5, 1, 6, 'a', 0, 1, 0 ]] +:let lst+=[['operatorfunc', 'A', 'B', 'C', 2, 0, 1, 0 ]] +:let lst+=[['number', 0, 1, 1, 0, 1, 0, 1 ]] +:let lst+=[['numberwidth', 2, 3, 5, -100, 0, 0, 1 ]] +:let lst+=[['colorcolumn', '+1', '+2', '+3', 'abc4', 0, 0, 1 ]] +:let lst+=[['statusline', '1', '2', '4', 0, 0, 1, 1 ]] +:let lst+=[['autoindent', 0, 1, 1, 2, 1, 0, 2 ]] +:let lst+=[['shiftwidth', 0, 2, 1, 3, 0, 0, 2 ]] +:let lst+=[['omnifunc', 'A', 'B', 'C', 1, 0, 0, 2 ]] +:let lst+=[['preserveindent', 0, 1, 1, 2, 1, 1, 2 ]] +:let lst+=[['path', '.,,', ',,', '.', 0, 0, 1, 2 ]] +:for [oname, oval1, oval2, oval3, invval, bool, global, local] in lst +: py3 oname=vim.eval('oname') +: py3 oval1=vim.bindeval('oval1') +: py3 oval2=vim.bindeval('oval2') +: py3 oval3=vim.bindeval('oval3') +: if invval is 0 || invval is 1 +: py3 invval=bool(vim.bindeval('invval')) +: else +: py3 invval=vim.bindeval('invval') +: endif +: if bool +: py3 oval1=bool(oval1) +: py3 oval2=bool(oval2) +: py3 oval3=bool(oval3) +: endif +: put ='>>> '.oname +: $put =' g/w/b:'.py3eval('oname in gset').'/'.py3eval('oname in wset').'/'.py3eval('oname in bset') +: $put =' g/w/b (in):'.py3eval('oname in gopts1').'/'.py3eval('oname in wopts1').'/'.py3eval('oname in bopts1') +: for v in ['gopts1', 'wopts1', 'bopts1'] +: try +: put =' p/'.v.': '.Ev('repr('.v.'['''.oname.'''])') +: catch +: put =' p/'.v.'! '.v:exception +: endtry +: let r=E(v.'['''.oname.''']=invval') +: if r isnot 0 +: put =' inv: '.string(invval).'! '.r +: endif +: for vv in (v is# 'gopts1' ? [v] : [v, v[:-2].'2', v[:-2].'3']) +: let val=substitute(vv, '^.opts', 'oval', '') +: let r=E(vv.'['''.oname.''']='.val) +: if r isnot 0 +: put =' '.vv.'! '.r +: endif +: endfor +: endfor +: call RecVars(oname) +: for v in ['wopts3', 'bopts3'] +: let r=E('del '.v.'["'.oname.'"]') +: if r isnot 0 +: put =' del '.v.'! '.r +: endif +: endfor +: call RecVars(oname) +:endfor +:delfunction RecVars +:delfunction E +:delfunction Ev +:py3 del ev +:py3 del e +:only +:for buf in g:bufs[1:] +: execute 'bwipeout!' buf +:endfor +:py3 del gopts1 +:py3 del wopts1 +:py3 del wopts2 +:py3 del wopts3 +:py3 del bopts1 +:py3 del bopts2 +:py3 del bopts3 +:py3 del oval1 +:py3 del oval2 +:py3 del oval3 +:py3 del oname +:py3 del invval +:" +:" Test buffer object +:vnew +:put ='First line' +:put ='Second line' +:put ='Third line' +:1 delete _ +:py3 b=vim.current.buffer +:wincmd w +:mark a +:augroup BUFS +: autocmd BufFilePost * python3 cb.append(vim.eval('expand("<abuf>")') + ':BufFilePost:' + vim.eval('bufnr("%")')) +: autocmd BufFilePre * python3 cb.append(vim.eval('expand("<abuf>")') + ':BufFilePre:' + vim.eval('bufnr("%")')) +:augroup END +py3 << EOF +# Tests BufferAppend and BufferItem +cb.append(b[0]) +# Tests BufferSlice and BufferAssSlice +cb.append('abc5') # Will be overwritten +cb[-1:] = b[:-2] +# Test BufferLength and BufferAssSlice +cb.append('def') # Will not be overwritten +cb[len(cb):] = b[:] +# Test BufferAssItem and BufferMark +cb.append('ghi') # Will be overwritten +cb[-1] = repr((len(cb) - cb.mark('a')[0], cb.mark('a')[1])) +# Test BufferRepr +cb.append(repr(cb) + repr(b)) +# Modify foreign buffer +b.append('foo') +b[0]='bar' +b[0:0]=['baz'] +vim.command('call append("$", getbufline(%i, 1, "$"))' % b.number) +# Test assigning to name property +import os +old_name = cb.name +cb.name = 'foo' +cb.append(cb.name[-11:].replace(os.path.sep, '/')) +b.name = 'bar' +cb.append(b.name[-11:].replace(os.path.sep, '/')) +cb.name = old_name +cb.append(cb.name[-17:].replace(os.path.sep, '/')) +del old_name +# Test CheckBuffer +for _b in vim.buffers: + if _b is not cb: + vim.command('bwipeout! ' + str(_b.number)) +del _b +cb.append('valid: b:%s, cb:%s' % (repr(b.valid), repr(cb.valid))) +for expr in ('b[1]','b[:] = ["A", "B"]','b[:]','b.append("abc6")'): + try: + exec(expr) + except vim.error: + pass + else: + # Usually a SEGV here + # Should not happen in any case + cb.append('No exception for ' + expr) +vim.command('cd .') +del b +EOF +:" +:" Test vim.buffers object +:set hidden +:edit a +:buffer # +:edit b +:buffer # +:edit c +:buffer # +py3 << EOF +# Check GCing iterator that was not fully exhausted +i = iter(vim.buffers) +cb.append('i:' + str(next(i))) +# and also check creating more than one iterator at a time +i2 = iter(vim.buffers) +cb.append('i2:' + str(next(i2))) +cb.append('i:' + str(next(i))) +# The following should trigger GC and not cause any problems +del i +del i2 +i3 = iter(vim.buffers) +cb.append('i3:' + str(next(i3))) +del i3 + +prevnum = 0 +for b in vim.buffers: + # Check buffer order + if prevnum >= b.number: + cb.append('!!! Buffer numbers not in strictly ascending order') + # Check indexing: vim.buffers[number].number == number + cb.append(str(b.number) + ':' + repr(vim.buffers[b.number]) + '=' + repr(b)) + prevnum = b.number +del prevnum + +cb.append(str(len(vim.buffers))) + +bnums = list(map(lambda b: b.number, vim.buffers))[1:] + +# Test wiping out buffer with existing iterator +i4 = iter(vim.buffers) +cb.append('i4:' + str(next(i4))) +vim.command('bwipeout! ' + str(bnums.pop(0))) +try: + next(i4) +except vim.error: + pass +else: + cb.append('!!!! No vim.error') +i4 = iter(vim.buffers) +vim.command('bwipeout! ' + str(bnums.pop(-1))) +vim.command('bwipeout! ' + str(bnums.pop(-1))) +cb.append('i4:' + str(next(i4))) +try: + next(i4) +except StopIteration: + cb.append('StopIteration') +del i4 +del bnums +EOF +:" +:" Test vim.{tabpage,window}list and vim.{tabpage,window} objects +:tabnew 0 +:tabnew 1 +:vnew a.1 +:tabnew 2 +:vnew a.2 +:vnew b.2 +:vnew c.2 +py3 << EOF +cb.append('Number of tabs: ' + str(len(vim.tabpages))) +cb.append('Current tab pages:') + +def W(w): + if '(unknown)' in repr(w): + return '<window object (unknown)>' + else: + return repr(w) + +def Cursor(w, start=len(cb)): + if w.buffer is cb: + return repr((start - w.cursor[0], w.cursor[1])) + else: + return repr(w.cursor) + +for t in vim.tabpages: + cb.append(' ' + repr(t) + '(' + str(t.number) + ')' + ': ' + str(len(t.windows)) + ' windows, current is ' + W(t.window)) + cb.append(' Windows:') + for w in t.windows: + cb.append(' ' + W(w) + '(' + str(w.number) + ')' + ': displays buffer ' + repr(w.buffer) + '; cursor is at ' + Cursor(w)) + # Other values depend on the size of the terminal, so they are checked partly: + for attr in ('height', 'row', 'width', 'col'): + try: + aval = getattr(w, attr) + if type(aval) is not int: + raise TypeError + if aval < 0: + raise ValueError + except Exception as e: + cb.append('!!!!!! Error while getting attribute ' + attr + ': ' + e.__class__.__name__) + del aval + del attr + w.cursor = (len(w.buffer), 0) +del W +del Cursor +cb.append('Number of windows in current tab page: ' + str(len(vim.windows))) +if list(vim.windows) != list(vim.current.tabpage.windows): + cb.append('!!!!!! Windows differ') +EOF +:" +:" Test vim.current +py3 << EOF +def H(o): + return repr(o) +cb.append('Current tab page: ' + repr(vim.current.tabpage)) +cb.append('Current window: ' + repr(vim.current.window) + ': ' + H(vim.current.window) + ' is ' + H(vim.current.tabpage.window)) +cb.append('Current buffer: ' + repr(vim.current.buffer) + ': ' + H(vim.current.buffer) + ' is ' + H(vim.current.window.buffer)+ ' is ' + H(vim.current.tabpage.window.buffer)) +del H +# Assigning: fails +try: + vim.current.window = vim.tabpages[0].window +except ValueError: + cb.append('ValueError at assigning foreign tab window') + +for attr in ('window', 'tabpage', 'buffer'): + try: + setattr(vim.current, attr, None) + except TypeError: + cb.append('Type error at assigning None to vim.current.' + attr) +del attr + +# Assigning: success +vim.current.tabpage = vim.tabpages[-2] +vim.current.buffer = cb +vim.current.window = vim.windows[0] +vim.current.window.cursor = (len(vim.current.buffer), 0) +cb.append('Current tab page: ' + repr(vim.current.tabpage)) +cb.append('Current window: ' + repr(vim.current.window)) +cb.append('Current buffer: ' + repr(vim.current.buffer)) +cb.append('Current line: ' + repr(vim.current.line)) +ws = list(vim.windows) +ts = list(vim.tabpages) +for b in vim.buffers: + if b is not cb: + vim.command('bwipeout! ' + str(b.number)) +del b +cb.append('w.valid: ' + repr([w.valid for w in ws])) +cb.append('t.valid: ' + repr([t.valid for t in ts])) +del w +del t +del ts +del ws +EOF +:tabonly! +:only! +:" +:" Test types +py3 << EOF +for expr, attr in ( + ('vim.vars', 'Dictionary'), + ('vim.options', 'Options'), + ('vim.bindeval("{}")', 'Dictionary'), + ('vim.bindeval("[]")', 'List'), + ('vim.bindeval("function(\'tr\')")', 'Function'), + ('vim.current.buffer', 'Buffer'), + ('vim.current.range', 'Range'), + ('vim.current.window', 'Window'), + ('vim.current.tabpage', 'TabPage'), +): + cb.append(expr + ':' + attr + ':' + repr(type(eval(expr)) is getattr(vim, attr))) +del expr +del attr +EOF +:" +:" Test __dir__() method +py3 << EOF +for name, o in ( + ('current', vim.current), + ('buffer', vim.current.buffer), + ('window', vim.current.window), + ('tabpage', vim.current.tabpage), + ('range', vim.current.range), + ('dictionary', vim.bindeval('{}')), + ('list', vim.bindeval('[]')), + ('function', vim.bindeval('function("tr")')), + ('output', sys.stdout), + ): + cb.append(name + ':' + ','.join(dir(o))) +del name +del o +EOF +:" +:" Test vim.*.__new__ +:$put =string(py3eval('vim.Dictionary({})')) +:$put =string(py3eval('vim.Dictionary(a=1)')) +:$put =string(py3eval('vim.Dictionary(((''a'', 1),))')) +:$put =string(py3eval('vim.List()')) +:$put =string(py3eval('vim.List(iter(''abc7''))')) +:$put =string(py3eval('vim.Function(''tr'')')) +:$put =string(py3eval('vim.Function(''tr'', args=[123, 3, 4])')) +:$put =string(py3eval('vim.Function(''tr'', args=[])')) +:$put =string(py3eval('vim.Function(''tr'', self={})')) +:$put =string(py3eval('vim.Function(''tr'', args=[123, 3, 4], self={})')) +:$put ='auto_rebind' +:$put =string(py3eval('vim.Function(''tr'', auto_rebind=False)')) +:$put =string(py3eval('vim.Function(''tr'', args=[123, 3, 4], auto_rebind=False)')) +:$put =string(py3eval('vim.Function(''tr'', args=[], auto_rebind=False)')) +:$put =string(py3eval('vim.Function(''tr'', self={}, auto_rebind=False)')) +:$put =string(py3eval('vim.Function(''tr'', args=[123, 3, 4], self={}, auto_rebind=False)')) +:" +:" Test vim.Function +:function Args(...) +: return a:000 +:endfunction +:function SelfArgs(...) dict +: return [a:000, self] +:endfunction +:" The following four lines should not crash +:let Pt = function('tr', [[]], {'l': []}) +:py3 Pt = vim.bindeval('Pt') +:unlet Pt +:py3 del Pt +py3 << EOF +def ecall(out_prefix, func, *args, **kwargs): + line = out_prefix + ': ' + try: + ret = func(*args, **kwargs) + except Exception: + line += '!exception: ' + emsg(sys.exc_info()) + else: + line += '!result: ' + str(vim.Function('string')(ret), 'utf-8') + cb.append(line) +a = vim.Function('Args') +pa1 = vim.Function('Args', args=['abcArgsPA1']) +pa2 = vim.Function('Args', args=[]) +pa3 = vim.Function('Args', args=['abcArgsPA3'], self={'abcSelfPA3': 'abcSelfPA3Val'}) +pa4 = vim.Function('Args', self={'abcSelfPA4': 'abcSelfPA4Val'}) +cb.append('a: ' + repr(a)) +cb.append('pa1: ' + repr(pa1)) +cb.append('pa2: ' + repr(pa2)) +cb.append('pa3: ' + repr(pa3)) +cb.append('pa4: ' + repr(pa4)) +sa = vim.Function('SelfArgs') +psa1 = vim.Function('SelfArgs', args=['abcArgsPSA1']) +psa2 = vim.Function('SelfArgs', args=[]) +psa3 = vim.Function('SelfArgs', args=['abcArgsPSA3'], self={'abcSelfPSA3': 'abcSelfPSA3Val'}) +psa4 = vim.Function('SelfArgs', self={'abcSelfPSA4': 'abcSelfPSA4Val'}) +psa5 = vim.Function('SelfArgs', self={'abcSelfPSA5': 'abcSelfPSA5Val'}, auto_rebind=0) +psa6 = vim.Function('SelfArgs', args=['abcArgsPSA6'], self={'abcSelfPSA6': 'abcSelfPSA6Val'}, auto_rebind=()) +psa7 = vim.Function('SelfArgs', args=['abcArgsPSA7'], auto_rebind=[]) +psa8 = vim.Function('SelfArgs', auto_rebind=False) +psa9 = vim.Function('SelfArgs', self={'abcSelfPSA9': 'abcSelfPSA9Val'}, auto_rebind=True) +psaA = vim.Function('SelfArgs', args=['abcArgsPSAA'], self={'abcSelfPSAA': 'abcSelfPSAAVal'}, auto_rebind=1) +psaB = vim.Function('SelfArgs', args=['abcArgsPSAB'], auto_rebind={'abcARPSAB': 'abcARPSABVal'}) +psaC = vim.Function('SelfArgs', auto_rebind=['abcARPSAC']) +cb.append('sa: ' + repr(sa)) +cb.append('psa1: ' + repr(psa1)) +cb.append('psa2: ' + repr(psa2)) +cb.append('psa3: ' + repr(psa3)) +cb.append('psa4: ' + repr(psa4)) +cb.append('psa5: ' + repr(psa5)) +cb.append('psa6: ' + repr(psa6)) +cb.append('psa7: ' + repr(psa7)) +cb.append('psa8: ' + repr(psa8)) +cb.append('psa9: ' + repr(psa9)) +cb.append('psaA: ' + repr(psaA)) +cb.append('psaB: ' + repr(psaB)) +cb.append('psaC: ' + repr(psaC)) + +psar = vim.Function('SelfArgs', args=[{'abcArgsPSAr': 'abcArgsPSArVal'}], self={'abcSelfPSAr': 'abcSelfPSArVal'}) +psar.args[0]['abcArgsPSAr2'] = [psar.self, psar.args[0]] +psar.self['rec'] = psar +psar.self['self'] = psar.self +psar.self['args'] = psar.args + +try: + cb.append('psar: ' + repr(psar)) +except Exception: + cb.append('!!!!!!!! Caught exception: ' + emsg(sys.exc_info())) +EOF +:$put ='s(a): '.string(py3eval('a')) +:$put ='s(pa1): '.string(py3eval('pa1')) +:$put ='s(pa2): '.string(py3eval('pa2')) +:$put ='s(pa3): '.string(py3eval('pa3')) +:$put ='s(pa4): '.string(py3eval('pa4')) +:$put ='s(sa): '.string(py3eval('sa')) +:$put ='s(psa1): '.string(py3eval('psa1')) +:$put ='s(psa2): '.string(py3eval('psa2')) +:$put ='s(psa3): '.string(py3eval('psa3')) +:$put ='s(psa4): '.string(py3eval('psa4')) +:$put ='s(psa5): '.string(py3eval('psa5')) +:$put ='s(psa6): '.string(py3eval('psa6')) +:$put ='s(psa7): '.string(py3eval('psa7')) +:$put ='s(psa8): '.string(py3eval('psa8')) +:$put ='s(psa9): '.string(py3eval('psa9')) +:$put ='s(psaA): '.string(py3eval('psaA')) +:$put ='s(psaB): '.string(py3eval('psaB')) +:$put ='s(psaC): '.string(py3eval('psaC')) +: +:for v in ['sa', 'psa1', 'psa2', 'psa3', 'psa4', 'psa5', 'psa6', 'psa7', 'psa8', 'psa9', 'psaA', 'psaB', 'psaC'] +: let d = {'f': py3eval(v)} +: $put ='d.'.v.'(): '.string(d.f()) +:endfor +: +:py3 ecall('a()', a, ) +:py3 ecall('pa1()', pa1, ) +:py3 ecall('pa2()', pa2, ) +:py3 ecall('pa3()', pa3, ) +:py3 ecall('pa4()', pa4, ) +:py3 ecall('sa()', sa, ) +:py3 ecall('psa1()', psa1, ) +:py3 ecall('psa2()', psa2, ) +:py3 ecall('psa3()', psa3, ) +:py3 ecall('psa4()', psa4, ) +: +:py3 ecall('a(42, 43)', a, 42, 43) +:py3 ecall('pa1(42, 43)', pa1, 42, 43) +:py3 ecall('pa2(42, 43)', pa2, 42, 43) +:py3 ecall('pa3(42, 43)', pa3, 42, 43) +:py3 ecall('pa4(42, 43)', pa4, 42, 43) +:py3 ecall('sa(42, 43)', sa, 42, 43) +:py3 ecall('psa1(42, 43)', psa1, 42, 43) +:py3 ecall('psa2(42, 43)', psa2, 42, 43) +:py3 ecall('psa3(42, 43)', psa3, 42, 43) +:py3 ecall('psa4(42, 43)', psa4, 42, 43) +: +:py3 ecall('a(42, self={"20": 1})', a, 42, self={'20': 1}) +:py3 ecall('pa1(42, self={"20": 1})', pa1, 42, self={'20': 1}) +:py3 ecall('pa2(42, self={"20": 1})', pa2, 42, self={'20': 1}) +:py3 ecall('pa3(42, self={"20": 1})', pa3, 42, self={'20': 1}) +:py3 ecall('pa4(42, self={"20": 1})', pa4, 42, self={'20': 1}) +:py3 ecall('sa(42, self={"20": 1})', sa, 42, self={'20': 1}) +:py3 ecall('psa1(42, self={"20": 1})', psa1, 42, self={'20': 1}) +:py3 ecall('psa2(42, self={"20": 1})', psa2, 42, self={'20': 1}) +:py3 ecall('psa3(42, self={"20": 1})', psa3, 42, self={'20': 1}) +:py3 ecall('psa4(42, self={"20": 1})', psa4, 42, self={'20': 1}) +: +:py3 ecall('a(self={"20": 1})', a, self={'20': 1}) +:py3 ecall('pa1(self={"20": 1})', pa1, self={'20': 1}) +:py3 ecall('pa2(self={"20": 1})', pa2, self={'20': 1}) +:py3 ecall('pa3(self={"20": 1})', pa3, self={'20': 1}) +:py3 ecall('pa4(self={"20": 1})', pa4, self={'20': 1}) +:py3 ecall('sa(self={"20": 1})', sa, self={'20': 1}) +:py3 ecall('psa1(self={"20": 1})', psa1, self={'20': 1}) +:py3 ecall('psa2(self={"20": 1})', psa2, self={'20': 1}) +:py3 ecall('psa3(self={"20": 1})', psa3, self={'20': 1}) +:py3 ecall('psa4(self={"20": 1})', psa4, self={'20': 1}) +py3 << EOF +def s(v): + if v is None: + return repr(v) + else: + return str(vim.Function('string')(v), 'utf-8') + +cb.append('a.args: ' + s(a.args)) +cb.append('pa1.args: ' + s(pa1.args)) +cb.append('pa2.args: ' + s(pa2.args)) +cb.append('pa3.args: ' + s(pa3.args)) +cb.append('pa4.args: ' + s(pa4.args)) +cb.append('sa.args: ' + s(sa.args)) +cb.append('psa1.args: ' + s(psa1.args)) +cb.append('psa2.args: ' + s(psa2.args)) +cb.append('psa3.args: ' + s(psa3.args)) +cb.append('psa4.args: ' + s(psa4.args)) + +cb.append('a.self: ' + s(a.self)) +cb.append('pa1.self: ' + s(pa1.self)) +cb.append('pa2.self: ' + s(pa2.self)) +cb.append('pa3.self: ' + s(pa3.self)) +cb.append('pa4.self: ' + s(pa4.self)) +cb.append('sa.self: ' + s(sa.self)) +cb.append('psa1.self: ' + s(psa1.self)) +cb.append('psa2.self: ' + s(psa2.self)) +cb.append('psa3.self: ' + s(psa3.self)) +cb.append('psa4.self: ' + s(psa4.self)) + +cb.append('a.name: ' + s(a.name)) +cb.append('pa1.name: ' + s(pa1.name)) +cb.append('pa2.name: ' + s(pa2.name)) +cb.append('pa3.name: ' + s(pa3.name)) +cb.append('pa4.name: ' + s(pa4.name)) +cb.append('sa.name: ' + s(sa.name)) +cb.append('psa1.name: ' + s(psa1.name)) +cb.append('psa2.name: ' + s(psa2.name)) +cb.append('psa3.name: ' + s(psa3.name)) +cb.append('psa4.name: ' + s(psa4.name)) + +cb.append('a.auto_rebind: ' + s(a.auto_rebind)) +cb.append('pa1.auto_rebind: ' + s(pa1.auto_rebind)) +cb.append('pa2.auto_rebind: ' + s(pa2.auto_rebind)) +cb.append('pa3.auto_rebind: ' + s(pa3.auto_rebind)) +cb.append('pa4.auto_rebind: ' + s(pa4.auto_rebind)) +cb.append('sa.auto_rebind: ' + s(sa.auto_rebind)) +cb.append('psa1.auto_rebind: ' + s(psa1.auto_rebind)) +cb.append('psa2.auto_rebind: ' + s(psa2.auto_rebind)) +cb.append('psa3.auto_rebind: ' + s(psa3.auto_rebind)) +cb.append('psa4.auto_rebind: ' + s(psa4.auto_rebind)) +cb.append('psa5.auto_rebind: ' + s(psa5.auto_rebind)) +cb.append('psa6.auto_rebind: ' + s(psa6.auto_rebind)) +cb.append('psa7.auto_rebind: ' + s(psa7.auto_rebind)) +cb.append('psa8.auto_rebind: ' + s(psa8.auto_rebind)) +cb.append('psa9.auto_rebind: ' + s(psa9.auto_rebind)) +cb.append('psaA.auto_rebind: ' + s(psaA.auto_rebind)) +cb.append('psaB.auto_rebind: ' + s(psaB.auto_rebind)) +cb.append('psaC.auto_rebind: ' + s(psaC.auto_rebind)) + +del s + +del a +del pa1 +del pa2 +del pa3 +del pa4 +del sa +del psa1 +del psa2 +del psa3 +del psa4 +del psa5 +del psa6 +del psa7 +del psa8 +del psa9 +del psaA +del psaB +del psaC +del psar + +del ecall +EOF +:" +:" Test stdout/stderr +:redir => messages +:py3 sys.stdout.write('abc8') ; sys.stdout.write('def') +:py3 sys.stderr.write('abc9') ; sys.stderr.write('def') +:py3 sys.stdout.writelines(iter('abcA')) +:py3 sys.stderr.writelines(iter('abcB')) +:redir END +:$put =string(substitute(messages, '\d\+', '', 'g')) +:" Test subclassing +:fun Put(...) +: $put =string(a:000) +: return a:000 +:endfun +py3 << EOF +class DupDict(vim.Dictionary): + def __setitem__(self, key, value): + super(DupDict, self).__setitem__(key, value) + super(DupDict, self).__setitem__('dup_' + key, value) +dd = DupDict() +dd['a'] = 'b' + +class DupList(vim.List): + def __getitem__(self, idx): + return [super(DupList, self).__getitem__(idx)] * 2 + +dl = DupList() +dl2 = DupList(iter('abcC')) +dl.extend(dl2[0]) + +class DupFun(vim.Function): + def __call__(self, arg): + return super(DupFun, self).__call__(arg, arg) + +df = DupFun('Put') +EOF +:$put =string(sort(keys(py3eval('dd')))) +:$put =string(py3eval('dl')) +:$put =string(py3eval('dl2')) +:$put =string(py3eval('df(2)')) +:$put =string(py3eval('dl') is# py3eval('dl')) +:$put =string(py3eval('dd') is# py3eval('dd')) +:$put =string(py3eval('df')) +:delfunction Put +py3 << EOF +del DupDict +del DupList +del DupFun +del dd +del dl +del dl2 +del df +EOF +:" +:" Test chdir +py3 << EOF +import os +fnamemodify = vim.Function('fnamemodify') +cb.append(str(fnamemodify('.', ':p:h:t'))) +cb.append(vim.eval('@%')) +os.chdir('..') +path = fnamemodify('.', ':p:h:t') +if path != b'src': + # Running tests from a shadow directory, so move up another level + # This will result in @% looking like shadow/testdir/test87.in, hence the + # slicing to remove the leading path and path separator + os.chdir('..') + cb.append(str(fnamemodify('.', ':p:h:t'))) + cb.append(vim.eval('@%')[len(path)+1:].replace(os.path.sep, '/')) + os.chdir(path) +else: + cb.append(str(fnamemodify('.', ':p:h:t'))) + cb.append(vim.eval('@%').replace(os.path.sep, '/')) +del path +os.chdir('testdir') +cb.append(str(fnamemodify('.', ':p:h:t'))) +cb.append(vim.eval('@%')) +del fnamemodify +EOF +:" +:" Test errors +:fun F() dict +:endfun +:fun D() +:endfun +py3 << EOF +d = vim.Dictionary() +ned = vim.Dictionary(foo='bar', baz='abcD') +dl = vim.Dictionary(a=1) +dl.locked = True +l = vim.List() +ll = vim.List('abcE') +ll.locked = True +nel = vim.List('abcO') +f = vim.Function('string') +fd = vim.Function('F') +fdel = vim.Function('D') +vim.command('delfunction D') + +def subexpr_test(expr, name, subexprs): + cb.append('>>> Testing %s using %s' % (name, expr)) + for subexpr in subexprs: + ee(expr % subexpr) + cb.append('<<< Finished') + +def stringtochars_test(expr): + return subexpr_test(expr, 'StringToChars', ( + '1', # Fail type checks + 'b"\\0"', # Fail PyString_AsStringAndSize(object, , NULL) check + '"\\0"', # Fail PyString_AsStringAndSize(bytes, , NULL) check + )) + +class Mapping(object): + def __init__(self, d): + self.d = d + + def __getitem__(self, key): + return self.d[key] + + def keys(self): + return self.d.keys() + + def items(self): + return self.d.items() + +def convertfrompyobject_test(expr, recurse=True): + # pydict_to_tv + stringtochars_test(expr % '{%s : 1}') + if recurse: + convertfrompyobject_test(expr % '{"abcF" : %s}', False) + # pymap_to_tv + stringtochars_test(expr % 'Mapping({%s : 1})') + if recurse: + convertfrompyobject_test(expr % 'Mapping({"abcG" : %s})', False) + # pyseq_to_tv + iter_test(expr) + return subexpr_test(expr, 'ConvertFromPyObject', ( + 'None', # Not conversible + '{b"": 1}', # Empty key not allowed + '{"": 1}', # Same, but with unicode object + 'FailingMapping()', # + 'FailingMappingKey()', # + 'FailingNumber()', # + )) + +def convertfrompymapping_test(expr): + convertfrompyobject_test(expr) + return subexpr_test(expr, 'ConvertFromPyMapping', ( + '[]', + )) + +def iter_test(expr): + return subexpr_test(expr, '*Iter*', ( + 'FailingIter()', + 'FailingIterNext()', + )) + +def number_test(expr, natural=False, unsigned=False): + if natural: + unsigned = True + return subexpr_test(expr, 'NumberToLong', ( + '[]', + 'None', + ) + (('-1',) if unsigned else ()) + + (('0',) if natural else ())) + +class FailingTrue(object): + def __bool__(self): + raise NotImplementedError('bool') + +class FailingIter(object): + def __iter__(self): + raise NotImplementedError('iter') + +class FailingIterNext(object): + def __iter__(self): + return self + + def __next__(self): + raise NotImplementedError('next') + +class FailingIterNextN(object): + def __init__(self, n): + self.n = n + + def __iter__(self): + return self + + def __next__(self): + if self.n: + self.n -= 1 + return 1 + else: + raise NotImplementedError('next N') + +class FailingMappingKey(object): + def __getitem__(self, item): + raise NotImplementedError('getitem:mappingkey') + + def keys(self): + return list("abcH") + +class FailingMapping(object): + def __getitem__(self): + raise NotImplementedError('getitem:mapping') + + def keys(self): + raise NotImplementedError('keys') + +class FailingList(list): + def __getitem__(self, idx): + if i == 2: + raise NotImplementedError('getitem:list') + else: + return super(FailingList, self).__getitem__(idx) + +class NoArgsCall(object): + def __call__(self): + pass + +class FailingCall(object): + def __call__(self, path): + raise NotImplementedError('call') + +class FailingNumber(object): + def __int__(self): + raise NotImplementedError('int') + +cb.append("> Output") +cb.append(">> OutputSetattr") +ee('del sys.stdout.softspace') +number_test('sys.stdout.softspace = %s', unsigned=True) +number_test('sys.stderr.softspace = %s', unsigned=True) +ee('assert sys.stdout.isatty()==False') +ee('assert sys.stdout.seekable()==False') +ee('sys.stdout.close()') +ee('sys.stdout.flush()') +ee('assert sys.stderr.isatty()==False') +ee('assert sys.stderr.seekable()==False') +ee('sys.stderr.close()') +ee('sys.stderr.flush()') +ee('sys.stdout.attr = None') +cb.append(">> OutputWrite") +ee('assert sys.stdout.writable()==True') +ee('assert sys.stdout.readable()==False') +ee('assert sys.stderr.writable()==True') +ee('assert sys.stderr.readable()==False') +ee('assert sys.stdout.closed()==False') +ee('assert sys.stderr.closed()==False') +ee('assert sys.stdout.errors=="strict"') +ee('assert sys.stderr.errors=="strict"') +ee('assert sys.stdout.encoding==sys.stderr.encoding') +ee('sys.stdout.write(None)') +cb.append(">> OutputWriteLines") +ee('sys.stdout.writelines(None)') +ee('sys.stdout.writelines([1])') +iter_test('sys.stdout.writelines(%s)') +cb.append("> VimCommand") +stringtochars_test('vim.command(%s)') +ee('vim.command("", 2)') +#! Not checked: vim->python exceptions translating: checked later +cb.append("> VimToPython") +#! Not checked: everything: needs errors in internal python functions +cb.append("> VimEval") +stringtochars_test('vim.eval(%s)') +ee('vim.eval("", FailingTrue())') +#! Not checked: everything: needs errors in internal python functions +cb.append("> VimEvalPy") +stringtochars_test('vim.bindeval(%s)') +ee('vim.eval("", 2)') +#! Not checked: vim->python exceptions translating: checked later +cb.append("> VimStrwidth") +stringtochars_test('vim.strwidth(%s)') +cb.append("> VimForeachRTP") +ee('vim.foreach_rtp(None)') +ee('vim.foreach_rtp(NoArgsCall())') +ee('vim.foreach_rtp(FailingCall())') +ee('vim.foreach_rtp(int, 2)') +cb.append('> import') +old_rtp = vim.options['rtp'] +vim.options['rtp'] = os.getcwd().replace('\\', '\\\\').replace(',', '\\,') +ee('import xxx_no_such_module_xxx') +ee('import failing_import') +ee('import failing') +vim.options['rtp'] = old_rtp +del old_rtp +cb.append("> Options") +cb.append(">> OptionsItem") +ee('vim.options["abcQ"]') +ee('vim.options[""]') +stringtochars_test('vim.options[%s]') +cb.append(">> OptionsContains") +stringtochars_test('%s in vim.options') +cb.append("> Dictionary") +cb.append(">> DictionaryConstructor") +ee('vim.Dictionary("abcI")') +##! Not checked: py_dict_alloc failure +cb.append(">> DictionarySetattr") +ee('del d.locked') +ee('d.locked = FailingTrue()') +ee('vim.vvars.locked = False') +ee('d.scope = True') +ee('d.xxx = True') +cb.append(">> _DictionaryItem") +ee('d.get("a", 2, 3)') +stringtochars_test('d.get(%s)') +ee('d.pop("a")') +ee('dl.pop("a")') +cb.append(">> DictionaryContains") +ee('"" in d') +ee('0 in d') +cb.append(">> DictionaryIterNext") +ee('for i in ned: ned["a"] = 1') +del i +cb.append(">> DictionaryAssItem") +ee('dl["b"] = 1') +stringtochars_test('d[%s] = 1') +convertfrompyobject_test('d["a"] = %s') +cb.append(">> DictionaryUpdate") +cb.append(">>> kwargs") +cb.append(">>> iter") +ee('d.update(FailingMapping())') +ee('d.update([FailingIterNext()])') +ee('d.update([FailingIterNextN(1)])') +iter_test('d.update(%s)') +convertfrompyobject_test('d.update(%s)') +stringtochars_test('d.update(((%s, 0),))') +convertfrompyobject_test('d.update((("a", %s),))') +cb.append(">> DictionaryPopItem") +ee('d.popitem(1, 2)') +cb.append(">> DictionaryHasKey") +ee('d.has_key()') +cb.append("> List") +cb.append(">> ListConstructor") +ee('vim.List(1, 2)') +ee('vim.List(a=1)') +iter_test('vim.List(%s)') +convertfrompyobject_test('vim.List([%s])') +cb.append(">> ListItem") +ee('l[1000]') +cb.append(">> ListAssItem") +ee('ll[1] = 2') +ee('l[1000] = 3') +cb.append(">> ListAssSlice") +ee('ll[1:100] = "abcJ"') +iter_test('l[:] = %s') +ee('nel[1:10:2] = "abcK"') +cb.append(repr(tuple(nel))) +ee('nel[1:10:2] = "a"') +cb.append(repr(tuple(nel))) +ee('nel[1:1:-1] = "a"') +cb.append(repr(tuple(nel))) +ee('nel[:] = FailingIterNextN(2)') +cb.append(repr(tuple(nel))) +convertfrompyobject_test('l[:] = [%s]') +cb.append(">> ListConcatInPlace") +iter_test('l.extend(%s)') +convertfrompyobject_test('l.extend([%s])') +cb.append(">> ListSetattr") +ee('del l.locked') +ee('l.locked = FailingTrue()') +ee('l.xxx = True') +cb.append("> Function") +cb.append(">> FunctionConstructor") +cb.append(">>> FunctionConstructor") +ee('vim.Function("123")') +ee('vim.Function("xxx_non_existent_function_xxx")') +ee('vim.Function("xxx#non#existent#function#xxx")') +ee('vim.Function("xxx_non_existent_function_xxx2", args=[])') +ee('vim.Function("xxx_non_existent_function_xxx3", self={})') +ee('vim.Function("xxx_non_existent_function_xxx4", args=[], self={})') +cb.append(">>> FunctionNew") +ee('vim.Function("tr", self="abcFuncSelf")') +ee('vim.Function("tr", args=427423)') +ee('vim.Function("tr", self="abcFuncSelf2", args="abcFuncArgs2")') +ee('vim.Function(self="abcFuncSelf2", args="abcFuncArgs2")') +ee('vim.Function("tr", "", self="abcFuncSelf2", args="abcFuncArgs2")') +ee('vim.Function("tr", "")') +cb.append(">> FunctionCall") +convertfrompyobject_test('f(%s)') +convertfrompymapping_test('fd(self=%s)') +cb.append("> TabPage") +cb.append(">> TabPageAttr") +ee('vim.current.tabpage.xxx') +cb.append("> TabList") +cb.append(">> TabListItem") +ee('vim.tabpages[1000]') +cb.append("> Window") +cb.append(">> WindowAttr") +ee('vim.current.window.xxx') +cb.append(">> WindowSetattr") +ee('vim.current.window.buffer = 0') +ee('vim.current.window.cursor = (100000000, 100000000)') +ee('vim.current.window.cursor = True') +number_test('vim.current.window.height = %s', unsigned=True) +number_test('vim.current.window.width = %s', unsigned=True) +ee('vim.current.window.xxxxxx = True') +cb.append("> WinList") +cb.append(">> WinListItem") +ee('vim.windows[1000]') +cb.append("> Buffer") +cb.append(">> StringToLine (indirect)") +ee('vim.current.buffer[0] = "\\na"') +ee('vim.current.buffer[0] = b"\\na"') +cb.append(">> SetBufferLine (indirect)") +ee('vim.current.buffer[0] = True') +cb.append(">> SetBufferLineList (indirect)") +ee('vim.current.buffer[:] = True') +ee('vim.current.buffer[:] = ["\\na", "bc"]') +cb.append(">> InsertBufferLines (indirect)") +ee('vim.current.buffer.append(None)') +ee('vim.current.buffer.append(["\\na", "bc"])') +ee('vim.current.buffer.append("\\nbc")') +cb.append(">> RBItem") +ee('vim.current.buffer[100000000]') +cb.append(">> RBAsItem") +ee('vim.current.buffer[100000000] = ""') +cb.append(">> BufferAttr") +ee('vim.current.buffer.xxx') +cb.append(">> BufferSetattr") +ee('vim.current.buffer.name = True') +ee('vim.current.buffer.xxx = True') +cb.append(">> BufferMark") +ee('vim.current.buffer.mark(0)') +ee('vim.current.buffer.mark("abcM")') +ee('vim.current.buffer.mark("!")') +cb.append(">> BufferRange") +ee('vim.current.buffer.range(1, 2, 3)') +cb.append("> BufMap") +cb.append(">> BufMapItem") +ee('vim.buffers[100000000]') +number_test('vim.buffers[%s]', natural=True) +cb.append("> Current") +cb.append(">> CurrentGetattr") +ee('vim.current.xxx') +cb.append(">> CurrentSetattr") +ee('vim.current.line = True') +ee('vim.current.buffer = True') +ee('vim.current.window = True') +ee('vim.current.tabpage = True') +ee('vim.current.xxx = True') +del d +del ned +del dl +del l +del ll +del nel +del f +del fd +del fdel +del subexpr_test +del stringtochars_test +del Mapping +del convertfrompyobject_test +del convertfrompymapping_test +del iter_test +del number_test +del FailingTrue +del FailingIter +del FailingIterNext +del FailingIterNextN +del FailingMapping +del FailingMappingKey +del FailingList +del NoArgsCall +del FailingCall +del FailingNumber +EOF +:delfunction F +:" +:" Test import +py3 << EOF +sys.path.insert(0, os.path.join(os.getcwd(), 'python_before')) +sys.path.append(os.path.join(os.getcwd(), 'python_after')) +vim.options['rtp'] = os.getcwd().replace(',', '\\,').replace('\\', '\\\\') +l = [] +def callback(path): + l.append(os.path.relpath(path)) +vim.foreach_rtp(callback) +cb.append(repr(l)) +del l +def callback(path): + return os.path.relpath(path) +cb.append(repr(vim.foreach_rtp(callback))) +del callback +from module import dir as d +from modulex import ddir +cb.append(d + ',' + ddir) +import before +cb.append(before.dir) +import after +cb.append(after.dir) +import topmodule as tm +import topmodule.submodule as tms +import topmodule.submodule.subsubmodule.subsubsubmodule as tmsss +cb.append(tm.__file__.replace(os.path.sep, '/')[-len('modulex/topmodule/__init__.py'):]) +cb.append(tms.__file__.replace(os.path.sep, '/')[-len('modulex/topmodule/submodule/__init__.py'):]) +cb.append(tmsss.__file__.replace(os.path.sep, '/')[-len('modulex/topmodule/submodule/subsubmodule/subsubsubmodule.py'):]) +del before +del after +del d +del ddir +del tm +del tms +del tmsss +EOF +:" +:" Test exceptions +:fun Exe(e) +: execute a:e +:endfun +py3 << EOF +Exe = vim.bindeval('function("Exe")') +ee('vim.command("throw \'abcN\'")') +ee('Exe("throw \'def\'")') +ee('vim.eval("Exe(\'throw \'\'ghi\'\'\')")') +ee('vim.eval("Exe(\'echoerr \'\'jkl\'\'\')")') +ee('vim.eval("Exe(\'xxx_non_existent_command_xxx\')")') +ee('vim.eval("xxx_unknown_function_xxx()")') +ee('vim.bindeval("Exe(\'xxx_non_existent_command_xxx\')")') +del Exe +EOF +:delfunction Exe +:" +:" Regression: interrupting vim.command propagates to next vim.command +py3 << EOF +def test_keyboard_interrupt(): + try: + vim.command('while 1 | endwhile') + except KeyboardInterrupt: + cb.append('Caught KeyboardInterrupt') + except Exception: + cb.append('!!!!!!!! Caught exception: ' + emsg(sys.exc_info())) + else: + cb.append('!!!!!!!! No exception') + try: + vim.command('$ put =\'Running :put\'') + except KeyboardInterrupt: + cb.append('!!!!!!!! Caught KeyboardInterrupt') + except Exception: + cb.append('!!!!!!!! Caught exception: ' + emsg(sys.exc_info())) + else: + cb.append('No exception') +EOF +:debuggreedy +:call inputsave() +:call feedkeys("s\ns\ns\ns\nq\n") +:redir => output +:debug silent! py3 test_keyboard_interrupt() +:redir END +:0 debuggreedy +:call inputrestore() +:silent $put =output +:unlet output +:py3 del test_keyboard_interrupt +:" +:" Cleanup +py3 << EOF +del cb +del ee +del emsg +del sys +del os +del vim +EOF +:endfun +:" +:fun RunTest() +:let checkrefs = !empty($PYTHONDUMPREFS) +:let start = getline(1, '$') +:for i in range(checkrefs ? 10 : 1) +: if i != 0 +: %d _ +: call setline(1, start) +: endif +: call Test() +: if i == 0 +: let result = getline(1, '$') +: endif +:endfor +:if checkrefs +: %d _ +: call setline(1, result) +:endif +:endfun +:" +:call RunTest() +:delfunction RunTest +:delfunction Test +:call garbagecollect(1) +:" +:/^start:/,$wq! test.out +:/^start:/,$w! test.out +:" vim: et ts=4 isk-=\: +:while getchar(0) isnot 0|endwhile +ENDTEST + +start: diff --git a/src/testdir/test87.ok b/src/testdir/test87.ok new file mode 100644 index 0000000..a7d4f64 --- /dev/null +++ b/src/testdir/test87.ok @@ -0,0 +1,1445 @@ +start: +[1, 'as''d', [1, 2, function('strlen'), {'a': 1}]] +[1, 2, function('strlen'), {'a': 1}] +Vim(put):E684: +[0, 'as''d', [1, 2, function('strlen'), {'a': 1}]] +[0, function('strlen'), [1, 2, function('strlen'), {'a': 1}]] +1 +[b'-1', b'0', b'1', b'b', b'f'] +[-1, <vim.Function '1'>, <vim.dictionary object at >, <vim.list object at >, b'asd'] +[(b'-1', <vim.dictionary object at >), (b'0', -1), (b'1', b'asd'), (b'b', <vim.list object at >), (b'f', <vim.Function '1'>)] +'-1' : {'a': 1} +'0' : -1 +'1' : 'asd' +'b' : [1, 2, function('strlen')] +'f' : function('1') +[0, function('strlen')] +[3] +[1, 2, function('strlen')] +[1, 2, function('strlen')] +1 +'asd' +2 +True +False +True +False +[b'0'] +{'0': -1} +(b'0', -1) +None +[] +[0, 1, 2, 3] +[0, 1, 2, 3] +[0, 1, 3] +[0, 1] +[0, 1] +[0, 1] +[0, 1, 2, 3] +[0, 1, 2, 3] +[0, 2, 3] +[2, 3] +[2, 3] +[2, 3] +[1, 3] +[0, 2] +[0, 1, 2, 3] +['a', 0, 1, 2, 3] +[0, 'b', 2, 3] +[0, 1, 'c'] +[0, 1, 2, 3, 'd'] +[0, 1, 2, 'e', 3] +['f', 2, 3] +[0, 1, 'g', 2, 3] +['h'] +[0, 1, 10, 3, 20, 5, 6, 7] +[0, 1, 2, 3, 20, 5, 10, 7] +[0, 1, 2, 3, 4, 5, 6, 7] +[0, 1, 2, 3, 4, 5, 6, 7] +[0, 1, 2, 3, 4, 5, 6, 7] +l[2] threw vim.error: error:('list is locked',) +[0, 1, 2, 3] +[function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd'] +[function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd', 'DictNewStart', 1, 2, 3, 'DictNewEnd', {'a': 'b'}] +[function('New'), function('DictNew'), 'NewStart', 1, 2, 3, 'NewEnd', 'DictNewStart', 1, 2, 3, 'DictNewEnd', {'a': 'b'}, 'New'] +l[1](1, 2, 3):(<class 'vim.error'>, error('Vim:E725: Calling dict function without Dictionary: DictNew',)) +f(1, 2, 3):(<class 'vim.error'>, error('Vim:E117: Unknown function: New',)) +[0.0, 0.0] +KeyError +TypeError +TypeError +ValueError +TypeError +TypeError +KeyError +KeyError +d : locked:0;scope:0 +dl : locked:1;scope:0 +v: : locked:2;scope:1 +g: : locked:0;scope:2 +d:{'abc2': 1} +dl:{'def': 1} +l : locked:0 +ll : locked:1 +l:[0] +ll:[1] +[0, 1, 2] +['a', 'b'] +['c', 1] +['d', ['e']] +py3eval("None") = v:none +0.0 +"\0": Vim(let):E859: +{"\0": 1}: Vim(let):E859: +undefined_name: Vim(let):Trace +vim: Vim(let):E859: +[1] +[1, 10, 11, 10, 11, 10, 11, 10, 11, 10, 11, 10, 1] +[0, 1, 2, 3] +[2, 3, 4, 5] +[0, 1] +[4, 5] +[2, 3] +[] +[2, 3] +[] +[0, 1, 2, 3, 4, 5] +[0, 1, 2, 3, 4, 5] +[0, 1, 2, 3, 4, 5] +[4, 3] +[0, 2, 4] +[] +Abc +bac +def +bar +jkl +wopts iters equal: 1 +bopts iters equal: 1 +>>> paste + g/w/b:1/0/0 + g/w/b (in):1/0/0 + p/gopts1: False + p/wopts1! KeyError + inv: 2! KeyError + wopts1! KeyError + wopts2! KeyError + wopts3! KeyError + p/bopts1! KeyError + inv: 2! KeyError + bopts1! KeyError + bopts2! KeyError + bopts3! KeyError + G: 1 + W: 1:1 2:1 3:1 4:1 + B: 1:1 2:1 3:1 4:1 + del wopts3! KeyError + del bopts3! KeyError + G: 1 + W: 1:1 2:1 3:1 4:1 + B: 1:1 2:1 3:1 4:1 +>>> previewheight + g/w/b:1/0/0 + g/w/b (in):1/0/0 + p/gopts1: 12 + inv: 'a'! TypeError + p/wopts1! KeyError + inv: 'a'! KeyError + wopts1! KeyError + wopts2! KeyError + wopts3! KeyError + p/bopts1! KeyError + inv: 'a'! KeyError + bopts1! KeyError + bopts2! KeyError + bopts3! KeyError + G: 5 + W: 1:5 2:5 3:5 4:5 + B: 1:5 2:5 3:5 4:5 + del wopts3! KeyError + del bopts3! KeyError + G: 5 + W: 1:5 2:5 3:5 4:5 + B: 1:5 2:5 3:5 4:5 +>>> operatorfunc + g/w/b:1/0/0 + g/w/b (in):1/0/0 + p/gopts1: b'' + inv: 2! TypeError + p/wopts1! KeyError + inv: 2! KeyError + wopts1! KeyError + wopts2! KeyError + wopts3! KeyError + p/bopts1! KeyError + inv: 2! KeyError + bopts1! KeyError + bopts2! KeyError + bopts3! KeyError + G: 'A' + W: 1:'A' 2:'A' 3:'A' 4:'A' + B: 1:'A' 2:'A' 3:'A' 4:'A' + del wopts3! KeyError + del bopts3! KeyError + G: 'A' + W: 1:'A' 2:'A' 3:'A' 4:'A' + B: 1:'A' 2:'A' 3:'A' 4:'A' +>>> number + g/w/b:0/1/0 + g/w/b (in):0/1/0 + p/gopts1! KeyError + inv: 0! KeyError + gopts1! KeyError + p/wopts1: False + p/bopts1! KeyError + inv: 0! KeyError + bopts1! KeyError + bopts2! KeyError + bopts3! KeyError + G: 0 + W: 1:1 2:1 3:0 4:0 + B: 1:1 2:1 3:0 4:0 + del wopts3! ValueError + del bopts3! KeyError + G: 0 + W: 1:1 2:1 3:0 4:0 + B: 1:1 2:1 3:0 4:0 +>>> numberwidth + g/w/b:0/1/0 + g/w/b (in):0/1/0 + p/gopts1! KeyError + inv: -100! KeyError + gopts1! KeyError + p/wopts1: 8 + inv: -100! error + p/bopts1! KeyError + inv: -100! KeyError + bopts1! KeyError + bopts2! KeyError + bopts3! KeyError + G: 8 + W: 1:3 2:5 3:2 4:8 + B: 1:3 2:5 3:2 4:8 + del wopts3! ValueError + del bopts3! KeyError + G: 8 + W: 1:3 2:5 3:2 4:8 + B: 1:3 2:5 3:2 4:8 +>>> colorcolumn + g/w/b:0/1/0 + g/w/b (in):0/1/0 + p/gopts1! KeyError + inv: 'abc4'! KeyError + gopts1! KeyError + p/wopts1: b'' + inv: 'abc4'! error + p/bopts1! KeyError + inv: 'abc4'! KeyError + bopts1! KeyError + bopts2! KeyError + bopts3! KeyError + G: '' + W: 1:'+2' 2:'+3' 3:'+1' 4:'' + B: 1:'+2' 2:'+3' 3:'+1' 4:'' + del wopts3! ValueError + del bopts3! KeyError + G: '' + W: 1:'+2' 2:'+3' 3:'+1' 4:'' + B: 1:'+2' 2:'+3' 3:'+1' 4:'' +>>> statusline + g/w/b:1/1/0 + g/w/b (in):1/1/0 + p/gopts1: b'' + inv: 0! TypeError + p/wopts1: None + inv: 0! TypeError + p/bopts1! KeyError + inv: 0! KeyError + bopts1! KeyError + bopts2! KeyError + bopts3! KeyError + G: '1' + W: 1:'2' 2:'4' 3:'1' 4:'1' + B: 1:'2' 2:'4' 3:'1' 4:'1' + del bopts3! KeyError + G: '1' + W: 1:'2' 2:'1' 3:'1' 4:'1' + B: 1:'2' 2:'1' 3:'1' 4:'1' +>>> autoindent + g/w/b:0/0/1 + g/w/b (in):0/0/1 + p/gopts1! KeyError + inv: 2! KeyError + gopts1! KeyError + p/wopts1! KeyError + inv: 2! KeyError + wopts1! KeyError + wopts2! KeyError + wopts3! KeyError + p/bopts1: False + G: 0 + W: 1:0 2:1 3:0 4:1 + B: 1:0 2:1 3:0 4:1 + del wopts3! KeyError + del bopts3! ValueError + G: 0 + W: 1:0 2:1 3:0 4:1 + B: 1:0 2:1 3:0 4:1 +>>> shiftwidth + g/w/b:0/0/1 + g/w/b (in):0/0/1 + p/gopts1! KeyError + inv: 3! KeyError + gopts1! KeyError + p/wopts1! KeyError + inv: 3! KeyError + wopts1! KeyError + wopts2! KeyError + wopts3! KeyError + p/bopts1: 8 + G: 8 + W: 1:0 2:2 3:8 4:1 + B: 1:0 2:2 3:8 4:1 + del wopts3! KeyError + del bopts3! ValueError + G: 8 + W: 1:0 2:2 3:8 4:1 + B: 1:0 2:2 3:8 4:1 +>>> omnifunc + g/w/b:0/0/1 + g/w/b (in):0/0/1 + p/gopts1! KeyError + inv: 1! KeyError + gopts1! KeyError + p/wopts1! KeyError + inv: 1! KeyError + wopts1! KeyError + wopts2! KeyError + wopts3! KeyError + p/bopts1: b'' + inv: 1! TypeError + G: '' + W: 1:'A' 2:'B' 3:'' 4:'C' + B: 1:'A' 2:'B' 3:'' 4:'C' + del wopts3! KeyError + del bopts3! ValueError + G: '' + W: 1:'A' 2:'B' 3:'' 4:'C' + B: 1:'A' 2:'B' 3:'' 4:'C' +>>> preserveindent + g/w/b:0/0/1 + g/w/b (in):0/0/1 + p/gopts1! KeyError + inv: 2! KeyError + gopts1! KeyError + p/wopts1! KeyError + inv: 2! KeyError + wopts1! KeyError + wopts2! KeyError + wopts3! KeyError + p/bopts1: False + G: 0 + W: 1:0 2:1 3:0 4:1 + B: 1:0 2:1 3:0 4:1 + del wopts3! KeyError + del bopts3! ValueError + G: 0 + W: 1:0 2:1 3:0 4:1 + B: 1:0 2:1 3:0 4:1 +>>> path + g/w/b:1/0/1 + g/w/b (in):1/0/1 + p/gopts1: b'.,..,,' + inv: 0! TypeError + p/wopts1! KeyError + inv: 0! KeyError + wopts1! KeyError + wopts2! KeyError + wopts3! KeyError + p/bopts1: None + inv: 0! TypeError + G: '.,,' + W: 1:'.,,' 2:',,' 3:'.,,' 4:'.' + B: 1:'.,,' 2:',,' 3:'.,,' 4:'.' + del wopts3! KeyError + G: '.,,' + W: 1:'.,,' 2:',,' 3:'.,,' 4:'.,,' + B: 1:'.,,' 2:',,' 3:'.,,' 4:'.,,' +First line +First line +def +First line +Second line +Third line +(7, 2) +<buffer test87.in><buffer > +baz +bar +Second line +Third line +foo +1:BufFilePre:1 +1:BufFilePost:1 +testdir/foo +5:BufFilePre:5 +5:BufFilePost:5 +testdir/bar +1:BufFilePre:1 +1:BufFilePost:1 +testdir/test87.in +valid: b:False, cb:True +i:<buffer test87.in> +i2:<buffer test87.in> +i:<buffer a> +i3:<buffer test87.in> +1:<buffer test87.in>=<buffer test87.in> +8:<buffer a>=<buffer a> +9:<buffer b>=<buffer b> +10:<buffer c>=<buffer c> +4 +i4:<buffer test87.in> +i4:<buffer test87.in> +StopIteration +Number of tabs: 4 +Current tab pages: + <tabpage 0>(1): 1 windows, current is <window object (unknown)> + Windows: + <window object (unknown)>(1): displays buffer <buffer test87.in>; cursor is at (37, 0) + <tabpage 1>(2): 1 windows, current is <window object (unknown)> + Windows: + <window object (unknown)>(1): displays buffer <buffer 0>; cursor is at (1, 0) + <tabpage 2>(3): 2 windows, current is <window object (unknown)> + Windows: + <window object (unknown)>(1): displays buffer <buffer a.1>; cursor is at (1, 0) + <window object (unknown)>(2): displays buffer <buffer 1>; cursor is at (1, 0) + <tabpage 3>(4): 4 windows, current is <window 0> + Windows: + <window 0>(1): displays buffer <buffer c.2>; cursor is at (1, 0) + <window 1>(2): displays buffer <buffer b.2>; cursor is at (1, 0) + <window 2>(3): displays buffer <buffer a.2>; cursor is at (1, 0) + <window 3>(4): displays buffer <buffer 2>; cursor is at (1, 0) +Number of windows in current tab page: 4 +Current tab page: <tabpage 3> +Current window: <window 0>: <window 0> is <window 0> +Current buffer: <buffer c.2>: <buffer c.2> is <buffer c.2> is <buffer c.2> +ValueError at assigning foreign tab window +Type error at assigning None to vim.current.window +Type error at assigning None to vim.current.tabpage +Type error at assigning None to vim.current.buffer +Current tab page: <tabpage 2> +Current window: <window 0> +Current buffer: <buffer test87.in> +Current line: 'Type error at assigning None to vim.current.buffer' +w.valid: [True, False] +t.valid: [True, False, True, False] +vim.vars:Dictionary:True +vim.options:Options:True +vim.bindeval("{}"):Dictionary:True +vim.bindeval("[]"):List:True +vim.bindeval("function('tr')"):Function:True +vim.current.buffer:Buffer:True +vim.current.range:Range:True +vim.current.window:Window:True +vim.current.tabpage:TabPage:True +current:__dir__,buffer,line,range,tabpage,window +buffer:__dir__,append,mark,name,number,options,range,valid,vars +window:__dir__,buffer,col,cursor,height,number,options,row,tabpage,valid,vars,width +tabpage:__dir__,number,valid,vars,window,windows +range:__dir__,append,end,start +dictionary:__dir__,get,has_key,items,keys,locked,pop,popitem,scope,update,values +list:__dir__,extend,locked +function:__dir__,args,auto_rebind,self,softspace +output:__dir__,close,closed,flush,isatty,readable,seekable,softspace,writable,write,writelines +{} +{'a': 1} +{'a': 1} +[] +['a', 'b', 'c', '7'] +function('tr') +function('tr', [123, 3, 4]) +function('tr') +function('tr', {}) +function('tr', [123, 3, 4], {}) +auto_rebind +function('tr') +function('tr', [123, 3, 4]) +function('tr') +function('tr', {}) +function('tr', [123, 3, 4], {}) +a: <vim.Function 'Args'> +pa1: <vim.Function 'Args', args=['abcArgsPA1']> +pa2: <vim.Function 'Args'> +pa3: <vim.Function 'Args', args=['abcArgsPA3'], self={'abcSelfPA3': 'abcSelfPA3Val'}> +pa4: <vim.Function 'Args', self={'abcSelfPA4': 'abcSelfPA4Val'}> +sa: <vim.Function 'SelfArgs'> +psa1: <vim.Function 'SelfArgs', args=['abcArgsPSA1']> +psa2: <vim.Function 'SelfArgs'> +psa3: <vim.Function 'SelfArgs', args=['abcArgsPSA3'], self={'abcSelfPSA3': 'abcSelfPSA3Val'}> +psa4: <vim.Function 'SelfArgs', self={'abcSelfPSA4': 'abcSelfPSA4Val'}> +psa5: <vim.Function 'SelfArgs', self={'abcSelfPSA5': 'abcSelfPSA5Val'}> +psa6: <vim.Function 'SelfArgs', args=['abcArgsPSA6'], self={'abcSelfPSA6': 'abcSelfPSA6Val'}> +psa7: <vim.Function 'SelfArgs', args=['abcArgsPSA7']> +psa8: <vim.Function 'SelfArgs'> +psa9: <vim.Function 'SelfArgs', self={'abcSelfPSA9': 'abcSelfPSA9Val'}, auto_rebind=True> +psaA: <vim.Function 'SelfArgs', args=['abcArgsPSAA'], self={'abcSelfPSAA': 'abcSelfPSAAVal'}, auto_rebind=True> +psaB: <vim.Function 'SelfArgs', args=['abcArgsPSAB']> +psaC: <vim.Function 'SelfArgs'> +psar: <vim.Function 'SelfArgs', args=[{'abcArgsPSAr2': [{'rec': function('SelfArgs', [{...}], {...}), 'self': {...}, 'abcSelfPSAr': 'abcSelfPSArVal', 'args': [{...}]}, {...}], 'abcArgsPSAr': 'abcArgsPSArVal'}], self={'rec': function('SelfArgs', [{'abcArgsPSAr2': [{...}, {...}], 'abcArgsPSAr': 'abcArgsPSArVal'}], {...}), 'self': {...}, 'abcSelfPSAr': 'abcSelfPSArVal', 'args': [{'abcArgsPSAr2': [{...}, {...}], 'abcArgsPSAr': 'abcArgsPSArVal'}]}> +s(a): function('Args') +s(pa1): function('Args', ['abcArgsPA1']) +s(pa2): function('Args') +s(pa3): function('Args', ['abcArgsPA3'], {'abcSelfPA3': 'abcSelfPA3Val'}) +s(pa4): function('Args', {'abcSelfPA4': 'abcSelfPA4Val'}) +s(sa): function('SelfArgs') +s(psa1): function('SelfArgs', ['abcArgsPSA1']) +s(psa2): function('SelfArgs') +s(psa3): function('SelfArgs', ['abcArgsPSA3'], {'abcSelfPSA3': 'abcSelfPSA3Val'}) +s(psa4): function('SelfArgs', {'abcSelfPSA4': 'abcSelfPSA4Val'}) +s(psa5): function('SelfArgs', {'abcSelfPSA5': 'abcSelfPSA5Val'}) +s(psa6): function('SelfArgs', ['abcArgsPSA6'], {'abcSelfPSA6': 'abcSelfPSA6Val'}) +s(psa7): function('SelfArgs', ['abcArgsPSA7']) +s(psa8): function('SelfArgs') +s(psa9): function('SelfArgs', {'abcSelfPSA9': 'abcSelfPSA9Val'}) +s(psaA): function('SelfArgs', ['abcArgsPSAA'], {'abcSelfPSAA': 'abcSelfPSAAVal'}) +s(psaB): function('SelfArgs', ['abcArgsPSAB']) +s(psaC): function('SelfArgs') +d.sa(): [[], {'f': function('SelfArgs')}] +d.psa1(): [['abcArgsPSA1'], {'f': function('SelfArgs', ['abcArgsPSA1'])}] +d.psa2(): [[], {'f': function('SelfArgs')}] +d.psa3(): [['abcArgsPSA3'], {'abcSelfPSA3': 'abcSelfPSA3Val'}] +d.psa4(): [[], {'abcSelfPSA4': 'abcSelfPSA4Val'}] +d.psa5(): [[], {'abcSelfPSA5': 'abcSelfPSA5Val'}] +d.psa6(): [['abcArgsPSA6'], {'abcSelfPSA6': 'abcSelfPSA6Val'}] +d.psa7(): [['abcArgsPSA7'], {'f': function('SelfArgs', ['abcArgsPSA7'])}] +d.psa8(): [[], {'f': function('SelfArgs')}] +d.psa9(): [[], {'f': function('SelfArgs', {'abcSelfPSA9': 'abcSelfPSA9Val'})}] +d.psaA(): [['abcArgsPSAA'], {'f': function('SelfArgs', ['abcArgsPSAA'], {'abcSelfPSAA': 'abcSelfPSAAVal'})}] +d.psaB(): [['abcArgsPSAB'], {'f': function('SelfArgs', ['abcArgsPSAB'])}] +d.psaC(): [[], {'f': function('SelfArgs')}] +a(): !result: [] +pa1(): !result: ['abcArgsPA1'] +pa2(): !result: [] +pa3(): !result: ['abcArgsPA3'] +pa4(): !result: [] +sa(): !exception: error:('Vim:E725: Calling dict function without Dictionary: SelfArgs',) +psa1(): !exception: error:('Vim:E725: Calling dict function without Dictionary: SelfArgs',) +psa2(): !exception: error:('Vim:E725: Calling dict function without Dictionary: SelfArgs',) +psa3(): !result: [['abcArgsPSA3'], {'abcSelfPSA3': 'abcSelfPSA3Val'}] +psa4(): !result: [[], {'abcSelfPSA4': 'abcSelfPSA4Val'}] +a(42, 43): !result: [42, 43] +pa1(42, 43): !result: ['abcArgsPA1', 42, 43] +pa2(42, 43): !result: [42, 43] +pa3(42, 43): !result: ['abcArgsPA3', 42, 43] +pa4(42, 43): !result: [42, 43] +sa(42, 43): !exception: error:('Vim:E725: Calling dict function without Dictionary: SelfArgs',) +psa1(42, 43): !exception: error:('Vim:E725: Calling dict function without Dictionary: SelfArgs',) +psa2(42, 43): !exception: error:('Vim:E725: Calling dict function without Dictionary: SelfArgs',) +psa3(42, 43): !result: [['abcArgsPSA3', 42, 43], {'abcSelfPSA3': 'abcSelfPSA3Val'}] +psa4(42, 43): !result: [[42, 43], {'abcSelfPSA4': 'abcSelfPSA4Val'}] +a(42, self={"20": 1}): !result: [42] +pa1(42, self={"20": 1}): !result: ['abcArgsPA1', 42] +pa2(42, self={"20": 1}): !result: [42] +pa3(42, self={"20": 1}): !result: ['abcArgsPA3', 42] +pa4(42, self={"20": 1}): !result: [42] +sa(42, self={"20": 1}): !result: [[42], {'20': 1}] +psa1(42, self={"20": 1}): !result: [['abcArgsPSA1', 42], {'20': 1}] +psa2(42, self={"20": 1}): !result: [[42], {'20': 1}] +psa3(42, self={"20": 1}): !result: [['abcArgsPSA3', 42], {'20': 1}] +psa4(42, self={"20": 1}): !result: [[42], {'20': 1}] +a(self={"20": 1}): !result: [] +pa1(self={"20": 1}): !result: ['abcArgsPA1'] +pa2(self={"20": 1}): !result: [] +pa3(self={"20": 1}): !result: ['abcArgsPA3'] +pa4(self={"20": 1}): !result: [] +sa(self={"20": 1}): !result: [[], {'20': 1}] +psa1(self={"20": 1}): !result: [['abcArgsPSA1'], {'20': 1}] +psa2(self={"20": 1}): !result: [[], {'20': 1}] +psa3(self={"20": 1}): !result: [['abcArgsPSA3'], {'20': 1}] +psa4(self={"20": 1}): !result: [[], {'20': 1}] +a.args: None +pa1.args: ['abcArgsPA1'] +pa2.args: None +pa3.args: ['abcArgsPA3'] +pa4.args: None +sa.args: None +psa1.args: ['abcArgsPSA1'] +psa2.args: None +psa3.args: ['abcArgsPSA3'] +psa4.args: None +a.self: None +pa1.self: None +pa2.self: None +pa3.self: {'abcSelfPA3': 'abcSelfPA3Val'} +pa4.self: {'abcSelfPA4': 'abcSelfPA4Val'} +sa.self: None +psa1.self: None +psa2.self: None +psa3.self: {'abcSelfPSA3': 'abcSelfPSA3Val'} +psa4.self: {'abcSelfPSA4': 'abcSelfPSA4Val'} +a.name: 'Args' +pa1.name: 'Args' +pa2.name: 'Args' +pa3.name: 'Args' +pa4.name: 'Args' +sa.name: 'SelfArgs' +psa1.name: 'SelfArgs' +psa2.name: 'SelfArgs' +psa3.name: 'SelfArgs' +psa4.name: 'SelfArgs' +a.auto_rebind: 1 +pa1.auto_rebind: 1 +pa2.auto_rebind: 1 +pa3.auto_rebind: 0 +pa4.auto_rebind: 0 +sa.auto_rebind: 1 +psa1.auto_rebind: 1 +psa2.auto_rebind: 1 +psa3.auto_rebind: 0 +psa4.auto_rebind: 0 +psa5.auto_rebind: 0 +psa6.auto_rebind: 0 +psa7.auto_rebind: 1 +psa8.auto_rebind: 1 +psa9.auto_rebind: 1 +psaA.auto_rebind: 1 +psaB.auto_rebind: 1 +psaC.auto_rebind: 1 +' +abcdef +Error detected while processing function RunTest[]..Test: +line : +abcdef +abcA +line : +abcB' +['a', 'dup_a'] +['a', 'a'] +['a', 'b', 'c', 'C'] +[2, 2] +[2, 2] +1 +1 +function('Put') +b'testdir' +test87.in +b'src' +testdir/test87.in +b'testdir' +test87.in +> Output +>> OutputSetattr +del sys.stdout.softspace:(<class 'AttributeError'>, AttributeError('cannot delete OutputObject attributes',)) +>>> Testing NumberToLong using sys.stdout.softspace = %s +sys.stdout.softspace = []:(<class 'TypeError'>, TypeError('expected int() or something supporting coercing to int(), but got list',)) +sys.stdout.softspace = None:(<class 'TypeError'>, TypeError('expected int() or something supporting coercing to int(), but got NoneType',)) +sys.stdout.softspace = -1:(<class 'ValueError'>, ValueError('number must be greater or equal to zero',)) +<<< Finished +>>> Testing NumberToLong using sys.stderr.softspace = %s +sys.stderr.softspace = []:(<class 'TypeError'>, TypeError('expected int() or something supporting coercing to int(), but got list',)) +sys.stderr.softspace = None:(<class 'TypeError'>, TypeError('expected int() or something supporting coercing to int(), but got NoneType',)) +sys.stderr.softspace = -1:(<class 'ValueError'>, ValueError('number must be greater or equal to zero',)) +<<< Finished +assert sys.stdout.isatty()==False:NOT FAILED +assert sys.stdout.seekable()==False:NOT FAILED +sys.stdout.close():NOT FAILED +sys.stdout.flush():NOT FAILED +assert sys.stderr.isatty()==False:NOT FAILED +assert sys.stderr.seekable()==False:NOT FAILED +sys.stderr.close():NOT FAILED +sys.stderr.flush():NOT FAILED +sys.stdout.attr = None:(<class 'AttributeError'>, AttributeError('invalid attribute: attr',)) +>> OutputWrite +assert sys.stdout.writable()==True:NOT FAILED +assert sys.stdout.readable()==False:NOT FAILED +assert sys.stderr.writable()==True:NOT FAILED +assert sys.stderr.readable()==False:NOT FAILED +assert sys.stdout.closed()==False:NOT FAILED +assert sys.stderr.closed()==False:NOT FAILED +assert sys.stdout.errors=="strict":NOT FAILED +assert sys.stderr.errors=="strict":NOT FAILED +assert sys.stdout.encoding==sys.stderr.encoding:NOT FAILED +sys.stdout.write(None):(<class 'TypeError'>, TypeError("Can't convert 'NoneType' object to str implicitly",)) +>> OutputWriteLines +sys.stdout.writelines(None):(<class 'TypeError'>, TypeError("'NoneType' object is not iterable",)) +sys.stdout.writelines([1]):(<class 'TypeError'>, TypeError("Can't convert 'int' object to str implicitly",)) +>>> Testing *Iter* using sys.stdout.writelines(%s) +sys.stdout.writelines(FailingIter()):(<class 'NotImplementedError'>, NotImplementedError('iter',)) +sys.stdout.writelines(FailingIterNext()):(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +> VimCommand +>>> Testing StringToChars using vim.command(%s) +vim.command(1):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +vim.command(b"\0"):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +vim.command("\0"):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +vim.command("", 2):(<class 'TypeError'>, TypeError('command() takes exactly one argument (2 given)',)) +> VimToPython +> VimEval +>>> Testing StringToChars using vim.eval(%s) +vim.eval(1):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +vim.eval(b"\0"):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +vim.eval("\0"):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +vim.eval("", FailingTrue()):(<class 'TypeError'>, TypeError('function takes exactly 1 argument (2 given)',)) +> VimEvalPy +>>> Testing StringToChars using vim.bindeval(%s) +vim.bindeval(1):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +vim.bindeval(b"\0"):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +vim.bindeval("\0"):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +vim.eval("", 2):(<class 'TypeError'>, TypeError('function takes exactly 1 argument (2 given)',)) +> VimStrwidth +>>> Testing StringToChars using vim.strwidth(%s) +vim.strwidth(1):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +vim.strwidth(b"\0"):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +vim.strwidth("\0"):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +> VimForeachRTP +vim.foreach_rtp(None):(<class 'TypeError'>, TypeError("'NoneType' object is not callable",)) +vim.foreach_rtp(NoArgsCall()):(<class 'TypeError'>, TypeError('__call__() takes exactly 1 positional argument (2 given)',)) +vim.foreach_rtp(FailingCall()):(<class 'NotImplementedError'>, NotImplementedError('call',)) +vim.foreach_rtp(int, 2):(<class 'TypeError'>, TypeError('foreach_rtp() takes exactly one argument (2 given)',)) +> import +import xxx_no_such_module_xxx:(<class 'ImportError'>, ImportError('No module named xxx_no_such_module_xxx',)) +import failing_import:(<class 'ImportError'>, ImportError()) +import failing:(<class 'NotImplementedError'>, NotImplementedError()) +> Options +>> OptionsItem +vim.options["abcQ"]:(<class 'KeyError'>, KeyError('abcQ',)) +vim.options[""]:(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +>>> Testing StringToChars using vim.options[%s] +vim.options[1]:(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +vim.options[b"\0"]:(<class 'TypeError'>, TypeError('expected bytes with no null',)) +vim.options["\0"]:(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>> OptionsContains +>>> Testing StringToChars using %s in vim.options +1 in vim.options:(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +b"\0" in vim.options:(<class 'TypeError'>, TypeError('expected bytes with no null',)) +"\0" in vim.options:(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +> Dictionary +>> DictionaryConstructor +vim.Dictionary("abcI"):(<class 'ValueError'>, ValueError('expected sequence element of size 2, but got sequence of size 1',)) +>> DictionarySetattr +del d.locked:(<class 'AttributeError'>, AttributeError('cannot delete vim.Dictionary attributes',)) +d.locked = FailingTrue():(<class 'NotImplementedError'>, NotImplementedError('bool',)) +vim.vvars.locked = False:(<class 'TypeError'>, TypeError('cannot modify fixed dictionary',)) +d.scope = True:(<class 'AttributeError'>, AttributeError('cannot set attribute scope',)) +d.xxx = True:(<class 'AttributeError'>, AttributeError('cannot set attribute xxx',)) +>> _DictionaryItem +d.get("a", 2, 3):(<class 'TypeError'>, TypeError('function takes at most 2 arguments (3 given)',)) +>>> Testing StringToChars using d.get(%s) +d.get(1):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +d.get(b"\0"):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +d.get("\0"):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +d.pop("a"):(<class 'KeyError'>, KeyError('a',)) +dl.pop("a"):(<class 'vim.error'>, error('dictionary is locked',)) +>> DictionaryContains +"" in d:(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +0 in d:(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +>> DictionaryIterNext +for i in ned: ned["a"] = 1:(<class 'RuntimeError'>, RuntimeError('hashtab changed during iteration',)) +>> DictionaryAssItem +dl["b"] = 1:(<class 'vim.error'>, error('dictionary is locked',)) +>>> Testing StringToChars using d[%s] = 1 +d[1] = 1:(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +d[b"\0"] = 1:(<class 'TypeError'>, TypeError('expected bytes with no null',)) +d["\0"] = 1:(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using d["a"] = {%s : 1} +d["a"] = {1 : 1}:(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +d["a"] = {b"\0" : 1}:(<class 'TypeError'>, TypeError('expected bytes with no null',)) +d["a"] = {"\0" : 1}:(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using d["a"] = {"abcF" : {%s : 1}} +d["a"] = {"abcF" : {1 : 1}}:(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +d["a"] = {"abcF" : {b"\0" : 1}}:(<class 'TypeError'>, TypeError('expected bytes with no null',)) +d["a"] = {"abcF" : {"\0" : 1}}:(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using d["a"] = {"abcF" : Mapping({%s : 1})} +d["a"] = {"abcF" : Mapping({1 : 1})}:(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +d["a"] = {"abcF" : Mapping({b"\0" : 1})}:(<class 'TypeError'>, TypeError('expected bytes with no null',)) +d["a"] = {"abcF" : Mapping({"\0" : 1})}:(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing *Iter* using d["a"] = {"abcF" : %s} +d["a"] = {"abcF" : FailingIter()}:(<class 'TypeError'>, TypeError('unable to convert FailingIter to vim structure',)) +d["a"] = {"abcF" : FailingIterNext()}:(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing ConvertFromPyObject using d["a"] = {"abcF" : %s} +d["a"] = {"abcF" : None}:NOT FAILED +d["a"] = {"abcF" : {b"": 1}}:(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +d["a"] = {"abcF" : {"": 1}}:(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +d["a"] = {"abcF" : FailingMapping()}:(<class 'NotImplementedError'>, NotImplementedError('keys',)) +d["a"] = {"abcF" : FailingMappingKey()}:(<class 'NotImplementedError'>, NotImplementedError('getitem:mappingkey',)) +d["a"] = {"abcF" : FailingNumber()}:(<class 'NotImplementedError'>, NotImplementedError('int',)) +<<< Finished +>>> Testing StringToChars using d["a"] = Mapping({%s : 1}) +d["a"] = Mapping({1 : 1}):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +d["a"] = Mapping({b"\0" : 1}):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +d["a"] = Mapping({"\0" : 1}):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using d["a"] = Mapping({"abcG" : {%s : 1}}) +d["a"] = Mapping({"abcG" : {1 : 1}}):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +d["a"] = Mapping({"abcG" : {b"\0" : 1}}):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +d["a"] = Mapping({"abcG" : {"\0" : 1}}):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using d["a"] = Mapping({"abcG" : Mapping({%s : 1})}) +d["a"] = Mapping({"abcG" : Mapping({1 : 1})}):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +d["a"] = Mapping({"abcG" : Mapping({b"\0" : 1})}):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +d["a"] = Mapping({"abcG" : Mapping({"\0" : 1})}):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing *Iter* using d["a"] = Mapping({"abcG" : %s}) +d["a"] = Mapping({"abcG" : FailingIter()}):(<class 'TypeError'>, TypeError('unable to convert FailingIter to vim structure',)) +d["a"] = Mapping({"abcG" : FailingIterNext()}):(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing ConvertFromPyObject using d["a"] = Mapping({"abcG" : %s}) +d["a"] = Mapping({"abcG" : None}):NOT FAILED +d["a"] = Mapping({"abcG" : {b"": 1}}):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +d["a"] = Mapping({"abcG" : {"": 1}}):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +d["a"] = Mapping({"abcG" : FailingMapping()}):(<class 'NotImplementedError'>, NotImplementedError('keys',)) +d["a"] = Mapping({"abcG" : FailingMappingKey()}):(<class 'NotImplementedError'>, NotImplementedError('getitem:mappingkey',)) +d["a"] = Mapping({"abcG" : FailingNumber()}):(<class 'NotImplementedError'>, NotImplementedError('int',)) +<<< Finished +>>> Testing *Iter* using d["a"] = %s +d["a"] = FailingIter():(<class 'TypeError'>, TypeError('unable to convert FailingIter to vim structure',)) +d["a"] = FailingIterNext():(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing ConvertFromPyObject using d["a"] = %s +d["a"] = None:NOT FAILED +d["a"] = {b"": 1}:(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +d["a"] = {"": 1}:(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +d["a"] = FailingMapping():(<class 'NotImplementedError'>, NotImplementedError('keys',)) +d["a"] = FailingMappingKey():(<class 'NotImplementedError'>, NotImplementedError('getitem:mappingkey',)) +d["a"] = FailingNumber():(<class 'NotImplementedError'>, NotImplementedError('int',)) +<<< Finished +>> DictionaryUpdate +>>> kwargs +>>> iter +d.update(FailingMapping()):(<class 'NotImplementedError'>, NotImplementedError('keys',)) +d.update([FailingIterNext()]):(<class 'NotImplementedError'>, NotImplementedError('next',)) +d.update([FailingIterNextN(1)]):(<class 'NotImplementedError'>, NotImplementedError('next N',)) +>>> Testing *Iter* using d.update(%s) +d.update(FailingIter()):(<class 'NotImplementedError'>, NotImplementedError('iter',)) +d.update(FailingIterNext()):(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing StringToChars using d.update({%s : 1}) +d.update({1 : 1}):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +d.update({b"\0" : 1}):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +d.update({"\0" : 1}):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using d.update({"abcF" : {%s : 1}}) +d.update({"abcF" : {1 : 1}}):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +d.update({"abcF" : {b"\0" : 1}}):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +d.update({"abcF" : {"\0" : 1}}):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using d.update({"abcF" : Mapping({%s : 1})}) +d.update({"abcF" : Mapping({1 : 1})}):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +d.update({"abcF" : Mapping({b"\0" : 1})}):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +d.update({"abcF" : Mapping({"\0" : 1})}):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing *Iter* using d.update({"abcF" : %s}) +d.update({"abcF" : FailingIter()}):(<class 'TypeError'>, TypeError('unable to convert FailingIter to vim structure',)) +d.update({"abcF" : FailingIterNext()}):(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing ConvertFromPyObject using d.update({"abcF" : %s}) +d.update({"abcF" : None}):NOT FAILED +d.update({"abcF" : {b"": 1}}):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +d.update({"abcF" : {"": 1}}):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +d.update({"abcF" : FailingMapping()}):(<class 'NotImplementedError'>, NotImplementedError('keys',)) +d.update({"abcF" : FailingMappingKey()}):(<class 'NotImplementedError'>, NotImplementedError('getitem:mappingkey',)) +d.update({"abcF" : FailingNumber()}):(<class 'NotImplementedError'>, NotImplementedError('int',)) +<<< Finished +>>> Testing StringToChars using d.update(Mapping({%s : 1})) +d.update(Mapping({1 : 1})):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +d.update(Mapping({b"\0" : 1})):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +d.update(Mapping({"\0" : 1})):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using d.update(Mapping({"abcG" : {%s : 1}})) +d.update(Mapping({"abcG" : {1 : 1}})):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +d.update(Mapping({"abcG" : {b"\0" : 1}})):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +d.update(Mapping({"abcG" : {"\0" : 1}})):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using d.update(Mapping({"abcG" : Mapping({%s : 1})})) +d.update(Mapping({"abcG" : Mapping({1 : 1})})):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +d.update(Mapping({"abcG" : Mapping({b"\0" : 1})})):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +d.update(Mapping({"abcG" : Mapping({"\0" : 1})})):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing *Iter* using d.update(Mapping({"abcG" : %s})) +d.update(Mapping({"abcG" : FailingIter()})):(<class 'TypeError'>, TypeError('unable to convert FailingIter to vim structure',)) +d.update(Mapping({"abcG" : FailingIterNext()})):(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing ConvertFromPyObject using d.update(Mapping({"abcG" : %s})) +d.update(Mapping({"abcG" : None})):NOT FAILED +d.update(Mapping({"abcG" : {b"": 1}})):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +d.update(Mapping({"abcG" : {"": 1}})):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +d.update(Mapping({"abcG" : FailingMapping()})):(<class 'NotImplementedError'>, NotImplementedError('keys',)) +d.update(Mapping({"abcG" : FailingMappingKey()})):(<class 'NotImplementedError'>, NotImplementedError('getitem:mappingkey',)) +d.update(Mapping({"abcG" : FailingNumber()})):(<class 'NotImplementedError'>, NotImplementedError('int',)) +<<< Finished +>>> Testing *Iter* using d.update(%s) +d.update(FailingIter()):(<class 'NotImplementedError'>, NotImplementedError('iter',)) +d.update(FailingIterNext()):(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing ConvertFromPyObject using d.update(%s) +d.update(None):(<class 'TypeError'>, TypeError("'NoneType' object is not iterable",)) +d.update({b"": 1}):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +d.update({"": 1}):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +d.update(FailingMapping()):(<class 'NotImplementedError'>, NotImplementedError('keys',)) +d.update(FailingMappingKey()):(<class 'NotImplementedError'>, NotImplementedError('getitem:mappingkey',)) +d.update(FailingNumber()):(<class 'TypeError'>, TypeError("'FailingNumber' object is not iterable",)) +<<< Finished +>>> Testing StringToChars using d.update(((%s, 0),)) +d.update(((1, 0),)):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +d.update(((b"\0", 0),)):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +d.update((("\0", 0),)):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using d.update((("a", {%s : 1}),)) +d.update((("a", {1 : 1}),)):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +d.update((("a", {b"\0" : 1}),)):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +d.update((("a", {"\0" : 1}),)):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using d.update((("a", {"abcF" : {%s : 1}}),)) +d.update((("a", {"abcF" : {1 : 1}}),)):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +d.update((("a", {"abcF" : {b"\0" : 1}}),)):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +d.update((("a", {"abcF" : {"\0" : 1}}),)):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using d.update((("a", {"abcF" : Mapping({%s : 1})}),)) +d.update((("a", {"abcF" : Mapping({1 : 1})}),)):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +d.update((("a", {"abcF" : Mapping({b"\0" : 1})}),)):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +d.update((("a", {"abcF" : Mapping({"\0" : 1})}),)):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing *Iter* using d.update((("a", {"abcF" : %s}),)) +d.update((("a", {"abcF" : FailingIter()}),)):(<class 'TypeError'>, TypeError('unable to convert FailingIter to vim structure',)) +d.update((("a", {"abcF" : FailingIterNext()}),)):(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing ConvertFromPyObject using d.update((("a", {"abcF" : %s}),)) +d.update((("a", {"abcF" : None}),)):(<class 'vim.error'>, error("failed to add key 'a' to dictionary",)) +d.update((("a", {"abcF" : {b"": 1}}),)):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +d.update((("a", {"abcF" : {"": 1}}),)):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +d.update((("a", {"abcF" : FailingMapping()}),)):(<class 'NotImplementedError'>, NotImplementedError('keys',)) +d.update((("a", {"abcF" : FailingMappingKey()}),)):(<class 'NotImplementedError'>, NotImplementedError('getitem:mappingkey',)) +d.update((("a", {"abcF" : FailingNumber()}),)):(<class 'NotImplementedError'>, NotImplementedError('int',)) +<<< Finished +>>> Testing StringToChars using d.update((("a", Mapping({%s : 1})),)) +d.update((("a", Mapping({1 : 1})),)):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +d.update((("a", Mapping({b"\0" : 1})),)):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +d.update((("a", Mapping({"\0" : 1})),)):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using d.update((("a", Mapping({"abcG" : {%s : 1}})),)) +d.update((("a", Mapping({"abcG" : {1 : 1}})),)):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +d.update((("a", Mapping({"abcG" : {b"\0" : 1}})),)):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +d.update((("a", Mapping({"abcG" : {"\0" : 1}})),)):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using d.update((("a", Mapping({"abcG" : Mapping({%s : 1})})),)) +d.update((("a", Mapping({"abcG" : Mapping({1 : 1})})),)):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +d.update((("a", Mapping({"abcG" : Mapping({b"\0" : 1})})),)):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +d.update((("a", Mapping({"abcG" : Mapping({"\0" : 1})})),)):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing *Iter* using d.update((("a", Mapping({"abcG" : %s})),)) +d.update((("a", Mapping({"abcG" : FailingIter()})),)):(<class 'TypeError'>, TypeError('unable to convert FailingIter to vim structure',)) +d.update((("a", Mapping({"abcG" : FailingIterNext()})),)):(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing ConvertFromPyObject using d.update((("a", Mapping({"abcG" : %s})),)) +d.update((("a", Mapping({"abcG" : None})),)):(<class 'vim.error'>, error("failed to add key 'a' to dictionary",)) +d.update((("a", Mapping({"abcG" : {b"": 1}})),)):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +d.update((("a", Mapping({"abcG" : {"": 1}})),)):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +d.update((("a", Mapping({"abcG" : FailingMapping()})),)):(<class 'NotImplementedError'>, NotImplementedError('keys',)) +d.update((("a", Mapping({"abcG" : FailingMappingKey()})),)):(<class 'NotImplementedError'>, NotImplementedError('getitem:mappingkey',)) +d.update((("a", Mapping({"abcG" : FailingNumber()})),)):(<class 'NotImplementedError'>, NotImplementedError('int',)) +<<< Finished +>>> Testing *Iter* using d.update((("a", %s),)) +d.update((("a", FailingIter()),)):(<class 'TypeError'>, TypeError('unable to convert FailingIter to vim structure',)) +d.update((("a", FailingIterNext()),)):(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing ConvertFromPyObject using d.update((("a", %s),)) +d.update((("a", None),)):(<class 'vim.error'>, error("failed to add key 'a' to dictionary",)) +d.update((("a", {b"": 1}),)):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +d.update((("a", {"": 1}),)):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +d.update((("a", FailingMapping()),)):(<class 'NotImplementedError'>, NotImplementedError('keys',)) +d.update((("a", FailingMappingKey()),)):(<class 'NotImplementedError'>, NotImplementedError('getitem:mappingkey',)) +d.update((("a", FailingNumber()),)):(<class 'NotImplementedError'>, NotImplementedError('int',)) +<<< Finished +>> DictionaryPopItem +d.popitem(1, 2):(<class 'TypeError'>, TypeError('popitem() takes no arguments (2 given)',)) +>> DictionaryHasKey +d.has_key():(<class 'TypeError'>, TypeError('has_key() takes exactly one argument (0 given)',)) +> List +>> ListConstructor +vim.List(1, 2):(<class 'TypeError'>, TypeError('function takes at most 1 argument (2 given)',)) +vim.List(a=1):(<class 'TypeError'>, TypeError('list constructor does not accept keyword arguments',)) +>>> Testing *Iter* using vim.List(%s) +vim.List(FailingIter()):(<class 'NotImplementedError'>, NotImplementedError('iter',)) +vim.List(FailingIterNext()):(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing StringToChars using vim.List([{%s : 1}]) +vim.List([{1 : 1}]):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +vim.List([{b"\0" : 1}]):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +vim.List([{"\0" : 1}]):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using vim.List([{"abcF" : {%s : 1}}]) +vim.List([{"abcF" : {1 : 1}}]):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +vim.List([{"abcF" : {b"\0" : 1}}]):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +vim.List([{"abcF" : {"\0" : 1}}]):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using vim.List([{"abcF" : Mapping({%s : 1})}]) +vim.List([{"abcF" : Mapping({1 : 1})}]):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +vim.List([{"abcF" : Mapping({b"\0" : 1})}]):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +vim.List([{"abcF" : Mapping({"\0" : 1})}]):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing *Iter* using vim.List([{"abcF" : %s}]) +vim.List([{"abcF" : FailingIter()}]):(<class 'TypeError'>, TypeError('unable to convert FailingIter to vim structure',)) +vim.List([{"abcF" : FailingIterNext()}]):(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing ConvertFromPyObject using vim.List([{"abcF" : %s}]) +vim.List([{"abcF" : None}]):NOT FAILED +vim.List([{"abcF" : {b"": 1}}]):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +vim.List([{"abcF" : {"": 1}}]):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +vim.List([{"abcF" : FailingMapping()}]):(<class 'NotImplementedError'>, NotImplementedError('keys',)) +vim.List([{"abcF" : FailingMappingKey()}]):(<class 'NotImplementedError'>, NotImplementedError('getitem:mappingkey',)) +vim.List([{"abcF" : FailingNumber()}]):(<class 'NotImplementedError'>, NotImplementedError('int',)) +<<< Finished +>>> Testing StringToChars using vim.List([Mapping({%s : 1})]) +vim.List([Mapping({1 : 1})]):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +vim.List([Mapping({b"\0" : 1})]):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +vim.List([Mapping({"\0" : 1})]):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using vim.List([Mapping({"abcG" : {%s : 1}})]) +vim.List([Mapping({"abcG" : {1 : 1}})]):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +vim.List([Mapping({"abcG" : {b"\0" : 1}})]):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +vim.List([Mapping({"abcG" : {"\0" : 1}})]):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using vim.List([Mapping({"abcG" : Mapping({%s : 1})})]) +vim.List([Mapping({"abcG" : Mapping({1 : 1})})]):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +vim.List([Mapping({"abcG" : Mapping({b"\0" : 1})})]):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +vim.List([Mapping({"abcG" : Mapping({"\0" : 1})})]):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing *Iter* using vim.List([Mapping({"abcG" : %s})]) +vim.List([Mapping({"abcG" : FailingIter()})]):(<class 'TypeError'>, TypeError('unable to convert FailingIter to vim structure',)) +vim.List([Mapping({"abcG" : FailingIterNext()})]):(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing ConvertFromPyObject using vim.List([Mapping({"abcG" : %s})]) +vim.List([Mapping({"abcG" : None})]):NOT FAILED +vim.List([Mapping({"abcG" : {b"": 1}})]):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +vim.List([Mapping({"abcG" : {"": 1}})]):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +vim.List([Mapping({"abcG" : FailingMapping()})]):(<class 'NotImplementedError'>, NotImplementedError('keys',)) +vim.List([Mapping({"abcG" : FailingMappingKey()})]):(<class 'NotImplementedError'>, NotImplementedError('getitem:mappingkey',)) +vim.List([Mapping({"abcG" : FailingNumber()})]):(<class 'NotImplementedError'>, NotImplementedError('int',)) +<<< Finished +>>> Testing *Iter* using vim.List([%s]) +vim.List([FailingIter()]):(<class 'TypeError'>, TypeError('unable to convert FailingIter to vim structure',)) +vim.List([FailingIterNext()]):(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing ConvertFromPyObject using vim.List([%s]) +vim.List([None]):NOT FAILED +vim.List([{b"": 1}]):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +vim.List([{"": 1}]):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +vim.List([FailingMapping()]):(<class 'NotImplementedError'>, NotImplementedError('keys',)) +vim.List([FailingMappingKey()]):(<class 'NotImplementedError'>, NotImplementedError('getitem:mappingkey',)) +vim.List([FailingNumber()]):(<class 'NotImplementedError'>, NotImplementedError('int',)) +<<< Finished +>> ListItem +l[1000]:(<class 'IndexError'>, IndexError('list index out of range',)) +>> ListAssItem +ll[1] = 2:(<class 'vim.error'>, error('list is locked',)) +l[1000] = 3:(<class 'IndexError'>, IndexError('list index out of range',)) +>> ListAssSlice +ll[1:100] = "abcJ":(<class 'vim.error'>, error('list is locked',)) +>>> Testing *Iter* using l[:] = %s +l[:] = FailingIter():(<class 'NotImplementedError'>, NotImplementedError('iter',)) +l[:] = FailingIterNext():(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +nel[1:10:2] = "abcK":(<class 'ValueError'>, ValueError('attempt to assign sequence of size greater than 2 to extended slice',)) +(b'a', b'b', b'c', b'O') +nel[1:10:2] = "a":(<class 'ValueError'>, ValueError('attempt to assign sequence of size 1 to extended slice of size 2',)) +(b'a', b'b', b'c', b'O') +nel[1:1:-1] = "a":(<class 'ValueError'>, ValueError('attempt to assign sequence of size greater than 0 to extended slice',)) +(b'a', b'b', b'c', b'O') +nel[:] = FailingIterNextN(2):(<class 'NotImplementedError'>, NotImplementedError('next N',)) +(b'a', b'b', b'c', b'O') +>>> Testing StringToChars using l[:] = [{%s : 1}] +l[:] = [{1 : 1}]:(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +l[:] = [{b"\0" : 1}]:(<class 'TypeError'>, TypeError('expected bytes with no null',)) +l[:] = [{"\0" : 1}]:(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using l[:] = [{"abcF" : {%s : 1}}] +l[:] = [{"abcF" : {1 : 1}}]:(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +l[:] = [{"abcF" : {b"\0" : 1}}]:(<class 'TypeError'>, TypeError('expected bytes with no null',)) +l[:] = [{"abcF" : {"\0" : 1}}]:(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using l[:] = [{"abcF" : Mapping({%s : 1})}] +l[:] = [{"abcF" : Mapping({1 : 1})}]:(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +l[:] = [{"abcF" : Mapping({b"\0" : 1})}]:(<class 'TypeError'>, TypeError('expected bytes with no null',)) +l[:] = [{"abcF" : Mapping({"\0" : 1})}]:(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing *Iter* using l[:] = [{"abcF" : %s}] +l[:] = [{"abcF" : FailingIter()}]:(<class 'TypeError'>, TypeError('unable to convert FailingIter to vim structure',)) +l[:] = [{"abcF" : FailingIterNext()}]:(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing ConvertFromPyObject using l[:] = [{"abcF" : %s}] +l[:] = [{"abcF" : None}]:NOT FAILED +l[:] = [{"abcF" : {b"": 1}}]:(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +l[:] = [{"abcF" : {"": 1}}]:(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +l[:] = [{"abcF" : FailingMapping()}]:(<class 'NotImplementedError'>, NotImplementedError('keys',)) +l[:] = [{"abcF" : FailingMappingKey()}]:(<class 'NotImplementedError'>, NotImplementedError('getitem:mappingkey',)) +l[:] = [{"abcF" : FailingNumber()}]:(<class 'NotImplementedError'>, NotImplementedError('int',)) +<<< Finished +>>> Testing StringToChars using l[:] = [Mapping({%s : 1})] +l[:] = [Mapping({1 : 1})]:(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +l[:] = [Mapping({b"\0" : 1})]:(<class 'TypeError'>, TypeError('expected bytes with no null',)) +l[:] = [Mapping({"\0" : 1})]:(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using l[:] = [Mapping({"abcG" : {%s : 1}})] +l[:] = [Mapping({"abcG" : {1 : 1}})]:(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +l[:] = [Mapping({"abcG" : {b"\0" : 1}})]:(<class 'TypeError'>, TypeError('expected bytes with no null',)) +l[:] = [Mapping({"abcG" : {"\0" : 1}})]:(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using l[:] = [Mapping({"abcG" : Mapping({%s : 1})})] +l[:] = [Mapping({"abcG" : Mapping({1 : 1})})]:(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +l[:] = [Mapping({"abcG" : Mapping({b"\0" : 1})})]:(<class 'TypeError'>, TypeError('expected bytes with no null',)) +l[:] = [Mapping({"abcG" : Mapping({"\0" : 1})})]:(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing *Iter* using l[:] = [Mapping({"abcG" : %s})] +l[:] = [Mapping({"abcG" : FailingIter()})]:(<class 'TypeError'>, TypeError('unable to convert FailingIter to vim structure',)) +l[:] = [Mapping({"abcG" : FailingIterNext()})]:(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing ConvertFromPyObject using l[:] = [Mapping({"abcG" : %s})] +l[:] = [Mapping({"abcG" : None})]:NOT FAILED +l[:] = [Mapping({"abcG" : {b"": 1}})]:(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +l[:] = [Mapping({"abcG" : {"": 1}})]:(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +l[:] = [Mapping({"abcG" : FailingMapping()})]:(<class 'NotImplementedError'>, NotImplementedError('keys',)) +l[:] = [Mapping({"abcG" : FailingMappingKey()})]:(<class 'NotImplementedError'>, NotImplementedError('getitem:mappingkey',)) +l[:] = [Mapping({"abcG" : FailingNumber()})]:(<class 'NotImplementedError'>, NotImplementedError('int',)) +<<< Finished +>>> Testing *Iter* using l[:] = [%s] +l[:] = [FailingIter()]:(<class 'TypeError'>, TypeError('unable to convert FailingIter to vim structure',)) +l[:] = [FailingIterNext()]:(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing ConvertFromPyObject using l[:] = [%s] +l[:] = [None]:NOT FAILED +l[:] = [{b"": 1}]:(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +l[:] = [{"": 1}]:(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +l[:] = [FailingMapping()]:(<class 'NotImplementedError'>, NotImplementedError('keys',)) +l[:] = [FailingMappingKey()]:(<class 'NotImplementedError'>, NotImplementedError('getitem:mappingkey',)) +l[:] = [FailingNumber()]:(<class 'NotImplementedError'>, NotImplementedError('int',)) +<<< Finished +>> ListConcatInPlace +>>> Testing *Iter* using l.extend(%s) +l.extend(FailingIter()):(<class 'NotImplementedError'>, NotImplementedError('iter',)) +l.extend(FailingIterNext()):(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing StringToChars using l.extend([{%s : 1}]) +l.extend([{1 : 1}]):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +l.extend([{b"\0" : 1}]):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +l.extend([{"\0" : 1}]):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using l.extend([{"abcF" : {%s : 1}}]) +l.extend([{"abcF" : {1 : 1}}]):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +l.extend([{"abcF" : {b"\0" : 1}}]):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +l.extend([{"abcF" : {"\0" : 1}}]):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using l.extend([{"abcF" : Mapping({%s : 1})}]) +l.extend([{"abcF" : Mapping({1 : 1})}]):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +l.extend([{"abcF" : Mapping({b"\0" : 1})}]):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +l.extend([{"abcF" : Mapping({"\0" : 1})}]):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing *Iter* using l.extend([{"abcF" : %s}]) +l.extend([{"abcF" : FailingIter()}]):(<class 'TypeError'>, TypeError('unable to convert FailingIter to vim structure',)) +l.extend([{"abcF" : FailingIterNext()}]):(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing ConvertFromPyObject using l.extend([{"abcF" : %s}]) +l.extend([{"abcF" : None}]):NOT FAILED +l.extend([{"abcF" : {b"": 1}}]):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +l.extend([{"abcF" : {"": 1}}]):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +l.extend([{"abcF" : FailingMapping()}]):(<class 'NotImplementedError'>, NotImplementedError('keys',)) +l.extend([{"abcF" : FailingMappingKey()}]):(<class 'NotImplementedError'>, NotImplementedError('getitem:mappingkey',)) +l.extend([{"abcF" : FailingNumber()}]):(<class 'NotImplementedError'>, NotImplementedError('int',)) +<<< Finished +>>> Testing StringToChars using l.extend([Mapping({%s : 1})]) +l.extend([Mapping({1 : 1})]):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +l.extend([Mapping({b"\0" : 1})]):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +l.extend([Mapping({"\0" : 1})]):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using l.extend([Mapping({"abcG" : {%s : 1}})]) +l.extend([Mapping({"abcG" : {1 : 1}})]):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +l.extend([Mapping({"abcG" : {b"\0" : 1}})]):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +l.extend([Mapping({"abcG" : {"\0" : 1}})]):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using l.extend([Mapping({"abcG" : Mapping({%s : 1})})]) +l.extend([Mapping({"abcG" : Mapping({1 : 1})})]):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +l.extend([Mapping({"abcG" : Mapping({b"\0" : 1})})]):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +l.extend([Mapping({"abcG" : Mapping({"\0" : 1})})]):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing *Iter* using l.extend([Mapping({"abcG" : %s})]) +l.extend([Mapping({"abcG" : FailingIter()})]):(<class 'TypeError'>, TypeError('unable to convert FailingIter to vim structure',)) +l.extend([Mapping({"abcG" : FailingIterNext()})]):(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing ConvertFromPyObject using l.extend([Mapping({"abcG" : %s})]) +l.extend([Mapping({"abcG" : None})]):NOT FAILED +l.extend([Mapping({"abcG" : {b"": 1}})]):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +l.extend([Mapping({"abcG" : {"": 1}})]):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +l.extend([Mapping({"abcG" : FailingMapping()})]):(<class 'NotImplementedError'>, NotImplementedError('keys',)) +l.extend([Mapping({"abcG" : FailingMappingKey()})]):(<class 'NotImplementedError'>, NotImplementedError('getitem:mappingkey',)) +l.extend([Mapping({"abcG" : FailingNumber()})]):(<class 'NotImplementedError'>, NotImplementedError('int',)) +<<< Finished +>>> Testing *Iter* using l.extend([%s]) +l.extend([FailingIter()]):(<class 'TypeError'>, TypeError('unable to convert FailingIter to vim structure',)) +l.extend([FailingIterNext()]):(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing ConvertFromPyObject using l.extend([%s]) +l.extend([None]):NOT FAILED +l.extend([{b"": 1}]):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +l.extend([{"": 1}]):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +l.extend([FailingMapping()]):(<class 'NotImplementedError'>, NotImplementedError('keys',)) +l.extend([FailingMappingKey()]):(<class 'NotImplementedError'>, NotImplementedError('getitem:mappingkey',)) +l.extend([FailingNumber()]):(<class 'NotImplementedError'>, NotImplementedError('int',)) +<<< Finished +>> ListSetattr +del l.locked:(<class 'AttributeError'>, AttributeError('cannot delete vim.List attributes',)) +l.locked = FailingTrue():(<class 'NotImplementedError'>, NotImplementedError('bool',)) +l.xxx = True:(<class 'AttributeError'>, AttributeError('cannot set attribute xxx',)) +> Function +>> FunctionConstructor +>>> FunctionConstructor +vim.Function("123"):(<class 'ValueError'>, ValueError('unnamed function 123 does not exist',)) +vim.Function("xxx_non_existent_function_xxx"):(<class 'ValueError'>, ValueError('function xxx_non_existent_function_xxx does not exist',)) +vim.Function("xxx#non#existent#function#xxx"):NOT FAILED +vim.Function("xxx_non_existent_function_xxx2", args=[]):(<class 'ValueError'>, ValueError('function xxx_non_existent_function_xxx2 does not exist',)) +vim.Function("xxx_non_existent_function_xxx3", self={}):(<class 'ValueError'>, ValueError('function xxx_non_existent_function_xxx3 does not exist',)) +vim.Function("xxx_non_existent_function_xxx4", args=[], self={}):(<class 'ValueError'>, ValueError('function xxx_non_existent_function_xxx4 does not exist',)) +>>> FunctionNew +vim.Function("tr", self="abcFuncSelf"):(<class 'AttributeError'>, AttributeError('keys',)) +vim.Function("tr", args=427423):(<class 'TypeError'>, TypeError('unable to convert int to vim list',)) +vim.Function("tr", self="abcFuncSelf2", args="abcFuncArgs2"):(<class 'AttributeError'>, AttributeError('keys',)) +vim.Function(self="abcFuncSelf2", args="abcFuncArgs2"):(<class 'AttributeError'>, AttributeError('keys',)) +vim.Function("tr", "", self="abcFuncSelf2", args="abcFuncArgs2"):(<class 'AttributeError'>, AttributeError('keys',)) +vim.Function("tr", ""):(<class 'TypeError'>, TypeError('function takes exactly 1 argument (2 given)',)) +>> FunctionCall +>>> Testing StringToChars using f({%s : 1}) +f({1 : 1}):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +f({b"\0" : 1}):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +f({"\0" : 1}):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using f({"abcF" : {%s : 1}}) +f({"abcF" : {1 : 1}}):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +f({"abcF" : {b"\0" : 1}}):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +f({"abcF" : {"\0" : 1}}):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using f({"abcF" : Mapping({%s : 1})}) +f({"abcF" : Mapping({1 : 1})}):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +f({"abcF" : Mapping({b"\0" : 1})}):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +f({"abcF" : Mapping({"\0" : 1})}):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing *Iter* using f({"abcF" : %s}) +f({"abcF" : FailingIter()}):(<class 'TypeError'>, TypeError('unable to convert FailingIter to vim structure',)) +f({"abcF" : FailingIterNext()}):(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing ConvertFromPyObject using f({"abcF" : %s}) +f({"abcF" : None}):NOT FAILED +f({"abcF" : {b"": 1}}):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +f({"abcF" : {"": 1}}):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +f({"abcF" : FailingMapping()}):(<class 'NotImplementedError'>, NotImplementedError('keys',)) +f({"abcF" : FailingMappingKey()}):(<class 'NotImplementedError'>, NotImplementedError('getitem:mappingkey',)) +f({"abcF" : FailingNumber()}):(<class 'NotImplementedError'>, NotImplementedError('int',)) +<<< Finished +>>> Testing StringToChars using f(Mapping({%s : 1})) +f(Mapping({1 : 1})):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +f(Mapping({b"\0" : 1})):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +f(Mapping({"\0" : 1})):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using f(Mapping({"abcG" : {%s : 1}})) +f(Mapping({"abcG" : {1 : 1}})):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +f(Mapping({"abcG" : {b"\0" : 1}})):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +f(Mapping({"abcG" : {"\0" : 1}})):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using f(Mapping({"abcG" : Mapping({%s : 1})})) +f(Mapping({"abcG" : Mapping({1 : 1})})):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +f(Mapping({"abcG" : Mapping({b"\0" : 1})})):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +f(Mapping({"abcG" : Mapping({"\0" : 1})})):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing *Iter* using f(Mapping({"abcG" : %s})) +f(Mapping({"abcG" : FailingIter()})):(<class 'TypeError'>, TypeError('unable to convert FailingIter to vim structure',)) +f(Mapping({"abcG" : FailingIterNext()})):(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing ConvertFromPyObject using f(Mapping({"abcG" : %s})) +f(Mapping({"abcG" : None})):NOT FAILED +f(Mapping({"abcG" : {b"": 1}})):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +f(Mapping({"abcG" : {"": 1}})):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +f(Mapping({"abcG" : FailingMapping()})):(<class 'NotImplementedError'>, NotImplementedError('keys',)) +f(Mapping({"abcG" : FailingMappingKey()})):(<class 'NotImplementedError'>, NotImplementedError('getitem:mappingkey',)) +f(Mapping({"abcG" : FailingNumber()})):(<class 'NotImplementedError'>, NotImplementedError('int',)) +<<< Finished +>>> Testing *Iter* using f(%s) +f(FailingIter()):(<class 'TypeError'>, TypeError('unable to convert FailingIter to vim structure',)) +f(FailingIterNext()):(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing ConvertFromPyObject using f(%s) +f(None):NOT FAILED +f({b"": 1}):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +f({"": 1}):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +f(FailingMapping()):(<class 'NotImplementedError'>, NotImplementedError('keys',)) +f(FailingMappingKey()):(<class 'NotImplementedError'>, NotImplementedError('getitem:mappingkey',)) +f(FailingNumber()):(<class 'NotImplementedError'>, NotImplementedError('int',)) +<<< Finished +>>> Testing StringToChars using fd(self={%s : 1}) +fd(self={1 : 1}):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +fd(self={b"\0" : 1}):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +fd(self={"\0" : 1}):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using fd(self={"abcF" : {%s : 1}}) +fd(self={"abcF" : {1 : 1}}):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +fd(self={"abcF" : {b"\0" : 1}}):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +fd(self={"abcF" : {"\0" : 1}}):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using fd(self={"abcF" : Mapping({%s : 1})}) +fd(self={"abcF" : Mapping({1 : 1})}):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +fd(self={"abcF" : Mapping({b"\0" : 1})}):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +fd(self={"abcF" : Mapping({"\0" : 1})}):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing *Iter* using fd(self={"abcF" : %s}) +fd(self={"abcF" : FailingIter()}):(<class 'TypeError'>, TypeError('unable to convert FailingIter to vim structure',)) +fd(self={"abcF" : FailingIterNext()}):(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing ConvertFromPyObject using fd(self={"abcF" : %s}) +fd(self={"abcF" : None}):NOT FAILED +fd(self={"abcF" : {b"": 1}}):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +fd(self={"abcF" : {"": 1}}):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +fd(self={"abcF" : FailingMapping()}):(<class 'NotImplementedError'>, NotImplementedError('keys',)) +fd(self={"abcF" : FailingMappingKey()}):(<class 'NotImplementedError'>, NotImplementedError('getitem:mappingkey',)) +fd(self={"abcF" : FailingNumber()}):(<class 'NotImplementedError'>, NotImplementedError('int',)) +<<< Finished +>>> Testing StringToChars using fd(self=Mapping({%s : 1})) +fd(self=Mapping({1 : 1})):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +fd(self=Mapping({b"\0" : 1})):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +fd(self=Mapping({"\0" : 1})):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using fd(self=Mapping({"abcG" : {%s : 1}})) +fd(self=Mapping({"abcG" : {1 : 1}})):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +fd(self=Mapping({"abcG" : {b"\0" : 1}})):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +fd(self=Mapping({"abcG" : {"\0" : 1}})):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing StringToChars using fd(self=Mapping({"abcG" : Mapping({%s : 1})})) +fd(self=Mapping({"abcG" : Mapping({1 : 1})})):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +fd(self=Mapping({"abcG" : Mapping({b"\0" : 1})})):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +fd(self=Mapping({"abcG" : Mapping({"\0" : 1})})):(<class 'TypeError'>, TypeError('expected bytes with no null',)) +<<< Finished +>>> Testing *Iter* using fd(self=Mapping({"abcG" : %s})) +fd(self=Mapping({"abcG" : FailingIter()})):(<class 'TypeError'>, TypeError('unable to convert FailingIter to vim structure',)) +fd(self=Mapping({"abcG" : FailingIterNext()})):(<class 'NotImplementedError'>, NotImplementedError('next',)) +<<< Finished +>>> Testing ConvertFromPyObject using fd(self=Mapping({"abcG" : %s})) +fd(self=Mapping({"abcG" : None})):NOT FAILED +fd(self=Mapping({"abcG" : {b"": 1}})):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +fd(self=Mapping({"abcG" : {"": 1}})):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +fd(self=Mapping({"abcG" : FailingMapping()})):(<class 'NotImplementedError'>, NotImplementedError('keys',)) +fd(self=Mapping({"abcG" : FailingMappingKey()})):(<class 'NotImplementedError'>, NotImplementedError('getitem:mappingkey',)) +fd(self=Mapping({"abcG" : FailingNumber()})):(<class 'NotImplementedError'>, NotImplementedError('int',)) +<<< Finished +>>> Testing *Iter* using fd(self=%s) +fd(self=FailingIter()):(<class 'TypeError'>, TypeError('unable to convert FailingIter to vim dictionary',)) +fd(self=FailingIterNext()):(<class 'TypeError'>, TypeError('unable to convert FailingIterNext to vim dictionary',)) +<<< Finished +>>> Testing ConvertFromPyObject using fd(self=%s) +fd(self=None):(<class 'TypeError'>, TypeError('unable to convert NoneType to vim dictionary',)) +fd(self={b"": 1}):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +fd(self={"": 1}):(<class 'ValueError'>, ValueError('empty keys are not allowed',)) +fd(self=FailingMapping()):(<class 'NotImplementedError'>, NotImplementedError('keys',)) +fd(self=FailingMappingKey()):(<class 'NotImplementedError'>, NotImplementedError('getitem:mappingkey',)) +fd(self=FailingNumber()):(<class 'TypeError'>, TypeError('unable to convert FailingNumber to vim dictionary',)) +<<< Finished +>>> Testing ConvertFromPyMapping using fd(self=%s) +fd(self=[]):(<class 'AttributeError'>, AttributeError('keys',)) +<<< Finished +> TabPage +>> TabPageAttr +vim.current.tabpage.xxx:(<class 'AttributeError'>, AttributeError("'vim.tabpage' object has no attribute 'xxx'",)) +> TabList +>> TabListItem +vim.tabpages[1000]:(<class 'IndexError'>, IndexError('no such tab page',)) +> Window +>> WindowAttr +vim.current.window.xxx:(<class 'AttributeError'>, AttributeError("'vim.window' object has no attribute 'xxx'",)) +>> WindowSetattr +vim.current.window.buffer = 0:(<class 'TypeError'>, TypeError('readonly attribute: buffer',)) +vim.current.window.cursor = (100000000, 100000000):(<class 'vim.error'>, error('cursor position outside buffer',)) +vim.current.window.cursor = True:(<class 'TypeError'>, TypeError('argument must be 2-item sequence, not bool',)) +>>> Testing NumberToLong using vim.current.window.height = %s +vim.current.window.height = []:(<class 'TypeError'>, TypeError('expected int() or something supporting coercing to int(), but got list',)) +vim.current.window.height = None:(<class 'TypeError'>, TypeError('expected int() or something supporting coercing to int(), but got NoneType',)) +vim.current.window.height = -1:(<class 'ValueError'>, ValueError('number must be greater or equal to zero',)) +<<< Finished +>>> Testing NumberToLong using vim.current.window.width = %s +vim.current.window.width = []:(<class 'TypeError'>, TypeError('expected int() or something supporting coercing to int(), but got list',)) +vim.current.window.width = None:(<class 'TypeError'>, TypeError('expected int() or something supporting coercing to int(), but got NoneType',)) +vim.current.window.width = -1:(<class 'ValueError'>, ValueError('number must be greater or equal to zero',)) +<<< Finished +vim.current.window.xxxxxx = True:(<class 'AttributeError'>, AttributeError('xxxxxx',)) +> WinList +>> WinListItem +vim.windows[1000]:(<class 'IndexError'>, IndexError('no such window',)) +> Buffer +>> StringToLine (indirect) +vim.current.buffer[0] = "\na":(<class 'vim.error'>, error('string cannot contain newlines',)) +vim.current.buffer[0] = b"\na":(<class 'vim.error'>, error('string cannot contain newlines',)) +>> SetBufferLine (indirect) +vim.current.buffer[0] = True:(<class 'TypeError'>, TypeError('bad argument type for built-in operation',)) +>> SetBufferLineList (indirect) +vim.current.buffer[:] = True:(<class 'TypeError'>, TypeError('bad argument type for built-in operation',)) +vim.current.buffer[:] = ["\na", "bc"]:(<class 'vim.error'>, error('string cannot contain newlines',)) +>> InsertBufferLines (indirect) +vim.current.buffer.append(None):(<class 'TypeError'>, TypeError('bad argument type for built-in operation',)) +vim.current.buffer.append(["\na", "bc"]):(<class 'vim.error'>, error('string cannot contain newlines',)) +vim.current.buffer.append("\nbc"):(<class 'vim.error'>, error('string cannot contain newlines',)) +>> RBItem +vim.current.buffer[100000000]:(<class 'IndexError'>, IndexError('line number out of range',)) +>> RBAsItem +vim.current.buffer[100000000] = "":(<class 'IndexError'>, IndexError('line number out of range',)) +>> BufferAttr +vim.current.buffer.xxx:(<class 'AttributeError'>, AttributeError("'vim.buffer' object has no attribute 'xxx'",)) +>> BufferSetattr +vim.current.buffer.name = True:(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got bool',)) +vim.current.buffer.xxx = True:(<class 'AttributeError'>, AttributeError('xxx',)) +>> BufferMark +vim.current.buffer.mark(0):(<class 'TypeError'>, TypeError('expected bytes() or str() instance, but got int',)) +vim.current.buffer.mark("abcM"):(<class 'ValueError'>, ValueError('mark name must be a single character',)) +vim.current.buffer.mark("!"):(<class 'vim.error'>, error('invalid mark name',)) +>> BufferRange +vim.current.buffer.range(1, 2, 3):(<class 'TypeError'>, TypeError('function takes exactly 2 arguments (3 given)',)) +> BufMap +>> BufMapItem +vim.buffers[100000000]:(<class 'KeyError'>, KeyError(100000000,)) +>>> Testing NumberToLong using vim.buffers[%s] +vim.buffers[[]]:(<class 'TypeError'>, TypeError('expected int() or something supporting coercing to int(), but got list',)) +vim.buffers[None]:(<class 'TypeError'>, TypeError('expected int() or something supporting coercing to int(), but got NoneType',)) +vim.buffers[-1]:(<class 'ValueError'>, ValueError('number must be greater than zero',)) +vim.buffers[0]:(<class 'ValueError'>, ValueError('number must be greater than zero',)) +<<< Finished +> Current +>> CurrentGetattr +vim.current.xxx:(<class 'AttributeError'>, AttributeError("'vim.currentdata' object has no attribute 'xxx'",)) +>> CurrentSetattr +vim.current.line = True:(<class 'TypeError'>, TypeError('bad argument type for built-in operation',)) +vim.current.buffer = True:(<class 'TypeError'>, TypeError('expected vim.Buffer object, but got bool',)) +vim.current.window = True:(<class 'TypeError'>, TypeError('expected vim.Window object, but got bool',)) +vim.current.tabpage = True:(<class 'TypeError'>, TypeError('expected vim.TabPage object, but got bool',)) +vim.current.xxx = True:(<class 'AttributeError'>, AttributeError('xxx',)) +['.'] +'.' +3,xx +before +after +pythonx/topmodule/__init__.py +pythonx/topmodule/submodule/__init__.py +pythonx/topmodule/submodule/subsubmodule/subsubsubmodule.py +vim.command("throw 'abcN'"):(<class 'vim.error'>, error('abcN',)) +Exe("throw 'def'"):(<class 'vim.error'>, error('def',)) +vim.eval("Exe('throw ''ghi''')"):(<class 'vim.error'>, error('ghi',)) +vim.eval("Exe('echoerr ''jkl''')"):(<class 'vim.error'>, error('Vim(echoerr):jkl',)) +vim.eval("Exe('xxx_non_existent_command_xxx')"):(<class 'vim.error'>, error('Vim:E492: Not an editor command: xxx_non_existent_command_xxx',)) +vim.eval("xxx_unknown_function_xxx()"):(<class 'vim.error'>, error('Vim:E117: Unknown function: xxx_unknown_function_xxx',)) +vim.bindeval("Exe('xxx_non_existent_command_xxx')"):(<class 'vim.error'>, error('Vim:E492: Not an editor command: xxx_non_existent_command_xxx',)) +Caught KeyboardInterrupt +Running :put +No exception + diff --git a/src/testdir/test88.in b/src/testdir/test88.in new file mode 100644 index 0000000..9e43f70 --- /dev/null +++ b/src/testdir/test88.in @@ -0,0 +1,99 @@ +vim: set ft=vim + +Tests for correct display (cursor column position) with +conceal and +tabulators. + +STARTTEST +:so small.vim +:if !has('conceal') + e! test.ok + wq! test.out +:endif +:" Conceal settings. +:set conceallevel=2 +:set concealcursor=nc +:syntax match test /|/ conceal +:" Save current cursor position. Only works in <expr> mode, can't be used +:" with :normal because it moves the cursor to the command line. Thanks to ZyX +:" <zyx.vim@gmail.com> for the idea to use an <expr> mapping. +:let positions = [] +:nnoremap <expr> GG ":let positions += ['".screenrow().":".screencol()."']\n" +:" Start test. +/^start: +:normal ztj +GGk +:" We should end up in the same column when running these commands on the two +:" lines. +:normal ft +GGk +:normal $ +GGk +:normal 0j +GGk +:normal ft +GGk +:normal $ +GGk +:normal 0j0j +GGk +:" Same for next test block. +:normal ft +GGk +:normal $ +GGk +:normal 0j +GGk +:normal ft +GGk +:normal $ +GGk +:normal 0j0j +GGk +:" And check W with multiple tabs and conceals in a line. +:normal W +GGk +:normal W +GGk +:normal W +GGk +:normal $ +GGk +:normal 0j +GGk +:normal W +GGk +:normal W +GGk +:normal W +GGk +:normal $ +GGk +:set lbr +:normal $ +GGk +:set list listchars=tab:>- +:normal 0 +GGk +:normal W +GGk +:normal W +GGk +:normal W +GGk +:normal $ +GGk +:" Display result. +:call append('$', 'end:') +:call append('$', positions) +:/^end/,$wq! test.out +ENDTEST + +start: +.concealed. text +|concealed| text + + .concealed. text + |concealed| text + +.a. .b. .c. .d. +|a| |b| |c| |d| diff --git a/src/testdir/test88.ok b/src/testdir/test88.ok new file mode 100644 index 0000000..12949f2 --- /dev/null +++ b/src/testdir/test88.ok @@ -0,0 +1,29 @@ +end: +2:1 +2:17 +2:20 +3:1 +3:17 +3:20 +5:8 +5:25 +5:28 +6:8 +6:25 +6:28 +8:1 +8:9 +8:17 +8:25 +8:27 +9:1 +9:9 +9:17 +9:25 +9:26 +9:26 +9:1 +9:9 +9:17 +9:25 +9:26 diff --git a/src/testdir/test94.in b/src/testdir/test94.in new file mode 100644 index 0000000..447fd2b --- /dev/null +++ b/src/testdir/test94.in @@ -0,0 +1,257 @@ +Test for Visual mode and operators + +Tests for the two kinds of operations: Those executed with Visual mode +followed by an operator and those executed via Operator-pending mode. Also +part of the test are mappings, counts, and repetition with the . command. + +Test cases: +- Visual modes (v V CTRL-V) followed by an operator; count; repeating +- Visual mode maps; count; repeating + - Simple + - With an Ex command (custom text object) +- Operator-pending mode maps + - Simple + - With Ex command moving the cursor + - With Ex command and Visual selection (custom text object) +- Patch 7.3.879: Properly abort Ex command in Operator-pending mode + +STARTTEST +:so small.vim +:set belloff=all +:set enc=utf-8 nocp viminfo+=nviminfo +: +:" User functions +:function MoveToCap() +: call search('\u', 'W') +:endfunction +:function SelectInCaps() +: let [line1, col1] = searchpos('\u', 'bcnW') +: let [line2, col2] = searchpos('.\u', 'nW') +: call setpos("'<", [0, line1, col1, 0]) +: call setpos("'>", [0, line2, col2, 0]) +: normal! gv +:endfunction +: +:" Visual modes followed by operator +/^apple +lvld.l3vd.: +/^line 1 +Vcnewlinej.j2Vd.: +/^xxxx +jlc l.l2c----l.: +: +:" Visual mode maps (movement and text object) +:vnoremap W /\u/s-1<CR> +:vnoremap iW :<C-U>call SelectInCaps()<CR> +/^Kiwi +vWcNol.fD2vd.: +/^Jambu +llviWc-l.l2vdl.: +: +:" Operator-pending mode maps (movement and text object) +:onoremap W /\u/<CR> +:onoremap <Leader>W :<C-U>call MoveToCap()<CR> +:onoremap iW :<C-U>call SelectInCaps()<CR> +/^Pineapple +cW-l.l2.l.: +/^Juniper +g?\WfD.: +/^Lemon +yiWPlciWNewfr.: +: +:" Patch 7.3.879: Properly abort Operator-pending mode for "dv:<Esc>" etc. +/^zzzz +dV:
dv:
:set noma | let v:errmsg = '' +d:
:set ma | put = v:errmsg =~# '^E21' ? 'ok' : 'failed' +dv:dV::set noma | let v:errmsg = '' +d::set ma | put = v:errmsg =~# '^E21' ? 'failed' : 'ok' +: +:$put ='' +:$put ='characterwise visual mode: replace last line' +:$put ='a' +:let @" = 'x' +:let v:errmsg = '' +v$p +:$put ='---' +:$put ='v:errmsg='.v:errmsg +: +:$put ='' +:$put ='characterwise visual mode: delete middle line' +:$put ='a' +:$put ='b' +:$put ='c' +kkv$d +:$put ='---' +: +:$put ='' +:$put ='characterwise visual mode: delete middle two line' +:$put ='a' +:$put ='b' +:$put ='c' +kkvj$d +:$put ='---' +: +:$put ='' +:$put ='characterwise visual mode: delete last line' +:$put ='a' +:$put ='b' +:$put ='c' +v$d +:$put ='---' +: +:$put ='' +:$put ='characterwise visual mode: delete last two line' +:$put ='a' +:$put ='b' +:$put ='c' +kvj$d +:$put ='---' +: +:" Select mode maps +:snoremap <lt>End> <End> +:snoremap <lt>Down> <Down> +:snoremap <lt>Del> <Del> +: +:$put ='' +:$put ='characterwise select mode: delete middle line' +:$put ='a' +:$put ='b' +:$put ='c' +kkgh<End><Del> +:$put ='---' +: +:$put ='' +:$put ='characterwise select mode: delete middle two line' +:$put ='a' +:$put ='b' +:$put ='c' +kkgh<Down><End><Del> +:$put ='---' +: +:$put ='' +:$put ='characterwise select mode: delete last line' +:$put ='a' +:$put ='b' +:$put ='c' +gh<End><Del> +:$put ='---' +: +:$put ='' +:$put ='characterwise select mode: delete last two line' +:$put ='a' +:$put ='b' +:$put ='c' +kgh<Down><End><Del> +:$put ='---' +: +:$put ='' +:$put ='linewise select mode: delete middle line' +:$put ='a' +:$put ='b' +:$put ='c' +kkgH<Del> +:$put ='---' +: +:$put ='' +:$put ='linewise select mode: delete middle two line' +:$put ='a' +:$put ='b' +:$put ='c' +kkgH<Down><Del> +:$put ='---' +: +:$put ='' +:$put ='linewise select mode: delete last line' +:$put ='a' +:$put ='b' +:$put ='c' +gH<Del> +:$put ='---' +: +:$put ='' +:$put ='linewise select mode: delete last two line' +:$put ='a' +:$put ='b' +:$put ='c' +kgH<Down><Del> +:$put ='---' +: +:$put ='' +:$put ='v_p: replace last character with line register at middle line' +:$put ='aaa' +:$put ='bbb' +:$put ='ccc' +:-2yank +k$vp +:$put ='---' +: +:$put ='' +:$put ='v_p: replace last character with line register at middle line selecting newline' +:$put ='aaa' +:$put ='bbb' +:$put ='ccc' +:-2yank +k$v$p +:$put ='---' +: +:$put ='' +:$put ='v_p: replace last character with line register at last line' +:$put ='aaa' +:$put ='bbb' +:$put ='ccc' +:-2yank +$vp +:$put ='---' +: +:$put ='' +:$put ='v_p: replace last character with line register at last line selecting newline' +:$put ='aaa' +:$put ='bbb' +:$put ='ccc' +:-2yank +$v$p +:$put ='---' +: +:$put ='' +:$put ='gv in exclusive select mode after operation' +:$put ='zzz ' +:$put ='äà ' +:set selection=exclusive +kv3lyjv3lpgvcxxx +:$put ='---' +: +:$put ='' +:$put ='gv in exclusive select mode without operation' +:$put ='zzz ' +:set selection=exclusive +0v3lgvcxxx +:$put ='---' +:/^start:/+2,$w! test.out +:q! +ENDTEST + +start: + +apple banana cherry + +line 1 line 1 +line 2 line 2 +line 3 line 3 +line 4 line 4 +line 5 line 5 +line 6 line 6 + +xxxxxxxxxxxxx +xxxxxxxxxxxxx +xxxxxxxxxxxxx +xxxxxxxxxxxxx + +KiwiRaspberryDateWatermelonPeach +JambuRambutanBananaTangerineMango + +PineappleQuinceLoganberryOrangeGrapefruitKiwiZ +JuniperDurianZ +LemonNectarineZ + +zzzz +zzzz diff --git a/src/testdir/test94.ok b/src/testdir/test94.ok new file mode 100644 index 0000000..c023922 --- /dev/null +++ b/src/testdir/test94.ok @@ -0,0 +1,123 @@ +a y + +newline +newline + + --------x + --------x +xxxx--------x +xxxx--------x + +NoNoberryach +--ago + +----Z +WhavcreQhevnaZ +LemonNewNewZ + +zzz +ok +ok + +characterwise visual mode: replace last line +x +--- +v:errmsg= + +characterwise visual mode: delete middle line +b +c +--- + +characterwise visual mode: delete middle two line +c +--- + +characterwise visual mode: delete last line +a +b + +--- + +characterwise visual mode: delete last two line +a + +--- + +characterwise select mode: delete middle line +b +c +--- + +characterwise select mode: delete middle two line +c +--- + +characterwise select mode: delete last line +a +b + +--- + +characterwise select mode: delete last two line +a + +--- + +linewise select mode: delete middle line +b +c +--- + +linewise select mode: delete middle two line +c +--- + +linewise select mode: delete last line +a +b +--- + +linewise select mode: delete last two line +a +--- + +v_p: replace last character with line register at middle line +aaa +bb +aaa + +ccc +--- + +v_p: replace last character with line register at middle line selecting newline +aaa +bb +aaa +ccc +--- + +v_p: replace last character with line register at last line +aaa +bbb +cc +aaa + +--- + +v_p: replace last character with line register at last line selecting newline +aaa +bbb +cc +aaa + +--- + +gv in exclusive select mode after operation +zzz +xxx +--- + +gv in exclusive select mode without operation +xxx +--- diff --git a/src/testdir/test95.in b/src/testdir/test95.in new file mode 100644 index 0000000..934afde --- /dev/null +++ b/src/testdir/test95.in @@ -0,0 +1,141 @@ +Test for regexp patterns with multi-byte support, using utf-8. +See test64 for the non-multi-byte tests. + +A pattern that gives the expected result produces OK, so that we know it was +actually tried. + +STARTTEST +:so small.vim +:so mbyte.vim +:set nocp encoding=utf-8 viminfo+=nviminfo nomore +:" tl is a List of Lists with: +:" 2: test auto/old/new 0: test auto/old 1: test auto/new +:" regexp pattern +:" text to test the pattern on +:" expected match (optional) +:" expected submatch 1 (optional) +:" expected submatch 2 (optional) +:" etc. +:" When there is no match use only the first two items. +:let tl = [] +: +:"""" Multi-byte character tests. These will fail unless vim is compiled +:"""" with Multibyte (FEAT_MBYTE) or BIG/HUGE features. +:call add(tl, [2, '[[:alpha:][=a=]]\+', '879 aiaãâaiuvna ', 'aiaãâaiuvna']) +:call add(tl, [2, '[[=a=]]\+', 'ddaãâbcd', 'aãâ']) " equivalence classes +:call add(tl, [2, '[^ม ]\+', 'มม oijasoifjos ifjoisj f osij j มมมมม abcd', 'oijasoifjos']) +:call add(tl, [2, ' [^ ]\+', 'start มabcdม ', ' มabcdม']) +:call add(tl, [2, '[ม[:alpha:][=a=]]\+', '879 aiaãมâมaiuvna ', 'aiaãมâมaiuvna']) +: +:" this is not a normal "i" but 0xec +:call add(tl, [2, '\p\+', 'ìa', 'ìa']) +:call add(tl, [2, '\p*', 'aあ', 'aあ']) +: +:"""" Test recognition of some character classes +:call add(tl, [2, '\i\+', '&*¨xx ', 'xx']) +:call add(tl, [2, '\f\+', '&*fname ', 'fname']) +: +:"""" Test composing character matching +:call add(tl, [2, '.ม', 'xม่x yมy', 'yม']) +:call add(tl, [2, '.ม่', 'xม่x yมy', 'xม่']) +:call add(tl, [2, "\u05b9", " x\u05b9 ", "x\u05b9"]) +:call add(tl, [2, ".\u05b9", " x\u05b9 ", "x\u05b9"]) +:call add(tl, [2, "\u05b9\u05bb", " x\u05b9\u05bb ", "x\u05b9\u05bb"]) +:call add(tl, [2, ".\u05b9\u05bb", " x\u05b9\u05bb ", "x\u05b9\u05bb"]) +:call add(tl, [2, "\u05bb\u05b9", " x\u05b9\u05bb ", "x\u05b9\u05bb"]) +:call add(tl, [2, ".\u05bb\u05b9", " x\u05b9\u05bb ", "x\u05b9\u05bb"]) +:call add(tl, [2, "\u05b9", " y\u05bb x\u05b9 ", "x\u05b9"]) +:call add(tl, [2, ".\u05b9", " y\u05bb x\u05b9 ", "x\u05b9"]) +:call add(tl, [2, "\u05b9", " y\u05bb\u05b9 x\u05b9 ", "y\u05bb\u05b9"]) +:call add(tl, [2, ".\u05b9", " y\u05bb\u05b9 x\u05b9 ", "y\u05bb\u05b9"]) +:call add(tl, [1, "\u05b9\u05bb", " y\u05b9 x\u05b9\u05bb ", "x\u05b9\u05bb"]) +:call add(tl, [2, ".\u05b9\u05bb", " y\u05bb x\u05b9\u05bb ", "x\u05b9\u05bb"]) +:call add(tl, [2, "a", "ca\u0300t"]) +:call add(tl, [2, "ca", "ca\u0300t"]) +:call add(tl, [2, "a\u0300", "ca\u0300t", "a\u0300"]) +:call add(tl, [2, 'a\%C', "ca\u0300t", "a\u0300"]) +:call add(tl, [2, 'ca\%C', "ca\u0300t", "ca\u0300"]) +:call add(tl, [2, 'ca\%Ct', "ca\u0300t", "ca\u0300t"]) +: +: +:"""" Test \Z +:call add(tl, [2, 'ú\Z', 'x']) +:call add(tl, [2, 'יהוה\Z', 'יהוה', 'יהוה']) +:call add(tl, [2, 'יְהוָה\Z', 'יהוה', 'יהוה']) +:call add(tl, [2, 'יהוה\Z', 'יְהוָה', 'יְהוָה']) +:call add(tl, [2, 'יְהוָה\Z', 'יְהוָה', 'יְהוָה']) +:call add(tl, [2, 'יְ\Z', 'וְיַ', 'יַ']) +:call add(tl, [2, "ק\u200d\u05b9x\\Z", "xק\u200d\u05b9xy", "ק\u200d\u05b9x"]) +:call add(tl, [2, "ק\u200d\u05b9x\\Z", "xק\u200dxy", "ק\u200dx"]) +:call add(tl, [2, "ק\u200dx\\Z", "xק\u200d\u05b9xy", "ק\u200d\u05b9x"]) +:call add(tl, [2, "ק\u200dx\\Z", "xק\u200dxy", "ק\u200dx"]) +:call add(tl, [2, "\u05b9\\Z", "xyz"]) +:call add(tl, [2, "\\Z\u05b9", "xyz"]) +:call add(tl, [2, "\u05b9\\Z", "xy\u05b9z", "y\u05b9"]) +:call add(tl, [2, "\\Z\u05b9", "xy\u05b9z", "y\u05b9"]) +:call add(tl, [1, "\u05b9\\+\\Z", "xy\u05b9z\u05b9 ", "y\u05b9z\u05b9"]) +:call add(tl, [1, "\\Z\u05b9\\+", "xy\u05b9z\u05b9 ", "y\u05b9z\u05b9"]) +: +:"""" Combining different tests and features +:call add(tl, [2, '[^[=a=]]\+', 'ddaãâbcd', 'dd']) +: +:"""" Run the tests +: +:" +:for t in tl +: let re = t[0] +: let pat = t[1] +: let text = t[2] +: let matchidx = 3 +: for engine in [0, 1, 2] +: if engine == 2 && re == 0 || engine == 1 && re == 1 +: continue +: endif +: let ®expengine = engine +: try +: let l = matchlist(text, pat) +: catch +: $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", caused an exception: \"' . v:exception . '\"' +: endtry +:" check the match itself +: if len(l) == 0 && len(t) > matchidx +: $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", did not match, expected: \"' . t[matchidx] . '\"' +: elseif len(l) > 0 && len(t) == matchidx +: $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", match: \"' . l[0] . '\", expected no match' +: elseif len(t) > matchidx && l[0] != t[matchidx] +: $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", match: \"' . l[0] . '\", expected: \"' . t[matchidx] . '\"' +: else +: $put ='OK ' . engine . ' - ' . pat +: endif +: if len(l) > 0 +:" check all the nine submatches +: for i in range(1, 9) +: if len(t) <= matchidx + i +: let e = '' +: else +: let e = t[matchidx + i] +: endif +: if l[i] != e +: $put ='ERROR ' . engine . ': pat: \"' . pat . '\", text: \"' . text . '\", submatch ' . i . ': \"' . l[i] . '\", expected: \"' . e . '\"' +: endif +: endfor +: unlet i +: endif +: endfor +:endfor +:unlet t tl e l +: +:" check that 'ambiwidth' does not change the meaning of \p +:set regexpengine=1 ambiwidth=single +:$put ='eng 1 ambi single: ' . match(\"\u00EC\", '\p') +:set regexpengine=1 ambiwidth=double +:$put ='eng 1 ambi double: ' . match(\"\u00EC\", '\p') +:set regexpengine=2 ambiwidth=single +:$put ='eng 2 ambi single: ' . match(\"\u00EC\", '\p') +:set regexpengine=2 ambiwidth=double +:$put ='eng 2 ambi double: ' . match(\"\u00EC\", '\p') +: +:/\%#=1^Results/,$wq! test.out +ENDTEST + +Results of test95: diff --git a/src/testdir/test95.ok b/src/testdir/test95.ok new file mode 100644 index 0000000..6762994 --- /dev/null +++ b/src/testdir/test95.ok @@ -0,0 +1,140 @@ +Results of test95: +OK 0 - [[:alpha:][=a=]]\+ +OK 1 - [[:alpha:][=a=]]\+ +OK 2 - [[:alpha:][=a=]]\+ +OK 0 - [[=a=]]\+ +OK 1 - [[=a=]]\+ +OK 2 - [[=a=]]\+ +OK 0 - [^ม ]\+ +OK 1 - [^ม ]\+ +OK 2 - [^ม ]\+ +OK 0 - [^ ]\+ +OK 1 - [^ ]\+ +OK 2 - [^ ]\+ +OK 0 - [ม[:alpha:][=a=]]\+ +OK 1 - [ม[:alpha:][=a=]]\+ +OK 2 - [ม[:alpha:][=a=]]\+ +OK 0 - \p\+ +OK 1 - \p\+ +OK 2 - \p\+ +OK 0 - \p* +OK 1 - \p* +OK 2 - \p* +OK 0 - \i\+ +OK 1 - \i\+ +OK 2 - \i\+ +OK 0 - \f\+ +OK 1 - \f\+ +OK 2 - \f\+ +OK 0 - .ม +OK 1 - .ม +OK 2 - .ม +OK 0 - .ม่ +OK 1 - .ม่ +OK 2 - .ม่ +OK 0 - ֹ +OK 1 - ֹ +OK 2 - ֹ +OK 0 - .ֹ +OK 1 - .ֹ +OK 2 - .ֹ +OK 0 - ֹֻ +OK 1 - ֹֻ +OK 2 - ֹֻ +OK 0 - .ֹֻ +OK 1 - .ֹֻ +OK 2 - .ֹֻ +OK 0 - ֹֻ +OK 1 - ֹֻ +OK 2 - ֹֻ +OK 0 - .ֹֻ +OK 1 - .ֹֻ +OK 2 - .ֹֻ +OK 0 - ֹ +OK 1 - ֹ +OK 2 - ֹ +OK 0 - .ֹ +OK 1 - .ֹ +OK 2 - .ֹ +OK 0 - ֹ +OK 1 - ֹ +OK 2 - ֹ +OK 0 - .ֹ +OK 1 - .ֹ +OK 2 - .ֹ +OK 0 - ֹֻ +OK 2 - ֹֻ +OK 0 - .ֹֻ +OK 1 - .ֹֻ +OK 2 - .ֹֻ +OK 0 - a +OK 1 - a +OK 2 - a +OK 0 - ca +OK 1 - ca +OK 2 - ca +OK 0 - à +OK 1 - à +OK 2 - à +OK 0 - a\%C +OK 1 - a\%C +OK 2 - a\%C +OK 0 - ca\%C +OK 1 - ca\%C +OK 2 - ca\%C +OK 0 - ca\%Ct +OK 1 - ca\%Ct +OK 2 - ca\%Ct +OK 0 - ú\Z +OK 1 - ú\Z +OK 2 - ú\Z +OK 0 - יהוה\Z +OK 1 - יהוה\Z +OK 2 - יהוה\Z +OK 0 - יְהוָה\Z +OK 1 - יְהוָה\Z +OK 2 - יְהוָה\Z +OK 0 - יהוה\Z +OK 1 - יהוה\Z +OK 2 - יהוה\Z +OK 0 - יְהוָה\Z +OK 1 - יְהוָה\Z +OK 2 - יְהוָה\Z +OK 0 - יְ\Z +OK 1 - יְ\Z +OK 2 - יְ\Z +OK 0 - קֹx\Z +OK 1 - קֹx\Z +OK 2 - קֹx\Z +OK 0 - קֹx\Z +OK 1 - קֹx\Z +OK 2 - קֹx\Z +OK 0 - קx\Z +OK 1 - קx\Z +OK 2 - קx\Z +OK 0 - קx\Z +OK 1 - קx\Z +OK 2 - קx\Z +OK 0 - ֹ\Z +OK 1 - ֹ\Z +OK 2 - ֹ\Z +OK 0 - \Zֹ +OK 1 - \Zֹ +OK 2 - \Zֹ +OK 0 - ֹ\Z +OK 1 - ֹ\Z +OK 2 - ֹ\Z +OK 0 - \Zֹ +OK 1 - \Zֹ +OK 2 - \Zֹ +OK 0 - ֹ\+\Z +OK 2 - ֹ\+\Z +OK 0 - \Zֹ\+ +OK 2 - \Zֹ\+ +OK 0 - [^[=a=]]\+ +OK 1 - [^[=a=]]\+ +OK 2 - [^[=a=]]\+ +eng 1 ambi single: 0 +eng 1 ambi double: 0 +eng 2 ambi single: 0 +eng 2 ambi double: 0 diff --git a/src/testdir/test99.in b/src/testdir/test99.in new file mode 100644 index 0000000..3961244 --- /dev/null +++ b/src/testdir/test99.in @@ -0,0 +1,69 @@ +Tests for regexp with multi-byte encoding and various magic settings. +Test matchstr() with a count and multi-byte chars. +See test44 for exactly the same test with re=1. + +STARTTEST +:so mbyte.vim +:set nocompatible encoding=utf-8 termencoding=latin1 viminfo+=nviminfo +:set re=2 +/^1 +/a*b\{2}c\+/e +x/\Md\*e\{2}f\+/e +x:set nomagic +/g\*h\{2}i\+/e +x/\mj*k\{2}l\+/e +x/\vm*n{2}o+/e +x/\V^aa$ +x:set magic +/\v(a)(b)\2\1\1/e +x/\V[ab]\(\[xy]\)\1 +x:" Now search for multi-byte without composing char +/ม +x:" Now search for multi-byte with composing char +/ม่ +x:" find word by change of word class +/ち\<カヨ\>は +x:" Test \%u, [\u] and friends +/\%u20ac +x/[\u4f7f\u5929]\+ +x/\%U12345678 +x/[\U1234abcd\u1234\uabcd] +x/\%d21879b +x:" Test backwards search from a multi-byte char +/x +x?. +x:let @w=':%s#comb[i]nations#œ̄ṣ́m̥̄ᾱ̆́#g' +:@w +:" +:" l Test what 7.3.192 fixed +/^l +:s/ \?/ /g +:?^1?,$w! test.out +:e! test.out +G:put =matchstr(\"אבגד\", \".\", 0, 2) " ב +:put =matchstr(\"אבגד\", \"..\", 0, 2) " בג +:put =matchstr(\"אבגד\", \".\", 0, 0) " א +:put =matchstr(\"אבגד\", \".\", 4, -1) " ג +:w! +:qa! +ENDTEST + +1 a aa abb abbccc +2 d dd dee deefff +3 g gg ghh ghhiii +4 j jj jkk jkklll +5 m mm mnn mnnooo +6 x ^aa$ x +7 (a)(b) abbaa +8 axx [ab]xx +9 หม่x อมx +a อมx หม่x +b ちカヨは +c x ¬€x +d 天使x +e y +f z +g a啷bb +j 0123❤x +k combinations +l äö üᾱ̆́ diff --git a/src/testdir/test99.ok b/src/testdir/test99.ok new file mode 100644 index 0000000..dea3665 --- /dev/null +++ b/src/testdir/test99.ok @@ -0,0 +1,23 @@ +1 a aa abb abbcc +2 d dd dee deeff +3 g gg ghh ghhii +4 j jj jkk jkkll +5 m mm mnn mnnoo +6 x aa$ x +7 (a)(b) abba +8 axx ab]xx +9 หม่x อx +a อมx หx +b カヨは +c x ¬x +d 使x +e y +f z +g abb +j 012❤ +k œ̄ṣ́m̥̄ᾱ̆́ + l ä ö ü ᾱ̆́ +ב +בג +א +ג diff --git a/src/testdir/test_alot.vim b/src/testdir/test_alot.vim new file mode 100644 index 0000000..81873af --- /dev/null +++ b/src/testdir/test_alot.vim @@ -0,0 +1,68 @@ +" A series of tests that can run in one Vim invocation. +" This makes testing go faster, since Vim doesn't need to restart. + +source test_assign.vim +source test_backup.vim +source test_behave.vim +source test_bufline.vim +source test_cd.vim +source test_changedtick.vim +source test_compiler.vim +source test_cursor_func.vim +source test_delete.vim +source test_ex_equal.vim +source test_ex_undo.vim +source test_ex_z.vim +source test_execute_func.vim +source test_expand.vim +source test_expand_dllpath.vim +source test_expand_func.vim +source test_expr.vim +source test_feedkeys.vim +source test_file_perm.vim +source test_fileformat.vim +source test_filetype.vim +source test_filter_cmd.vim +source test_filter_map.vim +source test_findfile.vim +source test_float_func.vim +source test_fnamemodify.vim +source test_functions.vim +source test_ga.vim +source test_glob2regpat.vim +source test_global.vim +source test_goto.vim +source test_help_tagjump.vim +source test_join.vim +source test_jumps.vim +source test_lambda.vim +source test_lispwords.vim +source test_mapping.vim +source test_match.vim +source test_menu.vim +source test_messages.vim +source test_modeline.vim +source test_move.vim +source test_partial.vim +source test_popup.vim +source test_put.vim +source test_recover.vim +source test_reltime.vim +source test_scroll_opt.vim +source test_searchpos.vim +source test_set.vim +source test_sort.vim +source test_sha256.vim +source test_statusline.vim +source test_suspend.vim +source test_syn_attr.vim +source test_tabline.vim +source test_tabpage.vim +source test_tagcase.vim +source test_tagjump.vim +source test_taglist.vim +source test_timers.vim +source test_true_false.vim +source test_unlet.vim +source test_virtualedit.vim +source test_window_cmd.vim diff --git a/src/testdir/test_alot_latin.vim b/src/testdir/test_alot_latin.vim new file mode 100644 index 0000000..23a404c --- /dev/null +++ b/src/testdir/test_alot_latin.vim @@ -0,0 +1,7 @@ +" A series of tests that can run in one Vim invocation. +" This makes testing go faster, since Vim doesn't need to restart. + +" These tests use latin1 'encoding'. Setting 'encoding' is in the individual +" files, so that they can be run by themselves. + +source test_regexp_latin.vim diff --git a/src/testdir/test_alot_utf8.vim b/src/testdir/test_alot_utf8.vim new file mode 100644 index 0000000..be0bd01 --- /dev/null +++ b/src/testdir/test_alot_utf8.vim @@ -0,0 +1,16 @@ +" A series of tests that can run in one Vim invocation. +" This makes testing go faster, since Vim doesn't need to restart. + +" These tests use utf8 'encoding'. Setting 'encoding' is already done in +" runtest.vim. + +source test_charsearch_utf8.vim +source test_expr_utf8.vim +source test_listlbr_utf8.vim +source test_matchadd_conceal_utf8.vim +source test_mksession_utf8.vim +source test_regexp_utf8.vim +source test_source_utf8.vim +source test_startup_utf8.vim +source test_utf8.vim +source test_utf8_comparisons.vim diff --git a/src/testdir/test_arabic.vim b/src/testdir/test_arabic.vim new file mode 100644 index 0000000..bc31db7 --- /dev/null +++ b/src/testdir/test_arabic.vim @@ -0,0 +1,613 @@ +" Simplistic testing of Arabic mode. +" NOTE: This just checks if the code works. If you know Arabic please add +" functional tests that check the shaping works with real text. + +if !has('arabic') + finish +endif + +source view_util.vim + +" Return list of Unicode characters at line lnum. +" Combining characters are treated as a single item. +func s:get_chars(lnum) + call cursor(a:lnum, 1) + let chars = [] + let numchars = strchars(getline('.'), 1) + for i in range(1, numchars) + exe 'norm ' i . '|' + let c = execute('ascii') + let c = substitute(c, '\n\?<.\{-}Hex\s*', 'U+', 'g') + let c = substitute(c, ',\s*Oct\(al\)\=\s\d*\(, Digr ..\)\=', '', 'g') + call add(chars, c) + endfor + return chars +endfunc + +func Test_arabic_toggle() + set arabic + call assert_equal(1, &rightleft) + call assert_equal(1, &arabicshape) + call assert_equal('arabic', &keymap) + call assert_equal(1, &delcombine) + + set iminsert=1 imsearch=1 + set arabic& + call assert_equal(0, &rightleft) + call assert_equal(1, &arabicshape) + call assert_equal('arabic', &keymap) + call assert_equal(1, &delcombine) + call assert_equal(0, &iminsert) + call assert_equal(-1, &imsearch) + + set arabicshape& keymap= delcombine& +endfunc + +func Test_arabic_input() + new + set arabic + " Typing sghl in Arabic insert mode should show the + " Arabic word 'Salaam' i.e. 'peace', spelled: + " SEEN, LAM, ALEF, MEEM. + " See: https://www.mediawiki.org/wiki/VisualEditor/Typing/Right-to-left + call feedkeys('isghl!', 'tx') + call assert_match("^ *!\uFEE1\uFEFC\uFEB3$", ScreenLines(1, &columns)[0]) + call assert_equal([ + \ 'U+0633', + \ 'U+0644 U+0627', + \ 'U+0645', + \ 'U+21'], s:get_chars(1)) + + " Without shaping, it should give individual Arabic letters. + set noarabicshape + call assert_match("^ *!\u0645\u0627\u0644\u0633$", ScreenLines(1, &columns)[0]) + call assert_equal([ + \ 'U+0633', + \ 'U+0644', + \ 'U+0627', + \ 'U+0645', + \ 'U+21'], s:get_chars(1)) + + set arabic& arabicshape& + bwipe! +endfunc + +func Test_arabic_toggle_keymap() + new + set arabic + call feedkeys("i12\<C-^>12\<C-^>12", 'tx') + call assert_match("^ *٢١21٢١$", ScreenLines(1, &columns)[0]) + call assert_equal('١٢12١٢', getline('.')) + set arabic& + bwipe! +endfunc + +func Test_delcombine() + new + set arabic + call feedkeys("isghl\<BS>\<BS>", 'tx') + call assert_match("^ *\uFEDE\uFEB3$", ScreenLines(1, &columns)[0]) + call assert_equal(['U+0633', 'U+0644'], s:get_chars(1)) + + " Now the same with 'nodelcombine' + set nodelcombine + %d + call feedkeys("isghl\<BS>\<BS>", 'tx') + call assert_match("^ *\uFEB1$", ScreenLines(1, &columns)[0]) + call assert_equal(['U+0633'], s:get_chars(1)) + set arabic& + bwipe! +endfunc + +" Values from src/arabic.h (not all used yet) +let s:a_COMMA = "\u060C" +let s:a_SEMICOLON = "\u061B" +let s:a_QUESTION = "\u061F" +let s:a_HAMZA = "\u0621" +let s:a_ALEF_MADDA = "\u0622" +let s:a_ALEF_HAMZA_ABOVE = "\u0623" +let s:a_WAW_HAMZA = "\u0624" +let s:a_ALEF_HAMZA_BELOW = "\u0625" +let s:a_YEH_HAMZA = "\u0626" +let s:a_ALEF = "\u0627" +let s:a_BEH = "\u0628" +let s:a_TEH_MARBUTA = "\u0629" +let s:a_TEH = "\u062a" +let s:a_THEH = "\u062b" +let s:a_JEEM = "\u062c" +let s:a_HAH = "\u062d" +let s:a_KHAH = "\u062e" +let s:a_DAL = "\u062f" +let s:a_THAL = "\u0630" +let s:a_REH = "\u0631" +let s:a_ZAIN = "\u0632" +let s:a_SEEN = "\u0633" +let s:a_SHEEN = "\u0634" +let s:a_SAD = "\u0635" +let s:a_DAD = "\u0636" +let s:a_TAH = "\u0637" +let s:a_ZAH = "\u0638" +let s:a_AIN = "\u0639" +let s:a_GHAIN = "\u063a" +let s:a_TATWEEL = "\u0640" +let s:a_FEH = "\u0641" +let s:a_QAF = "\u0642" +let s:a_KAF = "\u0643" +let s:a_LAM = "\u0644" +let s:a_MEEM = "\u0645" +let s:a_NOON = "\u0646" +let s:a_HEH = "\u0647" +let s:a_WAW = "\u0648" +let s:a_ALEF_MAKSURA = "\u0649" +let s:a_YEH = "\u064a" + +let s:a_FATHATAN = "\u064b" +let s:a_DAMMATAN = "\u064c" +let s:a_KASRATAN = "\u064d" +let s:a_FATHA = "\u064e" +let s:a_DAMMA = "\u064f" +let s:a_KASRA = "\u0650" +let s:a_SHADDA = "\u0651" +let s:a_SUKUN = "\u0652" + +let s:a_MADDA_ABOVE = "\u0653" +let s:a_HAMZA_ABOVE = "\u0654" +let s:a_HAMZA_BELOW = "\u0655" + +let s:a_ZERO = "\u0660" +let s:a_ONE = "\u0661" +let s:a_TWO = "\u0662" +let s:a_THREE = "\u0663" +let s:a_FOUR = "\u0664" +let s:a_FIVE = "\u0665" +let s:a_SIX = "\u0666" +let s:a_SEVEN = "\u0667" +let s:a_EIGHT = "\u0668" +let s:a_NINE = "\u0669" +let s:a_PERCENT = "\u066a" +let s:a_DECIMAL = "\u066b" +let s:a_THOUSANDS = "\u066c" +let s:a_STAR = "\u066d" +let s:a_MINI_ALEF = "\u0670" + +let s:a_s_FATHATAN = "\ufe70" +let s:a_m_TATWEEL_FATHATAN = "\ufe71" +let s:a_s_DAMMATAN = "\ufe72" + +let s:a_s_KASRATAN = "\ufe74" + +let s:a_s_FATHA = "\ufe76" +let s:a_m_FATHA = "\ufe77" +let s:a_s_DAMMA = "\ufe78" +let s:a_m_DAMMA = "\ufe79" +let s:a_s_KASRA = "\ufe7a" +let s:a_m_KASRA = "\ufe7b" +let s:a_s_SHADDA = "\ufe7c" +let s:a_m_SHADDA = "\ufe7d" +let s:a_s_SUKUN = "\ufe7e" +let s:a_m_SUKUN = "\ufe7f" + +let s:a_s_HAMZA = "\ufe80" +let s:a_s_ALEF_MADDA = "\ufe81" +let s:a_f_ALEF_MADDA = "\ufe82" +let s:a_s_ALEF_HAMZA_ABOVE = "\ufe83" +let s:a_f_ALEF_HAMZA_ABOVE = "\ufe84" +let s:a_s_WAW_HAMZA = "\ufe85" +let s:a_f_WAW_HAMZA = "\ufe86" +let s:a_s_ALEF_HAMZA_BELOW = "\ufe87" +let s:a_f_ALEF_HAMZA_BELOW = "\ufe88" +let s:a_s_YEH_HAMZA = "\ufe89" +let s:a_f_YEH_HAMZA = "\ufe8a" +let s:a_i_YEH_HAMZA = "\ufe8b" +let s:a_m_YEH_HAMZA = "\ufe8c" +let s:a_s_ALEF = "\ufe8d" +let s:a_f_ALEF = "\ufe8e" +let s:a_s_BEH = "\ufe8f" +let s:a_f_BEH = "\ufe90" +let s:a_i_BEH = "\ufe91" +let s:a_m_BEH = "\ufe92" +let s:a_s_TEH_MARBUTA = "\ufe93" +let s:a_f_TEH_MARBUTA = "\ufe94" +let s:a_s_TEH = "\ufe95" +let s:a_f_TEH = "\ufe96" +let s:a_i_TEH = "\ufe97" +let s:a_m_TEH = "\ufe98" +let s:a_s_THEH = "\ufe99" +let s:a_f_THEH = "\ufe9a" +let s:a_i_THEH = "\ufe9b" +let s:a_m_THEH = "\ufe9c" +let s:a_s_JEEM = "\ufe9d" +let s:a_f_JEEM = "\ufe9e" +let s:a_i_JEEM = "\ufe9f" +let s:a_m_JEEM = "\ufea0" +let s:a_s_HAH = "\ufea1" +let s:a_f_HAH = "\ufea2" +let s:a_i_HAH = "\ufea3" +let s:a_m_HAH = "\ufea4" +let s:a_s_KHAH = "\ufea5" +let s:a_f_KHAH = "\ufea6" +let s:a_i_KHAH = "\ufea7" +let s:a_m_KHAH = "\ufea8" +let s:a_s_DAL = "\ufea9" +let s:a_f_DAL = "\ufeaa" +let s:a_s_THAL = "\ufeab" +let s:a_f_THAL = "\ufeac" +let s:a_s_REH = "\ufead" +let s:a_f_REH = "\ufeae" +let s:a_s_ZAIN = "\ufeaf" +let s:a_f_ZAIN = "\ufeb0" +let s:a_s_SEEN = "\ufeb1" +let s:a_f_SEEN = "\ufeb2" +let s:a_i_SEEN = "\ufeb3" +let s:a_m_SEEN = "\ufeb4" +let s:a_s_SHEEN = "\ufeb5" +let s:a_f_SHEEN = "\ufeb6" +let s:a_i_SHEEN = "\ufeb7" +let s:a_m_SHEEN = "\ufeb8" +let s:a_s_SAD = "\ufeb9" +let s:a_f_SAD = "\ufeba" +let s:a_i_SAD = "\ufebb" +let s:a_m_SAD = "\ufebc" +let s:a_s_DAD = "\ufebd" +let s:a_f_DAD = "\ufebe" +let s:a_i_DAD = "\ufebf" +let s:a_m_DAD = "\ufec0" +let s:a_s_TAH = "\ufec1" +let s:a_f_TAH = "\ufec2" +let s:a_i_TAH = "\ufec3" +let s:a_m_TAH = "\ufec4" +let s:a_s_ZAH = "\ufec5" +let s:a_f_ZAH = "\ufec6" +let s:a_i_ZAH = "\ufec7" +let s:a_m_ZAH = "\ufec8" +let s:a_s_AIN = "\ufec9" +let s:a_f_AIN = "\ufeca" +let s:a_i_AIN = "\ufecb" +let s:a_m_AIN = "\ufecc" +let s:a_s_GHAIN = "\ufecd" +let s:a_f_GHAIN = "\ufece" +let s:a_i_GHAIN = "\ufecf" +let s:a_m_GHAIN = "\ufed0" +let s:a_s_FEH = "\ufed1" +let s:a_f_FEH = "\ufed2" +let s:a_i_FEH = "\ufed3" +let s:a_m_FEH = "\ufed4" +let s:a_s_QAF = "\ufed5" +let s:a_f_QAF = "\ufed6" +let s:a_i_QAF = "\ufed7" +let s:a_m_QAF = "\ufed8" +let s:a_s_KAF = "\ufed9" +let s:a_f_KAF = "\ufeda" +let s:a_i_KAF = "\ufedb" +let s:a_m_KAF = "\ufedc" +let s:a_s_LAM = "\ufedd" +let s:a_f_LAM = "\ufede" +let s:a_i_LAM = "\ufedf" +let s:a_m_LAM = "\ufee0" +let s:a_s_MEEM = "\ufee1" +let s:a_f_MEEM = "\ufee2" +let s:a_i_MEEM = "\ufee3" +let s:a_m_MEEM = "\ufee4" +let s:a_s_NOON = "\ufee5" +let s:a_f_NOON = "\ufee6" +let s:a_i_NOON = "\ufee7" +let s:a_m_NOON = "\ufee8" +let s:a_s_HEH = "\ufee9" +let s:a_f_HEH = "\ufeea" +let s:a_i_HEH = "\ufeeb" +let s:a_m_HEH = "\ufeec" +let s:a_s_WAW = "\ufeed" +let s:a_f_WAW = "\ufeee" +let s:a_s_ALEF_MAKSURA = "\ufeef" +let s:a_f_ALEF_MAKSURA = "\ufef0" +let s:a_s_YEH = "\ufef1" +let s:a_f_YEH = "\ufef2" +let s:a_i_YEH = "\ufef3" +let s:a_m_YEH = "\ufef4" +let s:a_s_LAM_ALEF_MADDA_ABOVE = "\ufef5" +let s:a_f_LAM_ALEF_MADDA_ABOVE = "\ufef6" +let s:a_s_LAM_ALEF_HAMZA_ABOVE = "\ufef7" +let s:a_f_LAM_ALEF_HAMZA_ABOVE = "\ufef8" +let s:a_s_LAM_ALEF_HAMZA_BELOW = "\ufef9" +let s:a_f_LAM_ALEF_HAMZA_BELOW = "\ufefa" +let s:a_s_LAM_ALEF = "\ufefb" +let s:a_f_LAM_ALEF = "\ufefc" + +let s:a_BYTE_ORDER_MARK = "\ufeff" + +func Test_shape_initial() + new + set arabicshape + + " Shaping arabic {testchar} non-arabic Tests chg_c_a2i(). + " pair[0] = testchar, pair[1] = next-result, pair[2] = current-result + for pair in [[s:a_YEH_HAMZA, s:a_f_GHAIN, s:a_i_YEH_HAMZA], + \ [s:a_HAMZA, s:a_s_GHAIN, s:a_s_HAMZA], + \ [s:a_ALEF_MADDA, s:a_s_GHAIN, s:a_s_ALEF_MADDA], + \ [s:a_ALEF_HAMZA_ABOVE, s:a_s_GHAIN, s:a_s_ALEF_HAMZA_ABOVE], + \ [s:a_WAW_HAMZA, s:a_s_GHAIN, s:a_s_WAW_HAMZA], + \ [s:a_ALEF_HAMZA_BELOW, s:a_s_GHAIN, s:a_s_ALEF_HAMZA_BELOW], + \ [s:a_ALEF, s:a_s_GHAIN, s:a_s_ALEF], + \ [s:a_TEH_MARBUTA, s:a_s_GHAIN, s:a_s_TEH_MARBUTA], + \ [s:a_DAL, s:a_s_GHAIN, s:a_s_DAL], + \ [s:a_THAL, s:a_s_GHAIN, s:a_s_THAL], + \ [s:a_REH, s:a_s_GHAIN, s:a_s_REH], + \ [s:a_ZAIN, s:a_s_GHAIN, s:a_s_ZAIN], + \ [s:a_TATWEEL, s:a_f_GHAIN, s:a_TATWEEL], + \ [s:a_WAW, s:a_s_GHAIN, s:a_s_WAW], + \ [s:a_ALEF_MAKSURA, s:a_s_GHAIN, s:a_s_ALEF_MAKSURA], + \ [s:a_BEH, s:a_f_GHAIN, s:a_i_BEH], + \ [s:a_TEH, s:a_f_GHAIN, s:a_i_TEH], + \ [s:a_THEH, s:a_f_GHAIN, s:a_i_THEH], + \ [s:a_JEEM, s:a_f_GHAIN, s:a_i_JEEM], + \ [s:a_HAH, s:a_f_GHAIN, s:a_i_HAH], + \ [s:a_KHAH, s:a_f_GHAIN, s:a_i_KHAH], + \ [s:a_SEEN, s:a_f_GHAIN, s:a_i_SEEN], + \ [s:a_SHEEN, s:a_f_GHAIN, s:a_i_SHEEN], + \ [s:a_SAD, s:a_f_GHAIN, s:a_i_SAD], + \ [s:a_DAD, s:a_f_GHAIN, s:a_i_DAD], + \ [s:a_TAH, s:a_f_GHAIN, s:a_i_TAH], + \ [s:a_ZAH, s:a_f_GHAIN, s:a_i_ZAH], + \ [s:a_AIN, s:a_f_GHAIN, s:a_i_AIN], + \ [s:a_GHAIN, s:a_f_GHAIN, s:a_i_GHAIN], + \ [s:a_FEH, s:a_f_GHAIN, s:a_i_FEH], + \ [s:a_QAF, s:a_f_GHAIN, s:a_i_QAF], + \ [s:a_KAF, s:a_f_GHAIN, s:a_i_KAF], + \ [s:a_LAM, s:a_f_GHAIN, s:a_i_LAM], + \ [s:a_MEEM, s:a_f_GHAIN, s:a_i_MEEM], + \ [s:a_NOON, s:a_f_GHAIN, s:a_i_NOON], + \ [s:a_HEH, s:a_f_GHAIN, s:a_i_HEH], + \ [s:a_YEH, s:a_f_GHAIN, s:a_i_YEH], + \ ] + call setline(1, s:a_GHAIN . pair[0] . ' ') + call assert_equal([pair[1] . pair[2] . ' '], ScreenLines(1, 3)) + endfor + + set arabicshape& + bwipe! +endfunc + +func Test_shape_isolated() + new + set arabicshape + + " Shaping non-arabic {testchar} non-arabic Tests chg_c_a2s(). + " pair[0] = testchar, pair[1] = current-result + for pair in [[s:a_HAMZA, s:a_s_HAMZA], + \ [s:a_ALEF_MADDA, s:a_s_ALEF_MADDA], + \ [s:a_ALEF_HAMZA_ABOVE, s:a_s_ALEF_HAMZA_ABOVE], + \ [s:a_WAW_HAMZA, s:a_s_WAW_HAMZA], + \ [s:a_ALEF_HAMZA_BELOW, s:a_s_ALEF_HAMZA_BELOW], + \ [s:a_YEH_HAMZA, s:a_s_YEH_HAMZA], + \ [s:a_ALEF, s:a_s_ALEF], + \ [s:a_TEH_MARBUTA, s:a_s_TEH_MARBUTA], + \ [s:a_DAL, s:a_s_DAL], + \ [s:a_THAL, s:a_s_THAL], + \ [s:a_REH, s:a_s_REH], + \ [s:a_ZAIN, s:a_s_ZAIN], + \ [s:a_TATWEEL, s:a_TATWEEL], + \ [s:a_WAW, s:a_s_WAW], + \ [s:a_ALEF_MAKSURA, s:a_s_ALEF_MAKSURA], + \ [s:a_BEH, s:a_s_BEH], + \ [s:a_TEH, s:a_s_TEH], + \ [s:a_THEH, s:a_s_THEH], + \ [s:a_JEEM, s:a_s_JEEM], + \ [s:a_HAH, s:a_s_HAH], + \ [s:a_KHAH, s:a_s_KHAH], + \ [s:a_SEEN, s:a_s_SEEN], + \ [s:a_SHEEN, s:a_s_SHEEN], + \ [s:a_SAD, s:a_s_SAD], + \ [s:a_DAD, s:a_s_DAD], + \ [s:a_TAH, s:a_s_TAH], + \ [s:a_ZAH, s:a_s_ZAH], + \ [s:a_AIN, s:a_s_AIN], + \ [s:a_GHAIN, s:a_s_GHAIN], + \ [s:a_FEH, s:a_s_FEH], + \ [s:a_QAF, s:a_s_QAF], + \ [s:a_KAF, s:a_s_KAF], + \ [s:a_LAM, s:a_s_LAM], + \ [s:a_MEEM, s:a_s_MEEM], + \ [s:a_NOON, s:a_s_NOON], + \ [s:a_HEH, s:a_s_HEH], + \ [s:a_YEH, s:a_s_YEH], + \ ] + call setline(1, ' ' . pair[0] . ' ') + call assert_equal([' ' . pair[1] . ' '], ScreenLines(1, 3)) + endfor + + set arabicshape& + bwipe! +endfunc + +func Test_shape_iso_to_medial() + new + set arabicshape + + " Shaping arabic {testchar} arabic Tests chg_c_a2m(). + " pair[0] = testchar, pair[1] = next-result, pair[2] = current-result, + " pair[3] = previous-result + for pair in [[s:a_HAMZA, s:a_s_GHAIN, s:a_s_HAMZA, s:a_s_BEH], + \[s:a_ALEF_MADDA, s:a_s_GHAIN, s:a_f_ALEF_MADDA, s:a_i_BEH], + \[s:a_ALEF_HAMZA_ABOVE, s:a_s_GHAIN, s:a_f_ALEF_HAMZA_ABOVE, s:a_i_BEH], + \[s:a_WAW_HAMZA, s:a_s_GHAIN, s:a_f_WAW_HAMZA, s:a_i_BEH], + \[s:a_ALEF_HAMZA_BELOW, s:a_s_GHAIN, s:a_f_ALEF_HAMZA_BELOW, s:a_i_BEH], + \[s:a_YEH_HAMZA, s:a_f_GHAIN, s:a_m_YEH_HAMZA, s:a_i_BEH], + \[s:a_ALEF, s:a_s_GHAIN, s:a_f_ALEF, s:a_i_BEH], + \[s:a_BEH, s:a_f_GHAIN, s:a_m_BEH, s:a_i_BEH], + \[s:a_TEH_MARBUTA, s:a_s_GHAIN, s:a_f_TEH_MARBUTA, s:a_i_BEH], + \[s:a_TEH, s:a_f_GHAIN, s:a_m_TEH, s:a_i_BEH], + \[s:a_THEH, s:a_f_GHAIN, s:a_m_THEH, s:a_i_BEH], + \[s:a_JEEM, s:a_f_GHAIN, s:a_m_JEEM, s:a_i_BEH], + \[s:a_HAH, s:a_f_GHAIN, s:a_m_HAH, s:a_i_BEH], + \[s:a_KHAH, s:a_f_GHAIN, s:a_m_KHAH, s:a_i_BEH], + \[s:a_DAL, s:a_s_GHAIN, s:a_f_DAL, s:a_i_BEH], + \[s:a_THAL, s:a_s_GHAIN, s:a_f_THAL, s:a_i_BEH], + \[s:a_REH, s:a_s_GHAIN, s:a_f_REH, s:a_i_BEH], + \[s:a_ZAIN, s:a_s_GHAIN, s:a_f_ZAIN, s:a_i_BEH], + \[s:a_SEEN, s:a_f_GHAIN, s:a_m_SEEN, s:a_i_BEH], + \[s:a_SHEEN, s:a_f_GHAIN, s:a_m_SHEEN, s:a_i_BEH], + \[s:a_SAD, s:a_f_GHAIN, s:a_m_SAD, s:a_i_BEH], + \[s:a_DAD, s:a_f_GHAIN, s:a_m_DAD, s:a_i_BEH], + \[s:a_TAH, s:a_f_GHAIN, s:a_m_TAH, s:a_i_BEH], + \[s:a_ZAH, s:a_f_GHAIN, s:a_m_ZAH, s:a_i_BEH], + \[s:a_AIN, s:a_f_GHAIN, s:a_m_AIN, s:a_i_BEH], + \[s:a_GHAIN, s:a_f_GHAIN, s:a_m_GHAIN, s:a_i_BEH], + \[s:a_TATWEEL, s:a_f_GHAIN, s:a_TATWEEL, s:a_i_BEH], + \[s:a_FEH, s:a_f_GHAIN, s:a_m_FEH, s:a_i_BEH], + \[s:a_QAF, s:a_f_GHAIN, s:a_m_QAF, s:a_i_BEH], + \[s:a_KAF, s:a_f_GHAIN, s:a_m_KAF, s:a_i_BEH], + \[s:a_LAM, s:a_f_GHAIN, s:a_m_LAM, s:a_i_BEH], + \[s:a_MEEM, s:a_f_GHAIN, s:a_m_MEEM, s:a_i_BEH], + \[s:a_NOON, s:a_f_GHAIN, s:a_m_NOON, s:a_i_BEH], + \[s:a_HEH, s:a_f_GHAIN, s:a_m_HEH, s:a_i_BEH], + \[s:a_WAW, s:a_s_GHAIN, s:a_f_WAW, s:a_i_BEH], + \[s:a_ALEF_MAKSURA, s:a_s_GHAIN, s:a_f_ALEF_MAKSURA, s:a_i_BEH], + \[s:a_YEH, s:a_f_GHAIN, s:a_m_YEH, s:a_i_BEH], + \ ] + call setline(1, s:a_GHAIN . pair[0] . s:a_BEH) + call assert_equal([pair[1] . pair[2] . pair[3]], ScreenLines(1, 3)) + endfor + + set arabicshape& + bwipe! +endfunc + +func Test_shape_final() + new + set arabicshape + + " Shaping arabic {testchar} arabic Tests chg_c_a2f(). + " pair[0] = testchar, pair[1] = current-result, pair[2] = previous-result + for pair in [[s:a_HAMZA, s:a_s_HAMZA, s:a_s_BEH], + \[s:a_ALEF_MADDA, s:a_f_ALEF_MADDA, s:a_i_BEH], + \[s:a_ALEF_HAMZA_ABOVE, s:a_f_ALEF_HAMZA_ABOVE, s:a_i_BEH], + \[s:a_WAW_HAMZA, s:a_f_WAW_HAMZA, s:a_i_BEH], + \[s:a_ALEF_HAMZA_BELOW, s:a_f_ALEF_HAMZA_BELOW, s:a_i_BEH], + \[s:a_YEH_HAMZA, s:a_f_YEH_HAMZA, s:a_i_BEH], + \[s:a_ALEF, s:a_f_ALEF, s:a_i_BEH], + \[s:a_BEH, s:a_f_BEH, s:a_i_BEH], + \[s:a_TEH_MARBUTA, s:a_f_TEH_MARBUTA, s:a_i_BEH], + \[s:a_TEH, s:a_f_TEH, s:a_i_BEH], + \[s:a_THEH, s:a_f_THEH, s:a_i_BEH], + \[s:a_JEEM, s:a_f_JEEM, s:a_i_BEH], + \[s:a_HAH, s:a_f_HAH, s:a_i_BEH], + \[s:a_KHAH, s:a_f_KHAH, s:a_i_BEH], + \[s:a_DAL, s:a_f_DAL, s:a_i_BEH], + \[s:a_THAL, s:a_f_THAL, s:a_i_BEH], + \[s:a_REH, s:a_f_REH, s:a_i_BEH], + \[s:a_ZAIN, s:a_f_ZAIN, s:a_i_BEH], + \[s:a_SEEN, s:a_f_SEEN, s:a_i_BEH], + \[s:a_SHEEN, s:a_f_SHEEN, s:a_i_BEH], + \[s:a_SAD, s:a_f_SAD, s:a_i_BEH], + \[s:a_DAD, s:a_f_DAD, s:a_i_BEH], + \[s:a_TAH, s:a_f_TAH, s:a_i_BEH], + \[s:a_ZAH, s:a_f_ZAH, s:a_i_BEH], + \[s:a_AIN, s:a_f_AIN, s:a_i_BEH], + \[s:a_GHAIN, s:a_f_GHAIN, s:a_i_BEH], + \[s:a_TATWEEL, s:a_TATWEEL, s:a_i_BEH], + \[s:a_FEH, s:a_f_FEH, s:a_i_BEH], + \[s:a_QAF, s:a_f_QAF, s:a_i_BEH], + \[s:a_KAF, s:a_f_KAF, s:a_i_BEH], + \[s:a_LAM, s:a_f_LAM, s:a_i_BEH], + \[s:a_MEEM, s:a_f_MEEM, s:a_i_BEH], + \[s:a_NOON, s:a_f_NOON, s:a_i_BEH], + \[s:a_HEH, s:a_f_HEH, s:a_i_BEH], + \[s:a_WAW, s:a_f_WAW, s:a_i_BEH], + \[s:a_ALEF_MAKSURA, s:a_f_ALEF_MAKSURA, s:a_i_BEH], + \[s:a_YEH, s:a_f_YEH, s:a_i_BEH], + \ ] + call setline(1, ' ' . pair[0] . s:a_BEH) + call assert_equal([' ' . pair[1] . pair[2]], ScreenLines(1, 3)) + endfor + + set arabicshape& + bwipe! +endfunc + +func Test_shape_final_to_medial() + new + set arabicshape + + " Shaping arabic {testchar} arabic Tests chg_c_f2m(). + " This does not test much... + " pair[0] = testchar, pair[1] = current-result + for pair in [[s:a_f_YEH_HAMZA, s:a_f_BEH], + \[s:a_f_WAW_HAMZA, s:a_s_BEH], + \[s:a_f_ALEF, s:a_s_BEH], + \[s:a_f_TEH_MARBUTA, s:a_s_BEH], + \[s:a_f_DAL, s:a_s_BEH], + \[s:a_f_THAL, s:a_s_BEH], + \[s:a_f_REH, s:a_s_BEH], + \[s:a_f_ZAIN, s:a_s_BEH], + \[s:a_f_WAW, s:a_s_BEH], + \[s:a_f_ALEF_MAKSURA, s:a_s_BEH], + \[s:a_f_BEH, s:a_f_BEH], + \[s:a_f_TEH, s:a_f_BEH], + \[s:a_f_THEH, s:a_f_BEH], + \[s:a_f_JEEM, s:a_f_BEH], + \[s:a_f_HAH, s:a_f_BEH], + \[s:a_f_KHAH, s:a_f_BEH], + \[s:a_f_SEEN, s:a_f_BEH], + \[s:a_f_SHEEN, s:a_f_BEH], + \[s:a_f_SAD, s:a_f_BEH], + \[s:a_f_DAD, s:a_f_BEH], + \[s:a_f_TAH, s:a_f_BEH], + \[s:a_f_ZAH, s:a_f_BEH], + \[s:a_f_AIN, s:a_f_BEH], + \[s:a_f_GHAIN, s:a_f_BEH], + \[s:a_f_FEH, s:a_f_BEH], + \[s:a_f_QAF, s:a_f_BEH], + \[s:a_f_KAF, s:a_f_BEH], + \[s:a_f_LAM, s:a_f_BEH], + \[s:a_f_MEEM, s:a_f_BEH], + \[s:a_f_NOON, s:a_f_BEH], + \[s:a_f_HEH, s:a_f_BEH], + \[s:a_f_YEH, s:a_f_BEH], + \ ] + call setline(1, ' ' . s:a_BEH . pair[0]) + call assert_equal([' ' . pair[1] . pair[0]], ScreenLines(1, 3)) + endfor + + set arabicshape& + bwipe! +endfunc + +func Test_shape_combination_final() + new + set arabicshape + + " Shaping arabic {testchar} arabic Tests chg_c_laa2f(). + " pair[0] = testchar, pair[1] = current-result + for pair in [[s:a_ALEF_MADDA, s:a_f_LAM_ALEF_MADDA_ABOVE], + \ [s:a_ALEF_HAMZA_ABOVE, s:a_f_LAM_ALEF_HAMZA_ABOVE], + \ [s:a_ALEF_HAMZA_BELOW, s:a_f_LAM_ALEF_HAMZA_BELOW], + \ [s:a_ALEF, s:a_f_LAM_ALEF], + \ ] + " The test char is a composing char, put on s:a_LAM. + call setline(1, ' ' . s:a_LAM . pair[0] . s:a_BEH) + call assert_equal([' ' . pair[1] . s:a_i_BEH], ScreenLines(1, 3)) + endfor + + set arabicshape& + bwipe! +endfunc + +func Test_shape_combination_isolated() + new + set arabicshape + + " Shaping arabic {testchar} arabic Tests chg_c_laa2i(). + " pair[0] = testchar, pair[1] = current-result + for pair in [[s:a_ALEF_MADDA, s:a_s_LAM_ALEF_MADDA_ABOVE], + \ [s:a_ALEF_HAMZA_ABOVE, s:a_s_LAM_ALEF_HAMZA_ABOVE], + \ [s:a_ALEF_HAMZA_BELOW, s:a_s_LAM_ALEF_HAMZA_BELOW], + \ [s:a_ALEF, s:a_s_LAM_ALEF], + \ ] + " The test char is a composing char, put on s:a_LAM. + call setline(1, ' ' . s:a_LAM . pair[0] . ' ') + call assert_equal([' ' . pair[1] . ' '], ScreenLines(1, 3)) + endfor + + set arabicshape& + bwipe! +endfunc diff --git a/src/testdir/test_arglist.vim b/src/testdir/test_arglist.vim new file mode 100644 index 0000000..ad44a85 --- /dev/null +++ b/src/testdir/test_arglist.vim @@ -0,0 +1,482 @@ +" Test argument list commands + +func Test_argidx() + args a b c + last + call assert_equal(2, argidx()) + %argdelete + call assert_equal(0, argidx()) + " doing it again doesn't result in an error + %argdelete + call assert_equal(0, argidx()) + call assert_fails('2argdelete', 'E16:') + + args a b c + call assert_equal(0, argidx()) + next + call assert_equal(1, argidx()) + next + call assert_equal(2, argidx()) + 1argdelete + call assert_equal(1, argidx()) + 1argdelete + call assert_equal(0, argidx()) + 1argdelete + call assert_equal(0, argidx()) +endfunc + +func Test_argadd() + %argdelete + argadd a b c + call assert_equal(0, argidx()) + + %argdelete + argadd a + call assert_equal(0, argidx()) + argadd b c d + call assert_equal(0, argidx()) + + call Init_abc() + argadd x + call Assert_argc(['a', 'b', 'x', 'c']) + call assert_equal(1, argidx()) + + call Init_abc() + 0argadd x + call Assert_argc(['x', 'a', 'b', 'c']) + call assert_equal(2, argidx()) + + call Init_abc() + 1argadd x + call Assert_argc(['a', 'x', 'b', 'c']) + call assert_equal(2, argidx()) + + call Init_abc() + $argadd x + call Assert_argc(['a', 'b', 'c', 'x']) + call assert_equal(1, argidx()) + + call Init_abc() + $argadd x + +2argadd y + call Assert_argc(['a', 'b', 'c', 'x', 'y']) + call assert_equal(1, argidx()) + + %argd + edit d + arga + call assert_equal(1, len(argv())) + call assert_equal('d', get(argv(), 0, '')) + + %argd + edit some\ file + arga + call assert_equal(1, len(argv())) + call assert_equal('some file', get(argv(), 0, '')) + + %argd + new + arga + call assert_equal(0, len(argv())) +endfunc + +func Test_argadd_empty_curbuf() + new + let curbuf = bufnr('%') + call writefile(['test', 'Xargadd'], 'Xargadd') + " must not re-use the current buffer. + argadd Xargadd + call assert_equal(curbuf, bufnr('%')) + call assert_equal('', bufname('%')) + call assert_equal(1, line('$')) + rew + call assert_notequal(curbuf, bufnr('%')) + call assert_equal('Xargadd', bufname('%')) + call assert_equal(2, line('$')) + + call delete('Xargadd') + %argd + bwipe! +endfunc + +func Init_abc() + args a b c + next +endfunc + +func Assert_argc(l) + call assert_equal(len(a:l), argc()) + let i = 0 + while i < len(a:l) && i < argc() + call assert_equal(a:l[i], argv(i)) + let i += 1 + endwhile +endfunc + +" Test for [count]argument and [count]argdelete commands +" Ported from the test_argument_count.in test script +func Test_argument() + " Clean the argument list + arga a | %argd + + let save_hidden = &hidden + set hidden + + let g:buffers = [] + augroup TEST + au BufEnter * call add(buffers, expand('%:t')) + augroup END + + argadd a b c d + $argu + $-argu + -argu + 1argu + +2argu + + augroup TEST + au! + augroup END + + call assert_equal(['d', 'c', 'b', 'a', 'c'], g:buffers) + + redir => result + args + redir END + call assert_equal('a b [c] d', trim(result)) + + .argd + call assert_equal(['a', 'b', 'd'], argv()) + + -argd + call assert_equal(['a', 'd'], argv()) + + $argd + call assert_equal(['a'], argv()) + + 1arga c + 1arga b + $argu + $arga x + call assert_equal(['a', 'b', 'c', 'x'], argv()) + + 0arga y + call assert_equal(['y', 'a', 'b', 'c', 'x'], argv()) + + %argd + call assert_equal([], argv()) + + arga a b c d e f + 2,$-argd + call assert_equal(['a', 'f'], argv()) + + let &hidden = save_hidden + + " Setting argument list should fail when the current buffer has unsaved + " changes + %argd + enew! + set modified + call assert_fails('args x y z', 'E37:') + args! x y z + call assert_equal(['x', 'y', 'z'], argv()) + call assert_equal('x', expand('%:t')) + + last | enew | argu + call assert_equal('z', expand('%:t')) + + %argdelete + call assert_fails('argument', 'E163:') +endfunc + +func Test_list_arguments() + " Clean the argument list + arga a | %argd + + " four args half the screen width makes two lines with two columns + let aarg = repeat('a', &columns / 2 - 4) + let barg = repeat('b', &columns / 2 - 4) + let carg = repeat('c', &columns / 2 - 4) + let darg = repeat('d', &columns / 2 - 4) + exe 'argadd ' aarg barg carg darg + + redir => result + args + redir END + call assert_match('\[' . aarg . '] \+' . carg . '\n' . barg . ' \+' . darg, trim(result)) + + " if one arg is longer than half the screen make one column + exe 'argdel' aarg + let aarg = repeat('a', &columns / 2 + 2) + exe '0argadd' aarg + redir => result + args + redir END + call assert_match(aarg . '\n\[' . barg . ']\n' . carg . '\n' . darg, trim(result)) + + %argdelete +endfunc + +func Test_args_with_quote() + " Only on Unix can a file name include a double quote. + if has('unix') + args \"foobar + call assert_equal('"foobar', argv(0)) + %argdelete + endif +endfunc + +" Test for 0argadd and 0argedit +" Ported from the test_argument_0count.in test script +func Test_zero_argadd() + " Clean the argument list + arga a | %argd + + arga a b c d + 2argu + 0arga added + call assert_equal(['added', 'a', 'b', 'c', 'd'], argv()) + + 2argu + arga third + call assert_equal(['added', 'a', 'third', 'b', 'c', 'd'], argv()) + + %argd + arga a b c d + 2argu + 0arge edited + call assert_equal(['edited', 'a', 'b', 'c', 'd'], argv()) + + 2argu + arga third + call assert_equal(['edited', 'a', 'third', 'b', 'c', 'd'], argv()) + + 2argu + argedit file\ with\ spaces another file + call assert_equal(['edited', 'a', 'file with spaces', 'another', 'file', 'third', 'b', 'c', 'd'], argv()) + call assert_equal('file with spaces', expand('%')) +endfunc + +func Reset_arglist() + args a | %argd +endfunc + +" Test for argc() +func Test_argc() + call Reset_arglist() + call assert_equal(0, argc()) + argadd a b + call assert_equal(2, argc()) +endfunc + +" Test for arglistid() +func Test_arglistid() + call Reset_arglist() + arga a b + call assert_equal(0, arglistid()) + split + arglocal + call assert_equal(1, arglistid()) + tabnew | tabfirst + call assert_equal(0, arglistid(2)) + call assert_equal(1, arglistid(1, 1)) + call assert_equal(0, arglistid(2, 1)) + call assert_equal(1, arglistid(1, 2)) + tabonly | only | enew! + argglobal + call assert_equal(0, arglistid()) +endfunc + +" Tests for argv() and argc() +func Test_argv() + call Reset_arglist() + call assert_equal([], argv()) + call assert_equal("", argv(2)) + call assert_equal(0, argc()) + argadd a b c d + call assert_equal(4, argc()) + call assert_equal('c', argv(2)) + + let w1_id = win_getid() + split + let w2_id = win_getid() + arglocal + args e f g + tabnew + let w3_id = win_getid() + split + let w4_id = win_getid() + argglobal + tabfirst + call assert_equal(4, argc(w1_id)) + call assert_equal('b', argv(1, w1_id)) + call assert_equal(['a', 'b', 'c', 'd'], argv(-1, w1_id)) + + call assert_equal(3, argc(w2_id)) + call assert_equal('f', argv(1, w2_id)) + call assert_equal(['e', 'f', 'g'], argv(-1, w2_id)) + + call assert_equal(3, argc(w3_id)) + call assert_equal('e', argv(0, w3_id)) + call assert_equal(['e', 'f', 'g'], argv(-1, w3_id)) + + call assert_equal(4, argc(w4_id)) + call assert_equal('c', argv(2, w4_id)) + call assert_equal(['a', 'b', 'c', 'd'], argv(-1, w4_id)) + + call assert_equal(4, argc(-1)) + call assert_equal(3, argc()) + call assert_equal('d', argv(3, -1)) + call assert_equal(['a', 'b', 'c', 'd'], argv(-1, -1)) + tabonly | only | enew! + " Negative test cases + call assert_equal(-1, argc(100)) + call assert_equal('', argv(1, 100)) + call assert_equal([], argv(-1, 100)) + call assert_equal('', argv(10, -1)) +endfunc + +" Test for the :argedit command +func Test_argedit() + call Reset_arglist() + argedit a + call assert_equal(['a'], argv()) + call assert_equal('a', expand('%:t')) + argedit b + call assert_equal(['a', 'b'], argv()) + call assert_equal('b', expand('%:t')) + argedit a + call assert_equal(['a', 'b', 'a'], argv()) + call assert_equal('a', expand('%:t')) + " When file name case is ignored, an existing buffer with only case + " difference is re-used. + argedit C D + call assert_equal('C', expand('%:t')) + call assert_equal(['a', 'b', 'a', 'C', 'D'], argv()) + argedit c + if has('fname_case') + call assert_equal(['a', 'b', 'a', 'C', 'c', 'D'], argv()) + else + call assert_equal(['a', 'b', 'a', 'C', 'C', 'D'], argv()) + endif + 0argedit x + if has('fname_case') + call assert_equal(['x', 'a', 'b', 'a', 'C', 'c', 'D'], argv()) + else + call assert_equal(['x', 'a', 'b', 'a', 'C', 'C', 'D'], argv()) + endif + enew! | set modified + call assert_fails('argedit y', 'E37:') + argedit! y + if has('fname_case') + call assert_equal(['x', 'y', 'y', 'a', 'b', 'a', 'C', 'c', 'D'], argv()) + else + call assert_equal(['x', 'y', 'y', 'a', 'b', 'a', 'C', 'C', 'D'], argv()) + endif + %argd + bwipe! C + bwipe! D + + " :argedit reuses the current buffer if it is empty + %argd + " make sure to use a new buffer number for x when it is loaded + bw! x + new + let a = bufnr('') + argedit x + call assert_equal(a, bufnr('')) + call assert_equal('x', bufname('')) + %argd + bw! x +endfunc + +" Test for the :argdelete command +func Test_argdelete() + call Reset_arglist() + args aa a aaa b bb + argdelete a* + call assert_equal(['b', 'bb'], argv()) + call assert_equal('aa', expand('%:t')) + last + argdelete % + call assert_equal(['b'], argv()) + call assert_fails('argdelete', 'E471:') + call assert_fails('1,100argdelete', 'E16:') + %argd +endfunc + +func Test_argdelete_completion() + args foo bar + + call feedkeys(":argdelete \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"argdelete bar foo', @:) + + call feedkeys(":argdelete x \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"argdelete x bar foo', @:) + + %argd +endfunc + +" Tests for the :next, :prev, :first, :last, :rewind commands +func Test_argpos() + call Reset_arglist() + args a b c d + last + call assert_equal(3, argidx()) + call assert_fails('next', 'E165:') + prev + call assert_equal(2, argidx()) + Next + call assert_equal(1, argidx()) + first + call assert_equal(0, argidx()) + call assert_fails('prev', 'E164:') + 3next + call assert_equal(3, argidx()) + rewind + call assert_equal(0, argidx()) + %argd +endfunc + +" Test for autocommand that redefines the argument list, when doing ":all". +func Test_arglist_autocmd() + autocmd BufReadPost Xxx2 next Xxx2 Xxx1 + call writefile(['test file Xxx1'], 'Xxx1') + call writefile(['test file Xxx2'], 'Xxx2') + call writefile(['test file Xxx3'], 'Xxx3') + + new + " redefine arglist; go to Xxx1 + next! Xxx1 Xxx2 Xxx3 + " open window for all args + all + call assert_equal('test file Xxx1', getline(1)) + wincmd w + wincmd w + call assert_equal('test file Xxx1', getline(1)) + " should now be in Xxx2 + rewind + call assert_equal('test file Xxx2', getline(1)) + + autocmd! BufReadPost Xxx2 + enew! | only + call delete('Xxx1') + call delete('Xxx2') + call delete('Xxx3') + argdelete Xxx* + bwipe! Xxx1 Xxx2 Xxx3 +endfunc + +func Test_arg_all_expand() + call writefile(['test file Xxx1'], 'Xx x') + next notexist Xx\ x runtest.vim + call assert_equal('notexist Xx\ x runtest.vim', expand('##')) + call delete('Xx x') +endfunc + +func Test_large_arg() + " Argument longer or equal to the number of columns used to cause + " access to invalid memory. + exe 'argadd ' .repeat('x', &columns) + args +endfunc diff --git a/src/testdir/test_assert.vim b/src/testdir/test_assert.vim new file mode 100644 index 0000000..298a6db --- /dev/null +++ b/src/testdir/test_assert.vim @@ -0,0 +1,218 @@ +" Test that the methods used for testing work. + +func Test_assert_false() + call assert_equal(0, assert_false(0)) + call assert_equal(0, assert_false(v:false)) + + call assert_equal(1, assert_false(123)) + call assert_match("Expected False but got 123", v:errors[0]) + call remove(v:errors, 0) +endfunc + +func Test_assert_true() + call assert_equal(0, assert_true(1)) + call assert_equal(0, assert_true(123)) + call assert_equal(0, assert_true(v:true)) + + call assert_equal(1, assert_true(0)) + call assert_match("Expected True but got 0", v:errors[0]) + call remove(v:errors, 0) +endfunc + +func Test_assert_equal() + let s = 'foo' + call assert_equal(0, assert_equal('foo', s)) + let n = 4 + call assert_equal(0, assert_equal(4, n)) + let l = [1, 2, 3] + call assert_equal(0, assert_equal([1, 2, 3], l)) + + let s = 'foo' + call assert_equal(1, assert_equal('bar', s)) + call assert_match("Expected 'bar' but got 'foo'", v:errors[0]) + call remove(v:errors, 0) + + call assert_equal('XxxxxxxxxxxxxxxxxxxxxxX', 'XyyyyyyyyyyyyyyyyyyyyyyyyyX') + call assert_match("Expected 'X\\\\\\[x occurs 21 times]X' but got 'X\\\\\\[y occurs 25 times]X'", v:errors[0]) + call remove(v:errors, 0) +endfunc + +func Test_assert_equalfile() + call assert_equal(1, assert_equalfile('abcabc', 'xyzxyz')) + call assert_match("E485: Can't read file abcabc", v:errors[0]) + call remove(v:errors, 0) + + let goodtext = ["one", "two", "three"] + call writefile(goodtext, 'Xone') + call assert_equal(1, assert_equalfile('Xone', 'xyzxyz')) + call assert_match("E485: Can't read file xyzxyz", v:errors[0]) + call remove(v:errors, 0) + + call writefile(goodtext, 'Xtwo') + call assert_equal(0, assert_equalfile('Xone', 'Xtwo')) + + call writefile([goodtext[0]], 'Xone') + call assert_equal(1, assert_equalfile('Xone', 'Xtwo')) + call assert_match("first file is shorter", v:errors[0]) + call remove(v:errors, 0) + + call writefile(goodtext, 'Xone') + call writefile([goodtext[0]], 'Xtwo') + call assert_equal(1, assert_equalfile('Xone', 'Xtwo')) + call assert_match("second file is shorter", v:errors[0]) + call remove(v:errors, 0) + + call writefile(['1234X89'], 'Xone') + call writefile(['1234Y89'], 'Xtwo') + call assert_equal(1, assert_equalfile('Xone', 'Xtwo')) + call assert_match("difference at byte 4", v:errors[0]) + call remove(v:errors, 0) + + call delete('Xone') + call delete('Xtwo') +endfunc + +func Test_assert_notequal() + let n = 4 + call assert_equal(0, assert_notequal('foo', n)) + let s = 'foo' + call assert_equal(0, assert_notequal([1, 2, 3], s)) + + call assert_equal(1, assert_notequal('foo', s)) + call assert_match("Expected not equal to 'foo'", v:errors[0]) + call remove(v:errors, 0) +endfunc + +func Test_assert_report() + call assert_equal(1, assert_report('something is wrong')) + call assert_match('something is wrong', v:errors[0]) + call remove(v:errors, 0) +endfunc + +func Test_assert_exception() + try + nocommand + catch + call assert_equal(0, assert_exception('E492:')) + endtry + + try + nocommand + catch + try + " illegal argument, get NULL for error + call assert_equal(1, assert_exception([])) + catch + call assert_equal(0, assert_exception('E730:')) + endtry + endtry +endfunc + +func Test_wrong_error_type() + let save_verrors = v:errors + let v:['errors'] = {'foo': 3} + call assert_equal('yes', 'no') + let verrors = v:errors + let v:errors = save_verrors + call assert_equal(type([]), type(verrors)) +endfunc + +func Test_compare_fail() + let s:v = {} + let s:x = {"a": s:v} + let s:v["b"] = s:x + let s:w = {"c": s:x, "d": ''} + try + call assert_equal(s:w, '') + catch + call assert_equal(0, assert_exception('E724:')) + call assert_match("Expected NULL but got ''", v:errors[0]) + call remove(v:errors, 0) + endtry +endfunc + +func Test_match() + call assert_equal(0, assert_match('^f.*b.*r$', 'foobar')) + + call assert_equal(1, assert_match('bar.*foo', 'foobar')) + call assert_match("Pattern 'bar.*foo' does not match 'foobar'", v:errors[0]) + call remove(v:errors, 0) + + call assert_equal(1, assert_match('bar.*foo', 'foobar', 'wrong')) + call assert_match('wrong', v:errors[0]) + call remove(v:errors, 0) +endfunc + +func Test_notmatch() + call assert_equal(0, assert_notmatch('foo', 'bar')) + call assert_equal(0, assert_notmatch('^foobar$', 'foobars')) + + call assert_equal(1, assert_notmatch('foo', 'foobar')) + call assert_match("Pattern 'foo' does match 'foobar'", v:errors[0]) + call remove(v:errors, 0) +endfunc + +func Test_assert_fail_fails() + call assert_equal(1, assert_fails('xxx', {})) + call assert_match("Expected {} but got 'E731:", v:errors[0]) + call remove(v:errors, 0) + + call assert_equal(1, assert_fails('xxx', {}, 'stupid')) + call assert_match("stupid: Expected {} but got 'E731:", v:errors[0]) + call remove(v:errors, 0) + + call assert_equal(1, assert_fails('echo', '', 'echo command')) + call assert_match("command did not fail: echo command", v:errors[0]) + call remove(v:errors, 0) +endfunc + +func Test_assert_beeps() + new + call assert_equal(0, assert_beeps('normal h')) + + call assert_equal(1, assert_beeps('normal 0')) + call assert_match("command did not beep: normal 0", v:errors[0]) + call remove(v:errors, 0) + bwipe +endfunc + +func Test_assert_inrange() + call assert_equal(0, assert_inrange(7, 7, 7)) + call assert_equal(0, assert_inrange(5, 7, 5)) + call assert_equal(0, assert_inrange(5, 7, 6)) + call assert_equal(0, assert_inrange(5, 7, 7)) + + call assert_equal(1, assert_inrange(5, 7, 4)) + call assert_match("Expected range 5 - 7, but got 4", v:errors[0]) + call remove(v:errors, 0) + call assert_equal(1, assert_inrange(5, 7, 8)) + call assert_match("Expected range 5 - 7, but got 8", v:errors[0]) + call remove(v:errors, 0) + + call assert_fails('call assert_inrange(1, 1)', 'E119:') +endfunc + +func Test_assert_with_msg() + call assert_equal('foo', 'bar', 'testing') + call assert_match("testing: Expected 'foo' but got 'bar'", v:errors[0]) + call remove(v:errors, 0) +endfunc + +func Test_override() + call test_override('char_avail', 1) + call test_override('redraw', 1) + call test_override('ALL', 0) + call assert_fails("call test_override('xxx', 1)", 'E475') + call assert_fails("call test_override('redraw', 'yes')", 'E474') +endfunc + +func Test_user_is_happy() + smile + sleep 300m +endfunc + +" Must be last. +func Test_zz_quit_detected() + " Verify that if a test function ends Vim the test script detects this. + quit +endfunc diff --git a/src/testdir/test_assign.vim b/src/testdir/test_assign.vim new file mode 100644 index 0000000..1715a3f --- /dev/null +++ b/src/testdir/test_assign.vim @@ -0,0 +1,53 @@ +" Test for assignment + +func Test_no_type_checking() + let v = 1 + let v = [1,2,3] + let v = {'a': 1, 'b': 2} + let v = 3.4 + let v = 'hello' +endfunc + +func Test_let_termcap() + " Terminal code + let old_t_te = &t_te + let &t_te = "\<Esc>[yes;" + call assert_match('t_te.*^[[yes;', execute("set termcap")) + let &t_te = old_t_te + + if exists("+t_k1") + " Key code + let old_t_k1 = &t_k1 + let &t_k1 = "that" + call assert_match('t_k1.*that', execute("set termcap")) + let &t_k1 = old_t_k1 + endif + + call assert_fails('let x = &t_xx', 'E113') + let &t_xx = "yes" + call assert_equal("yes", &t_xx) + let &t_xx = "" + call assert_fails('let x = &t_xx', 'E113') +endfunc + +func Test_let_option_error() + let _w = &tw + let &tw = 80 + call assert_fails('let &tw .= 1', 'E734') + call assert_equal(80, &tw) + let &tw = _w + + let _w = &fillchars + let &fillchars = "vert:|" + call assert_fails('let &fillchars += "diff:-"', 'E734') + call assert_equal("vert:|", &fillchars) + let &fillchars = _w +endfunc + +func Test_let_errors() + let s = 'abcd' + call assert_fails('let s[1] = 5', 'E689:') + + let l = [1, 2, 3] + call assert_fails('let l[:] = 5', 'E709:') +endfunc diff --git a/src/testdir/test_autochdir.vim b/src/testdir/test_autochdir.vim new file mode 100644 index 0000000..90538fb --- /dev/null +++ b/src/testdir/test_autochdir.vim @@ -0,0 +1,27 @@ +" Test 'autochdir' behavior + +if !exists("+autochdir") + finish +endif + +func Test_set_filename() + let cwd = getcwd() + call test_autochdir() + set acd + + let s:li = [] + autocmd DirChanged auto call add(s:li, "autocd") + autocmd DirChanged auto call add(s:li, expand("<afile>")) + + new + w samples/Xtest + call assert_equal("Xtest", expand('%')) + call assert_equal("samples", substitute(getcwd(), '.*/\(\k*\)', '\1', '')) + call assert_equal(["autocd", getcwd()], s:li) + + bwipe! + au! DirChanged + set noacd + exe 'cd ' . cwd + call delete('samples/Xtest') +endfunc diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim new file mode 100644 index 0000000..71df515 --- /dev/null +++ b/src/testdir/test_autocmd.vim @@ -0,0 +1,1418 @@ +" Tests for autocommands + +source shared.vim + +func s:cleanup_buffers() abort + for bnr in range(1, bufnr('$')) + if bufloaded(bnr) && bufnr('%') != bnr + execute 'bd! ' . bnr + endif + endfor +endfunc + +func Test_vim_did_enter() + call assert_false(v:vim_did_enter) + + " This script will never reach the main loop, can't check if v:vim_did_enter + " becomes one. +endfunc + +if has('timers') + func ExitInsertMode(id) + call feedkeys("\<Esc>") + endfunc + + func Test_cursorhold_insert() + " Need to move the cursor. + call feedkeys("ggG", "xt") + + let g:triggered = 0 + au CursorHoldI * let g:triggered += 1 + set updatetime=20 + call timer_start(100, 'ExitInsertMode') + call feedkeys('a', 'x!') + call assert_equal(1, g:triggered) + unlet g:triggered + au! CursorHoldI + set updatetime& + endfunc + + func Test_cursorhold_insert_with_timer_interrupt() + if !has('job') + return + endif + " Need to move the cursor. + call feedkeys("ggG", "xt") + + " Confirm the timer invoked in exit_cb of the job doesn't disturb + " CursorHoldI event. + let g:triggered = 0 + au CursorHoldI * let g:triggered += 1 + set updatetime=500 + call job_start(has('win32') ? 'cmd /c echo:' : 'echo', + \ {'exit_cb': {-> timer_start(1000, 'ExitInsertMode')}}) + call feedkeys('a', 'x!') + call assert_equal(1, g:triggered) + unlet g:triggered + au! CursorHoldI + set updatetime& + endfunc + + func Test_cursorhold_insert_ctrl_x() + let g:triggered = 0 + au CursorHoldI * let g:triggered += 1 + set updatetime=20 + call timer_start(100, 'ExitInsertMode') + " CursorHoldI does not trigger after CTRL-X + call feedkeys("a\<C-X>", 'x!') + call assert_equal(0, g:triggered) + unlet g:triggered + au! CursorHoldI + set updatetime& + endfunc +endif + +func Test_bufunload() + augroup test_bufunload_group + autocmd! + autocmd BufUnload * call add(s:li, "bufunload") + autocmd BufDelete * call add(s:li, "bufdelete") + autocmd BufWipeout * call add(s:li, "bufwipeout") + augroup END + + let s:li=[] + new + setlocal bufhidden= + bunload + call assert_equal(["bufunload", "bufdelete"], s:li) + + let s:li=[] + new + setlocal bufhidden=delete + bunload + call assert_equal(["bufunload", "bufdelete"], s:li) + + let s:li=[] + new + setlocal bufhidden=unload + bwipeout + call assert_equal(["bufunload", "bufdelete", "bufwipeout"], s:li) + + au! test_bufunload_group + augroup! test_bufunload_group +endfunc + +" SEGV occurs in older versions. (At least 7.4.2005 or older) +func Test_autocmd_bufunload_with_tabnext() + tabedit + tabfirst + + augroup test_autocmd_bufunload_with_tabnext_group + autocmd! + autocmd BufUnload <buffer> tabnext + augroup END + + quit + call assert_equal(2, tabpagenr('$')) + + autocmd! test_autocmd_bufunload_with_tabnext_group + augroup! test_autocmd_bufunload_with_tabnext_group + tablast + quit +endfunc + +func Test_autocmd_bufwinleave_with_tabfirst() + tabedit + augroup sample + autocmd! + autocmd BufWinLeave <buffer> tabfirst + augroup END + call setline(1, ['a', 'b', 'c']) + edit! a.txt + tabclose +endfunc + +" SEGV occurs in older versions. (At least 7.4.2321 or older) +func Test_autocmd_bufunload_avoiding_SEGV_01() + split aa.txt + let lastbuf = bufnr('$') + + augroup test_autocmd_bufunload + autocmd! + exe 'autocmd BufUnload <buffer> ' . (lastbuf + 1) . 'bwipeout!' + augroup END + + " Todo: check for E937 generated first + " call assert_fails('edit bb.txt', 'E937:') + call assert_fails('edit bb.txt', 'E517:') + + autocmd! test_autocmd_bufunload + augroup! test_autocmd_bufunload + bwipe! aa.txt + bwipe! bb.txt +endfunc + +" SEGV occurs in older versions. (At least 7.4.2321 or older) +func Test_autocmd_bufunload_avoiding_SEGV_02() + setlocal buftype=nowrite + let lastbuf = bufnr('$') + + augroup test_autocmd_bufunload + autocmd! + exe 'autocmd BufUnload <buffer> ' . (lastbuf + 1) . 'bwipeout!' + augroup END + + normal! i1 + call assert_fails('edit a.txt', 'E517:') + call feedkeys("\<CR>") + + autocmd! test_autocmd_bufunload + augroup! test_autocmd_bufunload + bwipe! a.txt +endfunc + +func Test_win_tab_autocmd() + let g:record = [] + + augroup testing + au WinNew * call add(g:record, 'WinNew') + au WinEnter * call add(g:record, 'WinEnter') + au WinLeave * call add(g:record, 'WinLeave') + au TabNew * call add(g:record, 'TabNew') + au TabClosed * call add(g:record, 'TabClosed') + au TabEnter * call add(g:record, 'TabEnter') + au TabLeave * call add(g:record, 'TabLeave') + augroup END + + split + tabnew + close + close + + call assert_equal([ + \ 'WinLeave', 'WinNew', 'WinEnter', + \ 'WinLeave', 'TabLeave', 'WinNew', 'WinEnter', 'TabNew', 'TabEnter', + \ 'WinLeave', 'TabLeave', 'TabClosed', 'WinEnter', 'TabEnter', + \ 'WinLeave', 'WinEnter' + \ ], g:record) + + let g:record = [] + tabnew somefile + tabnext + bwipe somefile + + call assert_equal([ + \ 'WinLeave', 'TabLeave', 'WinNew', 'WinEnter', 'TabNew', 'TabEnter', + \ 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter', + \ 'TabClosed' + \ ], g:record) + + augroup testing + au! + augroup END + unlet g:record +endfunc + +func s:AddAnAutocmd() + augroup vimBarTest + au BufReadCmd * echo 'hello' + augroup END + call assert_equal(3, len(split(execute('au vimBarTest'), "\n"))) +endfunc + +func Test_early_bar() + " test that a bar is recognized before the {event} + call s:AddAnAutocmd() + augroup vimBarTest | au! | augroup END + call assert_equal(1, len(split(execute('au vimBarTest'), "\n"))) + + call s:AddAnAutocmd() + augroup vimBarTest| au!| augroup END + call assert_equal(1, len(split(execute('au vimBarTest'), "\n"))) + + " test that a bar is recognized after the {event} + call s:AddAnAutocmd() + augroup vimBarTest| au!BufReadCmd| augroup END + call assert_equal(1, len(split(execute('au vimBarTest'), "\n"))) + + " test that a bar is recognized after the {group} + call s:AddAnAutocmd() + au! vimBarTest|echo 'hello' + call assert_equal(1, len(split(execute('au vimBarTest'), "\n"))) +endfunc + +func RemoveGroup() + autocmd! StartOK + augroup! StartOK +endfunc + +func Test_augroup_warning() + augroup TheWarning + au VimEnter * echo 'entering' + augroup END + call assert_true(match(execute('au VimEnter'), "TheWarning.*VimEnter") >= 0) + redir => res + augroup! TheWarning + redir END + call assert_true(match(res, "W19:") >= 0) + call assert_true(match(execute('au VimEnter'), "-Deleted-.*VimEnter") >= 0) + + " check "Another" does not take the pace of the deleted entry + augroup Another + augroup END + call assert_true(match(execute('au VimEnter'), "-Deleted-.*VimEnter") >= 0) + augroup! Another + + " no warning for postpone aucmd delete + augroup StartOK + au VimEnter * call RemoveGroup() + augroup END + call assert_true(match(execute('au VimEnter'), "StartOK.*VimEnter") >= 0) + redir => res + doautocmd VimEnter + redir END + call assert_true(match(res, "W19:") < 0) + au! VimEnter +endfunc + +func Test_BufReadCmdHelp() + " This used to cause access to free memory + au BufReadCmd * e +h + help + + au! BufReadCmd +endfunc + +func Test_BufReadCmdHelpJump() + " This used to cause access to free memory + au BufReadCmd * e +h{ + " } to fix highlighting + call assert_fails('help', 'E434:') + + au! BufReadCmd +endfunc + +func Test_augroup_deleted() + " This caused a crash before E936 was introduced + augroup x + call assert_fails('augroup! x', 'E936:') + au VimEnter * echo + augroup end + augroup! x + call assert_true(match(execute('au VimEnter'), "-Deleted-.*VimEnter") >= 0) + au! VimEnter +endfunc + +" Tests for autocommands on :close command. +" This used to be in test13. +func Test_three_windows() + " Clean up buffers, because in some cases this function fails. + call s:cleanup_buffers() + + " Write three files and open them, each in a window. + " Then go to next window, with autocommand that deletes the previous one. + " Do this twice, writing the file. + e! Xtestje1 + call setline(1, 'testje1') + w + sp Xtestje2 + call setline(1, 'testje2') + w + sp Xtestje3 + call setline(1, 'testje3') + w + wincmd w + au WinLeave Xtestje2 bwipe + wincmd w + call assert_equal('Xtestje1', expand('%')) + + au WinLeave Xtestje1 bwipe Xtestje3 + close + call assert_equal('Xtestje1', expand('%')) + + " Test deleting the buffer on a Unload event. If this goes wrong there + " will be the ATTENTION prompt. + e Xtestje1 + au! + au! BufUnload Xtestje1 bwipe + call assert_fails('e Xtestje3', 'E937:') + call assert_equal('Xtestje3', expand('%')) + + e Xtestje2 + sp Xtestje1 + call assert_fails('e', 'E937:') + call assert_equal('Xtestje1', expand('%')) + + " Test changing buffers in a BufWipeout autocommand. If this goes wrong + " there are ml_line errors and/or a Crash. + au! + only + e Xanother + e Xtestje1 + bwipe Xtestje2 + bwipe Xtestje3 + au BufWipeout Xtestje1 buf Xtestje1 + bwipe + call assert_equal('Xanother', expand('%')) + + only + help + wincmd w + 1quit + call assert_equal('Xanother', expand('%')) + + au! + enew + call delete('Xtestje1') + call delete('Xtestje2') + call delete('Xtestje3') +endfunc + +func Test_BufEnter() + au! BufEnter + au Bufenter * let val = val . '+' + let g:val = '' + split NewFile + call assert_equal('+', g:val) + bwipe! + call assert_equal('++', g:val) + + " Also get BufEnter when editing a directory + call mkdir('Xdir') + split Xdir + call assert_equal('+++', g:val) + + " On MS-Windows we can't edit the directory, make sure we wipe the right + " buffer. + bwipe! Xdir + + call delete('Xdir', 'd') + au! BufEnter +endfunc + +" Closing a window might cause an endless loop +" E814 for older Vims +func Test_autocmd_bufwipe_in_SessLoadPost() + edit Xtest + tabnew + file Xsomething + set noswapfile + mksession! + + let content = ['set nocp noswapfile', + \ 'let v:swapchoice="e"', + \ 'augroup test_autocmd_sessionload', + \ 'autocmd!', + \ 'autocmd SessionLoadPost * exe bufnr("Xsomething") . "bw!"', + \ 'augroup END', + \ '', + \ 'func WriteErrors()', + \ ' call writefile([execute("messages")], "Xerrors")', + \ 'endfunc', + \ 'au VimLeave * call WriteErrors()', + \ ] + call writefile(content, 'Xvimrc') + call system(v:progpath. ' -u Xvimrc --not-a-term --noplugins -S Session.vim -c cq') + let errors = join(readfile('Xerrors')) + call assert_match('E814', errors) + + set swapfile + for file in ['Session.vim', 'Xvimrc', 'Xerrors'] + call delete(file) + endfor +endfunc + +" SEGV occurs in older versions. +func Test_autocmd_bufwipe_in_SessLoadPost2() + tabnew + set noswapfile + mksession! + + let content = ['set nocp noswapfile', + \ 'function! DeleteInactiveBufs()', + \ ' tabfirst', + \ ' let tabblist = []', + \ ' for i in range(1, tabpagenr(''$''))', + \ ' call extend(tabblist, tabpagebuflist(i))', + \ ' endfor', + \ ' for b in range(1, bufnr(''$''))', + \ ' if bufexists(b) && buflisted(b) && (index(tabblist, b) == -1 || bufname(b) =~# ''^$'')', + \ ' exec ''bwipeout '' . b', + \ ' endif', + \ ' endfor', + \ ' echomsg "SessionLoadPost DONE"', + \ 'endfunction', + \ 'au SessionLoadPost * call DeleteInactiveBufs()', + \ '', + \ 'func WriteErrors()', + \ ' call writefile([execute("messages")], "Xerrors")', + \ 'endfunc', + \ 'au VimLeave * call WriteErrors()', + \ ] + call writefile(content, 'Xvimrc') + call system(v:progpath. ' -u Xvimrc --not-a-term --noplugins -S Session.vim -c cq') + let errors = join(readfile('Xerrors')) + " This probably only ever matches on unix. + call assert_notmatch('Caught deadly signal SEGV', errors) + call assert_match('SessionLoadPost DONE', errors) + + set swapfile + for file in ['Session.vim', 'Xvimrc', 'Xerrors'] + call delete(file) + endfor +endfunc + +func Test_empty_doau() + doau \| +endfunc + +func s:AutoCommandOptionSet(match) + let item = remove(g:options, 0) + let expected = printf("Option: <%s>, Oldval: <%s>, NewVal: <%s>, Scope: <%s>\n", item[0], item[1], item[2], item[3]) + let actual = printf("Option: <%s>, Oldval: <%s>, NewVal: <%s>, Scope: <%s>\n", a:match, v:option_old, v:option_new, v:option_type) + let g:opt = [expected, actual] + "call assert_equal(expected, actual) +endfunc + +func Test_OptionSet() + if !has("eval") || !exists("+autochdir") + return + endif + + badd test_autocmd.vim + + call test_override('starting', 1) + set nocp + au OptionSet * :call s:AutoCommandOptionSet(expand("<amatch>")) + + " 1: Setting number option" + let g:options=[['number', 0, 1, 'global']] + set nu + call assert_equal([], g:options) + call assert_equal(g:opt[0], g:opt[1]) + + " 2: Setting local number option" + let g:options=[['number', 1, 0, 'local']] + setlocal nonu + call assert_equal([], g:options) + call assert_equal(g:opt[0], g:opt[1]) + + " 3: Setting global number option" + let g:options=[['number', 1, 0, 'global']] + setglobal nonu + call assert_equal([], g:options) + call assert_equal(g:opt[0], g:opt[1]) + + " 4: Setting local autoindent option" + let g:options=[['autoindent', 0, 1, 'local']] + setlocal ai + call assert_equal([], g:options) + call assert_equal(g:opt[0], g:opt[1]) + + " 5: Setting global autoindent option" + let g:options=[['autoindent', 0, 1, 'global']] + setglobal ai + call assert_equal([], g:options) + call assert_equal(g:opt[0], g:opt[1]) + + " 6: Setting global autoindent option" + let g:options=[['autoindent', 1, 0, 'global']] + set ai! + call assert_equal([], g:options) + call assert_equal(g:opt[0], g:opt[1]) + + " Should not print anything, use :noa + " 7: don't trigger OptionSet" + let g:options=[['invalid', 1, 1, 'invalid']] + noa set nonu + call assert_equal([['invalid', 1, 1, 'invalid']], g:options) + call assert_equal(g:opt[0], g:opt[1]) + + " 8: Setting several global list and number option" + let g:options=[['list', 0, 1, 'global'], ['number', 0, 1, 'global']] + set list nu + call assert_equal([], g:options) + call assert_equal(g:opt[0], g:opt[1]) + + " 9: don't trigger OptionSet" + let g:options=[['invalid', 1, 1, 'invalid'], ['invalid', 1, 1, 'invalid']] + noa set nolist nonu + call assert_equal([['invalid', 1, 1, 'invalid'], ['invalid', 1, 1, 'invalid']], g:options) + call assert_equal(g:opt[0], g:opt[1]) + + " 10: Setting global acd" + let g:options=[['autochdir', 0, 1, 'local']] + setlocal acd + call assert_equal([], g:options) + call assert_equal(g:opt[0], g:opt[1]) + + " 11: Setting global autoread (also sets local value)" + let g:options=[['autoread', 0, 1, 'global']] + set ar + call assert_equal([], g:options) + call assert_equal(g:opt[0], g:opt[1]) + + " 12: Setting local autoread" + let g:options=[['autoread', 1, 1, 'local']] + setlocal ar + call assert_equal([], g:options) + call assert_equal(g:opt[0], g:opt[1]) + + " 13: Setting global autoread" + let g:options=[['autoread', 1, 0, 'global']] + setglobal invar + call assert_equal([], g:options) + call assert_equal(g:opt[0], g:opt[1]) + + " 14: Setting option backspace through :let" + let g:options=[['backspace', '', 'eol,indent,start', 'global']] + let &bs="eol,indent,start" + call assert_equal([], g:options) + call assert_equal(g:opt[0], g:opt[1]) + + " 15: Setting option backspace through setbufvar()" + let g:options=[['backup', 0, 1, 'local']] + " try twice, first time, shouldn't trigger because option name is invalid, + " second time, it should trigger + let bnum = bufnr('%') + call assert_fails("call setbufvar(bnum, '&l:bk', 1)", "E355") + " should trigger, use correct option name + call setbufvar(bnum, '&backup', 1) + call assert_equal([], g:options) + call assert_equal(g:opt[0], g:opt[1]) + + " 16: Setting number option using setwinvar" + let g:options=[['number', 0, 1, 'local']] + call setwinvar(0, '&number', 1) + call assert_equal([], g:options) + call assert_equal(g:opt[0], g:opt[1]) + + " 17: Setting key option, shouldn't trigger" + let g:options=[['key', 'invalid', 'invalid1', 'invalid']] + setlocal key=blah + setlocal key= + call assert_equal([['key', 'invalid', 'invalid1', 'invalid']], g:options) + call assert_equal(g:opt[0], g:opt[1]) + + " 18: Setting string option" + let oldval = &tags + let g:options=[['tags', oldval, 'tagpath', 'global']] + set tags=tagpath + call assert_equal([], g:options) + call assert_equal(g:opt[0], g:opt[1]) + + " 1l: Resetting string option" + let g:options=[['tags', 'tagpath', oldval, 'global']] + set tags& + call assert_equal([], g:options) + call assert_equal(g:opt[0], g:opt[1]) + + " Cleanup + au! OptionSet + for opt in ['nu', 'ai', 'acd', 'ar', 'bs', 'backup', 'cul', 'cp'] + exe printf(":set %s&vim", opt) + endfor + call test_override('starting', 0) + delfunc! AutoCommandOptionSet +endfunc + +func Test_OptionSet_diffmode() + call test_override('starting', 1) + " 18: Changing an option when entering diff mode + new + au OptionSet diff :let &l:cul=v:option_new + + call setline(1, ['buffer 1', 'line2', 'line3', 'line4']) + call assert_equal(0, &l:cul) + diffthis + call assert_equal(1, &l:cul) + + vnew + call setline(1, ['buffer 2', 'line 2', 'line 3', 'line4']) + call assert_equal(0, &l:cul) + diffthis + call assert_equal(1, &l:cul) + + diffoff + call assert_equal(0, &l:cul) + call assert_equal(1, getwinvar(2, '&l:cul')) + bw! + + call assert_equal(1, &l:cul) + diffoff! + call assert_equal(0, &l:cul) + call assert_equal(0, getwinvar(1, '&l:cul')) + bw! + + " Cleanup + au! OptionSet + call test_override('starting', 0) +endfunc + +func Test_OptionSet_diffmode_close() + call test_override('starting', 1) + " 19: Try to close the current window when entering diff mode + " should not segfault + new + au OptionSet diff close + + call setline(1, ['buffer 1', 'line2', 'line3', 'line4']) + call assert_fails(':diffthis', 'E788') + call assert_equal(1, &diff) + vnew + call setline(1, ['buffer 2', 'line 2', 'line 3', 'line4']) + call assert_fails(':diffthis', 'E788') + call assert_equal(1, &diff) + bw! + call assert_fails(':diffoff!', 'E788') + bw! + + " Cleanup + au! OptionSet + call test_override('starting', 0) + "delfunc! AutoCommandOptionSet +endfunc + +func Test_OptionSet_modeline() + call test_override('starting', 1) + au! OptionSet + augroup set_tabstop + au OptionSet tabstop call timer_start(1, {-> execute("echo 'Handler called'", "")}) + augroup END + call writefile(['vim: set ts=7 sw=5 :', 'something'], 'XoptionsetModeline') + set modeline + let v:errmsg = '' + call assert_fails('split XoptionsetModeline', 'E12:') + call assert_equal(7, &ts) + call assert_equal('', v:errmsg) + + augroup set_tabstop + au! + augroup END + bwipe! + set ts& + call delete('XoptionsetModeline') + call test_override('starting', 0) +endfunc + +" Test for Bufleave autocommand that deletes the buffer we are about to edit. +func Test_BufleaveWithDelete() + new | edit Xfile1 + + augroup test_bufleavewithdelete + autocmd! + autocmd BufLeave Xfile1 bwipe Xfile2 + augroup END + + call assert_fails('edit Xfile2', 'E143:') + call assert_equal('Xfile1', bufname('%')) + + autocmd! test_bufleavewithdelete BufLeave Xfile1 + augroup! test_bufleavewithdelete + + new + bwipe! Xfile1 +endfunc + +" Test for autocommand that changes the buffer list, when doing ":ball". +func Test_Acmd_BufAll() + enew! + %bwipe! + call writefile(['Test file Xxx1'], 'Xxx1') + call writefile(['Test file Xxx2'], 'Xxx2') + call writefile(['Test file Xxx3'], 'Xxx3') + + " Add three files to the buffer list + split Xxx1 + close + split Xxx2 + close + split Xxx3 + close + + " Wipe the buffer when the buffer is opened + au BufReadPost Xxx2 bwipe + + call append(0, 'Test file Xxx4') + ball + + call assert_equal(2, winnr('$')) + call assert_equal('Xxx1', bufname(winbufnr(winnr('$')))) + wincmd t + + au! BufReadPost + %bwipe! + call delete('Xxx1') + call delete('Xxx2') + call delete('Xxx3') + enew! | only +endfunc + +" Test for autocommand that changes current buffer on BufEnter event. +" Check if modelines are interpreted for the correct buffer. +func Test_Acmd_BufEnter() + %bwipe! + call writefile(['start of test file Xxx1', + \ "\<Tab>this is a test", + \ 'end of test file Xxx1'], 'Xxx1') + call writefile(['start of test file Xxx2', + \ 'vim: set noai :', + \ "\<Tab>this is a test", + \ 'end of test file Xxx2'], 'Xxx2') + + au BufEnter Xxx2 brew + set ai modeline modelines=3 + edit Xxx1 + " edit Xxx2, autocmd will do :brew + edit Xxx2 + exe "normal G?this is a\<CR>" + " Append text with autoindent to this file + normal othis should be auto-indented + call assert_equal("\<Tab>this should be auto-indented", getline('.')) + call assert_equal(3, line('.')) + " Remove autocmd and edit Xxx2 again + au! BufEnter Xxx2 + buf! Xxx2 + exe "normal G?this is a\<CR>" + " append text without autoindent to Xxx + normal othis should be in column 1 + call assert_equal("this should be in column 1", getline('.')) + call assert_equal(4, line('.')) + + %bwipe! + call delete('Xxx1') + call delete('Xxx2') + set ai&vim modeline&vim modelines&vim +endfunc + +" Test for issue #57 +" do not move cursor on <c-o> when autoindent is set +func Test_ai_CTRL_O() + enew! + set ai + let save_fo = &fo + set fo+=r + exe "normal o# abcdef\<Esc>2hi\<CR>\<C-O>d0\<Esc>" + exe "normal o# abcdef\<Esc>2hi\<C-O>d0\<Esc>" + call assert_equal(['# abc', 'def', 'def'], getline(2, 4)) + + set ai&vim + let &fo = save_fo + enew! +endfunc + +" Test for autocommand that deletes the current buffer on BufLeave event. +" Also test deleting the last buffer, should give a new, empty buffer. +func Test_BufLeave_Wipe() + %bwipe! + let content = ['start of test file Xxx', + \ 'this is a test', + \ 'end of test file Xxx'] + call writefile(content, 'Xxx1') + call writefile(content, 'Xxx2') + + au BufLeave Xxx2 bwipe + edit Xxx1 + split Xxx2 + " delete buffer Xxx2, we should be back to Xxx1 + bwipe + call assert_equal('Xxx1', bufname('%')) + call assert_equal(1, winnr('$')) + + " Create an alternate buffer + %write! test.out + call assert_equal('test.out', bufname('#')) + " delete alternate buffer + bwipe test.out + call assert_equal('Xxx1', bufname('%')) + call assert_equal('', bufname('#')) + + au BufLeave Xxx1 bwipe + " delete current buffer, get an empty one + bwipe! + call assert_equal(1, line('$')) + call assert_equal('', bufname('%')) + let g:bufinfo = getbufinfo() + call assert_equal(1, len(g:bufinfo)) + + call delete('Xxx1') + call delete('Xxx2') + call delete('test.out') + %bwipe + au! BufLeave + + " check that bufinfo doesn't contain a pointer to freed memory + call test_garbagecollect_now() +endfunc + +func Test_QuitPre() + edit Xfoo + let winid = win_getid(winnr()) + split Xbar + au! QuitPre * let g:afile = expand('<afile>') + " Close the other window, <afile> should be correct. + exe win_id2win(winid) . 'q' + call assert_equal('Xfoo', g:afile) + + unlet g:afile + bwipe Xfoo + bwipe Xbar +endfunc + +func Test_Cmdline() + au! CmdlineChanged : let g:text = getcmdline() + let g:text = 0 + call feedkeys(":echom 'hello'\<CR>", 'xt') + call assert_equal("echom 'hello'", g:text) + au! CmdlineChanged + + au! CmdlineChanged : let g:entered = expand('<afile>') + let g:entered = 0 + call feedkeys(":echom 'hello'\<CR>", 'xt') + call assert_equal(':', g:entered) + au! CmdlineChanged + + au! CmdlineEnter : let g:entered = expand('<afile>') + au! CmdlineLeave : let g:left = expand('<afile>') + let g:entered = 0 + let g:left = 0 + call feedkeys(":echo 'hello'\<CR>", 'xt') + call assert_equal(':', g:entered) + call assert_equal(':', g:left) + au! CmdlineEnter + au! CmdlineLeave + + let save_shellslash = &shellslash + set noshellslash + au! CmdlineEnter / let g:entered = expand('<afile>') + au! CmdlineLeave / let g:left = expand('<afile>') + let g:entered = 0 + let g:left = 0 + new + call setline(1, 'hello') + call feedkeys("/hello\<CR>", 'xt') + call assert_equal('/', g:entered) + call assert_equal('/', g:left) + bwipe! + au! CmdlineEnter + au! CmdlineLeave + let &shellslash = save_shellslash +endfunc + +" Test for BufWritePre autocommand that deletes or unloads the buffer. +func Test_BufWritePre() + %bwipe + au BufWritePre Xxx1 bunload + au BufWritePre Xxx2 bwipe + + call writefile(['start of Xxx1', 'test', 'end of Xxx1'], 'Xxx1') + call writefile(['start of Xxx2', 'test', 'end of Xxx2'], 'Xxx2') + + edit Xtest + e! Xxx2 + bdel Xtest + e Xxx1 + " write it, will unload it and give an error msg + call assert_fails('w', 'E203') + call assert_equal('Xxx2', bufname('%')) + edit Xtest + e! Xxx2 + bwipe Xtest + " write it, will delete the buffer and give an error msg + call assert_fails('w', 'E203') + call assert_equal('Xxx1', bufname('%')) + au! BufWritePre + call delete('Xxx1') + call delete('Xxx2') +endfunc + +" Test for BufUnload autocommand that unloads all the other buffers +func Test_bufunload_all() + call writefile(['Test file Xxx1'], 'Xxx1')" + call writefile(['Test file Xxx2'], 'Xxx2')" + + let content = [ + \ "func UnloadAllBufs()", + \ " let i = 1", + \ " while i <= bufnr('$')", + \ " if i != bufnr('%') && bufloaded(i)", + \ " exe i . 'bunload'", + \ " endif", + \ " let i += 1", + \ " endwhile", + \ "endfunc", + \ "au BufUnload * call UnloadAllBufs()", + \ "au VimLeave * call writefile(['Test Finished'], 'Xout')", + \ "edit Xxx1", + \ "split Xxx2", + \ "q"] + call writefile(content, 'Xtest') + + call delete('Xout') + call system(v:progpath. ' --clean -N --not-a-term -S Xtest') + call assert_true(filereadable('Xout')) + + call delete('Xxx1') + call delete('Xxx2') + call delete('Xtest') + call delete('Xout') +endfunc + +" Some tests for buffer-local autocommands +func Test_buflocal_autocmd() + let g:bname = '' + edit xx + au BufLeave <buffer> let g:bname = expand("%") + " here, autocommand for xx should trigger. + " but autocommand shall not apply to buffer named <buffer>. + edit somefile + call assert_equal('xx', g:bname) + let g:bname = '' + " here, autocommand shall be auto-deleted + bwipe xx + " autocmd should not trigger + edit xx + call assert_equal('', g:bname) + " autocmd should not trigger + edit somefile + call assert_equal('', g:bname) + enew + unlet g:bname +endfunc + +" Test for "*Cmd" autocommands +func Test_Cmd_Autocmds() + call writefile(['start of Xxx', "\tabc2", 'end of Xxx'], 'Xxx') + + enew! + au BufReadCmd XtestA 0r Xxx|$del + edit XtestA " will read text of Xxd instead + call assert_equal('start of Xxx', getline(1)) + + au BufWriteCmd XtestA call append(line("$"), "write") + write " will append a line to the file + call assert_equal('write', getline('$')) + call assert_fails('read XtestA', 'E484') " should not read anything + call assert_equal('write', getline(4)) + + " now we have: + " 1 start of Xxx + " 2 abc2 + " 3 end of Xxx + " 4 write + + au FileReadCmd XtestB '[r Xxx + 2r XtestB " will read Xxx below line 2 instead + call assert_equal('start of Xxx', getline(3)) + + " now we have: + " 1 start of Xxx + " 2 abc2 + " 3 start of Xxx + " 4 abc2 + " 5 end of Xxx + " 6 end of Xxx + " 7 write + + au FileWriteCmd XtestC '[,']copy $ + normal 4GA1 + 4,5w XtestC " will copy lines 4 and 5 to the end + call assert_equal("\tabc21", getline(8)) + call assert_fails('r XtestC', 'E484') " should not read anything + call assert_equal("end of Xxx", getline(9)) + + " now we have: + " 1 start of Xxx + " 2 abc2 + " 3 start of Xxx + " 4 abc21 + " 5 end of Xxx + " 6 end of Xxx + " 7 write + " 8 abc21 + " 9 end of Xxx + + let g:lines = [] + au FileAppendCmd XtestD call extend(g:lines, getline(line("'["), line("']"))) + w >>XtestD " will add lines to 'lines' + call assert_equal(9, len(g:lines)) + call assert_fails('$r XtestD', 'E484') " should not read anything + call assert_equal(9, line('$')) + call assert_equal('end of Xxx', getline('$')) + + au BufReadCmd XtestE 0r Xxx|$del + sp XtestE " split window with test.out + call assert_equal('end of Xxx', getline(3)) + + let g:lines = [] + exe "normal 2Goasdf\<Esc>\<C-W>\<C-W>" + au BufWriteCmd XtestE call extend(g:lines, getline(0, '$')) + wall " will write other window to 'lines' + call assert_equal(4, len(g:lines), g:lines) + call assert_equal('asdf', g:lines[2]) + + au! BufReadCmd + au! BufWriteCmd + au! FileReadCmd + au! FileWriteCmd + au! FileAppendCmd + %bwipe! + call delete('Xxx') + enew! +endfunc + +func SetChangeMarks(start, end) + exe a:start. 'mark [' + exe a:end. 'mark ]' +endfunc + +" Verify the effects of autocmds on '[ and '] +func Test_change_mark_in_autocmds() + edit! Xtest + call feedkeys("ia\<CR>b\<CR>c\<CR>d\<C-g>u", 'xtn') + + call SetChangeMarks(2, 3) + write + call assert_equal([1, 4], [line("'["), line("']")]) + + call SetChangeMarks(2, 3) + au BufWritePre * call assert_equal([1, 4], [line("'["), line("']")]) + write + au! BufWritePre + + if executable('cat') + write XtestFilter + write >> XtestFilter + + call SetChangeMarks(2, 3) + " Marks are set to the entire range of the write + au FilterWritePre * call assert_equal([1, 4], [line("'["), line("']")]) + " '[ is adjusted to just before the line that will receive the filtered + " data + au FilterReadPre * call assert_equal([4, 4], [line("'["), line("']")]) + " The filtered data is read into the buffer, and the source lines are + " still present, so the range is after the source lines + au FilterReadPost * call assert_equal([5, 12], [line("'["), line("']")]) + %!cat XtestFilter + " After the filtered data is read, the original lines are deleted + call assert_equal([1, 8], [line("'["), line("']")]) + au! FilterWritePre,FilterReadPre,FilterReadPost + undo + + call SetChangeMarks(1, 4) + au FilterWritePre * call assert_equal([2, 3], [line("'["), line("']")]) + au FilterReadPre * call assert_equal([3, 3], [line("'["), line("']")]) + au FilterReadPost * call assert_equal([4, 11], [line("'["), line("']")]) + 2,3!cat XtestFilter + call assert_equal([2, 9], [line("'["), line("']")]) + au! FilterWritePre,FilterReadPre,FilterReadPost + undo + + call delete('XtestFilter') + endif + + call SetChangeMarks(1, 4) + au FileWritePre * call assert_equal([2, 3], [line("'["), line("']")]) + 2,3write Xtest2 + au! FileWritePre + + call SetChangeMarks(2, 3) + au FileAppendPre * call assert_equal([1, 4], [line("'["), line("']")]) + write >> Xtest2 + au! FileAppendPre + + call SetChangeMarks(1, 4) + au FileAppendPre * call assert_equal([2, 3], [line("'["), line("']")]) + 2,3write >> Xtest2 + au! FileAppendPre + + call SetChangeMarks(1, 1) + au FileReadPre * call assert_equal([3, 1], [line("'["), line("']")]) + au FileReadPost * call assert_equal([4, 11], [line("'["), line("']")]) + 3read Xtest2 + au! FileReadPre,FileReadPost + undo + + call SetChangeMarks(4, 4) + " When the line is 0, it's adjusted to 1 + au FileReadPre * call assert_equal([1, 4], [line("'["), line("']")]) + au FileReadPost * call assert_equal([1, 8], [line("'["), line("']")]) + 0read Xtest2 + au! FileReadPre,FileReadPost + undo + + call SetChangeMarks(4, 4) + " When the line is 0, it's adjusted to 1 + au FileReadPre * call assert_equal([1, 4], [line("'["), line("']")]) + au FileReadPost * call assert_equal([2, 9], [line("'["), line("']")]) + 1read Xtest2 + au! FileReadPre,FileReadPost + undo + + bwipe! + call delete('Xtest') + call delete('Xtest2') +endfunc + +func Test_Filter_noshelltemp() + if !executable('cat') + return + endif + + enew! + call setline(1, ['a', 'b', 'c', 'd']) + + let shelltemp = &shelltemp + set shelltemp + + let g:filter_au = 0 + au FilterWritePre * let g:filter_au += 1 + au FilterReadPre * let g:filter_au += 1 + au FilterReadPost * let g:filter_au += 1 + %!cat + call assert_equal(3, g:filter_au) + + if has('filterpipe') + set noshelltemp + + let g:filter_au = 0 + au FilterWritePre * let g:filter_au += 1 + au FilterReadPre * let g:filter_au += 1 + au FilterReadPost * let g:filter_au += 1 + %!cat + call assert_equal(0, g:filter_au) + endif + + au! FilterWritePre,FilterReadPre,FilterReadPost + let &shelltemp = shelltemp + bwipe! +endfunc + +func Test_TextYankPost() + enew! + call setline(1, ['foo']) + + let g:event = [] + au TextYankPost * let g:event = copy(v:event) + + call assert_equal({}, v:event) + call assert_fails('let v:event = {}', 'E46:') + call assert_fails('let v:event.mykey = 0', 'E742:') + + norm "ayiw + call assert_equal( + \{'regcontents': ['foo'], 'regname': 'a', 'operator': 'y', 'regtype': 'v'}, + \g:event) + norm y_ + call assert_equal( + \{'regcontents': ['foo'], 'regname': '', 'operator': 'y', 'regtype': 'V'}, + \g:event) + call feedkeys("\<C-V>y", 'x') + call assert_equal( + \{'regcontents': ['f'], 'regname': '', 'operator': 'y', 'regtype': "\x161"}, + \g:event) + norm "xciwbar + call assert_equal( + \{'regcontents': ['foo'], 'regname': 'x', 'operator': 'c', 'regtype': 'v'}, + \g:event) + norm "bdiw + call assert_equal( + \{'regcontents': ['bar'], 'regname': 'b', 'operator': 'd', 'regtype': 'v'}, + \g:event) + + call assert_equal({}, v:event) + + au! TextYankPost + unlet g:event + bwipe! +endfunc + +func Test_nocatch_wipe_all_buffers() + " Real nasty autocommand: wipe all buffers on any event. + au * * bwipe * + " Get E93 first? + " call assert_fails('next x', 'E93:') + call assert_fails('next x', 'E517:') + bwipe + au! +endfunc + +func Test_nocatch_wipe_dummy_buffer() + " Nasty autocommand: wipe buffer on any event. + au * x bwipe + call assert_fails('lv½ /x', 'E480') + au! +endfunc + +function s:Before_test_dirchanged() + augroup test_dirchanged + autocmd! + augroup END + let s:li = [] + let s:dir_this = getcwd() + let s:dir_foo = s:dir_this . '/foo' + call mkdir(s:dir_foo) + let s:dir_bar = s:dir_this . '/bar' + call mkdir(s:dir_bar) +endfunc + +function s:After_test_dirchanged() + exe 'cd' s:dir_this + call delete(s:dir_foo, 'd') + call delete(s:dir_bar, 'd') + augroup test_dirchanged + autocmd! + augroup END +endfunc + +function Test_dirchanged_global() + call s:Before_test_dirchanged() + autocmd test_dirchanged DirChanged global call add(s:li, "cd:") + autocmd test_dirchanged DirChanged global call add(s:li, expand("<afile>")) + exe 'cd' s:dir_foo + call assert_equal(["cd:", s:dir_foo], s:li) + exe 'cd' s:dir_foo + call assert_equal(["cd:", s:dir_foo], s:li) + exe 'lcd' s:dir_bar + call assert_equal(["cd:", s:dir_foo], s:li) + call s:After_test_dirchanged() +endfunc + +function Test_dirchanged_local() + call s:Before_test_dirchanged() + autocmd test_dirchanged DirChanged window call add(s:li, "lcd:") + autocmd test_dirchanged DirChanged window call add(s:li, expand("<afile>")) + exe 'cd' s:dir_foo + call assert_equal([], s:li) + exe 'lcd' s:dir_bar + call assert_equal(["lcd:", s:dir_bar], s:li) + exe 'lcd' s:dir_bar + call assert_equal(["lcd:", s:dir_bar], s:li) + call s:After_test_dirchanged() +endfunc + +function Test_dirchanged_auto() + if !exists('+autochdir') + return + endif + call s:Before_test_dirchanged() + call test_autochdir() + autocmd test_dirchanged DirChanged auto call add(s:li, "auto:") + autocmd test_dirchanged DirChanged auto call add(s:li, expand("<afile>")) + set acd + exe 'cd ..' + call assert_equal([], s:li) + exe 'edit ' . s:dir_foo . '/Xfile' + call assert_equal(s:dir_foo, getcwd()) + call assert_equal(["auto:", s:dir_foo], s:li) + set noacd + bwipe! + call s:After_test_dirchanged() +endfunc + +" Test TextChangedI and TextChangedP +func Test_ChangedP() + new + call setline(1, ['foo', 'bar', 'foobar']) + call test_override("char_avail", 1) + set complete=. completeopt=menuone + + func! TextChangedAutocmd(char) + let g:autocmd .= a:char + endfunc + + au! TextChanged <buffer> :call TextChangedAutocmd('N') + au! TextChangedI <buffer> :call TextChangedAutocmd('I') + au! TextChangedP <buffer> :call TextChangedAutocmd('P') + + call cursor(3, 1) + let g:autocmd = '' + call feedkeys("o\<esc>", 'tnix') + call assert_equal('I', g:autocmd) + + let g:autocmd = '' + call feedkeys("Sf", 'tnix') + call assert_equal('II', g:autocmd) + + let g:autocmd = '' + call feedkeys("Sf\<C-N>", 'tnix') + call assert_equal('IIP', g:autocmd) + + let g:autocmd = '' + call feedkeys("Sf\<C-N>\<C-N>", 'tnix') + call assert_equal('IIPP', g:autocmd) + + let g:autocmd = '' + call feedkeys("Sf\<C-N>\<C-N>\<C-N>", 'tnix') + call assert_equal('IIPPP', g:autocmd) + + let g:autocmd = '' + call feedkeys("Sf\<C-N>\<C-N>\<C-N>\<C-N>", 'tnix') + call assert_equal('IIPPPP', g:autocmd) + + call assert_equal(['foo', 'bar', 'foobar', 'foo'], getline(1, '$')) + " TODO: how should it handle completeopt=noinsert,noselect? + + " CleanUp + call test_override("char_avail", 0) + au! TextChanged + au! TextChangedI + au! TextChangedP + delfu TextChangedAutocmd + unlet! g:autocmd + set complete&vim completeopt&vim + + bw! +endfunc + +let g:setline_handled = v:false +func SetLineOne() + if !g:setline_handled + call setline(1, "(x)") + let g:setline_handled = v:true + endif +endfunc + +func Test_TextChangedI_with_setline() + new + call test_override('char_avail', 1) + autocmd TextChangedI <buffer> call SetLineOne() + call feedkeys("i(\<CR>\<Esc>", 'tx') + call assert_equal('(', getline(1)) + call assert_equal('x)', getline(2)) + undo + call assert_equal('', getline(1)) + call assert_equal('', getline(2)) + + call test_override('starting', 0) + bwipe! +endfunc + +func Test_Changed_FirstTime() + if !has('terminal') || has('gui_running') + return + endif + " Prepare file for TextChanged event. + call writefile([''], 'Xchanged.txt') + let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile'], {'term_rows': 3}) + call assert_equal('running', term_getstatus(buf)) + " Wait for the ruler (in the status line) to be shown. + " In ConPTY, there is additional character which is drawn up to the width of + " the screen. + if has('conpty') + call WaitForAssert({-> assert_match('\<All.*$', term_getline(buf, 3))}) + else + call WaitForAssert({-> assert_match('\<All$', term_getline(buf, 3))}) + endif + " It's only adding autocmd, so that no event occurs. + call term_sendkeys(buf, ":au! TextChanged <buffer> call writefile(['No'], 'Xchanged.txt')\<cr>") + call term_sendkeys(buf, "\<C-\\>\<C-N>:qa!\<cr>") + call WaitForAssert({-> assert_equal('finished', term_getstatus(buf))}) + call assert_equal([''], readfile('Xchanged.txt')) + + " clean up + call delete('Xchanged.txt') + bwipe! +endfunc + +" FileChangedShell tested in test_filechanged.vim diff --git a/src/testdir/test_autoload.vim b/src/testdir/test_autoload.vim new file mode 100644 index 0000000..7396c22 --- /dev/null +++ b/src/testdir/test_autoload.vim @@ -0,0 +1,17 @@ +" Tests for autoload + +set runtimepath=./sautest + +func Test_autoload_dict_func() + let g:loaded_foo_vim = 0 + let g:called_foo_bar_echo = 0 + call g:foo#bar.echo() + call assert_equal(1, g:loaded_foo_vim) + call assert_equal(1, g:called_foo_bar_echo) +endfunc + +func Test_source_autoload() + let g:loaded_sourced_vim = 0 + source sautest/autoload/sourced.vim + call assert_equal(1, g:loaded_sourced_vim) +endfunc diff --git a/src/testdir/test_backspace_opt.vim b/src/testdir/test_backspace_opt.vim new file mode 100644 index 0000000..fd81f42 --- /dev/null +++ b/src/testdir/test_backspace_opt.vim @@ -0,0 +1,59 @@ +" Tests for 'backspace' settings + +:func Exec(expr) + let str='' + try + exec a:expr + catch /.*/ + let str=v:exception + endtry + return str +:endfunc + +func Test_backspace_option() + set backspace= + call assert_equal('', &backspace) + set backspace=indent + call assert_equal('indent', &backspace) + set backspace=eol + call assert_equal('eol', &backspace) + set backspace=start + call assert_equal('start', &backspace) + " Add the value + set backspace= + set backspace=indent + call assert_equal('indent', &backspace) + set backspace+=eol + call assert_equal('indent,eol', &backspace) + set backspace+=start + call assert_equal('indent,eol,start', &backspace) + " Delete the value + set backspace-=indent + call assert_equal('eol,start', &backspace) + set backspace-=start + call assert_equal('eol', &backspace) + set backspace-=eol + call assert_equal('', &backspace) + " Check the error + call assert_equal(0, match(Exec('set backspace=ABC'), '.*E474')) + call assert_equal(0, match(Exec('set backspace+=def'), '.*E474')) + " NOTE: Vim doesn't check following error... + "call assert_equal(0, match(Exec('set backspace-=ghi'), '.*E474')) + + " Check backwards compatibility with version 5.4 and earlier + set backspace=0 + call assert_equal('0', &backspace) + set backspace=1 + call assert_equal('1', &backspace) + set backspace=2 + call assert_equal('2', &backspace) + call assert_false(match(Exec('set backspace=3'), '.*E474')) + call assert_false(match(Exec('set backspace=10'), '.*E474')) + + " Cleared when 'compatible' is set + set compatible + call assert_equal('', &backspace) + set nocompatible viminfo+=nviminfo +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_backup.vim b/src/testdir/test_backup.vim new file mode 100644 index 0000000..ce2bfe7 --- /dev/null +++ b/src/testdir/test_backup.vim @@ -0,0 +1,58 @@ +" Tests for the backup function + +func Test_backup() + set backup backupdir=. backupskip= + new + call setline(1, ['line1', 'line2']) + :f Xbackup.txt + :w! Xbackup.txt + " backup file is only created after + " writing a second time (before overwriting) + :w! Xbackup.txt + let l = readfile('Xbackup.txt~') + call assert_equal(['line1', 'line2'], l) + bw! + set backup&vim backupdir&vim backupskip&vim + call delete('Xbackup.txt') + call delete('Xbackup.txt~') +endfunc + +func Test_backup2() + set backup backupdir=.// backupskip= + new + call setline(1, ['line1', 'line2', 'line3']) + :f Xbackup.txt + :w! Xbackup.txt + " backup file is only created after + " writing a second time (before overwriting) + :w! Xbackup.txt + sp *Xbackup.txt~ + call assert_equal(['line1', 'line2', 'line3'], getline(1,'$')) + let f=expand('%') + call assert_match('%testdir%Xbackup.txt\~', f) + bw! + bw! + call delete('Xbackup.txt') + call delete(f) + set backup&vim backupdir&vim backupskip&vim +endfunc + +func Test_backup2_backupcopy() + set backup backupdir=.// backupcopy=yes backupskip= + new + call setline(1, ['line1', 'line2', 'line3']) + :f Xbackup.txt + :w! Xbackup.txt + " backup file is only created after + " writing a second time (before overwriting) + :w! Xbackup.txt + sp *Xbackup.txt~ + call assert_equal(['line1', 'line2', 'line3'], getline(1,'$')) + let f=expand('%') + call assert_match('%testdir%Xbackup.txt\~', f) + bw! + bw! + call delete('Xbackup.txt') + call delete(f) + set backup&vim backupdir&vim backupcopy&vim backupskip&vim +endfunc diff --git a/src/testdir/test_behave.vim b/src/testdir/test_behave.vim new file mode 100644 index 0000000..c26bfe7 --- /dev/null +++ b/src/testdir/test_behave.vim @@ -0,0 +1,29 @@ +" Test the :behave command + +func Test_behave() + behave mswin + call assert_equal('mouse,key', &selectmode) + call assert_equal('popup', &mousemodel) + call assert_equal('startsel,stopsel', &keymodel) + call assert_equal('exclusive', &selection) + + behave xterm + call assert_equal('', &selectmode) + call assert_equal('extend', &mousemodel) + call assert_equal('', &keymodel) + call assert_equal('inclusive', &selection) + + set selection& + set mousemodel& + set keymodel& + set selection& +endfunc + +func Test_behave_completion() + call feedkeys(":behave \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"behave mswin xterm', @:) +endfunc + +func Test_behave_error() + call assert_fails('behave x', 'E475:') +endfunc diff --git a/src/testdir/test_blob.vim b/src/testdir/test_blob.vim new file mode 100644 index 0000000..b01e11b --- /dev/null +++ b/src/testdir/test_blob.vim @@ -0,0 +1,320 @@ +" Tests for the Blob types + +func TearDown() + " Run garbage collection after every test + call test_garbagecollect_now() +endfunc + +" Tests for Blob type + +" Blob creation from constant +func Test_blob_create() + let b = 0zDEADBEEF + call assert_equal(v:t_blob, type(b)) + call assert_equal(4, len(b)) + call assert_equal(0xDE, b[0]) + call assert_equal(0xAD, b[1]) + call assert_equal(0xBE, b[2]) + call assert_equal(0xEF, b[3]) + call assert_fails('let x = b[4]') + + call assert_equal(0xDE, get(b, 0)) + call assert_equal(0xEF, get(b, 3)) + + call assert_fails('let b = 0z1', 'E973:') + call assert_fails('let b = 0z1x', 'E973:') + call assert_fails('let b = 0z12345', 'E973:') + + call assert_equal(0z, test_null_blob()) + + let b = 0z001122.33445566.778899.aabbcc.dd + call assert_equal(0z00112233445566778899aabbccdd, b) + call assert_fails('let b = 0z1.1') + call assert_fails('let b = 0z.') + call assert_fails('let b = 0z001122.') + call assert_fails('call get("", 1)', 'E896:') +endfunc + +" assignment to a blob +func Test_blob_assign() + let b = 0zDEADBEEF + let b2 = b[1:2] + call assert_equal(0zADBE, b2) + + let bcopy = b[:] + call assert_equal(b, bcopy) + call assert_false(b is bcopy) + + let b = 0zDEADBEEF + let b2 = b + call assert_true(b is b2) + let b[:] = 0z11223344 + call assert_equal(0z11223344, b) + call assert_equal(0z11223344, b2) + call assert_true(b is b2) + + let b = 0zDEADBEEF + let b[3:] = 0z66 + call assert_equal(0zDEADBE66, b) + let b[:1] = 0z8899 + call assert_equal(0z8899BE66, b) + + call assert_fails('let b[2:3] = 0z112233', 'E972:') + call assert_fails('let b[2:3] = 0z11', 'E972:') + call assert_fails('let b[3:2] = 0z', 'E979:') + + let b = 0zDEADBEEF + let b += 0z99 + call assert_equal(0zDEADBEEF99, b) + + call assert_fails('let b .= 0z33', 'E734:') + call assert_fails('let b .= "xx"', 'E734:') + call assert_fails('let b += "xx"', 'E734:') + call assert_fails('let b[1:1] .= 0z55', 'E734:') +endfunc + +func Test_blob_get_range() + let b = 0z0011223344 + call assert_equal(0z2233, b[2:3]) + call assert_equal(0z223344, b[2:-1]) + call assert_equal(0z00, b[0:-5]) + call assert_equal(0z, b[0:-11]) + call assert_equal(0z44, b[-1:]) + call assert_equal(0z0011223344, b[:]) + call assert_equal(0z0011223344, b[:-1]) + call assert_equal(0z, b[5:6]) +endfunc + +func Test_blob_get() + let b = 0z0011223344 + call assert_equal(0x00, get(b, 0)) + call assert_equal(0x22, get(b, 2, 999)) + call assert_equal(0x44, get(b, 4)) + call assert_equal(0x44, get(b, -1)) + call assert_equal(-1, get(b, 5)) + call assert_equal(999, get(b, 5, 999)) + call assert_equal(-1, get(b, -8)) + call assert_equal(999, get(b, -8, 999)) + + call assert_equal(0x00, b[0]) + call assert_equal(0x22, b[2]) + call assert_equal(0x44, b[4]) + call assert_equal(0x44, b[-1]) + call assert_fails('echo b[5]', 'E979:') + call assert_fails('echo b[-8]', 'E979:') +endfunc + +func Test_blob_to_string() + let b = 0z00112233445566778899aabbccdd + call assert_equal('0z00112233.44556677.8899AABB.CCDD', string(b)) + call assert_equal(b, eval(string(b))) + call remove(b, 4, -1) + call assert_equal('0z00112233', string(b)) + call remove(b, 0, 3) + call assert_equal('0z', string(b)) +endfunc + +func Test_blob_compare() + let b1 = 0z0011 + let b2 = 0z1100 + let b3 = 0z001122 + call assert_true(b1 == b1) + call assert_false(b1 == b2) + call assert_false(b1 == b3) + call assert_true(b1 != b2) + call assert_true(b1 != b3) + call assert_true(b1 == 0z0011) + call assert_fails('echo b1 == 9', 'E977:') + call assert_fails('echo b1 != 9', 'E977:') + + call assert_false(b1 is b2) + let b2 = b1 + call assert_true(b1 == b2) + call assert_true(b1 is b2) + let b2 = copy(b1) + call assert_true(b1 == b2) + call assert_false(b1 is b2) + let b2 = b1[:] + call assert_true(b1 == b2) + call assert_false(b1 is b2) + + call assert_fails('let x = b1 > b2') + call assert_fails('let x = b1 < b2') + call assert_fails('let x = b1 - b2') + call assert_fails('let x = b1 / b2') + call assert_fails('let x = b1 * b2') +endfunc + +" test for range assign +func Test_blob_range_assign() + let b = 0z00 + let b[1] = 0x11 + let b[2] = 0x22 + call assert_equal(0z001122, b) + call assert_fails('let b[4] = 0x33', 'E979:') +endfunc + +func Test_blob_for_loop() + let blob = 0z00010203 + let i = 0 + for byte in blob + call assert_equal(i, byte) + let i += 1 + endfor + call assert_equal(4, i) + + let blob = 0z00 + call remove(blob, 0) + call assert_equal(0, len(blob)) + for byte in blob + call assert_error('loop over empty blob') + endfor + + let blob = 0z0001020304 + let i = 0 + for byte in blob + call assert_equal(i, byte) + if i == 1 + call remove(blob, 0) + elseif i == 3 + call remove(blob, 3) + endif + let i += 1 + endfor + call assert_equal(5, i) +endfunc + +func Test_blob_concatenate() + let b = 0z0011 + let b += 0z2233 + call assert_equal(0z00112233, b) + + call assert_fails('let b += "a"') + call assert_fails('let b += 88') + + let b = 0zDEAD + 0zBEEF + call assert_equal(0zDEADBEEF, b) +endfunc + +func Test_blob_add() + let b = 0z0011 + call add(b, 0x22) + call assert_equal(0z001122, b) + call add(b, '51') + call assert_equal(0z00112233, b) + + call assert_fails('call add(b, [9])', 'E745:') + call assert_fails('call add("", 0x01)', 'E897:') +endfunc + +func Test_blob_empty() + call assert_false(empty(0z001122)) + call assert_true(empty(0z)) + call assert_true(empty(test_null_blob())) +endfunc + +" Test removing items in blob +func Test_blob_func_remove() + " Test removing 1 element + let b = 0zDEADBEEF + call assert_equal(0xDE, remove(b, 0)) + call assert_equal(0zADBEEF, b) + + let b = 0zDEADBEEF + call assert_equal(0xEF, remove(b, -1)) + call assert_equal(0zDEADBE, b) + + let b = 0zDEADBEEF + call assert_equal(0xAD, remove(b, 1)) + call assert_equal(0zDEBEEF, b) + + " Test removing range of element(s) + let b = 0zDEADBEEF + call assert_equal(0zBE, remove(b, 2, 2)) + call assert_equal(0zDEADEF, b) + + let b = 0zDEADBEEF + call assert_equal(0zADBE, remove(b, 1, 2)) + call assert_equal(0zDEEF, b) + + " Test invalid cases + let b = 0zDEADBEEF + call assert_fails("call remove(b, 5)", 'E979:') + call assert_fails("call remove(b, 1, 5)", 'E979:') + call assert_fails("call remove(b, 3, 2)", 'E979:') + call assert_fails("call remove(1, 0)", 'E896:') + call assert_fails("call remove(b, b)", 'E974:') +endfunc + +func Test_blob_read_write() + let b = 0zDEADBEEF + call writefile(b, 'Xblob') + let br = readfile('Xblob', 'B') + call assert_equal(b, br) + call delete('Xblob') +endfunc + +" filter() item in blob +func Test_blob_filter() + let b = 0zDEADBEEF + call filter(b, 'v:val != 0xEF') + call assert_equal(0zDEADBE, b) +endfunc + +" map() item in blob +func Test_blob_map() + let b = 0zDEADBEEF + call map(b, 'v:val + 1') + call assert_equal(0zDFAEBFF0, b) + + call assert_fails("call map(b, '[9]')", 'E978:') +endfunc + +func Test_blob_index() + call assert_equal(2, index(0zDEADBEEF, 0xBE)) + call assert_equal(-1, index(0zDEADBEEF, 0)) + call assert_equal(2, index(0z11111111, 0x11, 2)) + call assert_equal(3, index(0z11110111, 0x11, 2)) + call assert_equal(2, index(0z11111111, 0x11, -2)) + call assert_equal(3, index(0z11110111, 0x11, -2)) + + call assert_fails('call index("asdf", 0)', 'E897:') +endfunc + +func Test_blob_insert() + let b = 0zDEADBEEF + call insert(b, 0x33) + call assert_equal(0z33DEADBEEF, b) + + let b = 0zDEADBEEF + call insert(b, 0x33, 2) + call assert_equal(0zDEAD33BEEF, b) + + call assert_fails('call insert(b, -1)', 'E475:') + call assert_fails('call insert(b, 257)', 'E475:') + call assert_fails('call insert(b, 0, [9])', 'E745:') +endfunc + +func Test_blob_reverse() + call assert_equal(0zEFBEADDE, reverse(0zDEADBEEF)) + call assert_equal(0zBEADDE, reverse(0zDEADBE)) + call assert_equal(0zADDE, reverse(0zDEAD)) + call assert_equal(0zDE, reverse(0zDE)) +endfunc + +func Test_blob_json_encode() + call assert_equal('[222,173,190,239]', json_encode(0zDEADBEEF)) + call assert_equal('[]', json_encode(0z)) +endfunc + +func Test_blob_lock() + let b = 0z112233 + lockvar b + call assert_fails('let b = 0z44', 'E741:') + unlockvar b + let b = 0z44 +endfunc + +func Test_blob_sort() + call assert_fails('call sort([1.0, 0z11], "f")', 'E975:') +endfunc diff --git a/src/testdir/test_blockedit.vim b/src/testdir/test_blockedit.vim new file mode 100644 index 0000000..527224c --- /dev/null +++ b/src/testdir/test_blockedit.vim @@ -0,0 +1,33 @@ +" Test for block inserting +" +" TODO: rewrite test39.in into this new style test + +func Test_blockinsert_indent() + new + filetype plugin indent on + setlocal sw=2 et ft=vim + call setline(1, ['let a=[', ' ''eins'',', ' ''zwei'',', ' ''drei'']']) + call cursor(2, 3) + exe "norm! \<c-v>2jI\\ \<esc>" + call assert_equal(['let a=[', ' \ ''eins'',', ' \ ''zwei'',', ' \ ''drei'']'], + \ getline(1,'$')) + " reset to sane state + filetype off + bwipe! +endfunc + +func Test_blockinsert_delete() + new + let _bs = &bs + set bs=2 + call setline(1, ['case Arg is ', ' when Name_Async,', ' when Name_Num_Gangs,', 'end if;']) + exe "norm! ggjVj\<c-v>$o$A\<bs>\<esc>" + "call feedkeys("Vj\<c-v>$o$A\<bs>\<esc>", 'ti') + call assert_equal(["case Arg is ", " when Name_Async", " when Name_Num_Gangs,", "end if;"], + \ getline(1,'$')) + " reset to sane state + let &bs = _bs + bwipe! +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_breakindent.vim b/src/testdir/test_breakindent.vim new file mode 100644 index 0000000..ae05479 --- /dev/null +++ b/src/testdir/test_breakindent.vim @@ -0,0 +1,617 @@ +" Test for breakindent +" +" Note: if you get strange failures when adding new tests, it might be that +" while the test is run, the breakindent cacheing gets in its way. +" It helps to change the tabstop setting and force a redraw (e.g. see +" Test_breakindent08()) +if !exists('+breakindent') + finish +endif + +source view_util.vim + +let s:input ="\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP" + +func s:screen_lines(lnum, width) abort + return ScreenLines([a:lnum, a:lnum + 2], a:width) +endfunc + +func s:compare_lines(expect, actual) + call assert_equal(join(a:expect, "\n"), join(a:actual, "\n")) +endfunc + +func s:test_windows(...) + call NewWindow(10, 20) + setl ts=4 sw=4 sts=4 breakindent + put =s:input + exe get(a:000, 0, '') +endfunc + +func s:close_windows(...) + call CloseWindow() + exe get(a:000, 0, '') +endfunc + +func Test_breakindent01() + " simple breakindent test + call s:test_windows('setl briopt=min:0') + let lines = s:screen_lines(line('.'),8) + let expect = [ + \ " abcd", + \ " qrst", + \ " GHIJ", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_breakindent01_vartabs() + " like 01 but with vartabs feature + if !has("vartabs") + return + endif + call s:test_windows('setl briopt=min:0 vts=4') + let lines = s:screen_lines(line('.'),8) + let expect = [ + \ " abcd", + \ " qrst", + \ " GHIJ", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows('set vts&') +endfunc + +func Test_breakindent02() + " simple breakindent test with showbreak set + call s:test_windows('setl briopt=min:0 sbr=>>') + let lines = s:screen_lines(line('.'),8) + let expect = [ + \ " abcd", + \ " >>qr", + \ " >>EF", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows('set sbr=') +endfunc + +func Test_breakindent02_vartabs() + if !has("vartabs") + return + endif + " simple breakindent test with showbreak set + call s:test_windows('setl briopt=min:0 sbr=>> vts=4') + let lines = s:screen_lines(line('.'),8) + let expect = [ + \ " abcd", + \ " >>qr", + \ " >>EF", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows('set sbr= vts&') +endfunc + +func Test_breakindent03() + " simple breakindent test with showbreak set and briopt including sbr + call s:test_windows('setl briopt=sbr,min:0 sbr=++') + let lines = s:screen_lines(line('.'),8) + let expect = [ + \ " abcd", + \ "++ qrst", + \ "++ GHIJ", + \ ] + call s:compare_lines(expect, lines) + " clean up + call s:close_windows('set sbr=') +endfunc + +func Test_breakindent03_vartabs() + " simple breakindent test with showbreak set and briopt including sbr + if !has("vartabs") + return + endif + call s:test_windows('setl briopt=sbr,min:0 sbr=++ vts=4') + let lines = s:screen_lines(line('.'),8) + let expect = [ + \ " abcd", + \ "++ qrst", + \ "++ GHIJ", + \ ] + call s:compare_lines(expect, lines) + " clean up + call s:close_windows('set sbr= vts&') +endfunc + +func Test_breakindent04() + " breakindent set with min width 18 + call s:test_windows('setl sbr= briopt=min:18') + let lines = s:screen_lines(line('.'),8) + let expect = [ + \ " abcd", + \ " qrstuv", + \ " IJKLMN", + \ ] + call s:compare_lines(expect, lines) + " clean up + call s:close_windows('set sbr=') +endfunc + +func Test_breakindent04_vartabs() + " breakindent set with min width 18 + if !has("vartabs") + return + endif + call s:test_windows('setl sbr= briopt=min:18 vts=4') + let lines = s:screen_lines(line('.'),8) + let expect = [ + \ " abcd", + \ " qrstuv", + \ " IJKLMN", + \ ] + call s:compare_lines(expect, lines) + " clean up + call s:close_windows('set sbr= vts&') +endfunc + +func Test_breakindent05() + " breakindent set and shift by 2 + call s:test_windows('setl briopt=shift:2,min:0') + let lines = s:screen_lines(line('.'),8) + let expect = [ + \ " abcd", + \ " qr", + \ " EF", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_breakindent05_vartabs() + " breakindent set and shift by 2 + if !has("vartabs") + return + endif + call s:test_windows('setl briopt=shift:2,min:0 vts=4') + let lines = s:screen_lines(line('.'),8) + let expect = [ + \ " abcd", + \ " qr", + \ " EF", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows('set vts&') +endfunc + +func Test_breakindent06() + " breakindent set and shift by -1 + call s:test_windows('setl briopt=shift:-1,min:0') + let lines = s:screen_lines(line('.'),8) + let expect = [ + \ " abcd", + \ " qrstu", + \ " HIJKL", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_breakindent06_vartabs() + " breakindent set and shift by -1 + if !has("vartabs") + return + endif + call s:test_windows('setl briopt=shift:-1,min:0 vts=4') + let lines = s:screen_lines(line('.'),8) + let expect = [ + \ " abcd", + \ " qrstu", + \ " HIJKL", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows('set vts&') +endfunc + +func Test_breakindent07() + " breakindent set and shift by 1, Number set sbr=? and briopt:sbr + call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 cpo+=n') + let lines = s:screen_lines(line('.'),10) + let expect = [ + \ " 2 ab", + \ "? m", + \ "? x", + \ ] + call s:compare_lines(expect, lines) + " clean up + call s:close_windows('set sbr= cpo-=n') +endfunc + +func Test_breakindent07_vartabs() + if !has("vartabs") + return + endif + " breakindent set and shift by 1, Number set sbr=? and briopt:sbr + call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 cpo+=n vts=4') + let lines = s:screen_lines(line('.'),10) + let expect = [ + \ " 2 ab", + \ "? m", + \ "? x", + \ ] + call s:compare_lines(expect, lines) + " clean up + call s:close_windows('set sbr= cpo-=n vts&') +endfunc + +func Test_breakindent07a() + " breakindent set and shift by 1, Number set sbr=? and briopt:sbr + call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4') + let lines = s:screen_lines(line('.'),10) + let expect = [ + \ " 2 ab", + \ " ? m", + \ " ? x", + \ ] + call s:compare_lines(expect, lines) + " clean up + call s:close_windows('set sbr=') +endfunc + +func Test_breakindent07a_vartabs() + if !has("vartabs") + return + endif + " breakindent set and shift by 1, Number set sbr=? and briopt:sbr + call s:test_windows('setl briopt=shift:1,sbr,min:0 nu sbr=? nuw=4 vts=4') + let lines = s:screen_lines(line('.'),10) + let expect = [ + \ " 2 ab", + \ " ? m", + \ " ? x", + \ ] + call s:compare_lines(expect, lines) + " clean up + call s:close_windows('set sbr= vts&') +endfunc + +func Test_breakindent08() + " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr + call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list cpo+=n ts=4') + " make sure, cache is invalidated! + set ts=8 + redraw! + set ts=4 + redraw! + let lines = s:screen_lines(line('.'),10) + let expect = [ + \ " 2 ^Iabcd", + \ "# opq", + \ "# BCD", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows('set sbr= cpo-=n') +endfunc + +func Test_breakindent08_vartabs() + if !has("vartabs") + return + endif + " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr + call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list cpo+=n ts=4 vts=4') + " make sure, cache is invalidated! + set ts=8 + redraw! + set ts=4 + redraw! + let lines = s:screen_lines(line('.'),10) + let expect = [ + \ " 2 ^Iabcd", + \ "# opq", + \ "# BCD", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows('set sbr= cpo-=n vts&') +endfunc + +func Test_breakindent08a() + " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr + call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list') + let lines = s:screen_lines(line('.'),10) + let expect = [ + \ " 2 ^Iabcd", + \ " # opq", + \ " # BCD", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows('set sbr=') +endfunc + +func Test_breakindent08a_vartabs() + if !has("vartabs") + return + endif + " breakindent set and shift by 1, Number and list set sbr=# and briopt:sbr + call s:test_windows('setl briopt=shift:1,sbr,min:0 nu nuw=4 sbr=# list vts=4') + let lines = s:screen_lines(line('.'),10) + let expect = [ + \ " 2 ^Iabcd", + \ " # opq", + \ " # BCD", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows('set sbr= vts&') +endfunc + +func Test_breakindent09() + " breakindent set and shift by 1, Number and list set sbr=# + call s:test_windows('setl briopt=shift:1,min:0 nu nuw=4 sbr=# list') + let lines = s:screen_lines(line('.'),10) + let expect = [ + \ " 2 ^Iabcd", + \ " #op", + \ " #AB", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows('set sbr=') +endfunc + +func Test_breakindent09_vartabs() + if !has("vartabs") + return + endif + " breakindent set and shift by 1, Number and list set sbr=# + call s:test_windows('setl briopt=shift:1,min:0 nu nuw=4 sbr=# list vts=4') + let lines = s:screen_lines(line('.'),10) + let expect = [ + \ " 2 ^Iabcd", + \ " #op", + \ " #AB", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows('set sbr= vts&') +endfunc + +func Test_breakindent10() + " breakindent set, Number set sbr=~ + call s:test_windows('setl cpo+=n sbr=~ nu nuw=4 nolist briopt=sbr,min:0') + " make sure, cache is invalidated! + set ts=8 + redraw! + set ts=4 + redraw! + let lines = s:screen_lines(line('.'),10) + let expect = [ + \ " 2 ab", + \ "~ mn", + \ "~ yz", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows('set sbr= cpo-=n') +endfunc + +func Test_breakindent10_vartabs() + if !has("vartabs") + return + endif + " breakindent set, Number set sbr=~ + call s:test_windows('setl cpo+=n sbr=~ nu nuw=4 nolist briopt=sbr,min:0 vts=4') + " make sure, cache is invalidated! + set ts=8 + redraw! + set ts=4 + redraw! + let lines = s:screen_lines(line('.'),10) + let expect = [ + \ " 2 ab", + \ "~ mn", + \ "~ yz", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows('set sbr= cpo-=n vts&') +endfunc + +func Test_breakindent11() + " test strdisplaywidth() + call s:test_windows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4') + let text = getline(2) + let width = strlen(text[1:])+indent(2)+strlen(&sbr)*3 " text wraps 3 times + call assert_equal(width, strdisplaywidth(text)) + call s:close_windows('set sbr=') +endfunc + +func Test_breakindent11_vartabs() + if !has("vartabs") + return + endif + " test strdisplaywidth() + call s:test_windows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4 vts=4') + let text = getline(2) + let width = strlen(text[1:])+indent(2)+strlen(&sbr)*3 " text wraps 3 times + call assert_equal(width, strdisplaywidth(text)) + call s:close_windows('set sbr= vts&') +endfunc + +func Test_breakindent12() + " test breakindent with long indent + let s:input = "\t\t\t\t\t{" + call s:test_windows('setl breakindent linebreak briopt=min:10 nu numberwidth=3 ts=4 list listchars=tab:>-') + let lines = s:screen_lines(2,16) + let expect = [ + \ " 2 >--->--->--->", + \ " ---{ ", + \ "~ ", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows('set nuw=4 listchars=') +endfunc + +func Test_breakindent12_vartabs() + if !has("vartabs") + return + endif + " test breakindent with long indent + let s:input = "\t\t\t\t\t{" + call s:test_windows('setl breakindent linebreak briopt=min:10 nu numberwidth=3 ts=4 list listchars=tab:>- vts=4') + let lines = s:screen_lines(2,16) + let expect = [ + \ " 2 >--->--->--->", + \ " ---{ ", + \ "~ ", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows('set nuw=4 listchars= vts&') +endfunc + +func Test_breakindent13() + let s:input = "" + call s:test_windows('setl breakindent briopt=min:10 ts=8') + vert resize 20 + call setline(1, [" a\tb\tc\td\te", " z y x w v"]) + 1 + norm! fbgj"ayl + 2 + norm! fygj"byl + call assert_equal('d', @a) + call assert_equal('w', @b) + call s:close_windows() +endfunc + +func Test_breakindent13_vartabs() + if !has("vartabs") + return + endif + let s:input = "" + call s:test_windows('setl breakindent briopt=min:10 ts=8 vts=8') + vert resize 20 + call setline(1, [" a\tb\tc\td\te", " z y x w v"]) + 1 + norm! fbgj"ayl + 2 + norm! fygj"byl + call assert_equal('d', @a) + call assert_equal('w', @b) + call s:close_windows('set vts&') +endfunc + +func Test_breakindent14() + let s:input = "" + call s:test_windows('setl breakindent briopt= ts=8') + vert resize 30 + norm! 3a1234567890 + norm! a abcde + exec "norm! 0\<C-V>tex" + let lines = s:screen_lines(line('.'),8) + let expect = [ + \ "e ", + \ "~ ", + \ "~ ", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_breakindent14_vartabs() + if !has("vartabs") + return + endif + let s:input = "" + call s:test_windows('setl breakindent briopt= ts=8 vts=8') + vert resize 30 + norm! 3a1234567890 + norm! a abcde + exec "norm! 0\<C-V>tex" + let lines = s:screen_lines(line('.'),8) + let expect = [ + \ "e ", + \ "~ ", + \ "~ ", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows('set vts&') +endfunc + +func Test_breakindent15() + let s:input = "" + call s:test_windows('setl breakindent briopt= ts=8 sw=8') + vert resize 30 + norm! 4a1234567890 + exe "normal! >>\<C-V>3f0x" + let lines = s:screen_lines(line('.'),20) + let expect = [ + \ " 1234567890 ", + \ "~ ", + \ "~ ", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_breakindent15_vartabs() + if !has("vartabs") + return + endif + let s:input = "" + call s:test_windows('setl breakindent briopt= ts=8 sw=8 vts=8') + vert resize 30 + norm! 4a1234567890 + exe "normal! >>\<C-V>3f0x" + let lines = s:screen_lines(line('.'),20) + let expect = [ + \ " 1234567890 ", + \ "~ ", + \ "~ ", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows('set vts&') +endfunc + +func Test_breakindent16() + " Check that overlong lines are indented correctly. + let s:input = "" + call s:test_windows('setl breakindent briopt=min:0 ts=4') + call setline(1, "\t".repeat("1234567890", 10)) + resize 6 + norm! 1gg$ + redraw! + let lines = s:screen_lines(1,10) + let expect = [ + \ " 789012", + \ " 345678", + \ " 901234", + \ ] + call s:compare_lines(expect, lines) + let lines = s:screen_lines(4,10) + let expect = [ + \ " 567890", + \ " 123456", + \ " 7890 ", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_breakindent16_vartabs() + if !has("vartabs") + return + endif + " Check that overlong lines are indented correctly. + let s:input = "" + call s:test_windows('setl breakindent briopt=min:0 ts=4 vts=4') + call setline(1, "\t".repeat("1234567890", 10)) + resize 6 + norm! 1gg$ + redraw! + let lines = s:screen_lines(1,10) + let expect = [ + \ " 789012", + \ " 345678", + \ " 901234", + \ ] + call s:compare_lines(expect, lines) + let lines = s:screen_lines(4,10) + let expect = [ + \ " 567890", + \ " 123456", + \ " 7890 ", + \ ] + call s:compare_lines(expect, lines) + call s:close_windows('set vts&') +endfunc diff --git a/src/testdir/test_bufline.vim b/src/testdir/test_bufline.vim new file mode 100644 index 0000000..524144d --- /dev/null +++ b/src/testdir/test_bufline.vim @@ -0,0 +1,141 @@ +" Tests for setbufline(), getbufline(), appendbufline(), deletebufline() + +source shared.vim + +func Test_setbufline_getbufline() + new + let b = bufnr('%') + hide + call assert_equal(0, setbufline(b, 1, ['foo', 'bar'])) + call assert_equal(['foo'], getbufline(b, 1)) + call assert_equal(['bar'], getbufline(b, 2)) + call assert_equal(['foo', 'bar'], getbufline(b, 1, 2)) + exe "bd!" b + call assert_equal([], getbufline(b, 1, 2)) + + split Xtest + call setline(1, ['a', 'b', 'c']) + let b = bufnr('%') + wincmd w + call assert_equal(1, setbufline(b, 5, ['x'])) + call assert_equal(1, setbufline(1234, 1, ['x'])) + call assert_equal(0, setbufline(b, 4, ['d', 'e'])) + call assert_equal(['c'], getbufline(b, 3)) + call assert_equal(['d'], getbufline(b, 4)) + call assert_equal(['e'], getbufline(b, 5)) + call assert_equal([], getbufline(b, 6)) + exe "bwipe! " . b +endfunc + +func Test_setbufline_getbufline_fold() + split Xtest + setlocal foldmethod=expr foldexpr=0 + let b = bufnr('%') + new + call assert_equal(0, setbufline(b, 1, ['foo', 'bar'])) + call assert_equal(['foo'], getbufline(b, 1)) + call assert_equal(['bar'], getbufline(b, 2)) + call assert_equal(['foo', 'bar'], getbufline(b, 1, 2)) + exe "bwipe!" b + bwipe! +endfunc + +func Test_setbufline_getbufline_fold_tab() + split Xtest + setlocal foldmethod=expr foldexpr=0 + let b = bufnr('%') + tab new + call assert_equal(0, setbufline(b, 1, ['foo', 'bar'])) + call assert_equal(['foo'], getbufline(b, 1)) + call assert_equal(['bar'], getbufline(b, 2)) + call assert_equal(['foo', 'bar'], getbufline(b, 1, 2)) + exe "bwipe!" b + bwipe! +endfunc + +func Test_setline_startup() + let cmd = GetVimCommand('Xscript') + if cmd == '' + return + endif + call writefile(['call setline(1, "Hello")', 'silent w Xtest', 'q!'], 'Xscript') + call system(cmd) + call assert_equal(['Hello'], readfile('Xtest')) + + call delete('Xscript') + call delete('Xtest') +endfunc + +func Test_appendbufline() + new + let b = bufnr('%') + hide + call assert_equal(0, appendbufline(b, 0, ['foo', 'bar'])) + call assert_equal(['foo'], getbufline(b, 1)) + call assert_equal(['bar'], getbufline(b, 2)) + call assert_equal(['foo', 'bar'], getbufline(b, 1, 2)) + exe "bd!" b + call assert_equal([], getbufline(b, 1, 2)) + + split Xtest + call setline(1, ['a', 'b', 'c']) + let b = bufnr('%') + wincmd w + call assert_equal(1, appendbufline(b, 4, ['x'])) + call assert_equal(1, appendbufline(1234, 1, ['x'])) + call assert_equal(0, appendbufline(b, 3, ['d', 'e'])) + call assert_equal(['c'], getbufline(b, 3)) + call assert_equal(['d'], getbufline(b, 4)) + call assert_equal(['e'], getbufline(b, 5)) + call assert_equal([], getbufline(b, 6)) + exe "bwipe! " . b +endfunc + +func Test_appendbufline_no_E315() + let after = [ + \ 'set stl=%f ls=2', + \ 'new', + \ 'let buf = bufnr("%")', + \ 'quit', + \ 'vsp', + \ 'exec "buffer" buf', + \ 'wincmd w', + \ 'call appendbufline(buf, 0, "abc")', + \ 'redraw', + \ 'while getbufline(buf, 1)[0] =~ "^\\s*$"', + \ ' sleep 10m', + \ 'endwhile', + \ 'au VimLeavePre * call writefile([v:errmsg], "Xerror")', + \ 'au VimLeavePre * call writefile(["done"], "Xdone")', + \ 'qall!', + \ ] + if !RunVim([], after, '--clean') + return + endif + call assert_notmatch("^E315:", readfile("Xerror")[0]) + call assert_equal("done", readfile("Xdone")[0]) + call delete("Xerror") + call delete("Xdone") +endfunc + +func Test_deletebufline() + new + let b = bufnr('%') + call setline(1, ['aaa', 'bbb', 'ccc']) + hide + call assert_equal(0, deletebufline(b, 2)) + call assert_equal(['aaa', 'ccc'], getbufline(b, 1, 2)) + call assert_equal(0, deletebufline(b, 2, 8)) + call assert_equal(['aaa'], getbufline(b, 1, 2)) + exe "bd!" b + call assert_equal(1, deletebufline(b, 1)) + + split Xtest + call setline(1, ['a', 'b', 'c']) + let b = bufnr('%') + wincmd w + call assert_equal(1, deletebufline(b, 4)) + call assert_equal(0, deletebufline(b, 1)) + call assert_equal(['b', 'c'], getbufline(b, 1, 2)) + exe "bwipe! " . b +endfunc diff --git a/src/testdir/test_bufwintabinfo.vim b/src/testdir/test_bufwintabinfo.vim new file mode 100644 index 0000000..0e8c7d1 --- /dev/null +++ b/src/testdir/test_bufwintabinfo.vim @@ -0,0 +1,141 @@ +" Tests for the getbufinfo(), getwininfo() and gettabinfo() functions + +function Test_getbufwintabinfo() + edit Xtestfile1 + edit Xtestfile2 + let buflist = getbufinfo() + call assert_equal(2, len(buflist)) + call assert_match('Xtestfile1', buflist[0].name) + call assert_match('Xtestfile2', getbufinfo('Xtestfile2')[0].name) + call assert_equal([], getbufinfo(2016)) + edit Xtestfile1 + hide edit Xtestfile2 + hide enew + call assert_equal(3, len(getbufinfo({'bufloaded':1}))) + + set tabstop&vim + let b:editor = 'vim' + let l = getbufinfo('%') + call assert_equal(bufnr('%'), l[0].bufnr) + call assert_equal('vim', l[0].variables.editor) + call assert_notequal(-1, index(l[0].windows, bufwinid('%'))) + + " Test for getbufinfo() with 'bufmodified' + call assert_equal(0, len(getbufinfo({'bufmodified' : 1}))) + call setbufline('Xtestfile1', 1, ["Line1"]) + let l = getbufinfo({'bufmodified' : 1}) + call assert_equal(1, len(l)) + call assert_equal(bufnr('Xtestfile1'), l[0].bufnr) + + if has('signs') + call append(0, ['Linux', 'Windows', 'Mac']) + sign define Mark text=>> texthl=Search + exe "sign place 2 line=3 name=Mark buffer=" . bufnr('%') + let l = getbufinfo('%') + call assert_equal(2, l[0].signs[0].id) + call assert_equal(3, l[0].signs[0].lnum) + call assert_equal('Mark', l[0].signs[0].name) + sign unplace * + sign undefine Mark + enew! + endif + + only + let w1_id = win_getid() + new + let w2_id = win_getid() + tabnew | let w3_id = win_getid() + new | let w4_id = win_getid() + vert new | let w5_id = win_getid() + call setwinvar(0, 'signal', 'green') + tabfirst + let winlist = getwininfo() + call assert_equal(5, len(winlist)) + call assert_equal(winwidth(1), winlist[0].width) + call assert_equal(1, winlist[0].wincol) + " tabline adds one row in terminal, not in GUI + let tablineheight = winlist[0].winrow == 2 ? 1 : 0 + call assert_equal(tablineheight + 1, winlist[0].winrow) + + call assert_equal(winbufnr(2), winlist[1].bufnr) + call assert_equal(winheight(2), winlist[1].height) + call assert_equal(1, winlist[1].wincol) + call assert_equal(tablineheight + winheight(1) + 2, winlist[1].winrow) + + call assert_equal(1, winlist[2].winnr) + call assert_equal(tablineheight + 1, winlist[2].winrow) + call assert_equal(1, winlist[2].wincol) + + call assert_equal(winlist[2].width + 2, winlist[3].wincol) + call assert_equal(1, winlist[4].wincol) + + call assert_equal(1, winlist[0].tabnr) + call assert_equal(1, winlist[1].tabnr) + call assert_equal(2, winlist[2].tabnr) + call assert_equal(2, winlist[3].tabnr) + call assert_equal(2, winlist[4].tabnr) + + call assert_equal('green', winlist[2].variables.signal) + call assert_equal(w4_id, winlist[3].winid) + let winfo = getwininfo(w5_id)[0] + call assert_equal(2, winfo.tabnr) + call assert_equal([], getwininfo(3)) + + call settabvar(1, 'space', 'build') + let tablist = gettabinfo() + call assert_equal(2, len(tablist)) + call assert_equal(3, len(tablist[1].windows)) + call assert_equal(2, tablist[1].tabnr) + call assert_equal('build', tablist[0].variables.space) + call assert_equal(w2_id, tablist[0].windows[0]) + call assert_equal([], gettabinfo(3)) + + tabonly | only + + lexpr '' + lopen + copen + let winlist = getwininfo() + call assert_false(winlist[0].quickfix) + call assert_false(winlist[0].loclist) + call assert_true(winlist[1].quickfix) + call assert_true(winlist[1].loclist) + call assert_true(winlist[2].quickfix) + call assert_false(winlist[2].loclist) + wincmd t | only +endfunction + +function Test_get_buf_options() + let opts = getbufvar(bufnr('%'), '&') + call assert_equal(v:t_dict, type(opts)) + call assert_equal(8, opts.tabstop) +endfunc + +function Test_get_win_options() + if has('folding') + set foldlevel=999 + endif + set list + let opts = getwinvar(1, '&') + call assert_equal(v:t_dict, type(opts)) + call assert_equal(0, opts.linebreak) + call assert_equal(1, opts.list) + if has('folding') + call assert_equal(999, opts.foldlevel) + endif + if has('signs') + call assert_equal('auto', opts.signcolumn) + endif + + let opts = gettabwinvar(1, 1, '&') + call assert_equal(v:t_dict, type(opts)) + call assert_equal(0, opts.linebreak) + call assert_equal(1, opts.list) + if has('signs') + call assert_equal('auto', opts.signcolumn) + endif + set list& + if has('folding') + set foldlevel=0 + endif +endfunc diff --git a/src/testdir/test_cd.vim b/src/testdir/test_cd.vim new file mode 100644 index 0000000..c63f006 --- /dev/null +++ b/src/testdir/test_cd.vim @@ -0,0 +1,67 @@ +" Test for :cd + +func Test_cd_large_path() + " This used to crash with a heap write overflow. + call assert_fails('cd ' . repeat('x', 5000), 'E472:') +endfunc + +func Test_cd_up_and_down() + let path = getcwd() + cd .. + call assert_notequal(path, getcwd()) + exe 'cd ' . path + call assert_equal(path, getcwd()) +endfunc + +func Test_cd_no_arg() + if has('unix') + " Test that cd without argument goes to $HOME directory on Unix systems. + let path = getcwd() + cd + call assert_equal($HOME, getcwd()) + call assert_notequal(path, getcwd()) + exe 'cd ' . path + call assert_equal(path, getcwd()) + else + " Test that cd without argument echoes cwd on non-Unix systems. + call assert_match(getcwd(), execute('cd')) + endif +endfunc + +func Test_cd_minus() + " Test the :cd - goes back to the previous directory. + let path = getcwd() + cd .. + let path_dotdot = getcwd() + call assert_notequal(path, path_dotdot) + cd - + call assert_equal(path, getcwd()) + cd - + call assert_equal(path_dotdot, getcwd()) + cd - + call assert_equal(path, getcwd()) +endfunc + +func Test_cd_with_cpo_chdir() + e Xfoo + call setline(1, 'foo') + let path = getcwd() + set cpo+=. + + " :cd should fail when buffer is modified and 'cpo' contains dot. + call assert_fails('cd ..', 'E747:') + call assert_equal(path, getcwd()) + + " :cd with exclamation mark should succeed. + cd! .. + call assert_notequal(path, getcwd()) + + " :cd should succeed when buffer has been written. + w! + exe 'cd ' . path + call assert_equal(path, getcwd()) + + call delete('Xfoo') + set cpo& + bw! +endfunc diff --git a/src/testdir/test_cdo.vim b/src/testdir/test_cdo.vim new file mode 100644 index 0000000..988de1d --- /dev/null +++ b/src/testdir/test_cdo.vim @@ -0,0 +1,205 @@ +" Tests for the :cdo, :cfdo, :ldo and :lfdo commands + +if !has('quickfix') + finish +endif + +" Create the files used by the tests +function SetUp() + call writefile(["Line1", "Line2", "Line3"], 'Xtestfile1') + call writefile(["Line1", "Line2", "Line3"], 'Xtestfile2') + call writefile(["Line1", "Line2", "Line3"], 'Xtestfile3') +endfunction + +" Remove the files used by the tests +function TearDown() + call delete('Xtestfile1') + call delete('Xtestfile2') + call delete('Xtestfile3') +endfunction + +" Returns the current line in '<filename> <linenum>L <column>C' format +function GetRuler() + return expand('%') . ' ' . line('.') . 'L' . ' ' . col('.') . 'C' +endfunction + +" Tests for the :cdo and :ldo commands +function XdoTests(cchar) + enew + + " Shortcuts for calling the cdo and ldo commands + let Xdo = a:cchar . 'do' + let Xgetexpr = a:cchar . 'getexpr' + let Xprev = a:cchar. 'prev' + let XdoCmd = Xdo . ' call add(l, GetRuler())' + + " Try with an empty list + let l = [] + exe XdoCmd + call assert_equal([], l) + + " Populate the list and then try + exe Xgetexpr . " ['non-error 1', 'Xtestfile1:1:3:Line1', 'non-error 2', 'Xtestfile2:2:2:Line2', 'non-error 3', 'Xtestfile3:3:1:Line3']" + + let l = [] + exe XdoCmd + call assert_equal(['Xtestfile1 1L 3C', 'Xtestfile2 2L 2C', 'Xtestfile3 3L 1C'], l) + + " Run command only on selected error lines + let l = [] + enew + exe "2,3" . XdoCmd + call assert_equal(['Xtestfile2 2L 2C', 'Xtestfile3 3L 1C'], l) + + " Boundary condition tests + let l = [] + enew + exe "1,1" . XdoCmd + call assert_equal(['Xtestfile1 1L 3C'], l) + + let l = [] + enew + exe "3" . XdoCmd + call assert_equal(['Xtestfile3 3L 1C'], l) + + " Range test commands + let l = [] + enew + exe "%" . XdoCmd + call assert_equal(['Xtestfile1 1L 3C', 'Xtestfile2 2L 2C', 'Xtestfile3 3L 1C'], l) + + let l = [] + enew + exe "1,$" . XdoCmd + call assert_equal(['Xtestfile1 1L 3C', 'Xtestfile2 2L 2C', 'Xtestfile3 3L 1C'], l) + + let l = [] + enew + exe Xprev + exe "." . XdoCmd + call assert_equal(['Xtestfile2 2L 2C'], l) + + let l = [] + enew + exe "+" . XdoCmd + call assert_equal(['Xtestfile3 3L 1C'], l) + + " Invalid error lines test + let l = [] + enew + exe "silent! 27" . XdoCmd + exe "silent! 4,5" . XdoCmd + call assert_equal([], l) + + " Run commands from an unsaved buffer + let v:errmsg='' + let l = [] + enew + setlocal modified + exe "silent! 2,2" . XdoCmd + if v:errmsg !~# 'No write since last change' + call add(v:errors, 'Unsaved file change test failed') + endif + + " If the executed command fails, then the operation should be aborted + enew! + let subst_count = 0 + exe "silent!" . Xdo . " s/Line/xLine/ | let subst_count += 1" + if subst_count != 1 || getline('.') != 'xLine1' + call add(v:errors, 'Abort command on error test failed') + endif + + let l = [] + exe "2,2" . Xdo . "! call add(l, GetRuler())" + call assert_equal(['Xtestfile2 2L 2C'], l) + + " List with no valid error entries + let l = [] + edit! +2 Xtestfile1 + exe Xgetexpr . " ['non-error 1', 'non-error 2', 'non-error 3']" + exe XdoCmd + call assert_equal([], l) + exe "silent! 2" . XdoCmd + call assert_equal([], l) + let v:errmsg='' + exe "%" . XdoCmd + exe "1,$" . XdoCmd + exe "." . XdoCmd + call assert_equal('', v:errmsg) + + " List with only one valid entry + let l = [] + exe Xgetexpr . " ['Xtestfile3:3:1:Line3']" + exe XdoCmd + call assert_equal(['Xtestfile3 3L 1C'], l) + +endfunction + +" Tests for the :cfdo and :lfdo commands +function XfdoTests(cchar) + enew + + " Shortcuts for calling the cfdo and lfdo commands + let Xfdo = a:cchar . 'fdo' + let Xgetexpr = a:cchar . 'getexpr' + let XfdoCmd = Xfdo . ' call add(l, GetRuler())' + let Xpfile = a:cchar. 'pfile' + + " Clear the quickfix/location list + exe Xgetexpr . " []" + + " Try with an empty list + let l = [] + exe XfdoCmd + call assert_equal([], l) + + " Populate the list and then try + exe Xgetexpr . " ['non-error 1', 'Xtestfile1:1:3:Line1', 'Xtestfile1:2:1:Line2', 'non-error 2', 'Xtestfile2:2:2:Line2', 'non-error 3', 'Xtestfile3:2:3:Line2', 'Xtestfile3:3:1:Line3']" + + let l = [] + exe XfdoCmd + call assert_equal(['Xtestfile1 1L 3C', 'Xtestfile2 2L 2C', 'Xtestfile3 2L 3C'], l) + + " Run command only on selected error lines + let l = [] + exe "2,3" . XfdoCmd + call assert_equal(['Xtestfile2 2L 2C', 'Xtestfile3 2L 3C'], l) + + " Boundary condition tests + let l = [] + exe "3" . XfdoCmd + call assert_equal(['Xtestfile3 2L 3C'], l) + + " Range test commands + let l = [] + exe "%" . XfdoCmd + call assert_equal(['Xtestfile1 1L 3C', 'Xtestfile2 2L 2C', 'Xtestfile3 2L 3C'], l) + + let l = [] + exe "1,$" . XfdoCmd + call assert_equal(['Xtestfile1 1L 3C', 'Xtestfile2 2L 2C', 'Xtestfile3 2L 3C'], l) + + let l = [] + exe Xpfile + exe "." . XfdoCmd + call assert_equal(['Xtestfile2 2L 2C'], l) + + " List with only one valid entry + let l = [] + exe Xgetexpr . " ['Xtestfile2:2:5:Line2']" + exe XfdoCmd + call assert_equal(['Xtestfile2 2L 5C'], l) + +endfunction + +" Tests for cdo and cfdo +function Test_cdo() + call XdoTests('c') + call XfdoTests('c') +endfunction + +" Tests for ldo and lfdo +function Test_ldo() + call XdoTests('l') + call XfdoTests('l') +endfunction diff --git a/src/testdir/test_changedtick.vim b/src/testdir/test_changedtick.vim new file mode 100644 index 0000000..3a91bb5 --- /dev/null +++ b/src/testdir/test_changedtick.vim @@ -0,0 +1,57 @@ +" Tests for b:changedtick + +func Test_changedtick_increments() + new + " New buffer has an empty line, tick starts at 2. + let expected = 2 + call assert_equal(expected, b:changedtick) + call assert_equal(expected, b:['changedtick']) + call setline(1, 'hello') + let expected += 1 + call assert_equal(expected, b:changedtick) + call assert_equal(expected, b:['changedtick']) + undo + " Somehow undo counts as two changes. + let expected += 2 + call assert_equal(expected, b:changedtick) + call assert_equal(expected, b:['changedtick']) + bwipe! +endfunc + +func Test_changedtick_dict_entry() + let d = b: + call assert_equal(b:changedtick, d['changedtick']) +endfunc + +func Test_changedtick_bdel() + new + let bnr = bufnr('%') + let v = b:changedtick + bdel + " Delete counts as a change too. + call assert_equal(v + 1, getbufvar(bnr, 'changedtick')) +endfunc + +func Test_changedtick_islocked() + call assert_equal(0, islocked('b:changedtick')) + let d = b: + call assert_equal(0, islocked('d.changedtick')) +endfunc + +func Test_changedtick_fixed() + call assert_fails('let b:changedtick = 4', 'E46:') + call assert_fails('let b:["changedtick"] = 4', 'E46:') + + call assert_fails('lockvar b:changedtick', 'E940:') + call assert_fails('lockvar b:["changedtick"]', 'E46:') + call assert_fails('unlockvar b:changedtick', 'E940:') + call assert_fails('unlockvar b:["changedtick"]', 'E46:') + call assert_fails('unlet b:changedtick', 'E795:') + call assert_fails('unlet b:["changedtick"]', 'E46:') + + let d = b: + call assert_fails('lockvar d["changedtick"]', 'E46:') + call assert_fails('unlockvar d["changedtick"]', 'E46:') + call assert_fails('unlet d["changedtick"]', 'E46:') + +endfunc diff --git a/src/testdir/test_changelist.vim b/src/testdir/test_changelist.vim new file mode 100644 index 0000000..dd6ea96 --- /dev/null +++ b/src/testdir/test_changelist.vim @@ -0,0 +1,48 @@ +" Tests for the changelist functionality + +" Tests for the getchangelist() function +func Test_getchangelist() + if !has("jumplist") + return + endif + + bwipe! + enew + call assert_equal([], getchangelist(10)) + call assert_equal([[], 0], getchangelist('%')) + + call writefile(['line1', 'line2', 'line3'], 'Xfile1.txt') + call writefile(['line1', 'line2', 'line3'], 'Xfile2.txt') + + edit Xfile1.txt + exe "normal 1Goline\<C-G>u1.1" + exe "normal 3Goline\<C-G>u2.1" + exe "normal 5Goline\<C-G>u3.1" + normal g; + call assert_equal([[ + \ {'lnum' : 2, 'col' : 4, 'coladd' : 0}, + \ {'lnum' : 4, 'col' : 4, 'coladd' : 0}, + \ {'lnum' : 6, 'col' : 4, 'coladd' : 0}], 2], + \ getchangelist('%')) + + hide edit Xfile2.txt + exe "normal 1GOline\<C-G>u1.0" + exe "normal 2Goline\<C-G>u2.0" + call assert_equal([[ + \ {'lnum' : 1, 'col' : 6, 'coladd' : 0}, + \ {'lnum' : 3, 'col' : 6, 'coladd' : 0}], 2], + \ getchangelist('%')) + hide enew + + call assert_equal([[ + \ {'lnum' : 2, 'col' : 4, 'coladd' : 0}, + \ {'lnum' : 4, 'col' : 4, 'coladd' : 0}, + \ {'lnum' : 6, 'col' : 4, 'coladd' : 0}], 3], getchangelist(2)) + call assert_equal([[ + \ {'lnum' : 1, 'col' : 6, 'coladd' : 0}, + \ {'lnum' : 3, 'col' : 6, 'coladd' : 0}], 2], getchangelist(3)) + + bwipe! + call delete('Xfile1.txt') + call delete('Xfile2.txt') +endfunc diff --git a/src/testdir/test_channel.py b/src/testdir/test_channel.py new file mode 100644 index 0000000..bafa9db --- /dev/null +++ b/src/testdir/test_channel.py @@ -0,0 +1,269 @@ +#!/usr/bin/python +# +# Server that will accept connections from a Vim channel. +# Used by test_channel.vim. +# +# This requires Python 2.6 or later. + +from __future__ import print_function +import json +import socket +import sys +import time +import threading + +try: + # Python 3 + import socketserver +except ImportError: + # Python 2 + import SocketServer as socketserver + +class ThreadedTCPRequestHandler(socketserver.BaseRequestHandler): + + def handle(self): + print("=== socket opened ===") + while True: + try: + received = self.request.recv(4096).decode('utf-8') + except socket.error: + print("=== socket error ===") + break + except IOError: + print("=== socket closed ===") + break + if received == '': + print("=== socket closed ===") + break + print("received: {0}".format(received)) + + # We may receive two messages at once. Take the part up to the + # newline, which should be after the matching "]". + todo = received + while todo != '': + splitidx = todo.find('\n') + if splitidx < 0: + used = todo + todo = '' + else: + used = todo[:splitidx] + todo = todo[splitidx + 1:] + if used != received: + print("using: {0}".format(used)) + + try: + decoded = json.loads(used) + except ValueError: + print("json decoding failed") + decoded = [-1, ''] + + # Send a response if the sequence number is positive. + if decoded[0] >= 0: + if decoded[1] == 'hello!': + # simply send back a string + response = "got it" + elif decoded[1] == 'malformed1': + cmd = '["ex",":"]wrong!["ex","smi"]' + print("sending: {0}".format(cmd)) + self.request.sendall(cmd.encode('utf-8')) + response = "ok" + # Need to wait for Vim to give up, otherwise it + # sometimes fails on OS X. + time.sleep(0.2) + elif decoded[1] == 'malformed2': + cmd = '"unterminated string' + print("sending: {0}".format(cmd)) + self.request.sendall(cmd.encode('utf-8')) + response = "ok" + # Need to wait for Vim to give up, otherwise the double + # quote in the "ok" response terminates the string. + time.sleep(0.2) + elif decoded[1] == 'malformed3': + cmd = '["ex","missing ]"' + print("sending: {0}".format(cmd)) + self.request.sendall(cmd.encode('utf-8')) + response = "ok" + # Need to wait for Vim to give up, otherwise the ] + # in the "ok" response terminates the list. + time.sleep(0.2) + elif decoded[1] == 'split': + cmd = '["ex","let ' + print("sending: {0}".format(cmd)) + self.request.sendall(cmd.encode('utf-8')) + time.sleep(0.01) + cmd = 'g:split = 123"]' + print("sending: {0}".format(cmd)) + self.request.sendall(cmd.encode('utf-8')) + response = "ok" + elif decoded[1].startswith("echo "): + # send back the argument + response = decoded[1][5:] + elif decoded[1] == 'make change': + # Send two ex commands at the same time, before + # replying to the request. + cmd = '["ex","call append(\\"$\\",\\"added1\\")"]' + cmd += '["ex","call append(\\"$\\",\\"added2\\")"]' + print("sending: {0}".format(cmd)) + self.request.sendall(cmd.encode('utf-8')) + response = "ok" + elif decoded[1] == 'bad command': + cmd = '["ex","foo bar"]' + print("sending: {0}".format(cmd)) + self.request.sendall(cmd.encode('utf-8')) + response = "ok" + elif decoded[1] == 'do normal': + # Send a normal command. + cmd = '["normal","G$s more\u001b"]' + print("sending: {0}".format(cmd)) + self.request.sendall(cmd.encode('utf-8')) + response = "ok" + elif decoded[1] == 'eval-works': + # Send an eval request. We ignore the response. + cmd = '["expr","\\"foo\\" . 123", -1]' + print("sending: {0}".format(cmd)) + self.request.sendall(cmd.encode('utf-8')) + response = "ok" + elif decoded[1] == 'eval-special': + # Send an eval request. We ignore the response. + cmd = '["expr","\\"foo\x7f\x10\x01bar\\"", -2]' + print("sending: {0}".format(cmd)) + self.request.sendall(cmd.encode('utf-8')) + response = "ok" + elif decoded[1] == 'eval-getline': + # Send an eval request. We ignore the response. + cmd = '["expr","getline(3)", -3]' + print("sending: {0}".format(cmd)) + self.request.sendall(cmd.encode('utf-8')) + response = "ok" + elif decoded[1] == 'eval-fails': + # Send an eval request that will fail. + cmd = '["expr","xxx", -4]' + print("sending: {0}".format(cmd)) + self.request.sendall(cmd.encode('utf-8')) + response = "ok" + elif decoded[1] == 'eval-error': + # Send an eval request that works but the result can't + # be encoded. + cmd = '["expr","function(\\"tr\\")", -5]' + print("sending: {0}".format(cmd)) + self.request.sendall(cmd.encode('utf-8')) + response = "ok" + elif decoded[1] == 'eval-bad': + # Send an eval request missing the third argument. + cmd = '["expr","xxx"]' + print("sending: {0}".format(cmd)) + self.request.sendall(cmd.encode('utf-8')) + response = "ok" + elif decoded[1] == 'an expr': + # Send an expr request. + cmd = '["expr","setline(\\"$\\", [\\"one\\",\\"two\\",\\"three\\"])"]' + print("sending: {0}".format(cmd)) + self.request.sendall(cmd.encode('utf-8')) + response = "ok" + elif decoded[1] == 'call-func': + cmd = '["call","MyFunction",[1,2,3], 0]' + print("sending: {0}".format(cmd)) + self.request.sendall(cmd.encode('utf-8')) + response = "ok" + elif decoded[1] == 'redraw': + cmd = '["redraw",""]' + print("sending: {0}".format(cmd)) + self.request.sendall(cmd.encode('utf-8')) + response = "ok" + elif decoded[1] == 'redraw!': + cmd = '["redraw","force"]' + print("sending: {0}".format(cmd)) + self.request.sendall(cmd.encode('utf-8')) + response = "ok" + elif decoded[1] == 'empty-request': + cmd = '[]' + print("sending: {0}".format(cmd)) + self.request.sendall(cmd.encode('utf-8')) + response = "ok" + elif decoded[1] == 'eval-result': + # Send back the last received eval result. + response = last_eval + elif decoded[1] == 'call me': + cmd = '[0,"we called you"]' + print("sending: {0}".format(cmd)) + self.request.sendall(cmd.encode('utf-8')) + response = "ok" + elif decoded[1] == 'call me again': + cmd = '[0,"we did call you"]' + print("sending: {0}".format(cmd)) + self.request.sendall(cmd.encode('utf-8')) + response = "" + elif decoded[1] == 'send zero': + cmd = '[0,"zero index"]' + print("sending: {0}".format(cmd)) + self.request.sendall(cmd.encode('utf-8')) + response = "sent zero" + elif decoded[1] == 'close me': + print("closing") + self.request.close() + response = "" + elif decoded[1] == 'wait a bit': + time.sleep(0.2) + response = "waited" + elif decoded[1] == '!quit!': + # we're done + self.server.shutdown() + return + elif decoded[1] == '!crash!': + # Crash! + 42 / 0 + else: + response = "what?" + + if response == "": + print("no response") + else: + encoded = json.dumps([decoded[0], response]) + print("sending: {0}".format(encoded)) + self.request.sendall(encoded.encode('utf-8')) + + # Negative numbers are used for "eval" responses. + elif decoded[0] < 0: + last_eval = decoded + +class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer): + pass + +def writePortInFile(port): + # Write the port number in Xportnr, so that the test knows it. + f = open("Xportnr", "w") + f.write("{0}".format(port)) + f.close() + +if __name__ == "__main__": + HOST, PORT = "localhost", 0 + + # Wait half a second before opening the port to test waittime in ch_open(). + # We do want to get the port number, get that first. We cannot open the + # socket, guess a port is free. + if len(sys.argv) >= 2 and sys.argv[1] == 'delay': + PORT = 13684 + writePortInFile(PORT) + + print("Wait for it...") + time.sleep(0.5) + + server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler) + ip, port = server.server_address + + # Start a thread with the server. That thread will then start a new thread + # for each connection. + server_thread = threading.Thread(target=server.serve_forever) + server_thread.start() + + writePortInFile(port) + + print("Listening on port {0}".format(port)) + + # Main thread terminates, but the server continues running + # until server.shutdown() is called. + try: + while server_thread.isAlive(): + server_thread.join(1) + except (KeyboardInterrupt, SystemExit): + server.shutdown() diff --git a/src/testdir/test_channel.vim b/src/testdir/test_channel.vim new file mode 100644 index 0000000..2aef3e1 --- /dev/null +++ b/src/testdir/test_channel.vim @@ -0,0 +1,2028 @@ +" Test for channel functions. + +if !has('channel') + finish +endif + +source shared.vim + +let s:python = PythonProg() +if s:python == '' + " Can't run this test without Python. + finish +endif + +" Uncomment the next line to see what happens. Output is in +" src/testdir/channellog. +" call ch_logfile('channellog', 'w') + +let s:chopt = {} + +" Run "testfunc" after sarting the server and stop the server afterwards. +func s:run_server(testfunc, ...) + call RunServer('test_channel.py', a:testfunc, a:000) +endfunc + +" Return a list of open files. +" Can be used to make sure no resources leaked. +" Returns an empty list on systems where this is not supported. +func s:get_resources() + let pid = getpid() + + if executable('lsof') + return systemlist('lsof -p ' . pid . ' | awk ''$4~/^[0-9]*[rwu]$/&&$5=="REG"{print$NF}''') + elseif isdirectory('/proc/' . pid . '/fd/') + return systemlist('readlink /proc/' . pid . '/fd/* | grep -v ''^/dev/''') + else + return [] + endif +endfunc + +let g:Ch_responseMsg = '' +func Ch_requestHandler(handle, msg) + let g:Ch_responseHandle = a:handle + let g:Ch_responseMsg = a:msg +endfunc + +func Ch_communicate(port) + " Avoid dropping messages, since we don't use a callback here. + let s:chopt.drop = 'never' + " Also add the noblock flag to try it out. + let s:chopt.noblock = 1 + let handle = ch_open('localhost:' . a:port, s:chopt) + unlet s:chopt.drop + unlet s:chopt.noblock + if ch_status(handle) == "fail" + call assert_report("Can't open channel") + return + endif + if has('job') + " check that getjob without a job is handled correctly + call assert_equal('no process', string(ch_getjob(handle))) + endif + let dict = ch_info(handle) + call assert_true(dict.id != 0) + call assert_equal('open', dict.status) + call assert_equal(a:port, string(dict.port)) + call assert_equal('open', dict.sock_status) + call assert_equal('socket', dict.sock_io) + + " Simple string request and reply. + call assert_equal('got it', ch_evalexpr(handle, 'hello!')) + + " Malformed command should be ignored. + call assert_equal('ok', ch_evalexpr(handle, 'malformed1')) + call assert_equal('ok', ch_evalexpr(handle, 'malformed2')) + call assert_equal('ok', ch_evalexpr(handle, 'malformed3')) + + " split command should work + call assert_equal('ok', ch_evalexpr(handle, 'split')) + call WaitFor('exists("g:split")') + call assert_equal(123, g:split) + + " string with ][ should work + call assert_equal('this][that', ch_evalexpr(handle, 'echo this][that')) + + " nothing to read now + call assert_equal(0, ch_canread(handle)) + + " sending three messages quickly then reading should work + for i in range(3) + call ch_sendexpr(handle, 'echo hello ' . i) + endfor + call assert_equal('hello 0', ch_read(handle)[1]) + call assert_equal('hello 1', ch_read(handle)[1]) + call assert_equal('hello 2', ch_read(handle)[1]) + + " Request that triggers sending two ex commands. These will usually be + " handled before getting the response, but it's not guaranteed, thus wait a + " tiny bit for the commands to get executed. + call assert_equal('ok', ch_evalexpr(handle, 'make change')) + call WaitForAssert({-> assert_equal("added2", getline("$"))}) + call assert_equal('added1', getline(line('$') - 1)) + + " Request command "foo bar", which fails silently. + call assert_equal('ok', ch_evalexpr(handle, 'bad command')) + call WaitForAssert({-> assert_match("E492:.*foo bar", v:errmsg)}) + + call assert_equal('ok', ch_evalexpr(handle, 'do normal', {'timeout': 100})) + call WaitForAssert({-> assert_equal('added more', getline('$'))}) + + " Send a request with a specific handler. + call ch_sendexpr(handle, 'hello!', {'callback': 'Ch_requestHandler'}) + call WaitFor('exists("g:Ch_responseHandle")') + if !exists('g:Ch_responseHandle') + call assert_report('g:Ch_responseHandle was not set') + else + call assert_equal(handle, g:Ch_responseHandle) + unlet g:Ch_responseHandle + endif + call assert_equal('got it', g:Ch_responseMsg) + + let g:Ch_responseMsg = '' + call ch_sendexpr(handle, 'hello!', {'callback': function('Ch_requestHandler')}) + call WaitFor('exists("g:Ch_responseHandle")') + if !exists('g:Ch_responseHandle') + call assert_report('g:Ch_responseHandle was not set') + else + call assert_equal(handle, g:Ch_responseHandle) + unlet g:Ch_responseHandle + endif + call assert_equal('got it', g:Ch_responseMsg) + + " Using lambda. + let g:Ch_responseMsg = '' + call ch_sendexpr(handle, 'hello!', {'callback': {a, b -> Ch_requestHandler(a, b)}}) + call WaitFor('exists("g:Ch_responseHandle")') + if !exists('g:Ch_responseHandle') + call assert_report('g:Ch_responseHandle was not set') + else + call assert_equal(handle, g:Ch_responseHandle) + unlet g:Ch_responseHandle + endif + call assert_equal('got it', g:Ch_responseMsg) + + " Collect garbage, tests that our handle isn't collected. + call test_garbagecollect_now() + + " check setting options (without testing the effect) + call ch_setoptions(handle, {'callback': 's:NotUsed'}) + call ch_setoptions(handle, {'timeout': 1111}) + call ch_setoptions(handle, {'mode': 'json'}) + call assert_fails("call ch_setoptions(handle, {'waittime': 111})", "E475") + call ch_setoptions(handle, {'callback': ''}) + call ch_setoptions(handle, {'drop': 'never'}) + call ch_setoptions(handle, {'drop': 'auto'}) + call assert_fails("call ch_setoptions(handle, {'drop': 'bad'})", "E475") + + " Send an eval request that works. + call assert_equal('ok', ch_evalexpr(handle, 'eval-works')) + sleep 10m + call assert_equal([-1, 'foo123'], ch_evalexpr(handle, 'eval-result')) + + " Send an eval request with special characters. + call assert_equal('ok', ch_evalexpr(handle, 'eval-special')) + sleep 10m + call assert_equal([-2, "foo\x7f\x10\x01bar"], ch_evalexpr(handle, 'eval-result')) + + " Send an eval request to get a line with special characters. + call setline(3, "a\nb\<CR>c\x01d\x7fe") + call assert_equal('ok', ch_evalexpr(handle, 'eval-getline')) + sleep 10m + call assert_equal([-3, "a\nb\<CR>c\x01d\x7fe"], ch_evalexpr(handle, 'eval-result')) + + " Send an eval request that fails. + call assert_equal('ok', ch_evalexpr(handle, 'eval-fails')) + sleep 10m + call assert_equal([-4, 'ERROR'], ch_evalexpr(handle, 'eval-result')) + + " Send an eval request that works but can't be encoded. + call assert_equal('ok', ch_evalexpr(handle, 'eval-error')) + sleep 10m + call assert_equal([-5, 'ERROR'], ch_evalexpr(handle, 'eval-result')) + + " Send a bad eval request. There will be no response. + call assert_equal('ok', ch_evalexpr(handle, 'eval-bad')) + sleep 10m + call assert_equal([-5, 'ERROR'], ch_evalexpr(handle, 'eval-result')) + + " Send an expr request + call assert_equal('ok', ch_evalexpr(handle, 'an expr')) + call WaitForAssert({-> assert_equal('three', getline('$'))}) + call assert_equal('one', getline(line('$') - 2)) + call assert_equal('two', getline(line('$') - 1)) + + " Request a redraw, we don't check for the effect. + call assert_equal('ok', ch_evalexpr(handle, 'redraw')) + call assert_equal('ok', ch_evalexpr(handle, 'redraw!')) + + call assert_equal('ok', ch_evalexpr(handle, 'empty-request')) + + " Reading while there is nothing available. + call assert_equal(v:none, ch_read(handle, {'timeout': 0})) + let start = reltime() + call assert_equal(v:none, ch_read(handle, {'timeout': 333})) + let elapsed = reltime(start) + call assert_true(reltimefloat(elapsed) > 0.3) + call assert_true(reltimefloat(elapsed) < 0.6) + + " Send without waiting for a response, then wait for a response. + call ch_sendexpr(handle, 'wait a bit') + let resp = ch_read(handle) + call assert_equal(type([]), type(resp)) + call assert_equal(type(11), type(resp[0])) + call assert_equal('waited', resp[1]) + + " make the server quit, can't check if this works, should not hang. + call ch_sendexpr(handle, '!quit!') +endfunc + +func Test_communicate() + call ch_log('Test_communicate()') + call s:run_server('Ch_communicate') +endfunc + +" Test that we can open two channels. +func Ch_two_channels(port) + let handle = ch_open('localhost:' . a:port, s:chopt) + call assert_equal(v:t_channel, type(handle)) + if ch_status(handle) == "fail" + call assert_report("Can't open channel") + return + endif + + call assert_equal('got it', ch_evalexpr(handle, 'hello!')) + + let newhandle = ch_open('localhost:' . a:port, s:chopt) + if ch_status(newhandle) == "fail" + call assert_report("Can't open second channel") + return + endif + call assert_equal('got it', ch_evalexpr(newhandle, 'hello!')) + call assert_equal('got it', ch_evalexpr(handle, 'hello!')) + + call ch_close(handle) + call assert_equal('got it', ch_evalexpr(newhandle, 'hello!')) + + call ch_close(newhandle) +endfunc + +func Test_two_channels() + call ch_log('Test_two_channels()') + call s:run_server('Ch_two_channels') +endfunc + +" Test that a server crash is handled gracefully. +func Ch_server_crash(port) + let handle = ch_open('localhost:' . a:port, s:chopt) + if ch_status(handle) == "fail" + call assert_report("Can't open channel") + return + endif + + call ch_evalexpr(handle, '!crash!') + + sleep 10m +endfunc + +func Test_server_crash() + call ch_log('Test_server_crash()') + call s:run_server('Ch_server_crash') +endfunc + +""""""""" + +func Ch_handler(chan, msg) + call ch_log('Ch_handler()') + unlet g:Ch_reply + let g:Ch_reply = a:msg +endfunc + +func Ch_channel_handler(port) + let handle = ch_open('localhost:' . a:port, s:chopt) + if ch_status(handle) == "fail" + call assert_report("Can't open channel") + return + endif + + " Test that it works while waiting on a numbered message. + call assert_equal('ok', ch_evalexpr(handle, 'call me')) + call WaitForAssert({-> assert_equal('we called you', g:Ch_reply)}) + + " Test that it works while not waiting on a numbered message. + call ch_sendexpr(handle, 'call me again') + call WaitForAssert({-> assert_equal('we did call you', g:Ch_reply)}) +endfunc + +func Test_channel_handler() + call ch_log('Test_channel_handler()') + let g:Ch_reply = "" + let s:chopt.callback = 'Ch_handler' + call s:run_server('Ch_channel_handler') + let g:Ch_reply = "" + let s:chopt.callback = function('Ch_handler') + call s:run_server('Ch_channel_handler') + unlet s:chopt.callback +endfunc + +""""""""" + +let g:Ch_reply = '' +func Ch_zeroHandler(chan, msg) + unlet g:Ch_reply + let g:Ch_reply = a:msg +endfunc + +let g:Ch_zero_reply = '' +func Ch_oneHandler(chan, msg) + unlet g:Ch_zero_reply + let g:Ch_zero_reply = a:msg +endfunc + +func Ch_channel_zero(port) + let handle = ch_open('localhost:' . a:port, s:chopt) + if ch_status(handle) == "fail" + call assert_report("Can't open channel") + return + endif + + " Check that eval works. + call assert_equal('got it', ch_evalexpr(handle, 'hello!')) + + " Check that eval works if a zero id message is sent back. + let g:Ch_reply = '' + call assert_equal('sent zero', ch_evalexpr(handle, 'send zero')) + if s:has_handler + call WaitForAssert({-> assert_equal('zero index', g:Ch_reply)}) + else + sleep 20m + call assert_equal('', g:Ch_reply) + endif + + " Check that handler works if a zero id message is sent back. + let g:Ch_reply = '' + let g:Ch_zero_reply = '' + call ch_sendexpr(handle, 'send zero', {'callback': 'Ch_oneHandler'}) + call WaitForAssert({-> assert_equal('sent zero', g:Ch_zero_reply)}) + if s:has_handler + call assert_equal('zero index', g:Ch_reply) + else + call assert_equal('', g:Ch_reply) + endif +endfunc + +func Test_zero_reply() + call ch_log('Test_zero_reply()') + " Run with channel handler + let s:has_handler = 1 + let s:chopt.callback = 'Ch_zeroHandler' + call s:run_server('Ch_channel_zero') + unlet s:chopt.callback + + " Run without channel handler + let s:has_handler = 0 + call s:run_server('Ch_channel_zero') +endfunc + +""""""""" + +let g:Ch_reply1 = "" +func Ch_handleRaw1(chan, msg) + unlet g:Ch_reply1 + let g:Ch_reply1 = a:msg +endfunc + +let g:Ch_reply2 = "" +func Ch_handleRaw2(chan, msg) + unlet g:Ch_reply2 + let g:Ch_reply2 = a:msg +endfunc + +let g:Ch_reply3 = "" +func Ch_handleRaw3(chan, msg) + unlet g:Ch_reply3 + let g:Ch_reply3 = a:msg +endfunc + +func Ch_raw_one_time_callback(port) + let handle = ch_open('localhost:' . a:port, s:chopt) + if ch_status(handle) == "fail" + call assert_report("Can't open channel") + return + endif + call ch_setoptions(handle, {'mode': 'raw'}) + + " The messages are sent raw, we do our own JSON strings here. + call ch_sendraw(handle, "[1, \"hello!\"]\n", {'callback': 'Ch_handleRaw1'}) + call WaitForAssert({-> assert_equal("[1, \"got it\"]", g:Ch_reply1)}) + call ch_sendraw(handle, "[2, \"echo something\"]\n", {'callback': 'Ch_handleRaw2'}) + call ch_sendraw(handle, "[3, \"wait a bit\"]\n", {'callback': 'Ch_handleRaw3'}) + call WaitForAssert({-> assert_equal("[2, \"something\"]", g:Ch_reply2)}) + " wait for the 200 msec delayed reply + call WaitForAssert({-> assert_equal("[3, \"waited\"]", g:Ch_reply3)}) +endfunc + +func Test_raw_one_time_callback() + call ch_log('Test_raw_one_time_callback()') + call s:run_server('Ch_raw_one_time_callback') +endfunc + +""""""""" + +" Test that trying to connect to a non-existing port fails quickly. +func Test_connect_waittime() + call ch_log('Test_connect_waittime()') + let start = reltime() + let handle = ch_open('localhost:9876', s:chopt) + if ch_status(handle) != "fail" + " Oops, port does exists. + call ch_close(handle) + else + let elapsed = reltime(start) + call assert_true(reltimefloat(elapsed) < 1.0) + endif + + " We intend to use a socket that doesn't exist and wait for half a second + " before giving up. If the socket does exist it can fail in various ways. + " Check for "Connection reset by peer" to avoid flakyness. + let start = reltime() + try + let handle = ch_open('localhost:9867', {'waittime': 500}) + if ch_status(handle) != "fail" + " Oops, port does exists. + call ch_close(handle) + else + " Failed connection should wait about 500 msec. Can be longer if the + " computer is busy with other things. + let elapsed = reltime(start) + call assert_true(reltimefloat(elapsed) > 0.3) + call assert_true(reltimefloat(elapsed) < 1.5) + endif + catch + if v:exception !~ 'Connection reset by peer' + call assert_report("Caught exception: " . v:exception) + endif + endtry +endfunc + +""""""""" + +func Test_raw_pipe() + if !has('job') + return + endif + call ch_log('Test_raw_pipe()') + " Add a dummy close callback to avoid that messages are dropped when calling + " ch_canread(). + " Also test the non-blocking option. + let job = job_start(s:python . " test_channel_pipe.py", + \ {'mode': 'raw', 'drop': 'never', 'noblock': 1}) + call assert_equal(v:t_job, type(job)) + call assert_equal("run", job_status(job)) + + call assert_equal("open", ch_status(job)) + call assert_equal("open", ch_status(job), {"part": "out"}) + call assert_equal("open", ch_status(job), {"part": "err"}) + call assert_fails('call ch_status(job, {"in_mode": "raw"})', 'E475:') + call assert_fails('call ch_status(job, {"part": "in"})', 'E475:') + + let dict = ch_info(job) + call assert_true(dict.id != 0) + call assert_equal('open', dict.status) + call assert_equal('open', dict.out_status) + call assert_equal('RAW', dict.out_mode) + call assert_equal('pipe', dict.out_io) + call assert_equal('open', dict.err_status) + call assert_equal('RAW', dict.err_mode) + call assert_equal('pipe', dict.err_io) + + try + " For a change use the job where a channel is expected. + call ch_sendraw(job, "echo something\n") + let msg = ch_readraw(job) + call assert_equal("something\n", substitute(msg, "\r", "", 'g')) + + call ch_sendraw(job, "double this\n") + let g:handle = job_getchannel(job) + call WaitFor('ch_canread(g:handle)') + unlet g:handle + let msg = ch_readraw(job) + call assert_equal("this\nAND this\n", substitute(msg, "\r", "", 'g')) + + let g:Ch_reply = "" + call ch_sendraw(job, "double this\n", {'callback': 'Ch_handler'}) + call WaitForAssert({-> assert_equal("this\nAND this\n", substitute(g:Ch_reply, "\r", "", 'g'))}) + + let reply = ch_evalraw(job, "quit\n", {'timeout': 100}) + call assert_equal("Goodbye!\n", substitute(reply, "\r", "", 'g')) + finally + call job_stop(job) + endtry + + let g:Ch_job = job + call WaitForAssert({-> assert_equal("dead", job_status(g:Ch_job))}) + let info = job_info(job) + call assert_equal("dead", info.status) + call assert_equal("term", info.stoponexit) + call assert_equal(2, len(info.cmd)) + call assert_equal("test_channel_pipe.py", info.cmd[1]) + + let found = 0 + for j in job_info() + if j == job + let found += 1 + endif + endfor + call assert_equal(1, found) +endfunc + +func Test_raw_pipe_blob() + if !has('job') + return + endif + call ch_log('Test_raw_pipe_blob()') + " Add a dummy close callback to avoid that messages are dropped when calling + " ch_canread(). + " Also test the non-blocking option. + let job = job_start(s:python . " test_channel_pipe.py", + \ {'mode': 'raw', 'drop': 'never', 'noblock': 1}) + call assert_equal(v:t_job, type(job)) + call assert_equal("run", job_status(job)) + + call assert_equal("open", ch_status(job)) + call assert_equal("open", ch_status(job), {"part": "out"}) + + try + " Create a blob with the echo command and write it. + let blob = 0z00 + let cmd = "echo something\n" + for i in range(0, len(cmd) - 1) + let blob[i] = char2nr(cmd[i]) + endfor + call assert_equal(len(cmd), len(blob)) + call ch_sendraw(job, blob) + + " Read a blob with the reply. + let msg = ch_readblob(job) + let expected = 'something' + for i in range(0, len(expected) - 1) + call assert_equal(char2nr(expected[i]), msg[i]) + endfor + + let reply = ch_evalraw(job, "quit\n", {'timeout': 100}) + call assert_equal("Goodbye!\n", substitute(reply, "\r", "", 'g')) + finally + call job_stop(job) + endtry + + let g:Ch_job = job + call WaitForAssert({-> assert_equal("dead", job_status(g:Ch_job))}) + let info = job_info(job) + call assert_equal("dead", info.status) +endfunc + +func Test_nl_pipe() + if !has('job') + return + endif + call ch_log('Test_nl_pipe()') + let job = job_start([s:python, "test_channel_pipe.py"]) + call assert_equal("run", job_status(job)) + try + let handle = job_getchannel(job) + call ch_sendraw(handle, "echo something\n") + call assert_equal("something", ch_readraw(handle)) + + call ch_sendraw(handle, "echoerr wrong\n") + call assert_equal("wrong", ch_readraw(handle, {'part': 'err'})) + + call ch_sendraw(handle, "double this\n") + call assert_equal("this", ch_readraw(handle)) + call assert_equal("AND this", ch_readraw(handle)) + + call ch_sendraw(handle, "split this line\n") + call assert_equal("this linethis linethis line", ch_read(handle)) + + let reply = ch_evalraw(handle, "quit\n") + call assert_equal("Goodbye!", reply) + finally + call job_stop(job) + endtry +endfunc + +func Test_nl_err_to_out_pipe() + if !has('job') + return + endif + call ch_logfile('Xlog') + call ch_log('Test_nl_err_to_out_pipe()') + let job = job_start(s:python . " test_channel_pipe.py", {'err_io': 'out'}) + call assert_equal("run", job_status(job)) + try + let handle = job_getchannel(job) + call ch_sendraw(handle, "echo something\n") + call assert_equal("something", ch_readraw(handle)) + + call ch_sendraw(handle, "echoerr wrong\n") + call assert_equal("wrong", ch_readraw(handle)) + finally + call job_stop(job) + call ch_logfile('') + let loglines = readfile('Xlog') + call assert_true(len(loglines) > 10) + let found_test = 0 + let found_send = 0 + let found_recv = 0 + let found_stop = 0 + for l in loglines + if l =~ 'Test_nl_err_to_out_pipe' + let found_test = 1 + endif + if l =~ 'SEND on.*echo something' + let found_send = 1 + endif + if l =~ 'RECV on.*something' + let found_recv = 1 + endif + if l =~ 'Stopping job with' + let found_stop = 1 + endif + endfor + call assert_equal(1, found_test) + call assert_equal(1, found_send) + call assert_equal(1, found_recv) + call assert_equal(1, found_stop) + " On MS-Windows need to sleep for a moment to be able to delete the file. + sleep 10m + call delete('Xlog') + endtry +endfunc + +func Stop_g_job() + call job_stop(g:job) + if has('win32') + " On MS-Windows the server must close the file handle before we are able + " to delete the file. + call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) + sleep 10m + endif +endfunc + +func Test_nl_read_file() + if !has('job') + return + endif + call ch_log('Test_nl_read_file()') + call writefile(['echo something', 'echoerr wrong', 'double this'], 'Xinput') + let g:job = job_start(s:python . " test_channel_pipe.py", + \ {'in_io': 'file', 'in_name': 'Xinput'}) + call assert_equal("run", job_status(g:job)) + try + let handle = job_getchannel(g:job) + call assert_equal("something", ch_readraw(handle)) + call assert_equal("wrong", ch_readraw(handle, {'part': 'err'})) + call assert_equal("this", ch_readraw(handle)) + call assert_equal("AND this", ch_readraw(handle)) + finally + call Stop_g_job() + call delete('Xinput') + endtry +endfunc + +func Test_nl_write_out_file() + if !has('job') + return + endif + call ch_log('Test_nl_write_out_file()') + let g:job = job_start(s:python . " test_channel_pipe.py", + \ {'out_io': 'file', 'out_name': 'Xoutput'}) + call assert_equal("run", job_status(g:job)) + try + let handle = job_getchannel(g:job) + call ch_sendraw(handle, "echo line one\n") + call ch_sendraw(handle, "echo line two\n") + call ch_sendraw(handle, "double this\n") + call WaitForAssert({-> assert_equal(['line one', 'line two', 'this', 'AND this'], readfile('Xoutput'))}) + finally + call Stop_g_job() + call assert_equal(-1, match(s:get_resources(), '\(^\|/\)Xoutput$')) + call delete('Xoutput') + endtry +endfunc + +func Test_nl_write_err_file() + if !has('job') + return + endif + call ch_log('Test_nl_write_err_file()') + let g:job = job_start(s:python . " test_channel_pipe.py", + \ {'err_io': 'file', 'err_name': 'Xoutput'}) + call assert_equal("run", job_status(g:job)) + try + let handle = job_getchannel(g:job) + call ch_sendraw(handle, "echoerr line one\n") + call ch_sendraw(handle, "echoerr line two\n") + call ch_sendraw(handle, "doubleerr this\n") + call WaitForAssert({-> assert_equal(['line one', 'line two', 'this', 'AND this'], readfile('Xoutput'))}) + finally + call Stop_g_job() + call delete('Xoutput') + endtry +endfunc + +func Test_nl_write_both_file() + if !has('job') + return + endif + call ch_log('Test_nl_write_both_file()') + let g:job = job_start(s:python . " test_channel_pipe.py", + \ {'out_io': 'file', 'out_name': 'Xoutput', 'err_io': 'out'}) + call assert_equal("run", job_status(g:job)) + try + let handle = job_getchannel(g:job) + call ch_sendraw(handle, "echoerr line one\n") + call ch_sendraw(handle, "echo line two\n") + call ch_sendraw(handle, "double this\n") + call ch_sendraw(handle, "doubleerr that\n") + call WaitForAssert({-> assert_equal(['line one', 'line two', 'this', 'AND this', 'that', 'AND that'], readfile('Xoutput'))}) + finally + call Stop_g_job() + call assert_equal(-1, match(s:get_resources(), '\(^\|/\)Xoutput$')) + call delete('Xoutput') + endtry +endfunc + +func BufCloseCb(ch) + let g:Ch_bufClosed = 'yes' +endfunc + +func Run_test_pipe_to_buffer(use_name, nomod, do_msg) + if !has('job') + return + endif + call ch_log('Test_pipe_to_buffer()') + let g:Ch_bufClosed = 'no' + let options = {'out_io': 'buffer', 'close_cb': 'BufCloseCb'} + let expected = ['', 'line one', 'line two', 'this', 'AND this', 'Goodbye!'] + if a:use_name + let options['out_name'] = 'pipe-output' + if a:do_msg + let expected[0] = 'Reading from channel output...' + else + let options['out_msg'] = 0 + call remove(expected, 0) + endif + else + sp pipe-output + let options['out_buf'] = bufnr('%') + quit + call remove(expected, 0) + endif + if a:nomod + let options['out_modifiable'] = 0 + endif + let job = job_start(s:python . " test_channel_pipe.py", options) + call assert_equal("run", job_status(job)) + try + let handle = job_getchannel(job) + call ch_sendraw(handle, "echo line one\n") + call ch_sendraw(handle, "echo line two\n") + call ch_sendraw(handle, "double this\n") + call ch_sendraw(handle, "quit\n") + sp pipe-output + call WaitFor('line("$") == ' . len(expected) . ' && g:Ch_bufClosed == "yes"') + call assert_equal(expected, getline(1, '$')) + if a:nomod + call assert_equal(0, &modifiable) + else + call assert_equal(1, &modifiable) + endif + call assert_equal('yes', g:Ch_bufClosed) + bwipe! + finally + call job_stop(job) + endtry +endfunc + +func Test_pipe_to_buffer_name() + call Run_test_pipe_to_buffer(1, 0, 1) +endfunc + +func Test_pipe_to_buffer_nr() + call Run_test_pipe_to_buffer(0, 0, 1) +endfunc + +func Test_pipe_to_buffer_name_nomod() + call Run_test_pipe_to_buffer(1, 1, 1) +endfunc + +func Test_pipe_to_buffer_name_nomsg() + call Run_test_pipe_to_buffer(1, 0, 1) +endfunc + +func Test_close_output_buffer() + if !has('job') + return + endif + enew! + let test_lines = ['one', 'two'] + call setline(1, test_lines) + call ch_log('Test_close_output_buffer()') + let options = {'out_io': 'buffer'} + let options['out_name'] = 'buffer-output' + let options['out_msg'] = 0 + split buffer-output + let job = job_start(s:python . " test_channel_write.py", options) + call assert_equal("run", job_status(job)) + try + call WaitForAssert({-> assert_equal(3, line('$'))}) + quit! + sleep 100m + " Make sure the write didn't happen to the wrong buffer. + call assert_equal(test_lines, getline(1, line('$'))) + call assert_equal(-1, bufwinnr('buffer-output')) + sbuf buffer-output + call assert_notequal(-1, bufwinnr('buffer-output')) + sleep 100m + close " no more writes + bwipe! + finally + call job_stop(job) + endtry +endfunc + +func Run_test_pipe_err_to_buffer(use_name, nomod, do_msg) + if !has('job') + return + endif + call ch_log('Test_pipe_err_to_buffer()') + let options = {'err_io': 'buffer'} + let expected = ['', 'line one', 'line two', 'this', 'AND this'] + if a:use_name + let options['err_name'] = 'pipe-err' + if a:do_msg + let expected[0] = 'Reading from channel error...' + else + let options['err_msg'] = 0 + call remove(expected, 0) + endif + else + sp pipe-err + let options['err_buf'] = bufnr('%') + quit + call remove(expected, 0) + endif + if a:nomod + let options['err_modifiable'] = 0 + endif + let job = job_start(s:python . " test_channel_pipe.py", options) + call assert_equal("run", job_status(job)) + try + let handle = job_getchannel(job) + call ch_sendraw(handle, "echoerr line one\n") + call ch_sendraw(handle, "echoerr line two\n") + call ch_sendraw(handle, "doubleerr this\n") + call ch_sendraw(handle, "quit\n") + sp pipe-err + call WaitForAssert({-> assert_equal(expected, getline(1, '$'))}) + if a:nomod + call assert_equal(0, &modifiable) + else + call assert_equal(1, &modifiable) + endif + bwipe! + finally + call job_stop(job) + endtry +endfunc + +func Test_pipe_err_to_buffer_name() + call Run_test_pipe_err_to_buffer(1, 0, 1) +endfunc + +func Test_pipe_err_to_buffer_nr() + call Run_test_pipe_err_to_buffer(0, 0, 1) +endfunc + +func Test_pipe_err_to_buffer_name_nomod() + call Run_test_pipe_err_to_buffer(1, 1, 1) +endfunc + +func Test_pipe_err_to_buffer_name_nomsg() + call Run_test_pipe_err_to_buffer(1, 0, 0) +endfunc + +func Test_pipe_both_to_buffer() + if !has('job') + return + endif + call ch_log('Test_pipe_both_to_buffer()') + let job = job_start(s:python . " test_channel_pipe.py", + \ {'out_io': 'buffer', 'out_name': 'pipe-err', 'err_io': 'out'}) + call assert_equal("run", job_status(job)) + try + let handle = job_getchannel(job) + call ch_sendraw(handle, "echo line one\n") + call ch_sendraw(handle, "echoerr line two\n") + call ch_sendraw(handle, "double this\n") + call ch_sendraw(handle, "doubleerr that\n") + call ch_sendraw(handle, "quit\n") + sp pipe-err + call WaitForAssert({-> assert_equal(['Reading from channel output...', 'line one', 'line two', 'this', 'AND this', 'that', 'AND that', 'Goodbye!'], getline(1, '$'))}) + bwipe! + finally + call job_stop(job) + endtry +endfunc + +func Run_test_pipe_from_buffer(use_name) + if !has('job') + return + endif + call ch_log('Test_pipe_from_buffer()') + + sp pipe-input + call setline(1, ['echo one', 'echo two', 'echo three']) + let options = {'in_io': 'buffer', 'block_write': 1} + if a:use_name + let options['in_name'] = 'pipe-input' + else + let options['in_buf'] = bufnr('%') + endif + + let job = job_start(s:python . " test_channel_pipe.py", options) + call assert_equal("run", job_status(job)) + try + let handle = job_getchannel(job) + call assert_equal('one', ch_read(handle)) + call assert_equal('two', ch_read(handle)) + call assert_equal('three', ch_read(handle)) + bwipe! + finally + call job_stop(job) + endtry +endfunc + +func Test_pipe_from_buffer_name() + call Run_test_pipe_from_buffer(1) +endfunc + +func Test_pipe_from_buffer_nr() + call Run_test_pipe_from_buffer(0) +endfunc + +func Run_pipe_through_sort(all, use_buffer) + if !executable('sort') || !has('job') + return + endif + let options = {'out_io': 'buffer', 'out_name': 'sortout'} + if a:use_buffer + split sortin + call setline(1, ['ccc', 'aaa', 'ddd', 'bbb', 'eee']) + let options.in_io = 'buffer' + let options.in_name = 'sortin' + endif + if !a:all + let options.in_top = 2 + let options.in_bot = 4 + endif + let job = job_start('sort', options) + + if !a:use_buffer + call assert_equal("run", job_status(job)) + call ch_sendraw(job, "ccc\naaa\nddd\nbbb\neee\n") + call ch_close_in(job) + endif + + call WaitForAssert({-> assert_equal("dead", job_status(job))}) + + sp sortout + call WaitFor('line("$") > 3') + call assert_equal('Reading from channel output...', getline(1)) + if a:all + call assert_equal(['aaa', 'bbb', 'ccc', 'ddd', 'eee'], getline(2, 6)) + else + call assert_equal(['aaa', 'bbb', 'ddd'], getline(2, 4)) + endif + + call job_stop(job) + if a:use_buffer + bwipe! sortin + endif + bwipe! sortout +endfunc + +func Test_pipe_through_sort_all() + call ch_log('Test_pipe_through_sort_all()') + call Run_pipe_through_sort(1, 1) +endfunc + +func Test_pipe_through_sort_some() + call ch_log('Test_pipe_through_sort_some()') + call Run_pipe_through_sort(0, 1) +endfunc + +func Test_pipe_through_sort_feed() + call ch_log('Test_pipe_through_sort_feed()') + call Run_pipe_through_sort(1, 0) +endfunc + +func Test_pipe_to_nameless_buffer() + if !has('job') + return + endif + call ch_log('Test_pipe_to_nameless_buffer()') + let job = job_start(s:python . " test_channel_pipe.py", + \ {'out_io': 'buffer'}) + call assert_equal("run", job_status(job)) + try + let handle = job_getchannel(job) + call ch_sendraw(handle, "echo line one\n") + call ch_sendraw(handle, "echo line two\n") + exe ch_getbufnr(handle, "out") . 'sbuf' + call WaitFor('line("$") >= 3') + call assert_equal(['Reading from channel output...', 'line one', 'line two'], getline(1, '$')) + bwipe! + finally + call job_stop(job) + endtry +endfunc + +func Test_pipe_to_buffer_json() + if !has('job') + return + endif + call ch_log('Test_pipe_to_buffer_json()') + let job = job_start(s:python . " test_channel_pipe.py", + \ {'out_io': 'buffer', 'out_mode': 'json'}) + call assert_equal("run", job_status(job)) + try + let handle = job_getchannel(job) + call ch_sendraw(handle, "echo [0, \"hello\"]\n") + call ch_sendraw(handle, "echo [-2, 12.34]\n") + exe ch_getbufnr(handle, "out") . 'sbuf' + call WaitFor('line("$") >= 3') + call assert_equal(['Reading from channel output...', '[0,"hello"]', '[-2,12.34]'], getline(1, '$')) + bwipe! + finally + call job_stop(job) + endtry +endfunc + +" Wait a little while for the last line, minus "offset", to equal "line". +func s:wait_for_last_line(line, offset) + for i in range(100) + if getline(line('$') - a:offset) == a:line + break + endif + sleep 10m + endfor +endfunc + +func Test_pipe_io_two_buffers() + if !has('job') + return + endif + call ch_log('Test_pipe_io_two_buffers()') + + " Create two buffers, one to read from and one to write to. + split pipe-output + set buftype=nofile + split pipe-input + set buftype=nofile + + let job = job_start(s:python . " test_channel_pipe.py", + \ {'in_io': 'buffer', 'in_name': 'pipe-input', 'in_top': 0, + \ 'out_io': 'buffer', 'out_name': 'pipe-output', + \ 'block_write': 1}) + call assert_equal("run", job_status(job)) + try + exe "normal Gaecho hello\<CR>" + exe bufwinnr('pipe-output') . "wincmd w" + call s:wait_for_last_line('hello', 0) + call assert_equal('hello', getline('$')) + + exe bufwinnr('pipe-input') . "wincmd w" + exe "normal Gadouble this\<CR>" + exe bufwinnr('pipe-output') . "wincmd w" + call s:wait_for_last_line('AND this', 0) + call assert_equal('this', getline(line('$') - 1)) + call assert_equal('AND this', getline('$')) + + bwipe! + exe bufwinnr('pipe-input') . "wincmd w" + bwipe! + finally + call job_stop(job) + endtry +endfunc + +func Test_pipe_io_one_buffer() + if !has('job') + return + endif + call ch_log('Test_pipe_io_one_buffer()') + + " Create one buffer to read from and to write to. + split pipe-io + set buftype=nofile + + let job = job_start(s:python . " test_channel_pipe.py", + \ {'in_io': 'buffer', 'in_name': 'pipe-io', 'in_top': 0, + \ 'out_io': 'buffer', 'out_name': 'pipe-io', + \ 'block_write': 1}) + call assert_equal("run", job_status(job)) + try + exe "normal Goecho hello\<CR>" + call s:wait_for_last_line('hello', 1) + call assert_equal('hello', getline(line('$') - 1)) + + exe "normal Gadouble this\<CR>" + call s:wait_for_last_line('AND this', 1) + call assert_equal('this', getline(line('$') - 2)) + call assert_equal('AND this', getline(line('$') - 1)) + + bwipe! + finally + call job_stop(job) + endtry +endfunc + +func Test_pipe_null() + if !has('job') + return + endif + call ch_log('Test_pipe_null()') + + " We cannot check that no I/O works, we only check that the job starts + " properly. + let job = job_start(s:python . " test_channel_pipe.py something", + \ {'in_io': 'null'}) + call assert_equal("run", job_status(job)) + try + call assert_equal('something', ch_read(job)) + finally + call job_stop(job) + endtry + + let job = job_start(s:python . " test_channel_pipe.py err-out", + \ {'out_io': 'null'}) + call assert_equal("run", job_status(job)) + try + call assert_equal('err-out', ch_read(job, {"part": "err"})) + finally + call job_stop(job) + endtry + + let job = job_start(s:python . " test_channel_pipe.py something", + \ {'err_io': 'null'}) + call assert_equal("run", job_status(job)) + try + call assert_equal('something', ch_read(job)) + finally + call job_stop(job) + endtry + + let job = job_start(s:python . " test_channel_pipe.py something", + \ {'out_io': 'null', 'err_io': 'out'}) + call assert_equal("run", job_status(job)) + call job_stop(job) + + let job = job_start(s:python . " test_channel_pipe.py something", + \ {'in_io': 'null', 'out_io': 'null', 'err_io': 'null'}) + call assert_equal("run", job_status(job)) + call assert_equal('channel fail', string(job_getchannel(job))) + call assert_equal('fail', ch_status(job)) + call job_stop(job) +endfunc + +func Test_pipe_to_buffer_raw() + if !has('job') + return + endif + call ch_log('Test_raw_pipe_to_buffer()') + let options = {'out_mode': 'raw', 'out_io': 'buffer', 'out_name': 'testout'} + split testout + let job = job_start([s:python, '-c', + \ 'import sys; [sys.stdout.write(".") and sys.stdout.flush() for _ in range(10000)]'], options) + " the job may be done quickly, also accept "dead" + call assert_match('^\%(dead\|run\)$', job_status(job)) + call WaitFor('len(join(getline(1, "$"), "")) >= 10000') + try + let totlen = 0 + for line in getline(1, '$') + call assert_equal('', substitute(line, '^\.*', '', '')) + let totlen += len(line) + endfor + call assert_equal(10000, totlen) + finally + call job_stop(job) + bwipe! + endtry +endfunc + +func Test_reuse_channel() + if !has('job') + return + endif + call ch_log('Test_reuse_channel()') + + let job = job_start(s:python . " test_channel_pipe.py") + call assert_equal("run", job_status(job)) + let handle = job_getchannel(job) + try + call ch_sendraw(handle, "echo something\n") + call assert_equal("something", ch_readraw(handle)) + finally + call job_stop(job) + endtry + + let job = job_start(s:python . " test_channel_pipe.py", {'channel': handle}) + call assert_equal("run", job_status(job)) + let handle = job_getchannel(job) + try + call ch_sendraw(handle, "echo again\n") + call assert_equal("again", ch_readraw(handle)) + finally + call job_stop(job) + endtry +endfunc + +func Test_out_cb() + if !has('job') + return + endif + call ch_log('Test_out_cb()') + + let dict = {'thisis': 'dict: '} + func dict.outHandler(chan, msg) dict + if type(a:msg) == v:t_string + let g:Ch_outmsg = self.thisis . a:msg + else + let g:Ch_outobj = a:msg + endif + endfunc + func dict.errHandler(chan, msg) dict + let g:Ch_errmsg = self.thisis . a:msg + endfunc + let job = job_start(s:python . " test_channel_pipe.py", + \ {'out_cb': dict.outHandler, + \ 'out_mode': 'json', + \ 'err_cb': dict.errHandler, + \ 'err_mode': 'json'}) + call assert_equal("run", job_status(job)) + try + let g:Ch_outmsg = '' + let g:Ch_errmsg = '' + call ch_sendraw(job, "echo [0, \"hello\"]\n") + call ch_sendraw(job, "echoerr [0, \"there\"]\n") + call WaitForAssert({-> assert_equal("dict: hello", g:Ch_outmsg)}) + call WaitForAssert({-> assert_equal("dict: there", g:Ch_errmsg)}) + + " Receive a json object split in pieces + unlet! g:Ch_outobj + call ch_sendraw(job, "echosplit [0, {\"one\": 1,| \"tw|o\": 2, \"three\": 3|}]\n") + let g:Ch_outobj = '' + call WaitForAssert({-> assert_equal({'one': 1, 'two': 2, 'three': 3}, g:Ch_outobj)}) + finally + call job_stop(job) + endtry +endfunc + +func Test_out_close_cb() + if !has('job') + return + endif + call ch_log('Test_out_close_cb()') + + let s:counter = 1 + let g:Ch_msg1 = '' + let g:Ch_closemsg = 0 + func! OutHandler(chan, msg) + if s:counter == 1 + let g:Ch_msg1 = a:msg + endif + let s:counter += 1 + endfunc + func! CloseHandler(chan) + let g:Ch_closemsg = s:counter + let s:counter += 1 + endfunc + let job = job_start(s:python . " test_channel_pipe.py quit now", + \ {'out_cb': 'OutHandler', + \ 'close_cb': 'CloseHandler'}) + " the job may be done quickly, also accept "dead" + call assert_match('^\%(dead\|run\)$', job_status(job)) + try + call WaitForAssert({-> assert_equal('quit', g:Ch_msg1)}) + call WaitForAssert({-> assert_equal(2, g:Ch_closemsg)}) + finally + call job_stop(job) + delfunc OutHandler + delfunc CloseHandler + endtry +endfunc + +func Test_read_in_close_cb() + if !has('job') + return + endif + call ch_log('Test_read_in_close_cb()') + + let g:Ch_received = '' + func! CloseHandler(chan) + let g:Ch_received = ch_read(a:chan) + endfunc + let job = job_start(s:python . " test_channel_pipe.py quit now", + \ {'close_cb': 'CloseHandler'}) + " the job may be done quickly, also accept "dead" + call assert_match('^\%(dead\|run\)$', job_status(job)) + try + call WaitForAssert({-> assert_equal('quit', g:Ch_received)}) + finally + call job_stop(job) + delfunc CloseHandler + endtry +endfunc + +" Use channel in NL mode but received text does not end in NL. +func Test_read_in_close_cb_incomplete() + if !has('job') + return + endif + call ch_log('Test_read_in_close_cb_incomplete()') + + let g:Ch_received = '' + func! CloseHandler(chan) + while ch_status(a:chan, {'part': 'out'}) == 'buffered' + let g:Ch_received .= ch_read(a:chan) + endwhile + endfunc + let job = job_start(s:python . " test_channel_pipe.py incomplete", + \ {'close_cb': 'CloseHandler'}) + " the job may be done quickly, also accept "dead" + call assert_match('^\%(dead\|run\)$', job_status(job)) + try + call WaitForAssert({-> assert_equal('incomplete', g:Ch_received)}) + finally + call job_stop(job) + delfunc CloseHandler + endtry +endfunc + +func Test_out_cb_lambda() + if !has('job') + return + endif + call ch_log('Test_out_cb_lambda()') + + let job = job_start(s:python . " test_channel_pipe.py", + \ {'out_cb': {ch, msg -> execute("let g:Ch_outmsg = 'lambda: ' . msg")}, + \ 'out_mode': 'json', + \ 'err_cb': {ch, msg -> execute(":let g:Ch_errmsg = 'lambda: ' . msg")}, + \ 'err_mode': 'json'}) + call assert_equal("run", job_status(job)) + try + let g:Ch_outmsg = '' + let g:Ch_errmsg = '' + call ch_sendraw(job, "echo [0, \"hello\"]\n") + call ch_sendraw(job, "echoerr [0, \"there\"]\n") + call WaitForAssert({-> assert_equal("lambda: hello", g:Ch_outmsg)}) + call WaitForAssert({-> assert_equal("lambda: there", g:Ch_errmsg)}) + finally + call job_stop(job) + endtry +endfunc + +func Test_close_and_exit_cb() + if !has('job') + return + endif + call ch_log('Test_close_and_exit_cb') + + let g:retdict = {'ret': {}} + func g:retdict.close_cb(ch) dict + let self.ret['close_cb'] = job_status(ch_getjob(a:ch)) + endfunc + func g:retdict.exit_cb(job, status) dict + let self.ret['exit_cb'] = job_status(a:job) + endfunc + + let job = job_start([&shell, &shellcmdflag, 'echo'], + \ {'close_cb': g:retdict.close_cb, + \ 'exit_cb': g:retdict.exit_cb}) + " the job may be done quickly, also accept "dead" + call assert_match('^\%(dead\|run\)$', job_status(job)) + call WaitForAssert({-> assert_equal(2, len(g:retdict.ret))}) + call assert_match('^\%(dead\|run\)$', g:retdict.ret['close_cb']) + call assert_equal('dead', g:retdict.ret['exit_cb']) + unlet g:retdict +endfunc + +"""""""""" + +function ExitCbWipe(job, status) + exe g:wipe_buf 'bw!' +endfunction + +" This caused a crash, because messages were handled while peeking for a +" character. +func Test_exit_cb_wipes_buf() + if !has('timers') + return + endif + set cursorline lazyredraw + call test_override('redraw_flag', 1) + new + let g:wipe_buf = bufnr('') + + let job = job_start(has('win32') ? 'cmd /c echo:' : ['true'], + \ {'exit_cb': 'ExitCbWipe'}) + let timer = timer_start(300, {-> feedkeys("\<Esc>", 'nt')}, {'repeat': 5}) + call feedkeys(repeat('g', 1000) . 'o', 'ntx!') + call WaitForAssert({-> assert_equal("dead", job_status(job))}) + call timer_stop(timer) + + set nocursorline nolazyredraw + unlet g:wipe_buf + call test_override('ALL', 0) +endfunc + +"""""""""" + +let g:Ch_unletResponse = '' +func s:UnletHandler(handle, msg) + let g:Ch_unletResponse = a:msg + unlet s:channelfd +endfunc + +" Test that "unlet handle" in a handler doesn't crash Vim. +func Ch_unlet_handle(port) + let s:channelfd = ch_open('localhost:' . a:port, s:chopt) + call ch_sendexpr(s:channelfd, "test", {'callback': function('s:UnletHandler')}) + call WaitForAssert({-> assert_equal('what?', g:Ch_unletResponse)}) +endfunc + +func Test_unlet_handle() + call ch_log('Test_unlet_handle()') + call s:run_server('Ch_unlet_handle') +endfunc + +"""""""""" + +let g:Ch_unletResponse = '' +func Ch_CloseHandler(handle, msg) + let g:Ch_unletResponse = a:msg + call ch_close(s:channelfd) +endfunc + +" Test that "unlet handle" in a handler doesn't crash Vim. +func Ch_close_handle(port) + let s:channelfd = ch_open('localhost:' . a:port, s:chopt) + call ch_sendexpr(s:channelfd, "test", {'callback': function('Ch_CloseHandler')}) + call WaitForAssert({-> assert_equal('what?', g:Ch_unletResponse)}) +endfunc + +func Test_close_handle() + call ch_log('Test_close_handle()') + call s:run_server('Ch_close_handle') +endfunc + +"""""""""" + +func Test_open_fail() + call ch_log('Test_open_fail()') + silent! let ch = ch_open("noserver") + echo ch + let d = ch +endfunc + +"""""""""" + +func Ch_open_delay(port) + " Wait up to a second for the port to open. + let s:chopt.waittime = 1000 + let channel = ch_open('localhost:' . a:port, s:chopt) + unlet s:chopt.waittime + if ch_status(channel) == "fail" + call assert_report("Can't open channel") + return + endif + call assert_equal('got it', ch_evalexpr(channel, 'hello!')) + call ch_close(channel) +endfunc + +func Test_open_delay() + call ch_log('Test_open_delay()') + " The server will wait half a second before creating the port. + call s:run_server('Ch_open_delay', 'delay') +endfunc + +""""""""" + +function MyFunction(a,b,c) + let g:Ch_call_ret = [a:a, a:b, a:c] +endfunc + +function Ch_test_call(port) + let handle = ch_open('localhost:' . a:port, s:chopt) + if ch_status(handle) == "fail" + call assert_report("Can't open channel") + return + endif + + let g:Ch_call_ret = [] + call assert_equal('ok', ch_evalexpr(handle, 'call-func')) + call WaitForAssert({-> assert_equal([1, 2, 3], g:Ch_call_ret)}) +endfunc + +func Test_call() + call ch_log('Test_call()') + call s:run_server('Ch_test_call') +endfunc + +""""""""" + +let g:Ch_job_exit_ret = 'not yet' +function MyExitCb(job, status) + let g:Ch_job_exit_ret = 'done' +endfunc + +function Ch_test_exit_callback(port) + call job_setoptions(g:currentJob, {'exit_cb': 'MyExitCb'}) + let g:Ch_exit_job = g:currentJob + call assert_equal('MyExitCb', job_info(g:currentJob)['exit_cb']) +endfunc + +func Test_exit_callback() + if has('job') + call ch_log('Test_exit_callback()') + call s:run_server('Ch_test_exit_callback') + + " wait up to a second for the job to exit + for i in range(100) + if g:Ch_job_exit_ret == 'done' + break + endif + sleep 10m + " calling job_status() triggers the callback + call job_status(g:Ch_exit_job) + endfor + + call assert_equal('done', g:Ch_job_exit_ret) + call assert_equal('dead', job_info(g:Ch_exit_job).status) + unlet g:Ch_exit_job + endif +endfunc + +function MyExitTimeCb(job, status) + if job_info(a:job).process == g:exit_cb_val.process + let g:exit_cb_val.end = reltime(g:exit_cb_val.start) + endif + call Resume() +endfunction + +func Test_exit_callback_interval() + if !has('job') + return + endif + + let g:exit_cb_val = {'start': reltime(), 'end': 0, 'process': 0} + let job = job_start([s:python, '-c', 'import time;time.sleep(0.5)'], {'exit_cb': 'MyExitTimeCb'}) + let g:exit_cb_val.process = job_info(job).process + call WaitFor('type(g:exit_cb_val.end) != v:t_number || g:exit_cb_val.end != 0') + let elapsed = reltimefloat(g:exit_cb_val.end) + call assert_true(elapsed > 0.5) + call assert_true(elapsed < 1.0) + + " case: unreferenced job, using timer + if !has('timers') + return + endif + + let g:exit_cb_val = {'start': reltime(), 'end': 0, 'process': 0} + let g:job = job_start([s:python, '-c', 'import time;time.sleep(0.5)'], {'exit_cb': 'MyExitTimeCb'}) + let g:exit_cb_val.process = job_info(g:job).process + unlet g:job + call Standby(1000) + if type(g:exit_cb_val.end) != v:t_number || g:exit_cb_val.end != 0 + let elapsed = reltimefloat(g:exit_cb_val.end) + else + let elapsed = 1.0 + endif + call assert_true(elapsed > 0.5) + call assert_true(elapsed < 1.0) +endfunc + +""""""""" + +let g:Ch_close_ret = 'alive' +function MyCloseCb(ch) + let g:Ch_close_ret = 'closed' +endfunc + +function Ch_test_close_callback(port) + let handle = ch_open('localhost:' . a:port, s:chopt) + if ch_status(handle) == "fail" + call assert_report("Can't open channel") + return + endif + call ch_setoptions(handle, {'close_cb': 'MyCloseCb'}) + + call assert_equal('', ch_evalexpr(handle, 'close me')) + call WaitForAssert({-> assert_equal('closed', g:Ch_close_ret)}) +endfunc + +func Test_close_callback() + call ch_log('Test_close_callback()') + call s:run_server('Ch_test_close_callback') +endfunc + +function Ch_test_close_partial(port) + let handle = ch_open('localhost:' . a:port, s:chopt) + if ch_status(handle) == "fail" + call assert_report("Can't open channel") + return + endif + let g:Ch_d = {} + func g:Ch_d.closeCb(ch) dict + let self.close_ret = 'closed' + endfunc + call ch_setoptions(handle, {'close_cb': g:Ch_d.closeCb}) + + call assert_equal('', ch_evalexpr(handle, 'close me')) + call WaitForAssert({-> assert_equal('closed', g:Ch_d.close_ret)}) + unlet g:Ch_d +endfunc + +func Test_close_partial() + call ch_log('Test_close_partial()') + call s:run_server('Ch_test_close_partial') +endfunc + +func Test_job_start_invalid() + call assert_fails('call job_start($x)', 'E474:') + call assert_fails('call job_start("")', 'E474:') +endfunc + +func Test_job_stop_immediately() + if !has('job') + return + endif + + let g:job = job_start([s:python, '-c', 'import time;time.sleep(10)']) + try + call job_stop(g:job) + call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) + finally + call job_stop(g:job, 'kill') + unlet g:job + endtry +endfunc + +" This was leaking memory. +func Test_partial_in_channel_cycle() + let d = {} + let d.a = function('string', [d]) + try + let d.b = ch_open('nowhere:123', {'close_cb': d.a}) + catch + call assert_exception('E901:') + endtry + unlet d +endfunc + +func Test_using_freed_memory() + let g:a = job_start(['ls']) + sleep 10m + call test_garbagecollect_now() +endfunc + +func Test_collapse_buffers() + if !executable('cat') || !has('job') + return + endif + sp test_channel.vim + let g:linecount = line('$') + close + split testout + 1,$delete + call job_start('cat test_channel.vim', {'out_io': 'buffer', 'out_name': 'testout'}) + call WaitForAssert({-> assert_inrange(g:linecount, g:linecount + 1, line('$'))}) + bwipe! +endfunc + +func Test_write_to_deleted_buffer() + if !executable('echo') || !has('job') + return + endif + let job = job_start('echo hello', {'out_io': 'buffer', 'out_name': 'test_buffer', 'out_msg': 0}) + let bufnr = bufnr('test_buffer') + call WaitForAssert({-> assert_equal(['hello'], getbufline(bufnr, 1, '$'))}) + call assert_equal('nofile', getbufvar(bufnr, '&buftype')) + call assert_equal('hide', getbufvar(bufnr, '&bufhidden')) + + bdel test_buffer + call assert_equal([], getbufline(bufnr, 1, '$')) + + let job = job_start('echo hello', {'out_io': 'buffer', 'out_name': 'test_buffer', 'out_msg': 0}) + call WaitForAssert({-> assert_equal(['hello'], getbufline(bufnr, 1, '$'))}) + call assert_equal('nofile', getbufvar(bufnr, '&buftype')) + call assert_equal('hide', getbufvar(bufnr, '&bufhidden')) + + bwipe! test_buffer +endfunc + +func Test_cmd_parsing() + if !has('unix') + return + endif + call assert_false(filereadable("file with space")) + let job = job_start('touch "file with space"') + call WaitForAssert({-> assert_true(filereadable("file with space"))}) + call delete("file with space") + + let job = job_start('touch file\ with\ space') + call WaitForAssert({-> assert_true(filereadable("file with space"))}) + call delete("file with space") +endfunc + +func Test_raw_passes_nul() + if !executable('cat') || !has('job') + return + endif + + " Test lines from the job containing NUL are stored correctly in a buffer. + new + call setline(1, ["asdf\nasdf", "xxx\n", "\nyyy"]) + w! Xtestread + bwipe! + split testout + 1,$delete + call job_start('cat Xtestread', {'out_io': 'buffer', 'out_name': 'testout'}) + call WaitFor('line("$") > 2') + call assert_equal("asdf\nasdf", getline(1)) + call assert_equal("xxx\n", getline(2)) + call assert_equal("\nyyy", getline(3)) + + call delete('Xtestread') + bwipe! + + " Test lines from a buffer with NUL bytes are written correctly to the job. + new mybuffer + call setline(1, ["asdf\nasdf", "xxx\n", "\nyyy"]) + let g:Ch_job = job_start('cat', {'in_io': 'buffer', 'in_name': 'mybuffer', 'out_io': 'file', 'out_name': 'Xtestwrite'}) + call WaitForAssert({-> assert_equal("dead", job_status(g:Ch_job))}) + bwipe! + split Xtestwrite + call assert_equal("asdf\nasdf", getline(1)) + call assert_equal("xxx\n", getline(2)) + call assert_equal("\nyyy", getline(3)) + call assert_equal(-1, match(s:get_resources(), '\(^\|/\)Xtestwrite$')) + + call delete('Xtestwrite') + bwipe! +endfunc + +func MyLineCountCb(ch, msg) + let g:linecount += 1 +endfunc + +func Test_read_nonl_line() + if !has('job') + return + endif + + let g:linecount = 0 + let arg = 'import sys;sys.stdout.write("1\n2\n3")' + call job_start([s:python, '-c', arg], {'callback': 'MyLineCountCb'}) + call WaitForAssert({-> assert_equal(3, g:linecount)}) +endfunc + +func Test_read_from_terminated_job() + if !has('job') + return + endif + + let g:linecount = 0 + let arg = 'import os,sys;os.close(1);sys.stderr.write("test\n")' + call job_start([s:python, '-c', arg], {'callback': 'MyLineCountCb'}) + call WaitForAssert({-> assert_equal(1, g:linecount)}) +endfunc + +func Test_job_start_windows() + if !has('job') || !has('win32') + return + endif + + " Check that backslash in $COMSPEC is handled properly. + let g:echostr = '' + let cmd = $COMSPEC . ' /c echo 123' + let job = job_start(cmd, {'callback': {ch,msg -> execute(":let g:echostr .= msg")}}) + let info = job_info(job) + call assert_equal([$COMSPEC, '/c', 'echo', '123'], info.cmd) + + call WaitForAssert({-> assert_equal("123", g:echostr)}) + unlet g:echostr +endfunc + +func Test_env() + if !has('job') + return + endif + + let g:envstr = '' + if has('win32') + let cmd = ['cmd', '/c', 'echo %FOO%'] + else + let cmd = [&shell, &shellcmdflag, 'echo $FOO'] + endif + call assert_fails('call job_start(cmd, {"env": 1})', 'E475:') + call job_start(cmd, {'callback': {ch,msg -> execute(":let g:envstr .= msg")}, 'env': {'FOO': 'bar'}}) + call WaitForAssert({-> assert_equal("bar", g:envstr)}) + unlet g:envstr +endfunc + +func Test_cwd() + if !has('job') + return + endif + + let g:envstr = '' + if has('win32') + let expect = $TEMP + let cmd = ['cmd', '/c', 'echo %CD%'] + else + let expect = $HOME + let cmd = ['pwd'] + endif + let job = job_start(cmd, {'callback': {ch,msg -> execute(":let g:envstr .= msg")}, 'cwd': expect}) + try + call WaitForAssert({-> assert_notequal("", g:envstr)}) + let expect = substitute(expect, '[/\\]$', '', '') + let g:envstr = substitute(g:envstr, '[/\\]$', '', '') + if $CI != '' && stridx(g:envstr, '/private/') == 0 + let g:envstr = g:envstr[8:] + endif + call assert_equal(expect, g:envstr) + finally + call job_stop(job) + unlet g:envstr + endtry +endfunc + +function Ch_test_close_lambda(port) + let handle = ch_open('localhost:' . a:port, s:chopt) + if ch_status(handle) == "fail" + call assert_report("Can't open channel") + return + endif + let g:Ch_close_ret = '' + call ch_setoptions(handle, {'close_cb': {ch -> execute("let g:Ch_close_ret = 'closed'")}}) + + call assert_equal('', ch_evalexpr(handle, 'close me')) + call WaitForAssert({-> assert_equal('closed', g:Ch_close_ret)}) +endfunc + +func Test_close_lambda() + call ch_log('Test_close_lambda()') + call s:run_server('Ch_test_close_lambda') +endfunc + +func s:test_list_args(cmd, out, remove_lf) + try + let g:out = '' + let job = job_start([s:python, '-c', a:cmd], {'callback': {ch, msg -> execute('let g:out .= msg')}, 'out_mode': 'raw'}) + call WaitFor('"" != g:out') + if has('win32') + let g:out = substitute(g:out, '\r', '', 'g') + endif + if a:remove_lf + let g:out = substitute(g:out, '\n$', '', 'g') + endif + call assert_equal(a:out, g:out) + finally + call job_stop(job) + unlet g:out + endtry +endfunc + +func Test_list_args() + if !has('job') + return + endif + + call s:test_list_args('import sys;sys.stdout.write("hello world")', "hello world", 0) + call s:test_list_args('import sys;sys.stdout.write("hello\nworld")', "hello\nworld", 0) + call s:test_list_args('import sys;sys.stdout.write(''hello\nworld'')', "hello\nworld", 0) + call s:test_list_args('import sys;sys.stdout.write(''hello"world'')', "hello\"world", 0) + call s:test_list_args('import sys;sys.stdout.write(''hello^world'')', "hello^world", 0) + call s:test_list_args('import sys;sys.stdout.write("hello&&world")', "hello&&world", 0) + call s:test_list_args('import sys;sys.stdout.write(''hello\\world'')', "hello\\world", 0) + call s:test_list_args('import sys;sys.stdout.write(''hello\\\\world'')', "hello\\\\world", 0) + call s:test_list_args('import sys;sys.stdout.write("hello\"world\"")', 'hello"world"', 0) + call s:test_list_args('import sys;sys.stdout.write("h\"ello worl\"d")', 'h"ello worl"d', 0) + call s:test_list_args('import sys;sys.stdout.write("h\"e\\\"llo wor\\\"l\"d")', 'h"e\"llo wor\"l"d', 0) + call s:test_list_args('import sys;sys.stdout.write("h\"e\\\"llo world")', 'h"e\"llo world', 0) + call s:test_list_args('import sys;sys.stdout.write("hello\tworld")', "hello\tworld", 0) + + " tests which not contain spaces in the argument + call s:test_list_args('print("hello\nworld")', "hello\nworld", 1) + call s:test_list_args('print(''hello\nworld'')', "hello\nworld", 1) + call s:test_list_args('print(''hello"world'')', "hello\"world", 1) + call s:test_list_args('print(''hello^world'')', "hello^world", 1) + call s:test_list_args('print("hello&&world")', "hello&&world", 1) + call s:test_list_args('print(''hello\\world'')', "hello\\world", 1) + call s:test_list_args('print(''hello\\\\world'')', "hello\\\\world", 1) + call s:test_list_args('print("hello\"world\"")', 'hello"world"', 1) + call s:test_list_args('print("hello\tworld")', "hello\tworld", 1) +endfunc + +" Do this last, it stops any channel log. +func Test_zz_ch_log() + call ch_logfile('Xlog', 'w') + call ch_log('hello there') + call ch_log('%s%s') + call ch_logfile('') + let text = readfile('Xlog') + call assert_match("hello there", text[1]) + call assert_match("%s%s", text[2]) + call delete('Xlog') +endfunc + +func Test_keep_pty_open() + if !has('unix') + return + endif + + let job = job_start(s:python . ' -c "import time;time.sleep(0.2)"', + \ {'out_io': 'null', 'err_io': 'null', 'pty': 1}) + let elapsed = WaitFor({-> job_status(job) ==# 'dead'}) + call assert_inrange(200, 1000, elapsed) + call job_stop(job) +endfunc + +func Test_job_start_in_timer() + if !has('job') || !has('timers') + return + endif + + func OutCb(chan, msg) + let g:val += 1 + endfunc + + func ExitCb(job, status) + let g:val += 1 + call Resume() + endfunc + + func TimerCb(timer) + if has('win32') + let cmd = ['cmd', '/c', 'echo.'] + else + let cmd = ['echo'] + endif + let g:job = job_start(cmd, {'out_cb': 'OutCb', 'exit_cb': 'ExitCb'}) + call substitute(repeat('a', 100000), '.', '', 'g') + endfunc + + " We should be interrupted before 'updatetime' elapsed. + let g:val = 0 + call timer_start(1, 'TimerCb') + let elapsed = Standby(&ut) + call assert_inrange(1, &ut / 2, elapsed) + + " Wait for both OutCb() and ExitCb() to have been called before deleting + " them. + call WaitForAssert({-> assert_equal(2, g:val)}) + call job_stop(g:job) + + delfunc OutCb + delfunc ExitCb + delfunc TimerCb + unlet! g:val + unlet! g:job +endfunc + +func Test_raw_large_data() + try + let g:out = '' + let job = job_start(s:python . " test_channel_pipe.py", + \ {'mode': 'raw', 'drop': 'never', 'noblock': 1, + \ 'callback': {ch, msg -> execute('let g:out .= msg')}}) + + let outlen = 79999 + let want = repeat('X', outlen) . "\n" + call ch_sendraw(job, want) + call WaitFor({-> len(g:out) >= outlen}, 10000) + call WaitForAssert({-> assert_equal("dead", job_status(job))}) + call assert_equal(want, substitute(g:out, '\r', '', 'g')) + finally + call job_stop(job) + unlet g:out + endtry +endfunc + +func Test_job_exitval_and_termsig() + if !has('unix') + return + endif + + " Terminate job normally + let cmd = ['echo'] + let job = job_start(cmd) + call WaitForAssert({-> assert_equal("dead", job_status(job))}) + let info = job_info(job) + call assert_equal(0, info.exitval) + call assert_equal("", info.termsig) + + " Terminate job by signal + let cmd = ['sleep', '10'] + let job = job_start(cmd) + sleep 10m + call job_stop(job) + call WaitForAssert({-> assert_equal("dead", job_status(job))}) + let info = job_info(job) + call assert_equal(-1, info.exitval) + call assert_equal("term", info.termsig) +endfunc diff --git a/src/testdir/test_channel_pipe.py b/src/testdir/test_channel_pipe.py new file mode 100644 index 0000000..810a8e3 --- /dev/null +++ b/src/testdir/test_channel_pipe.py @@ -0,0 +1,63 @@ +#!/usr/bin/python +# +# Server that will communicate over stdin/stderr +# +# This requires Python 2.6 or later. + +from __future__ import print_function +import sys +import time + +if __name__ == "__main__": + + if len(sys.argv) > 1: + if sys.argv[1].startswith("err"): + print(sys.argv[1], file=sys.stderr) + sys.stderr.flush() + elif sys.argv[1].startswith("incomplete"): + print(sys.argv[1], end='') + sys.stdout.flush() + sys.exit(0) + else: + print(sys.argv[1]) + sys.stdout.flush() + if sys.argv[1].startswith("quit"): + sys.exit(0) + + while True: + typed = sys.stdin.readline() + if typed.startswith("quit"): + print("Goodbye!") + sys.stdout.flush() + break + if typed.startswith("echo "): + print(typed[5:-1]) + sys.stdout.flush() + if typed.startswith("echosplit "): + for part in typed[10:-1].split('|'): + sys.stdout.write(part) + sys.stdout.flush() + time.sleep(0.05) + if typed.startswith("double "): + print(typed[7:-1] + "\nAND " + typed[7:-1]) + sys.stdout.flush() + if typed.startswith("split "): + print(typed[6:-1], end='') + sys.stdout.flush() + time.sleep(0.05) + print(typed[6:-1], end='') + sys.stdout.flush() + time.sleep(0.05) + print(typed[6:-1]) + sys.stdout.flush() + if typed.startswith("echoerr "): + print(typed[8:-1], file=sys.stderr) + sys.stderr.flush() + if typed.startswith("doubleerr "): + print(typed[10:-1] + "\nAND " + typed[10:-1], file=sys.stderr) + sys.stderr.flush() + if typed.startswith("XXX"): + print(typed, end='') + sys.stderr.flush() + break + diff --git a/src/testdir/test_channel_write.py b/src/testdir/test_channel_write.py new file mode 100644 index 0000000..9c8813b --- /dev/null +++ b/src/testdir/test_channel_write.py @@ -0,0 +1,18 @@ +#!/usr/bin/python +# +# Program that writes a number to stdout repeatedly +# +# This requires Python 2.6 or later. + +from __future__ import print_function +import sys +import time + +if __name__ == "__main__": + + done = 0 + while done < 10: + done = done + 1 + print(done) + sys.stdout.flush() + time.sleep(0.05) # sleep 50 msec diff --git a/src/testdir/test_charsearch.vim b/src/testdir/test_charsearch.vim new file mode 100644 index 0000000..17a49e0 --- /dev/null +++ b/src/testdir/test_charsearch.vim @@ -0,0 +1,62 @@ + +func Test_charsearch() + enew! + call append(0, ['Xabcdefghijkemnopqretuvwxyz', + \ 'Yabcdefghijkemnopqretuvwxyz', + \ 'Zabcdefghijkemnokqretkvwxyz']) + " check that "fe" and ";" work + 1 + normal! ylfep;;p,,p + call assert_equal('XabcdeXfghijkeXmnopqreXtuvwxyz', getline(1)) + " check that save/restore works + 2 + normal! ylfep + let csave = getcharsearch() + normal! fip + call setcharsearch(csave) + normal! ;p;p + call assert_equal('YabcdeYfghiYjkeYmnopqreYtuvwxyz', getline(2)) + + " check that setcharsearch() changes the settings. + 3 + normal! ylfep + call setcharsearch({'char': 'k'}) + normal! ;p + call setcharsearch({'forward': 0}) + normal! $;p + call setcharsearch({'until': 1}) + set cpo-=; + normal! ;;p + call assert_equal('ZabcdeZfghijkZZemnokqretkZvwxyz', getline(3)) + enew! +endfunc + +" Test for t,f,F,T movement commands and 'cpo-;' setting +func Test_search_cmds() + enew! + call append(0, ["aaa two three four", " zzz", "yyy ", + \ "bbb yee yoo four", "ccc two three four", + \ "ddd yee yoo four"]) + set cpo-=; + 1 + normal! 0tt;D + 2 + normal! 0fz;D + 3 + normal! $Fy;D + 4 + normal! $Ty;D + set cpo+=; + 5 + normal! 0tt;;D + 6 + normal! $Ty;;D + + call assert_equal('aaa two', getline(1)) + call assert_equal(' z', getline(2)) + call assert_equal('y', getline(3)) + call assert_equal('bbb y', getline(4)) + call assert_equal('ccc', getline(5)) + call assert_equal('ddd yee y', getline(6)) + enew! +endfunc diff --git a/src/testdir/test_charsearch_utf8.vim b/src/testdir/test_charsearch_utf8.vim new file mode 100644 index 0000000..82a807a --- /dev/null +++ b/src/testdir/test_charsearch_utf8.vim @@ -0,0 +1,19 @@ +" Tests for related f{char} and t{char} using utf-8. + +" Test for t,f,F,T movement commands +func Test_search_cmds() + new! + call setline(1, "・最初から最後まで最強のVimは最高") + 1 + normal! f最 + call assert_equal([0, 1, 4, 0], getpos('.')) + normal! ; + call assert_equal([0, 1, 16, 0], getpos('.')) + normal! 2; + call assert_equal([0, 1, 43, 0], getpos('.')) + normal! , + call assert_equal([0, 1, 28, 0], getpos('.')) + bw! +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_cindent.vim b/src/testdir/test_cindent.vim new file mode 100644 index 0000000..7c2c5e3 --- /dev/null +++ b/src/testdir/test_cindent.vim @@ -0,0 +1,105 @@ +" Test for cinoptions and cindent +" +" TODO: rewrite test3.in into this new style test + +func Test_cino_hash() + " Test that curbuf->b_ind_hash_comment is correctly reset + new + setlocal cindent cinoptions=#1 + setlocal cinoptions= + call setline(1, ["#include <iostream>"]) + call cursor(1, 1) + norm! o#include + "call feedkeys("o#include\<esc>", 't') + call assert_equal(["#include <iostream>", "#include"], getline(1,2)) + bwipe! +endfunc + +func Test_cino_extern_c() + " Test for cino-E + + let without_ind = [ + \ '#ifdef __cplusplus', + \ 'extern "C" {', + \ '#endif', + \ 'int func_a(void);', + \ '#ifdef __cplusplus', + \ '}', + \ '#endif' + \ ] + + let with_ind = [ + \ '#ifdef __cplusplus', + \ 'extern "C" {', + \ '#endif', + \ "\tint func_a(void);", + \ '#ifdef __cplusplus', + \ '}', + \ '#endif' + \ ] + new + setlocal cindent cinoptions=E0 + call setline(1, without_ind) + call feedkeys("gg=G", 'tx') + call assert_equal(with_ind, getline(1, '$')) + + setlocal cinoptions=E-s + call setline(1, with_ind) + call feedkeys("gg=G", 'tx') + call assert_equal(without_ind, getline(1, '$')) + + setlocal cinoptions=Es + let tests = [ + \ ['recognized', ['extern "C" {'], "\t\t;"], + \ ['recognized', ['extern "C++" {'], "\t\t;"], + \ ['recognized', ['extern /* com */ "C"{'], "\t\t;"], + \ ['recognized', ['extern"C"{'], "\t\t;"], + \ ['recognized', ['extern "C"', '{'], "\t\t;"], + \ ['not recognized', ['extern {'], "\t;"], + \ ['not recognized', ['extern /*"C"*/{'], "\t;"], + \ ['not recognized', ['extern "C" //{'], ";"], + \ ['not recognized', ['extern "C" /*{*/'], ";"], + \ ] + + for pair in tests + let lines = pair[1] + call setline(1, lines) + call feedkeys(len(lines) . "Go;", 'tx') + call assert_equal(pair[2], getline(len(lines) + 1), 'Failed for "' . string(lines) . '"') + endfor + + bwipe! +endfunc + +func Test_cindent_rawstring() + new + setl cindent + call feedkeys("i" . + \ "int main() {\<CR>" . + \ "R\"(\<CR>" . + \ ")\";\<CR>" . + \ "statement;\<Esc>", "x") + call assert_equal("\tstatement;", getline(line('.'))) + bw! +endfunc + +func Test_cindent_expr() + new + func! MyIndentFunction() + return v:lnum == 1 ? shiftwidth() : 0 + endfunc + setl expandtab sw=8 indentkeys+=; indentexpr=MyIndentFunction() + call setline(1, ['var_a = something()', 'b = something()']) + call cursor(1, 1) + call feedkeys("^\<c-v>j$A;\<esc>", 'tnix') + call assert_equal([' var_a = something();', 'b = something();'], getline(1, '$')) + + %d + call setline(1, [' var_a = something()', ' b = something()']) + call cursor(1, 1) + call feedkeys("^\<c-v>j$A;\<esc>", 'tnix') + call assert_equal([' var_a = something();', ' b = something()'], getline(1, '$')) + bw! +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_clientserver.vim b/src/testdir/test_clientserver.vim new file mode 100644 index 0000000..5c01ac4 --- /dev/null +++ b/src/testdir/test_clientserver.vim @@ -0,0 +1,104 @@ +" Tests for the +clientserver feature. + +if !has('job') || !has('clientserver') + finish +endif + +source shared.vim + +func Test_client_server() + let cmd = GetVimCommand() + if cmd == '' + return + endif + if has('x11') + if empty($DISPLAY) + throw 'Skipped: $DISPLAY is not set' + endif + try + call remote_send('xxx', '') + catch + if v:exception =~ 'E240:' + throw 'Skipped: no connection to the X server' + endif + " ignore other errors + endtry + endif + + let name = 'XVIMTEST' + let cmd .= ' --servername ' . name + let job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'}) + call WaitForAssert({-> assert_equal("run", job_status(job))}) + + " Takes a short while for the server to be active. + " When using valgrind it takes much longer. + call WaitForAssert({-> assert_match(name, serverlist())}) + + call remote_foreground(name) + + call remote_send(name, ":let testvar = 'yes'\<CR>") + call WaitFor('remote_expr("' . name . '", "exists(\"testvar\") ? testvar : \"\"", "", 1) == "yes"') + call assert_equal('yes', remote_expr(name, "testvar", "", 2)) + + if has('unix') && has('gui') && !has('gui_running') + " Running in a terminal and the GUI is available: Tell the server to open + " the GUI and check that the remote command still works. + " Need to wait for the GUI to start up, otherwise the send hangs in trying + " to send to the terminal window. + if has('gui_athena') || has('gui_motif') + " For those GUIs, ignore the 'failed to create input context' error. + call remote_send(name, ":call test_ignore_error('E285') | gui -f\<CR>") + else + call remote_send(name, ":gui -f\<CR>") + endif + " Wait for the server to be up and answering requests. + sleep 100m + call WaitForAssert({-> assert_true(remote_expr(name, "v:version", "", 1) != "")}) + + call remote_send(name, ":let testvar = 'maybe'\<CR>") + call WaitForAssert({-> assert_equal('maybe', remote_expr(name, "testvar", "", 2))}) + endif + + call assert_fails('call remote_send("XXX", ":let testvar = ''yes''\<CR>")', 'E241') + + " Expression evaluated locally. + if v:servername == '' + call remote_startserver('MYSELF') + " May get MYSELF1 when running the test again. + call assert_match('MYSELF', v:servername) + endif + let g:testvar = 'myself' + call assert_equal('myself', remote_expr(v:servername, 'testvar')) + + call remote_send(name, ":call server2client(expand('<client>'), 'got it')\<CR>", 'g:myserverid') + call assert_equal('got it', remote_read(g:myserverid, 2)) + + call remote_send(name, ":call server2client(expand('<client>'), 'another')\<CR>", 'g:myserverid') + let peek_result = 'nothing' + let r = remote_peek(g:myserverid, 'peek_result') + " unpredictable whether the result is already available. + if r > 0 + call assert_equal('another', peek_result) + elseif r == 0 + call assert_equal('nothing', peek_result) + else + call assert_report('remote_peek() failed') + endif + let g:peek_result = 'empty' + call WaitFor('remote_peek(g:myserverid, "g:peek_result") > 0') + call assert_equal('another', g:peek_result) + call assert_equal('another', remote_read(g:myserverid, 2)) + + call remote_send(name, ":qa!\<CR>") + try + call WaitForAssert({-> assert_equal("dead", job_status(job))}) + finally + if job_status(job) != 'dead' + call assert_report('Server did not exit') + call job_stop(job, 'kill') + endif + endtry +endfunc + +" Uncomment this line to get a debugging log +" call ch_logfile('channellog', 'w') diff --git a/src/testdir/test_close_count.vim b/src/testdir/test_close_count.vim new file mode 100644 index 0000000..1f9adba --- /dev/null +++ b/src/testdir/test_close_count.vim @@ -0,0 +1,174 @@ + +" Tests for :[count]close! command +func Test_close_count() + enew! | only + + let wids = [win_getid()] + for i in range(5) + new + call add(wids, win_getid()) + endfor + + 4wincmd w + close! + let ids = [] + windo call add(ids, win_getid()) + call assert_equal([wids[5], wids[4], wids[3], wids[1], wids[0]], ids) + + 1close! + let ids = [] + windo call add(ids, win_getid()) + call assert_equal([wids[4], wids[3], wids[1], wids[0]], ids) + + $close! + let ids = [] + windo call add(ids, win_getid()) + call assert_equal([wids[4], wids[3], wids[1]], ids) + + 1wincmd w + 2close! + let ids = [] + windo call add(ids, win_getid()) + call assert_equal([wids[4], wids[1]], ids) + + 1wincmd w + new + call add(wids, win_getid()) + new + call add(wids, win_getid()) + 2wincmd w + -1close! + let ids = [] + windo call add(ids, win_getid()) + call assert_equal([wids[6], wids[4], wids[1]], ids) + + 2wincmd w + +1close! + let ids = [] + windo call add(ids, win_getid()) + call assert_equal([wids[6], wids[4]], ids) + + only! +endfunc + +" Tests for :[count]hide command +func Test_hide_count() + enew! | only + + let wids = [win_getid()] + for i in range(5) + new + call add(wids, win_getid()) + endfor + + 4wincmd w + .hide + let ids = [] + windo call add(ids, win_getid()) + call assert_equal([wids[5], wids[4], wids[3], wids[1], wids[0]], ids) + + 1hide + let ids = [] + windo call add(ids, win_getid()) + call assert_equal([wids[4], wids[3], wids[1], wids[0]], ids) + + $hide + let ids = [] + windo call add(ids, win_getid()) + call assert_equal([wids[4], wids[3], wids[1]], ids) + + 1wincmd w + 2hide + let ids = [] + windo call add(ids, win_getid()) + call assert_equal([wids[4], wids[1]], ids) + + 1wincmd w + new + call add(wids, win_getid()) + new + call add(wids, win_getid()) + 3wincmd w + -hide + let ids = [] + windo call add(ids, win_getid()) + call assert_equal([wids[7], wids[4], wids[1]], ids) + + 2wincmd w + +hide + let ids = [] + windo call add(ids, win_getid()) + call assert_equal([wids[7], wids[4]], ids) + + only! +endfunc + +" Tests for :[count]close! command with 'hidden' +func Test_hidden_close_count() + enew! | only + + let wids = [win_getid()] + for i in range(5) + new + call add(wids, win_getid()) + endfor + + set hidden + + $ hide + let ids = [] + windo call add(ids, win_getid()) + call assert_equal([wids[5], wids[4], wids[3], wids[2], wids[1]], ids) + + $-1 close! + let ids = [] + windo call add(ids, win_getid()) + call assert_equal([wids[5], wids[4], wids[3], wids[1]], ids) + + 1wincmd w + .+close! + let ids = [] + windo call add(ids, win_getid()) + call assert_equal([wids[5], wids[3], wids[1]], ids) + + set nohidden + only! +endfunc + +" Tests for 'CTRL-W c' command to close windows. +func Test_winclose_command() + enew! | only + + let wids = [win_getid()] + for i in range(5) + new + call add(wids, win_getid()) + endfor + + set hidden + + 4wincmd w + exe "normal \<C-W>c" + let ids = [] + windo call add(ids, win_getid()) + call assert_equal([wids[5], wids[4], wids[3], wids[1], wids[0]], ids) + + exe "normal 1\<C-W>c" + let ids = [] + windo call add(ids, win_getid()) + call assert_equal([wids[4], wids[3], wids[1], wids[0]], ids) + + exe "normal 9\<C-W>c" + let ids = [] + windo call add(ids, win_getid()) + call assert_equal([wids[4], wids[3], wids[1]], ids) + + 1wincmd w + exe "normal 2\<C-W>c" + let ids = [] + windo call add(ids, win_getid()) + call assert_equal([wids[4], wids[1]], ids) + + set nohidden + only! +endfunc diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim new file mode 100644 index 0000000..02eeb6b --- /dev/null +++ b/src/testdir/test_cmdline.vim @@ -0,0 +1,612 @@ +" Tests for editing the command line. + +func Test_complete_tab() + call writefile(['testfile'], 'Xtestfile') + call feedkeys(":e Xtest\t\r", "tx") + call assert_equal('testfile', getline(1)) + call delete('Xtestfile') +endfunc + +func Test_complete_list() + " We can't see the output, but at least we check the code runs properly. + call feedkeys(":e test\<C-D>\r", "tx") + call assert_equal('test', expand('%:t')) +endfunc + +func Test_complete_wildmenu() + call writefile(['testfile1'], 'Xtestfile1') + call writefile(['testfile2'], 'Xtestfile2') + set wildmenu + call feedkeys(":e Xtest\t\t\r", "tx") + call assert_equal('testfile2', getline(1)) + + call delete('Xtestfile1') + call delete('Xtestfile2') + set nowildmenu +endfunc + +func Test_map_completion() + if !has('cmdline_compl') + return + endif + call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt') + call assert_equal('"map <unique> <silent>', getreg(':')) + call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt') + call assert_equal('"map <script> <unique>', getreg(':')) + call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt') + call assert_equal('"map <expr> <script>', getreg(':')) + call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt') + call assert_equal('"map <buffer> <expr>', getreg(':')) + call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt') + call assert_equal('"map <nowait> <buffer>', getreg(':')) + call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt') + call assert_equal('"map <special> <nowait>', getreg(':')) + call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt') + call assert_equal('"map <silent> <special>', getreg(':')) +endfunc + +func Test_match_completion() + if !has('cmdline_compl') + return + endif + hi Aardig ctermfg=green + call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt') + call assert_equal('"match Aardig', getreg(':')) + call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt') + call assert_equal('"match none', getreg(':')) +endfunc + +func Test_highlight_completion() + if !has('cmdline_compl') + return + endif + hi Aardig ctermfg=green + call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt') + call assert_equal('"hi Aardig', getreg(':')) + call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt') + call assert_equal('"hi default Aardig', getreg(':')) + call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt') + call assert_equal('"hi clear Aardig', getreg(':')) + call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt') + call assert_equal('"hi link', getreg(':')) + call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt') + call assert_equal('"hi default', getreg(':')) + call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt') + call assert_equal('"hi clear', getreg(':')) + + " A cleared group does not show up in completions. + hi Anders ctermfg=green + call assert_equal(['Aardig', 'Anders'], getcompletion('A', 'highlight')) + hi clear Aardig + call assert_equal(['Anders'], getcompletion('A', 'highlight')) + hi clear Anders + call assert_equal([], getcompletion('A', 'highlight')) +endfunc + +func Test_expr_completion() + if !has('cmdline_compl') + return + endif + for cmd in [ + \ 'let a = ', + \ 'if', + \ 'elseif', + \ 'while', + \ 'for', + \ 'echo', + \ 'echon', + \ 'execute', + \ 'echomsg', + \ 'echoerr', + \ 'call', + \ 'return', + \ 'cexpr', + \ 'caddexpr', + \ 'cgetexpr', + \ 'lexpr', + \ 'laddexpr', + \ 'lgetexpr'] + call feedkeys(":" . cmd . " getl\<Tab>\<Home>\"\<CR>", 'xt') + call assert_equal('"' . cmd . ' getline(', getreg(':')) + endfor +endfunc + +func Test_getcompletion() + if !has('cmdline_compl') + return + endif + let groupcount = len(getcompletion('', 'event')) + call assert_true(groupcount > 0) + let matchcount = len(getcompletion('File', 'event')) + call assert_true(matchcount > 0) + call assert_true(groupcount > matchcount) + + if has('menu') + source $VIMRUNTIME/menu.vim + let matchcount = len(getcompletion('', 'menu')) + call assert_true(matchcount > 0) + call assert_equal(['File.'], getcompletion('File', 'menu')) + call assert_true(matchcount > 0) + let matchcount = len(getcompletion('File.', 'menu')) + call assert_true(matchcount > 0) + endif + + let l = getcompletion('v:n', 'var') + call assert_true(index(l, 'v:null') >= 0) + let l = getcompletion('v:notexists', 'var') + call assert_equal([], l) + + args a.c b.c + let l = getcompletion('', 'arglist') + call assert_equal(['a.c', 'b.c'], l) + %argdelete + + let l = getcompletion('', 'augroup') + call assert_true(index(l, 'END') >= 0) + let l = getcompletion('blahblah', 'augroup') + call assert_equal([], l) + + let l = getcompletion('', 'behave') + call assert_true(index(l, 'mswin') >= 0) + let l = getcompletion('not', 'behave') + call assert_equal([], l) + + let l = getcompletion('', 'color') + call assert_true(index(l, 'default') >= 0) + let l = getcompletion('dirty', 'color') + call assert_equal([], l) + + let l = getcompletion('', 'command') + call assert_true(index(l, 'sleep') >= 0) + let l = getcompletion('awake', 'command') + call assert_equal([], l) + + let l = getcompletion('', 'dir') + call assert_true(index(l, 'samples/') >= 0) + let l = getcompletion('NoMatch', 'dir') + call assert_equal([], l) + + let l = getcompletion('exe', 'expression') + call assert_true(index(l, 'executable(') >= 0) + let l = getcompletion('kill', 'expression') + call assert_equal([], l) + + let l = getcompletion('tag', 'function') + call assert_true(index(l, 'taglist(') >= 0) + let l = getcompletion('paint', 'function') + call assert_equal([], l) + + let Flambda = {-> 'hello'} + let l = getcompletion('', 'function') + let l = filter(l, {i, v -> v =~ 'lambda'}) + call assert_equal([], l) + + let l = getcompletion('run', 'file') + call assert_true(index(l, 'runtest.vim') >= 0) + let l = getcompletion('walk', 'file') + call assert_equal([], l) + set wildignore=*.vim + let l = getcompletion('run', 'file', 1) + call assert_true(index(l, 'runtest.vim') < 0) + set wildignore& + + let l = getcompletion('ha', 'filetype') + call assert_true(index(l, 'hamster') >= 0) + let l = getcompletion('horse', 'filetype') + call assert_equal([], l) + + let l = getcompletion('z', 'syntax') + call assert_true(index(l, 'zimbu') >= 0) + let l = getcompletion('emacs', 'syntax') + call assert_equal([], l) + + let l = getcompletion('jikes', 'compiler') + call assert_true(index(l, 'jikes') >= 0) + let l = getcompletion('break', 'compiler') + call assert_equal([], l) + + let l = getcompletion('last', 'help') + call assert_true(index(l, ':tablast') >= 0) + let l = getcompletion('giveup', 'help') + call assert_equal([], l) + + let l = getcompletion('time', 'option') + call assert_true(index(l, 'timeoutlen') >= 0) + let l = getcompletion('space', 'option') + call assert_equal([], l) + + let l = getcompletion('er', 'highlight') + call assert_true(index(l, 'ErrorMsg') >= 0) + let l = getcompletion('dark', 'highlight') + call assert_equal([], l) + + let l = getcompletion('', 'messages') + call assert_true(index(l, 'clear') >= 0) + let l = getcompletion('not', 'messages') + call assert_equal([], l) + + let l = getcompletion('', 'mapclear') + call assert_true(index(l, '<buffer>') >= 0) + let l = getcompletion('not', 'mapclear') + call assert_equal([], l) + + let l = getcompletion('.', 'shellcmd') + call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"')) + call assert_equal(-1, match(l[2:], '^\.\.\?/$')) + let root = has('win32') ? 'C:\\' : '/' + let l = getcompletion(root, 'shellcmd') + let expected = map(filter(glob(root . '*', 0, 1), + \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val') + call assert_equal(expected, l) + + if has('cscope') + let l = getcompletion('', 'cscope') + let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show'] + call assert_equal(cmds, l) + " using cmdline completion must not change the result + call feedkeys(":cscope find \<c-d>\<c-c>", 'xt') + let l = getcompletion('', 'cscope') + call assert_equal(cmds, l) + let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't'] + let l = getcompletion('find ', 'cscope') + call assert_equal(keys, l) + endif + + if has('signs') + sign define Testing linehl=Comment + let l = getcompletion('', 'sign') + let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace'] + call assert_equal(cmds, l) + " using cmdline completion must not change the result + call feedkeys(":sign list \<c-d>\<c-c>", 'xt') + let l = getcompletion('', 'sign') + call assert_equal(cmds, l) + let l = getcompletion('list ', 'sign') + call assert_equal(['Testing'], l) + endif + + " For others test if the name is recognized. + let names = ['buffer', 'environment', 'file_in_path', 'mapping', 'tag', 'tag_listfiles', 'user'] + if has('cmdline_hist') + call add(names, 'history') + endif + if has('gettext') + call add(names, 'locale') + endif + if has('profile') + call add(names, 'syntime') + endif + + set tags=Xtags + call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags') + + for name in names + let matchcount = len(getcompletion('', name)) + call assert_true(matchcount >= 0, 'No matches for ' . name) + endfor + + call delete('Xtags') + + call assert_fails('call getcompletion("", "burp")', 'E475:') +endfunc + +func Test_shellcmd_completion() + let save_path = $PATH + + call mkdir('Xpathdir/Xpathsubdir', 'p') + call writefile([''], 'Xpathdir/Xfile.exe') + call setfperm('Xpathdir/Xfile.exe', 'rwx------') + + " Set PATH to example directory without trailing slash. + let $PATH = getcwd() . '/Xpathdir' + + " Test for the ":!<TAB>" case. Previously, this would include subdirs of + " dirs in the PATH, even though they won't be executed. We check that only + " subdirs of the PWD and executables from the PATH are included in the + " suggestions. + let actual = getcompletion('X', 'shellcmd') + let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"') + call insert(expected, 'Xfile.exe') + call assert_equal(expected, actual) + + call delete('Xpathdir', 'rf') + let $PATH = save_path +endfunc + +func Test_expand_star_star() + call mkdir('a/b', 'p') + call writefile(['asdfasdf'], 'a/b/fileXname') + call feedkeys(":find **/fileXname\<Tab>\<CR>", 'xt') + call assert_equal('find a/b/fileXname', getreg(':')) + bwipe! + call delete('a', 'rf') +endfunc + +func Test_paste_in_cmdline() + let @a = "def" + call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx') + call assert_equal('"abc def ghi', @:) + + new + call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ') + + call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') + call assert_equal('"aaa asdf bbb', @:) + + call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx') + call assert_equal('"aaa /tmp/some bbb', @:) + + call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx') + call assert_equal('"aaa '.getline(1).' bbb', @:) + + set incsearch + call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx') + call assert_equal('"aaa verylongword bbb', @:) + + call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx') + call assert_equal('"aaa a;b-c*d bbb', @:) + + call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx') + call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:) + bwipe! + + " Error while typing a command used to cause that it was not executed + " in the end. + new + try + call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx') + catch /^Vim\%((\a\+)\)\=:E32/ + " ignore error E32 + endtry + call assert_equal("Xtestfile", bufname("%")) + bwipe! +endfunc + +func Test_remove_char_in_cmdline() + call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx') + call assert_equal('"abc ef', @:) + + call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx') + call assert_equal('"abcdef', @:) + + call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx') + call assert_equal('"abc ghi', @:) + + call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx') + call assert_equal('"def', @:) +endfunc + +func Test_illegal_address1() + new + 2;'( + 2;') + quit +endfunc + +func Test_illegal_address2() + call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim') + new + source Xtest.vim + " Trigger calling validate_cursor() + diffsp Xtest.vim + quit! + bwipe! + call delete('Xtest.vim') +endfunc + +func Test_cmdline_complete_wildoptions() + help + call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx') + let a = join(sort(split(@:)),' ') + set wildoptions=tagfile + call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx') + let b = join(sort(split(@:)),' ') + call assert_equal(a, b) + bw! +endfunc + +func Test_cmdline_complete_user_cmd() + command! -complete=color -nargs=1 Foo : + call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx') + call assert_equal('"Foo blue', @:) + call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx') + call assert_equal('"Foo blue', @:) + delcommand Foo +endfunc + +func Test_cmdline_complete_user_names() + if has('unix') && executable('whoami') + let whoami = systemlist('whoami')[0] + let first_letter = whoami[0] + if len(first_letter) > 0 + " Trying completion of :e ~x where x is the first letter of + " the user name should complete to at least the user name. + call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx') + call assert_match('^"e \~.*\<' . whoami . '\>', @:) + endif + endif + if has('win32') + " Just in case: check that the system has an Administrator account. + let names = system('net user') + if names =~ 'Administrator' + " Trying completion of :e ~A should complete to Administrator. + " There could be other names starting with "A" before Administrator. + call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx') + call assert_match('^"e \~.*Administrator', @:) + endif + endif +endfunc + +funct Test_cmdline_complete_languages() + let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '') + + call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx') + call assert_match('^"language .*\<ctype\>.*\<messages\>.*\<time\>', @:) + + if has('unix') + " TODO: these tests don't work on Windows. lang appears to be 'C' + " but C does not appear in the completion. Why? + call assert_match('^"language .*\<' . lang . '\>', @:) + + call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx') + call assert_match('^"language .*\<' . lang . '\>', @:) + + call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx') + call assert_match('^"language .*\<' . lang . '\>', @:) + + call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx') + call assert_match('^"language .*\<' . lang . '\>', @:) + endif +endfunc + +func Test_cmdline_write_alternatefile() + new + call setline('.', ['one', 'two']) + f foo.txt + new + f #-A + call assert_equal('foo.txt-A', expand('%')) + f #<-B.txt + call assert_equal('foo-B.txt', expand('%')) + f %< + call assert_equal('foo-B', expand('%')) + new + call assert_fails('f #<', 'E95') + bw! + f foo-B.txt + f %<-A + call assert_equal('foo-B-A', expand('%')) + bw! + bw! +endfunc + +" using a leading backslash here +set cpo+=C + +func Test_cmdline_search_range() + new + call setline(1, ['a', 'b', 'c', 'd']) + /d + 1,\/s/b/B/ + call assert_equal('B', getline(2)) + + /a + $ + \?,4s/c/C/ + call assert_equal('C', getline(3)) + + call setline(1, ['a', 'b', 'c', 'd']) + %s/c/c/ + 1,\&s/b/B/ + call assert_equal('B', getline(2)) + + bwipe! +endfunc + +" Tests for getcmdline(), getcmdpos() and getcmdtype() +func Check_cmdline(cmdtype) + call assert_equal('MyCmd a', getcmdline()) + call assert_equal(8, getcmdpos()) + call assert_equal(a:cmdtype, getcmdtype()) + return '' +endfunc + +func Test_getcmdtype() + call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt") + + let cmdtype = '' + debuggreedy + call feedkeys(":debug echo 'test'\<CR>", "t") + call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t") + call feedkeys("cont\<CR>", "xt") + 0debuggreedy + call assert_equal('>', cmdtype) + + call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt") + call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt") + + call feedkeys(":call input('Answer?')\<CR>", "t") + call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt") + + call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt") + + cnoremap <expr> <F6> Check_cmdline('=') + call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt") + cunmap <F6> +endfunc + +func Test_getcmdwintype() + call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') + call assert_equal('/', a) + + call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') + call assert_equal('?', a) + + call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!') + call assert_equal(':', a) + + call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!') + call assert_equal(':', a) + + call assert_equal('', getcmdwintype()) +endfunc + +func Test_verbosefile() + set verbosefile=Xlog + echomsg 'foo' + echomsg 'bar' + set verbosefile= + let log = readfile('Xlog') + call assert_match("foo\nbar", join(log, "\n")) + call delete('Xlog') +endfunc + +func Test_setcmdpos() + func InsertTextAtPos(text, pos) + call assert_equal(0, setcmdpos(a:pos)) + return a:text + endfunc + + " setcmdpos() with position in the middle of the command line. + call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') + call assert_equal('"1ab2', @:) + + call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt') + call assert_equal('"1b2a', @:) + + " setcmdpos() with position beyond the end of the command line. + call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt') + call assert_equal('"12ab', @:) + + " setcmdpos() returns 1 when not editing the command line. + call assert_equal(1, setcmdpos(3)) +endfunc + +func Test_cmdline_overstrike() + let encodings = ['latin1', 'utf8'] + let encoding_save = &encoding + + for e in encodings + exe 'set encoding=' . e + + " Test overstrike in the middle of the command line. + call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') + call assert_equal('"0ab1cd4', @:) + + " Test overstrike going beyond end of command line. + call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt') + call assert_equal('"0ab1cdefgh', @:) + + " Test toggling insert/overstrike a few times. + call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt') + call assert_equal('"ab0cd3ef4', @:) + endfor + + " Test overstrike with multi-byte characters. + call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt') + call assert_equal('"テabキcdエディタ', @:) + + let &encoding = encoding_save +endfunc + +set cpo& diff --git a/src/testdir/test_command_count.vim b/src/testdir/test_command_count.vim new file mode 100644 index 0000000..55b2303 --- /dev/null +++ b/src/testdir/test_command_count.vim @@ -0,0 +1,196 @@ +" Test for user command counts. + +func Test_command_count_0() + let bufnr = bufnr('%') + set hidden + set noswapfile + + split DoesNotExistEver + let lastbuf = bufnr('$') + call setline(1, 'asdf') + quit! + + command! -range -addr=loaded_buffers RangeLoadedBuffers :let lines = [<line1>, <line2>] + command! -range=% -addr=loaded_buffers RangeLoadedBuffersAll :let lines = [<line1>, <line2>] + command! -range -addr=buffers RangeBuffers :let lines = [<line1>, <line2>] + command! -range=% -addr=buffers RangeBuffersAll :let lines = [<line1>, <line2>] + + .,$RangeLoadedBuffers + call assert_equal([bufnr, bufnr], lines) + %RangeLoadedBuffers + call assert_equal([bufnr, bufnr], lines) + RangeLoadedBuffersAll + call assert_equal([bufnr, bufnr], lines) + .,$RangeBuffers + call assert_equal([bufnr, lastbuf], lines) + %RangeBuffers + call assert_equal([bufnr, lastbuf], lines) + RangeBuffersAll + call assert_equal([bufnr, lastbuf], lines) + + delcommand RangeLoadedBuffers + delcommand RangeLoadedBuffersAll + delcommand RangeBuffers + delcommand RangeBuffersAll + + set hidden& + set swapfile& +endfunc + +func Test_command_count_1() + silent! %argd + arga a b c d e + argdo echo "loading buffers" + argu 3 + command! -range -addr=arguments RangeArguments :let lines = [<line1>, <line2>] + command! -range=% -addr=arguments RangeArgumentsAll :let lines = [<line1>, <line2>] + .-,$-RangeArguments + call assert_equal([2, 4], lines) + %RangeArguments + call assert_equal([1, 5], lines) + RangeArgumentsAll + call assert_equal([1, 5], lines) + N + .RangeArguments + call assert_equal([2, 2], lines) + delcommand RangeArguments + delcommand RangeArgumentsAll + + split|split|split|split + 3wincmd w + command! -range -addr=windows RangeWindows :let lines = [<line1>, <line2>] + .,$RangeWindows + call assert_equal([3, 5], lines) + %RangeWindows + call assert_equal([1, 5], lines) + delcommand RangeWindows + + command! -range=% -addr=windows RangeWindowsAll :let lines = [<line1>, <line2>] + RangeWindowsAll + call assert_equal([1, 5], lines) + delcommand RangeWindowsAll + only + blast|bd + + tabe|tabe|tabe|tabe + normal 2gt + command! -range -addr=tabs RangeTabs :let lines = [<line1>, <line2>] + .,$RangeTabs + call assert_equal([2, 5], lines) + %RangeTabs + call assert_equal([1, 5], lines) + delcommand RangeTabs + + command! -range=% -addr=tabs RangeTabsAll :let lines = [<line1>, <line2>] + RangeTabsAll + call assert_equal([1, 5], lines) + delcommand RangeTabsAll + 1tabonly + + s/\n/\r\r\r\r\r/ + 2ma< + $-ma> + command! -range=% RangeLines :let lines = [<line1>, <line2>] + '<,'>RangeLines + call assert_equal([2, 5], lines) + delcommand RangeLines + + command! -range=% -buffer LocalRangeLines :let lines = [<line1>, <line2>] + '<,'>LocalRangeLines + call assert_equal([2, 5], lines) + delcommand LocalRangeLines +endfunc + +func Test_command_count_2() + silent! %argd + arga a b c d + call assert_fails('5argu', 'E16:') + + $argu + call assert_equal('d', expand('%:t')) + + 1argu + call assert_equal('a', expand('%:t')) + + call assert_fails('300b', 'E16:') + + split|split|split|split + 0close + + $wincmd w + $close + call assert_equal(3, winnr()) + + call assert_fails('$+close', 'E16:') + + $tabe + call assert_equal(2, tabpagenr()) + + call assert_fails('$+tabe', 'E16:') + + only! + e x + 0tabm + normal 1gt + call assert_equal('x', expand('%:t')) + + tabonly! + only! +endfunc + +func Test_command_count_3() + let bufnr = bufnr('%') + se nohidden + e aaa + let buf_aaa = bufnr('%') + e bbb + let buf_bbb = bufnr('%') + e ccc + let buf_ccc = bufnr('%') + exe bufnr . 'buf' + call assert_equal([1, 1, 1], [buflisted(buf_aaa), buflisted(buf_bbb), buflisted(buf_ccc)]) + exe buf_bbb . "," . buf_ccc . "bdelete" + call assert_equal([1, 0, 0], [buflisted(buf_aaa), buflisted(buf_bbb), buflisted(buf_ccc)]) + exe buf_aaa . "bdelete" + call assert_equal([0, 0, 0], [buflisted(buf_aaa), buflisted(buf_bbb), buflisted(buf_ccc)]) +endfunc + +func Test_command_count_4() + %argd + let bufnr = bufnr('$') + next aa bb cc dd ee ff + call assert_equal(bufnr, bufnr('%')) + + 3argu + let args = [] + .,$-argdo call add(args, expand('%')) + call assert_equal(['cc', 'dd', 'ee'], args) + + " create windows to get 5 + split|split|split|split + 2wincmd w + let windows = [] + .,$-windo call add(windows, winnr()) + call assert_equal([2, 3, 4], windows) + only! + + exe bufnr . 'buf' + let bufnr = bufnr('%') + let buffers = [] + .,$-bufdo call add(buffers, bufnr('%')) + call assert_equal([bufnr, bufnr + 1, bufnr + 2, bufnr + 3, bufnr + 4], buffers) + + exe (bufnr + 3) . 'bdel' + let buffers = [] + exe (bufnr + 2) . ',' . (bufnr + 5) . "bufdo call add(buffers, bufnr('%'))" + call assert_equal([bufnr + 2, bufnr + 4, bufnr + 5], buffers) + + " create tabpages to get 5 + tabe|tabe|tabe|tabe + normal! 2gt + let tabpages = [] + .,$-tabdo call add(tabpages, tabpagenr()) + call assert_equal([2, 3, 4], tabpages) + tabonly! + bwipe! +endfunc diff --git a/src/testdir/test_comparators.vim b/src/testdir/test_comparators.vim new file mode 100644 index 0000000..87be006 --- /dev/null +++ b/src/testdir/test_comparators.vim @@ -0,0 +1,9 @@ +function Test_Comparators() + try + let oldisident=&isident + set isident+=# + call assert_equal(1, 1 is#1) + finally + let &isident=oldisident + endtry +endfunction diff --git a/src/testdir/test_compiler.vim b/src/testdir/test_compiler.vim new file mode 100644 index 0000000..46c14d8 --- /dev/null +++ b/src/testdir/test_compiler.vim @@ -0,0 +1,54 @@ +" Test the :compiler command + +func Test_compiler() + if !executable('perl') + return + endif + + " $LANG changes the output of Perl. + if $LANG != '' + unlet $LANG + endif + + e Xfoo.pl + compiler perl + call assert_equal('perl', b:current_compiler) + call assert_fails('let g:current_compiler', 'E121:') + + call setline(1, ['#!/usr/bin/perl -w', 'use strict;', 'my $foo=1']) + w! + call feedkeys(":make\<CR>\<CR>", 'tx') + call assert_fails('clist', 'E42:') + + call setline(1, ['#!/usr/bin/perl -w', 'use strict;', '$foo=1']) + w! + call feedkeys(":make\<CR>\<CR>", 'tx') + let a=execute('clist') + call assert_match("\n 1 Xfoo.pl:3: Global symbol \"\$foo\" " + \ . "requires explicit package name", a) + + call delete('Xfoo.pl') + bw! +endfunc + +func Test_compiler_without_arg() + let a=split(execute('compiler')) + call assert_match('^.*runtime/compiler/ant.vim$', a[0]) + call assert_match('^.*runtime/compiler/bcc.vim$', a[1]) + call assert_match('^.*runtime/compiler/xmlwf.vim$', a[-1]) +endfunc + +func Test_compiler_completion() + call feedkeys(":compiler \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_match('^"compiler ant bcc .* xmlwf$', @:) + + call feedkeys(":compiler p\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"compiler pbx perl php pylint pyunit', @:) + + call feedkeys(":compiler! p\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"compiler! pbx perl php pylint pyunit', @:) +endfunc + +func Test_compiler_error() + call assert_fails('compiler doesnotexist', 'E666:') +endfunc diff --git a/src/testdir/test_conceal.vim b/src/testdir/test_conceal.vim new file mode 100644 index 0000000..685c891 --- /dev/null +++ b/src/testdir/test_conceal.vim @@ -0,0 +1,136 @@ +" Tests for 'conceal'. +" Also see test88.in (should be converted to a test function here). + +if !has('conceal') + finish +endif + +source screendump.vim +if !CanRunVimInTerminal() + finish +endif + +func Test_conceal_two_windows() + call writefile([ + \ 'let lines = ["one one one one one", "two |hidden| here", "three |hidden| three"]', + \ 'call setline(1, lines)', + \ 'syntax match test /|hidden|/ conceal', + \ 'set conceallevel=2', + \ 'set concealcursor=', + \ 'exe "normal /here\r"', + \ 'new', + \ 'call setline(1, lines)', + \ 'call setline(4, "Second window")', + \ 'syntax match test /|hidden|/ conceal', + \ 'set conceallevel=2', + \ 'set concealcursor=nc', + \ 'exe "normal /here\r"', + \ ], 'XTest_conceal') + " Check that cursor line is concealed + let buf = RunVimInTerminal('-S XTest_conceal', {}) + call VerifyScreenDump(buf, 'Test_conceal_two_windows_01', {}) + + " Check that with concealed text vertical cursor movement is correct. + call term_sendkeys(buf, "k") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_02', {}) + + " Check that with cursor line is not concealed + call term_sendkeys(buf, "j") + call term_sendkeys(buf, ":set concealcursor=\r") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_03', {}) + + " Check that with cursor line is not concealed when moving cursor down + call term_sendkeys(buf, "j") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_04', {}) + + " Check that with cursor line is not concealed when switching windows + call term_sendkeys(buf, "\<C-W>\<C-W>") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_05', {}) + + " Check that with cursor line is only concealed in Normal mode + call term_sendkeys(buf, ":set concealcursor=n\r") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_06n', {}) + call term_sendkeys(buf, "a") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_06i', {}) + call term_sendkeys(buf, "\<Esc>/e") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_06c', {}) + call term_sendkeys(buf, "\<Esc>v") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_06v', {}) + call term_sendkeys(buf, "\<Esc>") + + " Check that with cursor line is only concealed in Insert mode + call term_sendkeys(buf, ":set concealcursor=i\r") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_07n', {}) + call term_sendkeys(buf, "a") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_07i', {}) + call term_sendkeys(buf, "\<Esc>/e") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_07c', {}) + call term_sendkeys(buf, "\<Esc>v") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_07v', {}) + call term_sendkeys(buf, "\<Esc>") + + " Check that with cursor line is only concealed in Command mode + call term_sendkeys(buf, ":set concealcursor=c\r") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_08n', {}) + call term_sendkeys(buf, "a") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_08i', {}) + call term_sendkeys(buf, "\<Esc>/e") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_08c', {}) + call term_sendkeys(buf, "\<Esc>v") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_08v', {}) + call term_sendkeys(buf, "\<Esc>") + + " Check that with cursor line is only concealed in Visual mode + call term_sendkeys(buf, ":set concealcursor=v\r") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_09n', {}) + call term_sendkeys(buf, "a") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_09i', {}) + call term_sendkeys(buf, "\<Esc>/e") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_09c', {}) + call term_sendkeys(buf, "\<Esc>v") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_09v', {}) + call term_sendkeys(buf, "\<Esc>") + + " Check moving the cursor while in insert mode. + call term_sendkeys(buf, ":set concealcursor=\r") + call term_sendkeys(buf, "a") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_10', {}) + call term_sendkeys(buf, "\<Down>") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_11', {}) + call term_sendkeys(buf, "\<Esc>") + + " Check the "o" command + call VerifyScreenDump(buf, 'Test_conceal_two_windows_12', {}) + call term_sendkeys(buf, "o") + call VerifyScreenDump(buf, 'Test_conceal_two_windows_13', {}) + call term_sendkeys(buf, "\<Esc>") + + " clean up + call StopVimInTerminal(buf) + call delete('XTest_conceal') +endfunc + +func Test_conceal_with_cursorline() + " Opens a help window, where 'conceal' is set, switches to the other window + " where 'cursorline' needs to be updated when the cursor moves. + call writefile([ + \ 'set cursorline', + \ 'normal othis is a test', + \ 'new', + \ 'call setline(1, ["one", "two", "three", "four", "five"])', + \ 'set ft=help', + \ 'normal M', + \ ], 'XTest_conceal_cul') + let buf = RunVimInTerminal('-S XTest_conceal_cul', {}) + call VerifyScreenDump(buf, 'Test_conceal_cul_01', {}) + + call term_sendkeys(buf, ":wincmd w\r") + call VerifyScreenDump(buf, 'Test_conceal_cul_02', {}) + + call term_sendkeys(buf, "k") + call VerifyScreenDump(buf, 'Test_conceal_cul_03', {}) + + " clean up + call StopVimInTerminal(buf) + call delete('XTest_conceal_cul') +endfunc diff --git a/src/testdir/test_crypt.vim b/src/testdir/test_crypt.vim new file mode 100644 index 0000000..bf1a511 --- /dev/null +++ b/src/testdir/test_crypt.vim @@ -0,0 +1,113 @@ +" Tests for encryption. + +if !has('cryptv') + finish +endif + +func Common_head_only(text) + " This was crashing Vim + split Xtest.txt + call setline(1, a:text) + wq + call feedkeys(":split Xtest.txt\<CR>foobar\<CR>", "tx") + call delete('Xtest.txt') + call assert_match('VimCrypt', getline(1)) + bwipe! +endfunc + +func Test_head_only_2() + call Common_head_only('VimCrypt~02!abc') +endfunc + +func Test_head_only_3() + call Common_head_only('VimCrypt~03!abc') +endfunc + +func Crypt_uncrypt(method) + exe "set cryptmethod=" . a:method + " If the blowfish test fails 'cryptmethod' will be 'zip' now. + call assert_equal(a:method, &cryptmethod) + + split Xtest.txt + let text = ['01234567890123456789012345678901234567', + \ 'line 2 foo bar blah', + \ 'line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'] + call setline(1, text) + call feedkeys(":X\<CR>foobar\<CR>foobar\<CR>", 'xt') + call assert_equal('*****', &key) + w! + bwipe! + call feedkeys(":split Xtest.txt\<CR>foobar\<CR>", 'xt') + call assert_equal(text, getline(1, 3)) + set key= cryptmethod& + bwipe! + call delete('Xtest.txt') +endfunc + +func Test_crypt_zip() + call Crypt_uncrypt('zip') +endfunc + +func Test_crypt_blowfish() + call Crypt_uncrypt('blowfish') +endfunc + +func Test_crypt_blowfish2() + call Crypt_uncrypt('blowfish2') +endfunc + +func Uncrypt_stable(method, crypted_text, key, uncrypted_text) + split Xtest.txt + set bin noeol key= fenc=latin1 + exe "set cryptmethod=" . a:method + call setline(1, a:crypted_text) + w! + bwipe! + set nobin + call feedkeys(":split Xtest.txt\<CR>" . a:key . "\<CR>", 'xt') + call assert_equal(a:uncrypted_text, getline(1, len(a:uncrypted_text))) + bwipe! + call delete('Xtest.txt') + set key= +endfunc + +func Test_uncrypt_zip() + call Uncrypt_stable('zip', "VimCrypt~01!\u0006\u001clV'\u00de}Mg\u00a0\u00ea\u00a3V\u00a9\u00e7\u0007E#3\u008e2U\u00e9\u0097", "foofoo", ["1234567890", "aábbccddeëff"]) +endfunc + +func Test_uncrypt_blowfish() + call Uncrypt_stable('blowfish', "VimCrypt~02!k)\u00be\u0017\u0097#\u0016\u00ddS\u009c\u00f5=\u00ba\u00e0\u00c8#\u00a5M\u00b4\u0086J\u00c3A\u00cd\u00a5M\u00b4\u0086!\u0080\u0015\u009b\u00f5\u000f\u00e1\u00d2\u0019\u0082\u0016\u0098\u00f7\u000d\u00da", "barbar", ["asdfasdfasdf", "0001112223333"]) +endfunc + +func Test_uncrypt_blowfish2() + call Uncrypt_stable('blowfish', "VimCrypt~03!\u001e\u00d1N\u00e3;\u00d3\u00c0\u00a0^C)\u0004\u00f7\u007f.\u00b6\u00abF\u000eS\u0019\u00e0\u008b6\u00d2[T\u00cb\u00a7\u0085\u00d8\u00be9\u000b\u00812\u000bQ\u00b3\u00cc@\u0097\u000f\u00df\u009a\u00adIv\u00aa.\u00d8\u00c9\u00ee\u009e`\u00bd$\u00af%\u00d0", "barburp", ["abcdefghijklmnopqrstuvwxyz", "!@#$%^&*()_+=-`~"]) +endfunc + +func Test_uncrypt_unknown_method() + split Xuncrypt_unknown.txt + set bin noeol key= fenc=latin1 + call setline(1, "VimCrypt~93!\u001e\u00d1") + w! + bwipe! + set nobin + call assert_fails(":split Xuncrypt_unknown.txt", 'E821:') + + bwipe! + call delete('Xuncrypt_unknown.txt') + set key= +endfunc + +func Test_crypt_key_mismatch() + set cryptmethod=blowfish + + split Xtest.txt + call setline(1, 'nothing') + call feedkeys(":X\<CR>foobar\<CR>nothing\<CR>", 'xt') + call assert_match("Keys don't match!", execute(':2messages')) + call assert_equal('', &key) + call feedkeys("\<CR>\<CR>", 'xt') + + set cryptmethod& + bwipe! +endfunc + diff --git a/src/testdir/test_cscope.vim b/src/testdir/test_cscope.vim new file mode 100644 index 0000000..63f2c18 --- /dev/null +++ b/src/testdir/test_cscope.vim @@ -0,0 +1,302 @@ +" Test for cscope commands. + +if !has('cscope') || !executable('cscope') || !has('quickfix') + finish +endif + +func CscopeSetupOrClean(setup) + if a:setup + noa sp ../memfile_test.c + saveas! Xmemfile_test.c + call system('cscope -bk -fXcscope.out Xmemfile_test.c') + call system('cscope -bk -fXcscope2.out Xmemfile_test.c') + cscope add Xcscope.out + set cscopequickfix=s-,g-,d-,c-,t-,e-,f-,i-,a- + else + cscope kill -1 + for file in ['Xcscope.out', 'Xcscope2.out', 'Xmemfile_test.c'] + call delete(file) + endfo + endif +endfunc + +func Test_cscopeWithCscopeConnections() + call CscopeSetupOrClean(1) + " Test 0: E568: duplicate cscope database not added + try + set nocscopeverbose + cscope add Xcscope.out + set cscopeverbose + catch + call assert_report('exception thrown') + endtry + call assert_fails('cscope add', 'E560') + call assert_fails('cscope add Xcscope.out', 'E568') + call assert_fails('cscope add doesnotexist.out', 'E563') + + " Test 1: Find this C-Symbol + for cmd in ['cs find s main', 'cs find 0 main'] + let a = execute(cmd) + " Test 1.1 test where it moves the cursor + call assert_equal('main(void)', getline('.')) + " Test 1.2 test the output of the :cs command + call assert_match('\n(1 of 1): <<main>> main(void )', a) + endfor + + " Test 2: Find this definition + for cmd in ['cs find g test_mf_hash', 'cs find 1 test_mf_hash'] + exe cmd + call assert_equal(['', '/*', ' * Test mf_hash_*() functions.', ' */', ' static void', 'test_mf_hash(void)', '{'], getline(line('.')-5, line('.')+1)) + endfor + + " Test 3: Find functions called by this function + for cmd in ['cs find d test_mf_hash', 'cs find 2 test_mf_hash'] + let a = execute(cmd) + call assert_match('\n(1 of 42): <<mf_hash_init>> mf_hash_init(&ht);', a) + call assert_equal(' mf_hash_init(&ht);', getline('.')) + endfor + + " Test 4: Find functions calling this function + for cmd in ['cs find c test_mf_hash', 'cs find 3 test_mf_hash'] + let a = execute(cmd) + call assert_match('\n(1 of 1): <<main>> test_mf_hash();', a) + call assert_equal(' test_mf_hash();', getline('.')) + endfor + + " Test 5: Find this text string + for cmd in ['cs find t Bram', 'cs find 4 Bram'] + let a = execute(cmd) + call assert_match('(1 of 1): <<<unknown>>> \* VIM - Vi IMproved^Iby Bram Moolenaar', a) + call assert_equal(' * VIM - Vi IMproved by Bram Moolenaar', getline('.')) + endfor + + " Test 6: Find this egrep pattern + " test all matches returned by cscope + for cmd in ['cs find e ^\#includ.', 'cs find 6 ^\#includ.'] + let a = execute(cmd) + call assert_match('\n(1 of 3): <<<unknown>>> #include <assert.h>', a) + call assert_equal('#include <assert.h>', getline('.')) + cnext + call assert_equal('#include "main.c"', getline('.')) + cnext + call assert_equal('#include "memfile.c"', getline('.')) + call assert_fails('cnext', 'E553:') + endfor + + " Test 7: Find the same egrep pattern using lcscope this time. + let a = execute('lcs find e ^\#includ.') + call assert_match('\n(1 of 3): <<<unknown>>> #include <assert.h>', a) + call assert_equal('#include <assert.h>', getline('.')) + lnext + call assert_equal('#include "main.c"', getline('.')) + lnext + call assert_equal('#include "memfile.c"', getline('.')) + call assert_fails('lnext', 'E553:') + + " Test 8: Find this file + for cmd in ['cs find f Xmemfile_test.c', 'cs find 7 Xmemfile_test.c'] + enew + let a = execute(cmd) + call assert_true(a =~ '"Xmemfile_test.c" \d\+L, \d\+C') + call assert_equal('Xmemfile_test.c', @%) + endfor + + " Test 9: Find files #including this file + for cmd in ['cs find i assert.h', 'cs find 8 assert.h'] + enew + let a = execute(cmd) + let alines = split(a, '\n', 1) + call assert_equal('', alines[0]) + call assert_true(alines[1] =~ '"Xmemfile_test.c" \d\+L, \d\+C') + call assert_equal('(1 of 1): <<global>> #include <assert.h>', alines[2]) + call assert_equal('#include <assert.h>', getline('.')) + endfor + + " Test 10: Invalid find command + call assert_fails('cs find x', 'E560:') + + " Test 11: Find places where this symbol is assigned a value + " this needs a cscope >= 15.8 + " unfortunately, Travis has cscope version 15.7 + let cscope_version = systemlist('cscope --version')[0] + let cs_version = str2float(matchstr(cscope_version, '\d\+\(\.\d\+\)\?')) + if cs_version >= 15.8 + for cmd in ['cs find a item', 'cs find 9 item'] + let a = execute(cmd) + call assert_equal(['', '(1 of 4): <<test_mf_hash>> item = (mf_hashitem_T *)lalloc_clear(sizeof(mf_hashtab_T), FALSE);'], split(a, '\n', 1)) + call assert_equal(' item = (mf_hashitem_T *)lalloc_clear(sizeof(mf_hashtab_T), FALSE);', getline('.')) + cnext + call assert_equal(' item = mf_hash_find(&ht, key);', getline('.')) + cnext + call assert_equal(' item = mf_hash_find(&ht, key);', getline('.')) + cnext + call assert_equal(' item = mf_hash_find(&ht, key);', getline('.')) + endfor + endif + + " Test 12: leading whitespace is not removed for cscope find text + let a = execute('cscope find t test_mf_hash') + call assert_equal(['', '(1 of 1): <<<unknown>>> test_mf_hash();'], split(a, '\n', 1)) + call assert_equal(' test_mf_hash();', getline('.')) + + " Test 13: test with scscope + let a = execute('scs find t Bram') + call assert_match('(1 of 1): <<<unknown>>> \* VIM - Vi IMproved^Iby Bram Moolenaar', a) + call assert_equal(' * VIM - Vi IMproved by Bram Moolenaar', getline('.')) + + " Test 14: cscope help + for cmd in ['cs', 'cs help', 'cs xxx'] + let a = execute(cmd) + call assert_match('^cscope commands:\n', a) + call assert_match('\nadd :', a) + call assert_match('\nfind :', a) + call assert_match('\nhelp : Show this message', a) + call assert_match('\nkill : Kill a connection', a) + call assert_match('\nreset: Reinit all connections', a) + call assert_match('\nshow : Show connections', a) + endfor + let a = execute('scscope help') + call assert_match('This cscope command does not support splitting the window\.', a) + + " Test 15: reset connections + let a = execute('cscope reset') + call assert_match('\nAdded cscope database.*Xcscope.out (#0)', a) + call assert_match('\nAll cscope databases reset', a) + + " Test 16: cscope show + let a = execute('cscope show') + call assert_match('\n 0 \d\+.*Xcscope.out\s*<none>', a) + + " Test 17: cstag and 'csto' option + set csto=0 + let a = execute('cstag TEST_COUNT') + call assert_match('(1 of 1): <<TEST_COUNT>> #define TEST_COUNT 50000', a) + call assert_equal('#define TEST_COUNT 50000', getline('.')) + set csto=1 + let a = execute('cstag index_to_key') + call assert_match('(1 of 1): <<index_to_key>> #define index_to_key(i) ((i) ^ 15167)', a) + call assert_equal('#define index_to_key(i) ((i) ^ 15167)', getline('.')) + call assert_fails('cstag xxx', 'E257:') + call assert_fails('cstag', 'E562:') + + " Test 18: 'cst' option + set nocst + call assert_fails('tag TEST_COUNT', 'E426:') + set cst + let a = execute('tag TEST_COUNT') + call assert_match('(1 of 1): <<TEST_COUNT>> #define TEST_COUNT 50000', a) + call assert_equal('#define TEST_COUNT 50000', getline('.')) + let a = execute('tags') + call assert_match('1 1 TEST_COUNT\s\+\d\+\s\+#define index_to_key', a) + + " Test 19: this should trigger call to cs_print_tags() + " Unclear how to check result though, we just exercise the code. + set cst cscopequickfix=s0 + call feedkeys(":cs find s main\<CR>", 't') + + " Test 20: cscope kill + call assert_fails('cscope kill 2', 'E261:') + call assert_fails('cscope kill xxx', 'E261:') + + let a = execute('cscope kill 0') + call assert_match('cscope connection 0 closed', a) + + cscope add Xcscope.out + let a = execute('cscope kill Xcscope.out') + call assert_match('cscope connection Xcscope.out closed', a) + + cscope add Xcscope.out . + let a = execute('cscope kill -1') + call assert_match('cscope connection .*Xcscope.out closed', a) + let a = execute('cscope kill -1') + call assert_equal('', a) + + " Test 21: 'csprg' option + call assert_equal('cscope', &csprg) + set csprg=doesnotexist + call assert_fails('cscope add Xcscope2.out', 'E609:') + set csprg=cscope + + " Test 22: multiple cscope connections + cscope add Xcscope.out + cscope add Xcscope2.out . -C + let a = execute('cscope show') + call assert_match('\n 0 \d\+.*Xcscope.out\s*<none>', a) + call assert_match('\n 1 \d\+.*Xcscope2.out\s*\.', a) + + " Test 23: test Ex command line completion + call feedkeys(":cs \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"cs add find help kill reset show', @:) + + call feedkeys(":scs \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"scs find', @:) + + call feedkeys(":cs find \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"cs find a c d e f g i s t', @:) + + call feedkeys(":cs kill \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"cs kill -1 0 1', @:) + + call feedkeys(":cs add Xcscope\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"cs add Xcscope.out Xcscope2.out', @:) + + " Test 24: cscope_connection() + call assert_equal(cscope_connection(), 1) + call assert_equal(cscope_connection(0, 'out'), 1) + call assert_equal(cscope_connection(0, 'xxx'), 1) + call assert_equal(cscope_connection(1, 'out'), 1) + call assert_equal(cscope_connection(1, 'xxx'), 0) + call assert_equal(cscope_connection(2, 'out'), 0) + call assert_equal(cscope_connection(3, 'xxx', '..'), 0) + call assert_equal(cscope_connection(3, 'out', 'xxx'), 0) + call assert_equal(cscope_connection(3, 'out', '.'), 1) + call assert_equal(cscope_connection(4, 'out', '.'), 0) + + " CleanUp + call CscopeSetupOrClean(0) +endfunc + +" Test ":cs add {dir}" (add the {dir}/cscope.out database) +func Test_cscope_add_dir() + call mkdir('Xcscopedir', 'p') + + " Cscope doesn't handle symlinks, so this needs to be resolved in case a + " shadow directory is being used. + let memfile = resolve('../memfile_test.c') + call system('cscope -bk -fXcscopedir/cscope.out ' . memfile) + + cs add Xcscopedir + let a = execute('cscope show') + let lines = split(a, "\n", 1) + call assert_equal(3, len(lines)) + call assert_equal(' # pid database name prepend path', lines[0]) + call assert_equal('', lines[1]) + call assert_match('^ 0 \d\+.*Xcscopedir/cscope.out\s\+<none>$', lines[2]) + + cs kill -1 + call delete('Xcscopedir/cscope.out') + call assert_fails('cs add Xcscopedir', 'E563:') + + call delete('Xcscopedir', 'd') +endfunc + +func Test_cscopequickfix() + set cscopequickfix=s-,g-,d+,c-,t+,e-,f0,i-,a- + call assert_equal('s-,g-,d+,c-,t+,e-,f0,i-,a-', &cscopequickfix) + + call assert_fails('set cscopequickfix=x-', 'E474:') + call assert_fails('set cscopequickfix=s', 'E474:') + call assert_fails('set cscopequickfix=s7', 'E474:') + call assert_fails('set cscopequickfix=s-a', 'E474:') +endfunc + +func Test_withoutCscopeConnection() + call assert_equal(cscope_connection(), 0) + + call assert_fails('cscope find s main', 'E567:') + let a = execute('cscope show') + call assert_match('no cscope connections', a) +endfunc + + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_cursor_func.vim b/src/testdir/test_cursor_func.vim new file mode 100644 index 0000000..a41cc7d --- /dev/null +++ b/src/testdir/test_cursor_func.vim @@ -0,0 +1,68 @@ +" Tests for cursor(). + +func Test_wrong_arguments() + call assert_fails('call cursor(1. 3)', 'E474:') +endfunc + +func Test_move_cursor() + new + call setline(1, ['aaa', 'bbb', 'ccc', 'ddd']) + + call cursor([1, 1, 0, 1]) + call assert_equal([1, 1, 0, 1], getcurpos()[1:]) + call cursor([4, 3, 0, 3]) + call assert_equal([4, 3, 0, 3], getcurpos()[1:]) + + call cursor(2, 2) + call assert_equal([2, 2, 0, 2], getcurpos()[1:]) + " line number zero keeps the line number + call cursor(0, 1) + call assert_equal([2, 1, 0, 1], getcurpos()[1:]) + " col number zero keeps the column + call cursor(3, 0) + call assert_equal([3, 1, 0, 1], getcurpos()[1:]) + " below last line goes to last line + call cursor(9, 1) + call assert_equal([4, 1, 0, 1], getcurpos()[1:]) + + quit! +endfunc + +" Very short version of what matchparen does. +function s:Highlight_Matching_Pair() + let save_cursor = getcurpos() + call setpos('.', save_cursor) +endfunc + +func Test_curswant_with_autocommand() + new + call setline(1, ['func()', '{', '}', '----']) + autocmd! CursorMovedI * call s:Highlight_Matching_Pair() + call test_override("char_avail", 1) + exe "normal! 3Ga\<Down>X\<Esc>" + call test_override("char_avail", 0) + call assert_equal('-X---', getline(4)) + autocmd! CursorMovedI * + quit! +endfunc + +" Tests for behavior of curswant with cursorcolumn/line +func Test_curswant_with_cursorcolumn() + new + call setline(1, ['01234567', '']) + exe "normal! ggf6j" + call assert_equal(6, winsaveview().curswant) + set cursorcolumn + call assert_equal(6, winsaveview().curswant) + quit! +endfunc + +func Test_curswant_with_cursorline() + new + call setline(1, ['01234567', '']) + exe "normal! ggf6j" + call assert_equal(6, winsaveview().curswant) + set cursorline + call assert_equal(6, winsaveview().curswant) + quit! +endfunc diff --git a/src/testdir/test_curswant.vim b/src/testdir/test_curswant.vim new file mode 100644 index 0000000..e54cd4b --- /dev/null +++ b/src/testdir/test_curswant.vim @@ -0,0 +1,23 @@ +" Tests for curswant not changing when setting an option + +func Test_curswant() + new + call append(0, ['1234567890', '12345']) + + normal! ggf8j + call assert_equal(7, winsaveview().curswant) + let &tabstop=&tabstop + call assert_equal(4, winsaveview().curswant) + + normal! ggf8j + call assert_equal(7, winsaveview().curswant) + let &timeoutlen=&timeoutlen + call assert_equal(7, winsaveview().curswant) + + normal! ggf8j + call assert_equal(7, winsaveview().curswant) + let &ttimeoutlen=&ttimeoutlen + call assert_equal(7, winsaveview().curswant) + + enew! +endfunc diff --git a/src/testdir/test_delete.vim b/src/testdir/test_delete.vim new file mode 100644 index 0000000..4686a0d --- /dev/null +++ b/src/testdir/test_delete.vim @@ -0,0 +1,107 @@ +" Test for delete(). + +func Test_file_delete() + split Xfile + call setline(1, ['a', 'b']) + wq + call assert_equal(['a', 'b'], readfile('Xfile')) + call assert_equal(0, delete('Xfile')) + call assert_fails('call readfile("Xfile")', 'E484:') + call assert_equal(-1, delete('Xfile')) + bwipe Xfile +endfunc + +func Test_dir_delete() + call mkdir('Xdir1') + call assert_true(isdirectory('Xdir1')) + call assert_equal(0, delete('Xdir1', 'd')) + call assert_false(isdirectory('Xdir1')) + call assert_equal(-1, delete('Xdir1', 'd')) +endfunc + +func Test_recursive_delete() + call mkdir('Xdir1') + call mkdir('Xdir1/subdir') + call mkdir('Xdir1/empty') + split Xdir1/Xfile + call setline(1, ['a', 'b']) + w + w Xdir1/subdir/Xfile + close + call assert_true(isdirectory('Xdir1')) + call assert_equal(['a', 'b'], readfile('Xdir1/Xfile')) + call assert_true(isdirectory('Xdir1/subdir')) + call assert_equal(['a', 'b'], readfile('Xdir1/subdir/Xfile')) + call assert_true(isdirectory('Xdir1/empty')) + call assert_equal(0, delete('Xdir1', 'rf')) + call assert_false(isdirectory('Xdir1')) + call assert_equal(-1, delete('Xdir1', 'd')) + bwipe Xdir1/Xfile + bwipe Xdir1/subdir/Xfile +endfunc + +func Test_symlink_delete() + if !has('unix') + return + endif + split Xfile + call setline(1, ['a', 'b']) + wq + silent !ln -s Xfile Xlink + " Delete the link, not the file + call assert_equal(0, delete('Xlink')) + call assert_equal(-1, delete('Xlink')) + call assert_equal(0, delete('Xfile')) + bwipe Xfile +endfunc + +func Test_symlink_dir_delete() + if !has('unix') + return + endif + call mkdir('Xdir1') + silent !ln -s Xdir1 Xlink + call assert_true(isdirectory('Xdir1')) + call assert_true(isdirectory('Xlink')) + " Delete the link, not the directory + call assert_equal(0, delete('Xlink')) + call assert_equal(-1, delete('Xlink')) + call assert_equal(0, delete('Xdir1', 'd')) +endfunc + +func Test_symlink_recursive_delete() + if !has('unix') + return + endif + call mkdir('Xdir3') + call mkdir('Xdir3/subdir') + call mkdir('Xdir4') + split Xdir3/Xfile + call setline(1, ['a', 'b']) + w + w Xdir3/subdir/Xfile + w Xdir4/Xfile + close + silent !ln -s ../Xdir4 Xdir3/Xlink + + call assert_true(isdirectory('Xdir3')) + call assert_equal(['a', 'b'], readfile('Xdir3/Xfile')) + call assert_true(isdirectory('Xdir3/subdir')) + call assert_equal(['a', 'b'], readfile('Xdir3/subdir/Xfile')) + call assert_true(isdirectory('Xdir4')) + call assert_true(isdirectory('Xdir3/Xlink')) + call assert_equal(['a', 'b'], readfile('Xdir4/Xfile')) + + call assert_equal(0, delete('Xdir3', 'rf')) + call assert_false(isdirectory('Xdir3')) + call assert_equal(-1, delete('Xdir3', 'd')) + " symlink is deleted, not the directory it points to + call assert_true(isdirectory('Xdir4')) + call assert_equal(['a', 'b'], readfile('Xdir4/Xfile')) + call assert_equal(0, delete('Xdir4/Xfile')) + call assert_equal(0, delete('Xdir4', 'd')) + + bwipe Xdir3/Xfile + bwipe Xdir3/subdir/Xfile + bwipe Xdir4/Xfile +endfunc diff --git a/src/testdir/test_diffmode.vim b/src/testdir/test_diffmode.vim new file mode 100644 index 0000000..84fb451 --- /dev/null +++ b/src/testdir/test_diffmode.vim @@ -0,0 +1,915 @@ +" Tests for diff mode +source shared.vim +source screendump.vim + +func Test_diff_fold_sync() + enew! + let g:update_count = 0 + au DiffUpdated * let g:update_count += 1 + + let l = range(50) + call setline(1, l) + diffthis + let winone = win_getid() + new + let l[25] = 'diff' + call setline(1, l) + diffthis + let wintwo = win_getid() + " line 15 is inside the closed fold + call assert_equal(19, foldclosedend(10)) + call win_gotoid(winone) + call assert_equal(19, foldclosedend(10)) + " open the fold + normal zv + call assert_equal(-1, foldclosedend(10)) + " fold in other window must have opened too + call win_gotoid(wintwo) + call assert_equal(-1, foldclosedend(10)) + + " cursor position is in sync + normal 23G + call win_gotoid(winone) + call assert_equal(23, getcurpos()[1]) + + call assert_equal(1, g:update_count) + au! DiffUpdated + + windo diffoff + close! + set nomodified +endfunc + +func Test_vert_split() + set diffopt=filler + call Common_vert_split() + set diffopt& +endfunc + +func Test_vert_split_internal() + set diffopt=internal,filler + call Common_vert_split() + set diffopt& +endfunc + +func Common_vert_split() + " Disable the title to avoid xterm keeping the wrong one. + set notitle noicon + new + let l = ['1 aa', '2 bb', '3 cc', '4 dd', '5 ee'] + call setline(1, l) + w! Xtest + normal dd + $ + put + normal kkrXoxxx + w! Xtest2 + file Nop + normal ggoyyyjjjozzzz + set foldmethod=marker foldcolumn=4 + call assert_equal(0, &diff) + call assert_equal('marker', &foldmethod) + call assert_equal(4, &foldcolumn) + call assert_equal(0, &scrollbind) + call assert_equal(0, &cursorbind) + call assert_equal(1, &wrap) + + vert diffsplit Xtest + vert diffsplit Xtest2 + call assert_equal(1, &diff) + call assert_equal('diff', &foldmethod) + call assert_equal(2, &foldcolumn) + call assert_equal(1, &scrollbind) + call assert_equal(1, &cursorbind) + call assert_equal(0, &wrap) + + let diff_fdm = &fdm + let diff_fdc = &fdc + " repeat entering diff mode here to see if this saves the wrong settings + diffthis + " jump to second window for a moment to have filler line appear at start of + " first window + wincmd w + normal gg + wincmd p + normal gg + call assert_equal(2, winline()) + normal j + call assert_equal(4, winline()) + normal j + call assert_equal(5, winline()) + normal j + call assert_equal(6, winline()) + normal j + call assert_equal(8, winline()) + normal j + call assert_equal(9, winline()) + + wincmd w + normal gg + call assert_equal(1, winline()) + normal j + call assert_equal(2, winline()) + normal j + call assert_equal(4, winline()) + normal j + call assert_equal(5, winline()) + normal j + call assert_equal(8, winline()) + + wincmd w + normal gg + call assert_equal(2, winline()) + normal j + call assert_equal(3, winline()) + normal j + call assert_equal(4, winline()) + normal j + call assert_equal(5, winline()) + normal j + call assert_equal(6, winline()) + normal j + call assert_equal(7, winline()) + normal j + call assert_equal(8, winline()) + + " Test diffoff + diffoff! + 1wincmd 2 + let &diff = 1 + let &fdm = diff_fdm + let &fdc = diff_fdc + 4wincmd w + diffoff! + 1wincmd w + call assert_equal(0, &diff) + call assert_equal('marker', &foldmethod) + call assert_equal(4, &foldcolumn) + call assert_equal(0, &scrollbind) + call assert_equal(0, &cursorbind) + call assert_equal(1, &wrap) + + wincmd w + call assert_equal(0, &diff) + call assert_equal('marker', &foldmethod) + call assert_equal(4, &foldcolumn) + call assert_equal(0, &scrollbind) + call assert_equal(0, &cursorbind) + call assert_equal(1, &wrap) + + wincmd w + call assert_equal(0, &diff) + call assert_equal('marker', &foldmethod) + call assert_equal(4, &foldcolumn) + call assert_equal(0, &scrollbind) + call assert_equal(0, &cursorbind) + call assert_equal(1, &wrap) + + call delete('Xtest') + call delete('Xtest2') + windo bw! +endfunc + +func Test_filler_lines() + " Test that diffing shows correct filler lines + enew! + put =range(4,10) + 1d _ + vnew + put =range(1,10) + 1d _ + windo diffthis + wincmd h + call assert_equal(1, line('w0')) + unlet! diff_fdm diff_fdc + windo diffoff + bwipe! + enew! +endfunc + +func Test_diffget_diffput() + enew! + let l = range(50) + call setline(1, l) + call assert_fails('diffget', 'E99:') + diffthis + call assert_fails('diffget', 'E100:') + new + let l[10] = 'one' + let l[20] = 'two' + let l[30] = 'three' + let l[40] = 'four' + call setline(1, l) + diffthis + call assert_equal('one', getline(11)) + 11diffget + call assert_equal('10', getline(11)) + 21diffput + wincmd w + call assert_equal('two', getline(21)) + normal 31Gdo + call assert_equal('three', getline(31)) + call assert_equal('40', getline(41)) + normal 41Gdp + wincmd w + call assert_equal('40', getline(41)) + new + diffthis + call assert_fails('diffget', 'E101:') + + windo diffoff + %bwipe! +endfunc + +" Test putting two changes from one buffer to another +func Test_diffput_two() + new a + let win_a = win_getid() + call setline(1, range(1, 10)) + diffthis + new b + let win_b = win_getid() + call setline(1, range(1, 10)) + 8del + 5del + diffthis + call win_gotoid(win_a) + %diffput + call win_gotoid(win_b) + call assert_equal(map(range(1, 10), 'string(v:val)'), getline(1, '$')) + bwipe! a + bwipe! b +endfunc + +func Test_dp_do_buffer() + e! one + let bn1=bufnr('%') + let l = range(60) + call setline(1, l) + diffthis + + new two + let l[10] = 'one' + let l[20] = 'two' + let l[30] = 'three' + let l[40] = 'four' + let l[50] = 'five' + call setline(1, l) + diffthis + + " dp and do with invalid buffer number. + 11 + call assert_fails('norm 99999dp', 'E102:') + call assert_fails('norm 99999do', 'E102:') + call assert_fails('diffput non_existing_buffer', 'E94:') + call assert_fails('diffget non_existing_buffer', 'E94:') + + " dp and do with valid buffer number. + call assert_equal('one', getline('.')) + exe 'norm ' . bn1 . 'do' + call assert_equal('10', getline('.')) + 21 + call assert_equal('two', getline('.')) + diffget one + call assert_equal('20', getline('.')) + + 31 + exe 'norm ' . bn1 . 'dp' + 41 + diffput one + wincmd w + 31 + call assert_equal('three', getline('.')) + 41 + call assert_equal('four', getline('.')) + + " dp and do with buffer number which is not in diff mode. + new not_in_diff_mode + let bn3=bufnr('%') + wincmd w + 51 + call assert_fails('exe "norm" . bn3 . "dp"', 'E103:') + call assert_fails('exe "norm" . bn3 . "do"', 'E103:') + call assert_fails('diffput not_in_diff_mode', 'E94:') + call assert_fails('diffget not_in_diff_mode', 'E94:') + + windo diffoff + %bwipe! +endfunc + +func Test_do_lastline() + e! one + call setline(1, ['1','2','3','4','5','6']) + diffthis + + new two + call setline(1, ['2','4','5']) + diffthis + + 1 + norm dp]c + norm dp]c + wincmd w + call assert_equal(4, line('$')) + norm G + norm do + call assert_equal(3, line('$')) + + windo diffoff + %bwipe! +endfunc + +func Test_diffoff() + enew! + call setline(1, ['Two', 'Three']) + redraw + let normattr = screenattr(1, 1) + diffthis + botright vert new + call setline(1, ['One', '', 'Two', 'Three']) + diffthis + redraw + call assert_notequal(normattr, screenattr(1, 1)) + diffoff! + redraw + call assert_equal(normattr, screenattr(1, 1)) + bwipe! + bwipe! +endfunc + +func Common_icase_test() + edit one + call setline(1, ['One', 'Two', 'Three', 'Four', 'Fi#ve']) + redraw + let normattr = screenattr(1, 1) + diffthis + + botright vert new two + call setline(1, ['one', 'TWO', 'Three ', 'Four', 'fI=VE']) + diffthis + + redraw + call assert_equal(normattr, screenattr(1, 1)) + call assert_equal(normattr, screenattr(2, 1)) + call assert_notequal(normattr, screenattr(3, 1)) + call assert_equal(normattr, screenattr(4, 1)) + + let dtextattr = screenattr(5, 3) + call assert_notequal(dtextattr, screenattr(5, 1)) + call assert_notequal(dtextattr, screenattr(5, 5)) + + diffoff! + %bwipe! +endfunc + +func Test_diffopt_icase() + set diffopt=icase,foldcolumn:0 + call Common_icase_test() + set diffopt& +endfunc + +func Test_diffopt_icase_internal() + set diffopt=icase,foldcolumn:0,internal + call Common_icase_test() + set diffopt& +endfunc + +func Common_iwhite_test() + edit one + " Difference in trailing spaces and amount of spaces should be ignored, + " but not other space differences. + call setline(1, ["One \t", 'Two', 'Three', 'one two', 'one two', 'Four']) + redraw + let normattr = screenattr(1, 1) + diffthis + + botright vert new two + call setline(1, ["One\t ", "Two\t ", 'Three', 'one two', 'onetwo', ' Four']) + diffthis + + redraw + call assert_equal(normattr, screenattr(1, 1)) + call assert_equal(normattr, screenattr(2, 1)) + call assert_equal(normattr, screenattr(3, 1)) + call assert_equal(normattr, screenattr(4, 1)) + call assert_notequal(normattr, screenattr(5, 1)) + call assert_notequal(normattr, screenattr(6, 1)) + + diffoff! + %bwipe! +endfunc + +func Test_diffopt_iwhite() + set diffopt=iwhite,foldcolumn:0 + call Common_iwhite_test() + set diffopt& +endfunc + +func Test_diffopt_iwhite_internal() + set diffopt=internal,iwhite,foldcolumn:0 + call Common_iwhite_test() + set diffopt& +endfunc + +func Test_diffopt_context() + enew! + call setline(1, ['1', '2', '3', '4', '5', '6', '7']) + diffthis + new + call setline(1, ['1', '2', '3', '4', '5x', '6', '7']) + diffthis + + set diffopt=context:2 + call assert_equal('+-- 2 lines: 1', foldtextresult(1)) + set diffopt=internal,context:2 + call assert_equal('+-- 2 lines: 1', foldtextresult(1)) + + set diffopt=context:1 + call assert_equal('+-- 3 lines: 1', foldtextresult(1)) + set diffopt=internal,context:1 + call assert_equal('+-- 3 lines: 1', foldtextresult(1)) + + diffoff! + %bwipe! + set diffopt& +endfunc + +func Test_diffopt_horizontal() + set diffopt=internal,horizontal + diffsplit + + call assert_equal(&columns, winwidth(1)) + call assert_equal(&columns, winwidth(2)) + call assert_equal(&lines, winheight(1) + winheight(2) + 3) + call assert_inrange(0, 1, winheight(1) - winheight(2)) + + set diffopt& + diffoff! + %bwipe +endfunc + +func Test_diffopt_vertical() + set diffopt=internal,vertical + diffsplit + + call assert_equal(&lines - 2, winheight(1)) + call assert_equal(&lines - 2, winheight(2)) + call assert_equal(&columns, winwidth(1) + winwidth(2) + 1) + call assert_inrange(0, 1, winwidth(1) - winwidth(2)) + + set diffopt& + diffoff! + %bwipe +endfunc + +func Test_diffopt_hiddenoff() + set diffopt=internal,filler,foldcolumn:0,hiddenoff + e! one + call setline(1, ['Two', 'Three']) + redraw + let normattr = screenattr(1, 1) + diffthis + botright vert new two + call setline(1, ['One', 'Four']) + diffthis + redraw + call assert_notequal(normattr, screenattr(1, 1)) + set hidden + close + redraw + " should not diffing with hidden buffer two while 'hiddenoff' is enabled + call assert_equal(normattr, screenattr(1, 1)) + + bwipe! + bwipe! + set hidden& diffopt& +endfunc + +func Test_diffoff_hidden() + set diffopt=internal,filler,foldcolumn:0 + e! one + call setline(1, ['Two', 'Three']) + redraw + let normattr = screenattr(1, 1) + diffthis + botright vert new two + call setline(1, ['One', 'Four']) + diffthis + redraw + call assert_notequal(normattr, screenattr(1, 1)) + set hidden + close + redraw + " diffing with hidden buffer two + call assert_notequal(normattr, screenattr(1, 1)) + diffoff + redraw + call assert_equal(normattr, screenattr(1, 1)) + diffthis + redraw + " still diffing with hidden buffer two + call assert_notequal(normattr, screenattr(1, 1)) + diffoff! + redraw + call assert_equal(normattr, screenattr(1, 1)) + diffthis + redraw + " no longer diffing with hidden buffer two + call assert_equal(normattr, screenattr(1, 1)) + + bwipe! + bwipe! + set hidden& diffopt& +endfunc + +func Test_setting_cursor() + new Xtest1 + put =range(1,90) + wq + new Xtest2 + put =range(1,100) + wq + + tabe Xtest2 + $ + diffsp Xtest1 + tabclose + + call delete('Xtest1') + call delete('Xtest2') +endfunc + +func Test_diff_move_to() + new + call setline(1, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + diffthis + vnew + call setline(1, [1, '2x', 3, 4, 4, 5, '6x', 7, '8x', 9, '10x']) + diffthis + norm ]c + call assert_equal(2, line('.')) + norm 3]c + call assert_equal(9, line('.')) + norm 10]c + call assert_equal(11, line('.')) + norm [c + call assert_equal(9, line('.')) + norm 2[c + call assert_equal(5, line('.')) + norm 10[c + call assert_equal(2, line('.')) + %bwipe! +endfunc + +func Test_diffexpr() + if !executable('diff') + return + endif + + func DiffExpr() + " Prepent some text to check diff type detection + call writefile(['warning', ' message'], v:fname_out) + silent exe '!diff ' . v:fname_in . ' ' . v:fname_new . '>>' . v:fname_out + endfunc + set diffexpr=DiffExpr() + set diffopt=foldcolumn:0 + + enew! + call setline(1, ['one', 'two', 'three']) + redraw + let normattr = screenattr(1, 1) + diffthis + + botright vert new + call setline(1, ['one', 'two', 'three.']) + diffthis + + redraw + call assert_equal(normattr, screenattr(1, 1)) + call assert_equal(normattr, screenattr(2, 1)) + call assert_notequal(normattr, screenattr(3, 1)) + + diffoff! + %bwipe! + set diffexpr& diffopt& +endfunc + +func Test_diffpatch() + " The patch program on MS-Windows may fail or hang. + if !executable('patch') || !has('unix') + return + endif + new + insert +*************** +*** 1,3 **** + 1 +! 2 + 3 +--- 1,4 ---- + 1 +! 2x + 3 ++ 4 +. + saveas! Xpatch + bwipe! + new + call assert_fails('diffpatch Xpatch', 'E816:') + + for name in ['Xpatch', 'Xpatch$HOME', 'Xpa''tch'] + call setline(1, ['1', '2', '3']) + if name != 'Xpatch' + call rename('Xpatch', name) + endif + exe 'diffpatch ' . escape(name, '$') + call assert_equal(['1', '2x', '3', '4'], getline(1, '$')) + if name != 'Xpatch' + call rename(name, 'Xpatch') + endif + bwipe! + endfor + + call delete('Xpatch') + bwipe! +endfunc + +func Test_diff_too_many_buffers() + for i in range(1, 8) + exe "new Xtest" . i + diffthis + endfor + new Xtest9 + call assert_fails('diffthis', 'E96:') + %bwipe! +endfunc + +func Test_diff_nomodifiable() + new + call setline(1, [1, 2, 3, 4]) + setl nomodifiable + diffthis + vnew + call setline(1, ['1x', 2, 3, 3, 4]) + diffthis + call assert_fails('norm dp', 'E793:') + setl nomodifiable + call assert_fails('norm do', 'E21:') + %bwipe! +endfunc + +func Test_diff_hlID() + new + call setline(1, [1, 2, 3]) + diffthis + vnew + call setline(1, ['1x', 2, 'x', 3]) + diffthis + redraw + + call assert_equal(synIDattr(diff_hlID(-1, 1), "name"), "") + + call assert_equal(synIDattr(diff_hlID(1, 1), "name"), "DiffChange") + call assert_equal(synIDattr(diff_hlID(1, 2), "name"), "DiffText") + call assert_equal(synIDattr(diff_hlID(2, 1), "name"), "") + call assert_equal(synIDattr(diff_hlID(3, 1), "name"), "DiffAdd") + call assert_equal(synIDattr(diff_hlID(4, 1), "name"), "") + + wincmd w + call assert_equal(synIDattr(diff_hlID(1, 1), "name"), "DiffChange") + call assert_equal(synIDattr(diff_hlID(2, 1), "name"), "") + call assert_equal(synIDattr(diff_hlID(3, 1), "name"), "") + + %bwipe! +endfunc + +func Test_diff_filler() + new + call setline(1, [1, 2, 3, 'x', 4]) + diffthis + vnew + call setline(1, [1, 2, 'y', 'y', 3, 4]) + diffthis + redraw + + call assert_equal([0, 0, 0, 0, 0, 0, 0, 1, 0], map(range(-1, 7), 'diff_filler(v:val)')) + wincmd w + call assert_equal([0, 0, 0, 0, 2, 0, 0, 0], map(range(-1, 6), 'diff_filler(v:val)')) + + %bwipe! +endfunc + +func Test_diff_lastline() + enew! + only! + call setline(1, ['This is a ', 'line with five ', 'rows']) + diffthis + botright vert new + call setline(1, ['This is', 'a line with ', 'four rows']) + diffthis + 1 + call feedkeys("Je a\<CR>", 'tx') + call feedkeys("Je a\<CR>", 'tx') + let w1lines = winline() + wincmd w + $ + let w2lines = winline() + call assert_equal(w2lines, w1lines) + bwipe! + bwipe! +endfunc + +func WriteDiffFiles(buf, list1, list2) + call writefile(a:list1, 'Xfile1') + call writefile(a:list2, 'Xfile2') + if a:buf + call term_sendkeys(a:buf, ":checktime\<CR>") + endif +endfunc + +" Verify a screendump with both the internal and external diff. +func VerifyBoth(buf, dumpfile, extra) + " trailing : for leaving the cursor on the command line + for cmd in [":set diffopt=filler" . a:extra . "\<CR>:", ":set diffopt+=internal\<CR>:"] + call term_sendkeys(a:buf, cmd) + if VerifyScreenDump(a:buf, a:dumpfile, {}, cmd =~ 'internal' ? 'internal' : 'external') + break " don't let the next iteration overwrite the "failed" file. + endif + endfor +endfunc + +" Verify a screendump with the internal diff only. +func VerifyInternal(buf, dumpfile, extra) + call term_sendkeys(a:buf, ":diffupdate!\<CR>") + " trailing : for leaving the cursor on the command line + call term_sendkeys(a:buf, ":set diffopt=internal,filler" . a:extra . "\<CR>:") + call VerifyScreenDump(a:buf, a:dumpfile, {}) +endfunc + +func Test_diff_screen() + if !CanRunVimInTerminal() || !has('menu') + return + endif + " clean up already existing swap files, just in case + call delete('.Xfile1.swp') + call delete('.Xfile2.swp') + + " Test 1: Add a line in beginning of file 2 + call WriteDiffFiles(0, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + let buf = RunVimInTerminal('-d Xfile1 Xfile2', {}) + " Set autoread mode, ,so that Vim won't complain once we re-write the test + " files + call term_sendkeys(buf, ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w") + + call VerifyBoth(buf, 'Test_diff_01', '') + + " Test 2: Add a line in beginning of file 1 + call WriteDiffFiles(buf, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + call VerifyBoth(buf, 'Test_diff_02', '') + + " Test 3: Add a line at the end of file 2 + call WriteDiffFiles(buf, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) + call VerifyBoth(buf, 'Test_diff_03', '') + + " Test 4: Add a line at the end of file 1 + call WriteDiffFiles(buf, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + call VerifyBoth(buf, 'Test_diff_04', '') + + " Test 5: Add a line in the middle of file 2, remove on at the end of file 1 + call WriteDiffFiles(buf, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [1, 2, 3, 4, 4, 5, 6, 7, 8, 9, 10]) + call VerifyBoth(buf, 'Test_diff_05', '') + + " Test 6: Add a line in the middle of file 1, remove on at the end of file 2 + call WriteDiffFiles(buf, [1, 2, 3, 4, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) + call VerifyBoth(buf, 'Test_diff_06', '') + + " Test 7 - 9: Test normal/patience/histogram diff algorithm + call WriteDiffFiles(buf, ['#include <stdio.h>', '', '// Frobs foo heartily', 'int frobnitz(int foo)', '{', + \ ' int i;', ' for(i = 0; i < 10; i++)', ' {', ' printf("Your answer is: ");', + \ ' printf("%d\n", foo);', ' }', '}', '', 'int fact(int n)', '{', ' if(n > 1)', ' {', + \ ' return fact(n-1) * n;', ' }', ' return 1;', '}', '', 'int main(int argc, char **argv)', + \ '{', ' frobnitz(fact(10));', '}'], + \ ['#include <stdio.h>', '', 'int fib(int n)', '{', ' if(n > 2)', ' {', + \ ' return fib(n-1) + fib(n-2);', ' }', ' return 1;', '}', '', '// Frobs foo heartily', + \ 'int frobnitz(int foo)', '{', ' int i;', ' for(i = 0; i < 10; i++)', ' {', + \ ' printf("%d\n", foo);', ' }', '}', '', + \ 'int main(int argc, char **argv)', '{', ' frobnitz(fib(10));', '}']) + call term_sendkeys(buf, ":diffupdate!\<cr>") + call term_sendkeys(buf, ":set diffopt+=internal\<cr>") + call VerifyScreenDump(buf, 'Test_diff_07', {}) + + call term_sendkeys(buf, ":set diffopt+=algorithm:patience\<cr>") + call VerifyScreenDump(buf, 'Test_diff_08', {}) + + call term_sendkeys(buf, ":set diffopt+=algorithm:histogram\<cr>") + call VerifyScreenDump(buf, 'Test_diff_09', {}) + + " Test 10-11: normal/indent-heuristic + call term_sendkeys(buf, ":set diffopt&vim\<cr>") + call WriteDiffFiles(buf, ['', ' def finalize(values)', '', ' values.each do |v|', ' v.finalize', ' end'], + \ ['', ' def finalize(values)', '', ' values.each do |v|', ' v.prepare', ' end', '', + \ ' values.each do |v|', ' v.finalize', ' end']) + call term_sendkeys(buf, ":diffupdate!\<cr>") + call term_sendkeys(buf, ":set diffopt+=internal\<cr>") + call VerifyScreenDump(buf, 'Test_diff_10', {}) + + " Leave trailing : at commandline! + call term_sendkeys(buf, ":set diffopt+=indent-heuristic\<cr>:\<cr>") + call VerifyScreenDump(buf, 'Test_diff_11', {}, 'one') + " shouldn't matter, if indent-algorithm comes before or after the algorithm + call term_sendkeys(buf, ":set diffopt&\<cr>") + call term_sendkeys(buf, ":set diffopt+=indent-heuristic,algorithm:patience\<cr>:\<cr>") + call VerifyScreenDump(buf, 'Test_diff_11', {}, 'two') + call term_sendkeys(buf, ":set diffopt&\<cr>") + call term_sendkeys(buf, ":set diffopt+=algorithm:patience,indent-heuristic\<cr>:\<cr>") + call VerifyScreenDump(buf, 'Test_diff_11', {}, 'three') + + " Test 12: diff the same file + call WriteDiffFiles(buf, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + call VerifyBoth(buf, 'Test_diff_12', '') + + " Test 13: diff an empty file + call WriteDiffFiles(buf, [], []) + call VerifyBoth(buf, 'Test_diff_13', '') + + " Test 14: test diffopt+=icase + call WriteDiffFiles(buf, ['a', 'b', 'cd'], ['A', 'b', 'cDe']) + call VerifyBoth(buf, 'Test_diff_14', " diffopt+=filler diffopt+=icase") + + " Test 15-16: test diffopt+=iwhite + call WriteDiffFiles(buf, ['int main()', '{', ' printf("Hello, World!");', ' return 0;', '}'], + \ ['int main()', '{', ' if (0)', ' {', ' printf("Hello, World!");', ' return 0;', ' }', '}']) + call term_sendkeys(buf, ":diffupdate!\<cr>") + call term_sendkeys(buf, ":set diffopt&vim diffopt+=filler diffopt+=iwhite\<cr>") + call VerifyScreenDump(buf, 'Test_diff_15', {}) + call term_sendkeys(buf, ":set diffopt+=internal\<cr>") + call VerifyScreenDump(buf, 'Test_diff_16', {}) + + " Test 17: test diffopt+=iblank + call WriteDiffFiles(buf, ['a', ' ', 'cd', 'ef', 'xxx'], ['a', 'cd', '', 'ef', 'yyy']) + call VerifyInternal(buf, 'Test_diff_17', " diffopt+=iblank") + + " Test 18: test diffopt+=iblank,iwhite / iwhiteall / iwhiteeol + call VerifyInternal(buf, 'Test_diff_18', " diffopt+=iblank,iwhite") + call VerifyInternal(buf, 'Test_diff_18', " diffopt+=iblank,iwhiteall") + call VerifyInternal(buf, 'Test_diff_18', " diffopt+=iblank,iwhiteeol") + + " Test 19: test diffopt+=iwhiteeol + call WriteDiffFiles(buf, ['a ', 'x', 'cd', 'ef', 'xx xx', 'foo', 'bar'], ['a', 'x', 'c d', ' ef', 'xx xx', 'foo', '', 'bar']) + call VerifyInternal(buf, 'Test_diff_19', " diffopt+=iwhiteeol") + + " Test 19: test diffopt+=iwhiteall + call VerifyInternal(buf, 'Test_diff_20', " diffopt+=iwhiteall") + + " clean up + call StopVimInTerminal(buf) + call delete('Xfile1') + call delete('Xfile2') +endfunc + +func Test_diff_with_cursorline() + if !CanRunVimInTerminal() + return + endif + + call writefile([ + \ 'hi CursorLine ctermbg=red ctermfg=white', + \ 'set cursorline', + \ 'call setline(1, ["foo","foo","foo","bar"])', + \ 'vnew', + \ 'call setline(1, ["bee","foo","foo","baz"])', + \ 'windo diffthis', + \ '2wincmd w', + \ ], 'Xtest_diff_cursorline') + let buf = RunVimInTerminal('-S Xtest_diff_cursorline', {}) + + call VerifyScreenDump(buf, 'Test_diff_with_cursorline_01', {}) + call term_sendkeys(buf, "j") + call VerifyScreenDump(buf, 'Test_diff_with_cursorline_02', {}) + call term_sendkeys(buf, "j") + call VerifyScreenDump(buf, 'Test_diff_with_cursorline_03', {}) + + " clean up + call StopVimInTerminal(buf) + call delete('Xtest_diff_cursorline') +endfunc + +func Test_diff_of_diff() + if !CanRunVimInTerminal() + return + endif + + call writefile([ + \ 'call setline(1, ["aa","bb","cc","@@ -3,2 +5,7 @@","dd","ee","ff"])', + \ 'vnew', + \ 'call setline(1, ["aa","bb","cc"])', + \ 'windo diffthis', + \ ], 'Xtest_diff_diff') + let buf = RunVimInTerminal('-S Xtest_diff_diff', {}) + + call VerifyScreenDump(buf, 'Test_diff_of_diff_01', {}) + + " clean up + call StopVimInTerminal(buf) + call delete('Xtest_diff_diff') +endfunc diff --git a/src/testdir/test_digraph.vim b/src/testdir/test_digraph.vim new file mode 100644 index 0000000..8d56a1a --- /dev/null +++ b/src/testdir/test_digraph.vim @@ -0,0 +1,477 @@ +" Tests for digraphs + +if !has("digraphs") + finish +endif + +func Put_Dig(chars) + exe "norm! o\<c-k>".a:chars +endfu + +func Put_Dig_BS(char1, char2) + exe "norm! o".a:char1."\<bs>".a:char2 +endfu + +func Test_digraphs() + new + call Put_Dig("00") + call assert_equal("∞", getline('.')) + " not a digraph + call Put_Dig("el") + call assert_equal("l", getline('.')) + call Put_Dig("ht") + call assert_equal("þ", getline('.')) + " digraph "ab" is the same as "ba" + call Put_Dig("ab") + call Put_Dig("ba") + call assert_equal(["ば","ば"], getline(line('.')-1,line('.'))) + " Euro sign + call Put_Dig("e=") + call Put_Dig("=e") + call Put_Dig("Eu") + call Put_Dig("uE") + call assert_equal(['е']+repeat(["€"],3), getline(line('.')-3,line('.'))) + " Rouble sign + call Put_Dig("R=") + call Put_Dig("=R") + call Put_Dig("=P") + call Put_Dig("P=") + call assert_equal(['Р']+repeat(["₽"],2)+['П'], getline(line('.')-3,line('.'))) + " Not a digraph + call Put_Dig("a\<bs>") + call Put_Dig("\<bs>a") + call assert_equal(["<BS>", "<BS>a"], getline(line('.')-1,line('.'))) + " Grave + call Put_Dig("a!") + call Put_Dig("!e") + call Put_Dig("b!") " not defined + call assert_equal(["à", "è", "!"], getline(line('.')-2,line('.'))) + " Acute accent + call Put_Dig("a'") + call Put_Dig("'e") + call Put_Dig("b'") " not defined + call assert_equal(["á", "é", "'"], getline(line('.')-2,line('.'))) + " Cicumflex + call Put_Dig("a>") + call Put_Dig(">e") + call Put_Dig("b>") " not defined + call assert_equal(['â', 'ê', '>'], getline(line('.')-2,line('.'))) + " Tilde + call Put_Dig("o~") + call Put_Dig("~u") " not defined + call Put_Dig("z~") " not defined + call assert_equal(['õ', 'u', '~'], getline(line('.')-2,line('.'))) + " Tilde + call Put_Dig("o?") + call Put_Dig("?u") + call Put_Dig("z?") " not defined + call assert_equal(['õ', 'ũ', '?'], getline(line('.')-2,line('.'))) + " Macron + call Put_Dig("o-") + call Put_Dig("-u") + call Put_Dig("z-") " not defined + call assert_equal(['ō', 'ū', '-'], getline(line('.')-2,line('.'))) + " Breve + call Put_Dig("o(") + call Put_Dig("(u") + call Put_Dig("z(") " not defined + call assert_equal(['ŏ', 'ŭ', '('], getline(line('.')-2,line('.'))) + " Dot above + call Put_Dig("b.") + call Put_Dig(".e") + call Put_Dig("a.") " not defined + call assert_equal(['ḃ', 'ė', '.'], getline(line('.')-2,line('.'))) + " Diaresis + call Put_Dig("a:") + call Put_Dig(":u") + call Put_Dig("b:") " not defined + call assert_equal(['ä', 'ü', ':'], getline(line('.')-2,line('.'))) + " Cedilla + call Put_Dig("',") + call Put_Dig(",C") + call Put_Dig("b,") " not defined + call assert_equal(['¸', 'Ç', ','], getline(line('.')-2,line('.'))) + " Underline + call Put_Dig("B_") + call Put_Dig("_t") + call Put_Dig("a_") " not defined + call assert_equal(['Ḇ', 'ṯ', '_'], getline(line('.')-2,line('.'))) + " Stroke + call Put_Dig("j/") + call Put_Dig("/l") + call Put_Dig("b/") " not defined + call assert_equal(['/', 'ł', '/'], getline(line('.')-2,line('.'))) + " Double acute + call Put_Dig('O"') + call Put_Dig('"y') + call Put_Dig('b"') " not defined + call assert_equal(['Ő', 'ÿ', '"'], getline(line('.')-2,line('.'))) + " Ogonek + call Put_Dig('u;') + call Put_Dig(';E') + call Put_Dig('b;') " not defined + call assert_equal(['ų', 'Ę', ';'], getline(line('.')-2,line('.'))) + " Caron + call Put_Dig('u<') + call Put_Dig('<E') + call Put_Dig('b<') " not defined + call assert_equal(['ǔ', 'Ě', '<'], getline(line('.')-2,line('.'))) + " Ring above + call Put_Dig('u0') + call Put_Dig('0E') " not defined + call Put_Dig('b0') " not defined + call assert_equal(['ů', 'E', '0'], getline(line('.')-2,line('.'))) + " Hook + call Put_Dig('u2') + call Put_Dig('2E') + call Put_Dig('b2') " not defined + call assert_equal(['ủ', 'Ẻ', '2'], getline(line('.')-2,line('.'))) + " Horn + call Put_Dig('u9') + call Put_Dig('9E') " not defined + call Put_Dig('b9') " not defined + call assert_equal(['ư', 'E', '9'], getline(line('.')-2,line('.'))) + " Cyrillic + call Put_Dig('u=') + call Put_Dig('=b') + call Put_Dig('=_') + call assert_equal(['у', 'б', '〓'], getline(line('.')-2,line('.'))) + " Greek + call Put_Dig('u*') + call Put_Dig('*b') + call Put_Dig('*_') + call assert_equal(['υ', 'β', '々'], getline(line('.')-2,line('.'))) + " Greek/Cyrillic special + call Put_Dig('u%') + call Put_Dig('%b') " not defined + call Put_Dig('%_') " not defined + call assert_equal(['ύ', 'b', '_'], getline(line('.')-2,line('.'))) + " Arabic + call Put_Dig('u+') + call Put_Dig('+b') + call Put_Dig('+_') " japanese industrial symbol + call assert_equal(['+', 'ب', '〄'], getline(line('.')-2,line('.'))) + " Hebrew + call Put_Dig('Q+') + call Put_Dig('+B') + call Put_Dig('+X') + call assert_equal(['ק', 'ב', 'ח'], getline(line('.')-2,line('.'))) + " Latin + call Put_Dig('a3') + call Put_Dig('A3') + call Put_Dig('3X') + call assert_equal(['ǣ', 'Ǣ', 'X'], getline(line('.')-2,line('.'))) + " Bopomofo + call Put_Dig('a4') + call Put_Dig('A4') + call Put_Dig('4X') + call assert_equal(['ㄚ', '4', 'X'], getline(line('.')-2,line('.'))) + " Hiragana + call Put_Dig('a5') + call Put_Dig('A5') + call Put_Dig('5X') + call assert_equal(['あ', 'ぁ', 'X'], getline(line('.')-2,line('.'))) + " Katakana + call Put_Dig('a6') + call Put_Dig('A6') + call Put_Dig('6X') + call assert_equal(['ァ', 'ア', 'X'], getline(line('.')-2,line('.'))) + " Superscripts + call Put_Dig('1S') + call Put_Dig('2S') + call Put_Dig('3S') + call assert_equal(['¹', '²', '³'], getline(line('.')-2,line('.'))) + " Subscripts + call Put_Dig('1s') + call Put_Dig('2s') + call Put_Dig('3s') + call assert_equal(['₁', '₂', '₃'], getline(line('.')-2,line('.'))) + " Eszet (only lowercase) + call Put_Dig("ss") + call Put_Dig("SS") " start of string + call assert_equal(["ß", ""], getline(line('.')-1,line('.'))) + " High bit set + call Put_Dig("a ") + call Put_Dig(" A") + call assert_equal(['á', 'Á'], getline(line('.')-1,line('.'))) + " Escape is not part of a digraph + call Put_Dig("a\<esc>") + call Put_Dig("\<esc>A") + call assert_equal(['', 'A'], getline(line('.')-1,line('.'))) + " define some custom digraphs + " old: 00 ∞ + " old: el l + digraph 00 9216 + digraph el 0252 + call Put_Dig("00") + call Put_Dig("el") + " Reset digraphs + digraph 00 8734 + digraph el 108 + call Put_Dig("00") + call Put_Dig("el") + call assert_equal(['␀', 'ü', '∞', 'l'], getline(line('.')-3,line('.'))) + bw! +endfunc + +func Test_digraphs_option() + " reset whichwrap option, so that testing <esc><bs>A works, + " without moving up a line + set digraph ww= + new + call Put_Dig_BS("0","0") + call assert_equal("∞", getline('.')) + " not a digraph + call Put_Dig_BS("e","l") + call assert_equal("l", getline('.')) + call Put_Dig_BS("h","t") + call assert_equal("þ", getline('.')) + " digraph "ab" is the same as "ba" + call Put_Dig_BS("a","b") + call Put_Dig_BS("b","a") + call assert_equal(["ば","ば"], getline(line('.')-1,line('.'))) + " Euro sign + call Put_Dig_BS("e","=") + call Put_Dig_BS("=","e") + call Put_Dig_BS("E","u") + call Put_Dig_BS("u","E") + call assert_equal(['е']+repeat(["€"],3), getline(line('.')-3,line('.'))) + " Rouble sign + call Put_Dig_BS("R","=") + call Put_Dig_BS("=","R") + call Put_Dig_BS("=","P") + call Put_Dig_BS("P","=") + call assert_equal(['Р']+repeat(["₽"],2)+['П'], getline(line('.')-3,line('.'))) + " Not a digraph: this is different from <c-k>! + call Put_Dig_BS("a","\<bs>") + call Put_Dig_BS("\<bs>","a") + call assert_equal(['','a'], getline(line('.')-1,line('.'))) + " Grave + call Put_Dig_BS("a","!") + call Put_Dig_BS("!","e") + call Put_Dig_BS("b","!") " not defined + call assert_equal(["à", "è", "!"], getline(line('.')-2,line('.'))) + " Acute accent + call Put_Dig_BS("a","'") + call Put_Dig_BS("'","e") + call Put_Dig_BS("b","'") " not defined + call assert_equal(["á", "é", "'"], getline(line('.')-2,line('.'))) + " Cicumflex + call Put_Dig_BS("a",">") + call Put_Dig_BS(">","e") + call Put_Dig_BS("b",">") " not defined + call assert_equal(['â', 'ê', '>'], getline(line('.')-2,line('.'))) + " Tilde + call Put_Dig_BS("o","~") + call Put_Dig_BS("~","u") " not defined + call Put_Dig_BS("z","~") " not defined + call assert_equal(['õ', 'u', '~'], getline(line('.')-2,line('.'))) + " Tilde + call Put_Dig_BS("o","?") + call Put_Dig_BS("?","u") + call Put_Dig_BS("z","?") " not defined + call assert_equal(['õ', 'ũ', '?'], getline(line('.')-2,line('.'))) + " Macron + call Put_Dig_BS("o","-") + call Put_Dig_BS("-","u") + call Put_Dig_BS("z","-") " not defined + call assert_equal(['ō', 'ū', '-'], getline(line('.')-2,line('.'))) + " Breve + call Put_Dig_BS("o","(") + call Put_Dig_BS("(","u") + call Put_Dig_BS("z","(") " not defined + call assert_equal(['ŏ', 'ŭ', '('], getline(line('.')-2,line('.'))) + " Dot above + call Put_Dig_BS("b",".") + call Put_Dig_BS(".","e") + call Put_Dig_BS("a",".") " not defined + call assert_equal(['ḃ', 'ė', '.'], getline(line('.')-2,line('.'))) + " Diaresis + call Put_Dig_BS("a",":") + call Put_Dig_BS(":","u") + call Put_Dig_BS("b",":") " not defined + call assert_equal(['ä', 'ü', ':'], getline(line('.')-2,line('.'))) + " Cedilla + call Put_Dig_BS("'",",") + call Put_Dig_BS(",","C") + call Put_Dig_BS("b",",") " not defined + call assert_equal(['¸', 'Ç', ','], getline(line('.')-2,line('.'))) + " Underline + call Put_Dig_BS("B","_") + call Put_Dig_BS("_","t") + call Put_Dig_BS("a","_") " not defined + call assert_equal(['Ḇ', 'ṯ', '_'], getline(line('.')-2,line('.'))) + " Stroke + call Put_Dig_BS("j","/") + call Put_Dig_BS("/","l") + call Put_Dig_BS("b","/") " not defined + call assert_equal(['/', 'ł', '/'], getline(line('.')-2,line('.'))) + " Double acute + call Put_Dig_BS('O','"') + call Put_Dig_BS('"','y') + call Put_Dig_BS('b','"') " not defined + call assert_equal(['Ő', 'ÿ', '"'], getline(line('.')-2,line('.'))) + " Ogonek + call Put_Dig_BS('u',';') + call Put_Dig_BS(';','E') + call Put_Dig_BS('b',';') " not defined + call assert_equal(['ų', 'Ę', ';'], getline(line('.')-2,line('.'))) + " Caron + call Put_Dig_BS('u','<') + call Put_Dig_BS('<','E') + call Put_Dig_BS('b','<') " not defined + call assert_equal(['ǔ', 'Ě', '<'], getline(line('.')-2,line('.'))) + " Ring above + call Put_Dig_BS('u','0') + call Put_Dig_BS('0','E') " not defined + call Put_Dig_BS('b','0') " not defined + call assert_equal(['ů', 'E', '0'], getline(line('.')-2,line('.'))) + " Hook + call Put_Dig_BS('u','2') + call Put_Dig_BS('2','E') + call Put_Dig_BS('b','2') " not defined + call assert_equal(['ủ', 'Ẻ', '2'], getline(line('.')-2,line('.'))) + " Horn + call Put_Dig_BS('u','9') + call Put_Dig_BS('9','E') " not defined + call Put_Dig_BS('b','9') " not defined + call assert_equal(['ư', 'E', '9'], getline(line('.')-2,line('.'))) + " Cyrillic + call Put_Dig_BS('u','=') + call Put_Dig_BS('=','b') + call Put_Dig_BS('=','_') + call assert_equal(['у', 'б', '〓'], getline(line('.')-2,line('.'))) + " Greek + call Put_Dig_BS('u','*') + call Put_Dig_BS('*','b') + call Put_Dig_BS('*','_') + call assert_equal(['υ', 'β', '々'], getline(line('.')-2,line('.'))) + " Greek/Cyrillic special + call Put_Dig_BS('u','%') + call Put_Dig_BS('%','b') " not defined + call Put_Dig_BS('%','_') " not defined + call assert_equal(['ύ', 'b', '_'], getline(line('.')-2,line('.'))) + " Arabic + call Put_Dig_BS('u','+') + call Put_Dig_BS('+','b') + call Put_Dig_BS('+','_') " japanese industrial symbol + call assert_equal(['+', 'ب', '〄'], getline(line('.')-2,line('.'))) + " Hebrew + call Put_Dig_BS('Q','+') + call Put_Dig_BS('+','B') + call Put_Dig_BS('+','X') + call assert_equal(['ק', 'ב', 'ח'], getline(line('.')-2,line('.'))) + " Latin + call Put_Dig_BS('a','3') + call Put_Dig_BS('A','3') + call Put_Dig_BS('3','X') + call assert_equal(['ǣ', 'Ǣ', 'X'], getline(line('.')-2,line('.'))) + " Bopomofo + call Put_Dig_BS('a','4') + call Put_Dig_BS('A','4') + call Put_Dig_BS('4','X') + call assert_equal(['ㄚ', '4', 'X'], getline(line('.')-2,line('.'))) + " Hiragana + call Put_Dig_BS('a','5') + call Put_Dig_BS('A','5') + call Put_Dig_BS('5','X') + call assert_equal(['あ', 'ぁ', 'X'], getline(line('.')-2,line('.'))) + " Katakana + call Put_Dig_BS('a','6') + call Put_Dig_BS('A','6') + call Put_Dig_BS('6','X') + call assert_equal(['ァ', 'ア', 'X'], getline(line('.')-2,line('.'))) + " Superscripts + call Put_Dig_BS('1','S') + call Put_Dig_BS('2','S') + call Put_Dig_BS('3','S') + call assert_equal(['¹', '²', '³'], getline(line('.')-2,line('.'))) + " Subscripts + call Put_Dig_BS('1','s') + call Put_Dig_BS('2','s') + call Put_Dig_BS('3','s') + call assert_equal(['₁', '₂', '₃'], getline(line('.')-2,line('.'))) + " Eszet (only lowercase) + call Put_Dig_BS("s","s") + call Put_Dig_BS("S","S") " start of string + call assert_equal(["ß", ""], getline(line('.')-1,line('.'))) + " High bit set (different from <c-k>) + call Put_Dig_BS("a"," ") + call Put_Dig_BS(" ","A") + call assert_equal([' ', 'A'], getline(line('.')-1,line('.'))) + " Escape is not part of a digraph (different from <c-k>) + call Put_Dig_BS("a","\<esc>") + call Put_Dig_BS("\<esc>","A") + call assert_equal(['', ''], getline(line('.')-1,line('.'))) + " define some custom digraphs + " old: 00 ∞ + " old: el l + digraph 00 9216 + digraph el 0252 + call Put_Dig_BS("0","0") + call Put_Dig_BS("e","l") + " Reset digraphs + digraph 00 8734 + digraph el 108 + call Put_Dig_BS("0","0") + call Put_Dig_BS("e","l") + call assert_equal(['␀', 'ü', '∞', 'l'], getline(line('.')-3,line('.'))) + set nodigraph ww&vim + bw! +endfunc + +func Test_digraphs_output() + new + let out = execute(':digraph') + call assert_equal('Eu € 8364', matchstr(out, '\C\<Eu\D*8364\>')) + call assert_equal('=e € 8364', matchstr(out, '\C=e\D*8364\>')) + call assert_equal('=R ₽ 8381', matchstr(out, '\C=R\D*8381\>')) + call assert_equal('=P ₽ 8381', matchstr(out, '\C=P\D*8381\>')) + call assert_equal('o: ö 246', matchstr(out, '\C\<o:\D*246\>')) + call assert_equal('v4 ㄪ 12586', matchstr(out, '\C\<v4\D*12586\>')) + call assert_equal("'0 ˚ 730", matchstr(out, '\C''0\D*730\>')) + call assert_equal('Z% Ж 1046', matchstr(out, '\C\<Z%\D*1046\>')) + call assert_equal('u- ū 363', matchstr(out, '\C\<u-\D*363\>')) + call assert_equal('SH ^A 1', matchstr(out, '\C\<SH\D*1\>')) + bw! +endfunc + +func Test_loadkeymap() + if !has('keymap') + return + endif + new + set keymap=czech + set iminsert=0 + call feedkeys("o|\<c-^>|01234567890|\<esc>", 'tx') + call assert_equal("|'é+ěščřžýáíé'", getline('.')) + " reset keymap and encoding option + set keymap= + bw! +endfunc + +func Test_digraph_cmndline() + " Create digraph on commandline + " This is a hack, to let Vim create the digraph in commandline mode + let s = '' + exe "sil! norm! :let s.='\<c-k>Eu'\<cr>" + call assert_equal("€", s) +endfunc + +func Test_show_digraph() + new + call Put_Dig("e=") + call assert_equal("\n<е> 1077, Hex 0435, Oct 2065, Digr e=", execute('ascii')) + bwipe! +endfunc + +func Test_show_digraph_cp1251() + new + set encoding=cp1251 + call Put_Dig("='") + call assert_equal("\n<\xfa> <|z> <M-z> 250, Hex fa, Oct 372, Digr ='", execute('ascii')) + set encoding=utf-8 + bwipe! +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_display.vim b/src/testdir/test_display.vim new file mode 100644 index 0000000..81ffb2c --- /dev/null +++ b/src/testdir/test_display.vim @@ -0,0 +1,69 @@ +" Test for displaying stuff +if !has('gui_running') && has('unix') + set term=ansi +endif + +source view_util.vim + +func Test_display_foldcolumn() + if !has("folding") + return + endif + new + vnew + vert resize 25 + call assert_equal(25, winwidth(winnr())) + set isprint=@ + + 1put='e more noise blah blah more stuff here' + + let expect = [ + \ "e more noise blah blah<82", + \ "> more stuff here " + \ ] + + call cursor(2, 1) + norm! zt + let lines=ScreenLines([1,2], winwidth(0)) + call assert_equal(expect, lines) + set fdc=2 + let lines=ScreenLines([1,2], winwidth(0)) + let expect = [ + \ " e more noise blah blah<", + \ " 82> more stuff here " + \ ] + call assert_equal(expect, lines) + + quit! + quit! +endfunc + +func Test_display_foldtext_mbyte() + if !has("folding") + return + endif + call NewWindow(10, 40) + call append(0, range(1,20)) + exe "set foldmethod=manual foldtext=foldtext() fillchars=fold:\u2500,vert:\u2502 fdc=2" + call cursor(2, 1) + norm! zf13G + let lines=ScreenLines([1,3], winwidth(0)+1) + let expect=[ + \ " 1 \u2502", + \ "+ +-- 12 lines: 2". repeat("\u2500", 23). "\u2502", + \ " 14 \u2502", + \ ] + call assert_equal(expect, lines) + + set fillchars=fold:-,vert:\| + let lines=ScreenLines([1,3], winwidth(0)+1) + let expect=[ + \ " 1 |", + \ "+ +-- 12 lines: 2". repeat("-", 23). "|", + \ " 14 |", + \ ] + call assert_equal(expect, lines) + + set foldtext& fillchars& foldmethod& fdc& + bw! +endfunc diff --git a/src/testdir/test_edit.vim b/src/testdir/test_edit.vim new file mode 100644 index 0000000..9a60d01 --- /dev/null +++ b/src/testdir/test_edit.vim @@ -0,0 +1,1438 @@ +" Test for edit functions +" +if exists("+t_kD") + let &t_kD="[3;*~" +endif + +" Needed for testing basic rightleft: Test_edit_rightleft +source view_util.vim + +" Needs to come first until the bug in getchar() is +" fixed: https://groups.google.com/d/msg/vim_dev/fXL9yme4H4c/bOR-U6_bAQAJ +func Test_edit_00b() + new + call setline(1, ['abc ']) + inoreabbr <buffer> h here some more + call cursor(1, 4) + " <c-l> expands the abbreviation and ends insertmode + call feedkeys(":set im\<cr> h\<c-l>:set noim\<cr>", 'tix') + call assert_equal(['abc here some more '], getline(1,'$')) + iunabbr <buffer> h + bw! +endfunc + +func Test_edit_01() + " set for Travis CI? + " set nocp noesckeys + new + " 1) empty buffer + call assert_equal([''], getline(1,'$')) + " 2) delete in an empty line + call feedkeys("i\<del>\<esc>", 'tnix') + call assert_equal([''], getline(1,'$')) + %d + " 3) delete one character + call setline(1, 'a') + call feedkeys("i\<del>\<esc>", 'tnix') + call assert_equal([''], getline(1,'$')) + %d + " 4) delete a multibyte character + call setline(1, "\u0401") + call feedkeys("i\<del>\<esc>", 'tnix') + call assert_equal([''], getline(1,'$')) + %d + " 5.1) delete linebreak with 'bs' option containing eol + let _bs=&bs + set bs=eol + call setline(1, ["abc def", "ghi jkl"]) + call cursor(1, 1) + call feedkeys("A\<del>\<esc>", 'tnix') + call assert_equal(['abc defghi jkl'], getline(1, 2)) + %d + " 5.2) delete linebreak with backspace option w/out eol + set bs= + call setline(1, ["abc def", "ghi jkl"]) + call cursor(1, 1) + call feedkeys("A\<del>\<esc>", 'tnix') + call assert_equal(["abc def", "ghi jkl"], getline(1, 2)) + let &bs=_bs + bw! +endfunc + +func Test_edit_02() + " Change cursor position in InsertCharPre command + new + call setline(1, 'abc') + call cursor(1, 1) + fu! DoIt(...) + call cursor(1, 4) + if len(a:000) + let v:char=a:1 + endif + endfu + au InsertCharPre <buffer> :call DoIt('y') + call feedkeys("ix\<esc>", 'tnix') + call assert_equal(['abcy'], getline(1, '$')) + " Setting <Enter> in InsertCharPre + au! InsertCharPre <buffer> :call DoIt("\n") + call setline(1, 'abc') + call cursor(1, 1) + call feedkeys("ix\<esc>", 'tnix') + call assert_equal(['abc', ''], getline(1, '$')) + %d + au! InsertCharPre + " Change cursor position in InsertEnter command + " 1) when setting v:char, keeps changed cursor position + au! InsertEnter <buffer> :call DoIt('y') + call setline(1, 'abc') + call cursor(1, 1) + call feedkeys("ix\<esc>", 'tnix') + call assert_equal(['abxc'], getline(1, '$')) + " 2) when not setting v:char, restores changed cursor position + au! InsertEnter <buffer> :call DoIt() + call setline(1, 'abc') + call cursor(1, 1) + call feedkeys("ix\<esc>", 'tnix') + call assert_equal(['xabc'], getline(1, '$')) + au! InsertEnter + delfu DoIt + bw! +endfunc + +func Test_edit_03() + " Change cursor after <c-o> command to end of line + new + call setline(1, 'abc') + call cursor(1, 1) + call feedkeys("i\<c-o>$y\<esc>", 'tnix') + call assert_equal(['abcy'], getline(1, '$')) + %d + call setline(1, 'abc') + call cursor(1, 1) + call feedkeys("i\<c-o>80|y\<esc>", 'tnix') + call assert_equal(['abcy'], getline(1, '$')) + %d + call setline(1, 'abc') + call feedkeys("Ad\<c-o>:s/$/efg/\<cr>hij", 'tnix') + call assert_equal(['hijabcdefg'], getline(1, '$')) + bw! +endfunc + +func Test_edit_04() + " test for :stopinsert + new + call setline(1, 'abc') + call cursor(1, 1) + call feedkeys("i\<c-o>:stopinsert\<cr>$", 'tnix') + call feedkeys("aX\<esc>", 'tnix') + call assert_equal(['abcX'], getline(1, '$')) + %d + bw! +endfunc + +func Test_edit_05() + " test for folds being opened + new + call setline(1, ['abcX', 'abcX', 'zzzZ']) + call cursor(1, 1) + set foldmethod=manual foldopen+=insert + " create fold for those two lines + norm! Vjzf + call feedkeys("$ay\<esc>", 'tnix') + call assert_equal(['abcXy', 'abcX', 'zzzZ'], getline(1, '$')) + %d + call setline(1, ['abcX', 'abcX', 'zzzZ']) + call cursor(1, 1) + set foldmethod=manual foldopen-=insert + " create fold for those two lines + norm! Vjzf + call feedkeys("$ay\<esc>", 'tnix') + call assert_equal(['abcXy', 'abcX', 'zzzZ'], getline(1, '$')) + %d + bw! +endfunc + +func Test_edit_06() + " Test in diff mode + if !has("diff") || !executable("diff") + return + endif + new + call setline(1, ['abc', 'xxx', 'yyy']) + vnew + call setline(1, ['abc', 'zzz', 'xxx', 'yyy']) + wincmd p + diffthis + wincmd p + diffthis + wincmd p + call cursor(2, 1) + norm! zt + call feedkeys("Ozzz\<esc>", 'tnix') + call assert_equal(['abc', 'zzz', 'xxx', 'yyy'], getline(1,'$')) + bw! + bw! +endfunc + +func Test_edit_07() + " 1) Test with completion <c-l> when popupmenu is visible + new + call setline(1, 'J') + + func! ListMonths() + call complete(col('.')-1, ['January', 'February', 'March', + \ 'April', 'May', 'June', 'July', 'August', 'September', + \ 'October', 'November', 'December']) + return '' + endfunc + inoremap <buffer> <F5> <C-R>=ListMonths()<CR> + + call feedkeys("A\<f5>\<c-p>". repeat("\<down>", 6)."\<c-l>\<down>\<c-l>\<cr>", 'tx') + call assert_equal(['July'], getline(1,'$')) + " 1) Test completion when InsertCharPre kicks in + %d + call setline(1, 'J') + fu! DoIt() + if v:char=='u' + let v:char='an' + endif + endfu + au InsertCharPre <buffer> :call DoIt() + call feedkeys("A\<f5>\<c-p>u\<cr>\<c-l>\<cr>", 'tx') + call assert_equal(["Jan\<c-l>",''], getline(1,'$')) + %d + call setline(1, 'J') + call feedkeys("A\<f5>\<c-p>u\<down>\<c-l>\<cr>", 'tx') + call assert_equal(["January"], getline(1,'$')) + + delfu ListMonths + delfu DoIt + iunmap <buffer> <f5> + bw! +endfunc + +func Test_edit_08() + " reset insertmode from i_ctrl-r_= + let g:bufnr = bufnr('%') + new + call setline(1, ['abc']) + call cursor(1, 4) + call feedkeys(":set im\<cr>ZZZ\<c-r>=setbufvar(g:bufnr,'&im', 0)\<cr>",'tnix') + call assert_equal(['abZZZc'], getline(1,'$')) + call assert_equal([0, 1, 1, 0], getpos('.')) + call assert_false(0, '&im') + bw! + unlet g:bufnr +endfunc + +func Test_edit_09() + " test i_CTRL-\ combinations + new + call setline(1, ['abc', 'def', 'ghi']) + call cursor(1, 1) + " 1) CTRL-\ CTLR-N + call feedkeys(":set im\<cr>\<c-\>\<c-n>ccABC\<c-l>", 'txin') + call assert_equal(['ABC', 'def', 'ghi'], getline(1,'$')) + call setline(1, ['ABC', 'def', 'ghi']) + " 2) CTRL-\ CTLR-G + call feedkeys("j0\<c-\>\<c-g>ZZZ\<cr>\<c-l>", 'txin') + call assert_equal(['ABC', 'ZZZ', 'def', 'ghi'], getline(1,'$')) + call feedkeys("I\<c-\>\<c-g>YYY\<c-l>", 'txin') + call assert_equal(['ABC', 'ZZZ', 'YYYdef', 'ghi'], getline(1,'$')) + set noinsertmode + " 3) CTRL-\ CTRL-O + call setline(1, ['ABC', 'ZZZ', 'def', 'ghi']) + call cursor(1, 1) + call feedkeys("A\<c-o>ix", 'txin') + call assert_equal(['ABxC', 'ZZZ', 'def', 'ghi'], getline(1,'$')) + call feedkeys("A\<c-\>\<c-o>ix", 'txin') + call assert_equal(['ABxCx', 'ZZZ', 'def', 'ghi'], getline(1,'$')) + " 4) CTRL-\ a (should be inserted literally, not special after <c-\> + call setline(1, ['ABC', 'ZZZ', 'def', 'ghi']) + call cursor(1, 1) + call feedkeys("A\<c-\>a", 'txin') + call assert_equal(["ABC\<c-\>a", 'ZZZ', 'def', 'ghi'], getline(1, '$')) + bw! +endfunc + +func Test_edit_10() + " Test for starting selectmode + new + set selectmode=key keymodel=startsel + call setline(1, ['abc', 'def', 'ghi']) + call cursor(1, 4) + call feedkeys("A\<s-home>start\<esc>", 'txin') + call assert_equal(['startdef', 'ghi'], getline(1, '$')) + set selectmode= keymodel= + bw! +endfunc + +func Test_edit_11() + " Test that indenting kicks in + new + set cindent + call setline(1, ['{', '', '']) + call cursor(2, 1) + call feedkeys("i\<c-f>int c;\<esc>", 'tnix') + call cursor(3, 1) + call feedkeys("i/* comment */", 'tnix') + call assert_equal(['{', "\<tab>int c;", "/* comment */"], getline(1, '$')) + " added changed cindentkeys slightly + set cindent cinkeys+=*/ + call setline(1, ['{', '', '']) + call cursor(2, 1) + call feedkeys("i\<c-f>int c;\<esc>", 'tnix') + call cursor(3, 1) + call feedkeys("i/* comment */", 'tnix') + call assert_equal(['{', "\<tab>int c;", "\<tab>/* comment */"], getline(1, '$')) + set cindent cinkeys+==end + call feedkeys("oend\<cr>\<esc>", 'tnix') + call assert_equal(['{', "\<tab>int c;", "\<tab>/* comment */", "\tend", ''], getline(1, '$')) + set cinkeys-==end + %d + " Use indentexpr instead of cindenting + func! Do_Indent() + if v:lnum == 3 + return 3*shiftwidth() + else + return 2*shiftwidth() + endif + endfunc + setl indentexpr=Do_Indent() indentkeys+=*/ + call setline(1, ['{', '', '']) + call cursor(2, 1) + call feedkeys("i\<c-f>int c;\<esc>", 'tnix') + call cursor(3, 1) + call feedkeys("i/* comment */", 'tnix') + call assert_equal(['{', "\<tab>\<tab>int c;", "\<tab>\<tab>\<tab>/* comment */"], getline(1, '$')) + set cinkeys&vim indentkeys&vim + set nocindent indentexpr= + delfu Do_Indent + bw! +endfunc + +func Test_edit_11_indentexpr() + " Test that indenting kicks in + new + " Use indentexpr instead of cindenting + func! Do_Indent() + let pline=prevnonblank(v:lnum) + if empty(getline(v:lnum)) + if getline(pline) =~ 'if\|then' + return shiftwidth() + else + return 0 + endif + else + return 0 + endif + endfunc + setl indentexpr=Do_Indent() indentkeys+=0=then,0=fi + call setline(1, ['if [ $this ]']) + call cursor(1, 1) + call feedkeys("othen\<cr>that\<cr>fi", 'tnix') + call assert_equal(['if [ $this ]', "then", "\<tab>that", "fi"], getline(1, '$')) + set cinkeys&vim indentkeys&vim + set nocindent indentexpr= + delfu Do_Indent + bw! +endfunc + +func Test_edit_12() + " Test changing indent in replace mode + new + call setline(1, ["\tabc", "\tdef"]) + call cursor(2, 4) + call feedkeys("R^\<c-d>", 'tnix') + call assert_equal(["\tabc", "def"], getline(1, '$')) + call assert_equal([0, 2, 2, 0], getpos('.')) + %d + call setline(1, ["\tabc", "\t\tdef"]) + call cursor(2, 2) + call feedkeys("R^\<c-d>", 'tnix') + call assert_equal(["\tabc", "def"], getline(1, '$')) + call assert_equal([0, 2, 1, 0], getpos('.')) + %d + call setline(1, ["\tabc", "\t\tdef"]) + call cursor(2, 2) + call feedkeys("R\<c-t>", 'tnix') + call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$')) + call assert_equal([0, 2, 2, 0], getpos('.')) + bw! + 10vnew + call setline(1, ["\tabc", "\t\tdef"]) + call cursor(2, 2) + call feedkeys("R\<c-t>", 'tnix') + call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$')) + call assert_equal([0, 2, 2, 0], getpos('.')) + %d + set sw=4 + call setline(1, ["\tabc", "\t\tdef"]) + call cursor(2, 2) + call feedkeys("R\<c-t>\<c-t>", 'tnix') + call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$')) + call assert_equal([0, 2, 2, 0], getpos('.')) + %d + call setline(1, ["\tabc", "\t\tdef"]) + call cursor(2, 2) + call feedkeys("R\<c-t>\<c-t>", 'tnix') + call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$')) + call assert_equal([0, 2, 2, 0], getpos('.')) + set et + set sw& et& + %d + call setline(1, ["\t/*"]) + set formatoptions=croql + call cursor(1, 3) + call feedkeys("A\<cr>\<cr>/", 'tnix') + call assert_equal(["\t/*", " *", " */"], getline(1, '$')) + set formatoptions& + bw! +endfunc + +func Test_edit_13() + " Test smartindenting + if exists("+smartindent") + new + set smartindent autoindent + call setline(1, ["\tabc"]) + call feedkeys("A {\<cr>more\<cr>}\<esc>", 'tnix') + call assert_equal(["\tabc {", "\t\tmore", "\t}"], getline(1, '$')) + set smartindent& autoindent& + bw! + endif +endfunc + +func Test_edit_CR() + " Test for <CR> in insert mode + " basically only in quickfix mode ist tested, the rest + " has been taken care of by other tests + if !has("quickfix") + return + endif + botright new + call writefile(range(1, 10), 'Xqflist.txt') + call setqflist([{'filename': 'Xqflist.txt', 'lnum': 2}]) + copen + set modifiable + call feedkeys("A\<cr>", 'tnix') + call assert_equal('Xqflist.txt', bufname('')) + call assert_equal(2, line('.')) + cclose + botright new + call setloclist(0, [{'filename': 'Xqflist.txt', 'lnum': 10}]) + lopen + set modifiable + call feedkeys("A\<cr>", 'tnix') + call assert_equal('Xqflist.txt', bufname('')) + call assert_equal(10, line('.')) + call feedkeys("A\<Enter>", 'tnix') + call feedkeys("A\<kEnter>", 'tnix') + call feedkeys("A\n", 'tnix') + call feedkeys("A\r", 'tnix') + call assert_equal(map(range(1, 10), 'string(v:val)') + ['', '', '', ''], getline(1, '$')) + bw! + lclose + call delete('Xqflist.txt') +endfunc + +func Test_edit_CTRL_() + " disabled for Windows builds, why? + if !has("rightleft") || has("win32") + return + endif + let _encoding=&encoding + set encoding=utf-8 + " Test for CTRL-_ + new + call setline(1, ['abc']) + call cursor(1, 1) + call feedkeys("i\<c-_>xyz\<esc>", 'tnix') + call assert_equal(["\<C-_>xyzabc"], getline(1, '$')) + call assert_false(&revins) + set ari + call setline(1, ['abc']) + call cursor(1, 1) + call feedkeys("i\<c-_>xyz\<esc>", 'tnix') + call assert_equal(["æèñabc"], getline(1, '$')) + call assert_true(&revins) + call setline(1, ['abc']) + call cursor(1, 1) + call feedkeys("i\<c-_>xyz\<esc>", 'tnix') + call assert_equal(["xyzabc"], getline(1, '$')) + call assert_false(&revins) + set noari + let &encoding=_encoding + bw! +endfunc + +" needs to come first, to have the @. register empty +func Test_edit_00a_CTRL_A() + " Test pressing CTRL-A + new + call setline(1, repeat([''], 5)) + call cursor(1, 1) + try + call feedkeys("A\<NUL>", 'tnix') + catch /^Vim\%((\a\+)\)\=:E29/ + call assert_true(1, 'E29 error caught') + endtry + call cursor(1, 1) + call feedkeys("Afoobar \<esc>", 'tnix') + call cursor(2, 1) + call feedkeys("A\<c-a>more\<esc>", 'tnix') + call cursor(3, 1) + call feedkeys("A\<NUL>and more\<esc>", 'tnix') + call assert_equal(['foobar ', 'foobar more', 'foobar morend more', '', ''], getline(1, '$')) + bw! +endfunc + +func Test_edit_CTRL_EY() + " Ctrl-E/ Ctrl-Y in insert mode completion to scroll + 10new + call setline(1, range(1, 100)) + call cursor(30, 1) + norm! z. + call feedkeys("A\<c-x>\<c-e>\<c-e>\<c-e>\<c-e>\<c-e>", 'tnix') + call assert_equal(30, winsaveview()['topline']) + call assert_equal([0, 30, 2, 0], getpos('.')) + call feedkeys("A\<c-x>\<c-e>\<c-e>\<c-e>\<c-e>\<c-e>", 'tnix') + call feedkeys("A\<c-x>".repeat("\<c-y>", 10), 'tnix') + call assert_equal(21, winsaveview()['topline']) + call assert_equal([0, 30, 2, 0], getpos('.')) + bw! +endfunc + +func Test_edit_CTRL_G() + new + call setline(1, ['foobar', 'foobar', 'foobar']) + call cursor(2, 4) + call feedkeys("ioooooooo\<c-g>k\<c-r>.\<esc>", 'tnix') + call assert_equal(['foooooooooobar', 'foooooooooobar', 'foobar'], getline(1, '$')) + call assert_equal([0, 1, 11, 0], getpos('.')) + call feedkeys("i\<c-g>k\<esc>", 'tnix') + call assert_equal([0, 1, 10, 0], getpos('.')) + call cursor(2, 4) + call feedkeys("i\<c-g>jzzzz\<esc>", 'tnix') + call assert_equal(['foooooooooobar', 'foooooooooobar', 'foozzzzbar'], getline(1, '$')) + call assert_equal([0, 3, 7, 0], getpos('.')) + call feedkeys("i\<c-g>j\<esc>", 'tnix') + call assert_equal([0, 3, 6, 0], getpos('.')) + bw! +endfunc + +func Test_edit_CTRL_I() + " Tab in completion mode + let path=expand("%:p:h") + new + call setline(1, [path. "/", '']) + call feedkeys("Arunt\<c-x>\<c-f>\<tab>\<cr>\<esc>", 'tnix') + call assert_match('runtest\.vim', getline(1)) + %d + call writefile(['one', 'two', 'three'], 'Xinclude.txt') + let include='#include Xinclude.txt' + call setline(1, [include, '']) + call cursor(2, 1) + call feedkeys("A\<c-x>\<tab>\<cr>\<esc>", 'tnix') + call assert_equal([include, 'one', ''], getline(1, '$')) + call feedkeys("2ggC\<c-x>\<tab>\<down>\<cr>\<esc>", 'tnix') + call assert_equal([include, 'two', ''], getline(1, '$')) + call feedkeys("2ggC\<c-x>\<tab>\<down>\<down>\<cr>\<esc>", 'tnix') + call assert_equal([include, 'three', ''], getline(1, '$')) + call feedkeys("2ggC\<c-x>\<tab>\<down>\<down>\<down>\<cr>\<esc>", 'tnix') + call assert_equal([include, '', ''], getline(1, '$')) + call delete("Xinclude.txt") + bw! +endfunc + +func Test_edit_CTRL_K() + " Test pressing CTRL-K (basically only dictionary completion and digraphs + " the rest is already covered + call writefile(['A', 'AA', 'AAA', 'AAAA'], 'Xdictionary.txt') + set dictionary=Xdictionary.txt + new + call setline(1, 'A') + call cursor(1, 1) + call feedkeys("A\<c-x>\<c-k>\<cr>\<esc>", 'tnix') + call assert_equal(['AA', ''], getline(1, '$')) + %d + call setline(1, 'A') + call cursor(1, 1) + call feedkeys("A\<c-x>\<c-k>\<down>\<cr>\<esc>", 'tnix') + call assert_equal(['AAA'], getline(1, '$')) + %d + call setline(1, 'A') + call cursor(1, 1) + call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<cr>\<esc>", 'tnix') + call assert_equal(['AAAA'], getline(1, '$')) + %d + call setline(1, 'A') + call cursor(1, 1) + call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<down>\<cr>\<esc>", 'tnix') + call assert_equal(['A'], getline(1, '$')) + %d + call setline(1, 'A') + call cursor(1, 1) + call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<down>\<down>\<cr>\<esc>", 'tnix') + call assert_equal(['AA'], getline(1, '$')) + + " press an unexecpted key after dictionary completion + %d + call setline(1, 'A') + call cursor(1, 1) + call feedkeys("A\<c-x>\<c-k>\<c-]>\<cr>\<esc>", 'tnix') + call assert_equal(['AA', ''], getline(1, '$')) + %d + call setline(1, 'A') + call cursor(1, 1) + call feedkeys("A\<c-x>\<c-k>\<c-s>\<cr>\<esc>", 'tnix') + call assert_equal(["AA\<c-s>", ''], getline(1, '$')) + %d + call setline(1, 'A') + call cursor(1, 1) + call feedkeys("A\<c-x>\<c-k>\<c-f>\<cr>\<esc>", 'tnix') + call assert_equal(["AA\<c-f>", ''], getline(1, '$')) + + set dictionary= + %d + call setline(1, 'A') + call cursor(1, 1) + let v:testing = 1 + try + call feedkeys("A\<c-x>\<c-k>\<esc>", 'tnix') + catch + " error sleeps 2 seconds, when v:testing is not set + let v:testing = 0 + endtry + call delete('Xdictionary.txt') + + call test_override("char_avail", 1) + set showcmd + %d + call feedkeys("A\<c-k>a:\<esc>", 'tnix') + call assert_equal(['ä'], getline(1, '$')) + call test_override("char_avail", 0) + set noshowcmd + + bw! +endfunc + +func Test_edit_CTRL_L() + " Test Ctrl-X Ctrl-L (line completion) + new + set complete=. + call setline(1, ['one', 'two', 'three', '', '', '', '']) + call cursor(4, 1) + call feedkeys("A\<c-x>\<c-l>\<esc>", 'tnix') + call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$')) + call feedkeys("cct\<c-x>\<c-l>\<c-n>\<esc>", 'tnix') + call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$')) + call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<esc>", 'tnix') + call assert_equal(['one', 'two', 'three', 'two', '', '', ''], getline(1, '$')) + call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<c-n>\<esc>", 'tnix') + call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$')) + call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<c-n>\<c-n>\<esc>", 'tnix') + call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$')) + call feedkeys("cct\<c-x>\<c-l>\<c-p>\<esc>", 'tnix') + call assert_equal(['one', 'two', 'three', 'two', '', '', ''], getline(1, '$')) + call feedkeys("cct\<c-x>\<c-l>\<c-p>\<c-p>\<esc>", 'tnix') + call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$')) + call feedkeys("cct\<c-x>\<c-l>\<c-p>\<c-p>\<c-p>\<esc>", 'tnix') + call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$')) + set complete= + call cursor(5, 1) + call feedkeys("A\<c-x>\<c-l>\<c-p>\<c-n>\<esc>", 'tnix') + call assert_equal(['one', 'two', 'three', 'three', "\<c-l>\<c-p>\<c-n>", '', ''], getline(1, '$')) + set complete& + %d + if has("conceal") && has("syntax") + call setline(1, ['foo', 'bar', 'foobar']) + call test_override("char_avail", 1) + set conceallevel=2 concealcursor=n + syn on + syn match ErrorMsg "^bar" + call matchadd("Conceal", 'oo', 10, -1, {'conceal': 'X'}) + func! DoIt() + let g:change=1 + endfunc + au! TextChangedI <buffer> :call DoIt() + + call cursor(2, 1) + call assert_false(exists("g:change")) + call feedkeys("A \<esc>", 'tnix') + call assert_equal(['foo', 'bar ', 'foobar'], getline(1, '$')) + call assert_equal(1, g:change) + + call test_override("char_avail", 0) + call clearmatches() + syn off + au! TextChangedI + delfu DoIt + unlet! g:change + endif + bw! +endfunc + +func Test_edit_CTRL_N() + " Check keyword completion + new + set complete=. + call setline(1, ['INFER', 'loWER', '', '', ]) + call cursor(3, 1) + call feedkeys("Ai\<c-n>\<cr>\<esc>", "tnix") + call feedkeys("ILO\<c-n>\<cr>\<esc>", 'tnix') + call assert_equal(['INFER', 'loWER', 'i', 'LO', '', ''], getline(1, '$')) + %d + call setline(1, ['INFER', 'loWER', '', '', ]) + call cursor(3, 1) + set ignorecase infercase + call feedkeys("Ii\<c-n>\<cr>\<esc>", "tnix") + call feedkeys("ILO\<c-n>\<cr>\<esc>", 'tnix') + call assert_equal(['INFER', 'loWER', 'infer', 'LOWER', '', ''], getline(1, '$')) + + set noignorecase noinfercase complete& + bw! +endfunc + +func Test_edit_CTRL_O() + " Check for CTRL-O in insert mode + new + inoreabbr <buffer> h here some more + call setline(1, ['abc', 'def']) + call cursor(1, 1) + " Ctrl-O after an abbreviation + exe "norm A h\<c-o>:set nu\<cr> text" + call assert_equal(['abc here some more text', 'def'], getline(1, '$')) + call assert_true(&nu) + set nonu + iunabbr <buffer> h + " Ctrl-O at end of line with 've'=onemore + call cursor(1, 1) + call feedkeys("A\<c-o>:let g:a=getpos('.')\<cr>\<esc>", 'tnix') + call assert_equal([0, 1, 23, 0], g:a) + call cursor(1, 1) + set ve=onemore + call feedkeys("A\<c-o>:let g:a=getpos('.')\<cr>\<esc>", 'tnix') + call assert_equal([0, 1, 24, 0], g:a) + set ve= + unlet! g:a + bw! +endfunc + +func Test_edit_CTRL_R() + " Insert Register + new + call test_override("ALL", 1) + set showcmd + call feedkeys("AFOOBAR eins zwei\<esc>", 'tnix') + call feedkeys("O\<c-r>.", 'tnix') + call feedkeys("O\<c-r>=10*500\<cr>\<esc>", 'tnix') + call feedkeys("O\<c-r>=getreg('=', 1)\<cr>\<esc>", 'tnix') + call assert_equal(["getreg('=', 1)", '5000', "FOOBAR eins zwei", "FOOBAR eins zwei"], getline(1, '$')) + call test_override("ALL", 0) + set noshowcmd + bw! +endfunc + +func Test_edit_CTRL_S() + " Test pressing CTRL-S (basically only spellfile completion) + " the rest is already covered + new + if !has("spell") + call setline(1, 'vim') + call feedkeys("A\<c-x>ss\<cr>\<esc>", 'tnix') + call assert_equal(['vims', ''], getline(1, '$')) + bw! + return + endif + call setline(1, 'vim') + " spell option not yet set + try + call feedkeys("A\<c-x>\<c-s>\<cr>\<esc>", 'tnix') + catch /^Vim\%((\a\+)\)\=:E756/ + call assert_true(1, 'error caught') + endtry + call assert_equal(['vim', ''], getline(1, '$')) + %d + setl spell spelllang=en + call setline(1, 'vim') + call cursor(1, 1) + call feedkeys("A\<c-x>\<c-s>\<cr>\<esc>", 'tnix') + call assert_equal(['Vim', ''], getline(1, '$')) + %d + call setline(1, 'vim') + call cursor(1, 1) + call feedkeys("A\<c-x>\<c-s>\<down>\<cr>\<esc>", 'tnix') + call assert_equal(['Aim'], getline(1, '$')) + %d + call setline(1, 'vim') + call cursor(1, 1) + call feedkeys("A\<c-x>\<c-s>\<c-p>\<cr>\<esc>", 'tnix') + call assert_equal(['vim', ''], getline(1, '$')) + %d + " empty buffer + call cursor(1, 1) + call feedkeys("A\<c-x>\<c-s>\<c-p>\<cr>\<esc>", 'tnix') + call assert_equal(['', ''], getline(1, '$')) + setl nospell + bw! +endfunc + +func Test_edit_CTRL_T() + " Check for CTRL-T and CTRL-X CTRL-T in insert mode + " 1) increase indent + new + call setline(1, "abc") + call cursor(1, 1) + call feedkeys("A\<c-t>xyz", 'tnix') + call assert_equal(["\<tab>abcxyz"], getline(1, '$')) + " 2) also when paste option is set + set paste + call setline(1, "abc") + call cursor(1, 1) + call feedkeys("A\<c-t>xyz", 'tnix') + call assert_equal(["\<tab>abcxyz"], getline(1, '$')) + set nopaste + " CTRL-X CTRL-T (thesaurus complete) + call writefile(['angry furious mad enraged'], 'Xthesaurus') + set thesaurus=Xthesaurus + call setline(1, 'mad') + call cursor(1, 1) + call feedkeys("A\<c-x>\<c-t>\<cr>\<esc>", 'tnix') + call assert_equal(['mad', ''], getline(1, '$')) + %d + call setline(1, 'mad') + call cursor(1, 1) + call feedkeys("A\<c-x>\<c-t>\<c-n>\<cr>\<esc>", 'tnix') + call assert_equal(['angry', ''], getline(1, '$')) + %d + call setline(1, 'mad') + call cursor(1, 1) + call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') + call assert_equal(['furious', ''], getline(1, '$')) + %d + call setline(1, 'mad') + call cursor(1, 1) + call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') + call assert_equal(['enraged', ''], getline(1, '$')) + %d + call setline(1, 'mad') + call cursor(1, 1) + call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') + call assert_equal(['mad', ''], getline(1, '$')) + %d + call setline(1, 'mad') + call cursor(1, 1) + call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') + call assert_equal(['mad', ''], getline(1, '$')) + " Using <c-p> <c-n> when 'complete' is empty + set complete= + %d + call setline(1, 'mad') + call cursor(1, 1) + call feedkeys("A\<c-x>\<c-t>\<c-n>\<cr>\<esc>", 'tnix') + call assert_equal(['angry', ''], getline(1, '$')) + %d + call setline(1, 'mad') + call cursor(1, 1) + call feedkeys("A\<c-x>\<c-t>\<c-p>\<cr>\<esc>", 'tnix') + call assert_equal(['mad', ''], getline(1, '$')) + set complete& + + set thesaurus= + %d + call setline(1, 'mad') + call cursor(1, 1) + let v:testing = 1 + try + call feedkeys("A\<c-x>\<c-t>\<esc>", 'tnix') + catch + " error sleeps 2 seconds, when v:testing is not set + let v:testing = 0 + endtry + call assert_equal(['mad'], getline(1, '$')) + call delete('Xthesaurus') + bw! +endfunc + +func Test_edit_CTRL_U() + " Test 'completefunc' + new + " -1, -2 and -3 are special return values + let g:special=0 + fun! CompleteMonths(findstart, base) + if a:findstart + " locate the start of the word + return g:special + else + " find months matching with "a:base" + let res = [] + for m in split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec") + if m =~ '^\c'.a:base + call add(res, {'word': m, 'abbr': m.' Month', 'icase': 0}) + endif + endfor + return {'words': res, 'refresh': 'always'} + endif + endfun + set completefunc=CompleteMonths + call setline(1, ['', '']) + call cursor(1, 1) + call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix') + call assert_equal(['X', '', ''], getline(1, '$')) + %d + let g:special=-1 + call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix') + call assert_equal(['XJan', ''], getline(1, '$')) + %d + let g:special=-2 + call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix') + call assert_equal(['X', ''], getline(1, '$')) + %d + let g:special=-3 + call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix') + call assert_equal(['X', ''], getline(1, '$')) + %d + let g:special=0 + call feedkeys("AM\<c-x>\<c-u>\<cr>\<esc>", 'tnix') + call assert_equal(['Mar', ''], getline(1, '$')) + %d + call feedkeys("AM\<c-x>\<c-u>\<c-n>\<cr>\<esc>", 'tnix') + call assert_equal(['May', ''], getline(1, '$')) + %d + call feedkeys("AM\<c-x>\<c-u>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') + call assert_equal(['M', ''], getline(1, '$')) + delfu CompleteMonths + %d + try + call feedkeys("A\<c-x>\<c-u>", 'tnix') + call assert_fails(1, 'unknown completion function') + catch /^Vim\%((\a\+)\)\=:E117/ + call assert_true(1, 'E117 error caught') + endtry + set completefunc= + bw! +endfunc + +func Test_edit_CTRL_Z() + " Ctrl-Z when insertmode is not set inserts it literally + new + call setline(1, 'abc') + call feedkeys("A\<c-z>\<esc>", 'tnix') + call assert_equal(["abc\<c-z>"], getline(1,'$')) + bw! + " TODO: How to Test Ctrl-Z in insert mode, e.g. suspend? +endfunc + +func Test_edit_DROP() + if !has("dnd") + return + endif + new + call setline(1, ['abc def ghi']) + call cursor(1, 1) + try + call feedkeys("i\<Drop>\<Esc>", 'tnix') + call assert_fails(1, 'Invalid register name') + catch /^Vim\%((\a\+)\)\=:E353/ + call assert_true(1, 'error caught') + endtry + bw! +endfunc + +func Test_edit_CTRL_V() + if has("ebcdic") + return + endif + new + call setline(1, ['abc']) + call cursor(2, 1) + " force some redraws + set showmode showcmd + "call test_override_char_avail(1) + call test_override('ALL', 1) + call feedkeys("A\<c-v>\<c-n>\<c-v>\<c-l>\<c-v>\<c-b>\<esc>", 'tnix') + call assert_equal(["abc\x0e\x0c\x02"], getline(1, '$')) + + if has("rightleft") && exists("+rl") + set rl + call setline(1, ['abc']) + call cursor(2, 1) + call feedkeys("A\<c-v>\<c-n>\<c-v>\<c-l>\<c-v>\<c-b>\<esc>", 'tnix') + call assert_equal(["abc\x0e\x0c\x02"], getline(1, '$')) + set norl + endif + + call test_override('ALL', 0) + set noshowmode showcmd + bw! +endfunc + +func Test_edit_F1() + " Pressing <f1> + new + call feedkeys(":set im\<cr>\<f1>\<c-l>", 'tnix') + set noinsertmode + call assert_equal('help', &buftype) + bw + bw +endfunc + +func Test_edit_F21() + " Pressing <f21> + " sends a netbeans command + if has("netbeans_intg") + new + " I have no idea what this is supposed to do :) + call feedkeys("A\<F21>\<F1>\<esc>", 'tnix') + bw + endif +endfunc + +func Test_edit_HOME_END() + " Test Home/End Keys + new + set foldopen+=hor + call setline(1, ['abc', 'def']) + call cursor(1, 1) + call feedkeys("AX\<Home>Y\<esc>", 'tnix') + call cursor(2, 1) + call feedkeys("iZ\<End>Y\<esc>", 'tnix') + call assert_equal(['YabcX', 'ZdefY'], getline(1, '$')) + + set foldopen-=hor + bw! +endfunc + +func Test_edit_INS() + " Test for Pressing <Insert> + new + call setline(1, ['abc', 'def']) + call cursor(1, 1) + call feedkeys("i\<Insert>ZYX>", 'tnix') + call assert_equal(['ZYX>', 'def'], getline(1, '$')) + call setline(1, ['abc', 'def']) + call cursor(1, 1) + call feedkeys("i\<Insert>Z\<Insert>YX>", 'tnix') + call assert_equal(['ZYX>bc', 'def'], getline(1, '$')) + bw! +endfunc + +func Test_edit_LEFT_RIGHT() + " Left, Shift-Left, Right, Shift-Right + new + call setline(1, ['abc def ghi', 'ABC DEF GHI', 'ZZZ YYY XXX']) + let _ww=&ww + set ww= + call cursor(2, 1) + call feedkeys("i\<left>\<esc>", 'tnix') + call assert_equal([0, 2, 1, 0], getpos('.')) + " Is this a bug, <s-left> does not respect whichwrap option + call feedkeys("i\<s-left>\<esc>", 'tnix') + call assert_equal([0, 1, 8, 0], getpos('.')) + call feedkeys("i". repeat("\<s-left>", 3). "\<esc>", 'tnix') + call assert_equal([0, 1, 1, 0], getpos('.')) + call feedkeys("i\<right>\<esc>", 'tnix') + call assert_equal([0, 1, 1, 0], getpos('.')) + call feedkeys("i\<right>\<right>\<esc>", 'tnix') + call assert_equal([0, 1, 2, 0], getpos('.')) + call feedkeys("A\<right>\<esc>", 'tnix') + call assert_equal([0, 1, 11, 0], getpos('.')) + call feedkeys("A\<s-right>\<esc>", 'tnix') + call assert_equal([0, 2, 1, 0], getpos('.')) + call feedkeys("i\<s-right>\<esc>", 'tnix') + call assert_equal([0, 2, 4, 0], getpos('.')) + call cursor(3, 11) + call feedkeys("A\<right>\<esc>", 'tnix') + call feedkeys("A\<s-right>\<esc>", 'tnix') + call assert_equal([0, 3, 11, 0], getpos('.')) + call cursor(2, 11) + " <S-Right> does not respect 'whichwrap' option + call feedkeys("A\<s-right>\<esc>", 'tnix') + call assert_equal([0, 3, 1, 0], getpos('.')) + " Check motion when 'whichwrap' contains cursor keys for insert mode + set ww+=[,] + call cursor(2, 1) + call feedkeys("i\<left>\<esc>", 'tnix') + call assert_equal([0, 1, 11, 0], getpos('.')) + call cursor(2, 11) + call feedkeys("A\<right>\<esc>", 'tnix') + call assert_equal([0, 3, 1, 0], getpos('.')) + call cursor(2, 11) + call feedkeys("A\<s-right>\<esc>", 'tnix') + call assert_equal([0, 3, 1, 0], getpos('.')) + let &ww = _ww + bw! +endfunc + +func Test_edit_MOUSE() + " This is a simple test, since we not really using the mouse here + if !has("mouse") + return + endif + 10new + call setline(1, range(1, 100)) + call cursor(1, 1) + set mouse=a + call feedkeys("A\<ScrollWheelDown>\<esc>", 'tnix') + call assert_equal([0, 4, 1, 0], getpos('.')) + " This should move by one pageDown, but only moves + " by one line when the test is run... + call feedkeys("A\<S-ScrollWheelDown>\<esc>", 'tnix') + call assert_equal([0, 5, 1, 0], getpos('.')) + set nostartofline + call feedkeys("A\<C-ScrollWheelDown>\<esc>", 'tnix') + call assert_equal([0, 6, 1, 0], getpos('.')) + call feedkeys("A\<LeftMouse>\<esc>", 'tnix') + call assert_equal([0, 6, 1, 0], getpos('.')) + call feedkeys("A\<RightMouse>\<esc>", 'tnix') + call assert_equal([0, 6, 1, 0], getpos('.')) + call cursor(1, 100) + norm! zt + " this should move by a screen up, but when the test + " is run, it moves up to the top of the buffer... + call feedkeys("A\<ScrollWheelUp>\<esc>", 'tnix') + call assert_equal([0, 1, 1, 0], getpos('.')) + call cursor(1, 30) + norm! zt + call feedkeys("A\<S-ScrollWheelUp>\<esc>", 'tnix') + call assert_equal([0, 1, 1, 0], getpos('.')) + call cursor(1, 30) + norm! zt + call feedkeys("A\<C-ScrollWheelUp>\<esc>", 'tnix') + call assert_equal([0, 1, 1, 0], getpos('.')) + %d + call setline(1, repeat(["12345678901234567890"], 100)) + call cursor(2, 1) + call feedkeys("A\<ScrollWheelRight>\<esc>", 'tnix') + call assert_equal([0, 2, 20, 0], getpos('.')) + call feedkeys("A\<ScrollWheelLeft>\<esc>", 'tnix') + call assert_equal([0, 2, 20, 0], getpos('.')) + call feedkeys("A\<S-ScrollWheelRight>\<esc>", 'tnix') + call assert_equal([0, 2, 20, 0], getpos('.')) + call feedkeys("A\<S-ScrollWheelLeft>\<esc>", 'tnix') + call assert_equal([0, 2, 20, 0], getpos('.')) + call feedkeys("A\<C-ScrollWheelRight>\<esc>", 'tnix') + call assert_equal([0, 2, 20, 0], getpos('.')) + call feedkeys("A\<C-ScrollWheelLeft>\<esc>", 'tnix') + call assert_equal([0, 2, 20, 0], getpos('.')) + set mouse& startofline + bw! +endfunc + +func Test_edit_PAGEUP_PAGEDOWN() + 10new + call setline(1, repeat(['abc def ghi'], 30)) + call cursor(1, 1) + call feedkeys("i\<PageDown>\<esc>", 'tnix') + call assert_equal([0, 9, 1, 0], getpos('.')) + call feedkeys("i\<PageDown>\<esc>", 'tnix') + call assert_equal([0, 17, 1, 0], getpos('.')) + call feedkeys("i\<PageDown>\<esc>", 'tnix') + call assert_equal([0, 25, 1, 0], getpos('.')) + call feedkeys("i\<PageDown>\<esc>", 'tnix') + call assert_equal([0, 30, 1, 0], getpos('.')) + call feedkeys("i\<PageDown>\<esc>", 'tnix') + call assert_equal([0, 30, 1, 0], getpos('.')) + call feedkeys("A\<PageUp>\<esc>", 'tnix') + call assert_equal([0, 29, 1, 0], getpos('.')) + call feedkeys("A\<PageUp>\<esc>", 'tnix') + call assert_equal([0, 21, 1, 0], getpos('.')) + call feedkeys("A\<PageUp>\<esc>", 'tnix') + call assert_equal([0, 13, 1, 0], getpos('.')) + call feedkeys("A\<PageUp>\<esc>", 'tnix') + call assert_equal([0, 5, 1, 0], getpos('.')) + call feedkeys("A\<PageUp>\<esc>", 'tnix') + call assert_equal([0, 5, 11, 0], getpos('.')) + " <S-Up> is the same as <PageUp> + " <S-Down> is the same as <PageDown> + call cursor(1, 1) + call feedkeys("i\<S-Down>\<esc>", 'tnix') + call assert_equal([0, 9, 1, 0], getpos('.')) + call feedkeys("i\<S-Down>\<esc>", 'tnix') + call assert_equal([0, 17, 1, 0], getpos('.')) + call feedkeys("i\<S-Down>\<esc>", 'tnix') + call assert_equal([0, 25, 1, 0], getpos('.')) + call feedkeys("i\<S-Down>\<esc>", 'tnix') + call assert_equal([0, 30, 1, 0], getpos('.')) + call feedkeys("i\<S-Down>\<esc>", 'tnix') + call assert_equal([0, 30, 1, 0], getpos('.')) + call feedkeys("A\<S-Up>\<esc>", 'tnix') + call assert_equal([0, 29, 1, 0], getpos('.')) + call feedkeys("A\<S-Up>\<esc>", 'tnix') + call assert_equal([0, 21, 1, 0], getpos('.')) + call feedkeys("A\<S-Up>\<esc>", 'tnix') + call assert_equal([0, 13, 1, 0], getpos('.')) + call feedkeys("A\<S-Up>\<esc>", 'tnix') + call assert_equal([0, 5, 1, 0], getpos('.')) + call feedkeys("A\<S-Up>\<esc>", 'tnix') + call assert_equal([0, 5, 11, 0], getpos('.')) + set nostartofline + call cursor(30, 11) + norm! zt + call feedkeys("A\<PageUp>\<esc>", 'tnix') + call assert_equal([0, 29, 11, 0], getpos('.')) + call feedkeys("A\<PageUp>\<esc>", 'tnix') + call assert_equal([0, 21, 11, 0], getpos('.')) + call feedkeys("A\<PageUp>\<esc>", 'tnix') + call assert_equal([0, 13, 11, 0], getpos('.')) + call feedkeys("A\<PageUp>\<esc>", 'tnix') + call assert_equal([0, 5, 11, 0], getpos('.')) + call feedkeys("A\<PageUp>\<esc>", 'tnix') + call assert_equal([0, 5, 11, 0], getpos('.')) + call cursor(1, 1) + call feedkeys("A\<PageDown>\<esc>", 'tnix') + call assert_equal([0, 9, 11, 0], getpos('.')) + call feedkeys("A\<PageDown>\<esc>", 'tnix') + call assert_equal([0, 17, 11, 0], getpos('.')) + call feedkeys("A\<PageDown>\<esc>", 'tnix') + call assert_equal([0, 25, 11, 0], getpos('.')) + call feedkeys("A\<PageDown>\<esc>", 'tnix') + call assert_equal([0, 30, 11, 0], getpos('.')) + call feedkeys("A\<PageDown>\<esc>", 'tnix') + call assert_equal([0, 30, 11, 0], getpos('.')) + " <S-Up> is the same as <PageUp> + " <S-Down> is the same as <PageDown> + call cursor(30, 11) + norm! zt + call feedkeys("A\<S-Up>\<esc>", 'tnix') + call assert_equal([0, 29, 11, 0], getpos('.')) + call feedkeys("A\<S-Up>\<esc>", 'tnix') + call assert_equal([0, 21, 11, 0], getpos('.')) + call feedkeys("A\<S-Up>\<esc>", 'tnix') + call assert_equal([0, 13, 11, 0], getpos('.')) + call feedkeys("A\<S-Up>\<esc>", 'tnix') + call assert_equal([0, 5, 11, 0], getpos('.')) + call feedkeys("A\<S-Up>\<esc>", 'tnix') + call assert_equal([0, 5, 11, 0], getpos('.')) + call cursor(1, 1) + call feedkeys("A\<S-Down>\<esc>", 'tnix') + call assert_equal([0, 9, 11, 0], getpos('.')) + call feedkeys("A\<S-Down>\<esc>", 'tnix') + call assert_equal([0, 17, 11, 0], getpos('.')) + call feedkeys("A\<S-Down>\<esc>", 'tnix') + call assert_equal([0, 25, 11, 0], getpos('.')) + call feedkeys("A\<S-Down>\<esc>", 'tnix') + call assert_equal([0, 30, 11, 0], getpos('.')) + call feedkeys("A\<S-Down>\<esc>", 'tnix') + call assert_equal([0, 30, 11, 0], getpos('.')) + bw! +endfunc + +func Test_edit_forbidden() + new + " 1) edit in the sandbox is not allowed + call setline(1, 'a') + com! Sandbox :sandbox call feedkeys("i\<del>\<esc>", 'tnix') + call assert_fails(':Sandbox', 'E48:') + com! Sandbox :sandbox exe "norm! i\<del>" + call assert_fails(':Sandbox', 'E48:') + delcom Sandbox + call assert_equal(['a'], getline(1,'$')) + " 2) edit with textlock set + fu! DoIt() + call feedkeys("i\<del>\<esc>", 'tnix') + endfu + au InsertCharPre <buffer> :call DoIt() + try + call feedkeys("ix\<esc>", 'tnix') + call assert_fails(1, 'textlock') + catch /^Vim\%((\a\+)\)\=:E523/ " catch E523: not allowed here + endtry + " TODO: Might be a bug: should x really be inserted here + call assert_equal(['xa'], getline(1, '$')) + delfu DoIt + try + call feedkeys("ix\<esc>", 'tnix') + call assert_fails(1, 'unknown function') + catch /^Vim\%((\a\+)\)\=:E117/ " catch E117: unknown function + endtry + au! InsertCharPre + " 3) edit when completion is shown + fun! Complete(findstart, base) + if a:findstart + return col('.') + else + call feedkeys("i\<del>\<esc>", 'tnix') + return [] + endif + endfun + set completefunc=Complete + try + call feedkeys("i\<c-x>\<c-u>\<esc>", 'tnix') + call assert_fails(1, 'change in complete function') + catch /^Vim\%((\a\+)\)\=:E523/ " catch E523 + endtry + delfu Complete + set completefunc= + if has("rightleft") && exists("+fkmap") + " 4) 'R' when 'fkmap' and 'revins' is set. + set revins fkmap + try + normal Ri + call assert_fails(1, "R with 'fkmap' and 'ri' set") + catch + finally + set norevins nofkmap + endtry + endif + bw! +endfunc + +func Test_edit_rightleft() + " Cursor in rightleft mode moves differently + if !exists("+rightleft") + return + endif + call NewWindow(10, 20) + call setline(1, ['abc', 'def', 'ghi']) + call cursor(1, 2) + set rightleft + " Screen looks as expected + let lines = ScreenLines([1, 4], winwidth(0)) + let expect = [ + \" cba", + \" fed", + \" ihg", + \" ~"] + call assert_equal(join(expect, "\n"), join(lines, "\n")) + " 2) right moves to the left + call feedkeys("i\<right>\<esc>x", 'txin') + call assert_equal(['bc', 'def', 'ghi'], getline(1,'$')) + call cursor(1, 2) + call feedkeys("i\<s-right>\<esc>", 'txin') + call cursor(1, 2) + call feedkeys("i\<c-right>\<esc>", 'txin') + " Screen looks as expected + let lines = ScreenLines([1, 4], winwidth(0)) + let expect = [ + \" cb", + \" fed", + \" ihg", + \" ~"] + call assert_equal(join(expect, "\n"), join(lines, "\n")) + " 2) left moves to the right + call setline(1, ['abc', 'def', 'ghi']) + call cursor(1, 2) + call feedkeys("i\<left>\<esc>x", 'txin') + call assert_equal(['ac', 'def', 'ghi'], getline(1,'$')) + call cursor(1, 2) + call feedkeys("i\<s-left>\<esc>", 'txin') + call cursor(1, 2) + call feedkeys("i\<c-left>\<esc>", 'txin') + " Screen looks as expected + let lines = ScreenLines([1, 4], winwidth(0)) + let expect = [ + \" ca", + \" fed", + \" ihg", + \" ~"] + call assert_equal(join(expect, "\n"), join(lines, "\n")) + set norightleft + bw! +endfunc + +func Test_edit_complete_very_long_name() + if !has('unix') + " Long directory names only work on Unix. + return + endif + + let dirname = getcwd() . "/Xdir" + let longdirname = dirname . repeat('/' . repeat('d', 255), 4) + try + call mkdir(longdirname, 'p') + catch /E739:/ + " Long directory name probably not supported. + call delete(dirname, 'rf') + return + endtry + + " Try to get the Vim window position before setting 'columns'. + let winposx = getwinposx() + let winposy = getwinposy() + let save_columns = &columns + " Need at least about 1100 columns to reproduce the problem. + set columns=2000 + set noswapfile + + let longfilename = longdirname . '/' . repeat('a', 255) + call writefile(['Totum', 'Table'], longfilename) + new + exe "next Xfile " . longfilename + exe "normal iT\<C-N>" + + bwipe! + exe 'bwipe! ' . longfilename + call delete(dirname, 'rf') + let &columns = save_columns + if winposx >= 0 && winposy >= 0 + exe 'winpos ' . winposx . ' ' . winposy + endif + set swapfile& +endfunc + +func Test_edit_backtick() + next a\`b c + call assert_equal('a`b', expand('%')) + next + call assert_equal('c', expand('%')) + call assert_equal('a\`b c', expand('##')) +endfunc + +func Test_edit_quit() + edit foo.txt + split + new + call setline(1, 'hello') + 3wincmd w + redraw! + call assert_fails('1q', 'E37:') + bwipe! foo.txt + only +endfunc + +func Test_edit_alt() + " Keeping the cursor line didn't happen when the first line has indent. + new + call setline(1, [' one', 'two', 'three']) + w XAltFile + $ + call assert_equal(3, line('.')) + e Xother + e # + call assert_equal(3, line('.')) + + bwipe XAltFile + call delete('XAltFile') +endfunc + +func Test_leave_insert_autocmd() + new + au InsertLeave * let g:did_au = 1 + let g:did_au = 0 + call feedkeys("afoo\<Esc>", 'tx') + call assert_equal(1, g:did_au) + call assert_equal('foo', getline(1)) + + let g:did_au = 0 + call feedkeys("Sbar\<C-C>", 'tx') + call assert_equal(0, g:did_au) + call assert_equal('bar', getline(1)) + + inoremap x xx<Esc> + let g:did_au = 0 + call feedkeys("Saax", 'tx') + call assert_equal(1, g:did_au) + call assert_equal('aaxx', getline(1)) + + inoremap x xx<C-C> + let g:did_au = 0 + call feedkeys("Sbbx", 'tx') + call assert_equal(0, g:did_au) + call assert_equal('bbxx', getline(1)) + + bwipe! + au! InsertLeave + iunmap x +endfunc diff --git a/src/testdir/test_erasebackword.vim b/src/testdir/test_erasebackword.vim new file mode 100644 index 0000000..9522ec2 --- /dev/null +++ b/src/testdir/test_erasebackword.vim @@ -0,0 +1,19 @@ + +func Test_erasebackword() + enew + + exe "normal o wwwこんにちわ世界ワールドvim \<C-W>" + call assert_equal(' wwwこんにちわ世界ワールド', getline('.')) + exe "normal o wwwこんにちわ世界ワールドvim \<C-W>\<C-W>" + call assert_equal(' wwwこんにちわ世界', getline('.')) + exe "normal o wwwこんにちわ世界ワールドvim \<C-W>\<C-W>\<C-W>" + call assert_equal(' wwwこんにちわ', getline('.')) + exe "normal o wwwこんにちわ世界ワールドvim \<C-W>\<C-W>\<C-W>\<C-W>" + call assert_equal(' www', getline('.')) + exe "normal o wwwこんにちわ世界ワールドvim \<C-W>\<C-W>\<C-W>\<C-W>\<C-W>" + call assert_equal(' ', getline('.')) + exe "normal o wwwこんにちわ世界ワールドvim \<C-W>\<C-W>\<C-W>\<C-W>\<C-W>\<C-W>" + call assert_equal('', getline('.')) + + enew! +endfunc diff --git a/src/testdir/test_escaped_glob.vim b/src/testdir/test_escaped_glob.vim new file mode 100644 index 0000000..880f32e --- /dev/null +++ b/src/testdir/test_escaped_glob.vim @@ -0,0 +1,33 @@ +" Test whether glob()/globpath() return correct results with certain escaped +" characters. + +function SetUp() + " consistent sorting of file names + set nofileignorecase +endfunction + +function Test_glob() + if !has('unix') + " This test fails on Windows because of the special characters in the + " filenames. Disable the test on non-Unix systems for now. + return + endif + + " Execute these commands in the sandbox, so that using the shell fails. + " Setting 'shell' to an invalid name causes a memory leak. + sandbox call assert_equal("", glob('Xxx\{')) + sandbox call assert_equal("", glob('Xxx\$')) + w! Xxx{ + w! Xxx\$ + sandbox call assert_equal("Xxx{", glob('Xxx\{')) + sandbox call assert_equal("Xxx$", glob('Xxx\$')) + call delete('Xxx{') + call delete('Xxx$') +endfunction + +function Test_globpath() + sandbox call assert_equal("sautest/autoload/globone.vim\nsautest/autoload/globtwo.vim", + \ globpath('sautest/autoload', 'glob*.vim')) + sandbox call assert_equal(['sautest/autoload/globone.vim', 'sautest/autoload/globtwo.vim'], + \ globpath('sautest/autoload', 'glob*.vim', 0, 1)) +endfunction diff --git a/src/testdir/test_eval.in b/src/testdir/test_eval.in new file mode 100644 index 0000000..3b61442 --- /dev/null +++ b/src/testdir/test_eval.in @@ -0,0 +1,249 @@ +Test for various eval features. vim: set ft=vim : + +NOTE: Do not add more here, use new style test test_eval_stuff.vim + +Note: system clipboard is saved, changed and restored. + +clipboard contents +something else + +STARTTEST +:so small.vim +:set encoding=latin1 +:set noswapfile +:lang C +:fun AppendRegContents(reg) + call AppendRegParts(a:reg, getregtype(a:reg), getreg(a:reg), string(getreg(a:reg, 0, 1)), getreg(a:reg, 1), string(getreg(a:reg, 1, 1))) +:endfun +:fun AppendRegParts(reg, type, cont, strcont, cont1, strcont1) + call append('$', printf('%s: type %s; value: %s (%s), expr: %s (%s)', a:reg, a:type, a:cont, a:strcont, a:cont1, a:strcont1)) +endfun +:command -nargs=? AR :call AppendRegContents(<q-args>) +:fun SetReg(...) + call call('setreg', a:000) + call append('$', printf('{{{2 setreg(%s)', string(a:000)[1:-2])) + call AppendRegContents(a:1) + if a:1 isnot# '=' + execute "silent normal! Go==\n==\e\"".a:1."P" + endif +endfun +:fun ErrExe(str) + call append('$', 'Executing '.a:str) + try + execute a:str + catch + $put =v:exception + endtry +endfun +:fun Test() +$put ='{{{1 let tests' +let @" = 'abc' +AR " +let @" = "abc\n" +AR " +let @" = "abc\<C-m>" +AR " +let @= = '"abc"' +AR = + +$put ='{{{1 Basic setreg tests' +call SetReg('a', 'abcA', 'c') +call SetReg('b', 'abcB', 'v') +call SetReg('c', 'abcC', 'l') +call SetReg('d', 'abcD', 'V') +call SetReg('e', 'abcE', 'b') +call SetReg('f', 'abcF', "\<C-v>") +call SetReg('g', 'abcG', 'b10') +call SetReg('h', 'abcH', "\<C-v>10") +call SetReg('I', 'abcI') + +$put ='{{{1 Appending single lines with setreg()' +call SetReg('A', 'abcAc', 'c') +call SetReg('A', 'abcAl', 'l') +call SetReg('A', 'abcAc2','c') +call SetReg('b', 'abcBc', 'ca') +call SetReg('b', 'abcBb', 'ba') +call SetReg('b', 'abcBc2','ca') +call SetReg('b', 'abcBb2','b50a') + +call SetReg('C', 'abcCl', 'l') +call SetReg('C', 'abcCc', 'c') +call SetReg('D', 'abcDb', 'b') + +call SetReg('E', 'abcEb', 'b') +call SetReg('E', 'abcEl', 'l') +call SetReg('F', 'abcFc', 'c') + +$put ='{{{1 Appending NL with setreg()' +call setreg('a', 'abcA2', 'c') +call setreg('b', 'abcB2', 'v') +call setreg('c', 'abcC2', 'l') +call setreg('d', 'abcD2', 'V') +call setreg('e', 'abcE2', 'b') +call setreg('f', 'abcF2', "\<C-v>") +call setreg('g', 'abcG2', 'b10') +call setreg('h', 'abcH2', "\<C-v>10") +call setreg('I', 'abcI2') + +call SetReg('A', "\n") +call SetReg('B', "\n", 'c') +call SetReg('C', "\n") +call SetReg('D', "\n", 'l') +call SetReg('E', "\n") +call SetReg('F', "\n", 'b') + +$put ='{{{1 Setting lists with setreg()' +call SetReg('a', ['abcA3'], 'c') +call SetReg('b', ['abcB3'], 'l') +call SetReg('c', ['abcC3'], 'b') +call SetReg('d', ['abcD3']) +call SetReg('e', [1, 2, 'abc', 3]) +call SetReg('f', [1, 2, 3]) + +$put ='{{{1 Appending lists with setreg()' +call SetReg('A', ['abcA3c'], 'c') +call SetReg('b', ['abcB3l'], 'la') +call SetReg('C', ['abcC3b'], 'lb') +call SetReg('D', ['abcD32']) + +call SetReg('A', ['abcA32']) +call SetReg('B', ['abcB3c'], 'c') +call SetReg('C', ['abcC3l'], 'l') +call SetReg('D', ['abcD3b'], 'b') + +$put ='{{{1 Appending lists with NL with setreg()' +call SetReg('A', ["\n", 'abcA3l2'], 'l') +call SetReg('B', ["\n", 'abcB3c2'], 'c') +call SetReg('C', ["\n", 'abcC3b2'], 'b') +call SetReg('D', ["\n", 'abcD3b50'],'b50') + +$put ='{{{1 Setting lists with NLs with setreg()' +call SetReg('a', ['abcA4-0', "\n", "abcA4-2\n", "\nabcA4-3", "abcA4-4\nabcA4-4-2"]) +call SetReg('b', ['abcB4c-0', "\n", "abcB4c-2\n", "\nabcB4c-3", "abcB4c-4\nabcB4c-4-2"], 'c') +call SetReg('c', ['abcC4l-0', "\n", "abcC4l-2\n", "\nabcC4l-3", "abcC4l-4\nabcC4l-4-2"], 'l') +call SetReg('d', ['abcD4b-0', "\n", "abcD4b-2\n", "\nabcD4b-3", "abcD4b-4\nabcD4b-4-2"], 'b') +call SetReg('e', ['abcE4b10-0', "\n", "abcE4b10-2\n", "\nabcE4b10-3", "abcE4b10-4\nabcE4b10-4-2"], 'b10') + +$put ='{{{1 Search and expressions' +call SetReg('/', ['abc/']) +call SetReg('/', ["abc/\n"]) +call SetReg('=', ['"abc/"']) +call SetReg('=', ["\"abc/\n\""]) +$put ='{{{1 System clipboard' +if has('clipboard') +" Save and restore system clipboard. +" If no connection to X-Server is possible, test should succeed. +let _clipreg = ['*', getreg('*'), getregtype('*')] +let _clipopt = &cb +let &cb='unnamed' +7y +AR * +tabdo :windo :echo "hi" +8y +AR * +let &cb=_clipopt +call call('setreg', _clipreg) +else + call AppendRegParts('*', 'V', "clipboard contents\n", "['clipboard contents']", "clipboard contents\n", "['clipboard contents']") + call AppendRegParts('*', 'V', "something else\n", "['something else']", "something else\n", "['something else']") +endif +$put ='{{{1 Errors' +call ErrExe('call setreg()') +call ErrExe('call setreg(1)') +call ErrExe('call setreg(1, 2, 3, 4)') +call ErrExe('call setreg([], 2)') +call ErrExe('call setreg(1, {})') +call ErrExe('call setreg(1, 2, [])') +call ErrExe('call setreg("/", ["1", "2"])') +call ErrExe('call setreg("=", ["1", "2"])') +call ErrExe('call setreg(1, ["", "", [], ""])') +endfun +:" +:call Test() +:" +:delfunction SetReg +:delfunction AppendRegContents +:delfunction ErrExe +:delfunction Test +:delcommand AR +:call garbagecollect(1) +:" +:" function name not starting with capital +:try +:func! g:test() +:echo "test" +:endfunc +:catch +:$put =v:exception +:endtry +:" +:" function name includes a colon +:try +:func! b:test() +:echo "test" +:endfunc +:catch +:$put =v:exception +:endtry +:" +:" function name folowed by # +:try +:func! test2() "# +:echo "test2" +:endfunc +:catch +:$put =v:exception +:endtry +:" +:" function name starting with/without "g:", buffer-local funcref. +:function! g:Foo(n) +: $put ='called Foo(' . a:n . ')' +:endfunction +:let b:my_func = function('Foo') +:call b:my_func(1) +:echo g:Foo(2) +:echo Foo(3) +:" +:" script-local function used in Funcref must exist. +:so test_eval_func.vim +:" +:" Using $ instead of '$' must give an error +:try +: call append($, 'foobar') +:catch +:$put =v:exception +:endtry +:" +:$put ='{{{1 getcurpos/setpos' +/^012345678 +6l:let sp = getcurpos() +0:call setpos('.', sp) +jyl:$put +:" +:" substring and variable name +:let str = 'abcdef' +:let n = 3 +:$put =str[n:] +:$put =str[:n] +:$put =str[n:n] +:unlet n +:let nn = 3 +:$put =str[nn:] +:$put =str[:nn] +:$put =str[nn:nn] +:unlet nn +:let b:nn = 4 +:$put =str[b:nn:] +:$put =str[:b:nn] +:$put =str[b:nn:b:nn] +:unlet b:nn +:" +:/^start:/+1,$wq! test.out +:" vim: et ts=4 isk-=\: fmr=???,??? +:call getchar() +ENDTEST + +012345678 +012345678 + +start: diff --git a/src/testdir/test_eval.ok b/src/testdir/test_eval.ok Binary files differnew file mode 100644 index 0000000..9ffa541 --- /dev/null +++ b/src/testdir/test_eval.ok diff --git a/src/testdir/test_eval_func.vim b/src/testdir/test_eval_func.vim new file mode 100644 index 0000000..09d2f62 --- /dev/null +++ b/src/testdir/test_eval_func.vim @@ -0,0 +1,10 @@ +" Vim script used in test_eval.in. Needed for script-local function. + +func s:Testje() + return "foo" +endfunc +let Bar = function('s:Testje') +$put ='s:Testje exists: ' . exists('s:Testje') +$put ='func s:Testje exists: ' . exists('*s:Testje') +$put ='Bar exists: ' . exists('Bar') +$put ='func Bar exists: ' . exists('*Bar') diff --git a/src/testdir/test_eval_stuff.vim b/src/testdir/test_eval_stuff.vim new file mode 100644 index 0000000..f4b3598 --- /dev/null +++ b/src/testdir/test_eval_stuff.vim @@ -0,0 +1,96 @@ +" Tests for various eval things. + +function s:foo() abort + try + return [] == 0 + catch + return 1 + endtry +endfunction + +func Test_catch_return_with_error() + call assert_equal(1, s:foo()) +endfunc + +func Test_nocatch_restore_silent_emsg() + silent! try + throw 1 + catch + endtry + echoerr 'wrong' + let c1 = nr2char(screenchar(&lines, 1)) + let c2 = nr2char(screenchar(&lines, 2)) + let c3 = nr2char(screenchar(&lines, 3)) + let c4 = nr2char(screenchar(&lines, 4)) + let c5 = nr2char(screenchar(&lines, 5)) + call assert_equal('wrong', c1 . c2 . c3 . c4 . c5) +endfunc + +func Test_mkdir_p() + call mkdir('Xmkdir/nested', 'p') + call assert_true(isdirectory('Xmkdir/nested')) + try + " Trying to make existing directories doesn't error + call mkdir('Xmkdir', 'p') + call mkdir('Xmkdir/nested', 'p') + catch /E739:/ + call assert_report('mkdir(..., "p") failed for an existing directory') + endtry + " 'p' doesn't suppress real errors + call writefile([], 'Xfile') + call assert_fails('call mkdir("Xfile", "p")', 'E739') + call delete('Xfile') + call delete('Xmkdir', 'rf') +endfunc + +func Test_line_continuation() + let array = [5, + "\ ignore this + \ 6, + "\ more to ignore + "\ more moreto ignore + \ ] + "\ and some more + call assert_equal([5, 6], array) +endfunc + +func Test_E963() + " These commands used to cause an internal error prior to vim 8.1.0563 + let v_e = v:errors + let v_o = v:oldfiles + call assert_fails("let v:errors=''", 'E963:') + call assert_equal(v_e, v:errors) + call assert_fails("let v:oldfiles=''", 'E963:') + call assert_equal(v_o, v:oldfiles) +endfunc + +func Test_for_invalid() + call assert_fails("for x in 99", 'E714:') + call assert_fails("for x in 'asdf'", 'E714:') + call assert_fails("for x in {'a': 9}", 'E714:') +endfunc + +func Test_readfile_binary() + new + call setline(1, ['one', 'two', 'three']) + setlocal ff=dos + write XReadfile + let lines = readfile('XReadfile') + call assert_equal(['one', 'two', 'three'], lines) + let lines = readfile('XReadfile', '', 2) + call assert_equal(['one', 'two'], lines) + let lines = readfile('XReadfile', 'b') + call assert_equal(["one\r", "two\r", "three\r", ""], lines) + let lines = readfile('XReadfile', 'b', 2) + call assert_equal(["one\r", "two\r"], lines) + + bwipe! + call delete('XReadfile') +endfunc + +func Test_let_errmsg() + call assert_fails('let v:errmsg = []', 'E730:') + let v:errmsg = '' + call assert_fails('let v:errmsg = []', 'E730:') + let v:errmsg = '' +endfunc diff --git a/src/testdir/test_ex_equal.vim b/src/testdir/test_ex_equal.vim new file mode 100644 index 0000000..05ad276 --- /dev/null +++ b/src/testdir/test_ex_equal.vim @@ -0,0 +1,32 @@ +" Test Ex := command. + +func Test_ex_equal() + new + call setline(1, ["foo\tbar", "bar\tfoo"]) + + let a = execute('=') + call assert_equal("\n2", a) + + let a = execute('=#') + call assert_equal("\n2\n 1 foo bar", a) + + let a = execute('=l') + call assert_equal("\n2\nfoo^Ibar$", a) + + let a = execute('=p') + call assert_equal("\n2\nfoo bar", a) + + let a = execute('=l#') + call assert_equal("\n2\n 1 foo^Ibar$", a) + + let a = execute('=p#') + call assert_equal("\n2\n 1 foo bar", a) + + let a = execute('.=') + call assert_equal("\n1", a) + + call assert_fails('3=', 'E16:') + call assert_fails('=x', 'E488:') + + bwipe! +endfunc diff --git a/src/testdir/test_ex_undo.vim b/src/testdir/test_ex_undo.vim new file mode 100644 index 0000000..44feb36 --- /dev/null +++ b/src/testdir/test_ex_undo.vim @@ -0,0 +1,19 @@ +" Tests for :undo + +func Test_ex_undo() + new ex-undo + setlocal ul=10 + exe "normal ione\n\<Esc>" + setlocal ul=10 + exe "normal itwo\n\<Esc>" + setlocal ul=10 + exe "normal ithree\n\<Esc>" + call assert_equal(4, line('$')) + undo + call assert_equal(3, line('$')) + undo 1 + call assert_equal(2, line('$')) + undo 0 + call assert_equal(1, line('$')) + quit! +endfunc diff --git a/src/testdir/test_ex_z.vim b/src/testdir/test_ex_z.vim new file mode 100644 index 0000000..6e03b0b --- /dev/null +++ b/src/testdir/test_ex_z.vim @@ -0,0 +1,85 @@ +" Test :z + +func Test_z() + call setline(1, range(1, 100)) + + let a = execute('20z3') + call assert_equal("\n20\n21\n22", a) + call assert_equal(22, line('.')) + " 'window' should be set to the {count} value. + call assert_equal(3, &window) + + " If there is only one window, then twice the amount of 'scroll' is used. + set scroll=2 + let a = execute('20z') + call assert_equal("\n20\n21\n22\n23", a) + call assert_equal(23, line('.')) + + let a = execute('20z+3') + " FIXME: I would expect the same result as '20z3' but it + " gives "\n21\n22\n23" instead. Bug in Vim or in ":help :z"? + "call assert_equal("\n20\n21\n22", a) + "call assert_equal(22, line('.')) + + let a = execute('20z-3') + call assert_equal("\n18\n19\n20", a) + call assert_equal(20, line('.')) + + let a = execute('20z=3') + call assert_match("^\n18\n19\n-\\+\n20\n-\\+\n21\n22$", a) + call assert_equal(20, line('.')) + + let a = execute('20z^3') + call assert_equal("\n14\n15\n16\n17", a) + call assert_equal(17, line('.')) + + let a = execute('20z.3') + call assert_equal("\n19\n20\n21", a) + call assert_equal(21, line('.')) + + let a = execute('20z#3') + call assert_equal("\n 20 20\n 21 21\n 22 22", a) + call assert_equal(22, line('.')) + + let a = execute('20z#-3') + call assert_equal("\n 18 18\n 19 19\n 20 20", a) + call assert_equal(20, line('.')) + + let a = execute('20z#=3') + call assert_match("^\n 18 18\n 19 19\n-\\+\n 20 20\n-\\+\n 21 21\n 22 22$", a) + call assert_equal(20, line('.')) + + " Test with {count} bigger than the number of lines in buffer. + let a = execute('20z1000') + call assert_match("^\n20\n21\n.*\n99\n100$", a) + call assert_equal(100, line('.')) + + let a = execute('20z-1000') + call assert_match("^\n1\n2\n.*\n19\n20$", a) + call assert_equal(20, line('.')) + + let a = execute('20z=1000') + call assert_match("^\n1\n.*\n-\\+\n20\n-\\\+\n.*\n100$", a) + call assert_equal(20, line('.')) + + call assert_fails('20z=a', 'E144:') + + set window& scroll& + bw! +endfunc + +func Test_z_overflow() + " This used to access invalid memory as a result of an integer overflow + " and freeze vim. + normal ox + normal Heat + z777777776666666 + ') +endfunc + +func Test_z_negative_lnum() + new + z^ + call assert_equal(1, line('.')) + bwipe! +endfunc diff --git a/src/testdir/test_exec_while_if.vim b/src/testdir/test_exec_while_if.vim new file mode 100644 index 0000000..d6afabf --- /dev/null +++ b/src/testdir/test_exec_while_if.vim @@ -0,0 +1,53 @@ +" Test for :execute, :while and :if + +function Test_exec_while_if() + new + + let i = 0 + while i < 12 + let i = i + 1 + if has("ebcdic") + execute "normal o" . i . "\047" + else + execute "normal o" . i . "\033" + endif + if i % 2 + normal Ax + if i == 9 + break + endif + if i == 5 + continue + else + let j = 9 + while j > 0 + if has("ebcdic") + execute "normal" j . "a" . j . "\x27" + else + execute "normal" j . "a" . j . "\x1b" + endif + let j = j - 1 + endwhile + endif + endif + if i == 9 + if has("ebcdic") + execute "normal Az\047" + else + execute "normal Az\033" + endif + endif + endwhile + unlet i j + + call assert_equal(["", + \ "1x999999999888888887777777666666555554444333221", + \ "2", + \ "3x999999999888888887777777666666555554444333221", + \ "4", + \ "5x", + \ "6", + \ "7x999999999888888887777777666666555554444333221", + \ "8", + \ "9x"], getline(1, 10)) +endfunction diff --git a/src/testdir/test_execute_func.vim b/src/testdir/test_execute_func.vim new file mode 100644 index 0000000..b84fbeb --- /dev/null +++ b/src/testdir/test_execute_func.vim @@ -0,0 +1,80 @@ +" test execute() + +func NestedEval() + let nested = execute('echo "nested\nlines"') + echo 'got: "' . nested . '"' +endfunc + +func NestedRedir() + redir => var + echo 'broken' + redir END +endfunc + +func Test_execute_string() + call assert_equal("\nnocompatible", execute('set compatible?')) + call assert_equal("\nsomething\nnice", execute('echo "something\nnice"')) + call assert_equal("noendofline", execute('echon "noendofline"')) + call assert_equal("", execute(123)) + + call assert_equal("\ngot: \"\nnested\nlines\"", execute('call NestedEval()')) + redir => redired + echo 'this' + let evaled = execute('echo "that"') + echo 'theend' + redir END + call assert_equal("\nthis\ntheend", redired) + call assert_equal("\nthat", evaled) + + call assert_fails('call execute("doesnotexist")', 'E492:') + call assert_fails('call execute(3.4)', 'E806:') + call assert_fails('call execute("call NestedRedir()")', 'E930:') + + call assert_equal("\nsomething", execute('echo "something"', '')) + call assert_equal("\nsomething", execute('echo "something"', 'silent')) + call assert_equal("\nsomething", execute('echo "something"', 'silent!')) + call assert_equal("", execute('burp', 'silent!')) + call assert_fails('call execute("echo \"x\"", 3.4)', 'E806:') + + call assert_equal("", execute(test_null_string())) +endfunc + +func Test_execute_list() + call assert_equal("\nsomething\nnice", execute(['echo "something"', 'echo "nice"'])) + let l = ['for n in range(0, 3)', + \ 'echo n', + \ 'endfor'] + call assert_equal("\n0\n1\n2\n3", execute(l)) + + call assert_equal("", execute([])) + call assert_equal("", execute(test_null_list())) +endfunc + +func Test_execute_does_not_change_col() + echo '' + echon 'abcd' + let x = execute('silent echo 234343') + echon 'xyz' + let text = '' + for col in range(1, 7) + let text .= nr2char(screenchar(&lines, col)) + endfor + call assert_equal('abcdxyz', text) +endfunc + +func Test_execute_not_silent() + echo '' + echon 'abcd' + let x = execute('echon 234', '') + echo 'xyz' + let text1 = '' + for col in range(1, 8) + let text1 .= nr2char(screenchar(&lines - 1, col)) + endfor + call assert_equal('abcd234 ', text1) + let text2 = '' + for col in range(1, 4) + let text2 .= nr2char(screenchar(&lines, col)) + endfor + call assert_equal('xyz ', text2) +endfunc diff --git a/src/testdir/test_exists.vim b/src/testdir/test_exists.vim new file mode 100644 index 0000000..fd34be8 --- /dev/null +++ b/src/testdir/test_exists.vim @@ -0,0 +1,321 @@ +" Tests for the exists() function +func Test_exists() + augroup myagroup + autocmd! BufEnter *.my echo "myfile edited" + autocmd! FuncUndefined UndefFun exec "fu UndefFun()\nendfu" + augroup END + set rtp+=./sautest + + " valid autocmd group + call assert_equal(1, exists('#myagroup')) + " valid autocmd group with garbage + call assert_equal(0, exists('#myagroup+b')) + " Valid autocmd group and event + call assert_equal(1, exists('#myagroup#BufEnter')) + " Valid autocmd group, event and pattern + call assert_equal(1, exists('#myagroup#BufEnter#*.my')) + " Valid autocmd event + call assert_equal(1, exists('#BufEnter')) + " Valid autocmd event and pattern + call assert_equal(1, exists('#BufEnter#*.my')) + " Non-existing autocmd group or event + call assert_equal(0, exists('#xyzagroup')) + " Non-existing autocmd group and valid autocmd event + call assert_equal(0, exists('#xyzagroup#BufEnter')) + " Valid autocmd group and event with no matching pattern + call assert_equal(0, exists('#myagroup#CmdwinEnter')) + " Valid autocmd group and non-existing autocmd event + call assert_equal(0, exists('#myagroup#xyzacmd')) + " Valid autocmd group and event and non-matching pattern + call assert_equal(0, exists('#myagroup#BufEnter#xyzpat')) + " Valid autocmd event and non-matching pattern + call assert_equal(0, exists('#BufEnter#xyzpat')) + " Empty autocmd group, event and pattern + call assert_equal(0, exists('###')) + " Empty autocmd group and event or empty event and pattern + call assert_equal(0, exists('##')) + " Valid autocmd event + call assert_equal(1, exists('##FileReadCmd')) + " Non-existing autocmd event + call assert_equal(0, exists('##MySpecialCmd')) + + " Existing and working option (long form) + call assert_equal(1, exists('&textwidth')) + " Existing and working option (short form) + call assert_equal(1, exists('&tw')) + " Existing and working option with garbage + call assert_equal(0, exists('&tw-')) + " Global option + call assert_equal(1, exists('&g:errorformat')) + " Local option + call assert_equal(1, exists('&l:errorformat')) + " Negative form of existing and working option (long form) + call assert_equal(0, exists('&nojoinspaces')) + " Negative form of existing and working option (short form) + call assert_equal(0, exists('&nojs')) + " Non-existing option + call assert_equal(0, exists('&myxyzoption')) + + " Existing and working option (long form) + call assert_equal(1, exists('+incsearch')) + " Existing and working option with garbage + call assert_equal(0, exists('+incsearch!1')) + " Existing and working option (short form) + call assert_equal(1, exists('+is')) + " Existing option that is hidden. + call assert_equal(0, exists('+autoprint')) + + " Existing environment variable + let $EDITOR_NAME = 'Vim Editor' + call assert_equal(1, exists('$EDITOR_NAME')) + " Non-existing environment variable + call assert_equal(0, exists('$NON_ENV_VAR')) + + " Valid internal function + call assert_equal(1, exists('*bufnr')) + " Valid internal function with () + call assert_equal(1, exists('*bufnr()')) + " Non-existing internal function + call assert_equal(0, exists('*myxyzfunc')) + " Valid internal function with garbage + call assert_equal(0, exists('*bufnr&6')) + " Valid user defined function + call assert_equal(1, exists('*Test_exists')) + " Non-existing user defined function + call assert_equal(0, exists('*MyxyzFunc')) + " Function that may be created by FuncUndefined event + call assert_equal(0, exists('*UndefFun')) + " Function that may be created by script autoloading + call assert_equal(0, exists('*footest#F')) + + " Valid internal command (full match) + call assert_equal(2, exists(':edit')) + " Valid internal command (full match) with garbage + call assert_equal(0, exists(':edit/a')) + " Valid internal command (partial match) + call assert_equal(1, exists(':q')) + " Non-existing internal command + call assert_equal(0, exists(':invalidcmd')) + + " User defined command (full match) + command! MyCmd :echo 'My command' + call assert_equal(2, exists(':MyCmd')) + " User defined command (partial match) + command! MyOtherCmd :echo 'Another command' + call assert_equal(3, exists(':My')) + + " Command modifier + call assert_equal(2, exists(':rightbelow')) + + " Non-existing user defined command (full match) + delcommand MyCmd + call assert_equal(0, exists(':MyCmd')) + + " Non-existing user defined command (partial match) + delcommand MyOtherCmd + call assert_equal(0, exists(':My')) + + " Valid local variable + let local_var = 1 + call assert_equal(1, exists('local_var')) + " Valid local variable with garbage + call assert_equal(0, exists('local_var%n')) + " Non-existing local variable + unlet local_var + call assert_equal(0, exists('local_var')) + + " Non-existing autoload variable that may be autoloaded + call assert_equal(0, exists('footest#x')) + + " Valid local list + let local_list = ["blue", "orange"] + call assert_equal(1, exists('local_list')) + " Valid local list item + call assert_equal(1, exists('local_list[1]')) + " Valid local list item with garbage + call assert_equal(0, exists('local_list[1]+5')) + " Invalid local list item + call assert_equal(0, exists('local_list[2]')) + " Non-existing local list + unlet local_list + call assert_equal(0, exists('local_list')) + " Valid local dictionary + let local_dict = {"xcord":100, "ycord":2} + call assert_equal(1, exists('local_dict')) + " Non-existing local dictionary + unlet local_dict + call assert_equal(0, exists('local_dict')) + " Existing local curly-brace variable + let str = "local" + let curly_{str}_var = 1 + call assert_equal(1, exists('curly_{str}_var')) + " Non-existing local curly-brace variable + unlet curly_{str}_var + call assert_equal(0, exists('curly_{str}_var')) + + " Existing global variable + let g:global_var = 1 + call assert_equal(1, exists('g:global_var')) + " Existing global variable with garbage + call assert_equal(0, exists('g:global_var-n')) + " Non-existing global variable + unlet g:global_var + call assert_equal(0, exists('g:global_var')) + " Existing global list + let g:global_list = ["blue", "orange"] + call assert_equal(1, exists('g:global_list')) + " Non-existing global list + unlet g:global_list + call assert_equal(0, exists('g:global_list')) + " Existing global dictionary + let g:global_dict = {"xcord":100, "ycord":2} + call assert_equal(1, exists('g:global_dict')) + " Non-existing global dictionary + unlet g:global_dict + call assert_equal(0, exists('g:global_dict')) + " Existing global curly-brace variable + let str = "global" + let g:curly_{str}_var = 1 + call assert_equal(1, exists('g:curly_{str}_var')) + " Non-existing global curly-brace variable + unlet g:curly_{str}_var + call assert_equal(0, exists('g:curly_{str}_var')) + + " Existing window variable + let w:window_var = 1 + call assert_equal(1, exists('w:window_var')) + " Non-existing window variable + unlet w:window_var + call assert_equal(0, exists('w:window_var')) + " Existing window list + let w:window_list = ["blue", "orange"] + call assert_equal(1, exists('w:window_list')) + " Non-existing window list + unlet w:window_list + call assert_equal(0, exists('w:window_list')) + " Existing window dictionary + let w:window_dict = {"xcord":100, "ycord":2} + call assert_equal(1, exists('w:window_dict')) + " Non-existing window dictionary + unlet w:window_dict + call assert_equal(0, exists('w:window_dict')) + " Existing window curly-brace variable + let str = "window" + let w:curly_{str}_var = 1 + call assert_equal(1, exists('w:curly_{str}_var')) + " Non-existing window curly-brace variable + unlet w:curly_{str}_var + call assert_equal(0, exists('w:curly_{str}_var')) + + " Existing tab variable + let t:tab_var = 1 + call assert_equal(1, exists('t:tab_var')) + " Non-existing tab variable + unlet t:tab_var + call assert_equal(0, exists('t:tab_var')) + " Existing tab list + let t:tab_list = ["blue", "orange"] + call assert_equal(1, exists('t:tab_list')) + " Non-existing tab list + unlet t:tab_list + call assert_equal(0, exists('t:tab_list')) + " Existing tab dictionary + let t:tab_dict = {"xcord":100, "ycord":2} + call assert_equal(1, exists('t:tab_dict')) + " Non-existing tab dictionary + unlet t:tab_dict + call assert_equal(0, exists('t:tab_dict')) + " Existing tab curly-brace variable + let str = "tab" + let t:curly_{str}_var = 1 + call assert_equal(1, exists('t:curly_{str}_var')) + " Non-existing tab curly-brace variable + unlet t:curly_{str}_var + call assert_equal(0, exists('t:curly_{str}_var')) + + " Existing buffer variable + let b:buffer_var = 1 + call assert_equal(1, exists('b:buffer_var')) + " Non-existing buffer variable + unlet b:buffer_var + call assert_equal(0, exists('b:buffer_var')) + " Existing buffer list + let b:buffer_list = ["blue", "orange"] + call assert_equal(1, exists('b:buffer_list')) + " Non-existing buffer list + unlet b:buffer_list + call assert_equal(0, exists('b:buffer_list')) + " Existing buffer dictionary + let b:buffer_dict = {"xcord":100, "ycord":2} + call assert_equal(1, exists('b:buffer_dict')) + " Non-existing buffer dictionary + unlet b:buffer_dict + call assert_equal(0, exists('b:buffer_dict')) + " Existing buffer curly-brace variable + let str = "buffer" + let b:curly_{str}_var = 1 + call assert_equal(1, exists('b:curly_{str}_var')) + " Non-existing buffer curly-brace variable + unlet b:curly_{str}_var + call assert_equal(0, exists('b:curly_{str}_var')) + + " Existing Vim internal variable + call assert_equal(1, exists('v:version')) + " Non-existing Vim internal variable + call assert_equal(0, exists('v:non_exists_var')) + + " Existing script-local variable + let s:script_var = 1 + call assert_equal(1, exists('s:script_var')) + " Non-existing script-local variable + unlet s:script_var + call assert_equal(0, exists('s:script_var')) + " Existing script-local list + let s:script_list = ["blue", "orange"] + call assert_equal(1, exists('s:script_list')) + " Non-existing script-local list + unlet s:script_list + call assert_equal(0, exists('s:script_list')) + " Existing script-local dictionary + let s:script_dict = {"xcord":100, "ycord":2} + call assert_equal(1, exists('s:script_dict')) + " Non-existing script-local dictionary + unlet s:script_dict + call assert_equal(0, exists('s:script_dict')) + " Existing script curly-brace variable + let str = "script" + let s:curly_{str}_var = 1 + call assert_equal(1, exists('s:curly_{str}_var')) + " Non-existing script-local curly-brace variable + unlet s:curly_{str}_var + call assert_equal(0, exists('s:curly_{str}_var')) + + " Existing script-local function + function! s:my_script_func() + endfunction + + echo '*s:my_script_func: 1' + call assert_equal(1, exists('*s:my_script_func')) + + " Non-existing script-local function + delfunction s:my_script_func + + call assert_equal(0, exists('*s:my_script_func')) + unlet str + + call assert_equal(1, g:footest#x) + call assert_equal(0, footest#F()) + call assert_equal(0, UndefFun()) +endfunc + +" exists() test for Function arguments +func FuncArg_Tests(func_arg, ...) + call assert_equal(1, exists('a:func_arg')) + call assert_equal(0, exists('a:non_exists_arg')) + call assert_equal(1, exists('a:1')) + call assert_equal(0, exists('a:2')) +endfunc + +func Test_exists_funcarg() + call FuncArg_Tests("arg1", "arg2") +endfunc diff --git a/src/testdir/test_exists_autocmd.vim b/src/testdir/test_exists_autocmd.vim new file mode 100644 index 0000000..7e44a72 --- /dev/null +++ b/src/testdir/test_exists_autocmd.vim @@ -0,0 +1,26 @@ +" Test that groups and patterns are tested correctly when calling exists() for +" autocommands. + +function Test_AutoCommands() + let results=[] + augroup auexists + augroup END + call assert_true(exists("##BufEnter")) + call assert_false(exists("#BufEnter")) + au BufEnter * let g:entered=1 + call assert_true(exists("#BufEnter")) + call assert_false(exists("#auexists#BufEnter")) + augroup auexists + au BufEnter * let g:entered=1 + augroup END + call assert_true(exists("#auexists#BufEnter")) + call assert_false(exists("#BufEnter#*.test")) + au BufEnter *.test let g:entered=1 + call assert_true(exists("#BufEnter#*.test")) + edit testfile.test + call assert_false(exists("#BufEnter#<buffer>")) + au BufEnter <buffer> let g:entered=1 + call assert_true(exists("#BufEnter#<buffer>")) + edit testfile2.test + call assert_false(exists("#BufEnter#<buffer>")) +endfunction diff --git a/src/testdir/test_exit.vim b/src/testdir/test_exit.vim new file mode 100644 index 0000000..8f02fd2 --- /dev/null +++ b/src/testdir/test_exit.vim @@ -0,0 +1,57 @@ +" Tests for exiting Vim. + +source shared.vim + +func Test_exiting() + let after = [ + \ 'au QuitPre * call writefile(["QuitPre"], "Xtestout")', + \ 'au ExitPre * call writefile(["ExitPre"], "Xtestout", "a")', + \ 'quit', + \ ] + if RunVim([], after, '') + call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout')) + endif + call delete('Xtestout') + + let after = [ + \ 'au QuitPre * call writefile(["QuitPre"], "Xtestout")', + \ 'au ExitPre * call writefile(["ExitPre"], "Xtestout", "a")', + \ 'help', + \ 'wincmd w', + \ 'quit', + \ ] + if RunVim([], after, '') + call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout')) + endif + call delete('Xtestout') + + let after = [ + \ 'au QuitPre * call writefile(["QuitPre"], "Xtestout")', + \ 'au ExitPre * call writefile(["ExitPre"], "Xtestout", "a")', + \ 'split', + \ 'new', + \ 'qall', + \ ] + if RunVim([], after, '') + call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout')) + endif + call delete('Xtestout') + + let after = [ + \ 'au QuitPre * call writefile(["QuitPre"], "Xtestout", "a")', + \ 'au ExitPre * call writefile(["ExitPre"], "Xtestout", "a")', + \ 'augroup nasty', + \ ' au ExitPre * split', + \ 'augroup END', + \ 'quit', + \ 'augroup nasty', + \ ' au! ExitPre', + \ 'augroup END', + \ 'quit', + \ ] + if RunVim([], after, '') + call assert_equal(['QuitPre', 'ExitPre', 'QuitPre', 'ExitPre'], + \ readfile('Xtestout')) + endif + call delete('Xtestout') +endfunc diff --git a/src/testdir/test_expand.vim b/src/testdir/test_expand.vim new file mode 100644 index 0000000..b4f1363 --- /dev/null +++ b/src/testdir/test_expand.vim @@ -0,0 +1,49 @@ +" Test for expanding file names + +func Test_with_directories() + call mkdir('Xdir1') + call mkdir('Xdir2') + call mkdir('Xdir3') + cd Xdir3 + call mkdir('Xdir4') + cd .. + + split Xdir1/file + call setline(1, ['a', 'b']) + w + w Xdir3/Xdir4/file + close + + next Xdir?/*/file + call assert_equal('Xdir3/Xdir4/file', expand('%')) + if has('unix') + next! Xdir?/*/nofile + call assert_equal('Xdir?/*/nofile', expand('%')) + endif + " Edit another file, on MS-Windows the swap file would be in use and can't + " be deleted. + edit foo + + call assert_equal(0, delete('Xdir1', 'rf')) + call assert_equal(0, delete('Xdir2', 'rf')) + call assert_equal(0, delete('Xdir3', 'rf')) +endfunc + +func Test_with_tilde() + let dir = getcwd() + call mkdir('Xdir ~ dir') + call assert_true(isdirectory('Xdir ~ dir')) + cd Xdir\ ~\ dir + call assert_true(getcwd() =~ 'Xdir \~ dir') + exe 'cd ' . fnameescape(dir) + call delete('Xdir ~ dir', 'd') + call assert_false(isdirectory('Xdir ~ dir')) +endfunc + +func Test_expand_tilde_filename() + split ~ + call assert_equal('~', expand('%')) + call assert_notequal(expand('%:p'), expand('~/')) + call assert_match('\~', expand('%:p')) + bwipe! +endfunc diff --git a/src/testdir/test_expand_dllpath.vim b/src/testdir/test_expand_dllpath.vim new file mode 100644 index 0000000..1542095 --- /dev/null +++ b/src/testdir/test_expand_dllpath.vim @@ -0,0 +1,32 @@ +func s:test_expand_dllpath(optname) + let $TEST_EXPAND_DLLPATH = '/dllpath/lib' . substitute(a:optname, '\zedll$', '.', '') + execute 'let dllpath_save = &' . a:optname + try + execute 'set ' . a:optname . '=$TEST_EXPAND_DLLPATH' + execute 'call assert_equal("' . $TEST_EXPAND_DLLPATH . '", &' . a:optname . ')' + + execute 'set ' . a:optname . '=~' . $TEST_EXPAND_DLLPATH + let home = substitute($HOME, '\\', '/', 'g') + execute 'call assert_equal("' . home . $TEST_EXPAND_DLLPATH . '", &' . a:optname . ')' + finally + execute 'let &' . a:optname . ' = dllpath_save' + let $TEST_EXPAND_DLLPATH = '' + endtry +endfunc + +func s:generate_test_if_exists(optname) + if exists('+' . a:optname) + execute join([ + \ 'func Test_expand_' . a:optname . '()', + \ ' call s:test_expand_dllpath("' . a:optname . '")', + \ 'endfunc' + \ ], "\n") + endif +endfunc + +call s:generate_test_if_exists('luadll') +call s:generate_test_if_exists('perldll') +call s:generate_test_if_exists('pythondll') +call s:generate_test_if_exists('pythonthreedll') +call s:generate_test_if_exists('rubydll') +call s:generate_test_if_exists('tcldll') diff --git a/src/testdir/test_expand_func.vim b/src/testdir/test_expand_func.vim new file mode 100644 index 0000000..fb29c3e --- /dev/null +++ b/src/testdir/test_expand_func.vim @@ -0,0 +1,66 @@ +" Tests for expand() + +let s:sfile = expand('<sfile>') +let s:slnum = str2nr(expand('<slnum>')) +let s:sflnum = str2nr(expand('<sflnum>')) + +func s:expand_sfile() + return expand('<sfile>') +endfunc + +func s:expand_slnum() + return str2nr(expand('<slnum>')) +endfunc + +func s:expand_sflnum() + return str2nr(expand('<sflnum>')) +endfunc + +func Test_expand_sfile() + call assert_match('test_expand_func\.vim$', s:sfile) + call assert_match('^function .*\.\.Test_expand_sfile$', expand('<sfile>')) + + " Call in script-local function + call assert_match('^function .*\.\.Test_expand_sfile\[5\]\.\.<SNR>\d\+_expand_sfile$', s:expand_sfile()) + + " Call in command + command Sfile echo expand('<sfile>') + call assert_match('^function .*\.\.Test_expand_sfile$', trim(execute('Sfile'))) + delcommand Sfile +endfunc + +func Test_expand_slnum() + call assert_equal(4, s:slnum) + call assert_equal(2, str2nr(expand('<slnum>'))) + + " Line-continuation + call assert_equal( + \ 5, + \ str2nr(expand('<slnum>'))) + + " Call in script-local function + call assert_equal(1, s:expand_slnum()) + + " Call in command + command Slnum echo expand('<slnum>') + call assert_equal(14, str2nr(trim(execute('Slnum')))) + delcommand Slnum +endfunc + +func Test_expand_sflnum() + call assert_equal(5, s:sflnum) + call assert_equal(52, str2nr(expand('<sflnum>'))) + + " Line-continuation + call assert_equal( + \ 55, + \ str2nr(expand('<sflnum>'))) + + " Call in script-local function + call assert_equal(16, s:expand_sflnum()) + + " Call in command + command Flnum echo expand('<sflnum>') + call assert_equal(64, str2nr(trim(execute('Flnum')))) + delcommand Flnum +endfunc diff --git a/src/testdir/test_expr.vim b/src/testdir/test_expr.vim new file mode 100644 index 0000000..216a00f --- /dev/null +++ b/src/testdir/test_expr.vim @@ -0,0 +1,514 @@ +" Tests for expressions. + +func Test_equal() + let base = {} + func base.method() + return 1 + endfunc + func base.other() dict + return 1 + endfunc + let instance = copy(base) + call assert_true(base.method == instance.method) + call assert_true([base.method] == [instance.method]) + call assert_true(base.other == instance.other) + call assert_true([base.other] == [instance.other]) + + call assert_false(base.method == base.other) + call assert_false([base.method] == [base.other]) + call assert_false(base.method == instance.other) + call assert_false([base.method] == [instance.other]) + + call assert_fails('echo base.method > instance.method') +endfunc + +func Test_version() + call assert_true(has('patch-7.4.001')) + call assert_true(has('patch-7.4.01')) + call assert_true(has('patch-7.4.1')) + call assert_true(has('patch-6.9.999')) + call assert_true(has('patch-7.1.999')) + call assert_true(has('patch-7.4.123')) + + call assert_false(has('patch-7')) + call assert_false(has('patch-7.4')) + call assert_false(has('patch-7.4.')) + call assert_false(has('patch-9.1.0')) + call assert_false(has('patch-9.9.1')) +endfunc + +func Test_dict() + let d = {'': 'empty', 'a': 'a', 0: 'zero'} + call assert_equal('empty', d['']) + call assert_equal('a', d['a']) + call assert_equal('zero', d[0]) + call assert_true(has_key(d, '')) + call assert_true(has_key(d, 'a')) + + let d[''] = 'none' + let d['a'] = 'aaa' + call assert_equal('none', d['']) + call assert_equal('aaa', d['a']) +endfunc + +func Test_strgetchar() + call assert_equal(char2nr('a'), strgetchar('axb', 0)) + call assert_equal(char2nr('x'), strgetchar('axb', 1)) + call assert_equal(char2nr('b'), strgetchar('axb', 2)) + + call assert_equal(-1, strgetchar('axb', -1)) + call assert_equal(-1, strgetchar('axb', 3)) + call assert_equal(-1, strgetchar('', 0)) +endfunc + +func Test_strcharpart() + call assert_equal('a', strcharpart('axb', 0, 1)) + call assert_equal('x', strcharpart('axb', 1, 1)) + call assert_equal('b', strcharpart('axb', 2, 1)) + call assert_equal('xb', strcharpart('axb', 1)) + + call assert_equal('', strcharpart('axb', 1, 0)) + call assert_equal('', strcharpart('axb', 1, -1)) + call assert_equal('', strcharpart('axb', -1, 1)) + call assert_equal('', strcharpart('axb', -2, 2)) + + call assert_equal('a', strcharpart('axb', -1, 2)) +endfunc + +func Test_getreg_empty_list() + call assert_equal('', getreg('x')) + call assert_equal([], getreg('x', 1, 1)) + let x = getreg('x', 1, 1) + let y = x + call add(x, 'foo') + call assert_equal(['foo'], y) +endfunc + +func Test_loop_over_null_list() + let null_list = test_null_list() + for i in null_list + call assert_report('should not get here') + endfor +endfunc + +func Test_compare_null_dict() + call assert_fails('let x = test_null_dict()[10]') + call assert_equal({}, {}) + call assert_equal(test_null_dict(), test_null_dict()) + call assert_notequal({}, test_null_dict()) +endfunc + +func Test_set_reg_null_list() + call setreg('x', test_null_list()) +endfunc + +func Test_special_char() + " The failure is only visible using valgrind. + call assert_fails('echo "\<C-">') +endfunc + +func Test_option_value() + " boolean + set bri + call assert_equal(1, &bri) + set nobri + call assert_equal(0, &bri) + + " number + set ts=1 + call assert_equal(1, &ts) + set ts=8 + call assert_equal(8, &ts) + + " string + exe "set cedit=\<Esc>" + call assert_equal("\<Esc>", &cedit) + set cpo= + call assert_equal("", &cpo) + set cpo=abcdefgi + call assert_equal("abcdefgi", &cpo) + set cpo&vim +endfunc + +function Test_printf_misc() + call assert_equal('123', printf('123')) + call assert_fails("call printf('123', 3)", "E767:") + + call assert_equal('123', printf('%d', 123)) + call assert_equal('123', printf('%i', 123)) + call assert_equal('123', printf('%D', 123)) + call assert_equal('123', printf('%U', 123)) + call assert_equal('173', printf('%o', 123)) + call assert_equal('173', printf('%O', 123)) + call assert_equal('7b', printf('%x', 123)) + call assert_equal('7B', printf('%X', 123)) + + call assert_equal('123', printf('%hd', 123)) + call assert_equal('-123', printf('%hd', -123)) + call assert_equal('-1', printf('%hd', 0xFFFF)) + call assert_equal('-1', printf('%hd', 0x1FFFFF)) + + call assert_equal('123', printf('%hu', 123)) + call assert_equal('65413', printf('%hu', -123)) + call assert_equal('65535', printf('%hu', 0xFFFF)) + call assert_equal('65535', printf('%hu', 0x1FFFFF)) + + call assert_equal('123', printf('%ld', 123)) + call assert_equal('-123', printf('%ld', -123)) + call assert_equal('65535', printf('%ld', 0xFFFF)) + call assert_equal('131071', printf('%ld', 0x1FFFF)) + + if has('ebcdic') + call assert_equal('#', printf('%c', 123)) + else + call assert_equal('{', printf('%c', 123)) + endif + call assert_equal('abc', printf('%s', 'abc')) + call assert_equal('abc', printf('%S', 'abc')) + + call assert_equal('+123', printf('%+d', 123)) + call assert_equal('-123', printf('%+d', -123)) + call assert_equal('+123', printf('%+ d', 123)) + call assert_equal(' 123', printf('% d', 123)) + call assert_equal(' 123', printf('% d', 123)) + call assert_equal('-123', printf('% d', -123)) + + call assert_equal('123', printf('%2d', 123)) + call assert_equal(' 123', printf('%6d', 123)) + call assert_equal('000123', printf('%06d', 123)) + call assert_equal('+00123', printf('%+06d', 123)) + call assert_equal(' 00123', printf('% 06d', 123)) + call assert_equal(' +123', printf('%+6d', 123)) + call assert_equal(' 123', printf('% 6d', 123)) + call assert_equal(' -123', printf('% 6d', -123)) + + " Test left adjusted. + call assert_equal('123 ', printf('%-6d', 123)) + call assert_equal('+123 ', printf('%-+6d', 123)) + call assert_equal(' 123 ', printf('%- 6d', 123)) + call assert_equal('-123 ', printf('%- 6d', -123)) + + call assert_equal(' 00123', printf('%7.5d', 123)) + call assert_equal(' -00123', printf('%7.5d', -123)) + call assert_equal(' +00123', printf('%+7.5d', 123)) + " Precision field should not be used when combined with %0 + call assert_equal(' 00123', printf('%07.5d', 123)) + call assert_equal(' -00123', printf('%07.5d', -123)) + + call assert_equal(' 123', printf('%*d', 5, 123)) + call assert_equal('123 ', printf('%*d', -5, 123)) + call assert_equal('00123', printf('%.*d', 5, 123)) + call assert_equal(' 123', printf('% *d', 5, 123)) + call assert_equal(' +123', printf('%+ *d', 5, 123)) + + call assert_equal('foobar', printf('%.*s', 9, 'foobar')) + call assert_equal('foo', printf('%.*s', 3, 'foobar')) + call assert_equal('', printf('%.*s', 0, 'foobar')) + call assert_equal('foobar', printf('%.*s', -1, 'foobar')) + + " Simple quote (thousand grouping char) is ignored. + call assert_equal('+00123456', printf("%+'09d", 123456)) + + " Unrecognized format specifier kept as-is. + call assert_equal('_123', printf("%_%d", 123)) + + " Test alternate forms. + call assert_equal('0x7b', printf('%#x', 123)) + call assert_equal('0X7B', printf('%#X', 123)) + call assert_equal('0173', printf('%#o', 123)) + call assert_equal('0173', printf('%#O', 123)) + call assert_equal('abc', printf('%#s', 'abc')) + call assert_equal('abc', printf('%#S', 'abc')) + call assert_equal(' 0173', printf('%#6o', 123)) + call assert_equal(' 00173', printf('%#6.5o', 123)) + call assert_equal(' 0173', printf('%#6.2o', 123)) + call assert_equal(' 0173', printf('%#6.2o', 123)) + call assert_equal('0173', printf('%#2.2o', 123)) + + call assert_equal(' 00123', printf('%6.5d', 123)) + call assert_equal(' 0007b', printf('%6.5x', 123)) + + call assert_equal('123', printf('%.2d', 123)) + call assert_equal('0123', printf('%.4d', 123)) + call assert_equal('0000000123', printf('%.10d', 123)) + call assert_equal('123', printf('%.0d', 123)) + + call assert_equal('abc', printf('%2s', 'abc')) + call assert_equal('abc', printf('%2S', 'abc')) + call assert_equal('abc', printf('%.4s', 'abc')) + call assert_equal('abc', printf('%.4S', 'abc')) + call assert_equal('ab', printf('%.2s', 'abc')) + call assert_equal('ab', printf('%.2S', 'abc')) + call assert_equal('', printf('%.0s', 'abc')) + call assert_equal('', printf('%.s', 'abc')) + call assert_equal(' abc', printf('%4s', 'abc')) + call assert_equal(' abc', printf('%4S', 'abc')) + call assert_equal('0abc', printf('%04s', 'abc')) + call assert_equal('0abc', printf('%04S', 'abc')) + call assert_equal('abc ', printf('%-4s', 'abc')) + call assert_equal('abc ', printf('%-4S', 'abc')) + + call assert_equal('1%', printf('%d%%', 1)) +endfunc + +function Test_printf_float() + if has('float') + call assert_equal('1.000000', printf('%f', 1)) + call assert_equal('1.230000', printf('%f', 1.23)) + call assert_equal('1.230000', printf('%F', 1.23)) + call assert_equal('9999999.9', printf('%g', 9999999.9)) + call assert_equal('9999999.9', printf('%G', 9999999.9)) + call assert_equal('1.00000001e7', printf('%.8g', 10000000.1)) + call assert_equal('1.00000001E7', printf('%.8G', 10000000.1)) + call assert_equal('1.230000e+00', printf('%e', 1.23)) + call assert_equal('1.230000E+00', printf('%E', 1.23)) + call assert_equal('1.200000e-02', printf('%e', 0.012)) + call assert_equal('-1.200000e-02', printf('%e', -0.012)) + call assert_equal('0.33', printf('%.2f', 1.0/3.0)) + call assert_equal(' 0.33', printf('%6.2f', 1.0/3.0)) + call assert_equal(' -0.33', printf('%6.2f', -1.0/3.0)) + call assert_equal('000.33', printf('%06.2f', 1.0/3.0)) + call assert_equal('-00.33', printf('%06.2f', -1.0/3.0)) + call assert_equal('-00.33', printf('%+06.2f', -1.0/3.0)) + call assert_equal('+00.33', printf('%+06.2f', 1.0/3.0)) + call assert_equal(' 00.33', printf('% 06.2f', 1.0/3.0)) + call assert_equal('000.33', printf('%06.2g', 1.0/3.0)) + call assert_equal('-00.33', printf('%06.2g', -1.0/3.0)) + call assert_equal('0.33', printf('%3.2f', 1.0/3.0)) + call assert_equal('003.33e-01', printf('%010.2e', 1.0/3.0)) + call assert_equal(' 03.33e-01', printf('% 010.2e', 1.0/3.0)) + call assert_equal('+03.33e-01', printf('%+010.2e', 1.0/3.0)) + call assert_equal('-03.33e-01', printf('%010.2e', -1.0/3.0)) + + " When precision is 0, the dot should be omitted. + call assert_equal(' 2', printf('%3.f', 7.0/3.0)) + call assert_equal(' 2', printf('%3.g', 7.0/3.0)) + call assert_equal(' 2e+00', printf('%7.e', 7.0/3.0)) + + " Float zero can be signed. + call assert_equal('+0.000000', printf('%+f', 0.0)) + call assert_equal('0.000000', printf('%f', 1.0/(1.0/0.0))) + call assert_equal('-0.000000', printf('%f', 1.0/(-1.0/0.0))) + call assert_equal('0.0', printf('%s', 1.0/(1.0/0.0))) + call assert_equal('-0.0', printf('%s', 1.0/(-1.0/0.0))) + call assert_equal('0.0', printf('%S', 1.0/(1.0/0.0))) + call assert_equal('-0.0', printf('%S', 1.0/(-1.0/0.0))) + + " Float infinity can be signed. + call assert_equal('inf', printf('%f', 1.0/0.0)) + call assert_equal('-inf', printf('%f', -1.0/0.0)) + call assert_equal('inf', printf('%g', 1.0/0.0)) + call assert_equal('-inf', printf('%g', -1.0/0.0)) + call assert_equal('inf', printf('%e', 1.0/0.0)) + call assert_equal('-inf', printf('%e', -1.0/0.0)) + call assert_equal('INF', printf('%F', 1.0/0.0)) + call assert_equal('-INF', printf('%F', -1.0/0.0)) + call assert_equal('INF', printf('%E', 1.0/0.0)) + call assert_equal('-INF', printf('%E', -1.0/0.0)) + call assert_equal('INF', printf('%E', 1.0/0.0)) + call assert_equal('-INF', printf('%G', -1.0/0.0)) + call assert_equal('+inf', printf('%+f', 1.0/0.0)) + call assert_equal('-inf', printf('%+f', -1.0/0.0)) + call assert_equal(' inf', printf('% f', 1.0/0.0)) + call assert_equal(' inf', printf('%6f', 1.0/0.0)) + call assert_equal(' -inf', printf('%6f', -1.0/0.0)) + call assert_equal(' inf', printf('%6g', 1.0/0.0)) + call assert_equal(' -inf', printf('%6g', -1.0/0.0)) + call assert_equal(' +inf', printf('%+6f', 1.0/0.0)) + call assert_equal(' inf', printf('% 6f', 1.0/0.0)) + call assert_equal(' +inf', printf('%+06f', 1.0/0.0)) + call assert_equal('inf ', printf('%-6f', 1.0/0.0)) + call assert_equal('-inf ', printf('%-6f', -1.0/0.0)) + call assert_equal('+inf ', printf('%-+6f', 1.0/0.0)) + call assert_equal(' inf ', printf('%- 6f', 1.0/0.0)) + call assert_equal('-INF ', printf('%-6F', -1.0/0.0)) + call assert_equal('+INF ', printf('%-+6F', 1.0/0.0)) + call assert_equal(' INF ', printf('%- 6F', 1.0/0.0)) + call assert_equal('INF ', printf('%-6G', 1.0/0.0)) + call assert_equal('-INF ', printf('%-6G', -1.0/0.0)) + call assert_equal('INF ', printf('%-6E', 1.0/0.0)) + call assert_equal('-INF ', printf('%-6E', -1.0/0.0)) + call assert_equal('inf', printf('%s', 1.0/0.0)) + call assert_equal('-inf', printf('%s', -1.0/0.0)) + + " Test special case where max precision is truncated at 340. + call assert_equal('1.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', printf('%.330f', 1.0)) + call assert_equal('1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', printf('%.340f', 1.0)) + call assert_equal('1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', printf('%.350f', 1.0)) + + " Float nan (not a number) has no sign. + call assert_equal('nan', printf('%f', sqrt(-1.0))) + call assert_equal('nan', printf('%f', 0.0/0.0)) + call assert_equal('nan', printf('%f', -0.0/0.0)) + call assert_equal('nan', printf('%g', 0.0/0.0)) + call assert_equal('nan', printf('%e', 0.0/0.0)) + call assert_equal('NAN', printf('%F', 0.0/0.0)) + call assert_equal('NAN', printf('%G', 0.0/0.0)) + call assert_equal('NAN', printf('%E', 0.0/0.0)) + call assert_equal('NAN', printf('%F', -0.0/0.0)) + call assert_equal('NAN', printf('%G', -0.0/0.0)) + call assert_equal('NAN', printf('%E', -0.0/0.0)) + call assert_equal(' nan', printf('%6f', 0.0/0.0)) + call assert_equal(' nan', printf('%06f', 0.0/0.0)) + call assert_equal('nan ', printf('%-6f', 0.0/0.0)) + call assert_equal('nan ', printf('%- 6f', 0.0/0.0)) + call assert_equal('nan', printf('%s', 0.0/0.0)) + call assert_equal('nan', printf('%s', -0.0/0.0)) + call assert_equal('nan', printf('%S', 0.0/0.0)) + call assert_equal('nan', printf('%S', -0.0/0.0)) + + call assert_fails('echo printf("%f", "a")', 'E807:') + endif +endfunc + +function Test_printf_errors() + call assert_fails('echo printf("%d", {})', 'E728:') + call assert_fails('echo printf("%d", [])', 'E745:') + call assert_fails('echo printf("%d", 1, 2)', 'E767:') + call assert_fails('echo printf("%*d", 1)', 'E766:') + call assert_fails('echo printf("%d", 1.2)', 'E805:') +endfunc + +function Test_max_min_errors() + call assert_fails('call max(v:true)', 'E712:') + call assert_fails('call max(v:true)', 'max()') + call assert_fails('call min(v:true)', 'E712:') + call assert_fails('call min(v:true)', 'min()') +endfunc + +function Test_printf_64bit() + if has('num64') + call assert_equal("123456789012345", printf('%d', 123456789012345)) + endif +endfunc + +function Test_printf_spec_s() + " number + call assert_equal("1234567890", printf('%s', 1234567890)) + + " string + call assert_equal("abcdefgi", printf('%s', "abcdefgi")) + + " float + if has('float') + call assert_equal("1.23", printf('%s', 1.23)) + endif + + " list + let value = [1, 'two', ['three', 4]] + call assert_equal(string(value), printf('%s', value)) + + " dict + let value = {'key1' : 'value1', 'key2' : ['list', 'value'], 'key3' : {'dict' : 'value'}} + call assert_equal(string(value), printf('%s', value)) + + " funcref + call assert_equal('printf', printf('%s', function('printf'))) + + " partial + call assert_equal(string(function('printf', ['%s'])), printf('%s', function('printf', ['%s']))) +endfunc + +function Test_printf_spec_b() + call assert_equal("0", printf('%b', 0)) + call assert_equal("00001100", printf('%08b', 12)) + call assert_equal("11111111", printf('%08b', 0xff)) + call assert_equal(" 1111011", printf('%10b', 123)) + call assert_equal("0001111011", printf('%010b', 123)) + call assert_equal(" 0b1111011", printf('%#10b', 123)) + call assert_equal("0B01111011", printf('%#010B', 123)) + call assert_equal("1001001100101100000001011010010", printf('%b', 1234567890)) + if has('num64') + call assert_equal("11100000100100010000110000011011101111101111001", printf('%b', 123456789012345)) + call assert_equal("1111111111111111111111111111111111111111111111111111111111111111", printf('%b', -1)) + else + call assert_equal("11111111111111111111111111111111", printf('%b', -1)) + endif +endfunc + +func Test_substitute_expr() + let g:val = 'XXX' + call assert_equal('XXX', substitute('yyy', 'y*', '\=g:val', '')) + call assert_equal('XXX', substitute('yyy', 'y*', {-> g:val}, '')) + call assert_equal("-\u1b \uf2-", substitute("-%1b %f2-", '%\(\x\x\)', + \ '\=nr2char("0x" . submatch(1))', 'g')) + call assert_equal("-\u1b \uf2-", substitute("-%1b %f2-", '%\(\x\x\)', + \ {-> nr2char("0x" . submatch(1))}, 'g')) + + call assert_equal('231', substitute('123', '\(.\)\(.\)\(.\)', + \ {-> submatch(2) . submatch(3) . submatch(1)}, '')) + + func Recurse() + return substitute('yyy', 'y\(.\)y', {-> submatch(1)}, '') + endfunc + " recursive call works + call assert_equal('-y-x-', substitute('xxx', 'x\(.\)x', {-> '-' . Recurse() . '-' . submatch(1) . '-'}, '')) +endfunc + +func Test_invalid_submatch() + " This was causing invalid memory access in Vim-7.4.2232 and older + call assert_fails("call substitute('x', '.', {-> submatch(10)}, '')", 'E935:') +endfunc + +func Test_substitute_expr_arg() + call assert_equal('123456789-123456789=', substitute('123456789', + \ '\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', + \ {m -> m[0] . '-' . m[1] . m[2] . m[3] . m[4] . m[5] . m[6] . m[7] . m[8] . m[9] . '='}, '')) + + call assert_equal('123456-123456=789', substitute('123456789', + \ '\(.\)\(.\)\(.\)\(a*\)\(n*\)\(.\)\(.\)\(.\)\(x*\)', + \ {m -> m[0] . '-' . m[1] . m[2] . m[3] . m[4] . m[5] . m[6] . m[7] . m[8] . m[9] . '='}, '')) + + call assert_equal('123456789-123456789x=', substitute('123456789', + \ '\(.\)\(.\)\(.*\)', + \ {m -> m[0] . '-' . m[1] . m[2] . m[3] . 'x' . m[4] . m[5] . m[6] . m[7] . m[8] . m[9] . '='}, '')) + + call assert_fails("call substitute('xxx', '.', {m -> string(add(m, 'x'))}, '')", 'E742:') + call assert_fails("call substitute('xxx', '.', {m -> string(insert(m, 'x'))}, '')", 'E742:') + call assert_fails("call substitute('xxx', '.', {m -> string(extend(m, ['x']))}, '')", 'E742:') + call assert_fails("call substitute('xxx', '.', {m -> string(remove(m, 1))}, '')", 'E742:') +endfunc + +func Test_function_with_funcref() + let s:f = function('type') + let s:fref = function(s:f) + call assert_equal(v:t_string, s:fref('x')) + call assert_fails("call function('s:f')", 'E700:') + + call assert_fails("call function('foo()')", 'E475:') + call assert_fails("call function('foo()')", 'foo()') +endfunc + +func Test_funcref() + func! One() + return 1 + endfunc + let OneByName = function('One') + let OneByRef = funcref('One') + func! One() + return 2 + endfunc + call assert_equal(2, OneByName()) + call assert_equal(1, OneByRef()) + let OneByRef = funcref('One') + call assert_equal(2, OneByRef()) + call assert_fails('echo funcref("{")', 'E475:') +endfunc + +func Test_setmatches() + hi def link 1 Comment + hi def link 2 PreProc + let set = [{"group": 1, "pattern": 2, "id": 3, "priority": 4}] + let exp = [{"group": '1', "pattern": '2', "id": 3, "priority": 4}] + if has('conceal') + let set[0]['conceal'] = 5 + let exp[0]['conceal'] = '5' + endif + call setmatches(set) + call assert_equal(exp, getmatches()) +endfunc + +func Test_empty_concatenate() + call assert_equal('b', 'a'[4:0] . 'b') + call assert_equal('b', 'b' . 'a'[4:0]) +endfunc diff --git a/src/testdir/test_expr_utf8.vim b/src/testdir/test_expr_utf8.vim new file mode 100644 index 0000000..fad725d --- /dev/null +++ b/src/testdir/test_expr_utf8.vim @@ -0,0 +1,34 @@ +" Tests for expressions using utf-8. + +func Test_strgetchar() + call assert_equal(char2nr('á'), strgetchar('áxb', 0)) + call assert_equal(char2nr('x'), strgetchar('áxb', 1)) + + call assert_equal(char2nr('a'), strgetchar('àxb', 0)) + call assert_equal(char2nr('̀'), strgetchar('àxb', 1)) + call assert_equal(char2nr('x'), strgetchar('àxb', 2)) + + call assert_equal(char2nr('あ'), strgetchar('あaい', 0)) + call assert_equal(char2nr('a'), strgetchar('あaい', 1)) + call assert_equal(char2nr('い'), strgetchar('あaい', 2)) +endfunc + +func Test_strcharpart() + call assert_equal('áxb', strcharpart('áxb', 0)) + call assert_equal('á', strcharpart('áxb', 0, 1)) + call assert_equal('x', strcharpart('áxb', 1, 1)) + + call assert_equal('いうeお', strcharpart('あいうeお', 1)) + call assert_equal('い', strcharpart('あいうeお', 1, 1)) + call assert_equal('いう', strcharpart('あいうeお', 1, 2)) + call assert_equal('いうe', strcharpart('あいうeお', 1, 3)) + call assert_equal('いうeお', strcharpart('あいうeお', 1, 4)) + call assert_equal('eお', strcharpart('あいうeお', 3)) + call assert_equal('e', strcharpart('あいうeお', 3, 1)) + + call assert_equal('あ', strcharpart('あいうeお', -3, 4)) + + call assert_equal('a', strcharpart('àxb', 0, 1)) + call assert_equal('̀', strcharpart('àxb', 1, 1)) + call assert_equal('x', strcharpart('àxb', 2, 1)) +endfunc diff --git a/src/testdir/test_farsi.vim b/src/testdir/test_farsi.vim new file mode 100644 index 0000000..dcfa024 --- /dev/null +++ b/src/testdir/test_farsi.vim @@ -0,0 +1,133 @@ +" Simplistic testing of Farsi mode. +" Note: must be edited with latin1 encoding. + +if !has('farsi') + finish +endif +" Farsi uses a single byte encoding. +set enc=latin1 + +func Test_farsi_toggle() + new + + set altkeymap + call assert_equal(0, &fkmap) + call assert_equal(0, &rl) + call feedkeys("\<F8>", 'x') + call assert_equal(1, &fkmap) + call assert_equal(1, &rl) + call feedkeys("\<F8>", 'x') + call assert_equal(0, &fkmap) + call assert_equal(0, &rl) + + set rl + " conversion from Farsi 3342 to Farsi VIM. + call setline(1, join(map(range(0x80, 0xff), 'nr2char(v:val)'), '')) + call feedkeys("\<F9>", 'x') + let exp = [0xfc, 0xf8, 0xc1, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, + \ 0xc8, 0xc9, 0xca, 0xd0, 0xd1, 0xd2, 0xd3, 0xd6, + \ 0xd6, 0xd6, 0xd7, 0xd7, 0xd7, 0xd8, 0xd9, 0xda, + \ 0xdb, 0xdc, 0xdc, 0xc1, 0xdd, 0xde, 0xe0, 0xe0, + \ 0xe1, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, + \ 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, + \ 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, + \ 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, + \ 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, + \ 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, + \ 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, + \ 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, + \ 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, + \ 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xfb, 0xfb, 0xfe, + \ 0xfe, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, + \ 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xe1, + \ ] + call assert_equal(join(map(exp, 'nr2char(v:val)'), ''), getline(1)) + + " conversion from Farsi VIM to Farsi 3342. + call setline(1, join(map(range(0x80, 0xff), 'nr2char(v:val)'), '')) + call feedkeys("\<F9>", 'x') + let exp = [0xfc, 0xf8, 0xc1, 0x83, 0x84, 0x85, 0x86, 0x87, + \ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x90, + \ 0x90, 0x90, 0x92, 0x93, 0x93, 0x95, 0x96, 0x97, + \ 0x98, 0xdc, 0x9a, 0x9b, 0x9c, 0x9e, 0x9e, 0xff, + \ 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, + \ 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, + \ 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, + \ 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, + \ 0xc0, 0xc1, 0xc2, 0x83, 0x84, 0x85, 0x86, 0x87, + \ 0x88, 0x89, 0x8a, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, + \ 0x8b, 0x8c, 0x8d, 0x8e, 0xd4, 0xd5, 0x90, 0x93, + \ 0x95, 0x96, 0x97, 0x98, 0x99, 0x9b, 0x9c, 0xdf, + \ 0x9d, 0xff, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, + \ 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xec, 0xee, 0xef, + \ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, + \ 0xf8, 0xf9, 0xfa, 0xec, 0x80, 0xfd, 0xee, 0xff, + \ ] + call assert_equal(join(map(exp, 'nr2char(v:val)'), ''), getline(1)) + + bwipe! +endfunc + +func Test_farsi_map() + new + + set altkeymap + set rl + " RHS of mapping is reversed. + imap xyz abc + call feedkeys("axyz\<Esc>", 'tx') + call assert_equal('cba', getline(1)) + + set norl + iunmap xyz + set noaltkeymap + bwipe! +endfunc + +func Test_input_farsi() + new + setlocal rightleft fkmap + " numbers switch input direction + call feedkeys("aabc0123456789.+-^%#=xyz\<Esc>", 'tx') + call assert_equal("\x8cν\x93", getline('.')) + + " all non-number special chars with spaces + call feedkeys("oB E F H I K L M O P Q R T U W Y ` ! @ # $ % ^ & * () - _ = + \\ | : \" . / < > ? \<Esc>", 'tx') + call assert_equal(" []蠨頽", getline('.')) + + " all non-number special chars without spaces + call feedkeys("oBEFHIKLMOPQRTUWY`!@#$%^&*()-_=+\\|:\"./<>?\<Esc>",'tx') + call assert_equal("[]訩齫꺻", getline('.')) + + " all letter chars with spaces + call feedkeys("oa A b c C d D e f g G h i j J k l m n N o p q r s S t u v V w x X y z Z ; \ , [ ] \<Esc>", 'tx') + call assert_equal("Ѡ̠ΠϠƠàܠŠޠݠĠˠˠʠɠӠ٠Рؠ֠͠͠ҠԠԠנՠڠߠǠȠ", getline('.')) + + " all letter chars without spaces + call feedkeys("oaAbcCdDefgGhijJklmnNopqrsStuvVwxXyzZ;\,[]\<Esc>", 'tx') + call assert_equal("\x8c\x9f\x86\x83\x9d\x85\x80\x9c\x9b\x84\x8a\x89\x8e\x96\x8b\x95\x90\x8d\x93\x97\x87\x88", getline('.')) + + bwipe! +endfunc + +func Test_command_line_farsi() + set allowrevins altkeymap + + " letter characters with spaces + call feedkeys(":\"\<C-_>a A b c C d D e f g G h i j J k l m n N o p q r s S t u v V w x X y z Z ; \\ , [ ]\<CR>", 'tx') + call assert_equal("\"\x88ǠߠڠՠՠנԠԠҠ֠͠͠ؠР٠ӠɠʠˠˠĠݠޠŠܠàƠϠΠ̠", getreg(':')) + + " letter characters without spaces + call feedkeys(":\"\<C-_>aAbcCdDefgGhijJklmnNopqrsStuvVwxXyzZ;\\,[]\<CR>", 'tx') + call assert_equal("\"\x88\x87\x93\x8d\x90\x95\x8b\x96\x8e\x89\x8a\x84\x9b\x9c\x80\x85\x9d\x83\x86\x9f\x8c", getreg(':')) + + " other characters with spaces + call feedkeys(":\"\<C-_>0 1 2 3 4 5 6 7 8 9 ` . ! \" $ % ^ & / () = \\ ? + - _ * : # ~ @ < > { } | B E F H I K L M O P Q R T U W Y\<CR>", 'tx') + call assert_equal("\"][ }{~頭렽", getreg(':')) + + " other characters without spaces + call feedkeys(":\"\<C-_>0123456789`.!\"$%^&/()=\\?+-_*:#~@<>{}|BEFHIKLMOPQRTUWY\<CR>", 'tx') + call assert_equal("\"][}{~魫뽩", getreg(':')) + + set noallowrevins noaltkeymap +endfunc diff --git a/src/testdir/test_feedkeys.vim b/src/testdir/test_feedkeys.vim new file mode 100644 index 0000000..70500f2 --- /dev/null +++ b/src/testdir/test_feedkeys.vim @@ -0,0 +1,14 @@ +" Test feedkeys() function. + +func Test_feedkeys_x_with_empty_string() + new + call feedkeys("ifoo\<Esc>") + call assert_equal('', getline('.')) + call feedkeys('', 'x') + call assert_equal('foo', getline('.')) + + " check it goes back to normal mode immediately. + call feedkeys('i', 'x') + call assert_equal('foo', getline('.')) + quit! +endfunc diff --git a/src/testdir/test_file_perm.vim b/src/testdir/test_file_perm.vim new file mode 100644 index 0000000..0dba6a7 --- /dev/null +++ b/src/testdir/test_file_perm.vim @@ -0,0 +1,24 @@ +" Test getting and setting file permissions. + +func Test_file_perm() + call assert_equal('', getfperm('Xtest')) + call assert_equal(0, setfperm('Xtest', 'r--------')) + + call writefile(['one'], 'Xtest') + call assert_true(len(getfperm('Xtest')) == 9) + + call assert_equal(1, setfperm('Xtest', 'rwx------')) + if has('win32') + call assert_equal('rw-rw-rw-', getfperm('Xtest')) + else + call assert_equal('rwx------', getfperm('Xtest')) + endif + + call assert_equal(1, setfperm('Xtest', 'r--r--r--')) + call assert_equal('r--r--r--', getfperm('Xtest')) + + call assert_fails("setfperm('Xtest', '---')") + + call assert_equal(1, setfperm('Xtest', 'rwx------')) + call delete('Xtest') +endfunc diff --git a/src/testdir/test_file_size.vim b/src/testdir/test_file_size.vim new file mode 100644 index 0000000..3e78a7b --- /dev/null +++ b/src/testdir/test_file_size.vim @@ -0,0 +1,58 @@ +" Inserts 2 million lines with consecutive integers starting from 1 +" (essentially, the output of GNU's seq 1 2000000), writes them to Xtest +" and writes its cksum to test.out. +" +" We need 2 million lines to trigger a call to mf_hash_grow(). If it would mess +" up the lines the checksum would differ. +" +" cksum is part of POSIX and so should be available on most Unixes. +" If it isn't available then the test will be skipped. +func Test_File_Size() + if !executable('cksum') + return + endif + + new + set fileformat=unix undolevels=-1 + for i in range(1, 2000000, 100) + call append(i, range(i, i + 99)) + endfor + + 1delete + w! Xtest + let res = systemlist('cksum Xtest')[0] + let res = substitute(res, "\r", "", "") + call assert_equal('3678979763 14888896 Xtest', res) + + enew! + call delete('Xtest') + set fileformat& undolevels& +endfunc + +" Test for writing and reading a file of over 100 Kbyte +func Test_File_Read_Write() + enew! + + " Create a file with the following contents + " 1 line: "This is the start" + " 3001 lines: "This is the leader" + " 1 line: "This is the middle" + " 3001 lines: "This is the trailer" + " 1 line: "This is the end" + call append(0, "This is the start") + call append(1, repeat(["This is the leader"], 3001)) + call append(3002, "This is the middle") + call append(3003, repeat(["This is the trailer"], 3001)) + call append(6004, "This is the end") + + write! Xtest + enew! + edit! Xtest + + call assert_equal("This is the start", getline(1)) + call assert_equal("This is the middle", getline(3003)) + call assert_equal("This is the end", getline(6005)) + + enew! + call delete("Xtest") +endfunc diff --git a/src/testdir/test_filechanged.vim b/src/testdir/test_filechanged.vim new file mode 100644 index 0000000..43f752d --- /dev/null +++ b/src/testdir/test_filechanged.vim @@ -0,0 +1,146 @@ +" Tests for when a file was changed outside of Vim. + +func Test_FileChangedShell_reload() + if !has('unix') + return + endif + augroup testreload + au FileChangedShell Xchanged_r let g:reason = v:fcs_reason | let v:fcs_choice = 'reload' + augroup END + new Xchanged_r + call setline(1, 'reload this') + write + " Need to wait until the timestamp would change by at least a second. + sleep 2 + silent !echo 'extra line' >>Xchanged_r + checktime + call assert_equal('changed', g:reason) + call assert_equal(2, line('$')) + call assert_equal('extra line', getline(2)) + + " Only triggers once + let g:reason = '' + checktime + call assert_equal('', g:reason) + + " When deleted buffer is not reloaded + silent !rm Xchanged_r + let g:reason = '' + checktime + call assert_equal('deleted', g:reason) + call assert_equal(2, line('$')) + call assert_equal('extra line', getline(2)) + + " When recreated buffer is reloaded + call setline(1, 'buffer is changed') + silent !echo 'new line' >>Xchanged_r + let g:reason = '' + checktime + call assert_equal('conflict', g:reason) + call assert_equal(1, line('$')) + call assert_equal('new line', getline(1)) + + " Only mode changed + silent !chmod +x Xchanged_r + let g:reason = '' + checktime + call assert_equal('mode', g:reason) + call assert_equal(1, line('$')) + call assert_equal('new line', getline(1)) + + " Only time changed + sleep 2 + silent !touch Xchanged_r + let g:reason = '' + checktime + call assert_equal('time', g:reason) + call assert_equal(1, line('$')) + call assert_equal('new line', getline(1)) + + if has('persistent_undo') + " With an undo file the reload can be undone and a change before the + " reload. + set undofile + call setline(2, 'before write') + write + call setline(2, 'after write') + sleep 2 + silent !echo 'different line' >>Xchanged_r + let g:reason = '' + checktime + call assert_equal('conflict', g:reason) + call assert_equal(3, line('$')) + call assert_equal('before write', getline(2)) + call assert_equal('different line', getline(3)) + " undo the reload + undo + call assert_equal(2, line('$')) + call assert_equal('after write', getline(2)) + " undo the change before reload + undo + call assert_equal(2, line('$')) + call assert_equal('before write', getline(2)) + + set noundofile + endif + + au! testreload + bwipe! + call delete('Xchanged_r') +endfunc + +func Test_file_changed_dialog() + if !has('unix') || has('gui_running') + return + endif + au! FileChangedShell + + new Xchanged_d + call setline(1, 'reload this') + write + " Need to wait until the timestamp would change by at least a second. + sleep 2 + silent !echo 'extra line' >>Xchanged_d + call feedkeys('L', 'L') + checktime + call assert_match('W11:', v:warningmsg) + call assert_equal(2, line('$')) + call assert_equal('reload this', getline(1)) + call assert_equal('extra line', getline(2)) + + " delete buffer, only shows an error, no prompt + silent !rm Xchanged_d + checktime + call assert_match('E211:', v:warningmsg) + call assert_equal(2, line('$')) + call assert_equal('extra line', getline(2)) + + " Recreate buffer and reload + call setline(1, 'buffer is changed') + silent !echo 'new line' >Xchanged_d + call feedkeys('L', 'L') + checktime + call assert_match('W12:', v:warningmsg) + call assert_equal(1, line('$')) + call assert_equal('new line', getline(1)) + + " Only mode changed, reload + silent !chmod +x Xchanged_d + call feedkeys('L', 'L') + checktime + call assert_match('W16:', v:warningmsg) + call assert_equal(1, line('$')) + call assert_equal('new line', getline(1)) + + " Only time changed, no prompt + sleep 2 + silent !touch Xchanged_d + let v:warningmsg = '' + checktime + call assert_equal('', v:warningmsg) + call assert_equal(1, line('$')) + call assert_equal('new line', getline(1)) + + bwipe! + call delete('Xchanged_d') +endfunc diff --git a/src/testdir/test_fileformat.vim b/src/testdir/test_fileformat.vim new file mode 100644 index 0000000..8dc25f6 --- /dev/null +++ b/src/testdir/test_fileformat.vim @@ -0,0 +1,33 @@ +" Test behavior of fileformat after bwipeout of last buffer + +func Test_fileformat_after_bw() + bwipeout + set fileformat& + if &fileformat == 'dos' + let test_fileformats = 'unix' + elseif &fileformat == 'unix' + let test_fileformats = 'mac' + else " must be mac + let test_fileformats = 'dos' + endif + exec 'set fileformats='.test_fileformats + bwipeout! + call assert_equal(test_fileformats, &fileformat) + set fileformats& +endfunc + +func Test_fileformat_autocommand() + let filecnt = ["", "foobar\<CR>", "eins\<CR>", "\<CR>", "zwei\<CR>", "drei", "vier", "fünf", ""] + let ffs = &ffs + call writefile(filecnt, 'Xfile', 'b') + au BufReadPre Xfile set ffs=dos ff=dos + new Xfile + call assert_equal('dos', &l:ff) + call assert_equal('dos', &ffs) + + " cleanup + call delete('Xfile') + let &ffs = ffs + au! BufReadPre Xfile + bw! +endfunc diff --git a/src/testdir/test_filetype.vim b/src/testdir/test_filetype.vim new file mode 100644 index 0000000..fd2f383 --- /dev/null +++ b/src/testdir/test_filetype.vim @@ -0,0 +1,603 @@ +" Test :setfiletype + +func Test_detection() + filetype on + augroup filetypedetect + au BufNewFile,BufRead * call assert_equal(1, did_filetype()) + augroup END + new something.vim + call assert_equal('vim', &filetype) + + bwipe! + filetype off +endfunc + +func Test_conf_type() + filetype on + call writefile(['# some comment', 'must be conf'], 'Xfile') + augroup filetypedetect + au BufNewFile,BufRead * call assert_equal(0, did_filetype()) + augroup END + split Xfile + call assert_equal('conf', &filetype) + + bwipe! + call delete('Xfile') + filetype off +endfunc + +func Test_other_type() + filetype on + augroup filetypedetect + au BufNewFile,BufRead * call assert_equal(0, did_filetype()) + au BufNewFile,BufRead Xfile setf testfile + au BufNewFile,BufRead * call assert_equal(1, did_filetype()) + augroup END + call writefile(['# some comment', 'must be conf'], 'Xfile') + split Xfile + call assert_equal('testfile', &filetype) + + bwipe! + call delete('Xfile') + filetype off +endfunc + +" Filetypes detected just from matching the file name. +let s:filename_checks = { + \ 'a2ps': ['/etc/a2ps.cfg', '/etc/a2ps/file.cfg', 'a2psrc', '.a2psrc'], + \ 'a65': ['file.a65'], + \ 'abap': ['file.abap'], + \ 'abc': ['file.abc'], + \ 'abel': ['file.abl'], + \ 'acedb': ['file.wrm'], + \ 'ada': ['file.adb', 'file.ads', 'file.ada', 'file.gpr'], + \ 'ahdl': ['file.tdf'], + \ 'alsaconf': ['.asoundrc', '/usr/share/alsa/alsa.conf', '/etc/asound.conf'], + \ 'aml': ['file.aml'], + \ 'ampl': ['file.run'], + \ 'ant': ['build.xml'], + \ 'apache': ['.htaccess', '/etc/httpd/file.conf'], + \ 'applescript': ['file.scpt'], + \ 'aptconf': ['apt.conf', '/.aptitude/config'], + \ 'arch': ['.arch-inventory'], + \ 'arduino': ['file.ino', 'file.pde'], + \ 'art': ['file.art'], + \ 'asciidoc': ['file.asciidoc', 'file.adoc'], + \ 'asn': ['file.asn', 'file.asn1'], + \ 'atlas': ['file.atl', 'file.as'], + \ 'autohotkey': ['file.ahk'], + \ 'autoit': ['file.au3'], + \ 'automake': ['GNUmakefile.am'], + \ 'ave': ['file.ave'], + \ 'awk': ['file.awk'], + \ 'b': ['file.mch', 'file.ref', 'file.imp'], + \ 'bc': ['file.bc'], + \ 'bdf': ['file.bdf'], + \ 'bib': ['file.bib'], + \ 'bindzone': ['named.root'], + \ 'blank': ['file.bl'], + \ 'bst': ['file.bst'], + \ 'bzr': ['bzr_log.any'], + \ 'c': ['enlightenment/file.cfg', 'file.qc', 'file.c'], + \ 'cabal': ['file.cabal'], + \ 'calendar': ['calendar'], + \ 'catalog': ['catalog'], + \ 'cdl': ['file.cdl'], + \ 'cdrdaoconf': ['/etc/cdrdao.conf', '/etc/defaults/cdrdao', '/etc/default/cdrdao', '.cdrdao'], + \ 'cdrtoc': ['file.toc'], + \ 'cf': ['file.cfm', 'file.cfi', 'file.cfc'], + \ 'cfengine': ['cfengine.conf'], + \ 'cfg': ['file.cfg', 'file.hgrc', 'filehgrc'], + \ 'ch': ['file.chf'], + \ 'chaiscript': ['file.chai'], + \ 'chaskell': ['file.chs'], + \ 'chill': ['file..ch'], + \ 'chordpro': ['file.chopro', 'file.crd', 'file.cho', 'file.crdpro', 'file.chordpro'], + \ 'cl': ['file.eni'], + \ 'clean': ['file.dcl', 'file.icl'], + \ 'clojure': ['file.clj', 'file.cljs', 'file.cljx', 'file.cljc'], + \ 'cmake': ['CMakeLists.txt', 'file.cmake', 'file.cmake.in'], + \ 'cmusrc': ['any/.cmus/autosave', 'any/.cmus/rc', 'any/.cmus/command-history', 'any/.cmus/file.theme', 'any/cmus/rc', 'any/cmus/file.theme'], + \ 'cobol': ['file.cbl', 'file.cob', 'file.lib'], + \ 'coco': ['file.atg'], + \ 'conaryrecipe': ['file.recipe'], + \ 'conf': ['auto.master'], + \ 'config': ['configure.in', 'configure.ac'], + \ 'context': ['tex/context/any/file.tex', 'file.mkii', 'file.mkiv', 'file.mkvi'], + \ 'cpp': ['file.cxx', 'file.c++', 'file.hh', 'file.hxx', 'file.hpp', 'file.ipp', 'file.moc', 'file.tcc', 'file.inl', 'file.tlh'], + \ 'crm': ['file.crm'], + \ 'cs': ['file.cs'], + \ 'csc': ['file.csc'], + \ 'csdl': ['file.csdl'], + \ 'csp': ['file.csp', 'file.fdr'], + \ 'css': ['file.css'], + \ 'cterm': ['file.con'], + \ 'cucumber': ['file.feature'], + \ 'cuda': ['file.cu'], + \ 'cupl': ['file.pld'], + \ 'cuplsim': ['file.si'], + \ 'cvs': ['cvs123'], + \ 'cvsrc': ['.cvsrc'], + \ 'cynpp': ['file.cyn'], + \ 'datascript': ['file.ds'], + \ 'dcd': ['file.dcd'], + \ 'debcontrol': ['/debian/control'], + \ 'debsources': ['/etc/apt/sources.list', '/etc/apt/sources.list.d/file.list'], + \ 'def': ['file.def'], + \ 'denyhosts': ['denyhosts.conf'], + \ 'desc': ['file.desc'], + \ 'desktop': ['file.desktop', '.directory'], + \ 'dictconf': ['dict.conf', '.dictrc'], + \ 'dictdconf': ['dictd.conf'], + \ 'diff': ['file.diff', 'file.rej'], + \ 'dircolors': ['.dir_colors', '.dircolors', '/etc/DIR_COLORS'], + \ 'dnsmasq': ['/etc/dnsmasq.conf'], + \ 'dockerfile': ['Dockerfile', 'file.Dockerfile'], + \ 'dosbatch': ['file.bat', 'file.sys'], + \ 'dosini': ['.editorconfig', '/etc/yum.conf', 'file.ini'], + \ 'dot': ['file.dot'], + \ 'dracula': ['file.drac', 'file.drc', 'filelvs', 'filelpe'], + \ 'dsl': ['file.dsl'], + \ 'dtd': ['file.dtd'], + \ 'dts': ['file.dts', 'file.dtsi'], + \ 'dylan': ['file.dylan'], + \ 'dylanintr': ['file.intr'], + \ 'dylanlid': ['file.lid'], + \ 'ecd': ['file.ecd'], + \ 'edif': ['file.edf', 'file.edif', 'file.edo'], + \ 'elinks': ['/etc/elinks.conf', '/.elinks/elinks.conf'], + \ 'elmfilt': ['filter-rules'], + \ 'erlang': ['file.erl', 'file.hrl', 'file.yaws'], + \ 'eruby': ['file.erb', 'file.rhtml'], + \ 'esmtprc': ['anyesmtprc'], + \ 'esqlc': ['file.ec', 'file.EC'], + \ 'esterel': ['file.strl'], + \ 'eterm': ['anyEterm/file.cfg'], + \ 'exim': ['exim.conf'], + \ 'expect': ['file.exp'], + \ 'exports': ['exports'], + \ 'factor': ['file.factor'], + \ 'falcon': ['file.fal'], + \ 'fan': ['file.fan', 'file.fwt'], + \ 'fetchmail': ['.fetchmailrc'], + \ 'fgl': ['file.4gl', 'file.4gh', 'file.m4gl'], + \ 'focexec': ['file.fex', 'file.focexec'], + \ 'forth': ['file.fs', 'file.ft', 'file.fth'], + \ 'fortran': ['file.f', 'file.for', 'file.fortran', 'file.fpp', 'file.ftn', 'file.f77', 'file.f90', 'file.f95', 'file.f03', 'file.f08'], + \ 'framescript': ['file.fsl'], + \ 'freebasic': ['file.fb', 'file.bi'], + \ 'fstab': ['fstab', 'mtab'], + \ 'gdb': ['.gdbinit'], + \ 'gdmo': ['file.mo', 'file.gdmo'], + \ 'gedcom': ['file.ged', 'lltxxxxx.txt'], + \ 'gitcommit': ['COMMIT_EDITMSG', 'MERGE_MSG', 'TAG_EDITMSG'], + \ 'gitconfig': ['file.git/config', '.gitconfig', '.gitmodules', 'file.git/modules//config', '/.config/git/config', '/etc/gitconfig'], + \ 'gitolite': ['gitolite.conf'], + \ 'gitrebase': ['git-rebase-todo'], + \ 'gitsendemail': ['.gitsendemail.msg.xxxxxx'], + \ 'gkrellmrc': ['gkrellmrc', 'gkrellmrc_x'], + \ 'gnash': ['gnashrc', '.gnashrc', 'gnashpluginrc', '.gnashpluginrc'], + \ 'gnuplot': ['file.gpi'], + \ 'go': ['file.go'], + \ 'gp': ['file.gp', '.gprc'], + \ 'gpg': ['/.gnupg/options', '/.gnupg/gpg.conf', '/usr/any/gnupg/options.skel'], + \ 'grads': ['file.gs'], + \ 'gretl': ['file.gretl'], + \ 'groovy': ['file.gradle', 'file.groovy'], + \ 'group': ['any/etc/group', 'any/etc/group-', 'any/etc/group.edit', 'any/etc/gshadow', 'any/etc/gshadow-', 'any/etc/gshadow.edit', 'any/var/backups/group.bak', 'any/var/backups/gshadow.bak'], + \ 'grub': ['/boot/grub/menu.lst', '/boot/grub/grub.conf', '/etc/grub.conf'], + \ 'gsp': ['file.gsp'], + \ 'gtkrc': ['.gtkrc', 'gtkrc'], + \ 'haml': ['file.haml'], + \ 'hamster': ['file.hsc', 'file.hsm'], + \ 'haskell': ['file.hs', 'file.hs-boot'], + \ 'haste': ['file.ht'], + \ 'hastepreproc': ['file.htpp'], + \ 'hb': ['file.hb'], + \ 'hercules': ['file.vc', 'file.ev', 'file.sum', 'file.errsum'], + \ 'hex': ['file.hex', 'file.h32'], + \ 'hgcommit': ['hg-editor-file.txt'], + \ 'hog': ['file.hog', 'snort.conf', 'vision.conf'], + \ 'hostconf': ['/etc/host.conf'], + \ 'hostsaccess': ['/etc/hosts.allow', '/etc/hosts.deny'], + \ 'htmlcheetah': ['file.tmpl'], + \ 'htmlm4': ['file.html.m4'], + \ 'httest': ['file.htt', 'file.htb'], + \ 'ibasic': ['file.iba', 'file.ibi'], + \ 'icemenu': ['/.icewm/menu'], + \ 'icon': ['file.icn'], + \ 'indent': ['.indent.pro', 'indentrc'], + \ 'inform': ['file.inf', 'file.INF'], + \ 'initng': ['/etc/initng/any/file.i', 'file.ii'], + \ 'inittab': ['inittab'], + \ 'ipfilter': ['ipf.conf', 'ipf6.conf', 'ipf.rules'], + \ 'iss': ['file.iss'], + \ 'ist': ['file.ist', 'file.mst'], + \ 'j': ['file.ijs'], + \ 'jal': ['file.jal', 'file.JAL'], + \ 'jam': ['file.jpl', 'file.jpr'], + \ 'java': ['file.java', 'file.jav'], + \ 'javacc': ['file.jj', 'file.jjt'], + \ 'javascript': ['file.js', 'file.javascript', 'file.es', 'file.jsx', 'file.mjs'], + \ 'jess': ['file.clp'], + \ 'jgraph': ['file.jgr'], + \ 'jovial': ['file.jov', 'file.j73', 'file.jovial'], + \ 'jproperties': ['file.properties', 'file.properties_xx', 'file.properties_xx_xx'], + \ 'json': ['file.json', 'file.jsonp', 'file.webmanifest'], + \ 'jsp': ['file.jsp'], + \ 'kconfig': ['Kconfig', 'Kconfig.debug'], + \ 'kivy': ['file.kv'], + \ 'kix': ['file.kix'], + \ 'kscript': ['file.ks'], + \ 'kwt': ['file.k'], + \ 'lace': ['file.ace', 'file.ACE'], + \ 'latte': ['file.latte', 'file.lte'], + \ 'ld': ['file.ld'], + \ 'ldif': ['file.ldif'], + \ 'less': ['file.less'], + \ 'lex': ['file.lex', 'file.l', 'file.lxx', 'file.l++'], + \ 'lftp': ['lftp.conf', '.lftprc', 'anylftp/rc'], + \ 'lhaskell': ['file.lhs'], + \ 'libao': ['/etc/libao.conf', '/.libao'], + \ 'lifelines': ['file.ll'], + \ 'lilo': ['lilo.conf'], + \ 'limits': ['/etc/limits', '/etc/anylimits.conf', '/etc/anylimits.d/file.conf'], + \ 'liquid': ['file.liquid'], + \ 'lisp': ['sbclrc', '.sbclrc'], + \ 'lite': ['file.lite', 'file.lt'], + \ 'litestep': ['/LiteStep/any/file.rc'], + \ 'loginaccess': ['/etc/login.access'], + \ 'logindefs': ['/etc/login.defs'], + \ 'logtalk': ['file.lgt'], + \ 'lotos': ['file.lot', 'file.lotos'], + \ 'lout': ['file.lou', 'file.lout'], + \ 'lprolog': ['file.sig'], + \ 'lsl': ['file.lsl'], + \ 'lss': ['file.lss'], + \ 'lua': ['file.lua', 'file.rockspec', 'file.nse'], + \ 'lynx': ['lynx.cfg'], + \ 'm4': ['file.at'], + \ 'mail': ['snd.123', '.letter', '.letter.123', '.followup', '.article', '.article.123', 'pico.123', 'mutt-xx-xxx', 'muttng-xx-xxx', 'ae123.txt', 'file.eml'], + \ 'mailaliases': ['/etc/mail/aliases', '/etc/aliases'], + \ 'mailcap': ['.mailcap', 'mailcap'], + \ 'make': ['file.mk', 'file.mak', 'file.dsp'], + \ 'mallard': ['file.page'], + \ 'man': ['file.man'], + \ 'manconf': ['/etc/man.conf', 'man.config'], + \ 'map': ['file.map'], + \ 'maple': ['file.mv', 'file.mpl', 'file.mws'], + \ 'markdown': ['file.markdown', 'file.mdown', 'file.mkd', 'file.mkdn', 'file.mdwn', 'file.md'], + \ 'mason': ['file.mason', 'file.mhtml', 'file.comp'], + \ 'master': ['file.mas', 'file.master'], + \ 'mel': ['file.mel'], + \ 'messages': ['/log/auth', '/log/cron', '/log/daemon', '/log/debug', '/log/kern', '/log/lpr', '/log/mail', '/log/messages', '/log/news/news', '/log/syslog', '/log/user', + \ '/log/auth.log', '/log/cron.log', '/log/daemon.log', '/log/debug.log', '/log/kern.log', '/log/lpr.log', '/log/mail.log', '/log/messages.log', '/log/news/news.log', '/log/syslog.log', '/log/user.log', + \ '/log/auth.err', '/log/cron.err', '/log/daemon.err', '/log/debug.err', '/log/kern.err', '/log/lpr.err', '/log/mail.err', '/log/messages.err', '/log/news/news.err', '/log/syslog.err', '/log/user.err', + \ '/log/auth.info', '/log/cron.info', '/log/daemon.info', '/log/debug.info', '/log/kern.info', '/log/lpr.info', '/log/mail.info', '/log/messages.info', '/log/news/news.info', '/log/syslog.info', '/log/user.info', + \ '/log/auth.warn', '/log/cron.warn', '/log/daemon.warn', '/log/debug.warn', '/log/kern.warn', '/log/lpr.warn', '/log/mail.warn', '/log/messages.warn', '/log/news/news.warn', '/log/syslog.warn', '/log/user.warn', + \ '/log/auth.crit', '/log/cron.crit', '/log/daemon.crit', '/log/debug.crit', '/log/kern.crit', '/log/lpr.crit', '/log/mail.crit', '/log/messages.crit', '/log/news/news.crit', '/log/syslog.crit', '/log/user.crit', + \ '/log/auth.notice', '/log/cron.notice', '/log/daemon.notice', '/log/debug.notice', '/log/kern.notice', '/log/lpr.notice', '/log/mail.notice', '/log/messages.notice', '/log/news/news.notice', '/log/syslog.notice', '/log/user.notice'], + \ 'mf': ['file.mf'], + \ 'mgl': ['file.mgl'], + \ 'mgp': ['file.mgp'], + \ 'mib': ['file.mib', 'file.my'], + \ 'mix': ['file.mix', 'file.mixal'], + \ 'mma': ['file.nb'], + \ 'mmp': ['file.mmp'], + \ 'modconf': ['/etc/modules.conf', '/etc/modules', '/etc/conf.modules'], + \ 'modula2': ['file.m2', 'file.mi'], + \ 'monk': ['file.isc', 'file.monk', 'file.ssc', 'file.tsc'], + \ 'moo': ['file.moo'], + \ 'mp': ['file.mp'], + \ 'mplayerconf': ['mplayer.conf', '/.mplayer/config'], + \ 'mrxvtrc': ['mrxvtrc', '.mrxvtrc'], + \ 'msidl': ['file.odl', 'file.mof'], + \ 'msql': ['file.msql'], + \ 'mupad': ['file.mu'], + \ 'mush': ['file.mush'], + \ 'muttrc': ['Muttngrc', 'Muttrc'], + \ 'mysql': ['file.mysql'], + \ 'n1ql': ['file.n1ql', 'file.nql'], + \ 'named': ['namedfile.conf', 'rndcfile.conf'], + \ 'nanorc': ['/etc/nanorc', 'file.nanorc'], + \ 'ncf': ['file.ncf'], + \ 'netrc': ['.netrc'], + \ 'ninja': ['file.ninja'], + \ 'nqc': ['file.nqc'], + \ 'nroff': ['file.tr', 'file.nr', 'file.roff', 'file.tmac', 'file.mom'], + \ 'nsis': ['file.nsi', 'file.nsh'], + \ 'obj': ['file.obj'], + \ 'ocaml': ['file.ml', 'file.mli', 'file.mll', 'file.mly', '.ocamlinit'], + \ 'occam': ['file.occ'], + \ 'omnimark': ['file.xom', 'file.xin'], + \ 'openroad': ['file.or'], + \ 'ora': ['file.ora'], + \ 'pamconf': ['/etc/pam.conf'], + \ 'papp': ['file.papp', 'file.pxml', 'file.pxsl'], + \ 'pascal': ['file.pas', 'file.dpr'], + \ 'passwd': ['any/etc/passwd', 'any/etc/passwd-', 'any/etc/passwd.edit', 'any/etc/shadow', 'any/etc/shadow-', 'any/etc/shadow.edit', 'any/var/backups/passwd.bak', 'any/var/backups/shadow.bak'], + \ 'pccts': ['file.g'], + \ 'pdf': ['file.pdf'], + \ 'perl': ['file.plx', 'file.al', 'file.psgi', 'gitolite.rc', '.gitolite.rc', 'example.gitolite.rc'], + \ 'perl6': ['file.p6', 'file.pm6', 'file.pl6'], + \ 'pf': ['pf.conf'], + \ 'pfmain': ['main.cf'], + \ 'php': ['file.php', 'file.php9', 'file.phtml', 'file.ctp'], + \ 'lpc': ['file.lpc', 'file.ulpc'], + \ 'pike': ['file.pike', 'file.pmod'], + \ 'cmod': ['file.cmod'], + \ 'pilrc': ['file.rcp'], + \ 'pine': ['.pinerc', 'pinerc', '.pinercex', 'pinercex'], + \ 'pinfo': ['/etc/pinforc', '/.pinforc'], + \ 'pli': ['file.pli', 'file.pl1'], + \ 'plm': ['file.plm', 'file.p36', 'file.pac'], + \ 'plp': ['file.plp'], + \ 'plsql': ['file.pls', 'file.plsql'], + \ 'po': ['file.po', 'file.pot'], + \ 'pod': ['file.pod'], + \ 'pod6': ['file.pod6'], + \ 'postscr': ['file.ps', 'file.pfa', 'file.afm', 'file.eps', 'file.epsf', 'file.epsi', 'file.ai'], + \ 'pov': ['file.pov'], + \ 'povini': ['.povrayrc'], + \ 'ppd': ['file.ppd'], + \ 'ppwiz': ['file.it', 'file.ih'], + \ 'privoxy': ['file.action'], + \ 'proc': ['file.pc'], + \ 'procmail': ['.procmail', '.procmailrc'], + \ 'prolog': ['file.pdb'], + \ 'promela': ['file.pml'], + \ 'proto': ['file.proto'], + \ 'protocols': ['/etc/protocols'], + \ 'psf': ['file.psf'], + \ 'pyrex': ['file.pyx', 'file.pxd'], + \ 'python': ['file.py', 'file.pyw', '.pythonstartup', '.pythonrc', 'file.ptl', 'file.pyi'], + \ 'quake': ['anybaseq2/file.cfg', 'anyid1/file.cfg', 'quake3/file.cfg'], + \ 'radiance': ['file.rad', 'file.mat'], + \ 'ratpoison': ['.ratpoisonrc', 'ratpoisonrc'], + \ 'rc': ['file.rc', 'file.rch'], + \ 'rcs': ['file,v'], + \ 'readline': ['.inputrc', 'inputrc'], + \ 'remind': ['.reminders', 'file.remind', 'file.rem'], + \ 'resolv': ['resolv.conf'], + \ 'reva': ['file.frt'], + \ 'rexx': ['file.rex', 'file.orx', 'file.rxo', 'file.rxj', 'file.jrexx', 'file.rexxj', 'file.rexx', 'file.testGroup', 'file.testUnit'], + \ 'rib': ['file.rib'], + \ 'rnc': ['file.rnc'], + \ 'rng': ['file.rng'], + \ 'robots': ['robots.txt'], + \ 'rpcgen': ['file.x'], + \ 'rpl': ['file.rpl'], + \ 'rst': ['file.rst'], + \ 'rtf': ['file.rtf'], + \ 'ruby': ['.irbrc', 'irbrc', 'file.rb', 'file.rbw', 'file.gemspec', 'file.ru', 'Gemfile', 'file.builder', 'file.rxml', 'file.rjs', 'file.rant', 'file.rake'], + \ 'rust': ['file.rs'], + \ 'samba': ['smb.conf'], + \ 'sas': ['file.sas'], + \ 'sass': ['file.sass'], + \ 'sather': ['file.sa'], + \ 'sbt': ['file.sbt'], + \ 'scala': ['file.scala'], + \ 'scheme': ['file.scm', 'file.ss', 'file.rkt'], + \ 'scilab': ['file.sci', 'file.sce'], + \ 'screen': ['.screenrc', 'screenrc'], + \ 'scss': ['file.scss'], + \ 'sd': ['file.sd'], + \ 'sdc': ['file.sdc'], + \ 'sdl': ['file.sdl', 'file.pr'], + \ 'sed': ['file.sed'], + \ 'sensors': ['/etc/sensors.conf', '/etc/sensors3.conf'], + \ 'services': ['/etc/services'], + \ 'setserial': ['/etc/serial.conf'], + \ 'sh': ['/etc/udev/cdsymlinks.conf'], + \ 'sieve': ['file.siv', 'file.sieve'], + \ 'simula': ['file.sim'], + \ 'sinda': ['file.sin', 'file.s85'], + \ 'sisu': ['file.sst', 'file.ssm', 'file.ssi', 'file.-sst', 'file._sst', 'file.sst.meta', 'file.-sst.meta', 'file._sst.meta'], + \ 'skill': ['file.il', 'file.ils', 'file.cdf'], + \ 'slang': ['file.sl'], + \ 'slice': ['file.ice'], + \ 'slpconf': ['/etc/slp.conf'], + \ 'slpreg': ['/etc/slp.reg'], + \ 'slpspi': ['/etc/slp.spi'], + \ 'slrnrc': ['.slrnrc'], + \ 'slrnsc': ['file.score'], + \ 'sm': ['sendmail.cf'], + \ 'smarty': ['file.tpl'], + \ 'smcl': ['file.hlp', 'file.ihlp', 'file.smcl'], + \ 'smith': ['file.smt', 'file.smith'], + \ 'sml': ['file.sml'], + \ 'snobol4': ['file.sno', 'file.spt'], + \ 'spec': ['file.spec'], + \ 'spice': ['file.sp', 'file.spice'], + \ 'spup': ['file.speedup', 'file.spdata', 'file.spd'], + \ 'spyce': ['file.spy', 'file.spi'], + \ 'sql': ['file.tyb', 'file.typ', 'file.tyc', 'file.pkb', 'file.pks'], + \ 'sqlj': ['file.sqlj'], + \ 'sqr': ['file.sqr', 'file.sqi'], + \ 'squid': ['squid.conf'], + \ 'srec': ['file.s19', 'file.s28', 'file.s37', 'file.mot', 'file.srec'], + \ 'sshconfig': ['ssh_config', '/.ssh/config'], + \ 'sshdconfig': ['sshd_config'], + \ 'st': ['file.st'], + \ 'stata': ['file.ado', 'file.do', 'file.imata', 'file.mata'], + \ 'stp': ['file.stp'], + \ 'sudoers': ['any/etc/sudoers', 'sudoers.tmp'], + \ 'svg': ['file.svg'], + \ 'svn': ['svn-commitfile.tmp'], + \ 'sysctl': ['/etc/sysctl.conf', '/etc/sysctl.d/file.conf'], + \ 'systemd': ['any/systemd/file.automount', 'any/systemd/file.mount', 'any/systemd/file.path', 'any/systemd/file.service', 'any/systemd/file.socket', 'any/systemd/file.swap', 'any/systemd/file.target', 'any/systemd/file.timer'], + \ 'systemverilog': ['file.sv', 'file.svh'], + \ 'tags': ['tags'], + \ 'tak': ['file.tak'], + \ 'taskdata': ['pending.data', 'completed.data', 'undo.data'], + \ 'taskedit': ['file.task'], + \ 'tcl': ['file.tcl', 'file.tk', 'file.itcl', 'file.itk', 'file.jacl'], + \ 'teraterm': ['file.ttl'], + \ 'terminfo': ['file.ti'], + \ 'tex': ['file.latex', 'file.sty', 'file.dtx', 'file.ltx', 'file.bbl'], + \ 'texinfo': ['file.texinfo', 'file.texi', 'file.txi'], + \ 'texmf': ['texmf.cnf'], + \ 'text': ['file.text', 'README'], + \ 'tf': ['file.tf', '.tfrc', 'tfrc'], + \ 'tidy': ['.tidyrc', 'tidyrc'], + \ 'tilde': ['file.t.html'], + \ 'tli': ['file.tli'], + \ 'tmux': ['tmuxfile.conf', '.tmuxfile.conf'], + \ 'tpp': ['file.tpp'], + \ 'treetop': ['file.treetop'], + \ 'trustees': ['trustees.conf'], + \ 'tsalt': ['file.slt'], + \ 'tsscl': ['file.tsscl'], + \ 'tssgm': ['file.tssgm'], + \ 'tssop': ['file.tssop'], + \ 'twig': ['file.twig'], + \ 'uc': ['file.uc'], + \ 'udevconf': ['/etc/udev/udev.conf'], + \ 'udevperm': ['/etc/udev/permissions.d/file.permissions'], + \ 'uil': ['file.uit', 'file.uil'], + \ 'updatedb': ['/etc/updatedb.conf'], + \ 'upstart': ['/usr/share/upstart/file.conf', '/usr/share/upstart/file.override', '/etc/init/file.conf', '/etc/init/file.override', '/.init/file.conf', '/.init/file.override', '/.config/upstart/file.conf', '/.config/upstart/file.override'], + \ 'upstreamdat': ['upstream.dat', 'UPSTREAM.DAT', 'upstream.file.dat', 'UPSTREAM.FILE.DAT', 'file.upstream.dat', 'FILE.UPSTREAM.DAT'], + \ 'upstreaminstalllog': ['upstreaminstall.log', 'UPSTREAMINSTALL.LOG', 'upstreaminstall.file.log', 'UPSTREAMINSTALL.FILE.LOG', 'file.upstreaminstall.log', 'FILE.UPSTREAMINSTALL.LOG'], + \ 'upstreamlog': ['fdrupstream.log', 'upstream.log', 'UPSTREAM.LOG', 'upstream.file.log', 'UPSTREAM.FILE.LOG', 'file.upstream.log', 'FILE.UPSTREAM.LOG', 'UPSTREAM-file.log', 'UPSTREAM-FILE.LOG'], + \ 'usserverlog': ['usserver.log', 'USSERVER.LOG', 'usserver.file.log', 'USSERVER.FILE.LOG', 'file.usserver.log', 'FILE.USSERVER.LOG'], + \ 'usw2kagtlog': ['usw2kagt.log', 'USW2KAGT.LOG', 'usw2kagt.file.log', 'USW2KAGT.FILE.LOG', 'file.usw2kagt.log', 'FILE.USW2KAGT.LOG'], + \ 'vb': ['file.sba', 'file.vb', 'file.vbs', 'file.dsm', 'file.ctl'], + \ 'vera': ['file.vr', 'file.vri', 'file.vrh'], + \ 'verilog': ['file.v'], + \ 'verilogams': ['file.va', 'file.vams'], + \ 'vgrindefs': ['vgrindefs'], + \ 'vhdl': ['file.hdl', 'file.vhd', 'file.vhdl', 'file.vbe', 'file.vst'], + \ 'vim': ['file.vim', 'file.vba', '.exrc', '_exrc'], + \ 'viminfo': ['.viminfo', '_viminfo'], + \ 'vmasm': ['file.mar'], + \ 'voscm': ['file.cm'], + \ 'vrml': ['file.wrl'], + \ 'vroom': ['file.vroom'], + \ 'wast': ['file.wast', 'file.wat'], + \ 'webmacro': ['file.wm'], + \ 'wget': ['.wgetrc', 'wgetrc'], + \ 'winbatch': ['file.wbt'], + \ 'wml': ['file.wml'], + \ 'wsml': ['file.wsml'], + \ 'wvdial': ['wvdial.conf', '.wvdialrc'], + \ 'xdefaults': ['.Xdefaults', '.Xpdefaults', '.Xresources', 'xdm-config', 'file.ad'], + \ 'xhtml': ['file.xhtml', 'file.xht'], + \ 'xinetd': ['/etc/xinetd.conf'], + \ 'xmath': ['file.msc', 'file.msf'], + \ 'xml': ['/etc/blkid.tab', '/etc/blkid.tab.old', 'file.xmi', 'file.csproj', 'file.csproj.user', 'file.ts', 'file.ui', 'file.tpm', '/etc/xdg/menus/file.menu', 'fglrxrc', 'file.xlf', 'file.xliff', 'file.xul', 'file.wsdl'], + \ 'xmodmap': ['anyXmodmap'], + \ 'xf86conf': ['xorg.conf', 'xorg.conf-4'], + \ 'xpm2': ['file.xpm2'], + \ 'xquery': ['file.xq', 'file.xql', 'file.xqm', 'file.xquery', 'file.xqy'], + \ 'xs': ['file.xs'], + \ 'xsd': ['file.xsd'], + \ 'xslt': ['file.xsl', 'file.xslt'], + \ 'yacc': ['file.yy', 'file.yxx', 'file.y++'], + \ 'yaml': ['file.yaml', 'file.yml'], + \ 'raml': ['file.raml'], + \ 'z8a': ['file.z8a'], + \ 'zimbu': ['file.zu'], + \ 'zimbutempl': ['file.zut'], + \ 'zsh': ['.zprofile', '/etc/zprofile', '.zfbfmarks', 'file.zsh'], + \ + \ 'aap': ['file.aap'], + \ 'help': [$VIMRUNTIME . '/doc/help.txt'], + \ 'xpm': ['file.xpm'], + \ } + +let s:filename_case_checks = { + \ 'modula2': ['file.DEF', 'file.MOD'], + \ } + +func CheckItems(checks) + for [ft, names] in items(a:checks) + for i in range(0, len(names) - 1) + new + try + exe 'edit ' . names[i] + catch + call assert_report('cannot edit "' . names[i] . '": ' . v:errmsg) + endtry + call assert_equal(ft, &filetype, 'with file name: ' . names[i]) + bwipe! + endfor + endfor +endfunc + +func Test_filetype_detection() + filetype on + call CheckItems(s:filename_checks) + if has('fname_case') + call CheckItems(s:filename_case_checks) + endif + filetype off +endfunc + +" Filetypes detected from the file contents by scripts.vim +let s:script_checks = { + \ 'virata': [['% Virata'], + \ ['', '% Virata'], + \ ['', '', '% Virata'], + \ ['', '', '', '% Virata'], + \ ['', '', '', '', '% Virata']], + \ 'strace': [['execve("/usr/bin/pstree", ["pstree"], 0x7ff0 /* 63 vars */) = 0'], + \ ['15:17:47 execve("/usr/bin/pstree", ["pstree"], ... "_=/usr/bin/strace"]) = 0'], + \ ['__libc_start_main and something']], + \ 'clojure': [['#!/path/clojure']], + \ 'scala': [['#!/path/scala']], + \ 'tcsh': [['#!/path/tcsh']], + \ 'zsh': [['#!/path/zsh']], + \ 'tcl': [['#!/path/tclsh'], + \ ['#!/path/wish'], + \ ['#!/path/expectk'], + \ ['#!/path/itclsh'], + \ ['#!/path/itkwish']], + \ 'expect': [['#!/path/expect']], + \ 'gnuplot': [['#!/path/gnuplot']], + \ 'make': [['#!/path/make']], + \ 'pike': [['#!/path/pike'], + \ ['#!/path/pike0'], + \ ['#!/path/pike9']], + \ 'lua': [['#!/path/lua']], + \ 'perl6': [['#!/path/perl6']], + \ 'perl': [['#!/path/perl']], + \ 'php': [['#!/path/php']], + \ 'python': [['#!/path/python'], + \ ['#!/path/python2'], + \ ['#!/path/python3']], + \ 'groovy': [['#!/path/groovy']], + \ 'ruby': [['#!/path/ruby']], + \ 'javascript': [['#!/path/node'], + \ ['#!/path/js'], + \ ['#!/path/nodejs'], + \ ['#!/path/rhino']], + \ 'bc': [['#!/path/bc']], + \ 'sed': [['#!/path/sed']], + \ 'ocaml': [['#!/path/ocaml']], + \ 'awk': [['#!/path/awk']], + \ 'wml': [['#!/path/wml']], + \ 'scheme': [['#!/path/scheme']], + \ 'cfengine': [['#!/path/cfengine']], + \ 'erlang': [['#!/path/escript']], + \ 'haskell': [['#!/path/haskell']], + \ } + +func Test_script_detection() + filetype on + for [ft, files] in items(s:script_checks) + for file in files + call writefile(file, 'Xtest') + split Xtest + call assert_equal(ft, &filetype, 'for text: ' . string(file)) + bwipe! + endfor + endfor + call delete('Xtest') + filetype off +endfunc + +func Test_setfiletype_completion() + call feedkeys(":setfiletype java\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"setfiletype java javacc javascript', @:) +endfunc diff --git a/src/testdir/test_filter_cmd.vim b/src/testdir/test_filter_cmd.vim new file mode 100644 index 0000000..6f40a90 --- /dev/null +++ b/src/testdir/test_filter_cmd.vim @@ -0,0 +1,132 @@ +" Test the :filter command modifier + +func Test_filter() + edit Xdoesnotmatch + edit Xwillmatch + call assert_equal('"Xwillmatch"', substitute(execute('filter willma ls'), '[^"]*\(".*"\)[^"]*', '\1', '')) + bwipe Xdoesnotmatch + bwipe Xwillmatch + + new + call setline(1, ['foo1', 'foo2', 'foo3', 'foo4', 'foo5']) + call assert_equal("\nfoo2\nfoo4", execute('filter /foo[24]/ 1,$print')) + call assert_equal("\n 2 foo2\n 4 foo4", execute('filter /foo[24]/ 1,$number')) + call assert_equal("\nfoo2$\nfoo4$", execute('filter /foo[24]/ 1,$list')) + + call assert_equal("\nfoo1$\nfoo3$\nfoo5$", execute('filter! /foo[24]/ 1,$list')) + bwipe! + + command XTryThis echo 'this' + command XTryThat echo 'that' + command XDoThat echo 'that' + let lines = split(execute('filter XTry command'), "\n") + call assert_equal(3, len(lines)) + call assert_match("XTryThat", lines[1]) + call assert_match("XTryThis", lines[2]) + delcommand XTryThis + delcommand XTryThat + delcommand XDoThat + + map f1 the first key + map f2 the second key + map f3 not a key + let lines = split(execute('filter the map f'), "\n") + call assert_equal(2, len(lines)) + call assert_match("f2", lines[0]) + call assert_match("f1", lines[1]) + unmap f1 + unmap f2 + unmap f3 +endfunc + +func Test_filter_fails() + call assert_fails('filter', 'E471:') + call assert_fails('filter pat', 'E476:') + call assert_fails('filter /pat', 'E476:') + call assert_fails('filter /pat/', 'E476:') + call assert_fails('filter /pat/ asdf', 'E492:') + + call assert_fails('filter!', 'E471:') + call assert_fails('filter! pat', 'E476:') + call assert_fails('filter! /pat', 'E476:') + call assert_fails('filter! /pat/', 'E476:') + call assert_fails('filter! /pat/ asdf', 'E492:') +endfunc + +function s:complete_filter_cmd(filtcmd) + let keystroke = "\<TAB>\<C-R>=execute('let cmdline = getcmdline()')\<CR>\<C-C>" + let cmdline = '' + call feedkeys(':' . a:filtcmd . keystroke, 'ntx') + return cmdline +endfunction + +func Test_filter_cmd_completion() + " Do not complete pattern + call assert_equal("filter \t", s:complete_filter_cmd('filter ')) + call assert_equal("filter pat\t", s:complete_filter_cmd('filter pat')) + call assert_equal("filter /pat\t", s:complete_filter_cmd('filter /pat')) + call assert_equal("filter /pat/\t", s:complete_filter_cmd('filter /pat/')) + + " Complete after string pattern + call assert_equal('filter pat print', s:complete_filter_cmd('filter pat pri')) + + " Complete after regexp pattern + call assert_equal('filter /pat/ print', s:complete_filter_cmd('filter /pat/ pri')) + call assert_equal('filter #pat# print', s:complete_filter_cmd('filter #pat# pri')) +endfunc + +func Test_filter_cmd_with_filter() + new + set shelltemp + %!echo "a|b" + let out = getline(1) + bw! + if has('win32') + let out = trim(out, '" ') + endif + call assert_equal('a|b', out) + set shelltemp& +endfunction + +func Test_filter_commands() + let g:test_filter_a = 1 + let b:test_filter_b = 2 + let test_filter_c = 3 + + " Test filtering :let command + let res = split(execute("filter /^test_filter/ let"), "\n") + call assert_equal(["test_filter_a #1"], res) + + let res = split(execute("filter /\\v^(b:)?test_filter/ let"), "\n") + call assert_equal(["test_filter_a #1", "b:test_filter_b #2"], res) + + unlet g:test_filter_a + unlet b:test_filter_b + unlet test_filter_c + + " Test filtering :set command + let helplang=&helplang + set helplang=en + let res = join(split(execute("filter /^help/ set"), "\n")[1:], " ") + call assert_match('^\s*helplang=\w*$', res) + let &helplang=helplang + + " Test filtering :llist command + call setloclist(0, [{"filename": "/path/vim.c"}, {"filename": "/path/vim.h"}, {"module": "Main.Test"}]) + let res = split(execute("filter /\\.c$/ llist"), "\n") + call assert_equal([" 1 /path/vim.c: "], res) + + let res = split(execute("filter /\\.Test$/ llist"), "\n") + call assert_equal([" 3 Main.Test: "], res) + + " Test filtering :jump command + e file.c + e file.h + e file.hs + let res = split(execute("filter /\.c$/ jumps"), "\n")[1:] + call assert_equal([" 2 1 0 file.c", ">"], res) + + bwipe file.c + bwipe file.h + bwipe file.hs +endfunc diff --git a/src/testdir/test_filter_map.vim b/src/testdir/test_filter_map.vim new file mode 100644 index 0000000..1dd3a5b --- /dev/null +++ b/src/testdir/test_filter_map.vim @@ -0,0 +1,86 @@ +" Test filter() and map() + +" list with expression string +func Test_filter_map_list_expr_string() + " filter() + call assert_equal([2, 3, 4], filter([1, 2, 3, 4], 'v:val > 1')) + call assert_equal([3, 4], filter([1, 2, 3, 4], 'v:key > 1')) + call assert_equal([], filter([1, 2, 3, 4], 0)) + + " map() + call assert_equal([2, 4, 6, 8], map([1, 2, 3, 4], 'v:val * 2')) + call assert_equal([0, 2, 4, 6], map([1, 2, 3, 4], 'v:key * 2')) + call assert_equal([9, 9, 9, 9], map([1, 2, 3, 4], 9)) +endfunc + +" dict with expression string +func Test_filter_map_dict_expr_string() + let dict = {"foo": 1, "bar": 2, "baz": 3} + + " filter() + call assert_equal({"bar": 2, "baz": 3}, filter(copy(dict), 'v:val > 1')) + call assert_equal({"foo": 1, "baz": 3}, filter(copy(dict), 'v:key > "bar"')) + call assert_equal({}, filter(copy(dict), 0)) + + " map() + call assert_equal({"foo": 2, "bar": 4, "baz": 6}, map(copy(dict), 'v:val * 2')) + call assert_equal({"foo": "f", "bar": "b", "baz": "b"}, map(copy(dict), 'v:key[0]')) + call assert_equal({"foo": 9, "bar": 9, "baz": 9}, map(copy(dict), 9)) +endfunc + +" list with funcref +func Test_filter_map_list_expr_funcref() + " filter() + func! s:filter1(index, val) abort + return a:val > 1 + endfunc + call assert_equal([2, 3, 4], filter([1, 2, 3, 4], function('s:filter1'))) + + func! s:filter2(index, val) abort + return a:index > 1 + endfunc + call assert_equal([3, 4], filter([1, 2, 3, 4], function('s:filter2'))) + + " map() + func! s:filter3(index, val) abort + return a:val * 2 + endfunc + call assert_equal([2, 4, 6, 8], map([1, 2, 3, 4], function('s:filter3'))) + + func! s:filter4(index, val) abort + return a:index * 2 + endfunc + call assert_equal([0, 2, 4, 6], map([1, 2, 3, 4], function('s:filter4'))) +endfunc + +" dict with funcref +func Test_filter_map_dict_expr_funcref() + let dict = {"foo": 1, "bar": 2, "baz": 3} + + " filter() + func! s:filter1(key, val) abort + return a:val > 1 + endfunc + call assert_equal({"bar": 2, "baz": 3}, filter(copy(dict), function('s:filter1'))) + + func! s:filter2(key, val) abort + return a:key > "bar" + endfunc + call assert_equal({"foo": 1, "baz": 3}, filter(copy(dict), function('s:filter2'))) + + " map() + func! s:filter3(key, val) abort + return a:val * 2 + endfunc + call assert_equal({"foo": 2, "bar": 4, "baz": 6}, map(copy(dict), function('s:filter3'))) + + func! s:filter4(key, val) abort + return a:key[0] + endfunc + call assert_equal({"foo": "f", "bar": "b", "baz": "b"}, map(copy(dict), function('s:filter4'))) +endfunc + +func Test_map_fails() + call assert_fails('call map([1], "42 +")', 'E15:') + call assert_fails('call filter([1], "42 +")', 'E15:') +endfunc diff --git a/src/testdir/test_find_complete.vim b/src/testdir/test_find_complete.vim new file mode 100644 index 0000000..a7bc135 --- /dev/null +++ b/src/testdir/test_find_complete.vim @@ -0,0 +1,163 @@ +" Tests for the 'find' command completion. + +" Do all the tests in a separate window to avoid E211 when we recursively +" delete the Xfind directory during cleanup +func Test_find_complete() + set belloff=all + + " On windows a stale "Xfind" directory may exist, remove it so that + " we start from a clean state. + call delete("Xfind", "rf") + let cwd = getcwd() + let test_out = cwd . '/test.out' + call mkdir('Xfind') + cd Xfind + + new + set path= + call assert_fails('call feedkeys(":find\t\n", "xt")', 'E345:') + close + + new + set path=. + call assert_fails('call feedkeys(":find\t\n", "xt")', 'E32:') + close + + new + set path=.,, + call assert_fails('call feedkeys(":find\t\n", "xt")', 'E32:') + close + + new + set path=./** + call assert_fails('call feedkeys(":find\t\n", "xt")', 'E32:') + close + + " We shouldn't find any file till this point + + call mkdir('in/path', 'p') + exe 'cd ' . cwd + call writefile(['Holy Grail'], 'Xfind/file.txt') + call writefile(['Jimmy Hoffa'], 'Xfind/in/file.txt') + call writefile(['Another Holy Grail'], 'Xfind/in/stuff.txt') + call writefile(['E.T.'], 'Xfind/in/path/file.txt') + + new + set path=Xfind/** + call feedkeys(":find file\t\n", "xt") + call assert_equal('Holy Grail', getline(1)) + call feedkeys(":find file\t\t\n", "xt") + call assert_equal('Jimmy Hoffa', getline(1)) + call feedkeys(":find file\t\t\t\n", "xt") + call assert_equal('E.T.', getline(1)) + + " Rerun the previous three find completions, using fullpath in 'path' + exec "set path=" . cwd . "/Xfind/**" + + call feedkeys(":find file\t\n", "xt") + call assert_equal('Holy Grail', getline(1)) + call feedkeys(":find file\t\t\n", "xt") + call assert_equal('Jimmy Hoffa', getline(1)) + call feedkeys(":find file\t\t\t\n", "xt") + call assert_equal('E.T.', getline(1)) + + " Same steps again, using relative and fullpath items that point to the same + " recursive location. + " This is to test that there are no duplicates in the completion list. + set path+=Xfind/** + call feedkeys(":find file\t\n", "xt") + call assert_equal('Holy Grail', getline(1)) + call feedkeys(":find file\t\t\n", "xt") + call assert_equal('Jimmy Hoffa', getline(1)) + call feedkeys(":find file\t\t\t\n", "xt") + call assert_equal('E.T.', getline(1)) + call feedkeys(":find file\t\t\n", "xt") + + " Test find completion for directory of current buffer, which at this point + " is Xfind/in/file.txt. + set path=. + call feedkeys(":find st\t\n", "xt") + call assert_equal('Another Holy Grail', getline(1)) + + " Test find completion for empty path item ",," which is the current + " directory + cd Xfind + set path=,, + call feedkeys(":find f\t\n", "xt") + call assert_equal('Holy Grail', getline(1)) + + " Test that find completion on directory appends a slash + call feedkeys(":find in/pa\tfile.txt\n", "xt") + call assert_equal('E.T.', getline(1)) + call feedkeys(":find ./i\tstuff.txt\n", "xt") + call assert_equal('Another Holy Grail', getline(1)) + + " Test shortening of + " + " foo/x/bar/voyager.txt + " foo/y/bar/voyager.txt + " + " When current directory is above foo/ they should be shortened to (in order + " of appearance): + " + " x/bar/voyager.txt + " y/bar/voyager.txt + call mkdir('foo/x/bar', 'p') + call mkdir('foo/y/bar', 'p') + call writefile(['Voyager 1'], 'foo/x/bar/voyager.txt') + call writefile(['Voyager 2'], 'foo/y/bar/voyager.txt') + + exec "set path=" . cwd . "/Xfind/**" + call feedkeys(":find voyager\t\n", "xt") + call assert_equal('Voyager 1', getline(1)) + call feedkeys(":find voyager\t\t\n", "xt") + call assert_equal('Voyager 2', getline(1)) + + " + " When current directory is .../foo/y/bar they should be shortened to (in + " order of appearance): + " + " ./voyager.txt + " x/bar/voyager.txt + cd foo/y/bar + call feedkeys(":find voyager\t\n", "xt") + call assert_equal('Voyager 2', getline(1)) + call feedkeys(":find voyager\t\t\n", "xt") + call assert_equal('Voyager 1', getline(1)) + + " Check the opposite too: + cd ../../x/bar + call feedkeys(":find voyager\t\n", "xt") + call assert_equal('Voyager 1', getline(1)) + call feedkeys(":find voyager\t\t\n", "xt") + call assert_equal('Voyager 2', getline(1)) + + " Check for correct handling of shorten_fname()'s behavior on windows + exec "cd " . cwd . "/Xfind/in" + call feedkeys(":find file\t\n", "xt") + call assert_equal('Jimmy Hoffa', getline(1)) + + " Test for relative to current buffer 'path' item + exec "cd " . cwd . "/Xfind/" + set path=./path + " Open the file where Jimmy Hoffa is found + e in/file.txt + " Find the file containing 'E.T.' in the Xfind/in/path directory + call feedkeys(":find file\t\n", "xt") + call assert_equal('E.T.', getline(1)) + + " Test that completion works when path=.,, + set path=.,, + " Open Jimmy Hoffa file + e in/file.txt + call assert_equal('Jimmy Hoffa', getline(1)) + + " Search for the file containing Holy Grail in same directory as in/path.txt + call feedkeys(":find stu\t\n", "xt") + call assert_equal('Another Holy Grail', getline(1)) + + enew | only + exe 'cd ' . cwd + call delete('Xfind', 'rf') + set path& +endfunc diff --git a/src/testdir/test_findfile.vim b/src/testdir/test_findfile.vim new file mode 100644 index 0000000..0bae161 --- /dev/null +++ b/src/testdir/test_findfile.vim @@ -0,0 +1,185 @@ +" Test findfile() and finddir() + +let s:files = [ 'Xdir1/foo', + \ 'Xdir1/bar', + \ 'Xdir1/Xdir2/foo', + \ 'Xdir1/Xdir2/foobar', + \ 'Xdir1/Xdir2/Xdir3/bar', + \ 'Xdir1/Xdir2/Xdir3/barfoo' ] + +func CreateFiles() + call mkdir('Xdir1/Xdir2/Xdir3/Xdir2', 'p') + for f in s:files + call writefile([], f) + endfor +endfunc + +func CleanFiles() + " Safer to delete each file even if it's more verbose + " than doing a recursive delete('Xdir1', 'rf'). + for f in s:files + call delete(f) + endfor + + call delete('Xdir1/Xdir2/Xdir3/Xdir2', 'd') + call delete('Xdir1/Xdir2/Xdir3', 'd') + call delete('Xdir1/Xdir2', 'd') + call delete('Xdir1', 'd') +endfunc + +" Test findfile({name} [, {path} [, {count}]]) +func Test_findfile() + let save_path = &path + let save_shellslash = &shellslash + let save_dir = getcwd() + set shellslash + call CreateFiles() + cd Xdir1 + e Xdir2/foo + + " With ,, in path, findfile() searches in current directory. + set path=,, + call assert_equal('foo', findfile('foo')) + call assert_equal('bar', findfile('bar')) + call assert_equal('', findfile('foobar')) + + " Directories should not be found (finddir() finds them). + call assert_equal('', findfile('Xdir2')) + + " With . in 'path', findfile() searches relatively to current file. + set path=. + call assert_equal('Xdir2/foo', findfile('foo')) + call assert_equal('', findfile('bar')) + call assert_equal('Xdir2/foobar', findfile('foobar')) + + " Empty {path} 2nd argument is the same as no 2nd argument. + call assert_equal('Xdir2/foo', findfile('foo', '')) + call assert_equal('', findfile('bar', '')) + + " Test with * + call assert_equal('Xdir2/foo', findfile('foo', '*')) + call assert_equal('', findfile('bar', '*')) + call assert_equal('Xdir2/Xdir3/bar', findfile('bar', '*/*')) + call assert_equal('Xdir2/Xdir3/bar', findfile('bar', 'Xdir2/*')) + call assert_equal('Xdir2/Xdir3/bar', findfile('bar', 'Xdir*/Xdir3')) + call assert_equal('Xdir2/Xdir3/bar', findfile('bar', '*2/*3')) + + " Test with ** + call assert_equal('bar', findfile('bar', '**')) + call assert_equal('Xdir2/Xdir3/bar', findfile('bar', '**/Xdir3')) + call assert_equal('Xdir2/Xdir3/bar', findfile('bar', 'Xdir2/**')) + + call assert_equal('Xdir2/Xdir3/barfoo', findfile('barfoo', '**2')) + call assert_equal('', findfile('barfoo', '**1')) + call assert_equal('Xdir2/foobar', findfile('foobar', '**1')) + + " Test with {count} 3rd argument. + call assert_equal('bar', findfile('bar', '**', 0)) + call assert_equal('bar', findfile('bar', '**', 1)) + call assert_equal('Xdir2/Xdir3/bar', findfile('bar', '**', 2)) + call assert_equal('', findfile('bar', '**', 3)) + call assert_equal(['bar', 'Xdir2/Xdir3/bar'], findfile('bar', '**', -1)) + + " Test upwards search. + cd Xdir2/Xdir3 + call assert_equal('bar', findfile('bar', ';')) + call assert_match('.*/Xdir1/Xdir2/foo', findfile('foo', ';')) + call assert_match('.*/Xdir1/Xdir2/foo', findfile('foo', ';', 1)) + call assert_match('.*/Xdir1/foo', findfile('foo', ';', 2)) + call assert_match('.*/Xdir1/foo', findfile('foo', ';', 2)) + call assert_match('.*/Xdir1/Xdir2/foo', findfile('foo', 'Xdir2;', 1)) + call assert_equal('', findfile('foo', 'Xdir2;', 2)) + + " List l should have at least 2 values (possibly more if foo file + " happens to be found upwards above Xdir1). + let l = findfile('foo', ';', -1) + call assert_match('.*/Xdir1/Xdir2/foo', l[0]) + call assert_match('.*/Xdir1/foo', l[1]) + + " Test upwards search with stop-directory. + cd Xdir2 + let l = findfile('bar', ';' . save_dir . '/Xdir1/Xdir2/', -1) + call assert_equal(1, len(l)) + call assert_match('.*/Xdir1/Xdir2/Xdir3/bar', l[0]) + + let l = findfile('bar', ';' . save_dir . '/Xdir1/', -1) + call assert_equal(2, len(l)) + call assert_match('.*/Xdir1/Xdir2/Xdir3/bar', l[0]) + call assert_match('.*/Xdir1/bar', l[1]) + + " Test combined downwards and upwards search from Xdir2/. + cd ../.. + call assert_equal('Xdir3/bar', findfile('bar', '**;', 1)) + call assert_match('.*/Xdir1/bar', findfile('bar', '**;', 2)) + + bwipe! + exe 'cd ' . save_dir + call CleanFiles() + let &path = save_path + let &shellslash = save_shellslash +endfunc + +func Test_findfile_error() + call assert_fails('call findfile([])', 'E730:') + call assert_fails('call findfile("x", [])', 'E730:') + call assert_fails('call findfile("x", "", [])', 'E745:') + call assert_fails('call findfile("x", "**x")', 'E343:') + call assert_fails('call findfile("x", repeat("x", 5000))', 'E854:') +endfunc + +" Test finddir({name} [, {path} [, {count}]]) +func Test_finddir() + let save_path = &path + let save_shellslash = &shellslash + let save_dir = getcwd() + set path=,, + call CreateFiles() + cd Xdir1 + + call assert_equal('Xdir2', finddir('Xdir2')) + call assert_equal('', finddir('Xdir3')) + + " Files should not be found (findfile() finds them). + call assert_equal('', finddir('foo')) + + call assert_equal('Xdir2', finddir('Xdir2', '**')) + call assert_equal('Xdir2/Xdir3', finddir('Xdir3', '**')) + + call assert_equal('Xdir2', finddir('Xdir2', '**', 1)) + call assert_equal('Xdir2/Xdir3/Xdir2', finddir('Xdir2', '**', 2)) + call assert_equal(['Xdir2', + \ 'Xdir2/Xdir3/Xdir2'], finddir('Xdir2', '**', -1)) + + call assert_equal('Xdir2', finddir('Xdir2', '**1')) + call assert_equal('Xdir2', finddir('Xdir2', '**0')) + call assert_equal('Xdir2/Xdir3', finddir('Xdir3', '**1')) + call assert_equal('', finddir('Xdir3', '**0')) + + " Test upwards dir search. + cd Xdir2/Xdir3 + call assert_match('.*/Xdir1', finddir('Xdir1', ';')) + + " Test upwards search with stop-directory. + call assert_match('.*/Xdir1', finddir('Xdir1', ';' . save_dir . '/')) + call assert_equal('', finddir('Xdir1', ';' . save_dir . '/Xdir1/')) + + " Test combined downwards and upwards dir search from Xdir2/. + cd .. + call assert_match('.*/Xdir1', finddir('Xdir1', '**;', 1)) + call assert_equal('Xdir3/Xdir2', finddir('Xdir2', '**;', 1)) + call assert_match('.*/Xdir1/Xdir2', finddir('Xdir2', '**;', 2)) + call assert_equal('Xdir3', finddir('Xdir3', '**;', 1)) + + exe 'cd ' . save_dir + call CleanFiles() + let &path = save_path + let &shellslash = save_shellslash +endfunc + +func Test_finddir_error() + call assert_fails('call finddir([])', 'E730:') + call assert_fails('call finddir("x", [])', 'E730:') + call assert_fails('call finddir("x", "", [])', 'E745:') + call assert_fails('call finddir("x", "**x")', 'E343:') + call assert_fails('call finddir("x", repeat("x", 5000))', 'E854:') +endfunc diff --git a/src/testdir/test_fixeol.vim b/src/testdir/test_fixeol.vim new file mode 100644 index 0000000..32cb059 --- /dev/null +++ b/src/testdir/test_fixeol.vim @@ -0,0 +1,48 @@ +" Tests for 'fixeol' and 'eol' +func Test_fixeol() + " first write two test files – with and without trailing EOL + " use Unix fileformat for consistency + set ff=unix + enew! + call setline('.', 'with eol') + w! XXEol + enew! + set noeol nofixeol + call setline('.', 'without eol') + w! XXNoEol + set eol fixeol + bwipe XXEol XXNoEol + + " try editing files with 'fixeol' disabled + e! XXEol + normal ostays eol + set nofixeol + w! XXTestEol + e! XXNoEol + normal ostays without + set nofixeol + w! XXTestNoEol + bwipe! XXEol XXNoEol XXTestEol XXTestNoEol + set fixeol + + " Append "END" to each file so that we can see what the last written char + " was. + normal ggdGaEND + w >>XXEol + w >>XXNoEol + w >>XXTestEol + w >>XXTestNoEol + + call assert_equal(['with eol', 'END'], readfile('XXEol')) + call assert_equal(['without eolEND'], readfile('XXNoEol')) + call assert_equal(['with eol', 'stays eol', 'END'], readfile('XXTestEol')) + call assert_equal(['without eol', 'stays withoutEND'], + \ readfile('XXTestNoEol')) + + call delete('XXEol') + call delete('XXNoEol') + call delete('XXTestEol') + call delete('XXTestNoEol') + set ff& fixeol& eol& + enew! +endfunc diff --git a/src/testdir/test_float_func.vim b/src/testdir/test_float_func.vim new file mode 100644 index 0000000..32b985e --- /dev/null +++ b/src/testdir/test_float_func.vim @@ -0,0 +1,331 @@ +" test float functions + +if !has('float') + finish +end + +func Test_abs() + call assert_equal('1.23', string(abs(1.23))) + call assert_equal('1.23', string(abs(-1.23))) + call assert_equal('0.0', string(abs(0.0))) + call assert_equal('0.0', string(abs(1.0/(1.0/0.0)))) + call assert_equal('0.0', string(abs(-1.0/(1.0/0.0)))) + call assert_equal('inf', string(abs(1.0/0.0))) + call assert_equal('inf', string(abs(-1.0/0.0))) + call assert_equal('nan', string(abs(0.0/0.0))) + call assert_equal('12', string(abs('-12abc'))) + call assert_fails("call abs([])", 'E745:') + call assert_fails("call abs({})", 'E728:') + call assert_fails("call abs(function('string'))", 'E703:') +endfunc + +func Test_sqrt() + call assert_equal('0.0', string(sqrt(0.0))) + call assert_equal('1.414214', string(sqrt(2.0))) + call assert_equal('inf', string(sqrt(1.0/0.0))) + call assert_equal('nan', string(sqrt(-1.0))) + call assert_equal('nan', string(sqrt(0.0/0.0))) + call assert_fails('call sqrt("")', 'E808:') +endfunc + +func Test_log() + call assert_equal('0.0', string(log(1.0))) + call assert_equal('-0.693147', string(log(0.5))) + call assert_equal('-inf', string(log(0.0))) + call assert_equal('nan', string(log(-1.0))) + call assert_equal('inf', string(log(1.0/0.0))) + call assert_equal('nan', string(log(0.0/0.0))) + call assert_fails('call log("")', 'E808:') +endfunc + +func Test_log10() + call assert_equal('0.0', string(log10(1.0))) + call assert_equal('2.0', string(log10(100.0))) + call assert_equal('2.079181', string(log10(120.0))) + call assert_equal('-inf', string(log10(0.0))) + call assert_equal('nan', string(log10(-1.0))) + call assert_equal('inf', string(log10(1.0/0.0))) + call assert_equal('nan', string(log10(0.0/0.0))) + call assert_fails('call log10("")', 'E808:') +endfunc + +func Test_exp() + call assert_equal('1.0', string(exp(0.0))) + call assert_equal('7.389056', string(exp(2.0))) + call assert_equal('0.367879', string(exp(-1.0))) + call assert_equal('inf', string(exp(1.0/0.0))) + call assert_equal('0.0', string(exp(-1.0/0.0))) + call assert_equal('nan', string(exp(0.0/0.0))) + call assert_fails('call exp("")', 'E808:') +endfunc + +func Test_sin() + call assert_equal('0.0', string(sin(0.0))) + call assert_equal('0.841471', string(sin(1.0))) + call assert_equal('-0.479426', string(sin(-0.5))) + call assert_equal('nan', string(sin(0.0/0.0))) + call assert_equal('nan', string(sin(1.0/0.0))) + call assert_equal('0.0', string(sin(1.0/(1.0/0.0)))) + call assert_equal('-0.0', string(sin(-1.0/(1.0/0.0)))) + call assert_fails('call sin("")', 'E808:') +endfunc + +func Test_asin() + call assert_equal('0.0', string(asin(0.0))) + call assert_equal('1.570796', string(asin(1.0))) + call assert_equal('-0.523599', string(asin(-0.5))) + call assert_equal('nan', string(asin(1.1))) + call assert_equal('nan', string(asin(1.0/0.0))) + call assert_equal('nan', string(asin(0.0/0.0))) + call assert_fails('call asin("")', 'E808:') +endfunc + +func Test_sinh() + call assert_equal('0.0', string(sinh(0.0))) + call assert_equal('0.521095', string(sinh(0.5))) + call assert_equal('-1.026517', string(sinh(-0.9))) + call assert_equal('inf', string(sinh(1.0/0.0))) + call assert_equal('-inf', string(sinh(-1.0/0.0))) + call assert_equal('nan', string(sinh(0.0/0.0))) + call assert_fails('call sinh("")', 'E808:') +endfunc + +func Test_cos() + call assert_equal('1.0', string(cos(0.0))) + call assert_equal('0.540302', string(cos(1.0))) + call assert_equal('0.877583', string(cos(-0.5))) + call assert_equal('nan', string(cos(0.0/0.0))) + call assert_equal('nan', string(cos(1.0/0.0))) + call assert_fails('call cos("")', 'E808:') +endfunc + +func Test_acos() + call assert_equal('1.570796', string(acos(0.0))) + call assert_equal('0.0', string(acos(1.0))) + call assert_equal('3.141593', string(acos(-1.0))) + call assert_equal('2.094395', string(acos(-0.5))) + call assert_equal('nan', string(acos(1.1))) + call assert_equal('nan', string(acos(1.0/0.0))) + call assert_equal('nan', string(acos(0.0/0.0))) + call assert_fails('call acos("")', 'E808:') +endfunc + +func Test_cosh() + call assert_equal('1.0', string(cosh(0.0))) + call assert_equal('1.127626', string(cosh(0.5))) + call assert_equal('inf', string(cosh(1.0/0.0))) + call assert_equal('inf', string(cosh(-1.0/0.0))) + call assert_equal('nan', string(cosh(0.0/0.0))) + call assert_fails('call cosh("")', 'E808:') +endfunc + +func Test_tan() + call assert_equal('0.0', string(tan(0.0))) + call assert_equal('0.546302', string(tan(0.5))) + call assert_equal('-0.546302', string(tan(-0.5))) + call assert_equal('nan', string(tan(1.0/0.0))) + call assert_equal('nan', string(cos(0.0/0.0))) + call assert_equal('0.0', string(tan(1.0/(1.0/0.0)))) + call assert_equal('-0.0', string(tan(-1.0/(1.0/0.0)))) + call assert_fails('call tan("")', 'E808:') +endfunc + +func Test_atan() + call assert_equal('0.0', string(atan(0.0))) + call assert_equal('0.463648', string(atan(0.5))) + call assert_equal('-0.785398', string(atan(-1.0))) + call assert_equal('1.570796', string(atan(1.0/0.0))) + call assert_equal('-1.570796', string(atan(-1.0/0.0))) + call assert_equal('nan', string(atan(0.0/0.0))) + call assert_fails('call atan("")', 'E808:') +endfunc + +func Test_atan2() + call assert_equal('-2.356194', string(atan2(-1, -1))) + call assert_equal('2.356194', string(atan2(1, -1))) + call assert_equal('0.0', string(atan2(1.0, 1.0/0.0))) + call assert_equal('1.570796', string(atan2(1.0/0.0, 1.0))) + call assert_equal('nan', string(atan2(0.0/0.0, 1.0))) + call assert_fails('call atan2("", -1)', 'E808:') + call assert_fails('call atan2(-1, "")', 'E808:') +endfunc + +func Test_tanh() + call assert_equal('0.0', string(tanh(0.0))) + call assert_equal('0.462117', string(tanh(0.5))) + call assert_equal('-0.761594', string(tanh(-1.0))) + call assert_equal('1.0', string(tanh(1.0/0.0))) + call assert_equal('-1.0', string(tanh(-1.0/0.0))) + call assert_equal('nan', string(tanh(0.0/0.0))) + call assert_fails('call tanh("")', 'E808:') +endfunc + +func Test_fmod() + call assert_equal('0.13', string(fmod(12.33, 1.22))) + call assert_equal('-0.13', string(fmod(-12.33, 1.22))) + call assert_equal('nan', string(fmod(1.0/0.0, 1.0))) + " On Windows we get "nan" instead of 1.0, accept both. + let res = string(fmod(1.0, 1.0/0.0)) + if res != 'nan' + call assert_equal('1.0', res) + endif + call assert_equal('nan', string(fmod(1.0, 0.0))) + call assert_fails("call fmod('', 1.22)", 'E808:') + call assert_fails("call fmod(12.33, '')", 'E808:') +endfunc + +func Test_pow() + call assert_equal('1.0', string(pow(0.0, 0.0))) + call assert_equal('8.0', string(pow(2.0, 3.0))) + call assert_equal('nan', string(pow(2.0, 0.0/0.0))) + call assert_equal('nan', string(pow(0.0/0.0, 3.0))) + call assert_equal('nan', string(pow(0.0/0.0, 3.0))) + call assert_equal('inf', string(pow(2.0, 1.0/0.0))) + call assert_equal('inf', string(pow(1.0/0.0, 3.0))) + call assert_fails("call pow('', 2.0)", 'E808:') + call assert_fails("call pow(2.0, '')", 'E808:') +endfunc + +func Test_str2float() + call assert_equal('1.0', string(str2float('1'))) + call assert_equal('1.0', string(str2float(' 1 '))) + call assert_equal('1.0', string(str2float(' 1.0 '))) + call assert_equal('1.23', string(str2float('1.23'))) + call assert_equal('1.23', string(str2float('1.23abc'))) + call assert_equal('1.0e40', string(str2float('1e40'))) + call assert_equal('-1.23', string(str2float('-1.23'))) + call assert_equal('1.23', string(str2float(' + 1.23 '))) + + call assert_equal('1.0', string(str2float('+1'))) + call assert_equal('1.0', string(str2float('+1'))) + call assert_equal('1.0', string(str2float(' +1 '))) + call assert_equal('1.0', string(str2float(' + 1 '))) + + call assert_equal('-1.0', string(str2float('-1'))) + call assert_equal('-1.0', string(str2float('-1'))) + call assert_equal('-1.0', string(str2float(' -1 '))) + call assert_equal('-1.0', string(str2float(' - 1 '))) + + call assert_equal('0.0', string(str2float('+0.0'))) + call assert_equal('-0.0', string(str2float('-0.0'))) + call assert_equal('inf', string(str2float('1e1000'))) + call assert_equal('inf', string(str2float('inf'))) + call assert_equal('-inf', string(str2float('-inf'))) + call assert_equal('inf', string(str2float('+inf'))) + call assert_equal('inf', string(str2float('Inf'))) + call assert_equal('inf', string(str2float(' +inf '))) + call assert_equal('nan', string(str2float('nan'))) + call assert_equal('nan', string(str2float('NaN'))) + call assert_equal('nan', string(str2float(' nan '))) + + call assert_fails("call str2float(1.2)", 'E806:') + call assert_fails("call str2float([])", 'E730:') + call assert_fails("call str2float({})", 'E731:') + call assert_fails("call str2float(function('string'))", 'E729:') +endfunc + +func Test_float2nr() + call assert_equal(1, float2nr(1.234)) + call assert_equal(123, float2nr(1.234e2)) + call assert_equal(12, float2nr(123.4e-1)) + let max_number = 1/0 + let min_number = -max_number + call assert_equal(max_number/2+1, float2nr(pow(2, 62))) + call assert_equal(max_number, float2nr(pow(2, 63))) + call assert_equal(max_number, float2nr(pow(2, 64))) + call assert_equal(min_number/2-1, float2nr(-pow(2, 62))) + call assert_equal(min_number, float2nr(-pow(2, 63))) + call assert_equal(min_number, float2nr(-pow(2, 64))) +endfunc + +func Test_floor() + call assert_equal('2.0', string(floor(2.0))) + call assert_equal('2.0', string(floor(2.11))) + call assert_equal('2.0', string(floor(2.99))) + call assert_equal('-3.0', string(floor(-2.11))) + call assert_equal('-3.0', string(floor(-2.99))) + call assert_equal('nan', string(floor(0.0/0.0))) + call assert_equal('inf', string(floor(1.0/0.0))) + call assert_equal('-inf', string(floor(-1.0/0.0))) + call assert_fails("call floor('')", 'E808:') +endfunc + +func Test_ceil() + call assert_equal('2.0', string(ceil(2.0))) + call assert_equal('3.0', string(ceil(2.11))) + call assert_equal('3.0', string(ceil(2.99))) + call assert_equal('-2.0', string(ceil(-2.11))) + call assert_equal('-2.0', string(ceil(-2.99))) + call assert_equal('nan', string(ceil(0.0/0.0))) + call assert_equal('inf', string(ceil(1.0/0.0))) + call assert_equal('-inf', string(ceil(-1.0/0.0))) + call assert_fails("call ceil('')", 'E808:') +endfunc + +func Test_round() + call assert_equal('2.0', string(round(2.1))) + call assert_equal('3.0', string(round(2.5))) + call assert_equal('3.0', string(round(2.9))) + call assert_equal('-2.0', string(round(-2.1))) + call assert_equal('-3.0', string(round(-2.5))) + call assert_equal('-3.0', string(round(-2.9))) + call assert_equal('nan', string(round(0.0/0.0))) + call assert_equal('inf', string(round(1.0/0.0))) + call assert_equal('-inf', string(round(-1.0/0.0))) + call assert_fails("call round('')", 'E808:') +endfunc + +func Test_trunc() + call assert_equal('2.0', string(trunc(2.1))) + call assert_equal('2.0', string(trunc(2.5))) + call assert_equal('2.0', string(trunc(2.9))) + call assert_equal('-2.0', string(trunc(-2.1))) + call assert_equal('-2.0', string(trunc(-2.5))) + call assert_equal('-2.0', string(trunc(-2.9))) + call assert_equal('nan', string(trunc(0.0/0.0))) + call assert_equal('inf', string(trunc(1.0/0.0))) + call assert_equal('-inf', string(trunc(-1.0/0.0))) + call assert_fails("call trunc('')", 'E808:') +endfunc + +func Test_isnan() + call assert_equal(0, isnan(1.0)) + call assert_equal(1, isnan(0.0/0.0)) + call assert_equal(0, isnan(1.0/0.0)) + call assert_equal(0, isnan('a')) + call assert_equal(0, isnan([])) + call assert_equal(0, isnan({})) +endfunc + +" This was converted from test65 +func Test_float_misc() + call assert_equal('123.456000', printf('%f', 123.456)) + call assert_equal('1.234560e+02', printf('%e', 123.456)) + call assert_equal('123.456', printf('%g', 123.456)) + " += + let v = 1.234 + let v += 6.543 + call assert_equal('7.777', printf('%g', v)) + let v = 1.234 + let v += 5 + call assert_equal('6.234', printf('%g', v)) + let v = 5 + let v += 3.333 + call assert_equal('8.333', string(v)) + " == + let v = 1.234 + call assert_true(v == 1.234) + call assert_false(v == 1.2341) + " add-subtract + call assert_equal('5.234', printf('%g', 4 + 1.234)) + call assert_equal('-6.766', printf('%g', 1.234 - 8)) + " mult-div + call assert_equal('4.936', printf('%g', 4 * 1.234)) + call assert_equal('0.003241', printf('%g', 4.0 / 1234)) + " dict + call assert_equal("{'x': 1.234, 'y': -2.0e20}", string({'x': 1.234, 'y': -2.0e20})) + " list + call assert_equal('[-123.4, 2.0e-20]', string([-123.4, 2.0e-20])) +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_fnameescape.vim b/src/testdir/test_fnameescape.vim new file mode 100644 index 0000000..5382b89 --- /dev/null +++ b/src/testdir/test_fnameescape.vim @@ -0,0 +1,21 @@ + +" Test if fnameescape is correct for special chars like ! +func Test_fnameescape() + let fname = 'Xspa ce' + let status = v:false + try + exe "w! " . fnameescape(fname) + let status = v:true + endtry + call assert_true(status, "Space") + call delete(fname) + + let fname = 'Xemark!' + let status = v:false + try + exe "w! " . fnameescape(fname) + let status = v:true + endtry + call assert_true(status, "ExclamationMark") + call delete(fname) +endfunc diff --git a/src/testdir/test_fnamemodify.vim b/src/testdir/test_fnamemodify.vim new file mode 100644 index 0000000..768d311 --- /dev/null +++ b/src/testdir/test_fnamemodify.vim @@ -0,0 +1,53 @@ +" Test filename modifiers. + +func Test_fnamemodify() + let save_home = $HOME + let save_shell = &shell + let $HOME = fnamemodify('.', ':p:h:h') + set shell=sh + + call assert_equal('/', fnamemodify('.', ':p')[-1:]) + call assert_equal('r', fnamemodify('.', ':p:h')[-1:]) + call assert_equal('t', fnamemodify('test.out', ':p')[-1:]) + call assert_equal('test.out', fnamemodify('test.out', ':.')) + call assert_equal('a', fnamemodify('../testdir/a', ':.')) + call assert_equal('~/testdir/test.out', fnamemodify('test.out', ':~')) + call assert_equal('~/testdir/a', fnamemodify('../testdir/a', ':~')) + call assert_equal('a', fnamemodify('../testdir/a', ':t')) + call assert_equal('', fnamemodify('.', ':p:t')) + call assert_equal('test.out', fnamemodify('test.out', ':p:t')) + call assert_equal('out', fnamemodify('test.out', ':p:e')) + call assert_equal('out', fnamemodify('test.out', ':p:t:e')) + call assert_equal('abc.fb2.tar', fnamemodify('abc.fb2.tar.gz', ':r')) + call assert_equal('abc.fb2', fnamemodify('abc.fb2.tar.gz', ':r:r')) + call assert_equal('abc', fnamemodify('abc.fb2.tar.gz', ':r:r:r')) + call assert_equal('testdir/abc.fb2', substitute(fnamemodify('abc.fb2.tar.gz', ':p:r:r'), '.*\(testdir/.*\)', '\1', '')) + call assert_equal('gz', fnamemodify('abc.fb2.tar.gz', ':e')) + call assert_equal('tar.gz', fnamemodify('abc.fb2.tar.gz', ':e:e')) + call assert_equal('fb2.tar.gz', fnamemodify('abc.fb2.tar.gz', ':e:e:e')) + call assert_equal('fb2.tar.gz', fnamemodify('abc.fb2.tar.gz', ':e:e:e:e')) + call assert_equal('tar', fnamemodify('abc.fb2.tar.gz', ':e:e:r')) + + call assert_equal('''abc def''', fnamemodify('abc def', ':S')) + call assert_equal('''abc" "def''', fnamemodify('abc" "def', ':S')) + call assert_equal('''abc"%"def''', fnamemodify('abc"%"def', ':S')) + call assert_equal('''abc''\'''' ''\''''def''', fnamemodify('abc'' ''def', ':S')) + call assert_equal('''abc''\''''%''\''''def''', fnamemodify('abc''%''def', ':S')) + sp test_alot.vim + call assert_equal(expand('%:r:S'), shellescape(expand('%:r'))) + call assert_equal('test_alot,''test_alot'',test_alot.vim', join([expand('%:r'), expand('%:r:S'), expand('%')], ',')) + quit + + call assert_equal("'abc\ndef'", fnamemodify("abc\ndef", ':S')) + set shell=tcsh + call assert_equal("'abc\\\ndef'", fnamemodify("abc\ndef", ':S')) + + let $HOME = save_home + let &shell = save_shell +endfunc + +func Test_expand() + new + call assert_equal("", expand('%:S')) + quit +endfunc diff --git a/src/testdir/test_fold.vim b/src/testdir/test_fold.vim new file mode 100644 index 0000000..67e5a48 --- /dev/null +++ b/src/testdir/test_fold.vim @@ -0,0 +1,743 @@ +" Test for folding + +source view_util.vim +source screendump.vim + +func PrepIndent(arg) + return [a:arg] + repeat(["\t".a:arg], 5) +endfu + +func Test_address_fold() + new + call setline(1, ['int FuncName() {/*{{{*/', 1, 2, 3, 4, 5, '}/*}}}*/', + \ 'after fold 1', 'after fold 2', 'after fold 3']) + setl fen fdm=marker + " The next commands should all copy the same part of the buffer, + " regardless of the addressing type, since the part to be copied + " is folded away + :1y + call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1)) + :.y + call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1)) + :.+y + call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1)) + :.,.y + call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1)) + :sil .1,.y + call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1)) + " use silent to make E493 go away + :sil .+,.y + call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1)) + :,y + call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1)) + :,+y + call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/','after fold 1'], getreg(0,1,1)) + " using .+3 as second address should copy the whole folded line + the next 3 + " lines + :.,+3y + call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/', + \ 'after fold 1', 'after fold 2', 'after fold 3'], getreg(0,1,1)) + :sil .,-2y + call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3', '4', '5', '}/*}}}*/'], getreg(0,1,1)) + + " now test again with folding disabled + set nofoldenable + :1y + call assert_equal(['int FuncName() {/*{{{*/'], getreg(0,1,1)) + :.y + call assert_equal(['int FuncName() {/*{{{*/'], getreg(0,1,1)) + :.+y + call assert_equal(['1'], getreg(0,1,1)) + :.,.y + call assert_equal(['int FuncName() {/*{{{*/'], getreg(0,1,1)) + " use silent to make E493 go away + :sil .1,.y + call assert_equal(['int FuncName() {/*{{{*/', '1'], getreg(0,1,1)) + " use silent to make E493 go away + :sil .+,.y + call assert_equal(['int FuncName() {/*{{{*/', '1'], getreg(0,1,1)) + :,y + call assert_equal(['int FuncName() {/*{{{*/'], getreg(0,1,1)) + :,+y + call assert_equal(['int FuncName() {/*{{{*/', '1'], getreg(0,1,1)) + " using .+3 as second address should copy the whole folded line + the next 3 + " lines + :.,+3y + call assert_equal(['int FuncName() {/*{{{*/', '1', '2', '3'], getreg(0,1,1)) + :7 + :sil .,-2y + call assert_equal(['4', '5', '}/*}}}*/'], getreg(0,1,1)) + + quit! +endfunc + +func Test_indent_fold() + new + call setline(1, ['', 'a', ' b', ' c']) + setl fen fdm=indent + 2 + norm! >> + let a=map(range(1,4), 'foldclosed(v:val)') + call assert_equal([-1,-1,-1,-1], a) + bw! +endfunc + +func Test_indent_fold2() + new + call setline(1, ['', '{{{', '}}}', '{{{', '}}}']) + setl fen fdm=marker + 2 + norm! >> + let a=map(range(1,5), 'foldclosed(v:val)') + call assert_equal([-1,-1,-1,4,4], a) + bw! +endfunc + +func Test_manual_fold_with_filter() + if !executable('cat') + return + endif + for type in ['manual', 'marker'] + exe 'set foldmethod=' . type + new + call setline(1, range(1, 20)) + 4,$fold + %foldopen + 10,$fold + %foldopen + " This filter command should not have an effect + 1,8! cat + call feedkeys('5ggzdzMGdd', 'xt') + call assert_equal(['1', '2', '3', '4', '5', '6', '7', '8', '9'], getline(1, '$')) + + bwipe! + set foldmethod& + endfor +endfunc + +func Test_indent_fold_with_read() + new + set foldmethod=indent + call setline(1, repeat(["\<Tab>a"], 4)) + for n in range(1, 4) + call assert_equal(1, foldlevel(n)) + endfor + + call writefile(["a", "", "\<Tab>a"], 'Xfile') + foldopen + 2read Xfile + %foldclose + call assert_equal(1, foldlevel(1)) + call assert_equal(2, foldclosedend(1)) + call assert_equal(0, foldlevel(3)) + call assert_equal(0, foldlevel(4)) + call assert_equal(1, foldlevel(5)) + call assert_equal(7, foldclosedend(5)) + + bwipe! + set foldmethod& + call delete('Xfile') +endfunc + +func Test_combining_folds_indent() + new + let one = "\<Tab>a" + let zero = 'a' + call setline(1, [one, one, zero, zero, zero, one, one, one]) + set foldmethod=indent + 3,5d + %foldclose + call assert_equal(5, foldclosedend(1)) + + set foldmethod& + bwipe! +endfunc + +func Test_combining_folds_marker() + new + call setline(1, ['{{{', '}}}', '', '', '', '{{{', '', '}}}']) + set foldmethod=marker + 3,5d + %foldclose + call assert_equal(2, foldclosedend(1)) + + set foldmethod& + bwipe! +endfunc + +func Test_folds_marker_in_comment() + new + call setline(1, ['" foo', 'bar', 'baz']) + setl fen fdm=marker + setl com=sO:\"\ -,mO:\"\ \ ,eO:\"\",:\" cms=\"%s + norm! zf2j + setl nofen + :1y + call assert_equal(['" foo{{{'], getreg(0,1,1)) + :+2y + call assert_equal(['baz"}}}'], getreg(0,1,1)) + + set foldmethod& + bwipe! +endfunc + +func s:TestFoldExpr(lnum) + let thisline = getline(a:lnum) + if thisline == 'a' + return 1 + elseif thisline == 'b' + return 0 + elseif thisline == 'c' + return '<1' + elseif thisline == 'd' + return '>1' + endif + return 0 +endfunction + +func Test_update_folds_expr_read() + new + call setline(1, ['a', 'a', 'a', 'a', 'a', 'a']) + set foldmethod=expr + set foldexpr=s:TestFoldExpr(v:lnum) + 2 + foldopen + call writefile(['b', 'b', 'a', 'a', 'd', 'a', 'a', 'c'], 'Xfile') + read Xfile + %foldclose + call assert_equal(2, foldclosedend(1)) + call assert_equal(0, foldlevel(3)) + call assert_equal(0, foldlevel(4)) + call assert_equal(6, foldclosedend(5)) + call assert_equal(10, foldclosedend(7)) + call assert_equal(14, foldclosedend(11)) + + call delete('Xfile') + bwipe! + set foldmethod& foldexpr& +endfunc + +func Check_foldlevels(expected) + call assert_equal(a:expected, map(range(1, line('$')), 'foldlevel(v:val)')) +endfunc + +func Test_move_folds_around_manual() + new + let input = PrepIndent("a") + PrepIndent("b") + PrepIndent("c") + call setline(1, PrepIndent("a") + PrepIndent("b") + PrepIndent("c")) + let folds=[-1, 2, 2, 2, 2, 2, -1, 8, 8, 8, 8, 8, -1, 14, 14, 14, 14, 14] + " all folds closed + set foldenable foldlevel=0 fdm=indent + " needs a forced redraw + redraw! + set fdm=manual + call assert_equal(folds, map(range(1, line('$')), 'foldclosed(v:val)')) + call assert_equal(input, getline(1, '$')) + 7,12m0 + call assert_equal(PrepIndent("b") + PrepIndent("a") + PrepIndent("c"), getline(1, '$')) + call assert_equal(folds, map(range(1, line('$')), 'foldclosed(v:val)')) + 10,12m0 + call assert_equal(PrepIndent("a")[1:] + PrepIndent("b") + ["a"] + PrepIndent("c"), getline(1, '$')) + call assert_equal([1, 1, 1, 1, 1, -1, 7, 7, 7, 7, 7, -1, -1, 14, 14, 14, 14, 14], map(range(1, line('$')), 'foldclosed(v:val)')) + " moving should not close the folds + %d + call setline(1, PrepIndent("a") + PrepIndent("b") + PrepIndent("c")) + set fdm=indent + redraw! + set fdm=manual + call cursor(2, 1) + %foldopen + 7,12m0 + let folds=repeat([-1], 18) + call assert_equal(PrepIndent("b") + PrepIndent("a") + PrepIndent("c"), getline(1, '$')) + call assert_equal(folds, map(range(1, line('$')), 'foldclosed(v:val)')) + norm! zM + " folds are not corrupted and all have been closed + call assert_equal([-1, 2, 2, 2, 2, 2, -1, 8, 8, 8, 8, 8, -1, 14, 14, 14, 14, 14], map(range(1, line('$')), 'foldclosed(v:val)')) + %d + call setline(1, ["a", "\tb", "\tc", "\td", "\te"]) + set fdm=indent + redraw! + set fdm=manual + %foldopen + 3m4 + %foldclose + call assert_equal(["a", "\tb", "\td", "\tc", "\te"], getline(1, '$')) + call assert_equal([-1, 5, 5, 5, 5], map(range(1, line('$')), 'foldclosedend(v:val)')) + %d + call setline(1, ["a", "\tb", "\tc", "\td", "\te", "z", "\ty", "\tx", "\tw", "\tv"]) + set fdm=indent foldlevel=0 + set fdm=manual + %foldopen + 3m1 + %foldclose + call assert_equal(["a", "\tc", "\tb", "\td", "\te", "z", "\ty", "\tx", "\tw", "\tv"], getline(1, '$')) + call assert_equal(0, foldlevel(2)) + call assert_equal(5, foldclosedend(3)) + call assert_equal([-1, -1, 3, 3, 3, -1, 7, 7, 7, 7], map(range(1, line('$')), 'foldclosed(v:val)')) + 2,6m$ + %foldclose + call assert_equal(5, foldclosedend(2)) + call assert_equal(0, foldlevel(6)) + call assert_equal(9, foldclosedend(7)) + call assert_equal([-1, 2, 2, 2, 2, -1, 7, 7, 7, -1], map(range(1, line('$')), 'foldclosed(v:val)')) + + %d + " Ensure moving around the edges still works. + call setline(1, PrepIndent("a") + repeat(["a"], 3) + ["\ta"]) + set fdm=indent foldlevel=0 + set fdm=manual + %foldopen + 6m$ + " The first fold has been truncated to the 5'th line. + " Second fold has been moved up because the moved line is now below it. + call Check_foldlevels([0, 1, 1, 1, 1, 0, 0, 0, 1, 0]) + + %delete + set fdm=indent foldlevel=0 + call setline(1, [ + \ "a", + \ "\ta", + \ "\t\ta", + \ "\t\ta", + \ "\t\ta", + \ "a", + \ "a"]) + set fdm=manual + %foldopen! + 4,5m6 + call Check_foldlevels([0, 1, 2, 0, 0, 0, 0]) + + %delete + set fdm=indent + call setline(1, [ + \ "\ta", + \ "\t\ta", + \ "\t\ta", + \ "\t\ta", + \ "\ta", + \ "\t\ta", + \ "\t\ta", + \ "\t\ta", + \ "\ta", + \ "\t\ta", + \ "\t\ta", + \ "\t\ta", + \ "\t\ta", + \ "\ta", + \ "a"]) + set fdm=manual + %foldopen! + 13m7 + call Check_foldlevels([1, 2, 2, 2, 1, 2, 2, 1, 1, 1, 2, 2, 2, 1, 0]) + + bw! +endfunc + +func Test_move_folds_around_indent() + new + let input = PrepIndent("a") + PrepIndent("b") + PrepIndent("c") + call setline(1, PrepIndent("a") + PrepIndent("b") + PrepIndent("c")) + let folds=[-1, 2, 2, 2, 2, 2, -1, 8, 8, 8, 8, 8, -1, 14, 14, 14, 14, 14] + " all folds closed + set fdm=indent + call assert_equal(folds, map(range(1, line('$')), 'foldclosed(v:val)')) + call assert_equal(input, getline(1, '$')) + 7,12m0 + call assert_equal(PrepIndent("b") + PrepIndent("a") + PrepIndent("c"), getline(1, '$')) + call assert_equal(folds, map(range(1, line('$')), 'foldclosed(v:val)')) + 10,12m0 + call assert_equal(PrepIndent("a")[1:] + PrepIndent("b") + ["a"] + PrepIndent("c"), getline(1, '$')) + call assert_equal([1, 1, 1, 1, 1, -1, 7, 7, 7, 7, 7, -1, -1, 14, 14, 14, 14, 14], map(range(1, line('$')), 'foldclosed(v:val)')) + " moving should not close the folds + %d + call setline(1, PrepIndent("a") + PrepIndent("b") + PrepIndent("c")) + set fdm=indent + call cursor(2, 1) + %foldopen + 7,12m0 + let folds=repeat([-1], 18) + call assert_equal(PrepIndent("b") + PrepIndent("a") + PrepIndent("c"), getline(1, '$')) + call assert_equal(folds, map(range(1, line('$')), 'foldclosed(v:val)')) + norm! zM + " folds are not corrupted and all have been closed + call assert_equal([-1, 2, 2, 2, 2, 2, -1, 8, 8, 8, 8, 8, -1, 14, 14, 14, 14, 14], map(range(1, line('$')), 'foldclosed(v:val)')) + %d + call setline(1, ["a", "\tb", "\tc", "\td", "\te"]) + set fdm=indent + %foldopen + 3m4 + %foldclose + call assert_equal(["a", "\tb", "\td", "\tc", "\te"], getline(1, '$')) + call assert_equal([-1, 5, 5, 5, 5], map(range(1, line('$')), 'foldclosedend(v:val)')) + %d + call setline(1, ["a", "\tb", "\tc", "\td", "\te", "z", "\ty", "\tx", "\tw", "\tv"]) + set fdm=indent foldlevel=0 + %foldopen + 3m1 + %foldclose + call assert_equal(["a", "\tc", "\tb", "\td", "\te", "z", "\ty", "\tx", "\tw", "\tv"], getline(1, '$')) + call assert_equal(1, foldlevel(2)) + call assert_equal(5, foldclosedend(3)) + call assert_equal([-1, 2, 2, 2, 2, -1, 7, 7, 7, 7], map(range(1, line('$')), 'foldclosed(v:val)')) + 2,6m$ + %foldclose + call assert_equal(9, foldclosedend(2)) + call assert_equal(1, foldlevel(6)) + call assert_equal(9, foldclosedend(7)) + call assert_equal([-1, 2, 2, 2, 2, 2, 2, 2, 2, -1], map(range(1, line('$')), 'foldclosed(v:val)')) + " Ensure moving around the edges still works. + %d + call setline(1, PrepIndent("a") + repeat(["a"], 3) + ["\ta"]) + set fdm=indent foldlevel=0 + %foldopen + 6m$ + " The first fold has been truncated to the 5'th line. + " Second fold has been moved up because the moved line is now below it. + call Check_foldlevels([0, 1, 1, 1, 1, 0, 0, 0, 1, 1]) + bw! +endfunc + +func Test_folddoopen_folddoclosed() + new + call setline(1, range(1, 9)) + set foldmethod=manual + 1,3 fold + 6,8 fold + + " Test without range. + folddoopen s/$/o/ + folddoclosed s/$/c/ + call assert_equal(['1c', '2c', '3c', + \ '4o', '5o', + \ '6c', '7c', '8c', + \ '9o'], getline(1, '$')) + + " Test with range. + call setline(1, range(1, 9)) + 1,8 folddoopen s/$/o/ + 4,$ folddoclosed s/$/c/ + call assert_equal(['1', '2', '3', + \ '4o', '5o', + \ '6c', '7c', '8c', + \ '9'], getline(1, '$')) + + set foldmethod& + bw! +endfunc + +func Test_fold_error() + new + call setline(1, [1, 2]) + + for fm in ['indent', 'expr', 'syntax', 'diff'] + exe 'set foldmethod=' . fm + call assert_fails('norm zf', 'E350:') + call assert_fails('norm zd', 'E351:') + call assert_fails('norm zE', 'E352:') + endfor + + set foldmethod=manual + call assert_fails('norm zd', 'E490:') + call assert_fails('norm zo', 'E490:') + call assert_fails('3fold', 'E16:') + + set foldmethod=marker + set nomodifiable + call assert_fails('1,2fold', 'E21:') + + set modifiable& + set foldmethod& + bw! +endfunc + +func Test_foldtext_recursive() + new + call setline(1, ['{{{', 'some text', '}}}']) + setlocal foldenable foldmethod=marker foldtext=foldtextresult(v\:foldstart) + " This was crashing because of endless recursion. + 2foldclose + redraw + call assert_equal(1, foldlevel(2)) + call assert_equal(1, foldclosed(2)) + call assert_equal(3, foldclosedend(2)) + bwipe! +endfunc + +" Various fold related tests + +" Basic test if a fold can be created, opened, moving to the end and closed +func Test_fold_manual() + enew! + set fdm=manual + + let content = ['1 aa', '2 bb', '3 cc'] + call append(0, content) + call cursor(1, 1) + normal zf2j + call assert_equal('1 aa', getline(foldclosed('.'))) + normal zo + call assert_equal(-1, foldclosed('.')) + normal ]z + call assert_equal('3 cc', getline('.')) + normal zc + call assert_equal('1 aa', getline(foldclosed('.'))) + + set fdm& + enew! +endfunc + +" test folding with markers. +func Test_fold_marker() + enew! + set fdm=marker fdl=1 fdc=3 + + let content = ['4 dd {{{', '5 ee {{{ }}}', '6 ff }}}'] + call append(0, content) + call cursor(2, 1) + call assert_equal(2, foldlevel('.')) + normal [z + call assert_equal(1, foldlevel('.')) + exe "normal jo{{ \<Esc>r{jj" + call assert_equal(1, foldlevel('.')) + normal kYpj + call assert_equal(0, foldlevel('.')) + + set fdm& fdl& fdc& + enew! +endfunc + +" test create fold markers with C filetype +func Test_fold_create_marker_in_C() + enew! + set fdm=marker fdl=9 + set filetype=c + + let content = [ + \ '/*', + \ ' * comment', + \ ' * ', + \ ' *', + \ ' */', + \ 'int f(int* p) {', + \ ' *p = 3;', + \ ' return 0;', + \ '}' + \] + for c in range(len(content) - 1) + bw! + call append(0, content) + call cursor(c + 1, 1) + norm! zfG + call assert_equal(content[c] . (c < 4 ? '{{{' : '/*{{{*/'), getline(c + 1)) + endfor + + set fdm& fdl& + enew! +endfunc + +" test folding with indent +func Test_fold_indent() + enew! + set fdm=indent sw=2 + + let content = ['1 aa', '2 bb', '3 cc'] + call append(0, content) + call cursor(2, 1) + exe "normal i \<Esc>jI " + call assert_equal(2, foldlevel('.')) + normal k + call assert_equal(1, foldlevel('.')) + + set fdm& sw& + enew! +endfunc + +" test syntax folding +func Test_fold_syntax() + if !has('syntax') + return + endif + + enew! + set fdm=syntax fdl=0 + + syn region Hup start="dd" end="ii" fold contains=Fd1,Fd2,Fd3 + syn region Fd1 start="ee" end="ff" fold contained + syn region Fd2 start="gg" end="hh" fold contained + syn region Fd3 start="commentstart" end="commentend" fold contained + let content = ['3 cc', '4 dd {{{', '5 ee {{{ }}}', '{{{{', '6 ff }}}', + \ '6 ff }}}', '7 gg', '8 hh', '9 ii'] + call append(0, content) + normal Gzk + call assert_equal('9 ii', getline('.')) + normal k + call assert_equal('3 cc', getline('.')) + exe "normal jAcommentstart \<Esc>Acommentend" + set fdl=1 + normal 3j + call assert_equal('7 gg', getline('.')) + set fdl=0 + exe "normal zO\<C-L>j" + call assert_equal('8 hh', getline('.')) + syn clear Fd1 Fd2 Fd3 Hup + + set fdm& fdl& + enew! +endfunc + +func Flvl() + let l = getline(v:lnum) + if l =~ "bb$" + return 2 + elseif l =~ "gg$" + return "s1" + elseif l =~ "ii$" + return ">2" + elseif l =~ "kk$" + return "0" + endif + return "=" +endfun + +" test expression folding +func Test_fold_expr() + enew! + set fdm=expr fde=Flvl() + + let content = ['1 aa', + \ '2 bb', + \ '3 cc', + \ '4 dd {{{commentstart commentend', + \ '5 ee {{{ }}}', + \ '{{{', + \ '6 ff }}}', + \ '6 ff }}}', + \ ' 7 gg', + \ ' 8 hh', + \ '9 ii', + \ 'a jj', + \ 'b kk'] + call append(0, content) + call cursor(1, 1) + exe "normal /bb$\<CR>" + call assert_equal(2, foldlevel('.')) + exe "normal /hh$\<CR>" + call assert_equal(1, foldlevel('.')) + exe "normal /ii$\<CR>" + call assert_equal(2, foldlevel('.')) + exe "normal /kk$\<CR>" + call assert_equal(0, foldlevel('.')) + + set fdm& fde& + enew! +endfunc + +" Bug with fdm=indent and moving folds +" Moving a fold a few times, messes up the folds below the moved fold. +" Fixed by 7.4.700 +func Test_fold_move() + enew! + set fdm=indent sw=2 fdl=0 + + let content = ['', '', 'Line1', ' Line2', ' Line3', + \ 'Line4', ' Line5', ' Line6', + \ 'Line7', ' Line8', ' Line9'] + call append(0, content) + normal zM + call cursor(4, 1) + move 2 + move 1 + call assert_equal(7, foldclosed(7)) + call assert_equal(8, foldclosedend(7)) + call assert_equal(0, foldlevel(9)) + call assert_equal(10, foldclosed(10)) + call assert_equal(11, foldclosedend(10)) + call assert_equal('+-- 2 lines: Line2', foldtextresult(2)) + call assert_equal('+-- 2 lines: Line8', foldtextresult(10)) + + set fdm& sw& fdl& + enew! +endfunc + +" test for patch 7.3.637 +" Cannot catch the error caused by a foldopen when there is no fold. +func Test_foldopen_exception() + enew! + let a = 'No error caught' + try + foldopen + catch + let a = matchstr(v:exception,'^[^ ]*') + endtry + call assert_equal('Vim(foldopen):E490:', a) + + let a = 'No error caught' + try + foobar + catch + let a = matchstr(v:exception,'^[^ ]*') + endtry + call assert_match('E492:', a) +endfunc + +func Test_fold_last_line_with_pagedown() + enew! + set fdm=manual + + let expect = '+-- 11 lines: 9---' + let content = range(1,19) + call append(0, content) + normal dd9G + normal zfG + normal zt + call assert_equal('9', getline(foldclosed('.'))) + call assert_equal('19', getline(foldclosedend('.'))) + call assert_equal(expect, ScreenLines(1, len(expect))[0]) + call feedkeys("\<C-F>", 'xt') + call assert_equal(expect, ScreenLines(1, len(expect))[0]) + call feedkeys("\<C-F>", 'xt') + call assert_equal(expect, ScreenLines(1, len(expect))[0]) + call feedkeys("\<C-B>\<C-F>\<C-F>", 'xt') + call assert_equal(expect, ScreenLines(1, len(expect))[0]) + + set fdm& + enew! +endfunc + +func Test_folds_with_rnu() + if !CanRunVimInTerminal() + return + endif + + call writefile([ + \ 'set fdm=marker rnu foldcolumn=2', + \ 'call setline(1, ["{{{1", "nline 1", "{{{1", "line 2"])', + \ ], 'Xtest_folds_with_rnu') + let buf = RunVimInTerminal('-S Xtest_folds_with_rnu', {}) + + call VerifyScreenDump(buf, 'Test_folds_with_rnu_01', {}) + call term_sendkeys(buf, "j") + call VerifyScreenDump(buf, 'Test_folds_with_rnu_02', {}) + + " clean up + call StopVimInTerminal(buf) + call delete('Xtest_folds_with_rnu') +endfunc + +func Test_folds_marker_in_comment2() + new + call setline(1, ['Lorem ipsum dolor sit', 'Lorem ipsum dolor sit', 'Lorem ipsum dolor sit']) + setl fen fdm=marker + setl commentstring=<!--%s--> + setl comments=s:<!--,m:\ \ \ \ ,e:--> + norm! zf2j + setl nofen + :1y + call assert_equal(['Lorem ipsum dolor sit<!--{{{-->'], getreg(0,1,1)) + :+2y + call assert_equal(['Lorem ipsum dolor sit<!--}}}-->'], getreg(0,1,1)) + + set foldmethod& + bwipe! +endfunc diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim new file mode 100644 index 0000000..b08d9aa --- /dev/null +++ b/src/testdir/test_functions.vim @@ -0,0 +1,1248 @@ +" Tests for various functions. +source shared.vim + +" Must be done first, since the alternate buffer must be unset. +func Test_00_bufexists() + call assert_equal(0, bufexists('does_not_exist')) + call assert_equal(1, bufexists(bufnr('%'))) + call assert_equal(0, bufexists(0)) + new Xfoo + let bn = bufnr('%') + call assert_equal(1, bufexists(bn)) + call assert_equal(1, bufexists('Xfoo')) + call assert_equal(1, bufexists(getcwd() . '/Xfoo')) + call assert_equal(1, bufexists(0)) + bw + call assert_equal(0, bufexists(bn)) + call assert_equal(0, bufexists('Xfoo')) +endfunc + +func Test_empty() + call assert_equal(1, empty('')) + call assert_equal(0, empty('a')) + + call assert_equal(1, empty(0)) + call assert_equal(1, empty(-0)) + call assert_equal(0, empty(1)) + call assert_equal(0, empty(-1)) + + call assert_equal(1, empty(0.0)) + call assert_equal(1, empty(-0.0)) + call assert_equal(0, empty(1.0)) + call assert_equal(0, empty(-1.0)) + call assert_equal(0, empty(1.0/0.0)) + call assert_equal(0, empty(0.0/0.0)) + + call assert_equal(1, empty([])) + call assert_equal(0, empty(['a'])) + + call assert_equal(1, empty({})) + call assert_equal(0, empty({'a':1})) + + call assert_equal(1, empty(v:null)) + call assert_equal(1, empty(v:none)) + call assert_equal(1, empty(v:false)) + call assert_equal(0, empty(v:true)) + + if has('channel') + call assert_equal(1, empty(test_null_channel())) + endif + if has('job') + call assert_equal(1, empty(test_null_job())) + endif + + call assert_equal(0, empty(function('Test_empty'))) +endfunc + +func Test_len() + call assert_equal(1, len(0)) + call assert_equal(2, len(12)) + + call assert_equal(0, len('')) + call assert_equal(2, len('ab')) + + call assert_equal(0, len([])) + call assert_equal(2, len([2, 1])) + + call assert_equal(0, len({})) + call assert_equal(2, len({'a': 1, 'b': 2})) + + call assert_fails('call len(v:none)', 'E701:') + call assert_fails('call len({-> 0})', 'E701:') +endfunc + +func Test_max() + call assert_equal(0, max([])) + call assert_equal(2, max([2])) + call assert_equal(2, max([1, 2])) + call assert_equal(2, max([1, 2, v:null])) + + call assert_equal(0, max({})) + call assert_equal(2, max({'a':1, 'b':2})) + + call assert_fails('call max(1)', 'E712:') + call assert_fails('call max(v:none)', 'E712:') +endfunc + +func Test_min() + call assert_equal(0, min([])) + call assert_equal(2, min([2])) + call assert_equal(1, min([1, 2])) + call assert_equal(0, min([1, 2, v:null])) + + call assert_equal(0, min({})) + call assert_equal(1, min({'a':1, 'b':2})) + + call assert_fails('call min(1)', 'E712:') + call assert_fails('call min(v:none)', 'E712:') +endfunc + +func Test_strwidth() + for aw in ['single', 'double'] + exe 'set ambiwidth=' . aw + call assert_equal(0, strwidth('')) + call assert_equal(1, strwidth("\t")) + call assert_equal(3, strwidth('Vim')) + call assert_equal(4, strwidth(1234)) + call assert_equal(5, strwidth(-1234)) + + call assert_equal(2, strwidth('😉')) + call assert_equal(17, strwidth('Eĥoŝanĝo ĉiuĵaŭde')) + call assert_equal((aw == 'single') ? 6 : 7, strwidth('Straße')) + + call assert_fails('call strwidth({->0})', 'E729:') + call assert_fails('call strwidth([])', 'E730:') + call assert_fails('call strwidth({})', 'E731:') + call assert_fails('call strwidth(1.2)', 'E806:') + endfor + + set ambiwidth& +endfunc + +func Test_str2nr() + call assert_equal(0, str2nr('')) + call assert_equal(1, str2nr('1')) + call assert_equal(1, str2nr(' 1 ')) + + call assert_equal(1, str2nr('+1')) + call assert_equal(1, str2nr('+ 1')) + call assert_equal(1, str2nr(' + 1 ')) + + call assert_equal(-1, str2nr('-1')) + call assert_equal(-1, str2nr('- 1')) + call assert_equal(-1, str2nr(' - 1 ')) + + call assert_equal(123456789, str2nr('123456789')) + call assert_equal(-123456789, str2nr('-123456789')) + + call assert_equal(5, str2nr('101', 2)) + call assert_equal(5, str2nr('0b101', 2)) + call assert_equal(5, str2nr('0B101', 2)) + call assert_equal(-5, str2nr('-101', 2)) + call assert_equal(-5, str2nr('-0b101', 2)) + call assert_equal(-5, str2nr('-0B101', 2)) + + call assert_equal(65, str2nr('101', 8)) + call assert_equal(65, str2nr('0101', 8)) + call assert_equal(-65, str2nr('-101', 8)) + call assert_equal(-65, str2nr('-0101', 8)) + + call assert_equal(11259375, str2nr('abcdef', 16)) + call assert_equal(11259375, str2nr('ABCDEF', 16)) + call assert_equal(-11259375, str2nr('-ABCDEF', 16)) + call assert_equal(11259375, str2nr('0xabcdef', 16)) + call assert_equal(11259375, str2nr('0Xabcdef', 16)) + call assert_equal(11259375, str2nr('0XABCDEF', 16)) + call assert_equal(-11259375, str2nr('-0xABCDEF', 16)) + + call assert_equal(0, str2nr('0x10')) + call assert_equal(0, str2nr('0b10')) + call assert_equal(1, str2nr('12', 2)) + call assert_equal(1, str2nr('18', 8)) + call assert_equal(1, str2nr('1g', 16)) + + call assert_equal(0, str2nr(v:null)) + call assert_equal(0, str2nr(v:none)) + + call assert_fails('call str2nr([])', 'E730:') + call assert_fails('call str2nr({->2})', 'E729:') + call assert_fails('call str2nr(1.2)', 'E806:') + call assert_fails('call str2nr(10, [])', 'E474:') +endfunc + +func Test_strftime() + if !exists('*strftime') + return + endif + " Format of strftime() depends on system. We assume + " that basic formats tested here are available and + " identical on all systems which support strftime(). + " + " The 2nd parameter of strftime() is a local time, so the output day + " of strftime() can be 17 or 18, depending on timezone. + call assert_match('^2017-01-1[78]$', strftime('%Y-%m-%d', 1484695512)) + " + call assert_match('^\d\d\d\d-\(0\d\|1[012]\)-\([012]\d\|3[01]\) \([01]\d\|2[0-3]\):[0-5]\d:\([0-5]\d\|60\)$', strftime('%Y-%m-%d %H:%M:%S')) + + call assert_fails('call strftime([])', 'E730:') + call assert_fails('call strftime("%Y", [])', 'E745:') +endfunc + +func Test_resolve() + if !has('unix') + return + endif + + " Xlink1 -> Xlink2 + " Xlink2 -> Xlink3 + silent !ln -s -f Xlink2 Xlink1 + silent !ln -s -f Xlink3 Xlink2 + call assert_equal('Xlink3', resolve('Xlink1')) + call assert_equal('./Xlink3', resolve('./Xlink1')) + call assert_equal('Xlink3/', resolve('Xlink2/')) + " FIXME: these tests result in things like "Xlink2/" instead of "Xlink3/"?! + "call assert_equal('Xlink3/', resolve('Xlink1/')) + "call assert_equal('./Xlink3/', resolve('./Xlink1/')) + "call assert_equal(getcwd() . '/Xlink3/', resolve(getcwd() . '/Xlink1/')) + call assert_equal(getcwd() . '/Xlink3', resolve(getcwd() . '/Xlink1')) + + " Test resolve() with a symlink cycle. + " Xlink1 -> Xlink2 + " Xlink2 -> Xlink3 + " Xlink3 -> Xlink1 + silent !ln -s -f Xlink1 Xlink3 + call assert_fails('call resolve("Xlink1")', 'E655:') + call assert_fails('call resolve("./Xlink1")', 'E655:') + call assert_fails('call resolve("Xlink2")', 'E655:') + call assert_fails('call resolve("Xlink3")', 'E655:') + call delete('Xlink1') + call delete('Xlink2') + call delete('Xlink3') + + silent !ln -s -f Xdir//Xfile Xlink + call assert_equal('Xdir/Xfile', resolve('Xlink')) + call delete('Xlink') + + silent !ln -s -f Xlink2/ Xlink1 + call assert_equal('Xlink2', resolve('Xlink1')) + call assert_equal('Xlink2/', resolve('Xlink1/')) + call delete('Xlink1') + + silent !ln -s -f ./Xlink2 Xlink1 + call assert_equal('Xlink2', resolve('Xlink1')) + call assert_equal('./Xlink2', resolve('./Xlink1')) + call delete('Xlink1') +endfunc + +func Test_simplify() + call assert_equal('', simplify('')) + call assert_equal('/', simplify('/')) + call assert_equal('/', simplify('/.')) + call assert_equal('/', simplify('/..')) + call assert_equal('/...', simplify('/...')) + call assert_equal('./dir/file', simplify('./dir/file')) + call assert_equal('./dir/file', simplify('.///dir//file')) + call assert_equal('./dir/file', simplify('./dir/./file')) + call assert_equal('./file', simplify('./dir/../file')) + call assert_equal('../dir/file', simplify('dir/../../dir/file')) + call assert_equal('./file', simplify('dir/.././file')) + + call assert_fails('call simplify({->0})', 'E729:') + call assert_fails('call simplify([])', 'E730:') + call assert_fails('call simplify({})', 'E731:') + call assert_fails('call simplify(1.2)', 'E806:') +endfunc + +func Test_pathshorten() + call assert_equal('', pathshorten('')) + call assert_equal('foo', pathshorten('foo')) + call assert_equal('/foo', pathshorten('/foo')) + call assert_equal('f/', pathshorten('foo/')) + call assert_equal('f/bar', pathshorten('foo/bar')) + call assert_equal('f/b/foobar', pathshorten('foo/bar/foobar')) + call assert_equal('/f/b/foobar', pathshorten('/foo/bar/foobar')) + call assert_equal('.f/bar', pathshorten('.foo/bar')) + call assert_equal('~f/bar', pathshorten('~foo/bar')) + call assert_equal('~.f/bar', pathshorten('~.foo/bar')) + call assert_equal('.~f/bar', pathshorten('.~foo/bar')) + call assert_equal('~/f/bar', pathshorten('~/foo/bar')) +endfunc + +func Test_strpart() + call assert_equal('de', strpart('abcdefg', 3, 2)) + call assert_equal('ab', strpart('abcdefg', -2, 4)) + call assert_equal('abcdefg', strpart('abcdefg', -2)) + call assert_equal('fg', strpart('abcdefg', 5, 4)) + call assert_equal('defg', strpart('abcdefg', 3)) + + call assert_equal('lép', strpart('éléphant', 2, 4)) + call assert_equal('léphant', strpart('éléphant', 2)) +endfunc + +func Test_tolower() + call assert_equal("", tolower("")) + + " Test with all printable ASCII characters. + call assert_equal(' !"#$%&''()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz[\]^_`abcdefghijklmnopqrstuvwxyz{|}~', + \ tolower(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~')) + + " Test with a few uppercase diacritics. + call assert_equal("aàáâãäåāăąǎǟǡả", tolower("AÀÁÂÃÄÅĀĂĄǍǞǠẢ")) + call assert_equal("bḃḇ", tolower("BḂḆ")) + call assert_equal("cçćĉċč", tolower("CÇĆĈĊČ")) + call assert_equal("dďđḋḏḑ", tolower("DĎĐḊḎḐ")) + call assert_equal("eèéêëēĕėęěẻẽ", tolower("EÈÉÊËĒĔĖĘĚẺẼ")) + call assert_equal("fḟ ", tolower("FḞ ")) + call assert_equal("gĝğġģǥǧǵḡ", tolower("GĜĞĠĢǤǦǴḠ")) + call assert_equal("hĥħḣḧḩ", tolower("HĤĦḢḦḨ")) + call assert_equal("iìíîïĩīĭįiǐỉ", tolower("IÌÍÎÏĨĪĬĮİǏỈ")) + call assert_equal("jĵ", tolower("JĴ")) + call assert_equal("kķǩḱḵ", tolower("KĶǨḰḴ")) + call assert_equal("lĺļľŀłḻ", tolower("LĹĻĽĿŁḺ")) + call assert_equal("mḿṁ", tolower("MḾṀ")) + call assert_equal("nñńņňṅṉ", tolower("NÑŃŅŇṄṈ")) + call assert_equal("oòóôõöøōŏőơǒǫǭỏ", tolower("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ")) + call assert_equal("pṕṗ", tolower("PṔṖ")) + call assert_equal("q", tolower("Q")) + call assert_equal("rŕŗřṙṟ", tolower("RŔŖŘṘṞ")) + call assert_equal("sśŝşšṡ", tolower("SŚŜŞŠṠ")) + call assert_equal("tţťŧṫṯ", tolower("TŢŤŦṪṮ")) + call assert_equal("uùúûüũūŭůűųưǔủ", tolower("UÙÚÛÜŨŪŬŮŰŲƯǓỦ")) + call assert_equal("vṽ", tolower("VṼ")) + call assert_equal("wŵẁẃẅẇ", tolower("WŴẀẂẄẆ")) + call assert_equal("xẋẍ", tolower("XẊẌ")) + call assert_equal("yýŷÿẏỳỷỹ", tolower("YÝŶŸẎỲỶỸ")) + call assert_equal("zźżžƶẑẕ", tolower("ZŹŻŽƵẐẔ")) + + " Test with a few lowercase diacritics, which should remain unchanged. + call assert_equal("aàáâãäåāăąǎǟǡả", tolower("aàáâãäåāăąǎǟǡả")) + call assert_equal("bḃḇ", tolower("bḃḇ")) + call assert_equal("cçćĉċč", tolower("cçćĉċč")) + call assert_equal("dďđḋḏḑ", tolower("dďđḋḏḑ")) + call assert_equal("eèéêëēĕėęěẻẽ", tolower("eèéêëēĕėęěẻẽ")) + call assert_equal("fḟ", tolower("fḟ")) + call assert_equal("gĝğġģǥǧǵḡ", tolower("gĝğġģǥǧǵḡ")) + call assert_equal("hĥħḣḧḩẖ", tolower("hĥħḣḧḩẖ")) + call assert_equal("iìíîïĩīĭįǐỉ", tolower("iìíîïĩīĭįǐỉ")) + call assert_equal("jĵǰ", tolower("jĵǰ")) + call assert_equal("kķǩḱḵ", tolower("kķǩḱḵ")) + call assert_equal("lĺļľŀłḻ", tolower("lĺļľŀłḻ")) + call assert_equal("mḿṁ ", tolower("mḿṁ ")) + call assert_equal("nñńņňʼnṅṉ", tolower("nñńņňʼnṅṉ")) + call assert_equal("oòóôõöøōŏőơǒǫǭỏ", tolower("oòóôõöøōŏőơǒǫǭỏ")) + call assert_equal("pṕṗ", tolower("pṕṗ")) + call assert_equal("q", tolower("q")) + call assert_equal("rŕŗřṙṟ", tolower("rŕŗřṙṟ")) + call assert_equal("sśŝşšṡ", tolower("sśŝşšṡ")) + call assert_equal("tţťŧṫṯẗ", tolower("tţťŧṫṯẗ")) + call assert_equal("uùúûüũūŭůűųưǔủ", tolower("uùúûüũūŭůűųưǔủ")) + call assert_equal("vṽ", tolower("vṽ")) + call assert_equal("wŵẁẃẅẇẘ", tolower("wŵẁẃẅẇẘ")) + call assert_equal("ẋẍ", tolower("ẋẍ")) + call assert_equal("yýÿŷẏẙỳỷỹ", tolower("yýÿŷẏẙỳỷỹ")) + call assert_equal("zźżžƶẑẕ", tolower("zźżžƶẑẕ")) + + " According to https://twitter.com/jifa/status/625776454479970304 + " Ⱥ (U+023A) and Ⱦ (U+023E) are the *only* code points to increase + " in length (2 to 3 bytes) when lowercased. So let's test them. + call assert_equal("ⱥ ⱦ", tolower("Ⱥ Ⱦ")) + + " This call to tolower with invalid utf8 sequence used to cause access to + " invalid memory. + call tolower("\xC0\x80\xC0") + call tolower("123\xC0\x80\xC0") +endfunc + +func Test_toupper() + call assert_equal("", toupper("")) + + " Test with all printable ASCII characters. + call assert_equal(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~', + \ toupper(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~')) + + " Test with a few lowercase diacritics. + call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", toupper("aàáâãäåāăąǎǟǡả")) + call assert_equal("BḂḆ", toupper("bḃḇ")) + call assert_equal("CÇĆĈĊČ", toupper("cçćĉċč")) + call assert_equal("DĎĐḊḎḐ", toupper("dďđḋḏḑ")) + call assert_equal("EÈÉÊËĒĔĖĘĚẺẼ", toupper("eèéêëēĕėęěẻẽ")) + call assert_equal("FḞ", toupper("fḟ")) + call assert_equal("GĜĞĠĢǤǦǴḠ", toupper("gĝğġģǥǧǵḡ")) + call assert_equal("HĤĦḢḦḨẖ", toupper("hĥħḣḧḩẖ")) + call assert_equal("IÌÍÎÏĨĪĬĮǏỈ", toupper("iìíîïĩīĭįǐỉ")) + call assert_equal("JĴǰ", toupper("jĵǰ")) + call assert_equal("KĶǨḰḴ", toupper("kķǩḱḵ")) + call assert_equal("LĹĻĽĿŁḺ", toupper("lĺļľŀłḻ")) + call assert_equal("MḾṀ ", toupper("mḿṁ ")) + call assert_equal("NÑŃŅŇʼnṄṈ", toupper("nñńņňʼnṅṉ")) + call assert_equal("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ", toupper("oòóôõöøōŏőơǒǫǭỏ")) + call assert_equal("PṔṖ", toupper("pṕṗ")) + call assert_equal("Q", toupper("q")) + call assert_equal("RŔŖŘṘṞ", toupper("rŕŗřṙṟ")) + call assert_equal("SŚŜŞŠṠ", toupper("sśŝşšṡ")) + call assert_equal("TŢŤŦṪṮẗ", toupper("tţťŧṫṯẗ")) + call assert_equal("UÙÚÛÜŨŪŬŮŰŲƯǓỦ", toupper("uùúûüũūŭůűųưǔủ")) + call assert_equal("VṼ", toupper("vṽ")) + call assert_equal("WŴẀẂẄẆẘ", toupper("wŵẁẃẅẇẘ")) + call assert_equal("ẊẌ", toupper("ẋẍ")) + call assert_equal("YÝŸŶẎẙỲỶỸ", toupper("yýÿŷẏẙỳỷỹ")) + call assert_equal("ZŹŻŽƵẐẔ", toupper("zźżžƶẑẕ")) + + " Test that uppercase diacritics, which should remain unchanged. + call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", toupper("AÀÁÂÃÄÅĀĂĄǍǞǠẢ")) + call assert_equal("BḂḆ", toupper("BḂḆ")) + call assert_equal("CÇĆĈĊČ", toupper("CÇĆĈĊČ")) + call assert_equal("DĎĐḊḎḐ", toupper("DĎĐḊḎḐ")) + call assert_equal("EÈÉÊËĒĔĖĘĚẺẼ", toupper("EÈÉÊËĒĔĖĘĚẺẼ")) + call assert_equal("FḞ ", toupper("FḞ ")) + call assert_equal("GĜĞĠĢǤǦǴḠ", toupper("GĜĞĠĢǤǦǴḠ")) + call assert_equal("HĤĦḢḦḨ", toupper("HĤĦḢḦḨ")) + call assert_equal("IÌÍÎÏĨĪĬĮİǏỈ", toupper("IÌÍÎÏĨĪĬĮİǏỈ")) + call assert_equal("JĴ", toupper("JĴ")) + call assert_equal("KĶǨḰḴ", toupper("KĶǨḰḴ")) + call assert_equal("LĹĻĽĿŁḺ", toupper("LĹĻĽĿŁḺ")) + call assert_equal("MḾṀ", toupper("MḾṀ")) + call assert_equal("NÑŃŅŇṄṈ", toupper("NÑŃŅŇṄṈ")) + call assert_equal("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ", toupper("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ")) + call assert_equal("PṔṖ", toupper("PṔṖ")) + call assert_equal("Q", toupper("Q")) + call assert_equal("RŔŖŘṘṞ", toupper("RŔŖŘṘṞ")) + call assert_equal("SŚŜŞŠṠ", toupper("SŚŜŞŠṠ")) + call assert_equal("TŢŤŦṪṮ", toupper("TŢŤŦṪṮ")) + call assert_equal("UÙÚÛÜŨŪŬŮŰŲƯǓỦ", toupper("UÙÚÛÜŨŪŬŮŰŲƯǓỦ")) + call assert_equal("VṼ", toupper("VṼ")) + call assert_equal("WŴẀẂẄẆ", toupper("WŴẀẂẄẆ")) + call assert_equal("XẊẌ", toupper("XẊẌ")) + call assert_equal("YÝŶŸẎỲỶỸ", toupper("YÝŶŸẎỲỶỸ")) + call assert_equal("ZŹŻŽƵẐẔ", toupper("ZŹŻŽƵẐẔ")) + + call assert_equal("Ⱥ Ⱦ", toupper("ⱥ ⱦ")) + + " This call to toupper with invalid utf8 sequence used to cause access to + " invalid memory. + call toupper("\xC0\x80\xC0") + call toupper("123\xC0\x80\xC0") +endfunc + +" Tests for the mode() function +let current_modes = '' +func Save_mode() + let g:current_modes = mode(0) . '-' . mode(1) + return '' +endfunc + +func Test_mode() + new + call append(0, ["Blue Ball Black", "Brown Band Bowl", ""]) + + " Only complete from the current buffer. + set complete=. + + inoremap <F2> <C-R>=Save_mode()<CR> + + normal! 3G + exe "normal i\<F2>\<Esc>" + call assert_equal('i-i', g:current_modes) + " i_CTRL-P: Multiple matches + exe "normal i\<C-G>uBa\<C-P>\<F2>\<Esc>u" + call assert_equal('i-ic', g:current_modes) + " i_CTRL-P: Single match + exe "normal iBro\<C-P>\<F2>\<Esc>u" + call assert_equal('i-ic', g:current_modes) + " i_CTRL-X + exe "normal iBa\<C-X>\<F2>\<Esc>u" + call assert_equal('i-ix', g:current_modes) + " i_CTRL-X CTRL-P: Multiple matches + exe "normal iBa\<C-X>\<C-P>\<F2>\<Esc>u" + call assert_equal('i-ic', g:current_modes) + " i_CTRL-X CTRL-P: Single match + exe "normal iBro\<C-X>\<C-P>\<F2>\<Esc>u" + call assert_equal('i-ic', g:current_modes) + " i_CTRL-X CTRL-P + CTRL-P: Single match + exe "normal iBro\<C-X>\<C-P>\<C-P>\<F2>\<Esc>u" + call assert_equal('i-ic', g:current_modes) + " i_CTRL-X CTRL-L: Multiple matches + exe "normal i\<C-X>\<C-L>\<F2>\<Esc>u" + call assert_equal('i-ic', g:current_modes) + " i_CTRL-X CTRL-L: Single match + exe "normal iBlu\<C-X>\<C-L>\<F2>\<Esc>u" + call assert_equal('i-ic', g:current_modes) + " i_CTRL-P: No match + exe "normal iCom\<C-P>\<F2>\<Esc>u" + call assert_equal('i-ic', g:current_modes) + " i_CTRL-X CTRL-P: No match + exe "normal iCom\<C-X>\<C-P>\<F2>\<Esc>u" + call assert_equal('i-ic', g:current_modes) + " i_CTRL-X CTRL-L: No match + exe "normal iabc\<C-X>\<C-L>\<F2>\<Esc>u" + call assert_equal('i-ic', g:current_modes) + + " R_CTRL-P: Multiple matches + exe "normal RBa\<C-P>\<F2>\<Esc>u" + call assert_equal('R-Rc', g:current_modes) + " R_CTRL-P: Single match + exe "normal RBro\<C-P>\<F2>\<Esc>u" + call assert_equal('R-Rc', g:current_modes) + " R_CTRL-X + exe "normal RBa\<C-X>\<F2>\<Esc>u" + call assert_equal('R-Rx', g:current_modes) + " R_CTRL-X CTRL-P: Multiple matches + exe "normal RBa\<C-X>\<C-P>\<F2>\<Esc>u" + call assert_equal('R-Rc', g:current_modes) + " R_CTRL-X CTRL-P: Single match + exe "normal RBro\<C-X>\<C-P>\<F2>\<Esc>u" + call assert_equal('R-Rc', g:current_modes) + " R_CTRL-X CTRL-P + CTRL-P: Single match + exe "normal RBro\<C-X>\<C-P>\<C-P>\<F2>\<Esc>u" + call assert_equal('R-Rc', g:current_modes) + " R_CTRL-X CTRL-L: Multiple matches + exe "normal R\<C-X>\<C-L>\<F2>\<Esc>u" + call assert_equal('R-Rc', g:current_modes) + " R_CTRL-X CTRL-L: Single match + exe "normal RBlu\<C-X>\<C-L>\<F2>\<Esc>u" + call assert_equal('R-Rc', g:current_modes) + " R_CTRL-P: No match + exe "normal RCom\<C-P>\<F2>\<Esc>u" + call assert_equal('R-Rc', g:current_modes) + " R_CTRL-X CTRL-P: No match + exe "normal RCom\<C-X>\<C-P>\<F2>\<Esc>u" + call assert_equal('R-Rc', g:current_modes) + " R_CTRL-X CTRL-L: No match + exe "normal Rabc\<C-X>\<C-L>\<F2>\<Esc>u" + call assert_equal('R-Rc', g:current_modes) + + call assert_equal('n', mode(0)) + call assert_equal('n', mode(1)) + + " i_CTRL-O + exe "normal i\<C-O>:call Save_mode()\<Cr>\<Esc>" + call assert_equal("n-niI", g:current_modes) + + " R_CTRL-O + exe "normal R\<C-O>:call Save_mode()\<Cr>\<Esc>" + call assert_equal("n-niR", g:current_modes) + + " gR_CTRL-O + exe "normal gR\<C-O>:call Save_mode()\<Cr>\<Esc>" + call assert_equal("n-niV", g:current_modes) + + " How to test operator-pending mode? + + call feedkeys("v", 'xt') + call assert_equal('v', mode()) + call assert_equal('v', mode(1)) + call feedkeys("\<Esc>V", 'xt') + call assert_equal('V', mode()) + call assert_equal('V', mode(1)) + call feedkeys("\<Esc>\<C-V>", 'xt') + call assert_equal("\<C-V>", mode()) + call assert_equal("\<C-V>", mode(1)) + call feedkeys("\<Esc>", 'xt') + + call feedkeys("gh", 'xt') + call assert_equal('s', mode()) + call assert_equal('s', mode(1)) + call feedkeys("\<Esc>gH", 'xt') + call assert_equal('S', mode()) + call assert_equal('S', mode(1)) + call feedkeys("\<Esc>g\<C-H>", 'xt') + call assert_equal("\<C-S>", mode()) + call assert_equal("\<C-S>", mode(1)) + call feedkeys("\<Esc>", 'xt') + + call feedkeys(":echo \<C-R>=Save_mode()\<C-U>\<CR>", 'xt') + call assert_equal('c-c', g:current_modes) + call feedkeys("gQecho \<C-R>=Save_mode()\<CR>\<CR>vi\<CR>", 'xt') + call assert_equal('c-cv', g:current_modes) + " How to test Ex mode? + + bwipe! + iunmap <F2> + set complete& +endfunc + +func Test_getbufvar() + let bnr = bufnr('%') + let b:var_num = '1234' + let def_num = '5678' + call assert_equal('1234', getbufvar(bnr, 'var_num')) + call assert_equal('1234', getbufvar(bnr, 'var_num', def_num)) + + let bd = getbufvar(bnr, '') + call assert_equal('1234', bd['var_num']) + call assert_true(exists("bd['changedtick']")) + call assert_equal(2, len(bd)) + + let bd2 = getbufvar(bnr, '', def_num) + call assert_equal(bd, bd2) + + unlet b:var_num + call assert_equal(def_num, getbufvar(bnr, 'var_num', def_num)) + call assert_equal('', getbufvar(bnr, 'var_num')) + + let bd = getbufvar(bnr, '') + call assert_equal(1, len(bd)) + let bd = getbufvar(bnr, '',def_num) + call assert_equal(1, len(bd)) + + call assert_equal('', getbufvar(9999, '')) + call assert_equal(def_num, getbufvar(9999, '', def_num)) + unlet def_num + + call assert_equal(0, getbufvar(bnr, '&autoindent')) + call assert_equal(0, getbufvar(bnr, '&autoindent', 1)) + + " Open new window with forced option values + set fileformats=unix,dos + new ++ff=dos ++bin ++enc=iso-8859-2 + call assert_equal('dos', getbufvar(bufnr('%'), '&fileformat')) + call assert_equal(1, getbufvar(bufnr('%'), '&bin')) + call assert_equal('iso-8859-2', getbufvar(bufnr('%'), '&fenc')) + close + + set fileformats& +endfunc + +func Test_last_buffer_nr() + call assert_equal(bufnr('$'), last_buffer_nr()) +endfunc + +func Test_stridx() + call assert_equal(-1, stridx('', 'l')) + call assert_equal(0, stridx('', '')) + call assert_equal(0, stridx('hello', '')) + call assert_equal(-1, stridx('hello', 'L')) + call assert_equal(2, stridx('hello', 'l', -1)) + call assert_equal(2, stridx('hello', 'l', 0)) + call assert_equal(2, stridx('hello', 'l', 1)) + call assert_equal(3, stridx('hello', 'l', 3)) + call assert_equal(-1, stridx('hello', 'l', 4)) + call assert_equal(-1, stridx('hello', 'l', 10)) + call assert_equal(2, stridx('hello', 'll')) + call assert_equal(-1, stridx('hello', 'hello world')) +endfunc + +func Test_strridx() + call assert_equal(-1, strridx('', 'l')) + call assert_equal(0, strridx('', '')) + call assert_equal(5, strridx('hello', '')) + call assert_equal(-1, strridx('hello', 'L')) + call assert_equal(3, strridx('hello', 'l')) + call assert_equal(3, strridx('hello', 'l', 10)) + call assert_equal(3, strridx('hello', 'l', 3)) + call assert_equal(2, strridx('hello', 'l', 2)) + call assert_equal(-1, strridx('hello', 'l', 1)) + call assert_equal(-1, strridx('hello', 'l', 0)) + call assert_equal(-1, strridx('hello', 'l', -1)) + call assert_equal(2, strridx('hello', 'll')) + call assert_equal(-1, strridx('hello', 'hello world')) +endfunc + +func Test_match_func() + call assert_equal(4, match('testing', 'ing')) + call assert_equal(4, match('testing', 'ing', 2)) + call assert_equal(-1, match('testing', 'ing', 5)) + call assert_equal(-1, match('testing', 'ing', 8)) + call assert_equal(1, match(['vim', 'testing', 'execute'], 'ing')) + call assert_equal(-1, match(['vim', 'testing', 'execute'], 'img')) +endfunc + +func Test_matchend() + call assert_equal(7, matchend('testing', 'ing')) + call assert_equal(7, matchend('testing', 'ing', 2)) + call assert_equal(-1, matchend('testing', 'ing', 5)) + call assert_equal(-1, matchend('testing', 'ing', 8)) + call assert_equal(match(['vim', 'testing', 'execute'], 'ing'), matchend(['vim', 'testing', 'execute'], 'ing')) + call assert_equal(match(['vim', 'testing', 'execute'], 'img'), matchend(['vim', 'testing', 'execute'], 'img')) +endfunc + +func Test_matchlist() + call assert_equal(['acd', 'a', '', 'c', 'd', '', '', '', '', ''], matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)')) + call assert_equal(['d', '', '', '', 'd', '', '', '', '', ''], matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2)) + call assert_equal([], matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 4)) +endfunc + +func Test_matchstr() + call assert_equal('ing', matchstr('testing', 'ing')) + call assert_equal('ing', matchstr('testing', 'ing', 2)) + call assert_equal('', matchstr('testing', 'ing', 5)) + call assert_equal('', matchstr('testing', 'ing', 8)) + call assert_equal('testing', matchstr(['vim', 'testing', 'execute'], 'ing')) + call assert_equal('', matchstr(['vim', 'testing', 'execute'], 'img')) +endfunc + +func Test_matchstrpos() + call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing')) + call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing', 2)) + call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 5)) + call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 8)) + call assert_equal(['ing', 1, 4, 7], matchstrpos(['vim', 'testing', 'execute'], 'ing')) + call assert_equal(['', -1, -1, -1], matchstrpos(['vim', 'testing', 'execute'], 'img')) +endfunc + +func Test_nextnonblank_prevnonblank() + new +insert +This + + +is + +a +Test +. + call assert_equal(0, nextnonblank(-1)) + call assert_equal(0, nextnonblank(0)) + call assert_equal(1, nextnonblank(1)) + call assert_equal(4, nextnonblank(2)) + call assert_equal(4, nextnonblank(3)) + call assert_equal(4, nextnonblank(4)) + call assert_equal(6, nextnonblank(5)) + call assert_equal(6, nextnonblank(6)) + call assert_equal(7, nextnonblank(7)) + call assert_equal(0, nextnonblank(8)) + + call assert_equal(0, prevnonblank(-1)) + call assert_equal(0, prevnonblank(0)) + call assert_equal(1, prevnonblank(1)) + call assert_equal(1, prevnonblank(2)) + call assert_equal(1, prevnonblank(3)) + call assert_equal(4, prevnonblank(4)) + call assert_equal(4, prevnonblank(5)) + call assert_equal(6, prevnonblank(6)) + call assert_equal(7, prevnonblank(7)) + call assert_equal(0, prevnonblank(8)) + bw! +endfunc + +func Test_byte2line_line2byte() + new + set endofline + call setline(1, ['a', 'bc', 'd']) + + set fileformat=unix + call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1], + \ map(range(-1, 8), 'byte2line(v:val)')) + call assert_equal([-1, -1, 1, 3, 6, 8, -1], + \ map(range(-1, 5), 'line2byte(v:val)')) + + set fileformat=mac + call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1], + \ map(range(-1, 8), 'byte2line(v:val)')) + call assert_equal([-1, -1, 1, 3, 6, 8, -1], + \ map(range(-1, 5), 'line2byte(v:val)')) + + set fileformat=dos + call assert_equal([-1, -1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, -1], + \ map(range(-1, 11), 'byte2line(v:val)')) + call assert_equal([-1, -1, 1, 4, 8, 11, -1], + \ map(range(-1, 5), 'line2byte(v:val)')) + + bw! + set noendofline nofixendofline + normal a- + for ff in ["unix", "mac", "dos"] + let &fileformat = ff + call assert_equal(1, line2byte(1)) + call assert_equal(2, line2byte(2)) " line2byte(line("$") + 1) is the buffer size plus one (as per :help line2byte). + endfor + + set endofline& fixendofline& fileformat& + bw! +endfunc + +func Test_count() + let l = ['a', 'a', 'A', 'b'] + call assert_equal(2, count(l, 'a')) + call assert_equal(1, count(l, 'A')) + call assert_equal(1, count(l, 'b')) + call assert_equal(0, count(l, 'B')) + + call assert_equal(2, count(l, 'a', 0)) + call assert_equal(1, count(l, 'A', 0)) + call assert_equal(1, count(l, 'b', 0)) + call assert_equal(0, count(l, 'B', 0)) + + call assert_equal(3, count(l, 'a', 1)) + call assert_equal(3, count(l, 'A', 1)) + call assert_equal(1, count(l, 'b', 1)) + call assert_equal(1, count(l, 'B', 1)) + call assert_equal(0, count(l, 'c', 1)) + + call assert_equal(1, count(l, 'a', 0, 1)) + call assert_equal(2, count(l, 'a', 1, 1)) + call assert_fails('call count(l, "a", 0, 10)', 'E684:') + + let d = {1: 'a', 2: 'a', 3: 'A', 4: 'b'} + call assert_equal(2, count(d, 'a')) + call assert_equal(1, count(d, 'A')) + call assert_equal(1, count(d, 'b')) + call assert_equal(0, count(d, 'B')) + + call assert_equal(2, count(d, 'a', 0)) + call assert_equal(1, count(d, 'A', 0)) + call assert_equal(1, count(d, 'b', 0)) + call assert_equal(0, count(d, 'B', 0)) + + call assert_equal(3, count(d, 'a', 1)) + call assert_equal(3, count(d, 'A', 1)) + call assert_equal(1, count(d, 'b', 1)) + call assert_equal(1, count(d, 'B', 1)) + call assert_equal(0, count(d, 'c', 1)) + + call assert_fails('call count(d, "a", 0, 1)', 'E474:') + + call assert_equal(0, count("foo", "bar")) + call assert_equal(1, count("foo", "oo")) + call assert_equal(2, count("foo", "o")) + call assert_equal(0, count("foo", "O")) + call assert_equal(2, count("foo", "O", 1)) + call assert_equal(2, count("fooooo", "oo")) + call assert_equal(0, count("foo", "")) +endfunc + +func Test_changenr() + new Xchangenr + call assert_equal(0, changenr()) + norm ifoo + call assert_equal(1, changenr()) + set undolevels=10 + norm Sbar + call assert_equal(2, changenr()) + undo + call assert_equal(1, changenr()) + redo + call assert_equal(2, changenr()) + bw! + set undolevels& +endfunc + +func Test_filewritable() + new Xfilewritable + write! + call assert_equal(1, filewritable('Xfilewritable')) + + call assert_notequal(0, setfperm('Xfilewritable', 'r--r-----')) + call assert_equal(0, filewritable('Xfilewritable')) + + call assert_notequal(0, setfperm('Xfilewritable', 'rw-r-----')) + call assert_equal(1, filewritable('Xfilewritable')) + + call assert_equal(0, filewritable('doesnotexist')) + + call delete('Xfilewritable') + bw! +endfunc + +func Test_Executable() + if has('win32') + call assert_equal(1, executable('notepad')) + call assert_equal(1, executable('notepad.exe')) + call assert_equal(0, executable('notepad.exe.exe')) + call assert_equal(0, executable('shell32.dll')) + call assert_equal(0, executable('win.ini')) + elseif has('unix') + call assert_equal(1, executable('cat')) + call assert_equal(0, executable('nodogshere')) + endif +endfunc + +func Test_hostname() + let hostname_vim = hostname() + if has('unix') + let hostname_system = systemlist('uname -n')[0] + call assert_equal(hostname_vim, hostname_system) + endif +endfunc + +func Test_getpid() + " getpid() always returns the same value within a vim instance. + call assert_equal(getpid(), getpid()) + if has('unix') + call assert_equal(systemlist('echo $PPID')[0], string(getpid())) + endif +endfunc + +func Test_hlexists() + call assert_equal(0, hlexists('does_not_exist')) + call assert_equal(0, hlexists('Number')) + call assert_equal(0, highlight_exists('does_not_exist')) + call assert_equal(0, highlight_exists('Number')) + syntax on + call assert_equal(0, hlexists('does_not_exist')) + call assert_equal(1, hlexists('Number')) + call assert_equal(0, highlight_exists('does_not_exist')) + call assert_equal(1, highlight_exists('Number')) + syntax off +endfunc + +func Test_col() + new + call setline(1, 'abcdef') + norm gg4|mx6|mY2| + call assert_equal(2, col('.')) + call assert_equal(7, col('$')) + call assert_equal(4, col("'x")) + call assert_equal(6, col("'Y")) + call assert_equal(2, col([1, 2])) + call assert_equal(7, col([1, '$'])) + + call assert_equal(0, col('')) + call assert_equal(0, col('x')) + call assert_equal(0, col([2, '$'])) + call assert_equal(0, col([1, 100])) + call assert_equal(0, col([1])) + bw! +endfunc + +func Test_inputlist() + call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>1\<cr>", 'tx') + call assert_equal(1, c) + call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>2\<cr>", 'tx') + call assert_equal(2, c) + call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>3\<cr>", 'tx') + call assert_equal(3, c) + + call assert_fails('call inputlist("")', 'E686:') +endfunc + +func Test_balloon_show() + if has('balloon_eval') + " This won't do anything but must not crash either. + call balloon_show('hi!') + endif +endfunc + +func Test_setbufvar_options() + " This tests that aucmd_prepbuf() and aucmd_restbuf() properly restore the + " window layout. + call assert_equal(1, winnr('$')) + split dummy_preview + resize 2 + set winfixheight winfixwidth + let prev_id = win_getid() + + wincmd j + let wh = winheight('.') + let dummy_buf = bufnr('dummy_buf1', v:true) + call setbufvar(dummy_buf, '&buftype', 'nofile') + execute 'belowright vertical split #' . dummy_buf + call assert_equal(wh, winheight('.')) + let dum1_id = win_getid() + + wincmd h + let wh = winheight('.') + let dummy_buf = bufnr('dummy_buf2', v:true) + call setbufvar(dummy_buf, '&buftype', 'nofile') + execute 'belowright vertical split #' . dummy_buf + call assert_equal(wh, winheight('.')) + + bwipe! + call win_gotoid(prev_id) + bwipe! + call win_gotoid(dum1_id) + bwipe! +endfunc + +func Test_redo_in_nested_functions() + nnoremap g. :set opfunc=Operator<CR>g@ + function Operator( type, ... ) + let @x = 'XXX' + execute 'normal! g`[' . (a:type ==# 'line' ? 'V' : 'v') . 'g`]' . '"xp' + endfunction + + function! Apply() + 5,6normal! . + endfunction + + new + call setline(1, repeat(['some "quoted" text', 'more "quoted" text'], 3)) + 1normal g.i" + call assert_equal('some "XXX" text', getline(1)) + 3,4normal . + call assert_equal('some "XXX" text', getline(3)) + call assert_equal('more "XXX" text', getline(4)) + call Apply() + call assert_equal('some "XXX" text', getline(5)) + call assert_equal('more "XXX" text', getline(6)) + bwipe! + + nunmap g. + delfunc Operator + delfunc Apply +endfunc + +func Test_shellescape() + let save_shell = &shell + set shell=bash + call assert_equal("'text'", shellescape('text')) + call assert_equal("'te\"xt'", shellescape('te"xt')) + call assert_equal("'te'\\''xt'", shellescape("te'xt")) + + call assert_equal("'te%xt'", shellescape("te%xt")) + call assert_equal("'te\\%xt'", shellescape("te%xt", 1)) + call assert_equal("'te#xt'", shellescape("te#xt")) + call assert_equal("'te\\#xt'", shellescape("te#xt", 1)) + call assert_equal("'te!xt'", shellescape("te!xt")) + call assert_equal("'te\\!xt'", shellescape("te!xt", 1)) + + call assert_equal("'te\nxt'", shellescape("te\nxt")) + call assert_equal("'te\\\nxt'", shellescape("te\nxt", 1)) + set shell=tcsh + call assert_equal("'te\\!xt'", shellescape("te!xt")) + call assert_equal("'te\\\\!xt'", shellescape("te!xt", 1)) + call assert_equal("'te\\\nxt'", shellescape("te\nxt")) + call assert_equal("'te\\\\\nxt'", shellescape("te\nxt", 1)) + + let &shell = save_shell +endfunc + +func Test_trim() + call assert_equal("Testing", trim(" \t\r\r\x0BTesting \t\n\r\n\t\x0B\x0B")) + call assert_equal("Testing", trim(" \t \r\r\n\n\x0BTesting \t\n\r\n\t\x0B\x0B")) + call assert_equal("RESERVE", trim("xyz \twwRESERVEzyww \t\t", " wxyz\t")) + call assert_equal("wRE \tSERVEzyww", trim("wRE \tSERVEzyww")) + call assert_equal("abcd\t xxxx tail", trim(" \tabcd\t xxxx tail")) + call assert_equal("\tabcd\t xxxx tail", trim(" \tabcd\t xxxx tail", " ")) + call assert_equal(" \tabcd\t xxxx tail", trim(" \tabcd\t xxxx tail", "abx")) + call assert_equal("RESERVE", trim("你RESERVE好", "你好")) + call assert_equal("您R E SER V E早", trim("你好您R E SER V E早好你你", "你好")) + call assert_equal("你好您R E SER V E早好你你", trim(" \n\r\r 你好您R E SER V E早好你你 \t \x0B", )) + call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" 你好您R E SER V E早好你你 \t \x0B", " 你好")) + call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" tteesstttt你好您R E SER V E早好你你 \t \x0B ttestt", " 你好tes")) + call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" tteesstttt你好您R E SER V E早好你你 \t \x0B ttestt", " 你你你好好好tttsses")) + call assert_equal("留下", trim("这些些不要这些留下这些", "这些不要")) + call assert_equal("", trim("", "")) + call assert_equal("a", trim("a", "")) + call assert_equal("", trim("", "a")) + + let chars = join(map(range(1, 0x20) + [0xa0], {n -> nr2char(n)}), '') + call assert_equal("x", trim(chars . "x" . chars)) +endfunc + +" Test for reg_recording() and reg_executing() +func Test_reg_executing_and_recording() + let s:reg_stat = '' + func s:save_reg_stat() + let s:reg_stat = reg_recording() . ':' . reg_executing() + return '' + endfunc + + new + call s:save_reg_stat() + call assert_equal(':', s:reg_stat) + call feedkeys("qa\"=s:save_reg_stat()\<CR>pq", 'xt') + call assert_equal('a:', s:reg_stat) + call feedkeys("@a", 'xt') + call assert_equal(':a', s:reg_stat) + call feedkeys("qb@aq", 'xt') + call assert_equal('b:a', s:reg_stat) + call feedkeys("q\"\"=s:save_reg_stat()\<CR>pq", 'xt') + call assert_equal('":', s:reg_stat) + + bwipe! + delfunc s:save_reg_stat + unlet s:reg_stat +endfunc + +func Test_libcall_libcallnr() + if !has('libcall') + return + endif + + if has('win32') + let libc = 'msvcrt.dll' + elseif has('mac') + let libc = 'libSystem.B.dylib' + elseif executable('ldd') + let libc = matchstr(split(system('ldd ' . GetVimProg())), '/libc\.so\>') + endif + if get(l:, 'libc', '') ==# '' + " On Unix, libc.so can be in various places. + if has('linux') + " There is not documented but regarding the 1st argument of glibc's + " dlopen an empty string and nullptr are equivalent, so using an empty + " string for the 1st argument of libcall allows to call functions. + let libc = '' + elseif has('sun') + " Set the path to libc.so according to the architecture. + let test_bits = system('file ' . GetVimProg()) + let test_arch = system('uname -p') + if test_bits =~ '64-bit' && test_arch =~ 'sparc' + let libc = '/usr/lib/sparcv9/libc.so' + elseif test_bits =~ '64-bit' && test_arch =~ 'i386' + let libc = '/usr/lib/amd64/libc.so' + else + let libc = '/usr/lib/libc.so' + endif + else + " Unfortunately skip this test until a good way is found. + return + endif + endif + + if has('win32') + call assert_equal($USERPROFILE, libcall(libc, 'getenv', 'USERPROFILE')) + else + call assert_equal($HOME, libcall(libc, 'getenv', 'HOME')) + endif + + " If function returns NULL, libcall() should return an empty string. + call assert_equal('', libcall(libc, 'getenv', 'X_ENV_DOES_NOT_EXIT')) + + " Test libcallnr() with string and integer argument. + call assert_equal(4, libcallnr(libc, 'strlen', 'abcd')) + call assert_equal(char2nr('A'), libcallnr(libc, 'toupper', char2nr('a'))) + + call assert_fails("call libcall(libc, 'Xdoesnotexist_', '')", 'E364:') + call assert_fails("call libcallnr(libc, 'Xdoesnotexist_', '')", 'E364:') + + call assert_fails("call libcall('Xdoesnotexist_', 'getenv', 'HOME')", 'E364:') + call assert_fails("call libcallnr('Xdoesnotexist_', 'strlen', 'abcd')", 'E364:') +endfunc + +sandbox function Fsandbox() + normal ix +endfunc + +func Test_func_sandbox() + sandbox let F = {-> 'hello'} + call assert_equal('hello', F()) + + sandbox let F = {-> execute("normal ix\<Esc>")} + call assert_fails('call F()', 'E48:') + unlet F + + call assert_fails('call Fsandbox()', 'E48:') + delfunc Fsandbox +endfunc + +func EditAnotherFile() + let word = expand('<cword>') + edit Xfuncrange2 +endfunc + +func Test_func_range_with_edit() + " Define a function that edits another buffer, then call it with a range that + " is invalid in that buffer. + call writefile(['just one line'], 'Xfuncrange2') + new + call setline(1, range(10)) + write Xfuncrange1 + call assert_fails('5,8call EditAnotherFile()', 'E16:') + + call delete('Xfuncrange1') + call delete('Xfuncrange2') + bwipe! +endfunc + +func Test_func_exists_on_reload() + call writefile(['func ExistingFunction()', 'echo "yes"', 'endfunc'], 'Xfuncexists') + call assert_equal(0, exists('*ExistingFunction')) + source Xfuncexists + call assert_equal(1, exists('*ExistingFunction')) + " Redefining a function when reloading a script is OK. + source Xfuncexists + call assert_equal(1, exists('*ExistingFunction')) + + " But redefining in another script is not OK. + call writefile(['func ExistingFunction()', 'echo "yes"', 'endfunc'], 'Xfuncexists2') + call assert_fails('source Xfuncexists2', 'E122:') + + delfunc ExistingFunction + call assert_equal(0, exists('*ExistingFunction')) + call writefile([ + \ 'func ExistingFunction()', 'echo "yes"', 'endfunc', + \ 'func ExistingFunction()', 'echo "no"', 'endfunc', + \ ], 'Xfuncexists') + call assert_fails('source Xfuncexists', 'E122:') + call assert_equal(1, exists('*ExistingFunction')) + + call delete('Xfuncexists2') + call delete('Xfuncexists') + delfunc ExistingFunction +endfunc + +" Test confirm({msg} [, {choices} [, {default} [, {type}]]]) +func Test_confirm() + if !has('unix') || has('gui_running') + return + endif + + call feedkeys('o', 'L') + let a = confirm('Press O to proceed') + call assert_equal(1, a) + + call feedkeys('y', 'L') + let a = confirm('Are you sure?', "&Yes\n&No") + call assert_equal(1, a) + + call feedkeys('n', 'L') + let a = confirm('Are you sure?', "&Yes\n&No") + call assert_equal(2, a) + + " confirm() should return 0 when pressing CTRL-C. + call feedkeys("\<C-c>", 'L') + let a = confirm('Are you sure?', "&Yes\n&No") + call assert_equal(0, a) + + " <Esc> requires another character to avoid it being seen as the start of an + " escape sequence. Zero should be harmless. + call feedkeys("\<Esc>0", 'L') + let a = confirm('Are you sure?', "&Yes\n&No") + call assert_equal(0, a) + + " Default choice is returned when pressing <CR>. + call feedkeys("\<CR>", 'L') + let a = confirm('Are you sure?', "&Yes\n&No") + call assert_equal(1, a) + + call feedkeys("\<CR>", 'L') + let a = confirm('Are you sure?', "&Yes\n&No", 2) + call assert_equal(2, a) + + call feedkeys("\<CR>", 'L') + let a = confirm('Are you sure?', "&Yes\n&No", 0) + call assert_equal(0, a) + + " Test with the {type} 4th argument + for type in ['Error', 'Question', 'Info', 'Warning', 'Generic'] + call feedkeys('y', 'L') + let a = confirm('Are you sure?', "&Yes\n&No\n", 1, type) + call assert_equal(1, a) + endfor + + call assert_fails('call confirm([])', 'E730:') + call assert_fails('call confirm("Are you sure?", [])', 'E730:') + call assert_fails('call confirm("Are you sure?", "&Yes\n&No\n", [])', 'E745:') + call assert_fails('call confirm("Are you sure?", "&Yes\n&No\n", 0, [])', 'E730:') +endfunc + +func Test_platform_name() + " The system matches at most only one name. + let names = ['amiga', 'beos', 'bsd', 'hpux', 'linux', 'mac', 'qnx', 'sun', 'vms', 'win32', 'win32unix'] + call assert_inrange(0, 1, len(filter(copy(names), 'has(v:val)'))) + + " Is Unix? + call assert_equal(has('beos'), has('beos') && has('unix')) + call assert_equal(has('bsd'), has('bsd') && has('unix')) + call assert_equal(has('hpux'), has('hpux') && has('unix')) + call assert_equal(has('linux'), has('linux') && has('unix')) + call assert_equal(has('mac'), has('mac') && has('unix')) + call assert_equal(has('qnx'), has('qnx') && has('unix')) + call assert_equal(has('sun'), has('sun') && has('unix')) + call assert_equal(has('win32'), has('win32') && !has('unix')) + call assert_equal(has('win32unix'), has('win32unix') && has('unix')) + + if has('unix') && executable('uname') + let uname = system('uname') + call assert_equal(uname =~? 'BeOS', has('beos')) + call assert_equal(uname =~? 'BSD\|DragonFly', has('bsd')) + call assert_equal(uname =~? 'HP-UX', has('hpux')) + call assert_equal(uname =~? 'Linux', has('linux')) + call assert_equal(uname =~? 'Darwin', has('mac')) + call assert_equal(uname =~? 'QNX', has('qnx')) + call assert_equal(uname =~? 'SunOS', has('sun')) + call assert_equal(uname =~? 'CYGWIN\|MSYS', has('win32unix')) + endif +endfunc diff --git a/src/testdir/test_ga.vim b/src/testdir/test_ga.vim new file mode 100644 index 0000000..ea3d211 --- /dev/null +++ b/src/testdir/test_ga.vim @@ -0,0 +1,33 @@ +" Test ga normal command, and :ascii Ex command. +func Do_ga(c) + call setline(1, a:c) + let l:a = execute("norm 1goga") + let l:b = execute("ascii") + call assert_equal(l:a, l:b) + return l:a +endfunc + +func Test_ga_command() + new + set display=uhex + call assert_equal("\nNUL", Do_ga('')) + call assert_equal("\n<<01>> 1, Hex 01, Oct 001, Digr SH", Do_ga("\x01")) + call assert_equal("\n<<09>> 9, Hex 09, Oct 011, Digr HT", Do_ga("\t")) + + set display= + call assert_equal("\nNUL", Do_ga('')) + call assert_equal("\n<^A> 1, Hex 01, Oct 001, Digr SH", Do_ga("\x01")) + call assert_equal("\n<^I> 9, Hex 09, Oct 011, Digr HT", Do_ga("\t")) + + call assert_equal("\n<e> 101, Hex 65, Octal 145", Do_ga('e')) + + " Test a few multi-bytes characters. + call assert_equal("\n<é> 233, Hex 00e9, Oct 351, Digr e'", Do_ga('é')) + call assert_equal("\n<ẻ> 7867, Hex 1ebb, Oct 17273, Digr e2", Do_ga('ẻ')) + + " Test with combining characters. + call assert_equal("\n<e> 101, Hex 65, Octal 145 < ́> 769, Hex 0301, Octal 1401", Do_ga("e\u0301")) + call assert_equal("\n<e> 101, Hex 65, Octal 145 < ́> 769, Hex 0301, Octal 1401 < ̱> 817, Hex 0331, Octal 1461", Do_ga("e\u0301\u0331")) + call assert_equal("\n<e> 101, Hex 65, Octal 145 < ́> 769, Hex 0301, Octal 1401 < ̱> 817, Hex 0331, Octal 1461 < ̸> 824, Hex 0338, Octal 1470", Do_ga("e\u0301\u0331\u0338")) + bwipe! +endfunc diff --git a/src/testdir/test_getcwd.vim b/src/testdir/test_getcwd.vim new file mode 100644 index 0000000..ca09878 --- /dev/null +++ b/src/testdir/test_getcwd.vim @@ -0,0 +1,112 @@ +func GetCwdInfo(win, tab) + let tab_changed = 0 + let mod = ":t" + if a:tab > 0 && a:tab != tabpagenr() + let tab_changed = 1 + exec "tabnext " . a:tab + endif + let bufname = fnamemodify(bufname(winbufnr(a:win)), mod) + if tab_changed + tabprevious + endif + if a:win == 0 && a:tab == 0 + let dirname = fnamemodify(getcwd(), mod) + let lflag = haslocaldir() + elseif a:tab == 0 + let dirname = fnamemodify(getcwd(a:win), mod) + let lflag = haslocaldir(a:win) + else + let dirname = fnamemodify(getcwd(a:win, a:tab), mod) + let lflag = haslocaldir(a:win, a:tab) + endif + return bufname . ' ' . dirname . ' ' . lflag +endfunc + +" Do all test in a separate window to avoid E211 when we recursively +" delete the Xtopdir directory during cleanup +function SetUp() + set visualbell + set nocp viminfo+=nviminfo + + " On windows a swapfile in Xtopdir prevents it from being cleaned up. + set noswapfile + + " On windows a stale "Xtopdir" directory may exist, remove it so that + " we start from a clean state. + call delete("Xtopdir", "rf") + new + call mkdir('Xtopdir') + cd Xtopdir + let g:topdir = getcwd() + call mkdir('Xdir1') + call mkdir('Xdir2') + call mkdir('Xdir3') +endfunction + +let g:cwd=getcwd() +function TearDown() + q + exec "cd " . g:cwd + call delete("Xtopdir", "rf") +endfunction + +function Test_GetCwd() + new a + new b + new c + 3wincmd w + lcd Xdir1 + call assert_equal("a Xdir1 1", GetCwdInfo(0, 0)) + call assert_equal(g:topdir, getcwd(-1)) + wincmd W + call assert_equal("b Xtopdir 0", GetCwdInfo(0, 0)) + call assert_equal(g:topdir, getcwd(-1)) + wincmd W + lcd Xdir3 + call assert_equal("c Xdir3 1", GetCwdInfo(0, 0)) + call assert_equal("a Xdir1 1", GetCwdInfo(bufwinnr("a"), 0)) + call assert_equal("b Xtopdir 0", GetCwdInfo(bufwinnr("b"), 0)) + call assert_equal("c Xdir3 1", GetCwdInfo(bufwinnr("c"), 0)) + call assert_equal(g:topdir, getcwd(-1)) + wincmd W + call assert_equal("a Xdir1 1", GetCwdInfo(bufwinnr("a"), tabpagenr())) + call assert_equal("b Xtopdir 0", GetCwdInfo(bufwinnr("b"), tabpagenr())) + call assert_equal("c Xdir3 1", GetCwdInfo(bufwinnr("c"), tabpagenr())) + call assert_equal(g:topdir, getcwd(-1)) + + tabnew x + new y + new z + 3wincmd w + call assert_equal("x Xtopdir 0", GetCwdInfo(0, 0)) + call assert_equal(g:topdir, getcwd(-1)) + wincmd W + lcd Xdir2 + call assert_equal("y Xdir2 1", GetCwdInfo(0, 0)) + call assert_equal(g:topdir, getcwd(-1)) + wincmd W + lcd Xdir3 + call assert_equal("z Xdir3 1", GetCwdInfo(0, 0)) + call assert_equal("x Xtopdir 0", GetCwdInfo(bufwinnr("x"), 0)) + call assert_equal("y Xdir2 1", GetCwdInfo(bufwinnr("y"), 0)) + call assert_equal("z Xdir3 1", GetCwdInfo(bufwinnr("z"), 0)) + call assert_equal(g:topdir, getcwd(-1)) + let tp_nr = tabpagenr() + tabrewind + call assert_equal("x Xtopdir 0", GetCwdInfo(3, tp_nr)) + call assert_equal("y Xdir2 1", GetCwdInfo(2, tp_nr)) + call assert_equal("z Xdir3 1", GetCwdInfo(1, tp_nr)) + call assert_equal(g:topdir, getcwd(-1)) +endfunc + +function Test_GetCwd_lcd_shellslash() + new + let root = fnamemodify('/', ':p') + exe 'lcd '.root + let cwd = getcwd() + if !exists('+shellslash') || &shellslash + call assert_equal(cwd[-1:], '/') + else + call assert_equal(cwd[-1:], '\') + endif +endfunc diff --git a/src/testdir/test_getvar.vim b/src/testdir/test_getvar.vim new file mode 100644 index 0000000..d6b6b69 --- /dev/null +++ b/src/testdir/test_getvar.vim @@ -0,0 +1,104 @@ +" Tests for getwinvar(), gettabvar() and gettabwinvar(). +func Test_var() + " Use strings to test for memory leaks. First, check that in an empty + " window, gettabvar() returns the correct value + let t:testvar='abcd' + call assert_equal('abcd', gettabvar(1, 'testvar')) + call assert_equal('abcd', gettabvar(1, 'testvar')) + + " test for getwinvar() + let w:var_str = "Dance" + let def_str = "Chance" + call assert_equal('Dance', getwinvar(1, 'var_str')) + call assert_equal('Dance', getwinvar(1, 'var_str', def_str)) + call assert_equal({'var_str': 'Dance'}, getwinvar(1, '')) + call assert_equal({'var_str': 'Dance'}, getwinvar(1, '', def_str)) + unlet w:var_str + call assert_equal('Chance', getwinvar(1, 'var_str', def_str)) + call assert_equal({}, getwinvar(1, '')) + call assert_equal({}, getwinvar(1, '', def_str)) + call assert_equal('', getwinvar(9, '')) + call assert_equal('Chance', getwinvar(9, '', def_str)) + call assert_equal(0, getwinvar(1, '&nu')) + call assert_equal(0, getwinvar(1, '&nu', 1)) + unlet def_str + + " test for gettabvar() + tabnew + tabnew + let t:var_list = [1, 2, 3] + let t:other = 777 + let def_list = [4, 5, 6, 7] + tabrewind + call assert_equal([1, 2, 3], gettabvar(3, 'var_list')) + call assert_equal([1, 2, 3], gettabvar(3, 'var_list', def_list)) + call assert_equal({'var_list': [1, 2, 3], 'other': 777}, gettabvar(3, '')) + call assert_equal({'var_list': [1, 2, 3], 'other': 777}, + \ gettabvar(3, '', def_list)) + + tablast + unlet t:var_list + tabrewind + call assert_equal([4, 5, 6, 7], gettabvar(3, 'var_list', def_list)) + call assert_equal('', gettabvar(9, '')) + call assert_equal([4, 5, 6, 7], gettabvar(9, '', def_list)) + call assert_equal('', gettabvar(3, '&nu')) + call assert_equal([4, 5, 6, 7], gettabvar(3, '&nu', def_list)) + unlet def_list + tabonly + + " test for gettabwinvar() + tabnew + tabnew + tabprev + split + split + wincmd w + vert split + wincmd w + let w:var_dict = {'dict': 'tabwin'} + let def_dict = {'dict2': 'newval'} + wincmd b + tabrewind + call assert_equal({'dict': 'tabwin'}, gettabwinvar(2, 3, 'var_dict')) + call assert_equal({'dict': 'tabwin'}, + \ gettabwinvar(2, 3, 'var_dict', def_dict)) + call assert_equal({'var_dict': {'dict': 'tabwin'}}, gettabwinvar(2, 3, '')) + call assert_equal({'var_dict': {'dict': 'tabwin'}}, + \ gettabwinvar(2, 3, '', def_dict)) + + tabnext + 3wincmd w + unlet w:var_dict + tabrewind + call assert_equal({'dict2': 'newval'}, + \ gettabwinvar(2, 3, 'var_dict', def_dict)) + call assert_equal({}, gettabwinvar(2, 3, '')) + call assert_equal({}, gettabwinvar(2, 3, '', def_dict)) + call assert_equal("", gettabwinvar(2, 9, '')) + call assert_equal({'dict2': 'newval'}, gettabwinvar(2, 9, '', def_dict)) + call assert_equal('', gettabwinvar(9, 3, '')) + call assert_equal({'dict2': 'newval'}, gettabwinvar(9, 3, '', def_dict)) + + unlet def_dict + + call assert_equal('', gettabwinvar(2, 3, '&nux')) + call assert_equal(1, gettabwinvar(2, 3, '&nux', 1)) + tabonly +endfunc + +" It was discovered that "gettabvar()" would fail if called from within the +" tabline when the user closed a window. This test confirms the fix. +func Test_gettabvar_in_tabline() + let t:var_str = 'value' + + set tabline=%{assert_equal('value',gettabvar(1,'var_str'))} + set showtabline=2 + + " Simulate the user opening a split (which becomes window #1) and then + " closing the split, which triggers the redrawing of the tabline. + leftabove split + redrawstatus! + close + redrawstatus! +endfunc diff --git a/src/testdir/test_gf.vim b/src/testdir/test_gf.vim new file mode 100644 index 0000000..c352379 --- /dev/null +++ b/src/testdir/test_gf.vim @@ -0,0 +1,61 @@ + +" This is a test if a URL is recognized by "gf", with the cursor before and +" after the "://". Also test ":\\". +func Test_gf_url() + enew! + call append(0, [ + \ "first test for URL://machine.name/tmp/vimtest2a and other text", + \ "second test for URL://machine.name/tmp/vimtest2b. And other text", + \ "third test for URL:\\\\machine.name\\vimtest2c and other text", + \ "fourth test for URL:\\\\machine.name\\tmp\\vimtest2d, and other text", + \ "fifth test for URL://machine.name/tmp?q=vim&opt=yes and other text", + \ ]) + call cursor(1,1) + call search("^first") + call search("tmp") + call assert_equal("URL://machine.name/tmp/vimtest2a", expand("<cfile>")) + call search("^second") + call search("URL") + call assert_equal("URL://machine.name/tmp/vimtest2b", expand("<cfile>")) + if has("ebcdic") + set isf=@,240-249,/,.,-,_,+,,,$,:,~,\ + else + set isf=@,48-57,/,.,-,_,+,,,$,:,~,\ + endif + call search("^third") + call search("name") + call assert_equal("URL:\\\\machine.name\\vimtest2c", expand("<cfile>")) + call search("^fourth") + call search("URL") + call assert_equal("URL:\\\\machine.name\\tmp\\vimtest2d", expand("<cfile>")) + + call search("^fifth") + call search("URL") + call assert_equal("URL://machine.name/tmp?q=vim&opt=yes", expand("<cfile>")) + + set isf&vim + enew! +endfunc + +func Test_gF() + new + call setline(1, ['111', '222', '333', '444']) + w! Xfile + close + new + set isfname-=: + call setline(1, ['one', 'Xfile:3', 'three']) + 2 + call assert_fails('normal gF', 'E37:') + call assert_equal(2, getcurpos()[1]) + w! Xfile2 + normal gF + call assert_equal('Xfile', bufname('%')) + call assert_equal(3, getcurpos()[1]) + + set isfname& + call delete('Xfile') + call delete('Xfile2') + bwipe Xfile + bwipe Xfile2 +endfunc diff --git a/src/testdir/test_glob2regpat.vim b/src/testdir/test_glob2regpat.vim new file mode 100644 index 0000000..e6e41f1 --- /dev/null +++ b/src/testdir/test_glob2regpat.vim @@ -0,0 +1,30 @@ +" Test glob2regpat() + +func Test_glob2regpat_invalid() + call assert_fails('call glob2regpat(1.33)', 'E806:') + call assert_fails('call glob2regpat("}")', 'E219:') + call assert_fails('call glob2regpat("{")', 'E220:') +endfunc + +func Test_glob2regpat_valid() + call assert_equal('^foo\.', glob2regpat('foo.*')) + call assert_equal('^foo.$', glob2regpat('foo?')) + call assert_equal('\.vim$', glob2regpat('*.vim')) + call assert_equal('^[abc]$', glob2regpat('[abc]')) + call assert_equal('^foo bar$', glob2regpat('foo\ bar')) + call assert_equal('^foo,bar$', glob2regpat('foo,bar')) + call assert_equal('^\(foo\|bar\)$', glob2regpat('{foo,bar}')) + call assert_equal('.*', glob2regpat('**')) + + if exists('+shellslash') + call assert_equal('^foo[\/].$', glob2regpat('foo\?')) + call assert_equal('^\(foo[\/]\|bar\|foobar\)$', glob2regpat('{foo\,bar,foobar}')) + call assert_equal('^[\/]\(foo\|bar[\/]\)$', glob2regpat('\{foo,bar\}')) + call assert_equal('^[\/][\/]\(foo\|bar[\/][\/]\)$', glob2regpat('\\{foo,bar\\}')) + else + call assert_equal('^foo?$', glob2regpat('foo\?')) + call assert_equal('^\(foo,bar\|foobar\)$', glob2regpat('{foo\,bar,foobar}')) + call assert_equal('^{foo,bar}$', glob2regpat('\{foo,bar\}')) + call assert_equal('^\\\(foo\|bar\\\)$', glob2regpat('\\{foo,bar\\}')) + endif +endfunc diff --git a/src/testdir/test_global.vim b/src/testdir/test_global.vim new file mode 100644 index 0000000..bdeaf8e --- /dev/null +++ b/src/testdir/test_global.vim @@ -0,0 +1,20 @@ + +func Test_yank_put_clipboard() + new + call setline(1, ['a', 'b', 'c']) + set clipboard=unnamed + g/^/normal yyp + call assert_equal(['a', 'a', 'b', 'b', 'c', 'c'], getline(1, 6)) + + set clipboard& + bwipe! +endfunc + +func Test_nested_global() + new + call setline(1, ['nothing', 'found', 'found bad', 'bad']) + call assert_fails('g/found/3v/bad/s/^/++/', 'E147') + g/found/v/bad/s/^/++/ + call assert_equal(['nothing', '++found', 'found bad', 'bad'], getline(1, 4)) + bwipe! +endfunc diff --git a/src/testdir/test_gn.vim b/src/testdir/test_gn.vim new file mode 100644 index 0000000..d0fdafc --- /dev/null +++ b/src/testdir/test_gn.vim @@ -0,0 +1,153 @@ +" Test for gn command + +func Test_gn_command() + noautocmd new + " replace a single char by itsself quoted: + call setline('.', 'abc x def x ghi x jkl') + let @/ = 'x' + exe "norm! cgn'x'\<esc>.." + call assert_equal("abc 'x' def 'x' ghi 'x' jkl", getline('.')) + sil! %d_ + + " simple search match + call setline('.', 'foobar') + let @/ = 'foobar' + exe "norm! gncsearchmatch" + call assert_equal('searchmatch', getline('.')) + sil! %d _ + + " replace a multi-line match + call setline('.', ['', 'one', 'two']) + let @/ = 'one\_s*two\_s' + exe "norm! gnceins\<CR>zwei" + call assert_equal(['','eins','zwei'], getline(1,'$')) + sil! %d _ + + " test count argument + call setline('.', ['', 'abcdx | abcdx | abcdx']) + let @/ = '[a]bcdx' + exe "norm! 2gnd" + call assert_equal(['','abcdx | | abcdx'], getline(1,'$')) + sil! %d _ + + " join lines + call setline('.', ['join ', 'lines']) + let @/ = '$' + exe "norm! 0gnd" + call assert_equal(['join lines'], getline(1,'$')) + sil! %d _ + + " zero-width match + call setline('.', ['', 'zero width pattern']) + let @/ = '\>\zs' + exe "norm! 0gnd" + call assert_equal(['', 'zerowidth pattern'], getline(1,'$')) + sil! %d _ + + " delete first and last chars + call setline('.', ['delete first and last chars']) + let @/ = '^' + exe "norm! 0gnd$" + let @/ = '\zs' + exe "norm! gnd" + call assert_equal(['elete first and last char'], getline(1,'$')) + sil! %d _ + + " using visual mode + call setline('.', ['', 'uniquepattern uniquepattern']) + exe "norm! /[u]niquepattern/s\<cr>vlgnd" + call assert_equal(['', ' uniquepattern'], getline(1,'$')) + sil! %d _ + + " backwards search + call setline('.', ['my very excellent mother just served us nachos']) + let @/ = 'mother' + exe "norm! $cgNmongoose" + call assert_equal(['my very excellent mongoose just served us nachos'], getline(1,'$')) + sil! %d _ + + " search for single char + call setline('.', ['','for (i=0; i<=10; i++)']) + let @/ = 'i' + exe "norm! cgnj" + call assert_equal(['','for (j=0; i<=10; i++)'], getline(1,'$')) + sil! %d _ + + " search hex char + call setline('.', ['','Y']) + set noignorecase + let @/ = '\%x59' + exe "norm! gnd" + call assert_equal(['',''], getline(1,'$')) + sil! %d _ + + " test repeating gdn + call setline('.', ['', '1', 'Johnny', '2', 'Johnny', '3']) + let @/ = 'Johnny' + exe "norm! dgn." + call assert_equal(['','1', '', '2', '', '3'], getline(1,'$')) + sil! %d _ + + " test repeating gUgn + call setline('.', ['', '1', 'Depp', '2', 'Depp', '3']) + let @/ = 'Depp' + exe "norm! gUgn." + call assert_equal(['', '1', 'DEPP', '2', 'DEPP', '3'], getline(1,'$')) + sil! %d _ + + " test using look-ahead assertions + call setline('.', ['a:10', '', 'a:1', '', 'a:20']) + let @/ = 'a:0\@!\zs\d\+' + exe "norm! 2nygno\<esc>p" + call assert_equal(['a:10', '', 'a:1', '1', '', 'a:20'], getline(1,'$')) + sil! %d _ + + " test using nowrapscan + set nowrapscan + call setline(1, 'foo bar baz') + exe "norm! /bar/e\<cr>" + exe "norm! gnd" + call assert_equal(['foo baz'], getline(1,'$')) + sil! %d_ + + " search upwards with nowrapscan set + call setline('.', ['foo', 'bar', 'foo', 'baz']) + set nowrapscan + let @/ = 'foo' + $ + norm! dgN + call assert_equal(['foo', 'bar', '', 'baz'], getline(1,'$')) + sil! %d_ + + " search using the \zs atom + call setline(1, [' nnoremap', '' , 'nnoremap']) + set wrapscan&vim + let @/ = '\_s\zsnnoremap' + $ + norm! cgnmatch + call assert_equal([' nnoremap', '', 'match'], getline(1,'$')) + sil! %d_ + + set wrapscan&vim +endfu + +func Test_gn_multi_line() + new + call setline(1, [ + \ 'func Tm1()', + \ ' echo "one"', + \ 'endfunc', + \ 'func Tm2()', + \ ' echo "two"', + \ 'endfunc', + \ 'func Tm3()', + \ ' echo "three"', + \ 'endfunc', + \]) + /\v^func Tm\d\(\)\n.*\zs".*"\ze$ + normal jgnrx + call assert_equal(' echo xxxxx', getline(5)) + bwipe! +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_goto.vim b/src/testdir/test_goto.vim new file mode 100644 index 0000000..c0235b1 --- /dev/null +++ b/src/testdir/test_goto.vim @@ -0,0 +1,373 @@ +" Test commands that jump somewhere. + +" Create a new buffer using "lines" and place the cursor on the word after the +" first occurrence of return and invoke "cmd". The cursor should now be +" positioned at the given line and col. +func XTest_goto_decl(cmd, lines, line, col) + new + call setline(1, a:lines) + /return/ + normal! W + execute 'norm! ' . a:cmd + call assert_equal(a:line, line('.')) + call assert_equal(a:col, col('.')) + quit! +endfunc + +func Test_gD() + let lines = [ + \ 'int x;', + \ '', + \ 'int func(void)', + \ '{', + \ ' return x;', + \ '}', + \ ] + call XTest_goto_decl('gD', lines, 1, 5) +endfunc + +func Test_gD_too() + let lines = [ + \ 'Filename x;', + \ '', + \ 'int Filename', + \ 'int func() {', + \ ' Filename x;', + \ ' return x;', + \ ] + call XTest_goto_decl('gD', lines, 1, 10) +endfunc + +func Test_gD_comment() + let lines = [ + \ '/* int x; */', + \ 'int x;', + \ '', + \ 'int func(void)', + \ '{', + \ ' return x;', + \ '}', + \ ] + call XTest_goto_decl('gD', lines, 2, 5) +endfunc + +func Test_gD_inline_comment() + let lines = [ + \ 'int y /* , x */;', + \ 'int x;', + \ '', + \ 'int func(void)', + \ '{', + \ ' return x;', + \ '}', + \ ] + call XTest_goto_decl('gD', lines, 2, 5) +endfunc + +func Test_gD_string() + let lines = [ + \ 'char *s[] = "x";', + \ 'int x = 1;', + \ '', + \ 'int func(void)', + \ '{', + \ ' return x;', + \ '}', + \ ] + call XTest_goto_decl('gD', lines, 2, 5) +endfunc + +func Test_gD_string_same_line() + let lines = [ + \ 'char *s[] = "x", int x = 1;', + \ '', + \ 'int func(void)', + \ '{', + \ ' return x;', + \ '}', + \ ] + call XTest_goto_decl('gD', lines, 1, 22) +endfunc + +func Test_gD_char() + let lines = [ + \ "char c = 'x';", + \ 'int x = 1;', + \ '', + \ 'int func(void)', + \ '{', + \ ' return x;', + \ '}', + \ ] + call XTest_goto_decl('gD', lines, 2, 5) +endfunc + +func Test_gd() + let lines = [ + \ 'int x;', + \ '', + \ 'int func(int x)', + \ '{', + \ ' return x;', + \ '}', + \ ] + call XTest_goto_decl('gd', lines, 3, 14) +endfunc + +func Test_gd_not_local() + let lines = [ + \ 'int func1(void)', + \ '{', + \ ' return x;', + \ '}', + \ '', + \ 'int func2(int x)', + \ '{', + \ ' return x;', + \ '}', + \ ] + call XTest_goto_decl('gd', lines, 3, 10) +endfunc + +func Test_gd_kr_style() + let lines = [ + \ 'int func(x)', + \ ' int x;', + \ '{', + \ ' return x;', + \ '}', + \ ] + call XTest_goto_decl('gd', lines, 2, 7) +endfunc + +func Test_gd_missing_braces() + let lines = [ + \ 'def func1(a)', + \ ' a + 1', + \ 'end', + \ '', + \ 'a = 1', + \ '', + \ 'def func2()', + \ ' return a', + \ 'end', + \ ] + call XTest_goto_decl('gd', lines, 1, 11) +endfunc + +func Test_gd_comment() + let lines = [ + \ 'int func(void)', + \ '{', + \ ' /* int x; */', + \ ' int x;', + \ ' return x;', + \ '}', + \] + call XTest_goto_decl('gd', lines, 4, 7) +endfunc + +func Test_gd_comment_in_string() + let lines = [ + \ 'int func(void)', + \ '{', + \ ' char *s ="//"; int x;', + \ ' int x;', + \ ' return x;', + \ '}', + \] + call XTest_goto_decl('gd', lines, 3, 22) +endfunc + +func Test_gd_string_in_comment() + set comments= + let lines = [ + \ 'int func(void)', + \ '{', + \ ' /* " */ int x;', + \ ' int x;', + \ ' return x;', + \ '}', + \] + call XTest_goto_decl('gd', lines, 3, 15) + set comments& +endfunc + +func Test_gd_inline_comment() + let lines = [ + \ 'int func(/* x is an int */ int x)', + \ '{', + \ ' return x;', + \ '}', + \ ] + call XTest_goto_decl('gd', lines, 1, 32) +endfunc + +func Test_gd_inline_comment_only() + let lines = [ + \ 'int func(void) /* one lonely x */', + \ '{', + \ ' return x;', + \ '}', + \ ] + call XTest_goto_decl('gd', lines, 3, 10) +endfunc + +func Test_gd_inline_comment_body() + let lines = [ + \ 'int func(void)', + \ '{', + \ ' int y /* , x */;', + \ '', + \ ' for (/* int x = 0 */; y < 2; y++);', + \ '', + \ ' int x = 0;', + \ '', + \ ' return x;', + \ '}', + \ ] + call XTest_goto_decl('gd', lines, 7, 7) +endfunc + +func Test_gd_trailing_multiline_comment() + let lines = [ + \ 'int func(int x) /* x is an int */', + \ '{', + \ ' return x;', + \ '}', + \ ] + call XTest_goto_decl('gd', lines, 1, 14) +endfunc + +func Test_gd_trailing_comment() + let lines = [ + \ 'int func(int x) // x is an int', + \ '{', + \ ' return x;', + \ '}', + \ ] + call XTest_goto_decl('gd', lines, 1, 14) +endfunc + +func Test_gd_string() + let lines = [ + \ 'int func(void)', + \ '{', + \ ' char *s = "x";', + \ ' int x = 1;', + \ '', + \ ' return x;', + \ '}', + \ ] + call XTest_goto_decl('gd', lines, 4, 7) +endfunc + +func Test_gd_string_only() + let lines = [ + \ 'int func(void)', + \ '{', + \ ' char *s = "x";', + \ '', + \ ' return x;', + \ '}', + \ ] + call XTest_goto_decl('gd', lines, 5, 10) +endfunc + +" Check that setting 'cursorline' does not change curswant +func Test_cursorline_keep_col() + new + call setline(1, ['long long long line', 'short line']) + normal ggfi + let pos = getcurpos() + normal j + set cursorline + normal k + call assert_equal(pos, getcurpos()) + bwipe! + set nocursorline +endfunc + +func Test_gd_local_block() + let lines = [ + \ ' int main()', + \ '{', + \ ' char *a = "NOT NULL";', + \ ' if(a)', + \ ' {', + \ ' char *b = a;', + \ ' printf("%s\n", b);', + \ ' }', + \ ' else', + \ ' {', + \ ' char *b = "NULL";', + \ ' return b;', + \ ' }', + \ '', + \ ' return 0;', + \ '}', + \ ] + call XTest_goto_decl('1gd', lines, 11, 11) +endfunc + +func Test_motion_if_elif_else_endif() + new + a +/* Test pressing % on #if, #else #elsif and #endif, + * with nested #if + */ +#if FOO +/* ... */ +# if BAR +/* ... */ +# endif +#elif BAR +/* ... */ +#else +/* ... */ +#endif +. + /#if FOO + norm % + call assert_equal([9, 1], getpos('.')[1:2]) + norm % + call assert_equal([11, 1], getpos('.')[1:2]) + norm % + call assert_equal([13, 1], getpos('.')[1:2]) + norm % + call assert_equal([4, 1], getpos('.')[1:2]) + /# if BAR + norm $% + call assert_equal([8, 1], getpos('.')[1:2]) + norm $% + call assert_equal([6, 1], getpos('.')[1:2]) + + bw! +endfunc + +func Test_motion_c_comment() + new + a +/* + * Test pressing % on beginning/end + * of C comments. + */ +/* Another comment */ +. + norm gg0% + call assert_equal([4, 3], getpos('.')[1:2]) + norm % + call assert_equal([1, 1], getpos('.')[1:2]) + norm gg0l% + call assert_equal([4, 3], getpos('.')[1:2]) + norm h% + call assert_equal([1, 1], getpos('.')[1:2]) + + norm G^ + norm % + call assert_equal([5, 21], getpos('.')[1:2]) + norm % + call assert_equal([5, 1], getpos('.')[1:2]) + + bw! +endfunc diff --git a/src/testdir/test_gui.vim b/src/testdir/test_gui.vim new file mode 100644 index 0000000..7874fff --- /dev/null +++ b/src/testdir/test_gui.vim @@ -0,0 +1,779 @@ +" Tests specifically for the GUI + +source shared.vim +if !CanRunGui() + finish +endif + +source setup_gui.vim + +func Setup() + call GUISetUpCommon() +endfunc + +func TearDown() + call GUITearDownCommon() +endfunc + +" Test for resetting "secure" flag after GUI has started. +" Must be run first, since it starts the GUI on Unix. +func Test_1_set_secure() + set exrc secure + gui -f + call assert_equal(1, has('gui_running')) +endfunc + +" As for non-GUI, a balloon_show() test was already added with patch 8.0.0401 +func Test_balloon_show() + if has('balloon_eval') + " This won't do anything but must not crash either. + call balloon_show('hi!') + endif +endfunc + +func Test_colorscheme() + let colorscheme_saved = exists('g:colors_name') ? g:colors_name : 'default' + let g:color_count = 0 + augroup TestColors + au! + au ColorScheme * let g:color_count += 1| let g:after_colors = g:color_count + au ColorSchemePre * let g:color_count += 1 |let g:before_colors = g:color_count + augroup END + + colorscheme torte + redraw! + call assert_equal('dark', &background) + call assert_equal(1, g:before_colors) + call assert_equal(2, g:after_colors) + call assert_equal("\ntorte", execute('colorscheme')) + + let a = substitute(execute('hi Search'), "\n\\s\\+", ' ', 'g') + call assert_match("\nSearch xxx term=reverse ctermfg=0 ctermbg=12 gui=bold guifg=Black guibg=Red", a) + + call assert_fails('colorscheme does_not_exist', 'E185:') + + exec 'colorscheme' colorscheme_saved + augroup TestColors + au! + augroup END + unlet g:color_count g:after_colors g:before_colors + redraw! +endfunc + +func Test_getfontname_with_arg() + let skipped = '' + + if !g:x11_based_gui + let skipped = g:not_implemented + elseif has('gui_athena') || has('gui_motif') + " Invalid font name. The result should be an empty string. + call assert_equal('', getfontname('notexist')) + + " Valid font name. This is usually the real name of 7x13 by default. + let fname = '-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1' + call assert_match(fname, getfontname(fname)) + + elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3') + " Invalid font name. The result should be the name plus the default size. + call assert_equal('notexist 10', getfontname('notexist')) + + " Valid font name. This is usually the real name of Monospace by default. + let fname = 'Bitstream Vera Sans Mono 12' + call assert_equal(fname, getfontname(fname)) + endif + + if !empty(skipped) + throw skipped + endif +endfunc + +func Test_getfontname_without_arg() + let skipped = '' + + let fname = getfontname() + + if !g:x11_based_gui + let skipped = g:not_implemented + elseif has('gui_kde') + " 'expected' is the value specified by SetUp() above. + call assert_equal('Courier 10 Pitch/8/-1/5/50/0/0/0/0/0', fname) + elseif has('gui_athena') || has('gui_motif') + " 'expected' is DFLT_FONT of gui_x11.c or its real name. + let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)' + call assert_match(pat, fname) + elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3') + " 'expected' is DEFAULT_FONT of gui_gtk_x11.c. + call assert_equal('Monospace 10', fname) + endif + + if !empty(skipped) + throw skipped + endif +endfunc + +func Test_getwinpos() + call assert_match('Window position: X \d\+, Y \d\+', execute('winpos')) + call assert_true(getwinposx() >= 0) + call assert_true(getwinposy() >= 0) + call assert_equal([getwinposx(), getwinposy()], getwinpos()) +endfunc + +func Test_quoteplus() + let skipped = '' + + if !g:x11_based_gui + let skipped = g:not_supported . 'quoteplus' + else + let quoteplus_saved = @+ + + let test_call = 'Can you hear me?' + let test_response = 'Yes, I can.' + let vim_exe = exepath(v:progpath) + let testee = 'VIMRUNTIME=' . $VIMRUNTIME . '; export VIMRUNTIME;' + \ . vim_exe + \ . ' -u NONE -U NONE --noplugin --not-a-term -c ''%s''' + " Ignore the "failed to create input context" error. + let cmd = 'call test_ignore_error("E285") | ' + \ . 'gui -f | ' + \ . 'call feedkeys("' + \ . '\"+p' + \ . ':s/' . test_call . '/' . test_response . '/\<CR>' + \ . '\"+yis' + \ . ':q!\<CR>", "tx")' + let run_vimtest = printf(testee, cmd) + + " Set the quoteplus register to test_call, and another gvim will launched. + " Then, it first tries to paste the content of its own quotedplus register + " onto it. Second, it tries to substitute test_response for the pasted + " sentence. If the sentence is identical to test_call, the substitution + " should succeed. Third, it tries to yank the result of the substitution + " to its own quoteplus register, and last it quits. When system() + " returns, the content of the quoteplus register should be identical to + " test_response if those quoteplus registers are synchronized properly + " with/through the X11 clipboard. + let @+ = test_call + call system(run_vimtest) + call assert_equal(test_response, @+) + + let @+ = quoteplus_saved + endif + + if !empty(skipped) + throw skipped + endif +endfunc + +func Test_set_background() + let background_saved = &background + + set background& + call assert_equal('light', &background) + + set background=dark + call assert_equal('dark', &background) + + let &background = background_saved +endfunc + +func Test_set_balloondelay() + if !exists('+balloondelay') + return + endif + + let balloondelay_saved = &balloondelay + + " Check if the default value is identical to that described in the manual. + set balloondelay& + call assert_equal(600, &balloondelay) + + " Edge cases + + " XXX This fact should be hidden so that people won't be tempted to write + " plugin/TimeMachine.vim. TODO Add reasonable range checks to the source + " code. + set balloondelay=-1 + call assert_equal(-1, &balloondelay) + + " Though it's possible to interpret the zero delay to be 'as soon as + " possible' or even 'indefinite', its actual meaning depends on the GUI + " toolkit in use after all. + set balloondelay=0 + call assert_equal(0, &balloondelay) + + set balloondelay=1 + call assert_equal(1, &balloondelay) + + " Since p_bdelay is of type long currently, the upper bound can be + " impractically huge and machine-dependent. Practically, it's sufficient + " to check if balloondelay works with 0x7fffffff (32 bits) for now. + set balloondelay=2147483647 + call assert_equal(2147483647, &balloondelay) + + let &balloondelay = balloondelay_saved +endfunc + +func Test_set_ballooneval() + if !exists('+ballooneval') + return + endif + + let ballooneval_saved = &ballooneval + + set ballooneval& + call assert_equal(0, &ballooneval) + + set ballooneval + call assert_notequal(0, &ballooneval) + + set noballooneval + call assert_equal(0, &ballooneval) + + let &ballooneval = ballooneval_saved +endfunc + +func Test_set_balloonexpr() + if !exists('+balloonexpr') + return + endif + + let balloonexpr_saved = &balloonexpr + + " Default value + set balloonexpr& + call assert_equal('', &balloonexpr) + + " User-defined function + new + func MyBalloonExpr() + return 'Cursor is at line ' . v:beval_lnum . + \', column ' . v:beval_col . + \ ' of file ' . bufname(v:beval_bufnr) . + \ ' on word "' . v:beval_text . '"' . + \ ' in window ' . v:beval_winid . ' (#' . v:beval_winnr . ')' + endfunc + setl balloonexpr=MyBalloonExpr() + setl ballooneval + call assert_equal('MyBalloonExpr()', &balloonexpr) + " TODO Read non-empty text, place the pointer at a character of a word, + " and check if the content of the balloon is the same as what is expected. + " Also, check if textlock works as expected. + setl balloonexpr& + call assert_equal('', &balloonexpr) + delfunc MyBalloonExpr + bwipe! + + " Multiline support + if has('balloon_multiline') + " Multiline balloon using NL + new + func MyBalloonFuncForMultilineUsingNL() + return "Multiline\nSuppported\nBalloon\nusing NL" + endfunc + setl balloonexpr=MyBalloonFuncForMultilineUsingNL() + setl ballooneval + call assert_equal('MyBalloonFuncForMultilineUsingNL()', &balloonexpr) + " TODO Read non-empty text, place the pointer at a character of a word, + " and check if the content of the balloon is the same as what is + " expected. Also, check if textlock works as expected. + setl balloonexpr& + delfunc MyBalloonFuncForMultilineUsingNL + bwipe! + + " Multiline balloon using List + new + func MyBalloonFuncForMultilineUsingList() + return [ 'Multiline', 'Suppported', 'Balloon', 'using List' ] + endfunc + setl balloonexpr=MyBalloonFuncForMultilineUsingList() + setl ballooneval + call assert_equal('MyBalloonFuncForMultilineUsingList()', &balloonexpr) + " TODO Read non-empty text, place the pointer at a character of a word, + " and check if the content of the balloon is the same as what is + " expected. Also, check if textlock works as expected. + setl balloonexpr& + delfunc MyBalloonFuncForMultilineUsingList + bwipe! + endif + + let &balloonexpr = balloonexpr_saved +endfunc + +" Invalid arguments are tested with test_options in conjunction with segfaults +" caused by them (Patch 8.0.0357, 24922ec233). +func Test_set_guicursor() + let guicursor_saved = &guicursor + + let default = [ + \ "n-v-c:block-Cursor/lCursor", + \ "ve:ver35-Cursor", + \ "o:hor50-Cursor", + \ "i-ci:ver25-Cursor/lCursor", + \ "r-cr:hor20-Cursor/lCursor", + \ "sm:block-Cursor-blinkwait175-blinkoff150-blinkon175" + \ ] + + " Default Value + set guicursor& + call assert_equal(join(default, ','), &guicursor) + + " Argument List Example 1 + let opt_list = copy(default) + let opt_list[0] = "n-c-v:block-nCursor" + exec "set guicursor=" . join(opt_list, ',') + call assert_equal(join(opt_list, ','), &guicursor) + unlet opt_list + + " Argument List Example 2 + let opt_list = copy(default) + let opt_list[3] = "i-ci:ver30-iCursor-blinkwait300-blinkon200-blinkoff150" + exec "set guicursor=" . join(opt_list, ',') + call assert_equal(join(opt_list, ','), &guicursor) + unlet opt_list + + " 'a' Mode + set guicursor& + let &guicursor .= ',a:blinkon0' + call assert_equal(join(default, ',') . ",a:blinkon0", &guicursor) + + let &guicursor = guicursor_saved +endfunc + +func Test_set_guifont() + let skipped = '' + + let guifont_saved = &guifont + if has('xfontset') + " Prevent 'guifontset' from canceling 'guifont'. + let guifontset_saved = &guifontset + set guifontset= + endif + + if !g:x11_based_gui + let skipped = g:not_implemented + elseif has('gui_athena') || has('gui_motif') + " Non-empty font list with invalid font names. + " + " This test is twofold: (1) It checks if the command fails as expected + " when there are no loadable fonts found in the list. (2) It checks if + " 'guifont' remains the same after the command loads none of the fonts + " listed. + let flist = &guifont + call assert_fails('set guifont=-notexist1-*,-notexist2-*') + call assert_equal(flist, &guifont) + + " Non-empty font list with a valid font name. Should pick up the first + " valid font. + set guifont=-notexist1-*,fixed,-notexist2-* + let pat = '\(fixed\)\|\(\c-Misc-Fixed-Medium-R-SemiCondensed--13-120-75-75-C-60-ISO8859-1\)' + call assert_match(pat, getfontname()) + + " Empty list. Should fallback to the built-in default. + set guifont= + let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)' + call assert_match(pat, getfontname()) + + elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3') + " For GTK, what we refer to as 'font names' in our manual are actually + " 'initial font patterns'. A valid font which matches the 'canonical font + " pattern' constructed from a given 'initial pattern' is to be looked up + " and loaded. That explains why the GTK GUIs appear to accept 'invalid + " font names'. + " + " Non-empty list. Should always pick up the first element, no matter how + " strange it is, as explained above. + set guifont=(´・ω・`)\ 12,Courier\ 12 + call assert_equal('(´・ω・`) 12', getfontname()) + + " Empty list. Should fallback to the built-in default. + set guifont= + call assert_equal('Monospace 10', getfontname()) + endif + + if has('xfontset') + let &guifontset = guifontset_saved + endif + let &guifont = guifont_saved + + if !empty(skipped) + throw skipped + endif +endfunc + +func Test_set_guifontset() + let skipped = '' + + if !has('xfontset') + let skipped = g:not_supported . 'xfontset' + else + let ctype_saved = v:ctype + + " First, since XCreateFontSet(3) is very sensitive to locale, fonts must + " be chosen meticulously. + let font_head = '-misc-fixed-medium-r-normal--14' + + let font_aw70 = font_head . '-130-75-75-c-70' + let font_aw140 = font_head . '-130-75-75-c-140' + + let font_jisx0201 = font_aw70 . '-jisx0201.1976-0' + let font_jisx0208 = font_aw140 . '-jisx0208.1983-0' + + let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',') + let short_XLFDs = join([ font_aw140, font_aw70 ], ',') + let singleton = font_head . '-*' + let aliases = 'k14,r14' + + " Second, among 'locales', look up such a locale that gets 'set + " guifontset=' to work successfully with every fontset specified with + " 'fontsets'. + let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ] + let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ] + + let feasible = 0 + for locale in locales + try + exec 'language ctype' locale + catch /^Vim\%((\a\+)\)\=:E197/ + continue + endtry + let done = 0 + for fontset in fontsets + try + exec 'set guifontset=' . fontset + catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/ + break + endtry + let done += 1 + endfor + if done == len(fontsets) + let feasible = 1 + break + endif + endfor + + " Third, give a set of tests if it is found feasible. + if !feasible + let skipped = g:not_hosted + else + " N.B. 'v:ctype' has already been set to an appropriate value in the + " previous loop. + for fontset in fontsets + exec 'set guifontset=' . fontset + call assert_equal(fontset, &guifontset) + endfor + endif + + " Finally, restore ctype. + exec 'language ctype' ctype_saved + endif + + if !empty(skipped) + throw skipped + endif +endfunc + +func Test_set_guifontwide() + let skipped = '' + + if !g:x11_based_gui + let skipped = g:not_implemented + elseif has('gui_gtk') + let guifont_saved = &guifont + let guifontwide_saved = &guifontwide + + let fc_match = exepath('fc-match') + if empty(fc_match) + let skipped = g:not_hosted + else + let &guifont = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=en') + let wide = system('fc-match -f "%{family[0]} %{size}" monospace:size=10:lang=ja') + exec 'set guifontwide=' . fnameescape(wide) + call assert_equal(wide, &guifontwide) + endif + + let &guifontwide = guifontwide_saved + let &guifont = guifont_saved + + elseif has('gui_athena') || has('gui_motif') + " guifontwide is premised upon the xfontset feature. + if !has('xfontset') + let skipped = g:not_supported . 'xfontset' + else + let encoding_saved = &encoding + let guifont_saved = &guifont + let guifontset_saved = &guifontset + let guifontwide_saved = &guifontwide + + let nfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-90-iso10646-1' + let wfont = '-misc-fixed-medium-r-normal-*-18-120-100-100-c-180-iso10646-1' + + set encoding=utf-8 + + " Case 1: guifontset is empty + set guifontset= + + " Case 1-1: Automatic selection + set guifontwide= + exec 'set guifont=' . nfont + call assert_equal(wfont, &guifontwide) + + " Case 1-2: Manual selection + exec 'set guifontwide=' . wfont + exec 'set guifont=' . nfont + call assert_equal(wfont, &guifontwide) + + " Case 2: guifontset is invalid + try + set guifontset=-*-notexist-* + call assert_report("'set guifontset=-*-notexist-*' should have failed") + catch + call assert_exception('E598') + endtry + " Set it to an invalid value brutally for preparation. + let &guifontset = '-*-notexist-*' + + " Case 2-1: Automatic selection + set guifontwide= + exec 'set guifont=' . nfont + call assert_equal(wfont, &guifontwide) + + " Case 2-2: Manual selection + exec 'set guifontwide=' . wfont + exec 'set guifont=' . nfont + call assert_equal(wfont, &guifontwide) + + let &guifontwide = guifontwide_saved + let &guifontset = guifontset_saved + let &guifont = guifont_saved + let &encoding = encoding_saved + endif + endif + + if !empty(skipped) + throw skipped + endif +endfunc + +func Test_set_guiheadroom() + let skipped = '' + + if !g:x11_based_gui + let skipped = g:not_supported . 'guiheadroom' + else + " Since this script is to be read together with '-U NONE', the default + " value must be preserved. + call assert_equal(50, &guiheadroom) + endif + + if !empty(skipped) + throw skipped + endif +endfunc + +func Test_set_guioptions() + let guioptions_saved = &guioptions + let duration = '200m' + + if has('win32') + " Default Value + set guioptions& + call assert_equal('egmrLtT', &guioptions) + + else + " Default Value + set guioptions& + call assert_equal('aegimrLtT', &guioptions) + + " To activate scrollbars of type 'L' or 'R'. + wincmd v + redraw! + + " Remove all default GUI ornaments + set guioptions-=T + exec 'sleep' . duration + call assert_equal('aegimrLt', &guioptions) + set guioptions-=t + exec 'sleep' . duration + call assert_equal('aegimrL', &guioptions) + set guioptions-=L + exec 'sleep' . duration + call assert_equal('aegimr', &guioptions) + set guioptions-=r + exec 'sleep' . duration + call assert_equal('aegim', &guioptions) + set guioptions-=m + exec 'sleep' . duration + call assert_equal('aegi', &guioptions) + + " Try non-default GUI ornaments + set guioptions+=l + exec 'sleep' . duration + call assert_equal('aegil', &guioptions) + set guioptions-=l + exec 'sleep' . duration + call assert_equal('aegi', &guioptions) + + set guioptions+=R + exec 'sleep' . duration + call assert_equal('aegiR', &guioptions) + set guioptions-=R + exec 'sleep' . duration + call assert_equal('aegi', &guioptions) + + set guioptions+=b + exec 'sleep' . duration + call assert_equal('aegib', &guioptions) + set guioptions+=h + exec 'sleep' . duration + call assert_equal('aegibh', &guioptions) + set guioptions-=h + exec 'sleep' . duration + call assert_equal('aegib', &guioptions) + set guioptions-=b + exec 'sleep' . duration + call assert_equal('aegi', &guioptions) + + set guioptions+=v + exec 'sleep' . duration + call assert_equal('aegiv', &guioptions) + set guioptions-=v + exec 'sleep' . duration + call assert_equal('aegi', &guioptions) + + if has('gui_motif') + set guioptions+=F + exec 'sleep' . duration + call assert_equal('aegiF', &guioptions) + set guioptions-=F + exec 'sleep' . duration + call assert_equal('aegi', &guioptions) + endif + + " Restore GUI ornaments to the default state. + set guioptions+=m + exec 'sleep' . duration + call assert_equal('aegim', &guioptions) + set guioptions+=r + exec 'sleep' . duration + call assert_equal('aegimr', &guioptions) + set guioptions+=L + exec 'sleep' . duration + call assert_equal('aegimrL', &guioptions) + set guioptions+=t + exec 'sleep' . duration + call assert_equal('aegimrLt', &guioptions) + set guioptions+=T + exec 'sleep' . duration + call assert_equal("aegimrLtT", &guioptions) + + wincmd o + redraw! + endif + + let &guioptions = guioptions_saved +endfunc + +func Test_scrollbars() + new + " buffer with 200 lines + call setline(1, repeat(['one', 'two'], 100)) + set guioptions+=rlb + + " scroll to move line 11 at top, moves the cursor there + call test_scrollbar('left', 10, 0) + redraw + call assert_equal(1, winline()) + call assert_equal(11, line('.')) + + " scroll to move line 1 at top, cursor stays in line 11 + call test_scrollbar('right', 0, 0) + redraw + call assert_equal(11, winline()) + call assert_equal(11, line('.')) + + set nowrap + call setline(11, repeat('x', 150)) + redraw + call assert_equal(1, wincol()) + call assert_equal(1, col('.')) + + " scroll to character 11, cursor is moved + call test_scrollbar('hor', 10, 0) + redraw + call assert_equal(1, wincol()) + call assert_equal(11, col('.')) + + set guioptions& + set wrap& + bwipe! +endfunc + +func Test_set_guipty() + let guipty_saved = &guipty + + " Default Value + set guipty& + call assert_equal(1, &guipty) + + set noguipty + call assert_equal(0, &guipty) + + let &guipty = guipty_saved +endfunc + +func Test_shell_command() + new + r !echo hello + call assert_equal('hello', substitute(getline(2), '\W', '', 'g')) + bwipe! +endfunc + +func Test_syntax_colortest() + runtime syntax/colortest.vim + redraw! + sleep 200m + bwipe! +endfunc + +func Test_set_term() + " It's enough to check the current value since setting 'term' to anything + " other than builtin_gui makes no sense at all. + call assert_equal('builtin_gui', &term) +endfunc + +func Test_windowid_variable() + if g:x11_based_gui || has('win32') + call assert_true(v:windowid > 0) + else + call assert_equal(0, v:windowid) + endif +endfunc + +" Test "vim -g" and also the GUIEnter autocommand. +func Test_gui_dash_g() + let cmd = GetVimCommand('Xscriptgui') + call writefile([""], "Xtestgui") + call writefile([ + \ 'au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")', + \ 'au GUIEnter * qall', + \ ], 'Xscriptgui') + call system(cmd . ' -g') + call WaitForAssert({-> assert_equal(['insertmode: 0'], readfile('Xtestgui'))}) + + call delete('Xscriptgui') + call delete('Xtestgui') +endfunc + +" Test "vim -7" and also the GUIEnter autocommand. +func Test_gui_dash_y() + let cmd = GetVimCommand('Xscriptgui') + call writefile([""], "Xtestgui") + call writefile([ + \ 'au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")', + \ 'au GUIEnter * qall', + \ ], 'Xscriptgui') + call system(cmd . ' -y') + call WaitForAssert({-> assert_equal(['insertmode: 1'], readfile('Xtestgui'))}) + + call delete('Xscriptgui') + call delete('Xtestgui') +endfunc diff --git a/src/testdir/test_gui_init.vim b/src/testdir/test_gui_init.vim new file mode 100644 index 0000000..638708f --- /dev/null +++ b/src/testdir/test_gui_init.vim @@ -0,0 +1,61 @@ +" Tests specifically for the GUI features/options that need to be set up at +" startup to take effect at runtime. + +source shared.vim +if !CanRunGui() + finish +endif + +source setup_gui.vim + +func Setup() + call GUISetUpCommon() +endfunc + +func TearDown() + call GUITearDownCommon() +endfunc + +" Ignore the "failed to create input context" error. +call test_ignore_error('E285:') + +" Start the GUI now, in the foreground. +gui -f + +func Test_set_guiheadroom() + let skipped = '' + + if !g:x11_based_gui + let skipped = g:not_supported . 'guiheadroom' + else + " The 'expected' value must be consistent with the value specified with + " gui_init.vim. + call assert_equal(0, &guiheadroom) + endif + + if !empty(skipped) + throw skipped + endif +endfunc + +func Test_set_guioptions_for_M() + sleep 200ms + " Check if the 'M' option is included. + call assert_match('.*M.*', &guioptions) +endfunc + +func Test_set_guioptions_for_p() + let skipped = '' + + if !g:x11_based_gui + let skipped = g:not_supported . '''p'' of guioptions' + else + sleep 200ms + " Check if the 'p' option is included. + call assert_match('.*p.*', &guioptions) + endif + + if !empty(skipped) + throw skipped + endif +endfunc diff --git a/src/testdir/test_hardcopy.vim b/src/testdir/test_hardcopy.vim new file mode 100644 index 0000000..ced13b1 --- /dev/null +++ b/src/testdir/test_hardcopy.vim @@ -0,0 +1,89 @@ +" Test :hardcopy + +func Test_printoptions_parsing() + " Only test that this doesn't throw an error. + set printoptions=left:5in,right:10pt,top:8mm,bottom:2pc + set printoptions=left:2in,top:30pt,right:16mm,bottom:3pc + set printoptions=header:3,syntax:y,number:7,wrap:n + set printoptions=duplex:short,collate:n,jobsplit:y,portrait:n + set printoptions=paper:10x14 + set printoptions=paper:A3 + set printoptions=paper:A4 + set printoptions=paper:A5 + set printoptions=paper:B4 + set printoptions=paper:B5 + set printoptions=paper:executive + set printoptions=paper:folio + set printoptions=paper:ledger + set printoptions=paper:legal + set printoptions=paper:letter + set printoptions=paper:quarto + set printoptions=paper:statement + set printoptions=paper:tabloid + set printoptions=formfeed:y + set printoptions= + set printoptions& + + call assert_fails('set printoptions=paper', 'E550:') + call assert_fails('set printoptions=shredder:on', 'E551:') + call assert_fails('set printoptions=left:no', 'E552:') +endfunc + +func Test_printmbfont_parsing() + " Only test that this doesn't throw an error. + set printmbfont=r:WadaMin-Regular,b:WadaMin-Bold,i:WadaMin-Italic,o:WadaMin-Bold-Italic,c:yes,a:no + set printmbfont= + set printmbfont& +endfunc + +func Test_printheader_parsing() + " Only test that this doesn't throw an error. + set printheader=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P + set printheader=%<%f%h%m%r%=%b\ 0x%B\ \ %l,%c%V\ %P + set printheader=%<%f%=\ [%1*%M%*%n%R%H]\ %-19(%3l,%02c%03V%)%O'%02b' + set printheader=...%r%{VarExists('b:gzflag','\ [GZ]')}%h... + set printheader= + set printheader& +endfunc + +" Test that :hardcopy produces a non-empty file. +" We don't check much of the contents. +func Test_with_syntax() + if has('postscript') + edit test_hardcopy.vim + set printoptions=syntax:y + syn on + hardcopy > Xhardcopy + let lines = readfile('Xhardcopy') + call assert_true(len(lines) > 20) + call assert_true(lines[0] =~ 'PS-Adobe') + call delete('Xhardcopy') + set printoptions& + endif +endfunc + +func Test_fname_with_spaces() + if !has('postscript') + return + endif + split t\ e\ s\ t.txt + call setline(1, ['just', 'some', 'text']) + hardcopy > %.ps + call assert_true(filereadable('t e s t.txt.ps')) + call delete('t e s t.txt.ps') + bwipe! +endfunc + +func Test_illegal_byte() + if !has('postscript') || &enc != 'utf-8' + return + endif + new + " conversion of 0xff will fail, this used to cause a crash + call setline(1, "\xff") + hardcopy >Xpstest + + bwipe! + call delete('Xpstest') +endfunc + diff --git a/src/testdir/test_help.vim b/src/testdir/test_help.vim new file mode 100644 index 0000000..c550ff0 --- /dev/null +++ b/src/testdir/test_help.vim @@ -0,0 +1,51 @@ +" Tests for :help + +func Test_help_restore_snapshot() + help + set buftype= + help + edit x + help + helpclose +endfunc + +func Test_help_errors() + call assert_fails('help doesnotexist', 'E149:') + call assert_fails('help!', 'E478:') + + new + set keywordprg=:help + call setline(1, " ") + call assert_fails('normal VK', 'E349:') + bwipe! +endfunc + +func Test_help_keyword() + new + set keywordprg=:help + call setline(1, " Visual ") + normal VK + call assert_match('^Visual mode', getline('.')) + call assert_equal('help', &ft) + close + bwipe! +endfunc + +func Test_help_local_additions() + call mkdir('Xruntime/doc', 'p') + call writefile(['*mydoc.txt* my awesome doc'], 'Xruntime/doc/mydoc.txt') + call writefile(['*mydoc-ext.txt* my extended awesome doc'], 'Xruntime/doc/mydoc-ext.txt') + let rtp_save = &rtp + set rtp+=./Xruntime + help + 1 + call search('mydoc.txt') + call assert_equal('|mydoc.txt| my awesome doc', getline('.')) + 1 + call search('mydoc-ext.txt') + call assert_equal('|mydoc-ext.txt| my extended awesome doc', getline('.')) + close + + call delete('Xruntime', 'rf') + let &rtp = rtp_save +endfunc diff --git a/src/testdir/test_help_tagjump.vim b/src/testdir/test_help_tagjump.vim new file mode 100644 index 0000000..46aa6a1 --- /dev/null +++ b/src/testdir/test_help_tagjump.vim @@ -0,0 +1,260 @@ +" Tests for :help! {subject} + +func Test_help_tagjump() + help + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ '\*help.txt\*') + helpclose + + help | + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ '\*bar\*') + helpclose + + help "* + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ '\*quotestar\*') + helpclose + + help sm?le + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ '\*:smile\*') + helpclose + + help :? + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ '\*:?\*') + helpclose + + help q? + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ '\*q?\*') + call assert_true(expand('<cword>') == 'q?') + helpclose + + help -? + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ '\*-?\*') + helpclose + + help v_g? + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ '\*v_g?\*') + helpclose + + help expr-!=? + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ '\*expr-!=?\*') + call assert_true(expand('<cword>') == 'expr-!=?') + helpclose + + help expr-isnot? + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ '\*expr-isnot?\*') + call assert_true(expand('<cword>') == 'expr-isnot?') + helpclose + + help FileW*Post + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ '\*FileWritePost\*') + helpclose + + help `ls` + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ '\*:ls\*') + helpclose + + help ^X + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ '\*CTRL-X\*') + helpclose + + help i_^_CTRL-D + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ '\*i_^_CTRL-D\*') + helpclose + + exec "help \<C-V>" + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ '\*CTRL-V\*') + helpclose + + + exec "help! ('textwidth'" + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ "\\*'textwidth'\\*") + helpclose + + exec "help! ('buflisted')," + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ "\\*'buflisted'\\*") + helpclose + + exec "help! abs({expr})" + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ '\*abs()\*') + helpclose + + exec "help! arglistid([{winnr}" + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ '\*arglistid()\*') + helpclose + + exec "help! 'autoindent'." + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ "\\*'autoindent'\\*") + helpclose + + exec "help! {address}." + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ '\*{address}\*') + helpclose + + exusage + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ '\*:index\*') + helpclose + + viusage + call assert_equal("help", &filetype) + call assert_true(getline('.') =~ '\*normal-index\*') + helpclose +endfunc + +let s:langs = ['en', 'ab', 'ja'] + +func s:doc_config_setup() + let s:helpfile_save = &helpfile + let &helpfile="Xdir1/doc-en/doc/testdoc.txt" + let s:rtp_save = &rtp + let &rtp="Xdir1/doc-en" + if has('multi_lang') + let s:helplang_save=&helplang + endif + + call delete('Xdir1', 'rf') + + for lang in s:langs + if lang ==# 'en' + let tagfname = 'tags' + let docfname = 'testdoc.txt' + else + let tagfname = 'tags-' . lang + let docfname = 'testdoc.' . lang . 'x' + endif + let docdir = "Xdir1/doc-" . lang . "/doc" + call mkdir(docdir, "p") + call writefile(["\t*test-char*", "\t*test-col*"], docdir . '/' . docfname) + call writefile(["test-char\t" . docfname . "\t/*test-char*", + \ "test-col\t" . docfname . "\t/*test-col*"], + \ docdir . '/' . tagfname) + endfor +endfunc + +func s:doc_config_teardown() + call delete('Xdir1', 'rf') + + let &helpfile = s:helpfile_save + let &rtp = s:rtp_save + if has('multi_lang') + let &helplang = s:helplang_save + endif +endfunc + +func s:get_help_compl_list(cmd) + return getcompletion(a:cmd, 'help') +endfunc + +func Test_help_complete() + try + let list = [] + call s:doc_config_setup() + + " 'helplang=' and help file lang is 'en' + if has('multi_lang') + set helplang= + endif + let list = s:get_help_compl_list("test") + call assert_equal(['test-col', 'test-char'], list) + + if has('multi_lang') + " 'helplang=ab' and help file lang is 'en' + set helplang=ab + let list = s:get_help_compl_list("test") + call assert_equal(['test-col', 'test-char'], list) + + " 'helplang=' and help file lang is 'en' and 'ab' + set rtp+=Xdir1/doc-ab + set helplang= + let list = s:get_help_compl_list("test") + call assert_equal(sort(['test-col@en', 'test-col@ab', + \ 'test-char@en', 'test-char@ab']), sort(list)) + + " 'helplang=ab' and help file lang is 'en' and 'ab' + set helplang=ab + let list = s:get_help_compl_list("test") + call assert_equal(sort(['test-col', 'test-col@en', + \ 'test-char', 'test-char@en']), sort(list)) + + " 'helplang=' and help file lang is 'en', 'ab' and 'ja' + set rtp+=Xdir1/doc-ja + set helplang= + let list = s:get_help_compl_list("test") + call assert_equal(sort(['test-col@en', 'test-col@ab', + \ 'test-col@ja', 'test-char@en', + \ 'test-char@ab', 'test-char@ja']), sort(list)) + + " 'helplang=ab' and help file lang is 'en', 'ab' and 'ja' + set helplang=ab + let list = s:get_help_compl_list("test") + call assert_equal(sort(['test-col', 'test-col@en', + \ 'test-col@ja', 'test-char', + \ 'test-char@en', 'test-char@ja']), sort(list)) + + " 'helplang=ab,ja' and help file lang is 'en', 'ab' and 'ja' + set helplang=ab,ja + let list = s:get_help_compl_list("test") + call assert_equal(sort(['test-col', 'test-col@ja', + \ 'test-col@en', 'test-char', + \ 'test-char@ja', 'test-char@en']), sort(list)) + endif + catch + call assert_exception('X') + finally + call s:doc_config_teardown() + endtry +endfunc + +func Test_help_respect_current_file_lang() + try + let list = [] + call s:doc_config_setup() + + if has('multi_lang') + function s:check_help_file_ext(help_keyword, ext) + exec 'help ' . a:help_keyword + call assert_equal(a:ext, expand('%:e')) + call feedkeys("\<C-]>", 'tx') + call assert_equal(a:ext, expand('%:e')) + pop + helpclose + endfunc + + set rtp+=Xdir1/doc-ab + set rtp+=Xdir1/doc-ja + + set helplang=ab + call s:check_help_file_ext('test-char', 'abx') + call s:check_help_file_ext('test-char@ja', 'jax') + set helplang=ab,ja + call s:check_help_file_ext('test-char@ja', 'jax') + call s:check_help_file_ext('test-char@en', 'txt') + endif + catch + call assert_exception('X') + finally + call s:doc_config_teardown() + endtry +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_hide.vim b/src/testdir/test_hide.vim new file mode 100644 index 0000000..128b8ff --- /dev/null +++ b/src/testdir/test_hide.vim @@ -0,0 +1,97 @@ +" Tests for :hide command/modifier and 'hidden' option + +function SetUp() + let s:save_hidden = &hidden + let s:save_bufhidden = &bufhidden + let s:save_autowrite = &autowrite + set nohidden + set bufhidden= + set noautowrite +endfunc + +function TearDown() + let &hidden = s:save_hidden + let &bufhidden = s:save_bufhidden + let &autowrite = s:save_autowrite +endfunc + +function Test_hide() + let orig_bname = bufname('') + let orig_winnr = winnr('$') + + new Xf1 + set modified + call assert_fails('edit Xf2') + bwipeout! Xf1 + + new Xf1 + set modified + edit! Xf2 + call assert_equal(['Xf2', 2], [bufname(''), winnr('$')]) + call assert_equal([1, 0], [buflisted('Xf1'), bufloaded('Xf1')]) + bwipeout! Xf1 + bwipeout! Xf2 + + new Xf1 + set modified + " :hide as a command + hide + call assert_equal([orig_bname, orig_winnr], [bufname(''), winnr('$')]) + call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')]) + bwipeout! Xf1 + + new Xf1 + set modified + " :hide as a command with trailing comment + hide " comment + call assert_equal([orig_bname, orig_winnr], [bufname(''), winnr('$')]) + call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')]) + bwipeout! Xf1 + + new Xf1 + set modified + " :hide as a command with bar + hide | new Xf2 " comment + call assert_equal(['Xf2', 2], [bufname(''), winnr('$')]) + call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')]) + bwipeout! Xf1 + bwipeout! Xf2 + + new Xf1 + set modified + " :hide as a modifier with trailing comment + hide edit Xf2 " comment + call assert_equal(['Xf2', 2], [bufname(''), winnr('$')]) + call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')]) + bwipeout! Xf1 + bwipeout! Xf2 + + new Xf1 + set modified + " To check that the bar is not recognized to separate commands + hide echo "one|two" + call assert_equal(['Xf1', 2], [bufname(''), winnr('$')]) + call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')]) + bwipeout! Xf1 + + " set hidden + new Xf1 + set hidden + set modified + edit Xf2 " comment + call assert_equal(['Xf2', 2], [bufname(''), winnr('$')]) + call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')]) + bwipeout! Xf1 + bwipeout! Xf2 + + " set hidden bufhidden=wipe + new Xf1 + set bufhidden=wipe + set modified + hide edit! Xf2 " comment + call assert_equal(['Xf2', 2], [bufname(''), winnr('$')]) + call assert_equal([0, 0], [buflisted('Xf1'), bufloaded('Xf1')]) + bwipeout! Xf2 +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_highlight.vim b/src/testdir/test_highlight.vim new file mode 100644 index 0000000..b37684c --- /dev/null +++ b/src/testdir/test_highlight.vim @@ -0,0 +1,554 @@ +" Tests for ":highlight" and highlighting. + +source view_util.vim +source screendump.vim + +func Test_highlight() + " basic test if ":highlight" doesn't crash + highlight + hi Search + + " test setting colors. + " test clearing one color and all doesn't generate error or warning + silent! hi NewGroup term=bold cterm=italic ctermfg=DarkBlue ctermbg=Grey gui= guifg=#00ff00 guibg=Cyan + silent! hi Group2 term= cterm= + hi Group3 term=underline cterm=bold + + let res = split(execute("hi NewGroup"), "\n")[0] + " filter ctermfg and ctermbg, the numbers depend on the terminal + let res = substitute(res, 'ctermfg=\d*', 'ctermfg=2', '') + let res = substitute(res, 'ctermbg=\d*', 'ctermbg=3', '') + call assert_equal("NewGroup xxx term=bold cterm=italic ctermfg=2 ctermbg=3", + \ res) + call assert_equal("Group2 xxx cleared", + \ split(execute("hi Group2"), "\n")[0]) + call assert_equal("Group3 xxx term=underline cterm=bold", + \ split(execute("hi Group3"), "\n")[0]) + + hi clear NewGroup + call assert_equal("NewGroup xxx cleared", + \ split(execute("hi NewGroup"), "\n")[0]) + call assert_equal("Group2 xxx cleared", + \ split(execute("hi Group2"), "\n")[0]) + hi Group2 NONE + call assert_equal("Group2 xxx cleared", + \ split(execute("hi Group2"), "\n")[0]) + hi clear + call assert_equal("Group3 xxx cleared", + \ split(execute("hi Group3"), "\n")[0]) + call assert_fails("hi Crash term='asdf", "E475:") +endfunc + +func HighlightArgs(name) + return 'hi ' . substitute(split(execute('hi ' . a:name), '\n')[0], '\<xxx\>', '', '') +endfunc + +func IsColorable() + return has('gui_running') || str2nr(&t_Co) >= 8 +endfunc + +func HiCursorLine() + let hiCursorLine = HighlightArgs('CursorLine') + if has('gui_running') + let guibg = matchstr(hiCursorLine, 'guibg=\w\+') + let hi_ul = 'hi CursorLine gui=underline guibg=NONE' + let hi_bg = 'hi CursorLine gui=NONE ' . guibg + else + let hi_ul = 'hi CursorLine cterm=underline ctermbg=NONE' + let hi_bg = 'hi CursorLine cterm=NONE ctermbg=Gray' + endif + return [hiCursorLine, hi_ul, hi_bg] +endfunc + +func Check_lcs_eol_attrs(attrs, row, col) + let save_lcs = &lcs + set list + + call assert_equal(a:attrs, ScreenAttrs(a:row, a:col)[0]) + + set nolist + let &lcs = save_lcs +endfunc + +func Test_highlight_eol_with_cursorline() + let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() + + call NewWindow('topleft 5', 20) + call setline(1, 'abcd') + call matchadd('Search', '\n') + + " expected: + " 'abcd ' + " ^^^^ ^^^^^ no highlight + " ^ 'Search' highlight + let attrs0 = ScreenAttrs(1, 10)[0] + call assert_equal(repeat([attrs0[0]], 4), attrs0[0:3]) + call assert_equal(repeat([attrs0[0]], 5), attrs0[5:9]) + call assert_notequal(attrs0[0], attrs0[4]) + + setlocal cursorline + + " underline + exe hi_ul + + " expected: + " 'abcd ' + " ^^^^ underline + " ^ 'Search' highlight with underline + " ^^^^^ underline + let attrs = ScreenAttrs(1, 10)[0] + call assert_equal(repeat([attrs[0]], 4), attrs[0:3]) + call assert_equal([attrs[4]] + repeat([attrs[5]], 5), attrs[4:9]) + call assert_notequal(attrs[0], attrs[4]) + call assert_notequal(attrs[4], attrs[5]) + call assert_notequal(attrs0[0], attrs[0]) + call assert_notequal(attrs0[4], attrs[4]) + call Check_lcs_eol_attrs(attrs, 1, 10) + + if IsColorable() + " bg-color + exe hi_bg + + " expected: + " 'abcd ' + " ^^^^ bg-color of 'CursorLine' + " ^ 'Search' highlight + " ^^^^^ bg-color of 'CursorLine' + let attrs = ScreenAttrs(1, 10)[0] + call assert_equal(repeat([attrs[0]], 4), attrs[0:3]) + call assert_equal(repeat([attrs[5]], 5), attrs[5:9]) + call assert_equal(attrs0[4], attrs[4]) + call assert_notequal(attrs[0], attrs[4]) + call assert_notequal(attrs[4], attrs[5]) + call assert_notequal(attrs0[0], attrs[0]) + call assert_notequal(attrs0[5], attrs[5]) + call Check_lcs_eol_attrs(attrs, 1, 10) + endif + + call CloseWindow() + exe hiCursorLine +endfunc + +func Test_highlight_eol_with_cursorline_vertsplit() + let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() + + call NewWindow('topleft 5', 5) + call setline(1, 'abcd') + call matchadd('Search', '\n') + + let expected = "abcd |abcd " + let actual = ScreenLines(1, 15)[0] + call assert_equal(expected, actual) + + " expected: + " 'abcd |abcd ' + " ^^^^ ^^^^^^^^^ no highlight + " ^ 'Search' highlight + " ^ 'VertSplit' highlight + let attrs0 = ScreenAttrs(1, 15)[0] + call assert_equal(repeat([attrs0[0]], 4), attrs0[0:3]) + call assert_equal(repeat([attrs0[0]], 9), attrs0[6:14]) + call assert_notequal(attrs0[0], attrs0[4]) + call assert_notequal(attrs0[0], attrs0[5]) + call assert_notequal(attrs0[4], attrs0[5]) + + setlocal cursorline + + " expected: + " 'abcd |abcd ' + " ^^^^ underline + " ^ 'Search' highlight with underline + " ^ 'VertSplit' highlight + " ^^^^^^^^^ no highlight + + " underline + exe hi_ul + + let actual = ScreenLines(1, 15)[0] + call assert_equal(expected, actual) + + let attrs = ScreenAttrs(1, 15)[0] + call assert_equal(repeat([attrs[0]], 4), attrs[0:3]) + call assert_equal(repeat([attrs[6]], 9), attrs[6:14]) + call assert_equal(attrs0[5:14], attrs[5:14]) + call assert_notequal(attrs[0], attrs[4]) + call assert_notequal(attrs[0], attrs[5]) + call assert_notequal(attrs[0], attrs[6]) + call assert_notequal(attrs[4], attrs[5]) + call assert_notequal(attrs[5], attrs[6]) + call assert_notequal(attrs0[0], attrs[0]) + call assert_notequal(attrs0[4], attrs[4]) + call Check_lcs_eol_attrs(attrs, 1, 15) + + if IsColorable() + " bg-color + exe hi_bg + + let actual = ScreenLines(1, 15)[0] + call assert_equal(expected, actual) + + let attrs = ScreenAttrs(1, 15)[0] + call assert_equal(repeat([attrs[0]], 4), attrs[0:3]) + call assert_equal(repeat([attrs[6]], 9), attrs[6:14]) + call assert_equal(attrs0[5:14], attrs[5:14]) + call assert_notequal(attrs[0], attrs[4]) + call assert_notequal(attrs[0], attrs[5]) + call assert_notequal(attrs[0], attrs[6]) + call assert_notequal(attrs[4], attrs[5]) + call assert_notequal(attrs[5], attrs[6]) + call assert_notequal(attrs0[0], attrs[0]) + call assert_equal(attrs0[4], attrs[4]) + call Check_lcs_eol_attrs(attrs, 1, 15) + endif + + call CloseWindow() + exe hiCursorLine +endfunc + +func Test_highlight_eol_with_cursorline_rightleft() + if !has('rightleft') + return + endif + + let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() + + call NewWindow('topleft 5', 10) + setlocal rightleft + call setline(1, 'abcd') + call matchadd('Search', '\n') + let attrs0 = ScreenAttrs(1, 10)[0] + + setlocal cursorline + + " underline + exe hi_ul + + " expected: + " ' dcba' + " ^^^^ underline + " ^ 'Search' highlight with underline + " ^^^^^ underline + let attrs = ScreenAttrs(1, 10)[0] + call assert_equal(repeat([attrs[9]], 4), attrs[6:9]) + call assert_equal(repeat([attrs[4]], 5) + [attrs[5]], attrs[0:5]) + call assert_notequal(attrs[9], attrs[5]) + call assert_notequal(attrs[4], attrs[5]) + call assert_notequal(attrs0[9], attrs[9]) + call assert_notequal(attrs0[5], attrs[5]) + call Check_lcs_eol_attrs(attrs, 1, 10) + + if IsColorable() + " bg-color + exe hi_bg + + " expected: + " ' dcba' + " ^^^^ bg-color of 'CursorLine' + " ^ 'Search' highlight + " ^^^^^ bg-color of 'CursorLine' + let attrs = ScreenAttrs(1, 10)[0] + call assert_equal(repeat([attrs[9]], 4), attrs[6:9]) + call assert_equal(repeat([attrs[4]], 5), attrs[0:4]) + call assert_equal(attrs0[5], attrs[5]) + call assert_notequal(attrs[9], attrs[5]) + call assert_notequal(attrs[5], attrs[4]) + call assert_notequal(attrs0[9], attrs[9]) + call assert_notequal(attrs0[4], attrs[4]) + call Check_lcs_eol_attrs(attrs, 1, 10) + endif + + call CloseWindow() + exe hiCursorLine +endfunc + +func Test_highlight_eol_with_cursorline_linewrap() + let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() + + call NewWindow('topleft 5', 10) + call setline(1, [repeat('a', 51) . 'bcd', '']) + call matchadd('Search', '\n') + + setlocal wrap + normal! gg$ + let attrs0 = ScreenAttrs(5, 10)[0] + setlocal cursorline + + " underline + exe hi_ul + + " expected: + " 'abcd ' + " ^^^^ underline + " ^ 'Search' highlight with underline + " ^^^^^ underline + let attrs = ScreenAttrs(5, 10)[0] + call assert_equal(repeat([attrs[0]], 4), attrs[0:3]) + call assert_equal([attrs[4]] + repeat([attrs[5]], 5), attrs[4:9]) + call assert_notequal(attrs[0], attrs[4]) + call assert_notequal(attrs[4], attrs[5]) + call assert_notequal(attrs0[0], attrs[0]) + call assert_notequal(attrs0[4], attrs[4]) + call Check_lcs_eol_attrs(attrs, 5, 10) + + if IsColorable() + " bg-color + exe hi_bg + + " expected: + " 'abcd ' + " ^^^^ bg-color of 'CursorLine' + " ^ 'Search' highlight + " ^^^^^ bg-color of 'CursorLine' + let attrs = ScreenAttrs(5, 10)[0] + call assert_equal(repeat([attrs[0]], 4), attrs[0:3]) + call assert_equal(repeat([attrs[5]], 5), attrs[5:9]) + call assert_equal(attrs0[4], attrs[4]) + call assert_notequal(attrs[0], attrs[4]) + call assert_notequal(attrs[4], attrs[5]) + call assert_notequal(attrs0[0], attrs[0]) + call assert_notequal(attrs0[5], attrs[5]) + call Check_lcs_eol_attrs(attrs, 5, 10) + endif + + setlocal nocursorline nowrap + normal! gg$ + let attrs0 = ScreenAttrs(1, 10)[0] + setlocal cursorline + + " underline + exe hi_ul + + " expected: + " 'aaabcd ' + " ^^^^^^ underline + " ^ 'Search' highlight with underline + " ^^^ underline + let attrs = ScreenAttrs(1, 10)[0] + call assert_equal(repeat([attrs[0]], 6), attrs[0:5]) + call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9]) + call assert_notequal(attrs[0], attrs[6]) + call assert_notequal(attrs[6], attrs[7]) + call assert_notequal(attrs0[0], attrs[0]) + call assert_notequal(attrs0[6], attrs[6]) + call Check_lcs_eol_attrs(attrs, 1, 10) + + if IsColorable() + " bg-color + exe hi_bg + + " expected: + " 'aaabcd ' + " ^^^^^^ bg-color of 'CursorLine' + " ^ 'Search' highlight + " ^^^ bg-color of 'CursorLine' + let attrs = ScreenAttrs(1, 10)[0] + call assert_equal(repeat([attrs[0]], 6), attrs[0:5]) + call assert_equal(repeat([attrs[7]], 3), attrs[7:9]) + call assert_equal(attrs0[6], attrs[6]) + call assert_notequal(attrs[0], attrs[6]) + call assert_notequal(attrs[6], attrs[7]) + call assert_notequal(attrs0[0], attrs[0]) + call assert_notequal(attrs0[7], attrs[7]) + call Check_lcs_eol_attrs(attrs, 1, 10) + endif + + call CloseWindow() + exe hiCursorLine +endfunc + +func Test_highlight_eol_with_cursorline_sign() + if !has('signs') + return + endif + + let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() + + call NewWindow('topleft 5', 10) + call setline(1, 'abcd') + call matchadd('Search', '\n') + + sign define Sign text=>> + exe 'sign place 1 line=1 name=Sign buffer=' . bufnr('') + let attrs0 = ScreenAttrs(1, 10)[0] + setlocal cursorline + + " underline + exe hi_ul + + " expected: + " '>>abcd ' + " ^^ sign + " ^^^^ underline + " ^ 'Search' highlight with underline + " ^^^ underline + let attrs = ScreenAttrs(1, 10)[0] + call assert_equal(repeat([attrs[2]], 4), attrs[2:5]) + call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9]) + call assert_notequal(attrs[2], attrs[6]) + call assert_notequal(attrs[6], attrs[7]) + call assert_notequal(attrs0[2], attrs[2]) + call assert_notequal(attrs0[6], attrs[6]) + call Check_lcs_eol_attrs(attrs, 1, 10) + + if IsColorable() + " bg-color + exe hi_bg + + " expected: + " '>>abcd ' + " ^^ sign + " ^^^^ bg-color of 'CursorLine' + " ^ 'Search' highlight + " ^^^ bg-color of 'CursorLine' + let attrs = ScreenAttrs(1, 10)[0] + call assert_equal(repeat([attrs[2]], 4), attrs[2:5]) + call assert_equal(repeat([attrs[7]], 3), attrs[7:9]) + call assert_equal(attrs0[6], attrs[6]) + call assert_notequal(attrs[2], attrs[6]) + call assert_notequal(attrs[6], attrs[7]) + call assert_notequal(attrs0[2], attrs[2]) + call assert_notequal(attrs0[7], attrs[7]) + call Check_lcs_eol_attrs(attrs, 1, 10) + endif + + sign unplace 1 + call CloseWindow() + exe hiCursorLine +endfunc + +func Test_highlight_eol_with_cursorline_breakindent() + if !has('linebreak') + return + endif + + let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() + + call NewWindow('topleft 5', 10) + setlocal breakindent breakindentopt=min:0,shift:1 showbreak=> + call setline(1, ' ' . repeat('a', 9) . 'bcd') + call matchadd('Search', '\n') + let attrs0 = ScreenAttrs(2, 10)[0] + setlocal cursorline + + " underline + exe hi_ul + + " expected: + " ' >bcd ' + " ^^^ breakindent and showbreak + " ^^^ underline + " ^ 'Search' highlight with underline + " ^^^ underline + let attrs = ScreenAttrs(2, 10)[0] + call assert_equal(repeat([attrs[0]], 2), attrs[0:1]) + call assert_equal(repeat([attrs[3]], 3), attrs[3:5]) + call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9]) + call assert_equal(attrs0[0], attrs[0]) + call assert_notequal(attrs[0], attrs[2]) + call assert_notequal(attrs[2], attrs[3]) + call assert_notequal(attrs[3], attrs[6]) + call assert_notequal(attrs[6], attrs[7]) + call assert_notequal(attrs0[2], attrs[2]) + call assert_notequal(attrs0[3], attrs[3]) + call assert_notequal(attrs0[6], attrs[6]) + call Check_lcs_eol_attrs(attrs, 2, 10) + + if IsColorable() + " bg-color + exe hi_bg + + " expected: + " ' >bcd ' + " ^^^ breakindent and showbreak + " ^^^ bg-color of 'CursorLine' + " ^ 'Search' highlight + " ^^^ bg-color of 'CursorLine' + let attrs = ScreenAttrs(2, 10)[0] + call assert_equal(repeat([attrs[0]], 2), attrs[0:1]) + call assert_equal(repeat([attrs[3]], 3), attrs[3:5]) + call assert_equal(repeat([attrs[7]], 3), attrs[7:9]) + call assert_equal(attrs0[0], attrs[0]) + call assert_equal(attrs0[6], attrs[6]) + call assert_notequal(attrs[0], attrs[2]) + call assert_notequal(attrs[2], attrs[3]) + call assert_notequal(attrs[3], attrs[6]) + call assert_notequal(attrs[6], attrs[7]) + call assert_notequal(attrs0[2], attrs[2]) + call assert_notequal(attrs0[3], attrs[3]) + call assert_notequal(attrs0[7], attrs[7]) + call Check_lcs_eol_attrs(attrs, 2, 10) + endif + + call CloseWindow() + set showbreak= + exe hiCursorLine +endfunc + +func Test_highlight_eol_on_diff() + call setline(1, ['abcd', '']) + call matchadd('Search', '\n') + let attrs0 = ScreenAttrs(1, 10)[0] + + diffthis + botright new + diffthis + + " expected: + " ' abcd ' + " ^^ sign + " ^^^^ ^^^ 'DiffAdd' highlight + " ^ 'Search' highlight + let attrs = ScreenAttrs(1, 10)[0] + call assert_equal(repeat([attrs[0]], 2), attrs[0:1]) + call assert_equal(repeat([attrs[2]], 4), attrs[2:5]) + call assert_equal(repeat([attrs[2]], 3), attrs[7:9]) + call assert_equal(attrs0[4], attrs[6]) + call assert_notequal(attrs[0], attrs[2]) + call assert_notequal(attrs[0], attrs[6]) + call assert_notequal(attrs[2], attrs[6]) + call Check_lcs_eol_attrs(attrs, 1, 10) + + bwipe! + diffoff +endfunc + +func Test_termguicolors() + if !exists('+termguicolors') + return + endif + if has('vtp') && !has('vcon') + " Win32: 'guicolors' doesn't work without virtual console. + call assert_fails('set termguicolors', 'E954:') + return + endif + + " Basic test that setting 'termguicolors' works with one color. + set termguicolors + redraw + set t_Co=1 + redraw + set t_Co=0 + redraw +endfunc + +func Test_cursorline_after_yank() + if !CanRunVimInTerminal() + return + endif + + call writefile([ + \ 'set cul rnu', + \ 'call setline(1, ["","1","2","3",""])', + \ ], 'Xtest_cursorline_yank') + let buf = RunVimInTerminal('-S Xtest_cursorline_yank', {'rows': 8}) + call term_wait(buf) + call term_sendkeys(buf, "Gy3k") + call term_wait(buf) + call term_sendkeys(buf, "jj") + + call VerifyScreenDump(buf, 'Test_cursorline_yank_01', {}) + + " clean up + call StopVimInTerminal(buf) + call delete('Xtest_cursorline_yank') +endfunc diff --git a/src/testdir/test_history.vim b/src/testdir/test_history.vim new file mode 100644 index 0000000..16aad98 --- /dev/null +++ b/src/testdir/test_history.vim @@ -0,0 +1,111 @@ +" Tests for the history functions + +if !has('cmdline_hist') + finish +endif + +set history=7 + +function History_Tests(hist) + " First clear the history + call histadd(a:hist, 'dummy') + call assert_true(histdel(a:hist)) + call assert_equal(-1, histnr(a:hist)) + call assert_equal('', histget(a:hist)) + + call assert_true(histadd(a:hist, 'ls')) + call assert_true(histadd(a:hist, 'buffers')) + call assert_equal('buffers', histget(a:hist)) + call assert_equal('ls', histget(a:hist, -2)) + call assert_equal('ls', histget(a:hist, 1)) + call assert_equal('', histget(a:hist, 5)) + call assert_equal('', histget(a:hist, -5)) + call assert_equal(2, histnr(a:hist)) + call assert_true(histdel(a:hist, 2)) + call assert_false(histdel(a:hist, 7)) + call assert_equal(1, histnr(a:hist)) + call assert_equal('ls', histget(a:hist, -1)) + + call assert_true(histadd(a:hist, 'buffers')) + call assert_true(histadd(a:hist, 'ls')) + call assert_equal('ls', histget(a:hist, -1)) + call assert_equal(4, histnr(a:hist)) + + let a=execute('history ' . a:hist) + call assert_match("^\n # \\S* history\n 3 buffers\n> 4 ls$", a) + let a=execute('history all') + call assert_match("^\n # .* history\n 3 buffers\n> 4 ls", a) + + if len(a:hist) > 0 + let a=execute('history ' . a:hist . ' 2') + call assert_match("^\n # \\S* history$", a) + let a=execute('history ' . a:hist . ' 3') + call assert_match("^\n # \\S* history\n 3 buffers$", a) + let a=execute('history ' . a:hist . ' 4') + call assert_match("^\n # \\S* history\n> 4 ls$", a) + let a=execute('history ' . a:hist . ' 3,4') + call assert_match("^\n # \\S* history\n 3 buffers\n> 4 ls$", a) + let a=execute('history ' . a:hist . ' -1') + call assert_match("^\n # \\S* history\n> 4 ls$", a) + let a=execute('history ' . a:hist . ' -2') + call assert_match("^\n # \\S* history\n 3 buffers$", a) + let a=execute('history ' . a:hist . ' -2,') + call assert_match("^\n # \\S* history\n 3 buffers\n> 4 ls$", a) + let a=execute('history ' . a:hist . ' -3') + call assert_match("^\n # \\S* history$", a) + endif + + " Test for removing entries matching a pattern + for i in range(1, 3) + call histadd(a:hist, 'text_' . i) + endfor + call assert_true(histdel(a:hist, 'text_\d\+')) + call assert_equal('ls', histget(a:hist, -1)) + + " Test for freeing the entire history list + for i in range(1, 7) + call histadd(a:hist, 'text_' . i) + endfor + call histdel(a:hist) + for i in range(1, 7) + call assert_equal('', histget(a:hist, i)) + call assert_equal('', histget(a:hist, i - 7 - 1)) + endfor +endfunction + +function Test_History() + for h in ['cmd', ':', '', 'search', '/', '?', 'expr', '=', 'input', '@', 'debug', '>'] + call History_Tests(h) + endfor + + " Negative tests + call assert_false(histdel('abc')) + call assert_equal('', histget('abc')) + call assert_fails('call histdel([])', 'E730:') + call assert_equal('', histget(10)) + call assert_fails('call histget([])', 'E730:') + call assert_equal(-1, histnr('abc')) + call assert_fails('call histnr([])', 'E730:') +endfunction + +function Test_Search_history_window() + new + call setline(1, ['a', 'b', 'a', 'b']) + 1 + call feedkeys("/a\<CR>", 'xt') + call assert_equal('a', getline('.')) + 1 + call feedkeys("/b\<CR>", 'xt') + call assert_equal('b', getline('.')) + 1 + " select the previous /a command + call feedkeys("q/kk\<CR>", 'x!') + call assert_equal('a', getline('.')) + call assert_equal('a', @/) + bwipe! +endfunc + +function Test_history_completion() + call feedkeys(":history \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"history / : = > ? @ all cmd debug expr input search', @:) +endfunc diff --git a/src/testdir/test_hlsearch.vim b/src/testdir/test_hlsearch.vim new file mode 100644 index 0000000..d4db4b7 --- /dev/null +++ b/src/testdir/test_hlsearch.vim @@ -0,0 +1,65 @@ +" Test for v:hlsearch + +func Test_hlsearch() + new + call setline(1, repeat(['aaa'], 10)) + set hlsearch nolazyredraw + " redraw is needed to make hlsearch highlight the matches + exe "normal! /aaa\<CR>" | redraw + let r1 = screenattr(1, 1) + nohlsearch | redraw + call assert_notequal(r1, screenattr(1,1)) + let v:hlsearch=1 | redraw + call assert_equal(r1, screenattr(1,1)) + let v:hlsearch=0 | redraw + call assert_notequal(r1, screenattr(1,1)) + set hlsearch | redraw + call assert_equal(r1, screenattr(1,1)) + let v:hlsearch=0 | redraw + call assert_notequal(r1, screenattr(1,1)) + exe "normal! n" | redraw + call assert_equal(r1, screenattr(1,1)) + let v:hlsearch=0 | redraw + call assert_notequal(r1, screenattr(1,1)) + exe "normal! /\<CR>" | redraw + call assert_equal(r1, screenattr(1,1)) + set nohls + exe "normal! /\<CR>" | redraw + call assert_notequal(r1, screenattr(1,1)) + call assert_fails('let v:hlsearch=[]', 'E745') + call garbagecollect(1) + call getchar(1) + enew! +endfunc + +func Test_hlsearch_hangs() + if !has('reltime') || !has('float') + return + endif + + " This pattern takes a long time to match, it should timeout. + new + call setline(1, ['aaa', repeat('abc ', 1000), 'ccc']) + let start = reltime() + set hlsearch nolazyredraw redrawtime=101 + let @/ = '\%#=1a*.*X\@<=b*' + redraw + let elapsed = reltimefloat(reltime(start)) + call assert_true(elapsed > 0.1) + call assert_true(elapsed < 1.0) + set nohlsearch redrawtime& + bwipe! +endfunc + +func Test_hlsearch_eol_highlight() + new + call append(1, repeat([''], 9)) + set hlsearch nolazyredraw + exe "normal! /$\<CR>" | redraw + let attr = screenattr(1, 1) + for row in range(2, 10) + call assert_equal(attr, screenattr(row, 1), 'in line ' . row) + endfor + set nohlsearch + bwipe! +endfunc diff --git a/src/testdir/test_iminsert.vim b/src/testdir/test_iminsert.vim new file mode 100644 index 0000000..1a8e4c8 --- /dev/null +++ b/src/testdir/test_iminsert.vim @@ -0,0 +1,27 @@ +source view_util.vim + +let s:imactivatefunc_called = 0 +let s:imstatusfunc_called = 0 + +func IM_activatefunc(active) + let s:imactivatefunc_called = 1 +endfunc + +func IM_statusfunc() + let s:imstatusfunc_called = 1 + return 0 +endfunc + +func Test_iminsert2() + set imactivatefunc=IM_activatefunc + set imstatusfunc=IM_statusfunc + set iminsert=2 + normal! i + set iminsert=0 + set imactivatefunc= + set imstatusfunc= + + let expected = has('gui_running') ? 0 : 1 + call assert_equal(expected, s:imactivatefunc_called) + call assert_equal(expected, s:imstatusfunc_called) +endfunc diff --git a/src/testdir/test_increment.vim b/src/testdir/test_increment.vim new file mode 100644 index 0000000..ad355dc --- /dev/null +++ b/src/testdir/test_increment.vim @@ -0,0 +1,781 @@ +" Tests for using Ctrl-A/Ctrl-X on visual selections + +func SetUp() + new dummy + set nrformats&vim +endfunc + +func TearDown() + bwipe! +endfunc + +" 1) Ctrl-A on visually selected number +" Text: +" foobar-10 +" Expected: +" 1) Ctrl-A on start of line: +" foobar-9 +" 2) Ctrl-A on visually selected "-10": +" foobar-9 +" 3) Ctrl-A on visually selected "10": +" foobar-11 +" 4) Ctrl-X on visually selected "-10" +" foobar-11 +" 5) Ctrl-X on visually selected "10" +" foobar-9 +func Test_visual_increment_01() + call setline(1, repeat(["foobaar-10"], 5)) + + call cursor(1, 1) + exec "norm! \<C-A>" + call assert_equal("foobaar-9", getline('.')) + call assert_equal([0, 1, 9, 0], getpos('.')) + + call cursor(2, 1) + exec "norm! f-v$\<C-A>" + call assert_equal("foobaar-9", getline('.')) + call assert_equal([0, 2, 8, 0], getpos('.')) + + call cursor(3, 1) + exec "norm! f1v$\<C-A>" + call assert_equal("foobaar-11", getline('.')) + call assert_equal([0, 3, 9, 0], getpos('.')) + + call cursor(4, 1) + exec "norm! f-v$\<C-X>" + call assert_equal("foobaar-11", getline('.')) + call assert_equal([0, 4, 8, 0], getpos('.')) + + call cursor(5, 1) + exec "norm! f1v$\<C-X>" + call assert_equal("foobaar-9", getline('.')) + call assert_equal([0, 5, 9, 0], getpos('.')) +endfunc + +" 2) Ctrl-A on visually selected lines +" Text: +" 10 +" 20 +" 30 +" 40 +" +" Expected: +" 1) Ctrl-A on visually selected lines: +" 11 +" 21 +" 31 +" 41 +" +" 2) Ctrl-X on visually selected lines: +" 9 +" 19 +" 29 +" 39 +func Test_visual_increment_02() + call setline(1, ["10", "20", "30", "40"]) + exec "norm! GV3k$\<C-A>" + call assert_equal(["11", "21", "31", "41"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) + + call setline(1, ["10", "20", "30", "40"]) + exec "norm! GV3k$\<C-X>" + call assert_equal(["9", "19", "29", "39"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 3) g Ctrl-A on visually selected lines, with non-numbers in between +" Text: +" 10 +" +" 20 +" +" 30 +" +" 40 +" +" Expected: +" 1) 2 g Ctrl-A on visually selected lines: +" 12 +" +" 24 +" +" 36 +" +" 48 +" 2) 2 g Ctrl-X on visually selected lines +" 8 +" +" 16 +" +" 24 +" +" 32 +func Test_visual_increment_03() + call setline(1, ["10", "", "20", "", "30", "", "40"]) + exec "norm! GV6k2g\<C-A>" + call assert_equal(["12", "", "24", "", "36", "", "48"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) + + call setline(1, ["10", "", "20", "", "30", "", "40"]) + exec "norm! GV6k2g\<C-X>" + call assert_equal(["8", "", "16", "", "24", "", "32"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 4) Ctrl-A on non-number +" Text: +" foobar-10 +" Expected: +" 1) visually select foobar: +" foobar-10 +func Test_visual_increment_04() + call setline(1, ["foobar-10"]) + exec "norm! vf-\<C-A>" + call assert_equal(["foobar-10"], getline(1, '$')) + " NOTE: I think this is correct behavior... + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 5) g<Ctrl-A> on letter +" Test: +" a +" a +" a +" a +" Expected: +" 1) g Ctrl-A on visually selected lines +" b +" c +" d +" e +func Test_visual_increment_05() + set nrformats+=alpha + call setline(1, repeat(["a"], 4)) + exec "norm! GV3kg\<C-A>" + call assert_equal(["b", "c", "d", "e"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 6) g<Ctrl-A> on letter +" Test: +" z +" z +" z +" z +" Expected: +" 1) g Ctrl-X on visually selected lines +" y +" x +" w +" v +func Test_visual_increment_06() + set nrformats+=alpha + call setline(1, repeat(["z"], 4)) + exec "norm! GV3kg\<C-X>" + call assert_equal(["y", "x", "w", "v"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 7) <Ctrl-A> on letter +" Test: +" 2 +" 1 +" 0 +" -1 +" -2 +" +" Expected: +" 1) Ctrl-A on visually selected lines +" 3 +" 2 +" 1 +" 0 +" -1 +" +" 2) Ctrl-X on visually selected lines +" 1 +" 0 +" -1 +" -2 +" -3 +func Test_visual_increment_07() + call setline(1, ["2", "1", "0", "-1", "-2"]) + exec "norm! GV4k\<C-A>" + call assert_equal(["3", "2", "1", "0", "-1"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) + + call setline(1, ["2", "1", "0", "-1", "-2"]) + exec "norm! GV4k\<C-X>" + call assert_equal(["1", "0", "-1", "-2", "-3"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 8) Block increment on 0x9 +" Text: +" 0x9 +" 0x9 +" Expected: +" 1) Ctrl-A on visually block selected region (cursor at beginning): +" 0xa +" 0xa +" 2) Ctrl-A on visually block selected region (cursor at end) +" 0xa +" 0xa +func Test_visual_increment_08() + call setline(1, repeat(["0x9"], 2)) + exec "norm! \<C-V>j$\<C-A>" + call assert_equal(["0xa", "0xa"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) + + call setline(1, repeat(["0x9"], 2)) + exec "norm! gg$\<C-V>+\<C-A>" + call assert_equal(["0xa", "0xa"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 9) Increment and redo +" Text: +" 2 +" 2 +" +" 3 +" 3 +" +" Expected: +" 1) 2 Ctrl-A on first 2 visually selected lines +" 4 +" 4 +" 2) redo (.) on 3 +" 5 +" 5 +func Test_visual_increment_09() + call setline(1, ["2", "2", "", "3", "3", ""]) + exec "norm! ggVj2\<C-A>" + call assert_equal(["4", "4", "", "3", "3", ""], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) + + exec "norm! 3j." + call assert_equal(["4", "4", "", "5", "5", ""], getline(1, '$')) + call assert_equal([0, 4, 1, 0], getpos('.')) +endfunc + +" 10) sequentially decrement 1 +" Text: +" 1 +" 1 +" 1 +" 1 +" Expected: +" 1) g Ctrl-X on visually selected lines +" 0 +" -1 +" -2 +" -3 +func Test_visual_increment_10() + call setline(1, repeat(["1"], 4)) + exec "norm! GV3kg\<C-X>" + call assert_equal(["0", "-1", "-2", "-3"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 11) visually block selected indented lines +" Text: +" 1 +" 1 +" 1 +" 1 +" Expexted: +" 1) g Ctrl-A on block selected indented lines +" 2 +" 1 +" 3 +" 4 +func Test_visual_increment_11() + call setline(1, [" 1", "1", " 1", " 1"]) + exec "norm! f1\<C-V>3jg\<C-A>" + call assert_equal([" 2", "1", " 3", " 4"], getline(1, '$')) + call assert_equal([0, 1, 5, 0], getpos('.')) +endfunc + +" 12) visually selected several columns +" Text: +" 0 0 +" 0 0 +" 0 0 +" Expected: +" 1) 'v' select last zero and first zeroes +" 0 1 +" 1 0 +" 1 0 +func Test_visual_increment_12() + call setline(1, repeat(["0 0"], 3)) + exec "norm! $v++\<C-A>" + call assert_equal(["0 1", "1 0", "1 0"], getline(1, '$')) + call assert_equal([0, 1, 3, 0], getpos('.')) +endfunc + +" 13) visually selected part of columns +" Text: +" max: 100px +" max: 200px +" max: 300px +" max: 400px +" Expected: +" 1) 'v' on first two numbers Ctrl-A +" max: 110px +" max: 220px +" max: 330px +" max: 400px +" 2) 'v' on first two numbers Ctrl-X +" max: 90px +" max: 190px +" max: 290px +" max: 400px +func Test_visual_increment_13() + call setline(1, ["max: 100px", "max: 200px", "max: 300px", "max: 400px"]) + exec "norm! f1\<C-V>l2j\<C-A>" + call assert_equal(["max: 110px", "max: 210px", "max: 310px", "max: 400px"], getline(1, '$')) + call assert_equal([0, 1, 6, 0], getpos('.')) + + call setline(1, ["max: 100px", "max: 200px", "max: 300px", "max: 400px"]) + exec "norm! ggf1\<C-V>l2j\<C-X>" + call assert_equal(["max: 90px", "max: 190px", "max: 290px", "max: 400px"], getline(1, '$')) + call assert_equal([0, 1, 6, 0], getpos('.')) +endfunc + +" 14) redo in block mode +" Text: +" 1 1 +" 1 1 +" Expected: +" 1) Ctrl-a on first column, redo on second column +" 2 2 +" 2 2 +func Test_visual_increment_14() + call setline(1, repeat(["1 1"], 2)) + exec "norm! G\<C-V>k\<C-A>w." + call assert_equal(["2 2", "2 2"], getline(1, '$')) + call assert_equal([0, 1, 3, 0], getpos('.')) +endfunc + +" 15) block select single numbers +" Text: +" 101 +" Expected: +" 1) Ctrl-a on visually selected zero +" 111 +" +" Also: 019 with "01" selected increments to "029". +func Test_visual_increment_15() + call setline(1, ["101"]) + exec "norm! lv\<C-A>" + call assert_equal(["111"], getline(1, '$')) + call assert_equal([0, 1, 2, 0], getpos('.')) + + call setline(1, ["019"]) + exec "norm! 0vl\<C-A>" + call assert_equal("029", getline(1)) + + call setline(1, ["01239"]) + exec "norm! 0vlll\<C-A>" + call assert_equal("01249", getline(1)) + + call setline(1, ["01299"]) + exec "norm! 0vlll\<C-A>" + call assert_equal("1309", getline(1)) +endfunc + +" 16) increment right aligned numbers +" Text: +" 1 +" 19 +" 119 +" Expected: +" 1) Ctrl-a on line selected region +" 2 +" 20 +" 120 +func Test_visual_increment_16() + call setline(1, [" 1", " 19", " 119"]) + exec "norm! VG\<C-A>" + call assert_equal([" 2", " 20", " 120"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 17) block-wise increment and redo +" Text: +" 100 +" 1 +" +" 100 +" 1 +" +" Expected: +" 1) Ctrl-V j $ on first block, afterwards '.' on second +" 101 +" 2 +" +" 101 +" 2 +func Test_visual_increment_17() + call setline(1, [" 100", " 1", "", " 100", " 1"]) + exec "norm! \<C-V>j$\<C-A>2j." + call assert_equal([" 101", " 2", "", " 101", " 1"], getline(1, '$')) + call assert_equal([0, 3, 1, 0], getpos('.')) +endfunc + +" 18) repeat of g<Ctrl-a> +" Text: +" 0 +" 0 +" 0 +" 0 +" +" Expected: +" 1) V 4j g<ctrl-a>, repeat twice afterwards with . +" 3 +" 6 +" 9 +" 12 +func Test_visual_increment_18() + call setline(1, repeat(["0"], 4)) + exec "norm! GV3kg\<C-A>" + exec "norm! .." + call assert_equal(["3", "6", "9", "12"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 19) increment on number with nrformat including alpha +" Text: +" 1 +" 1a +" +" Expected: +" 1) <Ctrl-V>j$ <ctrl-a> +" 2 +" 2a +func Test_visual_increment_19() + set nrformats+=alpha + call setline(1, ["1", "1a"]) + exec "norm! \<C-V>G$\<C-A>" + call assert_equal(["2", "2a"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 20) increment a single letter +" Text: +" a +" +" Expected: +" 1) <Ctrl-a> and cursor is on a +" b +func Test_visual_increment_20() + set nrformats+=alpha + call setline(1, ["a"]) + exec "norm! \<C-A>" + call assert_equal(["b"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 21) block-wise increment on part of hexadecimal +" Text: +" 0x123456 +" +" Expected: +" 1) Ctrl-V f3 <ctrl-a> +" 0x124456 +func Test_visual_increment_21() + call setline(1, ["0x123456"]) + exec "norm! \<C-V>f3\<C-A>" + call assert_equal(["0x124456"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 22) Block increment on 0b0 +" Text: +" 0b1 +" 0b1 +" Expected: +" 1) Ctrl-A on visually block selected region (cursor at beginning): +" 0b10 +" 0b10 +" 2) Ctrl-A on visually block selected region (cursor at end) +" 0b10 +" 0b10 +func Test_visual_increment_22() + call setline(1, repeat(["0b1"], 2)) + exec "norm! \<C-V>j$\<C-A>" + call assert_equal(repeat(["0b10"], 2), getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) + + call setline(1, repeat(["0b1"], 2)) + exec "norm! $\<C-V>+\<C-A>" + call assert_equal(repeat(["0b10"], 2), getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 23) block-wise increment on part of binary +" Text: +" 0b1001 +" +" Expected: +" 1) Ctrl-V 5l <ctrl-a> +" 0b1011 +func Test_visual_increment_23() + call setline(1, ["0b1001"]) + exec "norm! \<C-V>4l\<C-A>" + call assert_equal(["0b1011"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 24) increment hexadecimal +" Text: +" 0x0b1001 +" +" Expected: +" 1) <ctrl-a> +" 0x0b1002 +func Test_visual_increment_24() + call setline(1, ["0x0b1001"]) + exec "norm! \<C-V>$\<C-A>" + call assert_equal(["0x0b1002"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 25) increment binary with nrformats including alpha +" Text: +" 0b1001a +" +" Expected: +" 1) <ctrl-a> +" 0b1010a +func Test_visual_increment_25() + set nrformats+=alpha + call setline(1, ["0b1001a"]) + exec "norm! \<C-V>$\<C-A>" + call assert_equal(["0b1010a"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" 26) increment binary with 32 bits +" Text: +" 0b11111111111111111111111111111110 +" +" Expected: +" 1) <ctrl-a> +" 0b11111111111111111111111111111111 +func Test_visual_increment_26() + set nrformats+=alpha + call setline(1, ["0b11111111111111111111111111111110"]) + exec "norm! \<C-V>$\<C-A>" + call assert_equal(["0b11111111111111111111111111111111"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) + set nrformats-=alpha +endfunc + +" 27) increment with 'rightreft', if supported +func Test_visual_increment_27() + if exists('+rightleft') + set rightleft + call setline(1, ["1234 56"]) + + exec "norm! $\<C-A>" + call assert_equal(["1234 57"], getline(1, '$')) + call assert_equal([0, 1, 7, 0], getpos('.')) + + exec "norm! \<C-A>" + call assert_equal(["1234 58"], getline(1, '$')) + call assert_equal([0, 1, 7, 0], getpos('.')) + set norightleft + endif +endfunc + +" Tab code and linewise-visual inc/dec +func Test_visual_increment_28() + call setline(1, ["x\<TAB>10", "\<TAB>-1"]) + exec "norm! Vj\<C-A>" + call assert_equal(["x\<TAB>11", "\<TAB>0"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) + + call setline(1, ["x\<TAB>10", "\<TAB>-1"]) + exec "norm! ggVj\<C-X>" + call assert_equal(["x\<TAB>9", "\<TAB>-2"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" Tab code and linewise-visual inc/dec with 'nrformats'+=alpha +func Test_visual_increment_29() + set nrformats+=alpha + call setline(1, ["x\<TAB>10", "\<TAB>-1"]) + exec "norm! Vj\<C-A>" + call assert_equal(["y\<TAB>10", "\<TAB>0"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) + + call setline(1, ["x\<TAB>10", "\<TAB>-1"]) + exec "norm! ggVj\<C-X>" + call assert_equal(["w\<TAB>10", "\<TAB>-2"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" Tab code and character-visual inc/dec +func Test_visual_increment_30() + call setline(1, ["x\<TAB>10", "\<TAB>-1"]) + exec "norm! f1vjf1\<C-A>" + call assert_equal(["x\<TAB>11", "\<TAB>0"], getline(1, '$')) + call assert_equal([0, 1, 3, 0], getpos('.')) + + call setline(1, ["x\<TAB>10", "\<TAB>-1"]) + exec "norm! ggf1vjf1\<C-X>" + call assert_equal(["x\<TAB>9", "\<TAB>-2"], getline(1, '$')) + call assert_equal([0, 1, 3, 0], getpos('.')) +endfunc + +" Tab code and blockwise-visual inc/dec +func Test_visual_increment_31() + call setline(1, ["x\<TAB>10", "\<TAB>-1"]) + exec "norm! f1\<C-V>jl\<C-A>" + call assert_equal(["x\<TAB>11", "\<TAB>0"], getline(1, '$')) + call assert_equal([0, 1, 3, 0], getpos('.')) + + call setline(1, ["x\<TAB>10", "\<TAB>-1"]) + exec "norm! ggf1\<C-V>jl\<C-X>" + call assert_equal(["x\<TAB>9", "\<TAB>-2"], getline(1, '$')) + call assert_equal([0, 1, 3, 0], getpos('.')) +endfunc + +" Tab code and blockwise-visual decrement with 'linebreak' and 'showbreak' +func Test_visual_increment_32() + 28vnew dummy_31 + set linebreak showbreak=+ + call setline(1, ["x\<TAB>\<TAB>\<TAB>10", "\<TAB>\<TAB>\<TAB>\<TAB>-1"]) + exec "norm! ggf0\<C-V>jg_\<C-X>" + call assert_equal(["x\<TAB>\<TAB>\<TAB>1-1", "\<TAB>\<TAB>\<TAB>\<TAB>-2"], getline(1, '$')) + call assert_equal([0, 1, 6, 0], getpos('.')) + bwipe! +endfunc + +" Tab code and blockwise-visual increment with $ +func Test_visual_increment_33() + call setline(1, ["\<TAB>123", "456"]) + exec "norm! gg0\<C-V>j$\<C-A>" + call assert_equal(["\<TAB>124", "457"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" Tab code and blockwise-visual increment and redo +func Test_visual_increment_34() + call setline(1, ["\<TAB>123", " 456789"]) + exec "norm! gg0\<C-V>j\<C-A>" + call assert_equal(["\<TAB>123", " 457789"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) + + exec "norm! .." + call assert_equal(["\<TAB>123", " 459789"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" Tab code, spaces and character-visual increment and redo +func Test_visual_increment_35() + call setline(1, ["\<TAB>123", " 123", "\<TAB>123", "\<TAB>123"]) + exec "norm! ggvjf3\<C-A>..." + call assert_equal(["\<TAB>127", " 127", "\<TAB>123", "\<TAB>123"], getline(1, '$')) + call assert_equal([0, 1, 2, 0], getpos('.')) +endfunc + +" Tab code, spaces and blockwise-visual increment and redo +func Test_visual_increment_36() + call setline(1, [" 123", "\<TAB>456789"]) + exec "norm! G0\<C-V>kl\<C-A>" + call assert_equal([" 123", "\<TAB>556789"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) + + exec "norm! ..." + call assert_equal([" 123", "\<TAB>856789"], getline(1, '$')) + call assert_equal([0, 1, 1, 0], getpos('.')) +endfunc + +" block-wise increment and dot-repeat +" Text: +" 1 23 +" 4 56 +" +" Expected: +" 1) f2 Ctrl-V jl <ctrl-a>, repeat twice afterwards with . +" 1 26 +" 4 59 +" +" Try with and without indent. +func Test_visual_increment_37() + call setline(1, [" 1 23", " 4 56"]) + exec "norm! ggf2\<C-V>jl\<C-A>.." + call assert_equal([" 1 26", " 4 59"], getline(1, 2)) + + call setline(1, ["1 23", "4 56"]) + exec "norm! ggf2\<C-V>jl\<C-A>.." + call assert_equal(["1 26", "4 59"], getline(1, 2)) +endfunc + +" Check redo after the normal mode increment +func Test_visual_increment_38() + exec "norm! i10\<ESC>5\<C-A>." + call assert_equal(["20"], getline(1, '$')) + call assert_equal([0, 1, 2, 0], getpos('.')) +endfunc + +" Test what patch 7.3.414 fixed. Ctrl-A on "000" drops the leading zeros. +func Test_normal_increment_01() + call setline(1, "000") + exec "norm! gg0\<C-A>" + call assert_equal("001", getline(1)) + + call setline(1, "000") + exec "norm! gg$\<C-A>" + call assert_equal("001", getline(1)) + + call setline(1, "001") + exec "norm! gg0\<C-A>" + call assert_equal("002", getline(1)) + + call setline(1, "001") + exec "norm! gg$\<C-A>" + call assert_equal("002", getline(1)) +endfunc + +" Test a regression of patch 7.4.1087 fixed. +func Test_normal_increment_02() + call setline(1, ["hello 10", "world"]) + exec "norm! ggl\<C-A>jx" + call assert_equal(["hello 11", "worl"], getline(1, '$')) + call assert_equal([0, 2, 4, 0], getpos('.')) +endfunc + +" The test35 unified to this file. +func Test_normal_increment_03() + call setline(1, ["100 0x100 077 0", + \ "100 0x100 077 ", + \ "100 0x100 077 0xfF 0xFf", + \ "100 0x100 077 "]) + set nrformats=octal,hex + exec "norm! gg\<C-A>102\<C-X>\<C-A>l\<C-X>l\<C-A>64\<C-A>128\<C-X>$\<C-X>" + set nrformats=octal + exec "norm! j0\<C-A>102\<C-X>\<C-A>l\<C-X>2\<C-A>w65\<C-A>129\<C-X>blx6lD" + set nrformats=hex + exec "norm! j0101\<C-X>l257\<C-X>\<C-A>Txldt \<C-A> \<C-X> \<C-X>" + set nrformats= + exec "norm! j0200\<C-X>l100\<C-X>w78\<C-X>\<C-A>k" + call assert_equal(["0 0x0ff 0000 -1", + \ "0 1x100 0777777", + \ "-1 0x0 078 0xFE 0xfe", + \ "-100 -100x100 000 "], getline(1, '$')) + call assert_equal([0, 3, 25, 0], getpos('.')) +endfunc + +func Test_increment_empty_line() + new + call setline(1, ['0', '0', '0', '0', '0', '0', '']) + exe "normal Gvgg\<C-A>" + call assert_equal(['1', '1', '1', '1', '1', '1', ''], getline(1, 7)) + bwipe! +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_increment_dbcs.vim b/src/testdir/test_increment_dbcs.vim new file mode 100644 index 0000000..80b81ac --- /dev/null +++ b/src/testdir/test_increment_dbcs.vim @@ -0,0 +1,27 @@ +" Tests for using Ctrl-A/Ctrl-X using DBCS. +set encoding=cp932 +scriptencoding cp932 + +func SetUp() + new + set nrformats& +endfunc + +func TearDown() + bwipe! +endfunc + +func Test_increment_dbcs_1() + set nrformats+=alpha + call setline(1, ["R1"]) + exec "norm! 0\<C-A>" + call assert_equal(["R2"], getline(1, '$')) + call assert_equal([0, 1, 3, 0], getpos('.')) + + call setline(1, ["`ab0xDEe"]) + exec "norm! 0\<C-X>" + call assert_equal(["`ab0xDDe"], getline(1, '$')) + call assert_equal([0, 1, 10, 0], getpos('.')) +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_ins_complete.vim b/src/testdir/test_ins_complete.vim new file mode 100644 index 0000000..6fb6e79 --- /dev/null +++ b/src/testdir/test_ins_complete.vim @@ -0,0 +1,312 @@ + +" Test for insert expansion +func Test_ins_complete() + edit test_ins_complete.vim + " The files in the current directory interferes with the files + " used by this test. So use a separate directory for the test. + call mkdir('Xdir') + cd Xdir + + set ff=unix + call writefile(["test11\t36Gepeto\t/Tag/", + \ "asd\ttest11file\t36G", + \ "Makefile\tto\trun"], 'Xtestfile') + call writefile(['', 'start of testfile', + \ 'ru', + \ 'run1', + \ 'run2', + \ 'STARTTEST', + \ 'ENDTEST', + \ 'end of testfile'], 'Xtestdata') + set ff& + + enew! + edit Xtestdata + new + call append(0, ['#include "Xtestfile"', '']) + call cursor(2, 1) + + set cot= + set cpt=.,w + " add-expands (word from next line) from other window + exe "normal iru\<C-N>\<C-N>\<C-X>\<C-N>\<Esc>\<C-A>" + call assert_equal('run1 run3', getline('.')) + " add-expands (current buffer first) + exe "normal o\<C-P>\<C-X>\<C-N>" + call assert_equal('run3 run3', getline('.')) + " Local expansion, ends in an empty line (unless it becomes a global + " expansion) + exe "normal o\<C-X>\<C-P>\<C-P>\<C-P>\<C-P>\<C-P>" + call assert_equal('', getline('.')) + " starts Local and switches to global add-expansion + exe "normal o\<C-X>\<C-P>\<C-P>\<C-X>\<C-X>\<C-N>\<C-X>\<C-N>\<C-N>" + call assert_equal('run1 run2', getline('.')) + + set cpt=.,w,i + " i-add-expands and switches to local + exe "normal OM\<C-N>\<C-X>\<C-N>\<C-X>\<C-N>\<C-X>\<C-X>\<C-X>\<C-P>" + call assert_equal("Makefile\tto\trun3", getline('.')) + " add-expands lines (it would end in an empty line if it didn't ignored + " itself) + exe "normal o\<C-X>\<C-L>\<C-X>\<C-L>\<C-P>\<C-P>" + call assert_equal("Makefile\tto\trun3", getline('.')) + call assert_equal("Makefile\tto\trun3", getline(line('.') - 1)) + + set cpt=kXtestfile + " checks k-expansion, and file expansion (use Xtest11 instead of test11, + " because TEST11.OUT may match first on DOS) + write Xtest11.one + write Xtest11.two + exe "normal o\<C-N>\<Esc>IX\<Esc>A\<C-X>\<C-F>\<C-N>" + call assert_equal('Xtest11.two', getline('.')) + + " use CTRL-X CTRL-F to complete Xtest11.one, remove it and then use CTRL-X + " CTRL-F again to verify this doesn't cause trouble. + exe "normal oXt\<C-X>\<C-F>\<BS>\<BS>\<BS>\<BS>\<BS>\<BS>\<BS>\<BS>\<C-X>\<C-F>" + call assert_equal('Xtest11.one', getline('.')) + normal ddk + + set cpt=w + " checks make_cyclic in other window + exe "normal oST\<C-N>\<C-P>\<C-P>\<C-P>\<C-P>" + call assert_equal('STARTTEST', getline('.')) + + set cpt=u nohid + " checks unloaded buffer expansion + only + exe "normal oEN\<C-N>" + call assert_equal('ENDTEST', getline('.')) + " checks adding mode abortion + exe "normal ounl\<C-N>\<C-X>\<C-X>\<C-P>" + call assert_equal('unless', getline('.')) + + set cpt=t,d def=^\\k* tags=Xtestfile notagbsearch + " tag expansion, define add-expansion interrupted + exe "normal o\<C-X>\<C-]>\<C-X>\<C-D>\<C-X>\<C-D>\<C-X>\<C-X>\<C-D>\<C-X>\<C-D>\<C-X>\<C-D>\<C-X>\<C-D>" + call assert_equal('test11file 36Gepeto /Tag/ asd', getline('.')) + " t-expansion + exe "normal oa\<C-N>\<Esc>" + call assert_equal('asd', getline('.')) + + %bw! + call delete('Xtestfile') + call delete('Xtest11.one') + call delete('Xtest11.two') + call delete('Xtestdata') + set cpt& cot& def& tags& tagbsearch& hidden& + cd .. + call delete('Xdir', 'rf') +endfunc + +func Test_omni_dash() + func Omni(findstart, base) + if a:findstart + return 5 + else + echom a:base + return ['-help', '-v'] + endif + endfunc + set omnifunc=Omni + new + exe "normal Gofind -\<C-x>\<C-o>" + call assert_equal("\n-\nmatch 1 of 2", execute(':2mess')) + + bwipe! + delfunc Omni + set omnifunc= +endfunc + +func Test_completefunc_args() + let s:args = [] + func! CompleteFunc(findstart, base) + let s:args += [[a:findstart, empty(a:base)]] + endfunc + new + + set completefunc=CompleteFunc + call feedkeys("i\<C-X>\<C-U>\<Esc>", 'x') + call assert_equal([1, 1], s:args[0]) + call assert_equal(0, s:args[1][0]) + set completefunc= + + let s:args = [] + set omnifunc=CompleteFunc + call feedkeys("i\<C-X>\<C-O>\<Esc>", 'x') + call assert_equal([1, 1], s:args[0]) + call assert_equal(0, s:args[1][0]) + set omnifunc= + + bwipe! + unlet s:args + delfunc CompleteFunc +endfunc + +func s:CompleteDone_CompleteFuncNone( findstart, base ) + if a:findstart + return 0 + endif + + return v:none +endfunc + +func s:CompleteDone_CompleteFuncDict( findstart, base ) + if a:findstart + return 0 + endif + + return { + \ 'words': [ + \ { + \ 'word': 'aword', + \ 'abbr': 'wrd', + \ 'menu': 'extra text', + \ 'info': 'words are cool', + \ 'kind': 'W', + \ 'user_data': 'test' + \ } + \ ] + \ } +endfunc + +func s:CompleteDone_CheckCompletedItemNone() + let s:called_completedone = 1 +endfunc + +func s:CompleteDone_CheckCompletedItemDict() + call assert_equal( 'aword', v:completed_item[ 'word' ] ) + call assert_equal( 'wrd', v:completed_item[ 'abbr' ] ) + call assert_equal( 'extra text', v:completed_item[ 'menu' ] ) + call assert_equal( 'words are cool', v:completed_item[ 'info' ] ) + call assert_equal( 'W', v:completed_item[ 'kind' ] ) + call assert_equal( 'test', v:completed_item[ 'user_data' ] ) + + let s:called_completedone = 1 +endfunc + +func Test_CompleteDoneNone() + au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemNone() + + set completefunc=<SID>CompleteDone_CompleteFuncNone + execute "normal a\<C-X>\<C-U>\<C-Y>" + set completefunc& + + call assert_true(s:called_completedone) + + let s:called_completedone = 0 + au! CompleteDone +endfunc + +func Test_CompleteDoneDict() + au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDict() + + set completefunc=<SID>CompleteDone_CompleteFuncDict + execute "normal a\<C-X>\<C-U>\<C-Y>" + set completefunc& + + call assert_equal('test', v:completed_item[ 'user_data' ]) + call assert_true(s:called_completedone) + + let s:called_completedone = 0 + au! CompleteDone +endfunc + +func s:CompleteDone_CompleteFuncDictNoUserData(findstart, base) + if a:findstart + return 0 + endif + + return { + \ 'words': [ + \ { + \ 'word': 'aword', + \ 'abbr': 'wrd', + \ 'menu': 'extra text', + \ 'info': 'words are cool', + \ 'kind': 'W' + \ } + \ ] + \ } +endfunc + +func s:CompleteDone_CheckCompletedItemDictNoUserData() + call assert_equal( 'aword', v:completed_item[ 'word' ] ) + call assert_equal( 'wrd', v:completed_item[ 'abbr' ] ) + call assert_equal( 'extra text', v:completed_item[ 'menu' ] ) + call assert_equal( 'words are cool', v:completed_item[ 'info' ] ) + call assert_equal( 'W', v:completed_item[ 'kind' ] ) + call assert_equal( '', v:completed_item[ 'user_data' ] ) + + let s:called_completedone = 1 +endfunc + +func Test_CompleteDoneDictNoUserData() + au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemDictNoUserData() + + set completefunc=<SID>CompleteDone_CompleteFuncDictNoUserData + execute "normal a\<C-X>\<C-U>\<C-Y>" + set completefunc& + + call assert_equal('', v:completed_item[ 'user_data' ]) + call assert_true(s:called_completedone) + + let s:called_completedone = 0 + au! CompleteDone +endfunc + +func s:CompleteDone_CompleteFuncList(findstart, base) + if a:findstart + return 0 + endif + + return [ 'aword' ] +endfunc + +func s:CompleteDone_CheckCompletedItemList() + call assert_equal( 'aword', v:completed_item[ 'word' ] ) + call assert_equal( '', v:completed_item[ 'abbr' ] ) + call assert_equal( '', v:completed_item[ 'menu' ] ) + call assert_equal( '', v:completed_item[ 'info' ] ) + call assert_equal( '', v:completed_item[ 'kind' ] ) + call assert_equal( '', v:completed_item[ 'user_data' ] ) + + let s:called_completedone = 1 +endfunc + +func Test_CompleteDoneList() + au CompleteDone * :call <SID>CompleteDone_CheckCompletedItemList() + + set completefunc=<SID>CompleteDone_CompleteFuncList + execute "normal a\<C-X>\<C-U>\<C-Y>" + set completefunc& + + call assert_equal('', v:completed_item[ 'user_data' ]) + call assert_true(s:called_completedone) + + let s:called_completedone = 0 + au! CompleteDone +endfunc + +func Test_CompleteDone_undo() + au CompleteDone * call append(0, "prepend1") + new + call setline(1, ["line1", "line2"]) + call feedkeys("Go\<C-X>\<C-N>\<CR>\<ESC>", "tx") + call assert_equal(["prepend1", "line1", "line2", "line1", ""], + \ getline(1, '$')) + undo + call assert_equal(["line1", "line2"], getline(1, '$')) + bwipe! + au! CompleteDone +endfunc + +" Check that when using feedkeys() typeahead does not interrupt searching for +" completions. +func Test_compl_feedkeys() + new + set completeopt=menuone,noselect + call feedkeys("ajump ju\<C-X>\<C-N>\<C-P>\<ESC>", "tx") + call assert_equal("jump jump", getline(1)) + bwipe! + set completeopt& +endfunc diff --git a/src/testdir/test_job_fails.vim b/src/testdir/test_job_fails.vim new file mode 100644 index 0000000..affcb7d --- /dev/null +++ b/src/testdir/test_job_fails.vim @@ -0,0 +1,16 @@ +" This test is in a separate file, because it usually causes reports for memory +" leaks under valgrind. That is because when fork/exec fails memory is not +" freed. Since the process exists right away it's not a real leak. + +source shared.vim + +func Test_job_start_fails() + if has('job') + let job = job_start('axdfxsdf') + if has('unix') + call WaitForAssert({-> assert_equal("dead", job_status(job))}) + else + call WaitForAssert({-> assert_equal("fail", job_status(job))}) + endif + endif +endfunc diff --git a/src/testdir/test_join.vim b/src/testdir/test_join.vim new file mode 100644 index 0000000..1c97414 --- /dev/null +++ b/src/testdir/test_join.vim @@ -0,0 +1,35 @@ +" Test for joining lines. + +func Test_join_with_count() + new + call setline(1, ['one', 'two', 'three', 'four']) + normal J + call assert_equal('one two', getline(1)) + %del + call setline(1, ['one', 'two', 'three', 'four']) + normal 10J + call assert_equal('one two three four', getline(1)) + quit! +endfunc + +" Tests for setting the '[,'] marks when joining lines. +func Test_join_marks() + enew + call append(0, [ + \ "\t\tO sodales, ludite, vos qui", + \ "attamen consulite per voster honur. Tua pulchra " . + \ "facies me fay planszer milies", + \ "", + \ "This line.", + \ "Should be joined with the next line", + \ "and with this line"]) + + normal gg0gqj + call assert_equal([0, 1, 1, 0], getpos("'[")) + call assert_equal([0, 2, 1, 0], getpos("']")) + + /^This line/;'}-join + call assert_equal([0, 4, 11, 0], getpos("'[")) + call assert_equal([0, 4, 67, 0], getpos("']")) + enew! +endfunc diff --git a/src/testdir/test_json.vim b/src/testdir/test_json.vim new file mode 100644 index 0000000..fb3d992 --- /dev/null +++ b/src/testdir/test_json.vim @@ -0,0 +1,291 @@ +" Test for JSON functions. + +let s:json1 = '"str\"in\\g"' +let s:var1 = "str\"in\\g" +let s:json2 = '"\u0001\u0002\u0003\u0004\u0005\u0006\u0007"' +let s:var2 = "\x01\x02\x03\x04\x05\x06\x07" +let s:json3 = '"\b\t\n\u000b\f\r\u000e\u000f"' +let s:var3 = "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" +let s:json4 = '"\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017"' +let s:var4 = "\x10\x11\x12\x13\x14\x15\x16\x17" +let s:json5 = '"\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f"' +let s:var5 = "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" + +" surrogate pair +let s:jsonsp1 = '"\ud83c\udf63"' +let s:varsp1 = "\xf0\x9f\x8d\xa3" +let s:jsonsp2 = '"\ud83c\u00a0"' +let s:varsp2 = "\ud83c\u00a0" + +let s:jsonmb = '"s¢cĴgё"' +let s:varmb = "s¢cĴgё" +let s:jsonnr = '1234' +let s:varnr = 1234 +if has('float') + let s:jsonfl = '12.34' + let s:varfl = 12.34 + let s:jsonneginf = '-Infinity' + let s:jsonposinf = 'Infinity' + let s:varneginf = -1.0 / 0.0 + let s:varposinf = 1.0 / 0.0 + let s:jsonnan = 'NaN' + let s:varnan = 0.0 / 0.0 +endif + +let s:jsonl1 = '[1,"a",3]' +let s:varl1 = [1, "a", 3] +let s:jsonl2 = '[1,["a",[],"c"],3]' +let s:jsonl2s = " [\r1 , [ \"a\" , [ ] , \"c\" ] , 3\<Tab>]\r\n" +let s:varl2 = [1, 2, 3] +let l2 = ['a', s:varl2, 'c'] +let s:varl2[1] = l2 +let s:varl2x = [1, ["a", [], "c"], 3] +let s:jsonl3 = '[[1,2],[1,2]]' +let l3 = [1, 2] +let s:varl3 = [l3, l3] + +let s:jsond1 = '{"a":1,"b":"bee","c":[1,2]}' +let s:jsd1 = '{a:1,b:"bee",c:[1,2]}' +let s:vard1 = {"a": 1, "b": "bee","c": [1,2]} +let s:jsond2 = '{"1":1,"2":{"a":"aa","b":{},"c":"cc"},"3":3}' +let s:jsd2 = '{"1":1,"2":{a:"aa",b:{},c:"cc"},"3":3}' +let s:jsond2s = " { \"1\" : 1 , \"2\" :\n{ \"a\"\r: \"aa\" , \"b\" : {\<Tab>} , \"c\" : \"cc\" } , \"3\" : 3 }\r\n" +let s:jsd2s = " { \"1\" : 1 , \"2\" :\n{ a\r: \"aa\" , b : {\<Tab>} , c : \"cc\" } , \"3\" : 3 }\r\n" +let s:vard2 = {"1": 1, "2": 2, "3": 3} +let d2 = {"a": "aa", "b": s:vard2, "c": "cc"} +let s:vard2["2"] = d2 +let s:vard2x = {"1": 1, "2": {"a": "aa", "b": {}, "c": "cc"}, "3": 3} +let d3 = {"a": 1, "b": 2} +let s:vard3 = {"x": d3, "y": d3} +let s:jsond3 = '{"x":{"a":1,"b":2},"y":{"a":1,"b":2}}' +let s:jsd3 = '{x:{a:1,b:2},y:{a:1,b:2}}' +let s:vard4 = {"key": v:none} +let s:vard4x = {"key": v:null} +let s:jsond4 = '{"key":null}' +let s:jsd4 = '{key:null}' + +let s:jsonvals = '[true,false,null,null]' +let s:varvals = [v:true, v:false, v:null, v:null] + +func Test_json_encode() + call assert_equal(s:json1, json_encode(s:var1)) + call assert_equal(s:json2, json_encode(s:var2)) + call assert_equal(s:json3, json_encode(s:var3)) + call assert_equal(s:json4, json_encode(s:var4)) + call assert_equal(s:json5, json_encode(s:var5)) + + call assert_equal(s:jsonmb, json_encode(s:varmb)) + " no test for surrogate pair, json_encode() doesn't create them. + + call assert_equal(s:jsonnr, json_encode(s:varnr)) + if has('float') + call assert_equal(s:jsonfl, json_encode(s:varfl)) + call assert_equal(s:jsonneginf, json_encode(s:varneginf)) + call assert_equal(s:jsonposinf, json_encode(s:varposinf)) + call assert_equal(s:jsonnan, json_encode(s:varnan)) + endif + + call assert_equal(s:jsonl1, json_encode(s:varl1)) + call assert_equal(s:jsonl2, json_encode(s:varl2)) + call assert_equal(s:jsonl3, json_encode(s:varl3)) + + call assert_equal(s:jsond1, json_encode(s:vard1)) + call assert_equal(s:jsond2, json_encode(s:vard2)) + call assert_equal(s:jsond3, json_encode(s:vard3)) + call assert_equal(s:jsond4, json_encode(s:vard4)) + + call assert_equal(s:jsonvals, json_encode(s:varvals)) + + call assert_fails('echo json_encode(function("tr"))', 'E474:') + call assert_fails('echo json_encode([function("tr")])', 'E474:') + + call assert_equal('{"a":""}', json_encode({'a': test_null_string()})) + call assert_equal('{"a":[]}', json_encode({"a": test_null_list()})) + call assert_equal('{"a":{}}', json_encode({"a": test_null_dict()})) + + silent! let res = json_encode(function("tr")) + call assert_equal("", res) +endfunc + +func Test_json_decode() + call assert_equal(s:var1, json_decode(s:json1)) + call assert_equal(s:var2, json_decode(s:json2)) + call assert_equal(s:var3, json_decode(s:json3)) + call assert_equal(s:var4, json_decode(s:json4)) + call assert_equal(s:var5, json_decode(s:json5)) + + call assert_equal(s:varmb, json_decode(s:jsonmb)) + call assert_equal(s:varsp1, json_decode(s:jsonsp1)) + call assert_equal(s:varsp2, json_decode(s:jsonsp2)) + + call assert_equal(s:varnr, json_decode(s:jsonnr)) + if has('float') + call assert_equal(s:varfl, json_decode(s:jsonfl)) + endif + + call assert_equal(s:varl1, json_decode(s:jsonl1)) + call assert_equal(s:varl2x, json_decode(s:jsonl2)) + call assert_equal(s:varl2x, json_decode(s:jsonl2s)) + call assert_equal(s:varl3, json_decode(s:jsonl3)) + + call assert_equal(s:vard1, json_decode(s:jsond1)) + call assert_equal(s:vard2x, json_decode(s:jsond2)) + call assert_equal(s:vard2x, json_decode(s:jsond2s)) + call assert_equal(s:vard3, json_decode(s:jsond3)) + call assert_equal(s:vard4x, json_decode(s:jsond4)) + + call assert_equal(s:varvals, json_decode(s:jsonvals)) + + call assert_equal(v:true, json_decode('true')) + call assert_equal(type(v:true), type(json_decode('true'))) + call assert_equal(v:none, json_decode('')) + call assert_equal(type(v:none), type(json_decode(''))) + call assert_equal("", json_decode('""')) + + " empty key is OK + call assert_equal({'': 'ok'}, json_decode('{"": "ok"}')) + " but not twice + call assert_fails("call json_decode('{\"\": \"ok\", \"\": \"bad\"}')", 'E938:') + + call assert_equal({'n': 1}, json_decode('{"n":1,}')) + call assert_fails("call json_decode(\"{'n':'1',}\")", 'E474:') + call assert_fails("call json_decode(\"'n'\")", 'E474:') + + call assert_fails('call json_decode("\"")', "E474:") + call assert_fails('call json_decode("blah")', "E474:") + call assert_fails('call json_decode("true blah")', "E488:") + call assert_fails('call json_decode("<foobar>")', "E474:") + call assert_fails('call json_decode("{\"a\":1,\"a\":2}")', "E938:") + + call assert_fails('call json_decode("{")', "E474:") + call assert_fails('call json_decode("{foobar}")', "E474:") + call assert_fails('call json_decode("{\"n\",")', "E474:") + call assert_fails('call json_decode("{\"n\":")', "E474:") + call assert_fails('call json_decode("{\"n\":1")', "E474:") + call assert_fails('call json_decode("{\"n\":1,")', "E474:") + call assert_fails('call json_decode("{\"n\",1}")', "E474:") + call assert_fails('call json_decode("{-}")', "E474:") + + call assert_fails('call json_decode("[foobar]")', "E474:") + call assert_fails('call json_decode("[")', "E474:") + call assert_fails('call json_decode("[1")', "E474:") + call assert_fails('call json_decode("[1,")', "E474:") + call assert_fails('call json_decode("[1 2]")', "E474:") + + call assert_fails('call json_decode("[1,,2]")', "E474:") + + call assert_fails('call json_decode("{{}:42}")', "E474:") + call assert_fails('call json_decode("{[]:42}")', "E474:") +endfunc + +let s:jsl5 = '[7,,,]' +let s:varl5 = [7, v:none, v:none] + +func Test_js_encode() + call assert_equal(s:json1, js_encode(s:var1)) + call assert_equal(s:json2, js_encode(s:var2)) + call assert_equal(s:json3, js_encode(s:var3)) + call assert_equal(s:json4, js_encode(s:var4)) + call assert_equal(s:json5, js_encode(s:var5)) + + call assert_equal(s:jsonmb, js_encode(s:varmb)) + " no test for surrogate pair, js_encode() doesn't create them. + + call assert_equal(s:jsonnr, js_encode(s:varnr)) + if has('float') + call assert_equal(s:jsonfl, js_encode(s:varfl)) + call assert_equal(s:jsonneginf, js_encode(s:varneginf)) + call assert_equal(s:jsonposinf, js_encode(s:varposinf)) + call assert_equal(s:jsonnan, js_encode(s:varnan)) + endif + + call assert_equal(s:jsonl1, js_encode(s:varl1)) + call assert_equal(s:jsonl2, js_encode(s:varl2)) + call assert_equal(s:jsonl3, js_encode(s:varl3)) + + call assert_equal(s:jsd1, js_encode(s:vard1)) + call assert_equal(s:jsd2, js_encode(s:vard2)) + call assert_equal(s:jsd3, js_encode(s:vard3)) + call assert_equal(s:jsd4, js_encode(s:vard4)) + + call assert_equal(s:jsonvals, js_encode(s:varvals)) + + call assert_fails('echo js_encode(function("tr"))', 'E474:') + call assert_fails('echo js_encode([function("tr")])', 'E474:') + + silent! let res = js_encode(function("tr")) + call assert_equal("", res) + + call assert_equal(s:jsl5, js_encode(s:varl5)) +endfunc + +func Test_js_decode() + call assert_equal(s:var1, js_decode(s:json1)) + call assert_equal(s:var2, js_decode(s:json2)) + call assert_equal(s:var3, js_decode(s:json3)) + call assert_equal(s:var4, js_decode(s:json4)) + call assert_equal(s:var5, js_decode(s:json5)) + + call assert_equal(s:varmb, js_decode(s:jsonmb)) + call assert_equal(s:varsp1, js_decode(s:jsonsp1)) + call assert_equal(s:varsp2, js_decode(s:jsonsp2)) + + call assert_equal(s:varnr, js_decode(s:jsonnr)) + if has('float') + call assert_equal(s:varfl, js_decode(s:jsonfl)) + call assert_equal(s:varneginf, js_decode(s:jsonneginf)) + call assert_equal(s:varposinf, js_decode(s:jsonposinf)) + call assert_true(isnan(js_decode(s:jsonnan))) + endif + + call assert_equal(s:varl1, js_decode(s:jsonl1)) + call assert_equal(s:varl2x, js_decode(s:jsonl2)) + call assert_equal(s:varl2x, js_decode(s:jsonl2s)) + call assert_equal(s:varl3, js_decode(s:jsonl3)) + + call assert_equal(s:vard1, js_decode(s:jsond1)) + call assert_equal(s:vard1, js_decode(s:jsd1)) + call assert_equal(s:vard2x, js_decode(s:jsond2)) + call assert_equal(s:vard2x, js_decode(s:jsd2)) + call assert_equal(s:vard2x, js_decode(s:jsond2s)) + call assert_equal(s:vard2x, js_decode(s:jsd2s)) + call assert_equal(s:vard3, js_decode(s:jsond3)) + call assert_equal(s:vard3, js_decode(s:jsd3)) + call assert_equal(s:vard4x, js_decode(s:jsond4)) + call assert_equal(s:vard4x, js_decode(s:jsd4)) + + call assert_equal(s:varvals, js_decode(s:jsonvals)) + + call assert_equal(v:true, js_decode('true')) + call assert_equal(type(v:true), type(js_decode('true'))) + call assert_equal(v:none, js_decode('')) + call assert_equal(type(v:none), type(js_decode(''))) + call assert_equal("", js_decode('""')) + call assert_equal("", js_decode("''")) + + call assert_equal('n', js_decode("'n'")) + call assert_equal({'n': 1}, js_decode('{"n":1,}')) + call assert_equal({'n': '1'}, js_decode("{'n':'1',}")) + + call assert_fails('call js_decode("\"")', "E474:") + call assert_fails('call js_decode("blah")', "E474:") + call assert_fails('call js_decode("true blah")', "E474:") + call assert_fails('call js_decode("<foobar>")', "E474:") + + call assert_fails('call js_decode("{")', "E474:") + call assert_fails('call js_decode("{foobar}")', "E474:") + call assert_fails('call js_decode("{\"n\",")', "E474:") + call assert_fails('call js_decode("{\"n\":")', "E474:") + call assert_fails('call js_decode("{\"n\":1")', "E474:") + call assert_fails('call js_decode("{\"n\":1,")', "E474:") + call assert_fails('call js_decode("{\"n\",1}")', "E474:") + call assert_fails('call js_decode("{-}")', "E474:") + + call assert_fails('call js_decode("[foobar]")', "E474:") + call assert_fails('call js_decode("[")', "E474:") + call assert_fails('call js_decode("[1")', "E474:") + call assert_fails('call js_decode("[1,")', "E474:") + call assert_fails('call js_decode("[1 2]")', "E474:") + + call assert_equal(s:varl5, js_decode(s:jsl5)) +endfunc diff --git a/src/testdir/test_jumplist.vim b/src/testdir/test_jumplist.vim new file mode 100644 index 0000000..02dbd76 --- /dev/null +++ b/src/testdir/test_jumplist.vim @@ -0,0 +1,62 @@ +" Tests for the jumplist functionality + +" Tests for the getjumplist() function +func Test_getjumplist() + if !has("jumplist") + return + endif + + %bwipe + clearjumps + call assert_equal([[], 0], getjumplist()) + call assert_equal([[], 0], getjumplist(1)) + call assert_equal([[], 0], getjumplist(1, 1)) + + call assert_equal([], getjumplist(100)) + call assert_equal([], getjumplist(1, 100)) + + let lines = [] + for i in range(1, 100) + call add(lines, "Line " . i) + endfor + call writefile(lines, "Xtest") + + " Jump around and create a jump list + edit Xtest + let bnr = bufnr('%') + normal 50% + normal G + normal gg + + call assert_equal([[ + \ {'lnum': 1, 'bufnr': bnr, 'col': 0, 'coladd': 0}, + \ {'lnum': 50, 'bufnr': bnr, 'col': 0, 'coladd': 0}, + \ {'lnum': 100, 'bufnr': bnr, 'col': 0, 'coladd': 0}], 4], + \ getjumplist()) + + " Traverse the jump list and verify the results + 5 + exe "normal \<C-O>" + call assert_equal(2, getjumplist(1)[1]) + exe "normal 2\<C-O>" + call assert_equal(0, getjumplist(1, 1)[1]) + exe "normal 3\<C-I>" + call assert_equal(3, getjumplist()[1]) + exe "normal \<C-O>" + normal 20% + call assert_equal([[ + \ {'lnum': 1, 'bufnr': bnr, 'col': 0, 'coladd': 0}, + \ {'lnum': 50, 'bufnr': bnr, 'col': 0, 'coladd': 0}, + \ {'lnum': 5, 'bufnr': bnr, 'col': 0, 'coladd': 0}, + \ {'lnum': 100, 'bufnr': bnr, 'col': 0, 'coladd': 0}], 5], + \ getjumplist()) + + let l = getjumplist() + call test_garbagecollect_now() + call assert_equal(4, l[1]) + clearjumps + call test_garbagecollect_now() + call assert_equal(4, l[1]) + + call delete("Xtest") +endfunc diff --git a/src/testdir/test_jumps.vim b/src/testdir/test_jumps.vim new file mode 100644 index 0000000..5a3717d --- /dev/null +++ b/src/testdir/test_jumps.vim @@ -0,0 +1,11 @@ +func Test_empty_buffer() + new + insert +a +b +c +d +. + call assert_equal(1, line("''")) + bwipe! +endfunc diff --git a/src/testdir/test_lambda.vim b/src/testdir/test_lambda.vim new file mode 100644 index 0000000..4ff3e20 --- /dev/null +++ b/src/testdir/test_lambda.vim @@ -0,0 +1,292 @@ +" Test for lambda and closure + +func Test_lambda_feature() + call assert_equal(1, has('lambda')) +endfunc + +func Test_lambda_with_filter() + let s:x = 2 + call assert_equal([2, 3], filter([1, 2, 3], {i, v -> v >= s:x})) +endfunc + +func Test_lambda_with_map() + let s:x = 1 + call assert_equal([2, 3, 4], map([1, 2, 3], {i, v -> v + s:x})) +endfunc + +func Test_lambda_with_sort() + call assert_equal([1, 2, 3, 4, 7], sort([3,7,2,1,4], {a, b -> a - b})) +endfunc + +func Test_lambda_with_timer() + if !has('timers') + return + endif + + let s:n = 0 + let s:timer_id = 0 + func! s:Foo() + "let n = 0 + let s:timer_id = timer_start(50, {-> execute("let s:n += 1 | echo s:n", "")}, {"repeat": -1}) + endfunc + + call s:Foo() + sleep 200ms + " do not collect lambda + call test_garbagecollect_now() + let m = s:n + sleep 200ms + call timer_stop(s:timer_id) + call assert_true(m > 1) + call assert_true(s:n > m + 1) + call assert_true(s:n < 9) +endfunc + +func Test_lambda_with_partial() + let l:Cb = function({... -> ['zero', a:1, a:2, a:3]}, ['one', 'two']) + call assert_equal(['zero', 'one', 'two', 'three'], l:Cb('three')) +endfunc + +function Test_lambda_fails() + call assert_equal(3, {a, b -> a + b}(1, 2)) + call assert_fails('echo {a, a -> a + a}(1, 2)', 'E853:') + call assert_fails('echo {a, b -> a + b)}(1, 2)', 'E15:') +endfunc + +func Test_not_lamda() + let x = {'>' : 'foo'} + call assert_equal('foo', x['>']) +endfunc + +func Test_lambda_capture_by_reference() + let v = 1 + let l:F = {x -> x + v} + let v = 2 + call assert_equal(12, l:F(10)) +endfunc + +func Test_lambda_side_effect() + func! s:update_and_return(arr) + let a:arr[1] = 5 + return a:arr + endfunc + + func! s:foo(arr) + return {-> s:update_and_return(a:arr)} + endfunc + + let arr = [3,2,1] + call assert_equal([3, 5, 1], s:foo(arr)()) +endfunc + +func Test_lambda_refer_local_variable_from_other_scope() + func! s:foo(X) + return a:X() " refer l:x in s:bar() + endfunc + + func! s:bar() + let x = 123 + return s:foo({-> x}) + endfunc + + call assert_equal(123, s:bar()) +endfunc + +func Test_lambda_do_not_share_local_variable() + func! s:define_funcs() + let l:One = {-> split(execute("let a = 'abc' | echo a"))[0]} + let l:Two = {-> exists("a") ? a : "no"} + return [l:One, l:Two] + endfunc + + let l:F = s:define_funcs() + + call assert_equal('no', l:F[1]()) + call assert_equal('abc', l:F[0]()) + call assert_equal('no', l:F[1]()) +endfunc + +func Test_lambda_closure_counter() + func! s:foo() + let x = 0 + return {-> [execute("let x += 1"), x][-1]} + endfunc + + let l:F = s:foo() + call test_garbagecollect_now() + call assert_equal(1, l:F()) + call assert_equal(2, l:F()) + call assert_equal(3, l:F()) + call assert_equal(4, l:F()) +endfunc + +func Test_lambda_with_a_var() + func! s:foo() + let x = 2 + return {... -> a:000 + [x]} + endfunc + func! s:bar() + return s:foo()(1) + endfunc + + call assert_equal([1, 2], s:bar()) +endfunc + +func Test_lambda_call_lambda_from_lambda() + func! s:foo(x) + let l:F1 = {-> {-> a:x}} + return {-> l:F1()} + endfunc + + let l:F = s:foo(1) + call assert_equal(1, l:F()()) +endfunc + +func Test_lambda_delfunc() + func! s:gen() + let pl = l: + let l:Foo = {-> get(pl, "Foo", get(pl, "Bar", {-> 0}))} + let l:Bar = l:Foo + delfunction l:Foo + return l:Bar + endfunc + + let l:F = s:gen() + call assert_fails(':call l:F()', 'E933:') +endfunc + +func Test_lambda_scope() + func! s:NewCounter() + let c = 0 + return {-> [execute('let c += 1'), c][-1]} + endfunc + + func! s:NewCounter2() + return {-> [execute('let c += 100'), c][-1]} + endfunc + + let l:C = s:NewCounter() + let l:D = s:NewCounter2() + + call assert_equal(1, l:C()) + call assert_fails(':call l:D()', 'E121:') + call assert_equal(2, l:C()) +endfunc + +func Test_lambda_share_scope() + func! s:New() + let c = 0 + let l:Inc0 = {-> [execute('let c += 1'), c][-1]} + let l:Dec0 = {-> [execute('let c -= 1'), c][-1]} + return [l:Inc0, l:Dec0] + endfunc + + let [l:Inc, l:Dec] = s:New() + + call assert_equal(1, l:Inc()) + call assert_equal(2, l:Inc()) + call assert_equal(1, l:Dec()) +endfunc + +func Test_lambda_circular_reference() + func! s:Foo() + let d = {} + let d.f = {-> d} + return d.f + endfunc + + call s:Foo() + call test_garbagecollect_now() + let i = 0 | while i < 10000 | call s:Foo() | let i+= 1 | endwhile + call test_garbagecollect_now() +endfunc + +func Test_lambda_combination() + call assert_equal(2, {x -> {x -> x}}(1)(2)) + call assert_equal(10, {y -> {x -> x(y)(10)}({y -> y})}({z -> z})) + call assert_equal(5.0, {x -> {y -> x / y}}(10)(2.0)) + call assert_equal(6, {x -> {y -> {z -> x + y + z}}}(1)(2)(3)) + + call assert_equal(6, {x -> {f -> f(x)}}(3)({x -> x * 2})) + call assert_equal(6, {f -> {x -> f(x)}}({x -> x * 2})(3)) + + " Z combinator + let Z = {f -> {x -> f({y -> x(x)(y)})}({x -> f({y -> x(x)(y)})})} + let Fact = {f -> {x -> x == 0 ? 1 : x * f(x - 1)}} + call assert_equal(120, Z(Fact)(5)) +endfunc + +func Test_closure_counter() + func! s:foo() + let x = 0 + func! s:bar() closure + let x += 1 + return x + endfunc + return function('s:bar') + endfunc + + let l:F = s:foo() + call test_garbagecollect_now() + call assert_equal(1, l:F()) + call assert_equal(2, l:F()) + call assert_equal(3, l:F()) + call assert_equal(4, l:F()) +endfunc + +func Test_closure_unlet() + func! s:foo() + let x = 1 + func! s:bar() closure + unlet x + endfunc + call s:bar() + return l: + endfunc + + call assert_false(has_key(s:foo(), 'x')) + call test_garbagecollect_now() +endfunc + +func LambdaFoo() + let x = 0 + func! LambdaBar() closure + let x += 1 + return x + endfunc + return function('LambdaBar') +endfunc + +func Test_closure_refcount() + let g:Count = LambdaFoo() + call test_garbagecollect_now() + call assert_equal(1, g:Count()) + let g:Count2 = LambdaFoo() + call test_garbagecollect_now() + call assert_equal(1, g:Count2()) + call assert_equal(2, g:Count()) + call assert_equal(3, g:Count2()) + + delfunc LambdaFoo + delfunc LambdaBar +endfunc + +func Test_named_function_closure() + func! Afoo() + let x = 14 + func! s:Abar() closure + return x + endfunc + call assert_equal(14, s:Abar()) + endfunc + call Afoo() + call assert_equal(14, s:Abar()) + call test_garbagecollect_now() + call assert_equal(14, s:Abar()) +endfunc + +func Test_lambda_with_index() + let List = {x -> [x]} + let Extract = {-> function(List, ['foobar'])()[0]} + call assert_equal('foobar', Extract()) +endfunc diff --git a/src/testdir/test_langmap.vim b/src/testdir/test_langmap.vim new file mode 100644 index 0000000..572fad7 --- /dev/null +++ b/src/testdir/test_langmap.vim @@ -0,0 +1,28 @@ +" tests for 'langmap' + +if !has('langmap') + finish +endif + +func Test_langmap() + new + set langmap=}l,^x,%v + + call setline(1, ['abc']) + call feedkeys('gg0}^', 'tx') + call assert_equal('ac', getline(1)) + + " in Replace mode + " need silent! to avoid a delay when entering Insert mode + call setline(1, ['abcde']) + silent! call feedkeys("gg0lR%{z\<Esc>00", 'tx') + call assert_equal('a%{ze', getline(1)) + + " in Select mode + " need silent! to avoid a delay when entering Insert mode + call setline(1, ['abcde']) + silent! call feedkeys("gg0}%}\<C-G>}^\<Esc>00", 'tx') + call assert_equal('a}^de', getline(1)) + + quit! +endfunc diff --git a/src/testdir/test_largefile.vim b/src/testdir/test_largefile.vim new file mode 100644 index 0000000..1b3e02a --- /dev/null +++ b/src/testdir/test_largefile.vim @@ -0,0 +1,34 @@ +" Tests for large files +" This is only executed manually: "make test_largefile". +" This is not run as part of "make test". + +func Test_largefile() + let fname = 'Xlarge.txt' + + call delete(fname) + exe "e" fname + " Make sure that a line break is 1 byte (LF). + set ff=unix + set undolevels=-1 + " Input 99 'A's. The line becomes 100 bytes including a line break. + exe "normal 99iA\<Esc>" + yank + " Put 39,999,999 times. The file becomes 4,000,000,000 bytes. + normal 39999999p + " Moving around in the file randomly. + normal G + normal 10% + normal 90% + normal 50% + normal gg + w + " Check if the file size is 4,000,000,000 bytes. + let fsize=getfsize(fname) + if has('num64') + call assert_true(fsize == 4000000000) + else + " getfsize() returns -2 if a Number is 32 bits. + call assert_true(fsize == -2) + endif + call delete(fname) +endfunc diff --git a/src/testdir/test_let.vim b/src/testdir/test_let.vim new file mode 100644 index 0000000..24c6ef5 --- /dev/null +++ b/src/testdir/test_let.vim @@ -0,0 +1,27 @@ +" Tests for the :let command. + +func Test_let() + " Test to not autoload when assigning. It causes internal error. + set runtimepath+=./sautest + let Test104#numvar = function('tr') + call assert_equal("function('tr')", string(Test104#numvar)) + + let a = 1 + let b = 2 + + let out = execute('let a b') + let s = "\na #1\nb #2" + call assert_equal(s, out) + + let out = execute('let {0 == 1 ? "a" : "b"}') + let s = "\nb #2" + call assert_equal(s, out) + + let out = execute('let {0 == 1 ? "a" : "b"} a') + let s = "\nb #2\na #1" + call assert_equal(s, out) + + let out = execute('let a {0 == 1 ? "a" : "b"}') + let s = "\na #1\nb #2" + call assert_equal(s, out) +endfunc diff --git a/src/testdir/test_lineending.vim b/src/testdir/test_lineending.vim new file mode 100644 index 0000000..d531b74 --- /dev/null +++ b/src/testdir/test_lineending.vim @@ -0,0 +1,19 @@ +" Tests for saving/loading a file with some lines ending in +" CTRL-M, some not +func Test_lineending() + let l = ["this line ends in a\<CR>", + \ "this one doesn't", + \ "this one does\<CR>", + \ "and the last one doesn't"] + set ta tx + enew! + call append(0, l) + $delete + write Xfile1 + bwipe Xfile1 + edit Xfile1 + let t = getline(1, '$') + call assert_equal(l, t) + new | only + call delete('Xfile1') +endfunc diff --git a/src/testdir/test_lispwords.vim b/src/testdir/test_lispwords.vim new file mode 100644 index 0000000..4c05504 --- /dev/null +++ b/src/testdir/test_lispwords.vim @@ -0,0 +1,82 @@ +" Tests for 'lispwords' settings being global-local + +set nocompatible viminfo+=nviminfo + +func Test_global_local_lispwords() + setglobal lispwords=foo,bar,baz + setlocal lispwords-=foo | setlocal lispwords+=quux + call assert_equal('foo,bar,baz', &g:lispwords) + call assert_equal('bar,baz,quux', &l:lispwords) + call assert_equal('bar,baz,quux', &lispwords) + + setlocal lispwords< + call assert_equal('foo,bar,baz', &g:lispwords) + call assert_equal('foo,bar,baz', &l:lispwords) + call assert_equal('foo,bar,baz', &lispwords) +endfunc + +func Test_lisp_indent() + enew! + + call append(0, [ + \ '(defun html-file (base)', + \ '(format nil "~(~A~).html" base))', + \ '', + \ '(defmacro page (name title &rest body)', + \ '(let ((ti (gensym)))', + \ '`(with-open-file (*standard-output*', + \ '(html-file ,name)', + \ ':direction :output', + \ ':if-exists :supersede)', + \ '(let ((,ti ,title))', + \ '(as title ,ti)', + \ '(with center ', + \ '(as h2 (string-upcase ,ti)))', + \ '(brs 3)', + \ ',@body))))', + \ '', + \ ';;; Utilities for generating links', + \ '', + \ '(defmacro with-link (dest &rest body)', + \ '`(progn', + \ '(format t "<a href=\"~A\">" (html-file ,dest))', + \ ',@body', + \ '(princ "</a>")))' + \ ]) + set lisp + set lispwords& + let save_copt = &cpoptions + set cpoptions+=p + normal 1G=G + + call assert_equal([ + \ '(defun html-file (base)', + \ ' (format nil "~(~A~).html" base))', + \ '', + \ '(defmacro page (name title &rest body)', + \ ' (let ((ti (gensym)))', + \ ' `(with-open-file (*standard-output*', + \ ' (html-file ,name)', + \ ' :direction :output', + \ ' :if-exists :supersede)', + \ ' (let ((,ti ,title))', + \ ' (as title ,ti)', + \ ' (with center ', + \ ' (as h2 (string-upcase ,ti)))', + \ ' (brs 3)', + \ ' ,@body))))', + \ '', + \ ';;; Utilities for generating links', + \ '', + \ '(defmacro with-link (dest &rest body)', + \ ' `(progn', + \ ' (format t "<a href=\"~A\">" (html-file ,dest))', + \ ' ,@body', + \ ' (princ "</a>")))', + \ '' + \ ], getline(1, "$")) + + enew! + let &cpoptions=save_copt + set nolisp +endfunc diff --git a/src/testdir/test_listchars.vim b/src/testdir/test_listchars.vim new file mode 100644 index 0000000..2870f2d --- /dev/null +++ b/src/testdir/test_listchars.vim @@ -0,0 +1,115 @@ +" Tests for 'listchars' display with 'list' and :list + +source view_util.vim + +func Test_listchars() + enew! + set ff=unix + set list + + set listchars+=tab:>-,space:.,trail:< + call append(0, [ + \ ' aa ', + \ ' bb ', + \ ' cccc ', + \ 'dd ee ', + \ ' ' + \ ]) + let expected = [ + \ '>-------aa>-----$', + \ '..bb>---<<$', + \ '...cccc><$', + \ 'dd........ee<<>-$', + \ '<$' + \ ] + redraw! + for i in range(1, 5) + call cursor(i, 1) + call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) + endfor + + set listchars-=trail:< + let expected = [ + \ '>-------aa>-----$', + \ '..bb>---..$', + \ '...cccc>.$', + \ 'dd........ee..>-$', + \ '.$' + \ ] + redraw! + for i in range(1, 5) + call cursor(i, 1) + call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) + endfor + + " tab with 3rd character. + set listchars-=tab:>- + set listchars+=tab:<=>,trail:- + let expected = [ + \ '<======>aa<====>$', + \ '..bb<==>--$', + \ '...cccc>-$', + \ 'dd........ee--<>$', + \ '-$' + \ ] + redraw! + for i in range(1, 5) + call cursor(i, 1) + call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) + endfor + + set listchars-=trail:- + let expected = [ + \ '<======>aa<====>$', + \ '..bb<==>..$', + \ '...cccc>.$', + \ 'dd........ee..<>$', + \ '.$' + \ ] + redraw! + for i in range(1, 5) + call cursor(i, 1) + call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) + endfor + + set listchars-=tab:<=> + set listchars+=tab:>- + set listchars+=trail:< + set nolist + normal ggdG + call append(0, [ + \ ' fff ', + \ ' gg ', + \ ' h ', + \ 'iii ', + \ ]) + let l = split(execute("%list"), "\n") + call assert_equal([ + \ '..fff>--<<$', + \ '>-------gg>-----$', + \ '.....h>-$', + \ 'iii<<<<><<$', '$'], l) + + + " test nbsp + normal ggdG + set listchars=nbsp:X,trail:Y + set list + " Non-breaking space + let nbsp = nr2char(0xa0) + call append(0, [ ">".nbsp."<" ]) + + let expected = '>X< ' + + redraw! + call cursor(1, 1) + call assert_equal([expected], ScreenLines(1, virtcol('$'))) + + set listchars=nbsp:X + redraw! + call cursor(1, 1) + call assert_equal([expected], ScreenLines(1, virtcol('$'))) + + enew! + set listchars& ff& +endfunc diff --git a/src/testdir/test_listdict.vim b/src/testdir/test_listdict.vim new file mode 100644 index 0000000..1af47d9 --- /dev/null +++ b/src/testdir/test_listdict.vim @@ -0,0 +1,653 @@ +" Tests for the List and Dict types + +func TearDown() + " Run garbage collection after every test + call test_garbagecollect_now() +endfunc + +" Tests for List type + +" List creation +func Test_list_create() + " Creating List directly with different types + let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},] + call assert_equal("[1, 'as''d', [1, 2, function('strlen')], {'a': 1}]", string(l)) + call assert_equal({'a' : 1}, l[-1]) + call assert_equal(1, l[-4]) + let x = 10 + try + let x = l[-5] + catch + call assert_match('E684:', v:exception) + endtry + call assert_equal(10, x) +endfunc + +" List slices +func Test_list_slice() + let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},] + call assert_equal([1, 'as''d', [1, 2, function('strlen')], {'a': 1}], l[:]) + call assert_equal(['as''d', [1, 2, function('strlen')], {'a': 1}], l[1:]) + call assert_equal([1, 'as''d', [1, 2, function('strlen')]], l[:-2]) + call assert_equal([1, 'as''d', [1, 2, function('strlen')], {'a': 1}], l[0:8]) + call assert_equal([], l[8:-1]) +endfunc + +" List identity +func Test_list_identity() + let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},] + let ll = l + let lx = copy(l) + call assert_true(l == ll) + call assert_false(l isnot ll) + call assert_true(l is ll) + call assert_true(l == lx) + call assert_false(l is lx) + call assert_true(l isnot lx) +endfunc + +" removing items with :unlet +func Test_list_unlet() + let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},] + unlet l[2] + call assert_equal([1, 'as''d', {'a': 1}], l) + let l = range(8) + unlet l[:3] + unlet l[1:] + call assert_equal([4], l) + + " removing items out of range: silently skip items that don't exist + let l = [0, 1, 2, 3] + call assert_fails('unlet l[2:1]', 'E684') + let l = [0, 1, 2, 3] + unlet l[2:2] + call assert_equal([0, 1, 3], l) + let l = [0, 1, 2, 3] + unlet l[2:3] + call assert_equal([0, 1], l) + let l = [0, 1, 2, 3] + unlet l[2:4] + call assert_equal([0, 1], l) + let l = [0, 1, 2, 3] + unlet l[2:5] + call assert_equal([0, 1], l) + let l = [0, 1, 2, 3] + call assert_fails('unlet l[-1:2]', 'E684') + let l = [0, 1, 2, 3] + unlet l[-2:2] + call assert_equal([0, 1, 3], l) + let l = [0, 1, 2, 3] + unlet l[-3:2] + call assert_equal([0, 3], l) + let l = [0, 1, 2, 3] + unlet l[-4:2] + call assert_equal([3], l) + let l = [0, 1, 2, 3] + unlet l[-5:2] + call assert_equal([3], l) + let l = [0, 1, 2, 3] + unlet l[-6:2] + call assert_equal([3], l) +endfunc + +" assignment to a list +func Test_list_assign() + let l = [0, 1, 2, 3] + let [va, vb] = l[2:3] + call assert_equal([2, 3], [va, vb]) + call assert_fails('let [va, vb] = l', 'E687') + call assert_fails('let [va, vb] = l[1:1]', 'E688') +endfunc + +" test for range assign +func Test_list_range_assign() + let l = [0] + let l[:] = [1, 2] + call assert_equal([1, 2], l) +endfunc + +" Test removing items in list +func Test_list_func_remove() + " Test removing 1 element + let l = [1, 2, 3, 4] + call assert_equal(1, remove(l, 0)) + call assert_equal([2, 3, 4], l) + + let l = [1, 2, 3, 4] + call assert_equal(2, remove(l, 1)) + call assert_equal([1, 3, 4], l) + + let l = [1, 2, 3, 4] + call assert_equal(4, remove(l, -1)) + call assert_equal([1, 2, 3], l) + + " Test removing range of element(s) + let l = [1, 2, 3, 4] + call assert_equal([3], remove(l, 2, 2)) + call assert_equal([1, 2, 4], l) + + let l = [1, 2, 3, 4] + call assert_equal([2, 3], remove(l, 1, 2)) + call assert_equal([1, 4], l) + + let l = [1, 2, 3, 4] + call assert_equal([2, 3], remove(l, -3, -2)) + call assert_equal([1, 4], l) + + " Test invalid cases + let l = [1, 2, 3, 4] + call assert_fails("call remove(l, 5)", 'E684:') + call assert_fails("call remove(l, 1, 5)", 'E684:') + call assert_fails("call remove(l, 3, 2)", 'E16:') + call assert_fails("call remove(1, 0)", 'E896:') + call assert_fails("call remove(l, l)", 'E745:') +endfunc + +" Tests for Dictionary type + +func Test_dict() + " Creating Dictionary directly with different types + let d = {001: 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1},} + call assert_equal("{'1': 'asd', 'b': [1, 2, function('strlen')], '-1': {'a': 1}}", string(d)) + call assert_equal('asd', d.1) + call assert_equal(['-1', '1', 'b'], sort(keys(d))) + call assert_equal(['asd', [1, 2, function('strlen')], {'a': 1}], values(d)) + let v = [] + for [key, val] in items(d) + call extend(v, [key, val]) + unlet key val + endfor + call assert_equal(['1','asd','b',[1, 2, function('strlen')],'-1',{'a': 1}], v) + + call extend(d, {3:33, 1:99}) + call extend(d, {'b':'bbb', 'c':'ccc'}, "keep") + call assert_fails("call extend(d, {3:333,4:444}, 'error')", 'E737') + call assert_equal({'c': 'ccc', '1': 99, 'b': [1, 2, function('strlen')], '3': 33, '-1': {'a': 1}}, d) + call filter(d, 'v:key =~ ''[ac391]''') + call assert_equal({'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}}, d) +endfunc + +" Dictionary identity +func Test_dict_identity() + let d = {001: 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1},} + let dd = d + let dx = copy(d) + call assert_true(d == dd) + call assert_false(d isnot dd) + call assert_true(d is dd) + call assert_true(d == dx) + call assert_false(d is dx) + call assert_true(d isnot dx) +endfunc + +" removing items with :unlet +func Test_dict_unlet() + let d = {'b':'bbb', '1': 99, '3': 33, '-1': {'a': 1}} + unlet d.b + unlet d[-1] + call assert_equal({'1': 99, '3': 33}, d) +endfunc + +" manipulating a big Dictionary (hashtable.c has a border of 1000 entries) +func Test_dict_big() + let d = {} + for i in range(1500) + let d[i] = 3000 - i + endfor + call assert_equal([3000, 2900, 2001, 1600, 1501], [d[0], d[100], d[999], d[1400], d[1499]]) + let str = '' + try + let n = d[1500] + catch + let str=substitute(v:exception, '\v(.{14}).*( \d{4}).*', '\1\2', '') + endtry + call assert_equal('Vim(let):E716: 1500', str) + + " lookup each items + for i in range(1500) + call assert_equal(3000 - i, d[i]) + endfor + let i += 1 + + " delete even items + while i >= 2 + let i -= 2 + unlet d[i] + endwhile + call assert_equal('NONE', get(d, 1500 - 100, 'NONE')) + call assert_equal(2999, d[1]) + + " delete odd items, checking value, one intentionally wrong + let d[33] = 999 + let i = 1 + while i < 1500 + if i != 33 + call assert_equal(3000 - i, d[i]) + else + call assert_equal(999, d[i]) + endif + unlet d[i] + let i += 2 + endwhile + call assert_equal({}, d) + unlet d +endfunc + +" Dictionary function +func Test_dict_func() + let d = {} + func d.func(a) dict + return a:a . len(self.data) + endfunc + let d.data = [1,2,3] + call assert_equal('len: 3', d.func('len: ')) + let x = d.func('again: ') + call assert_equal('again: 3', x) + let Fn = d.func + call assert_equal('xxx3', Fn('xxx')) +endfunc + +" Function in script-local List or Dict +func Test_script_local_dict_func() + let g:dict = {} + function g:dict.func() dict + return 'g:dict.func' . self.foo[1] . self.foo[0]('asdf') + endfunc + let g:dict.foo = ['-', 2, 3] + call insert(g:dict.foo, function('strlen')) + call assert_equal('g:dict.func-4', g:dict.func()) + unlet g:dict +endfunc + +" Test removing items in la dictionary +func Test_dict_func_remove() + let d = {1:'a', 2:'b', 3:'c'} + call assert_equal('b', remove(d, 2)) + call assert_equal({1:'a', 3:'c'}, d) + + call assert_fails("call remove(d, 1, 2)", 'E118:') + call assert_fails("call remove(d, 'a')", 'E716:') + call assert_fails("call remove(d, [])", 'E730:') +endfunc + +" Nasty: remove func from Dict that's being called (works) +func Test_dict_func_remove_in_use() + let d = {1:1} + func d.func(a) + return "a:" . a:a + endfunc + let expected = 'a:' . string(get(d, 'func')) + call assert_equal(expected, d.func(string(remove(d, 'func')))) +endfunc + +" Nasty: deepcopy() dict that refers to itself (fails when noref used) +func Test_dict_deepcopy() + let d = {1:1, 2:2} + let l = [4, d, 6] + let d[3] = l + let dc = deepcopy(d) + call assert_fails('call deepcopy(d, 1)', 'E698') + let l2 = [0, l, l, 3] + let l[1] = l2 + let l3 = deepcopy(l2) + call assert_true(l3[1] is l3[2]) +endfunc + +" Locked variables +func Test_list_locked_var() + let expected = [ + \ [['0000-000', 'ppppppp'], + \ ['0000-000', 'ppppppp'], + \ ['0000-000', 'ppppppp']], + \ [['1000-000', 'ppppppF'], + \ ['0000-000', 'ppppppp'], + \ ['0000-000', 'ppppppp']], + \ [['1100-100', 'ppFppFF'], + \ ['0000-000', 'ppppppp'], + \ ['0000-000', 'ppppppp']], + \ [['1110-110', 'pFFpFFF'], + \ ['0010-010', 'pFppFpp'], + \ ['0000-000', 'ppppppp']], + \ [['1111-111', 'FFFFFFF'], + \ ['0011-011', 'FFpFFpp'], + \ ['0000-000', 'ppppppp']] + \ ] + for depth in range(5) + for u in range(3) + unlet! l + let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}] + exe "lockvar " . depth . " l" + if u == 1 + exe "unlockvar l" + elseif u == 2 + exe "unlockvar " . depth . " l" + endif + let ps = islocked("l").islocked("l[1]").islocked("l[1][1]").islocked("l[1][1][0]").'-'.islocked("l[2]").islocked("l[2]['6']").islocked("l[2]['6'][7]") + call assert_equal(expected[depth][u][0], ps) + let ps = '' + try + let l[1][1][0] = 99 + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + let l[1][1] = [99] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + let l[1] = [99] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + let l[2]['6'][7] = 99 + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + let l[2][6] = {99: 99} + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + let l[2] = {99: 99} + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + let l = [99] + let ps .= 'p' + catch + let ps .= 'F' + endtry + call assert_equal(expected[depth][u][1], ps) + endfor + endfor +endfunc + +" Unletting locked variables +func Test_list_locked_var_unlet() + let expected = [ + \ [['0000-000', 'ppppppp'], + \ ['0000-000', 'ppppppp'], + \ ['0000-000', 'ppppppp']], + \ [['1000-000', 'ppFppFp'], + \ ['0000-000', 'ppppppp'], + \ ['0000-000', 'ppppppp']], + \ [['1100-100', 'pFFpFFp'], + \ ['0000-000', 'ppppppp'], + \ ['0000-000', 'ppppppp']], + \ [['1110-110', 'FFFFFFp'], + \ ['0010-010', 'FppFppp'], + \ ['0000-000', 'ppppppp']], + \ [['1111-111', 'FFFFFFp'], + \ ['0011-011', 'FppFppp'], + \ ['0000-000', 'ppppppp']] + \ ] + + for depth in range(5) + for u in range(3) + unlet! l + let l = [0, [1, [2, 3]], {4: 5, 6: {7: 8}}] + exe "lockvar " . depth . " l" + if u == 1 + exe "unlockvar l" + elseif u == 2 + exe "unlockvar " . depth . " l" + endif + let ps = islocked("l").islocked("l[1]").islocked("l[1][1]").islocked("l[1][1][0]").'-'.islocked("l[2]").islocked("l[2]['6']").islocked("l[2]['6'][7]") + call assert_equal(expected[depth][u][0], ps) + let ps = '' + try + unlet l[2]['6'][7] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + unlet l[2][6] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + unlet l[2] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + unlet l[1][1][0] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + unlet l[1][1] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + unlet l[1] + let ps .= 'p' + catch + let ps .= 'F' + endtry + try + unlet l + let ps .= 'p' + catch + let ps .= 'F' + endtry + call assert_equal(expected[depth][u][1], ps) + endfor + endfor +endfunc + +" Locked variables and :unlet or list / dict functions + +" No :unlet after lock on dict: +func Test_dict_lock_unlet() + unlet! d + let d = {'a': 99, 'b': 100} + lockvar 1 d + call assert_fails('unlet d.a', 'E741') +endfunc + +" unlet after lock on dict item +func Test_dict_item_lock_unlet() + unlet! d + let d = {'a': 99, 'b': 100} + lockvar d.a + unlet d.a + call assert_equal({'b' : 100}, d) +endfunc + +" filter() after lock on dict item +func Test_dict_lock_filter() + unlet! d + let d = {'a': 99, 'b': 100} + lockvar d.a + call filter(d, 'v:key != "a"') + call assert_equal({'b' : 100}, d) +endfunc + +" map() after lock on dict +func Test_dict_lock_map() + unlet! d + let d = {'a': 99, 'b': 100} + lockvar 1 d + call map(d, 'v:val + 200') + call assert_equal({'a' : 299, 'b' : 300}, d) +endfunc + +" No extend() after lock on dict item +func Test_dict_lock_extend() + unlet! d + let d = {'a': 99, 'b': 100} + lockvar d.a + call assert_fails("call extend(d, {'a' : 123})", 'E741') + call assert_equal({'a': 99, 'b': 100}, d) +endfunc + +" No remove() of write-protected scope-level variable +func Tfunc1(this_is_a_long_parameter_name) + call assert_fails("call remove(a:, 'this_is_a_long_parameter_name')", 'E795') +endfunc +func Test_dict_scope_var_remove() + call Tfunc1('testval') +endfunc + +" No extend() of write-protected scope-level variable +func Tfunc2(this_is_a_long_parameter_name) + call assert_fails("call extend(a:, {'this_is_a_long_parameter_name': 1234})", 'E742') +endfunc +func Test_dict_scope_var_extend() + call Tfunc2('testval') +endfunc + +" No :unlet of variable in locked scope +func Test_lock_var_unlet() + let b:testvar = 123 + lockvar 1 b: + call assert_fails('unlet b:testvar', 'E741:') + unlockvar 1 b: + unlet! b:testvar +endfunc + +" No :let += of locked list variable +func Test_let_lock_list() + let l = ['a', 'b', 3] + lockvar 1 l + call assert_fails("let l += ['x']", 'E741:') + call assert_equal(['a', 'b', 3], l) + + unlet l + let l = [1, 2, 3, 4] + lockvar! l + call assert_equal([1, 2, 3, 4], l) + unlockvar l[1] + call assert_fails('unlet l[0:1]', 'E741:') + call assert_equal([1, 2, 3, 4], l) + call assert_fails('unlet l[1:2]', 'E741:') + call assert_equal([1, 2, 3, 4], l) + unlockvar l[1] + call assert_fails('let l[0:1] = [0, 1]', 'E741:') + call assert_equal([1, 2, 3, 4], l) + call assert_fails('let l[1:2] = [0, 1]', 'E741:') + call assert_equal([1, 2, 3, 4], l) + unlet l +endfunc + +" lockvar/islocked() triggering script autoloading +func Test_lockvar_script_autoload() + let old_rtp = &rtp + set rtp+=./sautest + lockvar g:footest#x + unlockvar g:footest#x + call assert_equal(-1, islocked('g:footest#x')) + call assert_equal(0, exists('g:footest#x')) + call assert_equal(1, g:footest#x) + let &rtp = old_rtp +endfunc + +" a:000 function argument test +func s:arg_list_test(...) + call assert_fails('let a:000 = [1, 2]', 'E46:') + call assert_fails('let a:000[0] = 9', 'E742:') + call assert_fails('let a:000[2] = [9, 10]', 'E742:') + call assert_fails('let a:000[3] = {9 : 10}', 'E742:') + + " now the tests that should pass + let a:000[2][1] = 9 + call extend(a:000[2], [5, 6]) + let a:000[3][5] = 8 + let a:000[3]['a'] = 12 + call assert_equal([1, 2, [3, 9, 5, 6], {'a': 12, '5': 8}], a:000) +endfunc + +func Test_func_arg_list() + call s:arg_list_test(1, 2, [3, 4], {5: 6}) +endfunc + +" Tests for reverse(), sort(), uniq() +func Test_reverse_sort_uniq() + let l = ['-0', 'A11', 2, 2, 'xaaa', 4, 'foo', 'foo6', 'foo', [0, 1, 2], 'x8', [0, 1, 2], 1.5] + call assert_equal(['-0', 'A11', 2, 'xaaa', 4, 'foo', 'foo6', 'foo', [0, 1, 2], 'x8', [0, 1, 2], 1.5], uniq(copy(l))) + call assert_equal([1.5, [0, 1, 2], 'x8', [0, 1, 2], 'foo', 'foo6', 'foo', 4, 'xaaa', 2, 2, 'A11', '-0'], reverse(l)) + call assert_equal([1.5, [0, 1, 2], 'x8', [0, 1, 2], 'foo', 'foo6', 'foo', 4, 'xaaa', 2, 2, 'A11', '-0'], reverse(reverse(l))) + call assert_equal(['-0', 'A11', 'foo', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 2, 4, [0, 1, 2], [0, 1, 2]], sort(l)) + call assert_equal([[0, 1, 2], [0, 1, 2], 4, 2, 2, 1.5, 'xaaa', 'x8', 'foo6', 'foo', 'foo', 'A11', '-0'], reverse(sort(l))) + call assert_equal(['-0', 'A11', 'foo', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 2, 4, [0, 1, 2], [0, 1, 2]], sort(reverse(sort(l)))) + call assert_equal(['-0', 'A11', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 4, [0, 1, 2]], uniq(sort(l))) + + let l=[7, 9, 'one', 18, 12, 22, 'two', 10.0e-16, -1, 'three', 0xff, 0.22, 'four'] + call assert_equal([-1, 'one', 'two', 'three', 'four', 1.0e-15, 0.22, 7, 9, 12, 18, 22, 255], sort(copy(l), 'n')) + + let l=[7, 9, 18, 12, 22, 10.0e-16, -1, 0xff, 0, -0, 0.22, 'bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', {}, []] + call assert_equal(['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l), 1)) + call assert_equal(['bar', 'BAR', 'Bar', 'Foo', 'FOO', 'foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l), 'i')) + call assert_equal(['BAR', 'Bar', 'FOO', 'FOOBAR', 'Foo', 'bar', 'foo', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l))) + + call assert_fails('call reverse("")', 'E899:') +endfunc + +" splitting a string to a List +func Test_str_split() + call assert_equal(['aa', 'bb'], split(' aa bb ')) + call assert_equal(['aa', 'bb'], split(' aa bb ', '\W\+', 0)) + call assert_equal(['', 'aa', 'bb', ''], split(' aa bb ', '\W\+', 1)) + call assert_equal(['', '', 'aa', '', 'bb', '', ''], split(' aa bb ', '\W', 1)) + call assert_equal(['aa', '', 'bb'], split(':aa::bb:', ':', 0)) + call assert_equal(['', 'aa', '', 'bb', ''], split(':aa::bb:', ':', 1)) + call assert_equal(['aa', '', 'bb', 'cc', ''], split('aa,,bb, cc,', ',\s*', 1)) + call assert_equal(['a', 'b', 'c'], split('abc', '\zs')) + call assert_equal(['', 'a', '', 'b', '', 'c', ''], split('abc', '\zs', 1)) +endfunc + +" compare recursively linked list and dict +func Test_listdict_compare() + let l = [1, 2, 3, 4] + let d = {'1': 1, '2': l, '3': 3} + let l[1] = d + call assert_true(l == l) + call assert_true(d == d) + call assert_false(l != deepcopy(l)) + call assert_false(d != deepcopy(d)) +endfunc + + " compare complex recursively linked list and dict +func Test_listdict_compare_complex() + let l = [] + call add(l, l) + let dict4 = {"l": l} + call add(dict4.l, dict4) + let lcopy = deepcopy(l) + let dict4copy = deepcopy(dict4) + call assert_true(l == lcopy) + call assert_true(dict4 == dict4copy) +endfunc + +func Test_listdict_extend() + " Pass the same List to extend() + let l = [1, 2, 3, 4, 5] + call extend(l, l) + call assert_equal([1, 2, 3, 4, 5, 1, 2, 3, 4, 5], l) + + " Pass the same Dict to extend() + let d = { 'a': {'b': 'B'}} + call extend(d, d) + call assert_equal({'a': {'b': 'B'}}, d) + + " Pass the same Dict to extend() with "error" + call assert_fails("call extend(d, d, 'error')", 'E737:') + call assert_equal({'a': {'b': 'B'}}, d) +endfunc diff --git a/src/testdir/test_listlbr.vim b/src/testdir/test_listlbr.vim new file mode 100644 index 0000000..29e797d --- /dev/null +++ b/src/testdir/test_listlbr.vim @@ -0,0 +1,235 @@ +" Test for linebreak and list option (non-utf8) + +set encoding=latin1 +scriptencoding latin1 + +if !exists("+linebreak") || !has("conceal") + finish +endif + +source view_util.vim + +function s:screen_lines(lnum, width) abort + return ScreenLines(a:lnum, a:width) +endfunction + +func s:compare_lines(expect, actual) + call assert_equal(join(a:expect, "\n"), join(a:actual, "\n")) +endfunc + +function s:test_windows(...) + call NewWindow(10, 20) + setl ts=8 sw=4 sts=4 linebreak sbr= wrap + exe get(a:000, 0, '') +endfunction + +function s:close_windows(...) + call CloseWindow() + exe get(a:000, 0, '') +endfunction + +func Test_set_linebreak() + call s:test_windows('setl ts=4 sbr=+') + call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz_1060ABCDEFGHIJKLMNOP ") + let lines = s:screen_lines([1, 4], winwidth(0)) + let expect = [ +\ " abcdef ", +\ "+hijklmn ", +\ "+pqrstuvwxyz_1060ABC", +\ "+DEFGHIJKLMNOP ", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_linebreak_with_list() + call s:test_windows('setl ts=4 sbr=+ list listchars=') + call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz_1060ABCDEFGHIJKLMNOP ") + let lines = s:screen_lines([1, 4], winwidth(0)) + let expect = [ +\ "^Iabcdef hijklmn^I ", +\ "+pqrstuvwxyz_1060ABC", +\ "+DEFGHIJKLMNOP ", +\ "~ ", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_linebreak_with_nolist() + call s:test_windows('setl ts=4 sbr=+ nolist') + call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz_1060ABCDEFGHIJKLMNOP ") + let lines = s:screen_lines([1, 4], winwidth(0)) + let expect = [ +\ " abcdef ", +\ "+hijklmn ", +\ "+pqrstuvwxyz_1060ABC", +\ "+DEFGHIJKLMNOP ", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_should_break() + call s:test_windows('setl sbr=+ nolist') + call setline(1, "1\t" . repeat('a', winwidth(0)-2)) + let lines = s:screen_lines([1, 4], winwidth(0)) + let expect = [ +\ "1 ", +\ "+aaaaaaaaaaaaaaaaaa ", +\ "~ ", +\ "~ ", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_linebreak_with_conceal() + call s:test_windows('setl cpo&vim sbr=+ list conceallevel=2 concealcursor=nv listchars=tab:ab') + call setline(1, "_S_\t bla") + syn match ConcealVar contained /_/ conceal + syn match All /.*/ contains=ConcealVar + let lines = s:screen_lines([1, 4], winwidth(0)) + let expect = [ +\ "Sabbbbbb bla ", +\ "~ ", +\ "~ ", +\ "~ ", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_virtual_block() + call s:test_windows('setl sbr=+') + call setline(1, [ +\ "REMOVE: this not", +\ "REMOVE: aaaaaaaaaaaaa", +\ ]) + exe "norm! 1/^REMOVE:" + exe "norm! 0\<C-V>jf x" + $put + let lines = s:screen_lines([1, 4], winwidth(0)) + let expect = [ +\ "this not ", +\ "aaaaaaaaaaaaa ", +\ "REMOVE: ", +\ "REMOVE: ", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_virtual_block_and_vbA() + call s:test_windows() + call setline(1, "long line: " . repeat("foobar ", 40) . "TARGET at end") + exe "norm! $3B\<C-v>eAx\<Esc>" + let lines = s:screen_lines([1, 10], winwidth(0)) + let expect = [ +\ "foobar foobar ", +\ "foobar foobar ", +\ "foobar foobar ", +\ "foobar foobar ", +\ "foobar foobar ", +\ "foobar foobar ", +\ "foobar foobar ", +\ "foobar foobar ", +\ "foobar foobar ", +\ "foobar TARGETx at ", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_virtual_char_and_block() + call s:test_windows() + call setline(1, "1111-1111-1111-11-1111-1111-1111") + exe "norm! 0f-lv3lc2222\<Esc>bgj." + let lines = s:screen_lines([1, 2], winwidth(0)) + let expect = [ +\ "1111-2222-1111-11- ", +\ "1111-2222-1111 ", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_undo_after_block_visual() + call s:test_windows() + call setline(1, ["aaa", "aaa", "a"]) + exe "norm! gg\<C-V>2j~e." + let lines = s:screen_lines([1, 3], winwidth(0)) + let expect = [ +\ "AaA ", +\ "AaA ", +\ "A ", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_norm_after_block_visual() + call s:test_windows() + call setline(1, ["abcd{ef", "ghijklm", "no}pgrs"]) + exe "norm! ggf{\<C-V>\<C-V>c%" + let lines = s:screen_lines([1, 3], winwidth(0)) + let expect = [ +\ "abcdpgrs ", +\ "~ ", +\ "~ ", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_block_replace_after_wrapping() + call s:test_windows() + call setline(1, repeat("a", 150)) + exe "norm! 0yypk147|\<C-V>jr0" + call assert_equal(repeat("a", 146) . "0aaa", getline(1)) + call assert_equal(repeat("a", 146) . "0aaa", getline(2)) + let lines = s:screen_lines([1, 10], winwidth(0)) + let expect = [ +\ "aaaaaaaaaaaaaaaaaaaa", +\ "aaaaaaaaaaaaaaaaaaaa", +\ "aaaaaaaaaaaaaaaaaaaa", +\ "aaaaaaaaaaaaaaaaaaaa", +\ "aaaaaaaaaaaaaaaaaaaa", +\ "aaaaaaaaaaaaaaaaaaaa", +\ "aaaaaaaaaaaaaaaaaaaa", +\ "aaaaaa0aaa ", +\ "@ ", +\ "@ ", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_list_with_listchars() + call s:test_windows('setl list listchars=space:_,trail:-,tab:>-,eol:$') + call setline(1, "a aaaaaaaaaaaaaaaaaaaaaa\ta ") + let lines = s:screen_lines([1, 3], winwidth(0)) + let expect = [ +\ "a_ ", +\ "aaaaaaaaaaaaaaaaaaaa", +\ "aa>-----a-$ ", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_list_with_tab_and_skipping_first_chars() + call s:test_windows('setl list listchars=tab:>- ts=70 nowrap') + call setline(1, ["iiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\taaaaaaaaaaaaaaaaaa"]) + call cursor(4,64) + norm! 2zl + let lines = s:screen_lines([1, 4], winwidth(0)) + let expect = [ +\ "---------------aaaaa", +\ "---------------aaaaa", +\ "---------------aaaaa", +\ "iiiiiiiii>-----aaaaa", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfu diff --git a/src/testdir/test_listlbr_utf8.vim b/src/testdir/test_listlbr_utf8.vim new file mode 100644 index 0000000..c38e0c5 --- /dev/null +++ b/src/testdir/test_listlbr_utf8.vim @@ -0,0 +1,271 @@ +" Test for linebreak and list option in utf-8 mode + +set encoding=utf-8 +scriptencoding utf-8 + +if !exists("+linebreak") || !has("conceal") || !has("signs") + finish +endif + +source view_util.vim + +func s:screen_lines(lnum, width) abort + return ScreenLines(a:lnum, a:width) +endfunc + +func s:compare_lines(expect, actual) + call assert_equal(a:expect, a:actual) +endfunc + +func s:screen_attr(lnum, chars, ...) abort + let line = getline(a:lnum) + let attr = [] + let prefix = get(a:000, 0, 0) + for i in range(a:chars[0], a:chars[1]) + let scol = strdisplaywidth(strcharpart(line, 0, i-1)) + 1 + let attr += [screenattr(a:lnum, scol + prefix)] + endfor + return attr +endfunc + +func s:test_windows(...) + call NewWindow(10, 20) + setl ts=4 sw=4 sts=4 linebreak sbr=+ wrap + exe get(a:000, 0, '') +endfunc + +func s:close_windows(...) + call CloseWindow() + exe get(a:000, 0, '') +endfunc + +func Test_linebreak_with_fancy_listchars() + call s:test_windows("setl list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6") + call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz\u00a01060ABCDEFGHIJKLMNOP ") + redraw! + let lines = s:screen_lines([1, 4], winwidth(0)) + let expect = [ +\ "▕———abcdef ", +\ "+hijklmn▕——— ", +\ "+pqrstuvwxyz␣1060ABC", +\ "+DEFGHIJKLMNOPˑ¶ ", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_nolinebreak_with_list() + call s:test_windows("setl nolinebreak list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6") + call setline(1, "\tabcdef hijklmn\tpqrstuvwxyz\u00a01060ABCDEFGHIJKLMNOP ") + redraw! + let lines = s:screen_lines([1, 4], winwidth(0)) + let expect = [ +\ "▕———abcdef hijklmn▕—", +\ "+pqrstuvwxyz␣1060ABC", +\ "+DEFGHIJKLMNOPˑ¶ ", +\ "~ ", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_linebreak_with_nolist() + call s:test_windows('setl nolist') + call setline(1, "\t*mask = nil;") + redraw! + let lines = s:screen_lines([1, 4], winwidth(0)) + let expect = [ +\ " *mask = nil; ", +\ "~ ", +\ "~ ", +\ "~ ", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_list_and_concealing1() + call s:test_windows('setl list listchars=tab:>- cole=1') + call setline(1, [ +\ "#define ABCDE\t\t1", +\ "#define ABCDEF\t\t1", +\ "#define ABCDEFG\t\t1", +\ "#define ABCDEFGH\t1", +\ "#define MSG_MODE_FILE\t\t\t1", +\ "#define MSG_MODE_CONSOLE\t\t2", +\ "#define MSG_MODE_FILE_AND_CONSOLE\t3", +\ "#define MSG_MODE_FILE_THEN_CONSOLE\t4", +\ ]) + vert resize 40 + syn match Conceal conceal cchar=>'AB\|MSG_MODE' + redraw! + let lines = s:screen_lines([1, 7], winwidth(0)) + let expect = [ +\ "#define ABCDE>-->---1 ", +\ "#define >CDEF>-->---1 ", +\ "#define >CDEFG>->---1 ", +\ "#define >CDEFGH>----1 ", +\ "#define >_FILE>--------->--->---1 ", +\ "#define >_CONSOLE>---------->---2 ", +\ "#define >_FILE_AND_CONSOLE>---------3 ", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_list_and_concealing2() + call s:test_windows('setl nowrap ts=2 list listchars=tab:>- cole=2 concealcursor=n') + call setline(1, "bbeeeeee\t\t;\tsome text") + vert resize 40 + syn clear + syn match meaning /;\s*\zs.*/ + syn match hasword /^\x\{8}/ contains=word + syn match word /\<\x\{8}\>/ contains=beginword,endword contained + syn match beginword /\<\x\x/ contained conceal + syn match endword /\x\{6}\>/ contained + hi meaning guibg=blue + hi beginword guibg=green + hi endword guibg=red + redraw! + let lines = s:screen_lines([1, 1], winwidth(0)) + let expect = [ +\ "eeeeee>--->-;>some text ", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_screenattr_for_comment() + call s:test_windows("setl ft=c ts=7 list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6") + call setline(1, " /*\t\t and some more */") + norm! gg0 + syntax on + hi SpecialKey term=underline ctermfg=red guifg=red + redraw! + let line = getline(1) + let attr = s:screen_attr(1, [1, 6]) + call assert_notequal(attr[0], attr[1]) + call assert_notequal(attr[1], attr[3]) + call assert_notequal(attr[3], attr[5]) + call s:close_windows() +endfunc + +func Test_visual_block_and_selection_exclusive() + call s:test_windows('setl selection=exclusive') + call setline(1, "long line: " . repeat("foobar ", 40) . "TARGETÃ' at end") + exe "norm! $3B\<C-v>eAx\<Esc>" + let lines = s:screen_lines([1, 10], winwidth(0)) + let expect = [ +\ "+foobar foobar ", +\ "+foobar foobar ", +\ "+foobar foobar ", +\ "+foobar foobar ", +\ "+foobar foobar ", +\ "+foobar foobar ", +\ "+foobar foobar ", +\ "+foobar foobar ", +\ "+foobar foobar ", +\ "+foobar TARGETÃx' ", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_multibyte_sign_and_colorcolumn() + call s:test_windows("setl nolinebreak cc=3 list listchars=nbsp:\u2423,tab:\u2595\u2014,trail:\u02d1,eol:\ub6") + call setline(1, ["", "a b c", "a b c"]) + exe "sign define foo text=\uff0b" + exe "sign place 1 name=foo line=2 buffer=" . bufnr('%') + redraw! + norm! ggj0 + let signwidth = strdisplaywidth("\uff0b") + let attr1 = s:screen_attr(2, [1, 3], signwidth) + let attr2 = s:screen_attr(3, [1, 3], signwidth) + call assert_equal(attr1[0], attr2[0]) + call assert_equal(attr1[1], attr2[1]) + call assert_equal(attr1[2], attr2[2]) + let lines = s:screen_lines([1, 3], winwidth(0)) + let expect = [ +\ " ¶ ", +\ "+a b c¶ ", +\ " a b c¶ ", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_colorcolumn_priority() + call s:test_windows('setl cc=4 cuc hls') + call setline(1, ["xxyy", ""]) + norm! gg + exe "normal! /xxyy\<CR>" + norm! G + redraw! + let line_attr = s:screen_attr(1, [1, &cc]) + " Search wins over CursorColumn + call assert_equal(line_attr[1], line_attr[0]) + " Search wins over Colorcolumn + call assert_equal(line_attr[2], line_attr[3]) + call s:close_windows('setl hls&vim') +endfunc + +func Test_illegal_byte_and_breakat() + call s:test_windows("setl sbr= brk+=<") + vert resize 18 + call setline(1, repeat("\x80", 6)) + redraw! + let lines = s:screen_lines([1, 2], winwidth(0)) + let expect = [ +\ "<80><80><80><80><8", +\ "0><80> ", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows('setl brk&vim') +endfunc + +func Test_multibyte_wrap_and_breakat() + call s:test_windows("setl sbr= brk+=>") + call setline(1, repeat('a', 17) . repeat('あ', 2)) + redraw! + let lines = s:screen_lines([1, 2], winwidth(0)) + let expect = [ +\ "aaaaaaaaaaaaaaaaaあ>", +\ "あ ", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows('setl brk&vim') +endfunc + +func Test_chinese_char_on_wrap_column() + call s:test_windows("setl nolbr wrap sbr=") + syntax off + call setline(1, [ +\ 'aaaaaaaaaaaaaaaaaaa中'. +\ 'aaaaaaaaaaaaaaaaa中'. +\ 'aaaaaaaaaaaaaaaaa中'. +\ 'aaaaaaaaaaaaaaaaa中'. +\ 'aaaaaaaaaaaaaaaaa中'. +\ 'aaaaaaaaaaaaaaaaa中'. +\ 'aaaaaaaaaaaaaaaaa中'. +\ 'aaaaaaaaaaaaaaaaa中'. +\ 'aaaaaaaaaaaaaaaaa中'. +\ 'aaaaaaaaaaaaaaaaa中'. +\ 'hello']) + call cursor(1,1) + norm! $ + redraw! + let expect=[ +\ '中aaaaaaaaaaaaaaaaa>', +\ '中aaaaaaaaaaaaaaaaa>', +\ '中aaaaaaaaaaaaaaaaa>', +\ '中aaaaaaaaaaaaaaaaa>', +\ '中aaaaaaaaaaaaaaaaa>', +\ '中aaaaaaaaaaaaaaaaa>', +\ '中aaaaaaaaaaaaaaaaa>', +\ '中aaaaaaaaaaaaaaaaa>', +\ '中aaaaaaaaaaaaaaaaa>', +\ '中hello '] + let lines = s:screen_lines([1, 10], winwidth(0)) + call s:compare_lines(expect, lines) + call s:close_windows() +endfu diff --git a/src/testdir/test_lua.vim b/src/testdir/test_lua.vim new file mode 100644 index 0000000..1a5c74f --- /dev/null +++ b/src/testdir/test_lua.vim @@ -0,0 +1,575 @@ +" Tests for Lua. + +if !has('lua') + finish +endif + +" Check that switching to another buffer does not trigger ml_get error. +func Test_command_new_no_ml_get_error() + new + let wincount = winnr('$') + call setline(1, ['one', 'two', 'three']) + luado vim.command("new") + call assert_equal(wincount + 1, winnr('$')) + %bwipe! +endfunc + +" Test vim.command() +func Test_command() + new + call setline(1, ['one', 'two', 'three']) + luado vim.command("1,2d_") + call assert_equal(['three'], getline(1, '$')) + bwipe! +endfunc + +" Test vim.eval() +func Test_eval() + " lua.eval with a number + lua v = vim.eval('123') + call assert_equal('number', luaeval('vim.type(v)')) + call assert_equal(123.0, luaeval('v')) + + " lua.eval with a string + lua v = vim.eval('"abc"') + call assert_equal('string', luaeval('vim.type(v)')) + call assert_equal('abc', luaeval('v')) + + " lua.eval with a list + lua v = vim.eval("['a']") + call assert_equal('list', luaeval('vim.type(v)')) + call assert_equal(['a'], luaeval('v')) + + " lua.eval with a dict + lua v = vim.eval("{'a':'b'}") + call assert_equal('dict', luaeval('vim.type(v)')) + call assert_equal({'a':'b'}, luaeval('v')) + + call assert_fails('lua v = vim.eval(nil)', + \ "[string \"vim chunk\"]:1: bad argument #1 to 'eval' (string expected, got nil)") + call assert_fails('lua v = vim.eval(true)', + \ "[string \"vim chunk\"]:1: bad argument #1 to 'eval' (string expected, got boolean)") + call assert_fails('lua v = vim.eval({})', + \ "[string \"vim chunk\"]:1: bad argument #1 to 'eval' (string expected, got table)") + call assert_fails('lua v = vim.eval(print)', + \ "[string \"vim chunk\"]:1: bad argument #1 to 'eval' (string expected, got function)") + call assert_fails('lua v = vim.eval(vim.buffer())', + \ "[string \"vim chunk\"]:1: bad argument #1 to 'eval' (string expected, got userdata)") + + lua v = nil +endfunc + +" Test vim.window() +func Test_window() + e Xfoo2 + new Xfoo1 + + " Window 1 (top window) contains Xfoo1 + " Window 2 (bottom window) contains Xfoo2 + call assert_equal('Xfoo1', luaeval('vim.window(1):buffer().name')) + call assert_equal('Xfoo2', luaeval('vim.window(2):buffer().name')) + + " Window 3 does not exist so vim.window(3) should return nil + call assert_equal('nil', luaeval('tostring(vim.window(3))')) + + %bwipe! +endfunc + +" Test vim.window().height +func Test_window_height() + new + lua vim.window().height = 2 + call assert_equal(2, winheight(0)) + lua vim.window().height = vim.window().height + 1 + call assert_equal(3, winheight(0)) + bwipe! +endfunc + +" Test vim.window().width +func Test_window_width() + vert new + lua vim.window().width = 2 + call assert_equal(2, winwidth(0)) + lua vim.window().width = vim.window().width + 1 + call assert_equal(3, winwidth(0)) + bwipe! +endfunc + +" Test vim.window().line and vim.window.col +func Test_window_line_col() + new + call setline(1, ['line1', 'line2', 'line3']) + lua vim.window().line = 2 + lua vim.window().col = 4 + call assert_equal([0, 2, 4, 0], getpos('.')) + lua vim.window().line = vim.window().line + 1 + lua vim.window().col = vim.window().col - 1 + call assert_equal([0, 3, 3, 0], getpos('.')) + + call assert_fails('lua vim.window().line = 10', + \ '[string "vim chunk"]:1: line out of range') + bwipe! +endfunc + +" Test setting the current window +func Test_window_set_current() + new Xfoo1 + lua w1 = vim.window() + new Xfoo2 + lua w2 = vim.window() + + call assert_equal('Xfoo2', bufname('%')) + lua w1() + call assert_equal('Xfoo1', bufname('%')) + lua w2() + call assert_equal('Xfoo2', bufname('%')) + + lua w1, w2 = nil + %bwipe! +endfunc + +" Test vim.window().buffer +func Test_window_buffer() + new Xfoo1 + lua w1 = vim.window() + lua b1 = w1.buffer() + new Xfoo2 + lua w2 = vim.window() + lua b2 = w2.buffer() + + lua b1() + call assert_equal('Xfoo1', bufname('%')) + lua b2() + call assert_equal('Xfoo2', bufname('%')) + + lua b1, b2, w1, w2 = nil + %bwipe! +endfunc + +" Test vim.window():previous() and vim.window():next() +func Test_window_next_previous() + new Xfoo1 + new Xfoo2 + new Xfoo3 + wincmd j + + call assert_equal('Xfoo2', luaeval('vim.window().buffer().name')) + call assert_equal('Xfoo1', luaeval('vim.window():next():buffer().name')) + call assert_equal('Xfoo3', luaeval('vim.window():previous():buffer().name')) + + %bwipe! +endfunc + +" Test vim.window():isvalid() +func Test_window_isvalid() + new Xfoo + lua w = vim.window() + call assert_true(luaeval('w:isvalid()')) + + " FIXME: how to test the case when isvalid() returns v:false? + " isvalid() gives errors when the window is deleted. Is it a bug? + + lua w = nil + bwipe! +endfunc + +" Test vim.buffer() with and without argument +func Test_buffer() + new Xfoo1 + let bn1 = bufnr('%') + new Xfoo2 + let bn2 = bufnr('%') + + " Test vim.buffer() without argument. + call assert_equal('Xfoo2', luaeval("vim.buffer().name")) + + " Test vim.buffer() with string argument. + call assert_equal('Xfoo1', luaeval("vim.buffer('Xfoo1').name")) + call assert_equal('Xfoo2', luaeval("vim.buffer('Xfoo2').name")) + + " Test vim.buffer() with integer argument. + call assert_equal('Xfoo1', luaeval("vim.buffer(" . bn1 . ").name")) + call assert_equal('Xfoo2', luaeval("vim.buffer(" . bn2 . ").name")) + + lua bn1, bn2 = nil + %bwipe! +endfunc + +" Test vim.buffer().name and vim.buffer().fname +func Test_buffer_name() + new + call assert_equal('', luaeval('vim.buffer().name')) + call assert_equal('', luaeval('vim.buffer().fname')) + bwipe! + + new Xfoo + call assert_equal('Xfoo', luaeval('vim.buffer().name')) + call assert_equal(expand('%:p'), luaeval('vim.buffer().fname')) + bwipe! +endfunc + +" Test vim.buffer().number +func Test_buffer_number() + " All numbers in Lua are floating points number (no integers). + call assert_equal(bufnr('%'), float2nr(luaeval('vim.buffer().number'))) +endfunc + +" Test inserting lines in buffer. +func Test_buffer_insert() + new + lua vim.buffer()[1] = '3' + lua vim.buffer():insert('1', 0) + lua vim.buffer():insert('2', 1) + lua vim.buffer():insert('4', 10) + + call assert_equal(['1', '2', '3', '4'], getline(1, '$')) + bwipe! +endfunc + +" Test deleting line in buffer +func Test_buffer_delete() + new + call setline(1, ['1', '2', '3']) + lua vim.buffer()[2] = nil + call assert_equal(['1', '3'], getline(1, '$')) + + call assert_fails('lua vim.buffer()[3] = nil', + \ '[string "vim chunk"]:1: invalid line number') + bwipe! +endfunc + +" Test #vim.buffer() i.e. number of lines in buffer +func Test_buffer_number_lines() + new + call setline(1, ['a', 'b', 'c']) + call assert_equal(3.0, luaeval('#vim.buffer()')) + bwipe! +endfunc + +" Test vim.buffer():next() and vim.buffer():previous() +" Note that these functions get the next or previous buffers +" but do not switch buffer. +func Test_buffer_next_previous() + new Xfoo1 + new Xfoo2 + new Xfoo3 + b Xfoo2 + + lua bn = vim.buffer():next() + lua bp = vim.buffer():previous() + + call assert_equal('Xfoo2', luaeval('vim.buffer().name')) + call assert_equal('Xfoo1', luaeval('bp.name')) + call assert_equal('Xfoo3', luaeval('bn.name')) + + call assert_equal('Xfoo2', bufname('%')) + + lua bn() + call assert_equal('Xfoo3', luaeval('vim.buffer().name')) + call assert_equal('Xfoo3', bufname('%')) + + lua bp() + call assert_equal('Xfoo1', luaeval('vim.buffer().name')) + call assert_equal('Xfoo1', bufname('%')) + + lua bn, bp = nil + %bwipe! +endfunc + +" Test vim.buffer():isvalid() +func Test_buffer_isvalid() + new Xfoo + lua b = vim.buffer() + call assert_true(luaeval('b:isvalid()')) + + " FIXME: how to test the case when isvalid() returns v:false? + " isvalid() gives errors when the buffer is wiped. Is it a bug? + + lua b = nil + bwipe! +endfunc + +func Test_list() + call assert_equal([], luaeval('vim.list()')) + + let l = [] + lua l = vim.eval('l') + lua l:add(123) + lua l:add('abc') + lua l:add(true) + lua l:add(false) + lua l:add(nil) + lua l:add(vim.eval("[1, 2, 3]")) + lua l:add(vim.eval("{'a':1, 'b':2, 'c':3}")) + call assert_equal([123.0, 'abc', v:true, v:false, v:null, [1, 2, 3], {'a': 1, 'b': 2, 'c': 3}], l) + call assert_equal(7.0, luaeval('#l')) + call assert_match('^list: \%(0x\)\?\x\+$', luaeval('tostring(l)')) + + lua l[0] = 124 + lua l[5] = nil + lua l:insert('first') + lua l:insert('xx', 3) + call assert_equal(['first', 124.0, 'abc', 'xx', v:true, v:false, v:null, {'a': 1, 'b': 2, 'c': 3}], l) + + lockvar 1 l + call assert_fails('lua l:add("x")', '[string "vim chunk"]:1: list is locked') + + lua l = nil +endfunc + +func Test_list_table() + " See :help lua-vim + " Non-numeric keys should not be used to initialize the list + " so say = 'hi' should be ignored. + lua t = {3.14, 'hello', false, true, say = 'hi'} + call assert_equal([3.14, 'hello', v:false, v:true], luaeval('vim.list(t)')) + lua t = nil + + call assert_fails('lua vim.list(1)', '[string "vim chunk"]:1: table expected, got number') + call assert_fails('lua vim.list("x")', '[string "vim chunk"]:1: table expected, got string') + call assert_fails('lua vim.list(print)', '[string "vim chunk"]:1: table expected, got function') + call assert_fails('lua vim.list(true)', '[string "vim chunk"]:1: table expected, got boolean') +endfunc + +" Test l() i.e. iterator on list +func Test_list_iter() + lua l = vim.list():add('foo'):add('bar') + lua str = '' + lua for v in l() do str = str .. v end + call assert_equal('foobar', luaeval('str')) + + lua str, l = nil +endfunc + +func Test_recursive_list() + lua l = vim.list():add(1):add(2) + lua l = l:add(l) + + call assert_equal(1.0, luaeval('l[0]')) + call assert_equal(2.0, luaeval('l[1]')) + + call assert_equal(1.0, luaeval('l[2][0]')) + call assert_equal(2.0, luaeval('l[2][1]')) + + call assert_equal(1.0, luaeval('l[2][2][0]')) + call assert_equal(2.0, luaeval('l[2][2][1]')) + + call assert_equal('[1.0, 2.0, [...]]', string(luaeval('l'))) + + call assert_match('^list: \%(0x\)\?\x\+$', luaeval('tostring(l)')) + call assert_equal(luaeval('tostring(l)'), luaeval('tostring(l[2])')) + + call assert_equal(luaeval('l'), luaeval('l[2]')) + call assert_equal(luaeval('l'), luaeval('l[2][2]')) + + lua l = nil +endfunc + +func Test_dict() + call assert_equal({}, luaeval('vim.dict()')) + + let d = {} + lua d = vim.eval('d') + lua d[0] = 123 + lua d[1] = "abc" + lua d[2] = true + lua d[3] = false + lua d[4] = vim.eval("[1, 2, 3]") + lua d[5] = vim.eval("{'a':1, 'b':2, 'c':3}") + call assert_equal({'0':123.0, '1':'abc', '2':v:true, '3':v:false, '4': [1, 2, 3], '5': {'a':1, 'b':2, 'c':3}}, d) + call assert_equal(6.0, luaeval('#d')) + call assert_match('^dict: \%(0x\)\?\x\+$', luaeval('tostring(d)')) + + call assert_equal('abc', luaeval('d[1]')) + + lua d[0] = 124 + lua d[4] = nil + call assert_equal({'0':124.0, '1':'abc', '2':v:true, '3':v:false, '5': {'a':1, 'b':2, 'c':3}}, d) + + lockvar 1 d + call assert_fails('lua d[6] = 1', '[string "vim chunk"]:1: dict is locked') + + lua d = nil +endfunc + +func Test_dict_table() + lua t = {key1 = 'x', key2 = 3.14, key3 = true, key4 = false} + call assert_equal({'key1': 'x', 'key2': 3.14, 'key3': v:true, 'key4': v:false}, + \ luaeval('vim.dict(t)')) + + " Same example as in :help lua-vim. + lua t = {math.pi, false, say = 'hi'} + " FIXME: commented out as it currently does not work as documented: + " Expected {'say': 'hi'} + " but got {'1': 3.141593, '2': v:false, 'say': 'hi'} + " Is the documentation or the code wrong? + "call assert_equal({'say' : 'hi'}, luaeval('vim.dict(t)')) + lua t = nil + + call assert_fails('lua vim.dict(1)', '[string "vim chunk"]:1: table expected, got number') + call assert_fails('lua vim.dict("x")', '[string "vim chunk"]:1: table expected, got string') + call assert_fails('lua vim.dict(print)', '[string "vim chunk"]:1: table expected, got function') + call assert_fails('lua vim.dict(true)', '[string "vim chunk"]:1: table expected, got boolean') +endfunc + +" Test d() i.e. iterator on dictionary +func Test_dict_iter() + let d = {'a': 1, 'b':2} + lua d = vim.eval('d') + lua str = '' + lua for k,v in d() do str = str .. k ..':' .. v .. ',' end + call assert_equal('a:1,b:2,', luaeval('str')) + + lua str, d = nil +endfunc + +func Test_funcref() + function I(x) + return a:x + endfunction + let R = function('I') + lua i1 = vim.funcref"I" + lua i2 = vim.eval"R" + lua msg = "funcref|test|" .. (#i2(i1) == #i1(i2) and "OK" or "FAIL") + lua msg = vim.funcref"tr"(msg, "|", " ") + call assert_equal("funcref test OK", luaeval('msg')) + + " dict funcref + function Mylen() dict + return len(self.data) + endfunction + let l = [0, 1, 2, 3] + let mydict = {'data': l} + lua d = vim.eval"mydict" + lua d.len = vim.funcref"Mylen" -- assign d as 'self' + lua res = (d.len() == vim.funcref"len"(vim.eval"l")) and "OK" or "FAIL" + call assert_equal("OK", luaeval('res')) + + lua i1, i2, msg, d, res = nil +endfunc + +" Test vim.type() +func Test_type() + " The following values are identical to Lua's type function. + call assert_equal('string', luaeval('vim.type("foo")')) + call assert_equal('number', luaeval('vim.type(1)')) + call assert_equal('number', luaeval('vim.type(1.2)')) + call assert_equal('function', luaeval('vim.type(print)')) + call assert_equal('table', luaeval('vim.type({})')) + call assert_equal('boolean', luaeval('vim.type(true)')) + call assert_equal('boolean', luaeval('vim.type(false)')) + call assert_equal('nil', luaeval('vim.type(nil)')) + + " The following values are specific to Vim. + call assert_equal('window', luaeval('vim.type(vim.window())')) + call assert_equal('buffer', luaeval('vim.type(vim.buffer())')) + call assert_equal('list', luaeval('vim.type(vim.list())')) + call assert_equal('dict', luaeval('vim.type(vim.dict())')) + call assert_equal('funcref', luaeval('vim.type(vim.funcref("Test_type"))')) +endfunc + +" Test vim.open() +func Test_open() + call assert_notmatch('XOpen', execute('ls')) + + " Open a buffer XOpen1, but do not jump to it. + lua b = vim.open('XOpen1') + call assert_equal('XOpen1', luaeval('b.name')) + call assert_equal('', bufname('%')) + + call assert_match('XOpen1', execute('ls')) + call assert_notequal('XOpen2', bufname('%')) + + " Open a buffer XOpen2 and jump to it. + lua b = vim.open('XOpen2')() + call assert_equal('XOpen2', luaeval('b.name')) + call assert_equal('XOpen2', bufname('%')) + + lua b = nil + %bwipe! +endfunc + +" Test vim.line() +func Test_line() + new + call setline(1, ['first line', 'second line']) + 1 + call assert_equal('first line', luaeval('vim.line()')) + 2 + call assert_equal('second line', luaeval('vim.line()')) + bwipe! +endfunc + +" Test vim.beep() +func Test_beep() + call assert_beeps('lua vim.beep()') +endfunc + +" Test errors in luaeval() +func Test_luaeval_error() + " Compile error + call assert_fails("call luaeval('-nil')", + \ '[string "luaeval"]:1: attempt to perform arithmetic on a nil value') + call assert_fails("call luaeval(']')", + \ "[string \"luaeval\"]:1: unexpected symbol near ']'") +endfunc + +" Test :luafile foo.lua +func Test_luafile() + call delete('Xlua_file') + call writefile(["str = 'hello'", "num = 123.0" ], 'Xlua_file') + call setfperm('Xlua_file', 'r-xr-xr-x') + + luafile Xlua_file + call assert_equal('hello', luaeval('str')) + call assert_equal(123.0, luaeval('num')) + + lua str, num = nil + call delete('Xlua_file') +endfunc + +" Test :luafile % +func Test_luafile_percent() + new Xlua_file + append + str, num = 'foo', 321.0 + print(string.format('str=%s, num=%d', str, num)) +. + w! + luafile % + let msg = split(execute('message'), "\n")[-1] + call assert_equal('str=foo, num=321', msg) + + lua str, num = nil + call delete('Xlua_file') + bwipe! +endfunc + +" Test :luafile with syntax error +func Test_luafile_error() + new Xlua_file + call writefile(['nil = 0' ], 'Xlua_file') + call setfperm('Xlua_file', 'r-xr-xr-x') + + call assert_fails('luafile Xlua_file', "Xlua_file:1: unexpected symbol near 'nil'") + + call delete('Xlua_file') + bwipe! +endfunc + +func Test_set_cursor() + " Check that setting the cursor position works. + new + call setline(1, ['first line', 'second line']) + normal gg + lua << EOF +w = vim.window() +w.line = 1 +w.col = 5 +EOF + call assert_equal([1, 5], [line('.'), col('.')]) + + " Check that movement after setting cursor position keeps current column. + normal j + call assert_equal([2, 5], [line('.'), col('.')]) +endfunc diff --git a/src/testdir/test_makeencoding.py b/src/testdir/test_makeencoding.py new file mode 100644 index 0000000..041edad --- /dev/null +++ b/src/testdir/test_makeencoding.py @@ -0,0 +1,67 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Test program for :make, :grep and :cgetfile. + +from __future__ import print_function, unicode_literals +import locale +import io +import sys + +def set_output_encoding(enc=None): + """Set the encoding of stdout and stderr + + arguments: + enc -- Encoding name. + If omitted, locale.getpreferredencoding() is used. + """ + if enc is None: + enc = locale.getpreferredencoding() + + def get_text_writer(fo, **kwargs): + kw = dict(kwargs) + kw.setdefault('errors', 'backslashreplace') # use \uXXXX style + kw.setdefault('closefd', False) + + if sys.version_info[0] < 3: + # Work around for Python 2.x + # New line conversion isn't needed here. Done in somewhere else. + writer = io.open(fo.fileno(), mode='w', newline='', **kw) + write = writer.write # save the original write() function + enc = locale.getpreferredencoding() + def convwrite(s): + if isinstance(s, bytes): + write(s.decode(enc)) # convert to unistr + else: + write(s) + try: + writer.flush() # needed on Windows + except IOError: + pass + writer.write = convwrite + else: + writer = io.open(fo.fileno(), mode='w', **kw) + return writer + + sys.stdout = get_text_writer(sys.stdout, encoding=enc) + sys.stderr = get_text_writer(sys.stderr, encoding=enc) + + +def main(): + enc = 'utf-8' + if len(sys.argv) > 1: + enc = sys.argv[1] + set_output_encoding(enc) + + message_tbl = { + 'utf-8': 'ÀÈÌÒÙ こんにちは 你好', + 'latin1': 'ÀÈÌÒÙ', + 'cp932': 'こんにちは', + 'cp936': '你好', + } + + print('Xfoobar.c(10) : %s (%s)' % (message_tbl[enc], enc)) + + +if __name__ == "__main__": + main() diff --git a/src/testdir/test_makeencoding.vim b/src/testdir/test_makeencoding.vim new file mode 100644 index 0000000..d18b3b6 --- /dev/null +++ b/src/testdir/test_makeencoding.vim @@ -0,0 +1,103 @@ +" Tests for 'makeencoding'. + +source shared.vim + +let s:python = PythonProg() +if s:python == '' + " Can't run this test. + finish +endif + +let s:script = 'test_makeencoding.py' + +let s:message_tbl = { + \ 'utf-8': 'ÀÈÌÒÙ こんにちは 你好', + \ 'latin1': 'ÀÈÌÒÙ', + \ 'cp932': 'こんにちは', + \ 'cp936': '你好', + \} + + +" Tests for :cgetfile and :lgetfile. +func Test_getfile() + set errorfile=Xerror.txt + set errorformat=%f(%l)\ :\ %m + + " :cgetfile + for enc in keys(s:message_tbl) + let &makeencoding = enc + exec "silent !" . s:python . " " . s:script . " " . enc . " > " . &errorfile + cgetfile + copen + call assert_equal("Xfoobar.c|10| " . s:message_tbl[enc] . " (" . enc . ")", + \ getline('.')) + cclose + endfor + + " :lgetfile + for enc in keys(s:message_tbl) + let &makeencoding = enc + exec "silent !" . s:python . " " . s:script . " " . enc . " > " . &errorfile + lgetfile + lopen + call assert_equal("Xfoobar.c|10| " . s:message_tbl[enc] . " (" . enc . ")", + \ getline('.')) + lclose + endfor + + call delete(&errorfile) +endfunc + + +" Tests for :grep and :lgrep. +func Test_grep() + let &grepprg = s:python + set grepformat=%f(%l)\ :\ %m + + " :grep + for enc in keys(s:message_tbl) + let &makeencoding = enc + exec "silent grep! " . s:script . " " . enc + copen + call assert_equal("Xfoobar.c|10| " . s:message_tbl[enc] . " (" . enc . ")", + \ getline('.')) + cclose + endfor + + " :lgrep + for enc in keys(s:message_tbl) + let &makeencoding = enc + exec "silent lgrep! " . s:script . " " . enc + lopen + call assert_equal("Xfoobar.c|10| " . s:message_tbl[enc] . " (" . enc . ")", + \ getline('.')) + lclose + endfor +endfunc + + +" Tests for :make and :lmake. +func Test_make() + let &makeprg = s:python + set errorformat=%f(%l)\ :\ %m + + " :make + for enc in keys(s:message_tbl) + let &makeencoding = enc + exec "silent make! " . s:script . " " . enc + copen + call assert_equal("Xfoobar.c|10| " . s:message_tbl[enc] . " (" . enc . ")", + \ getline('.')) + cclose + endfor + + " :lmake + for enc in keys(s:message_tbl) + let &makeencoding = enc + exec "silent lmake! " . s:script . " " . enc + lopen + call assert_equal("Xfoobar.c|10| " . s:message_tbl[enc] . " (" . enc . ")", + \ getline('.')) + lclose + endfor +endfunc diff --git a/src/testdir/test_man.vim b/src/testdir/test_man.vim new file mode 100644 index 0000000..1485ec3 --- /dev/null +++ b/src/testdir/test_man.vim @@ -0,0 +1,60 @@ +runtime ftplugin/man.vim + +function Test_g_ft_man_open_mode() + vnew + let l:h = winheight(1) + q + let l:w = winwidth(1) + + " split horizontally + let wincnt = winnr('$') + Man vim + if wincnt == winnr('$') + " Vim manual page cannot be found. + return + endif + + call assert_inrange(l:w - 2, l:w + 2, winwidth(1)) + call assert_true(l:h > winheight(1)) + call assert_equal(1, tabpagenr('$')) + call assert_equal(1, tabpagenr()) + q + + " split horizontally + let g:ft_man_open_mode = "horz" + Man vim + call assert_inrange(l:w - 2, l:w + 2, winwidth(1)) + call assert_true(l:h > winheight(1)) + call assert_equal(1, tabpagenr('$')) + call assert_equal(1, tabpagenr()) + q + + " split vertically + let g:ft_man_open_mode = "vert" + Man vim + call assert_true(l:w > winwidth(1)) + call assert_equal(l:h, winheight(1)) + call assert_equal(1, tabpagenr('$')) + call assert_equal(1, tabpagenr()) + q + + " separate tab + let g:ft_man_open_mode = "tab" + Man vim + call assert_inrange(l:w - 2, l:w + 2, winwidth(1)) + call assert_inrange(l:h - 1, l:h + 1, winheight(1)) + call assert_equal(2, tabpagenr('$')) + call assert_equal(2, tabpagenr()) + q +endfunction + +function Test_nomodifiable() + let wincnt = winnr('$') + Man vim + if wincnt == winnr('$') + " Vim manual page cannot be found. + return + endif + call assert_false(&l:modifiable) + q +endfunction diff --git a/src/testdir/test_maparg.vim b/src/testdir/test_maparg.vim new file mode 100644 index 0000000..86e046b --- /dev/null +++ b/src/testdir/test_maparg.vim @@ -0,0 +1,58 @@ +" Tests for maparg(). +" Also test utf8 map with a 0x80 byte. + +function s:SID() + return str2nr(matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$')) +endfun + +function Test_maparg() + new + set cpo-=< + set encoding=utf8 + " Test maparg() with a string result + let sid = s:SID() + let lnum = expand('<sflnum>') + map foo<C-V> is<F4>foo + vnoremap <script> <buffer> <expr> <silent> bar isbar + call assert_equal("is<F4>foo", maparg('foo<C-V>')) + call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'foo<C-V>', + \ 'mode': ' ', 'nowait': 0, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, + \ 'rhs': 'is<F4>foo', 'buffer': 0}, + \ maparg('foo<C-V>', '', 0, 1)) + call assert_equal({'silent': 1, 'noremap': 1, 'lhs': 'bar', 'mode': 'v', + \ 'nowait': 0, 'expr': 1, 'sid': sid, 'lnum': lnum + 2, + \ 'rhs': 'isbar', 'buffer': 1}, + \ maparg('bar', '', 0, 1)) + let lnum = expand('<sflnum>') + map <buffer> <nowait> foo bar + call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'foo', 'mode': ' ', + \ 'nowait': 1, 'expr': 0, 'sid': sid, 'lnum': lnum + 1, 'rhs': 'bar', + \ 'buffer': 1}, + \ maparg('foo', '', 0, 1)) + + map abc x<char-114>x + call assert_equal("xrx", maparg('abc')) + map abc y<S-char-114>y + call assert_equal("yRy", maparg('abc')) + + map abc <Nop> + call assert_equal("<Nop>", maparg('abc')) + unmap abc +endfunction + +function Test_range_map() + new + " Outside of the range, minimum + inoremap <Char-0x1040> a + execute "normal a\u1040\<Esc>" + " Inside of the range, minimum + inoremap <Char-0x103f> b + execute "normal a\u103f\<Esc>" + " Inside of the range, maximum + inoremap <Char-0xf03f> c + execute "normal a\uf03f\<Esc>" + " Outside of the range, maximum + inoremap <Char-0xf040> d + execute "normal a\uf040\<Esc>" + call assert_equal("abcd", getline(1)) +endfunction diff --git a/src/testdir/test_mapping.vim b/src/testdir/test_mapping.vim new file mode 100644 index 0000000..c454fc0 --- /dev/null +++ b/src/testdir/test_mapping.vim @@ -0,0 +1,320 @@ +" Tests for mappings and abbreviations + +source shared.vim + +func Test_abbreviation() + " abbreviation with 0x80 should work + inoreab чкпр vim + call feedkeys("Goчкпр \<Esc>", "xt") + call assert_equal('vim ', getline('$')) + iunab чкпр + set nomodified +endfunc + +func Test_map_ctrl_c_insert() + " mapping of ctrl-c in Insert mode + set cpo-=< cpo-=k + inoremap <c-c> <ctrl-c> + cnoremap <c-c> dummy + cunmap <c-c> + call feedkeys("GoTEST2: CTRL-C |\<C-C>A|\<Esc>", "xt") + call assert_equal('TEST2: CTRL-C |<ctrl-c>A|', getline('$')) + unmap! <c-c> + set nomodified +endfunc + +func Test_map_ctrl_c_visual() + " mapping of ctrl-c in Visual mode + vnoremap <c-c> :<C-u>$put ='vmap works' + call feedkeys("GV\<C-C>\<CR>", "xt") + call assert_equal('vmap works', getline('$')) + vunmap <c-c> + set nomodified +endfunc + +func Test_map_langmap() + if !has('langmap') + return + endif + + " check langmap applies in normal mode + set langmap=+- nolangremap + new + call setline(1, ['a', 'b', 'c']) + 2 + call assert_equal('b', getline('.')) + call feedkeys("+", "xt") + call assert_equal('a', getline('.')) + + " check no remapping + map x + + 2 + call feedkeys("x", "xt") + call assert_equal('c', getline('.')) + + " check with remapping + set langremap + 2 + call feedkeys("x", "xt") + call assert_equal('a', getline('.')) + + unmap x + bwipe! + + " 'langnoremap' follows 'langremap' and vise versa + set langremap + set langnoremap + call assert_equal(0, &langremap) + set langremap + call assert_equal(0, &langnoremap) + set nolangremap + call assert_equal(1, &langnoremap) + + " check default values + set langnoremap& + call assert_equal(0, &langnoremap) + call assert_equal(1, &langremap) + set langremap& + call assert_equal(0, &langnoremap) + call assert_equal(1, &langremap) + + " langmap should not apply in insert mode, 'langremap' doesn't matter + set langmap=+{ nolangremap + call feedkeys("Go+\<Esc>", "xt") + call assert_equal('+', getline('$')) + set langmap=+{ langremap + call feedkeys("Go+\<Esc>", "xt") + call assert_equal('+', getline('$')) + + " langmap used for register name in insert mode. + call setreg('a', 'aaaa') + call setreg('b', 'bbbb') + call setreg('c', 'cccc') + set langmap=ab langremap + call feedkeys("Go\<C-R>a\<Esc>", "xt") + call assert_equal('bbbb', getline('$')) + call feedkeys("Go\<C-R>\<C-R>a\<Esc>", "xt") + call assert_equal('bbbb', getline('$')) + " mapping does not apply + imap c a + call feedkeys("Go\<C-R>c\<Esc>", "xt") + call assert_equal('cccc', getline('$')) + imap a c + call feedkeys("Go\<C-R>a\<Esc>", "xt") + call assert_equal('bbbb', getline('$')) + + " langmap should not apply in Command-line mode + set langmap=+{ nolangremap + call feedkeys(":call append(line('$'), '+')\<CR>", "xt") + call assert_equal('+', getline('$')) + + iunmap a + iunmap c + set nomodified +endfunc + +func Test_map_feedkeys() + " issue #212 (feedkeys insert mapping at current position) + nnoremap . :call feedkeys(".", "in")<cr> + call setline('$', ['a b c d', 'a b c d']) + $-1 + call feedkeys("0qqdw.ifoo\<Esc>qj0@q\<Esc>", "xt") + call assert_equal(['fooc d', 'fooc d'], getline(line('$') - 1, line('$'))) + nunmap . + set nomodified +endfunc + +func Test_map_cursor() + " <c-g>U<cursor> works only within a single line + imapclear + imap ( ()<c-g>U<left> + call feedkeys("G2o\<Esc>ki\<CR>Test1: text with a (here some more text\<Esc>k.", "xt") + call assert_equal('Test1: text with a (here some more text)', getline(line('$') - 2)) + call assert_equal('Test1: text with a (here some more text)', getline(line('$') - 1)) + + " test undo + call feedkeys("G2o\<Esc>ki\<CR>Test2: text wit a (here some more text [und undo]\<C-G>u\<Esc>k.u", "xt") + call assert_equal('', getline(line('$') - 2)) + call assert_equal('Test2: text wit a (here some more text [und undo])', getline(line('$') - 1)) + set nomodified + imapclear +endfunc + +" This isn't actually testing a mapping, but similar use of CTRL-G U as above. +func Test_break_undo() + :set whichwrap=<,>,[,] + call feedkeys("G4o2k", "xt") + exe ":norm! iTest3: text with a (parenthesis here\<C-G>U\<Right>new line here\<esc>\<up>\<up>." + call assert_equal('new line here', getline(line('$') - 3)) + call assert_equal('Test3: text with a (parenthesis here', getline(line('$') - 2)) + call assert_equal('new line here', getline(line('$') - 1)) + set nomodified +endfunc + +func Test_map_meta_quotes() + imap <M-"> foo + call feedkeys("Go-\<M-\">-\<Esc>", "xt") + call assert_equal("-foo-", getline('$')) + set nomodified + iunmap <M-"> +endfunc + +func Test_abbr_after_line_join() + new + abbr foo bar + set backspace=indent,eol,start + exe "normal o\<BS>foo " + call assert_equal("bar ", getline(1)) + bwipe! + unabbr foo + set backspace& +endfunc + +func Test_map_timeout() + if !has('timers') + return + endif + nnoremap aaaa :let got_aaaa = 1<CR> + nnoremap bb :let got_bb = 1<CR> + nmap b aaa + new + func ExitInsert(timer) + let g:line = getline(1) + call feedkeys("\<Esc>", "t") + endfunc + set timeout timeoutlen=200 + let timer = timer_start(300, 'ExitInsert') + " After the 'b' Vim waits for another character to see if it matches 'bb'. + " When it times out it is expanded to "aaa", but there is no wait for + " "aaaa". Can't check that reliably though. + call feedkeys("b", "xt!") + call assert_equal("aa", g:line) + call assert_false(exists('got_aaa')) + call assert_false(exists('got_bb')) + + bwipe! + nunmap aaaa + nunmap bb + nunmap b + set timeoutlen& + delfunc ExitInsert + call timer_stop(timer) +endfunc + +func Test_map_timeout_with_timer_interrupt() + if !has('job') || !has('timers') + return + endif + + " Confirm the timer invoked in exit_cb of the job doesn't disturb mapped key + " sequence. + new + let g:val = 0 + nnoremap \12 :let g:val = 1<CR> + nnoremap \123 :let g:val = 2<CR> + set timeout timeoutlen=1000 + + func ExitCb(job, status) + let g:timer = timer_start(1, {-> feedkeys("3\<Esc>", 't')}) + endfunc + + call job_start([&shell, &shellcmdflag, 'echo'], {'exit_cb': 'ExitCb'}) + call feedkeys('\12', 'xt!') + call assert_equal(2, g:val) + + bwipe! + nunmap \12 + nunmap \123 + set timeoutlen& + call WaitFor({-> exists('g:timer')}) + call timer_stop(g:timer) + unlet g:timer + unlet g:val + delfunc ExitCb +endfunc + +func Test_abbreviation_CR() + new + func Eatchar(pat) + let c = nr2char(getchar(0)) + return (c =~ a:pat) ? '' : c + endfunc + iabbrev <buffer><silent> ~~7 <c-r>=repeat('~', 7)<CR><c-r>=Eatchar('\s')<cr> + call feedkeys("GA~~7 \<esc>", 'xt') + call assert_equal('~~~~~~~', getline('$')) + %d + call feedkeys("GA~~7\<cr>\<esc>", 'xt') + call assert_equal(['~~~~~~~', ''], getline(1,'$')) + delfunc Eatchar + bw! +endfunc + +func Test_cabbr_visual_mode() + cabbr s su + call feedkeys(":s \<c-B>\"\<CR>", 'itx') + call assert_equal('"su ', getreg(':')) + call feedkeys(":'<,'>s \<c-B>\"\<CR>", 'itx') + let expected = '"'. "'<,'>su " + call assert_equal(expected, getreg(':')) + call feedkeys(": '<,'>s \<c-B>\"\<CR>", 'itx') + let expected = '" '. "'<,'>su " + call assert_equal(expected, getreg(':')) + call feedkeys(":'a,'bs \<c-B>\"\<CR>", 'itx') + let expected = '"'. "'a,'bsu " + call assert_equal(expected, getreg(':')) + cunabbr s +endfunc + +func Test_motionforce_omap() + func GetCommand() + let g:m=mode(1) + let [g:lnum1, g:col1] = searchpos('-', 'Wb') + if g:lnum1 == 0 + return "\<Esc>" + endif + let [g:lnum2, g:col2] = searchpos('-', 'W') + if g:lnum2 == 0 + return "\<Esc>" + endif + return ":call Select()\<CR>" + endfunc + func Select() + call cursor([g:lnum1, g:col1]) + exe "normal! 1 ". (strlen(g:m) == 2 ? 'v' : g:m[2]) + call cursor([g:lnum2, g:col2]) + execute "normal! \<BS>" + endfunc + new + onoremap <buffer><expr> i- GetCommand() + " 1) default omap mapping + %d_ + call setline(1, ['aaa - bbb', 'x', 'ddd - eee']) + call cursor(2, 1) + norm di- + call assert_equal('no', g:m) + call assert_equal(['aaa -- eee'], getline(1, '$')) + " 2) forced characterwise operation + %d_ + call setline(1, ['aaa - bbb', 'x', 'ddd - eee']) + call cursor(2, 1) + norm dvi- + call assert_equal('nov', g:m) + call assert_equal(['aaa -- eee'], getline(1, '$')) + " 3) forced linewise operation + %d_ + call setline(1, ['aaa - bbb', 'x', 'ddd - eee']) + call cursor(2, 1) + norm dVi- + call assert_equal('noV', g:m) + call assert_equal([''], getline(1, '$')) + " 4) forced blockwise operation + %d_ + call setline(1, ['aaa - bbb', 'x', 'ddd - eee']) + call cursor(2, 1) + exe "norm d\<C-V>i-" + call assert_equal("no\<C-V>", g:m) + call assert_equal(['aaabbb', 'x', 'dddeee'], getline(1, '$')) + bwipe! + delfunc Select + delfunc GetCommand +endfunc diff --git a/src/testdir/test_marks.vim b/src/testdir/test_marks.vim new file mode 100644 index 0000000..a9bba57 --- /dev/null +++ b/src/testdir/test_marks.vim @@ -0,0 +1,176 @@ + +" Test that a deleted mark is restored after delete-undo-redo-undo. +func Test_Restore_DelMark() + enew! + call append(0, [" textline A", " textline B", " textline C"]) + normal! 2gg + set nocp viminfo+=nviminfo + exe "normal! i\<C-G>u\<Esc>" + exe "normal! maddu\<C-R>u" + let pos = getpos("'a") + call assert_equal(2, pos[1]) + call assert_equal(1, pos[2]) + enew! +endfunc + +" Test that CTRL-A and CTRL-X updates last changed mark '[, ']. +func Test_Incr_Marks() + enew! + call append(0, ["123 123 123", "123 123 123", "123 123 123"]) + normal! gg + execute "normal! \<C-A>`[v`]rAjwvjw\<C-X>`[v`]rX" + call assert_equal("AAA 123 123", getline(1)) + call assert_equal("123 XXXXXXX", getline(2)) + call assert_equal("XXX 123 123", getline(3)) + enew! +endfunc + +func Test_setpos() + new one + let onebuf = bufnr('%') + let onewin = win_getid() + call setline(1, ['aaa', 'bbb', 'ccc']) + new two + let twobuf = bufnr('%') + let twowin = win_getid() + call setline(1, ['aaa', 'bbb', 'ccc']) + + " for the cursor the buffer number is ignored + call setpos(".", [0, 2, 1, 0]) + call assert_equal([0, 2, 1, 0], getpos(".")) + call setpos(".", [onebuf, 3, 3, 0]) + call assert_equal([0, 3, 3, 0], getpos(".")) + + call setpos("''", [0, 1, 3, 0]) + call assert_equal([0, 1, 3, 0], getpos("''")) + call setpos("''", [onebuf, 2, 2, 0]) + call assert_equal([0, 2, 2, 0], getpos("''")) + + " buffer-local marks + for mark in ["'a", "'\"", "'[", "']", "'<", "'>"] + call win_gotoid(twowin) + call setpos(mark, [0, 2, 1, 0]) + call assert_equal([0, 2, 1, 0], getpos(mark), "for mark " . mark) + call setpos(mark, [onebuf, 1, 3, 0]) + call win_gotoid(onewin) + call assert_equal([0, 1, 3, 0], getpos(mark), "for mark " . mark) + endfor + + " global marks + call win_gotoid(twowin) + call setpos("'N", [0, 2, 1, 0]) + call assert_equal([twobuf, 2, 1, 0], getpos("'N")) + call setpos("'N", [onebuf, 1, 3, 0]) + call assert_equal([onebuf, 1, 3, 0], getpos("'N")) + + call win_gotoid(onewin) + bwipe! + call win_gotoid(twowin) + bwipe! +endfunc + +func Test_marks_cmd() + new Xone + call setline(1, ['aaa', 'bbb']) + norm! maG$mB + w! + new Xtwo + call setline(1, ['ccc', 'ddd']) + norm! $mcGmD + w! + + b Xone + let a = split(execute('marks'), "\n") + call assert_equal(9, len(a)) + call assert_equal('mark line col file/text', a[0]) + call assert_equal(" ' 2 0 bbb", a[1]) + call assert_equal(' a 1 0 aaa', a[2]) + call assert_equal(' B 2 2 bbb', a[3]) + call assert_equal(' D 2 0 Xtwo', a[4]) + call assert_equal(' " 1 0 aaa', a[5]) + call assert_equal(' [ 1 0 aaa', a[6]) + call assert_equal(' ] 2 0 bbb', a[7]) + call assert_equal(' . 2 0 bbb', a[8]) + + b Xtwo + let a = split(execute('marks'), "\n") + call assert_equal(9, len(a)) + call assert_equal('mark line col file/text', a[0]) + call assert_equal(" ' 1 0 ccc", a[1]) + call assert_equal(' c 1 2 ccc', a[2]) + call assert_equal(' B 2 2 Xone', a[3]) + call assert_equal(' D 2 0 ddd', a[4]) + call assert_equal(' " 2 0 ddd', a[5]) + call assert_equal(' [ 1 0 ccc', a[6]) + call assert_equal(' ] 2 0 ddd', a[7]) + call assert_equal(' . 2 0 ddd', a[8]) + + b Xone + delmarks aB + let a = split(execute('marks aBcD'), "\n") + call assert_equal(2, len(a)) + call assert_equal('mark line col file/text', a[0]) + call assert_equal(' D 2 0 Xtwo', a[1]) + + b Xtwo + delmarks cD + call assert_fails('marks aBcD', 'E283:') + + call delete('Xone') + call delete('Xtwo') + %bwipe +endfunc + +func Test_marks_cmd_multibyte() + new Xone + call setline(1, [repeat('á', &columns)]) + norm! ma + + let a = split(execute('marks a'), "\n") + call assert_equal(2, len(a)) + let expected = ' a 1 0 ' . repeat('á', &columns - 16) + call assert_equal(expected, a[1]) + + bwipe! +endfunc + +func Test_delmarks() + new + norm mx + norm `x + delmarks x + call assert_fails('norm `x', 'E20:') + + " Deleting an already deleted mark should not fail. + delmarks x + + " Test deleting a range of marks. + norm ma + norm mb + norm mc + norm mz + delmarks b-z + norm `a + call assert_fails('norm `b', 'E20:') + call assert_fails('norm `c', 'E20:') + call assert_fails('norm `z', 'E20:') + call assert_fails('delmarks z-b', 'E475:') + + call assert_fails('delmarks', 'E471:') + call assert_fails('delmarks /', 'E475:') + + " Test delmarks! + norm mx + norm `x + delmarks! + call assert_fails('norm `x', 'E20:') + call assert_fails('delmarks! x', 'E474:') + + bwipe! +endfunc + +func Test_mark_error() + call assert_fails('mark', 'E471:') + call assert_fails('mark xx', 'E488:') + call assert_fails('mark _', 'E191:') +endfunc diff --git a/src/testdir/test_match.vim b/src/testdir/test_match.vim new file mode 100644 index 0000000..94bca9a --- /dev/null +++ b/src/testdir/test_match.vim @@ -0,0 +1,241 @@ +" Test for :match, :2match, :3match, clearmatches(), getmatches(), matchadd(), +" matchaddpos(), matcharg(), matchdelete(), and setmatches(). + +function Test_match() + highlight MyGroup1 term=bold ctermbg=red guibg=red + highlight MyGroup2 term=italic ctermbg=green guibg=green + highlight MyGroup3 term=underline ctermbg=blue guibg=blue + + " --- Check that "matcharg()" returns the correct group and pattern if a match + " --- is defined. + match MyGroup1 /TODO/ + 2match MyGroup2 /FIXME/ + 3match MyGroup3 /XXX/ + call assert_equal(['MyGroup1', 'TODO'], matcharg(1)) + call assert_equal(['MyGroup2', 'FIXME'], matcharg(2)) + call assert_equal(['MyGroup3', 'XXX'], matcharg(3)) + + " --- Check that "matcharg()" returns an empty list if the argument is not 1, + " --- 2 or 3 (only 0 and 4 are tested). + call assert_equal([], matcharg(0)) + call assert_equal([], matcharg(4)) + + " --- Check that "matcharg()" returns ['', ''] if a match is not defined. + match + 2match + 3match + call assert_equal(['', ''], matcharg(1)) + call assert_equal(['', ''], matcharg(2)) + call assert_equal(['', ''], matcharg(3)) + + " --- Check that "matchadd()" and "getmatches()" agree on added matches and + " --- that default values apply. + let m1 = matchadd("MyGroup1", "TODO") + let m2 = matchadd("MyGroup2", "FIXME", 42) + let m3 = matchadd("MyGroup3", "XXX", 60, 17) + let ans = [{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 4}, + \ {'group': 'MyGroup2', 'pattern': 'FIXME', 'priority': 42, 'id': 5}, + \ {'group': 'MyGroup3', 'pattern': 'XXX', 'priority': 60, 'id': 17}] + call assert_equal(ans, getmatches()) + + " --- Check that "matchdelete()" deletes the matches defined in the previous + " --- test correctly. + call matchdelete(m1) + call matchdelete(m2) + call matchdelete(m3) + call assert_equal([], getmatches()) + + " --- Check that "matchdelete()" returns 0 if successful and otherwise -1. + let m = matchadd("MyGroup1", "TODO") + call assert_equal(0, matchdelete(m)) + call assert_fails('call matchdelete(42)', 'E803:') + + " --- Check that "clearmatches()" clears all matches defined by ":match" and + " --- "matchadd()". + let m1 = matchadd("MyGroup1", "TODO") + let m2 = matchadd("MyGroup2", "FIXME", 42) + let m3 = matchadd("MyGroup3", "XXX", 60, 17) + match MyGroup1 /COFFEE/ + 2match MyGroup2 /HUMPPA/ + 3match MyGroup3 /VIM/ + call clearmatches() + call assert_equal([], getmatches()) + + " --- Check that "setmatches()" restores a list of matches saved by + " --- "getmatches()" without changes. (Matches with equal priority must also + " --- remain in the same order.) + let m1 = matchadd("MyGroup1", "TODO") + let m2 = matchadd("MyGroup2", "FIXME", 42) + let m3 = matchadd("MyGroup3", "XXX", 60, 17) + match MyGroup1 /COFFEE/ + 2match MyGroup2 /HUMPPA/ + 3match MyGroup3 /VIM/ + let ml = getmatches() + call clearmatches() + call setmatches(ml) + call assert_equal(ml, getmatches()) + call clearmatches() + + " --- Check that "setmatches()" will not add two matches with the same ID. The + " --- expected behaviour (for now) is to add the first match but not the + " --- second and to return 0 (even though it is a matter of debate whether + " --- this can be considered successful behaviour). + let data = [{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}, + \ {'group': 'MyGroup2', 'pattern': 'FIXME', 'priority': 10, 'id': 1}] + call assert_fails('call setmatches(data)', 'E801:') + call assert_equal([data[0]], getmatches()) + call clearmatches() + + " --- Check that "setmatches()" returns 0 if successful and otherwise -1. + " --- (A range of valid and invalid input values are tried out to generate the + " --- return values.) + call assert_equal(0, setmatches([])) + call assert_equal(0, setmatches([{'group': 'MyGroup1', 'pattern': 'TODO', 'priority': 10, 'id': 1}])) + call clearmatches() + call assert_fails('call setmatches(0)', 'E714:') + call assert_fails('call setmatches([0])', 'E474:') + call assert_fails("call setmatches([{'wrong key': 'wrong value'}])", 'E474:') + + call setline(1, 'abcdefghijklmnopq') + call matchaddpos("MyGroup1", [[1, 5], [1, 8, 3]], 10, 3) + 1 + redraw! + let v1 = screenattr(1, 1) + let v5 = screenattr(1, 5) + let v6 = screenattr(1, 6) + let v8 = screenattr(1, 8) + let v10 = screenattr(1, 10) + let v11 = screenattr(1, 11) + call assert_notequal(v1, v5) + call assert_equal(v6, v1) + call assert_equal(v8, v5) + call assert_equal(v10, v5) + call assert_equal(v11, v1) + call assert_equal([{'group': 'MyGroup1', 'id': 3, 'priority': 10, 'pos1': [1, 5, 1], 'pos2': [1, 8, 3]}], getmatches()) + call clearmatches() + + call setline(1, 'abcdΣabcdef') + call matchaddpos("MyGroup1", [[1, 4, 2], [1, 9, 2]]) + 1 + redraw! + let v1 = screenattr(1, 1) + let v4 = screenattr(1, 4) + let v5 = screenattr(1, 5) + let v6 = screenattr(1, 6) + let v7 = screenattr(1, 7) + let v8 = screenattr(1, 8) + let v9 = screenattr(1, 9) + let v10 = screenattr(1, 10) + call assert_equal([{'group': 'MyGroup1', 'id': 11, 'priority': 10, 'pos1': [1, 4, 2], 'pos2': [1, 9, 2]}], getmatches()) + call assert_notequal(v1, v4) + call assert_equal(v5, v4) + call assert_equal(v6, v1) + call assert_equal(v7, v1) + call assert_equal(v8, v4) + call assert_equal(v9, v4) + call assert_equal(v10, v1) + + " Check, that setmatches() can correctly restore the matches from matchaddpos() + call matchadd('MyGroup1', '\%2lmatchadd') + let m=getmatches() + call clearmatches() + call setmatches(m) + call assert_equal([{'group': 'MyGroup1', 'id': 11, 'priority': 10, 'pos1': [1, 4, 2], 'pos2': [1,9, 2]}, {'group': 'MyGroup1', 'pattern': '\%2lmatchadd', 'priority': 10, 'id': 12}], getmatches()) + + highlight MyGroup1 NONE + highlight MyGroup2 NONE + highlight MyGroup3 NONE +endfunc + +func Test_matchaddpos() + syntax on + set hlsearch + + call setline(1, ['12345', 'NP']) + call matchaddpos('Error', [[1,2], [1,6], [2,2]]) + redraw! + call assert_notequal(screenattr(2,2), 0) + call assert_equal(screenattr(2,2), screenattr(1,2)) + call assert_notequal(screenattr(2,2), screenattr(1,6)) + 1 + call matchadd('Search', 'N\|\n') + redraw! + call assert_notequal(screenattr(2,1), 0) + call assert_equal(screenattr(2,1), screenattr(1,6)) + exec "norm! i0\<Esc>" + redraw! + call assert_equal(screenattr(2,2), screenattr(1,6)) + + " Check overlapping pos + call clearmatches() + call setline(1, ['1234567890', 'NH']) + call matchaddpos('Error', [[1,1,5], [1,3,5], [2,2]]) + redraw! + call assert_notequal(screenattr(2,2), 0) + call assert_equal(screenattr(2,2), screenattr(1,5)) + call assert_equal(screenattr(2,2), screenattr(1,7)) + call assert_notequal(screenattr(2,2), screenattr(1,8)) + + call clearmatches() + call matchaddpos('Error', [[1], [2,2]]) + redraw! + call assert_equal(screenattr(2,2), screenattr(1,1)) + call assert_equal(screenattr(2,2), screenattr(1,10)) + call assert_notequal(screenattr(2,2), screenattr(1,11)) + + nohl + call clearmatches() + syntax off + set hlsearch& +endfunc + +func Test_matchaddpos_otherwin() + syntax on + new + call setline(1, ['12345', 'NP']) + let winid = win_getid() + + wincmd w + call matchadd('Search', '4', 10, -1, {'window': winid}) + call matchaddpos('Error', [[1,2], [2,2]], 10, -1, {'window': winid}) + redraw! + call assert_notequal(screenattr(1,2), 0) + call assert_notequal(screenattr(1,4), 0) + call assert_notequal(screenattr(2,2), 0) + call assert_equal(screenattr(1,2), screenattr(2,2)) + call assert_notequal(screenattr(1,2), screenattr(1,4)) + + wincmd w + bwipe! + call clearmatches() + syntax off +endfunc + +func Test_matchaddpos_using_negative_priority() + set hlsearch + + call clearmatches() + + call setline(1, 'x') + let @/='x' + redraw! + let search_attr = screenattr(1,1) + + let @/='' + call matchaddpos('Error', [1], 10) + redraw! + let error_attr = screenattr(1,1) + + call setline(2, '-1 match priority') + call matchaddpos('Error', [2], -1) + redraw! + let negative_match_priority_attr = screenattr(2,1) + + call assert_notequal(negative_match_priority_attr, search_attr, "Match with negative priority is incorrectly highlighted with Search highlight.") + call assert_equal(negative_match_priority_attr, error_attr) + + nohl + set hlsearch& +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_matchadd_conceal.vim b/src/testdir/test_matchadd_conceal.vim new file mode 100644 index 0000000..8d774a0 --- /dev/null +++ b/src/testdir/test_matchadd_conceal.vim @@ -0,0 +1,279 @@ +" Test for matchadd() and conceal feature +if !has('conceal') + finish +endif + +if !has('gui_running') && has('unix') + set term=ansi +endif + +source shared.vim + +func Test_simple_matchadd() + new + + 1put='# This is a Test' + " 1234567890123456 + let expect = '# This is a Test' + + call cursor(1, 1) + call matchadd('Conceal', '\%2l ') + redraw! + let lnum = 2 + call assert_equal(expect, Screenline(lnum)) + call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 2)) + call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 2)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 7)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 10)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12)) + call assert_equal(screenattr(lnum, 1), screenattr(lnum, 16)) + + quit! +endfunc + +func Test_simple_matchadd_and_conceal() + new + setlocal concealcursor=n conceallevel=1 + + 1put='# This is a Test' + " 1234567890123456 + let expect = '#XThisXisXaXTest' + + call cursor(1, 1) + call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'X'}) + redraw! + let lnum = 2 + call assert_equal(expect, Screenline(lnum)) + call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 2)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 7)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 10)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12)) + call assert_equal(screenattr(lnum, 1), screenattr(lnum, 16)) + + quit! +endfunc + +func Test_matchadd_and_conceallevel_3() + new + + setlocal conceallevel=3 + " set filetype and :syntax on to change screenattr() + setlocal filetype=conf + syntax on + + 1put='# This is a Test' + " 1234567890123456 + let expect = '#ThisisaTest' + + call cursor(1, 1) + call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'X'}) + redraw! + let lnum = 2 + call assert_equal(expect, Screenline(lnum)) + call assert_equal(screenattr(lnum, 1), screenattr(lnum, 2)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 7)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 10)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12)) + call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 16)) + + " more matchadd() + " 1234567890123456 + let expect = '#Thisisa Test' + + call matchadd('ErrorMsg', '\%2l Test', 20, -1, {'conceal': 'X'}) + redraw! + call assert_equal(expect, Screenline(lnum)) + call assert_equal(screenattr(lnum, 1) , screenattr(lnum, 2)) + call assert_equal(screenattr(lnum, 2) , screenattr(lnum, 7)) + call assert_notequal(screenattr(lnum, 1) , screenattr(lnum, 10)) + call assert_equal(screenattr(lnum, 10), screenattr(lnum, 12)) + call assert_notequal(screenattr(lnum, 1) , screenattr(lnum, 16)) + call assert_notequal(screenattr(lnum, 10), screenattr(lnum, 16)) + + syntax off + quit! +endfunc + +func Test_default_conceal_char() + new + setlocal concealcursor=n conceallevel=1 + + 1put='# This is a Test' + " 1234567890123456 + let expect = '# This is a Test' + + call cursor(1, 1) + call matchadd('Conceal', '\%2l ', 10, -1, {}) + redraw! + let lnum = 2 + call assert_equal(expect, Screenline(lnum)) + call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 2)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 7)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 10)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12)) + call assert_equal(screenattr(lnum, 1), screenattr(lnum, 16)) + + " 1234567890123456 + let expect = '#+This+is+a+Test' + let listchars_save = &listchars + set listchars=conceal:+ + redraw! + + call assert_equal(expect, Screenline(lnum)) + call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 2)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 7)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 10)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12)) + call assert_equal(screenattr(lnum, 1), screenattr(lnum, 16)) + + let &listchars = listchars_save + quit! +endfunc + +func Test_syn_and_match_conceal() + new + setlocal concealcursor=n conceallevel=1 + + 1put='# This is a Test' + " 1234567890123456 + let expect = '#ZThisZisZaZTest' + + call cursor(1, 1) + call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'Z'}) + syntax match MyConceal /\%2l / conceal containedin=ALL cchar=* + redraw! + let lnum = 2 + call assert_equal(expect, Screenline(lnum)) + call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 2)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 7)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 10)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12)) + call assert_equal(screenattr(lnum, 1), screenattr(lnum, 16)) + + " 1234567890123456 + let expect = '#*This*is*a*Test' + call clearmatches() + redraw! + + call assert_equal(expect, Screenline(lnum)) + call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 2)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 7)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 10)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12)) + call assert_equal(screenattr(lnum, 1), screenattr(lnum, 16)) + + syntax off + quit! +endfunc + +func Test_clearmatches() + new + setlocal concealcursor=n conceallevel=1 + + 1put='# This is a Test' + " 1234567890123456 + let expect = '# This is a Test' + + call cursor(1, 1) + call matchadd('Conceal', '\%2l ', 10, -1, {'conceal': 'Z'}) + let a = getmatches() + call clearmatches() + redraw! + + let lnum = 2 + call assert_equal(expect, Screenline(lnum)) + call assert_equal(screenattr(lnum, 1), screenattr(lnum, 2)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 7)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 10)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12)) + call assert_equal(screenattr(lnum, 1), screenattr(lnum, 16)) + + " reset match using setmatches() + " 1234567890123456 + let expect = '#ZThisZisZaZTest' + call setmatches(a) + redraw! + + call assert_equal(expect, Screenline(lnum)) + call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 2)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 7)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 10)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12)) + call assert_equal(screenattr(lnum, 1), screenattr(lnum, 16)) + call assert_equal({'group': 'Conceal', 'pattern': '\%2l ', 'priority': 10, 'id': a[0].id, 'conceal': 'Z'}, a[0]) + + quit! +endfunc + +func Test_using_matchaddpos() + new + setlocal concealcursor=n conceallevel=1 + " set filetype and :syntax on to change screenattr() + setlocal filetype=conf + syntax on + + 1put='# This is a Test' + " 1234567890123456 + let expect = '#Pis a Test' + + call cursor(1, 1) + call matchaddpos('Conceal', [[2,2,6]], 10, -1, {'conceal': 'P'}) + let a = getmatches() + redraw! + + let lnum = 2 + call assert_equal(expect, Screenline(lnum)) + call assert_notequal(screenattr(lnum, 1) , screenattr(lnum, 2)) + call assert_notequal(screenattr(lnum, 2) , screenattr(lnum, 7)) + call assert_equal(screenattr(lnum, 1) , screenattr(lnum, 7)) + call assert_equal(screenattr(lnum, 1) , screenattr(lnum, 10)) + call assert_notequal(screenattr(lnum, 1) , screenattr(lnum, 12)) + call assert_notequal(screenattr(lnum, 1) , screenattr(lnum, 16)) + call assert_equal(screenattr(lnum, 12), screenattr(lnum, 16)) + call assert_equal({'group': 'Conceal', 'id': a[0].id, 'priority': 10, 'pos1': [2, 2, 6], 'conceal': 'P'}, a[0]) + + syntax off + quit! +endfunc + +func Test_matchadd_repeat_conceal_with_syntax_off() + new + + " To test targets in the same line string is replaced with conceal char + " correctly, repeat 'TARGET' + 1put ='TARGET_TARGETTARGET' + call cursor(1, 1) + redraw + call assert_equal('TARGET_TARGETTARGET', Screenline(2)) + + setlocal conceallevel=2 + call matchadd('Conceal', 'TARGET', 10, -1, {'conceal': 't'}) + + redraw + call assert_equal('t_tt', Screenline(2)) + + quit! +endfunc + +func Test_matchadd_and_syn_conceal() + new + let cnt='Inductive bool : Type := | true : bool | false : bool.' + let expect = 'Inductive - : Type := | true : - | false : -.' + 0put =cnt + " set filetype and :syntax on to change screenattr() + set cole=1 cocu=nv + hi link CheckedByCoq WarningMsg + syntax on + syntax keyword coqKwd bool conceal cchar=- + redraw! + call assert_equal(expect, Screenline(1)) + call assert_notequal(screenattr(1, 10) , screenattr(1, 11)) + call assert_notequal(screenattr(1, 11) , screenattr(1, 12)) + call assert_equal(screenattr(1, 11) , screenattr(1, 32)) + call matchadd('CheckedByCoq', '\%<2l\%>9c\%<16c') + redraw! + call assert_equal(expect, Screenline(1)) + call assert_notequal(screenattr(1, 10) , screenattr(1, 11)) + call assert_notequal(screenattr(1, 11) , screenattr(1, 12)) + call assert_equal(screenattr(1, 11) , screenattr(1, 32)) +endfunc diff --git a/src/testdir/test_matchadd_conceal_utf8.vim b/src/testdir/test_matchadd_conceal_utf8.vim new file mode 100644 index 0000000..d280c15 --- /dev/null +++ b/src/testdir/test_matchadd_conceal_utf8.vim @@ -0,0 +1,43 @@ +" Test for matchadd() and conceal feature using utf-8. +if !has('conceal') + finish +endif + +if !has('gui_running') && has('unix') + set term=ansi +endif + +func s:screenline(lnum) abort + let line = [] + for c in range(1, winwidth(0)) + call add(line, nr2char(screenchar(a:lnum, c))) + endfor + return s:trim(join(line, '')) +endfunc + +func s:trim(str) abort + return matchstr(a:str,'^\s*\zs.\{-}\ze\s*$') +endfunc + +func Test_match_using_multibyte_conceal_char() + new + setlocal concealcursor=n conceallevel=1 + + 1put='# This is a Test' + " 1234567890123456 + let expect = '#ˑThisˑisˑaˑTest' + + call cursor(1, 1) + call matchadd('Conceal', '\%2l ', 20, -1, {'conceal': "\u02d1"}) + redraw! + + let lnum = 2 + call assert_equal(expect, s:screenline(lnum)) + call assert_notequal(screenattr(lnum, 1), screenattr(lnum, 2)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 7)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 10)) + call assert_equal(screenattr(lnum, 2), screenattr(lnum, 12)) + call assert_equal(screenattr(lnum, 1), screenattr(lnum, 16)) + + quit! +endfunc diff --git a/src/testdir/test_menu.vim b/src/testdir/test_menu.vim new file mode 100644 index 0000000..6462d51 --- /dev/null +++ b/src/testdir/test_menu.vim @@ -0,0 +1,66 @@ +" Test that the system menu can be loaded. + +if !has('menu') + finish +endif + +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')) + source $VIMRUNTIME/delmenu.vim +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'<CR> + vmenu 2 Test.FooBar :let g:did_menu = 'visual'<CR> + smenu 2 Test.FooBar :let g:did_menu = 'select'<CR> + omenu 2 Test.FooBar :let g:did_menu = 'op-pending'<CR> + tlmenu 2 Test.FooBar :let g:did_menu = 'terminal'<CR> + imenu 2 Test.FooBar :let g:did_menu = 'insert'<CR> + cmenu 2 Test.FooBar :let g:did_menu = 'cmdline'<CR> + emenu n 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) + + aunmenu Test.FooBar + tlunmenu Test.FooBar + call assert_fails('emenu n Test.FooBar', 'E334:') + + nmenu 2 Test.FooBar.Child :let g:did_menu = 'foobar'<CR> + call assert_fails('emenu n Test.FooBar', 'E333:') + nunmenu Test.FooBar.Child + + unlet g:did_menu +endfun diff --git a/src/testdir/test_messages.vim b/src/testdir/test_messages.vim new file mode 100644 index 0000000..4bdc136 --- /dev/null +++ b/src/testdir/test_messages.vim @@ -0,0 +1,94 @@ +" Tests for :messages, :echomsg, :echoerr + +function Test_messages() + let oldmore = &more + try + set nomore + " Avoid the "message maintainer" line. + let $LANG = '' + + let arr = map(range(10), '"hello" . v:val') + for s in arr + echomsg s | redraw + endfor + let result = '' + + " get last two messages + redir => result + 2messages | redraw + redir END + let msg_list = split(result, "\n") + call assert_equal(["hello8", "hello9"], msg_list) + + " clear messages without last one + 1messages clear + redir => result + redraw | messages + redir END + let msg_list = split(result, "\n") + call assert_equal(['hello9'], msg_list) + + " clear all messages + messages clear + redir => result + redraw | messages + redir END + call assert_equal('', result) + finally + let &more = oldmore + endtry +endfunction + +" Patch 7.4.1696 defined the "clearmode()" function for clearing the mode +" indicator (e.g., "-- INSERT --") when ":stopinsert" is invoked. Message +" output could then be disturbed when 'cmdheight' was greater than one. +" This test ensures that the bugfix for this issue remains in place. +func Test_stopinsert_does_not_break_message_output() + set cmdheight=2 + redraw! + + stopinsert | echo 'test echo' + call assert_equal(116, screenchar(&lines - 1, 1)) + call assert_equal(32, screenchar(&lines, 1)) + redraw! + + stopinsert | echomsg 'test echomsg' + call assert_equal(116, screenchar(&lines - 1, 1)) + call assert_equal(32, screenchar(&lines, 1)) + redraw! + + set cmdheight& +endfunc + +func Test_message_completion() + call feedkeys(":message \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"message clear', @:) +endfunc + +func Test_echomsg() + call assert_equal("\nhello", execute(':echomsg "hello"')) + call assert_equal("\n", execute(':echomsg ""')) + call assert_equal("\n12345", execute(':echomsg 12345')) + call assert_equal("\n[]", execute(':echomsg []')) + call assert_equal("\n[1, 2, 3]", execute(':echomsg [1, 2, 3]')) + call assert_equal("\n{}", execute(':echomsg {}')) + call assert_equal("\n{'a': 1, 'b': 2}", execute(':echomsg {"a": 1, "b": 2}')) + if has('float') + call assert_equal("\n1.23", execute(':echomsg 1.23')) + endif + call assert_match("function('<lambda>\\d*')", execute(':echomsg {-> 1234}')) +endfunc + +func Test_echoerr() + call test_ignore_error('IgNoRe') + call assert_equal("\nIgNoRe hello", execute(':echoerr "IgNoRe hello"')) + call assert_equal("\n12345 IgNoRe", execute(':echoerr 12345 "IgNoRe"')) + call assert_equal("\n[1, 2, 'IgNoRe']", execute(':echoerr [1, 2, "IgNoRe"]')) + call assert_equal("\n{'IgNoRe': 2, 'a': 1}", execute(':echoerr {"a": 1, "IgNoRe": 2}')) + if has('float') + call assert_equal("\n1.23 IgNoRe", execute(':echoerr 1.23 "IgNoRe"')) + endif + call test_ignore_error('<lambda>') + call assert_match("function('<lambda>\\d*')", execute(':echoerr {-> 1234}')) + call test_ignore_error('RESET') +endfunc diff --git a/src/testdir/test_mksession.vim b/src/testdir/test_mksession.vim new file mode 100644 index 0000000..456cd1e --- /dev/null +++ b/src/testdir/test_mksession.vim @@ -0,0 +1,498 @@ +" Test for :mksession, :mkview and :loadview in latin1 encoding + +set encoding=latin1 +scriptencoding latin1 + +if !has('mksession') + finish +endif + +source shared.vim + +func Test_mksession() + tabnew + let wrap_save = &wrap + set sessionoptions=buffers splitbelow fileencoding=latin1 + call setline(1, [ + \ 'start:', + \ 'no multibyte chAracter', + \ ' one leaDing tab', + \ ' four leadinG spaces', + \ 'two consecutive tabs', + \ 'two tabs in one line', + \ 'one multibyteCharacter', + \ 'a two multiByte characters', + \ 'A three mulTibyte characters', + \ 'short line', + \ ]) + let tmpfile = 'Xtemp' + exec 'w! ' . tmpfile + /^start: + set wrap + vsplit + norm! j16| + split + norm! j16| + split + norm! j16| + split + norm! j8| + split + norm! j8| + split + norm! j16| + split + norm! j16| + split + norm! j16| + split + norm! j$ + wincmd l + + set nowrap + /^start: + norm! j16|3zl + split + norm! j016|3zl + split + norm! j016|3zl + split + norm! j08|3zl + split + norm! j08|3zl + split + norm! j016|3zl + split + norm! j016|3zl + split + norm! j016|3zl + split + call wincol() + mksession! Xtest_mks.out + let li = filter(readfile('Xtest_mks.out'), 'v:val =~# "\\(^ *normal! [0$]\\|^ *exe ''normal!\\)"') + let expected = [ + \ 'normal! 016|', + \ 'normal! 016|', + \ 'normal! 016|', + \ 'normal! 08|', + \ 'normal! 08|', + \ 'normal! 016|', + \ 'normal! 016|', + \ 'normal! 016|', + \ 'normal! $', + \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", + \ " normal! 016|", + \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", + \ " normal! 016|", + \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", + \ " normal! 016|", + \ " exe 'normal! ' . s:c . '|zs' . 8 . '|'", + \ " normal! 08|", + \ " exe 'normal! ' . s:c . '|zs' . 8 . '|'", + \ " normal! 08|", + \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", + \ " normal! 016|", + \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", + \ " normal! 016|", + \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", + \ " normal! 016|", + \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", + \ " normal! 016|" + \ ] + call assert_equal(expected, li) + tabclose! + + call delete('Xtest_mks.out') + call delete(tmpfile) + let &wrap = wrap_save + set sessionoptions& +endfunc + +func Test_mksession_winheight() + new + set winheight=10 + set winminheight=2 + mksession! Xtest_mks.out + source Xtest_mks.out + + call delete('Xtest_mks.out') +endfunc + +func Test_mksession_large_winheight() + set winheight=999 + mksession! Xtest_mks_winheight.out + set winheight& + source Xtest_mks_winheight.out + call delete('Xtest_mks_winheight.out') +endfunc + +func Test_mksession_rtp() + if has('win32') + " TODO: fix problem with backslashes + return + endif + new + let _rtp=&rtp + " Make a real long (invalid) runtimepath value, + " that should exceed PATH_MAX (hopefully) + let newrtp=&rtp.',~'.repeat('/foobar', 1000) + let newrtp.=",".expand("$HOME")."/.vim" + let &rtp=newrtp + + " determine expected value + let expected=split(&rtp, ',') + let expected = map(expected, '"set runtimepath+=".v:val') + let expected = ['set runtimepath='] + expected + let expected = map(expected, {v,w -> substitute(w, $HOME, "~", "g")}) + + mksession! Xtest_mks.out + let &rtp=_rtp + let li = filter(readfile('Xtest_mks.out'), 'v:val =~# "runtimepath"') + call assert_equal(expected, li) + + call delete('Xtest_mks.out') +endfunc + +func Test_mksession_arglist() + argdel * + next file1 file2 file3 file4 + mksession! Xtest_mks.out + source Xtest_mks.out + call assert_equal(['file1', 'file2', 'file3', 'file4'], argv()) + + call delete('Xtest_mks.out') + argdel * +endfunc + +func Test_mksession_one_buffer_two_windows() + edit Xtest1 + new Xtest2 + split + mksession! Xtest_mks.out + let lines = readfile('Xtest_mks.out') + let count1 = 0 + let count2 = 0 + let count2buf = 0 + for line in lines + if line =~ 'edit \f*Xtest1$' + let count1 += 1 + endif + if line =~ 'edit \f\{-}Xtest2' + let count2 += 1 + endif + if line =~ 'buffer \f\{-}Xtest2' + let count2buf += 1 + endif + endfor + call assert_equal(1, count1, 'Xtest1 count') + call assert_equal(2, count2, 'Xtest2 count') + call assert_equal(2, count2buf, 'Xtest2 buffer count') + + close + bwipe! + call delete('Xtest_mks.out') +endfunc + +func Test_mksession_lcd_multiple_tabs() + tabnew + tabnew + lcd . + tabfirst + lcd . + mksession! Xtest_mks.out + tabonly + source Xtest_mks.out + call assert_true(haslocaldir(), 'Tab 1 localdir') + tabnext 2 + call assert_true(!haslocaldir(), 'Tab 2 localdir') + tabnext 3 + call assert_true(haslocaldir(), 'Tab 3 localdir') + call delete('Xtest_mks.out') +endfunc + +func Test_mksession_blank_tabs() + tabnew + tabnew + tabnew + tabnext 3 + mksession! Xtest_mks.out + tabnew + tabnew + tabnext 2 + source Xtest_mks.out + call assert_equal(4, tabpagenr('$'), 'session restore should restore number of tabs') + call assert_equal(3, tabpagenr(), 'session restore should restore the active tab') + call delete('Xtest_mks.out') +endfunc + +func Test_mksession_buffer_count() + set hidden + + " Edit exactly three files in the current session. + %bwipe! + e Xfoo | tabe Xbar | tabe Xbaz + tabdo write + mksession! Xtest_mks.out + + " Verify that loading the session does not create additional buffers. + %bwipe! + source Xtest_mks.out + call assert_equal(3, len(getbufinfo())) + + " Clean up. + call delete('Xfoo') + call delete('Xbar') + call delete('Xbaz') + call delete('Xtest_mks.out') + %bwipe! + set hidden& +endfunc + +if has('extra_search') + +func Test_mksession_hlsearch() + set hlsearch + mksession! Xtest_mks.out + nohlsearch + source Xtest_mks.out + call assert_equal(1, v:hlsearch, 'session should restore search highlighting state') + nohlsearch + mksession! Xtest_mks.out + source Xtest_mks.out + call assert_equal(0, v:hlsearch, 'session should restore search highlighting state') + call delete('Xtest_mks.out') +endfunc + +endif + + +func Test_mksession_blank_windows() + split + split + split + 3 wincmd w + mksession! Xtest_mks.out + split + split + 2 wincmd w + source Xtest_mks.out + call assert_equal(4, winnr('$'), 'session restore should restore number of windows') + call assert_equal(3, winnr(), 'session restore should restore the active window') + call delete('Xtest_mks.out') +endfunc + +if has('terminal') + +func Test_mksession_terminal_shell() + terminal + mksession! Xtest_mks.out + let lines = readfile('Xtest_mks.out') + let term_cmd = '' + for line in lines + if line =~ '^terminal' + let term_cmd = line + elseif line =~ 'badd.*' . &shell + call assert_report('unexpected shell line: ' . line) + endif + endfor + call assert_match('terminal ++curwin ++cols=\d\+ ++rows=\d\+\s*.*$', term_cmd) + + call Stop_shell_in_terminal(bufnr('%')) + call delete('Xtest_mks.out') +endfunc + +func Test_mksession_terminal_no_restore_cmdarg() + terminal ++norestore + mksession! Xtest_mks.out + let lines = readfile('Xtest_mks.out') + let term_cmd = '' + for line in lines + if line =~ '^terminal' + call assert_report('session must not restore teminal') + endif + endfor + + call Stop_shell_in_terminal(bufnr('%')) + call delete('Xtest_mks.out') +endfunc + +func Test_mksession_terminal_no_restore_funcarg() + call term_start(&shell, {'norestore': 1}) + mksession! Xtest_mks.out + let lines = readfile('Xtest_mks.out') + let term_cmd = '' + for line in lines + if line =~ '^terminal' + call assert_report('session must not restore teminal') + endif + endfor + + call Stop_shell_in_terminal(bufnr('%')) + call delete('Xtest_mks.out') +endfunc + +func Test_mksession_terminal_no_restore_func() + terminal + call term_setrestore(bufnr('%'), 'NONE') + mksession! Xtest_mks.out + let lines = readfile('Xtest_mks.out') + let term_cmd = '' + for line in lines + if line =~ '^terminal' + call assert_report('session must not restore teminal') + endif + endfor + + call Stop_shell_in_terminal(bufnr('%')) + call delete('Xtest_mks.out') +endfunc + +func Test_mksession_terminal_no_ssop() + terminal + set sessionoptions-=terminal + mksession! Xtest_mks.out + let lines = readfile('Xtest_mks.out') + let term_cmd = '' + for line in lines + if line =~ '^terminal' + call assert_report('session must not restore teminal') + endif + endfor + + call Stop_shell_in_terminal(bufnr('%')) + call delete('Xtest_mks.out') + set sessionoptions& +endfunc + +func Test_mksession_terminal_restore_other() + terminal + call term_setrestore(bufnr('%'), 'other') + mksession! Xtest_mks.out + let lines = readfile('Xtest_mks.out') + let term_cmd = '' + for line in lines + if line =~ '^terminal' + let term_cmd = line + endif + endfor + call assert_match('terminal ++curwin ++cols=\d\+ ++rows=\d\+.*other', term_cmd) + + call Stop_shell_in_terminal(bufnr('%')) + call delete('Xtest_mks.out') +endfunc + +endif " has('terminal') + +" Test :mkview with a file argument. +func Test_mkview_file() + " Create a view with line number and a fold. + help :mkview + set number + norm! V}zf0 + let pos = getpos('.') + let linefoldclosed1 = foldclosed('.') + mkview! Xview + set nonumber + norm! zrj + " We can close the help window, as mkview with a file name should + " generate a command to edit the file. + helpclose + + source Xview + call assert_equal(1, &number) + call assert_match('\*:mkview\*$', getline('.')) + call assert_equal(pos, getpos('.')) + call assert_equal(linefoldclosed1, foldclosed('.')) + + " Creating a view again with the same file name should fail (file + " already exists). But with a !, the previous view should be + " overwritten without error. + help :loadview + call assert_fails('mkview Xview', 'E189:') + call assert_match('\*:loadview\*$', getline('.')) + mkview! Xview + call assert_match('\*:loadview\*$', getline('.')) + + call delete('Xview') + bwipe +endfunc + +" Test :mkview and :loadview with a custom 'viewdir'. +func Test_mkview_loadview_with_viewdir() + set viewdir=Xviewdir + + help :mkview + set number + norm! V}zf + let pos = getpos('.') + let linefoldclosed1 = foldclosed('.') + mkview 1 + set nonumber + norm! zrj + + loadview 1 + + " The directory Xviewdir/ should have been created and the view + " should be stored in that directory. + call assert_equal('Xviewdir/' . + \ substitute( + \ substitute( + \ expand('%:p'), '/', '=+', 'g'), ':', '=-', 'g') . '=1.vim', + \ glob('Xviewdir/*')) + call assert_equal(1, &number) + call assert_match('\*:mkview\*$', getline('.')) + call assert_equal(pos, getpos('.')) + call assert_equal(linefoldclosed1, foldclosed('.')) + + call delete('Xviewdir', 'rf') + set viewdir& + helpclose +endfunc + +func Test_mkview_no_file_name() + new + " :mkview or :mkview {nr} should fail in a unnamed buffer. + call assert_fails('mkview', 'E32:') + call assert_fails('mkview 1', 'E32:') + + " :mkview {file} should succeed in a unnamed buffer. + mkview Xview + help + source Xview + call assert_equal('', bufname('%')) + + call delete('Xview') + %bwipe +endfunc + +" A clean session (one empty buffer, one window, and one tab) should not +" set any error messages when sourced because no commands should fail. +func Test_mksession_no_errmsg() + let v:errmsg = '' + %bwipe! + mksession! Xtest_mks.out + source Xtest_mks.out + call assert_equal('', v:errmsg) + call delete('Xtest_mks.out') +endfunc + +func Test_mksession_quote_in_filename() + if !has('unix') + " only Unix can handle this weird filename + return + endif + let v:errmsg = '' + %bwipe! + split another + split x'y\"z + mksession! Xtest_mks_quoted.out + %bwipe! + source Xtest_mks_quoted.out + call assert_true(bufexists("x'y\"z")) + + %bwipe! + call delete('Xtest_mks_quoted.out') +endfunc + + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_mksession_utf8.vim b/src/testdir/test_mksession_utf8.vim new file mode 100644 index 0000000..67af3a9 --- /dev/null +++ b/src/testdir/test_mksession_utf8.vim @@ -0,0 +1,105 @@ +" Test for :mksession, :mkview and :loadview in utf-8 encoding + +set encoding=utf-8 +scriptencoding utf-8 + +if !has('mksession') + finish +endif + +func Test_mksession_utf8() + tabnew + let wrap_save = &wrap + set sessionoptions=buffers splitbelow fileencoding=utf-8 + call setline(1, [ + \ 'start:', + \ 'no multibyte chAracter', + \ ' one leaDing tab', + \ ' four leadinG spaces', + \ 'two consecutive tabs', + \ 'two tabs in one line', + \ 'one … multibyteCharacter', + \ 'a “b” two multiByte characters', + \ '“c”1€ three mulTibyte characters' + \ ]) + let tmpfile = tempname() + exec 'w! ' . tmpfile + /^start: + set wrap + vsplit + norm! j16| + split + norm! j16| + split + norm! j16| + split + norm! j8| + split + norm! j8| + split + norm! j16| + split + norm! j16| + split + norm! j16| + wincmd l + + set nowrap + /^start: + norm! j16|3zl + split + norm! j016|3zl + split + norm! j016|3zl + split + norm! j08|3zl + split + norm! j08|3zl + split + norm! j016|3zl + split + norm! j016|3zl + split + norm! j016|3zl + split + call wincol() + mksession! test_mks.out + let li = filter(readfile('test_mks.out'), 'v:val =~# "\\(^ *normal! 0\\|^ *exe ''normal!\\)"') + let expected = [ + \ 'normal! 016|', + \ 'normal! 016|', + \ 'normal! 016|', + \ 'normal! 08|', + \ 'normal! 08|', + \ 'normal! 016|', + \ 'normal! 016|', + \ 'normal! 016|', + \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", + \ " normal! 016|", + \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", + \ " normal! 016|", + \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", + \ " normal! 016|", + \ " exe 'normal! ' . s:c . '|zs' . 8 . '|'", + \ " normal! 08|", + \ " exe 'normal! ' . s:c . '|zs' . 8 . '|'", + \ " normal! 08|", + \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", + \ " normal! 016|", + \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", + \ " normal! 016|", + \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", + \ " normal! 016|", + \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", + \ " normal! 016|" + \ ] + call assert_equal(expected, li) + tabclose! + + call delete('test_mks.out') + call delete(tmpfile) + let &wrap = wrap_save + set sessionoptions& splitbelow& fileencoding& +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_modeline.vim b/src/testdir/test_modeline.vim new file mode 100644 index 0000000..e0f97c4 --- /dev/null +++ b/src/testdir/test_modeline.vim @@ -0,0 +1,94 @@ +" Tests for parsing the modeline. + +func Test_modeline_invalid() + " This was reading allocated memory in the past. + call writefile(['vi:0', 'nothing'], 'Xmodeline') + let modeline = &modeline + set modeline + call assert_fails('split Xmodeline', 'E518:') + + let &modeline = modeline + bwipe! + call delete('Xmodeline') +endfunc + +func Test_modeline_filetype() + call writefile(['vim: set ft=c :', 'nothing'], 'Xmodeline_filetype') + let modeline = &modeline + set modeline + filetype plugin on + split Xmodeline_filetype + call assert_equal("c", &filetype) + call assert_equal(1, b:did_ftplugin) + call assert_equal("ccomplete#Complete", &ofu) + + bwipe! + call delete('Xmodeline_filetype') + let &modeline = modeline + filetype plugin off +endfunc + +func Test_modeline_syntax() + call writefile(['vim: set syn=c :', 'nothing'], 'Xmodeline_syntax') + let modeline = &modeline + set modeline + syntax enable + split Xmodeline_syntax + call assert_equal("c", &syntax) + call assert_equal("c", b:current_syntax) + + bwipe! + call delete('Xmodeline_syntax') + let &modeline = modeline + syntax off +endfunc + +func Test_modeline_keymap() + if !has('keymap') + return + endif + call writefile(['vim: set keymap=greek :', 'nothing'], 'Xmodeline_keymap') + let modeline = &modeline + set modeline + split Xmodeline_keymap + call assert_equal("greek", &keymap) + call assert_match('greek\|grk', b:keymap_name) + + bwipe! + call delete('Xmodeline_keymap') + let &modeline = modeline + set keymap= iminsert=0 imsearch=-1 +endfunc + +func s:modeline_fails(what, text) + let fname = "Xmodeline_fails_" . a:what + call writefile(['vim: set ' . a:text . ' :', 'nothing'], fname) + let modeline = &modeline + set modeline + filetype plugin on + syntax enable + call assert_fails('split ' . fname, 'E474:') + call assert_equal("", &filetype) + call assert_equal("", &syntax) + + bwipe! + call delete(fname) + let &modeline = modeline + filetype plugin off + syntax off +endfunc + +func Test_modeline_filetype_fails() + call s:modeline_fails('filetype', 'ft=evil$CMD') +endfunc + +func Test_modeline_syntax_fails() + call s:modeline_fails('syntax', 'syn=evil$CMD') +endfunc + +func Test_modeline_keymap_fails() + if !has('keymap') + return + endif + call s:modeline_fails('keymap', 'keymap=evil$CMD') +endfunc diff --git a/src/testdir/test_move.vim b/src/testdir/test_move.vim new file mode 100644 index 0000000..d774c93 --- /dev/null +++ b/src/testdir/test_move.vim @@ -0,0 +1,40 @@ +" Test the ":move" command. + +func Test_move() + enew! + call append(0, ['line 1', 'line 2', 'line 3']) + g /^$/ delete _ + set nomodified + + move . + call assert_equal(['line 1', 'line 2', 'line 3'], getline(1, 3)) + call assert_false(&modified) + + 1,2move 0 + call assert_equal(['line 1', 'line 2', 'line 3'], getline(1, 3)) + call assert_false(&modified) + + 1,3move 3 + call assert_equal(['line 1', 'line 2', 'line 3'], getline(1, 3)) + call assert_false(&modified) + + 1move 2 + call assert_equal(['line 2', 'line 1', 'line 3'], getline(1, 3)) + call assert_true(&modified) + set nomodified + + 3move 0 + call assert_equal(['line 3', 'line 2', 'line 1'], getline(1, 3)) + call assert_true(&modified) + set nomodified + + 2,3move 0 + call assert_equal(['line 2', 'line 1', 'line 3'], getline(1, 3)) + call assert_true(&modified) + set nomodified + + call assert_fails('1,2move 1', 'E134') + call assert_fails('2,3move 2', 'E134') + + %bwipeout! +endfunc diff --git a/src/testdir/test_nested_function.vim b/src/testdir/test_nested_function.vim new file mode 100644 index 0000000..ec48f03 --- /dev/null +++ b/src/testdir/test_nested_function.vim @@ -0,0 +1,67 @@ +"Tests for nested functions +" +func NestedFunc() + func! Func1() + let g:text .= 'Func1 ' + endfunc + call Func1() + func! s:func2() + let g:text .= 's:func2 ' + endfunc + call s:func2() + func! s:_func3() + let g:text .= 's:_func3 ' + endfunc + call s:_func3() + let fn = 'Func4' + func! {fn}() + let g:text .= 'Func4 ' + endfunc + call {fn}() + let fn = 'func5' + func! s:{fn}() + let g:text .= 's:func5' + endfunc + call s:{fn}() +endfunc + +func Test_nested_functions() + let g:text = '' + call NestedFunc() + call assert_equal('Func1 s:func2 s:_func3 Func4 s:func5', g:text) +endfunction + +func Test_nested_argument() + func g:X() + let g:Y = function('sort') + endfunc + let g:Y = function('sort') + echo g:Y([], g:X()) + delfunc g:X + unlet g:Y +endfunc + +func Recurse(count) + if a:count > 0 + call Recurse(a:count - 1) + endif +endfunc + +func Test_max_nesting() + " TODO: why does this fail on Windows? Runs out of stack perhaps? + if has('win32') + return + endif + let call_depth_here = 2 + let ex_depth_here = 5 + set mfd& + + call Recurse(99 - call_depth_here) + call assert_fails('call Recurse(' . (100 - call_depth_here) . ')', 'E132:') + + set mfd=210 + call Recurse(209 - ex_depth_here) + call assert_fails('call Recurse(' . (210 - ex_depth_here) . ')', 'E169:') + + set mfd& +endfunc diff --git a/src/testdir/test_netbeans.py b/src/testdir/test_netbeans.py new file mode 100644 index 0000000..bdebb54 --- /dev/null +++ b/src/testdir/test_netbeans.py @@ -0,0 +1,91 @@ +#!/usr/bin/python +# +# Server that will communicate with Vim through the netbeans interface. +# Used by test_netbeans.vim. +# +# This requires Python 2.6 or later. + +from __future__ import print_function +import socket +import sys +import time +import threading + +try: + # Python 3 + import socketserver +except ImportError: + # Python 2 + import SocketServer as socketserver + +class ThreadedTCPRequestHandler(socketserver.BaseRequestHandler): + + def handle(self): + print("=== socket opened ===") + while True: + try: + received = self.request.recv(4096).decode('utf-8') + except socket.error: + print("=== socket error ===") + break + except IOError: + print("=== socket closed ===") + break + if received == '': + print("=== socket closed ===") + break + print("received: {0}".format(received)) + + # Write the received line into the file, so that the test can check + # what happened. + with open("Xnetbeans", "a") as myfile: + myfile.write(received) + + response = '' + if received.find('XREADME.txt') > 0: + name = received.split('"')[1] + response = '5:putBufferNumber!33 "' + name + '"\n' + response += '5:setDot!1 3/19\n' + elif received.find('disconnect') > 0: + # we're done + self.server.shutdown() + return + + if len(response) > 0: + self.request.sendall(response.encode('utf-8')) + # Write the respoinse into the file, so that the test can knows + # the command was sent. + with open("Xnetbeans", "a") as myfile: + myfile.write('send: ' + response) + +class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer): + pass + +def writePortInFile(port): + # Write the port number in Xportnr, so that the test knows it. + f = open("Xportnr", "w") + f.write("{0}".format(port)) + f.close() + +if __name__ == "__main__": + HOST, PORT = "localhost", 0 + + server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler) + ip, port = server.server_address + + # Start a thread with the server. That thread will then start a new thread + # for each connection. + server_thread = threading.Thread(target=server.serve_forever) + server_thread.start() + + writePortInFile(port) + + print("Listening on port {0}".format(port)) + + # Main thread terminates, but the server continues running + # until server.shutdown() is called. + try: + while server_thread.isAlive(): + server_thread.join(1) + except (KeyboardInterrupt, SystemExit): + server.shutdown() diff --git a/src/testdir/test_netbeans.vim b/src/testdir/test_netbeans.vim new file mode 100644 index 0000000..66177ad --- /dev/null +++ b/src/testdir/test_netbeans.vim @@ -0,0 +1,86 @@ +" Test the netbeans interface. + +if !has('netbeans_intg') + finish +endif + +source shared.vim + +let s:python = PythonProg() +if s:python == '' + " Can't run this test. + finish +endif + +" Run "testfunc" after sarting the server and stop the server afterwards. +func s:run_server(testfunc, ...) + call RunServer('test_netbeans.py', a:testfunc, a:000) +endfunc + +func Nb_basic(port) + call delete("Xnetbeans") + call writefile([], "Xnetbeans") + call writefile(repeat(['abcdefghijklmnopqrstuvwxyz'], 5), "XREADME.txt") + exe 'nbstart :localhost:' . a:port . ':bunny' + call assert_true(has("netbeans_enabled")) + + call WaitFor('len(readfile("Xnetbeans")) > 2') + split +$ XREADME.txt + + " Opening XREADME.txt will result in a setDot command + call WaitFor('len(readfile("Xnetbeans")) > 4') + call WaitFor('getcurpos()[1] == 3') + let pos = getcurpos() + call assert_equal(3, pos[1]) + call assert_equal(20, pos[2]) + close + nbclose + + call WaitFor('len(readfile("Xnetbeans")) > 6') + call assert_false(has("netbeans_enabled")) + let lines = readfile("Xnetbeans") + call assert_equal('AUTH bunny', lines[0]) + call assert_equal('0:version=0 "2.5"', lines[1]) + call assert_equal('0:startupDone=0', lines[2]) + call assert_equal('0:fileOpened=0 "XREADME.txt" T F', substitute(lines[3], '".*/', '"', '')) + + call assert_equal('0:disconnect=1', lines[6]) + + call delete("Xnetbeans") + call delete("XREADME.txt") +endfunc + +func Test_nb_basic() + call ch_log('Test_nb_basic') + call s:run_server('Nb_basic') +endfunc + +func Nb_file_auth(port) + call delete("Xnetbeans") + call writefile([], "Xnetbeans") + + call assert_fails('nbstart =notexist', 'E660:') + call writefile(['host=localhost', 'port=' . a:port, 'auth=bunny'], 'Xnbauth') + if has('unix') + call setfperm('Xnbauth', "rw-r--r--") + call assert_fails('nbstart =Xnbauth', 'E668:') + endif + call setfperm('Xnbauth', "rw-------") + exe 'nbstart =Xnbauth' + call assert_true(has("netbeans_enabled")) + + call WaitFor('len(readfile("Xnetbeans")) > 2') + nbclose + let lines = readfile("Xnetbeans") + call assert_equal('AUTH bunny', lines[0]) + call assert_equal('0:version=0 "2.5"', lines[1]) + call assert_equal('0:startupDone=0', lines[2]) + + call delete("Xnbauth") + call delete("Xnetbeans") +endfunc + +func Test_nb_file_auth() + call ch_log('Test_nb_file_auth') + call s:run_server('Nb_file_auth') +endfunc diff --git a/src/testdir/test_normal.vim b/src/testdir/test_normal.vim new file mode 100644 index 0000000..1224a3f --- /dev/null +++ b/src/testdir/test_normal.vim @@ -0,0 +1,2544 @@ +" Test for various Normal mode commands + +func Setup_NewWindow() + 10new + call setline(1, range(1,100)) +endfunc + +func MyFormatExpr() + " Adds '->$' at lines having numbers followed by trailing whitespace + for ln in range(v:lnum, v:lnum+v:count-1) + let line = getline(ln) + if getline(ln) =~# '\d\s\+$' + call setline(ln, substitute(line, '\s\+$', '', '') . '->$') + endif + endfor +endfunc + +func CountSpaces(type, ...) + " for testing operatorfunc + " will count the number of spaces + " and return the result in g:a + let sel_save = &selection + let &selection = "inclusive" + let reg_save = @@ + + if a:0 " Invoked from Visual mode, use gv command. + silent exe "normal! gvy" + elseif a:type == 'line' + silent exe "normal! '[V']y" + else + silent exe "normal! `[v`]y" + endif + let g:a=strlen(substitute(@@, '[^ ]', '', 'g')) + let &selection = sel_save + let @@ = reg_save +endfunc + +func OpfuncDummy(type, ...) + " for testing operatorfunc + let g:opt=&linebreak + + if a:0 " Invoked from Visual mode, use gv command. + silent exe "normal! gvy" + elseif a:type == 'line' + silent exe "normal! '[V']y" + else + silent exe "normal! `[v`]y" + endif + " Create a new dummy window + new + let g:bufnr=bufnr('%') +endfunc + +fun! Test_normal00_optrans() + new + call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line']) + 1 + exe "norm! Sfoobar\<esc>" + call assert_equal(['foobar', '2 This is the second line', '3 this is the third line', ''], getline(1,'$')) + 2 + exe "norm! $vbsone" + call assert_equal(['foobar', '2 This is the second one', '3 this is the third line', ''], getline(1,'$')) + norm! VS Second line here + call assert_equal(['foobar', ' Second line here', '3 this is the third line', ''], getline(1, '$')) + %d + call append(0, ['4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line']) + call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line']) + + 1 + norm! 2D + call assert_equal(['3 this is the third line', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$')) + set cpo+=# + norm! 4D + call assert_equal(['', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$')) + + " clean up + set cpo-=# + bw! +endfunc + +func Test_normal01_keymodel() + call Setup_NewWindow() + " Test 1: depending on 'keymodel' <s-down> does something different + 50 + call feedkeys("V\<S-Up>y", 'tx') + call assert_equal(['47', '48', '49', '50'], getline("'<", "'>")) + set keymodel=startsel + 50 + call feedkeys("V\<S-Up>y", 'tx') + call assert_equal(['49', '50'], getline("'<", "'>")) + " Start visual mode when keymodel = startsel + 50 + call feedkeys("\<S-Up>y", 'tx') + call assert_equal(['49', '5'], getreg(0, 0, 1)) + " Do not start visual mode when keymodel= + set keymodel= + 50 + call feedkeys("\<S-Up>y$", 'tx') + call assert_equal(['42'], getreg(0, 0, 1)) + " Stop visual mode when keymodel=stopsel + set keymodel=stopsel + 50 + call feedkeys("Vkk\<Up>yy", 'tx') + call assert_equal(['47'], getreg(0, 0, 1)) + + set keymodel= + 50 + call feedkeys("Vkk\<Up>yy", 'tx') + call assert_equal(['47', '48', '49', '50'], getreg(0, 0, 1)) + + " clean up + bw! +endfunc + +func Test_normal02_selectmode() + " some basic select mode tests + call Setup_NewWindow() + 50 + norm! gHy + call assert_equal('y51', getline('.')) + call setline(1, range(1,100)) + 50 + exe ":norm! V9jo\<c-g>y" + call assert_equal('y60', getline('.')) + " clean up + bw! +endfunc + +func Test_normal02_selectmode2() + " some basic select mode tests + call Setup_NewWindow() + 50 + call feedkeys(":set im\n\<c-o>gHc\<c-o>:set noim\n", 'tx') + call assert_equal('c51', getline('.')) + " clean up + bw! +endfunc + +func Test_normal03_join() + " basic join test + call Setup_NewWindow() + 50 + norm! VJ + call assert_equal('50 51', getline('.')) + $ + norm! J + call assert_equal('100', getline('.')) + $ + norm! V9-gJ + call assert_equal('919293949596979899100', getline('.')) + call setline(1, range(1,100)) + $ + :j 10 + call assert_equal('100', getline('.')) + " clean up + bw! +endfunc + +func Test_normal04_filter() + " basic filter test + " only test on non windows platform + if has('win32') + return + endif + call Setup_NewWindow() + 1 + call feedkeys("!!sed -e 's/^/| /'\n", 'tx') + call assert_equal('| 1', getline('.')) + 90 + :sil :!echo one + call feedkeys('.', 'tx') + call assert_equal('| 90', getline('.')) + 95 + set cpo+=! + " 2 <CR>, 1: for executing the command, + " 2: clear hit-enter-prompt + call feedkeys("!!\n", 'tx') + call feedkeys(":!echo one\n\n", 'tx') + call feedkeys(".", 'tx') + call assert_equal('one', getline('.')) + set cpo-=! + bw! +endfunc + +func Test_normal05_formatexpr() + " basic formatexpr test + call Setup_NewWindow() + %d_ + call setline(1, ['here: 1 ', '2', 'here: 3 ', '4', 'not here: ']) + 1 + set formatexpr=MyFormatExpr() + norm! gqG + call assert_equal(['here: 1->$', '2', 'here: 3->$', '4', 'not here: '], getline(1,'$')) + set formatexpr= + bw! +endfunc + +func Test_normal05_formatexpr_newbuf() + " Edit another buffer in the 'formatexpr' function + new + func! Format() + edit another + endfunc + set formatexpr=Format() + norm gqG + bw! + set formatexpr= +endfunc + +func Test_normal05_formatexpr_setopt() + " Change the 'formatexpr' value in the function + new + func! Format() + set formatexpr= + endfunc + set formatexpr=Format() + norm gqG + bw! + set formatexpr= +endfunc + +func Test_normal06_formatprg() + " basic test for formatprg + " only test on non windows platform + if has('win32') + return + endif + + " uses sed to number non-empty lines + call writefile(['#!/bin/sh', 'sed ''/./=''|sed ''/./{', 'N', 's/\n/ /', '}'''], 'Xsed_format.sh') + call system('chmod +x ./Xsed_format.sh') + let text = ['a', '', 'c', '', ' ', 'd', 'e'] + let expected = ['1 a', '', '3 c', '', '5 ', '6 d', '7 e'] + + 10new + call setline(1, text) + set formatprg=./Xsed_format.sh + norm! gggqG + call assert_equal(expected, getline(1, '$')) + bw! + + 10new + call setline(1, text) + set formatprg=donothing + setlocal formatprg=./Xsed_format.sh + norm! gggqG + call assert_equal(expected, getline(1, '$')) + bw! + + " clean up + set formatprg= + setlocal formatprg= + call delete('Xsed_format.sh') +endfunc + +func Test_normal07_internalfmt() + " basic test for internal formmatter to textwidth of 12 + let list=range(1,11) + call map(list, 'v:val." "') + 10new + call setline(1, list) + set tw=12 + norm! gggqG + call assert_equal(['1 2 3', '4 5 6', '7 8 9', '10 11 '], getline(1, '$')) + " clean up + set tw=0 + bw! +endfunc + +func Test_normal08_fold() + " basic tests for foldopen/folddelete + if !has("folding") + return + endif + call Setup_NewWindow() + 50 + setl foldenable fdm=marker + " First fold + norm! V4jzf + " check that folds have been created + call assert_equal(['50/*{{{*/', '51', '52', '53', '54/*}}}*/'], getline(50,54)) + " Second fold + 46 + norm! V10jzf + " check that folds have been created + call assert_equal('46/*{{{*/', getline(46)) + call assert_equal('60/*}}}*/', getline(60)) + norm! k + call assert_equal('45', getline('.')) + norm! j + call assert_equal('46/*{{{*/', getline('.')) + norm! j + call assert_equal('61', getline('.')) + norm! k + " open a fold + norm! Vzo + norm! k + call assert_equal('45', getline('.')) + norm! j + call assert_equal('46/*{{{*/', getline('.')) + norm! j + call assert_equal('47', getline('.')) + norm! k + norm! zcVzO + call assert_equal('46/*{{{*/', getline('.')) + norm! j + call assert_equal('47', getline('.')) + norm! j + call assert_equal('48', getline('.')) + norm! j + call assert_equal('49', getline('.')) + norm! j + call assert_equal('50/*{{{*/', getline('.')) + norm! j + call assert_equal('51', getline('.')) + " delete folds + :46 + " collapse fold + norm! V14jzC + " delete all folds recursively + norm! VzD + call assert_equal(['46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60'], getline(46,60)) + + " clean up + setl nofoldenable fdm=marker + bw! +endfunc + +func Test_normal09_operatorfunc() + " Test operatorfunc + call Setup_NewWindow() + " Add some spaces for counting + 50,60s/$/ / + unlet! g:a + let g:a=0 + nmap <buffer><silent> ,, :set opfunc=CountSpaces<CR>g@ + vmap <buffer><silent> ,, :<C-U>call CountSpaces(visualmode(), 1)<CR> + 50 + norm V2j,, + call assert_equal(6, g:a) + norm V,, + call assert_equal(2, g:a) + norm ,,l + call assert_equal(0, g:a) + 50 + exe "norm 0\<c-v>10j2l,," + call assert_equal(11, g:a) + 50 + norm V10j,, + call assert_equal(22, g:a) + + " clean up + unmap <buffer> ,, + set opfunc= + unlet! g:a + bw! +endfunc + +func Test_normal09a_operatorfunc() + " Test operatorfunc + call Setup_NewWindow() + " Add some spaces for counting + 50,60s/$/ / + unlet! g:opt + set linebreak + nmap <buffer><silent> ,, :set opfunc=OpfuncDummy<CR>g@ + 50 + norm ,,j + exe "bd!" g:bufnr + call assert_true(&linebreak) + call assert_equal(g:opt, &linebreak) + set nolinebreak + norm ,,j + exe "bd!" g:bufnr + call assert_false(&linebreak) + call assert_equal(g:opt, &linebreak) + + " clean up + unmap <buffer> ,, + set opfunc= + bw! + unlet! g:opt +endfunc + +func Test_normal10_expand() + " Test for expand() + 10new + call setline(1, ['1', 'ifooar,,cbar']) + 2 + norm! $ + call assert_equal('cbar', expand('<cword>')) + call assert_equal('ifooar,,cbar', expand('<cWORD>')) + + call setline(1, ['prx = list[idx];']) + 1 + let expected = ['', 'prx', 'prx', 'prx', + \ 'list', 'list', 'list', 'list', 'list', 'list', 'list', + \ 'idx', 'idx', 'idx', 'idx', + \ 'list[idx]', + \ '];', + \ ] + for i in range(1, 16) + exe 'norm ' . i . '|' + call assert_equal(expected[i], expand('<cexpr>'), 'i == ' . i) + endfor + + if executable('echo') + " Test expand(`...`) i.e. backticks command expansion. + " MS-Windows has a trailing space. + call assert_match('^abcde *$', expand('`echo abcde`')) + endif + + " Test expand(`=...`) i.e. backticks expression expansion + call assert_equal('5', expand('`=2+3`')) + + " clean up + bw! +endfunc + +func Test_normal11_showcmd() + " test for 'showcmd' + 10new + exe "norm! ofoobar\<esc>" + call assert_equal(2, line('$')) + set showcmd + exe "norm! ofoobar2\<esc>" + call assert_equal(3, line('$')) + exe "norm! VAfoobar3\<esc>" + call assert_equal(3, line('$')) + exe "norm! 0d3\<del>2l" + call assert_equal('obar2foobar3', getline('.')) + bw! +endfunc + +func Test_normal12_nv_error() + " Test for nv_error + 10new + call setline(1, range(1,5)) + " should not do anything, just beep + exe "norm! <c-k>" + call assert_equal(map(range(1,5), 'string(v:val)'), getline(1,'$')) + bw! +endfunc + +func Test_normal13_help() + " Test for F1 + call assert_equal(1, winnr()) + call feedkeys("\<f1>", 'txi') + call assert_match('help\.txt', bufname('%')) + call assert_equal(2, winnr('$')) + bw! +endfunc + +func Test_normal14_page() + " basic test for Ctrl-F and Ctrl-B + call Setup_NewWindow() + exe "norm! \<c-f>" + call assert_equal('9', getline('.')) + exe "norm! 2\<c-f>" + call assert_equal('25', getline('.')) + exe "norm! 2\<c-b>" + call assert_equal('18', getline('.')) + 1 + set scrolloff=5 + exe "norm! 2\<c-f>" + call assert_equal('21', getline('.')) + exe "norm! \<c-b>" + call assert_equal('13', getline('.')) + 1 + set scrolloff=99 + exe "norm! \<c-f>" + call assert_equal('13', getline('.')) + set scrolloff=0 + 100 + exe "norm! $\<c-b>" + call assert_equal('92', getline('.')) + call assert_equal([0, 92, 1, 0, 1], getcurpos()) + 100 + set nostartofline + exe "norm! $\<c-b>" + call assert_equal('92', getline('.')) + call assert_equal([0, 92, 2, 0, 2147483647], getcurpos()) + " cleanup + set startofline + bw! +endfunc + +func Test_normal14_page_eol() + 10new + norm oxxxxxxx + exe "norm 2\<c-f>" + " check with valgrind that cursor is put back in column 1 + exe "norm 2\<c-b>" + bw! +endfunc + +func Test_normal15_z_scroll_vert() + " basic test for z commands that scroll the window + call Setup_NewWindow() + 100 + norm! >> + " Test for z<cr> + exe "norm! z\<cr>" + call assert_equal(' 100', getline('.')) + call assert_equal(100, winsaveview()['topline']) + call assert_equal([0, 100, 2, 0, 9], getcurpos()) + + " Test for zt + 21 + norm! >>0zt + call assert_equal(' 21', getline('.')) + call assert_equal(21, winsaveview()['topline']) + call assert_equal([0, 21, 1, 0, 8], getcurpos()) + + " Test for zb + 30 + norm! >>$ztzb + call assert_equal(' 30', getline('.')) + call assert_equal(30, winsaveview()['topline']+winheight(0)-1) + call assert_equal([0, 30, 3, 0, 2147483647], getcurpos()) + + " Test for z- + 1 + 30 + norm! 0z- + call assert_equal(' 30', getline('.')) + call assert_equal(30, winsaveview()['topline']+winheight(0)-1) + call assert_equal([0, 30, 2, 0, 9], getcurpos()) + + " Test for z{height}<cr> + call assert_equal(10, winheight(0)) + exe "norm! z12\<cr>" + call assert_equal(12, winheight(0)) + exe "norm! z10\<cr>" + call assert_equal(10, winheight(0)) + + " Test for z. + 1 + 21 + norm! 0z. + call assert_equal(' 21', getline('.')) + call assert_equal(17, winsaveview()['topline']) + call assert_equal([0, 21, 2, 0, 9], getcurpos()) + + " Test for zz + 1 + 21 + norm! 0zz + call assert_equal(' 21', getline('.')) + call assert_equal(17, winsaveview()['topline']) + call assert_equal([0, 21, 1, 0, 8], getcurpos()) + + " Test for z+ + 11 + norm! zt + norm! z+ + call assert_equal(' 21', getline('.')) + call assert_equal(21, winsaveview()['topline']) + call assert_equal([0, 21, 2, 0, 9], getcurpos()) + + " Test for [count]z+ + 1 + norm! 21z+ + call assert_equal(' 21', getline('.')) + call assert_equal(21, winsaveview()['topline']) + call assert_equal([0, 21, 2, 0, 9], getcurpos()) + + " Test for z^ + norm! 22z+0 + norm! z^ + call assert_equal(' 21', getline('.')) + call assert_equal(12, winsaveview()['topline']) + call assert_equal([0, 21, 2, 0, 9], getcurpos()) + + " Test for [count]z^ + 1 + norm! 30z^ + call assert_equal(' 21', getline('.')) + call assert_equal(12, winsaveview()['topline']) + call assert_equal([0, 21, 2, 0, 9], getcurpos()) + + " cleanup + bw! +endfunc + +func Test_normal16_z_scroll_hor() + " basic test for z commands that scroll the window + 10new + 15vsp + set nowrap listchars= + let lineA='abcdefghijklmnopqrstuvwxyz' + let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' + $put =lineA + $put =lineB + 1d + + " Test for zl + 1 + norm! 5zl + call assert_equal(lineA, getline('.')) + call assert_equal(6, col('.')) + call assert_equal(5, winsaveview()['leftcol']) + norm! yl + call assert_equal('f', @0) + + " Test for zh + norm! 2zh + call assert_equal(lineA, getline('.')) + call assert_equal(6, col('.')) + norm! yl + call assert_equal('f', @0) + call assert_equal(3, winsaveview()['leftcol']) + + " Test for zL + norm! zL + call assert_equal(11, col('.')) + norm! yl + call assert_equal('k', @0) + call assert_equal(10, winsaveview()['leftcol']) + norm! 2zL + call assert_equal(25, col('.')) + norm! yl + call assert_equal('y', @0) + call assert_equal(24, winsaveview()['leftcol']) + + " Test for zH + norm! 2zH + call assert_equal(25, col('.')) + call assert_equal(10, winsaveview()['leftcol']) + norm! yl + call assert_equal('y', @0) + + " Test for zs + norm! $zs + call assert_equal(26, col('.')) + call assert_equal(25, winsaveview()['leftcol']) + norm! yl + call assert_equal('z', @0) + + " Test for ze + norm! ze + call assert_equal(26, col('.')) + call assert_equal(11, winsaveview()['leftcol']) + norm! yl + call assert_equal('z', @0) + + " cleanup + set wrap listchars=eol:$ + bw! +endfunc + +func Test_normal17_z_scroll_hor2() + " basic test for z commands that scroll the window + " using 'sidescrolloff' setting + 10new + 20vsp + set nowrap listchars= sidescrolloff=5 + let lineA='abcdefghijklmnopqrstuvwxyz' + let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' + $put =lineA + $put =lineB + 1d + + " Test for zl + 1 + norm! 5zl + call assert_equal(lineA, getline('.')) + call assert_equal(11, col('.')) + call assert_equal(5, winsaveview()['leftcol']) + norm! yl + call assert_equal('k', @0) + + " Test for zh + norm! 2zh + call assert_equal(lineA, getline('.')) + call assert_equal(11, col('.')) + norm! yl + call assert_equal('k', @0) + call assert_equal(3, winsaveview()['leftcol']) + + " Test for zL + norm! 0zL + call assert_equal(16, col('.')) + norm! yl + call assert_equal('p', @0) + call assert_equal(10, winsaveview()['leftcol']) + norm! 2zL + call assert_equal(26, col('.')) + norm! yl + call assert_equal('z', @0) + call assert_equal(15, winsaveview()['leftcol']) + + " Test for zH + norm! 2zH + call assert_equal(15, col('.')) + call assert_equal(0, winsaveview()['leftcol']) + norm! yl + call assert_equal('o', @0) + + " Test for zs + norm! $zs + call assert_equal(26, col('.')) + call assert_equal(20, winsaveview()['leftcol']) + norm! yl + call assert_equal('z', @0) + + " Test for ze + norm! ze + call assert_equal(26, col('.')) + call assert_equal(11, winsaveview()['leftcol']) + norm! yl + call assert_equal('z', @0) + + " cleanup + set wrap listchars=eol:$ sidescrolloff=0 + bw! +endfunc + +func Test_normal18_z_fold() + " basic tests for foldopen/folddelete + if !has("folding") + return + endif + call Setup_NewWindow() + 50 + setl foldenable fdm=marker foldlevel=5 + + " Test for zF + " First fold + norm! 4zF + " check that folds have been created + call assert_equal(['50/*{{{*/', '51', '52', '53/*}}}*/'], getline(50,53)) + + " Test for zd + 51 + norm! 2zF + call assert_equal(2, foldlevel('.')) + norm! kzd + call assert_equal(['50', '51/*{{{*/', '52/*}}}*/', '53'], getline(50,53)) + norm! j + call assert_equal(1, foldlevel('.')) + + " Test for zD + " also deletes partially selected folds recursively + 51 + norm! zF + call assert_equal(2, foldlevel('.')) + norm! kV2jzD + call assert_equal(['50', '51', '52', '53'], getline(50,53)) + + " Test for zE + 85 + norm! 4zF + 86 + norm! 2zF + 90 + norm! 4zF + call assert_equal(['85/*{{{*/', '86/*{{{*/', '87/*}}}*/', '88/*}}}*/', '89', '90/*{{{*/', '91', '92', '93/*}}}*/'], getline(85,93)) + norm! zE + call assert_equal(['85', '86', '87', '88', '89', '90', '91', '92', '93'], getline(85,93)) + + " Test for zn + 50 + set foldlevel=0 + norm! 2zF + norm! zn + norm! k + call assert_equal('49', getline('.')) + norm! j + call assert_equal('50/*{{{*/', getline('.')) + norm! j + call assert_equal('51/*}}}*/', getline('.')) + norm! j + call assert_equal('52', getline('.')) + call assert_equal(0, &foldenable) + + " Test for zN + 49 + norm! zN + call assert_equal('49', getline('.')) + norm! j + call assert_equal('50/*{{{*/', getline('.')) + norm! j + call assert_equal('52', getline('.')) + call assert_equal(1, &foldenable) + + " Test for zi + norm! zi + call assert_equal(0, &foldenable) + norm! zi + call assert_equal(1, &foldenable) + norm! zi + call assert_equal(0, &foldenable) + norm! zi + call assert_equal(1, &foldenable) + + " Test for za + 50 + norm! za + norm! k + call assert_equal('49', getline('.')) + norm! j + call assert_equal('50/*{{{*/', getline('.')) + norm! j + call assert_equal('51/*}}}*/', getline('.')) + norm! j + call assert_equal('52', getline('.')) + 50 + norm! za + norm! k + call assert_equal('49', getline('.')) + norm! j + call assert_equal('50/*{{{*/', getline('.')) + norm! j + call assert_equal('52', getline('.')) + + 49 + norm! 5zF + norm! k + call assert_equal('48', getline('.')) + norm! j + call assert_equal('49/*{{{*/', getline('.')) + norm! j + call assert_equal('55', getline('.')) + 49 + norm! za + call assert_equal('49/*{{{*/', getline('.')) + norm! j + call assert_equal('50/*{{{*/', getline('.')) + norm! j + call assert_equal('52', getline('.')) + set nofoldenable + " close fold and set foldenable + norm! za + call assert_equal(1, &foldenable) + + 50 + " have to use {count}za to open all folds and make the cursor visible + norm! 2za + norm! 2k + call assert_equal('48', getline('.')) + norm! j + call assert_equal('49/*{{{*/', getline('.')) + norm! j + call assert_equal('50/*{{{*/', getline('.')) + norm! j + call assert_equal('51/*}}}*/', getline('.')) + norm! j + call assert_equal('52', getline('.')) + + " Test for zA + 49 + set foldlevel=0 + 50 + norm! zA + norm! 2k + call assert_equal('48', getline('.')) + norm! j + call assert_equal('49/*{{{*/', getline('.')) + norm! j + call assert_equal('50/*{{{*/', getline('.')) + norm! j + call assert_equal('51/*}}}*/', getline('.')) + norm! j + call assert_equal('52', getline('.')) + + " zA on a opened fold when foldenable is not set + 50 + set nofoldenable + norm! zA + call assert_equal(1, &foldenable) + norm! k + call assert_equal('48', getline('.')) + norm! j + call assert_equal('49/*{{{*/', getline('.')) + norm! j + call assert_equal('55', getline('.')) + + " Test for zc + norm! zE + 50 + norm! 2zF + 49 + norm! 5zF + set nofoldenable + 50 + " There most likely is a bug somewhere: + " https://groups.google.com/d/msg/vim_dev/v2EkfJ_KQjI/u-Cvv94uCAAJ + " TODO: Should this only close the inner most fold or both folds? + norm! zc + call assert_equal(1, &foldenable) + norm! k + call assert_equal('48', getline('.')) + norm! j + call assert_equal('49/*{{{*/', getline('.')) + norm! j + call assert_equal('55', getline('.')) + set nofoldenable + 50 + norm! Vjzc + norm! k + call assert_equal('48', getline('.')) + norm! j + call assert_equal('49/*{{{*/', getline('.')) + norm! j + call assert_equal('55', getline('.')) + + " Test for zC + set nofoldenable + 50 + norm! zCk + call assert_equal('48', getline('.')) + norm! j + call assert_equal('49/*{{{*/', getline('.')) + norm! j + call assert_equal('55', getline('.')) + + " Test for zx + " 1) close folds at line 49-54 + set nofoldenable + 48 + norm! zx + call assert_equal(1, &foldenable) + norm! j + call assert_equal('49/*{{{*/', getline('.')) + norm! j + call assert_equal('55', getline('.')) + + " 2) do not close fold under cursor + 51 + set nofoldenable + norm! zx + call assert_equal(1, &foldenable) + norm! 3k + call assert_equal('48', getline('.')) + norm! j + call assert_equal('49/*{{{*/', getline('.')) + norm! j + call assert_equal('50/*{{{*/', getline('.')) + norm! j + call assert_equal('51/*}}}*/', getline('.')) + norm! j + call assert_equal('52', getline('.')) + norm! j + call assert_equal('53', getline('.')) + norm! j + call assert_equal('54/*}}}*/', getline('.')) + norm! j + call assert_equal('55', getline('.')) + + " 3) close one level of folds + 48 + set nofoldenable + set foldlevel=1 + norm! zx + call assert_equal(1, &foldenable) + call assert_equal('48', getline('.')) + norm! j + call assert_equal('49/*{{{*/', getline('.')) + norm! j + call assert_equal('50/*{{{*/', getline('.')) + norm! j + call assert_equal('52', getline('.')) + norm! j + call assert_equal('53', getline('.')) + norm! j + call assert_equal('54/*}}}*/', getline('.')) + norm! j + call assert_equal('55', getline('.')) + + " Test for zX + " Close all folds + set foldlevel=0 nofoldenable + 50 + norm! zX + call assert_equal(1, &foldenable) + norm! k + call assert_equal('48', getline('.')) + norm! j + call assert_equal('49/*{{{*/', getline('.')) + norm! j + call assert_equal('55', getline('.')) + + " Test for zm + 50 + set nofoldenable foldlevel=2 + norm! zm + call assert_equal(1, &foldenable) + call assert_equal(1, &foldlevel) + norm! zm + call assert_equal(0, &foldlevel) + norm! zm + call assert_equal(0, &foldlevel) + norm! k + call assert_equal('48', getline('.')) + norm! j + call assert_equal('49/*{{{*/', getline('.')) + norm! j + call assert_equal('55', getline('.')) + + " Test for zM + 48 + set nofoldenable foldlevel=99 + norm! zM + call assert_equal(1, &foldenable) + call assert_equal(0, &foldlevel) + call assert_equal('48', getline('.')) + norm! j + call assert_equal('49/*{{{*/', getline('.')) + norm! j + call assert_equal('55', getline('.')) + + " Test for zr + 48 + set nofoldenable foldlevel=0 + norm! zr + call assert_equal(0, &foldenable) + call assert_equal(1, &foldlevel) + set foldlevel=0 foldenable + norm! zr + call assert_equal(1, &foldenable) + call assert_equal(1, &foldlevel) + norm! zr + call assert_equal(2, &foldlevel) + call assert_equal('48', getline('.')) + norm! j + call assert_equal('49/*{{{*/', getline('.')) + norm! j + call assert_equal('50/*{{{*/', getline('.')) + norm! j + call assert_equal('51/*}}}*/', getline('.')) + norm! j + call assert_equal('52', getline('.')) + + " Test for zR + 48 + set nofoldenable foldlevel=0 + norm! zR + call assert_equal(0, &foldenable) + call assert_equal(2, &foldlevel) + set foldenable foldlevel=0 + norm! zR + call assert_equal(1, &foldenable) + call assert_equal(2, &foldlevel) + call assert_equal('48', getline('.')) + norm! j + call assert_equal('49/*{{{*/', getline('.')) + norm! j + call assert_equal('50/*{{{*/', getline('.')) + norm! j + call assert_equal('51/*}}}*/', getline('.')) + norm! j + call assert_equal('52', getline('.')) + call append(50, ['a /*{{{*/', 'b /*}}}*/']) + 48 + call assert_equal('48', getline('.')) + norm! j + call assert_equal('49/*{{{*/', getline('.')) + norm! j + call assert_equal('50/*{{{*/', getline('.')) + norm! j + call assert_equal('a /*{{{*/', getline('.')) + norm! j + call assert_equal('51/*}}}*/', getline('.')) + norm! j + call assert_equal('52', getline('.')) + 48 + norm! zR + call assert_equal(1, &foldenable) + call assert_equal(3, &foldlevel) + call assert_equal('48', getline('.')) + norm! j + call assert_equal('49/*{{{*/', getline('.')) + norm! j + call assert_equal('50/*{{{*/', getline('.')) + norm! j + call assert_equal('a /*{{{*/', getline('.')) + norm! j + call assert_equal('b /*}}}*/', getline('.')) + norm! j + call assert_equal('51/*}}}*/', getline('.')) + norm! j + call assert_equal('52', getline('.')) + + " clean up + setl nofoldenable fdm=marker foldlevel=0 + bw! +endfunc + +func Test_normal19_z_spell() + if !has("spell") || !has('syntax') + return + endif + new + call append(0, ['1 good', '2 goood', '3 goood']) + set spell spellfile=./Xspellfile.add spelllang=en + let oldlang=v:lang + lang C + + " Test for zg + 1 + norm! ]s + call assert_equal('2 goood', getline('.')) + norm! zg + 1 + let a=execute('unsilent :norm! ]s') + call assert_equal('1 good', getline('.')) + call assert_equal('search hit BOTTOM, continuing at TOP', a[1:]) + let cnt=readfile('./Xspellfile.add') + call assert_equal('goood', cnt[0]) + + " Test for zw + 2 + norm! $zw + 1 + norm! ]s + call assert_equal('2 goood', getline('.')) + let cnt=readfile('./Xspellfile.add') + call assert_equal('#oood', cnt[0]) + call assert_equal('goood/!', cnt[1]) + + " Test for zg in visual mode + let a=execute('unsilent :norm! V$zg') + call assert_equal("Word '2 goood' added to ./Xspellfile.add", a[1:]) + 1 + norm! ]s + call assert_equal('3 goood', getline('.')) + let cnt=readfile('./Xspellfile.add') + call assert_equal('2 goood', cnt[2]) + " Remove "2 good" from spellfile + 2 + let a=execute('unsilent norm! V$zw') + call assert_equal("Word '2 goood' added to ./Xspellfile.add", a[1:]) + let cnt=readfile('./Xspellfile.add') + call assert_equal('2 goood/!', cnt[3]) + + " Test for zG + let a=execute('unsilent norm! V$zG') + call assert_match("Word '2 goood' added to .*", a) + let fname=matchstr(a, 'to\s\+\zs\f\+$') + let cnt=readfile(fname) + call assert_equal('2 goood', cnt[0]) + + " Test for zW + let a=execute('unsilent norm! V$zW') + call assert_match("Word '2 goood' added to .*", a) + let cnt=readfile(fname) + call assert_equal('# goood', cnt[0]) + call assert_equal('2 goood/!', cnt[1]) + + " Test for zuW + let a=execute('unsilent norm! V$zuW') + call assert_match("Word '2 goood' removed from .*", a) + let cnt=readfile(fname) + call assert_equal('# goood', cnt[0]) + call assert_equal('# goood/!', cnt[1]) + + " Test for zuG + let a=execute('unsilent norm! $zG') + call assert_match("Word 'goood' added to .*", a) + let cnt=readfile(fname) + call assert_equal('# goood', cnt[0]) + call assert_equal('# goood/!', cnt[1]) + call assert_equal('goood', cnt[2]) + let a=execute('unsilent norm! $zuG') + let cnt=readfile(fname) + call assert_match("Word 'goood' removed from .*", a) + call assert_equal('# goood', cnt[0]) + call assert_equal('# goood/!', cnt[1]) + call assert_equal('#oood', cnt[2]) + " word not found in wordlist + let a=execute('unsilent norm! V$zuG') + let cnt=readfile(fname) + call assert_match("", a) + call assert_equal('# goood', cnt[0]) + call assert_equal('# goood/!', cnt[1]) + call assert_equal('#oood', cnt[2]) + + " Test for zug + call delete('./Xspellfile.add') + 2 + let a=execute('unsilent norm! $zg') + let cnt=readfile('./Xspellfile.add') + call assert_equal('goood', cnt[0]) + let a=execute('unsilent norm! $zug') + call assert_match("Word 'goood' removed from \./Xspellfile.add", a) + let cnt=readfile('./Xspellfile.add') + call assert_equal('#oood', cnt[0]) + " word not in wordlist + let a=execute('unsilent norm! V$zug') + call assert_match('', a) + let cnt=readfile('./Xspellfile.add') + call assert_equal('#oood', cnt[0]) + + " Test for zuw + call delete('./Xspellfile.add') + 2 + let a=execute('unsilent norm! Vzw') + let cnt=readfile('./Xspellfile.add') + call assert_equal('2 goood/!', cnt[0]) + let a=execute('unsilent norm! Vzuw') + call assert_match("Word '2 goood' removed from \./Xspellfile.add", a) + let cnt=readfile('./Xspellfile.add') + call assert_equal('# goood/!', cnt[0]) + " word not in wordlist + let a=execute('unsilent norm! $zug') + call assert_match('', a) + let cnt=readfile('./Xspellfile.add') + call assert_equal('# goood/!', cnt[0]) + + " add second entry to spellfile setting + set spellfile=./Xspellfile.add,./Xspellfile2.add + call delete('./Xspellfile.add') + 2 + let a=execute('unsilent norm! $2zg') + let cnt=readfile('./Xspellfile2.add') + call assert_match("Word 'goood' added to ./Xspellfile2.add", a) + call assert_equal('goood', cnt[0]) + + " Test for :spellgood! + let temp = execute(':spe!0/0') + call assert_match('Invalid region', temp) + let spellfile = matchstr(temp, 'Invalid region nr in \zs.*\ze line \d: 0') + call assert_equal(['# goood', '# goood/!', '#oood', '0/0'], readfile(spellfile)) + call delete(spellfile) + + " clean up + exe "lang" oldlang + call delete("./Xspellfile.add") + call delete("./Xspellfile2.add") + call delete("./Xspellfile.add.spl") + call delete("./Xspellfile2.add.spl") + + " zux -> no-op + 2 + norm! $zux + call assert_equal([], glob('Xspellfile.add',0,1)) + call assert_equal([], glob('Xspellfile2.add',0,1)) + + set spellfile= + bw! +endfunc + +func Test_normal20_exmode() + if !has("unix") + " Reading from redirected file doesn't work on MS-Windows + return + endif + call writefile(['1a', 'foo', 'bar', '.', 'w! Xfile2', 'q!'], 'Xscript') + call writefile(['1', '2'], 'Xfile') + call system(v:progpath .' -e -s < Xscript Xfile') + let a=readfile('Xfile2') + call assert_equal(['1', 'foo', 'bar', '2'], a) + + " clean up + for file in ['Xfile', 'Xfile2', 'Xscript'] + call delete(file) + endfor + bw! +endfunc + +func Test_normal21_nv_hat() + + " Edit a fresh file and wipe the buffer list so that there is no alternate + " file present. Next, check for the expected command failures. + edit Xfoo | %bw + call assert_fails(':buffer #', 'E86') + call assert_fails(':execute "normal! \<C-^>"', 'E23') + + " Test for the expected behavior when switching between two named buffers. + edit Xfoo | edit Xbar + call feedkeys("\<C-^>", 'tx') + call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t')) + call feedkeys("\<C-^>", 'tx') + call assert_equal('Xbar', fnamemodify(bufname('%'), ':t')) + + " Test for the expected behavior when only one buffer is named. + enew | let l:nr = bufnr('%') + call feedkeys("\<C-^>", 'tx') + call assert_equal('Xbar', fnamemodify(bufname('%'), ':t')) + call feedkeys("\<C-^>", 'tx') + call assert_equal('', bufname('%')) + call assert_equal(l:nr, bufnr('%')) + + " Test that no action is taken by "<C-^>" when an operator is pending. + edit Xfoo + call feedkeys("ci\<C-^>", 'tx') + call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t')) + + %bw! +endfunc + +func Test_normal22_zet() + " Test for ZZ + " let shell = &shell + " let &shell = 'sh' + call writefile(['1', '2'], 'Xfile') + let args = ' -u NONE -N -U NONE -i NONE --noplugins -X --not-a-term' + call system(v:progpath . args . ' -c "%d" -c ":norm! ZZ" Xfile') + let a = readfile('Xfile') + call assert_equal([], a) + " Test for ZQ + call writefile(['1', '2'], 'Xfile') + call system(v:progpath . args . ' -c "%d" -c ":norm! ZQ" Xfile') + let a = readfile('Xfile') + call assert_equal(['1', '2'], a) + + " clean up + for file in ['Xfile'] + call delete(file) + endfor + " let &shell = shell +endfunc + +func Test_normal23_K() + " Test for K command + new + call append(0, ['version8.txt', 'man', 'aa%bb', 'cc|dd']) + let k = &keywordprg + set keywordprg=:help + 1 + norm! VK + call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t')) + call assert_equal('help', &ft) + call assert_match('\*version8.txt\*', getline('.')) + helpclose + norm! 0K + call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t')) + call assert_equal('help', &ft) + call assert_match('\*version8\.\d\*', getline('.')) + helpclose + + set keywordprg=:new + set iskeyword+=% + set iskeyword+=\| + 2 + norm! K + call assert_equal('man', fnamemodify(bufname('%'), ':t')) + bwipe! + 3 + norm! K + call assert_equal('aa%bb', fnamemodify(bufname('%'), ':t')) + bwipe! + if !has('win32') + 4 + norm! K + call assert_equal('cc|dd', fnamemodify(bufname('%'), ':t')) + bwipe! + endif + set iskeyword-=% + set iskeyword-=\| + + " Only expect "man" to work on Unix + if !has("unix") + let &keywordprg = k + bw! + return + endif + set keywordprg=man\ --pager=cat + " Test for using man + 2 + let a = execute('unsilent norm! K') + call assert_match("man --pager=cat 'man'", a) + + " clean up + let &keywordprg = k + bw! +endfunc + +func Test_normal24_rot13() + " Testing for g?? g?g? + new + call append(0, 'abcdefghijklmnopqrstuvwxyzäüö') + 1 + norm! g?? + call assert_equal('nopqrstuvwxyzabcdefghijklmäüö', getline('.')) + norm! g?g? + call assert_equal('abcdefghijklmnopqrstuvwxyzäüö', getline('.')) + + " clean up + bw! +endfunc + +func Test_normal25_tag() + " Testing for CTRL-] g CTRL-] g] + " CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-] + h + " Test for CTRL-] + call search('\<x\>$') + exe "norm! \<c-]>" + call assert_equal("change.txt", fnamemodify(bufname('%'), ':t')) + norm! yiW + call assert_equal("*x*", @0) + exe ":norm \<c-o>" + + " Test for g_CTRL-] + call search('\<v_u\>$') + exe "norm! g\<c-]>" + call assert_equal("change.txt", fnamemodify(bufname('%'), ':t')) + norm! yiW + call assert_equal("*v_u*", @0) + exe ":norm \<c-o>" + + " Test for g] + call search('\<i_<Esc>$') + let a = execute(":norm! g]") + call assert_match('i_<Esc>.*insert.txt', a) + + if !empty(exepath('cscope')) && has('cscope') + " setting cscopetag changes how g] works + set cst + exe "norm! g]" + call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) + norm! yiW + call assert_equal("*i_<Esc>*", @0) + exe ":norm \<c-o>" + " Test for CTRL-W g] + exe "norm! \<C-W>g]" + call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) + norm! yiW + call assert_equal("*i_<Esc>*", @0) + call assert_equal(3, winnr('$')) + helpclose + set nocst + endif + + " Test for CTRL-W g] + let a = execute("norm! \<C-W>g]") + call assert_match('i_<Esc>.*insert.txt', a) + + " Test for CTRL-W CTRL-] + exe "norm! \<C-W>\<C-]>" + call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) + norm! yiW + call assert_equal("*i_<Esc>*", @0) + call assert_equal(3, winnr('$')) + helpclose + + " Test for CTRL-W g CTRL-] + exe "norm! \<C-W>g\<C-]>" + call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) + norm! yiW + call assert_equal("*i_<Esc>*", @0) + call assert_equal(3, winnr('$')) + helpclose + + " clean up + helpclose +endfunc + +func Test_normal26_put() + " Test for ]p ]P [p and [P + new + call append(0, ['while read LINE', 'do', ' ((count++))', ' if [ $? -ne 0 ]; then', " echo 'Error writing file'", ' fi', 'done']) + 1 + /Error/y a + 2 + norm! "a]pj"a[p + call assert_equal(['do', "echo 'Error writing file'", " echo 'Error writing file'", ' ((count++))'], getline(2,5)) + 1 + /^\s\{4}/ + exe "norm! \"a]P3Eldt'" + exe "norm! j\"a[P2Eldt'" + call assert_equal([' if [ $? -ne 0 ]; then', " echo 'Error writing'", " echo 'Error'", " echo 'Error writing file'", ' fi'], getline(6,10)) + + " clean up + bw! +endfunc + +func Test_normal27_bracket() + " Test for [' [` ]' ]` + call Setup_NewWindow() + 1,21s/.\+/ & b/ + 1 + norm! $ma + 5 + norm! $mb + 10 + norm! $mc + 15 + norm! $md + 20 + norm! $me + + " Test for [' + 9 + norm! 2[' + call assert_equal(' 1 b', getline('.')) + call assert_equal(1, line('.')) + call assert_equal(3, col('.')) + + " Test for ]' + norm! ]' + call assert_equal(' 5 b', getline('.')) + call assert_equal(5, line('.')) + call assert_equal(3, col('.')) + + " No mark after line 21, cursor moves to first non blank on current line + 21 + norm! $]' + call assert_equal(' 21 b', getline('.')) + call assert_equal(21, line('.')) + call assert_equal(3, col('.')) + + " Test for [` + norm! 2[` + call assert_equal(' 15 b', getline('.')) + call assert_equal(15, line('.')) + call assert_equal(8, col('.')) + + " Test for ]` + norm! ]` + call assert_equal(' 20 b', getline('.')) + call assert_equal(20, line('.')) + call assert_equal(8, col('.')) + + " clean up + bw! +endfunc + +func Test_normal28_parenthesis() + " basic testing for ( and ) + new + call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here']) + + $ + norm! d( + call assert_equal(['This is a test. With some sentences!', '', 'Even with a question? And one more. ', ''], getline(1, '$')) + norm! 2d( + call assert_equal(['This is a test. With some sentences!', '', ' ', ''], getline(1, '$')) + 1 + norm! 0d) + call assert_equal(['With some sentences!', '', ' ', ''], getline(1, '$')) + + call append('$', ['This is a long sentence', '', 'spanning', 'over several lines. ']) + $ + norm! $d( + call assert_equal(['With some sentences!', '', ' ', '', 'This is a long sentence', ''], getline(1, '$')) + + " clean up + bw! +endfunc + +fun! Test_normal29_brace() + " basic test for { and } movements + let text= ['A paragraph begins after each empty line, and also at each of a set of', + \ 'paragraph macros, specified by the pairs of characters in the ''paragraphs''', + \ 'option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to', + \ 'the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in', + \ 'the first column). A section boundary is also a paragraph boundary.', + \ 'Note that a blank line (only containing white space) is NOT a paragraph', + \ 'boundary.', + \ '', + \ '', + \ 'Also note that this does not include a ''{'' or ''}'' in the first column. When', + \ 'the ''{'' flag is in ''cpoptions'' then ''{'' in the first column is used as a', + \ 'paragraph boundary |posix|.', + \ '{', + \ 'This is no paragraph', + \ 'unless the ''{'' is set', + \ 'in ''cpoptions''', + \ '}', + \ '.IP', + \ 'The nroff macros IP separates a paragraph', + \ 'That means, it must be a ''.''', + \ 'followed by IP', + \ '.LPIt does not matter, if afterwards some', + \ 'more characters follow.', + \ '.SHAlso section boundaries from the nroff', + \ 'macros terminate a paragraph. That means', + \ 'a character like this:', + \ '.NH', + \ 'End of text here'] + new + call append(0, text) + 1 + norm! 0d2} + call assert_equal(['.IP', + \ 'The nroff macros IP separates a paragraph', 'That means, it must be a ''.''', 'followed by IP', + \ '.LPIt does not matter, if afterwards some', 'more characters follow.', '.SHAlso section boundaries from the nroff', + \ 'macros terminate a paragraph. That means', 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$')) + norm! 0d} + call assert_equal(['.LPIt does not matter, if afterwards some', 'more characters follow.', + \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', + \ 'a character like this:', '.NH', 'End of text here', ''], getline(1, '$')) + $ + norm! d{ + call assert_equal(['.LPIt does not matter, if afterwards some', 'more characters follow.', + \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', 'a character like this:', ''], getline(1, '$')) + norm! d{ + call assert_equal(['.LPIt does not matter, if afterwards some', 'more characters follow.', ''], getline(1,'$')) + " Test with { in cpooptions + %d + call append(0, text) + set cpo+={ + 1 + norm! 0d2} + call assert_equal(['{', 'This is no paragraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', + \ '.IP', 'The nroff macros IP separates a paragraph', 'That means, it must be a ''.''', + \ 'followed by IP', '.LPIt does not matter, if afterwards some', 'more characters follow.', + \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', + \ 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$')) + $ + norm! d} + call assert_equal(['{', 'This is no paragraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', + \ '.IP', 'The nroff macros IP separates a paragraph', 'That means, it must be a ''.''', + \ 'followed by IP', '.LPIt does not matter, if afterwards some', 'more characters follow.', + \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', + \ 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$')) + norm! gg} + norm! d5} + call assert_equal(['{', 'This is no paragraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', ''], getline(1,'$')) + + " clean up + set cpo-={ + bw! +endfunc + +fun! Test_normal30_changecase() + new + call append(0, 'This is a simple test: äüöß') + norm! 1ggVu + call assert_equal('this is a simple test: äüöß', getline('.')) + norm! VU + call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.')) + norm! guu + call assert_equal('this is a simple test: äüöss', getline('.')) + norm! gUgU + call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.')) + norm! gugu + call assert_equal('this is a simple test: äüöss', getline('.')) + norm! gUU + call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.')) + norm! 010~ + call assert_equal('this is a SIMPLE TEST: ÄÜÖSS', getline('.')) + norm! V~ + call assert_equal('THIS IS A simple test: äüöss', getline('.')) + + " Turkish ASCII turns to multi-byte. On some systems Turkish locale + " is available but toupper()/tolower() don't do the right thing. + try + lang tr_TR.UTF-8 + set casemap= + let iupper = toupper('i') + if iupper == "\u0130" + call setline(1, 'iI') + 1normal gUU + call assert_equal("\u0130I", getline(1)) + call assert_equal("\u0130I", toupper("iI")) + + call setline(1, 'iI') + 1normal guu + call assert_equal("i\u0131", getline(1)) + call assert_equal("i\u0131", tolower("iI")) + elseif iupper == "I" + call setline(1, 'iI') + 1normal gUU + call assert_equal("II", getline(1)) + call assert_equal("II", toupper("iI")) + + call setline(1, 'iI') + 1normal guu + call assert_equal("ii", getline(1)) + call assert_equal("ii", tolower("iI")) + else + call assert_true(false, "expected toupper('i') to be either 'I' or '\u0130'") + endif + set casemap& + call setline(1, 'iI') + 1normal gUU + call assert_equal("II", getline(1)) + call assert_equal("II", toupper("iI")) + + call setline(1, 'iI') + 1normal guu + call assert_equal("ii", getline(1)) + call assert_equal("ii", tolower("iI")) + + lang en_US.UTF-8 + catch /E197:/ + " can't use Turkish locale + throw 'Skipped: Turkish locale not available' + endtry + + " clean up + bw! +endfunc + +fun! Test_normal31_r_cmd() + " Test for r command + new + call append(0, 'This is a simple test: abcd') + exe "norm! 1gg$r\<cr>" + call assert_equal(['This is a simple test: abc', '', ''], getline(1,'$')) + exe "norm! 1gg2wlr\<cr>" + call assert_equal(['This is a', 'simple test: abc', '', ''], getline(1,'$')) + exe "norm! 2gg0W5r\<cr>" + call assert_equal(['This is a', 'simple ', ' abc', '', ''], getline('1', '$')) + set autoindent + call setline(2, ['simple test: abc', '']) + exe "norm! 2gg0W5r\<cr>" + call assert_equal(['This is a', 'simple ', 'abc', '', '', ''], getline('1', '$')) + exe "norm! 1ggVr\<cr>" + call assert_equal('^M^M^M^M^M^M^M^M^M', strtrans(getline(1))) + call setline(1, 'This is a') + exe "norm! 1gg05rf" + call assert_equal('fffffis a', getline(1)) + + " clean up + set noautoindent + bw! +endfunc + +func Test_normal32_g_cmd1() + " Test for g*, g# + new + call append(0, ['abc.x_foo', 'x_foobar.abc']) + 1 + norm! $g* + call assert_equal('x_foo', @/) + call assert_equal('x_foobar.abc', getline('.')) + norm! $g# + call assert_equal('abc', @/) + call assert_equal('abc.x_foo', getline('.')) + + " clean up + bw! +endfunc + +fun! Test_normal33_g_cmd2() + if !has("jumplist") + return + endif + " Tests for g cmds + call Setup_NewWindow() + " Test for g` + clearjumps + norm! ma10j + let a=execute(':jumps') + " empty jumplist + call assert_equal('>', a[-1:]) + norm! g`a + call assert_equal('>', a[-1:]) + call assert_equal(1, line('.')) + call assert_equal('1', getline('.')) + + " Test for g; and g, + norm! g; + " there is only one change in the changelist + " currently, when we setup the window + call assert_equal(2, line('.')) + call assert_fails(':norm! g;', 'E662') + call assert_fails(':norm! g,', 'E663') + let &ul=&ul + call append('$', ['a', 'b', 'c', 'd']) + let &ul=&ul + call append('$', ['Z', 'Y', 'X', 'W']) + let a = execute(':changes') + call assert_match('2\s\+0\s\+2', a) + call assert_match('101\s\+0\s\+a', a) + call assert_match('105\s\+0\s\+Z', a) + norm! 3g; + call assert_equal(2, line('.')) + norm! 2g, + call assert_equal(105, line('.')) + + " Test for g& - global substitute + %d + call setline(1, range(1,10)) + call append('$', ['a', 'b', 'c', 'd']) + $s/\w/&&/g + exe "norm! /[1-8]\<cr>" + norm! g& + call assert_equal(['11', '22', '33', '44', '55', '66', '77', '88', '9', '110', 'a', 'b', 'c', 'dd'], getline(1, '$')) + + " Test for gv + %d + call append('$', repeat(['abcdefgh'], 8)) + exe "norm! 2gg02l\<c-v>2j2ly" + call assert_equal(['cde', 'cde', 'cde'], getreg(0, 1, 1)) + " in visual mode, gv swaps current and last selected region + exe "norm! G0\<c-v>4k4lgvd" + call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh'], getline(1,'$')) + exe "norm! G0\<c-v>4k4ly" + exe "norm! gvood" + call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'fgh', 'fgh', 'fgh', 'fgh', 'fgh'], getline(1,'$')) + + " Test for gk/gj + %d + 15vsp + set wrap listchars= sbr= + let lineA='abcdefghijklmnopqrstuvwxyz' + let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' + $put =lineA + $put =lineB + + norm! 3gg0dgk + call assert_equal(['', 'abcdefghijklmno', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'], getline(1, '$')) + set nu + norm! 3gg0gjdgj + call assert_equal(['', 'abcdefghijklmno', '0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) + + " Test for gJ + norm! 2gggJ + call assert_equal(['', 'abcdefghijklmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) + call assert_equal(16, col('.')) + " shouldn't do anything + norm! 10gJ + call assert_equal(1, col('.')) + + " Test for g0 g^ gm g$ + exe "norm! 2gg0gji " + call assert_equal(['', 'abcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) + norm! g0yl + call assert_equal(12, col('.')) + call assert_equal(' ', getreg(0)) + norm! g$yl + call assert_equal(22, col('.')) + call assert_equal('3', getreg(0)) + norm! gmyl + call assert_equal(17, col('.')) + call assert_equal('n', getreg(0)) + norm! g^yl + call assert_equal(15, col('.')) + call assert_equal('l', getreg(0)) + + " Test for gI + norm! gIfoo + call assert_equal(['', 'fooabcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) + + " Test for gi + wincmd c + %d + set tw=0 + call setline(1, ['foobar', 'new line']) + norm! A next word + $put ='third line' + norm! gi another word + call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$')) + + " clean up + bw! +endfunc + +func Test_g_ctrl_g() + new + + let a = execute(":norm! g\<c-g>") + call assert_equal("\n--No lines in buffer--", a) + + call setline(1, ['first line', 'second line']) + + " Test g CTRL-g with dos, mac and unix file type. + norm! gojll + set ff=dos + let a = execute(":norm! g\<c-g>") + call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 15 of 25", a) + + set ff=mac + let a = execute(":norm! g\<c-g>") + call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a) + + set ff=unix + let a = execute(":norm! g\<c-g>") + call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a) + + " Test g CTRL-g in visual mode (v) + let a = execute(":norm! gojllvlg\<c-g>") + call assert_equal("\nSelected 1 of 2 Lines; 1 of 4 Words; 2 of 23 Bytes", a) + + " Test g CTRL-g in visual mode (CTRL-V) with end col > start col + let a = execute(":norm! \<Esc>gojll\<C-V>kllg\<c-g>") + call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a) + + " Test g_CTRL-g in visual mode (CTRL-V) with end col < start col + let a = execute(":norm! \<Esc>goll\<C-V>jhhg\<c-g>") + call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a) + + " Test g CTRL-g in visual mode (CTRL-V) with end_vcol being MAXCOL + let a = execute(":norm! \<Esc>gojll\<C-V>k$g\<c-g>") + call assert_equal("\nSelected 2 of 2 Lines; 4 of 4 Words; 17 of 23 Bytes", a) + + " There should be one byte less with noeol + set bin noeol + let a = execute(":norm! \<Esc>gog\<c-g>") + call assert_equal("\nCol 1 of 10; Line 1 of 2; Word 1 of 4; Char 1 of 23; Byte 1 of 22", a) + set bin & eol& + + call setline(1, ['Français', '日本語']) + + let a = execute(":norm! \<Esc>gojlg\<c-g>") + call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20", a) + + let a = execute(":norm! \<Esc>gojvlg\<c-g>") + call assert_equal("\nSelected 1 of 2 Lines; 1 of 2 Words; 2 of 13 Chars; 6 of 20 Bytes", a) + + let a = execute(":norm! \<Esc>goll\<c-v>jlg\<c-g>") + call assert_equal("\nSelected 4 Cols; 2 of 2 Lines; 2 of 2 Words; 6 of 13 Chars; 11 of 20 Bytes", a) + + set fenc=utf8 bomb + let a = execute(":norm! \<Esc>gojlg\<c-g>") + call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+3 for BOM)", a) + + set fenc=utf16 bomb + let a = execute(":norm! g\<c-g>") + call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+2 for BOM)", a) + + set fenc=utf32 bomb + let a = execute(":norm! g\<c-g>") + call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+4 for BOM)", a) + + set fenc& bomb& + + set ff& + bwipe! +endfunc + +fun! Test_normal34_g_cmd3() + " Test for g8 + new + let a=execute(':norm! 1G0g8') + call assert_equal("\nNUL", a) + + call setline(1, 'abcdefghijklmnopqrstuvwxyzäüö') + let a=execute(':norm! 1G$g8') + call assert_equal("\nc3 b6 ", a) + + call setline(1, "a\u0302") + let a=execute(':norm! 1G0g8') + call assert_equal("\n61 + cc 82 ", a) + + " clean up + bw! +endfunc + +func Test_normal_8g8() + new + + " Test 8g8 which finds invalid utf8 at or after the cursor. + + " With invalid byte. + call setline(1, "___\xff___") + norm! 1G08g8g + call assert_equal([0, 1, 4, 0, 1], getcurpos()) + + " With invalid byte before the cursor. + call setline(1, "___\xff___") + norm! 1G$h8g8g + call assert_equal([0, 1, 6, 0, 9], getcurpos()) + + " With truncated sequence. + call setline(1, "___\xE2\x82___") + norm! 1G08g8g + call assert_equal([0, 1, 4, 0, 1], getcurpos()) + + " With overlong sequence. + call setline(1, "___\xF0\x82\x82\xAC___") + norm! 1G08g8g + call assert_equal([0, 1, 4, 0, 1], getcurpos()) + + " With valid utf8. + call setline(1, "café") + norm! 1G08g8 + call assert_equal([0, 1, 1, 0, 1], getcurpos()) + + bw! +endfunc + +fun! Test_normal35_g_cmd4() + " Test for g< + " Cannot capture its output, + " probably a bug, therefore, test disabled: + throw "Skipped: output of g< can't be tested currently" + echo "a\nb\nc\nd" + let b=execute(':norm! g<') + call assert_true(!empty(b), 'failed `execute(g<)`') +endfunc + +fun! Test_normal36_g_cmd5() + new + call append(0, 'abcdefghijklmnopqrstuvwxyz') + set ff=unix + " Test for gp gP + call append(1, range(1,10)) + 1 + norm! 1yy + 3 + norm! gp + call assert_equal([0, 5, 1, 0, 1], getcurpos()) + $ + norm! gP + call assert_equal([0, 14, 1, 0, 1], getcurpos()) + + " Test for go + norm! 26go + call assert_equal([0, 1, 26, 0, 26], getcurpos()) + norm! 27go + call assert_equal([0, 1, 26, 0, 26], getcurpos()) + norm! 28go + call assert_equal([0, 2, 1, 0, 1], getcurpos()) + set ff=dos + norm! 29go + call assert_equal([0, 2, 1, 0, 1], getcurpos()) + set ff=unix + norm! gg0 + norm! 101go + call assert_equal([0, 13, 26, 0, 26], getcurpos()) + norm! 103go + call assert_equal([0, 14, 1, 0, 1], getcurpos()) + " count > buffer content + norm! 120go + call assert_equal([0, 14, 1, 0, 2147483647], getcurpos()) + " clean up + bw! +endfunc + +fun! Test_normal37_g_cmd6() + " basic test for gt and gT + tabnew 1.txt + tabnew 2.txt + tabnew 3.txt + norm! 1gt + call assert_equal(1, tabpagenr()) + norm! 3gt + call assert_equal(3, tabpagenr()) + norm! 1gT + " count gT goes not to the absolute tabpagenumber + " but, but goes to the count previous tabpagenumber + call assert_equal(2, tabpagenr()) + " wrap around + norm! 3gT + call assert_equal(3, tabpagenr()) + " gt does not wrap around + norm! 5gt + call assert_equal(3, tabpagenr()) + + for i in range(3) + tabclose + endfor + " clean up + call assert_fails(':tabclose', 'E784') +endfunc + +fun! Test_normal38_nvhome() + " Test for <Home> and <C-Home> key + new + call setline(1, range(10)) + $ + setl et sw=2 + norm! V10>$ + " count is ignored + exe "norm! 10\<home>" + call assert_equal(1, col('.')) + exe "norm! \<home>" + call assert_equal([0, 10, 1, 0, 1], getcurpos()) + exe "norm! 5\<c-home>" + call assert_equal([0, 5, 1, 0, 1], getcurpos()) + exe "norm! \<c-home>" + call assert_equal([0, 1, 1, 0, 1], getcurpos()) + + " clean up + bw! +endfunc + +fun! Test_normal39_cw() + " Test for cw and cW on whitespace + " and cpo+=w setting + new + set tw=0 + call append(0, 'here are some words') + norm! 1gg0elcwZZZ + call assert_equal('hereZZZare some words', getline('.')) + norm! 1gg0elcWYYY + call assert_equal('hereZZZareYYYsome words', getline('.')) + set cpo+=w + call setline(1, 'here are some words') + norm! 1gg0elcwZZZ + call assert_equal('hereZZZ are some words', getline('.')) + norm! 1gg2elcWYYY + call assert_equal('hereZZZ areYYY some words', getline('.')) + set cpo-=w + norm! 2gg0cwfoo + call assert_equal('foo', getline('.')) + + " clean up + bw! +endfunc + +fun! Test_normal40_ctrl_bsl() + " Basic test for CTRL-\ commands + new + call append(0, 'here are some words') + exe "norm! 1gg0a\<C-\>\<C-N>" + call assert_equal('n', mode()) + call assert_equal(1, col('.')) + call assert_equal('', visualmode()) + exe "norm! 1gg0viw\<C-\>\<C-N>" + call assert_equal('n', mode()) + call assert_equal(4, col('.')) + exe "norm! 1gg0a\<C-\>\<C-G>" + call assert_equal('n', mode()) + call assert_equal(1, col('.')) + "imap <buffer> , <c-\><c-n> + set im + exe ":norm! \<c-\>\<c-n>dw" + set noim + call assert_equal('are some words', getline(1)) + call assert_false(&insertmode) + + " clean up + bw! +endfunc + +fun! Test_normal41_insert_reg() + " Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>= + " in insert mode + new + set sts=2 sw=2 ts=8 tw=0 + call append(0, ["aaa\tbbb\tccc", '', '', '']) + let a=getline(1) + norm! 2gg0 + exe "norm! a\<c-r>=a\<cr>" + norm! 3gg0 + exe "norm! a\<c-r>\<c-r>=a\<cr>" + norm! 4gg0 + exe "norm! a\<c-r>\<c-o>=a\<cr>" + call assert_equal(['aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', ''], getline(1, '$')) + + " clean up + set sts=0 sw=8 ts=8 + bw! +endfunc + +func Test_normal42_halfpage() + " basic test for Ctrl-D and Ctrl-U + call Setup_NewWindow() + call assert_equal(5, &scroll) + exe "norm! \<c-d>" + call assert_equal('6', getline('.')) + exe "norm! 2\<c-d>" + call assert_equal('8', getline('.')) + call assert_equal(2, &scroll) + set scroll=5 + exe "norm! \<c-u>" + call assert_equal('3', getline('.')) + 1 + set scrolloff=5 + exe "norm! \<c-d>" + call assert_equal('10', getline('.')) + exe "norm! \<c-u>" + call assert_equal('5', getline('.')) + 1 + set scrolloff=99 + exe "norm! \<c-d>" + call assert_equal('10', getline('.')) + set scrolloff=0 + 100 + exe "norm! $\<c-u>" + call assert_equal('95', getline('.')) + call assert_equal([0, 95, 1, 0, 1], getcurpos()) + 100 + set nostartofline + exe "norm! $\<c-u>" + call assert_equal('95', getline('.')) + call assert_equal([0, 95, 2, 0, 2147483647], getcurpos()) + " cleanup + set startofline + bw! +endfunc + +fun! Test_normal43_textobject1() + " basic tests for text object aw + new + call append(0, ['foobar,eins,foobar', 'foo,zwei,foo ']) + " diw + norm! 1gg0diw + call assert_equal([',eins,foobar', 'foo,zwei,foo ', ''], getline(1,'$')) + " daw + norm! 2ggEdaw + call assert_equal([',eins,foobar', 'foo,zwei,', ''], getline(1, '$')) + %d + call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "]) + " diW + norm! 2ggwd2iW + call assert_equal(['foo eins foobar', 'foo foo ', ''], getline(1,'$')) + " daW + norm! 1ggd2aW + call assert_equal(['foobar', 'foo foo ', ''], getline(1,'$')) + + %d + call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "]) + " aw in visual line mode switches to characterwise mode + norm! 2gg$Vawd + call assert_equal(['foo eins foobar', 'foo zwei foo'], getline(1,'$')) + norm! 1gg$Viwd + call assert_equal(['foo eins ', 'foo zwei foo'], getline(1,'$')) + + " clean up + bw! +endfunc + +func Test_normal44_textobjects2() + " basic testing for is and as text objects + new + call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here']) + " Test for dis - does not remove trailing whitespace + norm! 1gg0dis + call assert_equal([' With some sentences!', '', 'Even with a question? And one more. And no sentence here', ''], getline(1,'$')) + " Test for das - removes leading whitespace + norm! 3ggf?ldas + call assert_equal([' With some sentences!', '', 'Even with a question? And no sentence here', ''], getline(1,'$')) + " when used in visual mode, is made characterwise + norm! 3gg$Visy + call assert_equal('v', visualmode()) + " reset visualmode() + norm! 3ggVy + norm! 3gg$Vasy + call assert_equal('v', visualmode()) + " basic testing for textobjects a< and at + %d + call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' ']) + " a< + norm! 1gg0da< + call assert_equal([' ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) + norm! 1pj + call assert_equal([' <div>', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) + " at + norm! d2at + call assert_equal([' '], getline(1,'$')) + %d + call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' ']) + " i< + norm! 1gg0di< + call assert_equal(['<> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) + norm! 1Pj + call assert_equal(['<div> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) + norm! d2it + call assert_equal(['<div></div>',' '], getline(1,'$')) + " basic testing for a[ and i[ text object + %d + call setline(1, [' ', '[', 'one [two]', 'thre', ']']) + norm! 3gg0di[ + call assert_equal([' ', '[', ']'], getline(1,'$')) + call setline(1, [' ', '[', 'one [two]', 'thre', ']']) + norm! 3gg0ftd2a[ + call assert_equal([' '], getline(1,'$')) + %d + " Test for i" when cursor is in front of a quoted object + call append(0, 'foo "bar"') + norm! 1gg0di" + call assert_equal(['foo ""', ''], getline(1,'$')) + + " clean up + bw! +endfunc + +func Test_normal45_drop() + if !has('dnd') + " The ~ register does not exist + call assert_beeps('norm! "~') + return + endif + + " basic test for drag-n-drop + " unfortunately, without a gui, we can't really test much here, + " so simply test that ~p fails (which uses the drop register) + new + call assert_fails(':norm! "~p', 'E353') + call assert_equal([], getreg('~', 1, 1)) + " the ~ register is read only + call assert_fails(':let @~="1"', 'E354') + bw! +endfunc + +func Test_normal46_ignore() + new + " How to test this? + " let's just for now test, that the buffer + " does not change + call feedkeys("\<c-s>", 't') + call assert_equal([''], getline(1,'$')) + + " no valid commands + exe "norm! \<char-0x100>" + call assert_equal([''], getline(1,'$')) + + exe "norm! ä" + call assert_equal([''], getline(1,'$')) + + " clean up + bw! +endfunc + +func Test_normal47_visual_buf_wipe() + " This was causing a crash or ml_get error. + enew! + call setline(1,'xxx') + normal $ + new + call setline(1, range(1,2)) + 2 + exe "norm \<C-V>$" + bw! + norm yp + set nomodified +endfunc + +func Test_normal47_autocmd() + " disabled, does not seem to be possible currently + throw "Skipped: not possible to test cursorhold autocmd while waiting for input in normal_cmd" + new + call append(0, repeat('-',20)) + au CursorHold * call feedkeys('2l', '') + 1 + set updatetime=20 + " should delete 12 chars (d12l) + call feedkeys('d1', '!') + call assert_equal('--------', getline(1)) + + " clean up + au! CursorHold + set updatetime=4000 + bw! +endfunc + +func Test_normal48_wincmd() + new + exe "norm! \<c-w>c" + call assert_equal(1, winnr('$')) + call assert_fails(":norm! \<c-w>c", "E444") +endfunc + +func Test_normal49_counts() + new + call setline(1, 'one two three four five six seven eight nine ten') + 1 + norm! 3d2w + call assert_equal('seven eight nine ten', getline(1)) + bw! +endfunc + +func Test_normal50_commandline() + if !has("timers") || !has("cmdline_hist") + return + endif + func! DoTimerWork(id) + call assert_equal('[Command Line]', bufname('')) + " should fail, with E11, but does fail with E23? + "call feedkeys("\<c-^>", 'tm') + + " should also fail with E11 + call assert_fails(":wincmd p", 'E11') + " return from commandline window + call feedkeys("\<cr>") + endfunc + + let oldlang=v:lang + lang C + set updatetime=20 + call timer_start(100, 'DoTimerWork') + try + " throws E23, for whatever reason... + call feedkeys('q:', 'x!') + catch /E23/ + " no-op + endtry + " clean up + set updatetime=4000 + exe "lang" oldlang + bw! +endfunc + +func Test_normal51_FileChangedRO() + if !has("autocmd") + return + endif + " Don't sleep after the warning message. + call test_settime(1) + call writefile(['foo'], 'Xreadonly.log') + new Xreadonly.log + setl ro + au FileChangedRO <buffer> :call feedkeys("\<c-^>", 'tix') + call assert_fails(":norm! Af", 'E788') + call assert_equal(['foo'], getline(1,'$')) + call assert_equal('Xreadonly.log', bufname('')) + + " cleanup + call test_settime(0) + bw! + call delete("Xreadonly.log") +endfunc + +func Test_normal52_rl() + if !has("rightleft") + return + endif + new + call setline(1, 'abcde fghij klmnopq') + norm! 1gg$ + set rl + call assert_equal(19, col('.')) + call feedkeys('l', 'tx') + call assert_equal(18, col('.')) + call feedkeys('h', 'tx') + call assert_equal(19, col('.')) + call feedkeys("\<right>", 'tx') + call assert_equal(18, col('.')) + call feedkeys("\<s-right>", 'tx') + call assert_equal(13, col('.')) + call feedkeys("\<c-right>", 'tx') + call assert_equal(7, col('.')) + call feedkeys("\<c-left>", 'tx') + call assert_equal(13, col('.')) + call feedkeys("\<s-left>", 'tx') + call assert_equal(19, col('.')) + call feedkeys("<<", 'tx') + call assert_equal(' abcde fghij klmnopq',getline(1)) + call feedkeys(">>", 'tx') + call assert_equal('abcde fghij klmnopq',getline(1)) + + " cleanup + set norl + bw! +endfunc + +func Test_normal53_digraph() + if !has('digraphs') + return + endif + new + call setline(1, 'abcdefgh|') + exe "norm! 1gg0f\<c-k>!!" + call assert_equal(9, col('.')) + set cpo+=D + exe "norm! 1gg0f\<c-k>!!" + call assert_equal(1, col('.')) + + set cpo-=D + bw! +endfunc + +func Test_normal54_Ctrl_bsl() + new + call setline(1, 'abcdefghijklmn') + exe "norm! df\<c-\>\<c-n>" + call assert_equal(['abcdefghijklmn'], getline(1,'$')) + exe "norm! df\<c-\>\<c-g>" + call assert_equal(['abcdefghijklmn'], getline(1,'$')) + exe "norm! df\<c-\>m" + call assert_equal(['abcdefghijklmn'], getline(1,'$')) + + call setline(2, 'abcdefghijklmnāf') + norm! 2gg0 + exe "norm! df\<Char-0x101>" + call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$')) + norm! 1gg0 + exe "norm! df\<esc>" + call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$')) + + " clean up + bw! +endfunc + +func Test_normal_large_count() + " This may fail with 32bit long, how do we detect that? + new + normal o + normal 6666666666dL + bwipe! +endfunc + +func Test_delete_until_paragraph() + new + normal grádv} + call assert_equal('á', getline(1)) + normal grád} + call assert_equal('', getline(1)) + bwipe! +endfunc + +" Test for the gr (virtual replace) command +" Test for the bug fixed by 7.4.387 +func Test_gr_command() + enew! + let save_cpo = &cpo + call append(0, ['First line', 'Second line', 'Third line']) + exe "normal i\<C-G>u" + call cursor(2, 1) + set cpo-=X + normal 4gro + call assert_equal('oooond line', getline(2)) + undo + set cpo+=X + normal 4gro + call assert_equal('ooooecond line', getline(2)) + let &cpo = save_cpo + enew! +endfunc + +" When splitting a window the changelist position is wrong. +" Test the changelist position after splitting a window. +" Test for the bug fixed by 7.4.386 +func Test_changelist() + let save_ul = &ul + enew! + call append('$', ['1', '2']) + exe "normal i\<C-G>u" + exe "normal Gkylpa\<C-G>u" + set ul=100 + exe "normal Gylpa\<C-G>u" + set ul=100 + normal gg + vsplit + normal g; + call assert_equal([3, 2], [line('.'), col('.')]) + normal g; + call assert_equal([2, 2], [line('.'), col('.')]) + call assert_fails('normal g;', 'E662:') + %bwipe! + let &ul = save_ul +endfunc + +func Test_nv_hat_count() + %bwipeout! + let l:nr = bufnr('%') + 1 + call assert_fails(':execute "normal! ' . l:nr . '\<C-^>"', 'E92') + + edit Xfoo + let l:foo_nr = bufnr('Xfoo') + + edit Xbar + let l:bar_nr = bufnr('Xbar') + + " Make sure we are not just using the alternate file. + edit Xbaz + + call feedkeys(l:foo_nr . "\<C-^>", 'tx') + call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t')) + + call feedkeys(l:bar_nr . "\<C-^>", 'tx') + call assert_equal('Xbar', fnamemodify(bufname('%'), ':t')) + + %bwipeout! +endfunc diff --git a/src/testdir/test_number.vim b/src/testdir/test_number.vim new file mode 100644 index 0000000..415aefc --- /dev/null +++ b/src/testdir/test_number.vim @@ -0,0 +1,254 @@ +" Test for 'number' and 'relativenumber' + +source view_util.vim + +func s:screen_lines(start, end) abort + return ScreenLines([a:start, a:end], 8) +endfunc + +func s:compare_lines(expect, actual) + call assert_equal(a:expect, a:actual) +endfunc + +func s:test_windows(h, w) abort + call NewWindow(a:h, a:w) +endfunc + +func s:close_windows() abort + call CloseWindow() +endfunc + +func s:validate_cursor() abort + " update skipcol. + " wincol(): + " f_wincol + " -> validate_cursor + " -> curs_columns + call wincol() +endfunc + +func Test_set_options() + set nu rnu + call assert_equal(1, &nu) + call assert_equal(1, &rnu) + + call s:test_windows(10, 20) + call assert_equal(1, &nu) + call assert_equal(1, &rnu) + call s:close_windows() + + set nu& rnu& +endfunc + +func Test_set_global_and_local() + " setlocal must NOT reset the other global value + set nonu nornu + setglobal nu + setlocal rnu + call assert_equal(1, &g:nu) + + set nonu nornu + setglobal rnu + setlocal nu + call assert_equal(1, &g:rnu) + + " setglobal MUST reset the other global value + set nonu nornu + setglobal nu + setglobal rnu + call assert_equal(1, &g:nu) + + set nonu nornu + setglobal rnu + setglobal nu + call assert_equal(1, &g:rnu) + + " set MUST reset the other global value + set nonu nornu + set nu + set rnu + call assert_equal(1, &g:nu) + + set nonu nornu + set rnu + set nu + call assert_equal(1, &g:rnu) + + set nu& rnu& +endfunc + +func Test_number() + call s:test_windows(10, 20) + call setline(1, ["abcdefghij", "klmnopqrst", "uvwxyzABCD", "EFGHIJKLMN", "OPQRSTUVWX", "YZ"]) + setl number + let lines = s:screen_lines(1, 4) + let expect = [ +\ " 1 abcd", +\ " 2 klmn", +\ " 3 uvwx", +\ " 4 EFGH", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_relativenumber() + call s:test_windows(10, 20) + call setline(1, ["abcdefghij", "klmnopqrst", "uvwxyzABCD", "EFGHIJKLMN", "OPQRSTUVWX", "YZ"]) + 3 + setl relativenumber + let lines = s:screen_lines(1, 6) + let expect = [ +\ " 2 abcd", +\ " 1 klmn", +\ " 0 uvwx", +\ " 1 EFGH", +\ " 2 OPQR", +\ " 3 YZ ", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_number_with_relativenumber() + call s:test_windows(10, 20) + call setline(1, ["abcdefghij", "klmnopqrst", "uvwxyzABCD", "EFGHIJKLMN", "OPQRSTUVWX", "YZ"]) + 4 + setl number relativenumber + let lines = s:screen_lines(1, 6) + let expect = [ +\ " 3 abcd", +\ " 2 klmn", +\ " 1 uvwx", +\ "4 EFGH", +\ " 1 OPQR", +\ " 2 YZ ", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_number_with_linewrap1() + call s:test_windows(3, 20) + normal! 61ia + setl number wrap + call s:validate_cursor() + let lines = s:screen_lines(1, 3) + let expect = [ +\ "--1 aaaa", +\ " aaaa", +\ " aaaa", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +" Pending: https://groups.google.com/forum/#!topic/vim_dev/tzNKP7EDWYI +func XTest_number_with_linewrap2() + call s:test_windows(3, 20) + normal! 61ia + setl number wrap + call s:validate_cursor() + 0 + call s:validate_cursor() + let lines = s:screen_lines(1, 3) + let expect = [ +\ " 1 aaaa", +\ " aaaa", +\ " aaaa", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +" Pending: https://groups.google.com/forum/#!topic/vim_dev/tzNKP7EDWYI +func XTest_number_with_linewrap3() + call s:test_windows(4, 20) + normal! 81ia + setl number wrap + call s:validate_cursor() + setl nonumber + call s:validate_cursor() + let lines = s:screen_lines(1, 4) + let expect = [ +\ "aaaaaaaa", +\ "aaaaaaaa", +\ "aaaaaaaa", +\ "a ", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_numberwidth() + call s:test_windows(10, 20) + call setline(1, repeat(['aaaa'], 10)) + setl number numberwidth=6 + let lines = s:screen_lines(1, 3) + let expect = [ +\ " 1 aa", +\ " 2 aa", +\ " 3 aa", +\ ] + call s:compare_lines(expect, lines) + + set relativenumber + let lines = s:screen_lines(1, 3) + let expect = [ +\ "1 aa", +\ " 1 aa", +\ " 2 aa", +\ ] + call s:compare_lines(expect, lines) + + set nonumber + let lines = s:screen_lines(1, 3) + let expect = [ +\ " 0 aa", +\ " 1 aa", +\ " 2 aa", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc + +func Test_numberwidth_adjusted() + call s:test_windows(10, 20) + call setline(1, repeat(['aaaa'], 10000)) + setl number numberwidth=4 + let lines = s:screen_lines(1, 3) + let expect = [ +\ " 1 aa", +\ " 2 aa", +\ " 3 aa", +\ ] + call s:compare_lines(expect, lines) + + $ + let lines = s:screen_lines(8, 10) + let expect = [ +\ " 9998 aa", +\ " 9999 aa", +\ "10000 aa", +\ ] + call s:compare_lines(expect, lines) + + setl relativenumber + let lines = s:screen_lines(8, 10) + let expect = [ +\ " 2 aa", +\ " 1 aa", +\ "10000 aa", +\ ] + call s:compare_lines(expect, lines) + + setl nonumber + let lines = s:screen_lines(8, 10) + let expect = [ +\ " 2 aaaa", +\ " 1 aaaa", +\ " 0 aaaa", +\ ] + call s:compare_lines(expect, lines) + call s:close_windows() +endfunc diff --git a/src/testdir/test_options.vim b/src/testdir/test_options.vim new file mode 100644 index 0000000..83b315d --- /dev/null +++ b/src/testdir/test_options.vim @@ -0,0 +1,520 @@ +" Test for options + +func Test_whichwrap() + set whichwrap=b,s + call assert_equal('b,s', &whichwrap) + + set whichwrap+=h,l + call assert_equal('b,s,h,l', &whichwrap) + + set whichwrap+=h,l + call assert_equal('b,s,h,l', &whichwrap) + + set whichwrap+=h,l + call assert_equal('b,s,h,l', &whichwrap) + + set whichwrap=h,h + call assert_equal('h', &whichwrap) + + set whichwrap=h,h,h + call assert_equal('h', &whichwrap) + + set whichwrap& +endfunc + +func Test_isfname() + " This used to cause Vim to access uninitialized memory. + set isfname= + call assert_equal("~X", expand("~X")) + set isfname& +endfunc + +func Test_wildchar() + " Empty 'wildchar' used to access invalid memory. + call assert_fails('set wildchar=', 'E521:') + call assert_fails('set wildchar=abc', 'E521:') + set wildchar=<Esc> + let a=execute('set wildchar?') + call assert_equal("\n wildchar=<Esc>", a) + set wildchar=27 + let a=execute('set wildchar?') + call assert_equal("\n wildchar=<Esc>", a) + set wildchar& +endfunc + +func Test_options() + let caught = 'ok' + try + options + catch + let caught = v:throwpoint . "\n" . v:exception + endtry + call assert_equal('ok', caught) + + " close option-window + close +endfunc + +func Test_path_keep_commas() + " Test that changing 'path' keeps two commas. + set path=foo,,bar + set path-=bar + set path+=bar + call assert_equal('foo,,bar', &path) + + set path& +endfunc + +func Test_signcolumn() + if has('signs') + call assert_equal("auto", &signcolumn) + set signcolumn=yes + set signcolumn=no + call assert_fails('set signcolumn=nope') + endif +endfunc + +func Test_filetype_valid() + set ft=valid_name + call assert_equal("valid_name", &filetype) + set ft=valid-name + call assert_equal("valid-name", &filetype) + + call assert_fails(":set ft=wrong;name", "E474:") + call assert_fails(":set ft=wrong\\\\name", "E474:") + call assert_fails(":set ft=wrong\\|name", "E474:") + call assert_fails(":set ft=wrong/name", "E474:") + call assert_fails(":set ft=wrong\\\nname", "E474:") + call assert_equal("valid-name", &filetype) + + exe "set ft=trunc\x00name" + call assert_equal("trunc", &filetype) +endfunc + +func Test_syntax_valid() + if !has('syntax') + return + endif + set syn=valid_name + call assert_equal("valid_name", &syntax) + set syn=valid-name + call assert_equal("valid-name", &syntax) + + call assert_fails(":set syn=wrong;name", "E474:") + call assert_fails(":set syn=wrong\\\\name", "E474:") + call assert_fails(":set syn=wrong\\|name", "E474:") + call assert_fails(":set syn=wrong/name", "E474:") + call assert_fails(":set syn=wrong\\\nname", "E474:") + call assert_equal("valid-name", &syntax) + + exe "set syn=trunc\x00name" + call assert_equal("trunc", &syntax) +endfunc + +func Test_keymap_valid() + if !has('keymap') + return + endif + call assert_fails(":set kmp=valid_name", "E544:") + call assert_fails(":set kmp=valid_name", "valid_name") + call assert_fails(":set kmp=valid-name", "E544:") + call assert_fails(":set kmp=valid-name", "valid-name") + + call assert_fails(":set kmp=wrong;name", "E474:") + call assert_fails(":set kmp=wrong\\\\name", "E474:") + call assert_fails(":set kmp=wrong\\|name", "E474:") + call assert_fails(":set kmp=wrong/name", "E474:") + call assert_fails(":set kmp=wrong\\\nname", "E474:") + + call assert_fails(":set kmp=trunc\x00name", "E544:") + call assert_fails(":set kmp=trunc\x00name", "trunc") +endfunc + +func Check_dir_option(name) + " Check that it's possible to set the option. + exe 'set ' . a:name . '=/usr/share/dict/words' + call assert_equal('/usr/share/dict/words', eval('&' . a:name)) + exe 'set ' . a:name . '=/usr/share/dict/words,/and/there' + call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name)) + exe 'set ' . a:name . '=/usr/share/dict\ words' + call assert_equal('/usr/share/dict words', eval('&' . a:name)) + + " Check rejecting weird characters. + call assert_fails("set " . a:name . "=/not&there", "E474:") + call assert_fails("set " . a:name . "=/not>there", "E474:") + call assert_fails("set " . a:name . "=/not.*there", "E474:") +endfunc + +func Test_cinkeys() + " This used to cause invalid memory access + set cindent cinkeys=0 + norm a + set cindent& cinkeys& +endfunc + +func Test_dictionary() + call Check_dir_option('dictionary') +endfunc + +func Test_thesaurus() + call Check_dir_option('thesaurus') +endfun + +func Test_complete() + " Trailing single backslash used to cause invalid memory access. + set complete=s\ + new + call feedkeys("i\<C-N>\<Esc>", 'xt') + bwipe! + set complete& +endfun + +func Test_set_completion() + call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:) + + " Expand boolan options. When doing :set no<Tab> + " vim displays the options names without "no" but completion uses "no...". + call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"set nodiff digraph', @:) + + call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"set invdiff digraph', @:) + + " Expand abbreviation of options. + call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"set tabstop thesaurus ttyscroll', @:) + + " Expand current value + call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:) + + call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:) + + " Expand key codes. + call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"set <Help> <Home>', @:) + + " Expand terminal options. + call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"set t_AB t_AF t_AL', @:) + + " Expand directories. + call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_match(' ./samples/ ', @:) + call assert_notmatch(' ./small.vim ', @:) + + " Expand files and directories. + call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_match(' ./samples/.* ./small.vim', @:) + + call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:) +endfunc + +func Test_set_errors() + call assert_fails('set scroll=-1', 'E49:') + call assert_fails('set backupcopy=', 'E474:') + call assert_fails('set regexpengine=3', 'E474:') + call assert_fails('set history=10001', 'E474:') + call assert_fails('set numberwidth=11', 'E474:') + call assert_fails('set colorcolumn=-a') + call assert_fails('set colorcolumn=a') + call assert_fails('set colorcolumn=1,') + call assert_fails('set cmdheight=-1', 'E487:') + call assert_fails('set cmdwinheight=-1', 'E487:') + if has('conceal') + call assert_fails('set conceallevel=-1', 'E487:') + call assert_fails('set conceallevel=4', 'E474:') + endif + call assert_fails('set helpheight=-1', 'E487:') + call assert_fails('set history=-1', 'E487:') + call assert_fails('set report=-1', 'E487:') + call assert_fails('set shiftwidth=-1', 'E487:') + call assert_fails('set sidescroll=-1', 'E487:') + call assert_fails('set tabstop=-1', 'E487:') + call assert_fails('set textwidth=-1', 'E487:') + call assert_fails('set timeoutlen=-1', 'E487:') + call assert_fails('set updatecount=-1', 'E487:') + call assert_fails('set updatetime=-1', 'E487:') + call assert_fails('set winheight=-1', 'E487:') + call assert_fails('set tabstop!', 'E488:') + call assert_fails('set xxx', 'E518:') + call assert_fails('set beautify?', 'E519:') + call assert_fails('set undolevels=x', 'E521:') + call assert_fails('set tabstop=', 'E521:') + call assert_fails('set comments=-', 'E524:') + call assert_fails('set comments=a', 'E525:') + call assert_fails('set foldmarker=x', 'E536:') + call assert_fails('set commentstring=x', 'E537:') + call assert_fails('set complete=x', 'E539:') + call assert_fails('set statusline=%{', 'E540:') + call assert_fails('set statusline=' . repeat("%p", 81), 'E541:') + call assert_fails('set statusline=%(', 'E542:') + if has('cursorshape') + " This invalid value for 'guicursor' used to cause Vim to crash. + call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:') + call assert_fails('set guicursor=i-ci', 'E545:') + call assert_fails('set guicursor=x', 'E545:') + call assert_fails('set guicursor=r-cr:horx', 'E548:') + call assert_fails('set guicursor=r-cr:hor0', 'E549:') + endif + call assert_fails('set backupext=~ patchmode=~', 'E589:') + call assert_fails('set winminheight=10 winheight=9', 'E591:') + call assert_fails('set winminwidth=10 winwidth=9', 'E592:') + call assert_fails("set showbreak=\x01", 'E595:') + call assert_fails('set t_foo=', 'E846:') +endfunc + +" Must be executed before other tests that set 'term'. +func Test_000_term_option_verbose() + if has('gui_running') + return + endif + let verb_cm = execute('verbose set t_cm') + call assert_notmatch('Last set from', verb_cm) + + let term_save = &term + set term=ansi + let verb_cm = execute('verbose set t_cm') + call assert_match('Last set from.*test_options.vim', verb_cm) + let &term = term_save +endfunc + +func Test_set_ttytype() + if !has('gui_running') && has('unix') + " Setting 'ttytype' used to cause a double-free when exiting vim and + " when vim is compiled with -DEXITFREE. + set ttytype=ansi + call assert_equal('ansi', &ttytype) + call assert_equal(&ttytype, &term) + set ttytype=xterm + call assert_equal('xterm', &ttytype) + call assert_equal(&ttytype, &term) + " "set ttytype=" gives E522 instead of E529 + " in travis on some builds. Why? Catch both for now + try + set ttytype= + call assert_report('set ttytype= did not fail') + catch /E529\|E522/ + endtry + + " Some systems accept any terminal name and return dumb settings, + " check for failure of finding the entry and for missing 'cm' entry. + try + set ttytype=xxx + call assert_report('set ttytype=xxx did not fail') + catch /E522\|E437/ + endtry + + set ttytype& + call assert_equal(&ttytype, &term) + endif +endfunc + +func Test_set_all() + set tw=75 + set iskeyword=a-z,A-Z + set nosplitbelow + let out = execute('set all') + call assert_match('textwidth=75', out) + call assert_match('iskeyword=a-z,A-Z', out) + call assert_match('nosplitbelow', out) + set tw& iskeyword& splitbelow& +endfunc + +func Test_set_values() + if filereadable('opt_test.vim') + source opt_test.vim + else + throw 'Skipped: opt_test.vim does not exist' + endif +endfunc + +func ResetIndentexpr() + set indentexpr= +endfunc + +func Test_set_indentexpr() + " this was causing usage of freed memory + set indentexpr=ResetIndentexpr() + new + call feedkeys("i\<c-f>", 'x') + call assert_equal('', &indentexpr) + bwipe! +endfunc + +func Test_backupskip() + " Option 'backupskip' may contain several comma-separated path + " specifications if one or more of the environment variables TMPDIR, TMP, + " or TEMP is defined. To simplify testing, convert the string value into a + " list. + let bsklist = split(&bsk, ',') + + if has("mac") + let found = (index(bsklist, '/private/tmp/*') >= 0) + call assert_true(found, '/private/tmp not in option bsk: ' . &bsk) + elseif has("unix") + let found = (index(bsklist, '/tmp/*') >= 0) + call assert_true(found, '/tmp not in option bsk: ' . &bsk) + endif + + " If our test platform is Windows, the path(s) in option bsk will use + " backslash for the path separator and the components could be in short + " (8.3) format. As such, we need to replace the backslashes with forward + " slashes and convert the path components to long format. The expand() + " function will do this but it cannot handle comma-separated paths. This is + " why bsk was converted from a string into a list of strings above. + " + " One final complication is that the wildcard "/*" is at the end of each + " path and so expand() might return a list of matching files. To prevent + " this, we need to remove the wildcard before calling expand() and then + " append it afterwards. + if has('win32') + let item_nbr = 0 + while item_nbr < len(bsklist) + let path_spec = bsklist[item_nbr] + let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2) + let path_spec = substitute(expand(path_spec), '\\', '/', 'g') + let bsklist[item_nbr] = path_spec . '/*' + let item_nbr += 1 + endwhile + endif + + " Option bsk will also include these environment variables if defined. + " If they're defined, verify they appear in the option value. + for var in ['$TMPDIR', '$TMP', '$TEMP'] + if exists(var) + let varvalue = substitute(expand(var), '\\', '/', 'g') + let varvalue = substitute(varvalue, '/$', '', '') + let varvalue .= '/*' + let found = (index(bsklist, varvalue) >= 0) + call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk) + endif + endfor +endfunc + +func Test_copy_winopt() + set hidden + + " Test copy option from current buffer in window + split + enew + setlocal numberwidth=5 + wincmd w + call assert_equal(4,&numberwidth) + bnext + call assert_equal(5,&numberwidth) + bw! + call assert_equal(4,&numberwidth) + + " Test copy value from window that used to be display the buffer + split + enew + setlocal numberwidth=6 + bnext + wincmd w + call assert_equal(4,&numberwidth) + bnext + call assert_equal(6,&numberwidth) + bw! + + " Test that if buffer is current, don't use the stale cached value + " from the last time the buffer was displayed. + split + enew + setlocal numberwidth=7 + bnext + bnext + setlocal numberwidth=8 + wincmd w + call assert_equal(4,&numberwidth) + bnext + call assert_equal(8,&numberwidth) + bw! + + " Test value is not copied if window already has seen the buffer + enew + split + setlocal numberwidth=9 + bnext + setlocal numberwidth=10 + wincmd w + call assert_equal(4,&numberwidth) + bnext + call assert_equal(4,&numberwidth) + bw! + + set hidden& +endfunc + +func Test_shortmess_F() + new + call assert_match('\[No Name\]', execute('file')) + set shortmess+=F + call assert_match('\[No Name\]', execute('file')) + call assert_match('^\s*$', execute('file foo')) + call assert_match('foo', execute('file')) + set shortmess-=F + call assert_match('bar', execute('file bar')) + call assert_match('bar', execute('file')) + set shortmess& + bwipe +endfunc + +func Test_shortmess_F2() + e file1 + e file2 + call assert_match('file1', execute('bn', '')) + call assert_match('file2', execute('bn', '')) + set shortmess+=F + call assert_true(empty(execute('bn', ''))) + call assert_true(empty(execute('bn', ''))) + set hidden + call assert_true(empty(execute('bn', ''))) + call assert_true(empty(execute('bn', ''))) + set nohidden + call assert_true(empty(execute('bn', ''))) + call assert_true(empty(execute('bn', ''))) + set shortmess& + call assert_match('file1', execute('bn', '')) + call assert_match('file2', execute('bn', '')) + bwipe + bwipe +endfunc + +func Test_local_scrolloff() + set so=5 + set siso=7 + split + call assert_equal(5, &so) + setlocal so=3 + call assert_equal(3, &so) + wincmd w + call assert_equal(5, &so) + wincmd w + setlocal so< + call assert_equal(5, &so) + setlocal so=0 + call assert_equal(0, &so) + setlocal so=-1 + call assert_equal(5, &so) + + call assert_equal(7, &siso) + setlocal siso=3 + call assert_equal(3, &siso) + wincmd w + call assert_equal(7, &siso) + wincmd w + setlocal siso< + call assert_equal(7, &siso) + setlocal siso=0 + call assert_equal(0, &siso) + setlocal siso=-1 + call assert_equal(7, &siso) + + close + set so& + set siso& +endfunc diff --git a/src/testdir/test_packadd.vim b/src/testdir/test_packadd.vim new file mode 100644 index 0000000..6d0565b --- /dev/null +++ b/src/testdir/test_packadd.vim @@ -0,0 +1,357 @@ +" Tests for 'packpath' and :packadd + + +func SetUp() + let s:topdir = getcwd() . '/Xdir' + exe 'set packpath=' . s:topdir + let s:plugdir = s:topdir . '/pack/mine/opt/mytest' +endfunc + +func TearDown() + call delete(s:topdir, 'rf') +endfunc + +func Test_packadd() + if !exists('s:plugdir') + echomsg 'when running this test manually, call SetUp() first' + return + endif + + call mkdir(s:plugdir . '/plugin/also', 'p') + call mkdir(s:plugdir . '/ftdetect', 'p') + call mkdir(s:plugdir . '/after', 'p') + set rtp& + let rtp = &rtp + filetype on + + let rtp_entries = split(rtp, ',') + for entry in rtp_entries + if entry =~? '\<after\>' + let first_after_entry = entry + break + endif + endfor + + exe 'split ' . s:plugdir . '/plugin/test.vim' + call setline(1, 'let g:plugin_works = 42') + wq + + exe 'split ' . s:plugdir . '/plugin/also/loaded.vim' + call setline(1, 'let g:plugin_also_works = 77') + wq + + exe 'split ' . s:plugdir . '/ftdetect/test.vim' + call setline(1, 'let g:ftdetect_works = 17') + wq + + packadd mytest + + call assert_equal(42, g:plugin_works) + call assert_equal(77, g:plugin_also_works) + call assert_equal(17, g:ftdetect_works) + call assert_true(len(&rtp) > len(rtp)) + call assert_match('/testdir/Xdir/pack/mine/opt/mytest\($\|,\)', &rtp) + + let new_after = match(&rtp, '/testdir/Xdir/pack/mine/opt/mytest/after,') + let forwarded = substitute(first_after_entry, '\\', '[/\\\\]', 'g') + let old_after = match(&rtp, ',' . forwarded . '\>') + call assert_true(new_after > 0, 'rtp is ' . &rtp) + call assert_true(old_after > 0, 'match ' . forwarded . ' in ' . &rtp) + call assert_true(new_after < old_after, 'rtp is ' . &rtp) + + " NOTE: '/.../opt/myte' forwardly matches with '/.../opt/mytest' + call mkdir(fnamemodify(s:plugdir, ':h') . '/myte', 'p') + let rtp = &rtp + packadd myte + + " Check the path of 'myte' is added + call assert_true(len(&rtp) > len(rtp)) + call assert_match('/testdir/Xdir/pack/mine/opt/myte\($\|,\)', &rtp) + + " Check exception + call assert_fails("packadd directorynotfound", 'E919:') + call assert_fails("packadd", 'E471:') +endfunc + +func Test_packadd_start() + let plugdir = s:topdir . '/pack/mine/start/other' + call mkdir(plugdir . '/plugin', 'p') + set rtp& + let rtp = &rtp + filetype on + + exe 'split ' . plugdir . '/plugin/test.vim' + call setline(1, 'let g:plugin_works = 24') + wq + + packadd other + + call assert_equal(24, g:plugin_works) + call assert_true(len(&rtp) > len(rtp)) + call assert_match('/testdir/Xdir/pack/mine/start/other\($\|,\)', &rtp) +endfunc + +func Test_packadd_noload() + call mkdir(s:plugdir . '/plugin', 'p') + call mkdir(s:plugdir . '/syntax', 'p') + set rtp& + let rtp = &rtp + + exe 'split ' . s:plugdir . '/plugin/test.vim' + call setline(1, 'let g:plugin_works = 42') + wq + let g:plugin_works = 0 + + packadd! mytest + + call assert_true(len(&rtp) > len(rtp)) + call assert_match('testdir/Xdir/pack/mine/opt/mytest\($\|,\)', &rtp) + call assert_equal(0, g:plugin_works) + + " check the path is not added twice + let new_rtp = &rtp + packadd! mytest + call assert_equal(new_rtp, &rtp) +endfunc + +func Test_packadd_symlink_dir() + if !has('unix') + return + endif + let top2_dir = s:topdir . '/Xdir2' + let real_dir = s:topdir . '/Xsym' + call mkdir(real_dir, 'p') + exec "silent !ln -s Xsym" top2_dir + let &rtp = top2_dir . ',' . top2_dir . '/after' + let &packpath = &rtp + + let s:plugdir = top2_dir . '/pack/mine/opt/mytest' + call mkdir(s:plugdir . '/plugin', 'p') + + exe 'split ' . s:plugdir . '/plugin/test.vim' + call setline(1, 'let g:plugin_works = 44') + wq + let g:plugin_works = 0 + + packadd mytest + + " Must have been inserted in the middle, not at the end + call assert_match('/pack/mine/opt/mytest,', &rtp) + call assert_equal(44, g:plugin_works) + + " No change when doing it again. + let rtp_before = &rtp + packadd mytest + call assert_equal(rtp_before, &rtp) + + set rtp& + let rtp = &rtp + exec "silent !rm" top2_dir +endfunc + +func Test_packadd_symlink_dir2() + if !has('unix') + return + endif + let top2_dir = s:topdir . '/Xdir2' + let real_dir = s:topdir . '/Xsym/pack' + call mkdir(top2_dir, 'p') + call mkdir(real_dir, 'p') + let &rtp = top2_dir . ',' . top2_dir . '/after' + let &packpath = &rtp + + exec "silent !ln -s ../Xsym/pack" top2_dir . '/pack' + let s:plugdir = top2_dir . '/pack/mine/opt/mytest' + call mkdir(s:plugdir . '/plugin', 'p') + + exe 'split ' . s:plugdir . '/plugin/test.vim' + call setline(1, 'let g:plugin_works = 48') + wq + let g:plugin_works = 0 + + packadd mytest + + " Must have been inserted in the middle, not at the end + call assert_match('/Xdir2/pack/mine/opt/mytest,', &rtp) + call assert_equal(48, g:plugin_works) + + " No change when doing it again. + let rtp_before = &rtp + packadd mytest + call assert_equal(rtp_before, &rtp) + + set rtp& + let rtp = &rtp + exec "silent !rm" top2_dir . '/pack' + exec "silent !rmdir" top2_dir +endfunc + +" Check command-line completion for 'packadd' +func Test_packadd_completion() + let optdir1 = &packpath . '/pack/mine/opt' + let optdir2 = &packpath . '/pack/candidate/opt' + + call mkdir(optdir1 . '/pluginA', 'p') + call mkdir(optdir1 . '/pluginC', 'p') + call mkdir(optdir2 . '/pluginB', 'p') + call mkdir(optdir2 . '/pluginC', 'p') + + let li = [] + call feedkeys(":packadd \<Tab>')\<C-B>call add(li, '\<CR>", 't') + call feedkeys(":packadd " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't') + call feedkeys(":packadd " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't') + call feedkeys(":packadd " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx') + call assert_equal("packadd pluginA", li[0]) + call assert_equal("packadd pluginB", li[1]) + call assert_equal("packadd pluginC", li[2]) + call assert_equal("packadd ", li[3]) +endfunc + +func Test_packloadall() + " plugin foo with an autoload directory + let fooplugindir = &packpath . '/pack/mine/start/foo/plugin' + call mkdir(fooplugindir, 'p') + call writefile(['let g:plugin_foo_number = 1234', + \ 'let g:plugin_foo_auto = bbb#value', + \ 'let g:plugin_extra_auto = extra#value'], fooplugindir . '/bar.vim') + let fooautodir = &packpath . '/pack/mine/start/foo/autoload' + call mkdir(fooautodir, 'p') + call writefile(['let bar#value = 77'], fooautodir . '/bar.vim') + + " plugin aaa with an autoload directory + let aaaplugindir = &packpath . '/pack/mine/start/aaa/plugin' + call mkdir(aaaplugindir, 'p') + call writefile(['let g:plugin_aaa_number = 333', + \ 'let g:plugin_aaa_auto = bar#value'], aaaplugindir . '/bbb.vim') + let aaaautodir = &packpath . '/pack/mine/start/aaa/autoload' + call mkdir(aaaautodir, 'p') + call writefile(['let bbb#value = 55'], aaaautodir . '/bbb.vim') + + " plugin extra with only an autoload directory + let extraautodir = &packpath . '/pack/mine/start/extra/autoload' + call mkdir(extraautodir, 'p') + call writefile(['let extra#value = 99'], extraautodir . '/extra.vim') + + packloadall + call assert_equal(1234, g:plugin_foo_number) + call assert_equal(55, g:plugin_foo_auto) + call assert_equal(99, g:plugin_extra_auto) + call assert_equal(333, g:plugin_aaa_number) + call assert_equal(77, g:plugin_aaa_auto) + + " only works once + call writefile(['let g:plugin_bar_number = 4321'], fooplugindir . '/bar2.vim') + packloadall + call assert_false(exists('g:plugin_bar_number')) + + " works when ! used + packloadall! + call assert_equal(4321, g:plugin_bar_number) +endfunc + +func Test_helptags() + let docdir1 = &packpath . '/pack/mine/start/foo/doc' + let docdir2 = &packpath . '/pack/mine/start/bar/doc' + call mkdir(docdir1, 'p') + call mkdir(docdir2, 'p') + call writefile(['look here: *look-here*'], docdir1 . '/bar.txt') + call writefile(['look away: *look-away*'], docdir2 . '/foo.txt') + exe 'set rtp=' . &packpath . '/pack/mine/start/foo,' . &packpath . '/pack/mine/start/bar' + + helptags ALL + + let tags1 = readfile(docdir1 . '/tags') + call assert_match('look-here', tags1[0]) + let tags2 = readfile(docdir2 . '/tags') + call assert_match('look-away', tags2[0]) +endfunc + +func Test_colorscheme() + let colordirrun = &packpath . '/runtime/colors' + let colordirstart = &packpath . '/pack/mine/start/foo/colors' + let colordiropt = &packpath . '/pack/mine/opt/bar/colors' + call mkdir(colordirrun, 'p') + call mkdir(colordirstart, 'p') + call mkdir(colordiropt, 'p') + call writefile(['let g:found_one = 1'], colordirrun . '/one.vim') + call writefile(['let g:found_two = 1'], colordirstart . '/two.vim') + call writefile(['let g:found_three = 1'], colordiropt . '/three.vim') + exe 'set rtp=' . &packpath . '/runtime' + + colorscheme one + call assert_equal(1, g:found_one) + colorscheme two + call assert_equal(1, g:found_two) + colorscheme three + call assert_equal(1, g:found_three) +endfunc + +func Test_colorscheme_completion() + let colordirrun = &packpath . '/runtime/colors' + let colordirstart = &packpath . '/pack/mine/start/foo/colors' + let colordiropt = &packpath . '/pack/mine/opt/bar/colors' + call mkdir(colordirrun, 'p') + call mkdir(colordirstart, 'p') + call mkdir(colordiropt, 'p') + call writefile(['let g:found_one = 1'], colordirrun . '/one.vim') + call writefile(['let g:found_two = 1'], colordirstart . '/two.vim') + call writefile(['let g:found_three = 1'], colordiropt . '/three.vim') + exe 'set rtp=' . &packpath . '/runtime' + + let li=[] + call feedkeys(":colorscheme " . repeat("\<Tab>", 1) . "')\<C-B>call add(li, '\<CR>", 't') + call feedkeys(":colorscheme " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't') + call feedkeys(":colorscheme " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't') + call feedkeys(":colorscheme " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx') + call assert_equal("colorscheme one", li[0]) + call assert_equal("colorscheme three", li[1]) + call assert_equal("colorscheme two", li[2]) + call assert_equal("colorscheme ", li[3]) +endfunc + +func Test_runtime() + let rundir = &packpath . '/runtime/extra' + let startdir = &packpath . '/pack/mine/start/foo/extra' + let optdir = &packpath . '/pack/mine/opt/bar/extra' + call mkdir(rundir, 'p') + call mkdir(startdir, 'p') + call mkdir(optdir, 'p') + call writefile(['let g:sequence .= "run"'], rundir . '/bar.vim') + call writefile(['let g:sequence .= "start"'], startdir . '/bar.vim') + call writefile(['let g:sequence .= "foostart"'], startdir . '/foo.vim') + call writefile(['let g:sequence .= "opt"'], optdir . '/bar.vim') + call writefile(['let g:sequence .= "xxxopt"'], optdir . '/xxx.vim') + exe 'set rtp=' . &packpath . '/runtime' + + let g:sequence = '' + runtime extra/bar.vim + call assert_equal('run', g:sequence) + let g:sequence = '' + runtime START extra/bar.vim + call assert_equal('start', g:sequence) + let g:sequence = '' + runtime OPT extra/bar.vim + call assert_equal('opt', g:sequence) + let g:sequence = '' + runtime PACK extra/bar.vim + call assert_equal('start', g:sequence) + let g:sequence = '' + runtime! PACK extra/bar.vim + call assert_equal('startopt', g:sequence) + let g:sequence = '' + runtime PACK extra/xxx.vim + call assert_equal('xxxopt', g:sequence) + + let g:sequence = '' + runtime ALL extra/bar.vim + call assert_equal('run', g:sequence) + let g:sequence = '' + runtime ALL extra/foo.vim + call assert_equal('foostart', g:sequence) + let g:sequence = '' + runtime! ALL extra/xxx.vim + call assert_equal('xxxopt', g:sequence) + let g:sequence = '' + runtime! ALL extra/bar.vim + call assert_equal('runstartopt', g:sequence) +endfunc diff --git a/src/testdir/test_partial.vim b/src/testdir/test_partial.vim new file mode 100644 index 0000000..b180510 --- /dev/null +++ b/src/testdir/test_partial.vim @@ -0,0 +1,386 @@ +" Test binding arguments to a Funcref. + +func MyFunc(arg1, arg2, arg3) + return a:arg1 . '/' . a:arg2 . '/' . a:arg3 +endfunc + +func MySort(up, one, two) + if a:one == a:two + return 0 + endif + if a:up + return a:one > a:two ? 1 : -1 + endif + return a:one < a:two ? 1 : -1 +endfunc + +func MyMap(sub, index, val) + return a:val - a:sub +endfunc + +func MyFilter(threshold, index, val) + return a:val > a:threshold +endfunc + +func Test_partial_args() + let Cb = function('MyFunc', ["foo", "bar"]) + + call Cb("zzz") + call assert_equal("foo/bar/xxx", Cb("xxx")) + call assert_equal("foo/bar/yyy", call(Cb, ["yyy"])) + let Cb2 = function(Cb) + call assert_equal("foo/bar/zzz", Cb2("zzz")) + let Cb3 = function(Cb, ["www"]) + call assert_equal("foo/bar/www", Cb3()) + + let Cb = function('MyFunc', []) + call assert_equal("a/b/c", Cb("a", "b", "c")) + let Cb2 = function(Cb, []) + call assert_equal("a/b/d", Cb2("a", "b", "d")) + let Cb3 = function(Cb, ["a", "b"]) + call assert_equal("a/b/e", Cb3("e")) + + let Sort = function('MySort', [1]) + call assert_equal([1, 2, 3], sort([3, 1, 2], Sort)) + let Sort = function('MySort', [0]) + call assert_equal([3, 2, 1], sort([3, 1, 2], Sort)) + + let Map = function('MyMap', [2]) + call assert_equal([-1, 0, 1], map([1, 2, 3], Map)) + let Map = function('MyMap', [3]) + call assert_equal([-2, -1, 0], map([1, 2, 3], Map)) + + let Filter = function('MyFilter', [1]) + call assert_equal([2, 3], filter([1, 2, 3], Filter)) + let Filter = function('MyFilter', [2]) + call assert_equal([3], filter([1, 2, 3], Filter)) +endfunc + +func MyDictFunc(arg1, arg2) dict + return self.name . '/' . a:arg1 . '/' . a:arg2 +endfunc + +func Test_partial_dict() + let dict = {'name': 'hello'} + let Cb = function('MyDictFunc', ["foo", "bar"], dict) + call assert_equal("hello/foo/bar", Cb()) + call assert_fails('Cb("xxx")', 'E492:') + + let Cb = function('MyDictFunc', ["foo"], dict) + call assert_equal("hello/foo/xxx", Cb("xxx")) + call assert_fails('Cb()', 'E492:') + + let Cb = function('MyDictFunc', [], dict) + call assert_equal("hello/ttt/xxx", Cb("ttt", "xxx")) + call assert_fails('Cb("yyy")', 'E492:') + + let Cb = function('MyDictFunc', dict) + call assert_equal("hello/xxx/yyy", Cb("xxx", "yyy")) + call assert_fails('Cb("fff")', 'E492:') + + let Cb = function('MyDictFunc', dict) + call assert_equal({"foo": "hello/foo/1", "bar": "hello/bar/2"}, map({"foo": 1, "bar": 2}, Cb)) + + let dict = {"tr": function('tr', ['hello', 'h', 'H'])} + call assert_equal("Hello", dict.tr()) +endfunc + +func Test_partial_implicit() + let dict = {'name': 'foo'} + func dict.MyFunc(arg) dict + return self.name . '/' . a:arg + endfunc + + call assert_equal('foo/bar', dict.MyFunc('bar')) + + call assert_fails('let func = dict.MyFunc', 'E704:') + let Func = dict.MyFunc + call assert_equal('foo/aaa', Func('aaa')) + + let Func = function(dict.MyFunc, ['bbb']) + call assert_equal('foo/bbb', Func()) +endfunc + +fun InnerCall(funcref) + return a:funcref +endfu + +fun OuterCall() + let opt = { 'func' : function('sin') } + call InnerCall(opt.func) +endfu + +func Test_function_in_dict() + call OuterCall() +endfunc + +func s:cache_clear() dict + return self.name +endfunc + +func Test_script_function_in_dict() + let s:obj = {'name': 'foo'} + let s:obj2 = {'name': 'bar'} + + let s:obj['clear'] = function('s:cache_clear') + + call assert_equal('foo', s:obj.clear()) + let F = s:obj.clear + call assert_equal('foo', F()) + call assert_equal('foo', call(s:obj.clear, [], s:obj)) + call assert_equal('bar', call(s:obj.clear, [], s:obj2)) + + let s:obj2['clear'] = function('s:cache_clear') + call assert_equal('bar', s:obj2.clear()) + let B = s:obj2.clear + call assert_equal('bar', B()) +endfunc + +func s:cache_arg(arg) dict + let s:result = self.name . '/' . a:arg + return s:result +endfunc + +func Test_script_function_in_dict_arg() + let s:obj = {'name': 'foo'} + let s:obj['clear'] = function('s:cache_arg') + + call assert_equal('foo/bar', s:obj.clear('bar')) + let F = s:obj.clear + let s:result = '' + call assert_equal('foo/bar', F('bar')) + call assert_equal('foo/bar', s:result) + + let s:obj['clear'] = function('s:cache_arg', ['bar']) + call assert_equal('foo/bar', s:obj.clear()) + let s:result = '' + call s:obj.clear() + call assert_equal('foo/bar', s:result) + + let F = s:obj.clear + call assert_equal('foo/bar', F()) + let s:result = '' + call F() + call assert_equal('foo/bar', s:result) + + call assert_equal('foo/bar', call(s:obj.clear, [], s:obj)) +endfunc + +func Test_partial_exists() + let F = function('MyFunc') + call assert_true(exists('*F')) + let lF = [F] + call assert_true(exists('*lF[0]')) + + let F = function('MyFunc', ['arg']) + call assert_true(exists('*F')) + let lF = [F] + call assert_true(exists('*lF[0]')) +endfunc + +func Test_partial_string() + let F = function('MyFunc') + call assert_equal("function('MyFunc')", string(F)) + let F = function('MyFunc', ['foo']) + call assert_equal("function('MyFunc', ['foo'])", string(F)) + let F = function('MyFunc', ['foo', 'bar']) + call assert_equal("function('MyFunc', ['foo', 'bar'])", string(F)) + let d = {'one': 1} + let F = function('MyFunc', d) + call assert_equal("function('MyFunc', {'one': 1})", string(F)) + let F = function('MyFunc', ['foo'], d) + call assert_equal("function('MyFunc', ['foo'], {'one': 1})", string(F)) +endfunc + +func Test_func_unref() + let obj = {} + function! obj.func() abort + endfunction + let funcnumber = matchstr(string(obj.func), '^function(''\zs.\{-}\ze''') + call assert_true(exists('*{' . funcnumber . '}')) + unlet obj + call assert_false(exists('*{' . funcnumber . '}')) +endfunc + +func Test_tostring() + let d = {} + let d.d = d + function d.test3() + echo 42 + endfunction + try + call string(d.test3) + catch + call assert_true(v:false, v:exception) + endtry +endfunc + +func Test_redefine_dict_func() + let d = {} + function d.test4() + endfunction + let d.test4 = d.test4 + try + function! d.test4(name) + endfunction + catch + call assert_true(v:errmsg, v:exception) + endtry +endfunc + +func Test_bind_in_python() + if has('python') + let g:d = {} + function g:d.test2() + endfunction + python import vim + try + call assert_equal(pyeval('vim.bindeval("g:d.test2")'), g:d.test2) + catch + call assert_true(v:false, v:exception) + endtry + endif +endfunc + +" This caused double free on exit if EXITFREE is defined. +func Test_cyclic_list_arg() + let l = [] + let Pt = function('string', [l]) + call add(l, Pt) + unlet l + unlet Pt +endfunc + +" This caused double free on exit if EXITFREE is defined. +func Test_cyclic_dict_arg() + let d = {} + let Pt = function('string', [d]) + let d.Pt = Pt + unlet d + unlet Pt +endfunc + +func Ignored3(job1, job2, status) +endfunc + +func Test_cycle_partial_job() + if has('job') + let job = job_start('echo') + call job_setoptions(job, {'exit_cb': function('Ignored3', [job])}) + unlet job + endif +endfunc + +func Ignored2(job, status) +endfunc + +func Test_ref_job_partial_dict() + if has('job') + let g:ref_job = job_start('echo') + let d = {'a': 'b'} + call job_setoptions(g:ref_job, {'exit_cb': function('Ignored2', [], d)}) + endif +endfunc + +func Test_auto_partial_rebind() + let dict1 = {'name': 'dict1'} + func! dict1.f1() + return self.name + endfunc + let dict1.f2 = function(dict1.f1, dict1) + + call assert_equal('dict1', dict1.f1()) + call assert_equal('dict1', dict1['f1']()) + call assert_equal('dict1', dict1.f2()) + call assert_equal('dict1', dict1['f2']()) + + let dict2 = {'name': 'dict2'} + let dict2.f1 = dict1.f1 + let dict2.f2 = dict1.f2 + + call assert_equal('dict2', dict2.f1()) + call assert_equal('dict2', dict2['f1']()) + call assert_equal('dict1', dict2.f2()) + call assert_equal('dict1', dict2['f2']()) +endfunc + +func Test_get_partial_items() + let dict = {'name': 'hello'} + let args = ["foo", "bar"] + let Func = function('MyDictFunc') + let Cb = function('MyDictFunc', args, dict) + + call assert_equal(Func, get(Cb, 'func')) + call assert_equal('MyDictFunc', get(Cb, 'name')) + call assert_equal(args, get(Cb, 'args')) + call assert_equal(dict, get(Cb, 'dict')) + call assert_fails('call get(Cb, "xxx")', 'E475:') + + call assert_equal(Func, get(Func, 'func')) + call assert_equal('MyDictFunc', get(Func, 'name')) + call assert_equal([], get(Func, 'args')) + call assert_true(empty( get(Func, 'dict'))) +endfunc + +func Test_compare_partials() + let d1 = {} + let d2 = {} + + function d1.f1() dict + endfunction + + function d1.f2() dict + endfunction + + let F1 = get(d1, 'f1') + let F2 = get(d1, 'f2') + + let F1d1 = function(F1, d1) + let F2d1 = function(F2, d2) + let F1d1a1 = function(F1d1, [1]) + let F1d1a12 = function(F1d1, [1, 2]) + let F1a1 = function(F1, [1]) + let F1a2 = function(F1, [2]) + let F1d2 = function(F1, d2) + let d3 = {'f1': F1, 'f2': F2} + let F1d3 = function(F1, d3) + let F1ad1 = function(F1, [d1]) + let F1ad3 = function(F1, [d3]) + + call assert_match('^function(''\d\+'')$', string(F1)) " Not a partial + call assert_match('^function(''\d\+'')$', string(F2)) " Not a partial + call assert_match('^function(''\d\+'', {.*})$', string(F1d1)) " A partial + call assert_match('^function(''\d\+'', {.*})$', string(F2d1)) " A partial + call assert_match('^function(''\d\+'', \[.*\])$', string(F1a1)) " No dict + + " != + let X = F1 + call assert_false(F1 != X) " same function + let X = F1d1 + call assert_false(F1d1 != X) " same partial + let X = F1d1a1 + call assert_false(F1d1a1 != X) " same partial + let X = F1a1 + call assert_false(F1a1 != X) " same partial + + call assert_true(F1 != F2) " Different functions + call assert_true(F1 != F1d1) " Partial /= non-partial + call assert_true(F1d1a1 != F1d1a12) " Different number of arguments + call assert_true(F1a1 != F1d1a12) " One has no dict + call assert_true(F1a1 != F1a2) " Different arguments + call assert_true(F1d2 != F1d1) " Different dictionaries + call assert_false(F1d1 != F1d3) " Equal dictionaries, even though d1 isnot d3 + + " isnot, option 1 + call assert_true(F1 isnot# F2) " Different functions + call assert_true(F1 isnot# F1d1) " Partial /= non-partial + call assert_true(F1d1 isnot# F1d3) " d1 isnot d3, even though d1 == d3 + call assert_true(F1a1 isnot# F1d1a12) " One has no dict + call assert_true(F1a1 isnot# F1a2) " Different number of arguments + call assert_true(F1ad1 isnot# F1ad3) " In arguments d1 isnot d3 + + " isnot, option 2 + call assert_true(F1 isnot# F2) " Different functions + call assert_true(F1 isnot# F1d1) " Partial /= non-partial + call assert_true(d1.f1 isnot# d1.f1) " handle_subscript creates new partial each time +endfunc diff --git a/src/testdir/test_paste.vim b/src/testdir/test_paste.vim new file mode 100644 index 0000000..65f300c --- /dev/null +++ b/src/testdir/test_paste.vim @@ -0,0 +1,112 @@ +" Tests for bracketed paste and other forms of pasting. + +" Bracketed paste only works with "xterm". Not in GUI. +if has('gui_running') + finish +endif +set term=xterm + +source shared.vim + +func Test_paste_normal_mode() + new + " In first column text is inserted + call setline(1, ['a', 'b', 'c']) + call cursor(2, 1) + call feedkeys("\<Esc>[200~foo\<CR>bar\<Esc>[201~", 'xt') + call assert_equal('foo', getline(2)) + call assert_equal('barb', getline(3)) + call assert_equal('c', getline(4)) + + " When repeating text is appended + normal . + call assert_equal('barfoo', getline(3)) + call assert_equal('barb', getline(4)) + call assert_equal('c', getline(5)) + bwipe! + + " In second column text is appended + call setline(1, ['a', 'bbb', 'c']) + call cursor(2, 2) + call feedkeys("\<Esc>[200~foo\<CR>bar\<Esc>[201~", 'xt') + call assert_equal('bbfoo', getline(2)) + call assert_equal('barb', getline(3)) + call assert_equal('c', getline(4)) + + " In last column text is appended + call setline(1, ['a', 'bbb', 'c']) + call cursor(2, 3) + call feedkeys("\<Esc>[200~foo\<CR>bar\<Esc>[201~", 'xt') + call assert_equal('bbbfoo', getline(2)) + call assert_equal('bar', getline(3)) + call assert_equal('c', getline(4)) +endfunc + +func Test_paste_insert_mode() + new + call setline(1, ['a', 'b', 'c']) + 2 + call feedkeys("i\<Esc>[200~foo\<CR>bar\<Esc>[201~ done\<Esc>", 'xt') + call assert_equal('foo', getline(2)) + call assert_equal('bar doneb', getline(3)) + call assert_equal('c', getline(4)) + + normal . + call assert_equal('bar donfoo', getline(3)) + call assert_equal('bar doneeb', getline(4)) + call assert_equal('c', getline(5)) + + set ai et tw=10 + call setline(1, ['a', ' b', 'c']) + 2 + call feedkeys("A\<Esc>[200~foo\<CR> bar bar bar\<Esc>[201~\<Esc>", 'xt') + call assert_equal(' bfoo', getline(2)) + call assert_equal(' bar bar bar', getline(3)) + call assert_equal('c', getline(4)) + + set ai& et& tw=0 + bwipe! +endfunc + +func Test_paste_clipboard() + if !WorkingClipboard() + return + endif + let @+ = "nasty\<Esc>:!ls\<CR>command" + new + exe "normal i\<C-R>+\<Esc>" + call assert_equal("nasty\<Esc>:!ls\<CR>command", getline(1)) + bwipe! +endfunc + +func Test_paste_cmdline() + call feedkeys(":a\<Esc>[200~foo\<CR>bar\<Esc>[201~b\<Home>\"\<CR>", 'xt') + call assert_equal("\"afoo\<CR>barb", getreg(':')) +endfunc + +func Test_paste_visual_mode() + new + call setline(1, 'here are some words') + call feedkeys("0fsve\<Esc>[200~more\<Esc>[201~", 'xt') + call assert_equal('here are more words', getline(1)) + call assert_equal('some', getreg('-')) + + " include last char in the line + call feedkeys("0fwve\<Esc>[200~noises\<Esc>[201~", 'xt') + call assert_equal('here are more noises', getline(1)) + call assert_equal('words', getreg('-')) + + " exclude last char in the line + call setline(1, 'some words!') + call feedkeys("0fwve\<Esc>[200~noises\<Esc>[201~", 'xt') + call assert_equal('some noises!', getline(1)) + call assert_equal('words', getreg('-')) + + " multi-line selection + call setline(1, ['some words', 'and more']) + call feedkeys("0fwvj0fd\<Esc>[200~letters\<Esc>[201~", 'xt') + call assert_equal('some letters more', getline(1)) + call assert_equal("words\nand", getreg('1')) + + bwipe! +endfunc diff --git a/src/testdir/test_perl.vim b/src/testdir/test_perl.vim new file mode 100644 index 0000000..03c5fa0 --- /dev/null +++ b/src/testdir/test_perl.vim @@ -0,0 +1,286 @@ +" Tests for Perl interface + +if !has('perl') + finish +end + +" FIXME: RunTest don't see any error when Perl abort... +perl $SIG{__WARN__} = sub { die "Unexpected warnings from perl: @_" }; + +func Test_change_buffer() + call setline(line('$'), ['1 line 1']) + perl VIM::DoCommand("normal /^1\n") + perl $curline = VIM::Eval("line('.')") + perl $curbuf->Set($curline, "1 changed line 1") + call assert_equal('1 changed line 1', getline('$')) +endfunc + +func Test_evaluate_list() + call setline(line('$'), ['2 line 2']) + perl VIM::DoCommand("normal /^2\n") + perl $curline = VIM::Eval("line('.')") + let l = ["abc", "def"] + perl << EOF + $l = VIM::Eval("l"); + $curbuf->Append($curline, $l); +EOF + normal j + .perldo s|\n|/|g + call assert_equal('abc/def/', getline('$')) +endfunc + +func Test_buffer_Delete() + new + call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']) + perl $curbuf->Delete(7) + perl $curbuf->Delete(2, 5) + perl $curbuf->Delete(10) + call assert_equal(['a', 'f', 'h'], getline(1, '$')) + bwipe! +endfunc + +func Test_buffer_Append() + new + perl $curbuf->Append(1, '1') + perl $curbuf->Append(2, '2', '3', '4') + perl @l = ('5' ..'7') + perl $curbuf->Append(0, @l) + call assert_equal(['5', '6', '7', '', '1', '2', '3', '4'], getline(1, '$')) + bwipe! +endfunc + +func Test_buffer_Set() + new + call setline(1, ['1', '2', '3', '4', '5']) + perl $curbuf->Set(2, 'a', 'b', 'c') + perl $curbuf->Set(4, 'A', 'B', 'C') + call assert_equal(['1', 'a', 'b', 'A', 'B'], getline(1, '$')) + bwipe! +endfunc + +func Test_buffer_Get() + new + call setline(1, ['1', '2', '3', '4']) + call assert_equal('2:3', perleval('join(":", $curbuf->Get(2, 3))')) + bwipe! +endfunc + +func Test_buffer_Count() + new + call setline(1, ['a', 'b', 'c']) + call assert_equal(3, perleval('$curbuf->Count()')) + bwipe! +endfunc + +func Test_buffer_Name() + new + call assert_equal('', perleval('$curbuf->Name()')) + bwipe! + new Xfoo + call assert_equal('Xfoo', perleval('$curbuf->Name()')) + bwipe! +endfunc + +func Test_buffer_Number() + call assert_equal(bufnr('%'), perleval('$curbuf->Number()')) +endfunc + +func Test_window_Cursor() + new + call setline(1, ['line1', 'line2']) + perl $curwin->Cursor(2, 3) + call assert_equal('2:3', perleval('join(":", $curwin->Cursor())')) + " Col is numbered from 0 in Perl, and from 1 in Vim script. + call assert_equal([0, 2, 4, 0], getpos('.')) + bwipe! +endfunc + +func Test_window_SetHeight() + new + perl $curwin->SetHeight(2) + call assert_equal(2, winheight(0)) + bwipe! +endfunc + +func Test_VIM_Windows() + new + " VIM::Windows() without argument in scalar and list context. + perl $winnr = VIM::Windows() + perl @winlist = VIM::Windows() + perl $curbuf->Append(0, $winnr, scalar(@winlist)) + call assert_equal(['2', '2', ''], getline(1, '$')) + + " VIM::Windows() with window number argument. + perl VIM::Windows(VIM::Eval('winnr()'))->Buffer()->Set(1, 'bar') + call assert_equal('bar', getline(1)) + bwipe! +endfunc + +func Test_VIM_Buffers() + new Xbar + " VIM::Buffers() without argument in scalar and list context. + perl $nbuf = VIM::Buffers() + perl @buflist = VIM::Buffers() + + " VIM::Buffers() with argument. + perl $mybuf = (VIM::Buffers('Xbar'))[0] + perl $mybuf->Append(0, $nbuf, scalar(@buflist)) + call assert_equal(['2', '2', ''], getline(1, '$')) + bwipe! +endfunc + +func <SID>catch_peval(expr) + try + call perleval(a:expr) + catch + return v:exception + endtry + call assert_report('no exception for `perleval("'.a:expr.'")`') + return '' +endfunc + +func Test_perleval() + call assert_false(perleval('undef')) + + " scalar + call assert_equal(0, perleval('0')) + call assert_equal(2, perleval('2')) + call assert_equal(-2, perleval('-2')) + if has('float') + call assert_equal(2.5, perleval('2.5')) + else + call assert_equal(2, perleval('2.5')) + end + + sandbox call assert_equal(2, perleval('2')) + + call assert_equal('abc', perleval('"abc"')) + call assert_equal("abc\ndef", perleval('"abc\0def"')) + + " ref + call assert_equal([], perleval('[]')) + call assert_equal(['word', 42, [42],{}], perleval('["word", 42, [42], {}]')) + + call assert_equal({}, perleval('{}')) + call assert_equal({'foo': 'bar'}, perleval('{foo => "bar"}')) + + perl our %h; our @a; + let a = perleval('[\(%h, %h, @a, @a)]') + call assert_true((a[0] is a[1])) + call assert_true((a[2] is a[3])) + perl undef %h; undef @a; + + call assert_true(<SID>catch_peval('{"" , 0}') =~ 'Malformed key Dictionary') + call assert_true(<SID>catch_peval('{"\0" , 0}') =~ 'Malformed key Dictionary') + call assert_true(<SID>catch_peval('{"foo\0bar" , 0}') =~ 'Malformed key Dictionary') + + call assert_equal('*VIM', perleval('"*VIM"')) + call assert_true(perleval('\\0') =~ 'SCALAR(0x\x\+)') +endfunc + +func Test_perldo() + sp __TEST__ + exe 'read ' g:testname + perldo s/perl/vieux_chameau/g + 1 + call assert_false(search('\Cperl')) + bw! + + " Check deleting lines does not trigger ml_get error. + new + call setline(1, ['one', 'two', 'three']) + perldo VIM::DoCommand("%d_") + bwipe! + + " Check switching to another buffer does not trigger ml_get error. + new + let wincount = winnr('$') + call setline(1, ['one', 'two', 'three']) + perldo VIM::DoCommand("new") + call assert_equal(wincount + 1, winnr('$')) + bwipe! + bwipe! +endfunc + +func Test_VIM_package() + perl VIM::DoCommand('let l:var = "foo"') + call assert_equal(l:var, 'foo') + + set noet + perl VIM::SetOption('et') + call assert_true(&et) +endfunc + +func Test_stdio() + redir =>l:out + perl <<EOF + VIM::Msg("&VIM::Msg"); + print "STDOUT"; + print STDERR "STDERR"; +EOF + redir END + call assert_equal(['&VIM::Msg', 'STDOUT', 'STDERR'], split(l:out, "\n")) +endfunc + +" Run first to get a clean namespace +func Test_000_SvREFCNT() + for i in range(8) + exec 'new X'.i + endfor + new t + perl <<--perl +#line 5 "Test_000_SvREFCNT()" + my ($b, $w); + + my $num = 0; + for ( 0 .. 100 ) { + if ( ++$num >= 8 ) { $num = 0 } + VIM::DoCommand("buffer X$num"); + $b = $curbuf; + } + + VIM::DoCommand("buffer t"); + + $b = $curbuf for 0 .. 100; + $w = $curwin for 0 .. 100; + () = VIM::Buffers for 0 .. 100; + () = VIM::Windows for 0 .. 100; + + VIM::DoCommand('bw! t'); + if (exists &Internals::SvREFCNT) { + my $cb = Internals::SvREFCNT($$b); + my $cw = Internals::SvREFCNT($$w); + VIM::Eval("assert_equal(2, $cb, 'T1')"); + VIM::Eval("assert_equal(2, $cw, 'T2')"); + my $strongref; + foreach ( VIM::Buffers, VIM::Windows ) { + VIM::DoCommand("%bw!"); + my $c = Internals::SvREFCNT($_); + VIM::Eval("assert_equal(2, $c, 'T3')"); + $c = Internals::SvREFCNT($$_); + next if $c == 2 && !$strongref++; + VIM::Eval("assert_equal(1, $c, 'T4')"); + } + $cb = Internals::SvREFCNT($$curbuf); + $cw = Internals::SvREFCNT($$curwin); + VIM::Eval("assert_equal(3, $cb, 'T5')"); + VIM::Eval("assert_equal(3, $cw, 'T6')"); + } + VIM::Eval("assert_false($$b)"); + VIM::Eval("assert_false($$w)"); +--perl + %bw! +endfunc + +func Test_set_cursor() + " Check that setting the cursor position works. + new + call setline(1, ['first line', 'second line']) + normal gg + perldo $curwin->Cursor(1, 5) + call assert_equal([1, 6], [line('.'), col('.')]) + + " Check that movement after setting cursor position keeps current column. + normal j + call assert_equal([2, 6], [line('.'), col('.')]) +endfunc diff --git a/src/testdir/test_plus_arg_edit.vim b/src/testdir/test_plus_arg_edit.vim new file mode 100644 index 0000000..e31680e --- /dev/null +++ b/src/testdir/test_plus_arg_edit.vim @@ -0,0 +1,34 @@ +" Tests for complicated + argument to :edit command +function Test_edit() + call writefile(["foo|bar"], "Xfile1") + call writefile(["foo/bar"], "Xfile2") + edit +1|s/|/PIPE/|w Xfile1| e Xfile2|1 | s/\//SLASH/|w + call assert_equal(["fooPIPEbar"], readfile("Xfile1")) + call assert_equal(["fooSLASHbar"], readfile("Xfile2")) + call delete('Xfile1') + call delete('Xfile2') +endfunction + +func Test_edit_bad() + " Test loading a utf8 file with bad utf8 sequences. + call writefile(["[\xff][\xc0][\xe2\x89\xf0][\xc2\xc2]"], "Xfile") + new + + " Without ++bad=..., the default behavior is like ++bad=? + e! ++enc=utf8 Xfile + call assert_equal('[?][?][???][??]', getline(1)) + + e! ++enc=utf8 ++bad=_ Xfile + call assert_equal('[_][_][___][__]', getline(1)) + + e! ++enc=utf8 ++bad=drop Xfile + call assert_equal('[][][][]', getline(1)) + + e! ++enc=utf8 ++bad=keep Xfile + call assert_equal("[\xff][\xc0][\xe2\x89\xf0][\xc2\xc2]", getline(1)) + + call assert_fails('e! ++enc=utf8 ++bad=foo Xfile', 'E474:') + + bw! + call delete('Xfile') +endfunc diff --git a/src/testdir/test_popup.vim b/src/testdir/test_popup.vim new file mode 100644 index 0000000..663a6a8 --- /dev/null +++ b/src/testdir/test_popup.vim @@ -0,0 +1,899 @@ +" Test for completion menu + +source shared.vim +source screendump.vim + +let g:months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] +let g:setting = '' + +func ListMonths() + if g:setting != '' + exe ":set" g:setting + endif + let mth = copy(g:months) + let entered = strcharpart(getline('.'),0,col('.')) + if !empty(entered) + let mth = filter(mth, 'v:val=~"^".entered') + endif + call complete(1, mth) + return '' +endfunc + +func Test_popup_complete2() + " Although the popupmenu is not visible, this does not mean completion mode + " has ended. After pressing <f5> to complete the currently typed char, Vim + " still stays in the first state of the completion (:h ins-completion-menu), + " although the popupmenu wasn't shown <c-e> will remove the inserted + " completed text (:h complete_CTRL-E), while the following <c-e> will behave + " like expected (:h i_CTRL-E) + new + inoremap <f5> <c-r>=ListMonths()<cr> + call append(1, ["December2015"]) + :1 + call feedkeys("aD\<f5>\<C-E>\<C-E>\<C-E>\<C-E>\<enter>\<esc>", 'tx') + call assert_equal(["Dece", "", "December2015"], getline(1,3)) + %d + bw! +endfunc + +func Test_popup_complete() + new + inoremap <f5> <c-r>=ListMonths()<cr> + + " <C-E> - select original typed text before the completion started + call feedkeys("aJu\<f5>\<down>\<c-e>\<esc>", 'tx') + call assert_equal(["Ju"], getline(1,2)) + %d + + " <C-Y> - accept current match + call feedkeys("a\<f5>". repeat("\<down>",7). "\<c-y>\<esc>", 'tx') + call assert_equal(["August"], getline(1,2)) + %d + + " <BS> - Delete one character from the inserted text (state: 1) + " TODO: This should not end the completion, but it does. + " This should according to the documentation: + " January + " but instead, this does + " Januar + " (idea is, C-L inserts the match from the popup menu + " but if the menu is closed, it will insert the character <c-l> + call feedkeys("aJ\<f5>\<bs>\<c-l>\<esc>", 'tx') + call assert_equal(["Januar"], getline(1,2)) + %d + + " any-non special character: Stop completion without changing the match + " and insert the typed character + call feedkeys("a\<f5>20", 'tx') + call assert_equal(["January20"], getline(1,2)) + %d + + " any-non printable, non-white character: Add this character and + " reduce number of matches + call feedkeys("aJu\<f5>\<c-p>l\<c-y>", 'tx') + call assert_equal(["Jul"], getline(1,2)) + %d + + " any-non printable, non-white character: Add this character and + " reduce number of matches + call feedkeys("aJu\<f5>\<c-p>l\<c-n>\<c-y>", 'tx') + call assert_equal(["July"], getline(1,2)) + %d + + " any-non printable, non-white character: Add this character and + " reduce number of matches + call feedkeys("aJu\<f5>\<c-p>l\<c-e>", 'tx') + call assert_equal(["Jul"], getline(1,2)) + %d + + " <BS> - Delete one character from the inserted text (state: 2) + call feedkeys("a\<f5>\<c-n>\<bs>", 'tx') + call assert_equal(["Februar"], getline(1,2)) + %d + + " <c-l> - Insert one character from the current match + call feedkeys("aJ\<f5>".repeat("\<c-n>",3)."\<c-l>\<esc>", 'tx') + call assert_equal(["J"], getline(1,2)) + %d + + " <c-l> - Insert one character from the current match + call feedkeys("aJ\<f5>".repeat("\<c-n>",4)."\<c-l>\<esc>", 'tx') + call assert_equal(["January"], getline(1,2)) + %d + + " <c-y> - Accept current selected match + call feedkeys("aJ\<f5>\<c-y>\<esc>", 'tx') + call assert_equal(["January"], getline(1,2)) + %d + + " <c-e> - End completion, go back to what was there before selecting a match + call feedkeys("aJu\<f5>\<c-e>\<esc>", 'tx') + call assert_equal(["Ju"], getline(1,2)) + %d + + " <PageUp> - Select a match several entries back + call feedkeys("a\<f5>\<PageUp>\<c-y>\<esc>", 'tx') + call assert_equal([""], getline(1,2)) + %d + + " <PageUp><PageUp> - Select a match several entries back + call feedkeys("a\<f5>\<PageUp>\<PageUp>\<c-y>\<esc>", 'tx') + call assert_equal(["December"], getline(1,2)) + %d + + " <PageUp><PageUp><PageUp> - Select a match several entries back + call feedkeys("a\<f5>\<PageUp>\<PageUp>\<PageUp>\<c-y>\<esc>", 'tx') + call assert_equal(["February"], getline(1,2)) + %d + + " <PageDown> - Select a match several entries further + call feedkeys("a\<f5>\<PageDown>\<c-y>\<esc>", 'tx') + call assert_equal(["November"], getline(1,2)) + %d + + " <PageDown><PageDown> - Select a match several entries further + call feedkeys("a\<f5>\<PageDown>\<PageDown>\<c-y>\<esc>", 'tx') + call assert_equal(["December"], getline(1,2)) + %d + + " <PageDown><PageDown><PageDown> - Select a match several entries further + call feedkeys("a\<f5>\<PageDown>\<PageDown>\<PageDown>\<c-y>\<esc>", 'tx') + call assert_equal([""], getline(1,2)) + %d + + " <PageDown><PageDown><PageDown><PageDown> - Select a match several entries further + call feedkeys("a\<f5>".repeat("\<PageDown>",4)."\<c-y>\<esc>", 'tx') + call assert_equal(["October"], getline(1,2)) + %d + + " <Up> - Select a match don't insert yet + call feedkeys("a\<f5>\<Up>\<c-y>\<esc>", 'tx') + call assert_equal([""], getline(1,2)) + %d + + " <Up><Up> - Select a match don't insert yet + call feedkeys("a\<f5>\<Up>\<Up>\<c-y>\<esc>", 'tx') + call assert_equal(["December"], getline(1,2)) + %d + + " <Up><Up><Up> - Select a match don't insert yet + call feedkeys("a\<f5>\<Up>\<Up>\<Up>\<c-y>\<esc>", 'tx') + call assert_equal(["November"], getline(1,2)) + %d + + " <Tab> - Stop completion and insert the match + call feedkeys("a\<f5>\<Tab>\<c-y>\<esc>", 'tx') + call assert_equal(["January "], getline(1,2)) + %d + + " <Space> - Stop completion and insert the match + call feedkeys("a\<f5>".repeat("\<c-p>",5)." \<esc>", 'tx') + call assert_equal(["September "], getline(1,2)) + %d + + " <Enter> - Use the text and insert line break (state: 1) + call feedkeys("a\<f5>\<enter>\<esc>", 'tx') + call assert_equal(["January", ''], getline(1,2)) + %d + + " <Enter> - Insert the current selected text (state: 2) + call feedkeys("a\<f5>".repeat("\<Up>",5)."\<enter>\<esc>", 'tx') + call assert_equal(["September"], getline(1,2)) + %d + + " Insert match immediately, if there is only one match + " <c-y> selects a character from the line above + call append(0, ["December2015"]) + call feedkeys("aD\<f5>\<C-Y>\<C-Y>\<C-Y>\<C-Y>\<enter>\<esc>", 'tx') + call assert_equal(["December2015", "December2015", ""], getline(1,3)) + %d + + " use menuone for 'completeopt' + " Since for the first <c-y> the menu is still shown, will only select + " three letters from the line above + set completeopt&vim + set completeopt+=menuone + call append(0, ["December2015"]) + call feedkeys("aD\<f5>\<C-Y>\<C-Y>\<C-Y>\<C-Y>\<enter>\<esc>", 'tx') + call assert_equal(["December2015", "December201", ""], getline(1,3)) + %d + + " use longest for 'completeopt' + set completeopt&vim + call feedkeys("aM\<f5>\<C-N>\<C-P>\<c-e>\<enter>\<esc>", 'tx') + set completeopt+=longest + call feedkeys("aM\<f5>\<C-N>\<C-P>\<c-e>\<enter>\<esc>", 'tx') + call assert_equal(["M", "Ma", ""], getline(1,3)) + %d + + " use noselect/noinsert for 'completeopt' + set completeopt&vim + call feedkeys("aM\<f5>\<enter>\<esc>", 'tx') + set completeopt+=noselect + call feedkeys("aM\<f5>\<enter>\<esc>", 'tx') + set completeopt-=noselect completeopt+=noinsert + call feedkeys("aM\<f5>\<enter>\<esc>", 'tx') + call assert_equal(["March", "M", "March"], getline(1,4)) + %d +endfunc + + +func Test_popup_completion_insertmode() + new + inoremap <F5> <C-R>=ListMonths()<CR> + + call feedkeys("a\<f5>\<down>\<enter>\<esc>", 'tx') + call assert_equal('February', getline(1)) + %d + " Set noinsertmode + let g:setting = 'noinsertmode' + call feedkeys("a\<f5>\<down>\<enter>\<esc>", 'tx') + call assert_equal('February', getline(1)) + call assert_false(pumvisible()) + %d + " Go through all matches, until none is selected + let g:setting = '' + call feedkeys("a\<f5>". repeat("\<c-n>",12)."\<enter>\<esc>", 'tx') + call assert_equal('', getline(1)) + %d + " select previous entry + call feedkeys("a\<f5>\<c-p>\<enter>\<esc>", 'tx') + call assert_equal('', getline(1)) + %d + " select last entry + call feedkeys("a\<f5>\<c-p>\<c-p>\<enter>\<esc>", 'tx') + call assert_equal('December', getline(1)) + + iunmap <F5> +endfunc + +func Test_noinsert_complete() + func! s:complTest1() abort + call complete(1, ['source', 'soundfold']) + return '' + endfunc + + func! s:complTest2() abort + call complete(1, ['source', 'soundfold']) + return '' + endfunc + + new + set completeopt+=noinsert + inoremap <F5> <C-R>=s:complTest1()<CR> + call feedkeys("i\<F5>soun\<CR>\<CR>\<ESC>.", 'tx') + call assert_equal('soundfold', getline(1)) + call assert_equal('soundfold', getline(2)) + bwipe! + + new + inoremap <F5> <C-R>=s:complTest2()<CR> + call feedkeys("i\<F5>\<CR>\<ESC>", 'tx') + call assert_equal('source', getline(1)) + bwipe! + + set completeopt-=noinsert + iunmap <F5> +endfunc + +func Test_compl_vim_cmds_after_register_expr() + func! s:test_func() + return 'autocmd ' + endfunc + augroup AAAAA_Group + au! + augroup END + + new + call feedkeys("i\<c-r>=s:test_func()\<CR>\<C-x>\<C-v>\<Esc>", 'tx') + call assert_equal('autocmd AAAAA_Group', getline(1)) + autocmd! AAAAA_Group + augroup! AAAAA_Group + bwipe! +endfunc + +func DummyCompleteOne(findstart, base) + if a:findstart + return 0 + else + wincmd n + return ['onedef', 'oneDEF'] + endif +endfunc + +" Test that nothing happens if the 'completefunc' opens +" a new window (no completion, no crash) +func Test_completefunc_opens_new_window_one() + new + let winid = win_getid() + setlocal completefunc=DummyCompleteOne + call setline(1, 'one') + /^one + call assert_fails('call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x")', 'E839:') + call assert_notequal(winid, win_getid()) + q! + call assert_equal(winid, win_getid()) + call assert_equal('', getline(1)) + q! +endfunc + +" Test that nothing happens if the 'completefunc' opens +" a new window (no completion, no crash) +func DummyCompleteTwo(findstart, base) + if a:findstart + wincmd n + return 0 + else + return ['twodef', 'twoDEF'] + endif +endfunc + +" Test that nothing happens if the 'completefunc' opens +" a new window (no completion, no crash) +func Test_completefunc_opens_new_window_two() + new + let winid = win_getid() + setlocal completefunc=DummyCompleteTwo + call setline(1, 'two') + /^two + call assert_fails('call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x")', 'E764:') + call assert_notequal(winid, win_getid()) + q! + call assert_equal(winid, win_getid()) + call assert_equal('two', getline(1)) + q! +endfunc + +func DummyCompleteThree(findstart, base) + if a:findstart + return 0 + else + return ['threedef', 'threeDEF'] + endif +endfunc + +:"Test that 'completefunc' works when it's OK. +func Test_completefunc_works() + new + let winid = win_getid() + setlocal completefunc=DummyCompleteThree + call setline(1, 'three') + /^three + call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x") + call assert_equal(winid, win_getid()) + call assert_equal('threeDEF', getline(1)) + q! +endfunc + +func DummyCompleteFour(findstart, base) + if a:findstart + return 0 + else + call complete_add('four1') + call complete_add('four2') + call complete_check() + call complete_add('four3') + call complete_add('four4') + call complete_check() + call complete_add('four5') + call complete_add('four6') + return [] + endif +endfunc + +" Test that 'omnifunc' works when it's OK. +func Test_omnifunc_with_check() + new + setlocal omnifunc=DummyCompleteFour + call setline(1, 'four') + /^four + call feedkeys("A\<C-X>\<C-O>\<C-N>\<Esc>", "x") + call assert_equal('four2', getline(1)) + + call setline(1, 'four') + /^four + call feedkeys("A\<C-X>\<C-O>\<C-N>\<C-N>\<Esc>", "x") + call assert_equal('four3', getline(1)) + + call setline(1, 'four') + /^four + call feedkeys("A\<C-X>\<C-O>\<C-N>\<C-N>\<C-N>\<C-N>\<Esc>", "x") + call assert_equal('four5', getline(1)) + + q! +endfunc + +func UndoComplete() + call complete(1, ['January', 'February', 'March', + \ 'April', 'May', 'June', 'July', 'August', 'September', + \ 'October', 'November', 'December']) + return '' +endfunc + +" Test that no undo item is created when no completion is inserted +func Test_complete_no_undo() + set completeopt=menu,preview,noinsert,noselect + inoremap <Right> <C-R>=UndoComplete()<CR> + new + call feedkeys("ixxx\<CR>\<CR>yyy\<Esc>k", 'xt') + call feedkeys("iaaa\<Esc>0", 'xt') + call assert_equal('aaa', getline(2)) + call feedkeys("i\<Right>\<Esc>", 'xt') + call assert_equal('aaa', getline(2)) + call feedkeys("u", 'xt') + call assert_equal('', getline(2)) + + call feedkeys("ibbb\<Esc>0", 'xt') + call assert_equal('bbb', getline(2)) + call feedkeys("A\<Right>\<Down>\<CR>\<Esc>", 'xt') + call assert_equal('January', getline(2)) + call feedkeys("u", 'xt') + call assert_equal('bbb', getline(2)) + + call feedkeys("A\<Right>\<C-N>\<Esc>", 'xt') + call assert_equal('January', getline(2)) + call feedkeys("u", 'xt') + call assert_equal('bbb', getline(2)) + + iunmap <Right> + set completeopt& + q! +endfunc + +func DummyCompleteFive(findstart, base) + if a:findstart + return 0 + else + return [ + \ { 'word': 'January', 'info': "info1-1\n1-2\n1-3" }, + \ { 'word': 'February', 'info': "info2-1\n2-2\n2-3" }, + \ { 'word': 'March', 'info': "info3-1\n3-2\n3-3" }, + \ { 'word': 'April', 'info': "info4-1\n4-2\n4-3" }, + \ { 'word': 'May', 'info': "info5-1\n5-2\n5-3" }, + \ ] + endif +endfunc + +" Test that 'completefunc' on Scratch buffer with preview window works when +" it's OK. +func Test_completefunc_with_scratch_buffer() + new +setlocal\ buftype=nofile\ bufhidden=wipe\ noswapfile + set completeopt+=preview + setlocal completefunc=DummyCompleteFive + call feedkeys("A\<C-X>\<C-U>\<C-N>\<C-N>\<C-N>\<Esc>", "x") + call assert_equal(['April'], getline(1, '$')) + pclose + q! + set completeopt& +endfunc + +" <C-E> - select original typed text before the completion started without +" auto-wrap text. +func Test_completion_ctrl_e_without_autowrap() + new + let tw_save = &tw + set tw=78 + let li = [ + \ '" zzz', + \ '" zzzyyyyyyyyyyyyyyyyyyy'] + call setline(1, li) + 0 + call feedkeys("A\<C-X>\<C-N>\<C-E>\<Esc>", "tx") + call assert_equal(li, getline(1, '$')) + + let &tw = tw_save + q! +endfunc + +func DummyCompleteSix() + call complete(1, ['Hello', 'World']) + return '' +endfunction + +" complete() correctly clears the list of autocomplete candidates +" See #1411 +func Test_completion_clear_candidate_list() + new + %d + " select first entry from the completion popup + call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>", "tx") + call assert_equal('Hello', getline(1)) + %d + " select second entry from the completion popup + call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>\<C-N>", "tx") + call assert_equal('World', getline(1)) + %d + " select original text + call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>\<C-N>\<C-N>", "tx") + call assert_equal(' xxx', getline(1)) + %d + " back at first entry from completion list + call feedkeys("a xxx\<C-N>\<C-R>=DummyCompleteSix()\<CR>\<C-N>\<C-N>\<C-N>", "tx") + call assert_equal('Hello', getline(1)) + + bw! +endfunc + +func Test_completion_respect_bs_option() + new + let li = ["aaa", "aaa12345", "aaaabcdef", "aaaABC"] + + set bs=indent,eol + call setline(1, li) + 1 + call feedkeys("A\<C-X>\<C-N>\<C-P>\<BS>\<BS>\<BS>\<Esc>", "tx") + call assert_equal('aaa', getline(1)) + + %d + set bs=indent,eol,start + call setline(1, li) + 1 + call feedkeys("A\<C-X>\<C-N>\<C-P>\<BS>\<BS>\<BS>\<Esc>", "tx") + call assert_equal('', getline(1)) + + bw! +endfunc + +func CompleteUndo() abort + call complete(1, g:months) + return '' +endfunc + +func Test_completion_can_undo() + inoremap <Right> <c-r>=CompleteUndo()<cr> + set completeopt+=noinsert,noselect + + new + call feedkeys("a\<Right>a\<Esc>", 'xt') + call assert_equal('a', getline(1)) + undo + call assert_equal('', getline(1)) + + bwipe! + set completeopt& + iunmap <Right> +endfunc + +func Test_completion_comment_formatting() + new + setl formatoptions=tcqro + call feedkeys("o/*\<cr>\<cr>/\<esc>", 'tx') + call assert_equal(['', '/*', ' *', ' */'], getline(1,4)) + %d + call feedkeys("o/*\<cr>foobar\<cr>/\<esc>", 'tx') + call assert_equal(['', '/*', ' * foobar', ' */'], getline(1,4)) + %d + try + call feedkeys("o/*\<cr>\<cr>\<c-x>\<c-u>/\<esc>", 'tx') + call assert_report('completefunc not set, should have failed') + catch + call assert_exception('E764:') + endtry + call assert_equal(['', '/*', ' *', ' */'], getline(1,4)) + bwipe! +endfunc + +func MessCompleteMonths() + for m in split("Jan Feb Mar Apr May Jun Jul Aug Sep") + call complete_add(m) + if complete_check() + break + endif + endfor + return [] +endfunc + +func MessCompleteMore() + call complete(1, split("Oct Nov Dec")) + return [] +endfunc + +func MessComplete(findstart, base) + if a:findstart + let line = getline('.') + let start = col('.') - 1 + while start > 0 && line[start - 1] =~ '\a' + let start -= 1 + endwhile + return start + else + call MessCompleteMonths() + call MessCompleteMore() + return [] + endif +endfunc + +func Test_complete_func_mess() + " Calling complete() after complete_add() in 'completefunc' is wrong, but it + " should not crash. + set completefunc=MessComplete + new + call setline(1, 'Ju') + call feedkeys("A\<c-x>\<c-u>/\<esc>", 'tx') + call assert_equal('Oct/Oct', getline(1)) + bwipe! + set completefunc= +endfunc + +func Test_complete_CTRLN_startofbuffer() + new + call setline(1, [ 'organize(cupboard, 3, 2);', + \ 'prioritize(bureau, 8, 7);', + \ 'realize(bannister, 4, 4);', + \ 'moralize(railing, 3,9);']) + let expected=['cupboard.organize(3, 2);', + \ 'bureau.prioritize(8, 7);', + \ 'bannister.realize(4, 4);', + \ 'railing.moralize(3,9);'] + call feedkeys("qai\<c-n>\<c-n>.\<esc>3wdW\<cr>q3@a", 'tx') + call assert_equal(expected, getline(1,'$')) + bwipe! +endfunc + +func Test_popup_and_window_resize() + if !has('terminal') || has('gui_running') + return + endif + let h = winheight(0) + if h < 15 + return + endif + let rows = h / 3 + let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile'], {'term_rows': rows}) + call term_sendkeys(buf, (h / 3 - 1) . "o\<esc>") + " Wait for the nested Vim to exit insert mode, where it will show the ruler. + " Need to trigger a redraw. + call WaitFor({-> execute("redraw") == "" && term_getline(buf, rows) =~ '\<' . rows . ',.*Bot'}) + + call term_sendkeys(buf, "Gi\<c-x>") + call term_sendkeys(buf, "\<c-v>") + call term_wait(buf, 100) + " popup first entry "!" must be at the top + call WaitForAssert({-> assert_match('^!\s*$', term_getline(buf, 1))}) + exe 'resize +' . (h - 1) + call term_wait(buf, 100) + redraw! + " popup shifted down, first line is now empty + call WaitForAssert({-> assert_equal('', term_getline(buf, 1))}) + sleep 100m + " popup is below cursor line and shows first match "!" + call WaitForAssert({-> assert_match('^!\s*$', term_getline(buf, term_getcursor(buf)[0] + 1))}) + " cursor line also shows ! + call assert_match('^!\s*$', term_getline(buf, term_getcursor(buf)[0])) + bwipe! +endfunc + +func Test_popup_and_preview_autocommand() + " This used to crash Vim + if !has('python') + return + endif + let h = winheight(0) + if h < 15 + return + endif + new + augroup MyBufAdd + au! + au BufAdd * nested tab sball + augroup END + set omnifunc=pythoncomplete#Complete + call setline(1, 'import os') + " make the line long + call setline(2, ' os.') + $ + call feedkeys("A\<C-X>\<C-O>\<C-N>\<C-N>\<C-N>\<enter>\<esc>", 'tx') + call assert_equal("import os", getline(1)) + call assert_match(' os.\(EX_IOERR\|O_CREAT\)$', getline(2)) + call assert_equal(1, winnr('$')) + " previewwindow option is not set + call assert_equal(0, &previewwindow) + norm! gt + call assert_equal(0, &previewwindow) + norm! gT + call assert_equal(10, tabpagenr('$')) + tabonly + pclose + augroup MyBufAdd + au! + augroup END + augroup! MyBufAdd + bw! +endfunc + +func Test_popup_and_previewwindow_dump() + if !CanRunVimInTerminal() + return + endif + call writefile([ + \ 'set previewheight=9', + \ 'silent! pedit', + \ 'call setline(1, map(repeat(["ab"], 10), "v:val. v:key"))', + \ 'exec "norm! G\<C-E>\<C-E>"', + \ ], 'Xscript') + let buf = RunVimInTerminal('-S Xscript', {}) + + " Test that popup and previewwindow do not overlap. + call term_sendkeys(buf, "o\<C-X>\<C-N>") + sleep 100m + call VerifyScreenDump(buf, 'Test_popup_and_previewwindow_01', {}) + + call term_sendkeys(buf, "\<Esc>u") + call StopVimInTerminal(buf) + call delete('Xscript') +endfunc + +func Test_balloon_split() + if !exists('*balloon_split') + return + endif + call assert_equal([ + \ 'tempname: 0x555555e380a0 "/home/mool/.viminfz.tmp"', + \ ], balloon_split( + \ 'tempname: 0x555555e380a0 "/home/mool/.viminfz.tmp"')) + call assert_equal([ + \ 'one two three four one two three four one two thre', + \ 'e four', + \ ], balloon_split( + \ 'one two three four one two three four one two three four')) + + call assert_equal([ + \ 'struct = {', + \ ' one = 1,', + \ ' two = 2,', + \ ' three = 3}', + \ ], balloon_split( + \ 'struct = {one = 1, two = 2, three = 3}')) + + call assert_equal([ + \ 'struct = {', + \ ' one = 1,', + \ ' nested = {', + \ ' n1 = "yes",', + \ ' n2 = "no"}', + \ ' two = 2}', + \ ], balloon_split( + \ 'struct = {one = 1, nested = {n1 = "yes", n2 = "no"} two = 2}')) + call assert_equal([ + \ 'struct = 0x234 {', + \ ' long = 2343 "\\"some long string that will be wr', + \ 'apped in two\\"",', + \ ' next = 123}', + \ ], balloon_split( + \ 'struct = 0x234 {long = 2343 "\\"some long string that will be wrapped in two\\"", next = 123}')) +endfunc + +func Test_popup_position() + if !CanRunVimInTerminal() + return + endif + call writefile([ + \ '123456789_123456789_123456789_a', + \ '123456789_123456789_123456789_b', + \ ' 123', + \ ], 'Xtest') + let buf = RunVimInTerminal('Xtest', {}) + call term_sendkeys(buf, ":vsplit\<CR>") + + " default pumwidth in left window: overlap in right window + call term_sendkeys(buf, "GA\<C-N>") + call VerifyScreenDump(buf, 'Test_popup_position_01', {'rows': 8}) + call term_sendkeys(buf, "\<Esc>u") + + " default pumwidth: fill until right of window + call term_sendkeys(buf, "\<C-W>l") + call term_sendkeys(buf, "GA\<C-N>") + call VerifyScreenDump(buf, 'Test_popup_position_02', {'rows': 8}) + + " larger pumwidth: used as minimum width + call term_sendkeys(buf, "\<Esc>u") + call term_sendkeys(buf, ":set pumwidth=30\<CR>") + call term_sendkeys(buf, "GA\<C-N>") + call VerifyScreenDump(buf, 'Test_popup_position_03', {'rows': 8}) + + " completed text wider than the window and 'pumwidth' smaller than available + " space + call term_sendkeys(buf, "\<Esc>u") + call term_sendkeys(buf, ":set pumwidth=20\<CR>") + call term_sendkeys(buf, "ggI123456789_\<Esc>") + call term_sendkeys(buf, "jI123456789_\<Esc>") + call term_sendkeys(buf, "GA\<C-N>") + call VerifyScreenDump(buf, 'Test_popup_position_04', {'rows': 10}) + + call term_sendkeys(buf, "\<Esc>u") + call StopVimInTerminal(buf) + call delete('Xtest') +endfunc + +func Test_popup_command() + if !CanRunVimInTerminal() || !has('menu') + return + endif + + call writefile([ + \ 'one two three four five', + \ 'and one two Xthree four five', + \ 'one more two three four five', + \ ], 'Xtest') + let buf = RunVimInTerminal('Xtest', {}) + call term_sendkeys(buf, ":source $VIMRUNTIME/menu.vim\<CR>") + call term_sendkeys(buf, "/X\<CR>:popup PopUp\<CR>") + call VerifyScreenDump(buf, 'Test_popup_command_01', {}) + + " Select a word + call term_sendkeys(buf, "jj") + call VerifyScreenDump(buf, 'Test_popup_command_02', {}) + + " Select a word + call term_sendkeys(buf, "j\<CR>") + call VerifyScreenDump(buf, 'Test_popup_command_03', {}) + + call term_sendkeys(buf, "\<Esc>") + call StopVimInTerminal(buf) + call delete('Xtest') +endfunc + +func Test_popup_complete_backwards() + new + call setline(1, ['Post', 'Port', 'Po']) + let expected=['Post', 'Port', 'Port'] + call cursor(3,2) + call feedkeys("A\<C-X>". repeat("\<C-P>", 3). "rt\<cr>", 'tx') + call assert_equal(expected, getline(1,'$')) + bwipe! +endfunc + +func Test_popup_complete_backwards_ctrl_p() + new + call setline(1, ['Post', 'Port', 'Po']) + let expected=['Post', 'Port', 'Port'] + call cursor(3,2) + call feedkeys("A\<C-P>\<C-N>rt\<cr>", 'tx') + call assert_equal(expected, getline(1,'$')) + bwipe! +endfunc + +func Test_complete_o_tab() + let s:o_char_pressed = 0 + + fun! s:act_on_text_changed() + if s:o_char_pressed + let s:o_char_pressed = 0 + call feedkeys("\<c-x>\<c-n>", 'i') + endif + endfunc + + set completeopt=menu,noselect + new + imap <expr> <buffer> <tab> pumvisible() ? "\<c-p>" : "X" + autocmd! InsertCharPre <buffer> let s:o_char_pressed = (v:char ==# 'o') + autocmd! TextChangedI <buffer> call <sid>act_on_text_changed() + call setline(1, ['hoard', 'hoax', 'hoarse', '']) + let l:expected = ['hoard', 'hoax', 'hoarse', 'hoax', 'hoax'] + call cursor(4,1) + call test_override("char_avail", 1) + call feedkeys("Ahoa\<tab>\<tab>\<c-y>\<esc>", 'tx') + call feedkeys("oho\<tab>\<tab>\<c-y>\<esc>", 'tx') + call assert_equal(l:expected, getline(1,'$')) + + call test_override("char_avail", 0) + bwipe! + set completeopt& + delfunc s:act_on_text_changed +endfunc + +func Test_menu_only_exists_in_terminal() + if !exists(':tlmenu') || has('gui_running') + return + endif + tlnoremenu &Edit.&Paste<Tab>"+gP <C-W>"+ + aunmenu * + try + popup Edit + call assert_false(1, 'command should have failed') + catch + call assert_exception('E328:') + endtry +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_preview.vim b/src/testdir/test_preview.vim new file mode 100644 index 0000000..91923fb --- /dev/null +++ b/src/testdir/test_preview.vim @@ -0,0 +1,13 @@ +" Tests for the preview window + +func Test_Psearch() + " this used to cause ml_get errors + help + let wincount = winnr('$') + 0f + ps. + call assert_equal(wincount + 1, winnr('$')) + pclose + call assert_equal(wincount, winnr('$')) + bwipe +endfunc diff --git a/src/testdir/test_profile.vim b/src/testdir/test_profile.vim new file mode 100644 index 0000000..d6e9c03 --- /dev/null +++ b/src/testdir/test_profile.vim @@ -0,0 +1,520 @@ +" Test Vim profiler +if !has('profile') + finish +endif + +func Test_profile_func() + let lines = [ + \ 'profile start Xprofile_func.log', + \ 'profile func Foo*"', + \ "func! Foo1()", + \ "endfunc", + \ "func! Foo2()", + \ " let l:count = 100", + \ " while l:count > 0", + \ " let l:count = l:count - 1", + \ " endwhile", + \ "endfunc", + \ "func! Foo3()", + \ "endfunc", + \ "func! Bar()", + \ "endfunc", + \ "call Foo1()", + \ "call Foo1()", + \ "profile pause", + \ "call Foo1()", + \ "profile continue", + \ "call Foo2()", + \ "call Foo3()", + \ "call Bar()", + \ "if !v:profiling", + \ " delfunc Foo2", + \ "endif", + \ "delfunc Foo3", + \ ] + + call writefile(lines, 'Xprofile_func.vim') + call system(v:progpath + \ . ' -es --clean' + \ . ' -c "so Xprofile_func.vim"' + \ . ' -c "qall!"') + call assert_equal(0, v:shell_error) + + let lines = readfile('Xprofile_func.log') + + " - Foo1() is called 3 times but should be reported as called twice + " since one call is in between "profile pause" .. "profile continue". + " - Foo2() should come before Foo1() since Foo1() does much more work. + " - Foo3() is not reported because function is deleted. + " - Unlike Foo3(), Foo2() should not be deleted since there is a check + " for v:profiling. + " - Bar() is not reported since it does not match "profile func Foo*". + call assert_equal(30, len(lines)) + + call assert_equal('FUNCTION Foo1()', lines[0]) + call assert_match('Defined:.*Xprofile_func.vim', lines[1]) + call assert_equal('Called 2 times', lines[2]) + call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[3]) + call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[4]) + call assert_equal('', lines[5]) + call assert_equal('count total (s) self (s)', lines[6]) + call assert_equal('', lines[7]) + call assert_equal('FUNCTION Foo2()', lines[8]) + call assert_equal('Called 1 time', lines[10]) + call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[11]) + call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[12]) + call assert_equal('', lines[13]) + call assert_equal('count total (s) self (s)', lines[14]) + call assert_match('^\s*1\s\+.*\slet l:count = 100$', lines[15]) + call assert_match('^\s*101\s\+.*\swhile l:count > 0$', lines[16]) + call assert_match('^\s*100\s\+.*\s let l:count = l:count - 1$', lines[17]) + call assert_match('^\s*101\s\+.*\sendwhile$', lines[18]) + call assert_equal('', lines[19]) + call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[20]) + call assert_equal('count total (s) self (s) function', lines[21]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo2()$', lines[22]) + call assert_match('^\s*2\s\+\d\+\.\d\+\s\+Foo1()$', lines[23]) + call assert_equal('', lines[24]) + call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[25]) + call assert_equal('count total (s) self (s) function', lines[26]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo2()$', lines[27]) + call assert_match('^\s*2\s\+\d\+\.\d\+\s\+Foo1()$', lines[28]) + call assert_equal('', lines[29]) + + call delete('Xprofile_func.vim') + call delete('Xprofile_func.log') +endfunc + +func Test_profile_func_with_ifelse() + let lines = [ + \ "func! Foo1()", + \ " if 1", + \ " let x = 0", + \ " elseif 1", + \ " let x = 1", + \ " else", + \ " let x = 2", + \ " endif", + \ "endfunc", + \ "func! Foo2()", + \ " if 0", + \ " let x = 0", + \ " elseif 1", + \ " let x = 1", + \ " else", + \ " let x = 2", + \ " endif", + \ "endfunc", + \ "func! Foo3()", + \ " if 0", + \ " let x = 0", + \ " elseif 0", + \ " let x = 1", + \ " else", + \ " let x = 2", + \ " endif", + \ "endfunc", + \ "call Foo1()", + \ "call Foo2()", + \ "call Foo3()", + \ ] + + call writefile(lines, 'Xprofile_func.vim') + call system(v:progpath + \ . ' -es -u NONE -U NONE -i NONE --noplugin' + \ . ' -c "profile start Xprofile_func.log"' + \ . ' -c "profile func Foo*"' + \ . ' -c "so Xprofile_func.vim"' + \ . ' -c "qall!"') + call assert_equal(0, v:shell_error) + + let lines = readfile('Xprofile_func.log') + + " - Foo1() should pass 'if' block. + " - Foo2() should pass 'elseif' block. + " - Foo3() should pass 'else' block. + call assert_equal(57, len(lines)) + + call assert_equal('FUNCTION Foo1()', lines[0]) + call assert_match('Defined:.*Xprofile_func.vim', lines[1]) + call assert_equal('Called 1 time', lines[2]) + call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[3]) + call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[4]) + call assert_equal('', lines[5]) + call assert_equal('count total (s) self (s)', lines[6]) + call assert_match('^\s*1\s\+.*\sif 1$', lines[7]) + call assert_match('^\s*1\s\+.*\s let x = 0$', lines[8]) + call assert_match( '^\s\+elseif 1$', lines[9]) + call assert_match( '^\s\+let x = 1$', lines[10]) + call assert_match( '^\s\+else$', lines[11]) + call assert_match( '^\s\+let x = 2$', lines[12]) + call assert_match('^\s*1\s\+.*\sendif$', lines[13]) + call assert_equal('', lines[14]) + call assert_equal('FUNCTION Foo2()', lines[15]) + call assert_equal('Called 1 time', lines[17]) + call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[18]) + call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[19]) + call assert_equal('', lines[20]) + call assert_equal('count total (s) self (s)', lines[21]) + call assert_match('^\s*1\s\+.*\sif 0$', lines[22]) + call assert_match( '^\s\+let x = 0$', lines[23]) + call assert_match('^\s*1\s\+.*\selseif 1$', lines[24]) + call assert_match('^\s*1\s\+.*\s let x = 1$', lines[25]) + call assert_match( '^\s\+else$', lines[26]) + call assert_match( '^\s\+let x = 2$', lines[27]) + call assert_match('^\s*1\s\+.*\sendif$', lines[28]) + call assert_equal('', lines[29]) + call assert_equal('FUNCTION Foo3()', lines[30]) + call assert_equal('Called 1 time', lines[32]) + call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[33]) + call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[34]) + call assert_equal('', lines[35]) + call assert_equal('count total (s) self (s)', lines[36]) + call assert_match('^\s*1\s\+.*\sif 0$', lines[37]) + call assert_match( '^\s\+let x = 0$', lines[38]) + call assert_match('^\s*1\s\+.*\selseif 0$', lines[39]) + call assert_match( '^\s\+let x = 1$', lines[40]) + call assert_match('^\s*1\s\+.*\selse$', lines[41]) + call assert_match('^\s*1\s\+.*\s let x = 2$', lines[42]) + call assert_match('^\s*1\s\+.*\sendif$', lines[43]) + call assert_equal('', lines[44]) + call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[45]) + call assert_equal('count total (s) self (s) function', lines[46]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[47]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[48]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[49]) + call assert_equal('', lines[50]) + call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[51]) + call assert_equal('count total (s) self (s) function', lines[52]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[53]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[54]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[55]) + call assert_equal('', lines[56]) + + call delete('Xprofile_func.vim') + call delete('Xprofile_func.log') +endfunc + +func Test_profile_func_with_trycatch() + let lines = [ + \ "func! Foo1()", + \ " try", + \ " let x = 0", + \ " catch", + \ " let x = 1", + \ " finally", + \ " let x = 2", + \ " endtry", + \ "endfunc", + \ "func! Foo2()", + \ " try", + \ " throw 0", + \ " catch", + \ " let x = 1", + \ " finally", + \ " let x = 2", + \ " endtry", + \ "endfunc", + \ "func! Foo3()", + \ " try", + \ " throw 0", + \ " catch", + \ " throw 1", + \ " finally", + \ " let x = 2", + \ " endtry", + \ "endfunc", + \ "call Foo1()", + \ "call Foo2()", + \ "try", + \ " call Foo3()", + \ "catch", + \ "endtry", + \ ] + + call writefile(lines, 'Xprofile_func.vim') + call system(v:progpath + \ . ' -es -u NONE -U NONE -i NONE --noplugin' + \ . ' -c "profile start Xprofile_func.log"' + \ . ' -c "profile func Foo*"' + \ . ' -c "so Xprofile_func.vim"' + \ . ' -c "qall!"') + call assert_equal(0, v:shell_error) + + let lines = readfile('Xprofile_func.log') + + " - Foo1() should pass 'try' 'finally' blocks. + " - Foo2() should pass 'catch' 'finally' blocks. + " - Foo3() should not pass 'endtry'. + call assert_equal(57, len(lines)) + + call assert_equal('FUNCTION Foo1()', lines[0]) + call assert_match('Defined:.*Xprofile_func.vim', lines[1]) + call assert_equal('Called 1 time', lines[2]) + call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[3]) + call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[4]) + call assert_equal('', lines[5]) + call assert_equal('count total (s) self (s)', lines[6]) + call assert_match('^\s*1\s\+.*\stry$', lines[7]) + call assert_match('^\s*1\s\+.*\s let x = 0$', lines[8]) + call assert_match( '^\s\+catch$', lines[9]) + call assert_match( '^\s\+let x = 1$', lines[10]) + call assert_match('^\s*1\s\+.*\sfinally$', lines[11]) + call assert_match('^\s*1\s\+.*\s let x = 2$', lines[12]) + call assert_match('^\s*1\s\+.*\sendtry$', lines[13]) + call assert_equal('', lines[14]) + call assert_equal('FUNCTION Foo2()', lines[15]) + call assert_equal('Called 1 time', lines[17]) + call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[18]) + call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[19]) + call assert_equal('', lines[20]) + call assert_equal('count total (s) self (s)', lines[21]) + call assert_match('^\s*1\s\+.*\stry$', lines[22]) + call assert_match('^\s*1\s\+.*\s throw 0$', lines[23]) + call assert_match('^\s*1\s\+.*\scatch$', lines[24]) + call assert_match('^\s*1\s\+.*\s let x = 1$', lines[25]) + call assert_match('^\s*1\s\+.*\sfinally$', lines[26]) + call assert_match('^\s*1\s\+.*\s let x = 2$', lines[27]) + call assert_match('^\s*1\s\+.*\sendtry$', lines[28]) + call assert_equal('', lines[29]) + call assert_equal('FUNCTION Foo3()', lines[30]) + call assert_equal('Called 1 time', lines[32]) + call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[33]) + call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[34]) + call assert_equal('', lines[35]) + call assert_equal('count total (s) self (s)', lines[36]) + call assert_match('^\s*1\s\+.*\stry$', lines[37]) + call assert_match('^\s*1\s\+.*\s throw 0$', lines[38]) + call assert_match('^\s*1\s\+.*\scatch$', lines[39]) + call assert_match('^\s*1\s\+.*\s throw 1$', lines[40]) + call assert_match('^\s*1\s\+.*\sfinally$', lines[41]) + call assert_match('^\s*1\s\+.*\s let x = 2$', lines[42]) + call assert_match( '^\s\+endtry$', lines[43]) + call assert_equal('', lines[44]) + call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[45]) + call assert_equal('count total (s) self (s) function', lines[46]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[47]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[48]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[49]) + call assert_equal('', lines[50]) + call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[51]) + call assert_equal('count total (s) self (s) function', lines[52]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[53]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[54]) + call assert_match('^\s*1\s\+\d\+\.\d\+\s\+Foo.()$', lines[55]) + call assert_equal('', lines[56]) + + call delete('Xprofile_func.vim') + call delete('Xprofile_func.log') +endfunc + +func Test_profile_file() + let lines = [ + \ 'func! Foo()', + \ 'endfunc', + \ 'for i in range(10)', + \ ' " a comment', + \ ' call Foo()', + \ 'endfor', + \ 'call Foo()', + \ ] + + call writefile(lines, 'Xprofile_file.vim') + call system(v:progpath + \ . ' -es --clean' + \ . ' -c "profile start Xprofile_file.log"' + \ . ' -c "profile file Xprofile_file.vim"' + \ . ' -c "so Xprofile_file.vim"' + \ . ' -c "so Xprofile_file.vim"' + \ . ' -c "qall!"') + call assert_equal(0, v:shell_error) + + let lines = readfile('Xprofile_file.log') + + call assert_equal(14, len(lines)) + + call assert_match('^SCRIPT .*Xprofile_file.vim$', lines[0]) + call assert_equal('Sourced 2 times', lines[1]) + call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[2]) + call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[3]) + call assert_equal('', lines[4]) + call assert_equal('count total (s) self (s)', lines[5]) + call assert_match(' 2 0.\d\+ func! Foo()', lines[6]) + call assert_equal(' endfunc', lines[7]) + " Loop iterates 10 times. Since script runs twice, body executes 20 times. + " First line of loop executes one more time than body to detect end of loop. + call assert_match('^\s*22\s\+\d\+\.\d\+\s\+for i in range(10)$', lines[8]) + call assert_equal(' " a comment', lines[9]) + " if self and total are equal we only get one number + call assert_match('^\s*20\s\+\(\d\+\.\d\+\s\+\)\=\d\+\.\d\+\s\+call Foo()$', lines[10]) + call assert_match('^\s*22\s\+\d\+\.\d\+\s\+endfor$', lines[11]) + " if self and total are equal we only get one number + call assert_match('^\s*2\s\+\(\d\+\.\d\+\s\+\)\=\d\+\.\d\+\s\+call Foo()$', lines[12]) + call assert_equal('', lines[13]) + + call delete('Xprofile_file.vim') + call delete('Xprofile_file.log') +endfunc + +func Test_profile_file_with_cont() + let lines = [ + \ 'echo "hello', + \ ' \ world"', + \ 'echo "foo ', + \ ' \bar"', + \ ] + + call writefile(lines, 'Xprofile_file.vim') + call system(v:progpath + \ . ' -es --clean' + \ . ' -c "profile start Xprofile_file.log"' + \ . ' -c "profile file Xprofile_file.vim"' + \ . ' -c "so Xprofile_file.vim"' + \ . ' -c "qall!"') + call assert_equal(0, v:shell_error) + + let lines = readfile('Xprofile_file.log') + call assert_equal(11, len(lines)) + + call assert_match('^SCRIPT .*Xprofile_file.vim$', lines[0]) + call assert_equal('Sourced 1 time', lines[1]) + call assert_match('^Total time:\s\+\d\+\.\d\+$', lines[2]) + call assert_match('^ Self time:\s\+\d\+\.\d\+$', lines[3]) + call assert_equal('', lines[4]) + call assert_equal('count total (s) self (s)', lines[5]) + call assert_match(' 1 0.\d\+ echo "hello', lines[6]) + call assert_equal(' \ world"', lines[7]) + call assert_match(' 1 0.\d\+ echo "foo ', lines[8]) + call assert_equal(' \bar"', lines[9]) + call assert_equal('', lines[10]) + + call delete('Xprofile_file.vim') + call delete('Xprofile_file.log') +endfunc + +func Test_profile_completion() + call feedkeys(":profile \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"profile continue file func pause start', @:) + + call feedkeys(":profile start test_prof\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_match('^"profile start.* test_profile\.vim', @:) +endfunc + +func Test_profile_errors() + call assert_fails("profile func Foo", 'E750:') + call assert_fails("profile pause", 'E750:') + call assert_fails("profile continue", 'E750:') +endfunc + +func Test_profile_truncate_mbyte() + if &enc !=# 'utf-8' + return + endif + + let lines = [ + \ 'scriptencoding utf-8', + \ 'func! Foo()', + \ ' return [', + \ ' \ "' . join(map(range(0x4E00, 0x4E00 + 340), 'nr2char(v:val)'), '') . '",', + \ ' \ "' . join(map(range(0x4F00, 0x4F00 + 340), 'nr2char(v:val)'), '') . '",', + \ ' \ ]', + \ 'endfunc', + \ 'call Foo()', + \ ] + + call writefile(lines, 'Xprofile_file.vim') + call system(v:progpath + \ . ' -es --clean --cmd "set enc=utf-8"' + \ . ' -c "profile start Xprofile_file.log"' + \ . ' -c "profile file Xprofile_file.vim"' + \ . ' -c "so Xprofile_file.vim"' + \ . ' -c "qall!"') + call assert_equal(0, v:shell_error) + + split Xprofile_file.log + if &fenc != '' + call assert_equal('utf-8', &fenc) + endif + /func! Foo() + let lnum = line('.') + call assert_match('^\s*return \[$', getline(lnum + 1)) + call assert_match("\u4F52$", getline(lnum + 2)) + call assert_match("\u5052$", getline(lnum + 3)) + call assert_match('^\s*\\ \]$', getline(lnum + 4)) + bwipe! + + call delete('Xprofile_file.vim') + call delete('Xprofile_file.log') +endfunc + +func Test_profdel_func() + let lines = [ + \ 'profile start Xprofile_file.log', + \ 'func! Foo1()', + \ 'endfunc', + \ 'func! Foo2()', + \ 'endfunc', + \ 'func! Foo3()', + \ 'endfunc', + \ '', + \ 'profile func Foo1', + \ 'profile func Foo2', + \ 'call Foo1()', + \ 'call Foo2()', + \ '', + \ 'profile func Foo3', + \ 'profdel func Foo2', + \ 'profdel func Foo3', + \ 'call Foo1()', + \ 'call Foo2()', + \ 'call Foo3()' ] + call writefile(lines, 'Xprofile_file.vim') + call system(v:progpath . ' -es --clean -c "so Xprofile_file.vim" -c q') + call assert_equal(0, v:shell_error) + + let lines = readfile('Xprofile_file.log') + call assert_equal(26, len(lines)) + + " Check that: + " - Foo1() is called twice (profdel not invoked) + " - Foo2() is called once (profdel invoked after it was called) + " - Foo3() is not called (profdel invoked before it was called) + call assert_equal('FUNCTION Foo1()', lines[0]) + call assert_match('Defined:.*Xprofile_file.vim', lines[1]) + call assert_equal('Called 2 times', lines[2]) + call assert_equal('FUNCTION Foo2()', lines[8]) + call assert_equal('Called 1 time', lines[10]) + call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[16]) + call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[21]) + + call delete('Xprofile_file.vim') + call delete('Xprofile_file.log') +endfunc + +func Test_profdel_star() + " Foo() is invoked once before and once after 'profdel *'. + " So profiling should report it only once. + let lines = [ + \ 'profile start Xprofile_file.log', + \ 'func! Foo()', + \ 'endfunc', + \ 'profile func Foo', + \ 'call Foo()', + \ 'profdel *', + \ 'call Foo()' ] + call writefile(lines, 'Xprofile_file.vim') + call system(v:progpath . ' -es --clean -c "so Xprofile_file.vim" -c q') + call assert_equal(0, v:shell_error) + + let lines = readfile('Xprofile_file.log') + call assert_equal(16, len(lines)) + + call assert_equal('FUNCTION Foo()', lines[0]) + call assert_match('Defined:.*Xprofile_file.vim', lines[1]) + call assert_equal('Called 1 time', lines[2]) + call assert_equal('FUNCTIONS SORTED ON TOTAL TIME', lines[8]) + call assert_equal('FUNCTIONS SORTED ON SELF TIME', lines[12]) + + call delete('Xprofile_file.vim') + call delete('Xprofile_file.log') +endfunc diff --git a/src/testdir/test_prompt_buffer.vim b/src/testdir/test_prompt_buffer.vim new file mode 100644 index 0000000..1b8a1ec --- /dev/null +++ b/src/testdir/test_prompt_buffer.vim @@ -0,0 +1,105 @@ +" Tests for setting 'buftype' to "prompt" + +if !has('channel') + finish +endif + +source shared.vim +source screendump.vim + +func CanTestPromptBuffer() + " We need to use a terminal window to be able to feed keys without leaving + " Insert mode. + if !has('terminal') + return 0 + endif + if has('win32') + " TODO: make the tests work on MS-Windows + return 0 + endif + return 1 +endfunc + +func WriteScript(name) + call writefile([ + \ 'func TextEntered(text)', + \ ' if a:text == "exit"', + \ ' " Reset &modified to allow the buffer to be closed.', + \ ' set nomodified', + \ ' stopinsert', + \ ' close', + \ ' else', + \ ' " Add the output above the current prompt.', + \ ' call append(line("$") - 1, "Command: \"" . a:text . "\"")', + \ ' " Reset &modified to allow the buffer to be closed.', + \ ' set nomodified', + \ ' call timer_start(20, {id -> TimerFunc(a:text)})', + \ ' endif', + \ 'endfunc', + \ '', + \ 'func TimerFunc(text)', + \ ' " Add the output above the current prompt.', + \ ' call append(line("$") - 1, "Result: \"" . a:text . "\"")', + \ ' " Reset &modified to allow the buffer to be closed.', + \ ' set nomodified', + \ 'endfunc', + \ '', + \ 'call setline(1, "other buffer")', + \ 'set nomodified', + \ 'new', + \ 'set buftype=prompt', + \ 'call prompt_setcallback(bufnr(""), function("TextEntered"))', + \ 'startinsert', + \ ], a:name) +endfunc + +func Test_prompt_basic() + if !CanTestPromptBuffer() + return + endif + let scriptName = 'XpromptscriptBasic' + call WriteScript(scriptName) + + let buf = RunVimInTerminal('-S ' . scriptName, {}) + call WaitForAssert({-> assert_equal('%', term_getline(buf, 1))}) + + call term_sendkeys(buf, "hello\<CR>") + call WaitForAssert({-> assert_equal('% hello', term_getline(buf, 1))}) + call WaitForAssert({-> assert_equal('Command: "hello"', term_getline(buf, 2))}) + call WaitForAssert({-> assert_equal('Result: "hello"', term_getline(buf, 3))}) + + call term_sendkeys(buf, "exit\<CR>") + call WaitForAssert({-> assert_equal('other buffer', term_getline(buf, 1))}) + + call StopVimInTerminal(buf) + call delete(scriptName) +endfunc + +func Test_prompt_editing() + if !CanTestPromptBuffer() + return + endif + let scriptName = 'XpromptscriptEditing' + call WriteScript(scriptName) + + let buf = RunVimInTerminal('-S ' . scriptName, {}) + call WaitForAssert({-> assert_equal('%', term_getline(buf, 1))}) + + let bs = "\<BS>" + call term_sendkeys(buf, "hello" . bs . bs) + call WaitForAssert({-> assert_equal('% hel', term_getline(buf, 1))}) + + let left = "\<Left>" + call term_sendkeys(buf, left . left . left . bs . '-') + call WaitForAssert({-> assert_equal('% -hel', term_getline(buf, 1))}) + + let end = "\<End>" + call term_sendkeys(buf, end . "x") + call WaitForAssert({-> assert_equal('% -helx', term_getline(buf, 1))}) + + call term_sendkeys(buf, "\<C-U>exit\<CR>") + call WaitForAssert({-> assert_equal('other buffer', term_getline(buf, 1))}) + + call StopVimInTerminal(buf) + call delete(scriptName) +endfunc diff --git a/src/testdir/test_put.vim b/src/testdir/test_put.vim new file mode 100644 index 0000000..2a9e8a3 --- /dev/null +++ b/src/testdir/test_put.vim @@ -0,0 +1,103 @@ +" Tests for put commands, e.g. ":put", "p", "gp", "P", "gP", etc. + +func Test_put_block() + new + call feedkeys("i\<C-V>u2500\<CR>x\<ESC>", 'x') + call feedkeys("\<C-V>y", 'x') + call feedkeys("gg0p", 'x') + call assert_equal("\u2500x", getline(1)) + bwipe! +endfunc + +func Test_put_char_block() + new + call setline(1, ['Line 1', 'Line 2']) + f Xfile_put + " visually select both lines and put the cursor at the top of the visual + " selection and then put the buffer name over it + exe "norm! G0\<c-v>ke\"%p" + call assert_equal(['Xfile_put 1', 'Xfile_put 2'], getline(1,2)) + bw! +endfunc + +func Test_put_char_block2() + new + let a = [ getreg('a'), getregtype('a') ] + call setreg('a', ' one ', 'v') + call setline(1, ['Line 1', '', 'Line 3', '']) + " visually select the first 3 lines and put register a over it + exe "norm! ggl\<c-v>2j2l\"ap" + call assert_equal(['L one 1', '', 'L one 3', ''], getline(1,4)) + " clean up + bw! + call setreg('a', a[0], a[1]) +endfunc + +func Test_put_lines() + new + let a = [ getreg('a'), getregtype('a') ] + call setline(1, ['Line 1', 'Line2', 'Line 3', '']) + exe 'norm! gg"add"AddG""p' + call assert_equal(['Line 3', '', 'Line 1', 'Line2'], getline(1,'$')) + " clean up + bw! + call setreg('a', a[0], a[1]) +endfunc + +func Test_put_expr() + new + call setline(1, repeat(['A'], 6)) + exec "1norm! \"=line('.')\<cr>p" + norm! j0. + norm! j0. + exec "4norm! \"=\<cr>P" + norm! j0. + norm! j0. + call assert_equal(['A1','A2','A3','4A','5A','6A'], getline(1,'$')) + bw! +endfunc + +func Test_put_fails_when_nomodifiable() + new + setlocal nomodifiable + + normal! yy + call assert_fails(':put', 'E21') + call assert_fails(':put!', 'E21') + call assert_fails(':normal! p', 'E21') + call assert_fails(':normal! gp', 'E21') + call assert_fails(':normal! P', 'E21') + call assert_fails(':normal! gP', 'E21') + + if has('mouse') + set mouse=n + call assert_fails('execute "normal! \<MiddleMouse>"', 'E21') + set mouse& + endif + + bwipeout! +endfunc + +" A bug was discovered where the Normal mode put commands (e.g., "p") would +" output duplicate error messages when invoked in a non-modifiable buffer. +func Test_put_p_errmsg_nodup() + new + setlocal nomodifiable + + normal! yy + + func Capture_p_error() + redir => s:p_err + normal! p + redir END + endfunc + + silent! call Capture_p_error() + + " Error message output within a function should be three lines (the function + " name, the line number, and the error message). + call assert_equal(3, count(s:p_err, "\n")) + + delfunction Capture_p_error + bwipeout! +endfunc diff --git a/src/testdir/test_python2.vim b/src/testdir/test_python2.vim new file mode 100644 index 0000000..d79400d --- /dev/null +++ b/src/testdir/test_python2.vim @@ -0,0 +1,65 @@ +" Test for python 2 commands. +" TODO: move tests from test87.in here. + +if !has('python') + finish +endif + +func Test_pydo() + " Check deleting lines does not trigger ml_get error. + py import vim + new + call setline(1, ['one', 'two', 'three']) + pydo vim.command("%d_") + bwipe! + + " Check switching to another buffer does not trigger ml_get error. + new + let wincount = winnr('$') + call setline(1, ['one', 'two', 'three']) + pydo vim.command("new") + call assert_equal(wincount + 1, winnr('$')) + bwipe! + bwipe! +endfunc + +func Test_set_cursor() + " Check that setting the cursor position works. + py import vim + new + call setline(1, ['first line', 'second line']) + normal gg + pydo vim.current.window.cursor = (1, 5) + call assert_equal([1, 6], [line('.'), col('.')]) + + " Check that movement after setting cursor position keeps current column. + normal j + call assert_equal([2, 6], [line('.'), col('.')]) +endfunc + +func Test_vim_function() + " Check creating vim.Function object + py import vim + + func s:foo() + return matchstr(expand('<sfile>'), '<SNR>\zs\d\+_foo$') + endfunc + let name = '<SNR>' . s:foo() + + try + py f = vim.bindeval('function("s:foo")') + call assert_equal(name, pyeval('f.name')) + catch + call assert_false(v:exception) + endtry + + try + py f = vim.Function('\x80\xfdR' + vim.eval('s:foo()')) + call assert_equal(name, pyeval('f.name')) + catch + call assert_false(v:exception) + endtry + + py del f + delfunc s:foo +endfunc diff --git a/src/testdir/test_python3.vim b/src/testdir/test_python3.vim new file mode 100644 index 0000000..344034a --- /dev/null +++ b/src/testdir/test_python3.vim @@ -0,0 +1,65 @@ +" Test for python 3 commands. +" TODO: move tests from test88.in here. + +if !has('python3') + finish +endif + +func Test_py3do() + " Check deleting lines does not trigger an ml_get error. + py3 import vim + new + call setline(1, ['one', 'two', 'three']) + py3do vim.command("%d_") + bwipe! + + " Check switching to another buffer does not trigger an ml_get error. + new + let wincount = winnr('$') + call setline(1, ['one', 'two', 'three']) + py3do vim.command("new") + call assert_equal(wincount + 1, winnr('$')) + bwipe! + bwipe! +endfunc + +func Test_set_cursor() + " Check that setting the cursor position works. + py3 import vim + new + call setline(1, ['first line', 'second line']) + normal gg + py3do vim.current.window.cursor = (1, 5) + call assert_equal([1, 6], [line('.'), col('.')]) + + " Check that movement after setting cursor position keeps current column. + normal j + call assert_equal([2, 6], [line('.'), col('.')]) +endfunc + +func Test_vim_function() + " Check creating vim.Function object + py3 import vim + + func s:foo() + return matchstr(expand('<sfile>'), '<SNR>\zs\d\+_foo$') + endfunc + let name = '<SNR>' . s:foo() + + try + py3 f = vim.bindeval('function("s:foo")') + call assert_equal(name, py3eval('f.name')) + catch + call assert_false(v:exception) + endtry + + try + py3 f = vim.Function(b'\x80\xfdR' + vim.eval('s:foo()').encode()) + call assert_equal(name, py3eval('f.name')) + catch + call assert_false(v:exception) + endtry + + py3 del f + delfunc s:foo +endfunc diff --git a/src/testdir/test_pyx2.vim b/src/testdir/test_pyx2.vim new file mode 100644 index 0000000..50e57c3 --- /dev/null +++ b/src/testdir/test_pyx2.vim @@ -0,0 +1,74 @@ +" Test for pyx* commands and functions with Python 2. + +set pyx=2 +if !has('python') + finish +endif + +let s:py2pattern = '^2\.[0-7]\.\d\+' +let s:py3pattern = '^3\.\d\+\.\d\+' + + +func Test_has_pythonx() + call assert_true(has('pythonx')) +endfunc + + +func Test_pyx() + redir => var + pyx << EOF +import sys +print(sys.version) +EOF + redir END + call assert_match(s:py2pattern, split(var)[0]) +endfunc + + +func Test_pyxdo() + pyx import sys + enew + pyxdo return sys.version.split("\n")[0] + call assert_match(s:py2pattern, split(getline('.'))[0]) +endfunc + + +func Test_pyxeval() + pyx import sys + call assert_match(s:py2pattern, split(pyxeval('sys.version'))[0]) +endfunc + + +func Test_pyxfile() + " No special comments nor shebangs + redir => var + pyxfile pyxfile/pyx.py + redir END + call assert_match(s:py2pattern, split(var)[0]) + + " Python 2 special comment + redir => var + pyxfile pyxfile/py2_magic.py + redir END + call assert_match(s:py2pattern, split(var)[0]) + + " Python 2 shebang + redir => var + pyxfile pyxfile/py2_shebang.py + redir END + call assert_match(s:py2pattern, split(var)[0]) + + if has('python3') + " Python 3 special comment + redir => var + pyxfile pyxfile/py3_magic.py + redir END + call assert_match(s:py3pattern, split(var)[0]) + + " Python 3 shebang + redir => var + pyxfile pyxfile/py3_shebang.py + redir END + call assert_match(s:py3pattern, split(var)[0]) + endif +endfunc diff --git a/src/testdir/test_pyx3.vim b/src/testdir/test_pyx3.vim new file mode 100644 index 0000000..64546b4 --- /dev/null +++ b/src/testdir/test_pyx3.vim @@ -0,0 +1,74 @@ +" Test for pyx* commands and functions with Python 3. + +set pyx=3 +if !has('python3') + finish +endif + +let s:py2pattern = '^2\.[0-7]\.\d\+' +let s:py3pattern = '^3\.\d\+\.\d\+' + + +func Test_has_pythonx() + call assert_true(has('pythonx')) +endfunc + + +func Test_pyx() + redir => var + pyx << EOF +import sys +print(sys.version) +EOF + redir END + call assert_match(s:py3pattern, split(var)[0]) +endfunc + + +func Test_pyxdo() + pyx import sys + enew + pyxdo return sys.version.split("\n")[0] + call assert_match(s:py3pattern, split(getline('.'))[0]) +endfunc + + +func Test_pyxeval() + pyx import sys + call assert_match(s:py3pattern, split(pyxeval('sys.version'))[0]) +endfunc + + +func Test_pyxfile() + " No special comments nor shebangs + redir => var + pyxfile pyxfile/pyx.py + redir END + call assert_match(s:py3pattern, split(var)[0]) + + " Python 3 special comment + redir => var + pyxfile pyxfile/py3_magic.py + redir END + call assert_match(s:py3pattern, split(var)[0]) + + " Python 3 shebang + redir => var + pyxfile pyxfile/py3_shebang.py + redir END + call assert_match(s:py3pattern, split(var)[0]) + + if has('python') + " Python 2 special comment + redir => var + pyxfile pyxfile/py2_magic.py + redir END + call assert_match(s:py2pattern, split(var)[0]) + + " Python 2 shebang + redir => var + pyxfile pyxfile/py2_shebang.py + redir END + call assert_match(s:py2pattern, split(var)[0]) + endif +endfunc diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim new file mode 100644 index 0000000..e7aa41e --- /dev/null +++ b/src/testdir/test_quickfix.vim @@ -0,0 +1,3901 @@ +" Test for the quickfix commands. + +if !has('quickfix') + finish +endif + +set encoding=utf-8 + +func s:setup_commands(cchar) + if a:cchar == 'c' + command! -nargs=* -bang Xlist <mods>clist<bang> <args> + command! -nargs=* Xgetexpr <mods>cgetexpr <args> + command! -nargs=* Xaddexpr <mods>caddexpr <args> + command! -nargs=* -count Xolder <mods><count>colder <args> + command! -nargs=* Xnewer <mods>cnewer <args> + command! -nargs=* Xopen <mods>copen <args> + command! -nargs=* Xwindow <mods>cwindow <args> + command! -nargs=* Xbottom <mods>cbottom <args> + command! -nargs=* Xclose <mods>cclose <args> + command! -nargs=* -bang Xfile <mods>cfile<bang> <args> + command! -nargs=* Xgetfile <mods>cgetfile <args> + command! -nargs=* Xaddfile <mods>caddfile <args> + command! -nargs=* -bang Xbuffer <mods>cbuffer<bang> <args> + command! -nargs=* Xgetbuffer <mods>cgetbuffer <args> + command! -nargs=* Xaddbuffer <mods>caddbuffer <args> + command! -nargs=* Xrewind <mods>crewind <args> + command! -count -nargs=* -bang Xnext <mods><count>cnext<bang> <args> + command! -count -nargs=* -bang Xprev <mods><count>cprev<bang> <args> + command! -nargs=* -bang Xfirst <mods>cfirst<bang> <args> + command! -nargs=* -bang Xlast <mods>clast<bang> <args> + command! -nargs=* -bang -range Xnfile <mods><count>cnfile<bang> <args> + command! -nargs=* -bang Xpfile <mods>cpfile<bang> <args> + command! -nargs=* Xexpr <mods>cexpr <args> + command! -range -nargs=* Xvimgrep <mods><count>vimgrep <args> + command! -nargs=* Xvimgrepadd <mods>vimgrepadd <args> + command! -nargs=* Xgrep <mods> grep <args> + command! -nargs=* Xgrepadd <mods> grepadd <args> + command! -nargs=* Xhelpgrep helpgrep <args> + command! -nargs=0 -count Xcc <count>cc + let g:Xgetlist = function('getqflist') + let g:Xsetlist = function('setqflist') + call setqflist([], 'f') + else + command! -nargs=* -bang Xlist <mods>llist<bang> <args> + command! -nargs=* Xgetexpr <mods>lgetexpr <args> + command! -nargs=* Xaddexpr <mods>laddexpr <args> + command! -nargs=* -count Xolder <mods><count>lolder <args> + command! -nargs=* Xnewer <mods>lnewer <args> + command! -nargs=* Xopen <mods>lopen <args> + command! -nargs=* Xwindow <mods>lwindow <args> + command! -nargs=* Xbottom <mods>lbottom <args> + command! -nargs=* Xclose <mods>lclose <args> + command! -nargs=* -bang Xfile <mods>lfile<bang> <args> + command! -nargs=* Xgetfile <mods>lgetfile <args> + command! -nargs=* Xaddfile <mods>laddfile <args> + command! -nargs=* -bang Xbuffer <mods>lbuffer<bang> <args> + command! -nargs=* Xgetbuffer <mods>lgetbuffer <args> + command! -nargs=* Xaddbuffer <mods>laddbuffer <args> + command! -nargs=* Xrewind <mods>lrewind <args> + command! -count -nargs=* -bang Xnext <mods><count>lnext<bang> <args> + command! -count -nargs=* -bang Xprev <mods><count>lprev<bang> <args> + command! -nargs=* -bang Xfirst <mods>lfirst<bang> <args> + command! -nargs=* -bang Xlast <mods>llast<bang> <args> + command! -nargs=* -bang -range Xnfile <mods><count>lnfile<bang> <args> + command! -nargs=* -bang Xpfile <mods>lpfile<bang> <args> + command! -nargs=* Xexpr <mods>lexpr <args> + command! -range -nargs=* Xvimgrep <mods><count>lvimgrep <args> + command! -nargs=* Xvimgrepadd <mods>lvimgrepadd <args> + command! -nargs=* Xgrep <mods> lgrep <args> + command! -nargs=* Xgrepadd <mods> lgrepadd <args> + command! -nargs=* Xhelpgrep lhelpgrep <args> + command! -nargs=0 -count Xcc <count>ll + let g:Xgetlist = function('getloclist', [0]) + let g:Xsetlist = function('setloclist', [0]) + call setloclist(0, [], 'f') + endif +endfunc + +" Tests for the :clist and :llist commands +func XlistTests(cchar) + call s:setup_commands(a:cchar) + + if a:cchar == 'l' + call assert_fails('llist', 'E776:') + endif + " With an empty list, command should return error + Xgetexpr [] + silent! Xlist + call assert_true(v:errmsg ==# 'E42: No Errors') + + " Populate the list and then try + Xgetexpr ['non-error 1', 'Xtestfile1:1:3:Line1', + \ 'non-error 2', 'Xtestfile2:2:2:Line2', + \ 'non-error 3', 'Xtestfile3:3:1:Line3'] + + " List only valid entries + let l = split(execute('Xlist', ''), "\n") + call assert_equal([' 2 Xtestfile1:1 col 3: Line1', + \ ' 4 Xtestfile2:2 col 2: Line2', + \ ' 6 Xtestfile3:3 col 1: Line3'], l) + + " List all the entries + let l = split(execute('Xlist!', ''), "\n") + call assert_equal([' 1: non-error 1', ' 2 Xtestfile1:1 col 3: Line1', + \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2', + \ ' 5: non-error 3', ' 6 Xtestfile3:3 col 1: Line3'], l) + + " List a range of errors + let l = split(execute('Xlist 3,6', ''), "\n") + call assert_equal([' 4 Xtestfile2:2 col 2: Line2', + \ ' 6 Xtestfile3:3 col 1: Line3'], l) + + let l = split(execute('Xlist! 3,4', ''), "\n") + call assert_equal([' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l) + + let l = split(execute('Xlist -6,-4', ''), "\n") + call assert_equal([' 2 Xtestfile1:1 col 3: Line1'], l) + + let l = split(execute('Xlist! -5,-3', ''), "\n") + call assert_equal([' 2 Xtestfile1:1 col 3: Line1', + \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l) + + " Test for '+' + let l = split(execute('Xlist! +2', ''), "\n") + call assert_equal([' 2 Xtestfile1:1 col 3: Line1', + \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l) + + " Different types of errors + call g:Xsetlist([{'lnum':10,'col':5,'type':'W', 'text':'Warning','nr':11}, + \ {'lnum':20,'col':10,'type':'e','text':'Error','nr':22}, + \ {'lnum':30,'col':15,'type':'i','text':'Info','nr':33}, + \ {'lnum':40,'col':20,'type':'x', 'text':'Other','nr':44}, + \ {'lnum':50,'col':25,'type':"\<C-A>",'text':'one','nr':55}]) + let l = split(execute('Xlist', ""), "\n") + call assert_equal([' 1:10 col 5 warning 11: Warning', + \ ' 2:20 col 10 error 22: Error', + \ ' 3:30 col 15 info 33: Info', + \ ' 4:40 col 20 x 44: Other', + \ ' 5:50 col 25 55: one'], l) + + " Test for module names, one needs to explicitly set `'valid':v:true` so + call g:Xsetlist([ + \ {'lnum':10,'col':5,'type':'W','module':'Data.Text','text':'ModuleWarning','nr':11,'valid':v:true}, + \ {'lnum':20,'col':10,'type':'W','module':'Data.Text','filename':'Data/Text.hs','text':'ModuleWarning','nr':22,'valid':v:true}, + \ {'lnum':30,'col':15,'type':'W','filename':'Data/Text.hs','text':'FileWarning','nr':33,'valid':v:true}]) + let l = split(execute('Xlist', ""), "\n") + call assert_equal([' 1 Data.Text:10 col 5 warning 11: ModuleWarning', + \ ' 2 Data.Text:20 col 10 warning 22: ModuleWarning', + \ ' 3 Data/Text.hs:30 col 15 warning 33: FileWarning'], l) + + " Error cases + call assert_fails('Xlist abc', 'E488:') +endfunc + +func Test_clist() + call XlistTests('c') + call XlistTests('l') +endfunc + +" Tests for the :colder, :cnewer, :lolder and :lnewer commands +" Note that this test assumes that a quickfix/location list is +" already set by the caller. +func XageTests(cchar) + call s:setup_commands(a:cchar) + + let list = [{'bufnr': bufnr('%'), 'lnum': 1}] + call g:Xsetlist(list) + + " Jumping to a non existent list should return error + silent! Xolder 99 + call assert_true(v:errmsg ==# 'E380: At bottom of quickfix stack') + + silent! Xnewer 99 + call assert_true(v:errmsg ==# 'E381: At top of quickfix stack') + + " Add three quickfix/location lists + Xgetexpr ['Xtestfile1:1:3:Line1'] + Xgetexpr ['Xtestfile2:2:2:Line2'] + Xgetexpr ['Xtestfile3:3:1:Line3'] + + " Go back two lists + Xolder + let l = g:Xgetlist() + call assert_equal('Line2', l[0].text) + + " Go forward two lists + Xnewer + let l = g:Xgetlist() + call assert_equal('Line3', l[0].text) + + " Test for the optional count argument + Xolder 2 + let l = g:Xgetlist() + call assert_equal('Line1', l[0].text) + + Xnewer 2 + let l = g:Xgetlist() + call assert_equal('Line3', l[0].text) +endfunc + +func Test_cage() + call XageTests('c') + call XageTests('l') +endfunc + +" Tests for the :cwindow, :lwindow :cclose, :lclose, :copen and :lopen +" commands +func XwindowTests(cchar) + call s:setup_commands(a:cchar) + + " Opening the location list window without any errors should fail + if a:cchar == 'l' + call assert_fails('lopen', 'E776:') + endif + + " Create a list with no valid entries + Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3'] + + " Quickfix/Location window should not open with no valid errors + Xwindow + call assert_true(winnr('$') == 1) + + " Create a list with valid entries + Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2', + \ 'Xtestfile3:3:1:Line3'] + + " Open the window + Xwindow + call assert_true(winnr('$') == 2 && winnr() == 2 && + \ getline('.') ==# 'Xtestfile1|1 col 3| Line1') + redraw! + + " Close the window + Xclose + call assert_true(winnr('$') == 1) + + " Create a list with no valid entries + Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3'] + + " Open the window + Xopen 5 + call assert_true(winnr('$') == 2 && getline('.') ==# '|| non-error 1' + \ && winheight('.') == 5) + + " Opening the window again, should move the cursor to that window + wincmd t + Xopen 7 + call assert_true(winnr('$') == 2 && winnr() == 2 && + \ winheight('.') == 7 && + \ getline('.') ==# '|| non-error 1') + + + " Calling cwindow should close the quickfix window with no valid errors + Xwindow + call assert_true(winnr('$') == 1) + + if a:cchar == 'c' + " Opening the quickfix window in multiple tab pages should reuse the + " quickfix buffer + Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2', + \ 'Xtestfile3:3:1:Line3'] + Xopen + let qfbufnum = bufnr('%') + tabnew + Xopen + call assert_equal(qfbufnum, bufnr('%')) + new | only | tabonly + endif +endfunc + +func Test_cwindow() + call XwindowTests('c') + call XwindowTests('l') +endfunc + +" Tests for the :cfile, :lfile, :caddfile, :laddfile, :cgetfile and :lgetfile +" commands. +func XfileTests(cchar) + call s:setup_commands(a:cchar) + + call writefile(['Xtestfile1:700:10:Line 700', + \ 'Xtestfile2:800:15:Line 800'], 'Xqftestfile1') + + enew! + Xfile Xqftestfile1 + let l = g:Xgetlist() + call assert_true(len(l) == 2 && + \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' && + \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800') + + " Test with a non existent file + call assert_fails('Xfile non_existent_file', 'E40') + + " Run cfile/lfile from a modified buffer + enew! + silent! put ='Quickfix' + silent! Xfile Xqftestfile1 + call assert_true(v:errmsg ==# 'E37: No write since last change (add ! to override)') + + call writefile(['Xtestfile3:900:30:Line 900'], 'Xqftestfile1') + Xaddfile Xqftestfile1 + let l = g:Xgetlist() + call assert_true(len(l) == 3 && + \ l[2].lnum == 900 && l[2].col == 30 && l[2].text ==# 'Line 900') + + call writefile(['Xtestfile1:222:77:Line 222', + \ 'Xtestfile2:333:88:Line 333'], 'Xqftestfile1') + + enew! + Xgetfile Xqftestfile1 + let l = g:Xgetlist() + call assert_true(len(l) == 2 && + \ l[0].lnum == 222 && l[0].col == 77 && l[0].text ==# 'Line 222' && + \ l[1].lnum == 333 && l[1].col == 88 && l[1].text ==# 'Line 333') + + call delete('Xqftestfile1') +endfunc + +func Test_cfile() + call XfileTests('c') + call XfileTests('l') +endfunc + +" Tests for the :cbuffer, :lbuffer, :caddbuffer, :laddbuffer, :cgetbuffer and +" :lgetbuffer commands. +func XbufferTests(cchar) + call s:setup_commands(a:cchar) + + enew! + silent! call setline(1, ['Xtestfile7:700:10:Line 700', + \ 'Xtestfile8:800:15:Line 800']) + Xbuffer! + let l = g:Xgetlist() + call assert_true(len(l) == 2 && + \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' && + \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800') + + enew! + silent! call setline(1, ['Xtestfile9:900:55:Line 900', + \ 'Xtestfile10:950:66:Line 950']) + Xgetbuffer + let l = g:Xgetlist() + call assert_true(len(l) == 2 && + \ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900' && + \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950') + + enew! + silent! call setline(1, ['Xtestfile11:700:20:Line 700', + \ 'Xtestfile12:750:25:Line 750']) + Xaddbuffer + let l = g:Xgetlist() + call assert_true(len(l) == 4 && + \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950' && + \ l[2].lnum == 700 && l[2].col == 20 && l[2].text ==# 'Line 700' && + \ l[3].lnum == 750 && l[3].col == 25 && l[3].text ==# 'Line 750') + enew! + + " Check for invalid buffer + call assert_fails('Xbuffer 199', 'E474:') + + " Check for unloaded buffer + edit Xtestfile1 + let bnr = bufnr('%') + enew! + call assert_fails('Xbuffer ' . bnr, 'E681:') + + " Check for invalid range + " Using Xbuffer will not run the range check in the cbuffer/lbuffer + " commands. So directly call the commands. + if (a:cchar == 'c') + call assert_fails('900,999cbuffer', 'E16:') + else + call assert_fails('900,999lbuffer', 'E16:') + endif +endfunc + +func Test_cbuffer() + call XbufferTests('c') + call XbufferTests('l') +endfunc + +func XexprTests(cchar) + call s:setup_commands(a:cchar) + + call assert_fails('Xexpr 10', 'E777:') +endfunc + +func Test_cexpr() + call XexprTests('c') + call XexprTests('l') +endfunc + +" Tests for :cnext, :cprev, :cfirst, :clast commands +func Xtest_browse(cchar) + call s:setup_commands(a:cchar) + + call g:Xsetlist([], 'f') + " Jumping to first or next location list entry without any error should + " result in failure + if a:cchar == 'c' + let err = 'E42:' + else + let err = 'E776:' + endif + call assert_fails('Xnext', err) + call assert_fails('Xprev', err) + call assert_fails('Xnfile', err) + call assert_fails('Xpfile', err) + + call s:create_test_file('Xqftestfile1') + call s:create_test_file('Xqftestfile2') + + Xgetexpr ['Xqftestfile1:5:Line5', + \ 'Xqftestfile1:6:Line6', + \ 'Xqftestfile2:10:Line10', + \ 'Xqftestfile2:11:Line11', + \ 'RegularLine1', + \ 'RegularLine2'] + + Xfirst + call assert_fails('Xprev', 'E553') + call assert_fails('Xpfile', 'E553') + Xnfile + call assert_equal('Xqftestfile2', bufname('%')) + call assert_equal(10, line('.')) + Xpfile + call assert_equal('Xqftestfile1', bufname('%')) + call assert_equal(6, line('.')) + 5Xcc + call assert_equal(5, g:Xgetlist({'idx':0}).idx) + 2Xcc + call assert_equal(2, g:Xgetlist({'idx':0}).idx) + 10Xcc + call assert_equal(6, g:Xgetlist({'idx':0}).idx) + Xlast + Xprev + call assert_equal('Xqftestfile2', bufname('%')) + call assert_equal(11, line('.')) + call assert_fails('Xnext', 'E553') + call assert_fails('Xnfile', 'E553') + Xrewind + call assert_equal('Xqftestfile1', bufname('%')) + call assert_equal(5, line('.')) + + 10Xnext + call assert_equal('Xqftestfile2', bufname('%')) + call assert_equal(11, line('.')) + 10Xprev + call assert_equal('Xqftestfile1', bufname('%')) + call assert_equal(5, line('.')) + + " Jumping to an error from the error window using cc command + Xgetexpr ['Xqftestfile1:5:Line5', + \ 'Xqftestfile1:6:Line6', + \ 'Xqftestfile2:10:Line10', + \ 'Xqftestfile2:11:Line11'] + Xopen + 10Xcc + call assert_equal(11, line('.')) + call assert_equal('Xqftestfile2', bufname('%')) + + " Jumping to an error from the error window (when only the error window is + " present) + Xopen | only + Xlast 1 + call assert_equal(5, line('.')) + call assert_equal('Xqftestfile1', bufname('%')) + + Xexpr "" + call assert_fails('Xnext', 'E42:') + + call delete('Xqftestfile1') + call delete('Xqftestfile2') + + " Should be able to use next/prev with invalid entries + Xexpr "" + call assert_equal(0, g:Xgetlist({'idx' : 0}).idx) + call assert_equal(0, g:Xgetlist({'size' : 0}).size) + Xaddexpr ['foo', 'bar', 'baz', 'quux', 'shmoo'] + call assert_equal(5, g:Xgetlist({'size' : 0}).size) + Xlast + call assert_equal(5, g:Xgetlist({'idx' : 0}).idx) + Xfirst + call assert_equal(1, g:Xgetlist({'idx' : 0}).idx) + 2Xnext + call assert_equal(3, g:Xgetlist({'idx' : 0}).idx) +endfunc + +func Test_browse() + call Xtest_browse('c') + call Xtest_browse('l') +endfunc + +func Test_nomem() + call test_alloc_fail(GetAllocId('qf_dirname_start'), 0, 0) + call assert_fails('vimgrep vim runtest.vim', 'E342:') + + call test_alloc_fail(GetAllocId('qf_dirname_now'), 0, 0) + call assert_fails('vimgrep vim runtest.vim', 'E342:') + + call test_alloc_fail(GetAllocId('qf_namebuf'), 0, 0) + call assert_fails('cfile runtest.vim', 'E342:') + + call test_alloc_fail(GetAllocId('qf_errmsg'), 0, 0) + call assert_fails('cfile runtest.vim', 'E342:') + + call test_alloc_fail(GetAllocId('qf_pattern'), 0, 0) + call assert_fails('cfile runtest.vim', 'E342:') + +endfunc + +func s:test_xhelpgrep(cchar) + call s:setup_commands(a:cchar) + Xhelpgrep quickfix + Xopen + if a:cchar == 'c' + let title_text = ':helpgrep quickfix' + else + let title_text = ':lhelpgrep quickfix' + endif + call assert_true(w:quickfix_title =~ title_text, w:quickfix_title) + + " Jumping to a help topic should open the help window + only + Xnext + call assert_true(&buftype == 'help') + call assert_true(winnr('$') == 2) + " Jumping to the next match should reuse the help window + Xnext + call assert_true(&buftype == 'help') + call assert_true(winnr() == 1) + call assert_true(winnr('$') == 2) + " Jumping to the next match from the quickfix window should reuse the help + " window + Xopen + Xnext + call assert_true(&buftype == 'help') + call assert_true(winnr() == 1) + call assert_true(winnr('$') == 2) + + " This wipes out the buffer, make sure that doesn't cause trouble. + Xclose + + if a:cchar == 'l' + " When a help window is present, running :lhelpgrep should reuse the + " help window and not the current window + new | only + call g:Xsetlist([], 'f') + help index.txt + wincmd w + lhelpgrep quickfix + call assert_equal(1, winnr()) + call assert_notequal([], getloclist(1)) + call assert_equal([], getloclist(2)) + endif + + new | only + + " Search for non existing help string + call assert_fails('Xhelpgrep a1b2c3', 'E480:') + " Invalid regular expression + call assert_fails('Xhelpgrep \@<!', 'E480:') +endfunc + +func Test_helpgrep() + call s:test_xhelpgrep('c') + helpclose + call s:test_xhelpgrep('l') +endfunc + +func Test_errortitle() + augroup QfBufWinEnter + au! + au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE') + augroup END + copen + let a=[{'lnum': 308, 'bufnr': bufnr(''), 'col': 58, 'valid': 1, 'vcol': 0, 'nr': 0, 'type': '', 'pattern': '', 'text': ' au BufWinEnter * :let g:a=get(w:, ''quickfix_title'', ''NONE'')'}] + call setqflist(a) + call assert_equal(':setqflist()', g:a) + augroup QfBufWinEnter + au! + augroup END + augroup! QfBufWinEnter +endfunc + +func Test_vimgreptitle() + augroup QfBufWinEnter + au! + au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE') + augroup END + try + vimgrep /pattern/j file + catch /E480/ + endtry + copen + call assert_equal(': vimgrep /pattern/j file', g:a) + augroup QfBufWinEnter + au! + augroup END + augroup! QfBufWinEnter +endfunc + +func XqfTitleTests(cchar) + call s:setup_commands(a:cchar) + + Xgetexpr ['file:1:1:message'] + let l = g:Xgetlist() + if a:cchar == 'c' + call setqflist(l, 'r') + else + call setloclist(0, l, 'r') + endif + + Xopen + if a:cchar == 'c' + let title = ':setqflist()' + else + let title = ':setloclist()' + endif + call assert_equal(title, w:quickfix_title) + Xclose +endfunc + +" Tests for quickfix window's title +func Test_qf_title() + call XqfTitleTests('c') + call XqfTitleTests('l') +endfunc + +" Tests for 'errorformat' +func Test_efm() + let save_efm = &efm + set efm=%EEEE%m,%WWWW%m,%+CCCC%.%#,%-GGGG%.%# + cgetexpr ['WWWW', 'EEEE', 'CCCC'] + let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]'))) + call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l) + cgetexpr ['WWWW', 'GGGG', 'EEEE', 'CCCC'] + let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]'))) + call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l) + cgetexpr ['WWWW', 'GGGG', 'ZZZZ', 'EEEE', 'CCCC', 'YYYY'] + let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]'))) + call assert_equal("[['W', 1], ['ZZZZ', 0], ['E^@CCCC', 1], ['YYYY', 0]]", l) + let &efm = save_efm +endfunc + +" This will test for problems in quickfix: +" A. incorrectly copying location lists which caused the location list to show +" a different name than the file that was actually being displayed. +" B. not reusing the window for which the location list window is opened but +" instead creating new windows. +" C. make sure that the location list window is not reused instead of the +" window it belongs to. +" +" Set up the test environment: +func ReadTestProtocol(name) + let base = substitute(a:name, '\v^test://(.*)%(\.[^.]+)?', '\1', '') + let word = substitute(base, '\v(.*)\..*', '\1', '') + + setl modifiable + setl noreadonly + setl noswapfile + setl bufhidden=delete + %del _ + " For problem 2: + " 'buftype' has to be set to reproduce the constant opening of new windows + setl buftype=nofile + + call setline(1, word) + + setl nomodified + setl nomodifiable + setl readonly + exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '') +endfunc + +func Test_locationlist() + enew + + augroup testgroup + au! + autocmd BufReadCmd test://* call ReadTestProtocol(expand("<amatch>")) + augroup END + + let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ] + + let qflist = [] + for word in words + call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', }) + " NOTE: problem 1: + " intentionally not setting 'lnum' so that the quickfix entries are not + " valid + call setloclist(0, qflist, ' ') + endfor + + " Test A + lrewind + enew + lopen + 4lnext + vert split + wincmd L + lopen + wincmd p + lnext + let fileName = expand("%") + wincmd p + let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '') + let fileName = substitute(fileName, '\\', '/', 'g') + let locationListFileName = substitute(locationListFileName, '\\', '/', 'g') + call assert_equal("test://bar.txt", fileName) + call assert_equal("test://bar.txt", locationListFileName) + + wincmd n | only + + " Test B: + lrewind + lopen + 2 + exe "normal \<CR>" + wincmd p + 3 + exe "normal \<CR>" + wincmd p + 4 + exe "normal \<CR>" + call assert_equal(2, winnr('$')) + wincmd n | only + + " Test C: + lrewind + lopen + " Let's move the location list window to the top to check whether it (the + " first window found) will be reused when we try to open new windows: + wincmd K + 2 + exe "normal \<CR>" + wincmd p + 3 + exe "normal \<CR>" + wincmd p + 4 + exe "normal \<CR>" + 1wincmd w + call assert_equal('quickfix', &buftype) + 2wincmd w + let bufferName = expand("%") + let bufferName = substitute(bufferName, '\\', '/', 'g') + call assert_equal('test://quux.txt', bufferName) + + wincmd n | only + + augroup! testgroup +endfunc + +func Test_locationlist_curwin_was_closed() + augroup testgroup + au! + autocmd BufReadCmd test_curwin.txt call R(expand("<amatch>")) + augroup END + + func! R(n) + quit + endfunc + + new + let q = [] + call add(q, {'filename': 'test_curwin.txt' }) + call setloclist(0, q) + call assert_fails('lrewind', 'E924:') + + augroup! testgroup +endfunc + +func Test_locationlist_cross_tab_jump() + call writefile(['loclistfoo'], 'loclistfoo') + call writefile(['loclistbar'], 'loclistbar') + set switchbuf=usetab + + edit loclistfoo + tabedit loclistbar + silent lgrep loclistfoo loclist* + call assert_equal(1, tabpagenr()) + + enew | only | tabonly + set switchbuf&vim + call delete('loclistfoo') + call delete('loclistbar') +endfunc + +" More tests for 'errorformat' +func Test_efm1() + if !has('unix') + " The 'errorformat' setting is different on non-Unix systems. + " This test works only on Unix-like systems. + return + endif + + let l = [ + \ '"Xtestfile", line 4.12: 1506-045 (S) Undeclared identifier fd_set.', + \ '"Xtestfile", line 6 col 19; this is an error', + \ 'gcc -c -DHAVE_CONFIsing-prototypes -I/usr/X11R6/include version.c', + \ 'Xtestfile:9: parse error before `asd''', + \ 'make: *** [vim] Error 1', + \ 'in file "Xtestfile" linenr 10: there is an error', + \ '', + \ '2 returned', + \ '"Xtestfile", line 11 col 1; this is an error', + \ '"Xtestfile", line 12 col 2; this is another error', + \ '"Xtestfile", line 14:10; this is an error in column 10', + \ '=Xtestfile=, line 15:10; this is another error, but in vcol 10 this time', + \ '"Xtestfile", linenr 16: yet another problem', + \ 'Error in "Xtestfile" at line 17:', + \ 'x should be a dot', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17', + \ ' ^', + \ 'Error in "Xtestfile" at line 18:', + \ 'x should be a dot', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18', + \ '.............^', + \ 'Error in "Xtestfile" at line 19:', + \ 'x should be a dot', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19', + \ '--------------^', + \ 'Error in "Xtestfile" at line 20:', + \ 'x should be a dot', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20', + \ ' ^', + \ '', + \ 'Does anyone know what is the problem and how to correction it?', + \ '"Xtestfile", line 21 col 9: What is the title of the quickfix window?', + \ '"Xtestfile", line 22 col 9: What is the title of the quickfix window?' + \ ] + + call writefile(l, 'Xerrorfile1') + call writefile(l[:-2], 'Xerrorfile2') + + let m = [ + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 2', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 3', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 4', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 5', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 6', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 7', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 8', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 9', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 10', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 11', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 12', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 13', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 14', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 15', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 16', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 21', + \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 22' + \ ] + call writefile(m, 'Xtestfile') + + let save_efm = &efm + set efm+==%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m + set efm^=%AError\ in\ \"%f\"\ at\ line\ %l:,%Z%p^,%C%m + + exe 'cf Xerrorfile2' + clast + copen + call assert_equal(':cf Xerrorfile2', w:quickfix_title) + wincmd p + + exe 'cf Xerrorfile1' + call assert_equal([4, 12], [line('.'), col('.')]) + cn + call assert_equal([6, 19], [line('.'), col('.')]) + cn + call assert_equal([9, 2], [line('.'), col('.')]) + cn + call assert_equal([10, 2], [line('.'), col('.')]) + cn + call assert_equal([11, 1], [line('.'), col('.')]) + cn + call assert_equal([12, 2], [line('.'), col('.')]) + cn + call assert_equal([14, 10], [line('.'), col('.')]) + cn + call assert_equal([15, 3, 10], [line('.'), col('.'), virtcol('.')]) + cn + call assert_equal([16, 2], [line('.'), col('.')]) + cn + call assert_equal([17, 6], [line('.'), col('.')]) + cn + call assert_equal([18, 7], [line('.'), col('.')]) + cn + call assert_equal([19, 8], [line('.'), col('.')]) + cn + call assert_equal([20, 9], [line('.'), col('.')]) + clast + cprev + cprev + wincmd w + call assert_equal(':cf Xerrorfile1', w:quickfix_title) + wincmd p + + let &efm = save_efm + call delete('Xerrorfile1') + call delete('Xerrorfile2') + call delete('Xtestfile') +endfunc + +" Test for quickfix directory stack support +func s:dir_stack_tests(cchar) + call s:setup_commands(a:cchar) + + let save_efm=&efm + set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f' + + let lines = ["Entering dir 'dir1/a'", + \ 'habits2.txt:1:Nine Healthy Habits', + \ "Entering dir 'b'", + \ 'habits3.txt:2:0 Hours of television', + \ 'habits2.txt:7:5 Small meals', + \ "Entering dir 'dir1/c'", + \ 'habits4.txt:3:1 Hour of exercise', + \ "Leaving dir 'dir1/c'", + \ "Leaving dir 'dir1/a'", + \ 'habits1.txt:4:2 Liters of water', + \ "Entering dir 'dir2'", + \ 'habits5.txt:5:3 Cups of hot green tea', + \ "Leaving dir 'dir2'" + \] + + Xexpr "" + for l in lines + Xaddexpr l + endfor + + let qf = g:Xgetlist() + + call assert_equal('dir1/a/habits2.txt', bufname(qf[1].bufnr)) + call assert_equal(1, qf[1].lnum) + call assert_equal('dir1/a/b/habits3.txt', bufname(qf[3].bufnr)) + call assert_equal(2, qf[3].lnum) + call assert_equal('dir1/a/habits2.txt', bufname(qf[4].bufnr)) + call assert_equal(7, qf[4].lnum) + call assert_equal('dir1/c/habits4.txt', bufname(qf[6].bufnr)) + call assert_equal(3, qf[6].lnum) + call assert_equal('habits1.txt', bufname(qf[9].bufnr)) + call assert_equal(4, qf[9].lnum) + call assert_equal('dir2/habits5.txt', bufname(qf[11].bufnr)) + call assert_equal(5, qf[11].lnum) + + let &efm=save_efm +endfunc + +" Tests for %D and %X errorformat options +func Test_efm_dirstack() + " Create the directory stack and files + call mkdir('dir1') + call mkdir('dir1/a') + call mkdir('dir1/a/b') + call mkdir('dir1/c') + call mkdir('dir2') + + let lines = ["Nine Healthy Habits", + \ "0 Hours of television", + \ "1 Hour of exercise", + \ "2 Liters of water", + \ "3 Cups of hot green tea", + \ "4 Short mental breaks", + \ "5 Small meals", + \ "6 AM wake up time", + \ "7 Minutes of laughter", + \ "8 Hours of sleep (at least)", + \ "9 PM end of the day and off to bed" + \ ] + call writefile(lines, 'habits1.txt') + call writefile(lines, 'dir1/a/habits2.txt') + call writefile(lines, 'dir1/a/b/habits3.txt') + call writefile(lines, 'dir1/c/habits4.txt') + call writefile(lines, 'dir2/habits5.txt') + + call s:dir_stack_tests('c') + call s:dir_stack_tests('l') + + call delete('dir1', 'rf') + call delete('dir2', 'rf') + call delete('habits1.txt') +endfunc + +" Test for resync after continuing an ignored message +func Xefm_ignore_continuations(cchar) + call s:setup_commands(a:cchar) + + let save_efm = &efm + + let &efm = + \ '%Eerror %m %l,' . + \ '%-Wignored %m %l,' . + \ '%+Cmore ignored %m %l,' . + \ '%Zignored end' + Xgetexpr ['ignored warning 1', 'more ignored continuation 2', 'ignored end', 'error resync 4'] + let l = map(g:Xgetlist(), '[v:val.text, v:val.valid, v:val.lnum, v:val.type]') + call assert_equal([['resync', 1, 4, 'E']], l) + + let &efm = save_efm +endfunc + +func Test_efm_ignore_continuations() + call Xefm_ignore_continuations('c') + call Xefm_ignore_continuations('l') +endfunc + +" Tests for invalid error format specifies +func Xinvalid_efm_Tests(cchar) + call s:setup_commands(a:cchar) + + let save_efm = &efm + + set efm=%f:%l:%m,%f:%f:%l:%m + call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E372:') + + set efm=%f:%l:%m,%f:%l:%r:%m + call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:') + + set efm=%f:%l:%m,%O:%f:%l:%m + call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:') + + set efm=%f:%l:%m,%f:%l:%*[^a-z + call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E374:') + + set efm=%f:%l:%m,%f:%l:%*c + call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E375:') + + set efm=%f:%l:%m,%L%M%N + call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E376:') + + set efm=%f:%l:%m,%f:%l:%m:%R + call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E377:') + + set efm= + call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E378:') + + set efm=%DEntering\ dir\ abc,%f:%l:%m + call assert_fails('Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]', 'E379:') + + let &efm = save_efm +endfunc + +func Test_invalid_efm() + call Xinvalid_efm_Tests('c') + call Xinvalid_efm_Tests('l') +endfunc + +" TODO: +" Add tests for the following formats in 'errorformat' +" %r %O +func Test_efm2() + let save_efm = &efm + + " Test for %s format in efm + set efm=%f:%s + cexpr 'Xtestfile:Line search text' + let l = getqflist() + call assert_equal(l[0].pattern, '^\VLine search text\$') + call assert_equal(l[0].lnum, 0) + + let l = split(execute('clist', ''), "\n") + call assert_equal([' 1 Xtestfile:^\VLine search text\$: '], l) + + " Test for %P, %Q and %t format specifiers + let lines=["[Xtestfile1]", + \ "(1,17) error: ';' missing", + \ "(21,2) warning: variable 'z' not defined", + \ "(67,3) error: end of file found before string ended", + \ "--", + \ "", + \ "[Xtestfile2]", + \ "--", + \ "", + \ "[Xtestfile3]", + \ "NEW compiler v1.1", + \ "(2,2) warning: variable 'x' not defined", + \ "(67,3) warning: 's' already defined", + \ "--" + \] + set efm=%+P[%f]%r,(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%+Q--%r + " To exercise the push/pop file functionality in quickfix, the test files + " need to be created. + call writefile(['Line1'], 'Xtestfile1') + call writefile(['Line2'], 'Xtestfile2') + call writefile(['Line3'], 'Xtestfile3') + cexpr "" + for l in lines + caddexpr l + endfor + let l = getqflist() + call assert_equal(12, len(l)) + call assert_equal(21, l[2].lnum) + call assert_equal(2, l[2].col) + call assert_equal('w', l[2].type) + call assert_equal('e', l[3].type) + call delete('Xtestfile1') + call delete('Xtestfile2') + call delete('Xtestfile3') + + " Tests for %E, %C and %Z format specifiers + let lines = ["Error 275", + \ "line 42", + \ "column 3", + \ "' ' expected after '--'" + \] + set efm=%EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m + cgetexpr lines + let l = getqflist() + call assert_equal(275, l[0].nr) + call assert_equal(42, l[0].lnum) + call assert_equal(3, l[0].col) + call assert_equal('E', l[0].type) + call assert_equal("\n' ' expected after '--'", l[0].text) + + " Test for %> + let lines = ["Error in line 147 of foo.c:", + \"unknown variable 'i'" + \] + set efm=unknown\ variable\ %m,%E%>Error\ in\ line\ %l\ of\ %f:,%Z%m + cgetexpr lines + let l = getqflist() + call assert_equal(147, l[0].lnum) + call assert_equal('E', l[0].type) + call assert_equal("\nunknown variable 'i'", l[0].text) + + " Test for %A, %C and other formats + let lines = [ + \"==============================================================", + \"FAIL: testGetTypeIdCachesResult (dbfacadeTest.DjsDBFacadeTest)", + \"--------------------------------------------------------------", + \"Traceback (most recent call last):", + \' File "unittests/dbfacadeTest.py", line 89, in testFoo', + \" self.assertEquals(34, dtid)", + \' File "/usr/lib/python2.2/unittest.py", line 286, in', + \" failUnlessEqual", + \" raise self.failureException, \\", + \"AssertionError: 34 != 33", + \"", + \"--------------------------------------------------------------", + \"Ran 27 tests in 0.063s" + \] + set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m + cgetexpr lines + let l = getqflist() + call assert_equal(8, len(l)) + call assert_equal(89, l[4].lnum) + call assert_equal(1, l[4].valid) + call assert_equal('unittests/dbfacadeTest.py', bufname(l[4].bufnr)) + + " Test for %o + set efm=%f(%o):%l\ %m + cgetexpr ['Xotestfile(Language.PureScript.Types):20 Error'] + call writefile(['Line1'], 'Xotestfile') + let l = getqflist() + call assert_equal(1, len(l), string(l)) + call assert_equal('Language.PureScript.Types', l[0].module) + copen + call assert_equal('Language.PureScript.Types|20| Error', getline(1)) + call feedkeys("\<CR>", 'xn') + call assert_equal('Xotestfile', expand('%:t')) + cclose + bd + call delete("Xotestfile") + + " The following sequence of commands used to crash Vim + set efm=%W%m + cgetexpr ['msg1'] + let l = getqflist() + call assert_equal(1, len(l), string(l)) + call assert_equal('msg1', l[0].text) + set efm=%C%m + lexpr 'msg2' + let l = getloclist(0) + call assert_equal(1, len(l), string(l)) + call assert_equal('msg2', l[0].text) + lopen + call setqflist([], 'r') + caddbuf + let l = getqflist() + call assert_equal(1, len(l), string(l)) + call assert_equal('|| msg2', l[0].text) + + " When matching error lines, case should be ignored. Test for this. + set noignorecase + let l=getqflist({'lines' : ['Xtest:FOO10:Line 20'], 'efm':'%f:foo%l:%m'}) + call assert_equal(10, l.items[0].lnum) + call assert_equal('Line 20', l.items[0].text) + set ignorecase& + + new | only + let &efm = save_efm +endfunc + +func XquickfixChangedByAutocmd(cchar) + call s:setup_commands(a:cchar) + if a:cchar == 'c' + let ErrorNr = 'E925' + func! ReadFunc() + colder + cgetexpr [] + endfunc + else + let ErrorNr = 'E926' + func! ReadFunc() + lolder + lgetexpr [] + endfunc + endif + + augroup testgroup + au! + autocmd BufReadCmd test_changed.txt call ReadFunc() + augroup END + + new | only + let words = [ "a", "b" ] + let qflist = [] + for word in words + call add(qflist, {'filename': 'test_changed.txt'}) + call g:Xsetlist(qflist, ' ') + endfor + call assert_fails('Xrewind', ErrorNr . ':') + + augroup! testgroup +endfunc + +func Test_quickfix_was_changed_by_autocmd() + call XquickfixChangedByAutocmd('c') + call XquickfixChangedByAutocmd('l') +endfunc + +func Test_caddbuffer_to_empty() + helpgr quickfix + call setqflist([], 'r') + cad + try + cn + catch + " number of matches is unknown + call assert_true(v:exception =~ 'E553:') + endtry + quit! +endfunc + +func Test_cgetexpr_works() + " this must not crash Vim + cgetexpr [$x] + lgetexpr [$x] +endfunc + +" Tests for the setqflist() and setloclist() functions +func SetXlistTests(cchar, bnum) + call s:setup_commands(a:cchar) + + call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 1}, + \ {'bufnr': a:bnum, 'lnum': 2}]) + let l = g:Xgetlist() + call assert_equal(2, len(l)) + call assert_equal(2, l[1].lnum) + + Xnext + call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3}], 'a') + let l = g:Xgetlist() + call assert_equal(3, len(l)) + Xnext + call assert_equal(3, line('.')) + + " Appending entries to the list should not change the cursor position + " in the quickfix window + Xwindow + 1 + call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 4}, + \ {'bufnr': a:bnum, 'lnum': 5}], 'a') + call assert_equal(1, line('.')) + close + + call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3}, + \ {'bufnr': a:bnum, 'lnum': 4}, + \ {'bufnr': a:bnum, 'lnum': 5}], 'r') + let l = g:Xgetlist() + call assert_equal(3, len(l)) + call assert_equal(5, l[2].lnum) + + call g:Xsetlist([]) + let l = g:Xgetlist() + call assert_equal(0, len(l)) + + " Tests for setting the 'valid' flag + call g:Xsetlist([{'bufnr':a:bnum, 'lnum':4, 'valid':0}]) + Xwindow + call assert_equal(1, winnr('$')) + let l = g:Xgetlist() + call g:Xsetlist(l) + call assert_equal(0, g:Xgetlist()[0].valid) + " Adding a non-valid entry should not mark the list as having valid entries + call g:Xsetlist([{'bufnr':a:bnum, 'lnum':5, 'valid':0}], 'a') + Xwindow + call assert_equal(1, winnr('$')) + + " :cnext/:cprev should still work even with invalid entries in the list + let l = [{'bufnr' : a:bnum, 'lnum' : 1, 'text' : '1', 'valid' : 0}, + \ {'bufnr' : a:bnum, 'lnum' : 2, 'text' : '2', 'valid' : 0}] + call g:Xsetlist(l) + Xnext + call assert_equal(2, g:Xgetlist({'idx' : 0}).idx) + Xprev + call assert_equal(1, g:Xgetlist({'idx' : 0}).idx) + " :cnext/:cprev should still work after appending invalid entries to an + " empty list + call g:Xsetlist([]) + call g:Xsetlist(l, 'a') + Xnext + call assert_equal(2, g:Xgetlist({'idx' : 0}).idx) + Xprev + call assert_equal(1, g:Xgetlist({'idx' : 0}).idx) + + call g:Xsetlist([{'text':'Text1', 'valid':1}]) + Xwindow + call assert_equal(2, winnr('$')) + Xclose + let save_efm = &efm + set efm=%m + Xgetexpr 'TestMessage' + let l = g:Xgetlist() + call g:Xsetlist(l) + call assert_equal(1, g:Xgetlist()[0].valid) + let &efm = save_efm + + " Error cases: + " Refer to a non-existing buffer and pass a non-dictionary type + call assert_fails("call g:Xsetlist([{'bufnr':998, 'lnum':4}," . + \ " {'bufnr':999, 'lnum':5}])", 'E92:') + call g:Xsetlist([[1, 2,3]]) + call assert_equal(0, len(g:Xgetlist())) +endfunc + +func Test_setqflist() + new Xtestfile | only + let bnum = bufnr('%') + call setline(1, range(1,5)) + + call SetXlistTests('c', bnum) + call SetXlistTests('l', bnum) + + enew! + call delete('Xtestfile') +endfunc + +func Xlist_empty_middle(cchar) + call s:setup_commands(a:cchar) + + " create three quickfix lists + let @/ = 'Test_' + Xvimgrep // test_quickfix.vim + let testlen = len(g:Xgetlist()) + call assert_true(testlen > 0) + Xvimgrep empty test_quickfix.vim + call assert_true(len(g:Xgetlist()) > 0) + Xvimgrep matches test_quickfix.vim + let matchlen = len(g:Xgetlist()) + call assert_true(matchlen > 0) + Xolder + " make the middle list empty + call g:Xsetlist([], 'r') + call assert_true(len(g:Xgetlist()) == 0) + Xolder + call assert_equal(testlen, len(g:Xgetlist())) + Xnewer + Xnewer + call assert_equal(matchlen, len(g:Xgetlist())) +endfunc + +func Test_setqflist_empty_middle() + call Xlist_empty_middle('c') + call Xlist_empty_middle('l') +endfunc + +func Xlist_empty_older(cchar) + call s:setup_commands(a:cchar) + + " create three quickfix lists + Xvimgrep one test_quickfix.vim + let onelen = len(g:Xgetlist()) + call assert_true(onelen > 0) + Xvimgrep two test_quickfix.vim + let twolen = len(g:Xgetlist()) + call assert_true(twolen > 0) + Xvimgrep three test_quickfix.vim + let threelen = len(g:Xgetlist()) + call assert_true(threelen > 0) + Xolder 2 + " make the first list empty, check the others didn't change + call g:Xsetlist([], 'r') + call assert_true(len(g:Xgetlist()) == 0) + Xnewer + call assert_equal(twolen, len(g:Xgetlist())) + Xnewer + call assert_equal(threelen, len(g:Xgetlist())) +endfunc + +func Test_setqflist_empty_older() + call Xlist_empty_older('c') + call Xlist_empty_older('l') +endfunc + +func XquickfixSetListWithAct(cchar) + call s:setup_commands(a:cchar) + + let list1 = [{'filename': 'fnameA', 'text': 'A'}, + \ {'filename': 'fnameB', 'text': 'B'}] + let list2 = [{'filename': 'fnameC', 'text': 'C'}, + \ {'filename': 'fnameD', 'text': 'D'}, + \ {'filename': 'fnameE', 'text': 'E'}] + + " {action} is unspecified. Same as specifing ' '. + new | only + silent! Xnewer 99 + call g:Xsetlist(list1) + call g:Xsetlist(list2) + let li = g:Xgetlist() + call assert_equal(3, len(li)) + call assert_equal('C', li[0]['text']) + call assert_equal('D', li[1]['text']) + call assert_equal('E', li[2]['text']) + silent! Xolder + let li = g:Xgetlist() + call assert_equal(2, len(li)) + call assert_equal('A', li[0]['text']) + call assert_equal('B', li[1]['text']) + + " {action} is specified ' '. + new | only + silent! Xnewer 99 + call g:Xsetlist(list1) + call g:Xsetlist(list2, ' ') + let li = g:Xgetlist() + call assert_equal(3, len(li)) + call assert_equal('C', li[0]['text']) + call assert_equal('D', li[1]['text']) + call assert_equal('E', li[2]['text']) + silent! Xolder + let li = g:Xgetlist() + call assert_equal(2, len(li)) + call assert_equal('A', li[0]['text']) + call assert_equal('B', li[1]['text']) + + " {action} is specified 'a'. + new | only + silent! Xnewer 99 + call g:Xsetlist(list1) + call g:Xsetlist(list2, 'a') + let li = g:Xgetlist() + call assert_equal(5, len(li)) + call assert_equal('A', li[0]['text']) + call assert_equal('B', li[1]['text']) + call assert_equal('C', li[2]['text']) + call assert_equal('D', li[3]['text']) + call assert_equal('E', li[4]['text']) + + " {action} is specified 'r'. + new | only + silent! Xnewer 99 + call g:Xsetlist(list1) + call g:Xsetlist(list2, 'r') + let li = g:Xgetlist() + call assert_equal(3, len(li)) + call assert_equal('C', li[0]['text']) + call assert_equal('D', li[1]['text']) + call assert_equal('E', li[2]['text']) + + " Test for wrong value. + new | only + call assert_fails("call g:Xsetlist(0)", 'E714:') + call assert_fails("call g:Xsetlist(list1, '')", 'E927:') + call assert_fails("call g:Xsetlist(list1, 'aa')", 'E927:') + call assert_fails("call g:Xsetlist(list1, ' a')", 'E927:') + call assert_fails("call g:Xsetlist(list1, 0)", 'E928:') +endfunc + +func Test_setqflist_invalid_nr() + " The following command used to crash Vim + call setqflist([], ' ', {'nr' : $XXX_DOES_NOT_EXIST}) +endfunc + +func Test_quickfix_set_list_with_act() + call XquickfixSetListWithAct('c') + call XquickfixSetListWithAct('l') +endfunc + +func XLongLinesTests(cchar) + let l = g:Xgetlist() + + call assert_equal(4, len(l)) + call assert_equal(1, l[0].lnum) + call assert_equal(1, l[0].col) + call assert_equal(1975, len(l[0].text)) + call assert_equal(2, l[1].lnum) + call assert_equal(1, l[1].col) + call assert_equal(4070, len(l[1].text)) + call assert_equal(3, l[2].lnum) + call assert_equal(1, l[2].col) + call assert_equal(4070, len(l[2].text)) + call assert_equal(4, l[3].lnum) + call assert_equal(1, l[3].col) + call assert_equal(10, len(l[3].text)) + + call g:Xsetlist([], 'r') +endfunc + +func s:long_lines_tests(cchar) + call s:setup_commands(a:cchar) + + let testfile = 'samples/quickfix.txt' + + " file + exe 'Xgetfile' testfile + call XLongLinesTests(a:cchar) + + " list + Xexpr readfile(testfile) + call XLongLinesTests(a:cchar) + + " string + Xexpr join(readfile(testfile), "\n") + call XLongLinesTests(a:cchar) + + " buffer + exe 'edit' testfile + exe 'Xbuffer' bufnr('%') + call XLongLinesTests(a:cchar) +endfunc + +func Test_long_lines() + call s:long_lines_tests('c') + call s:long_lines_tests('l') +endfunc + +func s:create_test_file(filename) + let l = [] + for i in range(1, 20) + call add(l, 'Line' . i) + endfor + call writefile(l, a:filename) +endfunc + +func Test_switchbuf() + call s:create_test_file('Xqftestfile1') + call s:create_test_file('Xqftestfile2') + call s:create_test_file('Xqftestfile3') + + new | only + edit Xqftestfile1 + let file1_winid = win_getid() + new Xqftestfile2 + let file2_winid = win_getid() + cgetexpr ['Xqftestfile1:5:Line5', + \ 'Xqftestfile1:6:Line6', + \ 'Xqftestfile2:10:Line10', + \ 'Xqftestfile2:11:Line11', + \ 'Xqftestfile3:15:Line15', + \ 'Xqftestfile3:16:Line16'] + + new + let winid = win_getid() + cfirst | cnext + call assert_equal(winid, win_getid()) + 2cnext + call assert_equal(winid, win_getid()) + 2cnext + call assert_equal(winid, win_getid()) + enew + + set switchbuf=useopen + cfirst | cnext + call assert_equal(file1_winid, win_getid()) + 2cnext + call assert_equal(file2_winid, win_getid()) + 2cnext + call assert_equal(file2_winid, win_getid()) + + enew | only + set switchbuf=usetab + tabedit Xqftestfile1 + tabedit Xqftestfile2 + tabedit Xqftestfile3 + tabfirst + cfirst | cnext + call assert_equal(2, tabpagenr()) + 2cnext + call assert_equal(3, tabpagenr()) + 6cnext + call assert_equal(4, tabpagenr()) + 2cpfile + call assert_equal(2, tabpagenr()) + 2cnfile + call assert_equal(4, tabpagenr()) + tabfirst | tabonly | enew + + set switchbuf=split + cfirst | cnext + call assert_equal(1, winnr('$')) + cnext | cnext + call assert_equal(2, winnr('$')) + cnext | cnext + call assert_equal(3, winnr('$')) + enew | only + + set switchbuf=newtab + cfirst | cnext + call assert_equal(1, tabpagenr('$')) + cnext | cnext + call assert_equal(2, tabpagenr('$')) + cnext | cnext + call assert_equal(3, tabpagenr('$')) + tabfirst | enew | tabonly | only + + set switchbuf= + edit Xqftestfile1 + let file1_winid = win_getid() + new Xqftestfile2 + let file2_winid = win_getid() + copen + exe "normal 1G\<CR>" + call assert_equal(file1_winid, win_getid()) + copen + exe "normal 3G\<CR>" + call assert_equal(file2_winid, win_getid()) + copen | only + exe "normal 5G\<CR>" + call assert_equal(2, winnr('$')) + call assert_equal(1, bufwinnr('Xqftestfile3')) + + " If only quickfix window is open in the current tabpage, jumping to an + " entry with 'switchubf' set to 'usetab' should search in other tabpages. + enew | only + set switchbuf=usetab + tabedit Xqftestfile1 + tabedit Xqftestfile2 + tabedit Xqftestfile3 + tabfirst + copen | only + clast + call assert_equal(4, tabpagenr()) + tabfirst | tabonly | enew | only + + call delete('Xqftestfile1') + call delete('Xqftestfile2') + call delete('Xqftestfile3') + set switchbuf&vim + + enew | only +endfunc + +func Xadjust_qflnum(cchar) + call s:setup_commands(a:cchar) + + enew | only + + let fname = 'Xqftestfile' . a:cchar + call s:create_test_file(fname) + exe 'edit ' . fname + + Xgetexpr [fname . ':5:Line5', + \ fname . ':10:Line10', + \ fname . ':15:Line15', + \ fname . ':20:Line20'] + + 6,14delete + call append(6, ['Buffer', 'Window']) + + let l = g:Xgetlist() + + call assert_equal(5, l[0].lnum) + call assert_equal(6, l[2].lnum) + call assert_equal(13, l[3].lnum) + + enew! + call delete(fname) +endfunc + +func Test_adjust_lnum() + call setloclist(0, []) + call Xadjust_qflnum('c') + call setqflist([]) + call Xadjust_qflnum('l') +endfunc + +" Tests for the :grep/:lgrep and :grepadd/:lgrepadd commands +func s:test_xgrep(cchar) + call s:setup_commands(a:cchar) + + " The following lines are used for the grep test. Don't remove. + " Grep_Test_Text: Match 1 + " Grep_Test_Text: Match 2 + " GrepAdd_Test_Text: Match 1 + " GrepAdd_Test_Text: Match 2 + enew! | only + set makeef&vim + silent Xgrep Grep_Test_Text: test_quickfix.vim + call assert_true(len(g:Xgetlist()) == 3) + Xopen + call assert_true(w:quickfix_title =~ '^:grep') + Xclose + enew + set makeef=Temp_File_## + silent Xgrepadd GrepAdd_Test_Text: test_quickfix.vim + call assert_true(len(g:Xgetlist()) == 6) +endfunc + +func Test_grep() + if !has('unix') + " The grepprg may not be set on non-Unix systems + return + endif + + call s:test_xgrep('c') + call s:test_xgrep('l') +endfunc + +func Test_two_windows() + " Use one 'errorformat' for two windows. Add an expression to each of them, + " make sure they each keep their own state. + set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f' + call mkdir('Xone/a', 'p') + call mkdir('Xtwo/a', 'p') + let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7'] + call writefile(lines, 'Xone/a/one.txt') + call writefile(lines, 'Xtwo/a/two.txt') + + new one + let one_id = win_getid() + lexpr "" + new two + let two_id = win_getid() + lexpr "" + + laddexpr "Entering dir 'Xtwo/a'" + call win_gotoid(one_id) + laddexpr "Entering dir 'Xone/a'" + call win_gotoid(two_id) + laddexpr 'two.txt:5:two two two' + call win_gotoid(one_id) + laddexpr 'one.txt:3:one one one' + + let loc_one = getloclist(one_id) + call assert_equal('Xone/a/one.txt', bufname(loc_one[1].bufnr)) + call assert_equal(3, loc_one[1].lnum) + + let loc_two = getloclist(two_id) + call assert_equal('Xtwo/a/two.txt', bufname(loc_two[1].bufnr)) + call assert_equal(5, loc_two[1].lnum) + + call win_gotoid(one_id) + bwipe! + call win_gotoid(two_id) + bwipe! + call delete('Xone', 'rf') + call delete('Xtwo', 'rf') +endfunc + +func XbottomTests(cchar) + call s:setup_commands(a:cchar) + + " Calling lbottom without any errors should fail + if a:cchar == 'l' + call assert_fails('lbottom', 'E776:') + endif + + call g:Xsetlist([{'filename': 'foo', 'lnum': 42}]) + Xopen + let wid = win_getid() + call assert_equal(1, line('.')) + wincmd w + call g:Xsetlist([{'filename': 'var', 'lnum': 24}], 'a') + Xbottom + call win_gotoid(wid) + call assert_equal(2, line('.')) + Xclose +endfunc + +" Tests for the :cbottom and :lbottom commands +func Test_cbottom() + call XbottomTests('c') + call XbottomTests('l') +endfunc + +func HistoryTest(cchar) + call s:setup_commands(a:cchar) + + " clear all lists after the first one, then replace the first one. + call g:Xsetlist([]) + call assert_fails('Xolder 99', 'E380:') + let entry = {'filename': 'foo', 'lnum': 42} + call g:Xsetlist([entry], 'r') + call g:Xsetlist([entry, entry]) + call g:Xsetlist([entry, entry, entry]) + let res = split(execute(a:cchar . 'hist'), "\n") + call assert_equal(3, len(res)) + let common = 'errors :set' . (a:cchar == 'c' ? 'qf' : 'loc') . 'list()' + call assert_equal(' error list 1 of 3; 1 ' . common, res[0]) + call assert_equal(' error list 2 of 3; 2 ' . common, res[1]) + call assert_equal('> error list 3 of 3; 3 ' . common, res[2]) + + call g:Xsetlist([], 'f') + let l = split(execute(a:cchar . 'hist'), "\n") + call assert_equal('No entries', l[0]) + + " An empty list should still show the stack history + call g:Xsetlist([]) + let res = split(execute(a:cchar . 'hist'), "\n") + call assert_equal('> error list 1 of 1; 0 ' . common, res[0]) + + call g:Xsetlist([], 'f') +endfunc + +func Test_history() + call HistoryTest('c') + call HistoryTest('l') +endfunc + +func Test_duplicate_buf() + " make sure we can get the highest buffer number + edit DoesNotExist + edit DoesNotExist2 + let last_buffer = bufnr("$") + + " make sure only one buffer is created + call writefile(['this one', 'that one'], 'Xgrepthis') + vimgrep one Xgrepthis + vimgrep one Xgrepthis + call assert_equal(last_buffer + 1, bufnr("$")) + + call delete('Xgrepthis') +endfunc + +" Quickfix/Location list set/get properties tests +func Xproperty_tests(cchar) + call s:setup_commands(a:cchar) + + " Error cases + call assert_fails('call g:Xgetlist(99)', 'E715:') + call assert_fails('call g:Xsetlist(99)', 'E714:') + call assert_fails('call g:Xsetlist([], "a", [])', 'E715:') + + " Set and get the title + call g:Xsetlist([]) + Xopen + wincmd p + call g:Xsetlist([{'filename':'foo', 'lnum':27}]) + let s = g:Xsetlist([], 'a', {'title' : 'Sample'}) + call assert_equal(0, s) + let d = g:Xgetlist({"title":1}) + call assert_equal('Sample', d.title) + " Try setting title to a non-string value + call assert_equal(-1, g:Xsetlist([], 'a', {'title' : ['Test']})) + call assert_equal('Sample', g:Xgetlist({"title":1}).title) + + Xopen + call assert_equal('Sample', w:quickfix_title) + Xclose + + " Tests for action argument + silent! Xolder 999 + let qfnr = g:Xgetlist({'all':1}).nr + call g:Xsetlist([], 'r', {'title' : 'N1'}) + call assert_equal('N1', g:Xgetlist({'all':1}).title) + call g:Xsetlist([], ' ', {'title' : 'N2'}) + call assert_equal(qfnr + 1, g:Xgetlist({'all':1}).nr) + + let res = g:Xgetlist({'nr': 0}) + call assert_equal(qfnr + 1, res.nr) + call assert_equal(['nr'], keys(res)) + + call g:Xsetlist([], ' ', {'title' : 'N3'}) + call assert_equal('N2', g:Xgetlist({'nr':2, 'title':1}).title) + + " Changing the title of an earlier quickfix list + call g:Xsetlist([], 'r', {'title' : 'NewTitle', 'nr' : 2}) + call assert_equal('NewTitle', g:Xgetlist({'nr':2, 'title':1}).title) + + " Changing the title of an invalid quickfix list + call assert_equal(-1, g:Xsetlist([], ' ', + \ {'title' : 'SomeTitle', 'nr' : 99})) + call assert_equal(-1, g:Xsetlist([], ' ', + \ {'title' : 'SomeTitle', 'nr' : 'abc'})) + + if a:cchar == 'c' + copen + call assert_equal({'winid':win_getid()}, getqflist({'winid':1})) + cclose + endif + + " Invalid arguments + call assert_fails('call g:Xgetlist([])', 'E715') + call assert_fails('call g:Xsetlist([], "a", [])', 'E715') + let s = g:Xsetlist([], 'a', {'abc':1}) + call assert_equal(-1, s) + + call assert_equal({}, g:Xgetlist({'abc':1})) + call assert_equal('', g:Xgetlist({'nr':99, 'title':1}).title) + call assert_equal('', g:Xgetlist({'nr':[], 'title':1}).title) + + if a:cchar == 'l' + call assert_equal({}, getloclist(99, {'title': 1})) + endif + + " Context related tests + let s = g:Xsetlist([], 'a', {'context':[1,2,3]}) + call assert_equal(0, s) + call test_garbagecollect_now() + let d = g:Xgetlist({'context':1}) + call assert_equal([1,2,3], d.context) + call g:Xsetlist([], 'a', {'context':{'color':'green'}}) + let d = g:Xgetlist({'context':1}) + call assert_equal({'color':'green'}, d.context) + call g:Xsetlist([], 'a', {'context':"Context info"}) + let d = g:Xgetlist({'context':1}) + call assert_equal("Context info", d.context) + call g:Xsetlist([], 'a', {'context':246}) + let d = g:Xgetlist({'context':1}) + call assert_equal(246, d.context) + if a:cchar == 'l' + " Test for copying context across two different location lists + new | only + let w1_id = win_getid() + let l = [1] + call setloclist(0, [], 'a', {'context':l}) + new + let w2_id = win_getid() + call add(l, 2) + call assert_equal([1, 2], getloclist(w1_id, {'context':1}).context) + call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context) + unlet! l + call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context) + only + call setloclist(0, [], 'f') + call assert_equal('', getloclist(0, {'context':1}).context) + endif + + " Test for changing the context of previous quickfix lists + call g:Xsetlist([], 'f') + Xexpr "One" + Xexpr "Two" + Xexpr "Three" + call g:Xsetlist([], 'r', {'context' : [1], 'nr' : 1}) + call g:Xsetlist([], 'a', {'context' : [2], 'nr' : 2}) + " Also, check for setting the context using quickfix list number zero. + call g:Xsetlist([], 'r', {'context' : [3], 'nr' : 0}) + call test_garbagecollect_now() + let l = g:Xgetlist({'nr' : 1, 'context' : 1}) + call assert_equal([1], l.context) + let l = g:Xgetlist({'nr' : 2, 'context' : 1}) + call assert_equal([2], l.context) + let l = g:Xgetlist({'nr' : 3, 'context' : 1}) + call assert_equal([3], l.context) + + " Test for changing the context through reference and for garbage + " collection of quickfix context + let l = ["red"] + call g:Xsetlist([], ' ', {'context' : l}) + call add(l, "blue") + let x = g:Xgetlist({'context' : 1}) + call add(x.context, "green") + call assert_equal(["red", "blue", "green"], l) + call assert_equal(["red", "blue", "green"], x.context) + unlet l + call test_garbagecollect_now() + let m = g:Xgetlist({'context' : 1}) + call assert_equal(["red", "blue", "green"], m.context) + + " Test for setting/getting items + Xexpr "" + let qfprev = g:Xgetlist({'nr':0}) + let s = g:Xsetlist([], ' ', {'title':'Green', + \ 'items' : [{'filename':'F1', 'lnum':10}]}) + call assert_equal(0, s) + let qfcur = g:Xgetlist({'nr':0}) + call assert_true(qfcur.nr == qfprev.nr + 1) + let l = g:Xgetlist({'items':1}) + call assert_equal('F1', bufname(l.items[0].bufnr)) + call assert_equal(10, l.items[0].lnum) + call g:Xsetlist([], 'a', {'items' : [{'filename':'F2', 'lnum':20}, + \ {'filename':'F2', 'lnum':30}]}) + let l = g:Xgetlist({'items':1}) + call assert_equal('F2', bufname(l.items[2].bufnr)) + call assert_equal(30, l.items[2].lnum) + call g:Xsetlist([], 'r', {'items' : [{'filename':'F3', 'lnum':40}]}) + let l = g:Xgetlist({'items':1}) + call assert_equal('F3', bufname(l.items[0].bufnr)) + call assert_equal(40, l.items[0].lnum) + call g:Xsetlist([], 'r', {'items' : []}) + let l = g:Xgetlist({'items':1}) + call assert_equal(0, len(l.items)) + + call g:Xsetlist([], 'r', {'title' : 'TestTitle'}) + call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]}) + call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]}) + call assert_equal('TestTitle', g:Xgetlist({'title' : 1}).title) + + " Test for getting id of window associated with a location list window + if a:cchar == 'l' + only + call assert_equal(0, g:Xgetlist({'all' : 1}).filewinid) + let wid = win_getid() + Xopen + call assert_equal(wid, g:Xgetlist({'filewinid' : 1}).filewinid) + wincmd w + call assert_equal(0, g:Xgetlist({'filewinid' : 1}).filewinid) + only + endif + + " The following used to crash Vim with address sanitizer + call g:Xsetlist([], 'f') + call g:Xsetlist([], 'a', {'items' : [{'filename':'F1', 'lnum':10}]}) + call assert_equal(10, g:Xgetlist({'items':1}).items[0].lnum) + + " Try setting the items using a string + call assert_equal(-1, g:Xsetlist([], ' ', {'items' : 'Test'})) + + " Save and restore the quickfix stack + call g:Xsetlist([], 'f') + call assert_equal(0, g:Xgetlist({'nr':'$'}).nr) + Xexpr "File1:10:Line1" + Xexpr "File2:20:Line2" + Xexpr "File3:30:Line3" + let last_qf = g:Xgetlist({'nr':'$'}).nr + call assert_equal(3, last_qf) + let qstack = [] + for i in range(1, last_qf) + let qstack = add(qstack, g:Xgetlist({'nr':i, 'all':1})) + endfor + call g:Xsetlist([], 'f') + for i in range(len(qstack)) + call g:Xsetlist([], ' ', qstack[i]) + endfor + call assert_equal(3, g:Xgetlist({'nr':'$'}).nr) + call assert_equal(10, g:Xgetlist({'nr':1, 'items':1}).items[0].lnum) + call assert_equal(20, g:Xgetlist({'nr':2, 'items':1}).items[0].lnum) + call assert_equal(30, g:Xgetlist({'nr':3, 'items':1}).items[0].lnum) + call g:Xsetlist([], 'f') + + " Swap two quickfix lists + Xexpr "File1:10:Line10" + Xexpr "File2:20:Line20" + Xexpr "File3:30:Line30" + call g:Xsetlist([], 'r', {'nr':1,'title':'Colors','context':['Colors']}) + call g:Xsetlist([], 'r', {'nr':2,'title':'Fruits','context':['Fruits']}) + let l1=g:Xgetlist({'nr':1,'all':1}) + let l2=g:Xgetlist({'nr':2,'all':1}) + let save_id = l1.id + let l1.id=l2.id + let l2.id=save_id + call g:Xsetlist([], 'r', l1) + call g:Xsetlist([], 'r', l2) + let newl1=g:Xgetlist({'nr':1,'all':1}) + let newl2=g:Xgetlist({'nr':2,'all':1}) + call assert_equal('Fruits', newl1.title) + call assert_equal(['Fruits'], newl1.context) + call assert_equal('Line20', newl1.items[0].text) + call assert_equal('Colors', newl2.title) + call assert_equal(['Colors'], newl2.context) + call assert_equal('Line10', newl2.items[0].text) + call g:Xsetlist([], 'f') +endfunc + +func Test_qf_property() + call Xproperty_tests('c') + call Xproperty_tests('l') +endfunc + +" Test for setting the current index in the location/quickfix list +func Xtest_setqfidx(cchar) + call s:setup_commands(a:cchar) + + Xgetexpr "F1:10:1:Line1\nF2:20:2:Line2\nF3:30:3:Line3" + Xgetexpr "F4:10:1:Line1\nF5:20:2:Line2\nF6:30:3:Line3" + Xgetexpr "F7:10:1:Line1\nF8:20:2:Line2\nF9:30:3:Line3" + + call g:Xsetlist([], 'a', {'nr' : 3, 'idx' : 2}) + call g:Xsetlist([], 'a', {'nr' : 2, 'idx' : 2}) + call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 3}) + Xolder 2 + Xopen + call assert_equal(3, line('.')) + Xnewer + call assert_equal(2, line('.')) + Xnewer + call assert_equal(2, line('.')) + " Update the current index with the quickfix window open + wincmd w + call g:Xsetlist([], 'a', {'nr' : 3, 'idx' : 3}) + Xopen + call assert_equal(3, line('.')) + Xclose + + " Set the current index to the last entry + call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : '$'}) + call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx) + " A large value should set the index to the last index + call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 1}) + call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 999}) + call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx) + " Invalid index values + call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : -1}) + call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx) + call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 0}) + call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx) + call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 'xx'}) + call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx) + call assert_fails("call g:Xsetlist([], 'a', {'nr':1, 'idx':[]})", 'E745:') + + call g:Xsetlist([], 'f') + new | only +endfunc + +func Test_setqfidx() + call Xtest_setqfidx('c') + call Xtest_setqfidx('l') +endfunc + +" Tests for the QuickFixCmdPre/QuickFixCmdPost autocommands +func QfAutoCmdHandler(loc, cmd) + call add(g:acmds, a:loc . a:cmd) +endfunc + +func Test_Autocmd() + autocmd QuickFixCmdPre * call QfAutoCmdHandler('pre', expand('<amatch>')) + autocmd QuickFixCmdPost * call QfAutoCmdHandler('post', expand('<amatch>')) + + let g:acmds = [] + cexpr "F1:10:Line 10" + caddexpr "F1:20:Line 20" + cgetexpr "F1:30:Line 30" + cexpr "" + caddexpr "" + cgetexpr "" + silent! cexpr non_existing_func() + silent! caddexpr non_existing_func() + silent! cgetexpr non_existing_func() + let l = ['precexpr', + \ 'postcexpr', + \ 'precaddexpr', + \ 'postcaddexpr', + \ 'precgetexpr', + \ 'postcgetexpr', + \ 'precexpr', + \ 'postcexpr', + \ 'precaddexpr', + \ 'postcaddexpr', + \ 'precgetexpr', + \ 'postcgetexpr', + \ 'precexpr', + \ 'precaddexpr', + \ 'precgetexpr'] + call assert_equal(l, g:acmds) + + let g:acmds = [] + enew! | call append(0, "F2:10:Line 10") + cbuffer! + enew! | call append(0, "F2:20:Line 20") + cgetbuffer + enew! | call append(0, "F2:30:Line 30") + caddbuffer + new + let bnum = bufnr('%') + bunload + exe 'silent! cbuffer! ' . bnum + exe 'silent! cgetbuffer ' . bnum + exe 'silent! caddbuffer ' . bnum + enew! + let l = ['precbuffer', + \ 'postcbuffer', + \ 'precgetbuffer', + \ 'postcgetbuffer', + \ 'precaddbuffer', + \ 'postcaddbuffer', + \ 'precbuffer', + \ 'precgetbuffer', + \ 'precaddbuffer'] + call assert_equal(l, g:acmds) + + call writefile(['Xtest:1:Line1'], 'Xtest') + call writefile([], 'Xempty') + let g:acmds = [] + cfile Xtest + caddfile Xtest + cgetfile Xtest + cfile Xempty + caddfile Xempty + cgetfile Xempty + silent! cfile do_not_exist + silent! caddfile do_not_exist + silent! cgetfile do_not_exist + let l = ['precfile', + \ 'postcfile', + \ 'precaddfile', + \ 'postcaddfile', + \ 'precgetfile', + \ 'postcgetfile', + \ 'precfile', + \ 'postcfile', + \ 'precaddfile', + \ 'postcaddfile', + \ 'precgetfile', + \ 'postcgetfile', + \ 'precfile', + \ 'postcfile', + \ 'precaddfile', + \ 'postcaddfile', + \ 'precgetfile', + \ 'postcgetfile'] + call assert_equal(l, g:acmds) + + let g:acmds = [] + helpgrep quickfix + silent! helpgrep non_existing_help_topic + vimgrep test Xtest + vimgrepadd test Xtest + silent! vimgrep non_existing_test Xtest + silent! vimgrepadd non_existing_test Xtest + set makeprg= + silent! make + set makeprg& + let l = ['prehelpgrep', + \ 'posthelpgrep', + \ 'prehelpgrep', + \ 'posthelpgrep', + \ 'previmgrep', + \ 'postvimgrep', + \ 'previmgrepadd', + \ 'postvimgrepadd', + \ 'previmgrep', + \ 'postvimgrep', + \ 'previmgrepadd', + \ 'postvimgrepadd', + \ 'premake', + \ 'postmake'] + call assert_equal(l, g:acmds) + + if has('unix') + " Run this test only on Unix-like systems. The grepprg may not be set on + " non-Unix systems. + " The following lines are used for the grep test. Don't remove. + " Grep_Autocmd_Text: Match 1 + " GrepAdd_Autocmd_Text: Match 2 + let g:acmds = [] + silent grep Grep_Autocmd_Text test_quickfix.vim + silent grepadd GrepAdd_Autocmd_Text test_quickfix.vim + silent grep abc123def Xtest + silent grepadd abc123def Xtest + let l = ['pregrep', + \ 'postgrep', + \ 'pregrepadd', + \ 'postgrepadd', + \ 'pregrep', + \ 'postgrep', + \ 'pregrepadd', + \ 'postgrepadd'] + call assert_equal(l, g:acmds) + endif + + call delete('Xtest') + call delete('Xempty') + au! QuickFixCmdPre + au! QuickFixCmdPost +endfunc + +func Test_Autocmd_Exception() + set efm=%m + lgetexpr '?' + + try + call DoesNotExit() + catch + lgetexpr '1' + finally + lgetexpr '1' + endtry + + call assert_equal('1', getloclist(0)[0].text) + + set efm&vim +endfunc + +func Test_caddbuffer_wrong() + " This used to cause a memory access in freed memory. + let save_efm = &efm + set efm=%EEEE%m,%WWWW,%+CCCC%>%#,%GGGG%.# + cgetexpr ['WWWW', 'EEEE', 'CCCC'] + let &efm = save_efm + caddbuffer + bwipe! +endfunc + +func Test_caddexpr_wrong() + " This used to cause a memory access in freed memory. + cbuffer + cbuffer + copen + let save_efm = &efm + set efm=% + call assert_fails('caddexpr ""', 'E376:') + let &efm = save_efm +endfunc + +func Test_dirstack_cleanup() + " This used to cause a memory access in freed memory. + let save_efm = &efm + lexpr '0' + lopen + fun X(c) + let save_efm=&efm + set efm=%D%f + if a:c == 'c' + caddexpr '::' + else + laddexpr ':0:0' + endif + let &efm=save_efm + endfun + call X('c') + call X('l') + call setqflist([], 'r') + caddbuffer + let &efm = save_efm +endfunc + +" Tests for jumping to entries from the location list window and quickfix +" window +func Test_cwindow_jump() + set efm=%f%%%l%%%m + lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"] + lopen | only + lfirst + call assert_true(winnr('$') == 2) + call assert_true(winnr() == 1) + " Location list for the new window should be set + call assert_true(getloclist(0)[2].text == 'Line 30') + + " Open a scratch buffer + " Open a new window and create a location list + " Open the location list window and close the other window + " Jump to an entry. + " Should create a new window and jump to the entry. The scrtach buffer + " should not be used. + enew | only + set buftype=nofile + below new + lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"] + lopen + 2wincmd c + lnext + call assert_true(winnr('$') == 3) + call assert_true(winnr() == 2) + + " Open two windows with two different location lists + " Open the location list window and close the previous window + " Jump to an entry in the location list window + " Should open the file in the first window and not set the location list. + enew | only + lgetexpr ["F1%5%Line 5"] + below new + lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"] + lopen + 2wincmd c + lnext + call assert_true(winnr() == 1) + call assert_true(getloclist(0)[0].text == 'Line 5') + + enew | only + cgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"] + copen + cnext + call assert_true(winnr('$') == 2) + call assert_true(winnr() == 1) + + enew | only + set efm&vim +endfunc + +func XvimgrepTests(cchar) + call s:setup_commands(a:cchar) + + call writefile(['Editor:VIM vim', + \ 'Editor:Emacs EmAcS', + \ 'Editor:Notepad NOTEPAD'], 'Xtestfile1') + call writefile(['Linux', 'MacOS', 'MS-Windows'], 'Xtestfile2') + + " Error cases + call assert_fails('Xvimgrep /abc *', 'E682:') + + let @/='' + call assert_fails('Xvimgrep // *', 'E35:') + + call assert_fails('Xvimgrep abc', 'E683:') + call assert_fails('Xvimgrep a1b2c3 Xtestfile1', 'E480:') + call assert_fails('Xvimgrep pat Xa1b2c3', 'E480:') + + Xexpr "" + Xvimgrepadd Notepad Xtestfile1 + Xvimgrepadd MacOS Xtestfile2 + let l = g:Xgetlist() + call assert_equal(2, len(l)) + call assert_equal('Editor:Notepad NOTEPAD', l[0].text) + + Xvimgrep #\cvim#g Xtestfile? + let l = g:Xgetlist() + call assert_equal(2, len(l)) + call assert_equal(8, l[0].col) + call assert_equal(12, l[1].col) + + 1Xvimgrep ?Editor? Xtestfile* + let l = g:Xgetlist() + call assert_equal(1, len(l)) + call assert_equal('Editor:VIM vim', l[0].text) + + edit +3 Xtestfile2 + Xvimgrep +\cemacs+j Xtestfile1 + let l = g:Xgetlist() + call assert_equal('Xtestfile2', bufname('')) + call assert_equal('Editor:Emacs EmAcS', l[0].text) + + " Test for unloading a buffer after vimgrep searched the buffer + %bwipe + Xvimgrep /Editor/j Xtestfile* + call assert_equal(0, getbufinfo('Xtestfile1')[0].loaded) + call assert_equal([], getbufinfo('Xtestfile2')) + + call delete('Xtestfile1') + call delete('Xtestfile2') +endfunc + +" Tests for the :vimgrep command +func Test_vimgrep() + call XvimgrepTests('c') + call XvimgrepTests('l') +endfunc + +" Test for incsearch highlighting of the :vimgrep pattern +" This test used to cause "E315: ml_get: invalid lnum" errors. +func Test_vimgrep_incsearch() + enew + set incsearch + call test_override("char_avail", 1) + + call feedkeys(":2vimgrep assert test_quickfix.vim test_cdo.vim\<CR>", "ntx") + let l = getqflist() + call assert_equal(2, len(l)) + + call test_override("ALL", 0) + set noincsearch +endfunc + +func XfreeTests(cchar) + call s:setup_commands(a:cchar) + + enew | only + + " Deleting the quickfix stack should work even When the current list is + " somewhere in the middle of the stack + Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15'] + Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25'] + Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35'] + Xolder + call g:Xsetlist([], 'f') + call assert_equal(0, len(g:Xgetlist())) + + " After deleting the stack, adding a new list should create a stack with a + " single list. + Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15'] + call assert_equal(1, g:Xgetlist({'all':1}).nr) + + " Deleting the stack from a quickfix window should update/clear the + " quickfix/location list window. + Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15'] + Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25'] + Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35'] + Xolder + Xwindow + call g:Xsetlist([], 'f') + call assert_equal(2, winnr('$')) + call assert_equal(1, line('$')) + Xclose + + " Deleting the stack from a non-quickfix window should update/clear the + " quickfix/location list window. + Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15'] + Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25'] + Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35'] + Xolder + Xwindow + wincmd p + call g:Xsetlist([], 'f') + call assert_equal(0, len(g:Xgetlist())) + wincmd p + call assert_equal(2, winnr('$')) + call assert_equal(1, line('$')) + + " After deleting the location list stack, if the location list window is + " opened, then a new location list should be created. So opening the + " location list window again should not create a new window. + if a:cchar == 'l' + lexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15'] + wincmd p + lopen + call assert_equal(2, winnr('$')) + endif + Xclose +endfunc + +" Tests for the quickfix free functionality +func Test_qf_free() + call XfreeTests('c') + call XfreeTests('l') +endfunc + +" Test for buffer overflow when parsing lines and adding new entries to +" the quickfix list. +func Test_bufoverflow() + set efm=%f:%l:%m + cgetexpr ['File1:100:' . repeat('x', 1025)] + + set efm=%+GCompiler:\ %.%#,%f:%l:%m + cgetexpr ['Compiler: ' . repeat('a', 1015), 'File1:10:Hello World'] + + set efm=%DEntering\ directory\ %f,%f:%l:%m + cgetexpr ['Entering directory ' . repeat('a', 1006), + \ 'File1:10:Hello World'] + set efm&vim +endfunc + +" Tests for getting the quickfix stack size +func XsizeTests(cchar) + call s:setup_commands(a:cchar) + + call g:Xsetlist([], 'f') + call assert_equal(0, g:Xgetlist({'nr':'$'}).nr) + call assert_equal('', g:Xgetlist({'nr':'$', 'all':1}).title) + call assert_equal(0, g:Xgetlist({'nr':0}).nr) + + Xexpr "File1:10:Line1" + Xexpr "File2:20:Line2" + Xexpr "File3:30:Line3" + Xolder | Xolder + call assert_equal(3, g:Xgetlist({'nr':'$'}).nr) + call g:Xsetlist([], 'f') + + Xexpr "File1:10:Line1" + Xexpr "File2:20:Line2" + Xexpr "File3:30:Line3" + Xolder | Xolder + call g:Xsetlist([], 'a', {'nr':'$', 'title':'Compiler'}) + call assert_equal('Compiler', g:Xgetlist({'nr':3, 'all':1}).title) +endfunc + +func Test_Qf_Size() + call XsizeTests('c') + call XsizeTests('l') +endfunc + +func Test_cclose_from_copen() + augroup QF_Test + au! + au FileType qf :call assert_fails(':cclose', 'E788') + augroup END + copen + augroup QF_Test + au! + augroup END + augroup! QF_Test +endfunc + +func Test_cclose_in_autocmd() + " Problem is only triggered if "starting" is zero, so that the OptionsSet + " event will be triggered. + call test_override('starting', 1) + augroup QF_Test + au! + au FileType qf :call assert_fails(':cclose', 'E788') + augroup END + copen + augroup QF_Test + au! + augroup END + augroup! QF_Test + call test_override('starting', 0) +endfunc + +" Check that ":file" without an argument is possible even when "curbuf_lock" +" is set. +func Test_file_from_copen() + " Works without argument. + augroup QF_Test + au! + au FileType qf file + augroup END + copen + + augroup QF_Test + au! + augroup END + cclose + + " Fails with argument. + augroup QF_Test + au! + au FileType qf call assert_fails(':file foo', 'E788') + augroup END + copen + augroup QF_Test + au! + augroup END + cclose + + augroup! QF_Test +endfunction + +func Test_resize_from_copen() + augroup QF_Test + au! + au FileType qf resize 5 + augroup END + try + " This should succeed without any exception. No other buffers are + " involved in the autocmd. + copen + finally + augroup QF_Test + au! + augroup END + augroup! QF_Test + endtry +endfunc + +" Tests for the quickfix buffer b:changedtick variable +func Xchangedtick_tests(cchar) + call s:setup_commands(a:cchar) + + new | only + + Xexpr "" | Xexpr "" | Xexpr "" + + Xopen + Xolder + Xolder + Xaddexpr "F1:10:Line10" + Xaddexpr "F2:20:Line20" + call g:Xsetlist([{"filename":"F3", "lnum":30, "text":"Line30"}], 'a') + call g:Xsetlist([], 'f') + call assert_equal(8, getbufvar('%', 'changedtick')) + Xclose +endfunc + +func Test_changedtick() + call Xchangedtick_tests('c') + call Xchangedtick_tests('l') +endfunc + +" Tests for parsing an expression using setqflist() +func Xsetexpr_tests(cchar) + call s:setup_commands(a:cchar) + + let t = ["File1:10:Line10", "File1:20:Line20"] + call g:Xsetlist([], ' ', {'lines' : t}) + call g:Xsetlist([], 'a', {'lines' : ["File1:30:Line30"]}) + + let l = g:Xgetlist() + call assert_equal(3, len(l)) + call assert_equal(20, l[1].lnum) + call assert_equal('Line30', l[2].text) + call g:Xsetlist([], 'r', {'lines' : ["File2:5:Line5"]}) + let l = g:Xgetlist() + call assert_equal(1, len(l)) + call assert_equal('Line5', l[0].text) + call assert_equal(-1, g:Xsetlist([], 'a', {'lines' : 10})) + call assert_equal(-1, g:Xsetlist([], 'a', {'lines' : "F1:10:L10"})) + + call g:Xsetlist([], 'f') + " Add entries to multiple lists + call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["File1:10:Line10"]}) + call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:20:Line20"]}) + call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["File1:15:Line15"]}) + call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:25:Line25"]}) + call assert_equal('Line15', g:Xgetlist({'nr':1, 'items':1}).items[1].text) + call assert_equal('Line25', g:Xgetlist({'nr':2, 'items':1}).items[1].text) + + " Adding entries using a custom efm + set efm& + call g:Xsetlist([], ' ', {'efm' : '%f#%l#%m', + \ 'lines' : ["F1#10#L10", "F2#20#L20"]}) + call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum) + call g:Xsetlist([], 'a', {'efm' : '%f#%l#%m', 'lines' : ["F3:30:L30"]}) + call assert_equal('F3:30:L30', g:Xgetlist({'items':1}).items[2].text) + call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum) + call assert_equal(-1, g:Xsetlist([], 'a', {'efm' : [], + \ 'lines' : ['F1:10:L10']})) +endfunc + +func Test_setexpr() + call Xsetexpr_tests('c') + call Xsetexpr_tests('l') +endfunc + +" Tests for per quickfix/location list directory stack +func Xmultidirstack_tests(cchar) + call s:setup_commands(a:cchar) + + call g:Xsetlist([], 'f') + Xexpr "" | Xexpr "" + + call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["Entering dir 'Xone/a'"]}) + call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["Entering dir 'Xtwo/a'"]}) + call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["one.txt:3:one one one"]}) + call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["two.txt:5:two two two"]}) + + let l1 = g:Xgetlist({'nr':1, 'items':1}) + let l2 = g:Xgetlist({'nr':2, 'items':1}) + call assert_equal('Xone/a/one.txt', bufname(l1.items[1].bufnr)) + call assert_equal(3, l1.items[1].lnum) + call assert_equal('Xtwo/a/two.txt', bufname(l2.items[1].bufnr)) + call assert_equal(5, l2.items[1].lnum) +endfunc + +func Test_multidirstack() + call mkdir('Xone/a', 'p') + call mkdir('Xtwo/a', 'p') + let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7'] + call writefile(lines, 'Xone/a/one.txt') + call writefile(lines, 'Xtwo/a/two.txt') + let save_efm = &efm + set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f' + + call Xmultidirstack_tests('c') + call Xmultidirstack_tests('l') + + let &efm = save_efm + call delete('Xone', 'rf') + call delete('Xtwo', 'rf') +endfunc + +" Tests for per quickfix/location list file stack +func Xmultifilestack_tests(cchar) + call s:setup_commands(a:cchar) + + call g:Xsetlist([], 'f') + Xexpr "" | Xexpr "" + + call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["[one.txt]"]}) + call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["[two.txt]"]}) + call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["(3,5) one one one"]}) + call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["(5,9) two two two"]}) + + let l1 = g:Xgetlist({'nr':1, 'items':1}) + let l2 = g:Xgetlist({'nr':2, 'items':1}) + call assert_equal('one.txt', bufname(l1.items[1].bufnr)) + call assert_equal(3, l1.items[1].lnum) + call assert_equal('two.txt', bufname(l2.items[1].bufnr)) + call assert_equal(5, l2.items[1].lnum) + + " Test for start of a new error line in the same line where a previous + " error line ends with a file stack. + let efm_val = 'Error\ l%l\ in\ %f,' + let efm_val .= '%-P%>(%f%r,Error\ l%l\ in\ %m,%-Q)%r' + let l = g:Xgetlist({'lines' : [ + \ '(one.txt', + \ 'Error l4 in one.txt', + \ ') (two.txt', + \ 'Error l6 in two.txt', + \ ')', + \ 'Error l8 in one.txt' + \ ], 'efm' : efm_val}) + call assert_equal(3, len(l.items)) + call assert_equal('one.txt', bufname(l.items[0].bufnr)) + call assert_equal(4, l.items[0].lnum) + call assert_equal('one.txt', l.items[0].text) + call assert_equal('two.txt', bufname(l.items[1].bufnr)) + call assert_equal(6, l.items[1].lnum) + call assert_equal('two.txt', l.items[1].text) + call assert_equal('one.txt', bufname(l.items[2].bufnr)) + call assert_equal(8, l.items[2].lnum) + call assert_equal('', l.items[2].text) +endfunc + +func Test_multifilestack() + let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7'] + call writefile(lines, 'one.txt') + call writefile(lines, 'two.txt') + let save_efm = &efm + set efm=%+P[%f],(%l\\,%c)\ %m,%-Q + + call Xmultifilestack_tests('c') + call Xmultifilestack_tests('l') + + let &efm = save_efm + call delete('one.txt') + call delete('two.txt') +endfunc + +" Tests for per buffer 'efm' setting +func Test_perbuf_efm() + call writefile(["File1-10-Line10"], 'one.txt') + call writefile(["File2#20#Line20"], 'two.txt') + set efm=%f#%l#%m + new | only + new + setlocal efm=%f-%l-%m + cfile one.txt + wincmd w + caddfile two.txt + + let l = getqflist() + call assert_equal(10, l[0].lnum) + call assert_equal('Line20', l[1].text) + + set efm& + new | only + call delete('one.txt') + call delete('two.txt') +endfunc + +" Open multiple help windows using ":lhelpgrep +" This test used to crash Vim +func Test_Multi_LL_Help() + new | only + lhelpgrep window + lopen + e# + lhelpgrep buffer + call assert_equal(3, winnr('$')) + call assert_true(len(getloclist(1)) != 0) + call assert_true(len(getloclist(2)) != 0) + new | only +endfunc + +" Tests for adding new quickfix lists using setqflist() +func XaddQf_tests(cchar) + call s:setup_commands(a:cchar) + + " Create a new list using ' ' for action + call g:Xsetlist([], 'f') + call g:Xsetlist([], ' ', {'title' : 'Test1'}) + let l = g:Xgetlist({'nr' : '$', 'all' : 1}) + call assert_equal(1, l.nr) + call assert_equal('Test1', l.title) + + " Create a new list using ' ' for action and '$' for 'nr' + call g:Xsetlist([], 'f') + call g:Xsetlist([], ' ', {'title' : 'Test2', 'nr' : '$'}) + let l = g:Xgetlist({'nr' : '$', 'all' : 1}) + call assert_equal(1, l.nr) + call assert_equal('Test2', l.title) + + " Create a new list using 'a' for action + call g:Xsetlist([], 'f') + call g:Xsetlist([], 'a', {'title' : 'Test3'}) + let l = g:Xgetlist({'nr' : '$', 'all' : 1}) + call assert_equal(1, l.nr) + call assert_equal('Test3', l.title) + + " Create a new list using 'a' for action and '$' for 'nr' + call g:Xsetlist([], 'f') + call g:Xsetlist([], 'a', {'title' : 'Test3', 'nr' : '$'}) + call g:Xsetlist([], 'a', {'title' : 'Test4'}) + let l = g:Xgetlist({'nr' : '$', 'all' : 1}) + call assert_equal(1, l.nr) + call assert_equal('Test4', l.title) + + " Adding a quickfix list should remove all the lists following the current + " list. + Xexpr "" | Xexpr "" | Xexpr "" + silent! 10Xolder + call g:Xsetlist([], ' ', {'title' : 'Test5'}) + let l = g:Xgetlist({'nr' : '$', 'all' : 1}) + call assert_equal(2, l.nr) + call assert_equal('Test5', l.title) + + " Add a quickfix list using '$' as the list number. + let lastqf = g:Xgetlist({'nr':'$'}).nr + silent! 99Xolder + call g:Xsetlist([], ' ', {'nr' : '$', 'title' : 'Test6'}) + let l = g:Xgetlist({'nr' : '$', 'all' : 1}) + call assert_equal(lastqf + 1, l.nr) + call assert_equal('Test6', l.title) + + " Add a quickfix list using 'nr' set to one more than the quickfix + " list size. + let lastqf = g:Xgetlist({'nr':'$'}).nr + silent! 99Xolder + call g:Xsetlist([], ' ', {'nr' : lastqf + 1, 'title' : 'Test7'}) + let l = g:Xgetlist({'nr' : '$', 'all' : 1}) + call assert_equal(lastqf + 1, l.nr) + call assert_equal('Test7', l.title) + + " Add a quickfix list to a stack with 10 lists using 'nr' set to '$' + exe repeat('Xexpr "" |', 9) . 'Xexpr ""' + silent! 99Xolder + call g:Xsetlist([], ' ', {'nr' : '$', 'title' : 'Test8'}) + let l = g:Xgetlist({'nr' : '$', 'all' : 1}) + call assert_equal(10, l.nr) + call assert_equal('Test8', l.title) + + " Add a quickfix list using 'nr' set to a value greater than 10 + call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : 12, 'title' : 'Test9'})) + + " Try adding a quickfix list with 'nr' set to a value greater than the + " quickfix list size but less than 10. + call g:Xsetlist([], 'f') + Xexpr "" | Xexpr "" | Xexpr "" + silent! 99Xolder + call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : 8, 'title' : 'Test10'})) + + " Add a quickfix list using 'nr' set to a some string or list + call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : [1,2], 'title' : 'Test11'})) +endfunc + +func Test_add_qf() + call XaddQf_tests('c') + call XaddQf_tests('l') +endfunc + +" Test for getting the quickfix list items from some text without modifying +" the quickfix stack +func XgetListFromLines(cchar) + call s:setup_commands(a:cchar) + call g:Xsetlist([], 'f') + + let l = g:Xgetlist({'lines' : ["File2:20:Line20", "File2:30:Line30"]}).items + call assert_equal(2, len(l)) + call assert_equal(30, l[1].lnum) + + call assert_equal({}, g:Xgetlist({'lines' : 10})) + call assert_equal({}, g:Xgetlist({'lines' : 'File1:10:Line10'})) + call assert_equal([], g:Xgetlist({'lines' : []}).items) + call assert_equal([], g:Xgetlist({'lines' : [10, 20]}).items) + + " Parse text using a custom efm + set efm& + let l = g:Xgetlist({'lines':['File3#30#Line30'], 'efm' : '%f#%l#%m'}).items + call assert_equal('Line30', l[0].text) + let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : '%f-%l-%m'}).items + call assert_equal('File3:30:Line30', l[0].text) + let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : [1,2]}) + call assert_equal({}, l) + call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':'%2'})", 'E376:') + call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':''})", 'E378:') + + " Make sure that the quickfix stack is not modified + call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr) +endfunc + +func Test_get_list_from_lines() + call XgetListFromLines('c') + call XgetListFromLines('l') +endfunc + +" Tests for the quickfix list id +func Xqfid_tests(cchar) + call s:setup_commands(a:cchar) + + call g:Xsetlist([], 'f') + call assert_equal(0, g:Xgetlist({'id':0}).id) + Xexpr '' + let start_id = g:Xgetlist({'id' : 0}).id + Xexpr '' | Xexpr '' + Xolder + call assert_equal(start_id, g:Xgetlist({'id':0, 'nr':1}).id) + call assert_equal(start_id + 1, g:Xgetlist({'id':0, 'nr':0}).id) + call assert_equal(start_id + 2, g:Xgetlist({'id':0, 'nr':'$'}).id) + call assert_equal(0, g:Xgetlist({'id':0, 'nr':99}).id) + call assert_equal(2, g:Xgetlist({'id':start_id + 1, 'nr':0}).nr) + call assert_equal(0, g:Xgetlist({'id':99, 'nr':0}).id) + call assert_equal(0, g:Xgetlist({'id':"abc", 'nr':0}).id) + + call g:Xsetlist([], 'a', {'id':start_id, 'context':[1,2]}) + call assert_equal([1,2], g:Xgetlist({'nr':1, 'context':1}).context) + call g:Xsetlist([], 'a', {'id':start_id+1, 'lines':['F1:10:L10']}) + call assert_equal('L10', g:Xgetlist({'nr':2, 'items':1}).items[0].text) + call assert_equal(-1, g:Xsetlist([], 'a', {'id':999, 'title':'Vim'})) + call assert_equal(-1, g:Xsetlist([], 'a', {'id':'abc', 'title':'Vim'})) + + let qfid = g:Xgetlist({'id':0, 'nr':0}) + call g:Xsetlist([], 'f') + call assert_equal(0, g:Xgetlist({'id':qfid, 'nr':0}).id) +endfunc + +func Test_qf_id() + call Xqfid_tests('c') + call Xqfid_tests('l') +endfunc + +func Xqfjump_tests(cchar) + call s:setup_commands(a:cchar) + + call writefile(["Line1\tFoo", "Line2"], 'F1') + call writefile(["Line1\tBar", "Line2"], 'F2') + call writefile(["Line1\tBaz", "Line2"], 'F3') + + call g:Xsetlist([], 'f') + + " Tests for + " Jumping to a line using a pattern + " Jumping to a column greater than the last column in a line + " Jumping to a line greater than the last line in the file + let l = [] + for i in range(1, 7) + call add(l, {}) + endfor + let l[0].filename='F1' + let l[0].pattern='Line1' + let l[1].filename='F2' + let l[1].pattern='Line1' + let l[2].filename='F3' + let l[2].pattern='Line1' + let l[3].filename='F3' + let l[3].lnum=1 + let l[3].col=9 + let l[3].vcol=1 + let l[4].filename='F3' + let l[4].lnum=99 + let l[5].filename='F3' + let l[5].lnum=1 + let l[5].col=99 + let l[5].vcol=1 + let l[6].filename='F3' + let l[6].pattern='abcxyz' + + call g:Xsetlist([], ' ', {'items' : l}) + Xopen | only + 2Xnext + call assert_equal(3, g:Xgetlist({'idx' : 0}).idx) + call assert_equal('F3', bufname('%')) + Xnext + call assert_equal(7, col('.')) + Xnext + call assert_equal(2, line('.')) + Xnext + call assert_equal(9, col('.')) + 2 + Xnext + call assert_equal(2, line('.')) + + if a:cchar == 'l' + " When jumping to a location list entry in the location list window and + " no usable windows are available, then a new window should be opened. + enew! | new | only + call g:Xsetlist([], 'f') + setlocal buftype=nofile + new + call g:Xsetlist([], ' ', {'lines' : ['F1:1:1:Line1', 'F1:2:2:Line2', 'F2:1:1:Line1', 'F2:2:2:Line2', 'F3:1:1:Line1', 'F3:2:2:Line2']}) + Xopen + let winid = win_getid() + wincmd p + close + call win_gotoid(winid) + Xnext + call assert_equal(3, winnr('$')) + call assert_equal(1, winnr()) + call assert_equal(2, line('.')) + + " When jumping to an entry in the location list window and the window + " associated with the location list is not present and a window containing + " the file is already present, then that window should be used. + close + belowright new + call g:Xsetlist([], 'f') + edit F3 + call win_gotoid(winid) + Xlast + call assert_equal(3, winnr()) + call assert_equal(6, g:Xgetlist({'size' : 1}).size) + call assert_equal(winid, g:Xgetlist({'winid' : 1}).winid) + endif + + " Cleanup + enew! + new | only + + call delete('F1') + call delete('F2') + call delete('F3') +endfunc + +func Test_qfjump() + call Xqfjump_tests('c') + call Xqfjump_tests('l') +endfunc + +" Tests for the getqflist() and getloclist() functions when the list is not +" present or is empty +func Xgetlist_empty_tests(cchar) + call s:setup_commands(a:cchar) + + " Empty quickfix stack + call g:Xsetlist([], 'f') + call assert_equal('', g:Xgetlist({'context' : 0}).context) + call assert_equal(0, g:Xgetlist({'id' : 0}).id) + call assert_equal(0, g:Xgetlist({'idx' : 0}).idx) + call assert_equal([], g:Xgetlist({'items' : 0}).items) + call assert_equal(0, g:Xgetlist({'nr' : 0}).nr) + call assert_equal(0, g:Xgetlist({'size' : 0}).size) + call assert_equal('', g:Xgetlist({'title' : 0}).title) + call assert_equal(0, g:Xgetlist({'winid' : 0}).winid) + call assert_equal(0, g:Xgetlist({'changedtick' : 0}).changedtick) + if a:cchar == 'c' + call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, + \ 'items' : [], 'nr' : 0, 'size' : 0, + \ 'title' : '', 'winid' : 0, 'changedtick': 0}, + \ g:Xgetlist({'all' : 0})) + else + call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, + \ 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '', + \ 'winid' : 0, 'changedtick': 0, 'filewinid' : 0}, + \ g:Xgetlist({'all' : 0})) + endif + + " Quickfix window with empty stack + silent! Xopen + let qfwinid = (a:cchar == 'c') ? win_getid() : 0 + call assert_equal(qfwinid, g:Xgetlist({'winid' : 0}).winid) + Xclose + + " Empty quickfix list + Xexpr "" + call assert_equal('', g:Xgetlist({'context' : 0}).context) + call assert_notequal(0, g:Xgetlist({'id' : 0}).id) + call assert_equal(0, g:Xgetlist({'idx' : 0}).idx) + call assert_equal([], g:Xgetlist({'items' : 0}).items) + call assert_notequal(0, g:Xgetlist({'nr' : 0}).nr) + call assert_equal(0, g:Xgetlist({'size' : 0}).size) + call assert_notequal('', g:Xgetlist({'title' : 0}).title) + call assert_equal(0, g:Xgetlist({'winid' : 0}).winid) + call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick) + + let qfid = g:Xgetlist({'id' : 0}).id + call g:Xsetlist([], 'f') + + " Non-existing quickfix identifier + call assert_equal('', g:Xgetlist({'id' : qfid, 'context' : 0}).context) + call assert_equal(0, g:Xgetlist({'id' : qfid}).id) + call assert_equal(0, g:Xgetlist({'id' : qfid, 'idx' : 0}).idx) + call assert_equal([], g:Xgetlist({'id' : qfid, 'items' : 0}).items) + call assert_equal(0, g:Xgetlist({'id' : qfid, 'nr' : 0}).nr) + call assert_equal(0, g:Xgetlist({'id' : qfid, 'size' : 0}).size) + call assert_equal('', g:Xgetlist({'id' : qfid, 'title' : 0}).title) + call assert_equal(0, g:Xgetlist({'id' : qfid, 'winid' : 0}).winid) + call assert_equal(0, g:Xgetlist({'id' : qfid, 'changedtick' : 0}).changedtick) + if a:cchar == 'c' + call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], + \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0, + \ 'changedtick' : 0}, g:Xgetlist({'id' : qfid, 'all' : 0})) + else + call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], + \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0, + \ 'changedtick' : 0, 'filewinid' : 0}, + \ g:Xgetlist({'id' : qfid, 'all' : 0})) + endif + + " Non-existing quickfix list number + call assert_equal('', g:Xgetlist({'nr' : 5, 'context' : 0}).context) + call assert_equal(0, g:Xgetlist({'nr' : 5}).nr) + call assert_equal(0, g:Xgetlist({'nr' : 5, 'idx' : 0}).idx) + call assert_equal([], g:Xgetlist({'nr' : 5, 'items' : 0}).items) + call assert_equal(0, g:Xgetlist({'nr' : 5, 'id' : 0}).id) + call assert_equal(0, g:Xgetlist({'nr' : 5, 'size' : 0}).size) + call assert_equal('', g:Xgetlist({'nr' : 5, 'title' : 0}).title) + call assert_equal(0, g:Xgetlist({'nr' : 5, 'winid' : 0}).winid) + call assert_equal(0, g:Xgetlist({'nr' : 5, 'changedtick' : 0}).changedtick) + if a:cchar == 'c' + call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], + \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0, + \ 'changedtick' : 0}, g:Xgetlist({'nr' : 5, 'all' : 0})) + else + call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], + \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0, + \ 'changedtick' : 0, 'filewinid' : 0}, + \ g:Xgetlist({'nr' : 5, 'all' : 0})) + endif +endfunc + +func Test_getqflist() + call Xgetlist_empty_tests('c') + call Xgetlist_empty_tests('l') +endfunc + +func Test_getqflist_invalid_nr() + " The following commands used to crash Vim + cexpr "" + call getqflist({'nr' : $XXX_DOES_NOT_EXIST_XXX}) + + " Cleanup + call setqflist([], 'r') +endfunc + +" Tests for the quickfix/location list changedtick +func Xqftick_tests(cchar) + call s:setup_commands(a:cchar) + + call g:Xsetlist([], 'f') + + Xexpr "F1:10:Line10" + let qfid = g:Xgetlist({'id' : 0}).id + call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick) + Xaddexpr "F2:20:Line20\nF2:21:Line21" + call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick) + call g:Xsetlist([], 'a', {'lines' : ["F3:30:Line30", "F3:31:Line31"]}) + call assert_equal(3, g:Xgetlist({'changedtick' : 0}).changedtick) + call g:Xsetlist([], 'r', {'lines' : ["F4:40:Line40"]}) + call assert_equal(4, g:Xgetlist({'changedtick' : 0}).changedtick) + call g:Xsetlist([], 'a', {'title' : 'New Title'}) + call assert_equal(5, g:Xgetlist({'changedtick' : 0}).changedtick) + + enew! + call append(0, ["F5:50:L50", "F6:60:L60"]) + Xaddbuffer + call assert_equal(6, g:Xgetlist({'changedtick' : 0}).changedtick) + enew! + + call g:Xsetlist([], 'a', {'context' : {'bus' : 'pci'}}) + call assert_equal(7, g:Xgetlist({'changedtick' : 0}).changedtick) + call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'}, + \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], 'a') + call assert_equal(8, g:Xgetlist({'changedtick' : 0}).changedtick) + call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'}, + \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], ' ') + call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick) + call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'}, + \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], 'r') + call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick) + + call writefile(["F8:80:L80", "F8:81:L81"], "Xone") + Xfile Xone + call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick) + Xaddfile Xone + call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick) + + " Test case for updating a non-current quickfix list + call g:Xsetlist([], 'f') + Xexpr "F1:1:L1" + Xexpr "F2:2:L2" + call g:Xsetlist([], 'a', {'nr' : 1, "lines" : ["F10:10:L10"]}) + call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick) + call assert_equal(2, g:Xgetlist({'nr' : 1, 'changedtick' : 0}).changedtick) + + call delete("Xone") +endfunc + +func Test_qf_tick() + call Xqftick_tests('c') + call Xqftick_tests('l') +endfunc + +" Test helpgrep with lang specifier +func Xtest_helpgrep_with_lang_specifier(cchar) + call s:setup_commands(a:cchar) + Xhelpgrep Vim@en + call assert_equal('help', &filetype) + call assert_notequal(0, g:Xgetlist({'nr' : '$'}).nr) + new | only +endfunc + +func Test_helpgrep_with_lang_specifier() + call Xtest_helpgrep_with_lang_specifier('c') + call Xtest_helpgrep_with_lang_specifier('l') +endfunc + +" The following test used to crash Vim. +" Open the location list window and close the regular window associated with +" the location list. When the garbage collection runs now, it incorrectly +" marks the location list context as not in use and frees the context. +func Test_ll_window_ctx() + call setloclist(0, [], 'f') + call setloclist(0, [], 'a', {'context' : []}) + lopen | only + call test_garbagecollect_now() + echo getloclist(0, {'context' : 1}).context + enew | only +endfunc + +" The following test used to crash vim +func Test_lfile_crash() + sp Xtest + au QuickFixCmdPre * bw + call assert_fails('lfile', 'E40') + au! QuickFixCmdPre +endfunc + +" The following test used to crash vim +func Test_lbuffer_crash() + sv Xtest + augroup QF_Test + au! + au * * bw + augroup END + lbuffer + augroup QF_Test + au! + augroup END +endfunc + +" The following test used to crash vim +func Test_lexpr_crash() + augroup QF_Test + au! + au * * call setloclist(0, [], 'f') + augroup END + lexpr "" + augroup QF_Test + au! + augroup END + + enew | only + augroup QF_Test + au! + au BufNew * call setloclist(0, [], 'f') + augroup END + lexpr 'x:1:x' + augroup QF_Test + au! + augroup END + + enew | only + lexpr '' + lopen + augroup QF_Test + au! + au FileType * call setloclist(0, [], 'f') + augroup END + lexpr '' + augroup QF_Test + au! + augroup END +endfunc + +" The following test used to crash Vim +func Test_lvimgrep_crash() + sv Xtest + augroup QF_Test + au! + au * * call setloclist(0, [], 'f') + augroup END + lvimgrep quickfix test_quickfix.vim + augroup QF_Test + au! + augroup END + + new | only + augroup QF_Test + au! + au BufEnter * call setloclist(0, [], 'r') + augroup END + call assert_fails('lvimgrep Test_lvimgrep_crash *', 'E926:') + augroup QF_Test + au! + augroup END + + enew | only +endfunc + +" Test for the position of the quickfix and location list window +func Test_qfwin_pos() + " Open two windows + new | only + new + cexpr ['F1:10:L10'] + copen + " Quickfix window should be the bottom most window + call assert_equal(3, winnr()) + close + " Open at the very top + wincmd t + topleft copen + call assert_equal(1, winnr()) + close + " open left of the current window + wincmd t + below new + leftabove copen + call assert_equal(2, winnr()) + close + " open right of the current window + rightbelow copen + call assert_equal(3, winnr()) + close +endfunc + +" Tests for quickfix/location lists changed by autocommands when +" :vimgrep/:lvimgrep commands are running. +func Test_vimgrep_autocmd() + call setqflist([], 'f') + call writefile(['stars'], 'Xtest1.txt') + call writefile(['stars'], 'Xtest2.txt') + + " Test 1: + " When searching for a pattern using :vimgrep, if the quickfix list is + " changed by an autocmd, the results should be added to the correct quickfix + " list. + autocmd BufRead Xtest2.txt cexpr '' | cexpr '' + silent vimgrep stars Xtest*.txt + call assert_equal(1, getqflist({'nr' : 0}).nr) + call assert_equal(3, getqflist({'nr' : '$'}).nr) + call assert_equal('Xtest2.txt', bufname(getqflist()[1].bufnr)) + au! BufRead Xtest2.txt + + " Test 2: + " When searching for a pattern using :vimgrep, if the quickfix list is + " freed, then a error should be given. + silent! %bwipe! + call setqflist([], 'f') + autocmd BufRead Xtest2.txt for i in range(10) | cexpr '' | endfor + call assert_fails('vimgrep stars Xtest*.txt', 'E925:') + au! BufRead Xtest2.txt + + " Test 3: + " When searching for a pattern using :lvimgrep, if the location list is + " freed, then the command should error out. + silent! %bwipe! + let g:save_winid = win_getid() + autocmd BufRead Xtest2.txt call setloclist(g:save_winid, [], 'f') + call assert_fails('lvimgrep stars Xtest*.txt', 'E926:') + au! BufRead Xtest2.txt + + call delete('Xtest1.txt') + call delete('Xtest2.txt') + call setqflist([], 'f') +endfunc + +" The following test used to crash Vim +func Test_lhelpgrep_autocmd() + lhelpgrep quickfix + autocmd QuickFixCmdPost * call setloclist(0, [], 'f') + lhelpgrep buffer + call assert_equal('help', &filetype) + call assert_equal(0, getloclist(0, {'nr' : '$'}).nr) + lhelpgrep tabpage + call assert_equal('help', &filetype) + call assert_equal(1, getloclist(0, {'nr' : '$'}).nr) + au! QuickFixCmdPost + + new | only + augroup QF_Test + au! + au BufEnter * call setqflist([], 'f') + augroup END + call assert_fails('helpgrep quickfix', 'E925:') + augroup QF_Test + au! BufEnter + augroup END + + new | only + augroup QF_Test + au! + au BufEnter * call setqflist([], 'r') + augroup END + call assert_fails('helpgrep quickfix', 'E925:') + augroup QF_Test + au! BufEnter + augroup END + + new | only + augroup QF_Test + au! + au BufEnter * call setloclist(0, [], 'r') + augroup END + call assert_fails('lhelpgrep quickfix', 'E926:') + augroup QF_Test + au! BufEnter + augroup END + + new | only +endfunc + +" Test for shortening/simplifying the file name when opening the +" quickfix window or when displaying the quickfix list +func Test_shorten_fname() + if !has('unix') + return + endif + %bwipe + " Create a quickfix list with a absolute path filename + let fname = getcwd() . '/test_quickfix.vim' + call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'}) + call assert_equal(fname, bufname('test_quickfix.vim')) + " Opening the quickfix window should simplify the file path + cwindow + call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim')) + cclose + %bwipe + " Create a quickfix list with a absolute path filename + call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'}) + call assert_equal(fname, bufname('test_quickfix.vim')) + " Displaying the quickfix list should simplify the file path + silent! clist + call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim')) +endfunc + +" Quickfix title tests +" In the below tests, 'exe "cmd"' is used to invoke the quickfix commands. +" Otherwise due to indentation, the title is set with spaces at the beginning +" of the command. +func Test_qftitle() + call writefile(["F1:1:Line1"], 'Xerr') + + " :cexpr + exe "cexpr readfile('Xerr')" + call assert_equal(":cexpr readfile('Xerr')", getqflist({'title' : 1}).title) + + " :cgetexpr + exe "cgetexpr readfile('Xerr')" + call assert_equal(":cgetexpr readfile('Xerr')", + \ getqflist({'title' : 1}).title) + + " :caddexpr + call setqflist([], 'f') + exe "caddexpr readfile('Xerr')" + call assert_equal(":caddexpr readfile('Xerr')", + \ getqflist({'title' : 1}).title) + + " :cbuffer + new Xerr + exe "cbuffer" + call assert_equal(':cbuffer (Xerr)', getqflist({'title' : 1}).title) + + " :cgetbuffer + edit Xerr + exe "cgetbuffer" + call assert_equal(':cgetbuffer (Xerr)', getqflist({'title' : 1}).title) + + " :caddbuffer + call setqflist([], 'f') + edit Xerr + exe "caddbuffer" + call assert_equal(':caddbuffer (Xerr)', getqflist({'title' : 1}).title) + + " :cfile + exe "cfile Xerr" + call assert_equal(':cfile Xerr', getqflist({'title' : 1}).title) + + " :cgetfile + exe "cgetfile Xerr" + call assert_equal(':cgetfile Xerr', getqflist({'title' : 1}).title) + + " :caddfile + call setqflist([], 'f') + exe "caddfile Xerr" + call assert_equal(':caddfile Xerr', getqflist({'title' : 1}).title) + + " :grep + set grepprg=internal + exe "grep F1 Xerr" + call assert_equal(':grep F1 Xerr', getqflist({'title' : 1}).title) + + " :grepadd + call setqflist([], 'f') + exe "grepadd F1 Xerr" + call assert_equal(':grepadd F1 Xerr', getqflist({'title' : 1}).title) + set grepprg&vim + + " :vimgrep + exe "vimgrep F1 Xerr" + call assert_equal(':vimgrep F1 Xerr', getqflist({'title' : 1}).title) + + " :vimgrepadd + call setqflist([], 'f') + exe "vimgrepadd F1 Xerr" + call assert_equal(':vimgrepadd F1 Xerr', getqflist({'title' : 1}).title) + + call setqflist(['F1:10:L10'], ' ') + call assert_equal(':setqflist()', getqflist({'title' : 1}).title) + + call setqflist([], 'f') + call setqflist(['F1:10:L10'], 'a') + call assert_equal(':setqflist()', getqflist({'title' : 1}).title) + + call setqflist([], 'f') + call setqflist(['F1:10:L10'], 'r') + call assert_equal(':setqflist()', getqflist({'title' : 1}).title) + + close + call delete('Xerr') + + call setqflist([], ' ', {'title' : 'Errors'}) + copen + call assert_equal('Errors', w:quickfix_title) + call setqflist([], 'r', {'items' : [{'filename' : 'a.c', 'lnum' : 10}]}) + call assert_equal('Errors', w:quickfix_title) + cclose +endfunc + +func Test_lbuffer_with_bwipe() + new + new + augroup nasty + au * * bwipe + augroup END + lbuffer + augroup nasty + au! + augroup END +endfunc + +" Test for an autocmd freeing the quickfix/location list when cexpr/lexpr is +" running +func Xexpr_acmd_freelist(cchar) + call s:setup_commands(a:cchar) + + " This was using freed memory. + augroup nasty + au * * call g:Xsetlist([], 'f') + augroup END + Xexpr "x" + augroup nasty + au! + augroup END +endfunc + +func Test_cexpr_acmd_freelist() + call Xexpr_acmd_freelist('c') + call Xexpr_acmd_freelist('l') +endfunc + +" Test for commands that create a new quickfix/location list and jump to the +" first error automatically. +func Xjumpto_first_error_test(cchar) + call s:setup_commands(a:cchar) + + call s:create_test_file('Xtestfile1') + call s:create_test_file('Xtestfile2') + let l = ['Xtestfile1:2:Line2', 'Xtestfile2:4:Line4'] + + " Test for cexpr/lexpr + enew + Xexpr l + call assert_equal('Xtestfile1', bufname('')) + call assert_equal(2, line('.')) + + " Test for cfile/lfile + enew + call writefile(l, 'Xerr') + Xfile Xerr + call assert_equal('Xtestfile1', bufname('')) + call assert_equal(2, line('.')) + + " Test for cbuffer/lbuffer + edit Xerr + Xbuffer + call assert_equal('Xtestfile1', bufname('')) + call assert_equal(2, line('.')) + + call delete('Xerr') + call delete('Xtestfile1') + call delete('Xtestfile2') +endfunc + +func Test_jumpto_first_error() + call Xjumpto_first_error_test('c') + call Xjumpto_first_error_test('l') +endfunc + +" Test for a quickfix autocmd changing the quickfix/location list before +" jumping to the first error in the new list. +func Xautocmd_changelist(cchar) + call s:setup_commands(a:cchar) + + " Test for cfile/lfile + call s:create_test_file('Xtestfile1') + call s:create_test_file('Xtestfile2') + Xexpr 'Xtestfile1:2:Line2' + autocmd QuickFixCmdPost * Xolder + call writefile(['Xtestfile2:4:Line4'], 'Xerr') + Xfile Xerr + call assert_equal('Xtestfile2', bufname('')) + call assert_equal(4, line('.')) + autocmd! QuickFixCmdPost + + " Test for cbuffer/lbuffer + call g:Xsetlist([], 'f') + Xexpr 'Xtestfile1:2:Line2' + autocmd QuickFixCmdPost * Xolder + call writefile(['Xtestfile2:4:Line4'], 'Xerr') + edit Xerr + Xbuffer + call assert_equal('Xtestfile2', bufname('')) + call assert_equal(4, line('.')) + autocmd! QuickFixCmdPost + + " Test for cexpr/lexpr + call g:Xsetlist([], 'f') + Xexpr 'Xtestfile1:2:Line2' + autocmd QuickFixCmdPost * Xolder + Xexpr 'Xtestfile2:4:Line4' + call assert_equal('Xtestfile2', bufname('')) + call assert_equal(4, line('.')) + autocmd! QuickFixCmdPost + + " The grepprg may not be set on non-Unix systems + if has('unix') + " Test for grep/lgrep + call g:Xsetlist([], 'f') + Xexpr 'Xtestfile1:2:Line2' + autocmd QuickFixCmdPost * Xolder + silent Xgrep Line5 Xtestfile2 + call assert_equal('Xtestfile2', bufname('')) + call assert_equal(5, line('.')) + autocmd! QuickFixCmdPost + endif + + " Test for vimgrep/lvimgrep + call g:Xsetlist([], 'f') + Xexpr 'Xtestfile1:2:Line2' + autocmd QuickFixCmdPost * Xolder + silent Xvimgrep Line5 Xtestfile2 + call assert_equal('Xtestfile2', bufname('')) + call assert_equal(5, line('.')) + autocmd! QuickFixCmdPost + + " Test for autocommands clearing the quickfix list before jumping to the + " first error. This should not result in an error + autocmd QuickFixCmdPost * call g:Xsetlist([], 'r') + let v:errmsg = '' + " Test for cfile/lfile + Xfile Xerr + call assert_true(v:errmsg !~# 'E42:') + " Test for cbuffer/lbuffer + edit Xerr + Xbuffer + call assert_true(v:errmsg !~# 'E42:') + " Test for cexpr/lexpr + Xexpr 'Xtestfile2:4:Line4' + call assert_true(v:errmsg !~# 'E42:') + " Test for grep/lgrep + " The grepprg may not be set on non-Unix systems + if has('unix') + silent Xgrep Line5 Xtestfile2 + call assert_true(v:errmsg !~# 'E42:') + endif + " Test for vimgrep/lvimgrep + call assert_fails('silent Xvimgrep Line5 Xtestfile2', 'E480:') + autocmd! QuickFixCmdPost + + call delete('Xerr') + call delete('Xtestfile1') + call delete('Xtestfile2') +endfunc + +func Test_autocmd_changelist() + call Xautocmd_changelist('c') + call Xautocmd_changelist('l') +endfunc + +" Tests for the ':filter /pat/ clist' command +func Test_filter_clist() + cexpr ['Xfile1:10:10:Line 10', 'Xfile2:15:15:Line 15'] + call assert_equal([' 2 Xfile2:15 col 15: Line 15'], + \ split(execute('filter /Line 15/ clist'), "\n")) + call assert_equal([' 1 Xfile1:10 col 10: Line 10'], + \ split(execute('filter /Xfile1/ clist'), "\n")) + call assert_equal([], split(execute('filter /abc/ clist'), "\n")) + + call setqflist([{'module' : 'abc', 'pattern' : 'pat1'}, + \ {'module' : 'pqr', 'pattern' : 'pat2'}], ' ') + call assert_equal([' 2 pqr:pat2: '], + \ split(execute('filter /pqr/ clist'), "\n")) + call assert_equal([' 1 abc:pat1: '], + \ split(execute('filter /pat1/ clist'), "\n")) +endfunc + +" Tests for the "CTRL-W <CR>" command. +func Xview_result_split_tests(cchar) + call s:setup_commands(a:cchar) + + " Test that "CTRL-W <CR>" in a qf/ll window fails with empty list. + call g:Xsetlist([]) + Xopen + let l:win_count = winnr('$') + call assert_fails('execute "normal! \<C-W>\<CR>"', 'E42') + call assert_equal(l:win_count, winnr('$')) + Xclose +endfunc + +func Test_view_result_split() + call Xview_result_split_tests('c') + call Xview_result_split_tests('l') +endfunc + +" Test that :cc sets curswant +func Test_curswant() + helpgrep quickfix + normal! llll + 1cc + call assert_equal(getcurpos()[4], virtcol('.')) + cclose | helpclose +endfunc + +" Test for opening a file from the quickfix window using CTRL-W <Enter> +" doesn't leave an empty buffer around. +func Test_splitview() + call s:create_test_file('Xtestfile1') + call s:create_test_file('Xtestfile2') + new | only + let last_bufnr = bufnr('Test_sv_1', 1) + let l = ['Xtestfile1:2:Line2', 'Xtestfile2:4:Line4'] + cgetexpr l + copen + let numbufs = len(getbufinfo()) + exe "normal \<C-W>\<CR>" + copen + exe "normal j\<C-W>\<CR>" + " Make sure new empty buffers are not created + call assert_equal(numbufs, len(getbufinfo())) + " Creating a new buffer should use the next available buffer number + call assert_equal(last_bufnr + 4, bufnr("Test_sv_2", 1)) + bwipe Test_sv_1 + bwipe Test_sv_2 + new | only + + " When split opening files from location list window, make sure that two + " windows doesn't refer to the same location list + lgetexpr l + let locid = getloclist(0, {'id' : 0}).id + lopen + exe "normal \<C-W>\<CR>" + call assert_notequal(locid, getloclist(0, {'id' : 0}).id) + call assert_equal(0, getloclist(0, {'winid' : 0}).winid) + new | only + + " When split opening files from a helpgrep location list window, a new help + " window should be opend with a copy of the location list. + lhelpgrep window + let locid = getloclist(0, {'id' : 0}).id + lwindow + exe "normal j\<C-W>\<CR>" + call assert_notequal(locid, getloclist(0, {'id' : 0}).id) + call assert_equal(0, getloclist(0, {'winid' : 0}).winid) + new | only + + call delete('Xtestfile1') + call delete('Xtestfile2') +endfunc + +" Test for parsing entries using visual screen column +func Test_viscol() + enew + call writefile(["Col1\tCol2\tCol3"], 'Xfile1') + edit Xfile1 + + " Use byte offset for column number + set efm& + cexpr "Xfile1:1:5:XX\nXfile1:1:9:YY\nXfile1:1:20:ZZ" + call assert_equal([5, 8], [col('.'), virtcol('.')]) + cnext + call assert_equal([9, 12], [col('.'), virtcol('.')]) + cnext + call assert_equal([14, 20], [col('.'), virtcol('.')]) + + " Use screen column offset for column number + set efm=%f:%l:%v:%m + cexpr "Xfile1:1:8:XX\nXfile1:1:12:YY\nXfile1:1:20:ZZ" + call assert_equal([5, 8], [col('.'), virtcol('.')]) + cnext + call assert_equal([9, 12], [col('.'), virtcol('.')]) + cnext + call assert_equal([14, 20], [col('.'), virtcol('.')]) + cexpr "Xfile1:1:6:XX\nXfile1:1:15:YY\nXfile1:1:24:ZZ" + call assert_equal([5, 8], [col('.'), virtcol('.')]) + cnext + call assert_equal([10, 16], [col('.'), virtcol('.')]) + cnext + call assert_equal([14, 20], [col('.'), virtcol('.')]) + + enew + call writefile(["Col1\täü\töß\tCol4"], 'Xfile1') + + " Use byte offset for column number + set efm& + cexpr "Xfile1:1:8:XX\nXfile1:1:11:YY\nXfile1:1:16:ZZ" + call assert_equal([8, 10], [col('.'), virtcol('.')]) + cnext + call assert_equal([11, 17], [col('.'), virtcol('.')]) + cnext + call assert_equal([16, 25], [col('.'), virtcol('.')]) + + " Use screen column offset for column number + set efm=%f:%l:%v:%m + cexpr "Xfile1:1:10:XX\nXfile1:1:17:YY\nXfile1:1:25:ZZ" + call assert_equal([8, 10], [col('.'), virtcol('.')]) + cnext + call assert_equal([11, 17], [col('.'), virtcol('.')]) + cnext + call assert_equal([16, 25], [col('.'), virtcol('.')]) + + enew | only + set efm& + call delete('Xfile1') +endfunc diff --git a/src/testdir/test_quotestar.vim b/src/testdir/test_quotestar.vim new file mode 100644 index 0000000..ce5a9ee --- /dev/null +++ b/src/testdir/test_quotestar.vim @@ -0,0 +1,154 @@ +" *-register (quotestar) tests + +if !has('clipboard') + finish +endif + +source shared.vim + +func Do_test_quotestar_for_macunix() + if empty(exepath('pbcopy')) || empty(exepath('pbpaste')) + return 'Test requires pbcopy(1) and pbpaste(1)' + endif + + let @* = '' + + " Test #1: Pasteboard to Vim + let test_msg = "text from pasteboard to vim via quotestar" + " Write a piece of text to the pasteboard. + call system('/bin/echo -n "' . test_msg . '" | pbcopy') + " See if the *-register is changed as expected. + call assert_equal(test_msg, @*) + + " Test #2: Vim to Pasteboard + let test_msg = "text from vim to pasteboard via quotestar" + " Write a piece of text to the *-register. + let @* = test_msg + " See if the pasteboard is changed as expected. + call assert_equal(test_msg, system('pbpaste')) + + return '' +endfunc + +func Do_test_quotestar_for_x11() + if !has('clientserver') || !has('job') + return 'Test requires the client-server and job features' + endif + + let cmd = GetVimCommand() + if cmd == '' + return 'GetVimCommand() failed' + endif + try + call remote_send('xxx', '') + catch + if v:exception =~ 'E240:' + " No connection to the X server, give up. + return + endif + " ignore other errors + endtry + + let name = 'XVIMCLIPBOARD' + + " Make sure a previous server has exited + try + call remote_send(name, ":qa!\<CR>") + catch /E241:/ + endtry + call WaitForAssert({-> assert_notmatch(name, serverlist())}) + + let cmd .= ' --servername ' . name + let job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'}) + call WaitForAssert({-> assert_equal("run", job_status(job))}) + + " Takes a short while for the server to be active. + call WaitForAssert({-> assert_match(name, serverlist())}) + + " Wait for the server to be up and answering requests. One second is not + " always sufficient. + call WaitForAssert({-> assert_notequal('', remote_expr(name, "v:version", "", 2))}) + + " Clear the *-register of this vim instance and wait for it to be picked up + " by the server. + let @* = 'no' + call remote_foreground(name) + call WaitForAssert({-> assert_equal("no", remote_expr(name, "@*", "", 1))}) + + " Set the * register on the server. + call remote_send(name, ":let @* = 'yes'\<CR>") + call WaitForAssert({-> assert_equal("yes", remote_expr(name, "@*", "", 1))}) + + " Check that the *-register of this vim instance is changed as expected. + call WaitForAssert({-> assert_equal("yes", @*)}) + + " Handle the large selection over 262040 byte. + let length = 262044 + let sample = 'a' . repeat('b', length - 2) . 'c' + let @* = sample + call WaitFor('remote_expr("' . name . '", "len(@*) >= ' . length . '", "", 1)') + let res = remote_expr(name, "@*", "", 2) + call assert_equal(length, len(res)) + " Check length to prevent a large amount of output at assertion failure. + if length == len(res) + call assert_equal(sample, res) + endif + + if has('unix') && has('gui') && !has('gui_running') + let @* = '' + + " Running in a terminal and the GUI is avaiable: Tell the server to open + " the GUI and check that the remote command still works. + " Need to wait for the GUI to start up, otherwise the send hangs in trying + " to send to the terminal window. + if has('gui_athena') || has('gui_motif') + " For those GUIs, ignore the 'failed to create input context' error. + call remote_send(name, ":call test_ignore_error('E285') | gui -f\<CR>") + else + call remote_send(name, ":gui -f\<CR>") + endif + " Wait for the server in the GUI to be up and answering requests. + call WaitForAssert({-> assert_match("1", remote_expr(name, "has('gui_running')", "", 1))}) + + call remote_send(name, ":let @* = 'maybe'\<CR>") + call WaitForAssert({-> assert_equal("maybe", remote_expr(name, "@*", "", 2))}) + + call assert_equal('maybe', @*) + endif + + call remote_send(name, ":qa!\<CR>") + try + call WaitForAssert({-> assert_equal("dead", job_status(job))}) + finally + if job_status(job) != 'dead' + call assert_report('Server did not exit') + call job_stop(job, 'kill') + endif + endtry + + return '' +endfunc + +func Test_quotestar() + let skipped = '' + + let quotestar_saved = @* + + if has('macunix') + let skipped = Do_test_quotestar_for_macunix() + elseif has('x11') + if empty($DISPLAY) + let skipped = "Test can only run when $DISPLAY is set." + else + let skipped = Do_test_quotestar_for_x11() + endif + else + let skipped = "Test is not implemented yet for this platform." + endif + + let @* = quotestar_saved + + if !empty(skipped) + throw 'Skipped: ' . skipped + endif +endfunc diff --git a/src/testdir/test_recover.vim b/src/testdir/test_recover.vim new file mode 100644 index 0000000..a9934a1 --- /dev/null +++ b/src/testdir/test_recover.vim @@ -0,0 +1,62 @@ +" Test :recover + +func Test_recover_root_dir() + " This used to access invalid memory. + split Xtest + set dir=/ + call assert_fails('recover', 'E305:') + close! + + if has('win32') || filewritable('/') == 2 + " can write in / directory on MS-Windows + set dir=/notexist/ + endif + call assert_fails('split Xtest', 'E303:') + set dir& +endfunc + +" Inserts 10000 lines with text to fill the swap file with two levels of pointer +" blocks. Then recovers from the swap file and checks all text is restored. +" +" We need about 10000 lines of 100 characters to get two levels of pointer +" blocks. +func Test_swap_file() + set fileformat=unix undolevels=-1 + edit! Xtest + let text = "\tabcdefghijklmnoparstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnoparstuvwxyz0123456789" + let i = 1 + let linecount = 10000 + while i <= linecount + call append(i - 1, i . text) + let i += 1 + endwhile + $delete + preserve + " get the name of the swap file + let swname = split(execute("swapname"))[0] + let swname = substitute(swname, '[[:blank:][:cntrl:]]*\(.\{-}\)[[:blank:][:cntrl:]]*$', '\1', '') + " make a copy of the swap file in Xswap + set binary + exe 'sp ' . swname + w! Xswap + set nobinary + new + only! + bwipe! Xtest + call rename('Xswap', swname) + recover Xtest + call delete(swname) + let linedollar = line('$') + call assert_equal(linecount, linedollar) + if linedollar < linecount + let linecount = linedollar + endif + let i = 1 + while i <= linecount + call assert_equal(i . text, getline(i)) + let i += 1 + endwhile + + set undolevels& + enew! | only +endfunc diff --git a/src/testdir/test_regex_char_classes.vim b/src/testdir/test_regex_char_classes.vim new file mode 100644 index 0000000..c1a4202 --- /dev/null +++ b/src/testdir/test_regex_char_classes.vim @@ -0,0 +1,295 @@ +" Tests for regexp with backslash and other special characters inside [] +" Also test backslash for hex/octal numbered character. +" + +scriptencoding utf-8 + +function RunSTest(value, calls, expected) + new + call feedkeys("i" . a:value, "mx") + exec a:calls + call assert_equal(a:expected, getline(1), printf("wrong result for %s", a:calls)) + quit! +endfunction + +function RunXTest(value, search_exp, expected) + new + call feedkeys("i" . a:value, "mx") + call feedkeys("gg" . a:search_exp . "\nx", "mx") + call assert_equal(a:expected, getline(1), printf("wrong result for %s", a:search_exp)) + quit! +endfunction + + +function Test_x_search() + let res = "test text test text" + call RunXTest("test \\text test text", "/[\\x]", res) + call RunXTest("test \ttext test text", "/[\\t\\]]", res) + call RunXTest("test text ]test text", "/[]y]", res) + call RunXTest("test ]text test text", "/[\\]]", res) + call RunXTest("test text te^st text", "/[y^]", res) + call RunXTest("test te$xt test text", "/[$y]", res) + call RunXTest("test taext test text", "/[\\x61]", res) + call RunXTest("test tbext test text","/[\\x60-\\x64]", res) + call RunXTest("test 5text test text","/[\\x785]", res) + call RunXTest("testc text test text","/[\\o143]", res) + call RunXTest("tesdt text test text","/[\\o140-\\o144]", res) + call RunXTest("test7 text test text", "/[\\o417]", res) + call RunXTest("test text tBest text", "/\\%x42", res) + call RunXTest("test text teCst text", "/\\%o103", res) + call RunXTest("test text \<C-V>x00test text", "/[\\x00]", res) +endfunction + +function Test_s_search() + let res = "test text test text" + call RunSTest("test te\<C-V>x00xt t\<C-V>x04est t\<C-V>x10ext", "s/[\\x00-\\x10]//g", res) + call RunSTest("test \\xyztext test text", "s/[\\x-z]\\+//", res) + call RunSTest("test text tev\\uyst text", "s/[\\u-z]\\{2,}//", res) + call RunSTest("xx aaaaa xx a", "s/\\(a\\)\\+//", "xx xx a") + call RunSTest("xx aaaaa xx a", "s/\\(a*\\)\\+//", "xx aaaaa xx a") + call RunSTest("xx aaaaa xx a", "s/\\(a*\\)*//", "xx aaaaa xx a") + call RunSTest("xx aaaaa xx", "s/\\(a\\)\\{2,3}/A/", "xx Aaa xx") + call RunSTest("xx aaaaa xx", "s/\\(a\\)\\{-2,3}/A/", "xx Aaaa xx") + call RunSTest("xx aaa12aa xx", "s/\\(a\\)*\\(12\\)\\@>/A/", "xx Aaa xx") + call RunSTest("xx foobar xbar xx", "s/\\(foo\\)\\@<!bar/A/", "xx foobar xA xx") + call RunSTest("xx an file xx", "s/\\(an\\_s\\+\\)\\@<=file/A/", "xx an A xx") + call RunSTest("x= 9;", "s/^\\(\\h\\w*\\%(->\\|\\.\\)\\=\\)\\+=/XX/", "XX 9;") + call RunSTest("hh= 77;", "s/^\\(\\h\\w*\\%(->\\|\\.\\)\\=\\)\\+=/YY/", "YY 77;") + call RunSTest(" aaa ", "s/aaa/xyz/", " xyz ") + call RunSTest(" xyz", "s/~/bcd/", " bcd") + call RunSTest(" bcdbcdbcd", "s/~\\+/BB/", " BB") +endfunction + +" Test character classes in regexp using regexpengine 0, 1, 2. +func Test_regex_char_classes() + new + let save_enc = &encoding + set encoding=utf-8 + + let input = "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b" + + " Format is [cmd_to_run, expected_output] + let tests = [ + \ [':s/\%#=0\d//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=1\d//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=2\d//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=0[0-9]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=1[0-9]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=2[0-9]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=0\D//g', + \ "0123456789"], + \ [':s/\%#=1\D//g', + \ "0123456789"], + \ [':s/\%#=2\D//g', + \ "0123456789"], + \ [':s/\%#=0[^0-9]//g', + \ "0123456789"], + \ [':s/\%#=1[^0-9]//g', + \ "0123456789"], + \ [':s/\%#=2[^0-9]//g', + \ "0123456789"], + \ [':s/\%#=0\o//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./89:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=1\o//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./89:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=2\o//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./89:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=0[0-7]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./89:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=1[0-7]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./89:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=2[0-7]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./89:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=0\O//g', + \ "01234567"], + \ [':s/\%#=1\O//g', + \ "01234567"], + \ [':s/\%#=2\O//g', + \ "01234567"], + \ [':s/\%#=0[^0-7]//g', + \ "01234567"], + \ [':s/\%#=1[^0-7]//g', + \ "01234567"], + \ [':s/\%#=2[^0-7]//g', + \ "01234567"], + \ [':s/\%#=0\x//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@GHIXYZ[\]^_`ghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=1\x//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@GHIXYZ[\]^_`ghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=2\x//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@GHIXYZ[\]^_`ghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=0[0-9A-Fa-f]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@GHIXYZ[\]^_`ghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=1[0-9A-Fa-f]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@GHIXYZ[\]^_`ghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=2[0-9A-Fa-f]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@GHIXYZ[\]^_`ghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=0\X//g', + \ "0123456789ABCDEFabcdef"], + \ [':s/\%#=1\X//g', + \ "0123456789ABCDEFabcdef"], + \ [':s/\%#=2\X//g', + \ "0123456789ABCDEFabcdef"], + \ [':s/\%#=0[^0-9A-Fa-f]//g', + \ "0123456789ABCDEFabcdef"], + \ [':s/\%#=1[^0-9A-Fa-f]//g', + \ "0123456789ABCDEFabcdef"], + \ [':s/\%#=2[^0-9A-Fa-f]//g', + \ "0123456789ABCDEFabcdef"], + \ [':s/\%#=0\w//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=1\w//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=2\w//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=0[0-9A-Za-z_]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=1[0-9A-Za-z_]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=2[0-9A-Za-z_]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=0\W//g', + \ "0123456789ABCDEFGHIXYZ_abcdefghiwxyz"], + \ [':s/\%#=1\W//g', + \ "0123456789ABCDEFGHIXYZ_abcdefghiwxyz"], + \ [':s/\%#=2\W//g', + \ "0123456789ABCDEFGHIXYZ_abcdefghiwxyz"], + \ [':s/\%#=0[^0-9A-Za-z_]//g', + \ "0123456789ABCDEFGHIXYZ_abcdefghiwxyz"], + \ [':s/\%#=1[^0-9A-Za-z_]//g', + \ "0123456789ABCDEFGHIXYZ_abcdefghiwxyz"], + \ [':s/\%#=2[^0-9A-Za-z_]//g', + \ "0123456789ABCDEFGHIXYZ_abcdefghiwxyz"], + \ [':s/\%#=0\h//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=1\h//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=2\h//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=0[A-Za-z_]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=1[A-Za-z_]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=2[A-Za-z_]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^`{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=0\H//g', + \ "ABCDEFGHIXYZ_abcdefghiwxyz"], + \ [':s/\%#=1\H//g', + \ "ABCDEFGHIXYZ_abcdefghiwxyz"], + \ [':s/\%#=2\H//g', + \ "ABCDEFGHIXYZ_abcdefghiwxyz"], + \ [':s/\%#=0[^A-Za-z_]//g', + \ "ABCDEFGHIXYZ_abcdefghiwxyz"], + \ [':s/\%#=1[^A-Za-z_]//g', + \ "ABCDEFGHIXYZ_abcdefghiwxyz"], + \ [':s/\%#=2[^A-Za-z_]//g', + \ "ABCDEFGHIXYZ_abcdefghiwxyz"], + \ [':s/\%#=0\a//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=1\a//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=2\a//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=0[A-Za-z]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=1[A-Za-z]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=2[A-Za-z]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=0\A//g', + \ "ABCDEFGHIXYZabcdefghiwxyz"], + \ [':s/\%#=1\A//g', + \ "ABCDEFGHIXYZabcdefghiwxyz"], + \ [':s/\%#=2\A//g', + \ "ABCDEFGHIXYZabcdefghiwxyz"], + \ [':s/\%#=0[^A-Za-z]//g', + \ "ABCDEFGHIXYZabcdefghiwxyz"], + \ [':s/\%#=1[^A-Za-z]//g', + \ "ABCDEFGHIXYZabcdefghiwxyz"], + \ [':s/\%#=2[^A-Za-z]//g', + \ "ABCDEFGHIXYZabcdefghiwxyz"], + \ [':s/\%#=0\l//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=1\l//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=2\l//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=0[a-z]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=1[a-z]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=2[a-z]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=0\L//g', + \ "abcdefghiwxyz"], + \ [':s/\%#=1\L//g', + \ "abcdefghiwxyz"], + \ [':s/\%#=2\L//g', + \ "abcdefghiwxyz"], + \ [':s/\%#=0[^a-z]//g', + \ "abcdefghiwxyz"], + \ [':s/\%#=1[^a-z]//g', + \ "abcdefghiwxyz"], + \ [':s/\%#=2[^a-z]//g', + \ "abcdefghiwxyz"], + \ [':s/\%#=0\u//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=1\u//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=2\u//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=0[A-Z]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=1[A-Z]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=2[A-Z]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./0123456789:;<=>?@[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=0\U//g', + \ "ABCDEFGHIXYZ"], + \ [':s/\%#=1\U//g', + \ "ABCDEFGHIXYZ"], + \ [':s/\%#=2\U//g', + \ "ABCDEFGHIXYZ"], + \ [':s/\%#=0[^A-Z]//g', + \ "ABCDEFGHIXYZ"], + \ [':s/\%#=1[^A-Z]//g', + \ "ABCDEFGHIXYZ"], + \ [':s/\%#=2[^A-Z]//g', + \ "ABCDEFGHIXYZ"], + \ [':s/\%#=0\%' . line('.') . 'l^\t...//g', + \ "!\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=1\%' . line('.') . 'l^\t...//g', + \ "!\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=2\%' . line('.') . 'l^\t...//g', + \ "!\"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=0[0-z]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=1[0-z]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=2[0-z]//g', + \ "\t\<C-L>\<C-M> !\"#$%&'()#+'-./{|}~\<C-?>\u0080\u0082\u0090\u009b"], + \ [':s/\%#=0[^0-z]//g', + \ "0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz"], + \ [':s/\%#=1[^0-z]//g', + \ "0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz"], + \ [':s/\%#=2[^0-z]//g', + \ "0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz"] + \] + + for [cmd, expected] in tests + call append(0, input) + call cursor(1, 1) + exe cmd + call assert_equal(expected, getline(1), cmd) + endfor + + let &encoding = save_enc + enew! + close +endfunc diff --git a/src/testdir/test_regexp_latin.vim b/src/testdir/test_regexp_latin.vim new file mode 100644 index 0000000..1524945 --- /dev/null +++ b/src/testdir/test_regexp_latin.vim @@ -0,0 +1,86 @@ +" Tests for regexp in latin1 encoding +set encoding=latin1 +scriptencoding latin1 + +func s:equivalence_test() + let str = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z" + let groups = split(str) + for group1 in groups + for c in split(group1, '\zs') + " next statement confirms that equivalence class matches every + " character in group + call assert_match('^[[=' . c . '=]]*$', group1) + for group2 in groups + if group2 != group1 + " next statement converts that equivalence class doesn't match + " a character in any other group + call assert_equal(-1, match(group2, '[[=' . c . '=]]')) + endif + endfor + endfor + endfor +endfunc + +func Test_equivalence_re1() + set re=1 + call s:equivalence_test() +endfunc + +func Test_equivalence_re2() + set re=2 + call s:equivalence_test() +endfunc + +func Test_recursive_substitute() + new + s/^/\=execute("s#^##gn") + " check we are now not in the sandbox + call setwinvar(1, 'myvar', 1) + bwipe! +endfunc + +func Test_nested_backrefs() + " Check example in change.txt. + new + for re in range(0, 2) + exe 'set re=' . re + call setline(1, 'aa ab x') + 1s/\(\(a[a-d] \)*\)\(x\)/-\1- -\2- -\3-/ + call assert_equal('-aa ab - -ab - -x-', getline(1)) + + call assert_equal('-aa ab - -ab - -x-', substitute('aa ab x', '\(\(a[a-d] \)*\)\(x\)', '-\1- -\2- -\3-', '')) + endfor + bwipe! + set re=0 +endfunc + +func Test_eow_with_optional() + let expected = ['abc def', 'abc', 'def', '', '', '', '', '', '', ''] + for re in range(0, 2) + exe 'set re=' . re + let actual = matchlist('abc def', '\(abc\>\)\?\s*\(def\)') + call assert_equal(expected, actual) + endfor +endfunc + +func Test_backref() + new + call setline(1, ['one', 'two', 'three', 'four', 'five']) + call assert_equal(3, search('\%#=1\(e\)\1')) + call assert_equal(3, search('\%#=2\(e\)\1')) + call assert_fails('call search("\\%#=1\\(e\\1\\)")', 'E65:') + call assert_fails('call search("\\%#=2\\(e\\1\\)")', 'E65:') + bwipe! +endfunc + +func Test_multi_failure() + set re=1 + call assert_fails('/a**', 'E61:') + call assert_fails('/a*\+', 'E62:') + call assert_fails('/a\{a}', 'E554:') + set re=2 + call assert_fails('/a**', 'E871:') + call assert_fails('/a*\+', 'E871:') + call assert_fails('/a\{a}', 'E870:') + set re=0 +endfunc diff --git a/src/testdir/test_regexp_utf8.vim b/src/testdir/test_regexp_utf8.vim new file mode 100644 index 0000000..98b9e73 --- /dev/null +++ b/src/testdir/test_regexp_utf8.vim @@ -0,0 +1,208 @@ +" Tests for regexp in utf8 encoding + +func s:equivalence_test() + let str = "AÀÁÂÃÄÅĀĂĄǍǞǠẢ BḂḆ CÇĆĈĊČ DĎĐḊḎḐ EÈÉÊËĒĔĖĘĚẺẼ FḞ GĜĞĠĢǤǦǴḠ HĤĦḢḦḨ IÌÍÎÏĨĪĬĮİǏỈ JĴ KĶǨḰḴ LĹĻĽĿŁḺ MḾṀ NÑŃŅŇṄṈ OÒÓÔÕÖØŌŎŐƠǑǪǬỎ PṔṖ Q RŔŖŘṘṞ SŚŜŞŠṠ TŢŤŦṪṮ UÙÚÛÜŨŪŬŮŰŲƯǓỦ VṼ WŴẀẂẄẆ XẊẌ YÝŶŸẎỲỶỸ ZŹŻŽƵẐẔ aàáâãäåāăąǎǟǡả bḃḇ cçćĉċč dďđḋḏḑ eèéêëēĕėęěẻẽ fḟ gĝğġģǥǧǵḡ hĥħḣḧḩẖ iìíîïĩīĭįǐỉ jĵǰ kķǩḱḵ lĺļľŀłḻ mḿṁ nñńņňʼnṅṉ oòóôõöøōŏőơǒǫǭỏ pṕṗ q rŕŗřṙṟ sśŝşšṡ tţťŧṫṯẗ uùúûüũūŭůűųưǔủ vṽ wŵẁẃẅẇẘ xẋẍ yýÿŷẏẙỳỷỹ zźżžƶẑẕ" + let groups = split(str) + for group1 in groups + for c in split(group1, '\zs') + " next statement confirms that equivalence class matches every + " character in group + call assert_match('^[[=' . c . '=]]*$', group1) + for group2 in groups + if group2 != group1 + " next statement converts that equivalence class doesn't match + " character in any other group + call assert_equal(-1, match(group2, '[[=' . c . '=]]')) + endif + endfor + endfor + endfor +endfunc + +func Test_equivalence_re1() + set re=1 + call s:equivalence_test() + set re=0 +endfunc + +func Test_equivalence_re2() + set re=2 + call s:equivalence_test() + set re=0 +endfunc + +func s:classes_test() + set isprint=@,161-255 + call assert_equal('Motörhead', matchstr('Motörhead', '[[:print:]]\+')) + + let alnumchars = '' + let alphachars = '' + let backspacechar = '' + let blankchars = '' + let cntrlchars = '' + let digitchars = '' + let escapechar = '' + let graphchars = '' + let lowerchars = '' + let printchars = '' + let punctchars = '' + let returnchar = '' + let spacechars = '' + let tabchar = '' + let upperchars = '' + let xdigitchars = '' + let identchars = '' + let identchars1 = '' + let kwordchars = '' + let kwordchars1 = '' + let fnamechars = '' + let fnamechars1 = '' + let i = 1 + while i <= 255 + let c = nr2char(i) + if c =~ '[[:alpha:]]' + let alphachars .= c + endif + if c =~ '[[:alnum:]]' + let alnumchars .= c + endif + if c =~ '[[:backspace:]]' + let backspacechar .= c + endif + if c =~ '[[:blank:]]' + let blankchars .= c + endif + if c =~ '[[:cntrl:]]' + let cntrlchars .= c + endif + if c =~ '[[:digit:]]' + let digitchars .= c + endif + if c =~ '[[:escape:]]' + let escapechar .= c + endif + if c =~ '[[:graph:]]' + let graphchars .= c + endif + if c =~ '[[:lower:]]' + let lowerchars .= c + endif + if c =~ '[[:print:]]' + let printchars .= c + endif + if c =~ '[[:punct:]]' + let punctchars .= c + endif + if c =~ '[[:return:]]' + let returnchar .= c + endif + if c =~ '[[:space:]]' + let spacechars .= c + endif + if c =~ '[[:tab:]]' + let tabchar .= c + endif + if c =~ '[[:upper:]]' + let upperchars .= c + endif + if c =~ '[[:xdigit:]]' + let xdigitchars .= c + endif + if c =~ '[[:ident:]]' + let identchars .= c + endif + if c =~ '\i' + let identchars1 .= c + endif + if c =~ '[[:keyword:]]' + let kwordchars .= c + endif + if c =~ '\k' + let kwordchars1 .= c + endif + if c =~ '[[:fname:]]' + let fnamechars .= c + endif + if c =~ '\f' + let fnamechars1 .= c + endif + let i += 1 + endwhile + + call assert_equal('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', alphachars) + call assert_equal('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', alnumchars) + call assert_equal("\b", backspacechar) + call assert_equal("\t ", blankchars) + call assert_equal("\x01\x02\x03\x04\x05\x06\x07\b\t\n\x0b\f\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\e\x1c\x1d\x1e\x1f\x7f", cntrlchars) + call assert_equal("0123456789", digitchars) + call assert_equal("\<Esc>", escapechar) + call assert_equal('!"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~', graphchars) + call assert_equal('abcdefghijklmnopqrstuvwxyzµßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ', lowerchars) + call assert_equal(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ', printchars) + call assert_equal('!"#$%&''()*+,-./:;<=>?@[\]^_`{|}~', punctchars) + call assert_equal('ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ', upperchars) + call assert_equal("\r", returnchar) + call assert_equal("\t\n\x0b\f\r ", spacechars) + call assert_equal("\t", tabchar) + call assert_equal('0123456789ABCDEFabcdef', xdigitchars) + + if has('win32') + let identchars_ok = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz
¡¢£¤¥¦§µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ' + let kwordchars_ok = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyzµÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ' + elseif has('ebcdic') + let identchars_ok = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz¬®µº¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ' + let kwordchars_ok = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz¬®µº¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ' + else + let identchars_ok = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyzµÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ' + let kwordchars_ok = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyzµÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ' + endif + + if has('win32') + let fnamechars_ok = '!#$%+,-./0123456789:=@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]_abcdefghijklmnopqrstuvwxyz{}~ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ' + elseif has('amiga') + let fnamechars_ok = '$+,-./0123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ' + elseif has('vms') + let fnamechars_ok = '#$%+,-./0123456789:;<>ABCDEFGHIJKLMNOPQRSTUVWXYZ[]_abcdefghijklmnopqrstuvwxyz~ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ' + elseif has('ebcdic') + let fnamechars_ok = '#$%+,-./=ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ' + else + let fnamechars_ok = '#$%+,-./0123456789=ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ' + endif + + call assert_equal(identchars_ok, identchars) + call assert_equal(kwordchars_ok, kwordchars) + call assert_equal(fnamechars_ok, fnamechars) + + call assert_equal(identchars1, identchars) + call assert_equal(kwordchars1, kwordchars) + call assert_equal(fnamechars1, fnamechars) +endfunc + +func Test_classes_re1() + set re=1 + call s:classes_test() + set re=0 +endfunc + +func Test_classes_re2() + set re=2 + call s:classes_test() + set re=0 +endfunc + +func Test_reversed_range() + for re in range(0, 2) + exe 'set re=' . re + call assert_fails('call match("abc def", "[c-a]")', 'E944:') + endfor + set re=0 +endfunc + +func Test_large_class() + set re=1 + call assert_fails('call match("abc def", "[\u3000-\u4000]")', 'E945:') + set re=2 + call assert_equal(0, 'abc def' =~# '[\u3000-\u4000]') + call assert_equal(1, "\u3042" =~# '[\u3000-\u4000]') + set re=0 +endfunc diff --git a/src/testdir/test_registers.vim b/src/testdir/test_registers.vim new file mode 100644 index 0000000..d7b6de5 --- /dev/null +++ b/src/testdir/test_registers.vim @@ -0,0 +1,65 @@ + +func Test_yank_shows_register() + enew + set report=0 + call setline(1, ['foo', 'bar']) + " Line-wise + exe 'norm! yy' + call assert_equal('1 line yanked', v:statusmsg) + exe 'norm! "zyy' + call assert_equal('1 line yanked into "z', v:statusmsg) + exe 'norm! yj' + call assert_equal('2 lines yanked', v:statusmsg) + exe 'norm! "zyj' + call assert_equal('2 lines yanked into "z', v:statusmsg) + + " Block-wise + exe "norm! \<C-V>y" + call assert_equal('block of 1 line yanked', v:statusmsg) + exe "norm! \<C-V>\"zy" + call assert_equal('block of 1 line yanked into "z', v:statusmsg) + exe "norm! \<C-V>jy" + call assert_equal('block of 2 lines yanked', v:statusmsg) + exe "norm! \<C-V>j\"zy" + call assert_equal('block of 2 lines yanked into "z', v:statusmsg) + + bwipe! +endfunc + +func Test_display_registers() + e file1 + e file2 + call setline(1, ['foo', 'bar']) + /bar + exe 'norm! y2l"axx' + call feedkeys("i\<C-R>=2*4\n\<esc>") + call feedkeys(":ls\n", 'xt') + + let a = execute('display') + let b = execute('registers') + + call assert_equal(a, b) + call assert_match('^\n--- Registers ---\n' + \ . '"" a\n' + \ . '"0 ba\n' + \ . '"1 b\n' + \ . '"a b\n' + \ . '.*' + \ . '"- a\n' + \ . '.*' + \ . '": ls\n' + \ . '"% file2\n' + \ . '"# file1\n' + \ . '"/ bar\n' + \ . '"= 2\*4', a) + + let a = execute('registers a') + call assert_match('^\n--- Registers ---\n' + \ . '"a b', a) + + let a = execute('registers :') + call assert_match('^\n--- Registers ---\n' + \ . '": ls', a) + + bwipe! +endfunc diff --git a/src/testdir/test_reltime.vim b/src/testdir/test_reltime.vim new file mode 100644 index 0000000..adabf16 --- /dev/null +++ b/src/testdir/test_reltime.vim @@ -0,0 +1,26 @@ +" Tests for reltime() + +if !has('reltime') || !has('float') + finish +endif + +func Test_reltime() + let now = reltime() + sleep 10m + let later = reltime() + let elapsed = reltime(now) + call assert_true(reltimestr(elapsed) =~ '0\.0') + call assert_true(reltimestr(elapsed) != '0.0') + call assert_true(reltimefloat(elapsed) < 0.1) + call assert_true(reltimefloat(elapsed) > 0.0) + + let same = reltime(now, now) + call assert_equal('0.000', split(reltimestr(same))[0][:4]) + call assert_equal(0.0, reltimefloat(same)) + + let differs = reltime(now, later) + call assert_true(reltimestr(differs) =~ '0\.0') + call assert_true(reltimestr(differs) != '0.0') + call assert_true(reltimefloat(differs) < 0.1) + call assert_true(reltimefloat(differs) > 0.0) +endfunc diff --git a/src/testdir/test_retab.vim b/src/testdir/test_retab.vim new file mode 100644 index 0000000..f11a32b --- /dev/null +++ b/src/testdir/test_retab.vim @@ -0,0 +1,77 @@ +" Test :retab +func SetUp() + new + call setline(1, "\ta \t b c ") +endfunc + +func TearDown() + bwipe! +endfunc + +func Retab(bang, n) + let l:old_tabstop = &tabstop + let l:old_line = getline(1) + exe "retab" . a:bang . a:n + let l:line = getline(1) + call setline(1, l:old_line) + if a:n > 0 + " :retab changes 'tabstop' to n with argument n > 0. + call assert_equal(a:n, &tabstop) + exe 'set tabstop=' . l:old_tabstop + else + " :retab does not change 'tabstop' with empty or n <= 0. + call assert_equal(l:old_tabstop, &tabstop) + endif + return l:line +endfunc + +func Test_retab() + set tabstop=8 noexpandtab + call assert_equal("\ta\t b c ", Retab('', '')) + call assert_equal("\ta\t b c ", Retab('', 0)) + call assert_equal("\ta\t b c ", Retab('', 8)) + call assert_equal("\ta\t b\t c\t ", Retab('!', '')) + call assert_equal("\ta\t b\t c\t ", Retab('!', 0)) + call assert_equal("\ta\t b\t c\t ", Retab('!', 8)) + + call assert_equal("\t\ta\t\t\tb c ", Retab('', 4)) + call assert_equal("\t\ta\t\t\tb\t\t c\t ", Retab('!', 4)) + + call assert_equal(" a\t\tb c ", Retab('', 10)) + call assert_equal(" a\t\tb c ", Retab('!', 10)) + + set tabstop=8 expandtab + call assert_equal(" a b c ", Retab('', '')) + call assert_equal(" a b c ", Retab('', 0)) + call assert_equal(" a b c ", Retab('', 8)) + call assert_equal(" a b c ", Retab('!', '')) + call assert_equal(" a b c ", Retab('!', 0)) + call assert_equal(" a b c ", Retab('!', 8)) + + call assert_equal(" a b c ", Retab(' ', 4)) + call assert_equal(" a b c ", Retab('!', 4)) + + call assert_equal(" a b c ", Retab(' ', 10)) + call assert_equal(" a b c ", Retab('!', 10)) + + set tabstop=4 noexpandtab + call assert_equal("\ta\t\tb c ", Retab('', '')) + call assert_equal("\ta\t\tb\t\t c\t ", Retab('!', '')) + call assert_equal("\t a\t\t\tb c ", Retab('', 3)) + call assert_equal("\t a\t\t\tb\t\t\tc\t ", Retab('!', 3)) + call assert_equal(" a\t b c ", Retab('', 5)) + call assert_equal(" a\t b\t\t c\t ", Retab('!', 5)) + + set tabstop=4 expandtab + call assert_equal(" a b c ", Retab('', '')) + call assert_equal(" a b c ", Retab('!', '')) + call assert_equal(" a b c ", Retab('', 3)) + call assert_equal(" a b c ", Retab('!', 3)) + call assert_equal(" a b c ", Retab('', 5)) + call assert_equal(" a b c ", Retab('!', 5)) +endfunc + +func Test_retab_error() + call assert_fails('retab -1', 'E487:') + call assert_fails('retab! -1', 'E487:') +endfunc diff --git a/src/testdir/test_ruby.vim b/src/testdir/test_ruby.vim new file mode 100644 index 0000000..5476e51 --- /dev/null +++ b/src/testdir/test_ruby.vim @@ -0,0 +1,379 @@ +" Tests for ruby interface + +if !has('ruby') + finish +end + +" Helper function as there is no builtin rubyeval() function similar +" to perleval, luaevel() or pyeval(). +func RubyEval(ruby_expr) + let s = split(execute('ruby print ' . a:ruby_expr), "\n") + return (len(s) == 0) ? '' : s[-1] +endfunc + +func Test_ruby_change_buffer() + call setline(line('$'), ['1 line 1']) + ruby Vim.command("normal /^1\n") + ruby $curbuf.line = "1 changed line 1" + call assert_equal('1 changed line 1', getline('$')) +endfunc + +func Test_rubydo() + " Check deleting lines does not trigger ml_get error. + new + call setline(1, ['one', 'two', 'three']) + rubydo Vim.command("%d_") + bwipe! + + " Check switching to another buffer does not trigger ml_get error. + new + let wincount = winnr('$') + call setline(1, ['one', 'two', 'three']) + rubydo Vim.command("new") + call assert_equal(wincount + 1, winnr('$')) + %bwipe! +endfunc + +func Test_rubyfile() + " Check :rubyfile does not SEGV with Ruby level exception but just fails + let tempfile = tempname() . '.rb' + call writefile(['raise "vim!"'], tempfile) + call assert_fails('rubyfile ' . tempfile) + call delete(tempfile) +endfunc + +func Test_set_cursor() + " Check that setting the cursor position works. + new + call setline(1, ['first line', 'second line']) + normal gg + rubydo $curwin.cursor = [1, 5] + call assert_equal([1, 6], [line('.'), col('.')]) + call assert_equal('[1, 5]', RubyEval('$curwin.cursor')) + + " Check that movement after setting cursor position keeps current column. + normal j + call assert_equal([2, 6], [line('.'), col('.')]) + call assert_equal('[2, 5]', RubyEval('$curwin.cursor')) + + call assert_fails('ruby $curwin.cursor = [1]', + \ 'ArgumentError: array length must be 2') + bwipe! +endfunc + +" Test buffer.count and buffer.length (number of lines in buffer) +func Test_buffer_count() + new + call setline(1, ['one', 'two', 'three']) + call assert_equal('3', RubyEval('$curbuf.count')) + call assert_equal('3', RubyEval('$curbuf.length')) + bwipe! +endfunc + +" Test buffer.name (buffer name) +func Test_buffer_name() + new Xfoo + call assert_equal(expand('%:p'), RubyEval('$curbuf.name')) + bwipe + call assert_equal('', RubyEval('$curbuf.name')) +endfunc + +" Test buffer.number (number of the buffer). +func Test_buffer_number() + new + call assert_equal(string(bufnr('%')), RubyEval('$curbuf.number')) + new + call assert_equal(string(bufnr('%')), RubyEval('$curbuf.number')) + + %bwipe +endfunc + +" Test buffer.delete({n}) (delete line {n}) +func Test_buffer_delete() + new + call setline(1, ['one', 'two', 'three']) + ruby $curbuf.delete(2) + call assert_equal(['one', 'three'], getline(1, '$')) + + call assert_fails('ruby $curbuf.delete(0)', 'IndexError: line number 0 out of range') + call assert_fails('ruby $curbuf.delete(3)', 'IndexError: line number 3 out of range') + + bwipe! +endfunc + +" Test buffer.append({str}, str) (append line {str} after line {n}) +func Test_buffer_append() + new + ruby $curbuf.append(0, 'one') + ruby $curbuf.append(1, 'three') + ruby $curbuf.append(1, 'two') + ruby $curbuf.append(4, 'four') + + call assert_equal(['one', 'two', 'three', '', 'four'], getline(1, '$')) + + call assert_fails('ruby $curbuf.append(-1, "x")', + \ 'IndexError: line number -1 out of range') + call assert_fails('ruby $curbuf.append(6, "x")', + \ 'IndexError: line number 6 out of range') + + bwipe! +endfunc + +" Test buffer.line (get or set the current line) +func Test_buffer_line() + new + call setline(1, ['one', 'two', 'three']) + 2 + call assert_equal('two', RubyEval('$curbuf.line')) + + ruby $curbuf.line = 'TWO' + call assert_equal(['one', 'TWO', 'three'], getline(1, '$')) + + bwipe! +endfunc + +" Test buffer.line_number (get current line number) +func Test_buffer_line_number() + new + call setline(1, ['one', 'two', 'three']) + 2 + call assert_equal('2', RubyEval('$curbuf.line_number')) + + bwipe! +endfunc + +func Test_buffer_get() + new + call setline(1, ['one', 'two']) + call assert_equal('one', RubyEval('$curbuf[1]')) + call assert_equal('two', RubyEval('$curbuf[2]')) + + call assert_fails('ruby $curbuf[0]', + \ 'IndexError: line number 0 out of range') + call assert_fails('ruby $curbuf[3]', + \ 'IndexError: line number 3 out of range') + + bwipe! +endfunc + +func Test_buffer_set() + new + call setline(1, ['one', 'two']) + ruby $curbuf[2] = 'TWO' + ruby $curbuf[1] = 'ONE' + + call assert_fails('ruby $curbuf[0] = "ZERO"', + \ 'IndexError: line number 0 out of range') + call assert_fails('ruby $curbuf[3] = "THREE"', + \ 'IndexError: line number 3 out of range') + bwipe! +endfunc + +" Test window.width (get or set window height). +func Test_window_height() + new + + " Test setting window height + ruby $curwin.height = 2 + call assert_equal(2, winheight(0)) + + " Test getting window height + call assert_equal('2', RubyEval('$curwin.height')) + + bwipe +endfunc + +" Test window.width (get or set window width). +func Test_window_width() + vnew + + " Test setting window width + ruby $curwin.width = 2 + call assert_equal(2, winwidth(0)) + + " Test getting window width + call assert_equal('2', RubyEval('$curwin.width')) + + bwipe +endfunc + +" Test window.buffer (get buffer object of a window object). +func Test_window_buffer() + new Xfoo1 + new Xfoo2 + ruby $b2 = $curwin.buffer + ruby $w2 = $curwin + wincmd j + ruby $b1 = $curwin.buffer + ruby $w1 = $curwin + + call assert_equal(RubyEval('$b1'), RubyEval('$w1.buffer')) + call assert_equal(RubyEval('$b2'), RubyEval('$w2.buffer')) + call assert_equal(string(bufnr('Xfoo1')), RubyEval('$w1.buffer.number')) + call assert_equal(string(bufnr('Xfoo2')), RubyEval('$w2.buffer.number')) + + ruby $b1, $w1, $b2, $w2 = nil + %bwipe +endfunc + +" Test Vim::Window.current (get current window object) +func Test_Vim_window_current() + let cw = RubyEval('$curwin') + call assert_equal(cw, RubyEval('Vim::Window.current')) + call assert_match('^#<Vim::Window:0x\x\+>$', cw) +endfunc + +" Test Vim::Window.count (number of windows) +func Test_Vim_window_count() + new Xfoo1 + new Xfoo2 + split + call assert_equal('4', RubyEval('Vim::Window.count')) + %bwipe + call assert_equal('1', RubyEval('Vim::Window.count')) +endfunc + +" Test Vim::Window[n] (get window object of window n) +func Test_Vim_window_get() + new Xfoo1 + new Xfoo2 + call assert_match('Xfoo2$', RubyEval('Vim::Window[0].buffer.name')) + wincmd j + call assert_match('Xfoo1$', RubyEval('Vim::Window[1].buffer.name')) + wincmd j + call assert_equal('', RubyEval('Vim::Window[2].buffer.name')) + %bwipe +endfunc + +" Test Vim::Buffer.current (return the buffer object of current buffer) +func Test_Vim_buffer_current() + let cb = RubyEval('$curbuf') + call assert_equal(cb, RubyEval('Vim::Buffer.current')) + call assert_match('^#<Vim::Buffer:0x\x\+>$', cb) +endfunc + +" Test Vim::Buffer:.count (return the number of buffers) +func Test_Vim_buffer_count() + new Xfoo1 + new Xfoo2 + call assert_equal('3', RubyEval('Vim::Buffer.count')) + %bwipe + call assert_equal('1', RubyEval('Vim::Buffer.count')) +endfunc + +" Test Vim::buffer[n] (return the buffer object of buffer number n) +func Test_Vim_buffer_get() + new Xfoo1 + new Xfoo2 + + " Index of Vim::Buffer[n] goes from 0 to the number of buffers. + call assert_equal('', RubyEval('Vim::Buffer[0].name')) + call assert_match('Xfoo1$', RubyEval('Vim::Buffer[1].name')) + call assert_match('Xfoo2$', RubyEval('Vim::Buffer[2].name')) + call assert_fails('ruby print Vim::Buffer[3].name', + \ "NoMethodError: undefined method `name' for nil:NilClass") + %bwipe +endfunc + +" Test Vim::command({cmd}) (execute a Ex command)) +" Test Vim::command({cmd}) +func Test_Vim_command() + new + call setline(1, ['one', 'two', 'three', 'four']) + ruby Vim::command('2,3d') + call assert_equal(['one', 'four'], getline(1, '$')) + bwipe! +endfunc + +" Test Vim::set_option (set a vim option) +func Test_Vim_set_option() + call assert_equal(0, &number) + ruby Vim::set_option('number') + call assert_equal(1, &number) + ruby Vim::set_option('nonumber') + call assert_equal(0, &number) +endfunc + +func Test_Vim_evaluate() + call assert_equal('123', RubyEval('Vim::evaluate("123")')) + " Vim::evaluate("123").class gives Integer or Fixnum depending + " on versions of Ruby. + call assert_match('^Integer\|Fixnum$', RubyEval('Vim::evaluate("123").class')) + + call assert_equal('1.23', RubyEval('Vim::evaluate("1.23")')) + call assert_equal('Float', RubyEval('Vim::evaluate("1.23").class')) + + call assert_equal('foo', RubyEval('Vim::evaluate("\"foo\"")')) + call assert_equal('String', RubyEval('Vim::evaluate("\"foo\"").class')) + + call assert_equal('[1, 2]', RubyEval('Vim::evaluate("[1, 2]")')) + call assert_equal('Array', RubyEval('Vim::evaluate("[1, 2]").class')) + + call assert_equal('{"1"=>2}', RubyEval('Vim::evaluate("{1:2}")')) + call assert_equal('Hash', RubyEval('Vim::evaluate("{1:2}").class')) + + call assert_equal('', RubyEval('Vim::evaluate("v:null")')) + call assert_equal('NilClass', RubyEval('Vim::evaluate("v:null").class')) + + call assert_equal('', RubyEval('Vim::evaluate("v:none")')) + call assert_equal('NilClass', RubyEval('Vim::evaluate("v:none").class')) + + call assert_equal('true', RubyEval('Vim::evaluate("v:true")')) + call assert_equal('TrueClass', RubyEval('Vim::evaluate("v:true").class')) + call assert_equal('false', RubyEval('Vim::evaluate("v:false")')) + call assert_equal('FalseClass',RubyEval('Vim::evaluate("v:false").class')) +endfunc + +func Test_Vim_evaluate_list() + call setline(line('$'), ['2 line 2']) + ruby Vim.command("normal /^2\n") + let l = ["abc", "def"] + ruby << EOF + curline = $curbuf.line_number + l = Vim.evaluate("l"); + $curbuf.append(curline, l.join("\n")) +EOF + normal j + .rubydo $_ = $_.gsub(/\n/, '/') + call assert_equal('abc/def', getline('$')) +endfunc + +func Test_Vim_evaluate_dict() + let d = {'a': 'foo', 'b': 123} + redir => l:out + ruby d = Vim.evaluate("d"); print d + redir END + call assert_equal(['{"a"=>"foo", "b"=>123}'], split(l:out, "\n")) +endfunc + +" Test Vim::message({msg}) (display message {msg}) +func Test_Vim_message() + ruby Vim::message('A message') + let messages = split(execute('message'), "\n") + call assert_equal('A message', messages[-1]) +endfunc + +func Test_print() + ruby print "Hello World!" + let messages = split(execute('message'), "\n") + call assert_equal('Hello World!', messages[-1]) +endfunc + +func Test_p() + ruby p 'Just a test' + let messages = split(execute('message'), "\n") + call assert_equal('"Just a test"', messages[-1]) + + " Check return values of p method + + call assert_equal('123', RubyEval('p(123)')) + call assert_equal('[1, 2, 3]', RubyEval('p(1, 2, 3)')) + + " Avoid the "message maintainer" line. + let $LANG = '' + messages clear + call assert_equal('true', RubyEval('p() == nil')) + + let messages = split(execute('message'), "\n") + call assert_equal(0, len(messages)) +endfunc diff --git a/src/testdir/test_scriptnames.vim b/src/testdir/test_scriptnames.vim new file mode 100644 index 0000000..fc6c910 --- /dev/null +++ b/src/testdir/test_scriptnames.vim @@ -0,0 +1,26 @@ +" Test for :scriptnames + +func Test_scriptnames() + call writefile(['let did_load_script = 123'], 'Xscripting') + source Xscripting + call assert_equal(123, g:did_load_script) + + let scripts = split(execute('scriptnames'), "\n") + let last = scripts[-1] + call assert_match('\<Xscripting\>', last) + let lastnr = substitute(last, '\D*\(\d\+\):.*', '\1', '') + exe 'script ' . lastnr + call assert_equal('Xscripting', expand('%:t')) + + call assert_fails('script ' . (lastnr + 1), 'E474:') + call assert_fails('script 0', 'E939:') + + new + call setline(1, 'nothing') + call assert_fails('script ' . lastnr, 'E37:') + exe 'script! ' . lastnr + call assert_equal('Xscripting', expand('%:t')) + + bwipe + call delete('Xscripting') +endfunc diff --git a/src/testdir/test_scroll_opt.vim b/src/testdir/test_scroll_opt.vim new file mode 100644 index 0000000..77920eb --- /dev/null +++ b/src/testdir/test_scroll_opt.vim @@ -0,0 +1,36 @@ +" Test for reset 'scroll' +" + +func Test_reset_scroll() + let scr = &l:scroll + + setlocal scroll=1 + setlocal scroll& + call assert_equal(scr, &l:scroll) + + setlocal scroll=1 + setlocal scroll=0 + call assert_equal(scr, &l:scroll) + + try + execute 'setlocal scroll=' . (winheight(0) + 1) + " not reached + call assert_false(1) + catch + call assert_exception('E49:') + endtry + + split + + let scr = &l:scroll + + setlocal scroll=1 + setlocal scroll& + call assert_equal(scr, &l:scroll) + + setlocal scroll=1 + setlocal scroll=0 + call assert_equal(scr, &l:scroll) + + quit! +endfunc diff --git a/src/testdir/test_scrollbind.vim b/src/testdir/test_scrollbind.vim new file mode 100644 index 0000000..baa24f1 --- /dev/null +++ b/src/testdir/test_scrollbind.vim @@ -0,0 +1,32 @@ +" Test for 'scrollbind' causing an unexpected scroll of one of the windows. +func Test_scrollbind() + " We don't want the status line to cause problems: + set laststatus=0 + let totalLines = &lines * 20 + let middle = totalLines / 2 + new | only + for i in range(1, totalLines) + call setline(i, 'LINE ' . i) + endfor + exe string(middle) + normal zt + normal M + aboveleft vert new + for i in range(1, totalLines) + call setline(i, 'line ' . i) + endfor + exe string(middle) + normal zt + normal M + " Execute the following two commands at once to reproduce the problem. + setl scb | wincmd p + setl scb + wincmd w + let topLineLeft = line('w0') + wincmd p + let topLineRight = line('w0') + setl noscrollbind + wincmd p + setl noscrollbind + call assert_equal(0, topLineLeft - topLineRight) +endfunc diff --git a/src/testdir/test_search.vim b/src/testdir/test_search.vim new file mode 100644 index 0000000..0dfea49 --- /dev/null +++ b/src/testdir/test_search.vim @@ -0,0 +1,1189 @@ +" Test for the search command + +source shared.vim +source screendump.vim + +func Test_search_cmdline() + if !exists('+incsearch') + return + endif + " need to disable char_avail, + " so that expansion of commandline works + call test_override("char_avail", 1) + new + call setline(1, [' 1', ' 2 these', ' 3 the', ' 4 their', ' 5 there', ' 6 their', ' 7 the', ' 8 them', ' 9 these', ' 10 foobar']) + " Test 1 + " CTRL-N / CTRL-P skips through the previous search history + set noincsearch + :1 + call feedkeys("/foobar\<cr>", 'tx') + call feedkeys("/the\<cr>",'tx') + call assert_equal('the', @/) + call feedkeys("/thes\<C-P>\<C-P>\<cr>",'tx') + call assert_equal('foobar', @/) + + " Test 2 + " Ctrl-G goes from one match to the next + " until the end of the buffer + set incsearch nowrapscan + :1 + " first match + call feedkeys("/the\<cr>", 'tx') + call assert_equal(' 2 these', getline('.')) + :1 + " second match + call feedkeys("/the\<C-G>\<cr>", 'tx') + call assert_equal(' 3 the', getline('.')) + call assert_equal([0, 0, 0, 0], getpos('"')) + :1 + " third match + call feedkeys("/the".repeat("\<C-G>", 2)."\<cr>", 'tx') + call assert_equal(' 4 their', getline('.')) + :1 + " fourth match + call feedkeys("/the".repeat("\<C-G>", 3)."\<cr>", 'tx') + call assert_equal(' 5 there', getline('.')) + :1 + " fifth match + call feedkeys("/the".repeat("\<C-G>", 4)."\<cr>", 'tx') + call assert_equal(' 6 their', getline('.')) + :1 + " sixth match + call feedkeys("/the".repeat("\<C-G>", 5)."\<cr>", 'tx') + call assert_equal(' 7 the', getline('.')) + :1 + " seventh match + call feedkeys("/the".repeat("\<C-G>", 6)."\<cr>", 'tx') + call assert_equal(' 8 them', getline('.')) + :1 + " eigth match + call feedkeys("/the".repeat("\<C-G>", 7)."\<cr>", 'tx') + call assert_equal(' 9 these', getline('.')) + :1 + " no further match + call feedkeys("/the".repeat("\<C-G>", 8)."\<cr>", 'tx') + call assert_equal(' 9 these', getline('.')) + call assert_equal([0, 0, 0, 0], getpos('"')) + + " Test 3 + " Ctrl-G goes from one match to the next + " and continues back at the top + set incsearch wrapscan + :1 + " first match + call feedkeys("/the\<cr>", 'tx') + call assert_equal(' 2 these', getline('.')) + :1 + " second match + call feedkeys("/the\<C-G>\<cr>", 'tx') + call assert_equal(' 3 the', getline('.')) + :1 + " third match + call feedkeys("/the".repeat("\<C-G>", 2)."\<cr>", 'tx') + call assert_equal(' 4 their', getline('.')) + :1 + " fourth match + call feedkeys("/the".repeat("\<C-G>", 3)."\<cr>", 'tx') + call assert_equal(' 5 there', getline('.')) + :1 + " fifth match + call feedkeys("/the".repeat("\<C-G>", 4)."\<cr>", 'tx') + call assert_equal(' 6 their', getline('.')) + :1 + " sixth match + call feedkeys("/the".repeat("\<C-G>", 5)."\<cr>", 'tx') + call assert_equal(' 7 the', getline('.')) + :1 + " seventh match + call feedkeys("/the".repeat("\<C-G>", 6)."\<cr>", 'tx') + call assert_equal(' 8 them', getline('.')) + :1 + " eigth match + call feedkeys("/the".repeat("\<C-G>", 7)."\<cr>", 'tx') + call assert_equal(' 9 these', getline('.')) + :1 + " back at first match + call feedkeys("/the".repeat("\<C-G>", 8)."\<cr>", 'tx') + call assert_equal(' 2 these', getline('.')) + + " Test 4 + " CTRL-T goes to the previous match + set incsearch nowrapscan + $ + " first match + call feedkeys("?the\<cr>", 'tx') + call assert_equal(' 9 these', getline('.')) + $ + " first match + call feedkeys("?the\<C-G>\<cr>", 'tx') + call assert_equal(' 9 these', getline('.')) + $ + " second match + call feedkeys("?the".repeat("\<C-T>", 1)."\<cr>", 'tx') + call assert_equal(' 8 them', getline('.')) + $ + " last match + call feedkeys("?the".repeat("\<C-T>", 7)."\<cr>", 'tx') + call assert_equal(' 2 these', getline('.')) + $ + " last match + call feedkeys("?the".repeat("\<C-T>", 8)."\<cr>", 'tx') + call assert_equal(' 2 these', getline('.')) + + " Test 5 + " CTRL-T goes to the previous match + set incsearch wrapscan + $ + " first match + call feedkeys("?the\<cr>", 'tx') + call assert_equal(' 9 these', getline('.')) + $ + " first match at the top + call feedkeys("?the\<C-G>\<cr>", 'tx') + call assert_equal(' 2 these', getline('.')) + $ + " second match + call feedkeys("?the".repeat("\<C-T>", 1)."\<cr>", 'tx') + call assert_equal(' 8 them', getline('.')) + $ + " last match + call feedkeys("?the".repeat("\<C-T>", 7)."\<cr>", 'tx') + call assert_equal(' 2 these', getline('.')) + $ + " back at the bottom of the buffer + call feedkeys("?the".repeat("\<C-T>", 8)."\<cr>", 'tx') + call assert_equal(' 9 these', getline('.')) + + " Test 6 + " CTRL-L adds to the search pattern + set incsearch wrapscan + 1 + " first match + call feedkeys("/the\<c-l>\<cr>", 'tx') + call assert_equal(' 2 these', getline('.')) + 1 + " go to next match of 'thes' + call feedkeys("/the\<c-l>\<C-G>\<cr>", 'tx') + call assert_equal(' 9 these', getline('.')) + 1 + " wrap around + call feedkeys("/the\<c-l>\<C-G>\<C-G>\<cr>", 'tx') + call assert_equal(' 2 these', getline('.')) + 1 + " wrap around + set nowrapscan + call feedkeys("/the\<c-l>\<C-G>\<C-G>\<cr>", 'tx') + call assert_equal(' 9 these', getline('.')) + + " Test 7 + " <bs> remove from match, but stay at current match + set incsearch wrapscan + 1 + " first match + call feedkeys("/thei\<cr>", 'tx') + call assert_equal(' 4 their', getline('.')) + 1 + " delete one char, add another + call feedkeys("/thei\<bs>s\<cr>", 'tx') + call assert_equal(' 2 these', getline('.')) + 1 + " delete one char, add another, go to previous match, add one char + call feedkeys("/thei\<bs>s\<bs>\<C-T>\<c-l>\<cr>", 'tx') + call assert_equal(' 9 these', getline('.')) + 1 + " delete all chars, start from the beginning again + call feedkeys("/them". repeat("\<bs>",4).'the\>'."\<cr>", 'tx') + call assert_equal(' 3 the', getline('.')) + + " clean up + call test_override("char_avail", 0) + bw! +endfunc + +func Test_search_cmdline2() + if !exists('+incsearch') + return + endif + " need to disable char_avail, + " so that expansion of commandline works + call test_override("char_avail", 1) + new + call setline(1, [' 1', ' 2 these', ' 3 the theother']) + " Test 1 + " Ctrl-T goes correctly back and forth + set incsearch + 1 + " first match + call feedkeys("/the\<cr>", 'tx') + call assert_equal(' 2 these', getline('.')) + 1 + " go to next match (on next line) + call feedkeys("/the\<C-G>\<cr>", 'tx') + call assert_equal(' 3 the theother', getline('.')) + 1 + " go to next match (still on line 3) + call feedkeys("/the\<C-G>\<C-G>\<cr>", 'tx') + call assert_equal(' 3 the theother', getline('.')) + 1 + " go to next match (still on line 3) + call feedkeys("/the\<C-G>\<C-G>\<C-G>\<cr>", 'tx') + call assert_equal(' 3 the theother', getline('.')) + 1 + " go to previous match (on line 3) + call feedkeys("/the\<C-G>\<C-G>\<C-G>\<C-T>\<cr>", 'tx') + call assert_equal(' 3 the theother', getline('.')) + 1 + " go to previous match (on line 3) + call feedkeys("/the\<C-G>\<C-G>\<C-G>\<C-T>\<C-T>\<cr>", 'tx') + call assert_equal(' 3 the theother', getline('.')) + 1 + " go to previous match (on line 2) + call feedkeys("/the\<C-G>\<C-G>\<C-G>\<C-T>\<C-T>\<C-T>\<cr>", 'tx') + call assert_equal(' 2 these', getline('.')) + + " Test 2: keep the view, + " after deleting a character from the search cmd + call setline(1, [' 1', ' 2 these', ' 3 the', ' 4 their', ' 5 there', ' 6 their', ' 7 the', ' 8 them', ' 9 these', ' 10 foobar']) + resize 5 + 1 + call feedkeys("/foo\<bs>\<cr>", 'tx') + redraw + call assert_equal({'lnum': 10, 'leftcol': 0, 'col': 4, 'topfill': 0, 'topline': 6, 'coladd': 0, 'skipcol': 0, 'curswant': 4}, winsaveview()) + + " remove all history entries + for i in range(10) + call histdel('/') + endfor + + " Test 3: reset the view, + " after deleting all characters from the search cmd + norm! 1gg0 + " unfortunately, neither "/foo\<c-w>\<cr>", nor "/foo\<bs>\<bs>\<bs>\<cr>", + " nor "/foo\<c-u>\<cr>" works to delete the commandline. + " In that case Vim should return "E35 no previous regular expression", + " but it looks like Vim still sees /foo and therefore the test fails. + " Therefore, disableing this test + "call assert_fails(feedkeys("/foo\<c-w>\<cr>", 'tx'), 'E35') + "call assert_equal({'lnum': 1, 'leftcol': 0, 'col': 0, 'topfill': 0, 'topline': 1, 'coladd': 0, 'skipcol': 0, 'curswant': 0}, winsaveview()) + + " clean up + set noincsearch + call test_override("char_avail", 0) + bw! +endfunc + +func Test_use_sub_pat() + split + let @/ = '' + func X() + s/^/a/ + / + endfunc + call X() + bwipe! +endfunc + +func Test_searchpair() + new + call setline(1, ['other code here', '', '[', '" cursor here', ']']) + 4 + let a = searchpair('\[','',']','bW') + call assert_equal(3, a) + set nomagic + 4 + let a = searchpair('\[','',']','bW') + call assert_equal(3, a) + set magic + q! +endfunc + +func Test_searchpair_errors() + call assert_fails("call searchpair([0], 'middle', 'end', 'bW', 'skip', 99, 100)", 'E730: using List as a String') + call assert_fails("call searchpair('start', {-> 0}, 'end', 'bW', 'skip', 99, 100)", 'E729: using Funcref as a String') + call assert_fails("call searchpair('start', 'middle', {'one': 1}, 'bW', 'skip', 99, 100)", 'E731: using Dictionary as a String') + call assert_fails("call searchpair('start', 'middle', 'end', 'flags', 'skip', 99, 100)", 'E475: Invalid argument: flags') + call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 0, 99, 100)", 'E475: Invalid argument: 0') + call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 'func', -99, 100)", 'E475: Invalid argument: -99') + call assert_fails("call searchpair('start', 'middle', 'end', 'bW', 'func', 99, -100)", 'E475: Invalid argument: -100') +endfunc + +func Test_searchpair_skip() + func Zero() + return 0 + endfunc + func Partial(x) + return a:x + endfunc + new + call setline(1, ['{', 'foo', 'foo', 'foo', '}']) + 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', '')) + 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', '0')) + 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', {-> 0})) + 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', function('Zero'))) + 3 | call assert_equal(1, searchpair('{', '', '}', 'bWn', function('Partial', [0]))) + bw! +endfunc + +func Test_searchpair_leak() + new + call setline(1, 'if one else another endif') + + " The error in the skip expression caused memory to leak. + call assert_fails("call searchpair('\\<if\\>', '\\<else\\>', '\\<endif\\>', '', '\"foo\" 2')", 'E15:') + + bwipe! +endfunc + +func Test_searchc() + " These commands used to cause memory overflow in searchc(). + new + norm ixx + exe "norm 0t\u93cf" + bw! +endfunc + +func Cmdline3_prep() + " need to disable char_avail, + " so that expansion of commandline works + call test_override("char_avail", 1) + new + call setline(1, [' 1', ' 2 the~e', ' 3 the theother']) + set incsearch +endfunc + +func Incsearch_cleanup() + set noincsearch + call test_override("char_avail", 0) + bw! +endfunc + +func Test_search_cmdline3() + if !exists('+incsearch') + return + endif + call Cmdline3_prep() + 1 + " first match + call feedkeys("/the\<c-l>\<cr>", 'tx') + call assert_equal(' 2 the~e', getline('.')) + + call Incsearch_cleanup() +endfunc + +func Test_search_cmdline3s() + if !exists('+incsearch') + return + endif + call Cmdline3_prep() + 1 + call feedkeys(":%s/the\<c-l>/xxx\<cr>", 'tx') + call assert_equal(' 2 xxxe', getline('.')) + undo + call feedkeys(":%subs/the\<c-l>/xxx\<cr>", 'tx') + call assert_equal(' 2 xxxe', getline('.')) + undo + call feedkeys(":%substitute/the\<c-l>/xxx\<cr>", 'tx') + call assert_equal(' 2 xxxe', getline('.')) + undo + call feedkeys(":%smagic/the.e/xxx\<cr>", 'tx') + call assert_equal(' 2 xxx', getline('.')) + undo + call assert_fails(":%snomagic/the.e/xxx\<cr>", 'E486') + " + call feedkeys(":%snomagic/the\\.e/xxx\<cr>", 'tx') + call assert_equal(' 2 xxx', getline('.')) + + call Incsearch_cleanup() +endfunc + +func Test_search_cmdline3g() + if !exists('+incsearch') + return + endif + call Cmdline3_prep() + 1 + call feedkeys(":g/the\<c-l>/d\<cr>", 'tx') + call assert_equal(' 3 the theother', getline(2)) + undo + call feedkeys(":global/the\<c-l>/d\<cr>", 'tx') + call assert_equal(' 3 the theother', getline(2)) + undo + call feedkeys(":g!/the\<c-l>/d\<cr>", 'tx') + call assert_equal(1, line('$')) + call assert_equal(' 2 the~e', getline(1)) + undo + call feedkeys(":global!/the\<c-l>/d\<cr>", 'tx') + call assert_equal(1, line('$')) + call assert_equal(' 2 the~e', getline(1)) + + call Incsearch_cleanup() +endfunc + +func Test_search_cmdline3v() + if !exists('+incsearch') + return + endif + call Cmdline3_prep() + 1 + call feedkeys(":v/the\<c-l>/d\<cr>", 'tx') + call assert_equal(1, line('$')) + call assert_equal(' 2 the~e', getline(1)) + undo + call feedkeys(":vglobal/the\<c-l>/d\<cr>", 'tx') + call assert_equal(1, line('$')) + call assert_equal(' 2 the~e', getline(1)) + + call Incsearch_cleanup() +endfunc + +func Test_search_cmdline4() + if !exists('+incsearch') + return + endif + " need to disable char_avail, + " so that expansion of commandline works + call test_override("char_avail", 1) + new + call setline(1, [' 1 the first', ' 2 the second', ' 3 the third']) + set incsearch + $ + call feedkeys("?the\<c-g>\<cr>", 'tx') + call assert_equal(' 3 the third', getline('.')) + $ + call feedkeys("?the\<c-g>\<c-g>\<cr>", 'tx') + call assert_equal(' 1 the first', getline('.')) + $ + call feedkeys("?the\<c-g>\<c-g>\<c-g>\<cr>", 'tx') + call assert_equal(' 2 the second', getline('.')) + $ + call feedkeys("?the\<c-t>\<cr>", 'tx') + call assert_equal(' 1 the first', getline('.')) + $ + call feedkeys("?the\<c-t>\<c-t>\<cr>", 'tx') + call assert_equal(' 3 the third', getline('.')) + $ + call feedkeys("?the\<c-t>\<c-t>\<c-t>\<cr>", 'tx') + call assert_equal(' 2 the second', getline('.')) + " clean up + set noincsearch + call test_override("char_avail", 0) + bw! +endfunc + +func Test_search_cmdline5() + if !exists('+incsearch') + return + endif + " Do not call test_override("char_avail", 1) so that <C-g> and <C-t> work + " regardless char_avail. + new + call setline(1, [' 1 the first', ' 2 the second', ' 3 the third']) + set incsearch + 1 + call feedkeys("/the\<c-g>\<c-g>\<cr>", 'tx') + call assert_equal(' 3 the third', getline('.')) + $ + call feedkeys("?the\<c-t>\<c-t>\<c-t>\<cr>", 'tx') + call assert_equal(' 2 the second', getline('.')) + " clean up + set noincsearch + bw! +endfunc + +func Test_search_cmdline6() + " Test that consecutive matches + " are caught by <c-g>/<c-t> + if !exists('+incsearch') + return + endif + " need to disable char_avail, + " so that expansion of commandline works + call test_override("char_avail", 1) + new + call setline(1, [' bbvimb', '']) + set incsearch + " first match + norm! gg0 + call feedkeys("/b\<cr>", 'tx') + call assert_equal([0,1,2,0], getpos('.')) + " second match + norm! gg0 + call feedkeys("/b\<c-g>\<cr>", 'tx') + call assert_equal([0,1,3,0], getpos('.')) + " third match + norm! gg0 + call feedkeys("/b\<c-g>\<c-g>\<cr>", 'tx') + call assert_equal([0,1,7,0], getpos('.')) + " first match again + norm! gg0 + call feedkeys("/b\<c-g>\<c-g>\<c-g>\<cr>", 'tx') + call assert_equal([0,1,2,0], getpos('.')) + set nowrapscan + " last match + norm! gg0 + call feedkeys("/b\<c-g>\<c-g>\<c-g>\<cr>", 'tx') + call assert_equal([0,1,7,0], getpos('.')) + " clean up + set wrapscan&vim + set noincsearch + call test_override("char_avail", 0) + bw! +endfunc + +func Test_search_cmdline7() + " Test that an pressing <c-g> in an empty command line + " does not move the cursor + if !exists('+incsearch') + return + endif + " need to disable char_avail, + " so that expansion of commandline works + call test_override("char_avail", 1) + new + let @/ = 'b' + call setline(1, [' bbvimb', '']) + set incsearch + " first match + norm! gg0 + " moves to next match of previous search pattern, just like /<cr> + call feedkeys("/\<c-g>\<cr>", 'tx') + call assert_equal([0,1,2,0], getpos('.')) + " moves to next match of previous search pattern, just like /<cr> + call feedkeys("/\<cr>", 'tx') + call assert_equal([0,1,3,0], getpos('.')) + " moves to next match of previous search pattern, just like /<cr> + call feedkeys("/\<c-t>\<cr>", 'tx') + call assert_equal([0,1,7,0], getpos('.')) + + " using an offset uses the last search pattern + call cursor(1, 1) + call setline(1, ['1 bbvimb', ' 2 bbvimb']) + let @/ = 'b' + call feedkeys("//e\<c-g>\<cr>", 'tx') + call assert_equal('1 bbvimb', getline('.')) + call assert_equal(4, col('.')) + + set noincsearch + call test_override("char_avail", 0) + bw! +endfunc + +func Test_search_cmdline8() + " Highlighting is cleared in all windows + " since hls applies to all windows + if !exists('+incsearch') || !has('terminal') || has('gui_running') || winwidth(0) < 30 + return + endif + if has("win32") + throw "Skipped: Bug with sending <ESC> to terminal window not fixed yet" + endif + let h = winheight(0) + if h < 3 + return + endif + " Prepare buffer text + let lines = ['abb vim vim vi', 'vimvivim'] + call writefile(lines, 'Xsearch.txt') + let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', 'Xsearch.txt'], {'term_rows': 3}) + + call WaitForAssert({-> assert_equal(lines, [term_getline(buf, 1), term_getline(buf, 2)])}) + + call term_sendkeys(buf, ":set incsearch hlsearch\<cr>") + call term_sendkeys(buf, ":14vsp\<cr>") + call term_sendkeys(buf, "/vim\<cr>") + call term_sendkeys(buf, "/b\<esc>") + call term_sendkeys(buf, "gg0") + call term_wait(buf, 500) + let screen_line = term_scrape(buf, 1) + let [a0,a1,a2,a3] = [screen_line[3].attr, screen_line[4].attr, + \ screen_line[18].attr, screen_line[19].attr] + call assert_notequal(a0, a1) + call assert_notequal(a0, a3) + call assert_notequal(a1, a2) + call assert_equal(a0, a2) + call assert_equal(a1, a3) + " clean up + call delete('Xsearch.txt') + + bwipe! +endfunc + +" Tests for regexp with various magic settings +func Test_search_regexp() + enew! + + put ='1 a aa abb abbccc' + exe 'normal! /a*b\{2}c\+/e' . "\<CR>" + call assert_equal([0, 2, 17, 0], getpos('.')) + + put ='2 d dd dee deefff' + exe 'normal! /\Md\*e\{2}f\+/e' . "\<CR>" + call assert_equal([0, 3, 17, 0], getpos('.')) + + set nomagic + put ='3 g gg ghh ghhiii' + exe 'normal! /g\*h\{2}i\+/e' . "\<CR>" + call assert_equal([0, 4, 17, 0], getpos('.')) + + put ='4 j jj jkk jkklll' + exe 'normal! /\mj*k\{2}l\+/e' . "\<CR>" + call assert_equal([0, 5, 17, 0], getpos('.')) + + put ='5 m mm mnn mnnooo' + exe 'normal! /\vm*n{2}o+/e' . "\<CR>" + call assert_equal([0, 6, 17, 0], getpos('.')) + + put ='6 x ^aa$ x' + exe 'normal! /\V^aa$' . "\<CR>" + call assert_equal([0, 7, 5, 0], getpos('.')) + + set magic + put ='7 (a)(b) abbaa' + exe 'normal! /\v(a)(b)\2\1\1/e' . "\<CR>" + call assert_equal([0, 8, 14, 0], getpos('.')) + + put ='8 axx [ab]xx' + exe 'normal! /\V[ab]\(\[xy]\)\1' . "\<CR>" + call assert_equal([0, 9, 7, 0], getpos('.')) + + set undolevels=100 + put ='9 foobar' + put ='' + exe "normal! a\<C-G>u\<Esc>" + normal G + exe 'normal! dv?bar?' . "\<CR>" + call assert_equal('9 foo', getline('.')) + call assert_equal([0, 10, 5, 0], getpos('.')) + call assert_equal(10, line('$')) + normal u + call assert_equal('9 foobar', getline('.')) + call assert_equal([0, 10, 6, 0], getpos('.')) + call assert_equal(11, line('$')) + + set undolevels& + enew! +endfunc + +func Test_search_cmdline_incsearch_highlight() + if !exists('+incsearch') + return + endif + set incsearch hlsearch + " need to disable char_avail, + " so that expansion of commandline works + call test_override("char_avail", 1) + new + call setline(1, ['aaa 1 the first', ' 2 the second', ' 3 the third']) + + 1 + call feedkeys("/second\<cr>", 'tx') + call assert_equal('second', @/) + call assert_equal(' 2 the second', getline('.')) + + " Canceling search won't change @/ + 1 + let @/ = 'last pattern' + call feedkeys("/third\<C-c>", 'tx') + call assert_equal('last pattern', @/) + call feedkeys("/third\<Esc>", 'tx') + call assert_equal('last pattern', @/) + call feedkeys("/3\<bs>\<bs>", 'tx') + call assert_equal('last pattern', @/) + call feedkeys("/third\<c-g>\<c-t>\<Esc>", 'tx') + call assert_equal('last pattern', @/) + + " clean up + set noincsearch nohlsearch + bw! +endfunc + +func Test_search_cmdline_incsearch_highlight_attr() + if !exists('+incsearch') || !has('terminal') || has('gui_running') + return + endif + let h = winheight(0) + if h < 3 + return + endif + + " Prepare buffer text + let lines = ['abb vim vim vi', 'vimvivim'] + call writefile(lines, 'Xsearch.txt') + let buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile', 'Xsearch.txt'], {'term_rows': 3}) + + call WaitForAssert({-> assert_equal(lines, [term_getline(buf, 1), term_getline(buf, 2)])}) + " wait for vim to complete initialization + call term_wait(buf) + + " Get attr of normal(a0), incsearch(a1), hlsearch(a2) highlight + call term_sendkeys(buf, ":set incsearch hlsearch\<cr>") + call term_sendkeys(buf, '/b') + call term_wait(buf, 200) + let screen_line1 = term_scrape(buf, 1) + call assert_true(len(screen_line1) > 2) + " a0: attr_normal + let a0 = screen_line1[0].attr + " a1: attr_incsearch + let a1 = screen_line1[1].attr + " a2: attr_hlsearch + let a2 = screen_line1[2].attr + call assert_notequal(a0, a1) + call assert_notequal(a0, a2) + call assert_notequal(a1, a2) + call term_sendkeys(buf, "\<cr>gg0") + + " Test incremental highlight search + call term_sendkeys(buf, "/vim") + call term_wait(buf, 200) + " Buffer: + " abb vim vim vi + " vimvivim + " Search: /vim + let attr_line1 = [a0,a0,a0,a0,a1,a1,a1,a0,a2,a2,a2,a0,a0,a0] + let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] + call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) + call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr')) + + " Test <C-g> + call term_sendkeys(buf, "\<C-g>\<C-g>") + call term_wait(buf, 200) + let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a2,a2,a2,a0,a0,a0] + let attr_line2 = [a1,a1,a1,a0,a0,a2,a2,a2] + call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) + call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr')) + + " Test <C-t> + call term_sendkeys(buf, "\<C-t>") + call term_wait(buf, 200) + let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a1,a1,a1,a0,a0,a0] + let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] + call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) + call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr')) + + " Type Enter and a1(incsearch highlight) should become a2(hlsearch highlight) + call term_sendkeys(buf, "\<cr>") + call term_wait(buf, 200) + let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a2,a2,a2,a0,a0,a0] + let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] + call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) + call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr')) + + " Test nohlsearch. a2(hlsearch highlight) should become a0(normal highlight) + call term_sendkeys(buf, ":1\<cr>") + call term_sendkeys(buf, ":set nohlsearch\<cr>") + call term_sendkeys(buf, "/vim") + call term_wait(buf, 200) + let attr_line1 = [a0,a0,a0,a0,a1,a1,a1,a0,a0,a0,a0,a0,a0,a0] + let attr_line2 = [a0,a0,a0,a0,a0,a0,a0,a0] + call assert_equal(attr_line1, map(term_scrape(buf, 1)[:len(attr_line1)-1], 'v:val.attr')) + call assert_equal(attr_line2, map(term_scrape(buf, 2)[:len(attr_line2)-1], 'v:val.attr')) + call delete('Xsearch.txt') + + call delete('Xsearch.txt') + bwipe! +endfunc + +func Test_incsearch_cmdline_modifier() + if !exists('+incsearch') + return + endif + call test_override("char_avail", 1) + new + call setline(1, ['foo']) + set incsearch + " Test that error E14 does not occur in parsing command modifier. + call feedkeys("V:tab", 'tx') + + call Incsearch_cleanup() +endfunc + +func Test_incsearch_scrolling() + if !CanRunVimInTerminal() + return + endif + call assert_equal(0, &scrolloff) + call writefile([ + \ 'let dots = repeat(".", 120)', + \ 'set incsearch cmdheight=2 scrolloff=0', + \ 'call setline(1, [dots, dots, dots, "", "target", dots, dots])', + \ 'normal gg', + \ 'redraw', + \ ], 'Xscript') + let buf = RunVimInTerminal('-S Xscript', {'rows': 9, 'cols': 70}) + " Need to send one key at a time to force a redraw + call term_sendkeys(buf, '/') + sleep 100m + call term_sendkeys(buf, 't') + sleep 100m + call term_sendkeys(buf, 'a') + sleep 100m + call term_sendkeys(buf, 'r') + sleep 100m + call term_sendkeys(buf, 'g') + call VerifyScreenDump(buf, 'Test_incsearch_scrolling_01', {}) + + call term_sendkeys(buf, "\<Esc>") + call StopVimInTerminal(buf) + call delete('Xscript') +endfunc + +func Test_incsearch_search_dump() + if !exists('+incsearch') + return + endif + if !CanRunVimInTerminal() + return + endif + call writefile([ + \ 'set incsearch hlsearch scrolloff=0', + \ 'for n in range(1, 8)', + \ ' call setline(n, "foo " . n)', + \ 'endfor', + \ '3', + \ ], 'Xis_search_script') + let buf = RunVimInTerminal('-S Xis_search_script', {'rows': 9, 'cols': 70}) + " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by + " the 'ambiwidth' check. + sleep 100m + + " Need to send one key at a time to force a redraw. + call term_sendkeys(buf, '/fo') + call VerifyScreenDump(buf, 'Test_incsearch_search_01', {}) + call term_sendkeys(buf, "\<Esc>") + sleep 100m + + call term_sendkeys(buf, '/\v') + call VerifyScreenDump(buf, 'Test_incsearch_search_02', {}) + call term_sendkeys(buf, "\<Esc>") + + call StopVimInTerminal(buf) + call delete('Xis_search_script') +endfunc + +func Test_incsearch_substitute() + if !exists('+incsearch') + return + endif + call test_override("char_avail", 1) + new + set incsearch + for n in range(1, 10) + call setline(n, 'foo ' . n) + endfor + 4 + call feedkeys(":.,.+2s/foo\<BS>o\<BS>o/xxx\<cr>", 'tx') + call assert_equal('foo 3', getline(3)) + call assert_equal('xxx 4', getline(4)) + call assert_equal('xxx 5', getline(5)) + call assert_equal('xxx 6', getline(6)) + call assert_equal('foo 7', getline(7)) + + call Incsearch_cleanup() +endfunc + +" Similar to Test_incsearch_substitute() but with a screendump halfway. +func Test_incsearch_substitute_dump() + if !exists('+incsearch') + return + endif + if !CanRunVimInTerminal() + return + endif + call writefile([ + \ 'set incsearch hlsearch scrolloff=0', + \ 'for n in range(1, 10)', + \ ' call setline(n, "foo " . n)', + \ 'endfor', + \ 'call setline(11, "bar 11")', + \ '3', + \ ], 'Xis_subst_script') + let buf = RunVimInTerminal('-S Xis_subst_script', {'rows': 9, 'cols': 70}) + " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by + " the 'ambiwidth' check. + sleep 100m + + " Need to send one key at a time to force a redraw. + " Select three lines at the cursor with typed pattern. + call term_sendkeys(buf, ':.,.+2s/') + sleep 100m + call term_sendkeys(buf, 'f') + sleep 100m + call term_sendkeys(buf, 'o') + sleep 100m + call term_sendkeys(buf, 'o') + call VerifyScreenDump(buf, 'Test_incsearch_substitute_01', {}) + call term_sendkeys(buf, "\<Esc>") + + " Select three lines at the cursor using previous pattern. + call term_sendkeys(buf, "/foo\<CR>") + sleep 100m + call term_sendkeys(buf, ':.,.+2s//') + call VerifyScreenDump(buf, 'Test_incsearch_substitute_02', {}) + + " Deleting last slash should remove the match. + call term_sendkeys(buf, "\<BS>") + call VerifyScreenDump(buf, 'Test_incsearch_substitute_03', {}) + call term_sendkeys(buf, "\<Esc>") + + " Reverse range is accepted + call term_sendkeys(buf, ':5,2s/foo') + call VerifyScreenDump(buf, 'Test_incsearch_substitute_04', {}) + call term_sendkeys(buf, "\<Esc>") + + " White space after the command is skipped + call term_sendkeys(buf, ':2,3sub /fo') + call VerifyScreenDump(buf, 'Test_incsearch_substitute_05', {}) + call term_sendkeys(buf, "\<Esc>") + + " Command modifiers are skipped + call term_sendkeys(buf, ':above below browse botr confirm keepmar keepalt keeppat keepjum filter xxx hide lockm leftabove noau noswap rightbel sandbox silent silent! $tab top unsil vert verbose 4,5s/fo.') + call VerifyScreenDump(buf, 'Test_incsearch_substitute_06', {}) + call term_sendkeys(buf, "\<Esc>") + + " Cursorline highlighting at match + call term_sendkeys(buf, ":set cursorline\<CR>") + call term_sendkeys(buf, 'G9G') + call term_sendkeys(buf, ':9,11s/bar') + call VerifyScreenDump(buf, 'Test_incsearch_substitute_07', {}) + call term_sendkeys(buf, "\<Esc>") + + " Cursorline highlighting at cursor when no match + call term_sendkeys(buf, ':9,10s/bar') + call VerifyScreenDump(buf, 'Test_incsearch_substitute_08', {}) + call term_sendkeys(buf, "\<Esc>") + + " Only \v handled as empty pattern, does not move cursor + call term_sendkeys(buf, '3G4G') + call term_sendkeys(buf, ":nohlsearch\<CR>") + call term_sendkeys(buf, ':6,7s/\v') + call VerifyScreenDump(buf, 'Test_incsearch_substitute_09', {}) + call term_sendkeys(buf, "\<Esc>") + + call term_sendkeys(buf, ":set nocursorline\<CR>") + + " All matches are highlighted for 'hlsearch' after the incsearch canceled + call term_sendkeys(buf, "1G*") + call term_sendkeys(buf, ":2,5s/foo") + sleep 100m + call term_sendkeys(buf, "\<Esc>") + call VerifyScreenDump(buf, 'Test_incsearch_substitute_10', {}) + + call term_sendkeys(buf, ":split\<CR>") + call term_sendkeys(buf, ":let @/ = 'xyz'\<CR>") + call term_sendkeys(buf, ":%s/.") + call VerifyScreenDump(buf, 'Test_incsearch_substitute_11', {}) + call term_sendkeys(buf, "\<BS>") + call VerifyScreenDump(buf, 'Test_incsearch_substitute_12', {}) + call term_sendkeys(buf, "\<Esc>") + call VerifyScreenDump(buf, 'Test_incsearch_substitute_13', {}) + + call StopVimInTerminal(buf) + call delete('Xis_subst_script') +endfunc + +" Similar to Test_incsearch_substitute_dump() for :sort +func Test_incsearch_sort_dump() + if !exists('+incsearch') + return + endif + if !CanRunVimInTerminal() + return + endif + call writefile([ + \ 'set incsearch hlsearch scrolloff=0', + \ 'call setline(1, ["another one 2", "that one 3", "the one 1"])', + \ ], 'Xis_sort_script') + let buf = RunVimInTerminal('-S Xis_sort_script', {'rows': 9, 'cols': 70}) + " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by + " the 'ambiwidth' check. + sleep 100m + + " Need to send one key at a time to force a redraw. + call term_sendkeys(buf, ':sort ni u /on') + call VerifyScreenDump(buf, 'Test_incsearch_sort_01', {}) + call term_sendkeys(buf, "\<Esc>") + + call StopVimInTerminal(buf) + call delete('Xis_sort_script') +endfunc + +" Similar to Test_incsearch_substitute_dump() for :vimgrep famiry +func Test_incsearch_vimgrep_dump() + if !exists('+incsearch') + return + endif + if !CanRunVimInTerminal() + return + endif + call writefile([ + \ 'set incsearch hlsearch scrolloff=0', + \ 'call setline(1, ["another one 2", "that one 3", "the one 1"])', + \ ], 'Xis_vimgrep_script') + let buf = RunVimInTerminal('-S Xis_vimgrep_script', {'rows': 9, 'cols': 70}) + " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by + " the 'ambiwidth' check. + sleep 100m + + " Need to send one key at a time to force a redraw. + call term_sendkeys(buf, ':vimgrep on') + call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_01', {}) + call term_sendkeys(buf, "\<Esc>") + + call term_sendkeys(buf, ':vimg /on/ *.txt') + call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_02', {}) + call term_sendkeys(buf, "\<Esc>") + + call term_sendkeys(buf, ':vimgrepadd "\<on') + call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_03', {}) + call term_sendkeys(buf, "\<Esc>") + + call term_sendkeys(buf, ':lv "tha') + call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_04', {}) + call term_sendkeys(buf, "\<Esc>") + + call term_sendkeys(buf, ':lvimgrepa "the" **/*.txt') + call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_05', {}) + call term_sendkeys(buf, "\<Esc>") + + call StopVimInTerminal(buf) + call delete('Xis_vimgrep_script') +endfunc + +func Test_keep_last_search_pattern() + if !exists('+incsearch') + return + endif + new + call setline(1, ['foo', 'foo', 'foo']) + set incsearch + call test_override("char_avail", 1) + let @/ = 'bar' + call feedkeys(":/foo/s//\<Esc>", 'ntx') + call assert_equal('bar', @/) + + " no error message if pattern not found + call feedkeys(":/xyz/s//\<Esc>", 'ntx') + call assert_equal('bar', @/) + + bwipe! + call test_override("ALL", 0) + set noincsearch +endfunc + +func Test_word_under_cursor_after_match() + if !exists('+incsearch') + return + endif + new + call setline(1, 'foo bar') + set incsearch + call test_override("char_avail", 1) + try + call feedkeys("/foo\<C-R>\<C-W>\<CR>", 'ntx') + catch /E486:/ + endtry + call assert_equal('foobar', @/) + + bwipe! + call test_override("ALL", 0) + set noincsearch +endfunc + +func Test_subst_word_under_cursor() + if !exists('+incsearch') + return + endif + new + call setline(1, ['int SomeLongName;', 'for (xxx = 1; xxx < len; ++xxx)']) + set incsearch + call test_override("char_avail", 1) + call feedkeys("/LongName\<CR>", 'ntx') + call feedkeys(":%s/xxx/\<C-R>\<C-W>/g\<CR>", 'ntx') + call assert_equal('for (SomeLongName = 1; SomeLongName < len; ++SomeLongName)', getline(2)) + + bwipe! + call test_override("ALL", 0) + set noincsearch +endfunc + +func Test_search_undefined_behaviour() + if !has("terminal") + return + endif + let h = winheight(0) + if h < 3 + return + endif + " did cause an undefined left shift + let g:buf = term_start([GetVimProg(), '--clean', '-e', '-s', '-c', 'call search(getline("."))', 'samples/test000'], {'term_rows': 3}) + call assert_equal([''], getline(1, '$')) + call term_sendkeys(g:buf, ":qa!\<cr>") + bwipe! +endfunc + +func Test_search_undefined_behaviour2() + call search("\%UC0000000") +endfunc + +" Test for search('multi-byte char', 'bce') +func Test_search_multibyte() + let save_enc = &encoding + set encoding=utf8 + enew! + call append('$', 'A') + call cursor(2, 1) + call assert_equal(2, search('A', 'bce', line('.'))) + enew! + let &encoding = save_enc +endfunc + +" This was causing E874. Also causes an invalid read? +func Test_look_behind() + new + call setline(1, '0\|\&\n\@<=') + call search(getline(".")) + bwipe! +endfunc + +func Test_search_sentence() + new + " this used to cause a crash + call assert_fails("/\\%')", 'E486') + call assert_fails("/", 'E486') + /\%'( + / +endfunc + +" Test that there is no crash when there is a last search pattern but no last +" substitute pattern. +func Test_no_last_substitute_pat() + " Use viminfo to set the last search pattern to a string and make the last + " substitute pattern the most recent used and make it empty (NULL). + call writefile(['~MSle0/bar', '~MSle0~&'], 'Xviminfo') + rviminfo! Xviminfo + call assert_fails('normal n', 'E35:') + + call delete('Xviminfo') +endfunc + +func Test_search_Ctrl_L_combining() + " Make sure, that Ctrl-L works correctly with combining characters. + " It uses an artificial example of an 'a' with 4 combining chars: + " 'a' U+0061 Dec:97 LATIN SMALL LETTER A a /\%u61\Z "\u0061" + " ' ̀' U+0300 Dec:768 COMBINING GRAVE ACCENT ̀ /\%u300\Z "\u0300" + " ' ́' U+0301 Dec:769 COMBINING ACUTE ACCENT ́ /\%u301\Z "\u0301" + " ' ̇' U+0307 Dec:775 COMBINING DOT ABOVE ̇ /\%u307\Z "\u0307" + " ' ̣' U+0323 Dec:803 COMBINING DOT BELOW ̣ /\%u323 "\u0323" + " Those should also appear on the commandline + if !exists('+incsearch') + return + endif + call Cmdline3_prep() + 1 + let bufcontent = ['', 'Miạ̀́̇m'] + call append('$', bufcontent) + call feedkeys("/Mi\<c-l>\<c-l>\<cr>", 'tx') + call assert_equal(5, line('.')) + call assert_equal(bufcontent[1], @/) + call Incsearch_cleanup() +endfunc diff --git a/src/testdir/test_searchpos.vim b/src/testdir/test_searchpos.vim new file mode 100644 index 0000000..8dffddc --- /dev/null +++ b/src/testdir/test_searchpos.vim @@ -0,0 +1,28 @@ +" Tests for searchpos() + +func Test_searchpos() + new one + 0put ='1a3' + 1put ='123xyz' + call cursor(1, 1) + call assert_equal([1, 1, 2], searchpos('\%(\([a-z]\)\|\_.\)\{-}xyz', 'pcW')) + call cursor(1, 2) + call assert_equal([2, 1, 1], searchpos('\%(\([a-z]\)\|\_.\)\{-}xyz', 'pcW')) + set cpo-=c + call cursor(1, 2) + call assert_equal([1, 2, 2], searchpos('\%(\([a-z]\)\|\_.\)\{-}xyz', 'pcW')) + call cursor(1, 3) + call assert_equal([1, 3, 1], searchpos('\%(\([a-z]\)\|\_.\)\{-}xyz', 'pcW')) + + " Now with \zs, first match is in column 0, "a" is matched. + call cursor(1, 3) + call assert_equal([2, 4, 2], searchpos('\%(\([a-z]\)\|\_.\)\{-}\zsxyz', 'pcW')) + " With z flag start at cursor column, don't see the "a". + call cursor(1, 3) + call assert_equal([2, 4, 1], searchpos('\%(\([a-z]\)\|\_.\)\{-}\zsxyz', 'pcWz')) + + set cpo+=c + " close the window + q! + +endfunc diff --git a/src/testdir/test_set.vim b/src/testdir/test_set.vim new file mode 100644 index 0000000..b980463 --- /dev/null +++ b/src/testdir/test_set.vim @@ -0,0 +1,27 @@ +" Tests for the :set command + +function Test_set_backslash() + let isk_save = &isk + + set isk=a,b,c + set isk+=d + call assert_equal('a,b,c,d', &isk) + set isk+=\\,e + call assert_equal('a,b,c,d,\,e', &isk) + set isk-=e + call assert_equal('a,b,c,d,\', &isk) + set isk-=\\ + call assert_equal('a,b,c,d', &isk) + + let &isk = isk_save +endfunction + +function Test_set_add() + let wig_save = &wig + + set wildignore=*.png, + set wildignore+=*.jpg + call assert_equal('*.png,*.jpg', &wig) + + let &wig = wig_save +endfunction diff --git a/src/testdir/test_sha256.vim b/src/testdir/test_sha256.vim new file mode 100644 index 0000000..dd47079 --- /dev/null +++ b/src/testdir/test_sha256.vim @@ -0,0 +1,22 @@ +" Tests for the sha256() function. + +if !has('cryptv') || !exists('*sha256') + finish +endif + +function Test_sha256() + " test for empty string: + call assert_equal(sha256(""), 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855') + + "'test for 1 char: + call assert_equal(sha256("a"), 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb') + " + "test for 3 chars: + call assert_equal(sha256("abc"), 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad') + + " test for contains meta char: + call assert_equal(sha256("foo\nbar"), '807eff6267f3f926a21d234f7b0cf867a86f47e07a532f15e8cc39ed110ca776') + + " test for contains non-ascii char: + call assert_equal(sha256("\xde\xad\xbe\xef"), '5f78c33274e43fa9de5659265c1d917e25c03722dcb0b8d27db8d5feaa813953') +endfunction diff --git a/src/testdir/test_short_sleep.py b/src/testdir/test_short_sleep.py new file mode 100644 index 0000000..a290443 --- /dev/null +++ b/src/testdir/test_short_sleep.py @@ -0,0 +1,11 @@ +#!/usr/bin/python +# +# Program that sleeps for 100 msec +# +# This requires Python 2.6 or later. + +import time + +if __name__ == "__main__": + + time.sleep(0.1) # sleep 100 msec diff --git a/src/testdir/test_shortpathname.vim b/src/testdir/test_shortpathname.vim new file mode 100644 index 0000000..f151788 --- /dev/null +++ b/src/testdir/test_shortpathname.vim @@ -0,0 +1,70 @@ +" Test for shortpathname ':8' extension. +" Only for use on Win32 systems! + +if !has('win32') + finish +endif + +func TestIt(file, bits, expected) + let res = fnamemodify(a:file, a:bits) + if a:expected != '' + call assert_equal(substitute(a:expected, '/', '\\', 'g'), + \ substitute(res, '/', '\\', 'g'), + \ "'" . a:file . "'->(" . a:bits . ")->'" . res . "'") + endif +endfunc + +func Test_ColonEight() + let save_dir = getcwd() + + " This could change for CygWin to //cygdrive/c + let dir1 = 'c:/x.x.y' + if filereadable(dir1) || isdirectory(dir1) + call assert_report("Fatal: '" . dir1 . "' exists, cannot run test") + return + endif + + let file1 = dir1 . '/zz.y.txt' + let nofile1 = dir1 . '/z.y.txt' + let dir2 = dir1 . '/VimIsTheGreatestSinceSlicedBread' + let file2 = dir2 . '/z.txt' + let nofile2 = dir2 . '/zz.txt' + + call mkdir(dir1) + let resdir1 = substitute(fnamemodify(dir1, ':p:8'), '/$', '', '') + call assert_match('\V\^c:/XX\x\x\x\x~1.Y\$', resdir1) + + let resfile1 = resdir1 . '/ZZY~1.TXT' + let resnofile1 = resdir1 . '/z.y.txt' + let resdir2 = resdir1 . '/VIMIST~1' + let resfile2 = resdir2 . '/z.txt' + let resnofile2 = resdir2 . '/zz.txt' + + call mkdir(dir2) + call writefile([], file1) + call writefile([], file2) + + call TestIt(file1, ':p:8', resfile1) + call TestIt(nofile1, ':p:8', resnofile1) + call TestIt(file2, ':p:8', resfile2) + call TestIt(nofile2, ':p:8', resnofile2) + call TestIt(nofile2, ':p:8:h', fnamemodify(resnofile2, ':h')) + exe 'cd ' . dir1 + call TestIt(file1, ':.:8', strpart(resfile1, strlen(resdir1)+1)) + call TestIt(nofile1, ':.:8', strpart(resnofile1, strlen(resdir1)+1)) + call TestIt(file2, ':.:8', strpart(resfile2, strlen(resdir1)+1)) + call TestIt(nofile2, ':.:8', strpart(resnofile2, strlen(resdir1)+1)) + let $HOME=dir1 + call TestIt(file1, ':~:8', '~' . strpart(resfile1, strlen(resdir1))) + call TestIt(nofile1, ':~:8', '~' . strpart(resnofile1, strlen(resdir1))) + call TestIt(file2, ':~:8', '~' . strpart(resfile2, strlen(resdir1))) + call TestIt(nofile2, ':~:8', '~' . strpart(resnofile2, strlen(resdir1))) + + cd c:/ + call delete(file2) + call delete(file1) + call delete(dir2, 'd') + call delete(dir1, 'd') + + exe "cd " . save_dir +endfunc diff --git a/src/testdir/test_signs.vim b/src/testdir/test_signs.vim new file mode 100644 index 0000000..49bd986 --- /dev/null +++ b/src/testdir/test_signs.vim @@ -0,0 +1,1340 @@ +" Test for signs + +if !has('signs') + finish +endif + +func Test_sign() + new + call setline(1, ['a', 'b', 'c', 'd']) + + " Define some signs. + " We can specify icons even if not all versions of vim support icons as + " icon is ignored when not supported. "(not supported)" is shown after + " the icon name when listing signs. + sign define Sign1 text=x + try + sign define Sign2 text=xy texthl=Title linehl=Error + \ icon=../../pixmaps/stock_vim_find_help.png + catch /E255:/ + " Ignore error: E255: Couldn't read in sign data! + " This error can happen when running in the GUI. + " Some gui like Motif do not support the png icon format. + endtry + + " Test listing signs. + let a=execute('sign list') + call assert_match('^\nsign Sign1 text=x \nsign Sign2 ' . + \ 'icon=../../pixmaps/stock_vim_find_help.png .*text=xy ' . + \ 'linehl=Error texthl=Title$', a) + + let a=execute('sign list Sign1') + call assert_equal("\nsign Sign1 text=x ", a) + + " Split the window to the bottom to verify sign jump will stay in the + " current window if the buffer is displayed there. + let bn = bufnr('%') + let wn = winnr() + exe 'sign place 41 line=3 name=Sign1 buffer=' . bn + 1 + bot split + exe 'sign jump 41 buffer=' . bufnr('%') + call assert_equal('c', getline('.')) + call assert_equal(3, winnr()) + call assert_equal(bn, bufnr('%')) + call assert_notequal(wn, winnr()) + + " Create a new buffer and check that ":sign jump" switches to the old buffer. + 1 + new foo + call assert_notequal(bn, bufnr('%')) + exe 'sign jump 41 buffer=' . bn + call assert_equal(bn, bufnr('%')) + call assert_equal('c', getline('.')) + + " Redraw to make sure that screen redraw with sign gets exercised, + " with and without 'rightleft'. + if has('rightleft') + set rightleft + redraw + set norightleft + endif + redraw + + " Check that we can't change sign. + call assert_fails("sign place 40 name=Sign1 buffer=" . bufnr('%'), 'E885:') + + " Check placed signs + let a=execute('sign place') + call assert_equal("\n--- Signs ---\nSigns for [NULL]:\n" . + \ " line=3 id=41 name=Sign1 priority=10\n", a) + + " Unplace the sign and try jumping to it again should fail. + sign unplace 41 + 1 + call assert_fails("sign jump 41 buffer=" . bufnr('%'), 'E157:') + call assert_equal('a', getline('.')) + + " Unplace sign on current line. + exe 'sign place 42 line=4 name=Sign2 buffer=' . bufnr('%') + 4 + sign unplace + let a=execute('sign place') + call assert_equal("\n--- Signs ---\n", a) + + " Try again to unplace sign on current line, it should fail this time. + call assert_fails('sign unplace', 'E159:') + + " Unplace all signs. + exe 'sign place 41 line=3 name=Sign1 buffer=' . bufnr('%') + sign unplace * + let a=execute('sign place') + call assert_equal("\n--- Signs ---\n", a) + + " Place a sign without specifying the filename or buffer + sign place 77 line=9 name=Sign2 + let a=execute('sign place') + call assert_equal("\n--- Signs ---\nSigns for [NULL]:\n" . + \ " line=9 id=77 name=Sign2 priority=10\n", a) + sign unplace * + + " Check :jump with file=... + edit foo + call setline(1, ['A', 'B', 'C', 'D']) + + try + sign define Sign3 text=y texthl=DoesNotExist linehl=DoesNotExist + \ icon=doesnotexist.xpm + catch /E255:/ + " ignore error: E255: it can happens for guis. + endtry + + let fn = expand('%:p') + exe 'sign place 43 line=2 name=Sign3 file=' . fn + edit bar + call assert_notequal(fn, expand('%:p')) + exe 'sign jump 43 file=' . fn + call assert_equal('B', getline('.')) + + " Check for jumping to a sign in a hidden buffer + enew! | only! + edit foo + call setline(1, ['A', 'B', 'C', 'D']) + let fn = expand('%:p') + exe 'sign place 21 line=3 name=Sign3 file=' . fn + hide edit bar + exe 'sign jump 21 file=' . fn + call assert_equal('C', getline('.')) + + " can't define a sign with a non-printable character as text + call assert_fails("sign define Sign4 text=\e linehl=Comment", 'E239:') + call assert_fails("sign define Sign4 text=a\e linehl=Comment", 'E239:') + call assert_fails("sign define Sign4 text=\ea linehl=Comment", 'E239:') + + " Only 1 or 2 character text is allowed + call assert_fails("sign define Sign4 text=abc linehl=Comment", 'E239:') + call assert_fails("sign define Sign4 text= linehl=Comment", 'E239:') + call assert_fails("sign define Sign4 text=\\ ab linehl=Comment", 'E239:') + + " define sign with whitespace + sign define Sign4 text=\ X linehl=Comment + sign undefine Sign4 + sign define Sign4 linehl=Comment text=\ X + sign undefine Sign4 + + sign define Sign5 text=X\ linehl=Comment + sign undefine Sign5 + sign define Sign5 linehl=Comment text=X\ + sign undefine Sign5 + + " define sign with backslash + sign define Sign4 text=\\\\ linehl=Comment + sign undefine Sign4 + sign define Sign4 text=\\ linehl=Comment + sign undefine Sign4 + + " define a sign with a leading 0 in the name + sign unplace * + sign define 004 text=#> linehl=Comment + let a = execute('sign list 4') + call assert_equal("\nsign 4 text=#> linehl=Comment", a) + exe 'sign place 20 line=3 name=004 buffer=' . bufnr('') + let a = execute('sign place') + call assert_equal("\n--- Signs ---\nSigns for foo:\n" . + \ " line=3 id=20 name=4 priority=10\n", a) + exe 'sign unplace 20 buffer=' . bufnr('') + sign undefine 004 + call assert_fails('sign list 4', 'E155:') + + " After undefining the sign, we should no longer be able to place it. + sign undefine Sign1 + sign undefine Sign2 + sign undefine Sign3 + call assert_fails("sign place 41 line=3 name=Sign1 buffer=" . + \ bufnr('%'), 'E155:') +endfunc + +" Undefining placed sign is not recommended. +" Quoting :help sign +" +" :sign undefine {name} +" Deletes a previously defined sign. If signs with this {name} +" are still placed this will cause trouble. +func Test_sign_undefine_still_placed() + new foobar + sign define Sign text=x + exe 'sign place 41 line=1 name=Sign buffer=' . bufnr('%') + sign undefine Sign + + " Listing placed sign should show that sign is deleted. + let a=execute('sign place') + call assert_equal("\n--- Signs ---\nSigns for foobar:\n" . + \ " line=1 id=41 name=[Deleted] priority=10\n", a) + + sign unplace 41 + let a=execute('sign place') + call assert_equal("\n--- Signs ---\n", a) +endfunc + +func Test_sign_completion() + sign define Sign1 text=x + sign define Sign2 text=y + + call feedkeys(":sign \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"sign define jump list place undefine unplace', @:) + + call feedkeys(":sign define Sign \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"sign define Sign icon= linehl= text= texthl=', @:) + + call feedkeys(":sign define Sign linehl=Spell\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"sign define Sign linehl=SpellBad SpellCap ' . + \ 'SpellLocal SpellRare', @:) + + call writefile(['foo'], 'XsignOne') + call writefile(['bar'], 'XsignTwo') + call feedkeys(":sign define Sign icon=Xsig\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"sign define Sign icon=XsignOne XsignTwo', @:) + call delete('XsignOne') + call delete('XsignTwo') + + call feedkeys(":sign undefine \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"sign undefine Sign1 Sign2', @:) + + call feedkeys(":sign place 1 \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"sign place 1 buffer= file= group= line= name= priority=', + \ @:) + + call feedkeys(":sign place 1 name=\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"sign place 1 name=Sign1 Sign2', @:) + + call feedkeys(":sign unplace 1 \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"sign unplace 1 buffer= file= group=', @:) + + call feedkeys(":sign list \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"sign list Sign1 Sign2', @:) + + call feedkeys(":sign jump 1 \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"sign jump 1 buffer= file= group=', @:) + + sign undefine Sign1 + sign undefine Sign2 +endfunc + +func Test_sign_invalid_commands() + sign define Sign1 text=x + + call assert_fails('sign', 'E471:') + call assert_fails('sign jump', 'E471:') + call assert_fails('sign xxx', 'E160:') + call assert_fails('sign define', 'E156:') + call assert_fails('sign define Sign1 xxx', 'E475:') + call assert_fails('sign undefine', 'E156:') + call assert_fails('sign list xxx', 'E155:') + call assert_fails('sign place 1 buffer=999', 'E158:') + call assert_fails('sign place 1 name=Sign1 buffer=999', 'E158:') + call assert_fails('sign place buffer=999', 'E158:') + call assert_fails('sign jump buffer=999', 'E158:') + call assert_fails('sign jump 1 file=', 'E158:') + call assert_fails('sign jump 1 group=', 'E474:') + call assert_fails('sign jump 1 name=', 'E474:') + call assert_fails('sign jump 1 name=Sign1', 'E474:') + call assert_fails('sign jump 1 line=100', '474:') + call assert_fails('sign define Sign2 text=', 'E239:') + " Non-numeric identifier for :sign place + call assert_fails("sign place abc line=3 name=Sign1 buffer=" . bufnr(''), + \ 'E474:') + " Non-numeric identifier for :sign unplace + call assert_fails("sign unplace abc name=Sign1 buffer=" . bufnr(''), + \ 'E474:') + " Number followed by an alphabet as sign identifier for :sign place + call assert_fails("sign place 1abc line=3 name=Sign1 buffer=" . bufnr(''), + \ 'E474:') + " Number followed by an alphabet as sign identifier for :sign unplace + call assert_fails("sign unplace 2abc name=Sign1 buffer=" . bufnr(''), + \ 'E474:') + " Sign identifier and '*' for :sign unplace + call assert_fails("sign unplace 2 *", 'E474:') + " Trailing characters after buffer number for :sign place + call assert_fails("sign place 1 line=3 name=Sign1 buffer=" . + \ bufnr('%') . 'xxx', 'E488:') + " Trailing characters after buffer number for :sign unplace + call assert_fails("sign unplace 1 buffer=" . bufnr('%') . 'xxx', 'E488:') + call assert_fails("sign unplace * buffer=" . bufnr('%') . 'xxx', 'E488:') + call assert_fails("sign unplace 1 xxx", 'E474:') + call assert_fails("sign unplace * xxx", 'E474:') + call assert_fails("sign unplace xxx", 'E474:') + " Placing a sign without line number + call assert_fails("sign place name=Sign1 buffer=" . bufnr('%'), 'E474:') + " Placing a sign without sign name + call assert_fails("sign place line=10 buffer=" . bufnr('%'), 'E474:') + " Unplacing a sign with line number + call assert_fails("sign unplace 2 line=10 buffer=" . bufnr('%'), 'E474:') + " Unplacing a sign with sign name + call assert_fails("sign unplace 2 name=Sign1 buffer=" . bufnr('%'), 'E474:') + " Placing a sign without sign name + call assert_fails("sign place 2 line=3 buffer=" . bufnr('%'), 'E474:') + " Placing a sign with only sign identifier + call assert_fails("sign place 2", 'E474:') + " Placing a sign with only a name + call assert_fails("sign place abc", 'E474:') + " Placing a sign with only line number + call assert_fails("sign place 5 line=3", 'E474:') + " Placing a sign with only sign group + call assert_fails("sign place 5 group=g1", 'E474:') + call assert_fails("sign place 5 group=*", 'E474:') + " Placing a sign with only sign priority + call assert_fails("sign place 5 priority=10", 'E474:') + + sign undefine Sign1 +endfunc + +func Test_sign_delete_buffer() + new + sign define Sign text=x + let bufnr = bufnr('%') + new + exe 'bd ' . bufnr + exe 'sign place 61 line=3 name=Sign buffer=' . bufnr + call assert_fails('sign jump 61 buffer=' . bufnr, 'E934:') + sign unplace 61 + sign undefine Sign +endfunc + +" Test for Vim script functions for managing signs +func Test_sign_funcs() + " Remove all the signs + call sign_unplace('*') + call sign_undefine() + + " Tests for sign_define() + let attr = {'text' : '=>', 'linehl' : 'Search', 'texthl' : 'Error'} + call assert_equal(0, sign_define("sign1", attr)) + call assert_equal([{'name' : 'sign1', 'texthl' : 'Error', + \ 'linehl' : 'Search', 'text' : '=>'}], sign_getdefined()) + + " Define a new sign without attributes and then update it + call sign_define("sign2") + let attr = {'text' : '!!', 'linehl' : 'DiffAdd', 'texthl' : 'DiffChange', + \ 'icon' : 'sign2.ico'} + try + call sign_define("sign2", attr) + catch /E255:/ + " ignore error: E255: Couldn't read in sign data! + " This error can happen when running in gui. + endtry + call assert_equal([{'name' : 'sign2', 'texthl' : 'DiffChange', + \ 'linehl' : 'DiffAdd', 'text' : '!!', 'icon' : 'sign2.ico'}], + \ sign_getdefined("sign2")) + + " Test for a sign name with digits + call assert_equal(0, sign_define(0002, {'linehl' : 'StatusLine'})) + call assert_equal([{'name' : '2', 'linehl' : 'StatusLine'}], + \ sign_getdefined(0002)) + call sign_undefine(0002) + + " Tests for invalid arguments to sign_define() + call assert_fails('call sign_define("sign4", {"text" : "===>"})', 'E239:') + call assert_fails('call sign_define("sign5", {"text" : ""})', 'E239:') + call assert_fails('call sign_define([])', 'E730:') + call assert_fails('call sign_define("sign6", [])', 'E715:') + + " Tests for sign_getdefined() + call assert_equal([], sign_getdefined("none")) + call assert_fails('call sign_getdefined({})', 'E731:') + + " Tests for sign_place() + call writefile(repeat(["Sun is shining"], 30), "Xsign") + edit Xsign + + call assert_equal(10, sign_place(10, '', 'sign1', 'Xsign', + \ {'lnum' : 20})) + call assert_equal([{'bufnr' : bufnr(''), 'signs' : + \ [{'id' : 10, 'group' : '', 'lnum' : 20, 'name' : 'sign1', + \ 'priority' : 10}]}], sign_getplaced('Xsign')) + call assert_equal([{'bufnr' : bufnr(''), 'signs' : + \ [{'id' : 10, 'group' : '', 'lnum' : 20, 'name' : 'sign1', + \ 'priority' : 10}]}], + \ sign_getplaced('%', {'lnum' : 20})) + call assert_equal([{'bufnr' : bufnr(''), 'signs' : + \ [{'id' : 10, 'group' : '', 'lnum' : 20, 'name' : 'sign1', + \ 'priority' : 10}]}], + \ sign_getplaced('', {'id' : 10})) + + " Tests for invalid arguments to sign_place() + call assert_fails('call sign_place([], "", "mySign", 1)', 'E745:') + call assert_fails('call sign_place(5, "", "mySign", -1)', 'E158:') + call assert_fails('call sign_place(-1, "", "sign1", "Xsign", [])', + \ 'E474:') + call assert_fails('call sign_place(-1, "", "sign1", "Xsign", + \ {"lnum" : 30})', 'E474:') + call assert_fails('call sign_place(10, "", "xsign1x", "Xsign", + \ {"lnum" : 30})', 'E155:') + call assert_fails('call sign_place(10, "", "", "Xsign", + \ {"lnum" : 30})', 'E155:') + call assert_fails('call sign_place(10, "", [], "Xsign", + \ {"lnum" : 30})', 'E730:') + call assert_fails('call sign_place(5, "", "sign1", "abcxyz.xxx", + \ {"lnum" : 10})', 'E158:') + call assert_fails('call sign_place(5, "", "sign1", "@", {"lnum" : 10})', + \ 'E158:') + call assert_fails('call sign_place(5, "", "sign1", [], {"lnum" : 10})', + \ 'E158:') + call assert_fails('call sign_place(21, "", "sign1", "Xsign", + \ {"lnum" : -1})', 'E885:') + call assert_fails('call sign_place(22, "", "sign1", "Xsign", + \ {"lnum" : 0})', 'E885:') + call assert_fails('call sign_place(22, "", "sign1", "Xsign", + \ {"lnum" : []})', 'E745:') + call assert_equal(-1, sign_place(1, "*", "sign1", "Xsign", {"lnum" : 10})) + + " Tests for sign_getplaced() + call assert_equal([{'bufnr' : bufnr(''), 'signs' : + \ [{'id' : 10, 'group' : '', 'lnum' : 20, 'name' : 'sign1', + \ 'priority' : 10}]}], + \ sign_getplaced(bufnr('Xsign'))) + call assert_equal([{'bufnr' : bufnr(''), 'signs' : + \ [{'id' : 10, 'group' : '', 'lnum' : 20, 'name' : 'sign1', + \ 'priority' : 10}]}], + \ sign_getplaced()) + call assert_fails("call sign_getplaced('dummy.sign')", 'E158:') + call assert_fails('call sign_getplaced("&")', 'E158:') + call assert_fails('call sign_getplaced(-1)', 'E158:') + call assert_fails('call sign_getplaced("Xsign", [])', 'E715:') + call assert_equal([{'bufnr' : bufnr(''), 'signs' : []}], + \ sign_getplaced('Xsign', {'lnum' : 1000000})) + call assert_fails("call sign_getplaced('Xsign', {'lnum' : []})", + \ 'E745:') + call assert_equal([{'bufnr' : bufnr(''), 'signs' : []}], + \ sign_getplaced('Xsign', {'id' : 44})) + call assert_fails("call sign_getplaced('Xsign', {'id' : []})", + \ 'E745:') + + " Tests for sign_unplace() + call sign_place(20, '', 'sign2', 'Xsign', {"lnum" : 30}) + call assert_equal(0, sign_unplace('', + \ {'id' : 20, 'buffer' : 'Xsign'})) + call assert_equal(-1, sign_unplace('', + \ {'id' : 30, 'buffer' : 'Xsign'})) + call sign_place(20, '', 'sign2', 'Xsign', {"lnum" : 30}) + call assert_fails("call sign_unplace('', + \ {'id' : 20, 'buffer' : 'buffer.c'})", 'E158:') + call assert_fails("call sign_unplace('', + \ {'id' : 20, 'buffer' : '&'})", 'E158:') + call assert_fails("call sign_unplace('g1', + \ {'id' : 20, 'buffer' : 200})", 'E158:') + call assert_fails("call sign_unplace('g1', 'mySign')", 'E715:') + + " Tests for sign_undefine() + call assert_equal(0, sign_undefine("sign1")) + call assert_equal([], sign_getdefined("sign1")) + call assert_fails('call sign_undefine("none")', 'E155:') + call assert_fails('call sign_undefine([])', 'E730:') + + call delete("Xsign") + call sign_unplace('*') + call sign_undefine() + enew | only +endfunc + +" Tests for sign groups +func Test_sign_group() + enew | only + " Remove all the signs + call sign_unplace('*') + call sign_undefine() + + call writefile(repeat(["Sun is shining"], 30), "Xsign") + + let attr = {'text' : '=>', 'linehl' : 'Search', 'texthl' : 'Error'} + call assert_equal(0, sign_define("sign1", attr)) + + edit Xsign + let bnum = bufnr('%') + + " Error case + call assert_fails("call sign_place(5, [], 'sign1', 'Xsign', + \ {'lnum' : 30})", 'E730:') + + " place three signs with the same identifier. One in the global group and + " others in the named groups + call assert_equal(5, sign_place(5, '', 'sign1', 'Xsign', + \ {'lnum' : 10})) + call assert_equal(5, sign_place(5, 'g1', 'sign1', bnum, {'lnum' : 20})) + call assert_equal(5, sign_place(5, 'g2', 'sign1', bnum, {'lnum' : 30})) + + " Test for sign_getplaced() with group + let s = sign_getplaced('Xsign') + call assert_equal(1, len(s[0].signs)) + call assert_equal(s[0].signs[0].group, '') + let s = sign_getplaced(bnum, {'group' : ''}) + call assert_equal([{'id' : 5, 'group' : '', 'name' : 'sign1', 'lnum' : 10, + \ 'priority' : 10}], s[0].signs) + call assert_equal(1, len(s[0].signs)) + let s = sign_getplaced(bnum, {'group' : 'g2'}) + call assert_equal('g2', s[0].signs[0].group) + let s = sign_getplaced(bnum, {'group' : 'g3'}) + call assert_equal([], s[0].signs) + let s = sign_getplaced(bnum, {'group' : '*'}) + call assert_equal([{'id' : 5, 'group' : '', 'name' : 'sign1', 'lnum' : 10, + \ 'priority' : 10}, + \ {'id' : 5, 'group' : 'g1', 'name' : 'sign1', 'lnum' : 20, + \ 'priority' : 10}, + \ {'id' : 5, 'group' : 'g2', 'name' : 'sign1', 'lnum' : 30, + \ 'priority' : 10}], + \ s[0].signs) + + " Test for sign_getplaced() with id + let s = sign_getplaced(bnum, {'id' : 5}) + call assert_equal([{'id' : 5, 'group' : '', 'name' : 'sign1', 'lnum' : 10, + \ 'priority' : 10}], + \ s[0].signs) + let s = sign_getplaced(bnum, {'id' : 5, 'group' : 'g2'}) + call assert_equal( + \ [{'id' : 5, 'name' : 'sign1', 'lnum' : 30, 'group' : 'g2', + \ 'priority' : 10}], + \ s[0].signs) + let s = sign_getplaced(bnum, {'id' : 5, 'group' : '*'}) + call assert_equal([{'id' : 5, 'group' : '', 'name' : 'sign1', 'lnum' : 10, + \ 'priority' : 10}, + \ {'id' : 5, 'group' : 'g1', 'name' : 'sign1', 'lnum' : 20, + \ 'priority' : 10}, + \ {'id' : 5, 'group' : 'g2', 'name' : 'sign1', 'lnum' : 30, + \ 'priority' : 10}], + \ s[0].signs) + let s = sign_getplaced(bnum, {'id' : 5, 'group' : 'g3'}) + call assert_equal([], s[0].signs) + + " Test for sign_getplaced() with lnum + let s = sign_getplaced(bnum, {'lnum' : 20}) + call assert_equal([], s[0].signs) + let s = sign_getplaced(bnum, {'lnum' : 20, 'group' : 'g1'}) + call assert_equal( + \ [{'id' : 5, 'name' : 'sign1', 'lnum' : 20, 'group' : 'g1', + \ 'priority' : 10}], + \ s[0].signs) + let s = sign_getplaced(bnum, {'lnum' : 30, 'group' : '*'}) + call assert_equal( + \ [{'id' : 5, 'name' : 'sign1', 'lnum' : 30, 'group' : 'g2', + \ 'priority' : 10}], + \ s[0].signs) + let s = sign_getplaced(bnum, {'lnum' : 40, 'group' : '*'}) + call assert_equal([], s[0].signs) + + " Error case + call assert_fails("call sign_getplaced(bnum, {'group' : []})", + \ 'E730:') + + " Clear the sign in global group + call sign_unplace('', {'id' : 5, 'buffer' : bnum}) + let s = sign_getplaced(bnum, {'group' : '*'}) + call assert_equal([ + \ {'id' : 5, 'name' : 'sign1', 'lnum' : 20, 'group' : 'g1', + \ 'priority' : 10}, + \ {'id' : 5, 'name' : 'sign1', 'lnum' : 30, 'group' : 'g2', + \ 'priority' : 10}], + \ s[0].signs) + + " Clear the sign in one of the groups + call sign_unplace('g1', {'buffer' : 'Xsign'}) + let s = sign_getplaced(bnum, {'group' : '*'}) + call assert_equal([ + \ {'id' : 5, 'name' : 'sign1', 'lnum' : 30, 'group' : 'g2', + \ 'priority' : 10}], + \ s[0].signs) + + " Clear all the signs from the buffer + call sign_unplace('*', {'buffer' : bnum}) + call assert_equal([], sign_getplaced(bnum, {'group' : '*'})[0].signs) + + " Clear sign across groups using an identifier + call sign_place(25, '', 'sign1', bnum, {'lnum' : 10}) + call sign_place(25, 'g1', 'sign1', bnum, {'lnum' : 11}) + call sign_place(25, 'g2', 'sign1', bnum, {'lnum' : 12}) + call assert_equal(0, sign_unplace('*', {'id' : 25})) + call assert_equal([], sign_getplaced(bnum, {'group' : '*'})[0].signs) + + " Error case + call assert_fails("call sign_unplace([])", 'E474:') + + " Place a sign in the global group and try to delete it using a group + call assert_equal(5, sign_place(5, '', 'sign1', bnum, {'lnum' : 10})) + call assert_equal(-1, sign_unplace('g1', {'id' : 5})) + + " Place signs in multiple groups and delete all the signs in one of the + " group + call assert_equal(5, sign_place(5, '', 'sign1', bnum, {'lnum' : 10})) + call assert_equal(6, sign_place(6, '', 'sign1', bnum, {'lnum' : 11})) + call assert_equal(5, sign_place(5, 'g1', 'sign1', bnum, {'lnum' : 10})) + call assert_equal(5, sign_place(5, 'g2', 'sign1', bnum, {'lnum' : 10})) + call assert_equal(6, sign_place(6, 'g1', 'sign1', bnum, {'lnum' : 11})) + call assert_equal(6, sign_place(6, 'g2', 'sign1', bnum, {'lnum' : 11})) + call assert_equal(0, sign_unplace('g1')) + let s = sign_getplaced(bnum, {'group' : 'g1'}) + call assert_equal([], s[0].signs) + let s = sign_getplaced(bnum) + call assert_equal(2, len(s[0].signs)) + let s = sign_getplaced(bnum, {'group' : 'g2'}) + call assert_equal('g2', s[0].signs[0].group) + call assert_equal(0, sign_unplace('', {'id' : 5})) + call assert_equal(0, sign_unplace('', {'id' : 6})) + let s = sign_getplaced(bnum, {'group' : 'g2'}) + call assert_equal('g2', s[0].signs[0].group) + call assert_equal(0, sign_unplace('', {'buffer' : bnum})) + + call sign_unplace('*') + + " Test for :sign command and groups + sign place 5 line=10 name=sign1 file=Xsign + sign place 5 group=g1 line=10 name=sign1 file=Xsign + sign place 5 group=g2 line=10 name=sign1 file=Xsign + + " Tests for the ':sign place' command + + " :sign place file={fname} + let a = execute('sign place file=Xsign') + call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" . + \ " line=10 id=5 name=sign1 priority=10\n", a) + + " :sign place group={group} file={fname} + let a = execute('sign place group=g2 file=Xsign') + call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" . + \ " line=10 id=5 group=g2 name=sign1 priority=10\n", a) + + " :sign place group=* file={fname} + let a = execute('sign place group=* file=Xsign') + call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" . + \ " line=10 id=5 group=g2 name=sign1 priority=10\n" . + \ " line=10 id=5 group=g1 name=sign1 priority=10\n" . + \ " line=10 id=5 name=sign1 priority=10\n", a) + + " Error case: non-existing group + let a = execute('sign place group=xyz file=Xsign') + call assert_equal("\n--- Signs ---\nSigns for Xsign:\n", a) + + call sign_unplace('*') + let bnum = bufnr('Xsign') + exe 'sign place 5 line=10 name=sign1 buffer=' . bnum + exe 'sign place 5 group=g1 line=11 name=sign1 buffer=' . bnum + exe 'sign place 5 group=g2 line=12 name=sign1 buffer=' . bnum + + " :sign place buffer={fname} + let a = execute('sign place buffer=' . bnum) + call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" . + \ " line=10 id=5 name=sign1 priority=10\n", a) + + " :sign place group={group} buffer={fname} + let a = execute('sign place group=g2 buffer=' . bnum) + call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" . + \ " line=12 id=5 group=g2 name=sign1 priority=10\n", a) + + " :sign place group=* buffer={fname} + let a = execute('sign place group=* buffer=' . bnum) + call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" . + \ " line=10 id=5 name=sign1 priority=10\n" . + \ " line=11 id=5 group=g1 name=sign1 priority=10\n" . + \ " line=12 id=5 group=g2 name=sign1 priority=10\n", a) + + " Error case: non-existing group + let a = execute('sign place group=xyz buffer=' . bnum) + call assert_equal("\n--- Signs ---\nSigns for Xsign:\n", a) + + " :sign place + let a = execute('sign place') + call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" . + \ " line=10 id=5 name=sign1 priority=10\n", a) + + " Place signs in more than one buffer and list the signs + split foo + set buftype=nofile + sign place 25 line=76 name=sign1 priority=99 file=foo + let a = execute('sign place') + call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" . + \ " line=10 id=5 name=sign1 priority=10\n" . + \ "Signs for foo:\n" . + \ " line=76 id=25 name=sign1 priority=99\n", a) + close + bwipe foo + + " :sign place group={group} + let a = execute('sign place group=g1') + call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" . + \ " line=11 id=5 group=g1 name=sign1 priority=10\n", a) + + " :sign place group=* + let a = execute('sign place group=*') + call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" . + \ " line=10 id=5 name=sign1 priority=10\n" . + \ " line=11 id=5 group=g1 name=sign1 priority=10\n" . + \ " line=12 id=5 group=g2 name=sign1 priority=10\n", a) + + " Test for ':sign jump' command with groups + sign jump 5 group=g1 file=Xsign + call assert_equal(11, line('.')) + call assert_equal('Xsign', bufname('')) + sign jump 5 group=g2 file=Xsign + call assert_equal(12, line('.')) + + " Test for :sign jump command without the filename or buffer + sign jump 5 + call assert_equal(10, line('.')) + sign jump 5 group=g1 + call assert_equal(11, line('.')) + + " Error cases + call assert_fails("sign place 3 group= name=sign1 buffer=" . bnum, 'E474:') + + call delete("Xsign") + call sign_unplace('*') + call sign_undefine() + enew | only +endfunc + +" Place signs used for ":sign unplace" command test +func Place_signs_for_test() + call sign_unplace('*') + + sign place 3 line=10 name=sign1 file=Xsign1 + sign place 3 group=g1 line=11 name=sign1 file=Xsign1 + sign place 3 group=g2 line=12 name=sign1 file=Xsign1 + sign place 4 line=15 name=sign1 file=Xsign1 + sign place 4 group=g1 line=16 name=sign1 file=Xsign1 + sign place 4 group=g2 line=17 name=sign1 file=Xsign1 + sign place 5 line=20 name=sign1 file=Xsign2 + sign place 5 group=g1 line=21 name=sign1 file=Xsign2 + sign place 5 group=g2 line=22 name=sign1 file=Xsign2 + sign place 6 line=25 name=sign1 file=Xsign2 + sign place 6 group=g1 line=26 name=sign1 file=Xsign2 + sign place 6 group=g2 line=27 name=sign1 file=Xsign2 +endfunc + +" Place multiple signs in a single line for test +func Place_signs_at_line_for_test() + call sign_unplace('*') + sign place 3 line=13 name=sign1 file=Xsign1 + sign place 3 group=g1 line=13 name=sign1 file=Xsign1 + sign place 3 group=g2 line=13 name=sign1 file=Xsign1 + sign place 4 line=13 name=sign1 file=Xsign1 + sign place 4 group=g1 line=13 name=sign1 file=Xsign1 + sign place 4 group=g2 line=13 name=sign1 file=Xsign1 +endfunc + +" Tests for the ':sign unplace' command +func Test_sign_unplace() + enew | only + " Remove all the signs + call sign_unplace('*') + call sign_undefine() + + " Create two files and define signs + call writefile(repeat(["Sun is shining"], 30), "Xsign1") + call writefile(repeat(["It is beautiful"], 30), "Xsign2") + + let attr = {'text' : '=>', 'linehl' : 'Search', 'texthl' : 'Error'} + call sign_define("sign1", attr) + + edit Xsign1 + let bnum1 = bufnr('%') + split Xsign2 + let bnum2 = bufnr('%') + + let signs1 = [{'id' : 3, 'name' : 'sign1', 'lnum' : 10, 'group' : '', + \ 'priority' : 10}, + \ {'id' : 3, 'name' : 'sign1', 'lnum' : 11, 'group' : 'g1', + \ 'priority' : 10}, + \ {'id' : 3, 'name' : 'sign1', 'lnum' : 12, 'group' : 'g2', + \ 'priority' : 10}, + \ {'id' : 4, 'name' : 'sign1', 'lnum' : 15, 'group' : '', + \ 'priority' : 10}, + \ {'id' : 4, 'name' : 'sign1', 'lnum' : 16, 'group' : 'g1', + \ 'priority' : 10}, + \ {'id' : 4, 'name' : 'sign1', 'lnum' : 17, 'group' : 'g2', + \ 'priority' : 10},] + let signs2 = [{'id' : 5, 'name' : 'sign1', 'lnum' : 20, 'group' : '', + \ 'priority' : 10}, + \ {'id' : 5, 'name' : 'sign1', 'lnum' : 21, 'group' : 'g1', + \ 'priority' : 10}, + \ {'id' : 5, 'name' : 'sign1', 'lnum' : 22, 'group' : 'g2', + \ 'priority' : 10}, + \ {'id' : 6, 'name' : 'sign1', 'lnum' : 25, 'group' : '', + \ 'priority' : 10}, + \ {'id' : 6, 'name' : 'sign1', 'lnum' : 26, 'group' : 'g1', + \ 'priority' : 10}, + \ {'id' : 6, 'name' : 'sign1', 'lnum' : 27, 'group' : 'g2', + \ 'priority' : 10},] + + " Test for :sign unplace {id} file={fname} + call Place_signs_for_test() + sign unplace 3 file=Xsign1 + sign unplace 6 file=Xsign2 + call assert_equal( + \ filter(copy(signs1), + \ {idx, val -> val.id != 3 || val.group != ''}), + \ sign_getplaced('Xsign1', {'group' : '*'})[0].signs) + call assert_equal( + \ filter(copy(signs2), + \ {idx, val -> val.id != 6 || val.group != ''}), + \ sign_getplaced('Xsign2', {'group' : '*'})[0].signs) + + " Test for :sign unplace {id} group={group} file={fname} + call Place_signs_for_test() + sign unplace 4 group=g1 file=Xsign1 + sign unplace 5 group=g2 file=Xsign2 + call assert_equal( + \ filter(copy(signs1), + \ {idx, val -> val.id != 4 || val.group != 'g1'}), + \ sign_getplaced('Xsign1', {'group' : '*'})[0].signs) + call assert_equal( + \ filter(copy(signs2), + \ {idx, val -> val.id != 5 || val.group != 'g2'}), + \ sign_getplaced('Xsign2', {'group' : '*'})[0].signs) + + " Test for :sign unplace {id} group=* file={fname} + call Place_signs_for_test() + sign unplace 3 group=* file=Xsign1 + sign unplace 6 group=* file=Xsign2 + call assert_equal( + \ filter(copy(signs1), + \ {idx, val -> val.id != 3}), + \ sign_getplaced('Xsign1', {'group' : '*'})[0].signs) + call assert_equal( + \ filter(copy(signs2), + \ {idx, val -> val.id != 6}), + \ sign_getplaced('Xsign2', {'group' : '*'})[0].signs) + + " Test for :sign unplace * file={fname} + call Place_signs_for_test() + sign unplace * file=Xsign1 + call assert_equal( + \ filter(copy(signs1), + \ {idx, val -> val.group != ''}), + \ sign_getplaced('Xsign1', {'group' : '*'})[0].signs) + call assert_equal(signs2, sign_getplaced('Xsign2', {'group' : '*'})[0].signs) + + " Test for :sign unplace * group={group} file={fname} + call Place_signs_for_test() + sign unplace * group=g1 file=Xsign1 + sign unplace * group=g2 file=Xsign2 + call assert_equal( + \ filter(copy(signs1), + \ {idx, val -> val.group != 'g1'}), + \ sign_getplaced('Xsign1', {'group' : '*'})[0].signs) + call assert_equal( + \ filter(copy(signs2), + \ {idx, val -> val.group != 'g2'}), + \ sign_getplaced('Xsign2', {'group' : '*'})[0].signs) + + " Test for :sign unplace * group=* file={fname} + call Place_signs_for_test() + sign unplace * group=* file=Xsign2 + call assert_equal(signs1, sign_getplaced('Xsign1', {'group' : '*'})[0].signs) + call assert_equal([], sign_getplaced('Xsign2', {'group' : '*'})[0].signs) + + " Test for :sign unplace {id} buffer={nr} + call Place_signs_for_test() + exe 'sign unplace 3 buffer=' . bnum1 + exe 'sign unplace 6 buffer=' . bnum2 + call assert_equal( + \ filter(copy(signs1), + \ {idx, val -> val.id != 3 || val.group != ''}), + \ sign_getplaced(bnum1, {'group' : '*'})[0].signs) + call assert_equal( + \ filter(copy(signs2), + \ {idx, val -> val.id != 6 || val.group != ''}), + \ sign_getplaced(bnum2, {'group' : '*'})[0].signs) + + " Test for :sign unplace {id} group={group} buffer={nr} + call Place_signs_for_test() + exe 'sign unplace 4 group=g1 buffer=' . bnum1 + exe 'sign unplace 5 group=g2 buffer=' . bnum2 + call assert_equal( + \ filter(copy(signs1), + \ {idx, val -> val.id != 4 || val.group != 'g1'}), + \ sign_getplaced(bnum1, {'group' : '*'})[0].signs) + call assert_equal( + \ filter(copy(signs2), + \ {idx, val -> val.id != 5 || val.group != 'g2'}), + \ sign_getplaced(bnum2, {'group' : '*'})[0].signs) + + " Test for :sign unplace {id} group=* buffer={nr} + call Place_signs_for_test() + exe 'sign unplace 3 group=* buffer=' . bnum1 + exe 'sign unplace 6 group=* buffer=' . bnum2 + call assert_equal( + \ filter(copy(signs1), + \ {idx, val -> val.id != 3}), + \ sign_getplaced(bnum1, {'group' : '*'})[0].signs) + call assert_equal( + \ filter(copy(signs2), + \ {idx, val -> val.id != 6}), + \ sign_getplaced(bnum2, {'group' : '*'})[0].signs) + + " Test for :sign unplace * buffer={nr} + call Place_signs_for_test() + exe 'sign unplace * buffer=' . bnum1 + call assert_equal( + \ filter(copy(signs1), + \ {idx, val -> val.group != ''}), + \ sign_getplaced(bnum1, {'group' : '*'})[0].signs) + call assert_equal(signs2, sign_getplaced(bnum2, {'group' : '*'})[0].signs) + + " Test for :sign unplace * group={group} buffer={nr} + call Place_signs_for_test() + exe 'sign unplace * group=g1 buffer=' . bnum1 + exe 'sign unplace * group=g2 buffer=' . bnum2 + call assert_equal( + \ filter(copy(signs1), + \ {idx, val -> val.group != 'g1'}), + \ sign_getplaced(bnum1, {'group' : '*'})[0].signs) + call assert_equal( + \ filter(copy(signs2), + \ {idx, val -> val.group != 'g2'}), + \ sign_getplaced(bnum2, {'group' : '*'})[0].signs) + + " Test for :sign unplace * group=* buffer={nr} + call Place_signs_for_test() + exe 'sign unplace * group=* buffer=' . bnum2 + call assert_equal(signs1, sign_getplaced(bnum1, {'group' : '*'})[0].signs) + call assert_equal([], sign_getplaced(bnum2, {'group' : '*'})[0].signs) + + " Test for :sign unplace {id} + call Place_signs_for_test() + sign unplace 4 + sign unplace 6 + call assert_equal( + \ filter(copy(signs1), + \ {idx, val -> val.id != 4 || val.group != ''}), + \ sign_getplaced('Xsign1', {'group' : '*'})[0].signs) + call assert_equal( + \ filter(copy(signs2), + \ {idx, val -> val.id != 6 || val.group != ''}), + \ sign_getplaced('Xsign2', {'group' : '*'})[0].signs) + + " Test for :sign unplace {id} group={group} + call Place_signs_for_test() + sign unplace 4 group=g1 + sign unplace 6 group=g2 + call assert_equal( + \ filter(copy(signs1), + \ {idx, val -> val.id != 4 || val.group != 'g1'}), + \ sign_getplaced('Xsign1', {'group' : '*'})[0].signs) + call assert_equal( + \ filter(copy(signs2), + \ {idx, val -> val.id != 6 || val.group != 'g2'}), + \ sign_getplaced('Xsign2', {'group' : '*'})[0].signs) + + " Test for :sign unplace {id} group=* + call Place_signs_for_test() + sign unplace 3 group=* + sign unplace 5 group=* + call assert_equal( + \ filter(copy(signs1), + \ {idx, val -> val.id != 3}), + \ sign_getplaced('Xsign1', {'group' : '*'})[0].signs) + call assert_equal( + \ filter(copy(signs2), + \ {idx, val -> val.id != 5}), + \ sign_getplaced('Xsign2', {'group' : '*'})[0].signs) + + " Test for :sign unplace * + call Place_signs_for_test() + sign unplace * + call assert_equal( + \ filter(copy(signs1), + \ {idx, val -> val.group != ''}), + \ sign_getplaced('Xsign1', {'group' : '*'})[0].signs) + call assert_equal( + \ filter(copy(signs2), + \ {idx, val -> val.group != ''}), + \ sign_getplaced('Xsign2', {'group' : '*'})[0].signs) + + " Test for :sign unplace * group={group} + call Place_signs_for_test() + sign unplace * group=g1 + call assert_equal( + \ filter(copy(signs1), + \ {idx, val -> val.group != 'g1'}), + \ sign_getplaced('Xsign1', {'group' : '*'})[0].signs) + call assert_equal( + \ filter(copy(signs2), + \ {idx, val -> val.group != 'g1'}), + \ sign_getplaced('Xsign2', {'group' : '*'})[0].signs) + + " Test for :sign unplace * group=* + call Place_signs_for_test() + sign unplace * group=* + call assert_equal([], sign_getplaced('Xsign1', {'group' : '*'})[0].signs) + call assert_equal([], sign_getplaced('Xsign2', {'group' : '*'})[0].signs) + + " Negative test cases + call Place_signs_for_test() + sign unplace 3 group=xy file=Xsign1 + sign unplace * group=xy file=Xsign1 + silent! sign unplace * group=* file=FileNotPresent + call assert_equal(signs1, sign_getplaced('Xsign1', {'group' : '*'})[0].signs) + call assert_equal(signs2, sign_getplaced('Xsign2', {'group' : '*'})[0].signs) + + " Tests for removing sign at the current cursor position + + " Test for ':sign unplace' + let signs1 = [{'id' : 4, 'name' : 'sign1', 'lnum' : 13, 'group' : 'g2', + \ 'priority' : 10}, + \ {'id' : 4, 'name' : 'sign1', 'lnum' : 13, 'group' : 'g1', + \ 'priority' : 10}, + \ {'id' : 4, 'name' : 'sign1', 'lnum' : 13, 'group' : '', + \ 'priority' : 10}, + \ {'id' : 3, 'name' : 'sign1', 'lnum' : 13, 'group' : 'g2', + \ 'priority' : 10}, + \ {'id' : 3, 'name' : 'sign1', 'lnum' : 13, 'group' : 'g1', + \ 'priority' : 10}, + \ {'id' : 3, 'name' : 'sign1', 'lnum' : 13, 'group' : '', + \ 'priority' : 10},] + exe bufwinnr('Xsign1') . 'wincmd w' + call cursor(13, 1) + + " Should remove only one sign in the global group + call Place_signs_at_line_for_test() + sign unplace + call assert_equal( + \ filter(copy(signs1), + \ {idx, val -> val.id != 4 || val.group != ''}), + \ sign_getplaced('Xsign1', {'group' : '*'})[0].signs) + " Should remove the second sign in the global group + sign unplace + call assert_equal( + \ filter(copy(signs1), + \ {idx, val -> val.group != ''}), + \ sign_getplaced('Xsign1', {'group' : '*'})[0].signs) + + " Test for ':sign unplace group={group}' + call Place_signs_at_line_for_test() + " Should remove only one sign in group g1 + sign unplace group=g1 + call assert_equal( + \ filter(copy(signs1), + \ {idx, val -> val.id != 4 || val.group != 'g1'}), + \ sign_getplaced('Xsign1', {'group' : '*'})[0].signs) + sign unplace group=g2 + call assert_equal( + \ filter(copy(signs1), + \ {idx, val -> val.id != 4 || val.group == ''}), + \ sign_getplaced('Xsign1', {'group' : '*'})[0].signs) + + " Test for ':sign unplace group=*' + call Place_signs_at_line_for_test() + sign unplace group=* + sign unplace group=* + sign unplace group=* + call assert_equal( + \ filter(copy(signs1), + \ {idx, val -> val.id != 4}), + \ sign_getplaced('Xsign1', {'group' : '*'})[0].signs) + sign unplace group=* + sign unplace group=* + sign unplace group=* + call assert_equal([], sign_getplaced('Xsign1', {'group' : '*'})[0].signs) + + call sign_unplace('*') + call sign_undefine() + enew | only + call delete("Xsign1") + call delete("Xsign2") +endfunc + +" Tests for auto-generating the sign identifier +func Test_sign_id_autogen() + enew | only + call sign_unplace('*') + call sign_undefine() + + let attr = {'text' : '=>', 'linehl' : 'Search', 'texthl' : 'Error'} + call assert_equal(0, sign_define("sign1", attr)) + + call writefile(repeat(["Sun is shining"], 30), "Xsign") + edit Xsign + + call assert_equal(1, sign_place(0, '', 'sign1', 'Xsign', + \ {'lnum' : 10})) + call assert_equal(2, sign_place(2, '', 'sign1', 'Xsign', + \ {'lnum' : 12})) + call assert_equal(3, sign_place(0, '', 'sign1', 'Xsign', + \ {'lnum' : 14})) + call sign_unplace('', {'buffer' : 'Xsign', 'id' : 2}) + call assert_equal(4, sign_place(0, '', 'sign1', 'Xsign', + \ {'lnum' : 12})) + + call assert_equal(1, sign_place(0, 'g1', 'sign1', 'Xsign', + \ {'lnum' : 11})) + " Check for the next generated sign id in this group + call assert_equal(2, sign_place(0, 'g1', 'sign1', 'Xsign', + \ {'lnum' : 12})) + call assert_equal(0, sign_unplace('g1', {'id' : 1})) + call assert_equal(10, + \ sign_getplaced('Xsign', {'id' : 1})[0].signs[0].lnum) + + call delete("Xsign") + call sign_unplace('*') + call sign_undefine() + enew | only +endfunc + +" Test for sign priority +func Test_sign_priority() + enew | only + call sign_unplace('*') + call sign_undefine() + + let attr = {'text' : '=>', 'linehl' : 'Search', 'texthl' : 'Search'} + call sign_define("sign1", attr) + call sign_define("sign2", attr) + call sign_define("sign3", attr) + + " Place three signs with different priority in the same line + call writefile(repeat(["Sun is shining"], 30), "Xsign") + edit Xsign + + call sign_place(1, 'g1', 'sign1', 'Xsign', + \ {'lnum' : 11, 'priority' : 50}) + call sign_place(2, 'g2', 'sign2', 'Xsign', + \ {'lnum' : 11, 'priority' : 100}) + call sign_place(3, '', 'sign3', 'Xsign', {'lnum' : 11}) + let s = sign_getplaced('Xsign', {'group' : '*'}) + call assert_equal([ + \ {'id' : 2, 'name' : 'sign2', 'lnum' : 11, 'group' : 'g2', + \ 'priority' : 100}, + \ {'id' : 1, 'name' : 'sign1', 'lnum' : 11, 'group' : 'g1', + \ 'priority' : 50}, + \ {'id' : 3, 'name' : 'sign3', 'lnum' : 11, 'group' : '', + \ 'priority' : 10}], + \ s[0].signs) + + " Error case + call assert_fails("call sign_place(1, 'g1', 'sign1', 'Xsign', + \ [])", 'E715:') + call assert_fails("call sign_place(1, 'g1', 'sign1', 'Xsign', + \ {'priority' : []})", 'E745:') + call sign_unplace('*') + + " Tests for the :sign place command with priority + sign place 5 line=10 name=sign1 priority=30 file=Xsign + sign place 5 group=g1 line=10 name=sign1 priority=20 file=Xsign + sign place 5 group=g2 line=10 name=sign1 priority=25 file=Xsign + let a = execute('sign place group=*') + call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" . + \ " line=10 id=5 name=sign1 priority=30\n" . + \ " line=10 id=5 group=g2 name=sign1 priority=25\n" . + \ " line=10 id=5 group=g1 name=sign1 priority=20\n", a) + + " Test for :sign place group={group} + let a = execute('sign place group=g1') + call assert_equal("\n--- Signs ---\nSigns for Xsign:\n" . + \ " line=10 id=5 group=g1 name=sign1 priority=20\n", a) + + call sign_unplace('*') + call sign_undefine() + enew | only + call delete("Xsign") +endfunc + +" Tests for memory allocation failures in sign functions +func Test_sign_memfailures() + call writefile(repeat(["Sun is shining"], 30), "Xsign") + edit Xsign + + call test_alloc_fail(GetAllocId('sign_getdefined'), 0, 0) + call assert_fails('call sign_getdefined("sign1")', 'E342:') + call test_alloc_fail(GetAllocId('sign_getplaced'), 0, 0) + call assert_fails('call sign_getplaced("Xsign")', 'E342:') + call test_alloc_fail(GetAllocId('sign_define_by_name'), 0, 0) + let attr = {'text' : '=>', 'linehl' : 'Search', 'texthl' : 'Error'} + call assert_fails('call sign_define("sign1", attr)', 'E342:') + + let attr = {'text' : '=>', 'linehl' : 'Search', 'texthl' : 'Error'} + call sign_define("sign1", attr) + call test_alloc_fail(GetAllocId('sign_getlist'), 0, 0) + call assert_fails('call sign_getdefined("sign1")', 'E342:') + + call sign_place(3, 'g1', 'sign1', 'Xsign', {'lnum' : 10}) + call test_alloc_fail(GetAllocId('sign_getplaced_dict'), 0, 0) + call assert_fails('call sign_getplaced("Xsign")', 'E342:') + call test_alloc_fail(GetAllocId('sign_getplaced_list'), 0, 0) + call assert_fails('call sign_getplaced("Xsign")', 'E342:') + + call test_alloc_fail(GetAllocId('insert_sign'), 0, 0) + call assert_fails('call sign_place(4, "g1", "sign1", "Xsign", {"lnum" : 11})', + \ 'E342:') + + call test_alloc_fail(GetAllocId('sign_getinfo'), 0, 0) + call assert_fails('call getbufinfo()', 'E342:') + call sign_place(4, 'g1', 'sign1', 'Xsign', {'lnum' : 11}) + call test_alloc_fail(GetAllocId('sign_getinfo'), 0, 0) + call assert_fails('let binfo=getbufinfo("Xsign")', 'E342:') + call assert_equal([{'lnum': 11, 'id': 4, 'name': 'sign1', + \ 'priority': 10, 'group': 'g1'}], binfo[0].signs) + + call sign_unplace('*') + call sign_undefine() + enew | only + call delete("Xsign") +endfunc + +" Test for auto-adjusting the line number of a placed sign. +func Test_sign_lnum_adjust() + enew! | only! + + sign define sign1 text=#> linehl=Comment + call setline(1, ['A', 'B', 'C', 'D', 'E']) + exe 'sign place 5 line=3 name=sign1 buffer=' . bufnr('') + let l = sign_getplaced(bufnr('')) + call assert_equal(3, l[0].signs[0].lnum) + + " Add some lines before the sign and check the sign line number + call append(2, ['BA', 'BB', 'BC']) + let l = sign_getplaced(bufnr('')) + call assert_equal(6, l[0].signs[0].lnum) + + " Delete some lines before the sign and check the sign line number + call deletebufline('%', 1, 2) + let l = sign_getplaced(bufnr('')) + call assert_equal(4, l[0].signs[0].lnum) + + " Insert some lines after the sign and check the sign line number + call append(5, ['DA', 'DB']) + let l = sign_getplaced(bufnr('')) + call assert_equal(4, l[0].signs[0].lnum) + + " Delete some lines after the sign and check the sign line number + call deletebufline('', 6, 7) + let l = sign_getplaced(bufnr('')) + call assert_equal(4, l[0].signs[0].lnum) + + " Break the undo. Otherwise the undo operation below will undo all the + " changes made by this function. + let &undolevels=&undolevels + + " Delete the line with the sign + call deletebufline('', 4) + let l = sign_getplaced(bufnr('')) + call assert_equal(4, l[0].signs[0].lnum) + + " Undo the delete operation + undo + let l = sign_getplaced(bufnr('')) + call assert_equal(5, l[0].signs[0].lnum) + + " Break the undo + let &undolevels=&undolevels + + " Delete few lines at the end of the buffer including the line with the sign + " Sign line number should not change (as it is placed outside of the buffer) + call deletebufline('', 3, 6) + let l = sign_getplaced(bufnr('')) + call assert_equal(5, l[0].signs[0].lnum) + + " Undo the delete operation. Sign should be restored to the previous line + undo + let l = sign_getplaced(bufnr('')) + call assert_equal(5, l[0].signs[0].lnum) + + sign unplace * group=* + sign undefine sign1 + enew! +endfunc + +" Test for changing the type of a placed sign +func Test_sign_change_type() + enew! | only! + + sign define sign1 text=#> linehl=Comment + sign define sign2 text=@@ linehl=Comment + + call setline(1, ['A', 'B', 'C', 'D']) + exe 'sign place 4 line=3 name=sign1 buffer=' . bufnr('') + let l = sign_getplaced(bufnr('')) + call assert_equal('sign1', l[0].signs[0].name) + exe 'sign place 4 name=sign2 buffer=' . bufnr('') + let l = sign_getplaced(bufnr('')) + call assert_equal('sign2', l[0].signs[0].name) + call sign_place(4, '', 'sign1', '') + let l = sign_getplaced(bufnr('')) + call assert_equal('sign1', l[0].signs[0].name) + + exe 'sign place 4 group=g1 line=4 name=sign1 buffer=' . bufnr('') + let l = sign_getplaced(bufnr(''), {'group' : 'g1'}) + call assert_equal('sign1', l[0].signs[0].name) + exe 'sign place 4 group=g1 name=sign2 buffer=' . bufnr('') + let l = sign_getplaced(bufnr(''), {'group' : 'g1'}) + call assert_equal('sign2', l[0].signs[0].name) + call sign_place(4, 'g1', 'sign1', '') + let l = sign_getplaced(bufnr(''), {'group' : 'g1'}) + call assert_equal('sign1', l[0].signs[0].name) + + sign unplace * group=* + sign undefine sign1 + sign undefine sign2 + enew! +endfunc + +" Test for the sign_jump() function +func Test_sign_jump_func() + enew! | only! + + sign define sign1 text=#> linehl=Comment + + edit foo + set buftype=nofile + call setline(1, ['A', 'B', 'C', 'D', 'E']) + call sign_place(5, '', 'sign1', '', {'lnum' : 2}) + call sign_place(5, 'g1', 'sign1', '', {'lnum' : 3}) + call sign_place(6, '', 'sign1', '', {'lnum' : 4}) + call sign_place(6, 'g1', 'sign1', '', {'lnum' : 5}) + split bar + set buftype=nofile + call setline(1, ['P', 'Q', 'R', 'S', 'T']) + call sign_place(5, '', 'sign1', '', {'lnum' : 2}) + call sign_place(5, 'g1', 'sign1', '', {'lnum' : 3}) + call sign_place(6, '', 'sign1', '', {'lnum' : 4}) + call sign_place(6, 'g1', 'sign1', '', {'lnum' : 5}) + + let r = sign_jump(5, '', 'foo') + call assert_equal(2, r) + call assert_equal(2, line('.')) + let r = sign_jump(6, 'g1', 'foo') + call assert_equal(5, r) + call assert_equal(5, line('.')) + let r = sign_jump(5, '', 'bar') + call assert_equal(2, r) + call assert_equal(2, line('.')) + + " Error cases + call assert_fails("call sign_jump(99, '', 'bar')", 'E157:') + call assert_fails("call sign_jump(0, '', 'foo')", 'E474:') + call assert_fails("call sign_jump(5, 'g5', 'foo')", 'E157:') + call assert_fails('call sign_jump([], "", "foo")', 'E745:') + call assert_fails('call sign_jump(2, [], "foo")', 'E730:') + call assert_fails('call sign_jump(2, "", {})', 'E158:') + call assert_fails('call sign_jump(2, "", "baz")', 'E158:') + + sign unplace * group=* + sign undefine sign1 + enew! | only! +endfunc diff --git a/src/testdir/test_smartindent.vim b/src/testdir/test_smartindent.vim new file mode 100644 index 0000000..e89ad19 --- /dev/null +++ b/src/testdir/test_smartindent.vim @@ -0,0 +1,41 @@ +" Tests for smartindent + +" Tests for not doing smart indenting when it isn't set. +func Test_nosmartindent() + new + call append(0, [" some test text", + \ " test text", + \ "test text", + \ " test text"]) + set nocindent nosmartindent autoindent + exe "normal! gg/some\<CR>" + exe "normal! 2cc#test\<Esc>" + call assert_equal(" #test", getline(1)) + enew! | close +endfunc + +func MyIndent() +endfunc + +" When 'indentexpr' is set, setting 'si' has no effect. +func Test_smartindent_has_no_effect() + new + exe "normal! i\<Tab>one\<Esc>" + set noautoindent + set smartindent + set indentexpr= + exe "normal! Gotwo\<Esc>" + call assert_equal("\ttwo", getline("$")) + + set indentexpr=MyIndent + exe "normal! Gothree\<Esc>" + call assert_equal("three", getline("$")) + + delfunction! MyIndent + set autoindent& + set smartindent& + set indentexpr& + bwipe! +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_sort.vim b/src/testdir/test_sort.vim new file mode 100644 index 0000000..14d008a --- /dev/null +++ b/src/testdir/test_sort.vim @@ -0,0 +1,1253 @@ +" Tests for the "sort()" function and for the ":sort" command. + +func Compare1(a, b) abort + call sort(range(3), 'Compare2') + return a:a - a:b +endfunc + +func Compare2(a, b) abort + return a:a - a:b +endfunc + +func Test_sort_strings() + " numbers compared as strings + call assert_equal([1, 2, 3], sort([3, 2, 1])) + call assert_equal([13, 28, 3], sort([3, 28, 13])) +endfunc + +func Test_sort_numeric() + call assert_equal([1, 2, 3], sort([3, 2, 1], 'n')) + call assert_equal([3, 13, 28], sort([13, 28, 3], 'n')) + " strings are not sorted + call assert_equal(['13', '28', '3'], sort(['13', '28', '3'], 'n')) +endfunc + +func Test_sort_numbers() + call assert_equal([3, 13, 28], sort([13, 28, 3], 'N')) + call assert_equal(['3', '13', '28'], sort(['13', '28', '3'], 'N')) +endfunc + +func Test_sort_float() + call assert_equal([0.28, 3, 13.5], sort([13.5, 0.28, 3], 'f')) +endfunc + +func Test_sort_nested() + " test ability to call sort() from a compare function + call assert_equal([1, 3, 5], sort([3, 1, 5], 'Compare1')) +endfunc + +func Test_sort_default() + " docs say omitted, empty or zero argument sorts on string representation. + call assert_equal(['2', 'A', 'AA', 'a', 1, 3.3], sort([3.3, 1, "2", "A", "a", "AA"])) + call assert_equal(['2', 'A', 'AA', 'a', 1, 3.3], sort([3.3, 1, "2", "A", "a", "AA"], '')) + call assert_equal(['2', 'A', 'AA', 'a', 1, 3.3], sort([3.3, 1, "2", "A", "a", "AA"], 0)) + call assert_equal(['2', 'A', 'a', 'AA', 1, 3.3], sort([3.3, 1, "2", "A", "a", "AA"], 1)) + call assert_fails('call sort([3.3, 1, "2"], 3)', "E474") +endfunc + +" Tests for the ":sort" command. +func Test_sort_cmd() + let tests = [ + \ { + \ 'name' : 'Alphabetical sort', + \ 'cmd' : '%sort', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b' + \ ], + \ 'expected' : [ + \ ' 123b', + \ 'a', + \ 'a122', + \ 'a123', + \ 'a321', + \ 'ab', + \ 'abc', + \ 'b123', + \ 'b321', + \ 'b321', + \ 'b321b', + \ 'b322b', + \ 'c123d', + \ 'c321d' + \ ] + \ }, + \ { + \ 'name' : 'Numeric sort', + \ 'cmd' : '%sort n', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'a', + \ 'x-22', + \ 'b321', + \ 'b123', + \ '', + \ 'c123d', + \ '-24', + \ ' 123b', + \ 'c321d', + \ '0', + \ 'b322b', + \ 'b321', + \ 'b321b' + \ ], + \ 'expected' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ '', + \ '-24', + \ 'x-22', + \ '0', + \ 'a122', + \ 'a123', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'a321', + \ 'b321', + \ 'c321d', + \ 'b321', + \ 'b321b', + \ 'b322b' + \ ] + \ }, + \ { + \ 'name' : 'Hexadecimal sort', + \ 'cmd' : '%sort x', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b' + \ ], + \ 'expected' : [ + \ 'a', + \ 'ab', + \ 'abc', + \ ' 123b', + \ 'a122', + \ 'a123', + \ 'a321', + \ 'b123', + \ 'b321', + \ 'b321', + \ 'b321b', + \ 'b322b', + \ 'c123d', + \ 'c321d' + \ ] + \ }, + \ { + \ 'name' : 'Alphabetical unique sort', + \ 'cmd' : '%sort u', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b' + \ ], + \ 'expected' : [ + \ ' 123b', + \ 'a', + \ 'a122', + \ 'a123', + \ 'a321', + \ 'ab', + \ 'abc', + \ 'b123', + \ 'b321', + \ 'b321b', + \ 'b322b', + \ 'c123d', + \ 'c321d' + \ ] + \ }, + \ { + \ 'name' : 'Alphabetical reverse sort', + \ 'cmd' : '%sort!', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b' + \ ], + \ 'expected' : [ + \ 'c321d', + \ 'c123d', + \ 'b322b', + \ 'b321b', + \ 'b321', + \ 'b321', + \ 'b123', + \ 'abc', + \ 'ab', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'a', + \ ' 123b', + \ ] + \ }, + \ { + \ 'name' : 'Numeric reverse sort', + \ 'cmd' : '%sort! n', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b' + \ ], + \ 'expected' : [ + \ 'b322b', + \ 'b321b', + \ 'b321', + \ 'c321d', + \ 'b321', + \ 'a321', + \ ' 123b', + \ 'c123d', + \ 'b123', + \ 'a123', + \ 'a122', + \ 'a', + \ 'ab', + \ 'abc' + \ ] + \ }, + \ { + \ 'name' : 'Unique reverse sort', + \ 'cmd' : 'sort! u', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b' + \ ], + \ 'expected' : [ + \ 'c321d', + \ 'c123d', + \ 'b322b', + \ 'b321b', + \ 'b321', + \ 'b123', + \ 'abc', + \ 'ab', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'a', + \ ' 123b', + \ ] + \ }, + \ { + \ 'name' : 'Octal sort', + \ 'cmd' : 'sort o', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b', + \ '', + \ '' + \ ], + \ 'expected' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ '', + \ '', + \ 'a122', + \ 'a123', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'a321', + \ 'b321', + \ 'c321d', + \ 'b321', + \ 'b321b', + \ 'b322b' + \ ] + \ }, + \ { + \ 'name' : 'Reverse hexadecimal sort', + \ 'cmd' : 'sort! x', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b', + \ '', + \ '' + \ ], + \ 'expected' : [ + \ 'c321d', + \ 'c123d', + \ 'b322b', + \ 'b321b', + \ 'b321', + \ 'b321', + \ 'b123', + \ 'a321', + \ 'a123', + \ 'a122', + \ ' 123b', + \ 'abc', + \ 'ab', + \ 'a', + \ '', + \ '' + \ ] + \ }, + \ { + \ 'name' : 'Alpha (skip first character) sort', + \ 'cmd' : 'sort/./', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b', + \ '', + \ '' + \ ], + \ 'expected' : [ + \ 'a', + \ '', + \ '', + \ 'a122', + \ 'a123', + \ 'b123', + \ ' 123b', + \ 'c123d', + \ 'a321', + \ 'b321', + \ 'b321', + \ 'b321b', + \ 'c321d', + \ 'b322b', + \ 'ab', + \ 'abc' + \ ] + \ }, + \ { + \ 'name' : 'Alpha (skip first 2 characters) sort', + \ 'cmd' : 'sort/../', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b', + \ '', + \ '' + \ ], + \ 'expected' : [ + \ 'ab', + \ 'a', + \ '', + \ '', + \ 'a321', + \ 'b321', + \ 'b321', + \ 'b321b', + \ 'c321d', + \ 'a122', + \ 'b322b', + \ 'a123', + \ 'b123', + \ ' 123b', + \ 'c123d', + \ 'abc' + \ ] + \ }, + \ { + \ 'name' : 'alpha, unique, skip first 2 characters', + \ 'cmd' : 'sort/../u', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b', + \ '', + \ '' + \ ], + \ 'expected' : [ + \ 'ab', + \ 'a', + \ '', + \ 'a321', + \ 'b321', + \ 'b321b', + \ 'c321d', + \ 'a122', + \ 'b322b', + \ 'a123', + \ 'b123', + \ ' 123b', + \ 'c123d', + \ 'abc' + \ ] + \ }, + \ { + \ 'name' : 'numeric, skip first character', + \ 'cmd' : 'sort/./n', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b', + \ '', + \ '' + \ ], + \ 'expected' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ '', + \ '', + \ 'a122', + \ 'a123', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'a321', + \ 'b321', + \ 'c321d', + \ 'b321', + \ 'b321b', + \ 'b322b' + \ ] + \ }, + \ { + \ 'name' : 'alpha, sort on first character', + \ 'cmd' : 'sort/./r', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b', + \ '', + \ '' + \ ], + \ 'expected' : [ + \ '', + \ '', + \ ' 123b', + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'b322b', + \ 'b321', + \ 'b321b', + \ 'c123d', + \ 'c321d' + \ ] + \ }, + \ { + \ 'name' : 'alpha, sort on first 2 characters', + \ 'cmd' : 'sort/../r', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b', + \ '', + \ '' + \ ], + \ 'expected' : [ + \ 'a', + \ '', + \ '', + \ ' 123b', + \ 'a123', + \ 'a122', + \ 'a321', + \ 'abc', + \ 'ab', + \ 'b123', + \ 'b321', + \ 'b322b', + \ 'b321', + \ 'b321b', + \ 'c123d', + \ 'c321d' + \ ] + \ }, + \ { + \ 'name' : 'numeric, sort on first character', + \ 'cmd' : 'sort/./rn', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b', + \ '', + \ '' + \ ], + \ 'expected' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b', + \ '', + \ '' + \ ] + \ }, + \ { + \ 'name' : 'alpha, skip past first digit', + \ 'cmd' : 'sort/\d/', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b', + \ '', + \ '' + \ ], + \ 'expected' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ '', + \ '', + \ 'a321', + \ 'b321', + \ 'b321', + \ 'b321b', + \ 'c321d', + \ 'a122', + \ 'b322b', + \ 'a123', + \ 'b123', + \ ' 123b', + \ 'c123d' + \ ] + \ }, + \ { + \ 'name' : 'alpha, sort on first digit', + \ 'cmd' : 'sort/\d/r', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b', + \ '', + \ '' + \ ], + \ 'expected' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ '', + \ '', + \ 'a123', + \ 'a122', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'a321', + \ 'b321', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b' + \ ] + \ }, + \ { + \ 'name' : 'numeric, skip past first digit', + \ 'cmd' : 'sort/\d/n', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b', + \ '', + \ '' + \ ], + \ 'expected' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ '', + \ '', + \ 'a321', + \ 'b321', + \ 'c321d', + \ 'b321', + \ 'b321b', + \ 'a122', + \ 'b322b', + \ 'a123', + \ 'b123', + \ 'c123d', + \ ' 123b' + \ ] + \ }, + \ { + \ 'name' : 'numeric, sort on first digit', + \ 'cmd' : 'sort/\d/rn', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b', + \ '', + \ '' + \ ], + \ 'expected' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ '', + \ '', + \ 'a123', + \ 'a122', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'a321', + \ 'b321', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b' + \ ] + \ }, + \ { + \ 'name' : 'alpha, skip past first 2 digits', + \ 'cmd' : 'sort/\d\d/', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b', + \ '', + \ '' + \ ], + \ 'expected' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ '', + \ '', + \ 'a321', + \ 'b321', + \ 'b321', + \ 'b321b', + \ 'c321d', + \ 'a122', + \ 'b322b', + \ 'a123', + \ 'b123', + \ ' 123b', + \ 'c123d' + \ ] + \ }, + \ { + \ 'name' : 'numeric, skip past first 2 digits', + \ 'cmd' : 'sort/\d\d/n', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b', + \ '', + \ '' + \ ], + \ 'expected' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ '', + \ '', + \ 'a321', + \ 'b321', + \ 'c321d', + \ 'b321', + \ 'b321b', + \ 'a122', + \ 'b322b', + \ 'a123', + \ 'b123', + \ 'c123d', + \ ' 123b' + \ ] + \ }, + \ { + \ 'name' : 'hexadecimal, skip past first 2 digits', + \ 'cmd' : 'sort/\d\d/x', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b', + \ '', + \ '' + \ ], + \ 'expected' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ '', + \ '', + \ 'a321', + \ 'b321', + \ 'b321', + \ 'a122', + \ 'a123', + \ 'b123', + \ 'b321b', + \ 'c321d', + \ 'b322b', + \ ' 123b', + \ 'c123d' + \ ] + \ }, + \ { + \ 'name' : 'alpha, sort on first 2 digits', + \ 'cmd' : 'sort/\d\d/r', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b', + \ '', + \ '' + \ ], + \ 'expected' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ '', + \ '', + \ 'a123', + \ 'a122', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'a321', + \ 'b321', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b' + \ ] + \ }, + \ { + \ 'name' : 'numeric, sort on first 2 digits', + \ 'cmd' : 'sort/\d\d/rn', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b', + \ '', + \ '' + \ ], + \ 'expected' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ '', + \ '', + \ 'a123', + \ 'a122', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'a321', + \ 'b321', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b' + \ ] + \ }, + \ { + \ 'name' : 'hexadecimal, sort on first 2 digits', + \ 'cmd' : 'sort/\d\d/rx', + \ 'input' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ 'a321', + \ 'a123', + \ 'a122', + \ 'b321', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b', + \ '', + \ '' + \ ], + \ 'expected' : [ + \ 'abc', + \ 'ab', + \ 'a', + \ '', + \ '', + \ 'a123', + \ 'a122', + \ 'b123', + \ 'c123d', + \ ' 123b', + \ 'a321', + \ 'b321', + \ 'c321d', + \ 'b322b', + \ 'b321', + \ 'b321b' + \ ] + \ }, + \ { + \ 'name' : 'binary', + \ 'cmd' : 'sort b', + \ 'input' : [ + \ '0b111000', + \ '0b101100', + \ '0b101001', + \ '0b101001', + \ '0b101000', + \ '0b000000', + \ '0b001000', + \ '0b010000', + \ '0b101000', + \ '0b100000', + \ '0b101010', + \ '0b100010', + \ '0b100100', + \ '0b100010', + \ '', + \ '' + \ ], + \ 'expected' : [ + \ '', + \ '', + \ '0b000000', + \ '0b001000', + \ '0b010000', + \ '0b100000', + \ '0b100010', + \ '0b100010', + \ '0b100100', + \ '0b101000', + \ '0b101000', + \ '0b101001', + \ '0b101001', + \ '0b101010', + \ '0b101100', + \ '0b111000' + \ ] + \ }, + \ { + \ 'name' : 'binary with leading characters', + \ 'cmd' : 'sort b', + \ 'input' : [ + \ '0b100010', + \ '0b010000', + \ ' 0b101001', + \ 'b0b101100', + \ '0b100010', + \ ' 0b100100', + \ 'a0b001000', + \ '0b101000', + \ '0b101000', + \ 'a0b101001', + \ 'ab0b100000', + \ '0b101010', + \ '0b000000', + \ 'b0b111000', + \ '', + \ '' + \ ], + \ 'expected' : [ + \ '', + \ '', + \ '0b000000', + \ 'a0b001000', + \ '0b010000', + \ 'ab0b100000', + \ '0b100010', + \ '0b100010', + \ ' 0b100100', + \ '0b101000', + \ '0b101000', + \ ' 0b101001', + \ 'a0b101001', + \ '0b101010', + \ 'b0b101100', + \ 'b0b111000' + \ ] + \ }, + \ { + \ 'name' : 'float', + \ 'cmd' : 'sort f', + \ 'input' : [ + \ '1.234', + \ '0.88', + \ '123.456', + \ '1.15e-6', + \ '-1.1e3', + \ '-1.01e3', + \ '', + \ '' + \ ], + \ 'expected' : [ + \ '', + \ '', + \ '-1.1e3', + \ '-1.01e3', + \ '1.15e-6', + \ '0.88', + \ '1.234', + \ '123.456' + \ ] + \ }, + \ { + \ 'name' : 'alphabetical, sorted input', + \ 'cmd' : 'sort', + \ 'input' : [ + \ 'a', + \ 'b', + \ 'c', + \ ], + \ 'expected' : [ + \ 'a', + \ 'b', + \ 'c', + \ ] + \ }, + \ { + \ 'name' : 'alphabetical, sorted input, unique at end', + \ 'cmd' : 'sort u', + \ 'input' : [ + \ 'aa', + \ 'bb', + \ 'cc', + \ 'cc', + \ ], + \ 'expected' : [ + \ 'aa', + \ 'bb', + \ 'cc', + \ ] + \ }, + \ ] + + for t in tests + enew! + call append(0, t.input) + $delete _ + setlocal nomodified + execute t.cmd + + call assert_equal(t.expected, getline(1, '$'), t.name) + + " Previously, the ":sort" command would set 'modified' even if the buffer + " contents did not change. Here, we check that this problem is fixed. + if t.input == t.expected + call assert_false(&modified, t.name . ': &mod is not correct') + else + call assert_true(&modified, t.name . ': &mod is not correct') + endif + endfor + + call assert_fails('sort no', 'E474') + + enew! +endfunc + +func Test_sort_cmd_report() + enew! + call append(0, repeat([1], 3) + repeat([2], 3) + repeat([3], 3)) + $delete _ + setlocal nomodified + let res = execute('%sort u') + + call assert_equal([1,2,3], map(getline(1, '$'), 'v:val+0')) + call assert_match("6 fewer lines", res) + enew! + call append(0, repeat([1], 3) + repeat([2], 3) + repeat([3], 3)) + $delete _ + setlocal nomodified report=10 + let res = execute('%sort u') + + call assert_equal([1,2,3], map(getline(1, '$'), 'v:val+0')) + call assert_equal("", res) + enew! + call append(0, repeat([1], 3) + repeat([2], 3) + repeat([3], 3)) + $delete _ + setl report&vim + setlocal nomodified + let res = execute('1g/^/%sort u') + + call assert_equal([1,2,3], map(getline(1, '$'), 'v:val+0')) + " the output comes from the :g command, not from the :sort + call assert_match("6 fewer lines", res) + enew! + endfunc diff --git a/src/testdir/test_source.vim b/src/testdir/test_source.vim new file mode 100644 index 0000000..a33d286 --- /dev/null +++ b/src/testdir/test_source.vim @@ -0,0 +1,38 @@ +" Tests for the :source command. + +func Test_source_autocmd() + call writefile([ + \ 'let did_source = 1', + \ ], 'Xsourced') + au SourcePre *source* let did_source_pre = 1 + au SourcePost *source* let did_source_post = 1 + + source Xsourced + + call assert_equal(g:did_source, 1) + call assert_equal(g:did_source_pre, 1) + call assert_equal(g:did_source_post, 1) + + call delete('Xsourced') + au! SourcePre + au! SourcePost + unlet g:did_source + unlet g:did_source_pre + unlet g:did_source_post +endfunc + +func Test_source_cmd() + au SourceCmd *source* let did_source = expand('<afile>') + au SourcePre *source* let did_source_pre = 2 + au SourcePost *source* let did_source_post = 2 + + source Xsourced + + call assert_equal(g:did_source, 'Xsourced') + call assert_false(exists('g:did_source_pre')) + call assert_equal(g:did_source_post, 2) + + au! SourceCmd + au! SourcePre + au! SourcePost +endfunc diff --git a/src/testdir/test_source_utf8.vim b/src/testdir/test_source_utf8.vim new file mode 100644 index 0000000..e93ea29 --- /dev/null +++ b/src/testdir/test_source_utf8.vim @@ -0,0 +1,60 @@ +" Test the :source! command + +func Test_source_utf8() + " check that sourcing a script with 0x80 as second byte works + new + call setline(1, [':%s/àx/--à1234--/g', ':%s/Àx/--À1234--/g']) + write! Xscript + bwipe! + new + call setline(1, [' àx ', ' Àx ']) + source! Xscript | echo + call assert_equal(' --à1234-- ', getline(1)) + call assert_equal(' --À1234-- ', getline(2)) + bwipe! + call delete('Xscript') +endfunc + +func Test_source_latin() + " check that sourcing a latin1 script with a 0xc0 byte works + new + call setline(1, ["call feedkeys('r')", "call feedkeys('\xc0', 'xt')"]) + write! Xscript + bwipe! + new + call setline(1, ['xxx']) + source Xscript + call assert_equal("\u00c0xx", getline(1)) + bwipe! + call delete('Xscript') +endfunc + +" Test for sourcing a file with CTRL-V's at the end of the line +func Test_source_ctrl_v() + call writefile(['map __1 afirst', + \ 'map __2 asecond', + \ 'map __3 athird', + \ 'map __4 afourth', + \ 'map __5 afifth', + \ "map __1 asd\<C-V>", + \ "map __2 asd\<C-V>\<C-V>", + \ "map __3 asd\<C-V>\<C-V>", + \ "map __4 asd\<C-V>\<C-V>\<C-V>", + \ "map __5 asd\<C-V>\<C-V>\<C-V>", + \ ], 'Xtestfile') + source Xtestfile + enew! + exe "normal __1\<Esc>\<Esc>__2\<Esc>__3\<Esc>\<Esc>__4\<Esc>__5\<Esc>" + exe "%s/\<C-J>/0/g" + call assert_equal(['sd', + \ "map __2 asd\<Esc>secondsd\<Esc>sd0map __5 asd0fifth"], + \ getline(1, 2)) + + enew! + call delete('Xtestfile') + unmap __1 + unmap __2 + unmap __3 + unmap __4 + unmap __5 +endfunc diff --git a/src/testdir/test_spell.vim b/src/testdir/test_spell.vim new file mode 100644 index 0000000..76ad12e --- /dev/null +++ b/src/testdir/test_spell.vim @@ -0,0 +1,887 @@ +" Test spell checking + +if !has('spell') + finish +endif + +func TearDown() + set nospell + call delete('Xtest.aff') + call delete('Xtest.dic') + call delete('Xtest.latin1.add') + call delete('Xtest.latin1.add.spl') + call delete('Xtest.latin1.spl') + call delete('Xtest.latin1.sug') +endfunc + +func Test_wrap_search() + new + call setline(1, ['The', '', 'A plong line with two zpelling mistakes', '', 'End']) + set spell wrapscan + normal ]s + call assert_equal('plong', expand('<cword>')) + normal ]s + call assert_equal('zpelling', expand('<cword>')) + normal ]s + call assert_equal('plong', expand('<cword>')) + bwipe! + set nospell +endfunc + +func Test_curswant() + new + call setline(1, ['Another plong line', 'abcdefghijklmnopq']) + set spell wrapscan + normal 0]s + call assert_equal('plong', expand('<cword>')) + normal j + call assert_equal(9, getcurpos()[2]) + normal 0[s + call assert_equal('plong', expand('<cword>')) + normal j + call assert_equal(9, getcurpos()[2]) + + normal 0]S + call assert_equal('plong', expand('<cword>')) + normal j + call assert_equal(9, getcurpos()[2]) + normal 0[S + call assert_equal('plong', expand('<cword>')) + normal j + call assert_equal(9, getcurpos()[2]) + + normal 1G0 + call assert_equal('plong', spellbadword()[0]) + normal j + call assert_equal(9, getcurpos()[2]) + + bwipe! + set nospell +endfunc + +func Test_z_equal_on_invalid_utf8_word() + split + set spell + call setline(1, "\xff") + norm z= + set nospell + bwipe! +endfunc + +" Test spellbadword() with argument +func Test_spellbadword() + set spell + + call assert_equal(['bycycle', 'bad'], spellbadword('My bycycle.')) + call assert_equal(['another', 'caps'], spellbadword('A sentence. another sentence')) + + set spelllang=en + call assert_equal(['', ''], spellbadword('centre')) + call assert_equal(['', ''], spellbadword('center')) + set spelllang=en_us + call assert_equal(['centre', 'local'], spellbadword('centre')) + call assert_equal(['', ''], spellbadword('center')) + set spelllang=en_gb + call assert_equal(['', ''], spellbadword('centre')) + call assert_equal(['center', 'local'], spellbadword('center')) + + " Create a small word list to test that spellbadword('...') + " can return ['...', 'rare']. + e Xwords + insert +foo +foobar/? +. + w! + mkspell! Xwords.spl Xwords + set spelllang=Xwords.spl + call assert_equal(['foobar', 'rare'], spellbadword('foo foobar')) + + " Typo should not be detected without the 'spell' option. + set spelllang=en_gb nospell + call assert_equal(['', ''], spellbadword('centre')) + call assert_equal(['', ''], spellbadword('My bycycle.')) + call assert_equal(['', ''], spellbadword('A sentence. another sentence')) + + call delete('Xwords.spl') + call delete('Xwords') + set spelllang& + set spell& +endfunc + +func Test_spellreall() + new + set spell + call assert_fails('spellrepall', 'E752:') + call setline(1, ['A speling mistake. The same speling mistake.', + \ 'Another speling mistake.']) + call feedkeys(']s1z=', 'tx') + call assert_equal('A spelling mistake. The same speling mistake.', getline(1)) + call assert_equal('Another speling mistake.', getline(2)) + spellrepall + call assert_equal('A spelling mistake. The same spelling mistake.', getline(1)) + call assert_equal('Another spelling mistake.', getline(2)) + call assert_fails('spellrepall', 'E753:') + set spell& + bwipe! +endfunc + +func Test_spellinfo() + new + + set enc=latin1 spell spelllang=en + call assert_match("^\nfile: .*/runtime/spell/en.latin1.spl\n$", execute('spellinfo')) + + set enc=cp1250 spell spelllang=en + call assert_match("^\nfile: .*/runtime/spell/en.ascii.spl\n$", execute('spellinfo')) + + set enc=utf-8 spell spelllang=en + call assert_match("^\nfile: .*/runtime/spell/en.utf-8.spl\n$", execute('spellinfo')) + + set enc=latin1 spell spelllang=en_us,en_nz + call assert_match("^\n" . + \ "file: .*/runtime/spell/en.latin1.spl\n" . + \ "file: .*/runtime/spell/en.latin1.spl\n$", execute('spellinfo')) + + set spell spelllang= + call assert_fails('spellinfo', 'E756:') + + set nospell spelllang=en + call assert_fails('spellinfo', 'E756:') + + set enc& spell& spelllang& + bwipe +endfunc + +func Test_zz_basic() + call LoadAffAndDic(g:test_data_aff1, g:test_data_dic1) + call RunGoodBad("wrong OK puts. Test the end", + \ "bad: inputs comment ok Ok. test d\xE9\xF4l end the", + \["Comment", "deol", "d\xE9\xF4r", "input", "OK", "output", "outputs", "outtest", "put", "puts", + \ "test", "testen", "testn", "the end", "uk", "wrong"], + \[ + \ ["bad", ["put", "uk", "OK"]], + \ ["inputs", ["input", "puts", "outputs"]], + \ ["comment", ["Comment", "outtest", "the end"]], + \ ["ok", ["OK", "uk", "put"]], + \ ["Ok", ["OK", "Uk", "Put"]], + \ ["test", ["Test", "testn", "testen"]], + \ ["d\xE9\xF4l", ["deol", "d\xE9\xF4r", "test"]], + \ ["end", ["put", "uk", "test"]], + \ ["the", ["put", "uk", "test"]], + \ ] + \ ) + + call assert_equal("gebletegek", soundfold('goobledygoook')) + call assert_equal("kepereneven", soundfold('koprnven')) + call assert_equal("everles gesvets etele", soundfold('oeverloos gezwets edale')) +endfunc + +" Postponed prefixes +func Test_zz_prefixes() + call LoadAffAndDic(g:test_data_aff2, g:test_data_dic1) + call RunGoodBad("puts", + \ "bad: inputs comment ok Ok end the. test d\xE9\xF4l", + \ ["Comment", "deol", "d\xE9\xF4r", "OK", "put", "input", "output", "puts", "outputs", "test", "outtest", "testen", "testn", "the end", "uk", "wrong"], + \ [ + \ ["bad", ["put", "uk", "OK"]], + \ ["inputs", ["input", "puts", "outputs"]], + \ ["comment", ["Comment"]], + \ ["ok", ["OK", "uk", "put"]], + \ ["Ok", ["OK", "Uk", "Put"]], + \ ["end", ["put", "uk", "deol"]], + \ ["the", ["put", "uk", "test"]], + \ ["test", ["Test", "testn", "testen"]], + \ ["d\xE9\xF4l", ["deol", "d\xE9\xF4r", "test"]], + \ ]) +endfunc + +"Compound words +func Test_zz_compound() + call LoadAffAndDic(g:test_data_aff3, g:test_data_dic3) + call RunGoodBad("foo m\xEF foobar foofoobar barfoo barbarfoo", + \ "bad: bar la foom\xEF barm\xEF m\xEFfoo m\xEFbar m\xEFm\xEF lala m\xEFla lam\xEF foola labar", + \ ["foo", "m\xEF"], + \ [ + \ ["bad", ["foo", "m\xEF"]], + \ ["bar", ["barfoo", "foobar", "foo"]], + \ ["la", ["m\xEF", "foo"]], + \ ["foom\xEF", ["foo m\xEF", "foo", "foofoo"]], + \ ["barm\xEF", ["barfoo", "m\xEF", "barbar"]], + \ ["m\xEFfoo", ["m\xEF foo", "foo", "foofoo"]], + \ ["m\xEFbar", ["foobar", "barbar", "m\xEF"]], + \ ["m\xEFm\xEF", ["m\xEF m\xEF", "m\xEF"]], + \ ["lala", []], + \ ["m\xEFla", ["m\xEF", "m\xEF m\xEF"]], + \ ["lam\xEF", ["m\xEF", "m\xEF m\xEF"]], + \ ["foola", ["foo", "foobar", "foofoo"]], + \ ["labar", ["barbar", "foobar"]], + \ ]) + + call LoadAffAndDic(g:test_data_aff4, g:test_data_dic4) + call RunGoodBad("word util bork prebork start end wordutil wordutils pro-ok bork borkbork borkborkbork borkborkborkbork borkborkborkborkbork tomato tomatotomato startend startword startwordword startwordend startwordwordend startwordwordwordend prebork preborkbork preborkborkbork nouword", + \ "bad: wordutilize pro borkborkborkborkborkbork tomatotomatotomato endstart endend startstart wordend wordstart preborkprebork preborkpreborkbork startwordwordwordwordend borkpreborkpreborkbork utilsbork startnouword", + \ ["bork", "prebork", "end", "pro-ok", "start", "tomato", "util", "utilize", "utils", "word", "nouword"], + \ [ + \ ["bad", ["end", "bork", "word"]], + \ ["wordutilize", ["word utilize", "wordutils", "wordutil"]], + \ ["pro", ["bork", "word", "end"]], + \ ["borkborkborkborkborkbork", ["bork borkborkborkborkbork", "borkbork borkborkborkbork", "borkborkbork borkborkbork"]], + \ ["tomatotomatotomato", ["tomato tomatotomato", "tomatotomato tomato", "tomato tomato tomato"]], + \ ["endstart", ["end start", "start"]], + \ ["endend", ["end end", "end"]], + \ ["startstart", ["start start"]], + \ ["wordend", ["word end", "word", "wordword"]], + \ ["wordstart", ["word start", "bork start"]], + \ ["preborkprebork", ["prebork prebork", "preborkbork", "preborkborkbork"]], + \ ["preborkpreborkbork", ["prebork preborkbork", "preborkborkbork", "preborkborkborkbork"]], + \ ["startwordwordwordwordend", ["startwordwordwordword end", "startwordwordwordword", "start wordwordwordword end"]], + \ ["borkpreborkpreborkbork", ["bork preborkpreborkbork", "bork prebork preborkbork", "bork preborkprebork bork"]], + \ ["utilsbork", ["utilbork", "utils bork", "util bork"]], + \ ["startnouword", ["start nouword", "startword", "startborkword"]], + \ ]) + +endfunc + +"Test affix flags with two characters +func Test_zz_affix() + call LoadAffAndDic(g:test_data_aff5, g:test_data_dic5) + call RunGoodBad("fooa1 fooa\xE9 bar prebar barbork prebarbork startprebar start end startend startmiddleend nouend", + \ "bad: foo fooa2 prabar probarbirk middle startmiddle middleend endstart startprobar startnouend", + \ ["bar", "barbork", "end", "fooa1", "fooa\xE9", "nouend", "prebar", "prebarbork", "start"], + \ [ + \ ["bad", ["bar", "end", "fooa1"]], + \ ["foo", ["fooa1", "fooa\xE9", "bar"]], + \ ["fooa2", ["fooa1", "fooa\xE9", "bar"]], + \ ["prabar", ["prebar", "bar", "bar bar"]], + \ ["probarbirk", ["prebarbork"]], + \ ["middle", []], + \ ["startmiddle", ["startmiddleend", "startmiddlebar"]], + \ ["middleend", []], + \ ["endstart", ["end start", "start"]], + \ ["startprobar", ["startprebar", "start prebar", "startbar"]], + \ ["startnouend", ["start nouend", "startend"]], + \ ]) + + call LoadAffAndDic(g:test_data_aff6, g:test_data_dic6) + call RunGoodBad("meea1 meea\xE9 bar prebar barbork prebarbork leadprebar lead end leadend leadmiddleend", + \ "bad: mee meea2 prabar probarbirk middle leadmiddle middleend endlead leadprobar", + \ ["bar", "barbork", "end", "lead", "meea1", "meea\xE9", "prebar", "prebarbork"], + \ [ + \ ["bad", ["bar", "end", "lead"]], + \ ["mee", ["meea1", "meea\xE9", "bar"]], + \ ["meea2", ["meea1", "meea\xE9", "lead"]], + \ ["prabar", ["prebar", "bar", "leadbar"]], + \ ["probarbirk", ["prebarbork"]], + \ ["middle", []], + \ ["leadmiddle", ["leadmiddleend", "leadmiddlebar"]], + \ ["middleend", []], + \ ["endlead", ["end lead", "lead", "end end"]], + \ ["leadprobar", ["leadprebar", "lead prebar", "leadbar"]], + \ ]) + + call LoadAffAndDic(g:test_data_aff7, g:test_data_dic7) + call RunGoodBad("meea1 meea\xE9 bar prebar barmeat prebarmeat leadprebar lead tail leadtail leadmiddletail", + \ "bad: mee meea2 prabar probarmaat middle leadmiddle middletail taillead leadprobar", + \ ["bar", "barmeat", "lead", "meea1", "meea\xE9", "prebar", "prebarmeat", "tail"], + \ [ + \ ["bad", ["bar", "lead", "tail"]], + \ ["mee", ["meea1", "meea\xE9", "bar"]], + \ ["meea2", ["meea1", "meea\xE9", "lead"]], + \ ["prabar", ["prebar", "bar", "leadbar"]], + \ ["probarmaat", ["prebarmeat"]], + \ ["middle", []], + \ ["leadmiddle", ["leadmiddlebar"]], + \ ["middletail", []], + \ ["taillead", ["tail lead", "tail"]], + \ ["leadprobar", ["leadprebar", "lead prebar", "leadbar"]], + \ ]) +endfunc + +func Test_zz_NOSLITSUGS() + call LoadAffAndDic(g:test_data_aff8, g:test_data_dic8) + call RunGoodBad("foo bar faabar", "bad: foobar barfoo", + \ ["bar", "faabar", "foo"], + \ [ + \ ["bad", ["bar", "foo"]], + \ ["foobar", ["faabar", "foo bar", "bar"]], + \ ["barfoo", ["bar foo", "bar", "foo"]], + \ ]) +endfunc + +" Numbers +func Test_zz_Numbers() + call LoadAffAndDic(g:test_data_aff9, g:test_data_dic9) + call RunGoodBad("0b1011 0777 1234 0x01ff", "", + \ ["bar", "foo"], + \ [ + \ ]) +endfunc + +function FirstSpellWord() + call feedkeys("/^start:\n", 'tx') + normal ]smm + let [str, a] = spellbadword() + return str +endfunc + +function SecondSpellWord() + normal `m]s + let [str, a] = spellbadword() + return str +endfunc + +"Test with SAL instead of SOFO items; test automatic reloading +func Test_zz_sal_and_addition() + set enc=latin1 + set spellfile= + call writefile(g:test_data_dic1, "Xtest.dic") + call writefile(g:test_data_aff_sal, "Xtest.aff") + mkspell! Xtest Xtest + set spl=Xtest.latin1.spl spell + call assert_equal('kbltykk', soundfold('goobledygoook')) + call assert_equal('kprnfn', soundfold('koprnven')) + call assert_equal('*fls kswts tl', soundfold('oeverloos gezwets edale')) + + "also use an addition file + call writefile(["/regions=usgbnz", "elequint/2", "elekwint/3"], "Xtest.latin1.add") + mkspell! Xtest.latin1.add.spl Xtest.latin1.add + + bwipe! + call setline(1, ["start: elequint test elekwint test elekwent asdf"]) + + set spellfile=Xtest.latin1.add + call assert_equal("elekwent", FirstSpellWord()) + + set spl=Xtest_us.latin1.spl + call assert_equal("elequint", FirstSpellWord()) + call assert_equal("elekwint", SecondSpellWord()) + + set spl=Xtest_gb.latin1.spl + call assert_equal("elekwint", FirstSpellWord()) + call assert_equal("elekwent", SecondSpellWord()) + + set spl=Xtest_nz.latin1.spl + call assert_equal("elequint", FirstSpellWord()) + call assert_equal("elekwent", SecondSpellWord()) + + set spl=Xtest_ca.latin1.spl + call assert_equal("elequint", FirstSpellWord()) + call assert_equal("elekwint", SecondSpellWord()) +endfunc + +func Test_region_error() + messages clear + call writefile(["/regions=usgbnz", "elequint/0"], "Xtest.latin1.add") + mkspell! Xtest.latin1.add.spl Xtest.latin1.add + call assert_match('Invalid region nr in Xtest.latin1.add line 2: 0', execute('messages')) + call delete('Xtest.latin1.add') + call delete('Xtest.latin1.add.spl') +endfunc + +" Check using z= in new buffer (crash fixed by patch 7.4a.028). +func Test_zeq_crash() + new + set maxmem=512 spell + call feedkeys('iasdz=:\"', 'tx') + + bwipe! +endfunc + +func LoadAffAndDic(aff_contents, dic_contents) + set enc=latin1 + set spellfile= + call writefile(a:aff_contents, "Xtest.aff") + call writefile(a:dic_contents, "Xtest.dic") + " Generate a .spl file from a .dic and .aff file. + mkspell! Xtest Xtest + " use that spell file + set spl=Xtest.latin1.spl spell +endfunc + +func ListWords() + spelldump + %yank + quit + return split(@", "\n") +endfunc + +func TestGoodBadBase() + exe '1;/^good:' + normal 0f:]s + let prevbad = '' + let result = [] + while 1 + let [bad, a] = spellbadword() + if bad == '' || bad == prevbad || bad == 'badend' + break + endif + let prevbad = bad + let lst = spellsuggest(bad, 3) + normal mm + + call add(result, [bad, lst]) + normal `m]s + endwhile + return result +endfunc + +func RunGoodBad(good, bad, expected_words, expected_bad_words) + bwipe! + call setline(1, ["good: ", a:good, a:bad, " badend "]) + let words = ListWords() + call assert_equal(a:expected_words, words[1:-1]) + let bad_words = TestGoodBadBase() + call assert_equal(a:expected_bad_words, bad_words) + bwipe! +endfunc + +let g:test_data_aff1 = [ + \"SET ISO8859-1", + \"TRY esianrtolcdugmphbyfvkwjkqxz-\xEB\xE9\xE8\xEA\xEF\xEE\xE4\xE0\xE2\xF6\xFC\xFB'ESIANRTOLCDUGMPHBYFVKWJKQXZ", + \"", + \"FOL \xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xDF\xFF", + \"LOW \xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xDF\xFF", + \"UPP \xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xFF", + \"", + \"SOFOFROM abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xDF\xFF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xBF", + \"SOFOTO ebctefghejklnnepkrstevvkesebctefghejklnnepkrstevvkeseeeeeeeceeeeeeeedneeeeeeeeeeepseeeeeeeeceeeeeeeedneeeeeeeeeeep?", + \"", + \"MIDWORD\t'-", + \"", + \"KEP =", + \"RAR ?", + \"BAD !", + \"", + \"PFX I N 1", + \"PFX I 0 in .", + \"", + \"PFX O Y 1", + \"PFX O 0 out .", + \"", + \"SFX S Y 2", + \"SFX S 0 s [^s]", + \"SFX S 0 es s", + \"", + \"SFX N N 3", + \"SFX N 0 en [^n]", + \"SFX N 0 nen n", + \"SFX N 0 n .", + \"", + \"REP 3", + \"REP g ch", + \"REP ch g", + \"REP svp s.v.p.", + \"", + \"MAP 9", + \"MAP a\xE0\xE1\xE2\xE3\xE4\xE5", + \"MAP e\xE8\xE9\xEA\xEB", + \"MAP i\xEC\xED\xEE\xEF", + \"MAP o\xF2\xF3\xF4\xF5\xF6", + \"MAP u\xF9\xFA\xFB\xFC", + \"MAP n\xF1", + \"MAP c\xE7", + \"MAP y\xFF\xFD", + \"MAP s\xDF", + \ ] +let g:test_data_dic1 = [ + \"123456", + \"test/NO", + \"# comment", + \"wrong", + \"Comment", + \"OK", + \"uk", + \"put/ISO", + \"the end", + \"deol", + \"d\xE9\xF4r", + \ ] +let g:test_data_aff2 = [ + \"SET ISO8859-1", + \"", + \"FOL \xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xDF\xFF", + \"LOW \xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xDF\xFF", + \"UPP \xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xFF", + \"", + \"PFXPOSTPONE", + \"", + \"MIDWORD\t'-", + \"", + \"KEP =", + \"RAR ?", + \"BAD !", + \"", + \"PFX I N 1", + \"PFX I 0 in .", + \"", + \"PFX O Y 1", + \"PFX O 0 out [a-z]", + \"", + \"SFX S Y 2", + \"SFX S 0 s [^s]", + \"SFX S 0 es s", + \"", + \"SFX N N 3", + \"SFX N 0 en [^n]", + \"SFX N 0 nen n", + \"SFX N 0 n .", + \"", + \"REP 3", + \"REP g ch", + \"REP ch g", + \"REP svp s.v.p.", + \"", + \"MAP 9", + \"MAP a\xE0\xE1\xE2\xE3\xE4\xE5", + \"MAP e\xE8\xE9\xEA\xEB", + \"MAP i\xEC\xED\xEE\xEF", + \"MAP o\xF2\xF3\xF4\xF5\xF6", + \"MAP u\xF9\xFA\xFB\xFC", + \"MAP n\xF1", + \"MAP c\xE7", + \"MAP y\xFF\xFD", + \"MAP s\xDF", + \ ] +let g:test_data_aff3 = [ + \"SET ISO8859-1", + \"", + \"COMPOUNDMIN 3", + \"COMPOUNDRULE m*", + \"NEEDCOMPOUND x", + \ ] +let g:test_data_dic3 = [ + \"1234", + \"foo/m", + \"bar/mx", + \"m\xEF/m", + \"la/mx", + \ ] +let g:test_data_aff4 = [ + \"SET ISO8859-1", + \"", + \"FOL \xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xDF\xFF", + \"LOW \xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xDF\xFF", + \"UPP \xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xFF", + \"", + \"COMPOUNDRULE m+", + \"COMPOUNDRULE sm*e", + \"COMPOUNDRULE sm+", + \"COMPOUNDMIN 3", + \"COMPOUNDWORDMAX 3", + \"COMPOUNDFORBIDFLAG t", + \"", + \"COMPOUNDSYLMAX 5", + \"SYLLABLE a\xE1e\xE9i\xEDo\xF3\xF6\xF5u\xFA\xFC\xFBy/aa/au/ea/ee/ei/ie/oa/oe/oo/ou/uu/ui", + \"", + \"MAP 9", + \"MAP a\xE0\xE1\xE2\xE3\xE4\xE5", + \"MAP e\xE8\xE9\xEA\xEB", + \"MAP i\xEC\xED\xEE\xEF", + \"MAP o\xF2\xF3\xF4\xF5\xF6", + \"MAP u\xF9\xFA\xFB\xFC", + \"MAP n\xF1", + \"MAP c\xE7", + \"MAP y\xFF\xFD", + \"MAP s\xDF", + \"", + \"NEEDAFFIX x", + \"", + \"PFXPOSTPONE", + \"", + \"MIDWORD '-", + \"", + \"SFX q N 1", + \"SFX q 0 -ok .", + \"", + \"SFX a Y 2", + \"SFX a 0 s .", + \"SFX a 0 ize/t .", + \"", + \"PFX p N 1", + \"PFX p 0 pre .", + \"", + \"PFX P N 1", + \"PFX P 0 nou .", + \ ] +let g:test_data_dic4 = [ + \"1234", + \"word/mP", + \"util/am", + \"pro/xq", + \"tomato/m", + \"bork/mp", + \"start/s", + \"end/e", + \ ] +let g:test_data_aff5 = [ + \"SET ISO8859-1", + \"", + \"FLAG long", + \"", + \"NEEDAFFIX !!", + \"", + \"COMPOUNDRULE ssmm*ee", + \"", + \"NEEDCOMPOUND xx", + \"COMPOUNDPERMITFLAG pp", + \"", + \"SFX 13 Y 1", + \"SFX 13 0 bork .", + \"", + \"SFX a1 Y 1", + \"SFX a1 0 a1 .", + \"", + \"SFX a\xE9 Y 1", + \"SFX a\xE9 0 a\xE9 .", + \"", + \"PFX zz Y 1", + \"PFX zz 0 pre/pp .", + \"", + \"PFX yy Y 1", + \"PFX yy 0 nou .", + \ ] +let g:test_data_dic5 = [ + \"1234", + \"foo/a1a\xE9!!", + \"bar/zz13ee", + \"start/ss", + \"end/eeyy", + \"middle/mmxx", + \ ] +let g:test_data_aff6 = [ + \"SET ISO8859-1", + \"", + \"FLAG caplong", + \"", + \"NEEDAFFIX A!", + \"", + \"COMPOUNDRULE sMm*Ee", + \"", + \"NEEDCOMPOUND Xx", + \"", + \"COMPOUNDPERMITFLAG p", + \"", + \"SFX N3 Y 1", + \"SFX N3 0 bork .", + \"", + \"SFX A1 Y 1", + \"SFX A1 0 a1 .", + \"", + \"SFX A\xE9 Y 1", + \"SFX A\xE9 0 a\xE9 .", + \"", + \"PFX Zz Y 1", + \"PFX Zz 0 pre/p .", + \ ] +let g:test_data_dic6 = [ + \"1234", + \"mee/A1A\xE9A!", + \"bar/ZzN3Ee", + \"lead/s", + \"end/Ee", + \"middle/MmXx", + \ ] +let g:test_data_aff7 = [ + \"SET ISO8859-1", + \"", + \"FLAG num", + \"", + \"NEEDAFFIX 9999", + \"", + \"COMPOUNDRULE 2,77*123", + \"", + \"NEEDCOMPOUND 1", + \"COMPOUNDPERMITFLAG 432", + \"", + \"SFX 61003 Y 1", + \"SFX 61003 0 meat .", + \"", + \"SFX 391 Y 1", + \"SFX 391 0 a1 .", + \"", + \"SFX 111 Y 1", + \"SFX 111 0 a\xE9 .", + \"", + \"PFX 17 Y 1", + \"PFX 17 0 pre/432 .", + \ ] +let g:test_data_dic7 = [ + \"1234", + \"mee/391,111,9999", + \"bar/17,61003,123", + \"lead/2", + \"tail/123", + \"middle/77,1", + \ ] +let g:test_data_aff8 = [ + \"SET ISO8859-1", + \"", + \"NOSPLITSUGS", + \ ] +let g:test_data_dic8 = [ + \"1234", + \"foo", + \"bar", + \"faabar", + \ ] +let g:test_data_aff9 = [ + \ ] +let g:test_data_dic9 = [ + \"1234", + \"foo", + \"bar", + \ ] +let g:test_data_aff_sal = [ + \"SET ISO8859-1", + \"TRY esianrtolcdugmphbyfvkwjkqxz-\xEB\xE9\xE8\xEA\xEF\xEE\xE4\xE0\xE2\xF6\xFC\xFB'ESIANRTOLCDUGMPHBYFVKWJKQXZ", + \"", + \"FOL \xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xDF\xFF", + \"LOW \xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xDF\xFF", + \"UPP \xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xFF", + \"", + \"MIDWORD\t'-", + \"", + \"KEP =", + \"RAR ?", + \"BAD !", + \"", + \"PFX I N 1", + \"PFX I 0 in .", + \"", + \"PFX O Y 1", + \"PFX O 0 out .", + \"", + \"SFX S Y 2", + \"SFX S 0 s [^s]", + \"SFX S 0 es s", + \"", + \"SFX N N 3", + \"SFX N 0 en [^n]", + \"SFX N 0 nen n", + \"SFX N 0 n .", + \"", + \"REP 3", + \"REP g ch", + \"REP ch g", + \"REP svp s.v.p.", + \"", + \"MAP 9", + \"MAP a\xE0\xE1\xE2\xE3\xE4\xE5", + \"MAP e\xE8\xE9\xEA\xEB", + \"MAP i\xEC\xED\xEE\xEF", + \"MAP o\xF2\xF3\xF4\xF5\xF6", + \"MAP u\xF9\xFA\xFB\xFC", + \"MAP n\xF1", + \"MAP c\xE7", + \"MAP y\xFF\xFD", + \"MAP s\xDF", + \"", + \"SAL AH(AEIOUY)-^ *H", + \"SAL AR(AEIOUY)-^ *R", + \"SAL A(HR)^ *", + \"SAL A^ *", + \"SAL AH(AEIOUY)- H", + \"SAL AR(AEIOUY)- R", + \"SAL A(HR) _", + \"SAL \xC0^ *", + \"SAL \xC5^ *", + \"SAL BB- _", + \"SAL B B", + \"SAL CQ- _", + \"SAL CIA X", + \"SAL CH X", + \"SAL C(EIY)- S", + \"SAL CK K", + \"SAL COUGH^ KF", + \"SAL CC< C", + \"SAL C K", + \"SAL DG(EIY) K", + \"SAL DD- _", + \"SAL D T", + \"SAL \xC9< E", + \"SAL EH(AEIOUY)-^ *H", + \"SAL ER(AEIOUY)-^ *R", + \"SAL E(HR)^ *", + \"SAL ENOUGH^$ *NF", + \"SAL E^ *", + \"SAL EH(AEIOUY)- H", + \"SAL ER(AEIOUY)- R", + \"SAL E(HR) _", + \"SAL FF- _", + \"SAL F F", + \"SAL GN^ N", + \"SAL GN$ N", + \"SAL GNS$ NS", + \"SAL GNED$ N", + \"SAL GH(AEIOUY)- K", + \"SAL GH _", + \"SAL GG9 K", + \"SAL G K", + \"SAL H H", + \"SAL IH(AEIOUY)-^ *H", + \"SAL IR(AEIOUY)-^ *R", + \"SAL I(HR)^ *", + \"SAL I^ *", + \"SAL ING6 N", + \"SAL IH(AEIOUY)- H", + \"SAL IR(AEIOUY)- R", + \"SAL I(HR) _", + \"SAL J K", + \"SAL KN^ N", + \"SAL KK- _", + \"SAL K K", + \"SAL LAUGH^ LF", + \"SAL LL- _", + \"SAL L L", + \"SAL MB$ M", + \"SAL MM M", + \"SAL M M", + \"SAL NN- _", + \"SAL N N", + \"SAL OH(AEIOUY)-^ *H", + \"SAL OR(AEIOUY)-^ *R", + \"SAL O(HR)^ *", + \"SAL O^ *", + \"SAL OH(AEIOUY)- H", + \"SAL OR(AEIOUY)- R", + \"SAL O(HR) _", + \"SAL PH F", + \"SAL PN^ N", + \"SAL PP- _", + \"SAL P P", + \"SAL Q K", + \"SAL RH^ R", + \"SAL ROUGH^ RF", + \"SAL RR- _", + \"SAL R R", + \"SAL SCH(EOU)- SK", + \"SAL SC(IEY)- S", + \"SAL SH X", + \"SAL SI(AO)- X", + \"SAL SS- _", + \"SAL S S", + \"SAL TI(AO)- X", + \"SAL TH @", + \"SAL TCH-- _", + \"SAL TOUGH^ TF", + \"SAL TT- _", + \"SAL T T", + \"SAL UH(AEIOUY)-^ *H", + \"SAL UR(AEIOUY)-^ *R", + \"SAL U(HR)^ *", + \"SAL U^ *", + \"SAL UH(AEIOUY)- H", + \"SAL UR(AEIOUY)- R", + \"SAL U(HR) _", + \"SAL V^ W", + \"SAL V F", + \"SAL WR^ R", + \"SAL WH^ W", + \"SAL W(AEIOU)- W", + \"SAL X^ S", + \"SAL X KS", + \"SAL Y(AEIOU)- Y", + \"SAL ZZ- _", + \"SAL Z S", + \ ] diff --git a/src/testdir/test_startup.vim b/src/testdir/test_startup.vim new file mode 100644 index 0000000..16b202f --- /dev/null +++ b/src/testdir/test_startup.vim @@ -0,0 +1,539 @@ +" Tests for startup. + +source shared.vim + +" Check that loading startup.vim works. +func Test_startup_script() + set compatible + source $VIMRUNTIME/defaults.vim + + call assert_equal(0, &compatible) +endfunc + +" Verify the order in which plugins are loaded: +" 1. plugins in non-after directories +" 2. packages +" 3. plugins in after directories +func Test_after_comes_later() + if !has('packages') + return + endif + let before = [ + \ 'set nocp viminfo+=nviminfo', + \ 'set guioptions+=M', + \ 'let $HOME = "/does/not/exist"', + \ 'set loadplugins', + \ 'set rtp=Xhere,Xafter,Xanother', + \ 'set packpath=Xhere,Xafter', + \ 'set nomore', + \ 'let g:sequence = ""', + \ ] + let after = [ + \ 'redir! > Xtestout', + \ 'scriptnames', + \ 'redir END', + \ 'redir! > Xsequence', + \ 'echo g:sequence', + \ 'redir END', + \ 'quit', + \ ] + call mkdir('Xhere/plugin', 'p') + call writefile(['let g:sequence .= "here "'], 'Xhere/plugin/here.vim') + call mkdir('Xanother/plugin', 'p') + call writefile(['let g:sequence .= "another "'], 'Xanother/plugin/another.vim') + call mkdir('Xhere/pack/foo/start/foobar/plugin', 'p') + call writefile(['let g:sequence .= "pack "'], 'Xhere/pack/foo/start/foobar/plugin/foo.vim') + + call mkdir('Xafter/plugin', 'p') + call writefile(['let g:sequence .= "after "'], 'Xafter/plugin/later.vim') + + if RunVim(before, after, '') + + let lines = readfile('Xtestout') + let expected = ['Xbefore.vim', 'here.vim', 'another.vim', 'foo.vim', 'later.vim', 'Xafter.vim'] + let found = [] + for line in lines + for one in expected + if line =~ one + call add(found, one) + endif + endfor + endfor + call assert_equal(expected, found) + endif + + call assert_equal('here another pack after', substitute(join(readfile('Xsequence', 1), ''), '\s\+$', '', '')) + + call delete('Xtestout') + call delete('Xsequence') + call delete('Xhere', 'rf') + call delete('Xanother', 'rf') + call delete('Xafter', 'rf') +endfunc + +func Test_pack_in_rtp_when_plugins_run() + if !has('packages') + return + endif + let before = [ + \ 'set nocp viminfo+=nviminfo', + \ 'set guioptions+=M', + \ 'let $HOME = "/does/not/exist"', + \ 'set loadplugins', + \ 'set rtp=Xhere', + \ 'set packpath=Xhere', + \ 'set nomore', + \ ] + let after = [ + \ 'quit', + \ ] + call mkdir('Xhere/plugin', 'p') + call writefile(['redir! > Xtestout', 'silent set runtimepath?', 'silent! call foo#Trigger()', 'redir END'], 'Xhere/plugin/here.vim') + call mkdir('Xhere/pack/foo/start/foobar/autoload', 'p') + call writefile(['function! foo#Trigger()', 'echo "autoloaded foo"', 'endfunction'], 'Xhere/pack/foo/start/foobar/autoload/foo.vim') + + if RunVim(before, after, '') + + let lines = filter(readfile('Xtestout'), '!empty(v:val)') + call assert_match('Xhere[/\\]pack[/\\]foo[/\\]start[/\\]foobar', get(lines, 0)) + call assert_match('autoloaded foo', get(lines, 1)) + endif + + call delete('Xtestout') + call delete('Xhere', 'rf') +endfunc + +func Test_help_arg() + if !has('unix') && has('gui') + " this doesn't work with gvim on MS-Windows + return + endif + if RunVim([], [], '--help >Xtestout') + let lines = readfile('Xtestout') + call assert_true(len(lines) > 20) + call assert_match('Vi IMproved', lines[0]) + + " check if couple of lines are there + let found = [] + for line in lines + if line =~ '-R.*Readonly mode' + call add(found, 'Readonly mode') + endif + " Watch out for a second --version line in the Gnome version. + if line =~ '--version.*Print version information and exit' + call add(found, "--version") + endif + endfor + call assert_equal(['Readonly mode', '--version'], found) + endif + call delete('Xtestout') +endfunc + +func Test_compatible_args() + let after = [ + \ 'call writefile([string(&compatible)], "Xtestout")', + \ 'set viminfo+=nviminfo', + \ 'quit', + \ ] + if RunVim([], after, '-C') + let lines = readfile('Xtestout') + call assert_equal('1', lines[0]) + endif + + if RunVim([], after, '-N') + let lines = readfile('Xtestout') + call assert_equal('0', lines[0]) + endif + + call delete('Xtestout') +endfunc + +" Test the -o[N] and -O[N] arguments to open N windows split +" horizontally or vertically. +func Test_o_arg() + let after = [ + \ 'call writefile([winnr("$"), + \ winheight(1), winheight(2), &lines, + \ winwidth(1), winwidth(2), &columns, + \ bufname(winbufnr(1)), bufname(winbufnr(2))], + \ "Xtestout")', + \ 'qall', + \ ] + if RunVim([], after, '-o2') + " Open 2 windows split horizontally. Expect: + " - 2 windows + " - both windows should have the same or almost the same height + " - sum of both windows height (+ 3 for both statusline and Ex command) + " should be equal to the number of lines + " - both windows should have the same width which should be equal to the + " number of columns + " - buffer of both windows should have no name + let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout') + call assert_equal('2', wn) + call assert_inrange(0, 1, wh1 - wh2) + call assert_equal(string(wh1 + wh2 + 3), ln) + call assert_equal(ww1, ww2) + call assert_equal(ww1, cn) + call assert_equal('', bn1) + call assert_equal('', bn2) + endif + + if RunVim([], after, '-o foo bar') + " Same expectations as for -o2 but buffer names should be foo and bar + let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout') + call assert_equal('2', wn) + call assert_inrange(0, 1, wh1 - wh2) + call assert_equal(string(wh1 + wh2 + 3), ln) + call assert_equal(ww1, ww2) + call assert_equal(ww1, cn) + call assert_equal('foo', bn1) + call assert_equal('bar', bn2) + endif + + if RunVim([], after, '-O2') + " Open 2 windows split vertically. Expect: + " - 2 windows + " - both windows should have the same or almost the same width + " - sum of both windows width (+ 1 for the separator) should be equal to + " the number of columns + " - both windows should have the same height + " - window height (+ 2 for the statusline and Ex command) should be equal + " to the number of lines + " - buffer of both windows should have no name + let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout') + call assert_equal('2', wn) + call assert_inrange(0, 1, ww1 - ww2) + call assert_equal(string(ww1 + ww2 + 1), cn) + call assert_equal(wh1, wh2) + call assert_equal(string(wh1 + 2), ln) + call assert_equal('', bn1) + call assert_equal('', bn2) + endif + + if RunVim([], after, '-O foo bar') + " Same expectations as for -O2 but buffer names should be foo and bar + let [wn, wh1, wh2, ln, ww1, ww2, cn, bn1, bn2] = readfile('Xtestout') + call assert_equal('2', wn) + call assert_inrange(0, 1, ww1 - ww2) + call assert_equal(string(ww1 + ww2 + 1), cn) + call assert_equal(wh1, wh2) + call assert_equal(string(wh1 + 2), ln) + call assert_equal('foo', bn1) + call assert_equal('bar', bn2) + endif + + call delete('Xtestout') +endfunc + +" Test the -p[N] argument to open N tabpages. +func Test_p_arg() + let after = [ + \ 'call writefile(split(execute("tabs"), "\n"), "Xtestout")', + \ 'qall', + \ ] + if RunVim([], after, '-p2') + let lines = readfile('Xtestout') + call assert_equal(4, len(lines)) + call assert_equal('Tab page 1', lines[0]) + call assert_equal('> [No Name]', lines[1]) + call assert_equal('Tab page 2', lines[2]) + call assert_equal(' [No Name]', lines[3]) + endif + + if RunVim([], after, '-p foo bar') + let lines = readfile('Xtestout') + call assert_equal(4, len(lines)) + call assert_equal('Tab page 1', lines[0]) + call assert_equal('> foo', lines[1]) + call assert_equal('Tab page 2', lines[2]) + call assert_equal(' bar', lines[3]) + endif + + call delete('Xtestout') +endfunc + +" Test the -V[N] argument to set the 'verbose' option to [N] +func Test_V_arg() + if has('gui_running') + " Can't catch the output of gvim. + return + endif + let out = system(GetVimCommand() . ' --clean -es -X -V0 -c "set verbose?" -cq') + call assert_equal(" verbose=0\n", out) + + let out = system(GetVimCommand() . ' --clean -es -X -V2 -c "set verbose?" -cq') + call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nSearching for \"filetype\.vim\".*\n", out) + call assert_match(" verbose=2\n", out) + + let out = system(GetVimCommand() . ' --clean -es -X -V15 -c "set verbose?" -cq') + call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\r\nline 1: \" The default vimrc file\..* verbose=15\n", out) +endfunc + +" Test the '-q [errorfile]' argument. +func Test_q_arg() + let source_file = has('win32') ? '..\memfile.c' : '../memfile.c' + let after = [ + \ 'call writefile([&errorfile, string(getpos("."))], "Xtestout")', + \ 'copen', + \ 'w >> Xtestout', + \ 'qall' + \ ] + + " Test with default argument '-q'. + call assert_equal('errors.err', &errorfile) + call writefile(["../memfile.c:1482:5: error: expected ';' before '}' token"], 'errors.err') + if RunVim([], after, '-q') + let lines = readfile('Xtestout') + call assert_equal(['errors.err', + \ '[0, 1482, 5, 0]', + \ source_file . "|1482 col 5| error: expected ';' before '}' token"], + \ lines) + endif + call delete('Xtestout') + call delete('errors.err') + + " Test with explicit argument '-q Xerrors' (with space). + call writefile(["../memfile.c:1482:5: error: expected ';' before '}' token"], 'Xerrors') + if RunVim([], after, '-q Xerrors') + let lines = readfile('Xtestout') + call assert_equal(['Xerrors', + \ '[0, 1482, 5, 0]', + \ source_file . "|1482 col 5| error: expected ';' before '}' token"], + \ lines) + endif + call delete('Xtestout') + + " Test with explicit argument '-qXerrors' (without space). + if RunVim([], after, '-qXerrors') + let lines = readfile('Xtestout') + call assert_equal(['Xerrors', + \ '[0, 1482, 5, 0]', + \ source_file . "|1482 col 5| error: expected ';' before '}' token"], + \ lines) + endif + + call delete('Xtestout') + call delete('Xerrors') +endfunc + +" Test the -V[N]{filename} argument to set the 'verbose' option to N +" and set 'verbosefile' to filename. +func Test_V_file_arg() + if RunVim([], [], ' --clean -V2Xverbosefile -c "set verbose? verbosefile?" -cq') + let out = join(readfile('Xverbosefile'), "\n") + call assert_match("sourcing \"$VIMRUNTIME[\\/]defaults\.vim\"\n", out) + call assert_match("\n verbose=2\n", out) + call assert_match("\n verbosefile=Xverbosefile", out) + endif + + call delete('Xverbosefile') +endfunc + +" Test the -m, -M and -R arguments: +" -m resets 'write' +" -M resets 'modifiable' and 'write' +" -R sets 'readonly' +func Test_m_M_R() + let after = [ + \ 'call writefile([&write, &modifiable, &readonly, &updatecount], "Xtestout")', + \ 'qall', + \ ] + if RunVim([], after, '') + let lines = readfile('Xtestout') + call assert_equal(['1', '1', '0', '200'], lines) + endif + if RunVim([], after, '-m') + let lines = readfile('Xtestout') + call assert_equal(['0', '1', '0', '200'], lines) + endif + if RunVim([], after, '-M') + let lines = readfile('Xtestout') + call assert_equal(['0', '0', '0', '200'], lines) + endif + if RunVim([], after, '-R') + let lines = readfile('Xtestout') + call assert_equal(['1', '1', '1', '10000'], lines) + endif + + call delete('Xtestout') +endfunc + +" Test the -A, -F and -H arguments (Arabic, Farsi and Hebrew modes). +func Test_A_F_H_arg() + let after = [ + \ 'call writefile([&rightleft, &arabic, &fkmap, &hkmap], "Xtestout")', + \ 'qall', + \ ] + " Use silent Ex mode to avoid the hit-Enter prompt for the warning that + " 'encoding' is not utf-8. + if has('arabic') && &encoding == 'utf-8' && RunVim([], after, '-e -s -A') + let lines = readfile('Xtestout') + call assert_equal(['1', '1', '0', '0'], lines) + endif + + if has('farsi') && RunVim([], after, '-F') + let lines = readfile('Xtestout') + call assert_equal(['1', '0', '1', '0'], lines) + endif + + if has('rightleft') && RunVim([], after, '-H') + let lines = readfile('Xtestout') + call assert_equal(['1', '0', '0', '1'], lines) + endif + + call delete('Xtestout') +endfunc + +func Test_file_args() + let after = [ + \ 'call writefile(argv(), "Xtestout")', + \ 'qall', + \ ] + if RunVim([], after, '') + let lines = readfile('Xtestout') + call assert_equal(0, len(lines)) + endif + + if RunVim([], after, 'one') + let lines = readfile('Xtestout') + call assert_equal(1, len(lines)) + call assert_equal('one', lines[0]) + endif + + if RunVim([], after, 'one two three') + let lines = readfile('Xtestout') + call assert_equal(3, len(lines)) + call assert_equal('one', lines[0]) + call assert_equal('two', lines[1]) + call assert_equal('three', lines[2]) + endif + + if RunVim([], after, 'one -c echo two') + let lines = readfile('Xtestout') + call assert_equal(2, len(lines)) + call assert_equal('one', lines[0]) + call assert_equal('two', lines[1]) + endif + + if RunVim([], after, 'one -- -c echo two') + let lines = readfile('Xtestout') + call assert_equal(4, len(lines)) + call assert_equal('one', lines[0]) + call assert_equal('-c', lines[1]) + call assert_equal('echo', lines[2]) + call assert_equal('two', lines[3]) + endif + + call delete('Xtestout') +endfunc + +func Test_startuptime() + if !has('startuptime') + return + endif + let after = ['qall'] + if RunVim([], after, '--startuptime Xtestout one') + let lines = readfile('Xtestout') + let expected = ['--- VIM STARTING ---', 'parsing arguments', + \ 'shell init', 'inits 3', 'start termcap', 'opening buffers'] + let found = [] + for line in lines + for exp in expected + if line =~ exp + call add(found, exp) + endif + endfor + endfor + call assert_equal(expected, found) + endif + call delete('Xtestout') +endfunc + +func Test_read_stdin() + let after = [ + \ 'write Xtestout', + \ 'quit!', + \ ] + if RunVimPiped([], after, '-', 'echo something | ') + let lines = readfile('Xtestout') + " MS-Windows adds a space after the word + call assert_equal(['something'], split(lines[0])) + endif + call delete('Xtestout') +endfunc + +func Test_set_shell() + let after = [ + \ 'call writefile([&shell], "Xtestout")', + \ 'quit!', + \ ] + let $SHELL = '/bin/with space/sh' + if RunVimPiped([], after, '', '') + let lines = readfile('Xtestout') + " MS-Windows adds a space after the word + call assert_equal('/bin/with\ space/sh', lines[0]) + endif + call delete('Xtestout') +endfunc + +func Test_progpath() + " Tests normally run with "./vim" or "../vim", these must have been expanded + " to a full path. + if has('unix') + call assert_equal('/', v:progpath[0]) + elseif has('win32') + call assert_equal(':', v:progpath[1]) + call assert_match('[/\\]', v:progpath[2]) + endif + + " Only expect "vim" to appear in v:progname. + call assert_match('vim\c', v:progname) +endfunc + +func Test_silent_ex_mode() + if !has('unix') || has('gui_running') + " can't get output of Vim. + return + endif + + " This caused an ml_get error. + let out = system(GetVimCommand() . '-u NONE -es -c''set verbose=1|h|exe "%norm\<c-y>\<c-d>"'' -c cq') + call assert_notmatch('E315:', out) +endfunc + +func Test_default_term() + if !has('unix') || has('gui_running') + " can't get output of Vim. + return + endif + + let save_term = $TERM + let $TERM = 'unknownxxx' + let out = system(GetVimCommand() . ' -c''set term'' -c cq') + call assert_match("defaulting to 'ansi'", out) + let $TERM = save_term +endfunc + +func Test_zzz_startinsert() + " Test :startinsert + call writefile(['123456'], 'Xtestout') + let after = [ + \ ':startinsert', + \ 'call feedkeys("foobar\<c-o>:wq\<cr>","t")' + \ ] + if RunVim([], after, 'Xtestout') + let lines = readfile('Xtestout') + call assert_equal(['foobar123456'], lines) + endif + " Test :startinsert! + call writefile(['123456'], 'Xtestout') + let after = [ + \ ':startinsert!', + \ 'call feedkeys("foobar\<c-o>:wq\<cr>","t")' + \ ] + if RunVim([], after, 'Xtestout') + let lines = readfile('Xtestout') + call assert_equal(['123456foobar'], lines) + endif + call delete('Xtestout') +endfunc diff --git a/src/testdir/test_startup_utf8.vim b/src/testdir/test_startup_utf8.vim new file mode 100644 index 0000000..8b3eca1 --- /dev/null +++ b/src/testdir/test_startup_utf8.vim @@ -0,0 +1,83 @@ +" Tests for startup using utf-8. + +source shared.vim +source screendump.vim + +func Test_read_stdin_utf8() + let linesin = ['テスト', '€ÀÈÌÒÙ'] + call writefile(linesin, 'Xtestin') + let before = [ + \ 'set enc=utf-8', + \ 'set fencs=cp932,utf-8', + \ ] + let after = [ + \ 'write ++enc=utf-8 Xtestout', + \ 'quit!', + \ ] + if has('win32') + let pipecmd = 'type Xtestin | ' + else + let pipecmd = 'cat Xtestin | ' + endif + if RunVimPiped(before, after, '-', pipecmd) + let lines = readfile('Xtestout') + call assert_equal(linesin, lines) + else + call assert_equal('', 'RunVimPiped failed.') + endif + call delete('Xtestout') + call delete('Xtestin') +endfunc + +func Test_read_fifo_utf8() + if !has('unix') + return + endif + " Using bash/zsh's process substitution. + if executable('bash') + set shell=bash + elseif executable('zsh') + set shell=zsh + else + return + endif + let linesin = ['テスト', '€ÀÈÌÒÙ'] + call writefile(linesin, 'Xtestin') + let before = [ + \ 'set enc=utf-8', + \ 'set fencs=cp932,utf-8', + \ ] + let after = [ + \ 'write ++enc=utf-8 Xtestout', + \ 'quit!', + \ ] + if RunVim(before, after, '<(cat Xtestin)') + let lines = readfile('Xtestout') + call assert_equal(linesin, lines) + else + call assert_equal('', 'RunVim failed.') + endif + call delete('Xtestout') + call delete('Xtestin') +endfunc + +func Test_detect_ambiwidth() + if !CanRunVimInTerminal() + return + endif + + " Use the title termcap entries to output the escape sequence. + call writefile([ + \ 'set enc=utf-8', + \ 'set ambiwidth=double', + \ 'call test_option_not_set("ambiwidth")', + \ 'redraw', + \ ], 'Xscript') + let buf = RunVimInTerminal('-S Xscript', {}) + call term_wait(buf) + call term_sendkeys(buf, "S\<C-R>=&ambiwidth\<CR>\<Esc>") + call WaitForAssert({-> assert_match('single', term_getline(buf, 1))}) + + call StopVimInTerminal(buf) + call delete('Xscript') +endfunc diff --git a/src/testdir/test_stat.vim b/src/testdir/test_stat.vim new file mode 100644 index 0000000..e48e887 --- /dev/null +++ b/src/testdir/test_stat.vim @@ -0,0 +1,185 @@ +" Tests for stat functions and checktime + +func CheckFileTime(doSleep) + let fnames = ['Xtest1.tmp', 'Xtest2.tmp', 'Xtest3.tmp'] + let times = [] + let result = 0 + + " Use three files istead of localtim(), with a network filesystem the file + " times may differ at bit + let fl = ['Hello World!'] + for fname in fnames + call writefile(fl, fname) + call add(times, getftime(fname)) + if a:doSleep + sleep 1 + endif + endfor + + let time_correct = (times[0] <= times[1] && times[1] <= times[2]) + if a:doSleep || time_correct + call assert_true(time_correct, printf('Expected %s <= %s <= %s', times[0], times[1], times[2])) + call assert_equal(strlen(fl[0] . "\n"), getfsize(fnames[0])) + call assert_equal('file', getftype(fnames[0])) + call assert_equal('rw-', getfperm(fnames[0])[0:2]) + let result = 1 + endif + + for fname in fnames + call delete(fname) + endfor + return result +endfunc + +func Test_existent_file() + " On some systems the file timestamp is rounded to a multiple of 2 seconds. + " We need to sleep to handle that, but that makes the test slow. First try + " without the sleep, and if it fails try again with the sleep. + if CheckFileTime(0) == 0 + call CheckFileTime(1) + endif +endfunc + +func Test_existent_directory() + let dname = '.' + + call assert_equal(0, getfsize(dname)) + call assert_equal('dir', getftype(dname)) + call assert_equal('rwx', getfperm(dname)[0:2]) +endfunc + +func SleepForTimestamp() + " FAT has a granularity of 2 seconds, otherwise it's usually 1 second + if has('win32') + sleep 2 + else + sleep 1 + endif +endfunc + +func Test_checktime() + let fname = 'Xtest.tmp' + + let fl = ['Hello World!'] + call writefile(fl, fname) + set autoread + exec 'e' fname + call SleepForTimestamp() + let fl = readfile(fname) + let fl[0] .= ' - checktime' + call writefile(fl, fname) + checktime + call assert_equal(fl[0], getline(1)) + + call delete(fname) +endfunc + +func Test_autoread_file_deleted() + new Xautoread + set autoread + call setline(1, 'original') + w! + + call SleepForTimestamp() + if has('win32') + silent !echo changed > Xautoread + else + silent !echo 'changed' > Xautoread + endif + checktime + call assert_equal('changed', trim(getline(1))) + + call SleepForTimestamp() + messages clear + if has('win32') + silent !del Xautoread + else + silent !rm Xautoread + endif + checktime + call assert_match('E211:', execute('messages')) + call assert_equal('changed', trim(getline(1))) + + call SleepForTimestamp() + if has('win32') + silent !echo recreated > Xautoread + else + silent !echo 'recreated' > Xautoread + endif + checktime + call assert_equal('recreated', trim(getline(1))) + + call delete('Xautoread') + bwipe! +endfunc + + +func Test_nonexistent_file() + let fname = 'Xtest.tmp' + + call delete(fname) + call assert_equal(-1, getftime(fname)) + call assert_equal(-1, getfsize(fname)) + call assert_equal('', getftype(fname)) + call assert_equal('', getfperm(fname)) +endfunc + +func Test_getftype() + call assert_equal('file', getftype(v:progpath)) + call assert_equal('dir', getftype('.')) + + if !has('unix') + return + endif + + silent !ln -s Xfile Xlink + call assert_equal('link', getftype('Xlink')) + call delete('Xlink') + + if executable('mkfifo') + silent !mkfifo Xfifo + call assert_equal('fifo', getftype('Xfifo')) + call delete('Xfifo') + endif + + for cdevfile in systemlist('find /dev -type c -maxdepth 2 2>/dev/null') + let type = getftype(cdevfile) + " ignore empty result, can happen if the file disappeared + if type != '' + call assert_equal('cdev', type) + endif + endfor + + for bdevfile in systemlist('find /dev -type b -maxdepth 2 2>/dev/null') + let type = getftype(bdevfile) + " ignore empty result, can happen if the file disappeared + if type != '' + call assert_equal('bdev', type) + endif + endfor + + " The /run/ directory typically contains socket files. + " If it does not, test won't fail but will not test socket files. + for socketfile in systemlist('find /run -type s -maxdepth 2 2>/dev/null') + let type = getftype(socketfile) + " ignore empty result, can happen if the file disappeared + if type != '' + call assert_equal('socket', type) + endif + endfor + + " TODO: file type 'other' is not tested. How can we test it? +endfunc + +func Test_win32_symlink_dir() + " On Windows, non-admin users cannot create symlinks. + " So we use an existing symlink for this test. + if has('win32') + " Check if 'C:\Users\All Users' is a symlink to a directory. + let res = system('dir C:\Users /a') + if match(res, '\C<SYMLINKD> *All Users') >= 0 + " Get the filetype of the symlink. + call assert_equal('dir', getftype('C:\Users\All Users')) + endif + endif +endfunc diff --git a/src/testdir/test_statusline.vim b/src/testdir/test_statusline.vim new file mode 100644 index 0000000..eafbecd --- /dev/null +++ b/src/testdir/test_statusline.vim @@ -0,0 +1,343 @@ +" Test 'statusline' +" +" Not tested yet: +" %a +" %N +" %T +" %X + +source view_util.vim + +func s:get_statusline() + return ScreenLines(&lines - 1, &columns)[0] +endfunc + +func StatuslineWithCaughtError() + let s:func_in_statusline_called = 1 + try + call eval('unknown expression') + catch + endtry + return '' +endfunc + +func StatuslineWithError() + let s:func_in_statusline_called = 1 + call eval('unknown expression') + return '' +endfunc + +" Function used to display syntax group. +func SyntaxItem() + return synIDattr(synID(line("."),col("."),1),"name") +endfunc + +func Test_caught_error_in_statusline() + let s:func_in_statusline_called = 0 + set laststatus=2 + let statusline = '%{StatuslineWithCaughtError()}' + let &statusline = statusline + redrawstatus + call assert_true(s:func_in_statusline_called) + call assert_equal(statusline, &statusline) + set statusline= +endfunc + +func Test_statusline_will_be_disabled_with_error() + let s:func_in_statusline_called = 0 + set laststatus=2 + let statusline = '%{StatuslineWithError()}' + try + let &statusline = statusline + redrawstatus + catch + endtry + call assert_true(s:func_in_statusline_called) + call assert_equal('', &statusline) + set statusline= +endfunc + +func Test_statusline() + new Xstatusline + only + set laststatus=2 + set splitbelow + call setline(1, range(1, 200)) + + " %b: Value of character under cursor. + " %B: As above, in hexadecimal. + call cursor(180, 2) + set statusline=%b,%B + call assert_match('^56,38\s*$', s:get_statusline()) + + " %o: Byte number in file of byte under cursor, first byte is 1. + " %O: As above, in hexadecimal. + set statusline=%o,%O + set fileformat=dos + call assert_match('^789,315\s*$', s:get_statusline()) + set fileformat=mac + call assert_match('^610,262\s*$', s:get_statusline()) + set fileformat=unix + call assert_match('^610,262\s*$', s:get_statusline()) + set fileformat& + + " %f: Path to the file in the buffer, as typed or relative to current dir. + set statusline=%f + call assert_match('^Xstatusline\s*$', s:get_statusline()) + + " %F: Full path to the file in the buffer. + set statusline=%F + call assert_match('/testdir/Xstatusline\s*$', s:get_statusline()) + + " %h: Help buffer flag, text is "[help]". + " %H: Help buffer flag, text is ",HLP". + set statusline=%h,%H + call assert_match('^,\s*$', s:get_statusline()) + help + call assert_match('^\[Help\],HLP\s*$', s:get_statusline()) + helpclose + + " %k: Value of "b:keymap_name" or 'keymap' + " when :lmap mappings are being used: <keymap>" + set statusline=%k + if has('keymap') + set keymap=esperanto + call assert_match('^<Eo>\s*$', s:get_statusline()) + set keymap& + else + call assert_match('^\s*$', s:get_statusline()) + endif + + " %l: Line number. + " %L: Number of line in buffer. + " %c: Column number. + set statusline=%l/%L,%c + call assert_match('^180/200,2\s*$', s:get_statusline()) + + " %m: Modified flag, text is "[+]", "[-]" if 'modifiable' is off. + " %M: Modified flag, text is ",+" or ",-". + set statusline=%m%M + call assert_match('^\[+\],+\s*$', s:get_statusline()) + set nomodifiable + call assert_match('^\[+-\],+-\s*$', s:get_statusline()) + write + call assert_match('^\[-\],-\s*$', s:get_statusline()) + set modifiable& + call assert_match('^\s*$', s:get_statusline()) + + " %n: Buffer number. + set statusline=%n + call assert_match('^'.bufnr('%').'\s*$', s:get_statusline()) + + " %p: Percentage through file in lines as in CTRL-G. + " %P: Percentage through file of displayed window. + set statusline=%p,%P + 0 + call assert_match('^0,Top\s*$', s:get_statusline()) + norm G + call assert_match('^100,Bot\s*$', s:get_statusline()) + 180 + " Don't check the exact percentage as it depends on the window size + call assert_match('^90,\(Top\|Bot\|\d\+%\)\s*$', s:get_statusline()) + + " %q: "[Quickfix List]", "[Location List]" or empty. + set statusline=%q + call assert_match('^\s*$', s:get_statusline()) + copen + call assert_match('^\[Quickfix List\]\s*$', s:get_statusline()) + cclose + lexpr getline(1, 2) + lopen + call assert_match('^\[Location List\]\s*$', s:get_statusline()) + lclose + + " %r: Readonly flag, text is "[RO]". + " %R: Readonly flag, text is ",RO". + set statusline=%r,%R + call assert_match('^,\s*$', s:get_statusline()) + help + call assert_match('^\[RO\],RO\s*$', s:get_statusline()) + helpclose + + " %t: File name (tail) of file in the buffer. + set statusline=%t + call assert_match('^Xstatusline\s*$', s:get_statusline()) + + " %v: Virtual column number. + " %V: Virtual column number as -{num}. Not displayed if equal to 'c'. + call cursor(180, 2) + set statusline=%v,%V + call assert_match('^2,\s*$', s:get_statusline()) + set virtualedit=all + norm 10| + call assert_match('^10,-10\s*$', s:get_statusline()) + set virtualedit& + + " %w: Preview window flag, text is "[Preview]". + " %W: Preview window flag, text is ",PRV". + set statusline=%w%W + call assert_match('^\s*$', s:get_statusline()) + pedit + wincmd j + call assert_match('^\[Preview\],PRV\s*$', s:get_statusline()) + pclose + + " %y: Type of file in the buffer, e.g., "[vim]". See 'filetype'. + " %Y: Type of file in the buffer, e.g., ",VIM". See 'filetype'. + set statusline=%y\ %Y + call assert_match('^\s*$', s:get_statusline()) + setfiletype vim + call assert_match('^\[vim\] VIM\s*$', s:get_statusline()) + + " %=: Separation point between left and right aligned items. + set statusline=foo%=bar + call assert_match('^foo\s\+bar\s*$', s:get_statusline()) + + " Test min/max width, leading zeroes, left/right justify. + set statusline=%04B + call cursor(180, 2) + call assert_match('^0038\s*$', s:get_statusline()) + set statusline=#%4B# + call assert_match('^# 38#\s*$', s:get_statusline()) + set statusline=#%-4B# + call assert_match('^#38 #\s*$', s:get_statusline()) + set statusline=%.6f + call assert_match('^<sline\s*$', s:get_statusline()) + + " %<: Where to truncate. + exe 'set statusline=a%<b' . repeat('c', 1000) . 'd' + call assert_match('^a<c*d$', s:get_statusline()) + exe 'set statusline=a' . repeat('b', 1000) . '%<c' + call assert_match('^ab*>$', s:get_statusline()) + + "%{: Evaluate expression between '%{' and '}' and substitute result. + syntax on + set statusline=%{SyntaxItem()} + call assert_match('^vimNumber\s*$', s:get_statusline()) + s/^/"/ + call assert_match('^vimLineComment\s*$', s:get_statusline()) + syntax off + + "%(: Start of item group. + set statusline=ab%(cd%q%)de + call assert_match('^abde\s*$', s:get_statusline()) + copen + call assert_match('^abcd\[Quickfix List]de\s*$', s:get_statusline()) + cclose + + " %#: Set highlight group. The name must follow and then a # again. + set statusline=ab%#Todo#cd%#Error#ef + call assert_match('^abcdef\s*$', s:get_statusline()) + let sa1=screenattr(&lines - 1, 1) + let sa2=screenattr(&lines - 1, 3) + let sa3=screenattr(&lines - 1, 5) + call assert_notequal(sa1, sa2) + call assert_notequal(sa1, sa3) + call assert_notequal(sa2, sa3) + call assert_equal(sa1, screenattr(&lines - 1, 2)) + call assert_equal(sa2, screenattr(&lines - 1, 4)) + call assert_equal(sa3, screenattr(&lines - 1, 6)) + call assert_equal(sa3, screenattr(&lines - 1, 7)) + + " %*: Set highlight group to User{N} + set statusline=a%1*b%0*c + call assert_match('^abc\s*$', s:get_statusline()) + let sa1=screenattr(&lines - 1, 1) + let sa2=screenattr(&lines - 1, 2) + let sa3=screenattr(&lines - 1, 3) + call assert_equal(sa1, sa3) + call assert_notequal(sa1, sa2) + + " An empty group that contains highlight changes + let g:a = '' + set statusline=ab%(cd%1*%{g:a}%*%)de + call assert_match('^abde\s*$', s:get_statusline()) + let sa1=screenattr(&lines - 1, 1) + let sa2=screenattr(&lines - 1, 4) + call assert_equal(sa1, sa2) + let g:a = 'X' + call assert_match('^abcdXde\s*$', s:get_statusline()) + let sa1=screenattr(&lines - 1, 1) + let sa2=screenattr(&lines - 1, 5) + let sa3=screenattr(&lines - 1, 7) + call assert_equal(sa1, sa3) + call assert_notequal(sa1, sa2) + + let g:a = '' + set statusline=ab%1*%(cd%*%{g:a}%1*%)de + call assert_match('^abde\s*$', s:get_statusline()) + let sa1=screenattr(&lines - 1, 1) + let sa2=screenattr(&lines - 1, 4) + call assert_notequal(sa1, sa2) + let g:a = 'X' + call assert_match('^abcdXde\s*$', s:get_statusline()) + let sa1=screenattr(&lines - 1, 1) + let sa2=screenattr(&lines - 1, 3) + let sa3=screenattr(&lines - 1, 5) + let sa4=screenattr(&lines - 1, 7) + call assert_notequal(sa1, sa2) + call assert_equal(sa1, sa3) + call assert_equal(sa2, sa4) + + " An empty group that contains highlight changes and doesn't reset them + let g:a = '' + set statusline=ab%(cd%1*%{g:a}%)de + call assert_match('^abcdde\s*$', s:get_statusline()) + let sa1=screenattr(&lines - 1, 1) + let sa2=screenattr(&lines - 1, 5) + call assert_notequal(sa1, sa2) + let g:a = 'X' + call assert_match('^abcdXde\s*$', s:get_statusline()) + let sa1=screenattr(&lines - 1, 1) + let sa2=screenattr(&lines - 1, 5) + let sa3=screenattr(&lines - 1, 7) + call assert_notequal(sa1, sa2) + call assert_equal(sa2, sa3) + + let g:a = '' + set statusline=ab%1*%(cd%*%{g:a}%)de + call assert_match('^abcdde\s*$', s:get_statusline()) + let sa1=screenattr(&lines - 1, 1) + let sa2=screenattr(&lines - 1, 3) + let sa3=screenattr(&lines - 1, 5) + call assert_notequal(sa1, sa2) + call assert_equal(sa1, sa3) + let g:a = 'X' + call assert_match('^abcdXde\s*$', s:get_statusline()) + let sa1=screenattr(&lines - 1, 1) + let sa2=screenattr(&lines - 1, 3) + let sa3=screenattr(&lines - 1, 5) + let sa4=screenattr(&lines - 1, 7) + call assert_notequal(sa1, sa2) + call assert_equal(sa1, sa3) + call assert_equal(sa1, sa4) + + let g:a = '' + set statusline=%#Error#{%(\ %{g:a}\ %)} + call assert_match('^{}\s*$', s:get_statusline()) + let g:a = 'X' + call assert_match('^{ X }\s*$', s:get_statusline()) + + " %%: a percent sign. + set statusline=10%% + call assert_match('^10%\s*$', s:get_statusline()) + + " %!: evaluated expression is used as the option value + set statusline=%!2*3+1 + call assert_match('7\s*$', s:get_statusline()) + + " Check statusline in current and non-current window + " with the 'fillchars' option. + set fillchars=stl:^,stlnc:=,vert:\|,fold:-,diff:- + vsplit + set statusline=x%=y + call assert_match('^x^\+y^x=\+y$', s:get_statusline()) + set fillchars& + close + + %bw! + call delete('Xstatusline') + set statusline& + set laststatus& + set splitbelow& +endfunc diff --git a/src/testdir/test_substitute.vim b/src/testdir/test_substitute.vim new file mode 100644 index 0000000..d84daa7 --- /dev/null +++ b/src/testdir/test_substitute.vim @@ -0,0 +1,502 @@ +" Tests for multi-line regexps with ":s". + +func Test_multiline_subst() + enew! + call append(0, ["1 aa", + \ "bb", + \ "cc", + \ "2 dd", + \ "ee", + \ "3 ef", + \ "gh", + \ "4 ij", + \ "5 a8", + \ "8b c9", + \ "9d", + \ "6 e7", + \ "77f", + \ "xxxxx"]) + + 1 + " test if replacing a line break works with a back reference + /^1/,/^2/s/\n\(.\)/ \1/ + " test if inserting a line break works with a back reference + /^3/,/^4/s/\(.\)$/\r\1/ + " test if replacing a line break with another line break works + /^5/,/^6/s/\(\_d\{3}\)/x\1x/ + call assert_equal('1 aa bb cc 2 dd ee', getline(1)) + call assert_equal('3 e', getline(2)) + call assert_equal('f', getline(3)) + call assert_equal('g', getline(4)) + call assert_equal('h', getline(5)) + call assert_equal('4 i', getline(6)) + call assert_equal('j', getline(7)) + call assert_equal('5 ax8', getline(8)) + call assert_equal('8xb cx9', getline(9)) + call assert_equal('9xd', getline(10)) + call assert_equal('6 ex7', getline(11)) + call assert_equal('7x7f', getline(12)) + call assert_equal('xxxxx', getline(13)) + enew! +endfunc + +func Test_substitute_variants() + " Validate that all the 2-/3-letter variants which embed the flags into the + " command name actually work. + enew! + let ln = 'Testing string' + let variants = [ + \ { 'cmd': ':s/Test/test/c', 'exp': 'testing string', 'prompt': 'y' }, + \ { 'cmd': ':s/foo/bar/ce', 'exp': ln }, + \ { 'cmd': ':s/t/r/cg', 'exp': 'Tesring srring', 'prompt': 'a' }, + \ { 'cmd': ':s/t/r/ci', 'exp': 'resting string', 'prompt': 'y' }, + \ { 'cmd': ':s/t/r/cI', 'exp': 'Tesring string', 'prompt': 'y' }, + \ { 'cmd': ':s/t/r/cn', 'exp': ln }, + \ { 'cmd': ':s/t/r/cp', 'exp': 'Tesring string', 'prompt': 'y' }, + \ { 'cmd': ':s/t/r/cl', 'exp': 'Tesring string', 'prompt': 'y' }, + \ { 'cmd': ':s/t/r/gc', 'exp': 'Tesring srring', 'prompt': 'a' }, + \ { 'cmd': ':s/foo/bar/ge', 'exp': ln }, + \ { 'cmd': ':s/t/r/g', 'exp': 'Tesring srring' }, + \ { 'cmd': ':s/t/r/gi', 'exp': 'resring srring' }, + \ { 'cmd': ':s/t/r/gI', 'exp': 'Tesring srring' }, + \ { 'cmd': ':s/t/r/gn', 'exp': ln }, + \ { 'cmd': ':s/t/r/gp', 'exp': 'Tesring srring' }, + \ { 'cmd': ':s/t/r/gl', 'exp': 'Tesring srring' }, + \ { 'cmd': ':s//r/gr', 'exp': 'Testr strr' }, + \ { 'cmd': ':s/t/r/ic', 'exp': 'resting string', 'prompt': 'y' }, + \ { 'cmd': ':s/foo/bar/ie', 'exp': ln }, + \ { 'cmd': ':s/t/r/i', 'exp': 'resting string' }, + \ { 'cmd': ':s/t/r/iI', 'exp': 'Tesring string' }, + \ { 'cmd': ':s/t/r/in', 'exp': ln }, + \ { 'cmd': ':s/t/r/ip', 'exp': 'resting string' }, + \ { 'cmd': ':s//r/ir', 'exp': 'Testr string' }, + \ { 'cmd': ':s/t/r/Ic', 'exp': 'Tesring string', 'prompt': 'y' }, + \ { 'cmd': ':s/foo/bar/Ie', 'exp': ln }, + \ { 'cmd': ':s/t/r/Ig', 'exp': 'Tesring srring' }, + \ { 'cmd': ':s/t/r/Ii', 'exp': 'resting string' }, + \ { 'cmd': ':s/t/r/I', 'exp': 'Tesring string' }, + \ { 'cmd': ':s/t/r/Ip', 'exp': 'Tesring string' }, + \ { 'cmd': ':s/t/r/Il', 'exp': 'Tesring string' }, + \ { 'cmd': ':s//r/Ir', 'exp': 'Testr string' }, + \ { 'cmd': ':s//r/rc', 'exp': 'Testr string', 'prompt': 'y' }, + \ { 'cmd': ':s//r/rg', 'exp': 'Testr strr' }, + \ { 'cmd': ':s//r/ri', 'exp': 'Testr string' }, + \ { 'cmd': ':s//r/rI', 'exp': 'Testr string' }, + \ { 'cmd': ':s//r/rn', 'exp': 'Testing string' }, + \ { 'cmd': ':s//r/rp', 'exp': 'Testr string' }, + \ { 'cmd': ':s//r/rl', 'exp': 'Testr string' }, + \ { 'cmd': ':s//r/r', 'exp': 'Testr string' }, + \] + + for var in variants + for run in [1, 2] + let cmd = var.cmd + if run == 2 && cmd =~ "/.*/.*/." + " Change :s/from/to/{flags} to :s{flags} + let cmd = substitute(cmd, '/.*/', '', '') + endif + call setline(1, [ln]) + let msg = printf('using "%s"', cmd) + let @/='ing' + let v:errmsg = '' + call feedkeys(cmd . "\<CR>" . get(var, 'prompt', ''), 'ntx') + " No error should exist (matters for testing e flag) + call assert_equal('', v:errmsg, msg) + call assert_equal(var.exp, getline('.'), msg) + endfor + endfor +endfunc + +func Test_substitute_repeat() + " This caused an invalid memory access. + split Xfile + s/^/x + call feedkeys("Qsc\<CR>y", 'tx') + bwipe! +endfunc + +" Test for *sub-replace-special* and *sub-replace-expression* on substitute(). +func Test_sub_replace_1() + " Run the tests with 'magic' on + set magic + set cpo& + call assert_equal('AA', substitute('A', 'A', '&&', '')) + call assert_equal('&', substitute('B', 'B', '\&', '')) + call assert_equal('C123456789987654321', substitute('C123456789', 'C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', '\0\9\8\7\6\5\4\3\2\1', '')) + call assert_equal('d', substitute('D', 'D', 'd', '')) + call assert_equal('~', substitute('E', 'E', '~', '')) + call assert_equal('~', substitute('F', 'F', '\~', '')) + call assert_equal('Gg', substitute('G', 'G', '\ugg', '')) + call assert_equal('Hh', substitute('H', 'H', '\Uh\Eh', '')) + call assert_equal('iI', substitute('I', 'I', '\lII', '')) + call assert_equal('jJ', substitute('J', 'J', '\LJ\EJ', '')) + call assert_equal('Kk', substitute('K', 'K', '\Uk\ek', '')) + call assert_equal("l\<C-V>\<C-M>l", + \ substitute('lLl', 'L', "\<C-V>\<C-M>", '')) + call assert_equal("m\<C-M>m", substitute('mMm', 'M', '\r', '')) + call assert_equal("n\<C-V>\<C-M>n", + \ substitute('nNn', 'N', "\\\<C-V>\<C-M>", '')) + call assert_equal("o\no", substitute('oOo', 'O', '\n', '')) + call assert_equal("p\<C-H>p", substitute('pPp', 'P', '\b', '')) + call assert_equal("q\tq", substitute('qQq', 'Q', '\t', '')) + call assert_equal('r\r', substitute('rRr', 'R', '\\', '')) + call assert_equal('scs', substitute('sSs', 'S', '\c', '')) + call assert_equal("u\nu", substitute('uUu', 'U', "\n", '')) + call assert_equal("v\<C-H>v", substitute('vVv', 'V', "\b", '')) + call assert_equal("w\\w", substitute('wWw', 'W', "\\", '')) + call assert_equal("x\<C-M>x", substitute('xXx', 'X', "\r", '')) + call assert_equal("YyyY", substitute('Y', 'Y', '\L\uyYy\l\EY', '')) + call assert_equal("zZZz", substitute('Z', 'Z', '\U\lZzZ\u\Ez', '')) +endfunc + +func Test_sub_replace_2() + " Run the tests with 'magic' off + set nomagic + set cpo& + call assert_equal('AA', substitute('A', 'A', '&&', '')) + call assert_equal('&', substitute('B', 'B', '\&', '')) + call assert_equal('C123456789987654321', substitute('C123456789', 'C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', '\0\9\8\7\6\5\4\3\2\1', '')) + call assert_equal('d', substitute('D', 'D', 'd', '')) + call assert_equal('~', substitute('E', 'E', '~', '')) + call assert_equal('~', substitute('F', 'F', '\~', '')) + call assert_equal('Gg', substitute('G', 'G', '\ugg', '')) + call assert_equal('Hh', substitute('H', 'H', '\Uh\Eh', '')) + call assert_equal('iI', substitute('I', 'I', '\lII', '')) + call assert_equal('jJ', substitute('J', 'J', '\LJ\EJ', '')) + call assert_equal('Kk', substitute('K', 'K', '\Uk\ek', '')) + call assert_equal("l\<C-V>\<C-M>l", + \ substitute('lLl', 'L', "\<C-V>\<C-M>", '')) + call assert_equal("m\<C-M>m", substitute('mMm', 'M', '\r', '')) + call assert_equal("n\<C-V>\<C-M>n", + \ substitute('nNn', 'N', "\\\<C-V>\<C-M>", '')) + call assert_equal("o\no", substitute('oOo', 'O', '\n', '')) + call assert_equal("p\<C-H>p", substitute('pPp', 'P', '\b', '')) + call assert_equal("q\tq", substitute('qQq', 'Q', '\t', '')) + call assert_equal('r\r', substitute('rRr', 'R', '\\', '')) + call assert_equal('scs', substitute('sSs', 'S', '\c', '')) + call assert_equal("t\<C-M>t", substitute('tTt', 'T', "\r", '')) + call assert_equal("u\nu", substitute('uUu', 'U', "\n", '')) + call assert_equal("v\<C-H>v", substitute('vVv', 'V', "\b", '')) + call assert_equal('w\w', substitute('wWw', 'W', "\\", '')) + call assert_equal('XxxX', substitute('X', 'X', '\L\uxXx\l\EX', '')) + call assert_equal('yYYy', substitute('Y', 'Y', '\U\lYyY\u\Ey', '')) +endfunc + +func Test_sub_replace_3() + set magic& + set cpo& + call assert_equal('a\a', substitute('aAa', 'A', '\="\\"', '')) + call assert_equal('b\\b', substitute('bBb', 'B', '\="\\\\"', '')) + call assert_equal("c\rc", substitute('cCc', 'C', "\\=\"\r\"", '')) + call assert_equal("d\\\rd", substitute('dDd', 'D', "\\=\"\\\\\r\"", '')) + call assert_equal("e\\\\\re", substitute('eEe', 'E', "\\=\"\\\\\\\\\r\"", '')) + call assert_equal('f\rf', substitute('fFf', 'F', '\="\\r"', '')) + call assert_equal('j\nj', substitute('jJj', 'J', '\="\\n"', '')) + call assert_equal("k\<C-M>k", substitute('kKk', 'K', '\="\r"', '')) + call assert_equal("l\nl", substitute('lLl', 'L', '\="\n"', '')) +endfunc + +" Test for submatch() on substitute(). +func Test_sub_replace_4() + set magic& + set cpo& + call assert_equal('a\a', substitute('aAa', 'A', + \ '\=substitute(submatch(0), ".", "\\", "")', '')) + call assert_equal('b\b', substitute('bBb', 'B', + \ '\=substitute(submatch(0), ".", "\\\\", "")', '')) + call assert_equal("c\<C-V>\<C-M>c", substitute('cCc', 'C', '\=substitute(submatch(0), ".", "\<C-V>\<C-M>", "")', '')) + call assert_equal("d\<C-V>\<C-M>d", substitute('dDd', 'D', '\=substitute(submatch(0), ".", "\\\<C-V>\<C-M>", "")', '')) + call assert_equal("e\\\<C-V>\<C-M>e", substitute('eEe', 'E', '\=substitute(submatch(0), ".", "\\\\\<C-V>\<C-M>", "")', '')) + call assert_equal("f\<C-M>f", substitute('fFf', 'F', '\=substitute(submatch(0), ".", "\\r", "")', '')) + call assert_equal("j\nj", substitute('jJj', 'J', '\=substitute(submatch(0), ".", "\\n", "")', '')) + call assert_equal("k\rk", substitute('kKk', 'K', '\=substitute(submatch(0), ".", "\r", "")', '')) + call assert_equal("l\nl", substitute('lLl', 'L', '\=substitute(submatch(0), ".", "\n", "")', '')) +endfunc + +func Test_sub_replace_5() + set magic& + set cpo& + call assert_equal('A123456789987654321', substitute('A123456789', + \ 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', + \ '\=submatch(0) . submatch(9) . submatch(8) . ' . + \ 'submatch(7) . submatch(6) . submatch(5) . ' . + \ 'submatch(4) . submatch(3) . submatch(2) . submatch(1)', + \ '')) + call assert_equal("[['A123456789'], ['9'], ['8'], ['7'], ['6'], " . + \ "['5'], ['4'], ['3'], ['2'], ['1']]", + \ substitute('A123456789', + \ 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', + \ '\=string([submatch(0, 1), submatch(9, 1), ' . + \ 'submatch(8, 1), submatch(7, 1), submatch(6, 1), ' . + \ 'submatch(5, 1), submatch(4, 1), submatch(3, 1), ' . + \ 'submatch(2, 1), submatch(1, 1)])', + \ '')) +endfunc + +func Test_sub_replace_6() + set magic& + set cpo+=/ + call assert_equal('a', substitute('A', 'A', 'a', '')) + call assert_equal('%', substitute('B', 'B', '%', '')) + set cpo-=/ + call assert_equal('c', substitute('C', 'C', 'c', '')) + call assert_equal('%', substitute('D', 'D', '%', '')) +endfunc + +func Test_sub_replace_7() + set magic& + set cpo& + call assert_equal('AA', substitute('AA', 'A.', '\=submatch(0)', '')) + call assert_equal("B\nB", substitute("B\nB", 'B.', '\=submatch(0)', '')) + call assert_equal("['B\n']B", substitute("B\nB", 'B.', '\=string(submatch(0, 1))', '')) + call assert_equal('-abab', substitute('-bb', '\zeb', 'a', 'g')) + call assert_equal('c-cbcbc', substitute('-bb', '\ze', 'c', 'g')) +endfunc + +" Test for *:s%* on :substitute. +func Test_sub_replace_8() + new + set magic& + set cpo& + $put =',,X' + s/\(^\|,\)\ze\(,\|X\)/\1N/g + call assert_equal('N,,NX', getline("$")) + $put =',,Y' + let cmd = ':s/\(^\|,\)\ze\(,\|Y\)/\1N/gc' + call feedkeys(cmd . "\<CR>a", "xt") + call assert_equal('N,,NY', getline("$")) + :$put =',,Z' + let cmd = ':s/\(^\|,\)\ze\(,\|Z\)/\1N/gc' + call feedkeys(cmd . "\<CR>yy", "xt") + call assert_equal('N,,NZ', getline("$")) + enew! | close +endfunc + +func Test_sub_replace_9() + new + set magic& + set cpo& + $put ='xxx' + call feedkeys(":s/x/X/gc\<CR>yyq", "xt") + call assert_equal('XXx', getline("$")) + enew! | close +endfunc + +func Test_sub_replace_10() + set magic& + set cpo& + call assert_equal('a1a2a3a', substitute('123', '\zs', 'a', 'g')) + call assert_equal('aaa', substitute('123', '\zs.', 'a', 'g')) + call assert_equal('1a2a3a', substitute('123', '.\zs', 'a', 'g')) + call assert_equal('a1a2a3a', substitute('123', '\ze', 'a', 'g')) + call assert_equal('a1a2a3', substitute('123', '\ze.', 'a', 'g')) + call assert_equal('aaa', substitute('123', '.\ze', 'a', 'g')) + call assert_equal('aa2a3a', substitute('123', '1\|\ze', 'a', 'g')) + call assert_equal('1aaa', substitute('123', '1\zs\|[23]', 'a', 'g')) +endfunc + +" Tests for *sub-replace-special* and *sub-replace-expression* on :substitute. + +" Execute a list of :substitute command tests +func Run_SubCmd_Tests(tests) + enew! + for t in a:tests + let start = line('.') + 1 + let end = start + len(t[2]) - 1 + exe "normal o" . t[0] + call cursor(start, 1) + exe t[1] + call assert_equal(t[2], getline(start, end), t[1]) + endfor + enew! +endfunc + +func Test_sub_cmd_1() + set magic + set cpo& + + " List entry format: [input, cmd, output] + let tests = [['A', 's/A/&&/', ['AA']], + \ ['B', 's/B/\&/', ['&']], + \ ['C123456789', 's/C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\0\9\8\7\6\5\4\3\2\1/', ['C123456789987654321']], + \ ['D', 's/D/d/', ['d']], + \ ['E', 's/E/~/', ['d']], + \ ['F', 's/F/\~/', ['~']], + \ ['G', 's/G/\ugg/', ['Gg']], + \ ['H', 's/H/\Uh\Eh/', ['Hh']], + \ ['I', 's/I/\lII/', ['iI']], + \ ['J', 's/J/\LJ\EJ/', ['jJ']], + \ ['K', 's/K/\Uk\ek/', ['Kk']], + \ ['lLl', "s/L/\<C-V>\<C-M>/", ["l\<C-V>", 'l']], + \ ['mMm', 's/M/\r/', ['m', 'm']], + \ ['nNn', "s/N/\\\<C-V>\<C-M>/", ["n\<C-V>", 'n']], + \ ['oOo', 's/O/\n/', ["o\no"]], + \ ['pPp', 's/P/\b/', ["p\<C-H>p"]], + \ ['qQq', 's/Q/\t/', ["q\tq"]], + \ ['rRr', 's/R/\\/', ['r\r']], + \ ['sSs', 's/S/\c/', ['scs']], + \ ['tTt', "s/T/\<C-V>\<C-J>/", ["t\<C-V>\<C-J>t"]], + \ ['U', 's/U/\L\uuUu\l\EU/', ['UuuU']], + \ ['V', 's/V/\U\lVvV\u\Ev/', ['vVVv']] + \ ] + call Run_SubCmd_Tests(tests) +endfunc + +func Test_sub_cmd_2() + set nomagic + set cpo& + + " List entry format: [input, cmd, output] + let tests = [['A', 's/A/&&/', ['&&']], + \ ['B', 's/B/\&/', ['B']], + \ ['C123456789', 's/\mC\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\0\9\8\7\6\5\4\3\2\1/', ['C123456789987654321']], + \ ['D', 's/D/d/', ['d']], + \ ['E', 's/E/~/', ['~']], + \ ['F', 's/F/\~/', ['~']], + \ ['G', 's/G/\ugg/', ['Gg']], + \ ['H', 's/H/\Uh\Eh/', ['Hh']], + \ ['I', 's/I/\lII/', ['iI']], + \ ['J', 's/J/\LJ\EJ/', ['jJ']], + \ ['K', 's/K/\Uk\ek/', ['Kk']], + \ ['lLl', "s/L/\<C-V>\<C-M>/", ["l\<C-V>", 'l']], + \ ['mMm', 's/M/\r/', ['m', 'm']], + \ ['nNn', "s/N/\\\<C-V>\<C-M>/", ["n\<C-V>", 'n']], + \ ['oOo', 's/O/\n/', ["o\no"]], + \ ['pPp', 's/P/\b/', ["p\<C-H>p"]], + \ ['qQq', 's/Q/\t/', ["q\tq"]], + \ ['rRr', 's/R/\\/', ['r\r']], + \ ['sSs', 's/S/\c/', ['scs']], + \ ['tTt', "s/T/\<C-V>\<C-J>/", ["t\<C-V>\<C-J>t"]], + \ ['U', 's/U/\L\uuUu\l\EU/', ['UuuU']], + \ ['V', 's/V/\U\lVvV\u\Ev/', ['vVVv']] + \ ] + call Run_SubCmd_Tests(tests) +endfunc + +func Test_sub_cmd_3() + set nomagic + set cpo& + + " List entry format: [input, cmd, output] + let tests = [['aAa', "s/A/\\='\\'/", ['a\a']], + \ ['bBb', "s/B/\\='\\\\'/", ['b\\b']], + \ ['cCc', "s/C/\\='\<C-V>\<C-M>'/", ["c\<C-V>", 'c']], + \ ['dDd', "s/D/\\='\\\<C-V>\<C-M>'/", ["d\\\<C-V>", 'd']], + \ ['eEe', "s/E/\\='\\\\\<C-V>\<C-M>'/", ["e\\\\\<C-V>", 'e']], + \ ['fFf', "s/F/\\='\r'/", ['f', 'f']], + \ ['gGg', "s/G/\\='\<C-V>\<C-J>'/", ["g\<C-V>", 'g']], + \ ['hHh', "s/H/\\='\\\<C-V>\<C-J>'/", ["h\\\<C-V>", 'h']], + \ ['iIi', "s/I/\\='\\\\\<C-V>\<C-J>'/", ["i\\\\\<C-V>", 'i']], + \ ['jJj', "s/J/\\='\n'/", ['j', 'j']], + \ ['kKk', 's/K/\="\r"/', ['k', 'k']], + \ ['lLl', 's/L/\="\n"/', ['l', 'l']] + \ ] + call Run_SubCmd_Tests(tests) +endfunc + +" Test for submatch() on :substitue. +func Test_sub_cmd_4() + set magic& + set cpo& + + " List entry format: [input, cmd, output] + let tests = [ ['aAa', "s/A/\\=substitute(submatch(0), '.', '\\', '')/", + \ ['a\a']], + \ ['bBb', "s/B/\\=substitute(submatch(0), '.', '\\', '')/", + \ ['b\b']], + \ ['cCc', "s/C/\\=substitute(submatch(0), '.', '\<C-V>\<C-M>', '')/", + \ ["c\<C-V>", 'c']], + \ ['dDd', "s/D/\\=substitute(submatch(0), '.', '\\\<C-V>\<C-M>', '')/", + \ ["d\<C-V>", 'd']], + \ ['eEe', "s/E/\\=substitute(submatch(0), '.', '\\\\\<C-V>\<C-M>', '')/", + \ ["e\\\<C-V>", 'e']], + \ ['fFf', "s/F/\\=substitute(submatch(0), '.', '\\r', '')/", + \ ['f', 'f']], + \ ['gGg', 's/G/\=substitute(submatch(0), ".", "\<C-V>\<C-J>", "")/', + \ ["g\<C-V>", 'g']], + \ ['hHh', 's/H/\=substitute(submatch(0), ".", "\\\<C-V>\<C-J>", "")/', + \ ["h\<C-V>", 'h']], + \ ['iIi', 's/I/\=substitute(submatch(0), ".", "\\\\\<C-V>\<C-J>", "")/', + \ ["i\\\<C-V>", 'i']], + \ ['jJj', "s/J/\\=substitute(submatch(0), '.', '\\n', '')/", + \ ['j', 'j']], + \ ['kKk', "s/K/\\=substitute(submatch(0), '.', '\\r', '')/", + \ ['k', 'k']], + \ ['lLl', "s/L/\\=substitute(submatch(0), '.', '\\n', '')/", + \ ['l', 'l']], + \ ] + call Run_SubCmd_Tests(tests) +endfunc + +func Test_sub_cmd_5() + set magic& + set cpo& + + " List entry format: [input, cmd, output] + let tests = [ ['A123456789', 's/A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\=submatch(0) . submatch(9) . submatch(8) . submatch(7) . submatch(6) . submatch(5) . submatch(4) . submatch(3) . submatch(2) . submatch(1)/', ['A123456789987654321']], + \ ['B123456789', 's/B\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)/\=string([submatch(0, 1), submatch(9, 1), submatch(8, 1), submatch(7, 1), submatch(6, 1), submatch(5, 1), submatch(4, 1), submatch(3, 1), submatch(2, 1), submatch(1, 1)])/', ["[['B123456789'], ['9'], ['8'], ['7'], ['6'], ['5'], ['4'], ['3'], ['2'], ['1']]"]], + \ ] + call Run_SubCmd_Tests(tests) +endfunc + +" Test for *:s%* on :substitute. +func Test_sub_cmd_6() + set magic& + set cpo+=/ + + " List entry format: [input, cmd, output] + let tests = [ ['A', 's/A/a/', ['a']], + \ ['B', 's/B/%/', ['a']], + \ ] + call Run_SubCmd_Tests(tests) + + set cpo-=/ + let tests = [ ['C', 's/C/c/', ['c']], + \ ['D', 's/D/%/', ['%']], + \ ] + call Run_SubCmd_Tests(tests) + + set cpo& +endfunc + +" Test for :s replacing \n with line break. +func Test_sub_cmd_7() + set magic& + set cpo& + + " List entry format: [input, cmd, output] + let tests = [ ["A\<C-V>\<C-M>A", 's/A./\=submatch(0)/', ['A', 'A']], + \ ["B\<C-V>\<C-J>B", 's/B./\=submatch(0)/', ['B', 'B']], + \ ["C\<C-V>\<C-J>C", 's/C./\=strtrans(string(submatch(0, 1)))/', [strtrans("['C\<C-J>']C")]], + \ ["D\<C-V>\<C-J>\nD", 's/D.\nD/\=strtrans(string(submatch(0, 1)))/', [strtrans("['D\<C-J>', 'D']")]], + \ ["E\<C-V>\<C-J>\n\<C-V>\<C-J>\n\<C-V>\<C-J>\n\<C-V>\<C-J>\n\<C-V>\<C-J>E", 's/E\_.\{-}E/\=strtrans(string(submatch(0, 1)))/', [strtrans("['E\<C-J>', '\<C-J>', '\<C-J>', '\<C-J>', '\<C-J>E']")]], + \ ] + call Run_SubCmd_Tests(tests) + + exe "normal oQ\nQ\<Esc>k" + call assert_fails('s/Q[^\n]Q/\=submatch(0)."foobar"/', 'E486') + enew! +endfunc + +func TitleString() + let check = 'foo' =~ 'bar' + return "" +endfunc + +func Test_sub_cmd_8() + set titlestring=%{TitleString()} + + enew! + call append(0, ['', 'test_one', 'test_two']) + call cursor(1,1) + /^test_one/s/.*/\="foo\nbar"/ + call assert_equal('foo', getline(2)) + call assert_equal('bar', getline(3)) + call feedkeys(':/^test_two/s/.*/\="foo\nbar"/c', "t") + call feedkeys("\<CR>y", "xt") + call assert_equal('foo', getline(4)) + call assert_equal('bar', getline(5)) + + enew! + set titlestring& +endfunc diff --git a/src/testdir/test_suspend.vim b/src/testdir/test_suspend.vim new file mode 100644 index 0000000..e569e49 --- /dev/null +++ b/src/testdir/test_suspend.vim @@ -0,0 +1,55 @@ +" Test :suspend + +source shared.vim + +func Test_suspend() + if !has('terminal') || !executable('/bin/sh') + return + endif + + let buf = term_start('/bin/sh') + " Wait for shell prompt. + call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))}) + + call term_sendkeys(buf, v:progpath + \ . " --clean -X" + \ . " -c 'set nu'" + \ . " -c 'call setline(1, \"foo\")'" + \ . " Xfoo\<CR>") + " Cursor in terminal buffer should be on first line in spawned vim. + call WaitForAssert({-> assert_equal(' 1 foo', term_getline(buf, '.'))}) + + for suspend_cmd in [":suspend\<CR>", + \ ":stop\<CR>", + \ ":suspend!\<CR>", + \ ":stop!\<CR>", + \ "\<C-Z>"] + " Suspend and wait for shell prompt. + call term_sendkeys(buf, suspend_cmd) + call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))}) + + " Without 'autowrite', buffer should not be written. + call assert_equal(0, filereadable('Xfoo')) + + call term_sendkeys(buf, "fg\<CR>") + call WaitForAssert({-> assert_equal(' 1 foo', term_getline(buf, '.'))}) + endfor + + " Test that :suspend! with 'autowrite' writes content of buffers if modified. + call term_sendkeys(buf, ":set autowrite\<CR>") + call assert_equal(0, filereadable('Xfoo')) + call term_sendkeys(buf, ":suspend\<CR>") + " Wait for shell prompt. + call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))}) + call assert_equal(['foo'], readfile('Xfoo')) + call term_sendkeys(buf, "fg\<CR>") + call WaitForAssert({-> assert_equal(' 1 foo', term_getline(buf, '.'))}) + + " Quit gracefully to dump coverage information. + call term_sendkeys(buf, ":qall!\<CR>") + call term_wait(buf) + call Stop_shell_in_terminal(buf) + + exe buf . 'bwipe!' + call delete('Xfoo') +endfunc diff --git a/src/testdir/test_swap.vim b/src/testdir/test_swap.vim new file mode 100644 index 0000000..ce52578 --- /dev/null +++ b/src/testdir/test_swap.vim @@ -0,0 +1,166 @@ +" Tests for the swap feature + +func s:swapname() + return trim(execute('swapname')) +endfunc + +" Tests for 'directory' option. +func Test_swap_directory() + if !has("unix") + return + endif + let content = ['start of testfile', + \ 'line 2 Abcdefghij', + \ 'line 3 Abcdefghij', + \ 'end of testfile'] + call writefile(content, 'Xtest1') + + " '.', swap file in the same directory as file + set dir=.,~ + + " Verify that the swap file doesn't exist in the current directory + call assert_equal([], glob(".Xtest1*.swp", 1, 1, 1)) + edit Xtest1 + let swfname = s:swapname() + call assert_equal([swfname], glob(swfname, 1, 1, 1)) + + " './dir', swap file in a directory relative to the file + set dir=./Xtest2,.,~ + + call mkdir("Xtest2") + edit Xtest1 + call assert_equal([], glob(swfname, 1, 1, 1)) + let swfname = "Xtest2/Xtest1.swp" + call assert_equal(swfname, s:swapname()) + call assert_equal([swfname], glob("Xtest2/*", 1, 1, 1)) + + " 'dir', swap file in directory relative to the current dir + set dir=Xtest.je,~ + + call mkdir("Xtest.je") + call writefile(content, 'Xtest2/Xtest3') + edit Xtest2/Xtest3 + call assert_equal(["Xtest2/Xtest3"], glob("Xtest2/*", 1, 1, 1)) + let swfname = "Xtest.je/Xtest3.swp" + call assert_equal(swfname, s:swapname()) + call assert_equal([swfname], glob("Xtest.je/*", 1, 1, 1)) + + set dir& + call delete("Xtest1") + call delete("Xtest2", "rf") + call delete("Xtest.je", "rf") +endfunc + +func Test_swap_group() + if !has("unix") + return + endif + let groups = split(system('groups')) + if len(groups) <= 1 + throw 'Skipped: need at least two groups, got ' . string(groups) + endif + + try + call delete('Xtest') + split Xtest + call setline(1, 'just some text') + wq + if system('ls -l Xtest') !~ ' ' . groups[0] . ' \d' + throw 'Skipped: test file does not have the first group' + else + silent !chmod 640 Xtest + call system('chgrp ' . groups[1] . ' Xtest') + if system('ls -l Xtest') !~ ' ' . groups[1] . ' \d' + throw 'Skipped: cannot set second group on test file' + else + split Xtest + let swapname = s:swapname() + call assert_match('Xtest', swapname) + " Group of swapfile must now match original file. + call assert_match(' ' . groups[1] . ' \d', system('ls -l ' . swapname)) + + bwipe! + endif + endif + finally + call delete('Xtest') + endtry +endfunc + +func Test_missing_dir() + call mkdir('Xswapdir') + exe 'set directory=' . getcwd() . '/Xswapdir' + + call assert_equal('', glob('foo')) + call assert_equal('', glob('bar')) + edit foo/x.txt + " This should not give a warning for an existing swap file. + split bar/x.txt + only + + " Delete the buffer so that swap file is removed before we try to delete the + " directory. That fails on MS-Windows. + %bdelete! + set directory& + call delete('Xswapdir', 'rf') +endfunc + +func Test_swapinfo() + new Xswapinfo + call setline(1, ['one', 'two', 'three']) + w + let fname = s:swapname() + call assert_match('Xswapinfo', fname) + let info = swapinfo(fname) + + let ver = printf('VIM %d.%d', v:version / 100, v:version % 100) + call assert_equal(ver, info.version) + + call assert_match('\w', info.user) + " host name is truncated to 39 bytes in the swap file + call assert_equal(hostname()[:38], info.host) + call assert_match('Xswapinfo', info.fname) + call assert_match(0, info.dirty) + call assert_equal(getpid(), info.pid) + call assert_match('^\d*$', info.mtime) + if has_key(info, 'inode') + call assert_match('\d', info.inode) + endif + bwipe! + call delete(fname) + call delete('Xswapinfo') + + let info = swapinfo('doesnotexist') + call assert_equal('Cannot open file', info.error) + + call writefile(['burp'], 'Xnotaswapfile') + let info = swapinfo('Xnotaswapfile') + call assert_equal('Cannot read file', info.error) + call delete('Xnotaswapfile') + + call writefile([repeat('x', 10000)], 'Xnotaswapfile') + let info = swapinfo('Xnotaswapfile') + call assert_equal('Not a swap file', info.error) + call delete('Xnotaswapfile') +endfunc + +func Test_swapname() + edit Xtest1 + let expected = s:swapname() + call assert_equal(expected, swapname('%')) + + new Xtest2 + let buf = bufnr('%') + let expected = s:swapname() + wincmd p + call assert_equal(expected, swapname(buf)) + + new Xtest3 + setlocal noswapfile + call assert_equal('', swapname('%')) + + bwipe! + call delete('Xtest1') + call delete('Xtest2') + call delete('Xtest3') +endfunc diff --git a/src/testdir/test_syn_attr.vim b/src/testdir/test_syn_attr.vim new file mode 100644 index 0000000..27f9fc0 --- /dev/null +++ b/src/testdir/test_syn_attr.vim @@ -0,0 +1,818 @@ +" Test syntax highlighting functions. + +func Test_missing_attr() + hi Mine term=bold cterm=italic + call assert_equal('Mine', synIDattr(hlID("Mine"), "name")) + call assert_equal('', synIDattr(hlID("Mine"), "bg", 'term')) + call assert_equal('1', synIDattr(hlID("Mine"), "bold", 'term')) + call assert_equal('1', synIDattr(hlID("Mine"), "italic", 'cterm')) + hi Mine term=reverse cterm=inverse + call assert_equal('1', synIDattr(hlID("Mine"), "reverse", 'term')) + call assert_equal('1', synIDattr(hlID("Mine"), "inverse", 'cterm')) + hi Mine term=underline cterm=standout gui=undercurl + call assert_equal('1', synIDattr(hlID("Mine"), "underline", 'term')) + call assert_equal('1', synIDattr(hlID("Mine"), "standout", 'cterm')) + call assert_equal('1', synIDattr(hlID("Mine"), "undercurl", 'gui')) + hi Mine term=NONE cterm=NONE gui=NONE + call assert_equal('', synIDattr(hlID("Mine"), "bold", 'term')) + call assert_equal('', synIDattr(hlID("Mine"), "italic", 'cterm')) + call assert_equal('', synIDattr(hlID("Mine"), "reverse", 'term')) + call assert_equal('', synIDattr(hlID("Mine"), "inverse", 'cterm')) + call assert_equal('', synIDattr(hlID("Mine"), "underline", 'term')) + call assert_equal('', synIDattr(hlID("Mine"), "standout", 'cterm')) + call assert_equal('', synIDattr(hlID("Mine"), "undercurl", 'gui')) + + if has('gui') + let fontname = getfontname() + if fontname == '' + let fontname = 'something' + endif + exe "hi Mine guifg=blue guibg=red font='" . fontname . "'" + call assert_equal('blue', synIDattr(hlID("Mine"), "fg", 'gui')) + call assert_equal('red', synIDattr(hlID("Mine"), "bg", 'gui')) + call assert_equal(fontname, synIDattr(hlID("Mine"), "font", 'gui')) + endif +endfunc + +func Test_color_names() + let colors = [ + \ 'AliceBlue', + \ 'AntiqueWhite', + \ 'AntiqueWhite1', + \ 'AntiqueWhite2', + \ 'AntiqueWhite3', + \ 'AntiqueWhite4', + \ 'BlanchedAlmond', + \ 'BlueViolet', + \ 'CadetBlue', + \ 'CadetBlue1', + \ 'CadetBlue2', + \ 'CadetBlue3', + \ 'CadetBlue4', + \ 'CornflowerBlue', + \ 'DarkBlue', + \ 'DarkCyan', + \ 'DarkGoldenrod', + \ 'DarkGoldenrod1', + \ 'DarkGoldenrod2', + \ 'DarkGoldenrod3', + \ 'DarkGoldenrod4', + \ 'DarkGray', + \ 'DarkGreen', + \ 'DarkGrey', + \ 'DarkKhaki', + \ 'DarkMagenta', + \ 'DarkOliveGreen', + \ 'DarkOliveGreen1', + \ 'DarkOliveGreen2', + \ 'DarkOliveGreen3', + \ 'DarkOliveGreen4', + \ 'DarkOrange', + \ 'DarkOrange1', + \ 'DarkOrange2', + \ 'DarkOrange3', + \ 'DarkOrange4', + \ 'DarkOrchid', + \ 'DarkOrchid1', + \ 'DarkOrchid2', + \ 'DarkOrchid3', + \ 'DarkOrchid4', + \ 'DarkRed', + \ 'DarkSalmon', + \ 'DarkSeaGreen', + \ 'DarkSeaGreen1', + \ 'DarkSeaGreen2', + \ 'DarkSeaGreen3', + \ 'DarkSeaGreen4', + \ 'DarkSlateBlue', + \ 'DarkSlateGray', + \ 'DarkSlateGray1', + \ 'DarkSlateGray2', + \ 'DarkSlateGray3', + \ 'DarkSlateGray4', + \ 'DarkSlateGrey', + \ 'DarkTurquoise', + \ 'DarkViolet', + \ 'DeepPink', + \ 'DeepPink1', + \ 'DeepPink2', + \ 'DeepPink3', + \ 'DeepPink4', + \ 'DeepSkyBlue', + \ 'DeepSkyBlue1', + \ 'DeepSkyBlue2', + \ 'DeepSkyBlue3', + \ 'DeepSkyBlue4', + \ 'DimGray', + \ 'DimGrey', + \ 'DodgerBlue', + \ 'DodgerBlue1', + \ 'DodgerBlue2', + \ 'DodgerBlue3', + \ 'DodgerBlue4', + \ 'FloralWhite', + \ 'ForestGreen', + \ 'GhostWhite', + \ 'GreenYellow', + \ 'HotPink', + \ 'HotPink1', + \ 'HotPink2', + \ 'HotPink3', + \ 'HotPink4', + \ 'IndianRed', + \ 'IndianRed1', + \ 'IndianRed2', + \ 'IndianRed3', + \ 'IndianRed4', + \ 'LavenderBlush', + \ 'LavenderBlush1', + \ 'LavenderBlush2', + \ 'LavenderBlush3', + \ 'LavenderBlush4', + \ 'LawnGreen', + \ 'LemonChiffon', + \ 'LemonChiffon1', + \ 'LemonChiffon2', + \ 'LemonChiffon3', + \ 'LemonChiffon4', + \ 'LightBlue', + \ 'LightBlue1', + \ 'LightBlue2', + \ 'LightBlue3', + \ 'LightBlue4', + \ 'LightCoral', + \ 'LightCyan', + \ 'LightCyan1', + \ 'LightCyan2', + \ 'LightCyan3', + \ 'LightCyan4', + \ 'LightGoldenrod', + \ 'LightGoldenrod1', + \ 'LightGoldenrod2', + \ 'LightGoldenrod3', + \ 'LightGoldenrod4', + \ 'LightGoldenrodYellow', + \ 'LightGray', + \ 'LightGreen', + \ 'LightGrey', + \ 'LightPink', + \ 'LightPink1', + \ 'LightPink2', + \ 'LightPink3', + \ 'LightPink4', + \ 'LightSalmon', + \ 'LightSalmon1', + \ 'LightSalmon2', + \ 'LightSalmon3', + \ 'LightSalmon4', + \ 'LightSeaGreen', + \ 'LightSkyBlue', + \ 'LightSkyBlue1', + \ 'LightSkyBlue2', + \ 'LightSkyBlue3', + \ 'LightSkyBlue4', + \ 'LightSlateBlue', + \ 'LightSlateGray', + \ 'LightSlateGrey', + \ 'LightSteelBlue', + \ 'LightSteelBlue1', + \ 'LightSteelBlue2', + \ 'LightSteelBlue3', + \ 'LightSteelBlue4', + \ 'LightYellow', + \ 'LightYellow1', + \ 'LightYellow2', + \ 'LightYellow3', + \ 'LightYellow4', + \ 'LimeGreen', + \ 'MediumAquamarine', + \ 'MediumBlue', + \ 'MediumOrchid', + \ 'MediumOrchid1', + \ 'MediumOrchid2', + \ 'MediumOrchid3', + \ 'MediumOrchid4', + \ 'MediumPurple', + \ 'MediumPurple1', + \ 'MediumPurple2', + \ 'MediumPurple3', + \ 'MediumPurple4', + \ 'MediumSeaGreen', + \ 'MediumSlateBlue', + \ 'MediumSpringGreen', + \ 'MediumTurquoise', + \ 'MediumVioletRed', + \ 'MidnightBlue', + \ 'MintCream', + \ 'MistyRose', + \ 'MistyRose1', + \ 'MistyRose2', + \ 'MistyRose3', + \ 'MistyRose4', + \ 'NavajoWhite', + \ 'NavajoWhite1', + \ 'NavajoWhite2', + \ 'NavajoWhite3', + \ 'NavajoWhite4', + \ 'NavyBlue', + \ 'OldLace', + \ 'OliveDrab', + \ 'OliveDrab1', + \ 'OliveDrab2', + \ 'OliveDrab3', + \ 'OliveDrab4', + \ 'OrangeRed', + \ 'OrangeRed1', + \ 'OrangeRed2', + \ 'OrangeRed3', + \ 'OrangeRed4', + \ 'PaleGoldenrod', + \ 'PaleGreen', + \ 'PaleGreen1', + \ 'PaleGreen2', + \ 'PaleGreen3', + \ 'PaleGreen4', + \ 'PaleTurquoise', + \ 'PaleTurquoise1', + \ 'PaleTurquoise2', + \ 'PaleTurquoise3', + \ 'PaleTurquoise4', + \ 'PaleVioletRed', + \ 'PaleVioletRed1', + \ 'PaleVioletRed2', + \ 'PaleVioletRed3', + \ 'PaleVioletRed4', + \ 'PapayaWhip', + \ 'PeachPuff', + \ 'PeachPuff1', + \ 'PeachPuff2', + \ 'PeachPuff3', + \ 'PeachPuff4', + \ 'PowderBlue', + \ 'RosyBrown', + \ 'RosyBrown1', + \ 'RosyBrown2', + \ 'RosyBrown3', + \ 'RosyBrown4', + \ 'RoyalBlue', + \ 'RoyalBlue1', + \ 'RoyalBlue2', + \ 'RoyalBlue3', + \ 'RoyalBlue4', + \ 'SaddleBrown', + \ 'SandyBrown', + \ 'SeaGreen', + \ 'SeaGreen1', + \ 'SeaGreen2', + \ 'SeaGreen3', + \ 'SeaGreen4', + \ 'SkyBlue', + \ 'SkyBlue1', + \ 'SkyBlue2', + \ 'SkyBlue3', + \ 'SkyBlue4', + \ 'SlateBlue', + \ 'SlateBlue1', + \ 'SlateBlue2', + \ 'SlateBlue3', + \ 'SlateBlue4', + \ 'SlateGray', + \ 'SlateGray1', + \ 'SlateGray2', + \ 'SlateGray3', + \ 'SlateGray4', + \ 'SlateGrey', + \ 'SpringGreen', + \ 'SpringGreen1', + \ 'SpringGreen2', + \ 'SpringGreen3', + \ 'SpringGreen4', + \ 'SteelBlue', + \ 'SteelBlue1', + \ 'SteelBlue2', + \ 'SteelBlue3', + \ 'SteelBlue4', + \ 'VioletRed', + \ 'VioletRed1', + \ 'VioletRed2', + \ 'VioletRed3', + \ 'VioletRed4', + \ 'WhiteSmoke', + \ 'YellowGreen', + \ 'alice blue', + \ 'antique white', + \ 'aquamarine', + \ 'aquamarine1', + \ 'aquamarine2', + \ 'aquamarine3', + \ 'aquamarine4', + \ 'azure', + \ 'azure1', + \ 'azure2', + \ 'azure3', + \ 'azure4', + \ 'beige', + \ 'bisque', + \ 'bisque1', + \ 'bisque2', + \ 'bisque3', + \ 'bisque4', + \ 'black', + \ 'blanched almond', + \ 'blue violet', + \ 'blue', + \ 'blue1', + \ 'blue2', + \ 'blue3', + \ 'blue4', + \ 'brown', + \ 'brown1', + \ 'brown2', + \ 'brown3', + \ 'brown4', + \ 'burlywood', + \ 'burlywood1', + \ 'burlywood2', + \ 'burlywood3', + \ 'burlywood4', + \ 'cadet blue', + \ 'chartreuse', + \ 'chartreuse1', + \ 'chartreuse2', + \ 'chartreuse3', + \ 'chartreuse4', + \ 'chocolate', + \ 'chocolate1', + \ 'chocolate2', + \ 'chocolate3', + \ 'chocolate4', + \ 'coral', + \ 'coral1', + \ 'coral2', + \ 'coral3', + \ 'coral4', + \ 'cornflower blue', + \ 'cornsilk', + \ 'cornsilk1', + \ 'cornsilk2', + \ 'cornsilk3', + \ 'cornsilk4', + \ 'cyan', + \ 'cyan1', + \ 'cyan2', + \ 'cyan3', + \ 'cyan4', + \ 'dark blue', + \ 'dark cyan', + \ 'dark goldenrod', + \ 'dark gray', + \ 'dark green', + \ 'dark grey', + \ 'dark khaki', + \ 'dark magenta', + \ 'dark olive green', + \ 'dark orange', + \ 'dark orchid', + \ 'dark red', + \ 'dark salmon', + \ 'dark sea green', + \ 'dark slate blue', + \ 'dark slate gray', + \ 'dark slate grey', + \ 'dark turquoise', + \ 'dark violet', + \ 'darkblue', + \ 'darkcyan', + \ 'darkgray', + \ 'darkgreen', + \ 'darkgrey', + \ 'darkmagenta', + \ 'darkred', + \ 'darkyellow', + \ 'deep pink', + \ 'deep sky blue', + \ 'dim gray', + \ 'dim grey', + \ 'dodger blue', + \ 'firebrick', + \ 'firebrick1', + \ 'firebrick2', + \ 'firebrick3', + \ 'firebrick4', + \ 'floral white', + \ 'forest green', + \ 'gainsboro', + \ 'ghost white', + \ 'gold', + \ 'gold1', + \ 'gold2', + \ 'gold3', + \ 'gold4', + \ 'goldenrod', + \ 'goldenrod1', + \ 'goldenrod2', + \ 'goldenrod3', + \ 'goldenrod4', + \ 'gray', + \ 'gray0', + \ 'gray1', + \ 'gray10', + \ 'gray100', + \ 'gray11', + \ 'gray12', + \ 'gray13', + \ 'gray14', + \ 'gray15', + \ 'gray16', + \ 'gray17', + \ 'gray18', + \ 'gray19', + \ 'gray2', + \ 'gray20', + \ 'gray21', + \ 'gray22', + \ 'gray23', + \ 'gray24', + \ 'gray25', + \ 'gray26', + \ 'gray27', + \ 'gray28', + \ 'gray29', + \ 'gray3', + \ 'gray30', + \ 'gray31', + \ 'gray32', + \ 'gray33', + \ 'gray34', + \ 'gray35', + \ 'gray36', + \ 'gray37', + \ 'gray38', + \ 'gray39', + \ 'gray4', + \ 'gray40', + \ 'gray41', + \ 'gray42', + \ 'gray43', + \ 'gray44', + \ 'gray45', + \ 'gray46', + \ 'gray47', + \ 'gray48', + \ 'gray49', + \ 'gray5', + \ 'gray50', + \ 'gray51', + \ 'gray52', + \ 'gray53', + \ 'gray54', + \ 'gray55', + \ 'gray56', + \ 'gray57', + \ 'gray58', + \ 'gray59', + \ 'gray6', + \ 'gray60', + \ 'gray61', + \ 'gray62', + \ 'gray63', + \ 'gray64', + \ 'gray65', + \ 'gray66', + \ 'gray67', + \ 'gray68', + \ 'gray69', + \ 'gray7', + \ 'gray70', + \ 'gray71', + \ 'gray72', + \ 'gray73', + \ 'gray74', + \ 'gray75', + \ 'gray76', + \ 'gray77', + \ 'gray78', + \ 'gray79', + \ 'gray8', + \ 'gray80', + \ 'gray81', + \ 'gray82', + \ 'gray83', + \ 'gray84', + \ 'gray85', + \ 'gray86', + \ 'gray87', + \ 'gray88', + \ 'gray89', + \ 'gray9', + \ 'gray90', + \ 'gray91', + \ 'gray92', + \ 'gray93', + \ 'gray94', + \ 'gray95', + \ 'gray96', + \ 'gray97', + \ 'gray98', + \ 'gray99', + \ 'green yellow', + \ 'green', + \ 'green1', + \ 'green2', + \ 'green3', + \ 'green4', + \ 'grey', + \ 'grey0', + \ 'grey1', + \ 'grey10', + \ 'grey100', + \ 'grey11', + \ 'grey12', + \ 'grey13', + \ 'grey14', + \ 'grey15', + \ 'grey16', + \ 'grey17', + \ 'grey18', + \ 'grey19', + \ 'grey2', + \ 'grey20', + \ 'grey21', + \ 'grey22', + \ 'grey23', + \ 'grey24', + \ 'grey25', + \ 'grey26', + \ 'grey27', + \ 'grey28', + \ 'grey29', + \ 'grey3', + \ 'grey30', + \ 'grey31', + \ 'grey32', + \ 'grey33', + \ 'grey34', + \ 'grey35', + \ 'grey36', + \ 'grey37', + \ 'grey38', + \ 'grey39', + \ 'grey4', + \ 'grey40', + \ 'grey41', + \ 'grey42', + \ 'grey43', + \ 'grey44', + \ 'grey45', + \ 'grey46', + \ 'grey47', + \ 'grey48', + \ 'grey49', + \ 'grey5', + \ 'grey50', + \ 'grey51', + \ 'grey52', + \ 'grey53', + \ 'grey54', + \ 'grey55', + \ 'grey56', + \ 'grey57', + \ 'grey58', + \ 'grey59', + \ 'grey6', + \ 'grey60', + \ 'grey61', + \ 'grey62', + \ 'grey63', + \ 'grey64', + \ 'grey65', + \ 'grey66', + \ 'grey67', + \ 'grey68', + \ 'grey69', + \ 'grey7', + \ 'grey70', + \ 'grey71', + \ 'grey72', + \ 'grey73', + \ 'grey74', + \ 'grey75', + \ 'grey76', + \ 'grey77', + \ 'grey78', + \ 'grey79', + \ 'grey8', + \ 'grey80', + \ 'grey81', + \ 'grey82', + \ 'grey83', + \ 'grey84', + \ 'grey85', + \ 'grey86', + \ 'grey87', + \ 'grey88', + \ 'grey89', + \ 'grey9', + \ 'grey90', + \ 'grey91', + \ 'grey92', + \ 'grey93', + \ 'grey94', + \ 'grey95', + \ 'grey96', + \ 'grey97', + \ 'grey98', + \ 'grey99', + \ 'honeydew', + \ 'honeydew1', + \ 'honeydew2', + \ 'honeydew3', + \ 'honeydew4', + \ 'hot pink', + \ 'indian red', + \ 'ivory', + \ 'ivory1', + \ 'ivory2', + \ 'ivory3', + \ 'ivory4', + \ 'khaki', + \ 'khaki1', + \ 'khaki2', + \ 'khaki3', + \ 'khaki4', + \ 'lavender blush', + \ 'lavender', + \ 'lawn green', + \ 'lemon chiffon', + \ 'light blue', + \ 'light coral', + \ 'light cyan', + \ 'light goldenrod yellow', + \ 'light goldenrod', + \ 'light gray', + \ 'light green', + \ 'light grey', + \ 'light pink', + \ 'light salmon', + \ 'light sea green', + \ 'light sky blue', + \ 'light slate blue', + \ 'light slate gray', + \ 'light slate grey', + \ 'light steel blue', + \ 'light yellow', + \ 'lightblue', + \ 'lightcyan', + \ 'lightgray', + \ 'lightgreen', + \ 'lightgrey', + \ 'lightmagenta', + \ 'lightred', + \ 'lightyellow', + \ 'lime green', + \ 'linen', + \ 'magenta', + \ 'magenta1', + \ 'magenta2', + \ 'magenta3', + \ 'magenta4', + \ 'maroon', + \ 'maroon1', + \ 'maroon2', + \ 'maroon3', + \ 'maroon4', + \ 'medium aquamarine', + \ 'medium blue', + \ 'medium orchid', + \ 'medium purple', + \ 'medium sea green', + \ 'medium slate blue', + \ 'medium spring green', + \ 'medium turquoise', + \ 'medium violet red', + \ 'midnight blue', + \ 'mint cream', + \ 'misty rose', + \ 'moccasin', + \ 'navajo white', + \ 'navy blue', + \ 'navy', + \ 'old lace', + \ 'olive drab', + \ 'orange red', + \ 'orange', + \ 'orange1', + \ 'orange2', + \ 'orange3', + \ 'orange4', + \ 'orchid', + \ 'orchid1', + \ 'orchid2', + \ 'orchid3', + \ 'orchid4', + \ 'pale goldenrod', + \ 'pale green', + \ 'pale turquoise', + \ 'pale violet red', + \ 'papaya whip', + \ 'peach puff', + \ 'peru', + \ 'pink', + \ 'pink1', + \ 'pink2', + \ 'pink3', + \ 'pink4', + \ 'plum', + \ 'plum1', + \ 'plum2', + \ 'plum3', + \ 'plum4', + \ 'powder blue', + \ 'purple', + \ 'purple1', + \ 'purple2', + \ 'purple3', + \ 'purple4', + \ 'red', + \ 'red1', + \ 'red2', + \ 'red3', + \ 'red4', + \ 'rosy brown', + \ 'royal blue', + \ 'saddle brown', + \ 'salmon', + \ 'salmon1', + \ 'salmon2', + \ 'salmon3', + \ 'salmon4', + \ 'sandy brown', + \ 'sea green', + \ 'seagreen', + \ 'seashell', + \ 'seashell1', + \ 'seashell2', + \ 'seashell3', + \ 'seashell4', + \ 'sienna', + \ 'sienna1', + \ 'sienna2', + \ 'sienna3', + \ 'sienna4', + \ 'sky blue', + \ 'slate blue', + \ 'slate gray', + \ 'slate grey', + \ 'slateblue', + \ 'snow', + \ 'snow1', + \ 'snow2', + \ 'snow3', + \ 'snow4', + \ 'spring green', + \ 'steel blue', + \ 'tan', + \ 'tan1', + \ 'tan2', + \ 'tan3', + \ 'tan4', + \ 'thistle', + \ 'thistle1', + \ 'thistle2', + \ 'thistle3', + \ 'thistle4', + \ 'tomato', + \ 'tomato1', + \ 'tomato2', + \ 'tomato3', + \ 'tomato4', + \ 'turquoise', + \ 'turquoise1', + \ 'turquoise2', + \ 'turquoise3', + \ 'turquoise4', + \ 'violet red', + \ 'violet', + \ 'wheat', + \ 'wheat1', + \ 'wheat2', + \ 'wheat3', + \ 'wheat4', + \ 'white smoke', + \ 'white', + \ 'yellow green', + \ 'yellow', + \ 'yellow1', + \ 'yellow2', + \ 'yellow3', + \ 'yellow4', + \ ] + for color in colors + " just test that the color name can be found. + exe "hi Mine guifg='" . color . "'" + endfor + + " case is ignored + hi Mine guifg=blanchedalmond + hi Mine guifg=BLANCHEDALMOND +endfunc diff --git a/src/testdir/test_syntax.vim b/src/testdir/test_syntax.vim new file mode 100644 index 0000000..c0be4a0 --- /dev/null +++ b/src/testdir/test_syntax.vim @@ -0,0 +1,585 @@ +" Test for syntax and syntax iskeyword option + +if !has("syntax") + finish +endif + +source view_util.vim +source screendump.vim + +func GetSyntaxItem(pat) + let c = '' + let a = ['a', getreg('a'), getregtype('a')] + 0 + redraw! + call search(a:pat, 'W') + let synid = synID(line('.'), col('.'), 1) + while synid == synID(line('.'), col('.'), 1) + norm! v"ay + " stop at whitespace + if @a =~# '\s' + break + endif + let c .= @a + norm! l + endw + call call('setreg', a) + 0 + return c +endfunc + +func Test_syn_iskeyword() + new + call setline(1, [ + \ 'CREATE TABLE FOOBAR(', + \ ' DLTD_BY VARCHAR2(100)', + \ ');', + \ '']) + + syntax on + set ft=sql + syn match SYN /C\k\+\>/ + hi link SYN ErrorMsg + call assert_equal('DLTD_BY', GetSyntaxItem('DLTD')) + /\<D\k\+\>/:norm! ygn + call assert_equal('DLTD_BY', @0) + redir @c + syn iskeyword + redir END + call assert_equal("\nsyntax iskeyword not set", @c) + + syn iskeyword @,48-57,_,192-255 + redir @c + syn iskeyword + redir END + call assert_equal("\nsyntax iskeyword @,48-57,_,192-255", @c) + + setlocal isk-=_ + call assert_equal('DLTD_BY', GetSyntaxItem('DLTD')) + /\<D\k\+\>/:norm! ygn + let b2 = @0 + call assert_equal('DLTD', @0) + + syn iskeyword clear + redir @c + syn iskeyword + redir END + call assert_equal("\nsyntax iskeyword not set", @c) + + quit! +endfunc + +func Test_syntax_after_reload() + split Xsomefile + call setline(1, ['hello', 'there']) + w! + only! + setl filetype=hello + au FileType hello let g:gotit = 1 + call assert_false(exists('g:gotit')) + edit other + buf Xsomefile + call assert_equal('hello', &filetype) + call assert_true(exists('g:gotit')) + call delete('Xsomefile') +endfunc + +func Test_syntime() + if !has('profile') + return + endif + + syntax on + syntime on + let a = execute('syntime report') + call assert_equal("\nNo Syntax items defined for this buffer", a) + + view ../memfile_test.c + setfiletype cpp + redraw + let a = execute('syntime report') + call assert_match('^ TOTAL *COUNT *MATCH *SLOWEST *AVERAGE *NAME *PATTERN', a) + call assert_match(' \d*\.\d* \+[^0]\d* .* cppRawString ', a) + call assert_match(' \d*\.\d* \+[^0]\d* .* cppNumber ', a) + + syntime off + syntime clear + let a = execute('syntime report') + call assert_match('^ TOTAL *COUNT *MATCH *SLOWEST *AVERAGE *NAME *PATTERN', a) + call assert_notmatch('.* cppRawString *', a) + call assert_notmatch('.* cppNumber*', a) + call assert_notmatch('[1-9]', a) + + call assert_fails('syntime abc', 'E475') + + syntax clear + let a = execute('syntime report') + call assert_equal("\nNo Syntax items defined for this buffer", a) + + bd +endfunc + +func Test_syntime_completion() + if !has('profile') + return + endif + + call feedkeys(":syntime \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"syntime clear off on report', @:) +endfunc + +func Test_syntax_list() + syntax on + let a = execute('syntax list') + call assert_equal("\nNo Syntax items defined for this buffer", a) + + view ../memfile_test.c + setfiletype c + + let a = execute('syntax list') + call assert_match('cInclude*', a) + call assert_match('cDefine', a) + + let a = execute('syntax list cDefine') + call assert_notmatch('cInclude*', a) + call assert_match('cDefine', a) + call assert_match(' links to Macro$', a) + + call assert_fails('syntax list ABCD', 'E28:') + call assert_fails('syntax list @ABCD', 'E392:') + + syntax clear + let a = execute('syntax list') + call assert_equal("\nNo Syntax items defined for this buffer", a) + + bd +endfunc + +func Test_syntax_completion() + call feedkeys(":syn \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"syn case clear cluster conceal enable include iskeyword keyword list manual match off on region reset spell sync', @:) + + call feedkeys(":syn case \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"syn case ignore match', @:) + + call feedkeys(":syn spell \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"syn spell default notoplevel toplevel', @:) + + call feedkeys(":syn sync \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"syn sync ccomment clear fromstart linebreaks= linecont lines= match maxlines= minlines= region', @:) + + " Check that clearing "Aap" avoids it showing up before Boolean. + hi Aap ctermfg=blue + call feedkeys(":syn list \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_match('^"syn list Aap Boolean Character ', @:) + hi clear Aap + + call feedkeys(":syn list \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_match('^"syn list Boolean Character ', @:) + + call feedkeys(":syn match \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_match('^"syn match Boolean Character ', @:) +endfunc + +func Test_syntax_arg_skipped() + syn clear + syntax case ignore + if 0 + syntax case match + endif + call assert_match('case ignore', execute('syntax case')) + + syn keyword Foo foo + call assert_match('Foo', execute('syntax')) + syn clear + call assert_match('case match', execute('syntax case')) + call assert_notmatch('Foo', execute('syntax')) + + if has('conceal') + syn clear + syntax conceal on + if 0 + syntax conceal off + endif + call assert_match('conceal on', execute('syntax conceal')) + syn clear + call assert_match('conceal off', execute('syntax conceal')) + + syntax conceal on + syntax conceal off + call assert_match('conceal off', execute('syntax conceal')) + endif + + syntax region Bar start=/</ end=/>/ + if 0 + syntax region NotTest start=/</ end=/>/ contains=@Spell + endif + call assert_match('Bar', execute('syntax')) + call assert_notmatch('NotTest', execute('syntax')) + call assert_notmatch('Spell', execute('syntax')) + + hi Foo ctermfg=blue + let a = execute('hi Foo') + if 0 + syntax rest + endif + call assert_equal(a, execute('hi Foo')) + hi clear Bar + hi clear Foo + + set ft=tags + syn off + if 0 + syntax enable + endif + call assert_match('No Syntax items defined', execute('syntax')) + syntax enable + call assert_match('tagComment', execute('syntax')) + set ft= + + syn clear + if 0 + syntax include @Spell nothing + endif + call assert_notmatch('Spell', execute('syntax')) + + syn clear + syn iskeyword 48-57,$,_ + call assert_match('48-57,$,_', execute('syntax iskeyword')) + if 0 + syn clear + syn iskeyword clear + endif + call assert_match('48-57,$,_', execute('syntax iskeyword')) + syn iskeyword clear + call assert_match('not set', execute('syntax iskeyword')) + syn iskeyword 48-57,$,_ + syn clear + call assert_match('not set', execute('syntax iskeyword')) + + syn clear + syn keyword Foo foo + if 0 + syn keyword NotAdded bar + endif + call assert_match('Foo', execute('syntax')) + call assert_notmatch('NotAdded', execute('highlight')) + + syn clear + syn keyword Foo foo + call assert_match('Foo', execute('syntax')) + call assert_match('Foo', execute('syntax list')) + call assert_notmatch('Foo', execute('if 0 | syntax | endif')) + call assert_notmatch('Foo', execute('if 0 | syntax list | endif')) + + syn clear + syn match Fopi /asdf/ + if 0 + syn match Fopx /asdf/ + endif + call assert_match('Fopi', execute('syntax')) + call assert_notmatch('Fopx', execute('syntax')) + + syn clear + syn spell toplevel + call assert_match('spell toplevel', execute('syntax spell')) + if 0 + syn spell notoplevel + endif + call assert_match('spell toplevel', execute('syntax spell')) + syn spell notoplevel + call assert_match('spell notoplevel', execute('syntax spell')) + syn spell default + call assert_match('spell default', execute('syntax spell')) + + syn clear + if 0 + syntax cluster Spell + endif + call assert_notmatch('Spell', execute('syntax')) + + syn clear + syn keyword Foo foo + syn sync ccomment + syn sync maxlines=5 + if 0 + syn sync maxlines=11 + endif + call assert_match('on C-style comments', execute('syntax sync')) + call assert_match('maximal 5 lines', execute('syntax sync')) + syn sync clear + if 0 + syn sync ccomment + endif + call assert_notmatch('on C-style comments', execute('syntax sync')) + + syn clear +endfunc + +func Test_syntax_invalid_arg() + call assert_fails('syntax case asdf', 'E390:') + if has('conceal') + call assert_fails('syntax conceal asdf', 'E390:') + endif + call assert_fails('syntax spell asdf', 'E390:') + call assert_fails('syntax clear @ABCD', 'E391:') + call assert_fails('syntax include @Xxx', 'E397:') + call assert_fails('syntax region X start="{"', 'E399:') + call assert_fails('syntax sync x', 'E404:') + call assert_fails('syntax keyword Abc a[', 'E789:') + call assert_fails('syntax keyword Abc a[bc]d', 'E890:') +endfunc + +func Test_syn_sync() + syntax region HereGroup start=/this/ end=/that/ + syntax sync match SyncHere grouphere HereGroup "pattern" + call assert_match('SyncHere', execute('syntax sync')) + syn sync clear + call assert_notmatch('SyncHere', execute('syntax sync')) + syn clear +endfunc + +func Test_syn_clear() + syntax keyword Foo foo + syntax keyword Bar tar + call assert_match('Foo', execute('syntax')) + call assert_match('Bar', execute('syntax')) + call assert_equal('Foo', synIDattr(hlID("Foo"), "name")) + syn clear Foo + call assert_notmatch('Foo', execute('syntax')) + call assert_match('Bar', execute('syntax')) + call assert_equal('Foo', synIDattr(hlID("Foo"), "name")) + syn clear Foo Bar + call assert_notmatch('Foo', execute('syntax')) + call assert_notmatch('Bar', execute('syntax')) + hi clear Foo + call assert_equal('Foo', synIDattr(hlID("Foo"), "name")) + hi clear Bar +endfunc + +func Test_invalid_name() + syn clear + syn keyword Nop yes + call assert_fails("syntax keyword Wr\x17ong bar", 'E669:') + syntax keyword @Wrong bar + call assert_match('W18:', execute('1messages')) + syn clear + hi clear Nop + hi clear @Wrong +endfunc + +func Test_ownsyntax() + new Xfoo + call setline(1, '#define FOO') + syntax on + set filetype=c + ownsyntax perl + call assert_equal('perlComment', synIDattr(synID(line('.'), col('.'), 1), 'name')) + call assert_equal('c', b:current_syntax) + call assert_equal('perl', w:current_syntax) + + " A new split window should have the original syntax. + split + call assert_equal('cDefine', synIDattr(synID(line('.'), col('.'), 1), 'name')) + call assert_equal('c', b:current_syntax) + call assert_equal(0, exists('w:current_syntax')) + + wincmd x + call assert_equal('perlComment', synIDattr(synID(line("."), col("."), 1), "name")) + + syntax off + set filetype& + %bw! +endfunc + +func Test_ownsyntax_completion() + call feedkeys(":ownsyntax java\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"ownsyntax java javacc javascript', @:) +endfunc + +func Test_highlight_invalid_arg() + if has('gui_running') + call assert_fails('hi XXX guifg=xxx', 'E254:') + endif + call assert_fails('hi DoesNotExist', 'E411:') + call assert_fails('hi link', 'E412:') + call assert_fails('hi link a', 'E412:') + call assert_fails('hi link a b c', 'E413:') + call assert_fails('hi XXX =', 'E415:') + call assert_fails('hi XXX cterm', 'E416:') + call assert_fails('hi XXX cterm=', 'E417:') + call assert_fails('hi XXX cterm=DoesNotExist', 'E418:') + call assert_fails('hi XXX ctermfg=DoesNotExist', 'E421:') + call assert_fails('hi XXX xxx=White', 'E423:') +endfunc + +func Test_bg_detection() + if has('gui_running') + return + endif + " auto-detection of &bg, make sure sure it isn't set anywhere before + " this test + hi Normal ctermbg=0 + call assert_equal('dark', &bg) + hi Normal ctermbg=4 + call assert_equal('dark', &bg) + hi Normal ctermbg=12 + call assert_equal('light', &bg) + hi Normal ctermbg=15 + call assert_equal('light', &bg) + + " manually-set &bg takes precedence over auto-detection + set bg=light + hi Normal ctermbg=4 + call assert_equal('light', &bg) + set bg=dark + hi Normal ctermbg=12 + call assert_equal('dark', &bg) + + hi Normal ctermbg=NONE +endfunc + +func Test_syntax_hangs() + if !has('reltime') || !has('float') || !has('syntax') + return + endif + + " This pattern takes a long time to match, it should timeout. + new + call setline(1, ['aaa', repeat('abc ', 1000), 'ccc']) + let start = reltime() + set nolazyredraw redrawtime=101 + syn match Error /\%#=1a*.*X\@<=b*/ + redraw + let elapsed = reltimefloat(reltime(start)) + call assert_true(elapsed > 0.1) + call assert_true(elapsed < 1.0) + + " second time syntax HL is disabled + let start = reltime() + redraw + let elapsed = reltimefloat(reltime(start)) + call assert_true(elapsed < 0.1) + + " after CTRL-L the timeout flag is reset + let start = reltime() + exe "normal \<C-L>" + redraw + let elapsed = reltimefloat(reltime(start)) + call assert_true(elapsed > 0.1) + call assert_true(elapsed < 1.0) + + set redrawtime& + bwipe! +endfunc + +func Test_conceal() + if !has('conceal') + return + endif + + new + call setline(1, ['', '123456']) + syn match test23 "23" conceal cchar=X + syn match test45 "45" conceal + + set conceallevel=0 + call assert_equal('123456 ', ScreenLines(2, 7)[0]) + call assert_equal([[0, '', 0], [0, '', 0], [0, '', 0], [0, '', 0], [0, '', 0], [0, '', 0]], map(range(1, 6), 'synconcealed(2, v:val)')) + + set conceallevel=1 + call assert_equal('1X 6 ', ScreenLines(2, 7)[0]) + call assert_equal([[0, '', 0], [1, 'X', 1], [1, 'X', 1], [1, ' ', 2], [1, ' ', 2], [0, '', 0]], map(range(1, 6), 'synconcealed(2, v:val)')) + + set conceallevel=1 + set listchars=conceal:Y + call assert_equal([[0, '', 0], [1, 'X', 1], [1, 'X', 1], [1, 'Y', 2], [1, 'Y', 2], [0, '', 0]], map(range(1, 6), 'synconcealed(2, v:val)')) + call assert_equal('1XY6 ', ScreenLines(2, 7)[0]) + + set conceallevel=2 + call assert_match('1X6 ', ScreenLines(2, 7)[0]) + call assert_equal([[0, '', 0], [1, 'X', 1], [1, 'X', 1], [1, '', 2], [1, '', 2], [0, '', 0]], map(range(1, 6), 'synconcealed(2, v:val)')) + + set conceallevel=3 + call assert_match('16 ', ScreenLines(2, 7)[0]) + call assert_equal([[0, '', 0], [1, '', 1], [1, '', 1], [1, '', 2], [1, '', 2], [0, '', 0]], map(range(1, 6), 'synconcealed(2, v:val)')) + + syn clear + set conceallevel& + bw! +endfunc + +func Test_synstack_synIDtrans() + new + setfiletype c + syntax on + call setline(1, ' /* A comment with a TODO */') + + call assert_equal([], synstack(1, 1)) + + norm f/ + call assert_equal(['cComment', 'cCommentStart'], map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")')) + call assert_equal(['Comment', 'Comment'], map(synstack(line("."), col(".")), 'synIDattr(synIDtrans(v:val), "name")')) + + norm fA + call assert_equal(['cComment'], map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")')) + call assert_equal(['Comment'], map(synstack(line("."), col(".")), 'synIDattr(synIDtrans(v:val), "name")')) + + norm fT + call assert_equal(['cComment', 'cTodo'], map(synstack(line("."), col(".")), 'synIDattr(v:val, "name")')) + call assert_equal(['Comment', 'Todo'], map(synstack(line("."), col(".")), 'synIDattr(synIDtrans(v:val), "name")')) + + syn clear + bw! +endfunc + +" Check highlighting for a small piece of C code with a screen dump. +func Test_syntax_c() + if !CanRunVimInTerminal() + return + endif + call writefile([ + \ '/* comment line at the top */', + \ ' int', + \ 'main(int argc, char **argv)// another comment', + \ '{', + \ '#if 0', + \ ' int not_used;', + \ '#else', + \ ' int used;', + \ '#endif', + \ ' printf("Just an example piece of C code\n");', + \ ' return 0x0ff;', + \ '}', + \ ' static void', + \ 'myFunction(const double count, struct nothing, long there) {', + \ ' // 123: nothing to read here', + \ ' for (int i = 0; i < count; ++i) {', + \ ' break;', + \ ' }', + \ '}', + \ ], 'Xtest.c') + + " This makes the default for 'background' use "dark", check that the + " response to t_RB corrects it to "light". + let $COLORFGBG = '15;0' + + let buf = RunVimInTerminal('Xtest.c', {}) + call VerifyScreenDump(buf, 'Test_syntax_c_01', {}) + call StopVimInTerminal(buf) + + let $COLORFGBG = '' + call delete('Xtest.c') +endfun + +" Using \z() in a region with NFA failing should not crash. +func Test_syn_wrong_z_one() + new + call setline(1, ['just some text', 'with foo and bar to match with']) + syn region FooBar start="foo\z(.*\)bar" end="\z1" + call test_override("nfa_fail", 1) + redraw! + redraw! + call test_override("ALL", 0) + bwipe! +endfunc diff --git a/src/testdir/test_system.vim b/src/testdir/test_system.vim new file mode 100644 index 0000000..25061ea --- /dev/null +++ b/src/testdir/test_system.vim @@ -0,0 +1,92 @@ +" Tests for system() and systemlist() + +func Test_System() + if !executable('echo') || !executable('cat') || !executable('wc') + return + endif + let out = system('echo 123') + " On Windows we may get a trailing space. + if out != "123 \n" + call assert_equal("123\n", out) + endif + + let out = systemlist('echo 123') + " On Windows we may get a trailing space and CR. + if out != ["123 \r"] + call assert_equal(['123'], out) + endif + + call assert_equal('123', system('cat', '123')) + call assert_equal(['123'], systemlist('cat', '123')) + call assert_equal(["as\<NL>df"], systemlist('cat', ["as\<NL>df"])) + + new Xdummy + call setline(1, ['asdf', "pw\<NL>er", 'xxxx']) + let out = system('wc -l', bufnr('%')) + " On OS/X we get leading spaces + let out = substitute(out, '^ *', '', '') + call assert_equal("3\n", out) + + let out = systemlist('wc -l', bufnr('%')) + " On Windows we may get a trailing CR. + if out != ["3\r"] + " On OS/X we get leading spaces + if type(out) == v:t_list + let out[0] = substitute(out[0], '^ *', '', '') + endif + call assert_equal(['3'], out) + endif + + let out = systemlist('cat', bufnr('%')) + " On Windows we may get a trailing CR. + if out != ["asdf\r", "pw\<NL>er\r", "xxxx\r"] + call assert_equal(['asdf', "pw\<NL>er", 'xxxx'], out) + endif + bwipe! + + call assert_fails('call system("wc -l", 99999)', 'E86:') +endfunc + +func Test_system_exmode() + if has('unix') " echo $? only works on Unix + let cmd = ' -es -u NONE -c "source Xscript" +q; echo "result=$?"' + " Need to put this in a script, "catch" isn't found after an unknown + " function. + call writefile(['try', 'call doesnotexist()', 'catch', 'endtry'], 'Xscript') + let a = system(v:progpath . cmd) + call assert_match('result=0', a) + call assert_equal(0, v:shell_error) + endif + + " Error before try does set error flag. + call writefile(['call nosuchfunction()', 'try', 'call doesnotexist()', 'catch', 'endtry'], 'Xscript') + if has('unix') " echo $? only works on Unix + let a = system(v:progpath . cmd) + call assert_notequal('0', a[0]) + endif + + let cmd = ' -es -u NONE -c "source Xscript" +q' + let a = system(v:progpath . cmd) + call assert_notequal(0, v:shell_error) + call delete('Xscript') + + if has('unix') " echo $? only works on Unix + let cmd = ' -es -u NONE -c "call doesnotexist()" +q; echo $?' + let a = system(v:progpath. cmd) + call assert_notequal(0, a[0]) + endif + + let cmd = ' -es -u NONE -c "call doesnotexist()" +q' + let a = system(v:progpath. cmd) + call assert_notequal(0, v:shell_error) + + if has('unix') " echo $? only works on Unix + let cmd = ' -es -u NONE -c "call doesnotexist()|let a=1" +q; echo $?' + let a = system(v:progpath. cmd) + call assert_notequal(0, a[0]) + endif + + let cmd = ' -es -u NONE -c "call doesnotexist()|let a=1" +q' + let a = system(v:progpath. cmd) + call assert_notequal(0, v:shell_error) +endfunc diff --git a/src/testdir/test_tab.vim b/src/testdir/test_tab.vim new file mode 100644 index 0000000..b8e8dfe --- /dev/null +++ b/src/testdir/test_tab.vim @@ -0,0 +1,90 @@ +" Various tests for inserting a Tab. + +" Tests for "r<Tab>" with 'smarttab' and 'expandtab' set/not set. +" Also test that dv_ works correctly +func Test_smarttab() + enew! + set smarttab expandtab ts=8 sw=4 + " make sure that backspace works, no matter what termcap is used + exe "set t_kD=\<C-V>x7f t_kb=\<C-V>x08" + call append(0, ['start text', + \ "\t\tsome test text", + \ 'test text', + \ "\t\tother test text", + \ ' a cde', + \ ' f ghi', + \ 'test text', + \ ' Second line beginning with whitespace' + \ ]) + call cursor(1, 1) + exe "normal /some\<CR>" + exe "normal r\t" + call assert_equal("\t\t ome test text", getline('.')) + set noexpandtab + exe "normal /other\<CR>" + exe "normal r\t" + call assert_equal("\t\t ther test text", getline('.')) + + " Test replacing with Tabs and then backspacing to undo it + exe "normal j0wR\t\t\t\<BS>\<BS>\<BS>" + call assert_equal(" a cde", getline('.')) + " Test replacing with Tabs + exe "normal j0wR\t\t\t" + call assert_equal(" \t\thi", getline('.')) + + " Test that copyindent works with expandtab set + set expandtab smartindent copyindent ts=8 sw=8 sts=8 + exe "normal jo{\<CR>x" + call assert_equal('{', getline(line('.') - 1)) + call assert_equal(' x', getline('.')) + set nosol + exe "normal /Second line/\<CR>" + exe "normal fwdv_" + call assert_equal(' with whitespace', getline('.')) + enew! + set expandtab& smartindent& copyindent& ts& sw& sts& +endfunc + +func Test_softtabstop() + new + set sts=0 sw=0 + exe "normal ix\<Tab>x\<Esc>" + call assert_equal("x\tx", getline(1)) + + call setline(1, '') + set sts=4 + exe "normal ix\<Tab>x\<Esc>" + call assert_equal("x x", getline(1)) + + call setline(1, '') + set sts=-1 sw=4 + exe "normal ix\<Tab>x\<Esc>" + call assert_equal("x x", getline(1)) + + call setline(1, 'x ') + set sts=0 sw=0 backspace=start + exe "normal A\<BS>x\<Esc>" + call assert_equal("x x", getline(1)) + + call setline(1, 'x ') + set sts=4 + exe "normal A\<BS>x\<Esc>" + call assert_equal("x x", getline(1)) + + call setline(1, 'x ') + set sts=-1 sw=4 + exe "normal A\<BS>x\<Esc>" + call assert_equal("x x", getline(1)) + + call setline(1, 'x') + set sts=-1 sw=0 smarttab + exe "normal I\<Tab>\<Esc>" + call assert_equal("\tx", getline(1)) + + call setline(1, 'x') + exe "normal I\<Tab>\<BS>\<Esc>" + call assert_equal("x", getline(1)) + + set sts=0 sw=0 backspace& nosmarttab + bwipe! +endfunc diff --git a/src/testdir/test_tabline.vim b/src/testdir/test_tabline.vim new file mode 100644 index 0000000..383d239 --- /dev/null +++ b/src/testdir/test_tabline.vim @@ -0,0 +1,72 @@ + +source shared.vim + +func TablineWithCaughtError() + let s:func_in_tabline_called = 1 + try + call eval('unknown expression') + catch + endtry + return '' +endfunc + +func TablineWithError() + let s:func_in_tabline_called = 1 + call eval('unknown expression') + return '' +endfunc + +func Test_caught_error_in_tabline() + if has('gui') + set guioptions-=e + endif + let showtabline_save = &showtabline + set showtabline=2 + let s:func_in_tabline_called = 0 + let tabline = '%{TablineWithCaughtError()}' + let &tabline = tabline + redraw! + call assert_true(s:func_in_tabline_called) + call assert_equal(tabline, &tabline) + set tabline= + let &showtabline = showtabline_save +endfunc + +func Test_tabline_will_be_disabled_with_error() + if has('gui') + set guioptions-=e + endif + let showtabline_save = &showtabline + set showtabline=2 + let s:func_in_tabline_called = 0 + let tabline = '%{TablineWithError()}' + try + let &tabline = tabline + redraw! + catch + endtry + call assert_true(s:func_in_tabline_called) + call assert_equal('', &tabline) + set tabline= + let &showtabline = showtabline_save +endfunc + +func Test_redrawtabline() + if has('gui') + set guioptions-=e + endif + let showtabline_save = &showtabline + set showtabline=2 + set tabline=%{bufnr('$')} + edit Xtabline1 + edit Xtabline2 + redraw + call assert_match(bufnr('$') . '', Screenline(1)) + au BufAdd * redrawtabline + badd Xtabline3 + call assert_match(bufnr('$') . '', Screenline(1)) + + set tabline= + let &showtabline = showtabline_save + au! Bufadd +endfunc diff --git a/src/testdir/test_tabpage.vim b/src/testdir/test_tabpage.vim new file mode 100644 index 0000000..48ac6eb --- /dev/null +++ b/src/testdir/test_tabpage.vim @@ -0,0 +1,558 @@ +" Tests for tabpage + + +function Test_tabpage() + bw! + " Simple test for opening and closing a tab page + tabnew + call assert_equal(2, tabpagenr()) + quit + + " Open three tab pages and use ":tabdo" + 0tabnew + 1tabnew + $tabnew + %del + tabdo call append(line('$'), tabpagenr()) + tabclose! 2 + tabrewind + let line1 = getline('$') + undo + q + tablast + let line2 = getline('$') + q! + call append(line('$'), line1) + call append(line('$'), line2) + unlet line1 line2 + call assert_equal(['', '3', '1', '4'], getline(1, '$')) + " + " Test for settabvar() and gettabvar() functions. Open a new tab page and + " set 3 variables to a number, string and a list. Verify that the variables + " are correctly set. + tabnew + tabfirst + call settabvar(2, 'val_num', 100) + call settabvar(2, 'val_str', 'SetTabVar test') + call settabvar(2, 'val_list', ['red', 'blue', 'green']) + " + call assert_true(gettabvar(2, 'val_num') == 100 && gettabvar(2, 'val_str') == 'SetTabVar test' && gettabvar(2, 'val_list') == ['red', 'blue', 'green']) + + tabnext 2 + call assert_true(t:val_num == 100 && t:val_str == 'SetTabVar test' && t:val_list == ['red', 'blue', 'green']) + tabclose + + " Test for ":tab drop exist-file" to keep current window. + sp test1 + tab drop test1 + call assert_true(tabpagenr('$') == 1 && winnr('$') == 2 && winnr() == 1) + close + " + " + " Test for ":tab drop new-file" to keep current window of tabpage 1. + split + tab drop newfile + call assert_true(tabpagenr('$') == 2 && tabpagewinnr(1, '$') == 2 && tabpagewinnr(1) == 1) + tabclose + q + " + " + " Test for ":tab drop multi-opend-file" to keep current tabpage and window. + new test1 + tabnew + new test1 + tab drop test1 + call assert_true(tabpagenr() == 2 && tabpagewinnr(2, '$') == 2 && tabpagewinnr(2) == 1) + tabclose + q + " + " + " Test for ":tab drop vertical-split-window" to jump test1 buffer + tabedit test1 + vnew + tabfirst + tab drop test1 + call assert_equal([2, 2, 2, 2], [tabpagenr('$'), tabpagenr(), tabpagewinnr(2, '$'), tabpagewinnr(2)]) + 1tabonly + " + " + for i in range(9) | tabnew | endfor + normal! 1gt + call assert_equal(1, tabpagenr()) + tabmove 5 + call assert_equal(5, tabpagenr()) + .tabmove + call assert_equal(5, tabpagenr()) + tabmove - + call assert_equal(4, tabpagenr()) + tabmove + + call assert_equal(5, tabpagenr()) + tabmove -2 + call assert_equal(3, tabpagenr()) + tabmove +4 + call assert_equal(7, tabpagenr()) + tabmove + call assert_equal(10, tabpagenr()) + 0tabmove + call assert_equal(1, tabpagenr()) + $tabmove + call assert_equal(10, tabpagenr()) + tabmove 0 + call assert_equal(1, tabpagenr()) + tabmove $ + call assert_equal(10, tabpagenr()) + 3tabmove + call assert_equal(4, tabpagenr()) + 7tabmove 5 + call assert_equal(5, tabpagenr()) + -tabmove + call assert_equal(4, tabpagenr()) + +tabmove + call assert_equal(5, tabpagenr()) + -2tabmove + call assert_equal(3, tabpagenr()) + +3tabmove + call assert_equal(6, tabpagenr()) + + " The following are a no-op + norm! 2gt + call assert_equal(2, tabpagenr()) + tabmove 2 + call assert_equal(2, tabpagenr()) + 2tabmove + call assert_equal(2, tabpagenr()) + tabmove 1 + call assert_equal(2, tabpagenr()) + 1tabmove + call assert_equal(2, tabpagenr()) + + call assert_fails("99tabmove", 'E16:') + call assert_fails("+99tabmove", 'E16:') + call assert_fails("-99tabmove", 'E16:') + call assert_fails("tabmove foo", 'E474:') + call assert_fails("tabmove 99", 'E474:') + call assert_fails("tabmove +99", 'E474:') + call assert_fails("tabmove -99", 'E474:') + call assert_fails("tabmove -3+", 'E474:') + call assert_fails("tabmove $3", 'E474:') + 1tabonly! +endfunc + +" Test autocommands +function Test_tabpage_with_autocmd() + if !has('autocmd') + return + endif + command -nargs=1 -bar C :call add(s:li, '=== ' . <q-args> . ' ===')|<args> + augroup TestTabpageGroup + au! + autocmd TabEnter * call add(s:li, 'TabEnter') + autocmd WinEnter * call add(s:li, 'WinEnter') + autocmd BufEnter * call add(s:li, 'BufEnter') + autocmd TabLeave * call add(s:li, 'TabLeave') + autocmd WinLeave * call add(s:li, 'WinLeave') + autocmd BufLeave * call add(s:li, 'BufLeave') + augroup END + + let s:li = [] + let t:a='a' + C tab split + call assert_equal(['=== tab split ===', 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter'], s:li) + let s:li = [] + let t:a='b' + C tabnew + call assert_equal(['=== tabnew ===', 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter', 'BufLeave', 'BufEnter'], s:li) + let t:a='c' + let s:li = split(join(map(range(1, tabpagenr('$')), 'gettabvar(v:val, "a")')) , '\s\+') + call assert_equal(['a', 'b', 'c'], s:li) + + let s:li = [] + C call map(range(1, tabpagenr('$')), 'settabvar(v:val, ''a'', v:val*2)') + call assert_equal(["=== call map(range(1, tabpagenr('$')), 'settabvar(v:val, ''a'', v:val*2)') ==="], s:li) + let s:li = split(join(map(range(1, tabpagenr('$')), 'gettabvar(v:val, "a")')) , '\s\+') + call assert_equal(['2', '4', '6'], s:li) + + let s:li = [] + let w:a='a' + C vsplit + call assert_equal(['=== vsplit ===', 'WinLeave', 'WinEnter'], s:li) + let s:li = [] + let w:a='a' + let tabn=tabpagenr() + let winr=range(1, winnr('$')) + C tabnext 1 + call assert_equal(['=== tabnext 1 ===', 'BufLeave', 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter', 'BufEnter'], s:li) + let s:li = split(join(map(copy(winr), 'gettabwinvar('.tabn.', v:val, "a")')), '\s\+') + call assert_equal(['a', 'a'], s:li) + let s:li = [] + C call map(copy(winr), 'settabwinvar('.tabn.', v:val, ''a'', v:val*2)') + let s:li = split(join(map(copy(winr), 'gettabwinvar('.tabn.', v:val, "a")')), '\s\+') + call assert_equal(['2', '4'], s:li) + + augroup TabDestructive + autocmd TabEnter * :C tabnext 2 | C tabclose 3 + augroup END + let s:li = [] + C tabnext 3 + call assert_equal(['=== tabnext 3 ===', 'BufLeave', 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter', '=== tabnext 2 ===', '=== tabclose 3 ==='], s:li) + call assert_equal(['2/2'], [tabpagenr().'/'.tabpagenr('$')]) + + autocmd! TabDestructive TabEnter + let s:li = [] + C tabnew + call assert_equal(['=== tabnew ===', 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter', 'BufLeave', 'BufEnter'], s:li) + let s:li = [] + C tabnext 1 + call assert_equal(['=== tabnext 1 ===', 'BufLeave', 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter', 'BufEnter'], s:li) + + autocmd TabDestructive TabEnter * nested :C tabnext 2 | C tabclose 3 + let s:li = [] + call assert_equal(3, tabpagenr('$')) + C tabnext 2 + call assert_equal(2, tabpagenr('$')) + call assert_equal(['=== tabnext 2 ===', 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter', '=== tabnext 2 ===', '=== tabclose 3 ==='], s:li) + call assert_equal(['2/2'], [tabpagenr().'/'.tabpagenr('$')]) + + delcommand C + autocmd! TabDestructive + augroup! TabDestructive + autocmd! TestTabpageGroup + augroup! TestTabpageGroup + 1tabonly! +endfunction + +function Test_tabpage_with_tab_modifier() + for n in range(4) + tabedit + endfor + + function s:check_tab(pre_nr, cmd, post_nr) + exec 'tabnext ' . a:pre_nr + exec a:cmd + call assert_equal(a:post_nr, tabpagenr()) + call assert_equal('help', &buftype) + helpclose + endfunc + + call s:check_tab(1, 'tab help', 2) + call s:check_tab(1, '3tab help', 4) + call s:check_tab(1, '.tab help', 2) + call s:check_tab(1, '.+1tab help', 3) + call s:check_tab(1, '0tab help', 1) + call s:check_tab(2, '+tab help', 4) + call s:check_tab(2, '+2tab help', 5) + call s:check_tab(4, '-tab help', 4) + call s:check_tab(4, '-2tab help', 3) + call s:check_tab(3, '$tab help', 6) + call assert_fails('99tab help', 'E16:') + call assert_fails('+99tab help', 'E16:') + call assert_fails('-99tab help', 'E16:') + + delfunction s:check_tab + 1tabonly! +endfunction + +function Check_tab_count(pre_nr, cmd, post_nr) + exec 'tabnext' a:pre_nr + normal! G + exec a:cmd + call assert_equal(a:post_nr, tabpagenr(), a:cmd) +endfunc + +" Test for [count] of tabnext +function Test_tabpage_with_tabnext() + for n in range(4) + tabedit + call setline(1, ['', '', '3']) + endfor + + call Check_tab_count(1, 'tabnext', 2) + call Check_tab_count(1, '3tabnext', 3) + call Check_tab_count(1, '.tabnext', 1) + call Check_tab_count(1, '.+1tabnext', 2) + call Check_tab_count(2, '+tabnext', 3) + call Check_tab_count(2, '+2tabnext', 4) + call Check_tab_count(4, '-tabnext', 3) + call Check_tab_count(4, '-2tabnext', 2) + call Check_tab_count(3, '$tabnext', 5) + call assert_fails('0tabnext', 'E16:') + call assert_fails('99tabnext', 'E16:') + call assert_fails('+99tabnext', 'E16:') + call assert_fails('-99tabnext', 'E16:') + call Check_tab_count(1, 'tabnext 3', 3) + call Check_tab_count(2, 'tabnext +', 3) + call Check_tab_count(2, 'tabnext +2', 4) + call Check_tab_count(4, 'tabnext -', 3) + call Check_tab_count(4, 'tabnext -2', 2) + call Check_tab_count(3, 'tabnext $', 5) + call assert_fails('tabnext 0', 'E474:') + call assert_fails('tabnext .', 'E474:') + call assert_fails('tabnext -+', 'E474:') + call assert_fails('tabnext +2-', 'E474:') + call assert_fails('tabnext $3', 'E474:') + call assert_fails('tabnext 99', 'E474:') + call assert_fails('tabnext +99', 'E474:') + call assert_fails('tabnext -99', 'E474:') + + 1tabonly! +endfunction + +" Test for [count] of tabprevious +function Test_tabpage_with_tabprevious() + for n in range(5) + tabedit + call setline(1, ['', '', '3']) + endfor + + for cmd in ['tabNext', 'tabprevious'] + call Check_tab_count(6, cmd, 5) + call Check_tab_count(6, '3' . cmd, 3) + call Check_tab_count(6, '8' . cmd, 4) + call Check_tab_count(6, cmd . ' 3', 3) + call Check_tab_count(6, cmd . ' 8', 4) + for n in range(2) + for c in ['0', '.+3', '+', '+2' , '-', '-2' , '$', '+99', '-99'] + if n == 0 " pre count + let entire_cmd = c . cmd + let err_code = 'E16:' + else + let entire_cmd = cmd . ' ' . c + let err_code = 'E474:' + endif + call assert_fails(entire_cmd, err_code) + endfor + endfor + endfor + + 1tabonly! +endfunction + +function s:reconstruct_tabpage_for_test(nr) + let n = (a:nr > 2) ? a:nr - 2 : 1 + 1tabonly! + 0tabedit n0 + for n in range(1, n) + exec '$tabedit n' . n + if n == 1 + call setline(1, ['', '', '3']) + endif + endfor +endfunc + +func Test_tabpage_ctrl_pgup_pgdown() + enew! + tabnew tab1 + tabnew tab2 + + call assert_equal(3, tabpagenr()) + exe "norm! \<C-PageUp>" + call assert_equal(2, tabpagenr()) + exe "norm! \<C-PageDown>" + call assert_equal(3, tabpagenr()) + + " Check wrapping at last or first page. + exe "norm! \<C-PageDown>" + call assert_equal(1, tabpagenr()) + exe "norm! \<C-PageUp>" + call assert_equal(3, tabpagenr()) + + " With a count, <C-PageUp> and <C-PageDown> are not symmetrical somehow: + " - {count}<C-PageUp> goes {count} pages downward (relative count) + " - {count}<C-PageDown> goes to page number {count} (absolute count) + exe "norm! 2\<C-PageUp>" + call assert_equal(1, tabpagenr()) + exe "norm! 2\<C-PageDown>" + call assert_equal(2, tabpagenr()) + + 1tabonly! +endfunc + +" Test for [count] of tabclose +function Test_tabpage_with_tabclose() + + " pre count + call s:reconstruct_tabpage_for_test(6) + call Check_tab_count(3, 'tabclose!', 3) + call Check_tab_count(1, '3tabclose', 1) + call Check_tab_count(4, '4tabclose', 3) + call Check_tab_count(3, '1tabclose', 2) + call Check_tab_count(2, 'tabclose', 1) + call assert_equal(1, tabpagenr('$')) + call assert_equal('', bufname('')) + + call s:reconstruct_tabpage_for_test(6) + call Check_tab_count(2, '$tabclose', 2) + call Check_tab_count(4, '.tabclose', 4) + call Check_tab_count(3, '.+tabclose', 3) + call Check_tab_count(3, '.-2tabclose', 2) + call Check_tab_count(1, '.+1tabclose!', 1) + call assert_equal(1, tabpagenr('$')) + call assert_equal('', bufname('')) + + " post count + call s:reconstruct_tabpage_for_test(6) + call Check_tab_count(3, 'tabclose!', 3) + call Check_tab_count(1, 'tabclose 3', 1) + call Check_tab_count(4, 'tabclose 4', 3) + call Check_tab_count(3, 'tabclose 1', 2) + call Check_tab_count(2, 'tabclose', 1) + call assert_equal(1, tabpagenr('$')) + call assert_equal('', bufname('')) + + call s:reconstruct_tabpage_for_test(6) + call Check_tab_count(2, 'tabclose $', 2) + call Check_tab_count(4, 'tabclose', 4) + call Check_tab_count(3, 'tabclose +', 3) + call Check_tab_count(3, 'tabclose -2', 2) + call Check_tab_count(1, 'tabclose! +1', 1) + call assert_equal(1, tabpagenr('$')) + call assert_equal('', bufname('')) + + call s:reconstruct_tabpage_for_test(6) + for n in range(2) + for c in ['0', '$3', '99', '+99', '-99'] + if n == 0 " pre count + let entire_cmd = c . 'tabclose' + let err_code = 'E16:' + else + let entire_cmd = 'tabclose ' . c + let err_code = 'E474:' + endif + call assert_fails(entire_cmd, err_code) + call assert_equal(6, tabpagenr('$')) + endfor + endfor + + call assert_fails('3tabclose', 'E37:') + call assert_fails('tabclose 3', 'E37:') + call assert_fails('tabclose -+', 'E474:') + call assert_fails('tabclose +2-', 'E474:') + call assert_equal(6, tabpagenr('$')) + + 1tabonly! +endfunction + +" Test for [count] of tabonly +function Test_tabpage_with_tabonly() + + " Test for the normal behavior (pre count only) + let tc = [ [4, '.', '!'], [2, '.+', ''], [3, '.-2', '!'], [1, '.+1', '!'] ] + for c in tc + call s:reconstruct_tabpage_for_test(6) + let entire_cmd = c[1] . 'tabonly' . c[2] + call Check_tab_count(c[0], entire_cmd, 1) + call assert_equal(1, tabpagenr('$')) + endfor + + " Test for the normal behavior + let tc2 = [ [3, '', ''], [1, '3', ''], [4, '4', '!'], [3, '1', '!'], + \ [2, '', '!'], + \ [2, '$', '!'], [3, '+', '!'], [3, '-2', '!'], [3, '+1', '!'] + \ ] + for n in range(2) + for c in tc2 + call s:reconstruct_tabpage_for_test(6) + if n == 0 " pre count + let entire_cmd = c[1] . 'tabonly' . c[2] + else + let entire_cmd = 'tabonly' . c[2] . ' ' . c[1] + endif + call Check_tab_count(c[0], entire_cmd, 1) + call assert_equal(1, tabpagenr('$')) + endfor + endfor + + " Test for the error behavior + for n in range(2) + for c in ['0', '$3', '99', '+99', '-99'] + call s:reconstruct_tabpage_for_test(6) + if n == 0 " pre count + let entire_cmd = c . 'tabonly' + let err_code = 'E16:' + else + let entire_cmd = 'tabonly ' . c + let err_code = 'E474:' + endif + call assert_fails(entire_cmd, err_code) + call assert_equal(6, tabpagenr('$')) + endfor + endfor + + " Test for the error behavior (post count only) + for c in tc + call s:reconstruct_tabpage_for_test(6) + let entire_cmd = 'tabonly' . c[2] . ' ' . c[1] + let err_code = 'E474:' + call assert_fails(entire_cmd, err_code) + call assert_equal(6, tabpagenr('$')) + endfor + + call assert_fails('tabonly -+', 'E474:') + call assert_fails('tabonly +2-', 'E474:') + call assert_equal(6, tabpagenr('$')) + + 1tabonly! + new + only! +endfunction + +func Test_tabnext_on_buf_unload1() + " This once caused a crash + new + tabedit + tabfirst + au BufUnload <buffer> tabnext + q + + while tabpagenr('$') > 1 + bwipe! + endwhile +endfunc + +func Test_tabnext_on_buf_unload2() + " This once caused a crash + tabedit + autocmd BufUnload <buffer> tabnext + file x + edit y + + while tabpagenr('$') > 1 + bwipe! + endwhile +endfunc + +func Test_close_on_quitpre() + " This once caused a crash + edit Xtest + new + only + set bufhidden=delete + au QuitPre <buffer> close + tabnew tab1 + tabnew tab2 + 1tabn + q! + call assert_equal(1, tabpagenr()) + call assert_equal(2, tabpagenr('$')) + " clean up + while tabpagenr('$') > 1 + bwipe! + endwhile + buf Xtest +endfunc + +func Test_tabs() + enew! + tabnew tab1 + norm ixxx + let a=split(execute(':tabs'), "\n") + call assert_equal(['Tab page 1', + \ ' [No Name]', + \ 'Tab page 2', + \ '> + tab1'], a) + + 1tabonly! + bw! +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_tagcase.vim b/src/testdir/test_tagcase.vim new file mode 100644 index 0000000..83e5328 --- /dev/null +++ b/src/testdir/test_tagcase.vim @@ -0,0 +1,73 @@ +" test 'tagcase' option + +func Test_tagcase() + call writefile(["Bar\tXtext\t3", "Foo\tXtext\t2", "foo\tXtext\t4"], 'Xtags') + set tags=Xtags + e Xtext + + for &ic in [0, 1] + for &scs in [0, 1] + for &g:tc in ["followic", "ignore", "match", "followscs", "smart"] + for &l:tc in ["", "followic", "ignore", "match", "followscs", "smart"] + let smart = 0 + if &l:tc != '' + let tc = &l:tc + else + let tc = &g:tc + endif + if tc == 'followic' + let ic = &ic + elseif tc == 'ignore' + let ic = 1 + elseif tc == 'followscs' + let ic = &ic + let smart = &scs + elseif tc == 'smart' + let ic = 1 + let smart = 1 + else + let ic = 0 + endif + if ic && smart + call assert_equal(['foo', 'Foo'], map(taglist("^foo$"), {i, v -> v.name})) + call assert_equal(['Foo'], map(taglist("^Foo$"), {i, v -> v.name})) + elseif ic + call assert_equal(['foo', 'Foo'], map(taglist("^foo$"), {i, v -> v.name})) + call assert_equal(['Foo', 'foo'], map(taglist("^Foo$"), {i, v -> v.name})) + else + call assert_equal(['foo'], map(taglist("^foo$"), {i, v -> v.name})) + call assert_equal(['Foo'], map(taglist("^Foo$"), {i, v -> v.name})) + endif + endfor + endfor + endfor + endfor + + call delete('Xtags') + set ic& + setg tc& + setl tc& + set scs& +endfunc + +func Test_set_tagcase() + " Verify default values. + set ic& + setg tc& + setl tc& + call assert_equal(0, &ic) + call assert_equal('followic', &g:tc) + call assert_equal('followic', &l:tc) + call assert_equal('followic', &tc) + + " Verify that the local setting accepts <empty> but that the global setting + " does not. The first of these (setting the local value to <empty>) should + " succeed; the other two should fail. + setl tc= + call assert_fails('setg tc=', 'E474:') + call assert_fails('set tc=', 'E474:') + + set ic& + setg tc& + setl tc& +endfunc diff --git a/src/testdir/test_tagjump.vim b/src/testdir/test_tagjump.vim new file mode 100644 index 0000000..ae47a69 --- /dev/null +++ b/src/testdir/test_tagjump.vim @@ -0,0 +1,369 @@ +" Tests for tagjump (tags and special searches) + +" SEGV occurs in older versions. (At least 7.4.1748 or older) +func Test_ptag_with_notagstack() + set notagstack + call assert_fails('ptag does_not_exist_tag_name', 'E426') + set tagstack&vim +endfunc + +func Test_cancel_ptjump() + set tags=Xtags + call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", + \ "word\tfile1\tcmd1", + \ "word\tfile2\tcmd2"], + \ 'Xtags') + + only! + call feedkeys(":ptjump word\<CR>\<CR>", "xt") + help + call assert_equal(2, winnr('$')) + + call delete('Xtags') + quit +endfunc + +func Test_static_tagjump() + set tags=Xtags + call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", + \ "one\tXfile1\t/^one/;\"\tf\tfile:\tsignature:(void)", + \ "word\tXfile2\tcmd2"], + \ 'Xtags') + new Xfile1 + call setline(1, ['empty', 'one()', 'empty']) + write + tag one + call assert_equal(2, line('.')) + + bwipe! + set tags& + call delete('Xtags') + call delete('Xfile1') +endfunc + +func Test_duplicate_tagjump() + set tags=Xtags + call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", + \ "thesame\tXfile1\t1;\"\td\tfile:", + \ "thesame\tXfile1\t2;\"\td\tfile:", + \ "thesame\tXfile1\t3;\"\td\tfile:", + \ ], + \ 'Xtags') + new Xfile1 + call setline(1, ['thesame one', 'thesame two', 'thesame three']) + write + tag thesame + call assert_equal(1, line('.')) + tnext + call assert_equal(2, line('.')) + tnext + call assert_equal(3, line('.')) + + bwipe! + set tags& + call delete('Xtags') + call delete('Xfile1') +endfunc + +func Test_tagjump_switchbuf() + set tags=Xtags + call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", + \ "second\tXfile1\t2", + \ "third\tXfile1\t3",], + \ 'Xtags') + call writefile(['first', 'second', 'third'], 'Xfile1') + + enew | only + set switchbuf= + stag second + call assert_equal(2, winnr('$')) + call assert_equal(2, line('.')) + stag third + call assert_equal(3, winnr('$')) + call assert_equal(3, line('.')) + + enew | only + set switchbuf=useopen + stag second + call assert_equal(2, winnr('$')) + call assert_equal(2, line('.')) + stag third + call assert_equal(2, winnr('$')) + call assert_equal(3, line('.')) + + enew | only + set switchbuf=usetab + tab stag second + call assert_equal(2, tabpagenr('$')) + call assert_equal(2, line('.')) + 1tabnext | stag third + call assert_equal(2, tabpagenr('$')) + call assert_equal(3, line('.')) + + tabclose! + enew | only + call delete('Xfile1') + call delete('Xtags') + set switchbuf&vim +endfunc + +" Tests for [ CTRL-I and CTRL-W CTRL-I commands +function Test_keyword_jump() + call writefile(["#include Xinclude", "", + \ "", + \ "/* test text test tex start here", + \ " some text", + \ " test text", + \ " start OK if found this line", + \ " start found wrong line", + \ "test text"], 'Xtestfile') + call writefile(["/* test text test tex start here", + \ " some text", + \ " test text", + \ " start OK if found this line", + \ " start found wrong line", + \ "test text"], 'Xinclude') + new Xtestfile + call cursor(1,1) + call search("start") + exe "normal! 5[\<C-I>" + call assert_equal(" start OK if found this line", getline('.')) + call cursor(1,1) + call search("start") + exe "normal! 5\<C-W>\<C-I>" + call assert_equal(" start OK if found this line", getline('.')) + enew! | only + call delete('Xtestfile') + call delete('Xinclude') +endfunction + +" Test for jumping to a tag with 'hidden' set, with symbolic link in path of +" tag. This only works for Unix, because of the symbolic link. +func Test_tag_symbolic() + if !has('unix') + return + endif + set hidden + call delete("Xtest.dir", "rf") + call system("ln -s . Xtest.dir") + " Create a tags file with the current directory name inserted. + call writefile([ + \ "SECTION_OFF " . getcwd() . "/Xtest.dir/Xtest.c /^#define SECTION_OFF 3$/", + \ '', + \ ], 'Xtags') + call writefile(['#define SECTION_OFF 3', + \ '#define NUM_SECTIONS 3'], 'Xtest.c') + + " Try jumping to a tag, but with a path that contains a symbolic link. When + " wrong, this will give the ATTENTION message. The next space will then be + " eaten by hit-return, instead of moving the cursor to 'd'. + set tags=Xtags + enew! + call append(0, 'SECTION_OFF') + call cursor(1,1) + exe "normal \<C-]> " + call assert_equal('Xtest.c', expand('%:t')) + call assert_equal(2, col('.')) + + set hidden& + set tags& + enew! + call delete('Xtags') + call delete('Xtest.c') + call delete("Xtest.dir", "rf") + %bwipe! +endfunc + +" Tests for tag search with !_TAG_FILE_ENCODING. +" Depends on the test83-tags2 and test83-tags3 files. +func Test_tag_file_encoding() + if has('vms') + return + endif + + if !has('iconv') || iconv("\x82\x60", "cp932", "utf-8") != "\uff21" + return + endif + + let save_enc = &encoding + set encoding=utf8 + + let content = ['text for tags1', 'abcdefghijklmnopqrs'] + call writefile(content, 'Xtags1.txt') + let content = ['text for tags2', 'ABC'] + call writefile(content, 'Xtags2.txt') + let content = ['text for tags3', 'ABC'] + call writefile(content, 'Xtags3.txt') + let content = ['!_TAG_FILE_ENCODING utf-8 //', 'abcdefghijklmnopqrs Xtags1.txt /abcdefghijklmnopqrs'] + call writefile(content, 'Xtags1') + + " case1: + new + set tags=Xtags1 + tag abcdefghijklmnopqrs + call assert_equal('Xtags1.txt', expand('%:t')) + call assert_equal('abcdefghijklmnopqrs', getline('.')) + close + + " case2: + new + set tags=test83-tags2 + tag /.BC + call assert_equal('Xtags2.txt', expand('%:t')) + call assert_equal('ABC', getline('.')) + close + + " case3: + new + set tags=test83-tags3 + tag abc50 + call assert_equal('Xtags3.txt', expand('%:t')) + call assert_equal('ABC', getline('.')) + close + + set tags& + let &encoding = save_enc + call delete('Xtags1.txt') + call delete('Xtags2.txt') + call delete('Xtags3.txt') + call delete('Xtags1') +endfunc + +func Test_tagjump_etags() + if !has('emacs_tags') + return + endif + call writefile([ + \ "void foo() {}", + \ "int main(int argc, char **argv)", + \ "{", + \ "\tfoo();", + \ "\treturn 0;", + \ "}", + \ ], 'Xmain.c') + + call writefile([ + \ "\x0c", + \ "Xmain.c,64", + \ "void foo() {}\x7ffoo\x011,0", + \ "int main(int argc, char **argv)\x7fmain\x012,14", + \ ], 'Xtags') + set tags=Xtags + ta foo + call assert_equal('void foo() {}', getline('.')) + + call delete('Xtags') + call delete('Xmain.c') + bwipe! +endfunc + +" Test for getting and modifying the tag stack +func Test_getsettagstack() + call writefile(['line1', 'line2', 'line3'], 'Xfile1') + call writefile(['line1', 'line2', 'line3'], 'Xfile2') + call writefile(['line1', 'line2', 'line3'], 'Xfile3') + + enew | only + call settagstack(1, {'items' : []}) + call assert_equal(0, gettagstack(1).length) + call assert_equal([], gettagstack(1).items) + " Error cases + call assert_equal({}, gettagstack(100)) + call assert_equal(-1, settagstack(100, {'items' : []})) + call assert_fails('call settagstack(1, [1, 10])', 'E715') + call assert_fails("call settagstack(1, {'items' : 10})", 'E714') + call assert_fails("call settagstack(1, {'items' : []}, 10)", 'E928') + call assert_fails("call settagstack(1, {'items' : []}, 'b')", 'E962') + + set tags=Xtags + call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", + \ "one\tXfile1\t1", + \ "three\tXfile3\t3", + \ "two\tXfile2\t2"], + \ 'Xtags') + + let stk = [] + call add(stk, {'bufnr' : bufnr('%'), 'tagname' : 'one', + \ 'from' : [bufnr('%'), line('.'), col('.'), 0], 'matchnr' : 1}) + tag one + call add(stk, {'bufnr' : bufnr('%'), 'tagname' : 'two', + \ 'from' : [bufnr('%'), line('.'), col('.'), 0], 'matchnr' : 1}) + tag two + call add(stk, {'bufnr' : bufnr('%'), 'tagname' : 'three', + \ 'from' : [bufnr('%'), line('.'), col('.'), 0], 'matchnr' : 1}) + tag three + call assert_equal(3, gettagstack(1).length) + call assert_equal(stk, gettagstack(1).items) + " Check for default - current window + call assert_equal(3, gettagstack().length) + call assert_equal(stk, gettagstack().items) + + " Try to set current index to invalid values + call settagstack(1, {'curidx' : -1}) + call assert_equal(1, gettagstack().curidx) + call settagstack(1, {'curidx' : 50}) + call assert_equal(4, gettagstack().curidx) + + " Try pushing invalid items onto the stack + call settagstack(1, {'items' : []}) + call settagstack(1, {'items' : ["plate"]}, 'a') + call assert_equal(0, gettagstack().length) + call assert_equal([], gettagstack().items) + call settagstack(1, {'items' : [{"tagname" : "abc"}]}, 'a') + call assert_equal(0, gettagstack().length) + call assert_equal([], gettagstack().items) + call settagstack(1, {'items' : [{"from" : 100}]}, 'a') + call assert_equal(0, gettagstack().length) + call assert_equal([], gettagstack().items) + call settagstack(1, {'items' : [{"from" : [2, 1, 0, 0]}]}, 'a') + call assert_equal(0, gettagstack().length) + call assert_equal([], gettagstack().items) + + " Push one item at a time to the stack + call settagstack(1, {'items' : []}) + call settagstack(1, {'items' : [stk[0]]}, 'a') + call settagstack(1, {'items' : [stk[1]]}, 'a') + call settagstack(1, {'items' : [stk[2]]}, 'a') + call settagstack(1, {'curidx' : 4}) + call assert_equal({'length' : 3, 'curidx' : 4, 'items' : stk}, + \ gettagstack(1)) + + " Try pushing items onto a full stack + for i in range(7) + call settagstack(1, {'items' : stk}, 'a') + endfor + call assert_equal(20, gettagstack().length) + call settagstack(1, + \ {'items' : [{'tagname' : 'abc', 'from' : [1, 10, 1, 0]}]}, 'a') + call assert_equal('abc', gettagstack().items[19].tagname) + + " Tag with multiple matches + call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", + \ "two\tXfile1\t1", + \ "two\tXfile2\t3", + \ "two\tXfile3\t2"], + \ 'Xtags') + call settagstack(1, {'items' : []}) + tag two + tnext + tnext + call assert_equal(1, gettagstack().length) + call assert_equal(3, gettagstack().items[0].matchnr) + + " Memory allocation failures + call test_alloc_fail(GetAllocId('tagstack_items'), 0, 0) + call assert_fails('call gettagstack()', 'E342:') + call test_alloc_fail(GetAllocId('tagstack_from'), 0, 0) + call assert_fails('call gettagstack()', 'E342:') + call test_alloc_fail(GetAllocId('tagstack_details'), 0, 0) + call assert_fails('call gettagstack()', 'E342:') + + call settagstack(1, {'items' : []}) + call delete('Xfile1') + call delete('Xfile2') + call delete('Xfile3') + call delete('Xtags') + set tags& +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_taglist.vim b/src/testdir/test_taglist.vim new file mode 100644 index 0000000..0a9350a --- /dev/null +++ b/src/testdir/test_taglist.vim @@ -0,0 +1,86 @@ +" test taglist(), tagfiles() functions and :tags command + +func Test_taglist() + call writefile([ + \ "FFoo\tXfoo\t1", + \ "FBar\tXfoo\t2", + \ "BFoo\tXbar\t1", + \ "BBar\tXbar\t2" + \ ], 'Xtags') + set tags=Xtags + split Xtext + + call assert_equal(['FFoo', 'BFoo'], map(taglist("Foo"), {i, v -> v.name})) + call assert_equal(['FFoo', 'BFoo'], map(taglist("Foo", "Xtext"), {i, v -> v.name})) + call assert_equal(['FFoo', 'BFoo'], map(taglist("Foo", "Xfoo"), {i, v -> v.name})) + call assert_equal(['BFoo', 'FFoo'], map(taglist("Foo", "Xbar"), {i, v -> v.name})) + + call delete('Xtags') + bwipe +endfunc + +func Test_taglist_native_etags() + if !has('emacs_tags') + return + endif + call writefile([ + \ "\x0c", + \ "src/os_unix.c,13491", + \ "set_signals(\x7f1335,32699", + \ "reset_signals(\x7f1407,34136", + \ ], 'Xtags') + + set tags=Xtags + + call assert_equal([['set_signals', '1335,32699'], ['reset_signals', '1407,34136']], + \ map(taglist('set_signals'), {i, v -> [v.name, v.cmd]})) + + call delete('Xtags') +endfunc + +func Test_taglist_ctags_etags() + if !has('emacs_tags') + return + endif + call writefile([ + \ "\x0c", + \ "src/os_unix.c,13491", + \ "set_signals(void)\x7fset_signals\x011335,32699", + \ "reset_signals(void)\x7freset_signals\x011407,34136", + \ ], 'Xtags') + + set tags=Xtags + + call assert_equal([['set_signals', '1335,32699'], ['reset_signals', '1407,34136']], + \ map(taglist('set_signals'), {i, v -> [v.name, v.cmd]})) + + call delete('Xtags') +endfunc + +func Test_tags_too_long() + call assert_fails('tag ' . repeat('x', 1020), 'E426') + tags +endfunc + +func Test_tagfiles() + call assert_equal([], tagfiles()) + + call writefile(["FFoo\tXfoo\t1"], 'Xtags1') + call writefile(["FBar\tXbar\t1"], 'Xtags2') + set tags=Xtags1,Xtags2 + call assert_equal(['Xtags1', 'Xtags2'], tagfiles()) + + help + let tf = tagfiles() + call assert_equal(1, len(tf)) + call assert_equal(fnamemodify(expand('$VIMRUNTIME/doc/tags'), ':p:gs?\\?/?'), + \ fnamemodify(tf[0], ':p:gs?\\?/?')) + helpclose + call assert_equal(['Xtags1', 'Xtags2'], tagfiles()) + set tags& + call assert_equal([], tagfiles()) + + call delete('Xtags1') + call delete('Xtags2') + bd +endfunc diff --git a/src/testdir/test_tcl.vim b/src/testdir/test_tcl.vim new file mode 100644 index 0000000..c0eadc6 --- /dev/null +++ b/src/testdir/test_tcl.vim @@ -0,0 +1,680 @@ +" Tests for the Tcl interface. + +if !has('tcl') + finish +end + +" Helper function as there is no builtin tcleval() function similar +" to perleval, luaevel(), pyeval(), etc. +func TclEval(tcl_expr) + let s = split(execute('tcl ' . a:tcl_expr), "\n") + return (len(s) == 0) ? '' : s[-1] +endfunc + +func Test_tcldo() + " Check deleting lines does not trigger ml_get error. + new + call setline(1, ['one', 'two', 'three']) + tcldo ::vim::command %d_ + bwipe! + + " Check that switching to another buffer does not trigger ml_get error. + new + let wincount = winnr('$') + call setline(1, ['one', 'two', 'three']) + tcldo ::vim::command new + call assert_equal(wincount + 1, winnr('$')) + %bwipe! +endfunc + +" Test :tcldo with a range +func Test_tcldo_range() + new + call setline(1, ['line1', 'line2', 'line3', 'line4']) + 2,3tcldo set line [string toupper $line] + call assert_equal(['line1', 'LINE2', 'LINE3', 'line4'], getline(1, '$')) + bwipe! +endfunc + +" Test ::vim::beep +func Test_vim_beep() + call assert_beeps('tcl ::vim::beep') + call assert_fails('tcl ::vim::beep x', 'wrong # args: should be "::vim::beep"') +endfunc + +" Test ::vim::buffer +func Test_vim_buffer() + " Test ::vim::buffer {nr} + e Xfoo1 + call setline(1, ['foobar']) + let bn1 = bufnr('%') + let b1 = TclEval('::vim::buffer ' . bn1) + call assert_equal(b1, TclEval('set ::vim::current(buffer)')) + + new Xfoo2 + call setline(1, ['barfoo']) + let bn2 = bufnr('%') + let b2 = TclEval('::vim::buffer ' . bn2) + call assert_equal(b2, TclEval('set ::vim::current(buffer)')) + + call assert_match('Xfoo1$', TclEval(b1 . ' name')) + call assert_match('Xfoo2$', TclEval(b2 . ' name')) + + " Test ::vim::buffer exists {nr} + call assert_match('^[1-9]\d*$', TclEval('::vim::buffer exists ' . bn1)) + call assert_match('^[1-9]\d*$', TclEval('::vim::buffer exists ' . bn2)) + call assert_equal('0', TclEval('::vim::buffer exists 54321')) + + " Test ::vim::buffer list + call assert_equal('2', TclEval('llength [::vim::buffer list]')) + call assert_equal(b1.' '.b2, TclEval('::vim::buffer list')) + tcl <<EOF + proc eachbuf { cmd } { + foreach b [::vim::buffer list] { $b command $cmd } + } +EOF + tcl eachbuf %s/foo/FOO/g + b! Xfoo1 + call assert_equal(['FOObar'], getline(1, '$')) + b! Xfoo2 + call assert_equal(['barFOO'], getline(1, '$')) + + call assert_fails('tcl ::vim::buffer', + \ 'wrong # args: should be "::vim::buffer option"') + call assert_fails('tcl ::vim::buffer ' . bn1 . ' x', + \ 'wrong # args: should be "::vim::buffer bufNumber"') + call assert_fails('tcl ::vim::buffer 4321', 'invalid buffer number') + call assert_fails('tcl ::vim::buffer x', + \ 'bad option "x": must be exists or list') + call assert_fails('tcl ::vim::buffer exists', + \ 'wrong # args: should be "::vim::buffer exists bufNumber"') + call assert_fails('tcl ::vim::buffer exists x', + \ 'expected integer but got "x"') + call assert_fails('tcl ::vim::buffer list x', + \ 'wrong # args: should be "::vim::buffer list "') + + tcl rename eachbuf "" + %bwipe! +endfunc + +" Test ::vim::option +func Test_vim_option() + set cc=3,5 + + " Test getting option 'cc' + call assert_equal('3,5', TclEval('::vim::option cc')) + call assert_equal('3,5', &cc) + + " Test setting option 'cc' (it returns the old option value) + call assert_equal('3,5', TclEval('::vim::option cc +4')) + call assert_equal('+4', &cc) + call assert_equal('+4', TclEval('::vim::option cc')) + + " Test boolean option with 'toggle', 'on' and 'off' keywords. + call assert_equal('0', TclEval('::vim::option nu toggle')) + call assert_equal(1, &nu) + call assert_equal('1', TclEval('::vim::option nu toggle')) + call assert_equal(0, &nu) + call assert_equal('0', TclEval('::vim::option nu on')) + call assert_equal(1, &nu) + call assert_equal('1', TclEval('::vim::option nu off')) + call assert_equal(0, &nu) + + call assert_fails('tcl ::vim::option nu x', 'expected integer but got "x"') + call assert_fails('tcl ::vim::option xxx', 'unknown vimOption') + call assert_fails('tcl ::vim::option', + \ 'wrong # args: should be "::vim::option vimOption ?value?"') + + set cc& +endfunc + +" Test ::vim::expr +func Test_vim_expr() + call assert_equal(string(char2nr('X')), + \ TclEval('::vim::expr char2nr("X")')) + + call assert_fails('tcl ::vim::expr x y', + \ 'wrong # args: should be "::vim::expr vimExpr"') + call assert_fails('tcl ::vim::expr 1-', 'E15: Invalid expression: 1-') +endfunc + +" Test ::vim::command +func Test_vim_command() + call assert_equal('hello world', + \ TclEval('::vim::command {echo "hello world"}')) + + " Check that if ::vim::command created a new Tcl interpreter, it is removed. + tcl set foo 123 + call assert_equal('321', TclEval('::vim::command "tcl set foo 321"')) + call assert_equal('123', TclEval('set foo')) + + " With the -quiet option, the error should silently be ignored. + call assert_equal('', TclEval('::vim::command -quiet xyz')) + + call assert_fails('tcl ::vim::command', + \ 'wrong # args: should be "::vim::command ?-quiet? exCommand"') + call assert_fails('tcl ::vim::command -foo xyz', 'unknown flag: -foo') + call assert_fails('tcl ::vim::command xyz', + \ 'E492: Not an editor command: xyz') + + " With the -quiet option, the error should silently be ignored. + call assert_equal('', TclEval('::vim::command -quiet xyz')) + + tcl unset foo +endfunc + +" Test ::vim::window list +func Test_vim_window_list() + e Xfoo1 + new Xfoo2 + let w2 = TclEval('set ::vim::current(window)') + wincmd j + let w1 = TclEval('set ::vim::current(window)') + + call assert_equal('2', TclEval('llength [::vim::window list]')) + call assert_equal(w2.' '.w1, TclEval('::vim::window list')) + + call assert_fails('tcl ::vim::window x', 'unknown option') + call assert_fails('tcl ::vim::window list x', + \ 'wrong # args: should be "::vim::window option"') + + %bwipe +endfunc + +" Test output messages +func Test_output() + call assert_fails('tcl puts vimerr "error #1"', 'error #1') + call assert_fails('tcl puts stderr "error #2"', 'error #2') + tcl puts vimout "message #1" + tcl puts stdout "message #2" + tcl puts "message #3" + let messages = split(execute('message'), "\n") + call assert_equal('message #3', messages[-1]) + call assert_equal('message #2', messages[-2]) + call assert_equal('message #1', messages[-3]) + + call assert_fails('tcl puts', + \ 'wrong # args: should be "puts ?-nonewline? ?channelId? string"') +endfunc + +" Test $win height (get and set window height) +func Test_window_height() + new + + " Test setting window height + tcl $::vim::current(window) height 2 + call assert_equal(2, winheight(0)) + + " Test getting window height + call assert_equal('2', TclEval('$::vim::current(window) height')) + + call assert_fails('tcl $::vim::current(window) height 2 2', 'wrong # args:') + call assert_fails('tcl $::vim::current(window) height x', + \ 'expected integer but got "x"') + bwipe +endfunc + +" Test $win cursor (get and set cursor) +func Test_window_cursor() + new + call setline(1, ['line1', 'line2', 'line3', 'line5']) + tcl set win $::vim::current(window) + + tcl $win cursor 2 4 + call assert_equal([0, 2, 4, 0], getpos('.')) + call assert_equal('row 2 column 4', TclEval('$win cursor')) + + " When setting ::vim::lbase to 0, line/col are counted from 0 + " instead of 1. + tcl set ::vim::lbase 0 + call assert_equal([0, 2, 4, 0], getpos('.')) + call assert_equal('row 1 column 3', TclEval('$win cursor')) + tcl $win cursor 2 4 + call assert_equal([0, 3, 5, 0], getpos('.')) + call assert_equal('row 2 column 4', TclEval('$win cursor')) + tcl set ::vim::lbase 1 + call assert_equal('row 3 column 5', TclEval('$win cursor')) + call assert_equal([0, 3, 5, 0], getpos('.')) + + " test $win cursor {$var} + call cursor(2, 3) + tcl array set here [$win cursor] + call assert_equal([0, 2, 3, 0], getpos('.')) + call cursor(3, 1) + call assert_equal([0, 3, 1, 0], getpos('.')) + tcl $win cursor here + call assert_equal([0, 2, 3, 0], getpos('.')) + call cursor(3, 1) + call assert_equal([0, 3, 1, 0], getpos('.')) + tcl $win cursor $here(row) $here(column) + call assert_equal([0, 2, 3, 0], getpos('.')) + + call assert_fails('tcl $win cursor 1 1 1', 'wrong # args:') + + tcl unset win here + bwipe! +endfunc + +" Test $win buffer +func Test_window_buffer() + new Xfoo1 + new Xfoo2 + tcl set b2 $::vim::current(buffer) + tcl set w2 $::vim::current(window) + wincmd j + tcl set b1 $::vim::current(buffer) + tcl set w1 $::vim::current(window) + + call assert_equal(TclEval('set b1'), TclEval('$w1 buffer')) + call assert_equal(TclEval('set b2'), TclEval('$w2 buffer')) + call assert_equal(string(bufnr('Xfoo1')), TclEval('[$w1 buffer] number')) + call assert_equal(string(bufnr('Xfoo2')), TclEval('[$w2 buffer] number')) + + call assert_fails('tcl $w1 buffer x', 'wrong # args:') + + tcl unset b1 b2 w1 w2 + %bwipe +endfunc + +" Test $win command +func Test_window_command() + new Xfoo1 + call setline(1, ['FOObar']) + new Xfoo2 + call setline(1, ['fooBAR']) + tcl set w2 $::vim::current(window) + wincmd j + tcl set w1 $::vim::current(window) + + tcl $w1 command "norm VU" + tcl $w2 command "norm Vu" + b! Xfoo1 + call assert_equal('FOOBAR', getline(1)) + b! Xfoo2 + call assert_equal('foobar', getline(1)) + + call assert_fails('tcl $w1 command xyz', + \ 'E492: Not an editor command: xyz') + tcl $w1 command -quiet xyz + + tcl unset w1 w2 + %bwipe! +endfunc + +" Test $win expr +func Test_window_expr() + new Xfoo1 + new Xfoo2 + tcl set w2 $::vim::current(window) + wincmd j + tcl set w1 $::vim::current(window) + + call assert_equal('Xfoo1', TclEval('$w1 expr bufname("%")')) + call assert_equal('Xfoo2', TclEval('$w2 expr bufname("%")')) + + call assert_fails('tcl $w1 expr', 'wrong # args:') + call assert_fails('tcl $w1 expr x x', 'wrong # args:') + + tcl unset w1 w2 + %bwipe +endfunc + +" Test $win option +func Test_window_option() + new Xfoo1 + new Xfoo2 + tcl set w2 $::vim::current(window) + wincmd j + tcl set w1 $::vim::current(window) + + " Test setting window option + tcl $w1 option syntax java + tcl $w2 option syntax rust + + call assert_equal('java', &syntax) + wincmd k + call assert_equal('rust', &syntax) + + " Test getting window option + call assert_equal('java', TclEval('$w1 option syntax')) + call assert_equal('rust', TclEval('$w2 option syntax')) + + tcl unset w1 w2 + %bwipe +endfunc + +" Test $win delcmd {cmd} +func Test_window_delcmd() + new + tcl $::vim::current(window) delcmd [list set msg "window deleted"] + call assert_fails('tcl set msg', "can't read \"msg\": no such variable") + q + call assert_equal('window deleted', TclEval('set msg')) + + call assert_fails('tcl $::vim::current(window) delcmd', 'wrong # args') + + tcl unset msg + bwipe +endfunc + +" Test $buf name +func Test_buffer_name() + " Test buffer name with a named buffer + new Xfoo + call assert_equal(expand('%:p'), TclEval('$::vim::current(buffer) name')) + bwipe + + " Test buffer name with an unnamed buffer + new + call assert_equal('', TclEval('$::vim::current(buffer) name')) + + call assert_fails('tcl $::vim::current(buffer) name x', 'wrong # args:') + + bwipe +endfunc + +" Test $buf number +func Test_buffer_number() + new + call assert_equal(string(bufnr('%')), TclEval('$::vim::current(buffer) number')) + new + call assert_equal(string(bufnr('%')), TclEval('$::vim::current(buffer) number')) + + call assert_fails('tcl $::vim::current(buffer) number x', 'wrong # args:') + + %bwipe +endfunc + +" Test $buf count and $buf last +func Test_buffer_count() + new + call setline(1, ['one', 'two', 'three']) + call assert_equal('3', TclEval('$::vim::current(buffer) count')) + call assert_equal('3', TclEval('$::vim::current(buffer) last')) + + " Check that $buf count and $buf last differ when ::vim::lbase is 0. + tcl set ::vim::lbase 0 + call assert_equal('3', TclEval('$::vim::current(buffer) count')) + call assert_equal('2', TclEval('$::vim::current(buffer) last')) + + call assert_fails('tcl $::vim::current(buffer) count x', 'wrong # args:') + call assert_fails('tcl $::vim::current(buffer) last x', 'wrong # args:') + + tcl set ::vim::lbase 1 + bwipe! +endfunc + +" Test $buf delete (delete line(s) in buffer) +func Test_buffer_delete() + new + call setline(1, ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight']) + tcl $::vim::current(buffer) delete 4 6 + tcl $::vim::current(buffer) delete 2 + call assert_equal(['one', 'three', 'seven', 'eight'], getline(1, '$')) + + call assert_fails('tcl $::vim::current(buffer) delete -1', 'line number out of range') + call assert_fails('tcl $::vim::current(buffer) delete 0', 'line number out of range') + call assert_fails('tcl $::vim::current(buffer) delete 5', 'line number out of range') + + call assert_fails('tcl $::vim::current(buffer) delete', 'wrong # args:') + call assert_fails('tcl $::vim::current(buffer) delete 1 2 3', 'wrong # args:') + + bwipe! +endfunc + +" Test $buf insert (insert line(s) in buffer) +func Test_buffer_insert() + new + tcl set buf $::vim::current(buffer) + tcl $buf insert 1 "first" + tcl $buf insert 2 "second" + tcl $buf insert 2 "third" + tcl $buf insert 4 "fourth" + tcl $buf insert 1 "fifth" + call assert_equal(['fifth', 'first', 'third', 'second', 'fourth', ''], getline(1, '$')) + + call assert_fails('tcl $buf insert -1 "x"', 'line number out of range') + call assert_fails('tcl $buf insert 0 "x"', 'line number out of range') + call assert_fails('tcl $buf insert 7 "x"', 'line number out of range') + + tcl unset buf + bwipe! +endfunc + +" Test $buf append (append line in buffer) +func Test_buffer_append() + new + tcl set buf $::vim::current(buffer) + tcl $buf append 1 "first" + tcl $buf append 2 "second" + tcl $buf append 2 "third" + tcl $buf append 4 "fourth" + tcl $buf append 1 "fifth" + call assert_equal(['', 'fifth', 'first', 'third', 'second', 'fourth'], getline(1, '$')) + + call assert_fails('tcl $buf append -1 "x"', 'line number out of range') + call assert_fails('tcl $buf append 0 "x"', 'line number out of range') + call assert_fails('tcl $buf append 7 "x"', 'line number out of range') + + call assert_fails('tcl $buf append', 'wrong # args:') + call assert_fails('tcl $buf append 1 x x', 'wrong # args:') + + tcl unset buf + bwipe! +endfunc + +" Test $buf set (replacing line(s) in a buffer) +func Test_buffer_set() + new + call setline(1, ['line1', 'line2', 'line3', 'line4', 'line5']) + tcl $::vim::current(buffer) set 2 a + call assert_equal(['line1', 'a', 'line3', 'line4', 'line5'], getline(1, '$')) + + " Test with fewer replacing lines than replaced lines: lines get deleted. + tcl $::vim::current(buffer) set 3 4 b + call assert_equal(['line1', 'a', 'b', 'line5'], getline(1, '$')) + tcl $::vim::current(buffer) set 4 3 c + call assert_equal(['line1', 'a', 'c'], getline(1, '$')) + + " Test with more replacing lines than replaced lines: lines get added. + tcl $::vim::current(buffer) set 2 3 {x y z} + call assert_equal(['line1', 'x', 'y', 'z'], getline(1, '$')) + tcl $::vim::current(buffer) set 3 2 {X Y Z} + call assert_equal(['line1', 'X', 'Y', 'Z', 'z'], getline(1, '$')) + + call assert_fails('tcl $::vim::current(buffer) set 0 "x"', 'line number out of range') + call assert_fails('tcl $::vim::current(buffer) set 6 "x"', 'line number out of range') + + call assert_fails('tcl $::vim::current(buffer) set', 'wrong # args:') + bwipe! +endfunc + +" Test $buf get (get line(s) from buffer) +func Test_buffer_get() + new + call setline(1, ['first line', 'two', 'three', 'last line']) + tcl set buf $::vim::current(buffer) + + call assert_equal('first line', TclEval('$buf get top')) + call assert_equal('first line', TclEval('$buf get begin')) + call assert_equal('last line', TclEval('$buf get bottom')) + call assert_equal('last line', TclEval('$buf get last')) + + call assert_equal('first line', TclEval('$buf get 1')) + call assert_equal('two', TclEval('$buf get 2')) + call assert_equal('three', TclEval('$buf get 3')) + call assert_equal('last line', TclEval('$buf get 4')) + + call assert_equal('two three', TclEval('$buf get 2 3')) + call assert_equal('two three', TclEval('$buf get 3 2')) + call assert_equal('three {last line}', TclEval('$buf get 3 last')) + + call assert_fails('tcl $buf get -1', 'line number out of range') + call assert_fails('tcl $buf get 0', 'line number out of range') + call assert_fails('tcl $buf get 5', 'line number out of range') + call assert_fails('tcl $buf get 0 1', 'line number out of range') + + call assert_fails('tcl $::vim::current(buffer) get x', 'expected integer but got "x"') + call assert_fails('tcl $::vim::current(buffer) get 1 1 1', 'wrong # args:') + + tcl unset buf + bwipe! +endfunc + +" Test $buf mark (get position of a mark) +func Test_buffer_mark() + new + call setline(1, ['one', 'two', 'three', 'four']) + /three + norm! ma + norm! jllmB + + call assert_equal('row 3 column 1', TclEval('$::vim::current(buffer) mark a')) + call assert_equal('row 4 column 3', TclEval('$::vim::current(buffer) mark B')) + + call assert_fails('tcl $::vim::current(buffer) mark /', 'invalid mark name') + call assert_fails('tcl $::vim::current(buffer) mark z', 'mark not set') + call assert_fails('tcl $::vim::current(buffer) mark', 'wrong # args:') + + delmarks aB + bwipe! +endfunc + +" Test $buf option (test and set option in context of a buffer) +func Test_buffer_option() + new Xfoo1 + tcl set b1 $::vim::current(buffer) + new Xfoo2 + tcl set b2 $::vim::current(buffer) + + tcl $b1 option foldcolumn 2 + tcl $b2 option foldcolumn 3 + + call assert_equal(3, &foldcolumn) + wincmd j + call assert_equal(2, &foldcolumn) + + call assert_equal('2', TclEval('$b1 option foldcolumn')) + call assert_equal('3', TclEval('$b2 option foldcolumn')) + + call assert_fails('tcl $::vim::current(buffer) option', 'wrong # args:') + + set foldcolumn& + tcl unset b1 b2 + %bwipe +endfunc + +" Test $buf expr (evaluate vim expression) +func Test_buffer_expr() + new Xfoo1 + norm ifoo1 + tcl set b1 $::vim::current(buffer) + + new Xfoo2 + norm ifoo2 + tcl set b2 $::vim::current(buffer) + + call assert_equal('foo1', TclEval('$b1 expr getline(1)')) + call assert_equal('foo2', TclEval('$b2 expr getline(1)')) + + call assert_fails('tcl expr', 'wrong # args:') + + tcl unset b1 b2 + %bwipe! +endfunc + +" Test $buf delcmd {cmd} (command executed when buffer is deleted) +func Test_buffer_delcmd() + new Xfoo + split + tcl $::vim::current(buffer) delcmd [list set msg "buffer deleted"] + q + call assert_fails('tcl set msg', "can't read \"msg\": no such variable") + q + call assert_equal('buffer deleted', TclEval('set msg')) + + call assert_fails('tcl $::vim::current(window) delcmd', 'wrong # args') + call assert_fails('tcl $::vim::current(window) delcmd x x', 'wrong # args') + + tcl unset msg + %bwipe +endfunc + +func Test_vim_current() + " Only test errors as ::vim::current(...) is already indirectly + " tested by many other tests. + call assert_fails('tcl $::vim::current(buffer)', 'wrong # args:') + call assert_fails('tcl $::vim::current(window)', 'wrong # args:') +endfunc + +" Test $buf windows (windows list of a buffer) +func Test_buffer_windows() + new Xfoo + split + new Xbar + split + vsplit + + tcl set bar_wl [$::vim::current(buffer) windows] + 2wincmd j + tcl set foo_wl [$::vim::current(buffer) windows] + + call assert_equal('2', TclEval('llength $foo_wl')) + call assert_equal('3', TclEval('llength $bar_wl')) + + call assert_fails('tcl $::vim::current(buffer) windows x', 'wrong # args:') + + tcl unset bar_wl foo_wl + %bwipe +endfunc + +" Test :tclfile +func Test_tclfile() + call delete('Xtcl_file') + call writefile(['set pi [format "%.2f" [expr acos(-1.0)]]'], 'Xtcl_file') + call setfperm('Xtcl_file', 'r-xr-xr-x') + + tclfile Xtcl_file + call assert_equal('3.14', TclEval('set pi')) + + tcl unset pi + call delete('Xtcl_file') +endfunc + +" Test :tclfile with syntax error in tcl script +func Test_tclfile_error() + call delete('Xtcl_file') + call writefile(['xyz'], 'Xtcl_file') + call setfperm('Xtcl_file', 'r-xr-xr-x') + + call assert_fails('tclfile Xtcl_file', 'invalid command name "xyz"') + + call delete('Xtcl_file') +endfunc + +" Test exiting current Tcl interpreter and re-creating one. +func Test_tcl_exit() + tcl set foo "foo" + call assert_fails('tcl exit 3', 'E572: exit code 3') + + " The Tcl interpreter should have been deleted and a new one + " is re-created with the next :tcl command. + call assert_fails('tcl set foo', "can't read \"foo\": no such variable") + tcl set bar "bar" + call assert_equal('bar', TclEval('set bar')) + + tcl unset bar +endfunc + +func Test_set_cursor() + " Check that setting the cursor position works. + new + call setline(1, ['first line', 'second line']) + normal gg + tcldo $::vim::current(window) cursor 1 5 + call assert_equal([1, 5], [line('.'), col('.')]) + + " Check that movement after setting cursor position keeps current column. + normal j + call assert_equal([2, 5], [line('.'), col('.')]) +endfunc diff --git a/src/testdir/test_termencoding.vim b/src/testdir/test_termencoding.vim new file mode 100644 index 0000000..f4f5c5a --- /dev/null +++ b/src/testdir/test_termencoding.vim @@ -0,0 +1,37 @@ +" Test for setting 'encoding' to something else than the terminal uses, then +" setting 'termencoding' to make it work. + +" This only works with "iconv". +if !has('iconv') + finish +endif + +source screendump.vim +if !CanRunVimInTerminal() + finish +endif + +" This Vim is running with 'encoding' "utf-8", the Vim in the terminal is +" running with 'encoding' "euc-jp". We need to make sure the text is in the +" right encoding, this is a bit tricky. +func Test_termencoding_euc_jp() + new + call setline(1, 'E89: バッファ %ld の変更は保存されていません (! で変更を破棄)') + write ++enc=euc-jp Xeuc_jp.txt + quit + + call writefile([ + \ 'set encoding=euc-jp', + \ 'set termencoding=utf-8', + \ 'scriptencoding utf-8', + \ 'exe "normal aE83: バッファを作成できないので、他のを使用します...\<Esc>"', + \ 'split Xeuc_jp.txt', + \ ], 'XTest_tenc_euc_jp') + let buf = RunVimInTerminal('-S XTest_tenc_euc_jp', {'rows': 10}) + call VerifyScreenDump(buf, 'Test_tenc_euc_jp_01', {}) + + " clean up + call StopVimInTerminal(buf) + call delete('Xeuc_jp.txt') + call delete('XTest_tenc_euc_jp') +endfunc diff --git a/src/testdir/test_terminal.vim b/src/testdir/test_terminal.vim new file mode 100644 index 0000000..8eb43a0 --- /dev/null +++ b/src/testdir/test_terminal.vim @@ -0,0 +1,1758 @@ +" Tests for the terminal window. + +if !has('terminal') + finish +endif + +source shared.vim +source screendump.vim + +let s:python = PythonProg() + +" Open a terminal with a shell, assign the job to g:job and return the buffer +" number. +func Run_shell_in_terminal(options) + if has('win32') + let buf = term_start([&shell,'/k'], a:options) + else + let buf = term_start(&shell, a:options) + endif + + let termlist = term_list() + call assert_equal(1, len(termlist)) + call assert_equal(buf, termlist[0]) + + let g:job = term_getjob(buf) + call assert_equal(v:t_job, type(g:job)) + + let string = string({'job': term_getjob(buf)}) + call assert_match("{'job': 'process \\d\\+ run'}", string) + + return buf +endfunc + +func Test_terminal_basic() + au TerminalOpen * let b:done = 'yes' + let buf = Run_shell_in_terminal({}) + + if has("unix") + call assert_match('^/dev/', job_info(g:job).tty_out) + call assert_match('^/dev/', term_gettty('')) + else + " ConPTY works on anonymous pipe. + if !has('conpty') + call assert_match('^\\\\.\\pipe\\', job_info(g:job).tty_out) + call assert_match('^\\\\.\\pipe\\', term_gettty('')) + endif + endif + call assert_equal('t', mode()) + call assert_equal('yes', b:done) + call assert_match('%aR[^\n]*running]', execute('ls')) + call assert_match('%aR[^\n]*running]', execute('ls R')) + call assert_notmatch('%[^\n]*running]', execute('ls F')) + call assert_notmatch('%[^\n]*running]', execute('ls ?')) + + call Stop_shell_in_terminal(buf) + call term_wait(buf) + call assert_equal('n', mode()) + call assert_match('%aF[^\n]*finished]', execute('ls')) + call assert_match('%aF[^\n]*finished]', execute('ls F')) + call assert_notmatch('%[^\n]*finished]', execute('ls R')) + call assert_notmatch('%[^\n]*finished]', execute('ls ?')) + + " closing window wipes out the terminal buffer a with finished job + close + call assert_equal("", bufname(buf)) + + au! TerminalOpen + unlet g:job +endfunc + +func Test_terminal_make_change() + let buf = Run_shell_in_terminal({}) + call Stop_shell_in_terminal(buf) + call term_wait(buf) + + setlocal modifiable + exe "normal Axxx\<Esc>" + call assert_fails(buf . 'bwipe', 'E517') + undo + + exe buf . 'bwipe' + unlet g:job +endfunc + +func Test_terminal_wipe_buffer() + let buf = Run_shell_in_terminal({}) + call assert_fails(buf . 'bwipe', 'E517') + exe buf . 'bwipe!' + call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) + call assert_equal("", bufname(buf)) + + unlet g:job +endfunc + +func Test_terminal_split_quit() + let buf = Run_shell_in_terminal({}) + call term_wait(buf) + split + quit! + call term_wait(buf) + sleep 50m + call assert_equal('run', job_status(g:job)) + + quit! + call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) + + exe buf . 'bwipe' + unlet g:job +endfunc + +func Test_terminal_hide_buffer() + let buf = Run_shell_in_terminal({}) + setlocal bufhidden=hide + quit + for nr in range(1, winnr('$')) + call assert_notequal(winbufnr(nr), buf) + endfor + call assert_true(bufloaded(buf)) + call assert_true(buflisted(buf)) + + exe 'split ' . buf . 'buf' + call Stop_shell_in_terminal(buf) + exe buf . 'bwipe' + + unlet g:job +endfunc + +func s:Nasty_exit_cb(job, st) + exe g:buf . 'bwipe!' + let g:buf = 0 +endfunc + +func Get_cat_123_cmd() + if has('win32') + if !has('conpty') + return 'cmd /c "cls && color 2 && echo 123"' + else + " When clearing twice, extra sequence is not output. + return 'cmd /c "cls && cls && color 2 && echo 123"' + endif + else + call writefile(["\<Esc>[32m123"], 'Xtext') + return "cat Xtext" + endif +endfunc + +func Test_terminal_nasty_cb() + let cmd = Get_cat_123_cmd() + let g:buf = term_start(cmd, {'exit_cb': function('s:Nasty_exit_cb')}) + let g:job = term_getjob(g:buf) + + call WaitForAssert({-> assert_equal("dead", job_status(g:job))}) + call WaitForAssert({-> assert_equal(0, g:buf)}) + unlet g:job + unlet g:buf + call delete('Xtext') +endfunc + +func Check_123(buf) + let l = term_scrape(a:buf, 0) + call assert_true(len(l) == 0) + let l = term_scrape(a:buf, 999) + call assert_true(len(l) == 0) + let l = term_scrape(a:buf, 1) + call assert_true(len(l) > 0) + call assert_equal('1', l[0].chars) + call assert_equal('2', l[1].chars) + call assert_equal('3', l[2].chars) + call assert_equal('#00e000', l[0].fg) + if has('win32') + " On Windows 'background' always defaults to dark, even though the terminal + " may use a light background. Therefore accept both white and black. + call assert_match('#ffffff\|#000000', l[0].bg) + else + if &background == 'light' + call assert_equal('#ffffff', l[0].bg) + else + call assert_equal('#000000', l[0].bg) + endif + endif + + let l = term_getline(a:buf, -1) + call assert_equal('', l) + let l = term_getline(a:buf, 0) + call assert_equal('', l) + let l = term_getline(a:buf, 999) + call assert_equal('', l) + let l = term_getline(a:buf, 1) + call assert_equal('123', l) +endfunc + +func Test_terminal_scrape_123() + let cmd = Get_cat_123_cmd() + let buf = term_start(cmd) + + let termlist = term_list() + call assert_equal(1, len(termlist)) + call assert_equal(buf, termlist[0]) + + " Nothing happens with invalid buffer number + call term_wait(1234) + + call term_wait(buf) + " On MS-Windows we first get a startup message of two lines, wait for the + " "cls" to happen, after that we have one line with three characters. + call WaitForAssert({-> assert_equal(3, len(term_scrape(buf, 1)))}) + call Check_123(buf) + + " Must still work after the job ended. + let job = term_getjob(buf) + call WaitForAssert({-> assert_equal("dead", job_status(job))}) + call term_wait(buf) + call Check_123(buf) + + exe buf . 'bwipe' + call delete('Xtext') +endfunc + +func Test_terminal_scrape_multibyte() + call writefile(["léttまrs"], 'Xtext') + if has('win32') + " Run cmd with UTF-8 codepage to make the type command print the expected + " multibyte characters. + let buf = term_start("cmd /K chcp 65001") + call term_sendkeys(buf, "type Xtext\<CR>") + call term_sendkeys(buf, "exit\<CR>") + let line = 4 + else + let buf = term_start("cat Xtext") + let line = 1 + endif + + call WaitFor({-> len(term_scrape(buf, line)) >= 7 && term_scrape(buf, line)[0].chars == "l"}) + let l = term_scrape(buf, line) + call assert_true(len(l) >= 7) + call assert_equal('l', l[0].chars) + call assert_equal('é', l[1].chars) + call assert_equal(1, l[1].width) + call assert_equal('t', l[2].chars) + call assert_equal('t', l[3].chars) + call assert_equal('ま', l[4].chars) + call assert_equal(2, l[4].width) + call assert_equal('r', l[5].chars) + call assert_equal('s', l[6].chars) + + let job = term_getjob(buf) + call WaitForAssert({-> assert_equal("dead", job_status(job))}) + call term_wait(buf) + + exe buf . 'bwipe' + call delete('Xtext') +endfunc + +func Test_terminal_scroll() + call writefile(range(1, 200), 'Xtext') + if has('win32') + let cmd = 'cmd /c "type Xtext"' + else + let cmd = "cat Xtext" + endif + let buf = term_start(cmd) + + let job = term_getjob(buf) + call WaitForAssert({-> assert_equal("dead", job_status(job))}) + call term_wait(buf) + if has('win32') + " TODO: this should not be needed + sleep 100m + endif + + let scrolled = term_getscrolled(buf) + call assert_equal('1', getline(1)) + call assert_equal('1', term_getline(buf, 1 - scrolled)) + call assert_equal('49', getline(49)) + call assert_equal('49', term_getline(buf, 49 - scrolled)) + call assert_equal('200', getline(200)) + call assert_equal('200', term_getline(buf, 200 - scrolled)) + + exe buf . 'bwipe' + call delete('Xtext') +endfunc + +func Test_terminal_scrollback() + let buf = Run_shell_in_terminal({'term_rows': 15}) + set termwinscroll=100 + call writefile(range(150), 'Xtext') + if has('win32') + call term_sendkeys(buf, "type Xtext\<CR>") + else + call term_sendkeys(buf, "cat Xtext\<CR>") + endif + let rows = term_getsize(buf)[0] + " On MS-Windows there is an empty line, check both last line and above it. + call WaitForAssert({-> assert_match( '149', term_getline(buf, rows - 1) . term_getline(buf, rows - 2))}) + let lines = line('$') + call assert_inrange(91, 100, lines) + + call Stop_shell_in_terminal(buf) + call term_wait(buf) + exe buf . 'bwipe' + set termwinscroll& +endfunc + +func Test_terminal_size() + let cmd = Get_cat_123_cmd() + + exe 'terminal ++rows=5 ' . cmd + let size = term_getsize('') + bwipe! + call assert_equal(5, size[0]) + + call term_start(cmd, {'term_rows': 6}) + let size = term_getsize('') + bwipe! + call assert_equal(6, size[0]) + + vsplit + exe 'terminal ++rows=5 ++cols=33 ' . cmd + call assert_equal([5, 33], term_getsize('')) + + call term_setsize('', 6, 0) + call assert_equal([6, 33], term_getsize('')) + + call term_setsize('', 0, 35) + call assert_equal([6, 35], term_getsize('')) + + call term_setsize('', 7, 30) + call assert_equal([7, 30], term_getsize('')) + + bwipe! + call assert_fails("call term_setsize('', 7, 30)", "E955:") + + call term_start(cmd, {'term_rows': 6, 'term_cols': 36}) + let size = term_getsize('') + bwipe! + call assert_equal([6, 36], size) + + exe 'vertical terminal ++cols=20 ' . cmd + let size = term_getsize('') + bwipe! + call assert_equal(20, size[1]) + + call term_start(cmd, {'vertical': 1, 'term_cols': 26}) + let size = term_getsize('') + bwipe! + call assert_equal(26, size[1]) + + split + exe 'vertical terminal ++rows=6 ++cols=20 ' . cmd + let size = term_getsize('') + bwipe! + call assert_equal([6, 20], size) + + call term_start(cmd, {'vertical': 1, 'term_rows': 7, 'term_cols': 27}) + let size = term_getsize('') + bwipe! + call assert_equal([7, 27], size) + + call delete('Xtext') +endfunc + +func Test_terminal_curwin() + let cmd = Get_cat_123_cmd() + call assert_equal(1, winnr('$')) + + split dummy + exe 'terminal ++curwin ' . cmd + call assert_equal(2, winnr('$')) + bwipe! + + split dummy + call term_start(cmd, {'curwin': 1}) + call assert_equal(2, winnr('$')) + bwipe! + + split dummy + call setline(1, 'change') + call assert_fails('terminal ++curwin ' . cmd, 'E37:') + call assert_equal(2, winnr('$')) + exe 'terminal! ++curwin ' . cmd + call assert_equal(2, winnr('$')) + bwipe! + + split dummy + call setline(1, 'change') + call assert_fails("call term_start(cmd, {'curwin': 1})", 'E37:') + call assert_equal(2, winnr('$')) + bwipe! + + split dummy + bwipe! + call delete('Xtext') +endfunc + +func s:get_sleep_cmd() + if s:python != '' + let cmd = s:python . " test_short_sleep.py" + " 500 was not enough for Travis + let waittime = 900 + else + echo 'This will take five seconds...' + let waittime = 2000 + if has('win32') + let cmd = $windir . '\system32\timeout.exe 1' + else + let cmd = 'sleep 1' + endif + endif + return [cmd, waittime] +endfunc + +func Test_terminal_finish_open_close() + call assert_equal(1, winnr('$')) + + let [cmd, waittime] = s:get_sleep_cmd() + + " shell terminal closes automatically + terminal + let buf = bufnr('%') + call assert_equal(2, winnr('$')) + " Wait for the shell to display a prompt + call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) + call Stop_shell_in_terminal(buf) + call WaitForAssert({-> assert_equal(1, winnr('$'))}, waittime) + + " shell terminal that does not close automatically + terminal ++noclose + let buf = bufnr('%') + call assert_equal(2, winnr('$')) + " Wait for the shell to display a prompt + call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) + call Stop_shell_in_terminal(buf) + call assert_equal(2, winnr('$')) + quit + call assert_equal(1, winnr('$')) + + exe 'terminal ++close ' . cmd + call assert_equal(2, winnr('$')) + wincmd p + call WaitForAssert({-> assert_equal(1, winnr('$'))}, waittime) + + call term_start(cmd, {'term_finish': 'close'}) + call assert_equal(2, winnr('$')) + wincmd p + call WaitForAssert({-> assert_equal(1, winnr('$'))}, waittime) + call assert_equal(1, winnr('$')) + + exe 'terminal ++open ' . cmd + close! + call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) + bwipe + + call term_start(cmd, {'term_finish': 'open'}) + close! + call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) + bwipe + + exe 'terminal ++hidden ++open ' . cmd + call assert_equal(1, winnr('$')) + call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) + bwipe + + call term_start(cmd, {'term_finish': 'open', 'hidden': 1}) + call assert_equal(1, winnr('$')) + call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) + bwipe + + call assert_fails("call term_start(cmd, {'term_opencmd': 'open'})", 'E475:') + call assert_fails("call term_start(cmd, {'term_opencmd': 'split %x'})", 'E475:') + call assert_fails("call term_start(cmd, {'term_opencmd': 'split %d and %s'})", 'E475:') + call assert_fails("call term_start(cmd, {'term_opencmd': 'split % and %d'})", 'E475:') + + call term_start(cmd, {'term_finish': 'open', 'term_opencmd': '4split | buffer %d'}) + close! + call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) + call assert_equal(4, winheight(0)) + bwipe +endfunc + +func Test_terminal_cwd() + if !executable('pwd') + return + endif + call mkdir('Xdir') + let buf = term_start('pwd', {'cwd': 'Xdir'}) + call WaitForAssert({-> assert_equal('Xdir', fnamemodify(getline(1), ":t"))}) + + exe buf . 'bwipe' + call delete('Xdir', 'rf') +endfunc + +func Test_terminal_cwd_failure() + " Case 1: Provided directory is not actually a directory. Attempt to make + " the file executable as well. + call writefile([], 'Xfile') + call setfperm('Xfile', 'rwx------') + call assert_fails("call term_start(&shell, {'cwd': 'Xfile'})", 'E475:') + call delete('Xfile') + + " Case 2: Directory does not exist. + call assert_fails("call term_start(&shell, {'cwd': 'Xdir'})", 'E475:') + + " Case 3: Directory exists but is not accessible. + " Skip this for root, it will be accessible anyway. + if $USER != 'root' + call mkdir('XdirNoAccess', '', '0600') + " return early if the directory permissions could not be set properly + if getfperm('XdirNoAccess')[2] == 'x' + call delete('XdirNoAccess', 'rf') + return + endif + call assert_fails("call term_start(&shell, {'cwd': 'XdirNoAccess'})", 'E475:') + call delete('XdirNoAccess', 'rf') + endif +endfunc + +func Test_terminal_servername() + if !has('clientserver') + return + endif + call s:test_environment("VIM_SERVERNAME", v:servername) +endfunc + +func Test_terminal_version() + call s:test_environment("VIM_TERMINAL", string(v:version)) +endfunc + +func s:test_environment(name, value) + let buf = Run_shell_in_terminal({}) + " Wait for the shell to display a prompt + call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) + if has('win32') + call term_sendkeys(buf, "echo %" . a:name . "%\r") + else + call term_sendkeys(buf, "echo $" . a:name . "\r") + endif + call term_wait(buf) + call Stop_shell_in_terminal(buf) + call WaitForAssert({-> assert_equal(a:value, getline(2))}) + + exe buf . 'bwipe' + unlet buf +endfunc + +func Test_terminal_env() + let buf = Run_shell_in_terminal({'env': {'TESTENV': 'correct'}}) + " Wait for the shell to display a prompt + call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) + if has('win32') + call term_sendkeys(buf, "echo %TESTENV%\r") + else + call term_sendkeys(buf, "echo $TESTENV\r") + endif + call term_wait(buf) + call Stop_shell_in_terminal(buf) + call WaitForAssert({-> assert_equal('correct', getline(2))}) + + exe buf . 'bwipe' +endfunc + +func Test_terminal_list_args() + let buf = term_start([&shell, &shellcmdflag, 'echo "123"']) + call assert_fails(buf . 'bwipe', 'E517') + exe buf . 'bwipe!' + call assert_equal("", bufname(buf)) +endfunction + +func Test_terminal_noblock() + let buf = term_start(&shell) + if has('bsd') || has('mac') || has('sun') + " The shell or something else has a problem dealing with more than 1000 + " characters at the same time. + let len = 1000 + " NPFS is used in Windows, nonblocking mode does not work properly. + elseif has('win32') + let len = 1 + else + let len = 5000 + endif + + for c in ['a','b','c','d','e','f','g','h','i','j','k'] + call term_sendkeys(buf, 'echo ' . repeat(c, len) . "\<cr>") + endfor + call term_sendkeys(buf, "echo done\<cr>") + + " On MS-Windows there is an extra empty line below "done". Find "done" in + " the last-but-one or the last-but-two line. + let lnum = term_getsize(buf)[0] - 1 + call WaitFor({-> term_getline(buf, lnum) =~ "done" || term_getline(buf, lnum - 1) =~ "done"}, 10000) + let line = term_getline(buf, lnum) + if line !~ 'done' + let line = term_getline(buf, lnum - 1) + endif + call assert_match('done', line) + + let g:job = term_getjob(buf) + call Stop_shell_in_terminal(buf) + call term_wait(buf) + unlet g:job + bwipe +endfunc + +func Test_terminal_write_stdin() + if !executable('wc') + throw 'skipped: wc command not available' + endif + if has('win32') + " TODO: enable once writing to stdin works on MS-Windows + return + endif + new + call setline(1, ['one', 'two', 'three']) + %term wc + call WaitForAssert({-> assert_match('3', getline("$"))}) + let nrs = split(getline('$')) + call assert_equal(['3', '3', '14'], nrs) + bwipe + + new + call setline(1, ['one', 'two', 'three', 'four']) + 2,3term wc + call WaitForAssert({-> assert_match('2', getline("$"))}) + let nrs = split(getline('$')) + call assert_equal(['2', '2', '10'], nrs) + bwipe + + if executable('python') + new + call setline(1, ['print("hello")']) + 1term ++eof=exit() python + " MS-Windows echoes the input, Unix doesn't. + call WaitFor('getline("$") =~ "exit" || getline(1) =~ "hello"') + if getline(1) =~ 'hello' + call assert_equal('hello', getline(1)) + else + call assert_equal('hello', getline(line('$') - 1)) + endif + bwipe + + if has('win32') + new + call setline(1, ['print("hello")']) + 1term ++eof=<C-Z> python + call WaitForAssert({-> assert_match('Z', getline("$"))}) + call assert_equal('hello', getline(line('$') - 1)) + bwipe + endif + endif + + bwipe! +endfunc + +func Test_terminal_no_cmd() + let buf = term_start('NONE', {}) + call assert_notequal(0, buf) + + let pty = job_info(term_getjob(buf))['tty_out'] + call assert_notequal('', pty) + if has('gui_running') && !has('win32') + " In the GUI job_start() doesn't work, it does not read from the pty. + call system('echo "look here" > ' . pty) + else + " Otherwise using a job works on all systems. + call job_start([&shell, &shellcmdflag, 'echo "look here" > ' . pty]) + endif + call WaitForAssert({-> assert_match('look here', term_getline(buf, 1))}) + + bwipe! +endfunc + +func Test_terminal_special_chars() + " this file name only works on Unix + if !has('unix') + return + endif + call mkdir('Xdir with spaces') + call writefile(['x'], 'Xdir with spaces/quoted"file') + term ls Xdir\ with\ spaces/quoted\"file + call WaitForAssert({-> assert_match('quoted"file', term_getline('', 1))}) + call term_wait('') + + call delete('Xdir with spaces', 'rf') + bwipe +endfunc + +func Test_terminal_wrong_options() + call assert_fails('call term_start(&shell, { + \ "in_io": "file", + \ "in_name": "xxx", + \ "out_io": "file", + \ "out_name": "xxx", + \ "err_io": "file", + \ "err_name": "xxx" + \ })', 'E474:') + call assert_fails('call term_start(&shell, { + \ "out_buf": bufnr("%") + \ })', 'E474:') + call assert_fails('call term_start(&shell, { + \ "err_buf": bufnr("%") + \ })', 'E474:') +endfunc + +func Test_terminal_redir_file() + let cmd = Get_cat_123_cmd() + let buf = term_start(cmd, {'out_io': 'file', 'out_name': 'Xfile'}) + call term_wait(buf) + " ConPTY may precede escape sequence. There are things that are not so. + if !has('conpty') + call WaitForAssert({-> assert_notequal(0, len(readfile("Xfile")))}) + call assert_match('123', readfile('Xfile')[0]) + endif + let g:job = term_getjob(buf) + call WaitForAssert({-> assert_equal("dead", job_status(g:job))}) + call delete('Xfile') + bwipe + + if has('unix') + call writefile(['one line'], 'Xfile') + let buf = term_start('cat', {'in_io': 'file', 'in_name': 'Xfile'}) + call term_wait(buf) + call WaitForAssert({-> assert_equal('one line', term_getline(buf, 1))}) + let g:job = term_getjob(buf) + call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) + bwipe + call delete('Xfile') + endif +endfunc + +func TerminalTmap(remap) + let buf = Run_shell_in_terminal({}) + call assert_equal('t', mode()) + + if a:remap + tmap 123 456 + else + tnoremap 123 456 + endif + " don't use abcde, it's an existing command + tmap 456 abxde + call assert_equal('456', maparg('123', 't')) + call assert_equal('abxde', maparg('456', 't')) + call feedkeys("123", 'tx') + call WaitForAssert({-> assert_match('abxde\|456', term_getline(buf, term_getcursor(buf)[0]))}) + let lnum = term_getcursor(buf)[0] + if a:remap + call assert_match('abxde', term_getline(buf, lnum)) + else + call assert_match('456', term_getline(buf, lnum)) + endif + + call term_sendkeys(buf, "\r") + call Stop_shell_in_terminal(buf) + call term_wait(buf) + + tunmap 123 + tunmap 456 + call assert_equal('', maparg('123', 't')) + close + unlet g:job +endfunc + +func Test_terminal_tmap() + call TerminalTmap(1) + call TerminalTmap(0) +endfunc + +func Test_terminal_wall() + let buf = Run_shell_in_terminal({}) + wall + call Stop_shell_in_terminal(buf) + call term_wait(buf) + exe buf . 'bwipe' + unlet g:job +endfunc + +func Test_terminal_wqall() + let buf = Run_shell_in_terminal({}) + call assert_fails('wqall', 'E948') + call Stop_shell_in_terminal(buf) + call term_wait(buf) + exe buf . 'bwipe' + unlet g:job +endfunc + +func Test_terminal_composing_unicode() + let save_enc = &encoding + set encoding=utf-8 + + if has('win32') + let cmd = "cmd /K chcp 65001" + let lnum = [3, 6, 9] + else + let cmd = &shell + let lnum = [1, 3, 5] + endif + + enew + let buf = term_start(cmd, {'curwin': bufnr('')}) + let g:job = term_getjob(buf) + call term_wait(buf, 50) + + if has('win32') + call assert_equal('cmd', job_info(g:job).cmd[0]) + else + call assert_equal(&shell, job_info(g:job).cmd[0]) + endif + + " ascii + composing + let txt = "a\u0308bc" + call term_sendkeys(buf, "echo " . txt . "\r") + call term_wait(buf, 50) + call assert_match("echo " . txt, term_getline(buf, lnum[0])) + call assert_equal(txt, term_getline(buf, lnum[0] + 1)) + let l = term_scrape(buf, lnum[0] + 1) + call assert_equal("a\u0308", l[0].chars) + call assert_equal("b", l[1].chars) + call assert_equal("c", l[2].chars) + + " multibyte + composing + let txt = "\u304b\u3099\u304e\u304f\u3099\u3052\u3053\u3099" + call term_sendkeys(buf, "echo " . txt . "\r") + call term_wait(buf, 50) + call assert_match("echo " . txt, term_getline(buf, lnum[1])) + call assert_equal(txt, term_getline(buf, lnum[1] + 1)) + let l = term_scrape(buf, lnum[1] + 1) + call assert_equal("\u304b\u3099", l[0].chars) + call assert_equal("\u304e", l[1].chars) + call assert_equal("\u304f\u3099", l[2].chars) + call assert_equal("\u3052", l[3].chars) + call assert_equal("\u3053\u3099", l[4].chars) + + " \u00a0 + composing + let txt = "abc\u00a0\u0308" + call term_sendkeys(buf, "echo " . txt . "\r") + call term_wait(buf, 50) + call assert_match("echo " . txt, term_getline(buf, lnum[2])) + call assert_equal(txt, term_getline(buf, lnum[2] + 1)) + let l = term_scrape(buf, lnum[2] + 1) + call assert_equal("\u00a0\u0308", l[3].chars) + + call term_sendkeys(buf, "exit\r") + call WaitForAssert({-> assert_equal('dead', job_status(g:job))}) + bwipe! + unlet g:job + let &encoding = save_enc +endfunc + +func Test_terminal_aucmd_on_close() + fun Nop() + let s:called = 1 + endfun + + aug repro + au! + au BufWinLeave * call Nop() + aug END + + let [cmd, waittime] = s:get_sleep_cmd() + + call assert_equal(1, winnr('$')) + new + call setline(1, ['one', 'two']) + exe 'term ++close ' . cmd + wincmd p + call WaitForAssert({-> assert_equal(2, winnr('$'))}, waittime) + call assert_equal(1, s:called) + bwipe! + + unlet s:called + au! repro + delfunc Nop +endfunc + +func Test_terminal_term_start_empty_command() + let cmd = "call term_start('', {'curwin' : 1, 'term_finish' : 'close'})" + call assert_fails(cmd, 'E474') + let cmd = "call term_start('', {'curwin' : 1, 'term_finish' : 'close'})" + call assert_fails(cmd, 'E474') + let cmd = "call term_start({}, {'curwin' : 1, 'term_finish' : 'close'})" + call assert_fails(cmd, 'E474') + let cmd = "call term_start(0, {'curwin' : 1, 'term_finish' : 'close'})" + call assert_fails(cmd, 'E474') +endfunc + +func Test_terminal_response_to_control_sequence() + if !has('unix') + return + endif + + let buf = Run_shell_in_terminal({}) + call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))}) + + call term_sendkeys(buf, "cat\<CR>") + call WaitForAssert({-> assert_match('cat', term_getline(buf, 1))}) + + " Request the cursor position. + call term_sendkeys(buf, "\x1b[6n\<CR>") + + " Wait for output from tty to display, below an empty line. + call WaitForAssert({-> assert_match('3;1R', term_getline(buf, 4))}) + + " End "cat" gently. + call term_sendkeys(buf, "\<CR>\<C-D>") + + call Stop_shell_in_terminal(buf) + exe buf . 'bwipe' + unlet g:job +endfunc + +" Run Vim, start a terminal in that Vim with the kill argument, +" :qall works. +func Run_terminal_qall_kill(line1, line2) + " 1. Open a terminal window and wait for the prompt to appear + " 2. set kill using term_setkill() + " 3. make Vim exit, it will kill the shell + let after = [ + \ a:line1, + \ 'let buf = bufnr("%")', + \ 'while term_getline(buf, 1) =~ "^\\s*$"', + \ ' sleep 10m', + \ 'endwhile', + \ a:line2, + \ 'au VimLeavePre * call writefile(["done"], "Xdone")', + \ 'qall', + \ ] + if !RunVim([], after, '') + return + endif + call assert_equal("done", readfile("Xdone")[0]) + call delete("Xdone") +endfunc + +" Run Vim in a terminal, then start a terminal in that Vim with a kill +" argument, check that :qall works. +func Test_terminal_qall_kill_arg() + call Run_terminal_qall_kill('term ++kill=kill', '') +endfunc + +" Run Vim, start a terminal in that Vim, set the kill argument with +" term_setkill(), check that :qall works. +func Test_terminal_qall_kill_func() + call Run_terminal_qall_kill('term', 'call term_setkill(buf, "kill")') +endfunc + +" Run Vim, start a terminal in that Vim without the kill argument, +" check that :qall does not exit, :qall! does. +func Test_terminal_qall_exit() + let after = [ + \ 'term', + \ 'let buf = bufnr("%")', + \ 'while term_getline(buf, 1) =~ "^\\s*$"', + \ ' sleep 10m', + \ 'endwhile', + \ 'set nomore', + \ 'au VimLeavePre * call writefile(["too early"], "Xdone")', + \ 'qall', + \ 'au! VimLeavePre * exe buf . "bwipe!" | call writefile(["done"], "Xdone")', + \ 'cquit', + \ ] + if !RunVim([], after, '') + return + endif + call assert_equal("done", readfile("Xdone")[0]) + call delete("Xdone") +endfunc + +" Run Vim in a terminal, then start a terminal in that Vim without a kill +" argument, check that :confirm qall works. +func Test_terminal_qall_prompt() + if !CanRunVimInTerminal() + return + endif + let buf = RunVimInTerminal('', {}) + + " Open a terminal window and wait for the prompt to appear + call term_sendkeys(buf, ":term\<CR>") + call WaitForAssert({-> assert_match('\[running]', term_getline(buf, 10))}) + call WaitForAssert({-> assert_notmatch('^\s*$', term_getline(buf, 1))}) + + " make Vim exit, it will prompt to kill the shell + call term_sendkeys(buf, "\<C-W>:confirm qall\<CR>") + call WaitForAssert({-> assert_match('ancel:', term_getline(buf, 20))}) + call term_sendkeys(buf, "y") + call WaitForAssert({-> assert_equal('finished', term_getstatus(buf))}) + + " close the terminal window where Vim was running + quit +endfunc + +func Test_terminal_open_autocmd() + augroup repro + au! + au TerminalOpen * let s:called += 1 + augroup END + + let s:called = 0 + + " Open a terminal window with :terminal + terminal + call assert_equal(1, s:called) + bwipe! + + " Open a terminal window with term_start() + call term_start(&shell) + call assert_equal(2, s:called) + bwipe! + + " Open a hidden terminal buffer with :terminal + terminal ++hidden + call assert_equal(3, s:called) + for buf in term_list() + exe buf . "bwipe!" + endfor + + " Open a hidden terminal buffer with term_start() + let buf = term_start(&shell, {'hidden': 1}) + call assert_equal(4, s:called) + exe buf . "bwipe!" + + unlet s:called + au! repro +endfunction + +func Check_dump01(off) + call assert_equal('one two three four five', trim(getline(a:off + 1))) + call assert_equal('~ Select Word', trim(getline(a:off + 7))) + call assert_equal(':popup PopUp', trim(getline(a:off + 20))) +endfunc + +func Test_terminal_dumpwrite_composing() + if !CanRunVimInTerminal() + return + endif + let save_enc = &encoding + set encoding=utf-8 + call assert_equal(1, winnr('$')) + + let text = " a\u0300 e\u0302 o\u0308" + call writefile([text], 'Xcomposing') + let buf = RunVimInTerminal('--cmd "set encoding=utf-8" Xcomposing', {}) + call WaitForAssert({-> assert_match(text, term_getline(buf, 1))}) + call term_dumpwrite(buf, 'Xdump') + let dumpline = readfile('Xdump')[0] + call assert_match('|à| |ê| |ö', dumpline) + + call StopVimInTerminal(buf) + call delete('Xcomposing') + call delete('Xdump') + let &encoding = save_enc +endfunc + +" just testing basic functionality. +func Test_terminal_dumpload() + call assert_equal(1, winnr('$')) + call term_dumpload('dumps/Test_popup_command_01.dump') + call assert_equal(2, winnr('$')) + call assert_equal(20, line('$')) + call Check_dump01(0) + quit +endfunc + +func Test_terminal_dumpdiff() + call assert_equal(1, winnr('$')) + call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_02.dump') + call assert_equal(2, winnr('$')) + call assert_equal(62, line('$')) + call Check_dump01(0) + call Check_dump01(42) + call assert_equal(' bbbbbbbbbbbbbbbbbb ', getline(26)[0:29]) + quit +endfunc + +func Test_terminal_dumpdiff_options() + set laststatus=0 + call assert_equal(1, winnr('$')) + let height = winheight(0) + call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_02.dump', {'vertical': 1, 'term_cols': 33}) + call assert_equal(2, winnr('$')) + call assert_equal(height, winheight(winnr())) + call assert_equal(33, winwidth(winnr())) + call assert_equal('dump diff dumps/Test_popup_command_01.dump', bufname('%')) + quit + + call assert_equal(1, winnr('$')) + let width = winwidth(0) + call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_02.dump', {'vertical': 0, 'term_rows': 13, 'term_name': 'something else'}) + call assert_equal(2, winnr('$')) + call assert_equal(width, winwidth(winnr())) + call assert_equal(13, winheight(winnr())) + call assert_equal('something else', bufname('%')) + quit + + call assert_equal(1, winnr('$')) + call term_dumpdiff('dumps/Test_popup_command_01.dump', 'dumps/Test_popup_command_02.dump', {'curwin': 1}) + call assert_equal(1, winnr('$')) + bwipe + + set laststatus& +endfunc + +func Api_drop_common(options) + call assert_equal(1, winnr('$')) + + " Use the title termcap entries to output the escape sequence. + call writefile([ + \ 'set title', + \ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"', + \ 'let &titlestring = ''["drop","Xtextfile"' . a:options . ']''', + \ 'redraw', + \ "set t_ts=", + \ ], 'Xscript') + let buf = RunVimInTerminal('-S Xscript', {}) + call WaitFor({-> bufnr('Xtextfile') > 0}) + call assert_equal('Xtextfile', expand('%:t')) + call assert_true(winnr('$') >= 3) + return buf +endfunc + +func Test_terminal_api_drop_newwin() + if !CanRunVimInTerminal() + return + endif + let buf = Api_drop_common('') + call assert_equal(0, &bin) + call assert_equal('', &fenc) + + call StopVimInTerminal(buf) + call delete('Xscript') + bwipe Xtextfile +endfunc + +func Test_terminal_api_drop_newwin_bin() + if !CanRunVimInTerminal() + return + endif + let buf = Api_drop_common(',{"bin":1}') + call assert_equal(1, &bin) + + call StopVimInTerminal(buf) + call delete('Xscript') + bwipe Xtextfile +endfunc + +func Test_terminal_api_drop_newwin_binary() + if !CanRunVimInTerminal() + return + endif + let buf = Api_drop_common(',{"binary":1}') + call assert_equal(1, &bin) + + call StopVimInTerminal(buf) + call delete('Xscript') + bwipe Xtextfile +endfunc + +func Test_terminal_api_drop_newwin_nobin() + if !CanRunVimInTerminal() + return + endif + set binary + let buf = Api_drop_common(',{"nobin":1}') + call assert_equal(0, &bin) + + call StopVimInTerminal(buf) + call delete('Xscript') + bwipe Xtextfile + set nobinary +endfunc + +func Test_terminal_api_drop_newwin_nobinary() + if !CanRunVimInTerminal() + return + endif + set binary + let buf = Api_drop_common(',{"nobinary":1}') + call assert_equal(0, &bin) + + call StopVimInTerminal(buf) + call delete('Xscript') + bwipe Xtextfile + set nobinary +endfunc + +func Test_terminal_api_drop_newwin_ff() + if !CanRunVimInTerminal() + return + endif + let buf = Api_drop_common(',{"ff":"dos"}') + call assert_equal("dos", &ff) + + call StopVimInTerminal(buf) + call delete('Xscript') + bwipe Xtextfile +endfunc + +func Test_terminal_api_drop_newwin_fileformat() + if !CanRunVimInTerminal() + return + endif + let buf = Api_drop_common(',{"fileformat":"dos"}') + call assert_equal("dos", &ff) + + call StopVimInTerminal(buf) + call delete('Xscript') + bwipe Xtextfile +endfunc + +func Test_terminal_api_drop_newwin_enc() + if !CanRunVimInTerminal() + return + endif + let buf = Api_drop_common(',{"enc":"utf-16"}') + call assert_equal("utf-16", &fenc) + + call StopVimInTerminal(buf) + call delete('Xscript') + bwipe Xtextfile +endfunc + +func Test_terminal_api_drop_newwin_encoding() + if !CanRunVimInTerminal() + return + endif + let buf = Api_drop_common(',{"encoding":"utf-16"}') + call assert_equal("utf-16", &fenc) + + call StopVimInTerminal(buf) + call delete('Xscript') + bwipe Xtextfile +endfunc + +func Test_terminal_api_drop_oldwin() + if !CanRunVimInTerminal() + return + endif + let firstwinid = win_getid() + split Xtextfile + let textfile_winid = win_getid() + call assert_equal(2, winnr('$')) + call win_gotoid(firstwinid) + + " Use the title termcap entries to output the escape sequence. + call writefile([ + \ 'set title', + \ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"', + \ 'let &titlestring = ''["drop","Xtextfile"]''', + \ 'redraw', + \ "set t_ts=", + \ ], 'Xscript') + let buf = RunVimInTerminal('-S Xscript', {'rows': 10}) + call WaitForAssert({-> assert_equal('Xtextfile', expand('%:t'))}) + call assert_equal(textfile_winid, win_getid()) + + call StopVimInTerminal(buf) + call delete('Xscript') + bwipe Xtextfile +endfunc + +func Tapi_TryThis(bufnum, arg) + let g:called_bufnum = a:bufnum + let g:called_arg = a:arg +endfunc + +func WriteApiCall(funcname) + " Use the title termcap entries to output the escape sequence. + call writefile([ + \ 'set title', + \ 'exe "set t_ts=\<Esc>]51; t_fs=\x07"', + \ 'let &titlestring = ''["call","' . a:funcname . '",["hello",123]]''', + \ 'redraw', + \ "set t_ts=", + \ ], 'Xscript') +endfunc + +func Test_terminal_api_call() + if !CanRunVimInTerminal() + return + endif + + call WriteApiCall('Tapi_TryThis') + let buf = RunVimInTerminal('-S Xscript', {}) + call WaitFor({-> exists('g:called_bufnum')}) + call assert_equal(buf, g:called_bufnum) + call assert_equal(['hello', 123], g:called_arg) + + call StopVimInTerminal(buf) + call delete('Xscript') + unlet g:called_bufnum + unlet g:called_arg +endfunc + +func Test_terminal_api_call_fails() + if !CanRunVimInTerminal() + return + endif + + call WriteApiCall('TryThis') + call ch_logfile('Xlog', 'w') + let buf = RunVimInTerminal('-S Xscript', {}) + call WaitForAssert({-> assert_match('Invalid function name: TryThis', string(readfile('Xlog')))}) + + call StopVimInTerminal(buf) + call delete('Xscript') + call ch_logfile('', '') + call delete('Xlog') +endfunc + +let s:caught_e937 = 0 + +func Tapi_Delete(bufnum, arg) + try + execute 'bdelete!' a:bufnum + catch /E937:/ + let s:caught_e937 = 1 + endtry +endfunc + +func Test_terminal_api_call_fail_delete() + if !CanRunVimInTerminal() + return + endif + + call WriteApiCall('Tapi_Delete') + let buf = RunVimInTerminal('-S Xscript', {}) + call WaitForAssert({-> assert_equal(1, s:caught_e937)}) + + call StopVimInTerminal(buf) + call delete('Xscript') + call ch_logfile('', '') +endfunc + +func Test_terminal_ansicolors_default() + let colors = [ + \ '#000000', '#e00000', + \ '#00e000', '#e0e000', + \ '#0000e0', '#e000e0', + \ '#00e0e0', '#e0e0e0', + \ '#808080', '#ff4040', + \ '#40ff40', '#ffff40', + \ '#4040ff', '#ff40ff', + \ '#40ffff', '#ffffff', + \] + + let buf = Run_shell_in_terminal({}) + call assert_equal(colors, term_getansicolors(buf)) + call Stop_shell_in_terminal(buf) + call term_wait(buf) + + exe buf . 'bwipe' +endfunc + +let s:test_colors = [ + \ '#616e64', '#0d0a79', + \ '#6d610d', '#0a7373', + \ '#690d0a', '#6d696e', + \ '#0d0a6f', '#616e0d', + \ '#0a6479', '#6d0d0a', + \ '#617373', '#0d0a69', + \ '#6d690d', '#0a6e6f', + \ '#610d0a', '#6e6479', + \] + +func Test_terminal_ansicolors_global() + let g:terminal_ansi_colors = reverse(copy(s:test_colors)) + let buf = Run_shell_in_terminal({}) + call assert_equal(g:terminal_ansi_colors, term_getansicolors(buf)) + call Stop_shell_in_terminal(buf) + call term_wait(buf) + + exe buf . 'bwipe' + unlet g:terminal_ansi_colors +endfunc + +func Test_terminal_ansicolors_func() + let g:terminal_ansi_colors = reverse(copy(s:test_colors)) + let buf = Run_shell_in_terminal({'ansi_colors': s:test_colors}) + call assert_equal(s:test_colors, term_getansicolors(buf)) + + call term_setansicolors(buf, g:terminal_ansi_colors) + call assert_equal(g:terminal_ansi_colors, term_getansicolors(buf)) + + let colors = [ + \ 'ivory', 'AliceBlue', + \ 'grey67', 'dark goldenrod', + \ 'SteelBlue3', 'PaleVioletRed4', + \ 'MediumPurple2', 'yellow2', + \ 'RosyBrown3', 'OrangeRed2', + \ 'white smoke', 'navy blue', + \ 'grey47', 'gray97', + \ 'MistyRose2', 'DodgerBlue4', + \] + call term_setansicolors(buf, colors) + + let colors[4] = 'Invalid' + call assert_fails('call term_setansicolors(buf, colors)', 'E474:') + + call Stop_shell_in_terminal(buf) + call term_wait(buf) + exe buf . 'bwipe' +endfunc + +func Test_terminal_termwinsize_option_fixed() + if !CanRunVimInTerminal() + return + endif + set termwinsize=6x40 + let text = [] + for n in range(10) + call add(text, repeat(n, 50)) + endfor + call writefile(text, 'Xwinsize') + let buf = RunVimInTerminal('Xwinsize', {}) + let win = bufwinid(buf) + call assert_equal([6, 40], term_getsize(buf)) + call assert_equal(6, winheight(win)) + call assert_equal(40, winwidth(win)) + + " resizing the window doesn't resize the terminal. + resize 10 + vertical resize 60 + call assert_equal([6, 40], term_getsize(buf)) + call assert_equal(10, winheight(win)) + call assert_equal(60, winwidth(win)) + + call StopVimInTerminal(buf) + call delete('Xwinsize') + + call assert_fails('set termwinsize=40', 'E474') + call assert_fails('set termwinsize=10+40', 'E474') + call assert_fails('set termwinsize=abc', 'E474') + + set termwinsize= +endfunc + +func Test_terminal_termwinsize_option_zero() + set termwinsize=0x0 + let buf = Run_shell_in_terminal({}) + let win = bufwinid(buf) + call assert_equal([winheight(win), winwidth(win)], term_getsize(buf)) + call Stop_shell_in_terminal(buf) + call term_wait(buf) + exe buf . 'bwipe' + + set termwinsize=7x0 + let buf = Run_shell_in_terminal({}) + let win = bufwinid(buf) + call assert_equal([7, winwidth(win)], term_getsize(buf)) + call Stop_shell_in_terminal(buf) + call term_wait(buf) + exe buf . 'bwipe' + + set termwinsize=0x33 + let buf = Run_shell_in_terminal({}) + let win = bufwinid(buf) + call assert_equal([winheight(win), 33], term_getsize(buf)) + call Stop_shell_in_terminal(buf) + call term_wait(buf) + exe buf . 'bwipe' + + set termwinsize= +endfunc + +func Test_terminal_termwinsize_mininmum() + set termwinsize=10*50 + vsplit + let buf = Run_shell_in_terminal({}) + let win = bufwinid(buf) + call assert_inrange(10, 1000, winheight(win)) + call assert_inrange(50, 1000, winwidth(win)) + call assert_equal([winheight(win), winwidth(win)], term_getsize(buf)) + + resize 15 + vertical resize 60 + redraw + call assert_equal([15, 60], term_getsize(buf)) + call assert_equal(15, winheight(win)) + call assert_equal(60, winwidth(win)) + + resize 7 + vertical resize 30 + redraw + call assert_equal([10, 50], term_getsize(buf)) + call assert_equal(7, winheight(win)) + call assert_equal(30, winwidth(win)) + + call Stop_shell_in_terminal(buf) + call term_wait(buf) + exe buf . 'bwipe' + + set termwinsize=0*0 + let buf = Run_shell_in_terminal({}) + let win = bufwinid(buf) + call assert_equal([winheight(win), winwidth(win)], term_getsize(buf)) + call Stop_shell_in_terminal(buf) + call term_wait(buf) + exe buf . 'bwipe' + + set termwinsize= +endfunc + +func Test_terminal_termwinkey() + call assert_equal(1, winnr('$')) + let thiswin = win_getid() + + let buf = Run_shell_in_terminal({}) + let termwin = bufwinid(buf) + set termwinkey=<C-L> + call feedkeys("\<C-L>w", 'tx') + call assert_equal(thiswin, win_getid()) + call feedkeys("\<C-W>w", 'tx') + + let job = term_getjob(buf) + call feedkeys("\<C-L>\<C-C>", 'tx') + call WaitForAssert({-> assert_equal("dead", job_status(job))}) +endfunc + +func Test_terminal_out_err() + if !has('unix') + return + endif + call writefile([ + \ '#!/bin/sh', + \ 'echo "this is standard error" >&2', + \ 'echo "this is standard out" >&1', + \ ], 'Xechoerrout.sh') + call setfperm('Xechoerrout.sh', 'rwxrwx---') + + let outfile = 'Xtermstdout' + let buf = term_start(['./Xechoerrout.sh'], {'out_io': 'file', 'out_name': outfile}) + + call WaitFor({-> !empty(readfile(outfile)) && !empty(term_getline(buf, 1))}) + call assert_equal(['this is standard out'], readfile(outfile)) + call assert_equal('this is standard error', term_getline(buf, 1)) + + call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))}) + exe buf . 'bwipe' + call delete('Xechoerrout.sh') + call delete(outfile) +endfunc + +func Test_terminwinscroll() + if !has('unix') + return + endif + + " Let the terminal output more than 'termwinscroll' lines, some at the start + " will be dropped. + exe 'set termwinscroll=' . &lines + let buf = term_start('/bin/sh') + for i in range(1, &lines) + call feedkeys("echo " . i . "\<CR>", 'xt') + call WaitForAssert({-> assert_match(string(i), term_getline(buf, term_getcursor(buf)[0] - 1))}) + endfor + " Go to Terminal-Normal mode to update the buffer. + call feedkeys("\<C-W>N", 'xt') + call assert_inrange(&lines, &lines * 110 / 100 + winheight(0), line('$')) + + " Every "echo nr" must only appear once + let lines = getline(1, line('$')) + for i in range(&lines - len(lines) / 2 + 2, &lines) + let filtered = filter(copy(lines), {idx, val -> val =~ 'echo ' . i . '\>'}) + call assert_equal(1, len(filtered), 'for "echo ' . i . '"') + endfor + + exe buf . 'bwipe!' +endfunc + +" Resizing the terminal window caused an ml_get error. +" TODO: This does not reproduce the original problem. +func Test_terminal_resize() + set statusline=x + terminal + call assert_equal(2, winnr('$')) + + " Fill the terminal with text. + if has('win32') + call feedkeys("dir\<CR>", 'xt') + else + call feedkeys("ls\<CR>", 'xt') + endif + " Go to Terminal-Normal mode for a moment. + call feedkeys("\<C-W>N", 'xt') + " Open a new window + call feedkeys("i\<C-W>n", 'xt') + call assert_equal(3, winnr('$')) + redraw + + close + call assert_equal(2, winnr('$')) + call feedkeys("exit\<CR>", 'xt') + set statusline& +endfunc + +" must be nearly the last, we can't go back from GUI to terminal +func Test_zz1_terminal_in_gui() + if !CanRunGui() + return + endif + + " Ignore the "failed to create input context" error. + call test_ignore_error('E285:') + + gui -f + + call assert_equal(1, winnr('$')) + let buf = Run_shell_in_terminal({'term_finish': 'close'}) + call Stop_shell_in_terminal(buf) + call term_wait(buf) + + " closing window wipes out the terminal buffer a with finished job + call WaitForAssert({-> assert_equal(1, winnr('$'))}) + call assert_equal("", bufname(buf)) + + unlet g:job +endfunc + +func Test_zz2_terminal_guioptions_bang() + if !has('gui_running') + return + endif + set guioptions+=! + + let filename = 'Xtestscript' + if has('win32') + let filename .= '.bat' + let prefix = '' + let contents = ['@echo off', 'exit %1'] + else + let filename .= '.sh' + let prefix = './' + let contents = ['#!/bin/sh', 'exit $1'] + endif + call writefile(contents, filename) + call setfperm(filename, 'rwxrwx---') + + " Check if v:shell_error is equal to the exit status. + let exitval = 0 + execute printf(':!%s%s %d', prefix, filename, exitval) + call assert_equal(exitval, v:shell_error) + + let exitval = 9 + execute printf(':!%s%s %d', prefix, filename, exitval) + call assert_equal(exitval, v:shell_error) + + set guioptions& + call delete(filename) +endfunc + +func Test_terminal_hidden() + if !has('unix') + return + endif + term ++hidden cat + let bnr = bufnr('$') + call assert_equal('terminal', getbufvar(bnr, '&buftype')) + exe 'sbuf ' . bnr + call assert_equal('terminal', &buftype) + call term_sendkeys(bnr, "asdf\<CR>") + call WaitForAssert({-> assert_match('asdf', term_getline(bnr, 2))}) + call term_sendkeys(bnr, "\<C-D>") + call WaitForAssert({-> assert_equal('finished', term_getstatus(bnr))}) + bwipe! +endfunc + +func Test_terminal_hidden_and_close() + if !has('unix') + return + endif + call assert_equal(1, winnr('$')) + term ++hidden ++close ls + let bnr = bufnr('$') + call assert_equal('terminal', getbufvar(bnr, '&buftype')) + call WaitForAssert({-> assert_false(bufexists(bnr))}) + call assert_equal(1, winnr('$')) +endfunc + +func Test_terminal_does_not_truncate_last_newlines() + " This test does not pass through ConPTY. + if has('conpty') + return + endif + let contents = [ + \ [ 'One', '', 'X' ], + \ [ 'Two', '', '' ], + \ [ 'Three' ] + repeat([''], 30) + \ ] + + for c in contents + call writefile(c, 'Xfile') + if has('win32') + term cmd /c type Xfile + else + term cat Xfile + endif + let bnr = bufnr('$') + call assert_equal('terminal', getbufvar(bnr, '&buftype')) + call WaitForAssert({-> assert_equal('finished', term_getstatus(bnr))}) + sleep 100m + call assert_equal(c, getline(1, line('$'))) + quit + endfor + + call delete('Xfile') +endfunc + +func Test_terminal_no_job() + let term = term_start('false', {'term_finish': 'close'}) + call WaitForAssert({-> assert_equal(v:null, term_getjob(term)) }) +endfunc + +func Test_term_gettitle() + if !has('title') || empty(&t_ts) + return + endif + " TODO: this fails on Travis + return + + " term_gettitle() returns an empty string for a non-terminal buffer + " or for a non-existing buffer. + call assert_equal('', term_gettitle(bufnr('%'))) + call assert_equal('', term_gettitle(bufnr('$') + 1)) + + let term = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile']) + call WaitForAssert({-> assert_equal('[No Name] - VIM', term_gettitle(term)) }) + + call term_sendkeys(term, ":e Xfoo\r") + call WaitForAssert({-> assert_match('Xfoo (.*[/\\]testdir) - VIM', term_gettitle(term)) }) + + call term_sendkeys(term, ":set titlestring=foo\r") + call WaitForAssert({-> assert_equal('foo', term_gettitle(term)) }) + + exe term . 'bwipe!' +endfunc + +" When drawing the statusline the cursor position may not have been updated +" yet. +" 1. create a terminal, make it show 2 lines +" 2. 0.5 sec later: leave terminal window, execute "i" +" 3. 0.5 sec later: clear terminal window, now it's 1 line +" 4. 0.5 sec later: redraw, including statusline (used to trigger bug) +" 4. 0.5 sec later: should be done, clean up +func Test_terminal_statusline() + if !has('unix') + return + endif + set statusline=x + terminal + let tbuf = bufnr('') + call term_sendkeys(tbuf, "clear; echo a; echo b; sleep 1; clear\n") + call timer_start(500, { tid -> feedkeys("\<C-w>j", 'tx') }) + call timer_start(1500, { tid -> feedkeys("\<C-l>", 'tx') }) + au BufLeave * if &buftype == 'terminal' | silent! normal i | endif + + sleep 2 + exe tbuf . 'bwipe!' + au! BufLeave + set statusline= +endfunc diff --git a/src/testdir/test_terminal_fail.vim b/src/testdir/test_terminal_fail.vim new file mode 100644 index 0000000..aad4b98 --- /dev/null +++ b/src/testdir/test_terminal_fail.vim @@ -0,0 +1,21 @@ +" This test is in a separate file, because it usually causes reports for memory +" leaks under valgrind. That is because when fork/exec fails memory is not +" freed. Since the process exists right away it's not a real leak. + +if !has('terminal') + finish +endif + +source shared.vim + +func Test_terminal_redir_fails() + if has('unix') + let buf = term_start('xyzabc', {'err_io': 'file', 'err_name': 'Xfile'}) + call term_wait(buf) + call WaitFor('len(readfile("Xfile")) > 0') + call assert_match('executing job failed', readfile('Xfile')[0]) + call WaitFor('!&modified') + call delete('Xfile') + bwipe + endif +endfunc diff --git a/src/testdir/test_textformat.vim b/src/testdir/test_textformat.vim new file mode 100644 index 0000000..13fb50b --- /dev/null +++ b/src/testdir/test_textformat.vim @@ -0,0 +1,491 @@ +" Tests for the various 'formatoptions' settings +func Test_text_format() + enew! + + setl noai tw=2 fo=t + call append('$', [ + \ '{', + \ ' ', + \ '', + \ '}']) + exe "normal /^{/+1\n0" + normal gRa b + let lnum = line('.') + call assert_equal([ + \ 'a', + \ 'b'], getline(lnum - 1, lnum)) + + normal ggdG + setl ai tw=2 fo=tw + call append('$', [ + \ '{', + \ 'a b ', + \ '', + \ 'a ', + \ '}']) + exe "normal /^{/+1\n0" + normal gqgqjjllab + let lnum = line('.') + call assert_equal([ + \ 'a ', + \ 'b ', + \ '', + \ 'a ', + \ 'b'], getline(lnum - 4, lnum)) + + normal ggdG + setl tw=3 fo=t + call append('$', [ + \ '{', + \ "a \<C-A>", + \ '}']) + exe "normal /^{/+1\n0" + exe "normal gqgqo\na \<C-V>\<C-A>" + let lnum = line('.') + call assert_equal([ + \ 'a', + \ "\<C-A>", + \ '', + \ 'a', + \ "\<C-A>"], getline(lnum - 4, lnum)) + + normal ggdG + setl tw=2 fo=tcq1 comments=:# + call append('$', [ + \ '{', + \ 'a b', + \ '#a b', + \ '}']) + exe "normal /^{/+1\n0" + exe "normal gqgqjgqgqo\na b\n#a b" + let lnum = line('.') + call assert_equal([ + \ 'a b', + \ '#a b', + \ '', + \ 'a b', + \ '#a b'], getline(lnum - 4, lnum)) + + normal ggdG + setl tw=5 fo=tcn comments=:# + call append('$', [ + \ '{', + \ ' 1 a', + \ '# 1 a', + \ '}']) + exe "normal /^{/+1\n0" + exe "normal A b\<Esc>jA b" + let lnum = line('.') + call assert_equal([ + \ ' 1 a', + \ ' b', + \ '# 1 a', + \ '# b'], getline(lnum - 3, lnum)) + + normal ggdG + setl tw=5 fo=t2a si + call append('$', [ + \ '{', + \ '', + \ ' x a', + \ ' b', + \ ' c', + \ '', + \ '}']) + exe "normal /^{/+3\n0" + exe "normal i \<Esc>A_" + let lnum = line('.') + call assert_equal([ + \ '', + \ ' x a', + \ ' b_', + \ ' c', + \ ''], getline(lnum - 2, lnum + 2)) + + normal ggdG + setl tw=5 fo=qn comments=:# + call append('$', [ + \ '{', + \ '# 1 a b', + \ '}']) + exe "normal /^{/+1\n5|" + normal gwap + call assert_equal(5, col('.')) + let lnum = line('.') + call assert_equal([ + \ '# 1 a', + \ '# b'], getline(lnum, lnum + 1)) + + normal ggdG + setl tw=5 fo=q2 comments=:# + call append('$', [ + \ '{', + \ '# x', + \ '# a b', + \ '}']) + exe "normal /^{/+1\n0" + normal gwap + let lnum = line('.') + call assert_equal([ + \ '# x a', + \ '# b'], getline(lnum, lnum + 1)) + + normal ggdG + setl tw& fo=a + call append('$', [ + \ '{', + \ ' 1aa', + \ ' 2bb', + \ '}']) + exe "normal /^{/+2\n0" + normal I^^ + call assert_equal('{ 1aa ^^2bb }', getline('.')) + + normal ggdG + setl tw=20 fo=an12wcq comments=s1:/*,mb:*,ex:*/ + call append('$', [ + \ '/* abc def ghi jkl ', + \ ' * mno pqr stu', + \ ' */']) + exe "normal /mno pqr/\n" + normal A vwx yz + let lnum = line('.') + call assert_equal([ + \ ' * mno pqr stu ', + \ ' * vwx yz', + \ ' */'], getline(lnum - 1, lnum + 1)) + + normal ggdG + setl tw=12 fo=tqnc comments=:# + call setline('.', '# 1 xxxxx') + normal A foobar + call assert_equal([ + \ '# 1 xxxxx', + \ '# foobar'], getline(1, 2)) + + " Test the 'p' flag for 'formatoptions' + " First test without the flag: that it will break "Mr. Feynman" at the space + normal ggdG + setl tw=28 fo=tcq + call setline('.', 'Surely you''re joking, Mr. Feynman!') + normal gqq + call assert_equal([ + \ 'Surely you''re joking, Mr.', + \ 'Feynman!'], getline(1, 2)) + " Now test with the flag: that it will push the name with the title onto the + " next line + normal ggdG + setl fo+=p + call setline('.', 'Surely you''re joking, Mr. Feynman!') + normal gqq + call assert_equal([ + \ 'Surely you''re joking,', + \ 'Mr. Feynman!'], getline(1, 2)) + " Ensure that it will still break if two spaces are entered + normal ggdG + call setline('.', 'Surely you''re joking, Mr. Feynman!') + normal gqq + call assert_equal([ + \ 'Surely you''re joking, Mr.', + \ 'Feynman!'], getline(1, 2)) + + setl ai& tw& fo& si& comments& + enew! +endfunc + +" Tests for :right, :center and :left on text with embedded TAB. +func Test_format_align() + enew! + set tw=65 + + " :left alignment + call append(0, [ + \ " test for :left", + \ " a a", + \ " fa a", + \ " dfa a", + \ " sdfa a", + \ " asdfa a", + \ " xasdfa a", + \ "asxxdfa a", + \ ]) + %left + call assert_equal([ + \ "test for :left", + \ "a a", + \ "fa a", + \ "dfa a", + \ "sdfa a", + \ "asdfa a", + \ "xasdfa a", + \ "asxxdfa a", + \ "" + \ ], getline(1, '$')) + enew! + + " :center alignment + call append(0, [ + \ " test for :center", + \ " a a", + \ " fa afd asdf", + \ " dfa a", + \ " sdfa afd asdf", + \ " asdfa a", + \ " xasdfa asdfasdfasdfasdfasdf", + \ "asxxdfa a" + \ ]) + %center + call assert_equal([ + \ " test for :center", + \ " a a", + \ " fa afd asdf", + \ " dfa a", + \ " sdfa afd asdf", + \ " asdfa a", + \ " xasdfa asdfasdfasdfasdfasdf", + \ " asxxdfa a", + \ "" + \ ], getline(1, '$')) + enew! + + " :right alignment + call append(0, [ + \ " test for :right", + \ " a a", + \ " fa a", + \ " dfa a", + \ " sdfa a", + \ " asdfa a", + \ " xasdfa a", + \ " asxxdfa a", + \ " asxa;ofa a", + \ " asdfaqwer a", + \ " a ax", + \ " fa ax", + \ " dfa ax", + \ " sdfa ax", + \ " asdfa ax", + \ " xasdfa ax", + \ " asxxdfa ax", + \ " asxa;ofa ax", + \ " asdfaqwer ax", + \ " a axx", + \ " fa axx", + \ " dfa axx", + \ " sdfa axx", + \ " asdfa axx", + \ " xasdfa axx", + \ " asxxdfa axx", + \ " asxa;ofa axx", + \ " asdfaqwer axx", + \ " a axxx", + \ " fa axxx", + \ " dfa axxx", + \ " sdfa axxx", + \ " asdfa axxx", + \ " xasdfa axxx", + \ " asxxdfa axxx", + \ " asxa;ofa axxx", + \ " asdfaqwer axxx", + \ " a axxxo", + \ " fa axxxo", + \ " dfa axxxo", + \ " sdfa axxxo", + \ " asdfa axxxo", + \ " xasdfa axxxo", + \ " asxxdfa axxxo", + \ " asxa;ofa axxxo", + \ " asdfaqwer axxxo", + \ " a axxxoi", + \ " fa axxxoi", + \ " dfa axxxoi", + \ " sdfa axxxoi", + \ " asdfa axxxoi", + \ " xasdfa axxxoi", + \ " asxxdfa axxxoi", + \ " asxa;ofa axxxoi", + \ " asdfaqwer axxxoi", + \ " a axxxoik", + \ " fa axxxoik", + \ " dfa axxxoik", + \ " sdfa axxxoik", + \ " asdfa axxxoik", + \ " xasdfa axxxoik", + \ " asxxdfa axxxoik", + \ " asxa;ofa axxxoik", + \ " asdfaqwer axxxoik", + \ " a axxxoike", + \ " fa axxxoike", + \ " dfa axxxoike", + \ " sdfa axxxoike", + \ " asdfa axxxoike", + \ " xasdfa axxxoike", + \ " asxxdfa axxxoike", + \ " asxa;ofa axxxoike", + \ " asdfaqwer axxxoike", + \ " a axxxoikey", + \ " fa axxxoikey", + \ " dfa axxxoikey", + \ " sdfa axxxoikey", + \ " asdfa axxxoikey", + \ " xasdfa axxxoikey", + \ " asxxdfa axxxoikey", + \ " asxa;ofa axxxoikey", + \ " asdfaqwer axxxoikey", + \ ]) + %right + call assert_equal([ + \ "\t\t\t\t test for :right", + \ "\t\t\t\t a a", + \ "\t\t\t\t fa a", + \ "\t\t\t\t dfa a", + \ "\t\t\t\t sdfa a", + \ "\t\t\t\t asdfa a", + \ "\t\t\t\t xasdfa a", + \ "\t\t\t\t asxxdfa a", + \ "\t\t\t\t asxa;ofa a", + \ "\t\t\t\t asdfaqwer a", + \ "\t\t\t\t a ax", + \ "\t\t\t\t fa ax", + \ "\t\t\t\t dfa ax", + \ "\t\t\t\t sdfa ax", + \ "\t\t\t\t asdfa ax", + \ "\t\t\t\t xasdfa ax", + \ "\t\t\t\t asxxdfa ax", + \ "\t\t\t\t asxa;ofa ax", + \ "\t\t\t\t asdfaqwer ax", + \ "\t\t\t\t a axx", + \ "\t\t\t\t fa axx", + \ "\t\t\t\t dfa axx", + \ "\t\t\t\t sdfa axx", + \ "\t\t\t\t asdfa axx", + \ "\t\t\t\t xasdfa axx", + \ "\t\t\t\t asxxdfa axx", + \ "\t\t\t\t asxa;ofa axx", + \ "\t\t\t\t asdfaqwer axx", + \ "\t\t\t\t a axxx", + \ "\t\t\t\t fa axxx", + \ "\t\t\t\t dfa axxx", + \ "\t\t\t\t sdfa axxx", + \ "\t\t\t\t asdfa axxx", + \ "\t\t\t\t xasdfa axxx", + \ "\t\t\t\t asxxdfa axxx", + \ "\t\t\t\t asxa;ofa axxx", + \ "\t\t\t\t asdfaqwer axxx", + \ "\t\t\t\t a axxxo", + \ "\t\t\t\t fa axxxo", + \ "\t\t\t\t dfa axxxo", + \ "\t\t\t\t sdfa axxxo", + \ "\t\t\t\t asdfa axxxo", + \ "\t\t\t\t xasdfa axxxo", + \ "\t\t\t\t asxxdfa axxxo", + \ "\t\t\t\t asxa;ofa axxxo", + \ "\t\t\t\t asdfaqwer axxxo", + \ "\t\t\t\t a axxxoi", + \ "\t\t\t\t fa axxxoi", + \ "\t\t\t\t dfa axxxoi", + \ "\t\t\t\t sdfa axxxoi", + \ "\t\t\t\t asdfa axxxoi", + \ "\t\t\t\t xasdfa axxxoi", + \ "\t\t\t\t asxxdfa axxxoi", + \ "\t\t\t\t asxa;ofa axxxoi", + \ "\t\t\t\t asdfaqwer axxxoi", + \ "\t\t\t\t a axxxoik", + \ "\t\t\t\t fa axxxoik", + \ "\t\t\t\t dfa axxxoik", + \ "\t\t\t\t sdfa axxxoik", + \ "\t\t\t\t asdfa axxxoik", + \ "\t\t\t\t xasdfa axxxoik", + \ "\t\t\t\t asxxdfa axxxoik", + \ "\t\t\t\t asxa;ofa axxxoik", + \ "\t\t\t\t asdfaqwer axxxoik", + \ "\t\t\t\t a axxxoike", + \ "\t\t\t\t fa axxxoike", + \ "\t\t\t\t dfa axxxoike", + \ "\t\t\t\t sdfa axxxoike", + \ "\t\t\t\t asdfa axxxoike", + \ "\t\t\t\t xasdfa axxxoike", + \ "\t\t\t\t asxxdfa axxxoike", + \ "\t\t\t\t asxa;ofa axxxoike", + \ "\t\t\t\t asdfaqwer axxxoike", + \ "\t\t\t\t a axxxoikey", + \ "\t\t\t\t fa axxxoikey", + \ "\t\t\t\t dfa axxxoikey", + \ "\t\t\t\t sdfa axxxoikey", + \ "\t\t\t\t asdfa axxxoikey", + \ "\t\t\t\t xasdfa axxxoikey", + \ "\t\t\t\t asxxdfa axxxoikey", + \ "\t\t\t\t asxa;ofa axxxoikey", + \ "\t\t\t\t asdfaqwer axxxoikey", + \ "" + \ ], getline(1, '$')) + enew! + + set tw& +endfunc + +" Test formatting a paragraph. +func Test_format_para() + enew! + set fo+=tcroql tw=72 + + call append(0, [ + \ "xxxxx xx xxxxxx ", + \ "xxxxxxx xxxxxxxxx xxx xxxx xxxxx xxxxx xxx xx", + \ "xxxxxxxxxxxxxxxxxx xxxxx xxxx, xxxx xxxx xxxx xxxx xxx xx xx", + \ "xx xxxxxxx. xxxx xxxx.", + \ "", + \ "> xx xx, xxxx xxxx xxx xxxx xxx xxxxx xxx xxx xxxxxxx xxx xxxxx", + \ "> xxxxxx xxxxxxx: xxxx xxxxxxx, xx xxxxxx xxxx xxxxxxxxxx" + \ ]) + exe "normal /xxxxxxxx$\<CR>" + normal 0gq6kk + call assert_equal([ + \ "xxxxx xx xxxxxx xxxxxxx xxxxxxxxx xxx xxxx xxxxx xxxxx xxx xx", + \ "xxxxxxxxxxxxxxxxxx xxxxx xxxx, xxxx xxxx xxxx xxxx xxx xx xx xx xxxxxxx.", + \ "xxxx xxxx.", + \ "", + \ "> xx xx, xxxx xxxx xxx xxxx xxx xxxxx xxx xxx xxxxxxx xxx xxxxx xxxxxx", + \ "> xxxxxxx: xxxx xxxxxxx, xx xxxxxx xxxx xxxxxxxxxx", + \ "" + \ ], getline(1, '$')) + + set fo& tw& + enew! +endfunc + +" Test undo after ":%s" and formatting. +func Test_format_undo() + enew! + map gg :.,.+2s/^/x/<CR>kk:set tw=3<CR>gqq + + call append(0, [ + \ "aa aa aa aa", + \ "bb bb bb bb", + \ "cc cc cc cc" + \ ]) + " undo/redo here to make the next undo only work on the following changes + exe "normal i\<C-G>u" + call cursor(1,1) + normal ggu + call assert_equal([ + \ "aa aa aa aa", + \ "bb bb bb bb", + \ "cc cc cc cc", + \ "" + \ ], getline(1, '$')) + + unmap gg + set tw& + enew! +endfunc + +func Test_format_list_auto() + new + call setline(1, ['1. abc', '2. def', '3. ghi']) + set fo=tan ai bs=2 + call feedkeys("3G0lli\<BS>\<BS>x\<Esc>", 'tx') + call assert_equal('2. defx ghi', getline(2)) + bwipe! + set fo& ai& bs& +endfunc diff --git a/src/testdir/test_textobjects.vim b/src/testdir/test_textobjects.vim new file mode 100644 index 0000000..3c403ab --- /dev/null +++ b/src/testdir/test_textobjects.vim @@ -0,0 +1,259 @@ +" Test for textobjects + +if !has('textobjects') + finish +endif + +func CpoM(line, useM, expected) + new + + if a:useM + set cpoptions+=M + else + set cpoptions-=M + endif + + call setline(1, a:line) + + call setreg('"', '') + normal! ggfrmavi)y + call assert_equal(getreg('"'), a:expected[0]) + + call setreg('"', '') + normal! `afbmavi)y + call assert_equal(getreg('"'), a:expected[1]) + + call setreg('"', '') + normal! `afgmavi)y + call assert_equal(getreg('"'), a:expected[2]) + + q! +endfunc + +func Test_inner_block_without_cpo_M() + call CpoM('(red \(blue) green)', 0, ['red \(blue', 'red \(blue', '']) +endfunc + +func Test_inner_block_with_cpo_M_left_backslash() + call CpoM('(red \(blue) green)', 1, ['red \(blue) green', 'blue', 'red \(blue) green']) +endfunc + +func Test_inner_block_with_cpo_M_right_backslash() + call CpoM('(red (blue\) green)', 1, ['red (blue\) green', 'blue\', 'red (blue\) green']) +endfunc + +func Test_quote_selection_selection_exclusive() + new + call setline(1, "a 'bcde' f") + set selection=exclusive + exe "norm! fdvhi'y" + call assert_equal('bcde', @") + set selection&vim + bw! +endfunc + +" Tests for string and html text objects +func Test_string_html_objects() + enew! + + let t = '"wo\"rd\\" foo' + put =t + normal! da" + call assert_equal('foo', getline('.')) + + let t = "'foo' 'bar' 'piep'" + put =t + normal! 0va'a'rx + call assert_equal("xxxxxxxxxxxx'piep'", getline('.')) + + let t = "bla bla `quote` blah" + put =t + normal! 02f`da` + call assert_equal("bla bla blah", getline('.')) + + let t = 'out " in "noXno"' + put =t + normal! 0fXdi" + call assert_equal('out " in ""', getline('.')) + + let t = "\"'\" 'blah' rep 'buh'" + put =t + normal! 03f'vi'ry + call assert_equal("\"'\" 'blah'yyyyy'buh'", getline('.')) + + set quoteescape=+*- + let t = "bla `s*`d-`+++`l**` b`la" + put =t + normal! di` + call assert_equal("bla `` b`la", getline('.')) + + let t = 'voo "nah" sdf " asdf" sdf " sdf" sd' + put =t + normal! $F"va"oha"i"rz + call assert_equal('voo "zzzzzzzzzzzzzzzzzzzzzzzzzzzzsd', getline('.')) + + let t = "-<b>asdf<i>Xasdf</i>asdf</b>-" + put =t + normal! fXdit + call assert_equal('-<b>asdf<i></i>asdf</b>-', getline('.')) + + let t = "-<b>asdX<i>a<i />sdf</i>asdf</b>-" + put =t + normal! 0fXdit + call assert_equal('-<b></b>-', getline('.')) + + let t = "-<b>asdf<i>Xasdf</i>asdf</b>-" + put =t + normal! fXdat + call assert_equal('-<b>asdfasdf</b>-', getline('.')) + + let t = "-<b>asdX<i>as<b />df</i>asdf</b>-" + put =t + normal! 0fXdat + call assert_equal('--', getline('.')) + + let t = "-<b>\ninnertext object\n</b>" + put =t + normal! dit + call assert_equal('-<b></b>', getline('.')) + + set quoteescape& + enew! +endfunc + +func Test_empty_html_tag() + new + call setline(1, '<div></div>') + normal 0citxxx + call assert_equal('<div>xxx</div>', getline(1)) + + call setline(1, '<div></div>') + normal 0f<cityyy + call assert_equal('<div>yyy</div>', getline(1)) + + call setline(1, '<div></div>') + normal 0f<vitsaaa + call assert_equal('aaa', getline(1)) + + bwipe! +endfunc + +" Tests for match() and matchstr() +func Test_match() + call assert_equal("b", matchstr("abcd", ".", 0, 2)) + call assert_equal("bc", matchstr("abcd", "..", 0, 2)) + call assert_equal("c", matchstr("abcd", ".", 2, 0)) + call assert_equal("a", matchstr("abcd", ".", 0, -1)) + call assert_equal(-1, match("abcd", ".", 0, 5)) + call assert_equal(0 , match("abcd", ".", 0, -1)) + call assert_equal(0 , match('abc', '.', 0, 1)) + call assert_equal(1 , match('abc', '.', 0, 2)) + call assert_equal(2 , match('abc', '.', 0, 3)) + call assert_equal(-1, match('abc', '.', 0, 4)) + call assert_equal(1 , match('abc', '.', 1, 1)) + call assert_equal(2 , match('abc', '.', 2, 1)) + call assert_equal(-1, match('abc', '.', 3, 1)) + call assert_equal(3 , match('abc', '$', 0, 1)) + call assert_equal(-1, match('abc', '$', 0, 2)) + call assert_equal(3 , match('abc', '$', 1, 1)) + call assert_equal(3 , match('abc', '$', 2, 1)) + call assert_equal(3 , match('abc', '$', 3, 1)) + call assert_equal(-1, match('abc', '$', 4, 1)) + call assert_equal(0 , match('abc', '\zs', 0, 1)) + call assert_equal(1 , match('abc', '\zs', 0, 2)) + call assert_equal(2 , match('abc', '\zs', 0, 3)) + call assert_equal(3 , match('abc', '\zs', 0, 4)) + call assert_equal(-1, match('abc', '\zs', 0, 5)) + call assert_equal(1 , match('abc', '\zs', 1, 1)) + call assert_equal(2 , match('abc', '\zs', 2, 1)) + call assert_equal(3 , match('abc', '\zs', 3, 1)) + call assert_equal(-1, match('abc', '\zs', 4, 1)) +endfunc + +" This was causing an illegal memory access +func Test_inner_tag() + new + norm ixxx + call feedkeys("v", 'xt') + insert +x +x +. + norm it + q! +endfunc + +func Test_sentence() + enew! + call setline(1, 'A sentence. A sentence? A sentence!') + + normal yis + call assert_equal('A sentence.', @") + normal yas + call assert_equal('A sentence. ', @") + + normal ) + + normal yis + call assert_equal('A sentence?', @") + normal yas + call assert_equal('A sentence? ', @") + + normal ) + + normal yis + call assert_equal('A sentence!', @") + normal yas + call assert_equal(' A sentence!', @") + + normal 0 + normal 2yis + call assert_equal('A sentence. ', @") + normal 3yis + call assert_equal('A sentence. A sentence?', @") + normal 2yas + call assert_equal('A sentence. A sentence? ', @") + + %delete _ +endfunc + +func Test_sentence_with_quotes() + enew! + call setline(1, 'A "sentence." A sentence.') + + normal yis + call assert_equal('A "sentence."', @") + normal yas + call assert_equal('A "sentence." ', @") + + normal ) + + normal yis + call assert_equal('A sentence.', @") + normal yas + call assert_equal(' A sentence.', @") + + %delete _ +endfunc + +func Test_sentence_with_cursor_on_delimiter() + enew! + call setline(1, "A '([sentence.])' A sentence.") + + normal! 15|yis + call assert_equal("A '([sentence.])'", @") + normal! 15|yas + call assert_equal("A '([sentence.])' ", @") + + normal! 16|yis + call assert_equal("A '([sentence.])'", @") + normal! 16|yas + call assert_equal("A '([sentence.])' ", @") + + normal! 17|yis + call assert_equal("A '([sentence.])'", @") + normal! 17|yas + call assert_equal("A '([sentence.])' ", @") + + %delete _ +endfunc diff --git a/src/testdir/test_textprop.vim b/src/testdir/test_textprop.vim new file mode 100644 index 0000000..311f30f --- /dev/null +++ b/src/testdir/test_textprop.vim @@ -0,0 +1,552 @@ +" Tests for defining text property types and adding text properties to the +" buffer. + +if !has('textprop') + finish +endif + +source screendump.vim + +" test length zero + +func Test_proptype_global() + call prop_type_add('comment', {'highlight': 'Directory', 'priority': 123, 'start_incl': 1, 'end_incl': 1}) + let proptypes = prop_type_list() + call assert_equal(1, len(proptypes)) + call assert_equal('comment', proptypes[0]) + + let proptype = prop_type_get('comment') + call assert_equal('Directory', proptype['highlight']) + call assert_equal(123, proptype['priority']) + call assert_equal(1, proptype['start_incl']) + call assert_equal(1, proptype['end_incl']) + + call prop_type_delete('comment') + call assert_equal(0, len(prop_type_list())) + + call prop_type_add('one', {}) + call assert_equal(1, len(prop_type_list())) + let proptype = prop_type_get('one') + call assert_false(has_key(proptype, 'highlight')) + call assert_equal(0, proptype['priority']) + call assert_equal(0, proptype['start_incl']) + call assert_equal(0, proptype['end_incl']) + + call prop_type_add('two', {}) + call assert_equal(2, len(prop_type_list())) + call prop_type_delete('one') + call assert_equal(1, len(prop_type_list())) + call prop_type_delete('two') + call assert_equal(0, len(prop_type_list())) +endfunc + +func Test_proptype_buf() + let bufnr = bufnr('') + call prop_type_add('comment', {'bufnr': bufnr, 'highlight': 'Directory', 'priority': 123, 'start_incl': 1, 'end_incl': 1}) + let proptypes = prop_type_list({'bufnr': bufnr}) + call assert_equal(1, len(proptypes)) + call assert_equal('comment', proptypes[0]) + + let proptype = prop_type_get('comment', {'bufnr': bufnr}) + call assert_equal('Directory', proptype['highlight']) + call assert_equal(123, proptype['priority']) + call assert_equal(1, proptype['start_incl']) + call assert_equal(1, proptype['end_incl']) + + call prop_type_delete('comment', {'bufnr': bufnr}) + call assert_equal(0, len(prop_type_list({'bufnr': bufnr}))) + + call prop_type_add('one', {'bufnr': bufnr}) + let proptype = prop_type_get('one', {'bufnr': bufnr}) + call assert_false(has_key(proptype, 'highlight')) + call assert_equal(0, proptype['priority']) + call assert_equal(0, proptype['start_incl']) + call assert_equal(0, proptype['end_incl']) + + call prop_type_add('two', {'bufnr': bufnr}) + call assert_equal(2, len(prop_type_list({'bufnr': bufnr}))) + call prop_type_delete('one', {'bufnr': bufnr}) + call assert_equal(1, len(prop_type_list({'bufnr': bufnr}))) + call prop_type_delete('two', {'bufnr': bufnr}) + call assert_equal(0, len(prop_type_list({'bufnr': bufnr}))) +endfunc + +func AddPropTypes() + call prop_type_add('one', {}) + call prop_type_add('two', {}) + call prop_type_add('three', {}) + call prop_type_add('whole', {}) +endfunc + +func DeletePropTypes() + call prop_type_delete('one') + call prop_type_delete('two') + call prop_type_delete('three') + call prop_type_delete('whole') +endfunc + +func SetupPropsInFirstLine() + call setline(1, 'one two three') + call prop_add(1, 1, {'length': 3, 'id': 11, 'type': 'one'}) + call prop_add(1, 5, {'length': 3, 'id': 12, 'type': 'two'}) + call prop_add(1, 9, {'length': 5, 'id': 13, 'type': 'three'}) + call prop_add(1, 1, {'length': 13, 'id': 14, 'type': 'whole'}) +endfunc + +func Get_expected_props() + return [ + \ {'col': 1, 'length': 13, 'id': 14, 'type': 'whole', 'start': 1, 'end': 1}, + \ {'col': 1, 'length': 3, 'id': 11, 'type': 'one', 'start': 1, 'end': 1}, + \ {'col': 5, 'length': 3, 'id': 12, 'type': 'two', 'start': 1, 'end': 1}, + \ {'col': 9, 'length': 5, 'id': 13, 'type': 'three', 'start': 1, 'end': 1}, + \ ] +endfunc + +func Test_prop_add() + new + call AddPropTypes() + call SetupPropsInFirstLine() + let expected_props = Get_expected_props() + call assert_equal(expected_props, prop_list(1)) + call assert_fails("call prop_add(10, 1, {'length': 1, 'id': 14, 'type': 'whole'})", 'E966:') + call assert_fails("call prop_add(1, 22, {'length': 1, 'id': 14, 'type': 'whole'})", 'E964:') + + " Insert a line above, text props must still be there. + call append(0, 'empty') + call assert_equal(expected_props, prop_list(2)) + " Delete a line above, text props must still be there. + 1del + call assert_equal(expected_props, prop_list(1)) + + " Prop without length or end column is zero length + call prop_clear(1) + call prop_add(1, 5, {'type': 'two'}) + let expected = [{'col': 5, 'length': 0, 'type': 'two', 'id': 0, 'start': 1, 'end': 1}] + call assert_equal(expected, prop_list(1)) + + call DeletePropTypes() + bwipe! +endfunc + +func Test_prop_remove() + new + call AddPropTypes() + call SetupPropsInFirstLine() + let props = Get_expected_props() + call assert_equal(props, prop_list(1)) + + " remove by id + call prop_remove({'id': 12}, 1) + unlet props[2] + call assert_equal(props, prop_list(1)) + + " remove by type + call prop_remove({'type': 'one'}, 1) + unlet props[1] + call assert_equal(props, prop_list(1)) + + call DeletePropTypes() + bwipe! +endfunc + +func SetupOneLine() + call setline(1, 'xonex xtwoxx') + call AddPropTypes() + call prop_add(1, 2, {'length': 3, 'id': 11, 'type': 'one'}) + call prop_add(1, 8, {'length': 3, 'id': 12, 'type': 'two'}) + let expected = [ + \ {'col': 2, 'length': 3, 'id': 11, 'type': 'one', 'start': 1, 'end': 1}, + \ {'col': 8, 'length': 3, 'id': 12, 'type': 'two', 'start': 1, 'end': 1}, + \] + call assert_equal(expected, prop_list(1)) + return expected +endfunc + +func Test_prop_add_remove_buf() + new + let bufnr = bufnr('') + call AddPropTypes() + call setline(1, 'one two three') + wincmd w + call prop_add(1, 1, {'length': 3, 'id': 11, 'type': 'one', 'bufnr': bufnr}) + call prop_add(1, 5, {'length': 3, 'id': 12, 'type': 'two', 'bufnr': bufnr}) + call prop_add(1, 11, {'length': 3, 'id': 13, 'type': 'three', 'bufnr': bufnr}) + + let props = [ + \ {'col': 1, 'length': 3, 'id': 11, 'type': 'one', 'start': 1, 'end': 1}, + \ {'col': 5, 'length': 3, 'id': 12, 'type': 'two', 'start': 1, 'end': 1}, + \ {'col': 11, 'length': 3, 'id': 13, 'type': 'three', 'start': 1, 'end': 1}, + \] + call assert_equal(props, prop_list(1, {'bufnr': bufnr})) + + " remove by id + call prop_remove({'id': 12, 'bufnr': bufnr}, 1) + unlet props[1] + call assert_equal(props, prop_list(1, {'bufnr': bufnr})) + + " remove by type + call prop_remove({'type': 'one', 'bufnr': bufnr}, 1) + unlet props[0] + call assert_equal(props, prop_list(1, {'bufnr': bufnr})) + + call DeletePropTypes() + wincmd w + bwipe! +endfunc + +func Test_prop_backspace() + new + set bs=2 + let expected = SetupOneLine() " 'xonex xtwoxx' + + exe "normal 0li\<BS>\<Esc>fxli\<BS>\<Esc>" + call assert_equal('one xtwoxx', getline(1)) + let expected[0].col = 1 + let expected[1].col = 6 + call assert_equal(expected, prop_list(1)) + + call DeletePropTypes() + bwipe! + set bs& +endfunc + +func Test_prop_replace() + new + set bs=2 + let expected = SetupOneLine() " 'xonex xtwoxx' + + exe "normal 0Ryyy\<Esc>" + call assert_equal('yyyex xtwoxx', getline(1)) + call assert_equal(expected, prop_list(1)) + + exe "normal ftRyy\<BS>" + call assert_equal('yyyex xywoxx', getline(1)) + call assert_equal(expected, prop_list(1)) + + exe "normal 0fwRyy\<BS>" + call assert_equal('yyyex xyyoxx', getline(1)) + call assert_equal(expected, prop_list(1)) + + exe "normal 0foRyy\<BS>\<BS>" + call assert_equal('yyyex xyyoxx', getline(1)) + call assert_equal(expected, prop_list(1)) + + call DeletePropTypes() + bwipe! + set bs& +endfunc + +func Test_prop_clear() + new + call AddPropTypes() + call SetupPropsInFirstLine() + call assert_equal(Get_expected_props(), prop_list(1)) + + call prop_clear(1) + call assert_equal([], prop_list(1)) + + call DeletePropTypes() + bwipe! +endfunc + +func Test_prop_clear_buf() + new + call AddPropTypes() + call SetupPropsInFirstLine() + let bufnr = bufnr('') + wincmd w + call assert_equal(Get_expected_props(), prop_list(1, {'bufnr': bufnr})) + + call prop_clear(1, 1, {'bufnr': bufnr}) + call assert_equal([], prop_list(1, {'bufnr': bufnr})) + + wincmd w + call DeletePropTypes() + bwipe! +endfunc + +func Test_prop_setline() + new + call AddPropTypes() + call SetupPropsInFirstLine() + call assert_equal(Get_expected_props(), prop_list(1)) + + call setline(1, 'foobar') + call assert_equal([], prop_list(1)) + + call DeletePropTypes() + bwipe! +endfunc + +func Test_prop_setbufline() + new + call AddPropTypes() + call SetupPropsInFirstLine() + let bufnr = bufnr('') + wincmd w + call assert_equal(Get_expected_props(), prop_list(1, {'bufnr': bufnr})) + + call setbufline(bufnr, 1, 'foobar') + call assert_equal([], prop_list(1, {'bufnr': bufnr})) + + wincmd w + call DeletePropTypes() + bwipe! +endfunc + +func Test_prop_substitute() + new + " Set first line to 'one two three' + call AddPropTypes() + call SetupPropsInFirstLine() + let expected_props = Get_expected_props() + call assert_equal(expected_props, prop_list(1)) + + " Change "n" in "one" to XX: 'oXXe two three' + s/n/XX/ + let expected_props[0].length += 1 + let expected_props[1].length += 1 + let expected_props[2].col += 1 + let expected_props[3].col += 1 + call assert_equal(expected_props, prop_list(1)) + + " Delete "t" in "two" and "three" to XX: 'oXXe wo hree' + s/t//g + let expected_props[0].length -= 2 + let expected_props[2].length -= 1 + let expected_props[3].length -= 1 + let expected_props[3].col -= 1 + call assert_equal(expected_props, prop_list(1)) + + " Split the line by changing w to line break: 'oXXe ', 'o hree' + " The long prop is split and spans both lines. + " The props on "two" and "three" move to the next line. + s/w/\r/ + let new_props = [ + \ copy(expected_props[0]), + \ copy(expected_props[2]), + \ copy(expected_props[3]), + \ ] + let expected_props[0].length = 5 + unlet expected_props[3] + unlet expected_props[2] + call assert_equal(expected_props, prop_list(1)) + + let new_props[0].length = 6 + let new_props[1].col = 1 + let new_props[1].length = 1 + let new_props[2].col = 3 + call assert_equal(new_props, prop_list(2)) + + call DeletePropTypes() + bwipe! +endfunc + +func Test_prop_change_indent() + call prop_type_add('comment', {'highlight': 'Directory'}) + new + call setline(1, [' xxx', 'yyyyy']) + call prop_add(2, 2, {'length': 2, 'type': 'comment'}) + let expect = {'col': 2, 'length': 2, 'type': 'comment', 'start': 1, 'end': 1, 'id': 0} + call assert_equal([expect], prop_list(2)) + + set shiftwidth=3 + normal 2G>> + call assert_equal(' yyyyy', getline(2)) + let expect.col += 3 + call assert_equal([expect], prop_list(2)) + + normal 2G== + call assert_equal(' yyyyy', getline(2)) + let expect.col = 6 + call assert_equal([expect], prop_list(2)) + + call prop_clear(2) + call prop_add(2, 2, {'length': 5, 'type': 'comment'}) + let expect.col = 2 + let expect.length = 5 + call assert_equal([expect], prop_list(2)) + + normal 2G<< + call assert_equal(' yyyyy', getline(2)) + let expect.length = 2 + call assert_equal([expect], prop_list(2)) + + set shiftwidth& + call prop_type_delete('comment') +endfunc + +" Setup a three line prop in lines 2 - 4. +" Add short props in line 1 and 5. +func Setup_three_line_prop() + new + call setline(1, ['one', 'twotwo', 'three', 'fourfour', 'five']) + call prop_add(1, 2, {'length': 1, 'type': 'comment'}) + call prop_add(2, 4, {'end_lnum': 4, 'end_col': 5, 'type': 'comment'}) + call prop_add(5, 2, {'length': 1, 'type': 'comment'}) +endfunc + +func Test_prop_multiline() + call prop_type_add('comment', {'highlight': 'Directory'}) + new + call setline(1, ['xxxxxxx', 'yyyyyyyyy', 'zzzzzzzz']) + + " start halfway line 1, end halfway line 3 + call prop_add(1, 3, {'end_lnum': 3, 'end_col': 5, 'type': 'comment'}) + let expect1 = {'col': 3, 'length': 6, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0} + call assert_equal([expect1], prop_list(1)) + let expect2 = {'col': 1, 'length': 10, 'type': 'comment', 'start': 0, 'end': 0, 'id': 0} + call assert_equal([expect2], prop_list(2)) + let expect3 = {'col': 1, 'length': 4, 'type': 'comment', 'start': 0, 'end': 1, 'id': 0} + call assert_equal([expect3], prop_list(3)) + call prop_clear(1, 3) + + " include all three lines + call prop_add(1, 1, {'end_lnum': 3, 'end_col': 999, 'type': 'comment'}) + let expect1.col = 1 + let expect1.length = 8 + call assert_equal([expect1], prop_list(1)) + call assert_equal([expect2], prop_list(2)) + let expect3.length = 9 + call assert_equal([expect3], prop_list(3)) + call prop_clear(1, 3) + + bwipe! + + " Test deleting the first line of a multi-line prop. + call Setup_three_line_prop() + let expect_short = {'col': 2, 'length': 1, 'type': 'comment', 'start': 1, 'end': 1, 'id': 0} + call assert_equal([expect_short], prop_list(1)) + let expect2 = {'col': 4, 'length': 4, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0} + call assert_equal([expect2], prop_list(2)) + 2del + call assert_equal([expect_short], prop_list(1)) + let expect2 = {'col': 1, 'length': 6, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0} + call assert_equal([expect2], prop_list(2)) + bwipe! + + " Test deleting the last line of a multi-line prop. + call Setup_three_line_prop() + let expect3 = {'col': 1, 'length': 6, 'type': 'comment', 'start': 0, 'end': 0, 'id': 0} + call assert_equal([expect3], prop_list(3)) + let expect4 = {'col': 1, 'length': 4, 'type': 'comment', 'start': 0, 'end': 1, 'id': 0} + call assert_equal([expect4], prop_list(4)) + 4del + let expect3.end = 1 + call assert_equal([expect3], prop_list(3)) + call assert_equal([expect_short], prop_list(4)) + bwipe! + + " Test appending a line below the multi-line text prop start. + call Setup_three_line_prop() + let expect2 = {'col': 4, 'length': 4, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0} + call assert_equal([expect2], prop_list(2)) + call append(2, "new line") + call assert_equal([expect2], prop_list(2)) + let expect3 = {'col': 1, 'length': 9, 'type': 'comment', 'start': 0, 'end': 0, 'id': 0} + call assert_equal([expect3], prop_list(3)) + bwipe! + + call prop_type_delete('comment') +endfunc + +func Test_prop_byteoff() + call prop_type_add('comment', {'highlight': 'Directory'}) + new + call setline(1, ['line1', 'second line', '']) + set ff=unix + call assert_equal(19, line2byte(3)) + call prop_add(1, 1, {'end_col': 3, 'type': 'comment'}) + call assert_equal(19, line2byte(3)) + + bwipe! + call prop_type_delete('comment') +endfunc + +func Test_prop_undo() + new + call prop_type_add('comment', {'highlight': 'Directory'}) + call setline(1, ['oneone', 'twotwo', 'three']) + " Set 'undolevels' to break changes into undo-able pieces. + set ul& + + call prop_add(1, 3, {'end_col': 5, 'type': 'comment'}) + let expected = [{'col': 3, 'length': 2, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] + call assert_equal(expected, prop_list(1)) + + " Insert a character, then undo. + exe "normal 0lllix\<Esc>" + set ul& + let expected[0].length = 3 + call assert_equal(expected, prop_list(1)) + undo + let expected[0].length = 2 + call assert_equal(expected, prop_list(1)) + + " Delete a character, then undo + exe "normal 0lllx" + set ul& + let expected[0].length = 1 + call assert_equal(expected, prop_list(1)) + undo + let expected[0].length = 2 + call assert_equal(expected, prop_list(1)) + + " Delete the line, then undo + 1d + set ul& + call assert_equal([], prop_list(1)) + undo + call assert_equal(expected, prop_list(1)) + + " Insert a character, delete two characters, then undo with "U" + exe "normal 0lllix\<Esc>" + set ul& + let expected[0].length = 3 + call assert_equal(expected, prop_list(1)) + exe "normal 0lllxx" + set ul& + let expected[0].length = 1 + call assert_equal(expected, prop_list(1)) + normal U + let expected[0].length = 2 + call assert_equal(expected, prop_list(1)) + + bwipe! + call prop_type_delete('comment') +endfunc + +" screenshot test with textprop highlighting +funct Test_textprop_screenshots() + if !CanRunVimInTerminal() || &encoding != 'utf-8' + return + endif + call writefile([ + \ "call setline(1, ['One two', 'Numbér 123 änd thœn 4¾7.', '--aa--bb--cc--dd--'])", + \ "hi NumberProp ctermfg=blue", + \ "hi LongProp ctermbg=yellow", + \ "call prop_type_add('number', {'highlight': 'NumberProp'})", + \ "call prop_type_add('long', {'highlight': 'LongProp'})", + \ "call prop_type_add('start', {'highlight': 'NumberProp', 'start_incl': 1})", + \ "call prop_type_add('end', {'highlight': 'NumberProp', 'end_incl': 1})", + \ "call prop_type_add('both', {'highlight': 'NumberProp', 'start_incl': 1, 'end_incl': 1})", + \ "call prop_add(1, 4, {'end_lnum': 3, 'end_col': 3, 'type': 'long'})", + \ "call prop_add(2, 9, {'length': 3, 'type': 'number'})", + \ "call prop_add(2, 24, {'length': 4, 'type': 'number'})", + \ "call prop_add(3, 3, {'length': 2, 'type': 'number'})", + \ "call prop_add(3, 7, {'length': 2, 'type': 'start'})", + \ "call prop_add(3, 11, {'length': 2, 'type': 'end'})", + \ "call prop_add(3, 15, {'length': 2, 'type': 'both'})", + \ "set number", + \ "hi clear SpellBad", + \ "set spell", + \ "normal 3G0llix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>lllix\<Esc>", + \ "normal 3G0lli\<BS>\<Esc>", + \], 'XtestProp') + let buf = RunVimInTerminal('-S XtestProp', {'rows': 6}) + call VerifyScreenDump(buf, 'Test_textprop_01', {}) + + " clean up + call StopVimInTerminal(buf) + call delete('XtestProp') +endfunc diff --git a/src/testdir/test_timers.vim b/src/testdir/test_timers.vim new file mode 100644 index 0000000..e900b1f --- /dev/null +++ b/src/testdir/test_timers.vim @@ -0,0 +1,313 @@ +" Test for timers + +if !has('timers') + finish +endif + +source shared.vim +source screendump.vim + +func MyHandler(timer) + let g:val += 1 +endfunc + +func MyHandlerWithLists(lists, timer) + let x = string(a:lists) +endfunc + +func Test_oneshot() + let g:val = 0 + let timer = timer_start(50, 'MyHandler') + let slept = WaitFor('g:val == 1') + call assert_equal(1, g:val) + if has('reltime') + call assert_inrange(49, 100, slept) + else + call assert_inrange(20, 100, slept) + endif +endfunc + +func Test_repeat_three() + let g:val = 0 + let timer = timer_start(50, 'MyHandler', {'repeat': 3}) + let slept = WaitFor('g:val == 3') + call assert_equal(3, g:val) + if has('reltime') + call assert_inrange(149, 250, slept) + else + call assert_inrange(80, 200, slept) + endif +endfunc + +func Test_repeat_many() + let g:val = 0 + let timer = timer_start(50, 'MyHandler', {'repeat': -1}) + sleep 200m + call timer_stop(timer) + call assert_inrange(2, 4, g:val) +endfunc + +func Test_with_partial_callback() + let g:val = 0 + let meow = {'one': 1} + function meow.bite(...) + let g:val += self.one + endfunction + + call timer_start(50, meow.bite) + let slept = WaitFor('g:val == 1') + call assert_equal(1, g:val) + if has('reltime') + call assert_inrange(49, 130, slept) + else + call assert_inrange(20, 100, slept) + endif +endfunc + +func Test_retain_partial() + call timer_start(50, function('MyHandlerWithLists', [['a']])) + call test_garbagecollect_now() + sleep 100m +endfunc + +func Test_info() + let id = timer_start(1000, 'MyHandler') + let info = timer_info(id) + call assert_equal(id, info[0]['id']) + call assert_equal(1000, info[0]['time']) + call assert_true(info[0]['remaining'] > 500) + call assert_true(info[0]['remaining'] <= 1000) + call assert_equal(1, info[0]['repeat']) + call assert_equal("function('MyHandler')", string(info[0]['callback'])) + + let found = 0 + for info in timer_info() + if info['id'] == id + let found += 1 + endif + endfor + call assert_equal(1, found) + + call timer_stop(id) + call assert_equal([], timer_info(id)) +endfunc + +func Test_stopall() + let id1 = timer_start(1000, 'MyHandler') + let id2 = timer_start(2000, 'MyHandler') + let info = timer_info() + call assert_equal(2, len(info)) + + call timer_stopall() + let info = timer_info() + call assert_equal(0, len(info)) +endfunc + +func Test_paused() + let g:val = 0 + + let id = timer_start(50, 'MyHandler') + let info = timer_info(id) + call assert_equal(0, info[0]['paused']) + + call timer_pause(id, 1) + let info = timer_info(id) + call assert_equal(1, info[0]['paused']) + sleep 100m + call assert_equal(0, g:val) + + call timer_pause(id, 0) + let info = timer_info(id) + call assert_equal(0, info[0]['paused']) + + let slept = WaitFor('g:val == 1') + call assert_equal(1, g:val) + if has('reltime') + if has('mac') + " The travis Mac machines appear to be very busy. + call assert_inrange(0, 50, slept) + else + call assert_inrange(0, 30, slept) + endif + else + call assert_inrange(0, 10, slept) + endif +endfunc + +func StopMyself(timer) + let g:called += 1 + if g:called == 2 + call timer_stop(a:timer) + endif +endfunc + +func Test_delete_myself() + let g:called = 0 + let t = timer_start(10, 'StopMyself', {'repeat': -1}) + call WaitForAssert({-> assert_equal(2, g:called)}) + call assert_equal(2, g:called) + call assert_equal([], timer_info(t)) +endfunc + +func StopTimer1(timer) + let g:timer2 = timer_start(10, 'StopTimer2') + " avoid maxfuncdepth error + call timer_pause(g:timer1, 1) + sleep 40m +endfunc + +func StopTimer2(timer) + call timer_stop(g:timer1) +endfunc + +func Test_stop_in_callback() + let g:timer1 = timer_start(10, 'StopTimer1') + sleep 40m +endfunc + +func StopTimerAll(timer) + call timer_stopall() +endfunc + +func Test_stop_all_in_callback() + let g:timer1 = timer_start(10, 'StopTimerAll') + let info = timer_info() + call assert_equal(1, len(info)) + sleep 40m + let info = timer_info() + call assert_equal(0, len(info)) +endfunc + +func FeedkeysCb(timer) + call feedkeys("hello\<CR>", 'nt') +endfunc + +func InputCb(timer) + call timer_start(10, 'FeedkeysCb') + let g:val = input('?') + call Resume() +endfunc + +func Test_input_in_timer() + let g:val = '' + call timer_start(10, 'InputCb') + call Standby(1000) + call assert_equal('hello', g:val) +endfunc + +func FuncWithError(timer) + let g:call_count += 1 + if g:call_count == 4 + return + endif + doesnotexist +endfunc + +func Test_timer_errors() + let g:call_count = 0 + let timer = timer_start(10, 'FuncWithError', {'repeat': -1}) + " Timer will be stopped after failing 3 out of 3 times. + call WaitForAssert({-> assert_equal(3, g:call_count)}) + sleep 50m + call assert_equal(3, g:call_count) +endfunc + +func FuncWithCaughtError(timer) + let g:call_count += 1 + try + doesnotexist + catch + " nop + endtry +endfunc + +func Test_timer_catch_error() + let g:call_count = 0 + let timer = timer_start(10, 'FuncWithCaughtError', {'repeat': 4}) + " Timer will not be stopped. + call WaitForAssert({-> assert_equal(4, g:call_count)}) + sleep 50m + call assert_equal(4, g:call_count) +endfunc + +func FeedAndPeek(timer) + call test_feedinput('a') + call getchar(1) +endfunc + +func Interrupt(timer) + call test_feedinput("\<C-C>") +endfunc + +func Test_peek_and_get_char() + if !has('unix') && !has('gui_running') + return + endif + call timer_start(0, 'FeedAndPeek') + let intr = timer_start(100, 'Interrupt') + let c = getchar() + call assert_equal(char2nr('a'), c) + call timer_stop(intr) +endfunc + +func Test_getchar_zero() + if has('win32') && !has('gui_running') + " Console: no low-level input + return + endif + + " Measure the elapsed time to avoid a hang when it fails. + let start = reltime() + let id = timer_start(20, {-> feedkeys('x', 'L')}) + let c = 0 + while c == 0 && reltimefloat(reltime(start)) < 0.2 + let c = getchar(0) + sleep 10m + endwhile + call assert_equal('x', nr2char(c)) + call timer_stop(id) +endfunc + +func Test_ex_mode() + " Function with an empty line. + func Foo(...) + + endfunc + let timer = timer_start(40, function('g:Foo'), {'repeat':-1}) + " This used to throw error E749. + exe "normal Qsleep 100m\rvi\r" + call timer_stop(timer) +endfunc + +func Test_restore_count() + if !CanRunVimInTerminal() + return + endif + " Check that v:count is saved and restored, not changed by a timer. + call writefile([ + \ 'nnoremap <expr><silent> L v:count ? v:count . "l" : "l"', + \ 'func Doit(id)', + \ ' normal 3j', + \ 'endfunc', + \ 'call timer_start(100, "Doit")', + \ ], 'Xtrcscript') + call writefile([ + \ '1-1234', + \ '2-1234', + \ '3-1234', + \ ], 'Xtrctext') + let buf = RunVimInTerminal('-S Xtrcscript Xtrctext', {}) + + " Wait for the timer to move the cursor to the third line. + call WaitForAssert({-> assert_equal(3, term_getcursor(buf)[0])}) + call assert_equal(1, term_getcursor(buf)[1]) + " Now check that v:count has not been set to 3 + call term_sendkeys(buf, 'L') + call WaitForAssert({-> assert_equal(2, term_getcursor(buf)[1])}) + + call StopVimInTerminal(buf) + call delete('Xtrcscript') + call delete('Xtrctext') +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_true_false.vim b/src/testdir/test_true_false.vim new file mode 100644 index 0000000..a23f2cc --- /dev/null +++ b/src/testdir/test_true_false.vim @@ -0,0 +1,150 @@ +" Test behavior of boolean-like values. + +" Test what is explained at ":help TRUE" and ":help FALSE". +func Test_if() + if v:false + call assert_true(false, 'v:false is false') + endif + if 0 + call assert_true(false, 'zero is false') + endif + if "0" + call assert_true(false, 'zero string is false') + endif + if "foo" + call assert_true(false, 'foo is false') + endif + if " " + call assert_true(false, 'space is false') + endif + if empty("foo") + call assert_true(false, 'foo is not empty') + endif + + if v:true + else + call assert_true(false, 'v:true is true') + endif + if 1 + else + call assert_true(false, 'one is true') + endif + if "1" + else + call assert_true(false, 'one string is true') + endif + if "1foo" + else + call assert_true(false, 'one in string is true') + endif + + call assert_fails('if [1]', 'E745') + call assert_fails('if {1: 1}', 'E728') + call assert_fails('if function("string")', 'E703') + call assert_fails('if 1.3")', 'E805') +endfunc + +function Try_arg_true_false(expr, false_val, true_val) + for v in ['v:false', '0', '"0"', '"foo"', '" "'] + let r = eval(substitute(a:expr, '%v%', v, '')) + call assert_equal(a:false_val, r, 'result for ' . v . ' is not ' . string(a:false_val) . ' but ' . string(r)) + endfor + for v in ['v:true', '1', '"1"', '"1foo"'] + let r = eval(substitute(a:expr, '%v%', v, '')) + call assert_equal(a:true_val, r, 'result for ' . v . ' is not ' . string(a:true_val) . ' but ' . string(r)) + endfor +endfunc + +" Test using TRUE or FALSE values for an argument. +func Test_true_false_arg() + call Try_arg_true_false('count(["a", "A"], "a", %v%)', 1, 2) + + set wildignore=*.swp + call Try_arg_true_false('expand("foo.swp", %v%)', "", "foo.swp") + call Try_arg_true_false('expand("foo.vim", 0, %v%)', "foo.vim", ["foo.vim"]) + + call setreg('a', ['x', 'y']) + call Try_arg_true_false('getreg("a", 1, %v%)', "x\ny\n", ['x', 'y']) + + set wildignore=*.vim + call Try_arg_true_false('glob("runtest.vim", %v%)', "", "runtest.vim") + set wildignore=*.swp + call Try_arg_true_false('glob("runtest.vim", 0, %v%)', "runtest.vim", ["runtest.vim"]) + if has('unix') + silent !ln -s doesntexit Xlink + call Try_arg_true_false('glob("Xlink", 0, 0, %v%)', "", "Xlink") + silent !rm Xlink + endif + + set wildignore=*.vim + call Try_arg_true_false('globpath(".", "runtest.vim", %v%)', "", "./runtest.vim") + set wildignore=*.swp + call Try_arg_true_false('globpath(".", "runtest.vim", 0, %v%)', "./runtest.vim", ["./runtest.vim"]) + if has('unix') + silent !ln -s doesntexit Xlink + call Try_arg_true_false('globpath(".", "Xlink", 0, 0, %v%)', "", "./Xlink") + silent !rm Xlink + endif + + abbr asdf asdff + call Try_arg_true_false('hasmapto("asdff", "i", %v%)', 0, 1) + + call Try_arg_true_false('index(["a", "A"], "A", 0, %v%)', 1, 0) + + function FilterMapArg(d) + if type(a:d) == type({}) + return filter(a:d, 'v:key == "rhs"') + endif + return a:d + endfunction + call Try_arg_true_false('maparg("asdf", "i", %v%)', "", "asdff") + call Try_arg_true_false('FilterMapArg(maparg("asdf", "i", 1, %v%))', "asdff", {'rhs': 'asdff'}) + + call Try_arg_true_false('hasmapto("asdf", "i", %v%)', 0, 1) + + new colored + call setline(1, '<here>') + syn match brackets "<.*>" + syn match here "here" transparent + let brackets_id = synID(1, 1, 0) + let here_id = synID(1, 3, 0) + call Try_arg_true_false('synID(1, 3, %v%)', here_id, brackets_id) + bwipe! +endfunc + +function Try_arg_non_zero(expr, false_val, true_val) + for v in ['v:false', '0', '[1]', '{2:3}', '3.4'] + let r = eval(substitute(a:expr, '%v%', v, '')) + call assert_equal(a:false_val, r, 'result for ' . v . ' is not ' . a:false_val . ' but ' . r) + endfor + for v in ['v:true', '1', '" "', '"0"'] + let r = eval(substitute(a:expr, '%v%', v, '')) + call assert_equal(a:true_val, r, 'result for ' . v . ' is not ' . a:true_val . ' but ' . r) + endfor +endfunc + + +" Test using non-zero-arg for an argument. +func Test_non_zero_arg() + call test_settime(93784) + call Try_arg_non_zero("mode(%v%)", 'x', 'x!') + call test_settime(0) + + call Try_arg_non_zero("shellescape('foo%', %v%)", "'foo%'", "'foo\\%'") + + " visualmode() needs to be called twice to check + for v in [v:false, 0, [1], {2:3}, 3.4] + normal vv + let r = visualmode(v) + call assert_equal('v', r, 'result for ' . string(v) . ' is not "v" but ' . r) + let r = visualmode(v) + call assert_equal('v', r, 'result for ' . string(v) . ' is not "v" but ' . r) + endfor + for v in [v:true, 1, " ", "0"] + normal vv + let r = visualmode(v) + call assert_equal('v', r, 'result for ' . v . ' is not "v" but ' . r) + let r = visualmode(v) + call assert_equal('', r, 'result for ' . v . ' is not "" but ' . r) + endfor +endfunc diff --git a/src/testdir/test_undo.vim b/src/testdir/test_undo.vim new file mode 100644 index 0000000..7c93e23 --- /dev/null +++ b/src/testdir/test_undo.vim @@ -0,0 +1,444 @@ +" Tests for the undo tree. +" Since this script is sourced we need to explicitly break changes up in +" undo-able pieces. Do that by setting 'undolevels'. +" Also tests :earlier and :later. + +func Test_undotree() + new + + normal! Aabc + set ul=100 + let d = undotree() + call assert_equal(1, d.seq_last) + call assert_equal(1, d.seq_cur) + call assert_equal(0, d.save_last) + call assert_equal(0, d.save_cur) + call assert_equal(1, len(d.entries)) + call assert_equal(1, d.entries[0].newhead) + call assert_equal(1, d.entries[0].seq) + call assert_true(d.entries[0].time <= d.time_cur) + + normal! Adef + set ul=100 + let d = undotree() + call assert_equal(2, d.seq_last) + call assert_equal(2, d.seq_cur) + call assert_equal(0, d.save_last) + call assert_equal(0, d.save_cur) + call assert_equal(2, len(d.entries)) + call assert_equal(1, d.entries[0].seq) + call assert_equal(1, d.entries[1].newhead) + call assert_equal(2, d.entries[1].seq) + call assert_true(d.entries[1].time <= d.time_cur) + + undo + set ul=100 + let d = undotree() + call assert_equal(2, d.seq_last) + call assert_equal(1, d.seq_cur) + call assert_equal(0, d.save_last) + call assert_equal(0, d.save_cur) + call assert_equal(2, len(d.entries)) + call assert_equal(1, d.entries[0].seq) + call assert_equal(1, d.entries[1].curhead) + call assert_equal(1, d.entries[1].newhead) + call assert_equal(2, d.entries[1].seq) + call assert_true(d.entries[1].time == d.time_cur) + + normal! Aghi + set ul=100 + let d = undotree() + call assert_equal(3, d.seq_last) + call assert_equal(3, d.seq_cur) + call assert_equal(0, d.save_last) + call assert_equal(0, d.save_cur) + call assert_equal(2, len(d.entries)) + call assert_equal(1, d.entries[0].seq) + call assert_equal(2, d.entries[1].alt[0].seq) + call assert_equal(1, d.entries[1].newhead) + call assert_equal(3, d.entries[1].seq) + call assert_true(d.entries[1].time <= d.time_cur) + + undo + set ul=100 + let d = undotree() + call assert_equal(3, d.seq_last) + call assert_equal(1, d.seq_cur) + call assert_equal(0, d.save_last) + call assert_equal(0, d.save_cur) + call assert_equal(2, len(d.entries)) + call assert_equal(1, d.entries[0].seq) + call assert_equal(2, d.entries[1].alt[0].seq) + call assert_equal(1, d.entries[1].curhead) + call assert_equal(1, d.entries[1].newhead) + call assert_equal(3, d.entries[1].seq) + call assert_true(d.entries[1].time == d.time_cur) + + w! Xtest + let d = undotree() + call assert_equal(1, d.save_cur) + call assert_equal(1, d.save_last) + call delete('Xtest') + bwipe! Xtest +endfunc + +func FillBuffer() + for i in range(1,13) + put=i + " Set 'undolevels' to split undo. + exe "setg ul=" . &g:ul + endfor +endfunc + +func Test_global_local_undolevels() + new one + set undolevels=5 + call FillBuffer() + " will only undo the last 5 changes, end up with 13 - (5 + 1) = 7 lines + earlier 10 + call assert_equal(5, &g:undolevels) + call assert_equal(-123456, &l:undolevels) + call assert_equal('7', getline('$')) + + new two + setlocal undolevels=2 + call FillBuffer() + " will only undo the last 2 changes, end up with 13 - (2 + 1) = 10 lines + earlier 10 + call assert_equal(5, &g:undolevels) + call assert_equal(2, &l:undolevels) + call assert_equal('10', getline('$')) + + setlocal ul=10 + call assert_equal(5, &g:undolevels) + call assert_equal(10, &l:undolevels) + + " Setting local value in "two" must not change local value in "one" + wincmd p + call assert_equal(5, &g:undolevels) + call assert_equal(-123456, &l:undolevels) + + new three + setglobal ul=50 + call assert_equal(50, &g:undolevels) + call assert_equal(-123456, &l:undolevels) + + " Drop created windows + set ul& + new + only! +endfunc + +func BackOne(expected) + call feedkeys('g-', 'xt') + call assert_equal(a:expected, getline(1)) +endfunc + +func Test_undo_del_chars() + " Setup a buffer without creating undo entries + new + set ul=-1 + call setline(1, ['123-456']) + set ul=100 + 1 + call test_settime(100) + + " Delete three characters and undo with g- + call feedkeys('x', 'xt') + call feedkeys('x', 'xt') + call feedkeys('x', 'xt') + call assert_equal('-456', getline(1)) + call BackOne('3-456') + call BackOne('23-456') + call BackOne('123-456') + call assert_fails("BackOne('123-456')") + + :" Delete three other characters and go back in time with g- + call feedkeys('$x', 'xt') + call feedkeys('x', 'xt') + call feedkeys('x', 'xt') + call assert_equal('123-', getline(1)) + call test_settime(101) + + call BackOne('123-4') + call BackOne('123-45') + " skips '123-456' because it's older + call BackOne('-456') + call BackOne('3-456') + call BackOne('23-456') + call BackOne('123-456') + call assert_fails("BackOne('123-456')") + normal 10g+ + call assert_equal('123-', getline(1)) + + :" Jump two seconds and go some seconds forward and backward + call test_settime(103) + call feedkeys("Aa\<Esc>", 'xt') + call feedkeys("Ab\<Esc>", 'xt') + call feedkeys("Ac\<Esc>", 'xt') + call assert_equal('123-abc', getline(1)) + earlier 1s + call assert_equal('123-', getline(1)) + earlier 3s + call assert_equal('123-456', getline(1)) + later 1s + call assert_equal('123-', getline(1)) + later 1h + call assert_equal('123-abc', getline(1)) + + close! +endfunc + +func Test_undolist() + new + set ul=100 + + let a = execute('undolist') + call assert_equal("\nNothing to undo", a) + + " 1 leaf (2 changes). + call feedkeys('achange1', 'xt') + call feedkeys('achange2', 'xt') + let a = execute('undolist') + call assert_match("^\nnumber changes when *saved\n *2 *2 .*$", a) + + " 2 leaves. + call feedkeys('u', 'xt') + call feedkeys('achange3\<Esc>', 'xt') + let a = execute('undolist') + call assert_match("^\nnumber changes when *saved\n *2 *2 *.*\n *3 *2 .*$", a) + close! +endfunc + +func Test_U_command() + new + set ul=100 + call feedkeys("achange1\<Esc>", 'xt') + call feedkeys("achange2\<Esc>", 'xt') + norm! U + call assert_equal('', getline(1)) + norm! U + call assert_equal('change1change2', getline(1)) + close! +endfunc + +func Test_undojoin() + new + call feedkeys("Goaaaa\<Esc>", 'xt') + call feedkeys("obbbb\<Esc>", 'xt') + call assert_equal(['aaaa', 'bbbb'], getline(2, '$')) + call feedkeys("u", 'xt') + call assert_equal(['aaaa'], getline(2, '$')) + call feedkeys("obbbb\<Esc>", 'xt') + undojoin + " Note: next change must not be as if typed + call feedkeys("occcc\<Esc>", 'x') + call assert_equal(['aaaa', 'bbbb', 'cccc'], getline(2, '$')) + call feedkeys("u", 'xt') + call assert_equal(['aaaa'], getline(2, '$')) + bwipe! +endfunc + +func Test_undojoin_redo() + new + call setline(1, ['first line', 'second line']) + call feedkeys("ixx\<Esc>", 'xt') + call feedkeys(":undojoin | redo\<CR>", 'xt') + call assert_equal('xxfirst line', getline(1)) + call assert_equal('second line', getline(2)) + bwipe! +endfunc + +func Test_undo_write() + call delete('Xtest') + split Xtest + call feedkeys("ione one one\<Esc>", 'xt') + w! + call feedkeys("otwo\<Esc>", 'xt') + call feedkeys("otwo\<Esc>", 'xt') + w + call feedkeys("othree\<Esc>", 'xt') + call assert_equal(['one one one', 'two', 'two', 'three'], getline(1, '$')) + earlier 1f + call assert_equal(['one one one', 'two', 'two'], getline(1, '$')) + earlier 1f + call assert_equal(['one one one'], getline(1, '$')) + earlier 1f + call assert_equal([''], getline(1, '$')) + later 1f + call assert_equal(['one one one'], getline(1, '$')) + later 1f + call assert_equal(['one one one', 'two', 'two'], getline(1, '$')) + later 1f + call assert_equal(['one one one', 'two', 'two', 'three'], getline(1, '$')) + + close! + call delete('Xtest') + bwipe! Xtest +endfunc + +func Test_insert_expr() + new + " calling setline() triggers undo sync + call feedkeys("oa\<Esc>", 'xt') + call feedkeys("ob\<Esc>", 'xt') + set ul=100 + call feedkeys("o1\<Esc>a2\<C-R>=setline('.','1234')\<CR>\<CR>\<Esc>", 'x') + call assert_equal(['a', 'b', '120', '34'], getline(2, '$')) + call feedkeys("u", 'x') + call assert_equal(['a', 'b', '12'], getline(2, '$')) + call feedkeys("u", 'x') + call assert_equal(['a', 'b'], getline(2, '$')) + + call feedkeys("oc\<Esc>", 'xt') + set ul=100 + call feedkeys("o1\<Esc>a2\<C-R>=setline('.','1234')\<CR>\<CR>\<Esc>", 'x') + call assert_equal(['a', 'b', 'c', '120', '34'], getline(2, '$')) + call feedkeys("u", 'x') + call assert_equal(['a', 'b', 'c', '12'], getline(2, '$')) + + call feedkeys("od\<Esc>", 'xt') + set ul=100 + call feedkeys("o1\<Esc>a2\<C-R>=string(123)\<CR>\<Esc>", 'x') + call assert_equal(['a', 'b', 'c', '12', 'd', '12123'], getline(2, '$')) + call feedkeys("u", 'x') + call assert_equal(['a', 'b', 'c', '12', 'd'], getline(2, '$')) + + close! +endfunc + +func Test_undofile_earlier() + " Issue #1254 + " create undofile with timestamps older than Vim startup time. + let t0 = localtime() - 43200 + call test_settime(t0) + new Xfile + call feedkeys("ione\<Esc>", 'xt') + set ul=100 + call test_settime(t0 + 1) + call feedkeys("otwo\<Esc>", 'xt') + set ul=100 + call test_settime(t0 + 2) + call feedkeys("othree\<Esc>", 'xt') + set ul=100 + w + wundo Xundofile + bwipe! + " restore normal timestamps. + call test_settime(0) + new Xfile + rundo Xundofile + earlier 1d + call assert_equal('', getline(1)) + bwipe! + call delete('Xfile') + call delete('Xundofile') +endfunc + +" Test for undo working properly when executing commands from a register. +" Also test this in an empty buffer. +func Test_cmd_in_reg_undo() + enew! + let @a = "Ox\<Esc>jAy\<Esc>kdd" + edit +/^$ test_undo.vim + normal @au + call assert_equal(0, &modified) + return + new + normal @au + call assert_equal(0, &modified) + only! + let @a = '' +endfunc + +" This used to cause an illegal memory access +func Test_undo_append() + new + call feedkeys("axx\<Esc>v", 'xt') + undo + norm o + quit +endfunc + +func Test_undo_0() + new + set ul=100 + normal i1 + undo + normal i2 + undo + normal i3 + + undo 0 + let d = undotree() + call assert_equal('', getline(1)) + call assert_equal(0, d.seq_cur) + + redo + let d = undotree() + call assert_equal('3', getline(1)) + call assert_equal(3, d.seq_cur) + + undo 2 + undo 0 + let d = undotree() + call assert_equal('', getline(1)) + call assert_equal(0, d.seq_cur) + + redo + let d = undotree() + call assert_equal('2', getline(1)) + call assert_equal(2, d.seq_cur) + + undo 1 + undo 0 + let d = undotree() + call assert_equal('', getline(1)) + call assert_equal(0, d.seq_cur) + + redo + let d = undotree() + call assert_equal('1', getline(1)) + call assert_equal(1, d.seq_cur) + + bwipe! +endfunc + +func Test_redo_empty_line() + new + exe "norm\x16r\x160" + exe "norm." + bwipe! +endfunc + +funct Test_undofile() + " Test undofile() without setting 'undodir'. + if has('persistent_undo') + call assert_equal(fnamemodify('.Xundofoo.un~', ':p'), undofile('Xundofoo')) + else + call assert_equal('', undofile('Xundofoo')) + endif + call assert_equal('', undofile('')) + + " Test undofile() with 'undodir' set to to an existing directory. + call mkdir('Xundodir') + set undodir=Xundodir + let cwd = getcwd() + if has('win32') + " Replace windows drive such as C:... into C%... + let cwd = substitute(cwd, '^\([a-zA-Z]\):', '\1%', 'g') + endif + let cwd = substitute(cwd . '/Xundofoo', '/', '%', 'g') + if has('persistent_undo') + call assert_equal('Xundodir/' . cwd, undofile('Xundofoo')) + else + call assert_equal('', undofile('Xundofoo')) + endif + call assert_equal('', undofile('')) + call delete('Xundodir', 'd') + + " Test undofile() with 'undodir' set to a non-existing directory. + call assert_equal('', undofile('Xundofoo')) + + set undodir& +endfunc diff --git a/src/testdir/test_unlet.vim b/src/testdir/test_unlet.vim new file mode 100644 index 0000000..0a9f3c6 --- /dev/null +++ b/src/testdir/test_unlet.vim @@ -0,0 +1,57 @@ +" Tests for :unlet + +func Test_read_only() + " these caused a crash + call assert_fails('unlet count', 'E795:') + call assert_fails('unlet errmsg', 'E795:') +endfunc + +func Test_existing() + let does_exist = 1 + call assert_true(exists('does_exist')) + unlet does_exist + call assert_false(exists('does_exist')) +endfunc + +func Test_not_existing() + unlet! does_not_exist + call assert_fails('unlet does_not_exist', 'E108:') +endfunc + +func Test_unlet_fails() + call assert_fails('unlet v:["count"]', 'E46:') +endfunc + +func Test_unlet_env() + let envcmd = has('win32') ? 'set' : 'env' + + let $FOOBAR = 'test' + let found = 0 + for kv in split(system(envcmd), "\r*\n") + if kv == 'FOOBAR=test' + let found = 1 + endif + endfor + call assert_equal(1, found) + + unlet $FOOBAR + let found = 0 + for kv in split(system(envcmd), "\r*\n") + if kv == 'FOOBAR=test' + let found = 1 + endif + endfor + call assert_equal(0, found) + + unlet $MUST_NOT_BE_AN_ERROR +endfunc + +func Test_unlet_complete() + let g:FOOBAR = 1 + call feedkeys(":unlet g:FOO\t\n", 'tx') + call assert_true(!exists('g:FOOBAR')) + + let $FOOBAR = 1 + call feedkeys(":unlet $FOO\t\n", 'tx') + call assert_true(!exists('$FOOBAR') || empty($FOOBAR)) +endfunc diff --git a/src/testdir/test_user_func.vim b/src/testdir/test_user_func.vim new file mode 100644 index 0000000..e7a3701 --- /dev/null +++ b/src/testdir/test_user_func.vim @@ -0,0 +1,96 @@ +" Test for user functions. +" Also test an <expr> mapping calling a function. +" Also test that a builtin function cannot be replaced. +" Also test for regression when calling arbitrary expression. + +func Table(title, ...) + let ret = a:title + let idx = 1 + while idx <= a:0 + exe "let ret = ret . a:" . idx + let idx = idx + 1 + endwhile + return ret +endfunc + +func Compute(n1, n2, divname) + if a:n2 == 0 + return "fail" + endif + exe "let g:" . a:divname . " = ". a:n1 / a:n2 + return "ok" +endfunc + +func Expr1() + silent! normal! v + return "111" +endfunc + +func Expr2() + call search('XX', 'b') + return "222" +endfunc + +func ListItem() + let g:counter += 1 + return g:counter . '. ' +endfunc + +func ListReset() + let g:counter = 0 + return '' +endfunc + +func FuncWithRef(a) + unlet g:FuncRef + return a:a +endfunc + +func Test_user_func() + let g:FuncRef=function("FuncWithRef") + let g:counter = 0 + inoremap <expr> ( ListItem() + inoremap <expr> [ ListReset() + imap <expr> + Expr1() + imap <expr> * Expr2() + let g:retval = "nop" + + call assert_equal('xxx4asdf', Table("xxx", 4, "asdf")) + call assert_equal('fail', Compute(45, 0, "retval")) + call assert_equal('nop', g:retval) + call assert_equal('ok', Compute(45, 5, "retval")) + call assert_equal(9, g:retval) + call assert_equal(333, g:FuncRef(333)) + + enew + + normal oXX+-XX + call assert_equal('XX111-XX', getline('.')) + normal o---*--- + call assert_equal('---222---', getline('.')) + normal o(one + call assert_equal('1. one', getline('.')) + normal o(two + call assert_equal('2. two', getline('.')) + normal o[(one again + call assert_equal('1. one again', getline('.')) + + call assert_equal(3, max([1, 2, 3])) + call assert_fails("call extend(g:, {'max': function('min')})", 'E704') + call assert_equal(3, max([1, 2, 3])) + + " Regression: the first line below used to throw ?E110: Missing ')'? + " Second is here just to prove that this line is correct when not skipping + " rhs of &&. + call assert_equal(0, (0 && (function('tr'))(1, 2, 3))) + call assert_equal(1, (1 && (function('tr'))(1, 2, 3))) + + delfunc Table + delfunc Compute + delfunc Expr1 + delfunc Expr2 + delfunc ListItem + delfunc ListReset + unlet g:retval g:counter + enew! +endfunc diff --git a/src/testdir/test_usercommands.vim b/src/testdir/test_usercommands.vim new file mode 100644 index 0000000..06b0a67 --- /dev/null +++ b/src/testdir/test_usercommands.vim @@ -0,0 +1,306 @@ +" Tests for user defined commands + +" Test for <mods> in user defined commands +function Test_cmdmods() + let g:mods = '' + + command! -nargs=* MyCmd let g:mods .= '<mods> ' + + MyCmd + aboveleft MyCmd + abo MyCmd + belowright MyCmd + bel MyCmd + botright MyCmd + bo MyCmd + browse MyCmd + bro MyCmd + confirm MyCmd + conf MyCmd + hide MyCmd + hid MyCmd + keepalt MyCmd + keepa MyCmd + keepjumps MyCmd + keepj MyCmd + keepmarks MyCmd + kee MyCmd + keeppatterns MyCmd + keepp MyCmd + leftabove MyCmd " results in :aboveleft + lefta MyCmd + lockmarks MyCmd + loc MyCmd + " noautocmd MyCmd + noswapfile MyCmd + nos MyCmd + rightbelow MyCmd " results in :belowright + rightb MyCmd + " sandbox MyCmd + silent MyCmd + sil MyCmd + tab MyCmd + topleft MyCmd + to MyCmd + " unsilent MyCmd + verbose MyCmd + verb MyCmd + vertical MyCmd + vert MyCmd + + aboveleft belowright botright browse confirm hide keepalt keepjumps + \ keepmarks keeppatterns lockmarks noswapfile silent tab + \ topleft verbose vertical MyCmd + + call assert_equal(' aboveleft aboveleft belowright belowright botright ' . + \ 'botright browse browse confirm confirm hide hide ' . + \ 'keepalt keepalt keepjumps keepjumps keepmarks keepmarks ' . + \ 'keeppatterns keeppatterns aboveleft aboveleft lockmarks lockmarks noswapfile ' . + \ 'noswapfile belowright belowright silent silent tab topleft topleft verbose verbose ' . + \ 'vertical vertical ' . + \ 'aboveleft belowright botright browse confirm hide keepalt keepjumps ' . + \ 'keepmarks keeppatterns lockmarks noswapfile silent tab topleft ' . + \ 'verbose vertical ', g:mods) + + let g:mods = '' + command! -nargs=* MyQCmd let g:mods .= '<q-mods> ' + + vertical MyQCmd + call assert_equal('"vertical" ', g:mods) + + delcommand MyCmd + delcommand MyQCmd + unlet g:mods +endfunction + +func Test_Ambiguous() + command Doit let g:didit = 'yes' + command Dothat let g:didthat = 'also' + call assert_fails('Do', 'E464:') + Doit + call assert_equal('yes', g:didit) + Dothat + call assert_equal('also', g:didthat) + unlet g:didit + unlet g:didthat + + delcommand Doit + Do + call assert_equal('also', g:didthat) + delcommand Dothat +endfunc + +func Test_redefine_on_reload() + call writefile(['command ExistingCommand echo "yes"'], 'Xcommandexists') + call assert_equal(0, exists(':ExistingCommand')) + source Xcommandexists + call assert_equal(2, exists(':ExistingCommand')) + " Redefining a command when reloading a script is OK. + source Xcommandexists + call assert_equal(2, exists(':ExistingCommand')) + + " But redefining in another script is not OK. + call writefile(['command ExistingCommand echo "yes"'], 'Xcommandexists2') + call assert_fails('source Xcommandexists2', 'E174:') + call delete('Xcommandexists2') + + " And defining twice in one script is not OK. + delcommand ExistingCommand + call assert_equal(0, exists(':ExistingCommand')) + call writefile([ + \ 'command ExistingCommand echo "yes"', + \ 'command ExistingCommand echo "no"', + \ ], 'Xcommandexists') + call assert_fails('source Xcommandexists', 'E174:') + call assert_equal(2, exists(':ExistingCommand')) + + call delete('Xcommandexists') + delcommand ExistingCommand +endfunc + +func Test_CmdUndefined() + call assert_fails('Doit', 'E492:') + au CmdUndefined Doit :command Doit let g:didit = 'yes' + Doit + call assert_equal('yes', g:didit) + delcommand Doit + + call assert_fails('Dothat', 'E492:') + au CmdUndefined * let g:didnot = 'yes' + call assert_fails('Dothat', 'E492:') + call assert_equal('yes', g:didnot) +endfunc + +func Test_CmdErrors() + call assert_fails('com! docmd :', 'E183:') + call assert_fails('com! \<Tab> :', 'E182:') + call assert_fails('com! _ :', 'E182:') + call assert_fails('com! X :', 'E841:') + call assert_fails('com! - DoCmd :', 'E175:') + call assert_fails('com! -xxx DoCmd :', 'E181:') + call assert_fails('com! -addr DoCmd :', 'E179:') + call assert_fails('com! -complete DoCmd :', 'E179:') + call assert_fails('com! -complete=xxx DoCmd :', 'E180:') + call assert_fails('com! -complete=custom DoCmd :', 'E467:') + call assert_fails('com! -complete=customlist DoCmd :', 'E467:') + call assert_fails('com! -complete=behave,CustomComplete DoCmd :', 'E468:') + call assert_fails('com! -nargs=x DoCmd :', 'E176:') + call assert_fails('com! -count=1 -count=2 DoCmd :', 'E177:') + call assert_fails('com! -count=x DoCmd :', 'E178:') + call assert_fails('com! -range=x DoCmd :', 'E178:') + + com! -nargs=0 DoCmd : + call assert_fails('DoCmd x', 'E488:') + + com! -nargs=1 DoCmd : + call assert_fails('DoCmd', 'E471:') + + com! -nargs=+ DoCmd : + call assert_fails('DoCmd', 'E471:') + + call assert_fails('com DoCmd :', 'E174:') + comclear + call assert_fails('delcom DoCmd', 'E184:') +endfunc + +func CustomComplete(A, L, P) + return "January\nFebruary\nMars\n" +endfunc + +func CustomCompleteList(A, L, P) + return [ "Monday", "Tuesday", "Wednesday" ] +endfunc + +func Test_CmdCompletion() + call feedkeys(":com -\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"com -addr bang bar buffer complete count nargs range register', @:) + + call feedkeys(":com -nargs=0 -\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"com -nargs=0 -addr bang bar buffer complete count nargs range register', @:) + + call feedkeys(":com -nargs=\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"com -nargs=* + 0 1 ?', @:) + + call feedkeys(":com -addr=\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"com -addr=arguments buffers lines loaded_buffers other quickfix tabs windows', @:) + + call feedkeys(":com -complete=co\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"com -complete=color command compiler', @:) + + command! DoCmd1 : + command! DoCmd2 : + call feedkeys(":com \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"com DoCmd1 DoCmd2', @:) + + call feedkeys(":DoC\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"DoCmd1 DoCmd2', @:) + + call feedkeys(":delcom DoC\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"delcom DoCmd1 DoCmd2', @:) + + delcom DoCmd1 + call feedkeys(":delcom DoC\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"delcom DoCmd2', @:) + + call feedkeys(":com DoC\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"com DoCmd2', @:) + + delcom DoCmd2 + call feedkeys(":delcom DoC\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"delcom DoC', @:) + + call feedkeys(":com DoC\<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"com DoC', @:) + + com! -complete=behave DoCmd : + call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"DoCmd mswin xterm', @:) + + " This does not work. Why? + "call feedkeys(":DoCmd x\<C-A>\<C-B>\"\<CR>", 'tx') + "call assert_equal('"DoCmd xterm', @:) + + com! -complete=custom,CustomComplete DoCmd : + call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"DoCmd January February Mars', @:) + + com! -complete=customlist,CustomCompleteList DoCmd : + call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"DoCmd Monday Tuesday Wednesday', @:) + + com! -complete=custom,CustomCompleteList DoCmd : + call assert_fails("call feedkeys(':DoCmd \<C-D>', 'tx')", 'E730:') + + com! -complete=customlist,CustomComp DoCmd : + call assert_fails("call feedkeys(':DoCmd \<C-D>', 'tx')", 'E117:') +endfunc + +func CallExecute(A, L, P) + " Drop first '\n' + return execute('echo "hi"')[1:] +endfunc + +func Test_use_execute_in_completion() + command! -nargs=* -complete=custom,CallExecute DoExec : + call feedkeys(":DoExec \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"DoExec hi', @:) + delcommand DoExec +endfunc + +func Test_addr_all() + command! -addr=lines DoSomething let g:a1 = <line1> | let g:a2 = <line2> + %DoSomething + call assert_equal(1, g:a1) + call assert_equal(line('$'), g:a2) + + command! -addr=arguments DoSomething let g:a1 = <line1> | let g:a2 = <line2> + args one two three + %DoSomething + call assert_equal(1, g:a1) + call assert_equal(3, g:a2) + + command! -addr=buffers DoSomething let g:a1 = <line1> | let g:a2 = <line2> + %DoSomething + for low in range(1, bufnr('$')) + if buflisted(low) + break + endif + endfor + call assert_equal(low, g:a1) + call assert_equal(bufnr('$'), g:a2) + + command! -addr=loaded_buffers DoSomething let g:a1 = <line1> | let g:a2 = <line2> + %DoSomething + for low in range(1, bufnr('$')) + if bufloaded(low) + break + endif + endfor + call assert_equal(low, g:a1) + for up in range(bufnr('$'), 1, -1) + if bufloaded(up) + break + endif + endfor + call assert_equal(up, g:a2) + + command! -addr=windows DoSomething let g:a1 = <line1> | let g:a2 = <line2> + new + %DoSomething + call assert_equal(1, g:a1) + call assert_equal(winnr('$'), g:a2) + bwipe + + command! -addr=tabs DoSomething let g:a1 = <line1> | let g:a2 = <line2> + tabnew + %DoSomething + call assert_equal(1, g:a1) + call assert_equal(len(gettabinfo()), g:a2) + bwipe + + command! -addr=other DoSomething echo 'nothing' + DoSomething + call assert_fails('%DoSomething') + + delcommand DoSomething +endfunc diff --git a/src/testdir/test_utf8.vim b/src/testdir/test_utf8.vim new file mode 100644 index 0000000..8a71f50 --- /dev/null +++ b/src/testdir/test_utf8.vim @@ -0,0 +1,62 @@ +" Tests for Unicode manipulations + + +" Visual block Insert adjusts for multi-byte char +func Test_visual_block_insert() + new + call setline(1, ["aaa", "あああ", "bbb"]) + exe ":norm! gg0l\<C-V>jjIx\<Esc>" + call assert_equal(['axaa', 'xあああ', 'bxbb'], getline(1, '$')) + bwipeout! +endfunc + +" Test for built-in function strchars() +func Test_strchars() + let inp = ["a", "あいa", "A\u20dd", "A\u20dd\u20dd", "\u20dd"] + let exp = [[1, 1, 1], [3, 3, 3], [2, 2, 1], [3, 3, 1], [1, 1, 1]] + for i in range(len(inp)) + call assert_equal(exp[i][0], strchars(inp[i])) + call assert_equal(exp[i][1], strchars(inp[i], 0)) + call assert_equal(exp[i][2], strchars(inp[i], 1)) + endfor +endfunc + +" Test for customlist completion +func CustomComplete1(lead, line, pos) + return ['あ', 'い'] +endfunc + +func CustomComplete2(lead, line, pos) + return ['あたし', 'あたま', 'あたりめ'] +endfunc + +func CustomComplete3(lead, line, pos) + return ['Nこ', 'Nん', 'Nぶ'] +endfunc + +func Test_customlist_completion() + command -nargs=1 -complete=customlist,CustomComplete1 Test1 echo + call feedkeys(":Test1 \<C-L>\<C-B>\"\<CR>", 'itx') + call assert_equal('"Test1 ', getreg(':')) + + command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo + call feedkeys(":Test2 \<C-L>\<C-B>\"\<CR>", 'itx') + call assert_equal('"Test2 あた', getreg(':')) + + command -nargs=1 -complete=customlist,CustomComplete3 Test3 echo + call feedkeys(":Test3 \<C-L>\<C-B>\"\<CR>", 'itx') + call assert_equal('"Test3 N', getreg(':')) + + call garbagecollect(1) +endfunc + +" Yank one 3 byte character and check the mark columns. +func Test_getvcol() + new + call setline(1, "x\u2500x") + normal 0lvy + call assert_equal(2, col("'[")) + call assert_equal(4, col("']")) + call assert_equal(2, virtcol("'[")) + call assert_equal(2, virtcol("']")) +endfunc diff --git a/src/testdir/test_utf8_comparisons.vim b/src/testdir/test_utf8_comparisons.vim new file mode 100644 index 0000000..312925b --- /dev/null +++ b/src/testdir/test_utf8_comparisons.vim @@ -0,0 +1,91 @@ +" Tests for case-insensitive UTF-8 comparisons (utf_strnicmp() in mbyte.c) +" Also test "g~ap". + +func Ch(a, op, b, expected) + call assert_equal(eval(printf('"%s" %s "%s"', a:a, a:op, a:b)), a:expected, + \ printf('"%s" %s "%s" should return %d', a:a, a:op, a:b, a:expected)) +endfunc + +func Chk(a, b, result) + if a:result == 0 + call Ch(a:a, '==?', a:b, 1) + call Ch(a:a, '!=?', a:b, 0) + call Ch(a:a, '<=?', a:b, 1) + call Ch(a:a, '>=?', a:b, 1) + call Ch(a:a, '<?', a:b, 0) + call Ch(a:a, '>?', a:b, 0) + elseif a:result > 0 + call Ch(a:a, '==?', a:b, 0) + call Ch(a:a, '!=?', a:b, 1) + call Ch(a:a, '<=?', a:b, 0) + call Ch(a:a, '>=?', a:b, 1) + call Ch(a:a, '<?', a:b, 0) + call Ch(a:a, '>?', a:b, 1) + else + call Ch(a:a, '==?', a:b, 0) + call Ch(a:a, '!=?', a:b, 1) + call Ch(a:a, '<=?', a:b, 1) + call Ch(a:a, '>=?', a:b, 0) + call Ch(a:a, '<?', a:b, 1) + call Ch(a:a, '>?', a:b, 0) + endif +endfunc + +func Check(a, b, result) + call Chk(a:a, a:b, a:result) + call Chk(a:b, a:a, -a:result) +endfunc + +func LT(a, b) + call Check(a:a, a:b, -1) +endfunc + +func GT(a, b) + call Check(a:a, a:b, 1) +endfunc + +func EQ(a, b) + call Check(a:a, a:b, 0) +endfunc + +func Test_comparisons() + call EQ('', '') + call LT('', 'a') + call EQ('abc', 'abc') + call EQ('Abc', 'abC') + call LT('ab', 'abc') + call LT('AB', 'abc') + call LT('ab', 'aBc') + call EQ('\xd0\xb9\xd1\x86\xd1\x83\xd0\xba\xd0\xb5\xd0\xbd', '\xd0\xb9\xd0\xa6\xd0\xa3\xd0\xba\xd0\x95\xd0\xbd') + call LT('\xd0\xb9\xd1\x86\xd1\x83\xd0\xba\xd0\xb5\xd0\xbd', '\xd0\xaf\xd1\x86\xd1\x83\xd0\xba\xd0\xb5\xd0\xbd') + call EQ('\xe2\x84\xaa', 'k') + call LT('\xe2\x84\xaa', 'kkkkkk') + call EQ('\xe2\x84\xaa\xe2\x84\xaa\xe2\x84\xaa', 'kkk') + call LT('kk', '\xe2\x84\xaa\xe2\x84\xaa\xe2\x84\xaa') + call EQ('\xe2\x84\xaa\xe2\x84\xa6k\xe2\x84\xaak\xcf\x89', 'k\xcf\x89\xe2\x84\xaakk\xe2\x84\xa6') + call EQ('Abc\x80', 'AbC\x80') + call LT('Abc\x80', 'AbC\x81') + call LT('Abc', 'AbC\x80') + call LT('abc\x80DEF', 'abc\x80def') " case folding stops at the first bad character + call LT('\xc3XYZ', '\xc3xyz') + call EQ('\xef\xbc\xba', '\xef\xbd\x9a') " FF3A (upper), FF5A (lower) + call GT('\xef\xbc\xba', '\xef\xbc\xff') " first string is ok and equals \xef\xbd\x9a after folding, second string is illegal and was left unchanged, then the strings were bytewise compared + call LT('\xc3', '\xc3\x83') + call EQ('\xc3\xa3xYz', '\xc3\x83XyZ') + for n in range(0x60, 0xFF) + call LT(printf('xYz\x%.2X', n-1), printf('XyZ\x%.2X', n)) + endfor + for n in range(0x80, 0xBF) + call EQ(printf('xYz\xc2\x%.2XUvW', n), printf('XyZ\xc2\x%.2XuVw', n)) + endfor + for n in range(0xC0, 0xFF) + call LT(printf('xYz\xc2\x%.2XUvW', n), printf('XyZ\xc2\x%.2XuVw', n)) + endfor +endfunc + +" test that g~ap changes one paragraph only. +func Test_gap() + new + call feedkeys("iabcd\n\ndefggg0g~ap", "tx") + call assert_equal(["ABCD", "", "defg"], getline(1,3)) +endfunc diff --git a/src/testdir/test_vartabs.vim b/src/testdir/test_vartabs.vim new file mode 100644 index 0000000..0d14aad --- /dev/null +++ b/src/testdir/test_vartabs.vim @@ -0,0 +1,374 @@ +" Test for variable tabstops + +if !has("vartabs") + finish +endif + +source view_util.vim +func s:compare_lines(expect, actual) + call assert_equal(join(a:expect, "\n"), join(a:actual, "\n")) +endfunc + +func Test_vartabs() + new + %d + + " Test normal operation of tabstops ... + set ts=4 + call setline(1, join(split('aaaaa', '\zs'), "\t")) + retab 8 + let expect = "a a\<tab>a a\<tab>a" + call assert_equal(expect, getline(1)) + + " ... and softtabstops + set ts=8 sts=6 + exe "norm! Sb\<tab>b\<tab>b\<tab>b\<tab>b" + let expect = "b b\<tab> b\<tab> b\<tab>b" + call assert_equal(expect, getline(1)) + + " Test variable tabstops. + set sts=0 vts=4,8,4,8 + exe "norm! Sc\<tab>c\<tab>c\<tab>c\<tab>c\<tab>c" + retab 8 + let expect = "c c\<tab> c\<tab>c\<tab>c\<tab>c" + call assert_equal(expect, getline(1)) + + set et vts=4,8,4,8 + exe "norm! Sd\<tab>d\<tab>d\<tab>d\<tab>d\<tab>d" + let expect = "d d d d d d" + call assert_equal(expect, getline(1)) + + " Changing ts should have no effect if vts is in use. + call cursor(1, 1) + set ts=6 + exe "norm! Se\<tab>e\<tab>e\<tab>e\<tab>e\<tab>e" + let expect = "e e e e e e" + call assert_equal(expect, getline(1)) + + " Clearing vts should revert to using ts. + set vts= + exe "norm! Sf\<tab>f\<tab>f\<tab>f\<tab>f\<tab>f" + let expect = "f f f f f f" + call assert_equal(expect, getline(1)) + + " Test variable softtabstops. + set noet ts=8 vsts=12,2,6 + exe "norm! Sg\<tab>g\<tab>g\<tab>g\<tab>g\<tab>g" + let expect = "g\<tab> g g\<tab> g\<tab> g\<tab>g" + call assert_equal(expect, getline(1)) + + " Variable tabstops and softtabstops combined. + set vsts=6,12,8 vts=4,6,8 + exe "norm! Sh\<tab>h\<tab>h\<tab>h\<tab>h" + let expect = "h\<tab> h\<tab>\<tab>h\<tab>h\<tab>h" + call assert_equal(expect, getline(1)) + + " Retab with a single value, not using vts. + set ts=8 sts=0 vts= vsts= + exe "norm! Si\<tab>i\<tab>i\<tab>i\<tab>i" + retab 4 + let expect = "i\<tab>\<tab>i\<tab>\<tab>i\<tab>\<tab>i\<tab>\<tab>i" + call assert_equal(expect, getline(1)) + + " Retab with a single value, using vts. + set ts=8 sts=0 vts=6 vsts= + exe "norm! Sj\<tab>j\<tab>j\<tab>j\<tab>j" + retab 4 + let expect = "j\<tab> j\<tab>\<tab>j\<tab> j\<tab>\<tab>j" + call assert_equal(expect, getline(1)) + + " Retab with multiple values, not using vts. + set ts=6 sts=0 vts= vsts= + exe "norm! Sk\<tab>k\<tab>k\<tab>k\<tab>k\<tab>k" + retab 4,8 + let expect = "k\<tab> k\<tab>k k\<tab> k\<tab> k" + call assert_equal(expect, getline(1)) + + " Retab with multiple values, using vts. + set ts=8 sts=0 vts=6 vsts= + exe "norm! Sl\<tab>l\<tab>l\<tab>l\<tab>l\<tab>l" + retab 4,8 + let expect = "l\<tab> l\<tab>l l\<tab> l\<tab> l" + call assert_equal(expect, getline(1)) + + " Check that global and local values are set. + set ts=4 vts=6 sts=8 vsts=10 + call assert_equal(&ts, 4) + call assert_equal(&vts, '6') + call assert_equal(&sts, 8) + call assert_equal(&vsts, '10') + new + call assert_equal(&ts, 4) + call assert_equal(&vts, '6') + call assert_equal(&sts, 8) + call assert_equal(&vsts, '10') + bwipeout! + + " Check that local values only are set. + setlocal ts=5 vts=7 sts=9 vsts=11 + call assert_equal(&ts, 5) + call assert_equal(&vts, '7') + call assert_equal(&sts, 9) + call assert_equal(&vsts, '11') + new + call assert_equal(&ts, 4) + call assert_equal(&vts, '6') + call assert_equal(&sts, 8) + call assert_equal(&vsts, '10') + bwipeout! + + " Check that global values only are set. + setglobal ts=6 vts=8 sts=10 vsts=12 + call assert_equal(&ts, 5) + call assert_equal(&vts, '7') + call assert_equal(&sts, 9) + call assert_equal(&vsts, '11') + new + call assert_equal(&ts, 6) + call assert_equal(&vts, '8') + call assert_equal(&sts, 10) + call assert_equal(&vsts, '12') + bwipeout! + + set ts& vts& sts& vsts& et& + bwipeout! +endfunc + +func Test_vartabs_breakindent() + if !exists("+breakindent") + return + endif + new + %d + + " Test normal operation of tabstops ... + set ts=4 + call setline(1, join(split('aaaaa', '\zs'), "\t")) + retab 8 + let expect = "a a\<tab>a a\<tab>a" + call assert_equal(expect, getline(1)) + + " ... and softtabstops + set ts=8 sts=6 + exe "norm! Sb\<tab>b\<tab>b\<tab>b\<tab>b" + let expect = "b b\<tab> b\<tab> b\<tab>b" + call assert_equal(expect, getline(1)) + + " Test variable tabstops. + set sts=0 vts=4,8,4,8 + exe "norm! Sc\<tab>c\<tab>c\<tab>c\<tab>c\<tab>c" + retab 8 + let expect = "c c\<tab> c\<tab>c\<tab>c\<tab>c" + call assert_equal(expect, getline(1)) + + set et vts=4,8,4,8 + exe "norm! Sd\<tab>d\<tab>d\<tab>d\<tab>d\<tab>d" + let expect = "d d d d d d" + call assert_equal(expect, getline(1)) + + " Changing ts should have no effect if vts is in use. + call cursor(1, 1) + set ts=6 + exe "norm! Se\<tab>e\<tab>e\<tab>e\<tab>e\<tab>e" + let expect = "e e e e e e" + call assert_equal(expect, getline(1)) + + " Clearing vts should revert to using ts. + set vts= + exe "norm! Sf\<tab>f\<tab>f\<tab>f\<tab>f\<tab>f" + let expect = "f f f f f f" + call assert_equal(expect, getline(1)) + + " Test variable softtabstops. + set noet ts=8 vsts=12,2,6 + exe "norm! Sg\<tab>g\<tab>g\<tab>g\<tab>g\<tab>g" + let expect = "g\<tab> g g\<tab> g\<tab> g\<tab>g" + call assert_equal(expect, getline(1)) + + " Variable tabstops and softtabstops combined. + set vsts=6,12,8 vts=4,6,8 + exe "norm! Sh\<tab>h\<tab>h\<tab>h\<tab>h" + let expect = "h\<tab> h\<tab>\<tab>h\<tab>h\<tab>h" + call assert_equal(expect, getline(1)) + + " Retab with a single value, not using vts. + set ts=8 sts=0 vts= vsts= + exe "norm! Si\<tab>i\<tab>i\<tab>i\<tab>i" + retab 4 + let expect = "i\<tab>\<tab>i\<tab>\<tab>i\<tab>\<tab>i\<tab>\<tab>i" + call assert_equal(expect, getline(1)) + + " Retab with a single value, using vts. + set ts=8 sts=0 vts=6 vsts= + exe "norm! Sj\<tab>j\<tab>j\<tab>j\<tab>j" + retab 4 + let expect = "j\<tab> j\<tab>\<tab>j\<tab> j\<tab>\<tab>j" + call assert_equal(expect, getline(1)) + + " Retab with multiple values, not using vts. + set ts=6 sts=0 vts= vsts= + exe "norm! Sk\<tab>k\<tab>k\<tab>k\<tab>k\<tab>k" + retab 4,8 + let expect = "k\<tab> k\<tab>k k\<tab> k\<tab> k" + call assert_equal(expect, getline(1)) + + " Retab with multiple values, using vts. + set ts=8 sts=0 vts=6 vsts= + exe "norm! Sl\<tab>l\<tab>l\<tab>l\<tab>l\<tab>l" + retab 4,8 + let expect = "l\<tab> l\<tab>l l\<tab> l\<tab> l" + call assert_equal(expect, getline(1)) + + " Check that global and local values are set. + set ts=4 vts=6 sts=8 vsts=10 + call assert_equal(&ts, 4) + call assert_equal(&vts, '6') + call assert_equal(&sts, 8) + call assert_equal(&vsts, '10') + new + call assert_equal(&ts, 4) + call assert_equal(&vts, '6') + call assert_equal(&sts, 8) + call assert_equal(&vsts, '10') + bwipeout! + + " Check that local values only are set. + setlocal ts=5 vts=7 sts=9 vsts=11 + call assert_equal(&ts, 5) + call assert_equal(&vts, '7') + call assert_equal(&sts, 9) + call assert_equal(&vsts, '11') + new + call assert_equal(&ts, 4) + call assert_equal(&vts, '6') + call assert_equal(&sts, 8) + call assert_equal(&vsts, '10') + bwipeout! + + " Check that global values only are set. + setglobal ts=6 vts=8 sts=10 vsts=12 + call assert_equal(&ts, 5) + call assert_equal(&vts, '7') + call assert_equal(&sts, 9) + call assert_equal(&vsts, '11') + new + call assert_equal(&ts, 6) + call assert_equal(&vts, '8') + call assert_equal(&sts, 10) + call assert_equal(&vsts, '12') + bwipeout! + + bwipeout! +endfunc + +func Test_vartabs_linebreak() + if winwidth(0) < 40 + return + endif + new + 40vnew + %d + setl linebreak vartabstop=10,20,30,40 + call setline(1, "\tx\tx\tx\tx") + + let expect = [' x ', + \ 'x x ', + \ 'x '] + let lines = ScreenLines([1, 3], winwidth(0)) + call s:compare_lines(expect, lines) + setl list listchars=tab:>- + let expect = ['>---------x>------------------ ', + \ 'x>------------------x>------------------', + \ 'x '] + let lines = ScreenLines([1, 3], winwidth(0)) + call s:compare_lines(expect, lines) + setl linebreak vartabstop=40 + let expect = ['>---------------------------------------', + \ 'x>--------------------------------------', + \ 'x>--------------------------------------', + \ 'x>--------------------------------------', + \ 'x '] + let lines = ScreenLines([1, 5], winwidth(0)) + call s:compare_lines(expect, lines) + + " cleanup + bw! + bw! + set nolist listchars&vim +endfunc + +func Test_vartabs_shiftwidth() + "return + if winwidth(0) < 40 + return + endif + new + 40vnew + %d +" setl varsofttabstop=10,20,30,40 + setl shiftwidth=0 vartabstop=10,20,30,40 + call setline(1, "x") + + " Check without any change. + let expect = ['x '] + let lines = ScreenLines(1, winwidth(0)) + call s:compare_lines(expect, lines) + " Test 1: + " shiftwidth depends on the indent, first check with cursor at the end of the + " line (which is the same as the start of the line, since there is only one + " character). + norm! $>> + let expect1 = [' x '] + let lines = ScreenLines(1, winwidth(0)) + call s:compare_lines(expect1, lines) + call assert_equal(10, shiftwidth()) + call assert_equal(10, shiftwidth(1)) + call assert_equal(20, shiftwidth(virtcol('.'))) + norm! $>> + let expect2 = [' x ', '~ '] + let lines = ScreenLines([1, 2], winwidth(0)) + call s:compare_lines(expect2, lines) + call assert_equal(20, shiftwidth(virtcol('.')-2)) + call assert_equal(30, shiftwidth(virtcol('.'))) + norm! $>> + let expect3 = [' ', ' x ', '~ '] + let lines = ScreenLines([1, 3], winwidth(0)) + call s:compare_lines(expect3, lines) + call assert_equal(30, shiftwidth(virtcol('.')-2)) + call assert_equal(40, shiftwidth(virtcol('.'))) + norm! $>> + let expect4 = [' ', ' ', ' x '] + let lines = ScreenLines([1, 3], winwidth(0)) + call assert_equal(40, shiftwidth(virtcol('.'))) + call s:compare_lines(expect4, lines) + + " Test 2: Put the cursor at the first column, result should be the same + call setline(1, "x") + norm! 0>> + let lines = ScreenLines(1, winwidth(0)) + call s:compare_lines(expect1, lines) + norm! 0>> + let lines = ScreenLines([1, 2], winwidth(0)) + call s:compare_lines(expect2, lines) + norm! 0>> + let lines = ScreenLines([1, 3], winwidth(0)) + call s:compare_lines(expect3, lines) + norm! 0>> + let lines = ScreenLines([1, 3], winwidth(0)) + call s:compare_lines(expect4, lines) + + " cleanup + bw! + bw! +endfunc + +func Test_vartabs_failures() + call assert_fails('set vts=8,') + call assert_fails('set vsts=8,') + call assert_fails('set vts=8,,8') + call assert_fails('set vsts=8,,8') + call assert_fails('set vts=8,,8,') + call assert_fails('set vsts=8,,8,') + call assert_fails('set vts=,8') + call assert_fails('set vsts=,8') +endfunc diff --git a/src/testdir/test_viminfo.vim b/src/testdir/test_viminfo.vim new file mode 100644 index 0000000..cea78e5 --- /dev/null +++ b/src/testdir/test_viminfo.vim @@ -0,0 +1,534 @@ +" Test for reading and writing .viminfo + +function Test_viminfo_read_and_write() + call histdel(':') + let lines = [ + \ '# comment line', + \ '*encoding=utf-8', + \ '~MSle0~/asdf', + \ '|copied as-is', + \ '|and one more', + \ ] + call writefile(lines, 'Xviminfo') + rviminfo Xviminfo + call assert_equal('asdf', @/) + + wviminfo Xviminfo + let lines = readfile('Xviminfo') + let done = 0 + for line in lines + if line[0] == '|' && line !~ '^|[234],' && line !~ '^|<' + if done == 0 + call assert_equal('|1,4', line) + elseif done == 1 + call assert_equal('|copied as-is', line) + elseif done == 2 + call assert_equal('|and one more', line) + endif + let done += 1 + endif + endfor + call assert_equal(3, done) + + call delete('Xviminfo') +endfunc + +func Test_global_vars() + let test_dict = {'foo': 1, 'bar': 0, 'longvarible': 1000} + let g:MY_GLOBAL_DICT = test_dict + " store a really long list, so line wrapping will occur in viminfo file + let test_list = range(1,100) + let g:MY_GLOBAL_LIST = test_list + let test_blob = 0z00112233445566778899aabbccddeeff + let g:MY_GLOBAL_BLOB = test_blob + let test_false = v:false + let g:MY_GLOBAL_FALSE = test_false + let test_true = v:true + let g:MY_GLOBAL_TRUE = test_true + let test_null = v:null + let g:MY_GLOBAL_NULL = test_null + let test_none = v:none + let g:MY_GLOBAL_NONE = test_none + + set viminfo='100,<50,s10,h,!,nviminfo + wv! Xviminfo + + unlet g:MY_GLOBAL_DICT + unlet g:MY_GLOBAL_LIST + unlet g:MY_GLOBAL_BLOB + unlet g:MY_GLOBAL_FALSE + unlet g:MY_GLOBAL_TRUE + unlet g:MY_GLOBAL_NULL + unlet g:MY_GLOBAL_NONE + + rv! Xviminfo + call assert_equal(test_dict, g:MY_GLOBAL_DICT) + call assert_equal(test_list, g:MY_GLOBAL_LIST) + call assert_equal(test_blob, g:MY_GLOBAL_BLOB) + call assert_equal(test_false, g:MY_GLOBAL_FALSE) + call assert_equal(test_true, g:MY_GLOBAL_TRUE) + call assert_equal(test_null, g:MY_GLOBAL_NULL) + call assert_equal(test_none, g:MY_GLOBAL_NONE) + + call delete('Xviminfo') + set viminfo-=! +endfunc + +func Test_cmdline_history() + call histdel(':') + call test_settime(11) + call histadd(':', "echo 'one'") + call test_settime(12) + " split into two lines + let long800 = repeat(" 'eight'", 100) + call histadd(':', "echo " . long800) + call test_settime(13) + " split into three lines + let long1400 = repeat(" 'fourteeeeen'", 100) + call histadd(':', "echo " . long1400) + wviminfo Xviminfo + let lines = readfile('Xviminfo') + let done_colon = 0 + let done_bar = 0 + let lnum = 0 + while lnum < len(lines) + let line = lines[lnum] | let lnum += 1 + if line[0] == ':' + if done_colon == 0 + call assert_equal(":\x161408", line) + let line = lines[lnum] | let lnum += 1 + call assert_equal('<echo ' . long1400, line) + elseif done_colon == 1 + call assert_equal(":\x16808", line) + let line = lines[lnum] | let lnum += 1 + call assert_equal("<echo " . long800, line) + elseif done_colon == 2 + call assert_equal(":echo 'one'", line) + endif + let done_colon += 1 + elseif line[0:4] == '|2,0,' + if done_bar == 0 + call assert_equal("|2,0,13,,>1407", line) + let line = lines[lnum] | let lnum += 1 + call assert_equal('|<"echo ' . long1400[0:484], line) + let line = lines[lnum] | let lnum += 1 + call assert_equal('|<' . long1400[485:974], line) + let line = lines[lnum] | let lnum += 1 + call assert_equal('|<' . long1400[975:] . '"', line) + elseif done_bar == 1 + call assert_equal('|2,0,12,,>807', line) + let line = lines[lnum] | let lnum += 1 + call assert_equal('|<"echo ' . long800[0:484], line) + let line = lines[lnum] | let lnum += 1 + call assert_equal('|<' . long800[485:] . '"', line) + elseif done_bar == 2 + call assert_equal("|2,0,11,,\"echo 'one'\"", line) + endif + let done_bar += 1 + endif + endwhile + call assert_equal(3, done_colon) + call assert_equal(3, done_bar) + + call histdel(':') + rviminfo Xviminfo + call assert_equal("echo " . long1400, histget(':', -1)) + call assert_equal("echo " . long800, histget(':', -2)) + call assert_equal("echo 'one'", histget(':', -3)) + + call delete('Xviminfo') +endfunc + +func Test_cmdline_history_order() + call histdel(':') + call test_settime(11) + call histadd(':', "echo '11'") + call test_settime(22) + call histadd(':', "echo '22'") + call test_settime(33) + call histadd(':', "echo '33'") + wviminfo Xviminfo + + call histdel(':') + " items go in between + call test_settime(15) + call histadd(':', "echo '15'") + call test_settime(27) + call histadd(':', "echo '27'") + + rviminfo Xviminfo + call assert_equal("echo '33'", histget(':', -1)) + call assert_equal("echo '27'", histget(':', -2)) + call assert_equal("echo '22'", histget(':', -3)) + call assert_equal("echo '15'", histget(':', -4)) + call assert_equal("echo '11'", histget(':', -5)) + + call histdel(':') + " items go before and after + call test_settime(8) + call histadd(':', "echo '8'") + call test_settime(39) + call histadd(':', "echo '39'") + + rviminfo Xviminfo + call assert_equal("echo '39'", histget(':', -1)) + call assert_equal("echo '33'", histget(':', -2)) + call assert_equal("echo '22'", histget(':', -3)) + call assert_equal("echo '11'", histget(':', -4)) + call assert_equal("echo '8'", histget(':', -5)) + + " Check sorting works when writing with merge. + call histdel(':') + call test_settime(8) + call histadd(':', "echo '8'") + call test_settime(15) + call histadd(':', "echo '15'") + call test_settime(27) + call histadd(':', "echo '27'") + call test_settime(39) + call histadd(':', "echo '39'") + wviminfo Xviminfo + + call histdel(':') + rviminfo Xviminfo + call assert_equal("echo '39'", histget(':', -1)) + call assert_equal("echo '33'", histget(':', -2)) + call assert_equal("echo '27'", histget(':', -3)) + call assert_equal("echo '22'", histget(':', -4)) + call assert_equal("echo '15'", histget(':', -5)) + call assert_equal("echo '11'", histget(':', -6)) + call assert_equal("echo '8'", histget(':', -7)) + + call delete('Xviminfo') +endfunc + +func Test_viminfo_registers() + call test_settime(8) + call setreg('a', "eight", 'c') + call test_settime(20) + call setreg('b', ["twenty", "again"], 'l') + call test_settime(40) + call setreg('c', ["four", "agai"], 'b4') + let l = [] + set viminfo='100,<600,s10,h,!,nviminfo + for i in range(500) + call add(l, 'something') + endfor + call setreg('d', l, 'l') + wviminfo Xviminfo + + call test_settime(10) + call setreg('a', '', 'b10') + call test_settime(15) + call setreg('b', 'drop') + call test_settime(50) + call setreg('c', 'keep', 'l') + call test_settime(30) + call setreg('d', 'drop', 'l') + rviminfo Xviminfo + + call assert_equal("", getreg('a')) + call assert_equal("\<C-V>10", getregtype('a')) + call assert_equal("twenty\nagain\n", getreg('b')) + call assert_equal("V", getregtype('b')) + call assert_equal("keep\n", getreg('c')) + call assert_equal("V", getregtype('c')) + call assert_equal(l, getreg('d', 1, 1)) + call assert_equal("V", getregtype('d')) + + " Length around 440 switches to line continuation. + let len = 434 + while len < 445 + let s = repeat('a', len) + call setreg('"', s) + wviminfo Xviminfo + call setreg('"', '') + rviminfo Xviminfo + call assert_equal(s, getreg('"'), 'wrong register at length: ' . len) + + let len += 1 + endwhile + + call delete('Xviminfo') +endfunc + +func Test_viminfo_marks() + sp bufa + let bufa = bufnr('%') + sp bufb + let bufb = bufnr('%') + + call test_settime(8) + call setpos("'A", [bufa, 1, 1, 0]) + call test_settime(20) + call setpos("'B", [bufb, 9, 1, 0]) + call setpos("'C", [bufa, 7, 1, 0]) + + delmark 0-9 + call test_settime(25) + call setpos("'1", [bufb, 12, 1, 0]) + call test_settime(35) + call setpos("'0", [bufa, 11, 1, 0]) + + call test_settime(45) + wviminfo Xviminfo + + " Writing viminfo inserts the '0 mark. + call assert_equal([bufb, 1, 1, 0], getpos("'0")) + call assert_equal([bufa, 11, 1, 0], getpos("'1")) + call assert_equal([bufb, 12, 1, 0], getpos("'2")) + + call test_settime(4) + call setpos("'A", [bufa, 9, 1, 0]) + call test_settime(30) + call setpos("'B", [bufb, 2, 3, 0]) + delmark C + + delmark 0-9 + call test_settime(30) + call setpos("'1", [bufb, 22, 1, 0]) + call test_settime(55) + call setpos("'0", [bufa, 21, 1, 0]) + + rviminfo Xviminfo + + call assert_equal([bufa, 1, 1, 0], getpos("'A")) + call assert_equal([bufb, 2, 3, 0], getpos("'B")) + call assert_equal([bufa, 7, 1, 0], getpos("'C")) + + " numbered marks are merged + call assert_equal([bufa, 21, 1, 0], getpos("'0")) " time 55 + call assert_equal([bufb, 1, 1, 0], getpos("'1")) " time 45 + call assert_equal([bufa, 11, 1, 0], getpos("'2")) " time 35 + call assert_equal([bufb, 22, 1, 0], getpos("'3")) " time 30 + call assert_equal([bufb, 12, 1, 0], getpos("'4")) " time 25 + + call delete('Xviminfo') + exe 'bwipe ' . bufa + exe 'bwipe ' . bufb +endfunc + +func Test_viminfo_jumplist() + split testbuf + clearjumps + call setline(1, ['time 05', 'time 10', 'time 15', 'time 20', 'time 30', 'last pos']) + call cursor(2, 1) + call test_settime(10) + exe "normal /20\r" + call test_settime(20) + exe "normal /30\r" + call test_settime(30) + exe "normal /last pos\r" + wviminfo Xviminfo + + clearjumps + call cursor(1, 1) + call test_settime(5) + exe "normal /15\r" + call test_settime(15) + exe "normal /last pos\r" + call test_settime(40) + exe "normal ?30\r" + rviminfo Xviminfo + + call assert_equal('time 30', getline('.')) + exe "normal \<C-O>" + call assert_equal('last pos', getline('.')) + exe "normal \<C-O>" + " duplicate for 'time 30' was removed + call assert_equal('time 20', getline('.')) + exe "normal \<C-O>" + call assert_equal('time 15', getline('.')) + exe "normal \<C-O>" + call assert_equal('time 10', getline('.')) + exe "normal \<C-O>" + call assert_equal('time 05', getline('.')) + + clearjumps + call cursor(1, 1) + call test_settime(5) + exe "normal /15\r" + call test_settime(15) + exe "normal /last pos\r" + call test_settime(40) + exe "normal ?30\r" + " Test merge when writing + wviminfo Xviminfo + clearjumps + rviminfo Xviminfo + + let last_line = line('.') + exe "normal \<C-O>" + call assert_equal('time 30', getline('.')) + exe "normal \<C-O>" + call assert_equal('last pos', getline('.')) + exe "normal \<C-O>" + " duplicate for 'time 30' was removed + call assert_equal('time 20', getline('.')) + exe "normal \<C-O>" + call assert_equal('time 15', getline('.')) + exe "normal \<C-O>" + call assert_equal('time 10', getline('.')) + exe "normal \<C-O>" + call assert_equal('time 05', getline('.')) + + " Test with jumplist full. + clearjumps + call setline(1, repeat(['match here'], 101)) + call cursor(1, 1) + call test_settime(10) + for i in range(100) + exe "normal /here\r" + endfor + rviminfo Xviminfo + + " must be newest mark that comes from viminfo. + exe "normal \<C-O>" + call assert_equal(last_line, line('.')) + + bwipe! + call delete('Xviminfo') +endfunc + +func Test_viminfo_encoding() + set enc=latin1 + call histdel(':') + call histadd(':', "echo '\xe9'") + wviminfo Xviminfo + + set fencs=utf-8,latin1 + set enc=utf-8 + sp Xviminfo + call assert_equal('latin1', &fenc) + close + + call histdel(':') + rviminfo Xviminfo + call assert_equal("echo 'é'", histget(':', -1)) + + call delete('Xviminfo') +endfunc + +func Test_viminfo_bad_syntax() + let lines = [] + call add(lines, '|<') " empty continuation line + call add(lines, '|234234234234234324,nothing') + call add(lines, '|1+"no comma"') + call add(lines, '|1,2,3,4,5,6,7') " too many items + call add(lines, '|1,"string version"') + call add(lines, '|1,>x') " bad continuation line + call add(lines, '|1,"x') " missing quote + call add(lines, '|1,"x\') " trailing backslash + call add(lines, '|1,,,,') "trailing comma + call add(lines, '|1,>234') " trailing continuation line + call writefile(lines, 'Xviminfo') + rviminfo Xviminfo + + call delete('Xviminfo') +endfunc + +func Test_viminfo_file_marks() + silent! bwipe test_viminfo.vim + silent! bwipe Xviminfo + + call test_settime(10) + edit ten + call test_settime(25) + edit again + call test_settime(30) + edit thirty + wviminfo Xviminfo + + call test_settime(20) + edit twenty + call test_settime(35) + edit again + call test_settime(40) + edit fourty + wviminfo Xviminfo + + sp Xviminfo + 1 + for name in ['fourty', 'again', 'thirty', 'twenty', 'ten'] + /^> + call assert_equal(name, substitute(getline('.'), '.*/', '', '')) + endfor + close + + call delete('Xviminfo') +endfunc + +func Test_viminfo_file_mark_tabclose() + tabnew Xtestfileintab + call setline(1, ['a','b','c','d','e']) + 4 + q! + wviminfo Xviminfo + sp Xviminfo + /^> .*Xtestfileintab + let lnum = line('.') + while 1 + if lnum == line('$') + call assert_report('mark not found in Xtestfileintab') + break + endif + let lnum += 1 + let line = getline(lnum) + if line == '' + call assert_report('mark not found in Xtestfileintab') + break + endif + if line =~ "^\t\"" + call assert_equal('4', substitute(line, ".*\"\t\\(\\d\\).*", '\1', '')) + break + endif + endwhile + + call delete('Xviminfo') + silent! bwipe Xtestfileintab +endfunc + +func Test_viminfo_file_mark_zero_time() + let lines = [ + \ '# Viminfo version', + \ '|1,4', + \ '', + \ '*encoding=utf-8', + \ '', + \ '# File marks:', + \ "'B 1 0 /tmp/nothing", + \ '|4,66,1,0,0,"/tmp/nothing"', + \ "", + \ ] + call writefile(lines, 'Xviminfo') + delmark B + rviminfo Xviminfo + call delete('Xviminfo') + call assert_equal(1, line("'B")) + delmark B +endfunc + +func Test_viminfo_oldfiles() + let v:oldfiles = [] + let lines = [ + \ '# comment line', + \ '*encoding=utf-8', + \ '', + \ "> /tmp/file_one.txt", + \ "\t\"\t11\t0", + \ "", + \ "> /tmp/file_two.txt", + \ "\t\"\t11\t0", + \ "", + \ "> /tmp/another.txt", + \ "\t\"\t11\t0", + \ "", + \ ] + call writefile(lines, 'Xviminfo') + rviminfo! Xviminfo + call delete('Xviminfo') + + call assert_equal(['1: /tmp/file_one.txt', '2: /tmp/file_two.txt', '3: /tmp/another.txt'], filter(split(execute('oldfiles'), "\n"), {i, v -> v =~ '/tmp/'})) + call assert_equal(['1: /tmp/file_one.txt', '2: /tmp/file_two.txt'], filter(split(execute('filter file_ oldfiles'), "\n"), {i, v -> v =~ '/tmp/'})) + call assert_equal(['3: /tmp/another.txt'], filter(split(execute('filter /another/ oldfiles'), "\n"), {i, v -> v =~ '/tmp/'})) +endfunc diff --git a/src/testdir/test_vimscript.vim b/src/testdir/test_vimscript.vim new file mode 100644 index 0000000..9de0a62 --- /dev/null +++ b/src/testdir/test_vimscript.vim @@ -0,0 +1,1448 @@ +" Test various aspects of the Vim script language. +" Most of this was formerly in test49. + +"------------------------------------------------------------------------------- +" Test environment {{{1 +"------------------------------------------------------------------------------- + +com! XpathINIT let g:Xpath = '' +com! -nargs=1 -bar Xpath let g:Xpath = g:Xpath . <args> + +" Append a message to the "messages" file +func Xout(text) + split messages + $put =a:text + wq +endfunc + +com! -nargs=1 Xout call Xout(<args>) + +" MakeScript() - Make a script file from a function. {{{2 +" +" Create a script that consists of the body of the function a:funcname. +" Replace any ":return" by a ":finish", any argument variable by a global +" variable, and and every ":call" by a ":source" for the next following argument +" in the variable argument list. This function is useful if similar tests are +" to be made for a ":return" from a function call or a ":finish" in a script +" file. +func MakeScript(funcname, ...) + let script = tempname() + execute "redir! >" . script + execute "function" a:funcname + redir END + execute "edit" script + " Delete the "function" and the "endfunction" lines. Do not include the + " word "function" in the pattern since it might be translated if LANG is + " set. When MakeScript() is being debugged, this deletes also the debugging + " output of its line 3 and 4. + exec '1,/.*' . a:funcname . '(.*)/d' + /^\d*\s*endfunction\>/,$d + %s/^\d*//e + %s/return/finish/e + %s/\<a:\(\h\w*\)/g:\1/ge + normal gg0 + let cnt = 0 + while search('\<call\s*\%(\u\|s:\)\w*\s*(.*)', 'W') > 0 + let cnt = cnt + 1 + s/\<call\s*\%(\u\|s:\)\w*\s*(.*)/\='source ' . a:{cnt}/ + endwhile + g/^\s*$/d + write + bwipeout + return script +endfunc + +" ExecAsScript - Source a temporary script made from a function. {{{2 +" +" Make a temporary script file from the function a:funcname, ":source" it, and +" delete it afterwards. However, if an exception is thrown the file may remain, +" the caller should call DeleteTheScript() afterwards. +let s:script_name = '' +function! ExecAsScript(funcname) + " Make a script from the function passed as argument. + let s:script_name = MakeScript(a:funcname) + + " Source and delete the script. + exec "source" s:script_name + call delete(s:script_name) + let s:script_name = '' +endfunction + +function! DeleteTheScript() + if s:script_name + call delete(s:script_name) + let s:script_name = '' + endif +endfunc + +com! -nargs=1 -bar ExecAsScript call ExecAsScript(<f-args>) + + +"------------------------------------------------------------------------------- +" Test 1: :endwhile in function {{{1 +" +" Detect if a broken loop is (incorrectly) reactivated by the +" :endwhile. Use a :return to prevent an endless loop, and make +" this test first to get a meaningful result on an error before other +" tests will hang. +"------------------------------------------------------------------------------- + +function! T1_F() + Xpath 'a' + let first = 1 + while 1 + Xpath 'b' + if first + Xpath 'c' + let first = 0 + break + else + Xpath 'd' + return + endif + endwhile +endfunction + +function! T1_G() + Xpath 'h' + let first = 1 + while 1 + Xpath 'i' + if first + Xpath 'j' + let first = 0 + break + else + Xpath 'k' + return + endif + if 1 " unmatched :if + endwhile +endfunction + +func Test_endwhile_function() + XpathINIT + call T1_F() + Xpath 'F' + + try + call T1_G() + catch + " Catch missing :endif + call assert_true(v:exception =~ 'E171') + Xpath 'x' + endtry + Xpath 'G' + + call assert_equal('abcFhijxG', g:Xpath) +endfunc + +"------------------------------------------------------------------------------- +" Test 2: :endwhile in script {{{1 +" +" Detect if a broken loop is (incorrectly) reactivated by the +" :endwhile. Use a :finish to prevent an endless loop, and place +" this test before others that might hang to get a meaningful result +" on an error. +" +" This test executes the bodies of the functions T1_F and T1_G from +" the previous test as script files (:return replaced by :finish). +"------------------------------------------------------------------------------- + +func Test_endwhile_script() + XpathINIT + ExecAsScript T1_F + Xpath 'F' + call DeleteTheScript() + + try + ExecAsScript T1_G + catch + " Catch missing :endif + call assert_true(v:exception =~ 'E171') + Xpath 'x' + endtry + Xpath 'G' + call DeleteTheScript() + + call assert_equal('abcFhijxG', g:Xpath) +endfunc + +"------------------------------------------------------------------------------- +" Test 3: :if, :elseif, :while, :continue, :break {{{1 +"------------------------------------------------------------------------------- + +function Test_if_while() + XpathINIT + if 1 + Xpath 'a' + let loops = 3 + while loops > -1 " main loop: loops == 3, 2, 1 (which breaks) + if loops <= 0 + let break_err = 1 + let loops = -1 + else + Xpath 'b' . loops + endif + if (loops == 2) + while loops == 2 " dummy loop + Xpath 'c' . loops + let loops = loops - 1 + continue " stop dummy loop + Xpath 'd' . loops + endwhile + continue " continue main loop + Xpath 'e' . loops + elseif (loops == 1) + let p = 1 + while p " dummy loop + Xpath 'f' . loops + let p = 0 + break " break dummy loop + Xpath 'g' . loops + endwhile + Xpath 'h' . loops + unlet p + break " break main loop + Xpath 'i' . loops + endif + if (loops > 0) + Xpath 'j' . loops + endif + while loops == 3 " dummy loop + let loops = loops - 1 + endwhile " end dummy loop + endwhile " end main loop + Xpath 'k' + else + Xpath 'l' + endif + Xpath 'm' + if exists("break_err") + Xpath 'm' + unlet break_err + endif + + unlet loops + + call assert_equal('ab3j3b2c2b1f1h1km', g:Xpath) +endfunc + +"------------------------------------------------------------------------------- +" Test 4: :return {{{1 +"------------------------------------------------------------------------------- + +function! T4_F() + if 1 + Xpath 'a' + let loops = 3 + while loops > 0 " 3: 2: 1: + Xpath 'b' . loops + if (loops == 2) + Xpath 'c' . loops + return + Xpath 'd' . loops + endif + Xpath 'e' . loops + let loops = loops - 1 + endwhile + Xpath 'f' + else + Xpath 'g' + endif +endfunction + +function Test_return() + XpathINIT + call T4_F() + Xpath '4' + + call assert_equal('ab3e3b2c24', g:Xpath) +endfunction + + +"------------------------------------------------------------------------------- +" Test 5: :finish {{{1 +" +" This test executes the body of the function T4_F from the previous +" test as a script file (:return replaced by :finish). +"------------------------------------------------------------------------------- + +function Test_finish() + XpathINIT + ExecAsScript T4_F + Xpath '5' + call DeleteTheScript() + + call assert_equal('ab3e3b2c25', g:Xpath) +endfunction + + + +"------------------------------------------------------------------------------- +" Test 6: Defining functions in :while loops {{{1 +" +" Functions can be defined inside other functions. An inner function +" gets defined when the outer function is executed. Functions may +" also be defined inside while loops. Expressions in braces for +" defining the function name are allowed. +" +" The functions are defined when sourcing the script, only the +" resulting path is checked in the test function. +"------------------------------------------------------------------------------- + +XpathINIT + +" The command CALL collects the argument of all its invocations in "calls" +" when used from a function (that is, when the global variable "calls" needs +" the "g:" prefix). This is to check that the function code is skipped when +" the function is defined. For inner functions, do so only if the outer +" function is not being executed. +" +let calls = "" +com! -nargs=1 CALL + \ if !exists("calls") && !exists("outer") | + \ let g:calls = g:calls . <args> | + \ endif + +let i = 0 +while i < 3 + let i = i + 1 + if i == 1 + Xpath 'a' + function! F1(arg) + CALL a:arg + let outer = 1 + + let j = 0 + while j < 1 + Xpath 'b' + let j = j + 1 + function! G1(arg) + CALL a:arg + endfunction + Xpath 'c' + endwhile + endfunction + Xpath 'd' + + continue + endif + + Xpath 'e' . i + function! F{i}(i, arg) + CALL a:arg + let outer = 1 + + if a:i == 3 + Xpath 'f' + endif + let k = 0 + while k < 3 + Xpath 'g' . k + let k = k + 1 + function! G{a:i}{k}(arg) + CALL a:arg + endfunction + Xpath 'h' . k + endwhile + endfunction + Xpath 'i' + +endwhile + +if exists("*G1") + Xpath 'j' +endif +if exists("*F1") + call F1("F1") + if exists("*G1") + call G1("G1") + endif +endif + +if exists("G21") || exists("G22") || exists("G23") + Xpath 'k' +endif +if exists("*F2") + call F2(2, "F2") + if exists("*G21") + call G21("G21") + endif + if exists("*G22") + call G22("G22") + endif + if exists("*G23") + call G23("G23") + endif +endif + +if exists("G31") || exists("G32") || exists("G33") + Xpath 'l' +endif +if exists("*F3") + call F3(3, "F3") + if exists("*G31") + call G31("G31") + endif + if exists("*G32") + call G32("G32") + endif + if exists("*G33") + call G33("G33") + endif +endif + +Xpath 'm' + +let g:test6_result = g:Xpath +let g:test6_calls = calls + +unlet calls +delfunction F1 +delfunction G1 +delfunction F2 +delfunction G21 +delfunction G22 +delfunction G23 +delfunction G31 +delfunction G32 +delfunction G33 + +function Test_defining_functions() + call assert_equal('ade2ie3ibcg0h1g1h2g2h3fg0h1g1h2g2h3m', g:test6_result) + call assert_equal('F1G1F2G21G22G23F3G31G32G33', g:test6_calls) +endfunc + +"------------------------------------------------------------------------------- +" Test 7: Continuing on errors outside functions {{{1 +" +" On an error outside a function, the script processing continues +" at the line following the outermost :endif or :endwhile. When not +" inside an :if or :while, the script processing continues at the next +" line. +"------------------------------------------------------------------------------- + +XpathINIT + +if 1 + Xpath 'a' + while 1 + Xpath 'b' + asdf + Xpath 'c' + break + endwhile | Xpath 'd' + Xpath 'e' +endif | Xpath 'f' +Xpath 'g' + +while 1 + Xpath 'h' + if 1 + Xpath 'i' + asdf + Xpath 'j' + endif | Xpath 'k' + Xpath 'l' + break +endwhile | Xpath 'm' +Xpath 'n' + +asdf +Xpath 'o' + +asdf | Xpath 'p' +Xpath 'q' + +let g:test7_result = g:Xpath + +func Test_error_in_script() + call assert_equal('abghinoq', g:test7_result) +endfunc + +"------------------------------------------------------------------------------- +" Test 8: Aborting and continuing on errors inside functions {{{1 +" +" On an error inside a function without the "abort" attribute, the +" script processing continues at the next line (unless the error was +" in a :return command). On an error inside a function with the +" "abort" attribute, the function is aborted and the script processing +" continues after the function call; the value -1 is returned then. +"------------------------------------------------------------------------------- + +XpathINIT + +function! T8_F() + if 1 + Xpath 'a' + while 1 + Xpath 'b' + asdf + Xpath 'c' + asdf | Xpath 'd' + Xpath 'e' + break + endwhile + Xpath 'f' + endif | Xpath 'g' + Xpath 'h' + + while 1 + Xpath 'i' + if 1 + Xpath 'j' + asdf + Xpath 'k' + asdf | Xpath 'l' + Xpath 'm' + endif + Xpath 'n' + break + endwhile | Xpath 'o' + Xpath 'p' + + return novar " returns (default return value 0) + Xpath 'q' + return 1 " not reached +endfunction + +function! T8_G() abort + if 1 + Xpath 'r' + while 1 + Xpath 's' + asdf " returns -1 + Xpath 't' + break + endwhile + Xpath 'v' + endif | Xpath 'w' + Xpath 'x' + + return -4 " not reached +endfunction + +function! T8_H() abort + while 1 + Xpath 'A' + if 1 + Xpath 'B' + asdf " returns -1 + Xpath 'C' + endif + Xpath 'D' + break + endwhile | Xpath 'E' + Xpath 'F' + + return -4 " not reached +endfunction + +" Aborted functions (T8_G and T8_H) return -1. +let g:test8_sum = (T8_F() + 1) - 4 * T8_G() - 8 * T8_H() +Xpath 'X' +let g:test8_result = g:Xpath + +func Test_error_in_function() + call assert_equal(13, g:test8_sum) + call assert_equal('abcefghijkmnoprsABX', g:test8_result) + + delfunction T8_F + delfunction T8_G + delfunction T8_H +endfunc + + +"------------------------------------------------------------------------------- +" Test 9: Continuing after aborted functions {{{1 +" +" When a function with the "abort" attribute is aborted due to an +" error, the next function back in the call hierarchy without an +" "abort" attribute continues; the value -1 is returned then. +"------------------------------------------------------------------------------- + +XpathINIT + +function! F() abort + Xpath 'a' + let result = G() " not aborted + Xpath 'b' + if result != 2 + Xpath 'c' + endif + return 1 +endfunction + +function! G() " no abort attribute + Xpath 'd' + if H() != -1 " aborted + Xpath 'e' + endif + Xpath 'f' + return 2 +endfunction + +function! H() abort + Xpath 'g' + call I() " aborted + Xpath 'h' + return 4 +endfunction + +function! I() abort + Xpath 'i' + asdf " error + Xpath 'j' + return 8 +endfunction + +if F() != 1 + Xpath 'k' +endif + +let g:test9_result = g:Xpath + +delfunction F +delfunction G +delfunction H +delfunction I + +func Test_func_abort() + call assert_equal('adgifb', g:test9_result) +endfunc + + +"------------------------------------------------------------------------------- +" Test 10: :if, :elseif, :while argument parsing {{{1 +" +" A '"' or '|' in an argument expression must not be mixed up with +" a comment or a next command after a bar. Parsing errors should +" be recognized. +"------------------------------------------------------------------------------- + +XpathINIT + +function! MSG(enr, emsg) + let english = v:lang == "C" || v:lang =~ '^[Ee]n' + if a:enr == "" + Xout "TODO: Add message number for:" a:emsg + let v:errmsg = ":" . v:errmsg + endif + let match = 1 + if v:errmsg !~ '^'.a:enr.':' || (english && v:errmsg !~ a:emsg) + let match = 0 + if v:errmsg == "" + Xout "Message missing." + else + let v:errmsg = escape(v:errmsg, '"') + Xout "Unexpected message:" v:errmsg + endif + endif + return match +endfunc + +if 1 || strlen("\"") | Xpath 'a' + Xpath 'b' +endif +Xpath 'c' + +if 0 +elseif 1 || strlen("\"") | Xpath 'd' + Xpath 'e' +endif +Xpath 'f' + +while 1 || strlen("\"") | Xpath 'g' + Xpath 'h' + break +endwhile +Xpath 'i' + +let v:errmsg = "" +if 1 ||| strlen("\"") | Xpath 'j' + Xpath 'k' +endif +Xpath 'l' +if !MSG('E15', "Invalid expression") + Xpath 'm' +endif + +let v:errmsg = "" +if 0 +elseif 1 ||| strlen("\"") | Xpath 'n' + Xpath 'o' +endif +Xpath 'p' +if !MSG('E15', "Invalid expression") + Xpath 'q' +endif + +let v:errmsg = "" +while 1 ||| strlen("\"") | Xpath 'r' + Xpath 's' + break +endwhile +Xpath 't' +if !MSG('E15', "Invalid expression") + Xpath 'u' +endif + +let g:test10_result = g:Xpath +delfunction MSG + +func Test_expr_parsing() + call assert_equal('abcdefghilpt', g:test10_result) +endfunc + + +"------------------------------------------------------------------------------- +" Test 11: :if, :elseif, :while argument evaluation after abort {{{1 +" +" When code is skipped over due to an error, the boolean argument to +" an :if, :elseif, or :while must not be evaluated. +"------------------------------------------------------------------------------- + +XpathINIT + +let calls = 0 + +function! P(num) + let g:calls = g:calls + a:num " side effect on call + return 0 +endfunction + +if 1 + Xpath 'a' + asdf " error + Xpath 'b' + if P(1) " should not be called + Xpath 'c' + elseif !P(2) " should not be called + Xpath 'd' + else + Xpath 'e' + endif + Xpath 'f' + while P(4) " should not be called + Xpath 'g' + endwhile + Xpath 'h' +endif +Xpath 'x' + +let g:test11_calls = calls +let g:test11_result = g:Xpath + +unlet calls +delfunction P + +func Test_arg_abort() + call assert_equal(0, g:test11_calls) + call assert_equal('ax', g:test11_result) +endfunc + + +"------------------------------------------------------------------------------- +" Test 12: Expressions in braces in skipped code {{{1 +" +" In code skipped over due to an error or inactive conditional, +" an expression in braces as part of a variable or function name +" should not be evaluated. +"------------------------------------------------------------------------------- + +XpathINIT + +function! NULL() + Xpath 'a' + return 0 +endfunction + +function! ZERO() + Xpath 'b' + return 0 +endfunction + +function! F0() + Xpath 'c' +endfunction + +function! F1(arg) + Xpath 'e' +endfunction + +let V0 = 1 + +Xpath 'f' +echo 0 ? F{NULL() + V{ZERO()}}() : 1 + +Xpath 'g' +if 0 + Xpath 'h' + call F{NULL() + V{ZERO()}}() +endif + +Xpath 'i' +if 1 + asdf " error + Xpath 'j' + call F1(F{NULL() + V{ZERO()}}()) +endif + +Xpath 'k' +if 1 + asdf " error + Xpath 'l' + call F{NULL() + V{ZERO()}}() +endif + +let g:test12_result = g:Xpath + +func Test_braces_skipped() + call assert_equal('fgik', g:test12_result) +endfunc + + +"------------------------------------------------------------------------------- +" Test 13: Failure in argument evaluation for :while {{{1 +" +" A failure in the expression evaluation for the condition of a :while +" causes the whole :while loop until the matching :endwhile being +" ignored. Continuation is at the next following line. +"------------------------------------------------------------------------------- + +XpathINIT + +Xpath 'a' +while asdf + Xpath 'b' + while 1 + Xpath 'c' + break + endwhile + Xpath 'd' + break +endwhile +Xpath 'e' + +while asdf | Xpath 'f' | endwhile | Xpath 'g' +Xpath 'h' +let g:test13_result = g:Xpath + +func Test_while_fail() + call assert_equal('aeh', g:test13_result) +endfunc + + +"------------------------------------------------------------------------------- +" Test 14: Failure in argument evaluation for :if {{{1 +" +" A failure in the expression evaluation for the condition of an :if +" does not cause the corresponding :else or :endif being matched to +" a previous :if/:elseif. Neither of both branches of the failed :if +" are executed. +"------------------------------------------------------------------------------- + +XpathINIT + +function! F() + Xpath 'a' + let x = 0 + if x " false + Xpath 'b' + elseif !x " always true + Xpath 'c' + let x = 1 + if g:boolvar " possibly undefined + Xpath 'd' + else + Xpath 'e' + endif + Xpath 'f' + elseif x " never executed + Xpath 'g' + endif + Xpath 'h' +endfunction + +let boolvar = 1 +call F() +Xpath '-' + +unlet boolvar +call F() +let g:test14_result = g:Xpath + +delfunction F + +func Test_if_fail() + call assert_equal('acdfh-acfh', g:test14_result) +endfunc + + +"------------------------------------------------------------------------------- +" Test 15: Failure in argument evaluation for :if (bar) {{{1 +" +" Like previous test, except that the failing :if ... | ... | :endif +" is in a single line. +"------------------------------------------------------------------------------- + +XpathINIT + +function! F() + Xpath 'a' + let x = 0 + if x " false + Xpath 'b' + elseif !x " always true + Xpath 'c' + let x = 1 + if g:boolvar | Xpath 'd' | else | Xpath 'e' | endif + Xpath 'f' + elseif x " never executed + Xpath 'g' + endif + Xpath 'h' +endfunction + +let boolvar = 1 +call F() +Xpath '-' + +unlet boolvar +call F() +let g:test15_result = g:Xpath + +delfunction F + +func Test_if_bar_fail() + call assert_equal('acdfh-acfh', g:test15_result) +endfunc + +"------------------------------------------------------------------------------- +" Test 90: Recognizing {} in variable name. {{{1 +"------------------------------------------------------------------------------- + +func Test_curlies() + let s:var = 66 + let ns = 's' + call assert_equal(66, {ns}:var) + + let g:a = {} + let g:b = 't' + let g:a[g:b] = 77 + call assert_equal(77, g:a['t']) +endfunc + +"------------------------------------------------------------------------------- +" Test 91: using type(). {{{1 +"------------------------------------------------------------------------------- + +func Test_type() + call assert_equal(0, type(0)) + call assert_equal(1, type("")) + call assert_equal(2, type(function("tr"))) + call assert_equal(2, type(function("tr", [8]))) + call assert_equal(3, type([])) + call assert_equal(4, type({})) + call assert_equal(5, type(0.0)) + call assert_equal(6, type(v:false)) + call assert_equal(6, type(v:true)) + call assert_equal(7, type(v:none)) + call assert_equal(7, type(v:null)) + call assert_equal(8, v:t_job) + call assert_equal(9, v:t_channel) + call assert_equal(v:t_number, type(0)) + call assert_equal(v:t_string, type("")) + call assert_equal(v:t_func, type(function("tr"))) + call assert_equal(v:t_func, type(function("tr", [8]))) + call assert_equal(v:t_list, type([])) + call assert_equal(v:t_dict, type({})) + call assert_equal(v:t_float, type(0.0)) + call assert_equal(v:t_bool, type(v:false)) + call assert_equal(v:t_bool, type(v:true)) + call assert_equal(v:t_none, type(v:none)) + call assert_equal(v:t_none, type(v:null)) + + + call assert_equal(0, 0 + v:false) + call assert_equal(1, 0 + v:true) + call assert_equal(0, 0 + v:none) + call assert_equal(0, 0 + v:null) + + call assert_equal('v:false', '' . v:false) + call assert_equal('v:true', '' . v:true) + call assert_equal('v:none', '' . v:none) + call assert_equal('v:null', '' . v:null) + + call assert_true(v:false == 0) + call assert_false(v:false != 0) + call assert_true(v:true == 1) + call assert_false(v:true != 1) + call assert_false(v:true == v:false) + call assert_true(v:true != v:false) + + call assert_true(v:null == 0) + call assert_false(v:null != 0) + call assert_true(v:none == 0) + call assert_false(v:none != 0) + + call assert_true(v:false is v:false) + call assert_true(v:true is v:true) + call assert_true(v:none is v:none) + call assert_true(v:null is v:null) + + call assert_false(v:false isnot v:false) + call assert_false(v:true isnot v:true) + call assert_false(v:none isnot v:none) + call assert_false(v:null isnot v:null) + + call assert_false(v:false is 0) + call assert_false(v:true is 1) + call assert_false(v:true is v:false) + call assert_false(v:none is 0) + call assert_false(v:null is 0) + call assert_false(v:null is v:none) + + call assert_true(v:false isnot 0) + call assert_true(v:true isnot 1) + call assert_true(v:true isnot v:false) + call assert_true(v:none isnot 0) + call assert_true(v:null isnot 0) + call assert_true(v:null isnot v:none) + + call assert_equal(v:false, eval(string(v:false))) + call assert_equal(v:true, eval(string(v:true))) + call assert_equal(v:none, eval(string(v:none))) + call assert_equal(v:null, eval(string(v:null))) + + call assert_equal(v:false, copy(v:false)) + call assert_equal(v:true, copy(v:true)) + call assert_equal(v:none, copy(v:none)) + call assert_equal(v:null, copy(v:null)) + + call assert_equal([v:false], deepcopy([v:false])) + call assert_equal([v:true], deepcopy([v:true])) + call assert_equal([v:none], deepcopy([v:none])) + call assert_equal([v:null], deepcopy([v:null])) + + call assert_true(empty(v:false)) + call assert_false(empty(v:true)) + call assert_true(empty(v:null)) + call assert_true(empty(v:none)) + + func ChangeYourMind() + try + return v:true + finally + return 'something else' + endtry + endfunc + + call ChangeYourMind() +endfunc + +"------------------------------------------------------------------------------- +" Test 92: skipping code {{{1 +"------------------------------------------------------------------------------- + +func Test_skip() + let Fn = function('Test_type') + call assert_false(0 && Fn[1]) + call assert_false(0 && string(Fn)) + call assert_false(0 && len(Fn)) + let l = [] + call assert_false(0 && l[1]) + call assert_false(0 && string(l)) + call assert_false(0 && len(l)) + let f = 1.0 + call assert_false(0 && f[1]) + call assert_false(0 && string(f)) + call assert_false(0 && len(f)) + let sp = v:null + call assert_false(0 && sp[1]) + call assert_false(0 && string(sp)) + call assert_false(0 && len(sp)) + +endfunc + +"------------------------------------------------------------------------------- +" Test 93: :echo and string() {{{1 +"------------------------------------------------------------------------------- + +func Test_echo_and_string() + " String + let a = 'foo bar' + redir => result + echo a + echo string(a) + redir END + let l = split(result, "\n") + call assert_equal(["foo bar", + \ "'foo bar'"], l) + + " Float + if has('float') + let a = -1.2e0 + redir => result + echo a + echo string(a) + redir END + let l = split(result, "\n") + call assert_equal(["-1.2", + \ "-1.2"], l) + endif + + " Funcref + redir => result + echo function('string') + echo string(function('string')) + redir END + let l = split(result, "\n") + call assert_equal(["string", + \ "function('string')"], l) + + " Recursive dictionary + let a = {} + let a["a"] = a + redir => result + echo a + echo string(a) + redir END + let l = split(result, "\n") + call assert_equal(["{'a': {...}}", + \ "{'a': {...}}"], l) + + " Recursive list + let a = [0] + let a[0] = a + redir => result + echo a + echo string(a) + redir END + let l = split(result, "\n") + call assert_equal(["[[...]]", + \ "[[...]]"], l) + + " Empty dictionaries in a list + let a = {} + redir => result + echo [a, a, a] + echo string([a, a, a]) + redir END + let l = split(result, "\n") + call assert_equal(["[{}, {}, {}]", + \ "[{}, {}, {}]"], l) + + " Empty dictionaries in a dictionary + let a = {} + let b = {"a": a, "b": a} + redir => result + echo b + echo string(b) + redir END + let l = split(result, "\n") + call assert_equal(["{'a': {}, 'b': {}}", + \ "{'a': {}, 'b': {}}"], l) + + " Empty lists in a list + let a = [] + redir => result + echo [a, a, a] + echo string([a, a, a]) + redir END + let l = split(result, "\n") + call assert_equal(["[[], [], []]", + \ "[[], [], []]"], l) + + " Empty lists in a dictionary + let a = [] + let b = {"a": a, "b": a} + redir => result + echo b + echo string(b) + redir END + let l = split(result, "\n") + call assert_equal(["{'a': [], 'b': []}", + \ "{'a': [], 'b': []}"], l) + + " Dictionaries in a list + let a = {"one": "yes", "two": "yes", "three": "yes"} + redir => result + echo [a, a, a] + echo string([a, a, a]) + redir END + let l = split(result, "\n") + call assert_equal(["[{'one': 'yes', 'two': 'yes', 'three': 'yes'}, {...}, {...}]", + \ "[{'one': 'yes', 'two': 'yes', 'three': 'yes'}, {'one': 'yes', 'two': 'yes', 'three': 'yes'}, {'one': 'yes', 'two': 'yes', 'three': 'yes'}]"], l) + + " Dictionaries in a dictionary + let a = {"one": "yes", "two": "yes", "three": "yes"} + let b = {"a": a, "b": a} + redir => result + echo b + echo string(b) + redir END + let l = split(result, "\n") + call assert_equal(["{'a': {'one': 'yes', 'two': 'yes', 'three': 'yes'}, 'b': {...}}", + \ "{'a': {'one': 'yes', 'two': 'yes', 'three': 'yes'}, 'b': {'one': 'yes', 'two': 'yes', 'three': 'yes'}}"], l) + + " Lists in a list + let a = [1, 2, 3] + redir => result + echo [a, a, a] + echo string([a, a, a]) + redir END + let l = split(result, "\n") + call assert_equal(["[[1, 2, 3], [...], [...]]", + \ "[[1, 2, 3], [1, 2, 3], [1, 2, 3]]"], l) + + " Lists in a dictionary + let a = [1, 2, 3] + let b = {"a": a, "b": a} + redir => result + echo b + echo string(b) + redir END + let l = split(result, "\n") + call assert_equal(["{'a': [1, 2, 3], 'b': [...]}", + \ "{'a': [1, 2, 3], 'b': [1, 2, 3]}"], l) + +endfunc + +"------------------------------------------------------------------------------- +" Test 94: 64-bit Numbers {{{1 +"------------------------------------------------------------------------------- + +func Test_num64() + if !has('num64') + return + endif + + call assert_notequal( 4294967296, 0) + call assert_notequal(-4294967296, 0) + call assert_equal( 4294967296, 0xFFFFffff + 1) + call assert_equal(-4294967296, -0xFFFFffff - 1) + + call assert_equal( 9223372036854775807, 1 / 0) + call assert_equal(-9223372036854775807, -1 / 0) + call assert_equal(-9223372036854775807 - 1, 0 / 0) + + call assert_equal( 0x7FFFffffFFFFffff, float2nr( 1.0e150)) + call assert_equal(-0x7FFFffffFFFFffff, float2nr(-1.0e150)) + + let rng = range(0xFFFFffff, 0x100000001) + call assert_equal([0xFFFFffff, 0x100000000, 0x100000001], rng) + call assert_equal(0x100000001, max(rng)) + call assert_equal(0xFFFFffff, min(rng)) + call assert_equal(rng, sort(range(0x100000001, 0xFFFFffff, -1), 'N')) +endfunc + +"------------------------------------------------------------------------------- +" Test 95: lines of :append, :change, :insert {{{1 +"------------------------------------------------------------------------------- + +function! DefineFunction(name, body) + let func = join(['function! ' . a:name . '()'] + a:body + ['endfunction'], "\n") + exec func +endfunction + +func Test_script_lines() + " :append + try + call DefineFunction('T_Append', [ + \ 'append', + \ 'py <<EOS', + \ '.', + \ ]) + catch + call assert_report("Can't define function") + endtry + try + call DefineFunction('T_Append', [ + \ 'append', + \ 'abc', + \ ]) + call assert_report("Shouldn't be able to define function") + catch + call assert_exception('Vim(function):E126: Missing :endfunction') + endtry + + " :change + try + call DefineFunction('T_Change', [ + \ 'change', + \ 'py <<EOS', + \ '.', + \ ]) + catch + call assert_report("Can't define function") + endtry + try + call DefineFunction('T_Change', [ + \ 'change', + \ 'abc', + \ ]) + call assert_report("Shouldn't be able to define function") + catch + call assert_exception('Vim(function):E126: Missing :endfunction') + endtry + + " :insert + try + call DefineFunction('T_Insert', [ + \ 'insert', + \ 'py <<EOS', + \ '.', + \ ]) + catch + call assert_report("Can't define function") + endtry + try + call DefineFunction('T_Insert', [ + \ 'insert', + \ 'abc', + \ ]) + call assert_report("Shouldn't be able to define function") + catch + call assert_exception('Vim(function):E126: Missing :endfunction') + endtry +endfunc + +"------------------------------------------------------------------------------- +" Test 96: line continuation {{{1 +" +" Undefined behavior was detected by ubsan with line continuation +" after an empty line. +"------------------------------------------------------------------------------- +func Test_script_emty_line_continuation() + + \ +endfunc + +"------------------------------------------------------------------------------- +" Test 97: bitwise functions {{{1 +"------------------------------------------------------------------------------- +func Test_bitwise_functions() + " and + call assert_equal(127, and(127, 127)) + call assert_equal(16, and(127, 16)) + call assert_equal(0, and(127, 128)) + call assert_fails("call and(1.0, 1)", 'E805:') + call assert_fails("call and([], 1)", 'E745:') + call assert_fails("call and({}, 1)", 'E728:') + call assert_fails("call and(1, 1.0)", 'E805:') + call assert_fails("call and(1, [])", 'E745:') + call assert_fails("call and(1, {})", 'E728:') + " or + call assert_equal(23, or(16, 7)) + call assert_equal(15, or(8, 7)) + call assert_equal(123, or(0, 123)) + call assert_fails("call or(1.0, 1)", 'E805:') + call assert_fails("call or([], 1)", 'E745:') + call assert_fails("call or({}, 1)", 'E728:') + call assert_fails("call or(1, 1.0)", 'E805:') + call assert_fails("call or(1, [])", 'E745:') + call assert_fails("call or(1, {})", 'E728:') + " xor + call assert_equal(0, xor(127, 127)) + call assert_equal(111, xor(127, 16)) + call assert_equal(255, xor(127, 128)) + call assert_fails("call xor(1.0, 1)", 'E805:') + call assert_fails("call xor([], 1)", 'E745:') + call assert_fails("call xor({}, 1)", 'E728:') + call assert_fails("call xor(1, 1.0)", 'E805:') + call assert_fails("call xor(1, [])", 'E745:') + call assert_fails("call xor(1, {})", 'E728:') + " invert + call assert_equal(65408, and(invert(127), 65535)) + call assert_equal(65519, and(invert(16), 65535)) + call assert_equal(65407, and(invert(128), 65535)) + call assert_fails("call invert(1.0)", 'E805:') + call assert_fails("call invert([])", 'E745:') + call assert_fails("call invert({})", 'E728:') +endfunc + +" Test trailing text after :endfunction {{{1 +func Test_endfunction_trailing() + call assert_false(exists('*Xtest')) + + exe "func Xtest()\necho 'hello'\nendfunc\nlet done = 'yes'" + call assert_true(exists('*Xtest')) + call assert_equal('yes', done) + delfunc Xtest + unlet done + + exe "func Xtest()\necho 'hello'\nendfunc|let done = 'yes'" + call assert_true(exists('*Xtest')) + call assert_equal('yes', done) + delfunc Xtest + unlet done + + " trailing line break + exe "func Xtest()\necho 'hello'\nendfunc\n" + call assert_true(exists('*Xtest')) + delfunc Xtest + + set verbose=1 + exe "func Xtest()\necho 'hello'\nendfunc \" garbage" + call assert_notmatch('W22:', split(execute('1messages'), "\n")[0]) + call assert_true(exists('*Xtest')) + delfunc Xtest + + exe "func Xtest()\necho 'hello'\nendfunc garbage" + call assert_match('W22:', split(execute('1messages'), "\n")[0]) + call assert_true(exists('*Xtest')) + delfunc Xtest + set verbose=0 + + function Foo() + echo 'hello' + endfunction | echo 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' + delfunc Foo +endfunc + +func Test_delfunction_force() + delfunc! Xtest + delfunc! Xtest + func Xtest() + echo 'nothing' + endfunc + delfunc! Xtest + delfunc! Xtest +endfunc + +" Test using bang after user command {{{1 +func Test_user_command_with_bang() + command -bang Nieuw let nieuw = 1 + Ni! + call assert_equal(1, nieuw) + unlet nieuw + delcommand Nieuw +endfunc + +" Test for script-local function +func <SID>DoLast() + call append(line('$'), "last line") +endfunc + +func s:DoNothing() + call append(line('$'), "nothing line") +endfunc + +func Test_script_local_func() + set nocp viminfo+=nviminfo + new + nnoremap <buffer> _x :call <SID>DoNothing()<bar>call <SID>DoLast()<bar>delfunc <SID>DoNothing<bar>delfunc <SID>DoLast<cr> + + normal _x + call assert_equal('nothing line', getline(2)) + call assert_equal('last line', getline(3)) + enew! | close +endfunc + +"------------------------------------------------------------------------------- +" Modelines {{{1 +" vim: ts=8 sw=4 tw=80 fdm=marker +" vim: fdt=substitute(substitute(foldtext(),\ '\\%(^+--\\)\\@<=\\(\\s*\\)\\(.\\{-}\\)\:\ \\%(\"\ \\)\\=\\(Test\ \\d*\\)\:\\s*',\ '\\3\ (\\2)\:\ \\1',\ \"\"),\ '\\(Test\\s*\\)\\(\\d\\)\\D\\@=',\ '\\1\ \\2',\ "") +"------------------------------------------------------------------------------- diff --git a/src/testdir/test_virtualedit.vim b/src/testdir/test_virtualedit.vim new file mode 100644 index 0000000..67adede --- /dev/null +++ b/src/testdir/test_virtualedit.vim @@ -0,0 +1,75 @@ +" Tests for 'virtualedit'. + +func Test_yank_move_change() + new + call setline(1, [ + \ "func foo() error {", + \ "\tif n, err := bar();", + \ "\terr != nil {", + \ "\t\treturn err", + \ "\t}", + \ "\tn = n * n", + \ ]) + set virtualedit=all + set ts=4 + function! MoveSelectionDown(count) abort + normal! m` + silent! exe "'<,'>move'>+".a:count + norm! `` + endfunction + + xmap ]e :<C-U>call MoveSelectionDown(v:count1)<CR> + 2 + normal 2gg + normal J + normal jVj + normal ]e + normal ce + bwipe! + set virtualedit= + set ts=8 +endfunc + +func Test_paste_end_of_line() + new + set virtualedit=all + call setline(1, ['456', '123']) + normal! gg0"ay$ + exe "normal! 2G$lllA\<C-O>:normal! \"agP\r" + call assert_equal('123456', getline(2)) + + bwipe! + set virtualedit= +endfunc + +func Test_replace_end_of_line() + new + set virtualedit=all + call setline(1, range(20)) + exe "normal! gg2jv10lr-" + call assert_equal(["1", "-----------", "3"], getline(2,4)) + call setline(1, range(20)) + exe "normal! gg2jv10lr\<c-k>hh" + call assert_equal(["1", "───────────", "3"], getline(2,4)) + + bwipe! + set virtualedit= +endfunc + +func Test_edit_CTRL_G() + new + set virtualedit=insert + call setline(1, ['123', '1', '12']) + exe "normal! ggA\<c-g>jx\<c-g>jx" + call assert_equal(['123', '1 x', '12 x'], getline(1,'$')) + + set virtualedit=all + %d_ + call setline(1, ['1', '12']) + exe "normal! ggllix\<c-g>jx" + call assert_equal(['1 x', '12x'], getline(1,'$')) + + + bwipe! + set virtualedit= +endfunc diff --git a/src/testdir/test_visual.vim b/src/testdir/test_visual.vim new file mode 100644 index 0000000..77064ba --- /dev/null +++ b/src/testdir/test_visual.vim @@ -0,0 +1,399 @@ +" Tests for various Visual mode. +if !has('visual') + finish +endif + + +func Test_block_shift_multibyte() + " Uses double-wide character. + split + call setline(1, ['xヹxxx', 'ヹxxx']) + exe "normal 1G0l\<C-V>jl>" + call assert_equal('x ヹxxx', getline(1)) + call assert_equal(' ヹxxx', getline(2)) + q! +endfunc + +func Test_block_shift_overflow() + " This used to cause a multiplication overflow followed by a crash. + new + normal ii + exe "normal \<C-V>876543210>" + q! +endfunc + +func Test_dotregister_paste() + new + exe "norm! ihello world\<esc>" + norm! 0ve".p + call assert_equal('hello world world', getline(1)) + q! +endfunc + +func Test_Visual_ctrl_o() + new + call setline(1, ['one', 'two', 'three']) + call cursor(1,2) + set noshowmode + set tw=0 + call feedkeys("\<c-v>jjlIa\<c-\>\<c-o>:set tw=88\<cr>\<esc>", 'tx') + call assert_equal(['oane', 'tawo', 'tahree'], getline(1, 3)) + call assert_equal(88, &tw) + set tw& + bw! +endfu + +func Test_Visual_vapo() + new + normal oxx + normal vapo + bwipe! +endfunc + +func Test_Visual_inner_quote() + new + normal oxX + normal vki' + bwipe! +endfunc + +" Test for Visual mode not being reset causing E315 error. +func TriggerTheProblem() + " At this point there is no visual selection because :call reset it. + " Let's restore the selection: + normal gv + '<,'>del _ + try + exe "normal \<Esc>" + catch /^Vim\%((\a\+)\)\=:E315/ + echom 'Snap! E315 error!' + let g:msg = 'Snap! E315 error!' + endtry +endfunc + +func Test_visual_mode_reset() + enew + let g:msg = "Everything's fine." + enew + setl buftype=nofile + call append(line('$'), 'Delete this line.') + + " NOTE: this has to be done by a call to a function because executing :del + " the ex-way will require the colon operator which resets the visual mode + " thus preventing the problem: + exe "normal! GV:call TriggerTheProblem()\<CR>" + call assert_equal("Everything's fine.", g:msg) + +endfunc + +" Test for visual block shift and tab characters. +func Test_block_shift_tab() + enew! + call append(0, repeat(['one two three'], 5)) + call cursor(1,1) + exe "normal i\<C-G>u" + exe "normal fe\<C-V>4jR\<Esc>ugvr1" + call assert_equal('on1 two three', getline(1)) + call assert_equal('on1 two three', getline(2)) + call assert_equal('on1 two three', getline(5)) + + enew! + call append(0, repeat(['abcdefghijklmnopqrstuvwxyz'], 5)) + call cursor(1,1) + exe "normal \<C-V>4jI \<Esc>j<<11|D" + exe "normal j7|a\<Tab>\<Tab>" + exe "normal j7|a\<Tab>\<Tab> " + exe "normal j7|a\<Tab> \<Tab>\<Esc>4k13|\<C-V>4j<" + call assert_equal(' abcdefghijklmnopqrstuvwxyz', getline(1)) + call assert_equal('abcdefghij', getline(2)) + call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(3)) + call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(4)) + call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(5)) + + %s/\s\+//g + call cursor(1,1) + exe "normal \<C-V>4jI \<Esc>j<<" + exe "normal j7|a\<Tab>\<Tab>" + exe "normal j7|a\<Tab>\<Tab>\<Tab>\<Tab>\<Tab>" + exe "normal j7|a\<Tab> \<Tab>\<Tab>\<Esc>4k13|\<C-V>4j3<" + call assert_equal(' abcdefghijklmnopqrstuvwxyz', getline(1)) + call assert_equal('abcdefghij', getline(2)) + call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(3)) + call assert_equal(" abc\<Tab>\<Tab>defghijklmnopqrstuvwxyz", getline(4)) + call assert_equal(" abc\<Tab> defghijklmnopqrstuvwxyz", getline(5)) + + enew! +endfunc + +" Tests Blockwise Visual when there are TABs before the text. +func Test_blockwise_visual() + enew! + call append(0, ['123456', + \ '234567', + \ '345678', + \ '', + \ 'test text test tex start here', + \ "\t\tsome text", + \ "\t\ttest text", + \ 'test text']) + call cursor(1,1) + exe "normal /start here$\<CR>" + exe 'normal "by$' . "\<C-V>jjlld" + exe "normal /456$\<CR>" + exe "normal \<C-V>jj" . '"bP' + call assert_equal(['123start here56', + \ '234start here67', + \ '345start here78', + \ '', + \ 'test text test tex rt here', + \ "\t\tsomext", + \ "\t\ttesext"], getline(1, 7)) + + enew! +endfunc + +" Test swapping corners in blockwise visual mode with o and O +func Test_blockwise_visual_o_O() + enew! + + exe "norm! 10i.\<Esc>Y4P3lj\<C-V>4l2jr " + exe "norm! gvO\<Esc>ra" + exe "norm! gvO\<Esc>rb" + exe "norm! gvo\<C-c>rc" + exe "norm! gvO\<C-c>rd" + + call assert_equal(['..........', + \ '...c d..', + \ '... ..', + \ '...a b..', + \ '..........'], getline(1, '$')) + + enew! +endfun + +" Test Virtual replace mode. +func Test_virtual_replace() + if exists('&t_kD') + let save_t_kD = &t_kD + endif + if exists('&t_kb') + let save_t_kb = &t_kb + endif + exe "set t_kD=\<C-V>x7f t_kb=\<C-V>x08" + enew! + exe "normal a\nabcdefghi\njk\tlmn\n opq rst\n\<C-D>uvwxyz" + call cursor(1,1) + set ai bs=2 + exe "normal gR0\<C-D> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR" + call assert_equal([' 1', + \ ' A', + \ ' BCDEFGHIJ', + \ ' KL', + \ ' MNO', + \ ' PQR', + \ ], getline(1, 6)) + normal G + mark a + exe "normal o0\<C-D>\nabcdefghi\njk\tlmn\n opq\trst\n\<C-D>uvwxyz\n" + exe "normal 'ajgR0\<C-D> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR" . repeat("\<BS>", 29) + call assert_equal([' 1', + \ 'abcdefghi', + \ 'jk lmn', + \ ' opq rst', + \ 'uvwxyz'], getline(7, 11)) + normal G + exe "normal iab\tcdefghi\tjkl" + exe "normal 0gRAB......CDEFGHI.J\<Esc>o" + exe "normal iabcdefghijklmnopqrst\<Esc>0gRAB\tIJKLMNO\tQR" + call assert_equal(['AB......CDEFGHI.Jkl', + \ 'AB IJKLMNO QRst'], getline(12, 13)) + enew! + set noai bs&vim + if exists('save_t_kD') + let &t_kD = save_t_kD + endif + if exists('save_t_kb') + let &t_kb = save_t_kb + endif +endfunc + +" Test Virtual replace mode. +func Test_virtual_replace2() + enew! + set bs=2 + exe "normal a\nabcdefghi\njk\tlmn\n opq rst\n\<C-D>uvwxyz" + call cursor(1,1) + " Test 1: Test that del deletes the newline + exe "normal gR0\<del> 1\nA\nBCDEFGHIJ\n\tKL\nMNO\nPQR" + call assert_equal(['0 1', + \ 'A', + \ 'BCDEFGHIJ', + \ ' KL', + \ 'MNO', + \ 'PQR', + \ ], getline(1, 6)) + " Test 2: + " a newline is not deleted, if no newline has been added in virtual replace mode + %d_ + call setline(1, ['abcd', 'efgh', 'ijkl']) + call cursor(2,1) + exe "norm! gR1234\<cr>5\<bs>\<bs>\<bs>" + call assert_equal(['abcd', + \ '123h', + \ 'ijkl'], getline(1, '$')) + " Test 3: + " a newline is deleted, if a newline has been inserted before in virtual replace mode + %d_ + call setline(1, ['abcd', 'efgh', 'ijkl']) + call cursor(2,1) + exe "norm! gR1234\<cr>\<cr>56\<bs>\<bs>\<bs>" + call assert_equal(['abcd', + \ '1234', + \ 'ijkl'], getline(1, '$')) + " Test 4: + " delete add a newline, delete it, add it again and check undo + %d_ + call setline(1, ['abcd', 'efgh', 'ijkl']) + call cursor(2,1) + " break undo sequence explicitly + let &ul = &ul + exe "norm! gR1234\<cr>\<bs>\<del>56\<cr>" + let &ul = &ul + call assert_equal(['abcd', + \ '123456', + \ ''], getline(1, '$')) + norm! u + call assert_equal(['abcd', + \ 'efgh', + \ 'ijkl'], getline(1, '$')) + " clean up + %d_ + set bs&vim +endfunc + +func Test_Visual_word_textobject() + new + call setline(1, ['First sentence. Second sentence.']) + + " When start and end of visual area are identical, 'aw' or 'iw' select + " the whole word. + norm! 1go2fcvawy + call assert_equal('Second ', @") + norm! 1go2fcviwy + call assert_equal('Second', @") + + " When start and end of visual area are not identical, 'aw' or 'iw' + " extend the word in direction of the end of the visual area. + norm! 1go2fcvlawy + call assert_equal('cond ', @") + norm! gv2awy + call assert_equal('cond sentence.', @") + + norm! 1go2fcvliwy + call assert_equal('cond', @") + norm! gv2iwy + call assert_equal('cond sentence', @") + + " Extend visual area in opposite direction. + norm! 1go2fcvhawy + call assert_equal(' Sec', @") + norm! gv2awy + call assert_equal(' sentence. Sec', @") + + norm! 1go2fcvhiwy + call assert_equal('Sec', @") + norm! gv2iwy + call assert_equal('. Sec', @") + + bwipe! +endfunc + +func Test_Visual_sentence_textobject() + new + call setline(1, ['First sentence. Second sentence. Third', 'sentence. Fourth sentence']) + + " When start and end of visual area are identical, 'as' or 'is' select + " the whole sentence. + norm! 1gofdvasy + call assert_equal('Second sentence. ', @") + norm! 1gofdvisy + call assert_equal('Second sentence.', @") + + " When start and end of visual area are not identical, 'as' or 'is' + " extend the sentence in direction of the end of the visual area. + norm! 1gofdvlasy + call assert_equal('d sentence. ', @") + norm! gvasy + call assert_equal("d sentence. Third\nsentence. ", @") + + norm! 1gofdvlisy + call assert_equal('d sentence.', @") + norm! gvisy + call assert_equal('d sentence. ', @") + norm! gvisy + call assert_equal("d sentence. Third\nsentence.", @") + + " Extend visual area in opposite direction. + norm! 1gofdvhasy + call assert_equal(' Second', @") + norm! gvasy + call assert_equal("First sentence. Second", @") + + norm! 1gofdvhisy + call assert_equal('Second', @") + norm! gvisy + call assert_equal(' Second', @") + norm! gvisy + call assert_equal('First sentence. Second', @") + + bwipe! +endfunc + +func Test_Visual_paragraph_textobject() + new + call setline(1, ['First line.', + \ '', + \ 'Second line.', + \ 'Third line.', + \ 'Fourth line.', + \ 'Fifth line.', + \ '', + \ 'Sixth line.']) + + " When start and end of visual area are identical, 'ap' or 'ip' select + " the whole paragraph. + norm! 4ggvapy + call assert_equal("Second line.\nThird line.\nFourth line.\nFifth line.\n\n", @") + norm! 4ggvipy + call assert_equal("Second line.\nThird line.\nFourth line.\nFifth line.\n", @") + + " When start and end of visual area are not identical, 'ap' or 'ip' + " extend the sentence in direction of the end of the visual area. + " FIXME: actually, it is not sufficient to have different start and + " end of visual selection, the start line and end line have to differ, + " which is not consistent with the documentation. + norm! 4ggVjapy + call assert_equal("Third line.\nFourth line.\nFifth line.\n\n", @") + norm! gvapy + call assert_equal("Third line.\nFourth line.\nFifth line.\n\nSixth line.\n", @") + norm! 4ggVjipy + call assert_equal("Third line.\nFourth line.\nFifth line.\n", @") + norm! gvipy + call assert_equal("Third line.\nFourth line.\nFifth line.\n\n", @") + norm! gvipy + call assert_equal("Third line.\nFourth line.\nFifth line.\n\nSixth line.\n", @") + + " Extend visual area in opposite direction. + norm! 5ggVkapy + call assert_equal("\nSecond line.\nThird line.\nFourth line.\n", @") + norm! gvapy + call assert_equal("First line.\n\nSecond line.\nThird line.\nFourth line.\n", @") + norm! 5ggVkipy + call assert_equal("Second line.\nThird line.\nFourth line.\n", @") + norma gvipy + call assert_equal("\nSecond line.\nThird line.\nFourth line.\n", @") + norm! gvipy + call assert_equal("First line.\n\nSecond line.\nThird line.\nFourth line.\n", @") + + bwipe! +endfunc diff --git a/src/testdir/test_winbar.vim b/src/testdir/test_winbar.vim new file mode 100644 index 0000000..1961607 --- /dev/null +++ b/src/testdir/test_winbar.vim @@ -0,0 +1,23 @@ +" Test WinBar + +if !has('menu') + finish +endif + +func Test_add_remove_menu() + new + amenu 1.10 WinBar.Next :let g:did_next = 11<CR> + amenu 1.20 WinBar.Cont :let g:did_cont = 12<CR> + emenu WinBar.Next + call assert_equal(11, g:did_next) + emenu WinBar.Cont + call assert_equal(12, g:did_cont) + + wincmd w + call assert_fails('emenu WinBar.Next', 'E334') + wincmd p + + aunmenu WinBar.Next + aunmenu WinBar.Cont + close +endfunc diff --git a/src/testdir/test_winbuf_close.vim b/src/testdir/test_winbuf_close.vim new file mode 100644 index 0000000..e461861 --- /dev/null +++ b/src/testdir/test_winbuf_close.vim @@ -0,0 +1,160 @@ +" Test for commands that close windows and/or buffers: +" :quit +" :close +" :hide +" :only +" :sall +" :all +" :ball +" :buf +" :edit +" +func Test_winbuf_close() + enew | only + + call writefile(['testtext 1'], 'Xtest1') + call writefile(['testtext 2'], 'Xtest2') + call writefile(['testtext 3'], 'Xtest3') + + next! Xtest1 Xtest2 + call setline(1, 'testtext 1 1') + + " test for working :n when hidden set + set hidden + next + call assert_equal('Xtest2', bufname('%')) + + " test for failing :rew when hidden not set + set nohidden + call setline(1, 'testtext 2 2') + call assert_fails('rewind', 'E37') + call assert_equal('Xtest2', bufname('%')) + call assert_equal('testtext 2 2', getline(1)) + + " test for working :rew when hidden set + set hidden + rewind + call assert_equal('Xtest1', bufname('%')) + call assert_equal('testtext 1 1', getline(1)) + + " test for :all keeping a buffer when it's modified + set nohidden + call setline(1, 'testtext 1 1 1') + split + next Xtest2 Xtest3 + all + 1wincmd w + call assert_equal('Xtest1', bufname('%')) + call assert_equal('testtext 1 1 1', getline(1)) + + " test abandoning changed buffer, should be unloaded even when 'hidden' set + set hidden + call setline(1, 'testtext 1 1 1 1') + quit! + call assert_equal('Xtest2', bufname('%')) + call assert_equal('testtext 2 2', getline(1)) + unhide + call assert_equal('Xtest2', bufname('%')) + call assert_equal('testtext 2 2', getline(1)) + + " test ":hide" hides anyway when 'hidden' not set + set nohidden + call setline(1, 'testtext 2 2 2') + hide + call assert_equal('Xtest3', bufname('%')) + call assert_equal('testtext 3', getline(1)) + + " test ":edit" failing in modified buffer when 'hidden' not set + call setline(1, 'testtext 3 3') + call assert_fails('edit Xtest1', 'E37') + call assert_equal('Xtest3', bufname('%')) + call assert_equal('testtext 3 3', getline(1)) + + " test ":edit" working in modified buffer when 'hidden' set + set hidden + edit Xtest1 + call assert_equal('Xtest1', bufname('%')) + call assert_equal('testtext 1', getline(1)) + + " test ":close" not hiding when 'hidden' not set in modified buffer + split Xtest3 + set nohidden + call setline(1, 'testtext 3 3 3') + call assert_fails('close', 'E37') + call assert_equal('Xtest3', bufname('%')) + call assert_equal('testtext 3 3 3', getline(1)) + + " test ":close!" does hide when 'hidden' not set in modified buffer; + call setline(1, 'testtext 3 3 3 3') + close! + call assert_equal('Xtest1', bufname('%')) + call assert_equal('testtext 1', getline(1)) + + set nohidden + + " test ":all!" hides changed buffer + split Xtest4 + call setline(1, 'testtext 4') + all! + 1wincmd w + call assert_equal('Xtest2', bufname('%')) + call assert_equal('testtext 2 2 2', getline(1)) + + " test ":q!" and hidden buffer. + bwipe! Xtest1 Xtest2 Xtest3 Xtest4 + split Xtest1 + wincmd w + bwipe! + set modified + bot split Xtest2 + set modified + bot split Xtest3 + set modified + wincmd t + hide + call assert_equal('Xtest2', bufname('%')) + quit! + call assert_equal('Xtest3', bufname('%')) + call assert_fails('silent! quit!', 'E162') + call assert_equal('Xtest1', bufname('%')) + + call delete('Xtest1') + call delete('Xtest2') + call delete('Xtest3') +endfunc + +" Test that ":close" will respect 'winfixheight' when possible. +func Test_winfixheight_on_close() + set nosplitbelow nosplitright + + split | split | vsplit + + $wincmd w + setlocal winfixheight + let l:height = winheight(0) + + 3close + + call assert_equal(l:height, winheight(0)) + + %bwipeout! + setlocal nowinfixheight splitbelow& splitright& +endfunc + +" Test that ":close" will respect 'winfixwidth' when possible. +func Test_winfixwidth_on_close() + set nosplitbelow nosplitright + + vsplit | vsplit | split + + $wincmd w + setlocal winfixwidth + let l:width = winwidth(0) + + 3close + + call assert_equal(l:width, winwidth(0)) + + %bwipeout! + setlocal nowinfixwidth splitbelow& splitright& +endfunction diff --git a/src/testdir/test_window_cmd.vim b/src/testdir/test_window_cmd.vim new file mode 100644 index 0000000..587ae23 --- /dev/null +++ b/src/testdir/test_window_cmd.vim @@ -0,0 +1,618 @@ +" Tests for window cmd (:wincmd, :split, :vsplit, :resize and etc...) + +func Test_window_cmd_ls0_with_split() + set ls=0 + set splitbelow + split + quit + call assert_equal(0, &lines - &cmdheight - winheight(0)) + new | only! + " + set splitbelow&vim + botright split + quit + call assert_equal(0, &lines - &cmdheight - winheight(0)) + new | only! + set ls&vim +endfunc + +func Test_window_cmd_cmdwin_with_vsp() + let efmt = 'Expected 0 but got %d (in ls=%d, %s window)' + for v in range(0, 2) + exec "set ls=" . v + vsplit + call feedkeys("q:\<CR>") + let ac = &lines - (&cmdheight + winheight(0) + !!v) + let emsg = printf(efmt, ac, v, 'left') + call assert_equal(0, ac, emsg) + wincmd w + let ac = &lines - (&cmdheight + winheight(0) + !!v) + let emsg = printf(efmt, ac, v, 'right') + call assert_equal(0, ac, emsg) + new | only! + endfor + set ls&vim +endfunc + +function Test_window_cmd_wincmd_gf() + let fname = 'test_gf.txt' + let swp_fname = '.' . fname . '.swp' + call writefile([], fname) + call writefile([], swp_fname) + function s:swap_exists() + let v:swapchoice = s:swap_choice + endfunc + augroup test_window_cmd_wincmd_gf + autocmd! + exec "autocmd SwapExists " . fname . " call s:swap_exists()" + augroup END + + call setline(1, fname) + " (E)dit anyway + let s:swap_choice = 'e' + wincmd gf + call assert_equal(2, tabpagenr()) + call assert_equal(fname, bufname("%")) + quit! + + " (Q)uit + let s:swap_choice = 'q' + wincmd gf + call assert_equal(1, tabpagenr()) + call assert_notequal(fname, bufname("%")) + new | only! + + call delete(fname) + call delete(swp_fname) + augroup! test_window_cmd_wincmd_gf +endfunc + +func Test_window_quit() + e Xa + split Xb + call assert_equal(2, winnr('$')) + call assert_equal('Xb', bufname(winbufnr(1))) + call assert_equal('Xa', bufname(winbufnr(2))) + + wincmd q + call assert_equal(1, winnr('$')) + call assert_equal('Xa', bufname(winbufnr(1))) + + bw Xa Xb +endfunc + +func Test_window_horizontal_split() + call assert_equal(1, winnr('$')) + 3wincmd s + call assert_equal(2, winnr('$')) + call assert_equal(3, winheight(0)) + call assert_equal(winwidth(1), winwidth(2)) + + call assert_fails('botright topleft wincmd s', 'E442:') + bw +endfunc + +func Test_window_vertical_split() + call assert_equal(1, winnr('$')) + 3wincmd v + call assert_equal(2, winnr('$')) + call assert_equal(3, winwidth(0)) + call assert_equal(winheight(1), winheight(2)) + + call assert_fails('botright topleft wincmd v', 'E442:') + bw +endfunc + +" Test the ":wincmd ^" and "<C-W>^" commands. +func Test_window_split_edit_alternate() + + " Test for failure when the alternate buffer/file no longer exists. + edit Xfoo | %bw + call assert_fails(':wincmd ^', 'E23') + + " Test for the expected behavior when we have two named buffers. + edit Xfoo | edit Xbar + wincmd ^ + call assert_equal('Xfoo', bufname(winbufnr(1))) + call assert_equal('Xbar', bufname(winbufnr(2))) + only + + " Test for the expected behavior when the alternate buffer is not named. + enew | let l:nr1 = bufnr('%') + edit Xfoo | let l:nr2 = bufnr('%') + wincmd ^ + call assert_equal(l:nr1, winbufnr(1)) + call assert_equal(l:nr2, winbufnr(2)) + only + + " FIXME: this currently fails on AppVeyor, but passes locally + if !has('win32') + " Test the Normal mode command. + call feedkeys("\<C-W>\<C-^>", 'tx') + call assert_equal(l:nr2, winbufnr(1)) + call assert_equal(l:nr1, winbufnr(2)) + endif + + %bw! +endfunc + +" Test the ":[count]wincmd ^" and "[count]<C-W>^" commands. +func Test_window_split_edit_bufnr() + + %bwipeout + let l:nr = bufnr('%') + 1 + call assert_fails(':execute "normal! ' . l:nr . '\<C-W>\<C-^>"', 'E92') + call assert_fails(':' . l:nr . 'wincmd ^', 'E16') + call assert_fails(':0wincmd ^', 'E16') + + edit Xfoo | edit Xbar | edit Xbaz + let l:foo_nr = bufnr('Xfoo') + let l:bar_nr = bufnr('Xbar') + let l:baz_nr = bufnr('Xbaz') + + " FIXME: this currently fails on AppVeyor, but passes locally + if !has('win32') + call feedkeys(l:foo_nr . "\<C-W>\<C-^>", 'tx') + call assert_equal('Xfoo', bufname(winbufnr(1))) + call assert_equal('Xbaz', bufname(winbufnr(2))) + only + + call feedkeys(l:bar_nr . "\<C-W>\<C-^>", 'tx') + call assert_equal('Xbar', bufname(winbufnr(1))) + call assert_equal('Xfoo', bufname(winbufnr(2))) + only + + execute l:baz_nr . 'wincmd ^' + call assert_equal('Xbaz', bufname(winbufnr(1))) + call assert_equal('Xbar', bufname(winbufnr(2))) + endif + + %bw! +endfunc + +func Test_window_preview() + " Open a preview window + pedit Xa + call assert_equal(2, winnr('$')) + call assert_equal(0, &previewwindow) + + " Go to the preview window + wincmd P + call assert_equal(1, &previewwindow) + + " Close preview window + wincmd z + call assert_equal(1, winnr('$')) + call assert_equal(0, &previewwindow) + + call assert_fails('wincmd P', 'E441:') +endfunc + +func Test_window_exchange() + e Xa + + " Nothing happens with window exchange when there is 1 window + wincmd x + call assert_equal(1, winnr('$')) + + split Xb + split Xc + + call assert_equal('Xc', bufname(winbufnr(1))) + call assert_equal('Xb', bufname(winbufnr(2))) + call assert_equal('Xa', bufname(winbufnr(3))) + + " Exchange current window 1 with window 3 + 3wincmd x + call assert_equal('Xa', bufname(winbufnr(1))) + call assert_equal('Xb', bufname(winbufnr(2))) + call assert_equal('Xc', bufname(winbufnr(3))) + + " Exchange window with next when at the top window + wincmd x + call assert_equal('Xb', bufname(winbufnr(1))) + call assert_equal('Xa', bufname(winbufnr(2))) + call assert_equal('Xc', bufname(winbufnr(3))) + + " Exchange window with next when at the middle window + wincmd j + wincmd x + call assert_equal('Xb', bufname(winbufnr(1))) + call assert_equal('Xc', bufname(winbufnr(2))) + call assert_equal('Xa', bufname(winbufnr(3))) + + " Exchange window with next when at the bottom window. + " When there is no next window, it exchanges with the previous window. + wincmd j + wincmd x + call assert_equal('Xb', bufname(winbufnr(1))) + call assert_equal('Xa', bufname(winbufnr(2))) + call assert_equal('Xc', bufname(winbufnr(3))) + + bw Xa Xb Xc +endfunc + +func Test_window_rotate() + e Xa + split Xb + split Xc + call assert_equal('Xc', bufname(winbufnr(1))) + call assert_equal('Xb', bufname(winbufnr(2))) + call assert_equal('Xa', bufname(winbufnr(3))) + + " Rotate downwards + wincmd r + call assert_equal('Xa', bufname(winbufnr(1))) + call assert_equal('Xc', bufname(winbufnr(2))) + call assert_equal('Xb', bufname(winbufnr(3))) + + 2wincmd r + call assert_equal('Xc', bufname(winbufnr(1))) + call assert_equal('Xb', bufname(winbufnr(2))) + call assert_equal('Xa', bufname(winbufnr(3))) + + " Rotate upwards + wincmd R + call assert_equal('Xb', bufname(winbufnr(1))) + call assert_equal('Xa', bufname(winbufnr(2))) + call assert_equal('Xc', bufname(winbufnr(3))) + + 2wincmd R + call assert_equal('Xc', bufname(winbufnr(1))) + call assert_equal('Xb', bufname(winbufnr(2))) + call assert_equal('Xa', bufname(winbufnr(3))) + + bot vsplit + call assert_fails('wincmd R', 'E443:') + + bw Xa Xb Xc +endfunc + +func Test_window_height() + e Xa + split Xb + + let [wh1, wh2] = [winheight(1), winheight(2)] + " Active window (1) should have the same height or 1 more + " than the other window. + call assert_inrange(wh2, wh2 + 1, wh1) + + wincmd - + call assert_equal(wh1 - 1, winheight(1)) + call assert_equal(wh2 + 1, winheight(2)) + + wincmd + + call assert_equal(wh1, winheight(1)) + call assert_equal(wh2, winheight(2)) + + 2wincmd _ + call assert_equal(2, winheight(1)) + call assert_equal(wh1 + wh2 - 2, winheight(2)) + + wincmd = + call assert_equal(wh1, winheight(1)) + call assert_equal(wh2, winheight(2)) + + 2wincmd _ + set winfixheight + split Xc + let [wh1, wh2, wh3] = [winheight(1), winheight(2), winheight(3)] + call assert_equal(2, winheight(2)) + call assert_inrange(wh3, wh3 + 1, wh1) + 3wincmd + + call assert_equal(2, winheight(2)) + call assert_equal(wh1 + 3, winheight(1)) + call assert_equal(wh3 - 3, winheight(3)) + wincmd = + call assert_equal(2, winheight(2)) + call assert_equal(wh1, winheight(1)) + call assert_equal(wh3, winheight(3)) + + wincmd j + set winfixheight& + + wincmd = + let [wh1, wh2, wh3] = [winheight(1), winheight(2), winheight(3)] + " Current window (2) should have the same height or 1 more + " than the other windows. + call assert_inrange(wh1, wh1 + 1, wh2) + call assert_inrange(wh3, wh3 + 1, wh2) + + bw Xa Xb Xc +endfunc + +func Test_window_width() + e Xa + vsplit Xb + + let [ww1, ww2] = [winwidth(1), winwidth(2)] + " Active window (1) should have the same width or 1 more + " than the other window. + call assert_inrange(ww2, ww2 + 1, ww1) + + wincmd < + call assert_equal(ww1 - 1, winwidth(1)) + call assert_equal(ww2 + 1, winwidth(2)) + + wincmd > + call assert_equal(ww1, winwidth(1)) + call assert_equal(ww2, winwidth(2)) + + 2wincmd | + call assert_equal(2, winwidth(1)) + call assert_equal(ww1 + ww2 - 2, winwidth(2)) + + wincmd = + call assert_equal(ww1, winwidth(1)) + call assert_equal(ww2, winwidth(2)) + + 2wincmd | + set winfixwidth + vsplit Xc + let [ww1, ww2, ww3] = [winwidth(1), winwidth(2), winwidth(3)] + call assert_equal(2, winwidth(2)) + call assert_inrange(ww3, ww3 + 1, ww1) + 3wincmd > + call assert_equal(2, winwidth(2)) + call assert_equal(ww1 + 3, winwidth(1)) + call assert_equal(ww3 - 3, winwidth(3)) + wincmd = + call assert_equal(2, winwidth(2)) + call assert_equal(ww1, winwidth(1)) + call assert_equal(ww3, winwidth(3)) + + wincmd l + set winfixwidth& + + wincmd = + let [ww1, ww2, ww3] = [winwidth(1), winwidth(2), winwidth(3)] + " Current window (2) should have the same width or 1 more + " than the other windows. + call assert_inrange(ww1, ww1 + 1, ww2) + call assert_inrange(ww3, ww3 + 1, ww2) + + bw Xa Xb Xc +endfunc + +func Test_equalalways_on_close() + set equalalways + vsplit + windo split + split + wincmd J + " now we have a frame top-left with two windows, a frame top-right with two + " windows and a frame at the bottom, full-width. + let height_1 = winheight(1) + let height_2 = winheight(2) + let height_3 = winheight(3) + let height_4 = winheight(4) + " closing the bottom window causes all windows to be resized. + close + call assert_notequal(height_1, winheight(1)) + call assert_notequal(height_2, winheight(2)) + call assert_notequal(height_3, winheight(3)) + call assert_notequal(height_4, winheight(4)) + call assert_equal(winheight(1), winheight(3)) + call assert_equal(winheight(2), winheight(4)) + + 1wincmd w + split + 4wincmd w + resize + 5 + " left column has three windows, equalized heights. + " right column has two windows, top one a bit higher + let height_1 = winheight(1) + let height_2 = winheight(2) + let height_4 = winheight(4) + let height_5 = winheight(5) + 3wincmd w + " closing window in left column equalizes heights in left column but not in + " the right column + close + call assert_notequal(height_1, winheight(1)) + call assert_notequal(height_2, winheight(2)) + call assert_equal(height_4, winheight(3)) + call assert_equal(height_5, winheight(4)) + + only + set equalalways& +endfunc + +func Test_win_screenpos() + call assert_equal(1, winnr('$')) + split + vsplit + 10wincmd _ + 30wincmd | + call assert_equal([1, 1], win_screenpos(1)) + call assert_equal([1, 32], win_screenpos(2)) + call assert_equal([12, 1], win_screenpos(3)) + call assert_equal([0, 0], win_screenpos(4)) + only +endfunc + +func Test_window_jump_tag() + help + /iccf + call assert_match('^|iccf|', getline('.')) + call assert_equal(2, winnr('$')) + 2wincmd } + call assert_equal(3, winnr('$')) + call assert_match('^|iccf|', getline('.')) + wincmd k + call assert_match('\*iccf\*', getline('.')) + call assert_equal(2, winheight(0)) + + wincmd z + set previewheight=4 + help + /bugs + wincmd } + wincmd k + call assert_match('\*bugs\*', getline('.')) + call assert_equal(4, winheight(0)) + set previewheight& + + %bw! +endfunc + +func Test_window_newtab() + e Xa + + call assert_equal(1, tabpagenr('$')) + call assert_equal("\nAlready only one window", execute('wincmd T')) + + split Xb + split Xc + + wincmd T + call assert_equal(2, tabpagenr('$')) + call assert_equal(['Xb', 'Xa'], map(tabpagebuflist(1), 'bufname(v:val)')) + call assert_equal(['Xc' ], map(tabpagebuflist(2), 'bufname(v:val)')) + + %bw! +endfunc + +func Test_next_split_all() + " This was causing an illegal memory access. + n x + norm axxx + split + split + s/x + s/x + all + bwipe! +endfunc + +" Tests for adjusting window and contents +func GetScreenStr(row) + let str = "" + for c in range(1,3) + let str .= nr2char(screenchar(a:row, c)) + endfor + return str +endfunc + +func Test_window_contents() + enew! | only | new + call setline(1, range(1,256)) + + exe "norm! \<C-W>t\<C-W>=1Gzt\<C-W>w\<C-W>+" + redraw + let s3 = GetScreenStr(1) + wincmd p + call assert_equal(1, line("w0")) + call assert_equal('1 ', s3) + + exe "norm! \<C-W>t\<C-W>=50Gzt\<C-W>w\<C-W>+" + redraw + let s3 = GetScreenStr(1) + wincmd p + call assert_equal(50, line("w0")) + call assert_equal('50 ', s3) + + exe "norm! \<C-W>t\<C-W>=59Gzt\<C-W>w\<C-W>+" + redraw + let s3 = GetScreenStr(1) + wincmd p + call assert_equal(59, line("w0")) + call assert_equal('59 ', s3) + + bwipeout! + call test_garbagecollect_now() +endfunc + +func Test_window_colon_command() + " This was reading invalid memory. + exe "norm! v\<C-W>:\<C-U>echo v:version" +endfunc + +func Test_access_freed_mem() + " This was accessing freed memory + au * 0 vs xxx + arg 0 + argadd + all + all + au! + bwipe xxx +endfunc + +func Test_visual_cleared_after_window_split() + new | only! + let smd_save = &showmode + set showmode + let ls_save = &laststatus + set laststatus=1 + call setline(1, ['a', 'b', 'c', 'd', '']) + norm! G + exe "norm! kkvk" + redraw + exe "norm! \<C-W>v" + redraw + " check if '-- VISUAL --' disappeared from command line + let columns = range(1, &columns) + let cmdlinechars = map(columns, 'nr2char(screenchar(&lines, v:val))') + let cmdline = join(cmdlinechars, '') + let cmdline_ltrim = substitute(cmdline, '^\s*', "", "") + let mode_shown = substitute(cmdline_ltrim, '\s*$', "", "") + call assert_equal('', mode_shown) + let &showmode = smd_save + let &laststatus = ls_save + bwipe! +endfunc + +func Test_winrestcmd() + 2split + 3vsplit + let a = winrestcmd() + call assert_equal(2, winheight(0)) + call assert_equal(3, winwidth(0)) + wincmd = + call assert_notequal(2, winheight(0)) + call assert_notequal(3, winwidth(0)) + exe a + call assert_equal(2, winheight(0)) + call assert_equal(3, winwidth(0)) + only +endfunc + +func Fun_RenewFile() + sleep 2 + silent execute '!echo "1" > tmp.txt' + sp + wincmd p + edit! tmp.txt +endfunc + +func Test_window_prevwin() + " Can we make this work on MS-Windows? + if !has('unix') + return + endif + + set hidden autoread + call writefile(['2'], 'tmp.txt') + new tmp.txt + q + " Need to wait a bit for the timestamp to be older. + call Fun_RenewFile() + call assert_equal(2, winnr()) + wincmd p + call assert_equal(1, winnr()) + wincmd p + q + call Fun_RenewFile() + call assert_equal(2, winnr()) + wincmd p + call assert_equal(1, winnr()) + wincmd p + " reset + q + call delete('tmp.txt') + set hidden&vim autoread&vim + delfunc Fun_RenewFile +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_window_id.vim b/src/testdir/test_window_id.vim new file mode 100644 index 0000000..d10d831 --- /dev/null +++ b/src/testdir/test_window_id.vim @@ -0,0 +1,123 @@ +" Test using the window ID. + +func Test_win_getid() + edit one + let id1 = win_getid() + let w:one = 'one' + split two + let id2 = win_getid() + let bufnr2 = bufnr('%') + let w:two = 'two' + split three + let id3 = win_getid() + let w:three = 'three' + tabnew + edit four + let id4 = win_getid() + let w:four = 'four' + split five + let id5 = win_getid() + let bufnr5 = bufnr('%') + let w:five = 'five' + tabnext + + wincmd w + call assert_equal("two", expand("%")) + call assert_equal(id2, win_getid()) + let nr2 = winnr() + wincmd w + call assert_equal("one", expand("%")) + call assert_equal(id1, win_getid()) + let nr1 = winnr() + wincmd w + call assert_equal("three", expand("%")) + call assert_equal(id3, win_getid()) + let nr3 = winnr() + call assert_equal('one', getwinvar(id1, 'one')) + call assert_equal('two', getwinvar(id2, 'two')) + call assert_equal('three', getwinvar(id3, 'three')) + tabnext + call assert_equal("five", expand("%")) + call assert_equal(id5, win_getid()) + let nr5 = winnr() + wincmd w + call assert_equal("four", expand("%")) + call assert_equal(id4, win_getid()) + let nr4 = winnr() + call assert_equal('four', getwinvar(id4, 'four')) + call assert_equal('five', getwinvar(id5, 'five')) + call settabwinvar(1, id2, 'two', '2') + call setwinvar(id4, 'four', '4') + tabnext + call assert_equal('4', gettabwinvar(2, id4, 'four')) + call assert_equal('five', gettabwinvar(2, id5, 'five')) + call assert_equal('2', getwinvar(id2, 'two')) + + exe nr1 . "wincmd w" + call assert_equal(id1, win_getid()) + exe nr2 . "wincmd w" + call assert_equal(id2, win_getid()) + exe nr3 . "wincmd w" + call assert_equal(id3, win_getid()) + tabnext + exe nr4 . "wincmd w" + call assert_equal(id4, win_getid()) + exe nr5 . "wincmd w" + call assert_equal(id5, win_getid()) + + call win_gotoid(id2) + call assert_equal("two", expand("%")) + call win_gotoid(id4) + call assert_equal("four", expand("%")) + call win_gotoid(id1) + call assert_equal("one", expand("%")) + call win_gotoid(id5) + call assert_equal("five", expand("%")) + + call assert_equal(0, win_id2win(9999)) + call assert_equal(nr5, win_id2win(id5)) + call assert_equal(0, win_id2win(id1)) + tabnext + call assert_equal(nr1, win_id2win(id1)) + + call assert_equal([0, 0], win_id2tabwin(9999)) + call assert_equal([1, nr2], win_id2tabwin(id2)) + call assert_equal([2, nr4], win_id2tabwin(id4)) + + call assert_equal([], win_findbuf(9999)) + call assert_equal([id2], win_findbuf(bufnr2)) + call win_gotoid(id5) + split + call assert_equal(sort([id5, win_getid()]), sort(win_findbuf(bufnr5))) + + only! +endfunc + +func Test_win_getid_curtab() + tabedit X + tabfirst + copen + only + call assert_equal(win_getid(1), win_getid(1, 1)) + tabclose! +endfunc + +func Test_winlayout() + let w1 = win_getid() + call assert_equal(['leaf', w1], winlayout()) + + split + let w2 = win_getid() + call assert_equal(['col', [['leaf', w2], ['leaf', w1]]], winlayout()) + + split + let w3 = win_getid() + call assert_equal(['col', [['leaf', w3], ['leaf', w2], ['leaf', w1]]], winlayout()) + + 2wincmd w + vsplit + let w4 = win_getid() + call assert_equal(['col', [['leaf', w3], ['row', [['leaf', w4], ['leaf', w2]]], ['leaf', w1]]], winlayout()) + + only! +endfunc diff --git a/src/testdir/test_windows_home.vim b/src/testdir/test_windows_home.vim new file mode 100644 index 0000000..2e311b9 --- /dev/null +++ b/src/testdir/test_windows_home.vim @@ -0,0 +1,121 @@ +" Test for $HOME on Windows. + +if !has('win32') + finish +endif + +let s:env = {} + +func s:restore_env() + for i in keys(s:env) + exe 'let ' . i . '=s:env["' . i . '"]' + endfor +endfunc + +func s:save_env(...) + for i in a:000 + exe 'let s:env["' . i . '"]=' . i + endfor +endfunc + +func s:unlet_env(...) + for i in a:000 + exe 'let ' . i . '=""' + endfor +endfunc + +func CheckHomeIsMissingFromSubprocessEnvironment() + silent! let out = system('set') + let env = filter(split(out, "\n"), 'v:val=~"^HOME="') + call assert_equal(0, len(env)) +endfunc + +func CheckHomeIsInSubprocessEnvironment(exp) + silent! let out = system('set') + let env = filter(split(out, "\n"), 'v:val=~"^HOME="') + let home = len(env) == 0 ? "" : substitute(env[0], '[^=]\+=', '', '') + call assert_equal(a:exp, home) +endfunc + +func CheckHome(exp, ...) + call assert_equal(a:exp, $HOME) + call assert_equal(a:exp, expand('~', ':p')) + if !a:0 + call CheckHomeIsMissingFromSubprocessEnvironment() + else + call CheckHomeIsInSubprocessEnvironment(a:1) + endif +endfunc + +func Test_WindowsHome() + command! -nargs=* SaveEnv call <SID>save_env(<f-args>) + command! -nargs=* RestoreEnv call <SID>restore_env() + command! -nargs=* UnletEnv call <SID>unlet_env(<f-args>) + set noshellslash + + let save_home = $HOME + SaveEnv $USERPROFILE $HOMEDRIVE $HOMEPATH + try + " Normal behavior: use $HOMEDRIVE and $HOMEPATH, ignore $USERPROFILE + let $USERPROFILE = 'unused' + let $HOMEDRIVE = 'C:' + let $HOMEPATH = '\foobar' + let $HOME = '' " Force recomputing "homedir" + call CheckHome('C:\foobar') + + " Same, but with $HOMEPATH not set + UnletEnv $HOMEPATH + let $HOME = '' " Force recomputing "homedir" + call CheckHome('C:\') + + " Use $USERPROFILE if $HOMEPATH and $HOMEDRIVE are empty + UnletEnv $HOMEDRIVE $HOMEPATH + let $USERPROFILE = 'C:\foo' + let $HOME = '' " Force recomputing "homedir" + call CheckHome('C:\foo') + + " If $HOME is set the others don't matter + let $HOME = 'C:\bar' + let $USERPROFILE = 'unused' + let $HOMEDRIVE = 'unused' + let $HOMEPATH = 'unused' + call CheckHome('C:\bar', 'C:\bar') + + " If $HOME contains %USERPROFILE% it is expanded + let $USERPROFILE = 'C:\foo' + let $HOME = '%USERPROFILE%\bar' + let $HOMEDRIVE = 'unused' + let $HOMEPATH = 'unused' + call CheckHome('C:\foo\bar', '%USERPROFILE%\bar') + + " Invalid $HOME is kept + let $USERPROFILE = 'C:\foo' + let $HOME = '%USERPROFILE' + let $HOMEDRIVE = 'unused' + let $HOMEPATH = 'unused' + call CheckHome('%USERPROFILE', '%USERPROFILE') + + " %USERPROFILE% not at start of $HOME is not expanded + let $USERPROFILE = 'unused' + let $HOME = 'C:\%USERPROFILE%' + let $HOMEDRIVE = 'unused' + let $HOMEPATH = 'unused' + call CheckHome('C:\%USERPROFILE%', 'C:\%USERPROFILE%') + + if has('channel') + RestoreEnv + let $HOME = save_home + let env = '' + let job = job_start('cmd /c set', {'out_cb': {ch,x->[env,execute('let env=x')]}}) + sleep 1 + let env = filter(split(env, "\n"), 'v:val=="HOME"') + let home = len(env) == 0 ? "" : env[0] + call assert_equal('', home) + endif + finally + RestoreEnv + delcommand SaveEnv + delcommand RestoreEnv + delcommand UnletEnv + endtry +endfunc diff --git a/src/testdir/test_wordcount.vim b/src/testdir/test_wordcount.vim new file mode 100644 index 0000000..6a3d410 --- /dev/null +++ b/src/testdir/test_wordcount.vim @@ -0,0 +1,104 @@ +" Test for wordcount() function + +func Test_wordcount() + let save_enc = &enc + set encoding=utf-8 + set selection=inclusive fileformat=unix fileformats=unix + + new + + " Test 1: empty window + call assert_equal({'chars': 0, 'cursor_chars': 0, 'words': 0, 'cursor_words': 0, + \ 'bytes': 0, 'cursor_bytes': 0}, wordcount()) + + " Test 2: some words, cursor at start + call append(1, 'one two three') + call cursor([1, 1, 0]) + call assert_equal({'chars': 15, 'cursor_chars': 1, 'words': 3, 'cursor_words': 0, + \ 'bytes': 15, 'cursor_bytes': 1}, wordcount()) + + " Test 3: some words, cursor at end + %d _ + call append(1, 'one two three') + call cursor([2, 99, 0]) + call assert_equal({'chars': 15, 'cursor_chars': 14, 'words': 3, 'cursor_words': 3, + \ 'bytes': 15, 'cursor_bytes': 14}, wordcount()) + + " Test 4: some words, cursor at end, ve=all + set ve=all + %d _ + call append(1, 'one two three') + call cursor([2, 99, 0]) + call assert_equal({'chars': 15, 'cursor_chars': 15, 'words': 3, 'cursor_words': 3, + \ 'bytes': 15, 'cursor_bytes': 15}, wordcount()) + set ve= + + " Test 5: several lines with words + %d _ + call append(1, ['one two three', 'one two three', 'one two three']) + call cursor([4, 99, 0]) + call assert_equal({'chars': 43, 'cursor_chars': 42, 'words': 9, 'cursor_words': 9, + \ 'bytes': 43, 'cursor_bytes': 42}, wordcount()) + + " Test 6: one line with BOM set + %d _ + call append(1, 'one two three') + set bomb + w! Xtest + call cursor([2, 99, 0]) + call assert_equal({'chars': 15, 'cursor_chars': 14, 'words': 3, 'cursor_words': 3, + \ 'bytes': 18, 'cursor_bytes': 14}, wordcount()) + set nobomb + w! + call delete('Xtest') + + " Test 7: one line with multibyte words + %d _ + call append(1, ['Äne M¤ne Müh']) + call cursor([2, 99, 0]) + call assert_equal({'chars': 14, 'cursor_chars': 13, 'words': 3, 'cursor_words': 3, + \ 'bytes': 17, 'cursor_bytes': 16}, wordcount()) + + " Test 8: several lines with multibyte words + %d _ + call append(1, ['Äne M¤ne Müh', 'und raus bist dü!']) + call cursor([3, 99, 0]) + call assert_equal({'chars': 32, 'cursor_chars': 31, 'words': 7, 'cursor_words': 7, + \ 'bytes': 36, 'cursor_bytes': 35}, wordcount()) + + " Visual map to capture wordcount() in visual mode + vnoremap <expr> <F2> execute("let g:visual_stat = wordcount()") + + " Test 9: visual mode, complete buffer + let g:visual_stat = {} + %d _ + call append(1, ['Äne M¤ne Müh', 'und raus bist dü!']) + " start visual mode and select the complete buffer + 0 + exe "normal V2j\<F2>y" + call assert_equal({'chars': 32, 'words': 7, 'bytes': 36, 'visual_chars': 32, + \ 'visual_words': 7, 'visual_bytes': 36}, g:visual_stat) + + " Test 10: visual mode (empty) + %d _ + call append(1, ['Äne M¤ne Müh', 'und raus bist dü!']) + " start visual mode and select the complete buffer + 0 + exe "normal v$\<F2>y" + call assert_equal({'chars': 32, 'words': 7, 'bytes': 36, 'visual_chars': 1, + \ 'visual_words': 0, 'visual_bytes': 1}, g:visual_stat) + + " Test 11: visual mode, single line + %d _ + call append(1, ['Äne M¤ne Müh', 'und raus bist dü!']) + " start visual mode and select the complete buffer + 2 + exe "normal 0v$\<F2>y" + call assert_equal({'chars': 32, 'words': 7, 'bytes': 36, 'visual_chars': 13, + \ 'visual_words': 3, 'visual_bytes': 16}, g:visual_stat) + + set selection& fileformat& fileformats& + let &enc = save_enc + enew! + close +endfunc diff --git a/src/testdir/test_writefile.vim b/src/testdir/test_writefile.vim new file mode 100644 index 0000000..ff36756 --- /dev/null +++ b/src/testdir/test_writefile.vim @@ -0,0 +1,152 @@ +" Tests for the writefile() function. + +func Test_writefile() + let f = tempname() + call writefile(["over","written"], f, "b") + call writefile(["hello","world"], f, "b") + call writefile(["!", "good"], f, "a") + call writefile(["morning"], f, "ab") + call writefile(["", "vimmers"], f, "ab") + let l = readfile(f) + call assert_equal("hello", l[0]) + call assert_equal("world!", l[1]) + call assert_equal("good", l[2]) + call assert_equal("morning", l[3]) + call assert_equal("vimmers", l[4]) + call delete(f) +endfunc + +func Test_writefile_fails_gently() + call assert_fails('call writefile(["test"], "Xfile", [])', 'E730:') + call assert_false(filereadable("Xfile")) + call delete("Xfile") + + call assert_fails('call writefile(["test", [], [], [], "tset"], "Xfile")', 'E730:') + call assert_false(filereadable("Xfile")) + call delete("Xfile") + + call assert_fails('call writefile([], "Xfile", [])', 'E730:') + call assert_false(filereadable("Xfile")) + call delete("Xfile") + + call assert_fails('call writefile([], [])', 'E730:') +endfunc + +func Test_writefile_fails_conversion() + if !has('iconv') || has('sun') + return + endif + set nobackup nowritebackup + new + let contents = ["line one", "line two"] + call writefile(contents, 'Xfile') + edit Xfile + call setline(1, ["first line", "cannot convert \u010b", "third line"]) + call assert_fails('write ++enc=cp932') + call assert_equal(contents, readfile('Xfile')) + + call delete('Xfile') + bwipe! + set backup& writebackup& +endfunc + +func SetFlag(timer) + let g:flag = 1 +endfunc + +func Test_write_quit_split() + " Prevent exiting by splitting window on file write. + augroup testgroup + autocmd BufWritePre * split + augroup END + e! Xfile + call setline(1, 'nothing') + wq + + if has('timers') + " timer will not run if "exiting" is still set + let g:flag = 0 + call timer_start(1, 'SetFlag') + sleep 50m + call assert_equal(1, g:flag) + unlet g:flag + endif + au! testgroup + bwipe Xfile + call delete('Xfile') +endfunc + +func Test_nowrite_quit_split() + " Prevent exiting by opening a help window. + e! Xfile + help + wincmd w + exe winnr() . 'q' + + if has('timers') + " timer will not run if "exiting" is still set + let g:flag = 0 + call timer_start(1, 'SetFlag') + sleep 50m + call assert_equal(1, g:flag) + unlet g:flag + endif + bwipe Xfile +endfunc + +func Test_writefile_sync_arg() + " This doesn't check if fsync() works, only that the argument is accepted. + call writefile(['one'], 'Xtest', 's') + call writefile(['two'], 'Xtest', 'S') + call delete('Xtest') +endfunc + +func Test_writefile_sync_dev_stdout() + if !has('unix') + return + endif + if filewritable('/dev/stdout') + " Just check that this doesn't cause an error. + call writefile(['one'], '/dev/stdout') + else + throw 'Skipped: /dev/stdout is not writable' + endif +endfunc + +func Test_writefile_autowrite() + set autowrite + new + next Xa Xb Xc + call setline(1, 'aaa') + next + call assert_equal(['aaa'], readfile('Xa')) + call setline(1, 'bbb') + call assert_fails('edit XX') + call assert_false(filereadable('Xb')) + + set autowriteall + edit XX + call assert_equal(['bbb'], readfile('Xb')) + + bwipe! + call delete('Xa') + call delete('Xb') + set noautowrite +endfunc + +func Test_writefile_autowrite_nowrite() + set autowrite + new + next Xa Xb Xc + set buftype=nowrite + call setline(1, 'aaa') + let buf = bufnr('%') + " buffer contents silently lost + edit XX + call assert_false(filereadable('Xa')) + rewind + call assert_equal('', getline(1)) + + bwipe! + set noautowrite +endfunc diff --git a/src/testdir/test_xxd.vim b/src/testdir/test_xxd.vim new file mode 100644 index 0000000..e4e7755 --- /dev/null +++ b/src/testdir/test_xxd.vim @@ -0,0 +1,183 @@ +" Test for the xxd command +if empty($XXD) && executable('..\xxd\xxd.exe') + let s:xxd_cmd = '..\xxd\xxd.exe' +elseif empty($XXD) || !executable($XXD) + finish +else + let s:xxd_cmd = $XXD +endif + +func PrepareBuffer(lines) + new + call append(0, a:lines) + $d +endfunc + +func s:Mess(counter) + return printf("Failed xxd test %d:", a:counter) +endfunc + +func Test_xxd() + call PrepareBuffer(range(1,30)) + set ff=unix + w! XXDfile + + " Test 1: simple, filter the result through xxd + let s:test = 1 + exe '%!' . s:xxd_cmd . ' %' + let expected = [ + \ '00000000: 310a 320a 330a 340a 350a 360a 370a 380a 1.2.3.4.5.6.7.8.', + \ '00000010: 390a 3130 0a31 310a 3132 0a31 330a 3134 9.10.11.12.13.14', + \ '00000020: 0a31 350a 3136 0a31 370a 3138 0a31 390a .15.16.17.18.19.', + \ '00000030: 3230 0a32 310a 3232 0a32 330a 3234 0a32 20.21.22.23.24.2', + \ '00000040: 350a 3236 0a32 370a 3238 0a32 390a 3330 5.26.27.28.29.30', + \ '00000050: 0a .'] + call assert_equal(expected, getline(1,'$'), s:Mess(s:test)) + + " Test 2: reverse the result + let s:test += 1 + exe '%!' . s:xxd_cmd . ' -r' + call assert_equal(map(range(1,30), {v,c -> string(c)}), getline(1,'$'), s:Mess(s:test)) + + " Test 3: Skip the first 0x30 bytes + let s:test += 1 + for arg in ['-s 0x30', '-s0x30', '-s+0x30', '-skip 0x030', '-seek 0x30', '-seek +0x30 --'] + exe '%!' . s:xxd_cmd . ' ' . arg . ' %' + call assert_equal(expected[3:], getline(1,'$'), s:Mess(s:test)) + endfor + + " Test 4: Skip the first 30 bytes + let s:test += 1 + for arg in ['-s -0x31', '-s-0x31'] + exe '%!' . s:xxd_cmd . ' ' . arg . ' %' + call assert_equal(expected[2:], getline(1,'$'), s:Mess(s:test)) + endfor + + " The following tests use the xxd man page. + " For these tests to pass, the fileformat must be "unix". + let man_copy = 'Xxd.1' + let man_page = '../../runtime/doc/xxd.1' + if has('win32') && !filereadable(man_page) + let man_page = '../../doc/xxd.1' + endif + %d + exe '0r ' man_page '| set ff=unix | $d | w' man_copy '| bwipe!' man_copy + + " Test 5: Print 120 bytes as continuous hexdump with 20 octets per line + let s:test += 1 + %d + exe '0r! ' . s:xxd_cmd . ' -l 120 -ps -c20 ' . man_copy + $d + let expected = [ + \ '2e54482058584420312022417567757374203139', + \ '39362220224d616e75616c207061676520666f72', + \ '20787864220a2e5c220a2e5c222032317374204d', + \ '617920313939360a2e5c22204d616e2070616765', + \ '20617574686f723a0a2e5c2220202020546f6e79', + \ '204e7567656e74203c746f6e79407363746e7567'] + call assert_equal(expected, getline(1,'$'), s:Mess(s:test)) + + " Test 6: Print the date from xxd.1 + let s:test += 1 + for arg in ['-l 13', '-l13', '-len 13'] + %d + exe '0r! ' . s:xxd_cmd . ' -s 0x36 ' . arg . ' -cols 13 ' . man_copy + $d + call assert_equal('00000036: 3231 7374 204d 6179 2031 3939 36 21st May 1996', getline(1), s:Mess(s:test)) + endfor + + " Cleanup after tests 5 and 6 + call delete(man_copy) + + " Test 7: Print C include + let s:test += 1 + call writefile(['TESTabcd09'], 'XXDfile') + %d + exe '0r! ' . s:xxd_cmd . ' -i XXDfile' + $d + let expected = ['unsigned char XXDfile[] = {', + \ ' 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a', '};', + \ 'unsigned int XXDfile_len = 11;'] + call assert_equal(expected, getline(1,'$'), s:Mess(s:test)) + + " Test 8: Print C include capitalized + let s:test += 1 + for arg in ['-C', '-capitalize'] + call writefile(['TESTabcd09'], 'XXDfile') + %d + exe '0r! ' . s:xxd_cmd . ' -i ' . arg . ' XXDfile' + $d + let expected = ['unsigned char XXDFILE[] = {', + \ ' 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a', '};', + \ 'unsigned int XXDFILE_LEN = 11;'] + call assert_equal(expected, getline(1,'$'), s:Mess(s:test)) + endfor + + " Test 9: Create a file with containing a single 'A' + let s:test += 1 + call delete('XXDfile') + bwipe! XXDfile + if has('unix') + call system('echo "010000: 41"|' . s:xxd_cmd . ' -r -s -0x10000 > XXDfile') + else + call writefile(['010000: 41'], 'Xinput') + silent exe '!' . s:xxd_cmd . ' -r -s -0x10000 < Xinput > XXDfile' + call delete('Xinput') + endif + call PrepareBuffer(readfile('XXDfile')[0]) + call assert_equal('A', getline(1), s:Mess(s:test)) + call delete('XXDfile') + + " Test 10: group with 4 octets + let s:test += 1 + for arg in ['-g 4', '-group 4', '-g4'] + call writefile(['TESTabcd09'], 'XXDfile') + %d + exe '0r! ' . s:xxd_cmd . ' ' . arg . ' XXDfile' + $d + let expected = ['00000000: 54455354 61626364 30390a TESTabcd09.'] + call assert_equal(expected, getline(1,'$'), s:Mess(s:test)) + call delete('XXDfile') + endfor + + " Test 11: reverse with CR, hex upper, Postscript style with a TAB + let s:test += 1 + call writefile([" 54455354\t610B6364 30390A TESTa\0x0bcd09.\r"], 'Xinput') + silent exe '!' . s:xxd_cmd . ' -r -p < Xinput > XXDfile' + let blob = readfile('XXDfile', 'B') + call assert_equal(0z54455354.610B6364.30390A, blob) + call delete('Xinput') + call delete('XXDfile') + + " Test 12: reverse with seek + let s:test += 1 + call writefile(["00000000: 54455354\t610B6364 30390A TESTa\0x0bcd09.\r"], 'Xinput') + silent exe '!' . s:xxd_cmd . ' -r -seek 5 < Xinput > XXDfile' + let blob = readfile('XXDfile', 'B') + call assert_equal(0z0000000000.54455354.610B6364.30390A, blob) + call delete('Xinput') + call delete('XXDfile') + + " TODO: + " -o -offset + + %d + bw! +endfunc + +" Various ways with wrong arguments that trigger the usage output. +func Test_xxd_usage() + for arg in ['-c', '-g', '-o', '-s', '-l', '-X', 'one two three'] + new + exe 'r! ' . s:xxd_cmd . ' ' . arg + call assert_match("Usage:", join(getline(1, 3))) + bwipe! + endfor +endfunc + +func Test_xxd_version() + new + exe 'r! ' . s:xxd_cmd . ' -v' + call assert_match("xxd V1.10 .* by Juergen Weigert", join(getline(1, 3))) + bwipe! +endfunc diff --git a/src/testdir/unix.vim b/src/testdir/unix.vim new file mode 100644 index 0000000..b82c63c --- /dev/null +++ b/src/testdir/unix.vim @@ -0,0 +1,13 @@ +" Settings for test script execution +" Always use "sh", don't use the value of "$SHELL". +set shell=sh + +" Only when the +eval feature is present. +if 1 + " While some tests overwrite $HOME to prevent them from polluting user files, + " we need to remember the original value so that we can tell external systems + " where to ask about their own user settings. + let g:tester_HOME = $HOME +endif + +source setup.vim diff --git a/src/testdir/view_util.vim b/src/testdir/view_util.vim new file mode 100644 index 0000000..29ea073 --- /dev/null +++ b/src/testdir/view_util.vim @@ -0,0 +1,51 @@ +" Functions about view shared by several tests + +" Only load this script once. +if exists('*ScreenLines') + finish +endif + +" ScreenLines(lnum, width) or +" ScreenLines([start, end], width) +function! ScreenLines(lnum, width) abort + redraw! + if type(a:lnum) == v:t_list + let start = a:lnum[0] + let end = a:lnum[1] + else + let start = a:lnum + let end = a:lnum + endif + let lines = [] + for l in range(start, end) + let lines += [join(map(range(1, a:width), 'nr2char(screenchar(l, v:val))'), '')] + endfor + return lines +endfunction + +function! ScreenAttrs(lnum, width) abort + redraw! + if type(a:lnum) == v:t_list + let start = a:lnum[0] + let end = a:lnum[1] + else + let start = a:lnum + let end = a:lnum + endif + let attrs = [] + for l in range(start, end) + let attrs += [map(range(1, a:width), 'screenattr(l, v:val)')] + endfor + return attrs +endfunction + +function! NewWindow(height, width) abort + exe a:height . 'new' + exe a:width . 'vsp' + redraw! +endfunction + +function! CloseWindow() abort + bw! + redraw! +endfunction diff --git a/src/testdir/vms.vim b/src/testdir/vms.vim new file mode 100644 index 0000000..64b390e --- /dev/null +++ b/src/testdir/vms.vim @@ -0,0 +1,6 @@ +" Settings for test script execution under OpenVMS + +" Do not use any swap files +set noswapfile + +source setup.vim |