annotate src/testdir/test_wordcount.vim @ 15525:3ef31ce9d9f9 v8.1.0770

patch 8.1.0770: inconsistent use of ELAPSED_FUNC commit https://github.com/vim/vim/commit/1ac56c2d11da5ffa44db23e1fd0c533d02ab2f66 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jan 17 22:28:22 2019 +0100 patch 8.1.0770: inconsistent use of ELAPSED_FUNC Problem: Inconsistent use of ELAPSED_FUNC. Solution: Consistently use ELAPSED_FUNC. Also turn ELAPSED_TYPE into a typedef. (Ozaki Kiichi, closes #3815)
author Bram Moolenaar <Bram@vim.org>
date Thu, 17 Jan 2019 22:30:06 +0100
parents 71109531c516
children 2dcaa860e3fc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13022
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Test for wordcount() function
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 if !has('multi_byte')
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 finish
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 endif
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 func Test_wordcount()
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 let save_enc = &enc
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 set encoding=utf-8
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 set selection=inclusive fileformat=unix fileformats=unix
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 new
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 " Test 1: empty window
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 call assert_equal({'chars': 0, 'cursor_chars': 0, 'words': 0, 'cursor_words': 0,
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 \ 'bytes': 0, 'cursor_bytes': 0}, wordcount())
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 " Test 2: some words, cursor at start
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 call append(1, 'one two three')
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 call cursor([1, 1, 0])
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 call assert_equal({'chars': 15, 'cursor_chars': 1, 'words': 3, 'cursor_words': 0,
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 \ 'bytes': 15, 'cursor_bytes': 1}, wordcount())
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 " Test 3: some words, cursor at end
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 %d _
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 call append(1, 'one two three')
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 call cursor([2, 99, 0])
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 call assert_equal({'chars': 15, 'cursor_chars': 14, 'words': 3, 'cursor_words': 3,
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 \ 'bytes': 15, 'cursor_bytes': 14}, wordcount())
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 " Test 4: some words, cursor at end, ve=all
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 set ve=all
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 %d _
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 call append(1, 'one two three')
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 call cursor([2, 99, 0])
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 call assert_equal({'chars': 15, 'cursor_chars': 15, 'words': 3, 'cursor_words': 3,
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 \ 'bytes': 15, 'cursor_bytes': 15}, wordcount())
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 set ve=
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 " Test 5: several lines with words
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 %d _
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 call append(1, ['one two three', 'one two three', 'one two three'])
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 call cursor([4, 99, 0])
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 call assert_equal({'chars': 43, 'cursor_chars': 42, 'words': 9, 'cursor_words': 9,
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 \ 'bytes': 43, 'cursor_bytes': 42}, wordcount())
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 " Test 6: one line with BOM set
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 %d _
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 call append(1, 'one two three')
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 set bomb
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 w! Xtest
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 call cursor([2, 99, 0])
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 call assert_equal({'chars': 15, 'cursor_chars': 14, 'words': 3, 'cursor_words': 3,
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 \ 'bytes': 18, 'cursor_bytes': 14}, wordcount())
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 set nobomb
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 w!
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 call delete('Xtest')
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 " Test 7: one line with multibyte words
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 %d _
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 call append(1, ['Äne M¤ne Müh'])
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 call cursor([2, 99, 0])
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 call assert_equal({'chars': 14, 'cursor_chars': 13, 'words': 3, 'cursor_words': 3,
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 \ 'bytes': 17, 'cursor_bytes': 16}, wordcount())
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 " Test 8: several lines with multibyte words
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 %d _
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 call append(1, ['Äne M¤ne Müh', 'und raus bist dü!'])
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 call cursor([3, 99, 0])
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 call assert_equal({'chars': 32, 'cursor_chars': 31, 'words': 7, 'cursor_words': 7,
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71 \ 'bytes': 36, 'cursor_bytes': 35}, wordcount())
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 " Visual map to capture wordcount() in visual mode
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 vnoremap <expr> <F2> execute("let g:visual_stat = wordcount()")
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
76 " Test 9: visual mode, complete buffer
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77 let g:visual_stat = {}
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78 %d _
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 call append(1, ['Äne M¤ne Müh', 'und raus bist dü!'])
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 " start visual mode and select the complete buffer
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 0
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82 exe "normal V2j\<F2>y"
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83 call assert_equal({'chars': 32, 'words': 7, 'bytes': 36, 'visual_chars': 32,
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 \ 'visual_words': 7, 'visual_bytes': 36}, g:visual_stat)
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86 " Test 10: visual mode (empty)
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 %d _
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88 call append(1, ['Äne M¤ne Müh', 'und raus bist dü!'])
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89 " start visual mode and select the complete buffer
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90 0
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 exe "normal v$\<F2>y"
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92 call assert_equal({'chars': 32, 'words': 7, 'bytes': 36, 'visual_chars': 1,
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 \ 'visual_words': 0, 'visual_bytes': 1}, g:visual_stat)
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
94
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
95 " Test 11: visual mode, single line
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
96 %d _
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
97 call append(1, ['Äne M¤ne Müh', 'und raus bist dü!'])
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
98 " start visual mode and select the complete buffer
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
99 2
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
100 exe "normal 0v$\<F2>y"
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101 call assert_equal({'chars': 32, 'words': 7, 'bytes': 36, 'visual_chars': 13,
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
102 \ 'visual_words': 3, 'visual_bytes': 16}, g:visual_stat)
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
103
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
104 set selection& fileformat& fileformats&
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
105 let &enc = save_enc
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
106 enew!
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107 close
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108 endfunc