Bram Moolenaar | 5374430 | 2015-07-17 17:38:22 +0200 | [diff] [blame^] | 1 | Test for option autocommand |
| 2 | |
| 3 | STARTTEST |
| 4 | :so small.vim |
| 5 | :if !has("eval") || !has("autocmd") | e! test.ok | w! test.out | qa! | endif |
| 6 | :fu! AutoCommand(match) |
| 7 | : let c=g:testcase |
| 8 | : let item=remove(g:options, 0) |
| 9 | : let c.=printf("Expected: Name: <%s>, Oldval: <%s>, NewVal: <%s>, Scope: <%s>\n", item[0], item[1], item[2], item[3]) |
| 10 | : let c.=printf("Autocmd Option: <%s>,", a:match) |
| 11 | : let c.=printf(" OldVal: <%s>,", v:option_old) |
| 12 | : let c.=printf(" NewVal: <%s>,", v:option_new) |
| 13 | : let c.=printf(" Scope: <%s>\n", v:option_type) |
| 14 | : call setreg('r', printf("%s\n%s", getreg('r'), c)) |
| 15 | :endfu |
| 16 | :au OptionSet * :call AutoCommand(expand("<amatch>")) |
| 17 | :let g:testcase="1: Setting number option\n" |
| 18 | :let g:options=[['number', 0, 1, 'global']] |
| 19 | :set nu |
| 20 | :let g:testcase="2: Setting local number option\n" |
| 21 | :let g:options=[['number', 1, 0, 'local']] |
| 22 | :setlocal nonu |
| 23 | :let g:testcase="3: Setting global number option\n" |
| 24 | :let g:options=[['number', 1, 0, 'global']] |
| 25 | :setglobal nonu |
| 26 | :let g:testcase="4: Setting local autoindent option\n" |
| 27 | :let g:options=[['autoindent', 0, 1, 'local']] |
| 28 | :setlocal ai |
| 29 | :let g:testcase="5: Setting global autoindent option\n" |
| 30 | :let g:options=[['autoindent', 0, 1, 'global']] |
| 31 | :setglobal ai |
| 32 | :let g:testcase="6: Setting global autoindent option\n" |
| 33 | :let g:options=[['autoindent', 1, 0, 'global']] |
| 34 | :set ai! |
| 35 | : Should not print anything, use :noa |
| 36 | :noa :set nonu |
| 37 | :let g:testcase="7: Setting several global list and number option\n" |
| 38 | :let g:options=[['list', 0, 1, 'global'], ['number', 0, 1, 'global']] |
| 39 | :set list nu |
| 40 | :noa set nolist nonu |
| 41 | :let g:testcase="8: Setting global acd\n" |
| 42 | :let g:options=[['autochdir', 0, 1, 'global']] |
| 43 | :setlocal acd |
| 44 | :let g:testcase="9: Setting global autoread\n" |
| 45 | :let g:options=[['autoread', 0, 1, 'global']] |
| 46 | :set ar |
| 47 | :let g:testcase="10: Setting local autoread\n" |
| 48 | :let g:options=[['autoread', 0, 1, 'local']] |
| 49 | :setlocal ar |
| 50 | :let g:testcase="11: Setting global autoread\n" |
| 51 | :let g:options=[['autoread', 1, 0, 'global']] |
| 52 | :setglobal invar |
| 53 | :let g:testcase="12: Setting option backspace through :let\n" |
| 54 | :let g:options=[['backspace', '', 'eol,indent,start', 'global']] |
| 55 | :let &bs="eol,indent,start" |
| 56 | :let g:testcase="13: Setting option backspace through setbufvar()\n" |
| 57 | :let g:options=[['backup', '', '1', 'local']] |
| 58 | : "try twice, first time, shouldn't trigger because option name is invalid, second time, it should trigger |
| 59 | :call setbufvar(1, '&l:bk', 1) |
| 60 | : "should trigger, use correct option name |
| 61 | :call setbufvar(1, '&backup', 1) |
| 62 | :" Write register now, because next test shouldn't output anything. |
| 63 | :$put r |
| 64 | :let @r='' |
| 65 | :let g:testcase="\n14: Setting key option, shouldn't trigger\n" |
| 66 | :let g:options=[['key', 'invalid', 'invalid1', 'invalid']] |
| 67 | :setlocal key=blah |
| 68 | :setlocal key= |
| 69 | :$put =g:testcase |
| 70 | :%w! test.out |
| 71 | :qa! |
| 72 | ENDTEST |
| 73 | dummy text |
| 74 | |
| 75 | 1: Setting number option |
| 76 | Expected: Name: <number>, Oldval: <0>, NewVal: <1>, Scope: <global> |
| 77 | Autocmd Option: <number>, OldVal: <0>, NewVal: <1>, Scope: <global> |
| 78 | |
| 79 | 2: Setting local number option |
| 80 | Expected: Name: <number>, Oldval: <1>, NewVal: <0>, Scope: <local> |
| 81 | Autocmd Option: <number>, OldVal: <1>, NewVal: <0>, Scope: <local> |
| 82 | |
| 83 | 3: Setting global number option |
| 84 | Expected: Name: <number>, Oldval: <1>, NewVal: <0>, Scope: <global> |
| 85 | Autocmd Option: <number>, OldVal: <1>, NewVal: <0>, Scope: <global> |
| 86 | |
| 87 | 4: Setting local autoindent option |
| 88 | Expected: Name: <autoindent>, Oldval: <0>, NewVal: <1>, Scope: <local> |
| 89 | Autocmd Option: <autoindent>, OldVal: <0>, NewVal: <1>, Scope: <local> |
| 90 | |
| 91 | 5: Setting global autoindent option |
| 92 | Expected: Name: <autoindent>, Oldval: <0>, NewVal: <1>, Scope: <global> |
| 93 | Autocmd Option: <autoindent>, OldVal: <0>, NewVal: <1>, Scope: <global> |
| 94 | |
| 95 | 6: Setting global autoindent option |
| 96 | Expected: Name: <autoindent>, Oldval: <1>, NewVal: <0>, Scope: <global> |
| 97 | Autocmd Option: <autoindent>, OldVal: <1>, NewVal: <0>, Scope: <global> |
| 98 | |
| 99 | 7: Setting several global list and number option |
| 100 | Expected: Name: <list>, Oldval: <0>, NewVal: <1>, Scope: <global> |
| 101 | Autocmd Option: <list>, OldVal: <0>, NewVal: <1>, Scope: <global> |
| 102 | |
| 103 | 7: Setting several global list and number option |
| 104 | Expected: Name: <number>, Oldval: <0>, NewVal: <1>, Scope: <global> |
| 105 | Autocmd Option: <number>, OldVal: <0>, NewVal: <1>, Scope: <global> |
| 106 | |
| 107 | 8: Setting global acd |
| 108 | Expected: Name: <autochdir>, Oldval: <0>, NewVal: <1>, Scope: <global> |
| 109 | Autocmd Option: <autochdir>, OldVal: <0>, NewVal: <1>, Scope: <local> |
| 110 | |
| 111 | 9: Setting global autoread |
| 112 | Expected: Name: <autoread>, Oldval: <0>, NewVal: <1>, Scope: <global> |
| 113 | Autocmd Option: <autoread>, OldVal: <0>, NewVal: <1>, Scope: <global> |
| 114 | |
| 115 | 10: Setting local autoread |
| 116 | Expected: Name: <autoread>, Oldval: <0>, NewVal: <1>, Scope: <local> |
| 117 | Autocmd Option: <autoread>, OldVal: <1>, NewVal: <1>, Scope: <local> |
| 118 | |
| 119 | 11: Setting global autoread |
| 120 | Expected: Name: <autoread>, Oldval: <1>, NewVal: <0>, Scope: <global> |
| 121 | Autocmd Option: <autoread>, OldVal: <1>, NewVal: <0>, Scope: <global> |
| 122 | |
| 123 | 12: Setting option backspace through :let |
| 124 | Expected: Name: <backspace>, Oldval: <>, NewVal: <eol,indent,start>, Scope: <global> |
| 125 | Autocmd Option: <backspace>, OldVal: <>, NewVal: <eol,indent,start>, Scope: <global> |
| 126 | |
| 127 | 13: Setting option backspace through setbufvar() |
| 128 | Expected: Name: <backup>, Oldval: <>, NewVal: <1>, Scope: <local> |
| 129 | Autocmd Option: <backup>, OldVal: <0>, NewVal: <1>, Scope: <local> |
| 130 | |
| 131 | 14: Setting key option, shouldn't trigger |