Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
4 changes: 2 additions & 2 deletions src/testdir/Make_all.mak
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion src/testdir/Make_ming.mak
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions src/testdir/Make_vms.mms
Original file line number Diff line number Diff line change
Expand Up @@ -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: ?
Expand Down
126 changes: 0 additions & 126 deletions src/testdir/test_wordcount.in

This file was deleted.

34 changes: 0 additions & 34 deletions src/testdir/test_wordcount.ok

This file was deleted.

108 changes: 108 additions & 0 deletions src/testdir/test_wordcount.vim
Original file line number Diff line number Diff line change
@@ -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