annotate src/testdir/test_wordcount.vim @ 19880:50fa63ca3828 v8.2.0496

patch 8.2.0496: Vim9: disassemble test fails Commit: https://github.com/vim/vim/commit/a4d4cf490e2974843c80598e6f40f83aae658fd3 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Apr 2 13:50:27 2020 +0200 patch 8.2.0496: Vim9: disassemble test fails Problem: Vim9: disassemble test fails. Solution: Separate test cases with recognized constant expressions.
author Bram Moolenaar <Bram@vim.org>
date Thu, 02 Apr 2020 14:00:06 +0200
parents 2dcaa860e3fc
children 08940efa6b4e
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 func Test_wordcount()
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 let save_enc = &enc
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 set encoding=utf-8
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 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
7
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 new
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 " Test 1: empty window
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 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
12 \ 'bytes': 0, 'cursor_bytes': 0}, wordcount())
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 2: some words, cursor at start
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 call append(1, 'one two three')
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 call cursor([1, 1, 0])
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 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
18 \ 'bytes': 15, 'cursor_bytes': 1}, wordcount())
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 " 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
21 %d _
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 call append(1, 'one two three')
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 call cursor([2, 99, 0])
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 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
25 \ 'bytes': 15, 'cursor_bytes': 14}, wordcount())
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 " 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
28 set ve=all
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 %d _
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 call append(1, 'one two three')
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 call cursor([2, 99, 0])
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 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
33 \ 'bytes': 15, 'cursor_bytes': 15}, wordcount())
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 set ve=
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 " Test 5: several lines with words
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 %d _
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 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
39 call cursor([4, 99, 0])
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 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
41 \ 'bytes': 43, 'cursor_bytes': 42}, wordcount())
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 " 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
44 %d _
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 call append(1, 'one two three')
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 set bomb
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 w! Xtest
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 call cursor([2, 99, 0])
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 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
50 \ 'bytes': 18, 'cursor_bytes': 14}, wordcount())
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 set nobomb
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 w!
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 call delete('Xtest')
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 " 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
56 %d _
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 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
58 call cursor([2, 99, 0])
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 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
60 \ 'bytes': 17, 'cursor_bytes': 16}, wordcount())
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 " 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
63 %d _
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 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
65 call cursor([3, 99, 0])
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 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
67 \ 'bytes': 36, 'cursor_bytes': 35}, wordcount())
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 " 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
70 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
71
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 " Test 9: visual mode, complete buffer
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 let g:visual_stat = {}
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 %d _
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75 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
76 " 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
77 0
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78 exe "normal V2j\<F2>y"
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 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
80 \ '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
81
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82 " Test 10: visual mode (empty)
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83 %d _
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 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
85 " 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
86 0
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 exe "normal v$\<F2>y"
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88 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
89 \ '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
90
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 " Test 11: visual mode, single line
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92 %d _
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 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
94 " 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
95 2
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
96 exe "normal 0v$\<F2>y"
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
97 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
98 \ '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
99
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
100 set selection& fileformat& fileformats&
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101 let &enc = save_enc
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
102 enew!
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
103 close
71109531c516 patch 8.0.1387: wordcount test is old style
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
104 endfunc