Bram Moolenaar | ed767a2 | 2016-01-03 22:49:16 +0100 | [diff] [blame] | 1 | Test for wordcount() function |
| 2 | |
| 3 | STARTTEST |
| 4 | :so small.vim |
| 5 | :so mbyte.vim |
| 6 | :set enc=utf8 |
Bram Moolenaar | 485dace | 2016-01-04 12:45:29 +0100 | [diff] [blame] | 7 | :set selection=inclusive fileformat=unix fileformats=unix |
Bram Moolenaar | ed767a2 | 2016-01-03 22:49:16 +0100 | [diff] [blame] | 8 | :new |
| 9 | :fu DoRecordWin(...) |
| 10 | : wincmd k |
| 11 | : if exists("a:1") |
| 12 | : call cursor(a:1) |
| 13 | : endif |
| 14 | : let result=[] |
| 15 | : call add(result, g:test) |
| 16 | : call add(result, getline(1, '$')) |
| 17 | : call add(result, wordcount()) |
| 18 | : wincmd j |
| 19 | : return result |
| 20 | :endfu |
| 21 | :fu PutInWindow(args) |
| 22 | : wincmd k |
| 23 | : %d _ |
| 24 | : call append(1, a:args) |
| 25 | : wincmd j |
| 26 | :endfu |
| 27 | :fu Log() |
| 28 | : $put ='----' |
| 29 | : $put =remove(g:log,0) |
| 30 | : $put =string(g:log) |
| 31 | :endfu |
| 32 | :fu! STL() |
| 33 | : if mode() =~? 'V' |
| 34 | : let g:visual_stat=wordcount() |
| 35 | : endif |
| 36 | : return string(wordcount()) |
| 37 | :endfu |
| 38 | :let g:test="Test 1: empty window" |
| 39 | :let log=DoRecordWin() |
| 40 | :call Log() |
| 41 | :" |
| 42 | :let g:test="Test 2: some words, cursor at start" |
| 43 | :call PutInWindow('one two three') |
| 44 | :let log=DoRecordWin([1,1,0]) |
| 45 | :call Log() |
| 46 | :" |
| 47 | :let g:test="Test 3: some words, cursor at end" |
| 48 | :call PutInWindow('one two three') |
| 49 | :let log=DoRecordWin([2,99,0]) |
| 50 | :call Log() |
| 51 | :" |
| 52 | :let g:test="Test 4: some words, cursor at end, ve=all" |
| 53 | :set ve=all |
| 54 | :call PutInWindow('one two three') |
| 55 | :let log=DoRecordWin([2,99,0]) |
| 56 | :call Log() |
| 57 | :set ve= |
| 58 | :" |
| 59 | :let g:test="Test 5: several lines with words" |
| 60 | :call PutInWindow(['one two three', 'one two three', 'one two three']) |
| 61 | :let log=DoRecordWin([4,99,0]) |
| 62 | :call Log() |
| 63 | :" |
| 64 | :let g:test="Test 6: one line with BOM set" |
| 65 | :call PutInWindow('one two three') |
| 66 | :wincmd k |
| 67 | :set bomb |
| 68 | :w! Xtest |
| 69 | :wincmd j |
| 70 | :let log=DoRecordWin([2,99,0]) |
| 71 | :call Log() |
| 72 | :wincmd k |
| 73 | :set nobomb |
| 74 | :w! |
| 75 | :wincmd j |
| 76 | :" |
| 77 | :let g:test="Test 7: one line with multibyte words" |
| 78 | :call PutInWindow(['Äne M¤ne Müh']) |
| 79 | :let log=DoRecordWin([2,99,0]) |
| 80 | :call Log() |
| 81 | :" |
| 82 | :let g:test="Test 8: several lines with multibyte words" |
| 83 | :call PutInWindow(['Äne M¤ne Müh', 'und raus bist dü!']) |
| 84 | :let log=DoRecordWin([3,99,0]) |
| 85 | :call Log() |
| 86 | :" |
| 87 | :let g:test="Test 9: visual mode, complete buffer" |
| 88 | :call PutInWindow(['Äne M¤ne Müh', 'und raus bist dü!']) |
| 89 | :wincmd k |
| 90 | :set ls=2 stl=%{STL()} |
| 91 | :" start visual mode quickly and select complete buffer |
| 92 | :0 |
| 93 | V2jy |
| 94 | :set stl= ls=1 |
| 95 | :let log=DoRecordWin([3,99,0]) |
| 96 | :let log[2]=g:visual_stat |
| 97 | :call Log() |
| 98 | :" |
| 99 | :let g:test="Test 10: visual mode (empty)" |
| 100 | :call PutInWindow(['Äne M¤ne Müh', 'und raus bist dü!']) |
| 101 | :wincmd k |
| 102 | :set ls=2 stl=%{STL()} |
| 103 | :" start visual mode quickly and select complete buffer |
| 104 | :0 |
| 105 | v$y |
| 106 | :set stl= ls=1 |
| 107 | :let log=DoRecordWin([3,99,0]) |
| 108 | :let log[2]=g:visual_stat |
| 109 | :call Log() |
| 110 | :" |
| 111 | :let g:test="Test 11: visual mode, single line" |
| 112 | :call PutInWindow(['Äne M¤ne Müh', 'und raus bist dü!']) |
| 113 | :wincmd k |
| 114 | :set ls=2 stl=%{STL()} |
| 115 | :" start visual mode quickly and select complete buffer |
| 116 | :2 |
| 117 | 0v$y |
| 118 | :set stl= ls=1 |
| 119 | :let log=DoRecordWin([3,99,0]) |
| 120 | :let log[2]=g:visual_stat |
| 121 | :call Log() |
| 122 | :" |
| 123 | :/^RESULT test/,$w! test.out |
| 124 | :qa! |
| 125 | ENDTEST |
| 126 | RESULT test: |