0
0
mirror of https://github.com/vim/vim.git synced 2025-07-04 23:07:33 -04:00

patch 8.0.1387: wordcount test is old style

Problem:    Wordcount test is old style.
Solution:   Change into a new style test. (Yegappan Lakshmanan, closes #2434)
This commit is contained in:
Bram Moolenaar 2017-12-11 22:55:26 +01:00
parent 8e6a31df81
commit a703aaee4d
8 changed files with 115 additions and 171 deletions

View File

@ -2101,7 +2101,6 @@ run_message_test: $(MESSAGE_TEST_TARGET)
# These do not depend on the executable, compile it when needed.
test1 \
test_eval \
test_wordcount \
test3 test11 test14 test15 test17 \
test29 test30 test36 test37 test39 \
test42 test44 test48 test49 \
@ -2296,6 +2295,7 @@ test_arglist \
test_window_cmd \
test_window_id \
test_windows_home \
test_wordcount \
test_writefile \
test_alot_latin \
test_alot_utf8 \

View File

@ -31,8 +31,7 @@ SCRIPTS_ALL = \
test95.out \
test99.out \
test108.out \
test_eval.out \
test_wordcount.out
test_eval.out
# Tests that run on most systems, but not on Amiga.
@ -183,6 +182,7 @@ NEW_TESTS = test_arabic.res \
test_winbuf_close.res \
test_window_id.res \
test_windows_home.res \
test_wordcount.res \
test_writefile.res \
test_alot_latin.res \
test_alot_utf8.res \

View File

@ -63,7 +63,7 @@ win32: fixff nolog $(SCRIPTS_FIRST) $(SCRIPTS) $(SCRIPTS_WIN32) newtests
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 test_wordcount.ok
dotest.in
clean:
-@if exist *.out $(DEL) *.out

View File

@ -81,13 +81,7 @@ SCRIPT = test1.out test3.out \
test64.out test69.out \
test72.out test77a.out test88.out \
test94.out test95.out test99.out test108.out \
test_autocmd_option.out \
test_breakindent.out \
test_eval.out \
test_listlbr.out \
test_listlbr_utf8.out \
test_utf8.out \
test_wordcount.out
test_eval.out
# Known problems:
# test17: ?

View File

@ -1,126 +0,0 @@
Test for wordcount() function
STARTTEST
:so small.vim
:so mbyte.vim
:set enc=utf8
:set selection=inclusive fileformat=unix fileformats=unix
:new
:fu DoRecordWin(...)
: wincmd k
: if exists("a:1")
: call cursor(a:1)
: endif
: let result=[]
: call add(result, g:test)
: call add(result, getline(1, '$'))
: call add(result, wordcount())
: wincmd j
: return result
:endfu
:fu PutInWindow(args)
: wincmd k
: %d _
: call append(1, a:args)
: wincmd j
:endfu
:fu Log()
: $put ='----'
: $put =remove(g:log,0)
: $put =string(g:log)
:endfu
:fu! STL()
: if mode() =~? 'V'
: let g:visual_stat=wordcount()
: endif
: return string(wordcount())
:endfu
:let g:test="Test 1: empty window"
:let log=DoRecordWin()
:call Log()
:"
:let g:test="Test 2: some words, cursor at start"
:call PutInWindow('one two three')
:let log=DoRecordWin([1,1,0])
:call Log()
:"
:let g:test="Test 3: some words, cursor at end"
:call PutInWindow('one two three')
:let log=DoRecordWin([2,99,0])
:call Log()
:"
:let g:test="Test 4: some words, cursor at end, ve=all"
:set ve=all
:call PutInWindow('one two three')
:let log=DoRecordWin([2,99,0])
:call Log()
:set ve=
:"
:let g:test="Test 5: several lines with words"
:call PutInWindow(['one two three', 'one two three', 'one two three'])
:let log=DoRecordWin([4,99,0])
:call Log()
:"
:let g:test="Test 6: one line with BOM set"
:call PutInWindow('one two three')
:wincmd k
:set bomb
:w! Xtest
:wincmd j
:let log=DoRecordWin([2,99,0])
:call Log()
:wincmd k
:set nobomb
:w!
:wincmd j
:"
:let g:test="Test 7: one line with multibyte words"
:call PutInWindow(['Äne M¤ne Müh'])
:let log=DoRecordWin([2,99,0])
:call Log()
:"
:let g:test="Test 8: several lines with multibyte words"
:call PutInWindow(['Äne M¤ne Müh', 'und raus bist dü!'])
:let log=DoRecordWin([3,99,0])
:call Log()
:"
:let g:test="Test 9: visual mode, complete buffer"
:call PutInWindow(['Äne M¤ne Müh', 'und raus bist dü!'])
:wincmd k
:set ls=2 stl=%{STL()}
:" start visual mode quickly and select complete buffer
:0
V2jy
:set stl= ls=1
:let log=DoRecordWin([3,99,0])
:let log[2]=g:visual_stat
:call Log()
:"
:let g:test="Test 10: visual mode (empty)"
:call PutInWindow(['Äne M¤ne Müh', 'und raus bist dü!'])
:wincmd k
:set ls=2 stl=%{STL()}
:" start visual mode quickly and select complete buffer
:0
v$y
:set stl= ls=1
:let log=DoRecordWin([3,99,0])
:let log[2]=g:visual_stat
:call Log()
:"
:let g:test="Test 11: visual mode, single line"
:call PutInWindow(['Äne M¤ne Müh', 'und raus bist dü!'])
:wincmd k
:set ls=2 stl=%{STL()}
:" start visual mode quickly and select complete buffer
:2
0v$y
:set stl= ls=1
:let log=DoRecordWin([3,99,0])
:let log[2]=g:visual_stat
:call Log()
:"
:/^RESULT test/,$w! test.out
:qa!
ENDTEST
RESULT test:

View File

@ -1,34 +0,0 @@
RESULT test:
----
Test 1: empty window
[[''], {'chars': 0, 'cursor_chars': 0, 'words': 0, 'cursor_words': 0, 'bytes': 0, 'cursor_bytes': 0}]
----
Test 2: some words, cursor at start
[['', 'one two three'], {'chars': 15, 'cursor_chars': 1, 'words': 3, 'cursor_words': 0, 'bytes': 15, 'cursor_bytes': 1}]
----
Test 3: some words, cursor at end
[['', 'one two three'], {'chars': 15, 'cursor_chars': 14, 'words': 3, 'cursor_words': 3, 'bytes': 15, 'cursor_bytes': 14}]
----
Test 4: some words, cursor at end, ve=all
[['', 'one two three'], {'chars': 15, 'cursor_chars': 15, 'words': 3, 'cursor_words': 3, 'bytes': 15, 'cursor_bytes': 15}]
----
Test 5: several lines with words
[['', 'one two three', 'one two three', 'one two three'], {'chars': 43, 'cursor_chars': 42, 'words': 9, 'cursor_words': 9, 'bytes': 43, 'cursor_bytes': 42}]
----
Test 6: one line with BOM set
[['', 'one two three'], {'chars': 15, 'cursor_chars': 14, 'words': 3, 'cursor_words': 3, 'bytes': 18, 'cursor_bytes': 14}]
----
Test 7: one line with multibyte words
[['', 'Äne M¤ne Müh'], {'chars': 14, 'cursor_chars': 13, 'words': 3, 'cursor_words': 3, 'bytes': 17, 'cursor_bytes': 16}]
----
Test 8: several lines with multibyte words
[['', 'Äne M¤ne Müh', 'und raus bist dü!'], {'chars': 32, 'cursor_chars': 31, 'words': 7, 'cursor_words': 7, 'bytes': 36, 'cursor_bytes': 35}]
----
Test 9: visual mode, complete buffer
[['', 'Äne M¤ne Müh', 'und raus bist dü!'], {'chars': 32, 'words': 7, 'bytes': 36, 'visual_chars': 32, 'visual_words': 7, 'visual_bytes': 36}]
----
Test 10: visual mode (empty)
[['', 'Äne M¤ne Müh', 'und raus bist dü!'], {'chars': 32, 'words': 7, 'bytes': 36, 'visual_chars': 1, 'visual_words': 0, 'visual_bytes': 1}]
----
Test 11: visual mode, single line
[['', 'Äne M¤ne Müh', 'und raus bist dü!'], {'chars': 32, 'words': 7, 'bytes': 36, 'visual_chars': 13, 'visual_words': 3, 'visual_bytes': 16}]

View File

@ -0,0 +1,108 @@
" Test for wordcount() function
if !has('multi_byte')
finish
endif
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

View File

@ -771,6 +771,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1387,
/**/
1386,
/**/