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