annotate src/testdir/test_functions.vim @ 32669:448aef880252

normalize line endings
author Christian Brabandt <cb@256bit.org>
date Mon, 26 Jun 2023 09:54:34 +0200
parents a699363f01cd
children 695b50472e85
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32669
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1 " Tests for various functions.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3 source shared.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
4 source check.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
5 source term_util.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
6 source screendump.vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
7 import './vim9.vim' as v9
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
8
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
9 " Must be done first, since the alternate buffer must be unset.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
10 func Test_00_bufexists()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
11 call assert_equal(0, bufexists('does_not_exist'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
12 call assert_equal(1, bufexists(bufnr('%')))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
13 call assert_equal(0, bufexists(0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
14 new Xfoo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
15 let bn = bufnr('%')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
16 call assert_equal(1, bufexists(bn))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
17 call assert_equal(1, bufexists('Xfoo'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
18 call assert_equal(1, bufexists(getcwd() . '/Xfoo'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
19 call assert_equal(1, bufexists(0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
20 bw
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
21 call assert_equal(0, bufexists(bn))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
22 call assert_equal(0, bufexists('Xfoo'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
23 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
24
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
25 func Test_has()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
26 call assert_equal(1, has('eval'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
27 call assert_equal(1, has('eval', 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
28
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
29 if has('unix')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
30 call assert_equal(1, or(has('ttyin'), 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
31 call assert_equal(0, and(has('ttyout'), 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
32 call assert_equal(1, has('multi_byte_encoding'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
33 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
34 call assert_equal(1, has('vcon', 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
35 call assert_equal(1, has('mouse_gpm_enabled', 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
36
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
37 call assert_equal(0, has('nonexistent'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
38 call assert_equal(0, has('nonexistent', 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
39
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
40 " Will we ever have patch 9999?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
41 let ver = 'patch-' .. v:version / 100 .. '.' .. v:version % 100 .. '.9999'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
42 call assert_equal(0, has(ver))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
43
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
44 " There actually isn't a patch 9.0.0, but this is more consistent.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
45 call assert_equal(1, has('patch-9.0.0'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
46 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
47
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
48 func Test_empty()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
49 call assert_equal(1, empty(''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
50 call assert_equal(0, empty('a'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
51
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
52 call assert_equal(1, empty(0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
53 call assert_equal(1, empty(-0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
54 call assert_equal(0, empty(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
55 call assert_equal(0, empty(-1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
56
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
57 call assert_equal(1, empty(0.0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
58 call assert_equal(1, empty(-0.0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
59 call assert_equal(0, empty(1.0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
60 call assert_equal(0, empty(-1.0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
61 call assert_equal(0, empty(1.0/0.0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
62 call assert_equal(0, empty(0.0/0.0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
63
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
64 call assert_equal(1, empty([]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
65 call assert_equal(0, empty(['a']))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
66
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
67 call assert_equal(1, empty({}))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
68 call assert_equal(0, empty({'a':1}))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
69
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
70 call assert_equal(1, empty(v:null))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
71 call assert_equal(1, empty(v:none))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
72 call assert_equal(1, empty(v:false))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
73 call assert_equal(0, empty(v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
74
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
75 if has('channel')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
76 call assert_equal(1, empty(test_null_channel()))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
77 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
78 if has('job')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
79 call assert_equal(1, empty(test_null_job()))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
80 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
81
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
82 call assert_equal(0, empty(function('Test_empty')))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
83 call assert_equal(0, empty(function('Test_empty', [0])))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
84
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
85 call assert_fails("call empty(test_void())", ['E340:', 'E685:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
86 call assert_fails("call empty(test_unknown())", ['E340:', 'E685:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
87 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
88
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
89 func Test_test_void()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
90 call assert_fails('echo 1 == test_void()', 'E1031:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
91 call assert_fails('echo 1.0 == test_void()', 'E1031:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
92 call assert_fails('let x = json_encode(test_void())', ['E340:', 'E685:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
93 call assert_fails('let x = copy(test_void())', ['E340:', 'E685:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
94 call assert_fails('let x = copy([test_void()])', 'E1031:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
95 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
96
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
97 func Test_islocked()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
98 call assert_fails('call islocked(99)', 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
99 call assert_fails('call islocked("s: x")', 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
100 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
101
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
102 func Test_len()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
103 call assert_equal(1, len(0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
104 call assert_equal(2, len(12))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
105
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
106 call assert_equal(0, len(''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
107 call assert_equal(2, len('ab'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
108
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
109 call assert_equal(0, len([]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
110 call assert_equal(0, len(test_null_list()))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
111 call assert_equal(2, len([2, 1]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
112
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
113 call assert_equal(0, len({}))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
114 call assert_equal(0, len(test_null_dict()))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
115 call assert_equal(2, len({'a': 1, 'b': 2}))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
116
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
117 call assert_fails('call len(v:none)', 'E701:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
118 call assert_fails('call len({-> 0})', 'E701:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
119 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
120
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
121 func Test_max()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
122 call assert_equal(0, max([]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
123 call assert_equal(2, max([2]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
124 call assert_equal(2, max([1, 2]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
125 call assert_equal(2, max([1, 2, v:null]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
126
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
127 call assert_equal(0, max({}))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
128 call assert_equal(2, max({'a':1, 'b':2}))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
129
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
130 call assert_fails('call max(1)', 'E712:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
131 call assert_fails('call max(v:none)', 'E712:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
132
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
133 " check we only get one error
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
134 call assert_fails('call max([#{}, [1]])', ['E728:', 'E728:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
135 call assert_fails('call max(#{a: {}, b: [1]})', ['E728:', 'E728:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
136 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
137
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
138 func Test_min()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
139 call assert_equal(0, min([]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
140 call assert_equal(2, min([2]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
141 call assert_equal(1, min([1, 2]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
142 call assert_equal(0, min([1, 2, v:null]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
143
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
144 call assert_equal(0, min({}))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
145 call assert_equal(1, min({'a':1, 'b':2}))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
146
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
147 call assert_fails('call min(1)', 'E712:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
148 call assert_fails('call min(v:none)', 'E712:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
149 call assert_fails('call min([1, {}])', 'E728:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
150
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
151 " check we only get one error
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
152 call assert_fails('call min([[1], #{}])', ['E745:', 'E745:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
153 call assert_fails('call min(#{a: [1], b: #{}})', ['E745:', 'E745:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
154 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
155
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
156 func Test_strwidth()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
157 for aw in ['single', 'double']
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
158 exe 'set ambiwidth=' . aw
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
159 call assert_equal(0, strwidth(''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
160 call assert_equal(1, strwidth("\t"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
161 call assert_equal(3, strwidth('Vim'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
162 call assert_equal(4, strwidth(1234))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
163 call assert_equal(5, strwidth(-1234))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
164
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
165 call assert_equal(2, strwidth('😉'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
166 call assert_equal(17, strwidth('Eĥoŝanĝo ĉiuĵaŭde'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
167 call assert_equal((aw == 'single') ? 6 : 7, strwidth('Straße'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
168
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
169 call assert_fails('call strwidth({->0})', 'E729:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
170 call assert_fails('call strwidth([])', 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
171 call assert_fails('call strwidth({})', 'E731:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
172 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
173
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
174 call assert_equal(3, strwidth(1.2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
175 call v9.CheckDefAndScriptFailure(['echo strwidth(1.2)'], ['E1013: Argument 1: type mismatch, expected string but got float', 'E1174: String required for argument 1'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
176
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
177 set ambiwidth&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
178 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
179
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
180 func Test_str2nr()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
181 call assert_equal(0, str2nr(''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
182 call assert_equal(1, str2nr('1'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
183 call assert_equal(1, str2nr(' 1 '))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
184
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
185 call assert_equal(1, str2nr('+1'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
186 call assert_equal(1, str2nr('+ 1'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
187 call assert_equal(1, str2nr(' + 1 '))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
188
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
189 call assert_equal(-1, str2nr('-1'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
190 call assert_equal(-1, str2nr('- 1'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
191 call assert_equal(-1, str2nr(' - 1 '))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
192
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
193 call assert_equal(123456789, str2nr('123456789'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
194 call assert_equal(-123456789, str2nr('-123456789'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
195
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
196 call assert_equal(5, str2nr('101', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
197 call assert_equal(5, '0b101'->str2nr(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
198 call assert_equal(5, str2nr('0B101', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
199 call assert_equal(-5, str2nr('-101', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
200 call assert_equal(-5, str2nr('-0b101', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
201 call assert_equal(-5, str2nr('-0B101', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
202
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
203 call assert_equal(65, str2nr('101', 8))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
204 call assert_equal(65, str2nr('0101', 8))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
205 call assert_equal(-65, str2nr('-101', 8))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
206 call assert_equal(-65, str2nr('-0101', 8))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
207 call assert_equal(65, str2nr('0o101', 8))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
208 call assert_equal(65, str2nr('0O0101', 8))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
209 call assert_equal(-65, str2nr('-0O101', 8))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
210 call assert_equal(-65, str2nr('-0o0101', 8))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
211
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
212 call assert_equal(11259375, str2nr('abcdef', 16))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
213 call assert_equal(11259375, str2nr('ABCDEF', 16))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
214 call assert_equal(-11259375, str2nr('-ABCDEF', 16))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
215 call assert_equal(11259375, str2nr('0xabcdef', 16))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
216 call assert_equal(11259375, str2nr('0Xabcdef', 16))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
217 call assert_equal(11259375, str2nr('0XABCDEF', 16))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
218 call assert_equal(-11259375, str2nr('-0xABCDEF', 16))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
219
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
220 call assert_equal(1, str2nr("1'000'000", 10, 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
221 call assert_equal(256, str2nr("1'0000'0000", 2, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
222 call assert_equal(262144, str2nr("1'000'000", 8, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
223 call assert_equal(1000000, str2nr("1'000'000", 10, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
224 call assert_equal(1000, str2nr("1'000''000", 10, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
225 call assert_equal(65536, str2nr("1'00'00", 16, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
226
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
227 call assert_equal(0, str2nr('0x10'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
228 call assert_equal(0, str2nr('0b10'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
229 call assert_equal(0, str2nr('0o10'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
230 call assert_equal(1, str2nr('12', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
231 call assert_equal(1, str2nr('18', 8))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
232 call assert_equal(1, str2nr('1g', 16))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
233
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
234 call assert_equal(0, str2nr(v:null))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
235 call assert_equal(0, str2nr(v:none))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
236
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
237 call assert_fails('call str2nr([])', 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
238 call assert_fails('call str2nr({->2})', 'E729:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
239 call assert_equal(1, str2nr(1.2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
240 call v9.CheckDefAndScriptFailure(['echo str2nr(1.2)'], ['E1013: Argument 1: type mismatch, expected string but got float', 'E1174: String required for argument 1'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
241 call assert_fails('call str2nr(10, [])', 'E745:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
242 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
243
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
244 func Test_strftime()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
245 CheckFunction strftime
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
246
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
247 " Format of strftime() depends on system. We assume
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
248 " that basic formats tested here are available and
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
249 " identical on all systems which support strftime().
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
250 "
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
251 " The 2nd parameter of strftime() is a local time, so the output day
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
252 " of strftime() can be 17 or 18, depending on timezone.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
253 call assert_match('^2017-01-1[78]$', strftime('%Y-%m-%d', 1484695512))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
254 "
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
255 call assert_match('^\d\d\d\d-\(0\d\|1[012]\)-\([012]\d\|3[01]\) \([01]\d\|2[0-3]\):[0-5]\d:\([0-5]\d\|60\)$', '%Y-%m-%d %H:%M:%S'->strftime())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
256
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
257 call assert_fails('call strftime([])', 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
258 call assert_fails('call strftime("%Y", [])', 'E745:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
259
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
260 " Check that the time changes after we change the timezone
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
261 " Save previous timezone value, if any
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
262 if exists('$TZ')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
263 let tz = $TZ
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
264 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
265
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
266 " Force EST and then UTC, save the current hour (24-hour clock) for each
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
267 let $TZ = 'EST' | let est = strftime('%H')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
268 let $TZ = 'UTC' | let utc = strftime('%H')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
269
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
270 " Those hours should be two bytes long, and should not be the same; if they
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
271 " are, a tzset(3) call may have failed somewhere
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
272 call assert_equal(strlen(est), 2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
273 call assert_equal(strlen(utc), 2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
274 " TODO: this fails on MS-Windows
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
275 if has('unix')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
276 call assert_notequal(est, utc)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
277 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
278
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
279 " If we cached a timezone value, put it back, otherwise clear it
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
280 if exists('tz')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
281 let $TZ = tz
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
282 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
283 unlet $TZ
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
284 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
285 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
286
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
287 func Test_strptime()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
288 CheckFunction strptime
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
289
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
290 if exists('$TZ')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
291 let tz = $TZ
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
292 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
293 let $TZ = 'UTC'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
294
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
295 call assert_equal(1484653763, strptime('%Y-%m-%d %T', '2017-01-17 11:49:23'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
296
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
297 " Force DST and check that it's considered
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
298 let $TZ = 'WINTER0SUMMER,J1,J365'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
299 call assert_equal(1484653763 - 3600, strptime('%Y-%m-%d %T', '2017-01-17 11:49:23'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
300
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
301 call assert_fails('call strptime()', 'E119:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
302 call assert_fails('call strptime("xxx")', 'E119:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
303 call assert_equal(0, strptime("%Y", ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
304 call assert_equal(0, strptime("%Y", "xxx"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
305
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
306 if exists('tz')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
307 let $TZ = tz
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
308 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
309 unlet $TZ
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
310 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
311 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
312
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
313 func Test_resolve_unix()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
314 CheckUnix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
315
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
316 " Xlink1 -> Xlink2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
317 " Xlink2 -> Xlink3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
318 silent !ln -s -f Xlink2 Xlink1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
319 silent !ln -s -f Xlink3 Xlink2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
320 call assert_equal('Xlink3', resolve('Xlink1'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
321 call assert_equal('./Xlink3', resolve('./Xlink1'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
322 call assert_equal('Xlink3/', resolve('Xlink2/'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
323 " FIXME: these tests result in things like "Xlink2/" instead of "Xlink3/"?!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
324 "call assert_equal('Xlink3/', resolve('Xlink1/'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
325 "call assert_equal('./Xlink3/', resolve('./Xlink1/'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
326 "call assert_equal(getcwd() . '/Xlink3/', resolve(getcwd() . '/Xlink1/'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
327 call assert_equal(getcwd() . '/Xlink3', resolve(getcwd() . '/Xlink1'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
328
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
329 " Test resolve() with a symlink cycle.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
330 " Xlink1 -> Xlink2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
331 " Xlink2 -> Xlink3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
332 " Xlink3 -> Xlink1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
333 silent !ln -s -f Xlink1 Xlink3
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
334 call assert_fails('call resolve("Xlink1")', 'E655:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
335 call assert_fails('call resolve("./Xlink1")', 'E655:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
336 call assert_fails('call resolve("Xlink2")', 'E655:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
337 call assert_fails('call resolve("Xlink3")', 'E655:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
338 call delete('Xlink1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
339 call delete('Xlink2')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
340 call delete('Xlink3')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
341
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
342 silent !ln -s -f Xresolvedir//Xfile Xresolvelink
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
343 call assert_equal('Xresolvedir/Xfile', resolve('Xresolvelink'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
344 call delete('Xresolvelink')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
345
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
346 silent !ln -s -f Xlink2/ Xlink1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
347 call assert_equal('Xlink2', 'Xlink1'->resolve())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
348 call assert_equal('Xlink2/', resolve('Xlink1/'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
349 call delete('Xlink1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
350
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
351 silent !ln -s -f ./Xlink2 Xlink1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
352 call assert_equal('Xlink2', resolve('Xlink1'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
353 call assert_equal('./Xlink2', resolve('./Xlink1'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
354 call delete('Xlink1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
355
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
356 call assert_equal('/', resolve('/'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
357 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
358
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
359 func s:normalize_fname(fname)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
360 let ret = substitute(a:fname, '\', '/', 'g')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
361 let ret = substitute(ret, '//', '/', 'g')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
362 return ret->tolower()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
363 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
364
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
365 func Test_resolve_win32()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
366 CheckMSWindows
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
367
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
368 " test for shortcut file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
369 if executable('cscript')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
370 new Xresfile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
371 wq
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
372 let lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
373 Set fs = CreateObject("Scripting.FileSystemObject")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
374 Set ws = WScript.CreateObject("WScript.Shell")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
375 Set shortcut = ws.CreateShortcut("Xlink.lnk")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
376 shortcut.TargetPath = fs.BuildPath(ws.CurrentDirectory, "Xresfile")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
377 shortcut.Save
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
378 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
379 call writefile(lines, 'link.vbs')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
380 silent !cscript link.vbs
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
381 call delete('link.vbs')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
382 call assert_equal(s:normalize_fname(getcwd() . '\Xresfile'), s:normalize_fname(resolve('./Xlink.lnk')))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
383 call delete('Xresfile')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
384
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
385 call assert_equal(s:normalize_fname(getcwd() . '\Xresfile'), s:normalize_fname(resolve('./Xlink.lnk')))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
386 call delete('Xlink.lnk')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
387 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
388 echomsg 'skipped test for shortcut file'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
389 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
390
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
391 " remove files
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
392 call delete('Xlink')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
393 call delete('Xdir', 'd')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
394 call delete('Xresfile')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
395
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
396 " test for symbolic link to a file
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
397 new Xresfile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
398 wq
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
399 call assert_equal('Xresfile', resolve('Xresfile'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
400 silent !mklink Xlink Xresfile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
401 if !v:shell_error
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
402 call assert_equal(s:normalize_fname(getcwd() . '\Xresfile'), s:normalize_fname(resolve('./Xlink')))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
403 call delete('Xlink')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
404 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
405 echomsg 'skipped test for symbolic link to a file'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
406 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
407 call delete('Xresfile')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
408
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
409 " test for junction to a directory
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
410 call mkdir('Xdir')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
411 silent !mklink /J Xlink Xdir
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
412 if !v:shell_error
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
413 call assert_equal(s:normalize_fname(getcwd() . '\Xdir'), s:normalize_fname(resolve(getcwd() . '/Xlink')))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
414
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
415 call delete('Xdir', 'd')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
416
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
417 " test for junction already removed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
418 call assert_equal(s:normalize_fname(getcwd() . '\Xlink'), s:normalize_fname(resolve(getcwd() . '/Xlink')))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
419 call delete('Xlink')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
420 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
421 echomsg 'skipped test for junction to a directory'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
422 call delete('Xdir', 'd')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
423 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
424
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
425 " test for symbolic link to a directory
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
426 call mkdir('Xdir')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
427 silent !mklink /D Xlink Xdir
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
428 if !v:shell_error
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
429 call assert_equal(s:normalize_fname(getcwd() . '\Xdir'), s:normalize_fname(resolve(getcwd() . '/Xlink')))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
430
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
431 call delete('Xdir', 'd')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
432
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
433 " test for symbolic link already removed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
434 call assert_equal(s:normalize_fname(getcwd() . '\Xlink'), s:normalize_fname(resolve(getcwd() . '/Xlink')))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
435 call delete('Xlink')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
436 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
437 echomsg 'skipped test for symbolic link to a directory'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
438 call delete('Xdir', 'd')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
439 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
440
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
441 " test for buffer name
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
442 new Xbuffile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
443 wq
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
444 silent !mklink Xlink Xbuffile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
445 if !v:shell_error
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
446 edit Xlink
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
447 call assert_equal('Xlink', bufname('%'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
448 call delete('Xlink')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
449 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
450 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
451 echomsg 'skipped test for buffer name'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
452 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
453 call delete('Xbuffile')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
454
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
455 " test for reparse point
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
456 call mkdir('Xdir')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
457 call assert_equal('Xdir', resolve('Xdir'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
458 silent !mklink /D Xdirlink Xdir
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
459 if !v:shell_error
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
460 w Xdir/text.txt
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
461 call assert_equal('Xdir/text.txt', resolve('Xdir/text.txt'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
462 call assert_equal(s:normalize_fname(getcwd() . '\Xdir\text.txt'), s:normalize_fname(resolve('Xdirlink\text.txt')))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
463 call assert_equal(s:normalize_fname(getcwd() . '\Xdir'), s:normalize_fname(resolve('Xdirlink')))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
464 call delete('Xdirlink')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
465 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
466 echomsg 'skipped test for reparse point'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
467 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
468
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
469 call delete('Xdir', 'rf')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
470 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
471
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
472 func Test_simplify()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
473 call assert_equal('', simplify(''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
474 call assert_equal('/', simplify('/'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
475 call assert_equal('/', simplify('/.'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
476 call assert_equal('/', simplify('/..'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
477 call assert_equal('/...', simplify('/...'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
478 call assert_equal('//path', simplify('//path'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
479 if has('unix')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
480 call assert_equal('/path', simplify('///path'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
481 call assert_equal('/path', simplify('////path'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
482 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
483
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
484 call assert_equal('./dir/file', './dir/file'->simplify())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
485 call assert_equal('./dir/file', simplify('.///dir//file'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
486 call assert_equal('./dir/file', simplify('./dir/./file'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
487 call assert_equal('./file', simplify('./dir/../file'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
488 call assert_equal('../dir/file', simplify('dir/../../dir/file'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
489 call assert_equal('./file', simplify('dir/.././file'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
490 call assert_equal('../dir', simplify('./../dir'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
491 call assert_equal('..', simplify('../testdir/..'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
492 call mkdir('Xsimpdir')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
493 call assert_equal('.', simplify('Xsimpdir/../.'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
494 call delete('Xsimpdir', 'd')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
495
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
496 call assert_fails('call simplify({->0})', 'E729:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
497 call assert_fails('call simplify([])', 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
498 call assert_fails('call simplify({})', 'E731:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
499 call assert_equal('1.2', simplify(1.2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
500 call v9.CheckDefAndScriptFailure(['echo simplify(1.2)'], ['E1013: Argument 1: type mismatch, expected string but got float', 'E1174: String required for argument 1'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
501 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
502
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
503 func Test_pathshorten()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
504 call assert_equal('', pathshorten(''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
505 call assert_equal('foo', pathshorten('foo'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
506 call assert_equal('/foo', '/foo'->pathshorten())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
507 call assert_equal('f/', pathshorten('foo/'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
508 call assert_equal('f/bar', pathshorten('foo/bar'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
509 call assert_equal('f/b/foobar', 'foo/bar/foobar'->pathshorten())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
510 call assert_equal('/f/b/foobar', pathshorten('/foo/bar/foobar'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
511 call assert_equal('.f/bar', pathshorten('.foo/bar'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
512 call assert_equal('~f/bar', pathshorten('~foo/bar'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
513 call assert_equal('~.f/bar', pathshorten('~.foo/bar'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
514 call assert_equal('.~f/bar', pathshorten('.~foo/bar'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
515 call assert_equal('~/f/bar', pathshorten('~/foo/bar'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
516 call assert_fails('call pathshorten([])', 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
517
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
518 " test pathshorten with optional variable to set preferred size of shortening
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
519 call assert_equal('', pathshorten('', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
520 call assert_equal('foo', pathshorten('foo', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
521 call assert_equal('/foo', pathshorten('/foo', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
522 call assert_equal('fo/', pathshorten('foo/', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
523 call assert_equal('fo/bar', pathshorten('foo/bar', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
524 call assert_equal('fo/ba/foobar', pathshorten('foo/bar/foobar', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
525 call assert_equal('/fo/ba/foobar', pathshorten('/foo/bar/foobar', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
526 call assert_equal('.fo/bar', pathshorten('.foo/bar', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
527 call assert_equal('~fo/bar', pathshorten('~foo/bar', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
528 call assert_equal('~.fo/bar', pathshorten('~.foo/bar', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
529 call assert_equal('.~fo/bar', pathshorten('.~foo/bar', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
530 call assert_equal('~/fo/bar', pathshorten('~/foo/bar', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
531 call assert_fails('call pathshorten([],2)', 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
532 call assert_notequal('~/fo/bar', pathshorten('~/foo/bar', 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
533 call assert_equal('~/foo/bar', pathshorten('~/foo/bar', 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
534 call assert_equal('~/f/bar', pathshorten('~/foo/bar', 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
535 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
536
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
537 func Test_strpart()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
538 call assert_equal('de', strpart('abcdefg', 3, 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
539 call assert_equal('ab', strpart('abcdefg', -2, 4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
540 call assert_equal('abcdefg', 'abcdefg'->strpart(-2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
541 call assert_equal('fg', strpart('abcdefg', 5, 4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
542 call assert_equal('defg', strpart('abcdefg', 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
543 call assert_equal('', strpart('abcdefg', 10))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
544 call assert_fails("let s=strpart('abcdef', [])", 'E745:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
545
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
546 call assert_equal('lép', strpart('éléphant', 2, 4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
547 call assert_equal('léphant', strpart('éléphant', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
548
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
549 call assert_equal('é', strpart('éléphant', 0, 1, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
550 call assert_equal('ép', strpart('éléphant', 3, 2, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
551 call assert_equal('ó', strpart('cómposed', 1, 1, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
552 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
553
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
554 func Test_tolower()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
555 call assert_equal("", tolower(""))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
556
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
557 " Test with all printable ASCII characters.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
558 call assert_equal(' !"#$%&''()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz[\]^_`abcdefghijklmnopqrstuvwxyz{|}~',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
559 \ tolower(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
560
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
561 " Test with a few uppercase diacritics.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
562 call assert_equal("aàáâãäåāăąǎǟǡả", tolower("AÀÁÂÃÄÅĀĂĄǍǞǠẢ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
563 call assert_equal("bḃḇ", tolower("BḂḆ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
564 call assert_equal("cçćĉċč", tolower("CÇĆĈĊČ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
565 call assert_equal("dďđḋḏḑ", tolower("DĎĐḊḎḐ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
566 call assert_equal("eèéêëēĕėęěẻẽ", tolower("EÈÉÊËĒĔĖĘĚẺẼ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
567 call assert_equal("fḟ ", tolower("FḞ "))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
568 call assert_equal("gĝğġģǥǧǵḡ", tolower("GĜĞĠĢǤǦǴḠ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
569 call assert_equal("hĥħḣḧḩ", tolower("HĤĦḢḦḨ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
570 call assert_equal("iìíîïĩīĭįiǐỉ", tolower("IÌÍÎÏĨĪĬĮİǏỈ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
571 call assert_equal("jĵ", tolower("JĴ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
572 call assert_equal("kķǩḱḵ", tolower("KĶǨḰḴ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
573 call assert_equal("lĺļľŀłḻ", tolower("LĹĻĽĿŁḺ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
574 call assert_equal("mḿṁ", tolower("MḾṀ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
575 call assert_equal("nñńņňṅṉ", tolower("NÑŃŅŇṄṈ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
576 call assert_equal("oòóôõöøōŏőơǒǫǭỏ", tolower("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
577 call assert_equal("pṕṗ", tolower("PṔṖ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
578 call assert_equal("q", tolower("Q"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
579 call assert_equal("rŕŗřṙṟ", tolower("RŔŖŘṘṞ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
580 call assert_equal("sśŝşšṡ", tolower("SŚŜŞŠṠ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
581 call assert_equal("tţťŧṫṯ", tolower("TŢŤŦṪṮ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
582 call assert_equal("uùúûüũūŭůűųưǔủ", tolower("UÙÚÛÜŨŪŬŮŰŲƯǓỦ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
583 call assert_equal("vṽ", tolower("VṼ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
584 call assert_equal("wŵẁẃẅẇ", tolower("WŴẀẂẄẆ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
585 call assert_equal("xẋẍ", tolower("XẊẌ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
586 call assert_equal("yýŷÿẏỳỷỹ", tolower("YÝŶŸẎỲỶỸ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
587 call assert_equal("zźżžƶẑẕ", tolower("ZŹŻŽƵẐẔ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
588
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
589 " Test with a few lowercase diacritics, which should remain unchanged.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
590 call assert_equal("aàáâãäåāăąǎǟǡả", tolower("aàáâãäåāăąǎǟǡả"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
591 call assert_equal("bḃḇ", tolower("bḃḇ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
592 call assert_equal("cçćĉċč", tolower("cçćĉċč"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
593 call assert_equal("dďđḋḏḑ", tolower("dďđḋḏḑ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
594 call assert_equal("eèéêëēĕėęěẻẽ", tolower("eèéêëēĕėęěẻẽ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
595 call assert_equal("fḟ", tolower("fḟ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
596 call assert_equal("gĝğġģǥǧǵḡ", tolower("gĝğġģǥǧǵḡ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
597 call assert_equal("hĥħḣḧḩẖ", tolower("hĥħḣḧḩẖ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
598 call assert_equal("iìíîïĩīĭįǐỉ", tolower("iìíîïĩīĭįǐỉ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
599 call assert_equal("jĵǰ", tolower("jĵǰ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
600 call assert_equal("kķǩḱḵ", tolower("kķǩḱḵ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
601 call assert_equal("lĺļľŀłḻ", tolower("lĺļľŀłḻ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
602 call assert_equal("mḿṁ ", tolower("mḿṁ "))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
603 call assert_equal("nñńņňʼnṅṉ", tolower("nñńņňʼnṅṉ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
604 call assert_equal("oòóôõöøōŏőơǒǫǭỏ", tolower("oòóôõöøōŏőơǒǫǭỏ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
605 call assert_equal("pṕṗ", tolower("pṕṗ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
606 call assert_equal("q", tolower("q"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
607 call assert_equal("rŕŗřṙṟ", tolower("rŕŗřṙṟ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
608 call assert_equal("sśŝşšṡ", tolower("sśŝşšṡ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
609 call assert_equal("tţťŧṫṯẗ", tolower("tţťŧṫṯẗ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
610 call assert_equal("uùúûüũūŭůűųưǔủ", tolower("uùúûüũūŭůűųưǔủ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
611 call assert_equal("vṽ", tolower("vṽ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
612 call assert_equal("wŵẁẃẅẇẘ", tolower("wŵẁẃẅẇẘ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
613 call assert_equal("ẋẍ", tolower("ẋẍ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
614 call assert_equal("yýÿŷẏẙỳỷỹ", tolower("yýÿŷẏẙỳỷỹ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
615 call assert_equal("zźżžƶẑẕ", tolower("zźżžƶẑẕ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
616
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
617 " According to https://twitter.com/jifa/status/625776454479970304
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
618 " Ⱥ (U+023A) and Ⱦ (U+023E) are the *only* code points to increase
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
619 " in length (2 to 3 bytes) when lowercased. So let's test them.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
620 call assert_equal("ⱥ ⱦ", tolower("Ⱥ Ⱦ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
621
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
622 " This call to tolower with invalid utf8 sequence used to cause access to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
623 " invalid memory.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
624 call tolower("\xC0\x80\xC0")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
625 call tolower("123\xC0\x80\xC0")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
626
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
627 " Test in latin1 encoding
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
628 let save_enc = &encoding
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
629 set encoding=latin1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
630 call assert_equal("abc", tolower("ABC"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
631 let &encoding = save_enc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
632 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
633
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
634 func Test_toupper()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
635 call assert_equal("", toupper(""))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
636
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
637 " Test with all printable ASCII characters.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
638 call assert_equal(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
639 \ toupper(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
640
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
641 " Test with a few lowercase diacritics.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
642 call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", "aàáâãäåāăąǎǟǡả"->toupper())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
643 call assert_equal("BḂḆ", toupper("bḃḇ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
644 call assert_equal("CÇĆĈĊČ", toupper("cçćĉċč"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
645 call assert_equal("DĎĐḊḎḐ", toupper("dďđḋḏḑ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
646 call assert_equal("EÈÉÊËĒĔĖĘĚẺẼ", toupper("eèéêëēĕėęěẻẽ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
647 call assert_equal("FḞ", toupper("fḟ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
648 call assert_equal("GĜĞĠĢǤǦǴḠ", toupper("gĝğġģǥǧǵḡ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
649 call assert_equal("HĤĦḢḦḨẖ", toupper("hĥħḣḧḩẖ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
650 call assert_equal("IÌÍÎÏĨĪĬĮǏỈ", toupper("iìíîïĩīĭįǐỉ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
651 call assert_equal("JĴǰ", toupper("jĵǰ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
652 call assert_equal("KĶǨḰḴ", toupper("kķǩḱḵ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
653 call assert_equal("LĹĻĽĿŁḺ", toupper("lĺļľŀłḻ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
654 call assert_equal("MḾṀ ", toupper("mḿṁ "))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
655 call assert_equal("NÑŃŅŇʼnṄṈ", toupper("nñńņňʼnṅṉ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
656 call assert_equal("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ", toupper("oòóôõöøōŏőơǒǫǭỏ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
657 call assert_equal("PṔṖ", toupper("pṕṗ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
658 call assert_equal("Q", toupper("q"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
659 call assert_equal("RŔŖŘṘṞ", toupper("rŕŗřṙṟ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
660 call assert_equal("SŚŜŞŠṠ", toupper("sśŝşšṡ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
661 call assert_equal("TŢŤŦṪṮẗ", toupper("tţťŧṫṯẗ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
662 call assert_equal("UÙÚÛÜŨŪŬŮŰŲƯǓỦ", toupper("uùúûüũūŭůűųưǔủ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
663 call assert_equal("VṼ", toupper("vṽ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
664 call assert_equal("WŴẀẂẄẆẘ", toupper("wŵẁẃẅẇẘ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
665 call assert_equal("ẊẌ", toupper("ẋẍ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
666 call assert_equal("YÝŸŶẎẙỲỶỸ", toupper("yýÿŷẏẙỳỷỹ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
667 call assert_equal("ZŹŻŽƵẐẔ", toupper("zźżžƶẑẕ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
668
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
669 " Test that uppercase diacritics, which should remain unchanged.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
670 call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", toupper("AÀÁÂÃÄÅĀĂĄǍǞǠẢ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
671 call assert_equal("BḂḆ", toupper("BḂḆ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
672 call assert_equal("CÇĆĈĊČ", toupper("CÇĆĈĊČ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
673 call assert_equal("DĎĐḊḎḐ", toupper("DĎĐḊḎḐ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
674 call assert_equal("EÈÉÊËĒĔĖĘĚẺẼ", toupper("EÈÉÊËĒĔĖĘĚẺẼ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
675 call assert_equal("FḞ ", toupper("FḞ "))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
676 call assert_equal("GĜĞĠĢǤǦǴḠ", toupper("GĜĞĠĢǤǦǴḠ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
677 call assert_equal("HĤĦḢḦḨ", toupper("HĤĦḢḦḨ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
678 call assert_equal("IÌÍÎÏĨĪĬĮİǏỈ", toupper("IÌÍÎÏĨĪĬĮİǏỈ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
679 call assert_equal("JĴ", toupper("JĴ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
680 call assert_equal("KĶǨḰḴ", toupper("KĶǨḰḴ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
681 call assert_equal("LĹĻĽĿŁḺ", toupper("LĹĻĽĿŁḺ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
682 call assert_equal("MḾṀ", toupper("MḾṀ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
683 call assert_equal("NÑŃŅŇṄṈ", toupper("NÑŃŅŇṄṈ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
684 call assert_equal("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ", toupper("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
685 call assert_equal("PṔṖ", toupper("PṔṖ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
686 call assert_equal("Q", toupper("Q"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
687 call assert_equal("RŔŖŘṘṞ", toupper("RŔŖŘṘṞ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
688 call assert_equal("SŚŜŞŠṠ", toupper("SŚŜŞŠṠ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
689 call assert_equal("TŢŤŦṪṮ", toupper("TŢŤŦṪṮ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
690 call assert_equal("UÙÚÛÜŨŪŬŮŰŲƯǓỦ", toupper("UÙÚÛÜŨŪŬŮŰŲƯǓỦ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
691 call assert_equal("VṼ", toupper("VṼ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
692 call assert_equal("WŴẀẂẄẆ", toupper("WŴẀẂẄẆ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
693 call assert_equal("XẊẌ", toupper("XẊẌ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
694 call assert_equal("YÝŶŸẎỲỶỸ", toupper("YÝŶŸẎỲỶỸ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
695 call assert_equal("ZŹŻŽƵẐẔ", toupper("ZŹŻŽƵẐẔ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
696
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
697 call assert_equal("Ⱥ Ⱦ", toupper("ⱥ ⱦ"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
698
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
699 " This call to toupper with invalid utf8 sequence used to cause access to
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
700 " invalid memory.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
701 call toupper("\xC0\x80\xC0")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
702 call toupper("123\xC0\x80\xC0")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
703
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
704 " Test in latin1 encoding
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
705 let save_enc = &encoding
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
706 set encoding=latin1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
707 call assert_equal("ABC", toupper("abc"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
708 let &encoding = save_enc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
709 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
710
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
711 func Test_tr()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
712 call assert_equal('foo', tr('bar', 'bar', 'foo'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
713 call assert_equal('zxy', 'cab'->tr('abc', 'xyz'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
714 call assert_fails("let s=tr([], 'abc', 'def')", 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
715 call assert_fails("let s=tr('abc', [], 'def')", 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
716 call assert_fails("let s=tr('abc', 'abc', [])", 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
717 call assert_fails("let s=tr('abcd', 'abcd', 'def')", 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
718 set encoding=latin1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
719 call assert_fails("let s=tr('abcd', 'abcd', 'def')", 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
720 call assert_equal('hEllO', tr('hello', 'eo', 'EO'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
721 call assert_equal('hello', tr('hello', 'xy', 'ab'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
722 call assert_fails('call tr("abc", "123", "₁₂")', 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
723 set encoding=utf8
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
724 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
725
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
726 " Tests for the mode() function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
727 let current_modes = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
728 func Save_mode()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
729 let g:current_modes = mode(0) . '-' . mode(1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
730 return ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
731 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
732
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
733 " Test for the mode() function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
734 func Test_mode()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
735 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
736 call append(0, ["Blue Ball Black", "Brown Band Bowl", ""])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
737
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
738 " Only complete from the current buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
739 set complete=.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
740
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
741 inoremap <F2> <C-R>=Save_mode()<CR>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
742 xnoremap <F2> <Cmd>call Save_mode()<CR>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
743
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
744 normal! 3G
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
745 exe "normal i\<F2>\<Esc>"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
746 call assert_equal('i-i', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
747 " i_CTRL-P: Multiple matches
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
748 exe "normal i\<C-G>uBa\<C-P>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
749 call assert_equal('i-ic', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
750 " i_CTRL-P: Single match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
751 exe "normal iBro\<C-P>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
752 call assert_equal('i-ic', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
753 " i_CTRL-X
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
754 exe "normal iBa\<C-X>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
755 call assert_equal('i-ix', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
756 " i_CTRL-X CTRL-P: Multiple matches
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
757 exe "normal iBa\<C-X>\<C-P>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
758 call assert_equal('i-ic', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
759 " i_CTRL-X CTRL-P: Single match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
760 exe "normal iBro\<C-X>\<C-P>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
761 call assert_equal('i-ic', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
762 " i_CTRL-X CTRL-P + CTRL-P: Single match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
763 exe "normal iBro\<C-X>\<C-P>\<C-P>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
764 call assert_equal('i-ic', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
765 " i_CTRL-X CTRL-L: Multiple matches
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
766 exe "normal i\<C-X>\<C-L>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
767 call assert_equal('i-ic', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
768 " i_CTRL-X CTRL-L: Single match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
769 exe "normal iBlu\<C-X>\<C-L>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
770 call assert_equal('i-ic', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
771 " i_CTRL-P: No match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
772 exe "normal iCom\<C-P>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
773 call assert_equal('i-ic', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
774 " i_CTRL-X CTRL-P: No match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
775 exe "normal iCom\<C-X>\<C-P>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
776 call assert_equal('i-ic', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
777 " i_CTRL-X CTRL-L: No match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
778 exe "normal iabc\<C-X>\<C-L>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
779 call assert_equal('i-ic', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
780
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
781 exe "normal R\<F2>\<Esc>"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
782 call assert_equal('R-R', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
783 " R_CTRL-P: Multiple matches
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
784 exe "normal RBa\<C-P>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
785 call assert_equal('R-Rc', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
786 " R_CTRL-P: Single match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
787 exe "normal RBro\<C-P>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
788 call assert_equal('R-Rc', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
789 " R_CTRL-X
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
790 exe "normal RBa\<C-X>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
791 call assert_equal('R-Rx', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
792 " R_CTRL-X CTRL-P: Multiple matches
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
793 exe "normal RBa\<C-X>\<C-P>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
794 call assert_equal('R-Rc', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
795 " R_CTRL-X CTRL-P: Single match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
796 exe "normal RBro\<C-X>\<C-P>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
797 call assert_equal('R-Rc', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
798 " R_CTRL-X CTRL-P + CTRL-P: Single match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
799 exe "normal RBro\<C-X>\<C-P>\<C-P>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
800 call assert_equal('R-Rc', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
801 " R_CTRL-X CTRL-L: Multiple matches
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
802 exe "normal R\<C-X>\<C-L>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
803 call assert_equal('R-Rc', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
804 " R_CTRL-X CTRL-L: Single match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
805 exe "normal RBlu\<C-X>\<C-L>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
806 call assert_equal('R-Rc', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
807 " R_CTRL-P: No match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
808 exe "normal RCom\<C-P>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
809 call assert_equal('R-Rc', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
810 " R_CTRL-X CTRL-P: No match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
811 exe "normal RCom\<C-X>\<C-P>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
812 call assert_equal('R-Rc', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
813 " R_CTRL-X CTRL-L: No match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
814 exe "normal Rabc\<C-X>\<C-L>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
815 call assert_equal('R-Rc', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
816
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
817 exe "normal gR\<F2>\<Esc>"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
818 call assert_equal('R-Rv', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
819 " gR_CTRL-P: Multiple matches
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
820 exe "normal gRBa\<C-P>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
821 call assert_equal('R-Rvc', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
822 " gR_CTRL-P: Single match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
823 exe "normal gRBro\<C-P>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
824 call assert_equal('R-Rvc', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
825 " gR_CTRL-X
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
826 exe "normal gRBa\<C-X>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
827 call assert_equal('R-Rvx', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
828 " gR_CTRL-X CTRL-P: Multiple matches
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
829 exe "normal gRBa\<C-X>\<C-P>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
830 call assert_equal('R-Rvc', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
831 " gR_CTRL-X CTRL-P: Single match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
832 exe "normal gRBro\<C-X>\<C-P>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
833 call assert_equal('R-Rvc', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
834 " gR_CTRL-X CTRL-P + CTRL-P: Single match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
835 exe "normal gRBro\<C-X>\<C-P>\<C-P>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
836 call assert_equal('R-Rvc', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
837 " gR_CTRL-X CTRL-L: Multiple matches
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
838 exe "normal gR\<C-X>\<C-L>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
839 call assert_equal('R-Rvc', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
840 " gR_CTRL-X CTRL-L: Single match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
841 exe "normal gRBlu\<C-X>\<C-L>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
842 call assert_equal('R-Rvc', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
843 " gR_CTRL-P: No match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
844 exe "normal gRCom\<C-P>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
845 call assert_equal('R-Rvc', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
846 " gR_CTRL-X CTRL-P: No match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
847 exe "normal gRCom\<C-X>\<C-P>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
848 call assert_equal('R-Rvc', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
849 " gR_CTRL-X CTRL-L: No match
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
850 exe "normal gRabc\<C-X>\<C-L>\<F2>\<Esc>u"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
851 call assert_equal('R-Rvc', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
852
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
853 call assert_equal('n', 0->mode())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
854 call assert_equal('n', 1->mode())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
855
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
856 " i_CTRL-O
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
857 exe "normal i\<C-O>:call Save_mode()\<Cr>\<Esc>"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
858 call assert_equal("n-niI", g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
859
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
860 " R_CTRL-O
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
861 exe "normal R\<C-O>:call Save_mode()\<Cr>\<Esc>"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
862 call assert_equal("n-niR", g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
863
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
864 " gR_CTRL-O
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
865 exe "normal gR\<C-O>:call Save_mode()\<Cr>\<Esc>"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
866 call assert_equal("n-niV", g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
867
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
868 " How to test operator-pending mode?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
869
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
870 call feedkeys("v", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
871 call assert_equal('v', mode())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
872 call assert_equal('v', mode(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
873 call feedkeys("\<Esc>V", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
874 call assert_equal('V', mode())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
875 call assert_equal('V', mode(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
876 call feedkeys("\<Esc>\<C-V>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
877 call assert_equal("\<C-V>", mode())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
878 call assert_equal("\<C-V>", mode(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
879 call feedkeys("\<Esc>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
880
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
881 call feedkeys("gh", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
882 call assert_equal('s', mode())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
883 call assert_equal('s', mode(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
884 call feedkeys("\<Esc>gH", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
885 call assert_equal('S', mode())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
886 call assert_equal('S', mode(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
887 call feedkeys("\<Esc>g\<C-H>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
888 call assert_equal("\<C-S>", mode())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
889 call assert_equal("\<C-S>", mode(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
890 call feedkeys("\<Esc>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
891
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
892 " v_CTRL-O
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
893 exe "normal gh\<C-O>\<F2>\<Esc>"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
894 call assert_equal("v-vs", g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
895 exe "normal gH\<C-O>\<F2>\<Esc>"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
896 call assert_equal("V-Vs", g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
897 exe "normal g\<C-H>\<C-O>\<F2>\<Esc>"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
898 call assert_equal("\<C-V>-\<C-V>s", g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
899
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
900 call feedkeys(":echo \<C-R>=Save_mode()\<C-U>\<CR>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
901 call assert_equal('c-c', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
902 call feedkeys("gQecho \<C-R>=Save_mode()\<CR>\<CR>vi\<CR>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
903 call assert_equal('c-cv', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
904 call feedkeys("Qcall Save_mode()\<CR>vi\<CR>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
905 call assert_equal('c-ce', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
906 " How to test Ex mode?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
907
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
908 " Test mode in operatorfunc (it used to be Operator-pending).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
909 set operatorfunc=OperatorFunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
910 function OperatorFunc(_)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
911 call Save_mode()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
912 endfunction
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
913 execute "normal! g@l\<Esc>"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
914 call assert_equal('n-n', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
915 execute "normal! i\<C-o>g@l\<Esc>"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
916 call assert_equal('n-niI', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
917 execute "normal! R\<C-o>g@l\<Esc>"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
918 call assert_equal('n-niR', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
919 execute "normal! gR\<C-o>g@l\<Esc>"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
920 call assert_equal('n-niV', g:current_modes)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
921
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
922 if has('terminal')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
923 term
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
924 call feedkeys("\<C-W>N", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
925 call assert_equal('n', mode())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
926 call assert_equal('nt', mode(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
927 call feedkeys("aexit\<CR>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
928 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
929
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
930 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
931 iunmap <F2>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
932 xunmap <F2>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
933 set complete&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
934 set operatorfunc&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
935 delfunction OperatorFunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
936 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
937
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
938 " Test for append()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
939 func Test_append()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
940 enew!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
941 split
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
942 call assert_equal(0, append(1, []))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
943 call assert_equal(0, append(1, test_null_list()))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
944 call assert_equal(0, append(0, ["foo"]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
945 call assert_equal(0, append(1, []))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
946 call assert_equal(0, append(1, test_null_list()))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
947 call assert_equal(0, append(8, []))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
948 call assert_equal(0, append(9, test_null_list()))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
949 call assert_equal(['foo', ''], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
950 split
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
951 only
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
952 undo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
953 undo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
954
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
955 " Using $ instead of '$' must give an error
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
956 call assert_fails("call append($, 'foobar')", 'E116:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
957
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
958 call assert_fails("call append({}, '')", ['E728:', 'E728:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
959 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
960
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
961 " Test for setline()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
962 func Test_setline()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
963 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
964 call setline(0, ["foo"])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
965 call setline(0, [])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
966 call setline(0, test_null_list())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
967 call setline(1, ["bar"])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
968 call setline(1, [])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
969 call setline(1, test_null_list())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
970 call setline(2, [])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
971 call setline(2, test_null_list())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
972 call setline(3, [])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
973 call setline(3, test_null_list())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
974 call setline(2, ["baz"])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
975 call assert_equal(['bar', 'baz'], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
976 close!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
977 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
978
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
979 func Test_getbufvar()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
980 let bnr = bufnr('%')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
981 let b:var_num = '1234'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
982 let def_num = '5678'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
983 call assert_equal('1234', getbufvar(bnr, 'var_num'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
984 call assert_equal('1234', getbufvar(bnr, 'var_num', def_num))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
985
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
986 let bd = getbufvar(bnr, '')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
987 call assert_equal('1234', bd['var_num'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
988 call assert_true(exists("bd['changedtick']"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
989 call assert_equal(2, len(bd))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
990
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
991 let bd2 = getbufvar(bnr, '', def_num)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
992 call assert_equal(bd, bd2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
993
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
994 unlet b:var_num
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
995 call assert_equal(def_num, getbufvar(bnr, 'var_num', def_num))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
996 call assert_equal('', getbufvar(bnr, 'var_num'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
997
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
998 let bd = getbufvar(bnr, '')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
999 call assert_equal(1, len(bd))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1000 let bd = getbufvar(bnr, '',def_num)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1001 call assert_equal(1, len(bd))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1002
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1003 call assert_equal('', getbufvar(9999, ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1004 call assert_equal(def_num, getbufvar(9999, '', def_num))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1005 unlet def_num
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1006
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1007 call assert_equal(0, getbufvar(bnr, '&autoindent'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1008 call assert_equal(0, getbufvar(bnr, '&autoindent', 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1009
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1010 " Set and get a buffer-local variable
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1011 call setbufvar(bnr, 'bufvar_test', ['one', 'two'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1012 call assert_equal(['one', 'two'], getbufvar(bnr, 'bufvar_test'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1013
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1014 " Open new window with forced option values
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1015 set fileformats=unix,dos
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1016 new ++ff=dos ++bin ++enc=iso-8859-2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1017 call assert_equal('dos', getbufvar(bufnr('%'), '&fileformat'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1018 call assert_equal(1, getbufvar(bufnr('%'), '&bin'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1019 call assert_equal('iso-8859-2', getbufvar(bufnr('%'), '&fenc'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1020 close
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1021
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1022 " Get the b: dict.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1023 let b:testvar = 'one'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1024 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1025 let b:testvar = 'two'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1026 let thebuf = bufnr()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1027 wincmd w
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1028 call assert_equal('two', getbufvar(thebuf, 'testvar'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1029 call assert_equal('two', getbufvar(thebuf, '').testvar)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1030 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1031
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1032 set fileformats&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1033 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1034
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1035 func Test_last_buffer_nr()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1036 call assert_equal(bufnr('$'), last_buffer_nr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1037 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1038
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1039 func Test_stridx()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1040 call assert_equal(-1, stridx('', 'l'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1041 call assert_equal(0, stridx('', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1042 call assert_equal(0, 'hello'->stridx(''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1043 call assert_equal(-1, stridx('hello', 'L'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1044 call assert_equal(2, stridx('hello', 'l', -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1045 call assert_equal(2, stridx('hello', 'l', 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1046 call assert_equal(2, 'hello'->stridx('l', 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1047 call assert_equal(3, stridx('hello', 'l', 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1048 call assert_equal(-1, stridx('hello', 'l', 4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1049 call assert_equal(-1, stridx('hello', 'l', 10))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1050 call assert_equal(2, stridx('hello', 'll'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1051 call assert_equal(-1, stridx('hello', 'hello world'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1052 call assert_fails("let n=stridx('hello', [])", 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1053 call assert_fails("let n=stridx([], 'l')", 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1054 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1055
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1056 func Test_strridx()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1057 call assert_equal(-1, strridx('', 'l'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1058 call assert_equal(0, strridx('', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1059 call assert_equal(5, strridx('hello', ''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1060 call assert_equal(-1, strridx('hello', 'L'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1061 call assert_equal(3, 'hello'->strridx('l'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1062 call assert_equal(3, strridx('hello', 'l', 10))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1063 call assert_equal(3, strridx('hello', 'l', 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1064 call assert_equal(2, strridx('hello', 'l', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1065 call assert_equal(-1, strridx('hello', 'l', 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1066 call assert_equal(-1, strridx('hello', 'l', 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1067 call assert_equal(-1, strridx('hello', 'l', -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1068 call assert_equal(2, strridx('hello', 'll'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1069 call assert_equal(-1, strridx('hello', 'hello world'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1070 call assert_fails("let n=strridx('hello', [])", 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1071 call assert_fails("let n=strridx([], 'l')", 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1072 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1073
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1074 func Test_match_func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1075 call assert_equal(4, match('testing', 'ing'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1076 call assert_equal(4, 'testing'->match('ing', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1077 call assert_equal(-1, match('testing', 'ing', 5))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1078 call assert_equal(-1, match('testing', 'ing', 8))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1079 call assert_equal(1, match(['vim', 'testing', 'execute'], 'ing'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1080 call assert_equal(-1, match(['vim', 'testing', 'execute'], 'img'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1081 call assert_fails("let x=match('vim', [])", 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1082 call assert_equal(3, match(['a', 'b', 'c', 'a'], 'a', 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1083 call assert_equal(-1, match(['a', 'b', 'c', 'a'], 'a', 5))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1084 call assert_equal(4, match('testing', 'ing', -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1085 call assert_fails("let x=match('testing', 'ing', 0, [])", 'E745:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1086 call assert_equal(-1, match(test_null_list(), 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1087 call assert_equal(-1, match('abc', '\\%('))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1088 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1089
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1090 func Test_matchend()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1091 call assert_equal(7, matchend('testing', 'ing'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1092 call assert_equal(7, 'testing'->matchend('ing', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1093 call assert_equal(-1, matchend('testing', 'ing', 5))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1094 call assert_equal(-1, matchend('testing', 'ing', 8))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1095 call assert_equal(match(['vim', 'testing', 'execute'], 'ing'), matchend(['vim', 'testing', 'execute'], 'ing'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1096 call assert_equal(match(['vim', 'testing', 'execute'], 'img'), matchend(['vim', 'testing', 'execute'], 'img'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1097 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1098
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1099 func Test_matchlist()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1100 call assert_equal(['acd', 'a', '', 'c', 'd', '', '', '', '', ''], matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1101 call assert_equal(['d', '', '', '', 'd', '', '', '', '', ''], 'acd'->matchlist('\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1102 call assert_equal([], matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1103 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1104
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1105 func Test_matchstr()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1106 call assert_equal('ing', matchstr('testing', 'ing'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1107 call assert_equal('ing', 'testing'->matchstr('ing', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1108 call assert_equal('', matchstr('testing', 'ing', 5))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1109 call assert_equal('', matchstr('testing', 'ing', 8))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1110 call assert_equal('testing', matchstr(['vim', 'testing', 'execute'], 'ing'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1111 call assert_equal('', matchstr(['vim', 'testing', 'execute'], 'img'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1112 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1113
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1114 func Test_matchstrpos()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1115 call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1116 call assert_equal(['ing', 4, 7], 'testing'->matchstrpos('ing', 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1117 call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 5))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1118 call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 8))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1119 call assert_equal(['ing', 1, 4, 7], matchstrpos(['vim', 'testing', 'execute'], 'ing'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1120 call assert_equal(['', -1, -1, -1], matchstrpos(['vim', 'testing', 'execute'], 'img'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1121 call assert_equal(['', -1, -1], matchstrpos(test_null_list(), '\a'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1122 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1123
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1124 func Test_nextnonblank_prevnonblank()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1125 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1126 insert
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1127 This
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1128
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1129
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1130 is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1131
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1132 a
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1133 Test
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1134 .
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1135 call assert_equal(0, nextnonblank(-1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1136 call assert_equal(0, nextnonblank(0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1137 call assert_equal(1, nextnonblank(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1138 call assert_equal(4, 2->nextnonblank())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1139 call assert_equal(4, nextnonblank(3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1140 call assert_equal(4, nextnonblank(4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1141 call assert_equal(6, nextnonblank(5))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1142 call assert_equal(6, nextnonblank(6))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1143 call assert_equal(7, nextnonblank(7))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1144 call assert_equal(0, 8->nextnonblank())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1145
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1146 call assert_equal(0, prevnonblank(-1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1147 call assert_equal(0, prevnonblank(0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1148 call assert_equal(1, 1->prevnonblank())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1149 call assert_equal(1, prevnonblank(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1150 call assert_equal(1, prevnonblank(3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1151 call assert_equal(4, prevnonblank(4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1152 call assert_equal(4, 5->prevnonblank())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1153 call assert_equal(6, prevnonblank(6))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1154 call assert_equal(7, prevnonblank(7))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1155 call assert_equal(0, prevnonblank(8))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1156 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1157 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1158
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1159 func Test_byte2line_line2byte()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1160 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1161 set endofline
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1162 call setline(1, ['a', 'bc', 'd'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1163
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1164 set fileformat=unix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1165 call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1166 \ map(range(-1, 8), 'byte2line(v:val)'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1167 call assert_equal([-1, -1, 1, 3, 6, 8, -1],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1168 \ map(range(-1, 5), 'line2byte(v:val)'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1169
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1170 set fileformat=mac
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1171 call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1172 \ map(range(-1, 8), 'v:val->byte2line()'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1173 call assert_equal([-1, -1, 1, 3, 6, 8, -1],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1174 \ map(range(-1, 5), 'v:val->line2byte()'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1175
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1176 set fileformat=dos
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1177 call assert_equal([-1, -1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, -1],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1178 \ map(range(-1, 11), 'byte2line(v:val)'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1179 call assert_equal([-1, -1, 1, 4, 8, 11, -1],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1180 \ map(range(-1, 5), 'line2byte(v:val)'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1181
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1182 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1183 set noendofline nofixendofline
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1184 normal a-
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1185 for ff in ["unix", "mac", "dos"]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1186 let &fileformat = ff
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1187 call assert_equal(1, line2byte(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1188 call assert_equal(2, line2byte(2)) " line2byte(line("$") + 1) is the buffer size plus one (as per :help line2byte).
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1189 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1190
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1191 set endofline& fixendofline& fileformat&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1192 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1193 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1194
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1195 " Test for byteidx() using a character index
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1196 func Test_byteidx()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1197 let a = '.é.' " one char of two bytes
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1198 call assert_equal(0, byteidx(a, 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1199 call assert_equal(1, byteidx(a, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1200 call assert_equal(3, byteidx(a, 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1201 call assert_equal(4, byteidx(a, 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1202 call assert_equal(-1, byteidx(a, 4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1203
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1204 let b = '.é.' " normal e with composing char
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1205 call assert_equal(0, b->byteidx(0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1206 call assert_equal(1, b->byteidx(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1207 call assert_equal(4, b->byteidx(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1208 call assert_equal(5, b->byteidx(3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1209 call assert_equal(-1, b->byteidx(4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1210
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1211 " string with multiple composing characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1212 let str = '-ą́-ą́'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1213 call assert_equal(0, byteidx(str, 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1214 call assert_equal(1, byteidx(str, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1215 call assert_equal(6, byteidx(str, 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1216 call assert_equal(7, byteidx(str, 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1217 call assert_equal(12, byteidx(str, 4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1218 call assert_equal(-1, byteidx(str, 5))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1219
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1220 " empty string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1221 call assert_equal(0, byteidx('', 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1222 call assert_equal(-1, byteidx('', 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1223
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1224 " error cases
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1225 call assert_fails("call byteidx([], 0)", 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1226 call assert_fails("call byteidx('abc', [])", 'E745:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1227 call assert_fails("call byteidx('abc', 0, {})", ['E728:', 'E728:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1228 call assert_fails("call byteidx('abc', 0, -1)", ['E1023:', 'E1023:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1229 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1230
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1231 " Test for byteidxcomp() using a character index
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1232 func Test_byteidxcomp()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1233 let a = '.é.' " one char of two bytes
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1234 call assert_equal(0, byteidxcomp(a, 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1235 call assert_equal(1, byteidxcomp(a, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1236 call assert_equal(3, byteidxcomp(a, 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1237 call assert_equal(4, byteidxcomp(a, 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1238 call assert_equal(-1, byteidxcomp(a, 4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1239
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1240 let b = '.é.' " normal e with composing char
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1241 call assert_equal(0, b->byteidxcomp(0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1242 call assert_equal(1, b->byteidxcomp(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1243 call assert_equal(2, b->byteidxcomp(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1244 call assert_equal(4, b->byteidxcomp(3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1245 call assert_equal(5, b->byteidxcomp(4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1246 call assert_equal(-1, b->byteidxcomp(5))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1247
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1248 " string with multiple composing characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1249 let str = '-ą́-ą́'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1250 call assert_equal(0, byteidxcomp(str, 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1251 call assert_equal(1, byteidxcomp(str, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1252 call assert_equal(2, byteidxcomp(str, 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1253 call assert_equal(4, byteidxcomp(str, 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1254 call assert_equal(6, byteidxcomp(str, 4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1255 call assert_equal(7, byteidxcomp(str, 5))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1256 call assert_equal(8, byteidxcomp(str, 6))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1257 call assert_equal(10, byteidxcomp(str, 7))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1258 call assert_equal(12, byteidxcomp(str, 8))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1259 call assert_equal(-1, byteidxcomp(str, 9))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1260
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1261 " empty string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1262 call assert_equal(0, byteidxcomp('', 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1263 call assert_equal(-1, byteidxcomp('', 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1264
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1265 " error cases
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1266 call assert_fails("call byteidxcomp([], 0)", 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1267 call assert_fails("call byteidxcomp('abc', [])", 'E745:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1268 call assert_fails("call byteidxcomp('abc', 0, {})", ['E728:', 'E728:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1269 call assert_fails("call byteidxcomp('abc', 0, -1)", ['E1023:', 'E1023:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1270 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1271
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1272 " Test for byteidx() using a UTF-16 index
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1273 func Test_byteidx_from_utf16_index()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1274 " string with single byte characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1275 let str = "abc"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1276 for i in range(3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1277 call assert_equal(i, byteidx(str, i, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1278 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1279 call assert_equal(3, byteidx(str, 3, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1280 call assert_equal(-1, byteidx(str, 4, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1281
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1282 " string with two byte characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1283 let str = "a©©b"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1284 call assert_equal(0, byteidx(str, 0, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1285 call assert_equal(1, byteidx(str, 1, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1286 call assert_equal(3, byteidx(str, 2, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1287 call assert_equal(5, byteidx(str, 3, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1288 call assert_equal(6, byteidx(str, 4, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1289 call assert_equal(-1, byteidx(str, 5, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1290
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1291 " string with two byte characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1292 let str = "a😊😊b"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1293 call assert_equal(0, byteidx(str, 0, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1294 call assert_equal(1, byteidx(str, 1, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1295 call assert_equal(1, byteidx(str, 2, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1296 call assert_equal(5, byteidx(str, 3, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1297 call assert_equal(5, byteidx(str, 4, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1298 call assert_equal(9, byteidx(str, 5, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1299 call assert_equal(10, byteidx(str, 6, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1300 call assert_equal(-1, byteidx(str, 7, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1301
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1302 " string with composing characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1303 let str = '-á-b́'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1304 call assert_equal(0, byteidx(str, 0, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1305 call assert_equal(1, byteidx(str, 1, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1306 call assert_equal(4, byteidx(str, 2, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1307 call assert_equal(5, byteidx(str, 3, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1308 call assert_equal(8, byteidx(str, 4, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1309 call assert_equal(-1, byteidx(str, 5, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1310
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1311 " string with multiple composing characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1312 let str = '-ą́-ą́'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1313 call assert_equal(0, byteidx(str, 0, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1314 call assert_equal(1, byteidx(str, 1, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1315 call assert_equal(6, byteidx(str, 2, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1316 call assert_equal(7, byteidx(str, 3, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1317 call assert_equal(12, byteidx(str, 4, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1318 call assert_equal(-1, byteidx(str, 5, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1319
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1320 " empty string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1321 call assert_equal(0, byteidx('', 0, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1322 call assert_equal(-1, byteidx('', 1, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1323
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1324 " error cases
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1325 call assert_fails('call byteidx(str, 0, [])', 'E745:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1326 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1327
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1328 " Test for byteidxcomp() using a UTF-16 index
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1329 func Test_byteidxcomp_from_utf16_index()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1330 " string with single byte characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1331 let str = "abc"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1332 for i in range(3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1333 call assert_equal(i, byteidxcomp(str, i, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1334 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1335 call assert_equal(3, byteidxcomp(str, 3, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1336 call assert_equal(-1, byteidxcomp(str, 4, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1337
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1338 " string with two byte characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1339 let str = "a©©b"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1340 call assert_equal(0, byteidxcomp(str, 0, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1341 call assert_equal(1, byteidxcomp(str, 1, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1342 call assert_equal(3, byteidxcomp(str, 2, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1343 call assert_equal(5, byteidxcomp(str, 3, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1344 call assert_equal(6, byteidxcomp(str, 4, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1345 call assert_equal(-1, byteidxcomp(str, 5, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1346
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1347 " string with two byte characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1348 let str = "a😊😊b"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1349 call assert_equal(0, byteidxcomp(str, 0, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1350 call assert_equal(1, byteidxcomp(str, 1, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1351 call assert_equal(1, byteidxcomp(str, 2, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1352 call assert_equal(5, byteidxcomp(str, 3, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1353 call assert_equal(5, byteidxcomp(str, 4, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1354 call assert_equal(9, byteidxcomp(str, 5, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1355 call assert_equal(10, byteidxcomp(str, 6, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1356 call assert_equal(-1, byteidxcomp(str, 7, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1357
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1358 " string with composing characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1359 let str = '-á-b́'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1360 call assert_equal(0, byteidxcomp(str, 0, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1361 call assert_equal(1, byteidxcomp(str, 1, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1362 call assert_equal(2, byteidxcomp(str, 2, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1363 call assert_equal(4, byteidxcomp(str, 3, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1364 call assert_equal(5, byteidxcomp(str, 4, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1365 call assert_equal(6, byteidxcomp(str, 5, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1366 call assert_equal(8, byteidxcomp(str, 6, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1367 call assert_equal(-1, byteidxcomp(str, 7, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1368 call assert_fails('call byteidxcomp(str, 0, [])', 'E745:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1369
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1370 " string with multiple composing characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1371 let str = '-ą́-ą́'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1372 call assert_equal(0, byteidxcomp(str, 0, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1373 call assert_equal(1, byteidxcomp(str, 1, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1374 call assert_equal(2, byteidxcomp(str, 2, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1375 call assert_equal(4, byteidxcomp(str, 3, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1376 call assert_equal(6, byteidxcomp(str, 4, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1377 call assert_equal(7, byteidxcomp(str, 5, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1378 call assert_equal(8, byteidxcomp(str, 6, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1379 call assert_equal(10, byteidxcomp(str, 7, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1380 call assert_equal(12, byteidxcomp(str, 8, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1381 call assert_equal(-1, byteidxcomp(str, 9, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1382
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1383 " empty string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1384 call assert_equal(0, byteidxcomp('', 0, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1385 call assert_equal(-1, byteidxcomp('', 1, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1386
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1387 " error cases
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1388 call assert_fails('call byteidxcomp(str, 0, [])', 'E745:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1389 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1390
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1391 " Test for charidx() using a byte index
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1392 func Test_charidx()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1393 let a = 'xáb́y'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1394 call assert_equal(0, charidx(a, 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1395 call assert_equal(1, charidx(a, 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1396 call assert_equal(2, charidx(a, 4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1397 call assert_equal(3, charidx(a, 7))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1398 call assert_equal(4, charidx(a, 8))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1399 call assert_equal(-1, charidx(a, 9))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1400 call assert_equal(-1, charidx(a, -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1401
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1402 " count composing characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1403 call assert_equal(0, a->charidx(0, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1404 call assert_equal(2, a->charidx(2, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1405 call assert_equal(3, a->charidx(4, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1406 call assert_equal(5, a->charidx(7, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1407 call assert_equal(6, a->charidx(8, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1408 call assert_equal(-1, a->charidx(9, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1409
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1410 " empty string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1411 call assert_equal(0, charidx('', 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1412 call assert_equal(-1, charidx('', 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1413 call assert_equal(0, charidx('', 0, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1414 call assert_equal(-1, charidx('', 1, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1415
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1416 " error cases
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1417 call assert_equal(0, charidx(test_null_string(), 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1418 call assert_equal(-1, charidx(test_null_string(), 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1419 call assert_fails('let x = charidx([], 1)', 'E1174:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1420 call assert_fails('let x = charidx("abc", [])', 'E1210:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1421 call assert_fails('let x = charidx("abc", 1, [])', 'E1212:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1422 call assert_fails('let x = charidx("abc", 1, -1)', 'E1212:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1423 call assert_fails('let x = charidx("abc", 1, 2)', 'E1212:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1424 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1425
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1426 " Test for charidx() using a UTF-16 index
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1427 func Test_charidx_from_utf16_index()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1428 " string with single byte characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1429 let str = "abc"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1430 for i in range(4)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1431 call assert_equal(i, charidx(str, i, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1432 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1433 call assert_equal(-1, charidx(str, 4, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1434
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1435 " string with two byte characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1436 let str = "a©©b"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1437 call assert_equal(0, charidx(str, 0, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1438 call assert_equal(1, charidx(str, 1, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1439 call assert_equal(2, charidx(str, 2, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1440 call assert_equal(3, charidx(str, 3, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1441 call assert_equal(4, charidx(str, 4, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1442 call assert_equal(-1, charidx(str, 5, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1443
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1444 " string with four byte characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1445 let str = "a😊😊b"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1446 call assert_equal(0, charidx(str, 0, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1447 call assert_equal(1, charidx(str, 1, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1448 call assert_equal(1, charidx(str, 2, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1449 call assert_equal(2, charidx(str, 3, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1450 call assert_equal(2, charidx(str, 4, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1451 call assert_equal(3, charidx(str, 5, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1452 call assert_equal(4, charidx(str, 6, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1453 call assert_equal(-1, charidx(str, 7, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1454
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1455 " string with composing characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1456 let str = '-á-b́'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1457 for i in str->strcharlen()->range()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1458 call assert_equal(i, charidx(str, i, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1459 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1460 call assert_equal(4, charidx(str, 4, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1461 call assert_equal(-1, charidx(str, 5, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1462 for i in str->strchars()->range()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1463 call assert_equal(i, charidx(str, i, v:true, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1464 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1465 call assert_equal(6, charidx(str, 6, v:true, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1466 call assert_equal(-1, charidx(str, 7, v:true, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1467
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1468 " string with multiple composing characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1469 let str = '-ą́-ą́'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1470 for i in str->strcharlen()->range()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1471 call assert_equal(i, charidx(str, i, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1472 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1473 call assert_equal(4, charidx(str, 4, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1474 call assert_equal(-1, charidx(str, 5, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1475 for i in str->strchars()->range()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1476 call assert_equal(i, charidx(str, i, v:true, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1477 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1478 call assert_equal(8, charidx(str, 8, v:true, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1479 call assert_equal(-1, charidx(str, 9, v:true, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1480
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1481 " empty string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1482 call assert_equal(0, charidx('', 0, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1483 call assert_equal(-1, charidx('', 1, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1484 call assert_equal(0, charidx('', 0, v:true, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1485 call assert_equal(-1, charidx('', 1, v:true, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1486
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1487 " error cases
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1488 call assert_equal(0, charidx('', 0, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1489 call assert_equal(-1, charidx('', 1, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1490 call assert_equal(0, charidx('', 0, v:true, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1491 call assert_equal(-1, charidx('', 1, v:true, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1492 call assert_equal(0, charidx(test_null_string(), 0, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1493 call assert_equal(-1, charidx(test_null_string(), 1, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1494 call assert_fails('let x = charidx("abc", 1, v:false, [])', 'E1212:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1495 call assert_fails('let x = charidx("abc", 1, v:true, [])', 'E1212:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1496 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1497
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1498 " Test for utf16idx() using a byte index
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1499 func Test_utf16idx_from_byteidx()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1500 " UTF-16 index of a string with single byte characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1501 let str = "abc"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1502 for i in range(4)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1503 call assert_equal(i, utf16idx(str, i))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1504 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1505 call assert_equal(-1, utf16idx(str, 4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1506
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1507 " UTF-16 index of a string with two byte characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1508 let str = 'a©©b'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1509 call assert_equal(0, str->utf16idx(0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1510 call assert_equal(1, str->utf16idx(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1511 call assert_equal(1, str->utf16idx(2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1512 call assert_equal(2, str->utf16idx(3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1513 call assert_equal(2, str->utf16idx(4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1514 call assert_equal(3, str->utf16idx(5))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1515 call assert_equal(4, str->utf16idx(6))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1516 call assert_equal(-1, str->utf16idx(7))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1517
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1518 " UTF-16 index of a string with four byte characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1519 let str = 'a😊😊b'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1520 call assert_equal(0, utf16idx(str, 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1521 call assert_equal(1, utf16idx(str, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1522 call assert_equal(1, utf16idx(str, 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1523 call assert_equal(1, utf16idx(str, 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1524 call assert_equal(1, utf16idx(str, 4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1525 call assert_equal(3, utf16idx(str, 5))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1526 call assert_equal(3, utf16idx(str, 6))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1527 call assert_equal(3, utf16idx(str, 7))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1528 call assert_equal(3, utf16idx(str, 8))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1529 call assert_equal(5, utf16idx(str, 9))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1530 call assert_equal(6, utf16idx(str, 10))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1531 call assert_equal(-1, utf16idx(str, 11))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1532
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1533 " UTF-16 index of a string with composing characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1534 let str = '-á-b́'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1535 call assert_equal(0, utf16idx(str, 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1536 call assert_equal(1, utf16idx(str, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1537 call assert_equal(1, utf16idx(str, 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1538 call assert_equal(1, utf16idx(str, 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1539 call assert_equal(2, utf16idx(str, 4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1540 call assert_equal(3, utf16idx(str, 5))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1541 call assert_equal(3, utf16idx(str, 6))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1542 call assert_equal(3, utf16idx(str, 7))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1543 call assert_equal(4, utf16idx(str, 8))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1544 call assert_equal(-1, utf16idx(str, 9))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1545 call assert_equal(0, utf16idx(str, 0, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1546 call assert_equal(1, utf16idx(str, 1, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1547 call assert_equal(2, utf16idx(str, 2, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1548 call assert_equal(2, utf16idx(str, 3, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1549 call assert_equal(3, utf16idx(str, 4, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1550 call assert_equal(4, utf16idx(str, 5, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1551 call assert_equal(5, utf16idx(str, 6, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1552 call assert_equal(5, utf16idx(str, 7, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1553 call assert_equal(6, utf16idx(str, 8, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1554 call assert_equal(-1, utf16idx(str, 9, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1555
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1556 " string with multiple composing characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1557 let str = '-ą́-ą́'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1558 call assert_equal(0, utf16idx(str, 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1559 call assert_equal(1, utf16idx(str, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1560 call assert_equal(1, utf16idx(str, 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1561 call assert_equal(1, utf16idx(str, 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1562 call assert_equal(1, utf16idx(str, 4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1563 call assert_equal(1, utf16idx(str, 5))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1564 call assert_equal(2, utf16idx(str, 6))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1565 call assert_equal(3, utf16idx(str, 7))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1566 call assert_equal(3, utf16idx(str, 8))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1567 call assert_equal(3, utf16idx(str, 9))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1568 call assert_equal(3, utf16idx(str, 10))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1569 call assert_equal(3, utf16idx(str, 11))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1570 call assert_equal(4, utf16idx(str, 12))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1571 call assert_equal(-1, utf16idx(str, 13))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1572 call assert_equal(0, utf16idx(str, 0, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1573 call assert_equal(1, utf16idx(str, 1, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1574 call assert_equal(2, utf16idx(str, 2, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1575 call assert_equal(2, utf16idx(str, 3, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1576 call assert_equal(3, utf16idx(str, 4, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1577 call assert_equal(3, utf16idx(str, 5, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1578 call assert_equal(4, utf16idx(str, 6, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1579 call assert_equal(5, utf16idx(str, 7, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1580 call assert_equal(6, utf16idx(str, 8, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1581 call assert_equal(6, utf16idx(str, 9, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1582 call assert_equal(7, utf16idx(str, 10, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1583 call assert_equal(7, utf16idx(str, 11, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1584 call assert_equal(8, utf16idx(str, 12, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1585 call assert_equal(-1, utf16idx(str, 13, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1586
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1587 " empty string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1588 call assert_equal(0, utf16idx('', 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1589 call assert_equal(-1, utf16idx('', 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1590 call assert_equal(0, utf16idx('', 0, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1591 call assert_equal(-1, utf16idx('', 1, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1592
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1593 " error cases
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1594 call assert_equal(0, utf16idx("", 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1595 call assert_equal(-1, utf16idx("", 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1596 call assert_equal(-1, utf16idx("abc", -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1597 call assert_equal(0, utf16idx(test_null_string(), 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1598 call assert_equal(-1, utf16idx(test_null_string(), 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1599 call assert_fails('let l = utf16idx([], 0)', 'E1174:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1600 call assert_fails('let l = utf16idx("ab", [])', 'E1210:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1601 call assert_fails('let l = utf16idx("ab", 0, [])', 'E1212:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1602 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1603
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1604 " Test for utf16idx() using a character index
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1605 func Test_utf16idx_from_charidx()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1606 let str = "abc"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1607 for i in str->strcharlen()->range()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1608 call assert_equal(i, utf16idx(str, i, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1609 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1610 call assert_equal(3, utf16idx(str, 3, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1611 call assert_equal(-1, utf16idx(str, 4, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1612
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1613 " UTF-16 index of a string with two byte characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1614 let str = "a©©b"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1615 for i in str->strcharlen()->range()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1616 call assert_equal(i, utf16idx(str, i, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1617 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1618 call assert_equal(4, utf16idx(str, 4, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1619 call assert_equal(-1, utf16idx(str, 5, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1620
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1621 " UTF-16 index of a string with four byte characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1622 let str = "a😊😊b"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1623 call assert_equal(0, utf16idx(str, 0, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1624 call assert_equal(1, utf16idx(str, 1, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1625 call assert_equal(3, utf16idx(str, 2, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1626 call assert_equal(5, utf16idx(str, 3, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1627 call assert_equal(6, utf16idx(str, 4, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1628 call assert_equal(-1, utf16idx(str, 5, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1629
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1630 " UTF-16 index of a string with composing characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1631 let str = '-á-b́'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1632 for i in str->strcharlen()->range()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1633 call assert_equal(i, utf16idx(str, i, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1634 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1635 call assert_equal(4, utf16idx(str, 4, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1636 call assert_equal(-1, utf16idx(str, 5, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1637 for i in str->strchars()->range()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1638 call assert_equal(i, utf16idx(str, i, v:true, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1639 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1640 call assert_equal(6, utf16idx(str, 6, v:true, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1641 call assert_equal(-1, utf16idx(str, 7, v:true, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1642
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1643 " string with multiple composing characters
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1644 let str = '-ą́-ą́'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1645 for i in str->strcharlen()->range()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1646 call assert_equal(i, utf16idx(str, i, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1647 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1648 call assert_equal(4, utf16idx(str, 4, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1649 call assert_equal(-1, utf16idx(str, 5, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1650 for i in str->strchars()->range()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1651 call assert_equal(i, utf16idx(str, i, v:true, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1652 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1653 call assert_equal(8, utf16idx(str, 8, v:true, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1654 call assert_equal(-1, utf16idx(str, 9, v:true, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1655
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1656 " empty string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1657 call assert_equal(0, utf16idx('', 0, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1658 call assert_equal(-1, utf16idx('', 1, v:false, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1659 call assert_equal(0, utf16idx('', 0, v:true, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1660 call assert_equal(-1, utf16idx('', 1, v:true, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1661
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1662 " error cases
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1663 call assert_equal(0, utf16idx(test_null_string(), 0, v:true, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1664 call assert_equal(-1, utf16idx(test_null_string(), 1, v:true, v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1665 call assert_fails('let l = utf16idx("ab", 0, v:false, [])', 'E1212:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1666 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1667
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1668 " Test for strutf16len()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1669 func Test_strutf16len()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1670 call assert_equal(3, strutf16len('abc'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1671 call assert_equal(3, 'abc'->strutf16len(v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1672 call assert_equal(4, strutf16len('a©©b'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1673 call assert_equal(4, strutf16len('a©©b', v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1674 call assert_equal(6, strutf16len('a😊😊b'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1675 call assert_equal(6, strutf16len('a😊😊b', v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1676 call assert_equal(4, strutf16len('-á-b́'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1677 call assert_equal(6, strutf16len('-á-b́', v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1678 call assert_equal(4, strutf16len('-ą́-ą́'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1679 call assert_equal(8, strutf16len('-ą́-ą́', v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1680 call assert_equal(0, strutf16len(''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1681
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1682 " error cases
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1683 call assert_fails('let l = strutf16len([])', 'E1174:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1684 call assert_fails('let l = strutf16len("a", [])', 'E1212:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1685 call assert_equal(0, strutf16len(test_null_string()))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1686 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1687
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1688 func Test_count()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1689 let l = ['a', 'a', 'A', 'b']
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1690 call assert_equal(2, count(l, 'a'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1691 call assert_equal(1, count(l, 'A'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1692 call assert_equal(1, count(l, 'b'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1693 call assert_equal(0, count(l, 'B'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1694
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1695 call assert_equal(2, count(l, 'a', 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1696 call assert_equal(1, count(l, 'A', 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1697 call assert_equal(1, count(l, 'b', 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1698 call assert_equal(0, count(l, 'B', 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1699
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1700 call assert_equal(3, count(l, 'a', 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1701 call assert_equal(3, count(l, 'A', 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1702 call assert_equal(1, count(l, 'b', 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1703 call assert_equal(1, count(l, 'B', 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1704 call assert_equal(0, count(l, 'c', 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1705
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1706 call assert_equal(1, count(l, 'a', 0, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1707 call assert_equal(2, count(l, 'a', 1, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1708 call assert_fails('call count(l, "a", 0, 10)', 'E684:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1709 call assert_fails('call count(l, "a", [])', 'E745:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1710
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1711 let d = {1: 'a', 2: 'a', 3: 'A', 4: 'b'}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1712 call assert_equal(2, count(d, 'a'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1713 call assert_equal(1, count(d, 'A'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1714 call assert_equal(1, count(d, 'b'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1715 call assert_equal(0, count(d, 'B'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1716
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1717 call assert_equal(2, count(d, 'a', 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1718 call assert_equal(1, count(d, 'A', 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1719 call assert_equal(1, count(d, 'b', 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1720 call assert_equal(0, count(d, 'B', 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1721
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1722 call assert_equal(3, count(d, 'a', 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1723 call assert_equal(3, count(d, 'A', 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1724 call assert_equal(1, count(d, 'b', 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1725 call assert_equal(1, count(d, 'B', 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1726 call assert_equal(0, count(d, 'c', 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1727
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1728 call assert_fails('call count(d, "a", 0, 1)', 'E474:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1729
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1730 call assert_equal(0, count("foo", "bar"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1731 call assert_equal(1, count("foo", "oo"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1732 call assert_equal(2, count("foo", "o"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1733 call assert_equal(0, count("foo", "O"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1734 call assert_equal(2, count("foo", "O", 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1735 call assert_equal(2, count("fooooo", "oo"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1736 call assert_equal(0, count("foo", ""))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1737
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1738 call assert_fails('call count(0, 0)', 'E712:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1739 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1740
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1741 func Test_changenr()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1742 new Xchangenr
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1743 call assert_equal(0, changenr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1744 norm ifoo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1745 call assert_equal(1, changenr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1746 set undolevels=10
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1747 norm Sbar
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1748 call assert_equal(2, changenr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1749 undo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1750 call assert_equal(1, changenr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1751 redo
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1752 call assert_equal(2, changenr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1753 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1754 set undolevels&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1755 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1756
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1757 func Test_filewritable()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1758 new Xfilewritable
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1759 write!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1760 call assert_equal(1, filewritable('Xfilewritable'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1761
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1762 call assert_notequal(0, setfperm('Xfilewritable', 'r--r-----'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1763 call assert_equal(0, filewritable('Xfilewritable'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1764
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1765 call assert_notequal(0, setfperm('Xfilewritable', 'rw-r-----'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1766 call assert_equal(1, 'Xfilewritable'->filewritable())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1767
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1768 call assert_equal(0, filewritable('doesnotexist'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1769
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1770 call mkdir('Xwritedir', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1771 call assert_equal(2, filewritable('Xwritedir'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1772
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1773 call delete('Xfilewritable')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1774 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1775 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1776
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1777 func Test_Executable()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1778 if has('win32')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1779 call assert_equal(1, executable('notepad'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1780 call assert_equal(1, 'notepad.exe'->executable())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1781 call assert_equal(0, executable('notepad.exe.exe'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1782 call assert_equal(0, executable('shell32.dll'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1783 call assert_equal(0, executable('win.ini'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1784
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1785 " get "notepad" path and remove the leading drive and sep. (ex. 'C:\')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1786 let notepadcmd = exepath('notepad.exe')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1787 let driveroot = notepadcmd[:2]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1788 let notepadcmd = notepadcmd[3:]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1789 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1790 " check that the relative path works in /
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1791 execute 'lcd' driveroot
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1792 call assert_equal(1, executable(notepadcmd))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1793 call assert_equal(driveroot .. notepadcmd, notepadcmd->exepath())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1794 bwipe
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1795
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1796 " create "notepad.bat"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1797 call mkdir('Xnotedir')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1798 let notepadbat = fnamemodify('Xnotedir/notepad.bat', ':p')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1799 call writefile([], notepadbat)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1800 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1801 " check that the path and the pathext order is valid
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1802 lcd Xnotedir
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1803 let [pathext, $PATHEXT] = [$PATHEXT, '.com;.exe;.bat;.cmd']
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1804 call assert_equal(notepadbat, exepath('notepad'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1805 let $PATHEXT = pathext
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1806 bwipe
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1807 eval 'Xnotedir'->delete('rf')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1808 elseif has('unix')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1809 call assert_equal(1, 'cat'->executable())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1810 call assert_equal(0, executable('nodogshere'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1811
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1812 " get "cat" path and remove the leading /
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1813 let catcmd = exepath('cat')[1:]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1814 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1815 " check that the relative path works in /
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1816 lcd /
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1817 call assert_equal(1, executable(catcmd))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1818 let result = catcmd->exepath()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1819 " when using chroot looking for sbin/cat can return bin/cat, that is OK
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1820 if catcmd =~ '\<sbin\>' && result =~ '\<bin\>'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1821 call assert_equal('/' .. substitute(catcmd, '\<sbin\>', 'bin', ''), result)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1822 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1823 " /bin/cat and /usr/bin/cat may be hard linked, we could get either
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1824 let result = substitute(result, '/usr/bin/cat', '/bin/cat', '')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1825 let catcmd = substitute(catcmd, 'usr/bin/cat', 'bin/cat', '')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1826 call assert_equal('/' .. catcmd, result)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1827 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1828 bwipe
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1829 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1830 throw 'Skipped: does not work on this platform'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1831 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1832 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1833
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1834 func Test_executable_windows_store_apps()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1835 CheckMSWindows
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1836
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1837 " Windows Store apps install some 'decoy' .exe that require some careful
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1838 " handling as they behave similarly to symlinks.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1839 let app_dir = expand("$LOCALAPPDATA\\Microsoft\\WindowsApps")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1840 if !isdirectory(app_dir)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1841 return
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1842 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1843
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1844 let save_path = $PATH
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1845 let $PATH = app_dir
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1846 " Ensure executable() finds all the app .exes
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1847 for entry in readdir(app_dir)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1848 if entry =~ '\.exe$'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1849 call assert_true(executable(entry))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1850 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1851 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1852
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1853 let $PATH = save_path
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1854 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1855
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1856 func Test_executable_longname()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1857 CheckMSWindows
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1858
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1859 " Create a temporary .bat file with 205 characters in the name.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1860 " Maximum length of a filename (including the path) on MS-Windows is 259
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1861 " characters.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1862 " See https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1863 let len = 259 - getcwd()->len() - 6
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1864 if len > 200
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1865 let len = 200
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1866 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1867
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1868 let fname = 'X' . repeat('あ', len) . '.bat'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1869 call writefile([], fname)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1870 call assert_equal(1, executable(fname))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1871 call delete(fname)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1872 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1873
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1874 func Test_hostname()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1875 let hostname_vim = hostname()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1876 if has('unix')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1877 let hostname_system = systemlist('uname -n')[0]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1878 call assert_equal(hostname_vim, hostname_system)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1879 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1880 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1881
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1882 func Test_getpid()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1883 " getpid() always returns the same value within a vim instance.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1884 call assert_equal(getpid(), getpid())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1885 if has('unix')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1886 call assert_equal(systemlist('echo $PPID')[0], string(getpid()))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1887 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1888 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1889
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1890 func Test_hlexists()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1891 call assert_equal(0, hlexists('does_not_exist'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1892 call assert_equal(0, 'Number'->hlexists())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1893 call assert_equal(0, highlight_exists('does_not_exist'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1894 call assert_equal(0, highlight_exists('Number'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1895 syntax on
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1896 call assert_equal(0, hlexists('does_not_exist'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1897 call assert_equal(1, hlexists('Number'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1898 call assert_equal(0, highlight_exists('does_not_exist'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1899 call assert_equal(1, highlight_exists('Number'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1900 syntax off
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1901 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1902
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1903 " Test for the col() function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1904 func Test_col()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1905 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1906 call setline(1, 'abcdef')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1907 norm gg4|mx6|mY2|
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1908 call assert_equal(2, col('.'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1909 call assert_equal(7, col('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1910 call assert_equal(2, col('v'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1911 call assert_equal(4, col("'x"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1912 call assert_equal(6, col("'Y"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1913 call assert_equal(2, [1, 2]->col())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1914 call assert_equal(7, col([1, '$']))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1915
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1916 call assert_equal(0, col(''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1917 call assert_equal(0, col('x'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1918 call assert_equal(0, col([2, '$']))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1919 call assert_equal(0, col([1, 100]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1920 call assert_equal(0, col([1]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1921 call assert_equal(0, col(test_null_list()))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1922 call assert_fails('let c = col({})', 'E1222:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1923 call assert_fails('let c = col(".", [])', 'E1210:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1924
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1925 " test for getting the visual start column
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1926 func T()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1927 let g:Vcol = col('v')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1928 return ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1929 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1930 let g:Vcol = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1931 xmap <expr> <F2> T()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1932 exe "normal gg3|ve\<F2>"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1933 call assert_equal(3, g:Vcol)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1934 xunmap <F2>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1935 delfunc T
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1936
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1937 " Test for the visual line start and end marks '< and '>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1938 call setline(1, ['one', 'one two', 'one two three'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1939 "normal! ggVG
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1940 call feedkeys("ggVG\<Esc>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1941 call assert_equal(1, col("'<"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1942 call assert_equal(14, col("'>"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1943 " Delete the last line of the visually selected region
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1944 $d
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1945 call assert_notequal(14, col("'>"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1946
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1947 " Test with 'virtualedit'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1948 set virtualedit=all
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1949 call cursor(1, 10)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1950 call assert_equal(4, col('.'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1951 set virtualedit&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1952
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1953 " Test for getting the column number in another window
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1954 let winid = win_getid()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1955 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1956 call win_execute(winid, 'normal 1G$')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1957 call assert_equal(3, col('.', winid))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1958 call win_execute(winid, 'normal 2G')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1959 call assert_equal(8, col('$', winid))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1960 call assert_equal(0, col('.', 5001))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1961
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1962 bw!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1963 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1964
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1965 " Test for input()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1966 func Test_input_func()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1967 " Test for prompt with multiple lines
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1968 redir => v
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1969 call feedkeys(":let c = input(\"A\\nB\\nC\\n? \")\<CR>B\<CR>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1970 redir END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1971 call assert_equal("B", c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1972 call assert_equal(['A', 'B', 'C'], split(v, "\n"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1973
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1974 " Test for default value
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1975 call feedkeys(":let c = input('color? ', 'red')\<CR>\<CR>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1976 call assert_equal('red', c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1977
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1978 " Test for completion at the input prompt
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1979 func! Tcomplete(arglead, cmdline, pos)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1980 return "item1\nitem2\nitem3"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1981 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1982 call feedkeys(":let c = input('Q? ', '', 'custom,Tcomplete')\<CR>"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1983 \ .. "\<C-A>\<CR>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1984 delfunc Tcomplete
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1985 call assert_equal('item1 item2 item3', c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1986
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1987 " Test for using special characters as default input
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1988 call feedkeys(":let c = input('name? ', \"x\\<BS>y\")\<CR>\<CR>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1989 call assert_equal('y', c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1990
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1991 " Test for using text with composing characters as default input
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1992 call feedkeys(":let c = input('name? ', \"ã̳\")\<CR>\<CR>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1993 call assert_equal('ã̳', c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1994
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1995 " Test for using <CR> as default input
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1996 call feedkeys(":let c = input('name? ', \"\\<CR>\")\<CR>x\<CR>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1997 call assert_equal(' x', c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1998
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
1999 call assert_fails("call input('F:', '', 'invalid')", 'E180:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2000 call assert_fails("call input('F:', '', [])", 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2001 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2002
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2003 " Test for the inputdialog() function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2004 func Test_inputdialog()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2005 set timeout timeoutlen=10
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2006 if has('gui_running')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2007 call assert_fails('let v=inputdialog([], "xx")', 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2008 call assert_fails('let v=inputdialog("Q", [])', 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2009 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2010 call feedkeys(":let v=inputdialog('Q:', 'xx', 'yy')\<CR>\<CR>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2011 call assert_equal('xx', v)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2012 call feedkeys(":let v=inputdialog('Q:', 'xx', 'yy')\<CR>\<Esc>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2013 call assert_equal('yy', v)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2014 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2015 set timeout& timeoutlen&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2016 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2017
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2018 " Test for inputlist()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2019 func Test_inputlist()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2020 call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>1\<cr>", 'tx')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2021 call assert_equal(1, c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2022 call feedkeys(":let c = ['Select color:', '1. red', '2. green', '3. blue']->inputlist()\<cr>2\<cr>", 'tx')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2023 call assert_equal(2, c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2024 call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>3\<cr>", 'tx')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2025 call assert_equal(3, c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2026
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2027 " CR to cancel
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2028 call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>\<cr>", 'tx')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2029 call assert_equal(0, c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2030
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2031 " Esc to cancel
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2032 call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>\<Esc>", 'tx')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2033 call assert_equal(0, c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2034
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2035 " q to cancel
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2036 call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>q", 'tx')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2037 call assert_equal(0, c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2038
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2039 " Cancel after inputting a number
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2040 call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>5q", 'tx')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2041 call assert_equal(0, c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2042
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2043 " Use backspace to delete characters in the prompt
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2044 call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>1\<BS>3\<BS>2\<cr>", 'tx')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2045 call assert_equal(2, c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2046
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2047 " Use mouse to make a selection
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2048 call test_setmouse(&lines - 3, 2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2049 call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>\<LeftMouse>", 'tx')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2050 call assert_equal(1, c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2051 " Mouse click outside of the list
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2052 call test_setmouse(&lines - 6, 2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2053 call feedkeys(":let c = inputlist(['Select color:', '1. red', '2. green', '3. blue'])\<cr>\<LeftMouse>", 'tx')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2054 call assert_equal(-2, c)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2055
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2056 call assert_fails('call inputlist("")', 'E686:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2057 call assert_fails('call inputlist(test_null_list())', 'E686:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2058 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2059
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2060 func Test_range_inputlist()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2061 " flush out any garbage left in the buffer
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2062 while getchar(0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2063 endwhile
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2064
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2065 call feedkeys(":let result = inputlist(range(10))\<CR>1\<CR>", 'x')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2066 call assert_equal(1, result)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2067 call feedkeys(":let result = inputlist(range(3, 10))\<CR>1\<CR>", 'x')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2068 call assert_equal(1, result)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2069
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2070 unlet result
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2071 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2072
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2073 func Test_balloon_show()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2074 CheckFeature balloon_eval
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2075
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2076 " This won't do anything but must not crash either.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2077 call balloon_show('hi!')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2078 if !has('gui_running')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2079 call balloon_show(range(3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2080 call balloon_show([])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2081 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2082 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2083
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2084 func Test_setbufvar_options()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2085 " This tests that aucmd_prepbuf() and aucmd_restbuf() properly restore the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2086 " window layout and cursor position.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2087 call assert_equal(1, winnr('$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2088 split dummy_preview
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2089 resize 2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2090 set winfixheight winfixwidth
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2091 let prev_id = win_getid()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2092
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2093 wincmd j
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2094 let wh = winheight(0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2095 let dummy_buf = bufnr('dummy_buf1', v:true)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2096 call setbufvar(dummy_buf, '&buftype', 'nofile')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2097 execute 'belowright vertical split #' . dummy_buf
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2098 call assert_equal(wh, winheight(0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2099 let dum1_id = win_getid()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2100 call setline(1, 'foo')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2101 normal! V$
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2102 call assert_equal(4, col('.'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2103 call setbufvar('dummy_preview', '&buftype', 'nofile')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2104 call assert_equal(4, col('.'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2105
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2106 wincmd h
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2107 let wh = winheight(0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2108 call setline(1, 'foo')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2109 normal! V$
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2110 call assert_equal(4, col('.'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2111 let dummy_buf = bufnr('dummy_buf2', v:true)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2112 eval 'nofile'->setbufvar(dummy_buf, '&buftype')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2113 call assert_equal(4, col('.'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2114 execute 'belowright vertical split #' . dummy_buf
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2115 call assert_equal(wh, winheight(0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2116
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2117 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2118 call win_gotoid(prev_id)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2119 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2120 call win_gotoid(dum1_id)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2121 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2122 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2123
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2124 func Test_setbufvar_keep_window_title()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2125 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2126 if !has('title') || empty(&t_ts)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2127 throw "Skipped: can't get/set title"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2128 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2129
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2130 let lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2131 set title
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2132 edit Xa.txt
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2133 let g:buf = bufadd('Xb.txt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2134 inoremap <F2> <C-R>=setbufvar(g:buf, '&autoindent', 1) ?? ''<CR>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2135 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2136 call writefile(lines, 'Xsetbufvar', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2137 let buf = RunVimInTerminal('-S Xsetbufvar', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2138 call WaitForAssert({-> assert_match('Xa.txt', term_gettitle(buf))}, 1000)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2139
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2140 call term_sendkeys(buf, "i\<F2>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2141 call TermWait(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2142 call term_sendkeys(buf, "\<Esc>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2143 call TermWait(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2144 call assert_match('Xa.txt', term_gettitle(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2145
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2146 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2147 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2148
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2149 func Test_redo_in_nested_functions()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2150 nnoremap g. :set opfunc=Operator<CR>g@
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2151 function Operator( type, ... )
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2152 let @x = 'XXX'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2153 execute 'normal! g`[' . (a:type ==# 'line' ? 'V' : 'v') . 'g`]' . '"xp'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2154 endfunction
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2155
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2156 function! Apply()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2157 5,6normal! .
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2158 endfunction
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2159
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2160 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2161 call setline(1, repeat(['some "quoted" text', 'more "quoted" text'], 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2162 1normal g.i"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2163 call assert_equal('some "XXX" text', getline(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2164 3,4normal .
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2165 call assert_equal('some "XXX" text', getline(3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2166 call assert_equal('more "XXX" text', getline(4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2167 call Apply()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2168 call assert_equal('some "XXX" text', getline(5))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2169 call assert_equal('more "XXX" text', getline(6))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2170 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2171
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2172 nunmap g.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2173 delfunc Operator
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2174 delfunc Apply
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2175 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2176
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2177 func Test_trim()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2178 call assert_equal("Testing", trim(" \t\r\r\x0BTesting \t\n\r\n\t\x0B\x0B"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2179 call assert_equal("Testing", " \t \r\r\n\n\x0BTesting \t\n\r\n\t\x0B\x0B"->trim())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2180 call assert_equal("RESERVE", trim("xyz \twwRESERVEzyww \t\t", " wxyz\t"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2181 call assert_equal("wRE \tSERVEzyww", trim("wRE \tSERVEzyww"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2182 call assert_equal("abcd\t xxxx tail", trim(" \tabcd\t xxxx tail"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2183 call assert_equal("\tabcd\t xxxx tail", trim(" \tabcd\t xxxx tail", " "))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2184 call assert_equal(" \tabcd\t xxxx tail", trim(" \tabcd\t xxxx tail", "abx"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2185 call assert_equal("RESERVE", trim("你RESERVE好", "你好"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2186 call assert_equal("您R E SER V E早", trim("你好您R E SER V E早好你你", "你好"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2187 call assert_equal("你好您R E SER V E早好你你", trim(" \n\r\r 你好您R E SER V E早好你你 \t \x0B", ))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2188 call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" 你好您R E SER V E早好你你 \t \x0B", " 你好"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2189 call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" tteesstttt你好您R E SER V E早好你你 \t \x0B ttestt", " 你好tes"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2190 call assert_equal("您R E SER V E早好你你 \t \x0B", trim(" tteesstttt你好您R E SER V E早好你你 \t \x0B ttestt", " 你你你好好好tttsses"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2191 call assert_equal("留下", trim("这些些不要这些留下这些", "这些不要"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2192 call assert_equal("", trim("", ""))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2193 call assert_equal("a", trim("a", ""))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2194 call assert_equal("", trim("", "a"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2195
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2196 call assert_equal("vim", trim(" vim ", " ", 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2197 call assert_equal("vim ", trim(" vim ", " ", 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2198 call assert_equal(" vim", trim(" vim ", " ", 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2199 call assert_fails('eval trim(" vim ", " ", [])', 'E745:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2200 call assert_fails('eval trim(" vim ", " ", -1)', 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2201 call assert_fails('eval trim(" vim ", " ", 3)', 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2202 call assert_fails('eval trim(" vim ", 0)', 'E1174:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2203
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2204 let chars = join(map(range(1, 0x20) + [0xa0], {n -> n->nr2char()}), '')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2205 call assert_equal("x", trim(chars . "x" . chars))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2206
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2207 call assert_fails('let c=trim([])', 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2208 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2209
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2210 " Test for reg_recording() and reg_executing()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2211 func Test_reg_executing_and_recording()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2212 let s:reg_stat = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2213 func s:save_reg_stat()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2214 let s:reg_stat = reg_recording() . ':' . reg_executing()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2215 return ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2216 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2217
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2218 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2219 call s:save_reg_stat()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2220 call assert_equal(':', s:reg_stat)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2221 call feedkeys("qa\"=s:save_reg_stat()\<CR>pq", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2222 call assert_equal('a:', s:reg_stat)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2223 call feedkeys("@a", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2224 call assert_equal(':a', s:reg_stat)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2225 call feedkeys("qb@aq", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2226 call assert_equal('b:a', s:reg_stat)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2227 call feedkeys("q\"\"=s:save_reg_stat()\<CR>pq", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2228 call assert_equal('":', s:reg_stat)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2229
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2230 " :normal command saves and restores reg_executing
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2231 let s:reg_stat = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2232 let @q = ":call TestFunc()\<CR>:call s:save_reg_stat()\<CR>"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2233 func TestFunc() abort
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2234 normal! ia
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2235 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2236 call feedkeys("@q", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2237 call assert_equal(':q', s:reg_stat)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2238 delfunc TestFunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2239
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2240 " getchar() command saves and restores reg_executing
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2241 map W :call TestFunc()<CR>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2242 let @q = "W"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2243 let g:typed = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2244 let g:regs = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2245 func TestFunc() abort
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2246 let g:regs += [reg_executing()]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2247 let g:typed = getchar(0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2248 let g:regs += [reg_executing()]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2249 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2250 call feedkeys("@qy", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2251 call assert_equal(char2nr("y"), g:typed)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2252 call assert_equal(['q', 'q'], g:regs)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2253 delfunc TestFunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2254 unmap W
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2255 unlet g:typed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2256 unlet g:regs
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2257
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2258 " input() command saves and restores reg_executing
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2259 map W :call TestFunc()<CR>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2260 let @q = "W"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2261 let g:typed = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2262 let g:regs = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2263 func TestFunc() abort
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2264 let g:regs += [reg_executing()]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2265 let g:typed = '?'->input()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2266 let g:regs += [reg_executing()]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2267 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2268 call feedkeys("@qy\<CR>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2269 call assert_equal("y", g:typed)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2270 call assert_equal(['q', 'q'], g:regs)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2271 delfunc TestFunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2272 unmap W
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2273 unlet g:typed
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2274 unlet g:regs
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2275
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2276 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2277 delfunc s:save_reg_stat
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2278 unlet s:reg_stat
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2279 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2280
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2281 func Test_inputsecret()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2282 map W :call TestFunc()<CR>
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2283 let @q = "W"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2284 let g:typed1 = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2285 let g:typed2 = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2286 let g:regs = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2287 func TestFunc() abort
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2288 let g:typed1 = '?'->inputsecret()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2289 let g:typed2 = inputsecret('password: ')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2290 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2291 call feedkeys("@qsomething\<CR>else\<CR>", 'xt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2292 call assert_equal("something", g:typed1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2293 call assert_equal("else", g:typed2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2294 delfunc TestFunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2295 unmap W
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2296 unlet g:typed1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2297 unlet g:typed2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2298 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2299
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2300 func Test_getchar()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2301 call feedkeys('a', '')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2302 call assert_equal(char2nr('a'), getchar())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2303 call assert_equal(0, getchar(0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2304 call assert_equal(0, getchar(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2305
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2306 call feedkeys('a', '')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2307 call assert_equal('a', getcharstr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2308 call assert_equal('', getcharstr(0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2309 call assert_equal('', getcharstr(1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2310
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2311 call feedkeys("\<M-F2>", '')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2312 call assert_equal("\<M-F2>", getchar(0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2313 call assert_equal(0, getchar(0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2314
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2315 call setline(1, 'xxxx')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2316 call test_setmouse(1, 3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2317 let v:mouse_win = 9
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2318 let v:mouse_winid = 9
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2319 let v:mouse_lnum = 9
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2320 let v:mouse_col = 9
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2321 call feedkeys("\<S-LeftMouse>", '')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2322 call assert_equal("\<S-LeftMouse>", getchar())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2323 call assert_equal(1, v:mouse_win)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2324 call assert_equal(win_getid(1), v:mouse_winid)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2325 call assert_equal(1, v:mouse_lnum)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2326 call assert_equal(3, v:mouse_col)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2327 enew!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2328 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2329
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2330 func Test_libcall_libcallnr()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2331 CheckFeature libcall
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2332
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2333 if has('win32')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2334 let libc = 'msvcrt.dll'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2335 elseif has('mac')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2336 let libc = 'libSystem.B.dylib'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2337 elseif executable('ldd')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2338 let libc = matchstr(split(system('ldd ' . GetVimProg())), '/libc\.so\>')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2339 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2340 if get(l:, 'libc', '') ==# ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2341 " On Unix, libc.so can be in various places.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2342 if has('linux')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2343 " There is not documented but regarding the 1st argument of glibc's
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2344 " dlopen an empty string and nullptr are equivalent, so using an empty
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2345 " string for the 1st argument of libcall allows to call functions.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2346 let libc = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2347 elseif has('sun')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2348 " Set the path to libc.so according to the architecture.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2349 let test_bits = system('file ' . GetVimProg())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2350 let test_arch = system('uname -p')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2351 if test_bits =~ '64-bit' && test_arch =~ 'sparc'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2352 let libc = '/usr/lib/sparcv9/libc.so'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2353 elseif test_bits =~ '64-bit' && test_arch =~ 'i386'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2354 let libc = '/usr/lib/amd64/libc.so'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2355 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2356 let libc = '/usr/lib/libc.so'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2357 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2358 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2359 " Unfortunately skip this test until a good way is found.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2360 return
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2361 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2362 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2363
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2364 if has('win32')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2365 call assert_equal($USERPROFILE, 'USERPROFILE'->libcall(libc, 'getenv'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2366 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2367 call assert_equal($HOME, 'HOME'->libcall(libc, 'getenv'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2368 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2369
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2370 " If function returns NULL, libcall() should return an empty string.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2371 call assert_equal('', libcall(libc, 'getenv', 'X_ENV_DOES_NOT_EXIT'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2372
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2373 " Test libcallnr() with string and integer argument.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2374 call assert_equal(4, 'abcd'->libcallnr(libc, 'strlen'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2375 call assert_equal(char2nr('A'), char2nr('a')->libcallnr(libc, 'toupper'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2376
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2377 call assert_fails("call libcall(libc, 'Xdoesnotexist_', '')", ['', 'E364:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2378 call assert_fails("call libcallnr(libc, 'Xdoesnotexist_', '')", ['', 'E364:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2379
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2380 call assert_fails("call libcall('Xdoesnotexist_', 'getenv', 'HOME')", ['', 'E364:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2381 call assert_fails("call libcallnr('Xdoesnotexist_', 'strlen', 'abcd')", ['', 'E364:'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2382 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2383
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2384 sandbox function Fsandbox()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2385 normal ix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2386 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2387
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2388 func Test_func_sandbox()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2389 sandbox let F = {-> 'hello'}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2390 call assert_equal('hello', F())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2391
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2392 sandbox let F = {-> "normal ix\<Esc>"->execute()}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2393 call assert_fails('call F()', 'E48:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2394 unlet F
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2395
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2396 call assert_fails('call Fsandbox()', 'E48:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2397 delfunc Fsandbox
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2398
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2399 " From a sandbox try to set a predefined variable (which cannot be modified
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2400 " from a sandbox)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2401 call assert_fails('sandbox let v:lnum = 10', 'E794:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2402 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2403
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2404 func EditAnotherFile()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2405 let word = expand('<cword>')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2406 edit Xfuncrange2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2407 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2408
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2409 func Test_func_range_with_edit()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2410 " Define a function that edits another buffer, then call it with a range that
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2411 " is invalid in that buffer.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2412 call writefile(['just one line'], 'Xfuncrange2', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2413 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2414 eval 10->range()->setline(1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2415 write Xfuncrange1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2416 call assert_fails('5,8call EditAnotherFile()', 'E16:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2417
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2418 call delete('Xfuncrange1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2419 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2420 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2421
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2422 func Test_func_exists_on_reload()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2423 call writefile(['func ExistingFunction()', 'echo "yes"', 'endfunc'], 'Xfuncexists', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2424 call assert_equal(0, exists('*ExistingFunction'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2425 source Xfuncexists
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2426 call assert_equal(1, '*ExistingFunction'->exists())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2427 " Redefining a function when reloading a script is OK.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2428 source Xfuncexists
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2429 call assert_equal(1, exists('*ExistingFunction'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2430
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2431 " But redefining in another script is not OK.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2432 call writefile(['func ExistingFunction()', 'echo "yes"', 'endfunc'], 'Xfuncexists2', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2433 call assert_fails('source Xfuncexists2', 'E122:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2434
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2435 " Defining a new function from the cmdline should fail if the function is
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2436 " already defined
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2437 call assert_fails('call feedkeys(":func ExistingFunction()\<CR>", "xt")', 'E122:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2438
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2439 delfunc ExistingFunction
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2440 call assert_equal(0, exists('*ExistingFunction'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2441 call writefile([
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2442 \ 'func ExistingFunction()', 'echo "yes"', 'endfunc',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2443 \ 'func ExistingFunction()', 'echo "no"', 'endfunc',
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2444 \ ], 'Xfuncexists')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2445 call assert_fails('source Xfuncexists', 'E122:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2446 call assert_equal(1, exists('*ExistingFunction'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2447
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2448 delfunc ExistingFunction
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2449 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2450
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2451 " Test confirm({msg} [, {choices} [, {default} [, {type}]]])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2452 func Test_confirm()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2453 CheckUnix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2454 CheckNotGui
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2455
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2456 call feedkeys('o', 'L')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2457 let a = confirm('Press O to proceed')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2458 call assert_equal(1, a)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2459
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2460 call feedkeys('y', 'L')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2461 let a = 'Are you sure?'->confirm("&Yes\n&No")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2462 call assert_equal(1, a)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2463
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2464 call feedkeys('n', 'L')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2465 let a = confirm('Are you sure?', "&Yes\n&No")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2466 call assert_equal(2, a)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2467
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2468 " confirm() should return 0 when pressing CTRL-C.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2469 call feedkeys("\<C-C>", 'L')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2470 let a = confirm('Are you sure?', "&Yes\n&No")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2471 call assert_equal(0, a)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2472
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2473 " <Esc> requires another character to avoid it being seen as the start of an
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2474 " escape sequence. Zero should be harmless.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2475 eval "\<Esc>0"->feedkeys('L')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2476 let a = confirm('Are you sure?', "&Yes\n&No")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2477 call assert_equal(0, a)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2478
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2479 " Default choice is returned when pressing <CR>.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2480 call feedkeys("\<CR>", 'L')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2481 let a = confirm('Are you sure?', "&Yes\n&No")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2482 call assert_equal(1, a)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2483
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2484 call feedkeys("\<CR>", 'L')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2485 let a = confirm('Are you sure?', "&Yes\n&No", 2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2486 call assert_equal(2, a)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2487
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2488 call feedkeys("\<CR>", 'L')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2489 let a = confirm('Are you sure?', "&Yes\n&No", 0)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2490 call assert_equal(0, a)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2491
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2492 " Test with the {type} 4th argument
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2493 for type in ['Error', 'Question', 'Info', 'Warning', 'Generic']
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2494 call feedkeys('y', 'L')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2495 let a = confirm('Are you sure?', "&Yes\n&No\n", 1, type)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2496 call assert_equal(1, a)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2497 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2498
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2499 call assert_fails('call confirm([])', 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2500 call assert_fails('call confirm("Are you sure?", [])', 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2501 call assert_fails('call confirm("Are you sure?", "&Yes\n&No\n", [])', 'E745:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2502 call assert_fails('call confirm("Are you sure?", "&Yes\n&No\n", 0, [])', 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2503 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2504
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2505 func Test_platform_name()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2506 " The system matches at most only one name.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2507 let names = ['amiga', 'bsd', 'hpux', 'linux', 'mac', 'qnx', 'sun', 'vms', 'win32', 'win32unix']
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2508 call assert_inrange(0, 1, len(filter(copy(names), 'has(v:val)')))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2509
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2510 " Is Unix?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2511 call assert_equal(has('bsd'), has('bsd') && has('unix'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2512 call assert_equal(has('hpux'), has('hpux') && has('unix'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2513 call assert_equal(has('linux'), has('linux') && has('unix'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2514 call assert_equal(has('mac'), has('mac') && has('unix'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2515 call assert_equal(has('qnx'), has('qnx') && has('unix'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2516 call assert_equal(has('sun'), has('sun') && has('unix'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2517 call assert_equal(has('win32'), has('win32') && !has('unix'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2518 call assert_equal(has('win32unix'), has('win32unix') && has('unix'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2519
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2520 if has('unix') && executable('uname')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2521 let uname = system('uname')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2522 " GNU userland on BSD kernels (e.g., GNU/kFreeBSD) don't have BSD defined
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2523 call assert_equal(uname =~? '\%(GNU/k\w\+\)\@<!BSD\|DragonFly', has('bsd'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2524 call assert_equal(uname =~? 'HP-UX', has('hpux'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2525 call assert_equal(uname =~? 'Linux', has('linux'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2526 call assert_equal(uname =~? 'Darwin', has('mac'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2527 call assert_equal(uname =~? 'QNX', has('qnx'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2528 call assert_equal(uname =~? 'SunOS', has('sun'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2529 call assert_equal(uname =~? 'CYGWIN\|MSYS', has('win32unix'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2530 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2531 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2532
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2533 func Test_readdir()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2534 call mkdir('Xreaddir', 'R')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2535 call writefile([], 'Xreaddir/foo.txt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2536 call writefile([], 'Xreaddir/bar.txt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2537 call mkdir('Xreaddir/dir')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2538
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2539 " All results
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2540 let files = readdir('Xreaddir')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2541 call assert_equal(['bar.txt', 'dir', 'foo.txt'], sort(files))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2542
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2543 " Only results containing "f"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2544 let files = 'Xreaddir'->readdir({ x -> stridx(x, 'f') != -1 })
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2545 call assert_equal(['foo.txt'], sort(files))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2546
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2547 " Only .txt files
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2548 let files = readdir('Xreaddir', { x -> x =~ '.txt$' })
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2549 call assert_equal(['bar.txt', 'foo.txt'], sort(files))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2550
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2551 " Only .txt files with string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2552 let files = readdir('Xreaddir', 'v:val =~ ".txt$"')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2553 call assert_equal(['bar.txt', 'foo.txt'], sort(files))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2554
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2555 " Limit to 1 result.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2556 let l = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2557 let files = readdir('Xreaddir', {x -> len(add(l, x)) == 2 ? -1 : 1})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2558 call assert_equal(1, len(files))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2559
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2560 " Nested readdir() must not crash
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2561 let files = readdir('Xreaddir', 'readdir("Xreaddir", "1") != []')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2562 call sort(files)->assert_equal(['bar.txt', 'dir', 'foo.txt'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2563 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2564
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2565 func Test_readdirex()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2566 call mkdir('Xexdir', 'R')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2567 call writefile(['foo'], 'Xexdir/foo.txt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2568 call writefile(['barbar'], 'Xexdir/bar.txt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2569 call mkdir('Xexdir/dir')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2570
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2571 " All results
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2572 let files = readdirex('Xexdir')->map({-> v:val.name})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2573 call assert_equal(['bar.txt', 'dir', 'foo.txt'], sort(files))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2574 let sizes = readdirex('Xexdir')->map({-> v:val.size})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2575 call assert_equal([0, 4, 7], sort(sizes))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2576
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2577 " Only results containing "f"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2578 let files = 'Xexdir'->readdirex({ e -> stridx(e.name, 'f') != -1 })
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2579 \ ->map({-> v:val.name})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2580 call assert_equal(['foo.txt'], sort(files))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2581
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2582 " Only .txt files
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2583 let files = readdirex('Xexdir', { e -> e.name =~ '.txt$' })
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2584 \ ->map({-> v:val.name})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2585 call assert_equal(['bar.txt', 'foo.txt'], sort(files))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2586
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2587 " Only .txt files with string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2588 let files = readdirex('Xexdir', 'v:val.name =~ ".txt$"')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2589 \ ->map({-> v:val.name})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2590 call assert_equal(['bar.txt', 'foo.txt'], sort(files))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2591
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2592 " Limit to 1 result.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2593 let l = []
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2594 let files = readdirex('Xexdir', {e -> len(add(l, e.name)) == 2 ? -1 : 1})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2595 \ ->map({-> v:val.name})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2596 call assert_equal(1, len(files))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2597
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2598 " Nested readdirex() must not crash
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2599 let files = readdirex('Xexdir', 'readdirex("Xexdir", "1") != []')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2600 \ ->map({-> v:val.name})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2601 call sort(files)->assert_equal(['bar.txt', 'dir', 'foo.txt'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2602
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2603 " report broken link correctly
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2604 if has("unix")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2605 call writefile([], 'Xexdir/abc.txt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2606 call system("ln -s Xexdir/abc.txt Xexdir/link")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2607 call delete('Xexdir/abc.txt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2608 let files = readdirex('Xexdir', 'readdirex("Xexdir", "1") != []')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2609 \ ->map({-> v:val.name .. '_' .. v:val.type})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2610 call sort(files)->assert_equal(
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2611 \ ['bar.txt_file', 'dir_dir', 'foo.txt_file', 'link_link'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2612 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2613
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2614 call assert_fails('call readdirex("doesnotexist")', 'E484:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2615 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2616
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2617 func Test_readdirex_sort()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2618 CheckUnix
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2619 " Skip tests on Mac OS X and Cygwin (does not allow several files with different casing)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2620 if has("osxdarwin") || has("osx") || has("macunix") || has("win32unix")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2621 throw 'Skipped: Test_readdirex_sort on systems that do not allow this using the default filesystem'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2622 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2623 let _collate = v:collate
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2624 call mkdir('Xsortdir2', 'R')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2625 call writefile(['1'], 'Xsortdir2/README.txt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2626 call writefile(['2'], 'Xsortdir2/Readme.txt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2627 call writefile(['3'], 'Xsortdir2/readme.txt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2628
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2629 " 1) default
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2630 let files = readdirex('Xsortdir2')->map({-> v:val.name})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2631 let default = copy(files)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2632 call assert_equal(['README.txt', 'Readme.txt', 'readme.txt'], files, 'sort using default')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2633
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2634 " 2) no sorting
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2635 let files = readdirex('Xsortdir2', 1, #{sort: 'none'})->map({-> v:val.name})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2636 let unsorted = copy(files)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2637 call assert_equal(['README.txt', 'Readme.txt', 'readme.txt'], sort(files), 'unsorted')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2638 call assert_fails("call readdirex('Xsortdir2', 1, #{slort: 'none'})", 'E857: Dictionary key "sort" required')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2639
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2640 " 3) sort by case (same as default)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2641 let files = readdirex('Xsortdir2', 1, #{sort: 'case'})->map({-> v:val.name})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2642 call assert_equal(default, files, 'sort by case')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2643
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2644 " 4) sort by ignoring case
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2645 let files = readdirex('Xsortdir2', 1, #{sort: 'icase'})->map({-> v:val.name})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2646 call assert_equal(unsorted->sort('i'), files, 'sort by icase')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2647
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2648 " 5) Default Collation
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2649 let collate = v:collate
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2650 lang collate C
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2651 let files = readdirex('Xsortdir2', 1, #{sort: 'collate'})->map({-> v:val.name})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2652 call assert_equal(['README.txt', 'Readme.txt', 'readme.txt'], files, 'sort by C collation')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2653
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2654 " 6) Collation de_DE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2655 " Switch locale, this may not work on the CI system, if the locale isn't
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2656 " available
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2657 try
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2658 lang collate de_DE
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2659 let files = readdirex('Xsortdir2', 1, #{sort: 'collate'})->map({-> v:val.name})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2660 call assert_equal(['readme.txt', 'Readme.txt', 'README.txt'], files, 'sort by de_DE collation')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2661 catch
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2662 throw 'Skipped: de_DE collation is not available'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2663
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2664 finally
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2665 exe 'lang collate' collate
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2666 endtry
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2667 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2668
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2669 func Test_readdir_sort()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2670 " some more cases for testing sorting for readdirex
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2671 let dir = 'Xsortdir3'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2672 call mkdir(dir, 'R')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2673 call writefile(['1'], dir .. '/README.txt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2674 call writefile(['2'], dir .. '/Readm.txt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2675 call writefile(['3'], dir .. '/read.txt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2676 call writefile(['4'], dir .. '/Z.txt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2677 call writefile(['5'], dir .. '/a.txt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2678 call writefile(['6'], dir .. '/b.txt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2679
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2680 " 1) default
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2681 let files = readdir(dir)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2682 let default = copy(files)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2683 call assert_equal(default->sort(), files, 'sort using default')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2684
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2685 " 2) sort by case (same as default)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2686 let files = readdir(dir, '1', #{sort: 'case'})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2687 call assert_equal(default, files, 'sort using default')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2688
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2689 " 3) sort by ignoring case
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2690 let files = readdir(dir, '1', #{sort: 'icase'})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2691 call assert_equal(default->sort('i'), files, 'sort by ignoring case')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2692
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2693 " 4) collation
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2694 let collate = v:collate
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2695 lang collate C
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2696 let files = readdir(dir, 1, #{sort: 'collate'})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2697 call assert_equal(default->sort(), files, 'sort by C collation')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2698 exe "lang collate" collate
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2699
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2700 " 5) Errors
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2701 call assert_fails('call readdir(dir, 1, 1)', 'E1206:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2702 call assert_fails('call readdir(dir, 1, #{sorta: 1})')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2703 call assert_fails('call readdir(dir, 1, test_null_dict())', 'E1297:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2704 call assert_fails('call readdirex(dir, 1, 1)', 'E1206:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2705 call assert_fails('call readdirex(dir, 1, #{sorta: 1})')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2706 call assert_fails('call readdirex(dir, 1, test_null_dict())', 'E1297:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2707
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2708 " 6) ignore other values in dict
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2709 let files = readdir(dir, '1', #{sort: 'c'})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2710 call assert_equal(default, files, 'sort using default2')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2711
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2712 " Cleanup
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2713 exe "lang collate" collate
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2714 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2715
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2716 func Test_delete_rf()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2717 call mkdir('Xrfdir')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2718 call writefile([], 'Xrfdir/foo.txt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2719 call writefile([], 'Xrfdir/bar.txt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2720 call mkdir('Xrfdir/[a-1]') " issue #696
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2721 call writefile([], 'Xrfdir/[a-1]/foo.txt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2722 call writefile([], 'Xrfdir/[a-1]/bar.txt')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2723 call assert_true(filereadable('Xrfdir/foo.txt'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2724 call assert_true('Xrfdir/[a-1]/foo.txt'->filereadable())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2725
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2726 call assert_equal(0, delete('Xrfdir', 'rf'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2727 call assert_false(filereadable('Xrfdir/foo.txt'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2728 call assert_false(filereadable('Xrfdir/[a-1]/foo.txt'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2729
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2730 if has('unix')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2731 call mkdir('Xrfdir/Xdir2', 'p')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2732 silent !chmod 555 Xrfdir
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2733 call assert_equal(-1, delete('Xrfdir/Xdir2', 'rf'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2734 call assert_equal(-1, delete('Xrfdir', 'rf'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2735 silent !chmod 755 Xrfdir
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2736 call assert_equal(0, delete('Xrfdir', 'rf'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2737 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2738 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2739
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2740 func Test_call()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2741 call assert_equal(3, call('len', [123]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2742 call assert_equal(3, 'len'->call([123]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2743 call assert_fails("call call('len', 123)", 'E1211:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2744 call assert_equal(0, call('', []))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2745 call assert_equal(0, call('len', test_null_list()))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2746
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2747 function Mylen() dict
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2748 return len(self.data)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2749 endfunction
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2750 let mydict = {'data': [0, 1, 2, 3], 'len': function("Mylen")}
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2751 eval mydict.len->call([], mydict)->assert_equal(4)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2752 call assert_fails("call call('Mylen', [], 0)", 'E1206:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2753 call assert_fails('call foo', 'E107:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2754
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2755 " These once caused a crash.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2756 call call(test_null_function(), [])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2757 call call(test_null_partial(), [])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2758 call assert_fails('call test_null_function()()', 'E1192:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2759 call assert_fails('call test_null_partial()()', 'E117:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2760
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2761 let lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2762 let Time = 'localtime'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2763 call Time()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2764 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2765 call v9.CheckScriptFailure(lines, 'E1085:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2766 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2767
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2768 func Test_char2nr()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2769 call assert_equal(12354, char2nr('あ', 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2770 call assert_equal(120, 'x'->char2nr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2771 set encoding=latin1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2772 call assert_equal(120, 'x'->char2nr())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2773 set encoding=utf-8
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2774 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2775
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2776 func Test_charclass()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2777 call assert_equal(0, charclass(' '))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2778 call assert_equal(1, charclass('.'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2779 call assert_equal(2, charclass('x'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2780 call assert_equal(3, charclass("\u203c"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2781 " this used to crash vim
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2782 call assert_equal(0, "xxx"[-1]->charclass())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2783 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2784
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2785 func Test_eventhandler()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2786 call assert_equal(0, eventhandler())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2787 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2788
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2789 func Test_bufadd_bufload()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2790 call assert_equal(0, bufexists('someName'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2791 let buf = bufadd('someName')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2792 call assert_notequal(0, buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2793 call assert_equal(1, bufexists('someName'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2794 call assert_equal(0, getbufvar(buf, '&buflisted'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2795 call assert_equal(0, bufloaded(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2796 call bufload(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2797 call assert_equal(1, bufloaded(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2798 call assert_equal([''], getbufline(buf, 1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2799
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2800 let curbuf = bufnr('')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2801 eval ['some', 'text']->writefile('XotherName')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2802 let buf = 'XotherName'->bufadd()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2803 call assert_notequal(0, buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2804 eval 'XotherName'->bufexists()->assert_equal(1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2805 call assert_equal(0, getbufvar(buf, '&buflisted'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2806 call assert_equal(0, bufloaded(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2807 eval buf->bufload()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2808 call assert_equal(1, bufloaded(buf))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2809 call assert_equal(['some', 'text'], getbufline(buf, 1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2810 call assert_equal(curbuf, bufnr(''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2811
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2812 let buf1 = bufadd('')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2813 let buf2 = bufadd('')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2814 call assert_notequal(0, buf1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2815 call assert_notequal(0, buf2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2816 call assert_notequal(buf1, buf2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2817 call assert_equal(1, bufexists(buf1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2818 call assert_equal(1, bufexists(buf2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2819 call assert_equal(0, bufloaded(buf1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2820 exe 'bwipe ' .. buf1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2821 call assert_equal(0, bufexists(buf1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2822 call assert_equal(1, bufexists(buf2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2823 exe 'bwipe ' .. buf2
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2824 call assert_equal(0, bufexists(buf2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2825
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2826 " When 'buftype' is "nofile" then bufload() does not read the file.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2827 " Other values too.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2828 for val in [['nofile', 0],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2829 \ ['nowrite', 1],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2830 \ ['acwrite', 1],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2831 \ ['quickfix', 0],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2832 \ ['help', 1],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2833 \ ['terminal', 0],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2834 \ ['prompt', 0],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2835 \ ['popup', 0],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2836 \ ]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2837 bwipe! XotherName
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2838 let buf = bufadd('XotherName')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2839 call setbufvar(buf, '&bt', val[0])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2840 call bufload(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2841 call assert_equal(val[1] ? ['some', 'text'] : [''], getbufline(buf, 1, '$'), val[0])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2842 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2843
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2844 bwipe someName
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2845 bwipe XotherName
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2846 call assert_equal(0, bufexists('someName'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2847 call delete('XotherName')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2848 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2849
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2850 func Test_state()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2851 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2852
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2853 let getstate = ":echo 'state: ' .. g:state .. '; mode: ' .. g:mode\<CR>"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2854
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2855 let lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2856 call setline(1, ['one', 'two', 'three'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2857 map ;; gg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2858 set complete=.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2859 func RunTimer()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2860 call timer_start(10, {id -> execute('let g:state = state()') .. execute('let g:mode = mode()')})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2861 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2862 au Filetype foobar let g:state = state()|let g:mode = mode()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2863 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2864 call writefile(lines, 'XState')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2865 let buf = RunVimInTerminal('-S XState', #{rows: 6})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2866
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2867 " Using a ":" command Vim is busy, thus "S" is returned
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2868 call term_sendkeys(buf, ":echo 'state: ' .. state() .. '; mode: ' .. mode()\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2869 call WaitForAssert({-> assert_match('state: S; mode: n', term_getline(buf, 6))}, 1000)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2870 call term_sendkeys(buf, ":\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2871
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2872 " Using a timer callback
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2873 call term_sendkeys(buf, ":call RunTimer()\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2874 call TermWait(buf, 25)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2875 call term_sendkeys(buf, getstate)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2876 call WaitForAssert({-> assert_match('state: c; mode: n', term_getline(buf, 6))}, 1000)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2877
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2878 " Halfway a mapping
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2879 call term_sendkeys(buf, ":call RunTimer()\<CR>;")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2880 call TermWait(buf, 25)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2881 call term_sendkeys(buf, ";")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2882 call term_sendkeys(buf, getstate)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2883 call WaitForAssert({-> assert_match('state: mSc; mode: n', term_getline(buf, 6))}, 1000)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2884
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2885 " Insert mode completion (bit slower on Mac)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2886 call term_sendkeys(buf, ":call RunTimer()\<CR>Got\<C-N>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2887 call TermWait(buf, 25)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2888 call term_sendkeys(buf, "\<Esc>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2889 call term_sendkeys(buf, getstate)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2890 call WaitForAssert({-> assert_match('state: aSc; mode: i', term_getline(buf, 6))}, 1000)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2891
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2892 " Autocommand executing
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2893 call term_sendkeys(buf, ":set filetype=foobar\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2894 call TermWait(buf, 25)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2895 call term_sendkeys(buf, getstate)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2896 call WaitForAssert({-> assert_match('state: xS; mode: n', term_getline(buf, 6))}, 1000)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2897
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2898 " Todo: "w" - waiting for ch_evalexpr()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2899
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2900 " messages scrolled
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2901 call term_sendkeys(buf, ":call RunTimer()\<CR>:echo \"one\\ntwo\\nthree\"\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2902 call TermWait(buf, 25)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2903 call term_sendkeys(buf, "\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2904 call term_sendkeys(buf, getstate)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2905 call WaitForAssert({-> assert_match('state: Scs; mode: r', term_getline(buf, 6))}, 1000)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2906
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2907 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2908 call delete('XState')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2909 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2910
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2911 func Test_range()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2912 " destructuring
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2913 let [x, y] = range(2)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2914 call assert_equal([0, 1], [x, y])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2915
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2916 " index
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2917 call assert_equal(4, range(1, 10)[3])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2918
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2919 " add()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2920 call assert_equal([0, 1, 2, 3], add(range(3), 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2921 call assert_equal([0, 1, 2, [0, 1, 2]], add([0, 1, 2], range(3)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2922 call assert_equal([0, 1, 2, [0, 1, 2]], add(range(3), range(3)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2923
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2924 " append()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2925 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2926 call append('.', range(5))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2927 call assert_equal(['', '0', '1', '2', '3', '4'], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2928 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2929
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2930 " appendbufline()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2931 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2932 call appendbufline(bufnr(''), '.', range(5))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2933 call assert_equal(['0', '1', '2', '3', '4', ''], getline(1, '$'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2934 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2935
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2936 " call()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2937 func TwoArgs(a, b)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2938 return [a:a, a:b]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2939 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2940 call assert_equal([0, 1], call('TwoArgs', range(2)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2941
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2942 " col()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2943 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2944 call setline(1, ['foo', 'bar'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2945 call assert_equal(2, col(range(1, 2)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2946 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2947
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2948 " complete()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2949 execute "normal! a\<C-r>=[complete(col('.'), range(10)), ''][1]\<CR>"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2950 " complete_info()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2951 execute "normal! a\<C-r>=[complete(col('.'), range(10)), ''][1]\<CR>\<C-r>=[complete_info(range(5)), ''][1]\<CR>"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2952
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2953 " copy()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2954 call assert_equal([1, 2, 3], copy(range(1, 3)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2955
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2956 " count()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2957 call assert_equal(0, count(range(0), 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2958 call assert_equal(0, count(range(2), 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2959 call assert_equal(1, count(range(5), 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2960
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2961 " cursor()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2962 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2963 call setline(1, ['aaa', 'bbb', 'ccc'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2964 call cursor(range(1, 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2965 call assert_equal([2, 1], [col('.'), line('.')])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2966 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2967
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2968 " deepcopy()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2969 call assert_equal([1, 2, 3], deepcopy(range(1, 3)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2970
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2971 " empty()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2972 call assert_true(empty(range(0)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2973 call assert_false(empty(range(2)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2974
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2975 " execute()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2976 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2977 call setline(1, ['aaa', 'bbb', 'ccc'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2978 call execute(range(3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2979 call assert_equal(2, line('.'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2980 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2981
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2982 " extend()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2983 call assert_equal([1, 2, 3, 4], extend([1], range(2, 4)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2984 call assert_equal([1, 2, 3, 4], extend(range(1, 1), range(2, 4)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2985 call assert_equal([1, 2, 3, 4], extend(range(1, 1), [2, 3, 4]))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2986
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2987 " filter()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2988 call assert_equal([1, 3], filter(range(5), 'v:val % 2'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2989 call assert_equal([1, 5, 7, 11, 13], filter(filter(range(15), 'v:val % 2'), 'v:val % 3'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2990
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2991 " funcref()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2992 call assert_equal([0, 1], funcref('TwoArgs', range(2))())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2993
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2994 " function()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2995 call assert_equal([0, 1], function('TwoArgs', range(2))())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2996
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2997 " garbagecollect()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2998 let thelist = [1, range(2), 3]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
2999 let otherlist = range(3)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3000 call test_garbagecollect_now()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3001
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3002 " get()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3003 call assert_equal(4, get(range(1, 10), 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3004 call assert_equal(-1, get(range(1, 10), 42, -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3005
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3006 " index()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3007 call assert_equal(1, index(range(1, 5), 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3008 call assert_fails("echo index([1, 2], 1, [])", 'E745:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3009
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3010 " insert()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3011 call assert_equal([42, 1, 2, 3, 4, 5], insert(range(1, 5), 42))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3012 call assert_equal([42, 1, 2, 3, 4, 5], insert(range(1, 5), 42, 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3013 call assert_equal([1, 42, 2, 3, 4, 5], insert(range(1, 5), 42, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3014 call assert_equal([1, 2, 3, 4, 42, 5], insert(range(1, 5), 42, 4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3015 call assert_equal([1, 2, 3, 4, 42, 5], insert(range(1, 5), 42, -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3016 call assert_equal([1, 2, 3, 4, 5, 42], insert(range(1, 5), 42, 5))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3017
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3018 " join()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3019 call assert_equal('0 1 2 3 4', join(range(5)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3020
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3021 " json_encode()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3022 call assert_equal('[0,1,2,3]', json_encode(range(4)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3023
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3024 " len()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3025 call assert_equal(0, len(range(0)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3026 call assert_equal(2, len(range(2)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3027 call assert_equal(5, len(range(0, 12, 3)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3028 call assert_equal(4, len(range(3, 0, -1)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3029
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3030 " list2str()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3031 call assert_equal('ABC', list2str(range(65, 67)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3032 call assert_fails('let s = list2str(5)', 'E1211:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3033
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3034 " lock()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3035 let thelist = range(5)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3036 lockvar thelist
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3037
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3038 " map()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3039 call assert_equal([0, 2, 4, 6, 8], map(range(5), 'v:val * 2'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3040 call assert_equal([3, 5, 7, 9, 11], map(map(range(5), 'v:val * 2'), 'v:val + 3'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3041 call assert_equal([2, 6], map(filter(range(5), 'v:val % 2'), 'v:val * 2'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3042 call assert_equal([2, 4, 8], filter(map(range(5), 'v:val * 2'), 'v:val % 3'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3043
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3044 " match()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3045 call assert_equal(3, match(range(5), 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3046
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3047 " matchaddpos()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3048 highlight MyGreenGroup ctermbg=green guibg=green
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3049 call matchaddpos('MyGreenGroup', range(line('.'), line('.')))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3050
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3051 " matchend()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3052 call assert_equal(4, matchend(range(5), '4'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3053 call assert_equal(3, matchend(range(1, 5), '4'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3054 call assert_equal(-1, matchend(range(1, 5), '42'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3055
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3056 " matchstrpos()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3057 call assert_equal(['4', 4, 0, 1], matchstrpos(range(5), '4'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3058 call assert_equal(['4', 3, 0, 1], matchstrpos(range(1, 5), '4'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3059 call assert_equal(['', -1, -1, -1], matchstrpos(range(1, 5), '42'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3060
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3061 " max() reverse()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3062 call assert_equal(0, max(range(0)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3063 call assert_equal(0, max(range(10, 9)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3064 call assert_equal(9, max(range(10)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3065 call assert_equal(18, max(range(0, 20, 3)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3066 call assert_equal(20, max(range(20, 0, -3)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3067 call assert_equal(99999, max(range(100000)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3068 call assert_equal(99999, max(range(99999, 0, -1)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3069 call assert_equal(99999, max(reverse(range(100000))))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3070 call assert_equal(99999, max(reverse(range(99999, 0, -1))))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3071
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3072 " min() reverse()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3073 call assert_equal(0, min(range(0)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3074 call assert_equal(0, min(range(10, 9)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3075 call assert_equal(5, min(range(5, 10)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3076 call assert_equal(5, min(range(5, 10, 3)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3077 call assert_equal(2, min(range(20, 0, -3)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3078 call assert_equal(0, min(range(100000)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3079 call assert_equal(0, min(range(99999, 0, -1)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3080 call assert_equal(0, min(reverse(range(100000))))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3081 call assert_equal(0, min(reverse(range(99999, 0, -1))))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3082
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3083 " remove()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3084 call assert_equal(1, remove(range(1, 10), 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3085 call assert_equal(2, remove(range(1, 10), 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3086 call assert_equal(9, remove(range(1, 10), 8))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3087 call assert_equal(10, remove(range(1, 10), 9))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3088 call assert_equal(10, remove(range(1, 10), -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3089 call assert_equal([3, 4, 5], remove(range(1, 10), 2, 4))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3090
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3091 " repeat()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3092 call assert_equal([0, 1, 2, 0, 1, 2], repeat(range(3), 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3093 call assert_equal([0, 1, 2], repeat(range(3), 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3094 call assert_equal([], repeat(range(3), 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3095 call assert_equal([], repeat(range(5, 4), 2))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3096 call assert_equal([], repeat(range(5, 4), 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3097
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3098 " reverse()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3099 call assert_equal([2, 1, 0], reverse(range(3)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3100 call assert_equal([0, 1, 2, 3], reverse(range(3, 0, -1)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3101 call assert_equal([9, 8, 7, 6, 5, 4, 3, 2, 1, 0], reverse(range(10)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3102 call assert_equal([20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10], reverse(range(10, 20)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3103 call assert_equal([16, 13, 10], reverse(range(10, 18, 3)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3104 call assert_equal([19, 16, 13, 10], reverse(range(10, 19, 3)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3105 call assert_equal([19, 16, 13, 10], reverse(range(10, 20, 3)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3106 call assert_equal([11, 14, 17, 20], reverse(range(20, 10, -3)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3107 call assert_equal([], reverse(range(0)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3108
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3109 " TODO: setpos()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3110 " new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3111 " call setline(1, repeat([''], bufnr('')))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3112 " call setline(bufnr('') + 1, repeat('x', bufnr('') * 2 + 6))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3113 " call setpos('x', range(bufnr(''), bufnr('') + 3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3114 " bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3115
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3116 " setreg()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3117 call setreg('a', range(3))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3118 call assert_equal("0\n1\n2\n", getreg('a'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3119
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3120 " settagstack()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3121 call settagstack(1, #{items : range(4)})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3122
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3123 " sign_define()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3124 call assert_fails("call sign_define(range(5))", "E715:")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3125 call assert_fails("call sign_placelist(range(5))", "E715:")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3126
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3127 " sign_undefine()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3128 call assert_fails("call sign_undefine(range(5))", "E908:")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3129
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3130 " sign_unplacelist()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3131 call assert_fails("call sign_unplacelist(range(5))", "E715:")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3132
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3133 " sort()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3134 call assert_equal([0, 1, 2, 3, 4, 5], sort(range(5, 0, -1)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3135
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3136 " string()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3137 call assert_equal('[0, 1, 2, 3, 4]', string(range(5)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3138
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3139 " taglist() with 'tagfunc'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3140 func TagFunc(pattern, flags, info)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3141 return range(10)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3142 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3143 set tagfunc=TagFunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3144 call assert_fails("call taglist('asdf')", 'E987:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3145 set tagfunc=
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3146
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3147 " term_start()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3148 if has('terminal') && has('termguicolors')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3149 call assert_fails('call term_start(range(3, 4))', 'E474:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3150 let g:terminal_ansi_colors = range(16)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3151 if has('win32')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3152 let cmd = "cmd /c dir"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3153 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3154 let cmd = "ls"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3155 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3156 call assert_fails('call term_start("' .. cmd .. '", #{term_finish: "close"'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3157 \ .. ', ansi_colors: range(16)})', 'E475:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3158 unlet g:terminal_ansi_colors
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3159 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3160
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3161 " type()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3162 call assert_equal(v:t_list, type(range(5)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3163
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3164 " uniq()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3165 call assert_equal([0, 1, 2, 3, 4], uniq(range(5)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3166
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3167 " errors
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3168 call assert_fails('let x=range(2, 8, 0)', 'E726:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3169 call assert_fails('let x=range(3, 1)', 'E727:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3170 call assert_fails('let x=range(1, 3, -2)', 'E727:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3171 call assert_fails('let x=range([])', 'E745:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3172 call assert_fails('let x=range(1, [])', 'E745:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3173 call assert_fails('let x=range(1, 4, [])', 'E745:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3174 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3175
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3176 func Test_garbagecollect_now_fails()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3177 let v:testing = 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3178 call assert_fails('call test_garbagecollect_now()', 'E1142:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3179 let v:testing = 1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3180 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3181
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3182 func Test_echoraw()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3183 CheckScreendump
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3184
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3185 " Normally used for escape codes, but let's test with a CR.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3186 let lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3187 call echoraw("hello\<CR>x")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3188 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3189 call writefile(lines, 'XTest_echoraw')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3190 let buf = RunVimInTerminal('-S XTest_echoraw', {'rows': 5, 'cols': 40})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3191 call VerifyScreenDump(buf, 'Test_functions_echoraw', {})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3192
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3193 " clean up
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3194 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3195 call delete('XTest_echoraw')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3196 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3197
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3198 " Test for echo highlighting
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3199 func Test_echohl()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3200 echohl Search
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3201 echo 'Vim'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3202 call assert_equal('Vim', Screenline(&lines))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3203 " TODO: How to check the highlight group used by echohl?
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3204 " ScreenAttrs() returns all zeros.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3205 echohl None
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3206 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3207
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3208 " Test for the eval() function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3209 func Test_eval()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3210 call assert_fails("call eval('5 a')", 'E488:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3211 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3212
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3213 " Test for the keytrans() function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3214 func Test_keytrans()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3215 call assert_equal('<Space>', keytrans(' '))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3216 call assert_equal('<lt>', keytrans('<'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3217 call assert_equal('<lt>Tab>', keytrans('<Tab>'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3218 call assert_equal('<Tab>', keytrans("\<Tab>"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3219 call assert_equal('<C-V>', keytrans("\<C-V>"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3220 call assert_equal('<BS>', keytrans("\<BS>"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3221 call assert_equal('<Home>', keytrans("\<Home>"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3222 call assert_equal('<C-Home>', keytrans("\<C-Home>"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3223 call assert_equal('<M-Home>', keytrans("\<M-Home>"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3224 call assert_equal('<C-Space>', keytrans("\<C-Space>"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3225 call assert_equal('<M-Space>', keytrans("\<*M-Space>"))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3226 call assert_equal('<M-x>', "\<*M-x>"->keytrans())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3227 call assert_equal('<C-I>', "\<*C-I>"->keytrans())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3228 call assert_equal('<S-3>', "\<*S-3>"->keytrans())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3229 call assert_equal('π', 'π'->keytrans())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3230 call assert_equal('<M-π>', "\<M-π>"->keytrans())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3231 call assert_equal('ě', 'ě'->keytrans())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3232 call assert_equal('<M-ě>', "\<M-ě>"->keytrans())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3233 call assert_equal('', ''->keytrans())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3234 call assert_equal('', test_null_string()->keytrans())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3235 call assert_fails('call keytrans(1)', 'E1174:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3236 call assert_fails('call keytrans()', 'E119:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3237 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3238
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3239 " Test for the nr2char() function
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3240 func Test_nr2char()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3241 set encoding=latin1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3242 call assert_equal('@', nr2char(64))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3243 set encoding=utf8
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3244 call assert_equal('a', nr2char(97, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3245 call assert_equal('a', nr2char(97, 0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3246
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3247 call assert_equal("\x80\xfc\b" .. nr2char(0x100000), eval('"\<M-' .. nr2char(0x100000) .. '>"'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3248 call assert_equal("\x80\xfc\b" .. nr2char(0x40000000), eval('"\<M-' .. nr2char(0x40000000) .. '>"'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3249 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3250
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3251 " Test for screenattr(), screenchar() and screenchars() functions
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3252 func Test_screen_functions()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3253 call assert_equal(-1, screenattr(-1, -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3254 call assert_equal(-1, screenchar(-1, -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3255 call assert_equal([], screenchars(-1, -1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3256
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3257 " Run this in a separate Vim instance to avoid messing up.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3258 let after =<< trim [CODE]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3259 scriptencoding utf-8
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3260 call setline(1, '口')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3261 redraw
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3262 call assert_equal(0, screenattr(1, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3263 call assert_equal(char2nr('口'), screenchar(1, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3264 call assert_equal([char2nr('口')], screenchars(1, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3265 call assert_equal('口', screenstring(1, 1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3266 call writefile(v:errors, 'Xresult')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3267 qall!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3268 [CODE]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3269
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3270 let encodings = ['utf-8', 'cp932', 'cp936', 'cp949', 'cp950']
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3271 if !has('win32')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3272 let encodings += ['euc-jp']
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3273 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3274 for enc in encodings
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3275 let msg = 'enc=' .. enc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3276 if RunVim([], after, $'--clean --cmd "set encoding={enc}"')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3277 call assert_equal([], readfile('Xresult'), msg)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3278 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3279 call delete('Xresult')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3280 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3281 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3282
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3283 " Test for getcurpos() and setpos()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3284 func Test_getcurpos_setpos()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3285 new
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3286 call setline(1, ['012345678', '012345678'])
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3287 normal gg6l
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3288 let sp = getcurpos()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3289 normal 0
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3290 call setpos('.', sp)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3291 normal jyl
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3292 call assert_equal('6', @")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3293 call assert_equal(-1, setpos('.', test_null_list()))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3294 call assert_equal(-1, setpos('.', {}))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3295
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3296 let winid = win_getid()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3297 normal G$
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3298 let pos = getcurpos()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3299 wincmd w
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3300 call assert_equal(pos, getcurpos(winid))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3301
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3302 wincmd w
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3303 close!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3304
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3305 call assert_equal(getcurpos(), getcurpos(0))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3306 call assert_equal([0, 0, 0, 0, 0], getcurpos(-1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3307 call assert_equal([0, 0, 0, 0, 0], getcurpos(1999))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3308 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3309
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3310 func Test_getmousepos()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3311 enew!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3312 call setline(1, "\t\t\t1234")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3313 call test_setmouse(1, 1)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3314 call assert_equal(#{
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3315 \ screenrow: 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3316 \ screencol: 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3317 \ winid: win_getid(),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3318 \ winrow: 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3319 \ wincol: 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3320 \ line: 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3321 \ column: 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3322 \ }, getmousepos())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3323 call test_setmouse(1, 25)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3324 call assert_equal(#{
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3325 \ screenrow: 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3326 \ screencol: 25,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3327 \ winid: win_getid(),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3328 \ winrow: 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3329 \ wincol: 25,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3330 \ line: 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3331 \ column: 4,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3332 \ }, getmousepos())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3333 call test_setmouse(1, 50)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3334 call assert_equal(#{
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3335 \ screenrow: 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3336 \ screencol: 50,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3337 \ winid: win_getid(),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3338 \ winrow: 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3339 \ wincol: 50,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3340 \ line: 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3341 \ column: 8,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3342 \ }, getmousepos())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3343
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3344 " If the mouse is positioned past the last buffer line, "line" and "column"
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3345 " should act like it's positioned on the last buffer line.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3346 call test_setmouse(2, 25)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3347 call assert_equal(#{
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3348 \ screenrow: 2,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3349 \ screencol: 25,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3350 \ winid: win_getid(),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3351 \ winrow: 2,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3352 \ wincol: 25,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3353 \ line: 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3354 \ column: 4,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3355 \ }, getmousepos())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3356 call test_setmouse(2, 50)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3357 call assert_equal(#{
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3358 \ screenrow: 2,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3359 \ screencol: 50,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3360 \ winid: win_getid(),
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3361 \ winrow: 2,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3362 \ wincol: 50,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3363 \ line: 1,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3364 \ column: 8,
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3365 \ }, getmousepos())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3366 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3367 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3368
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3369 func Test_getmouseshape()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3370 CheckFeature mouseshape
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3371
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3372 call assert_equal('arrow', getmouseshape())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3373 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3374
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3375 " Test for glob()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3376 func Test_glob()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3377 call assert_equal('', glob(test_null_string()))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3378 call assert_equal('', globpath(test_null_string(), test_null_string()))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3379 call assert_fails("let x = globpath(&rtp, 'syntax/c.vim', [])", 'E745:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3380
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3381 call writefile([], 'Xglob1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3382 call writefile([], 'XGLOB2')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3383 set wildignorecase
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3384 " Sort output of glob() otherwise we end up with different
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3385 " ordering depending on whether file system is case-sensitive.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3386 call assert_equal(['XGLOB2', 'Xglob1'], sort(glob('Xglob[12]', 0, 1)))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3387 " wildignorecase shall be applied even when the pattern contains no wildcards.
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3388 call assert_equal('XGLOB2', glob('xglob2'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3389 set wildignorecase&
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3390
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3391 call delete('Xglob1')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3392 call delete('XGLOB2')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3393
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3394 call assert_fails("call glob('*', 0, {})", 'E728:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3395 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3396
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3397 " Test for browse()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3398 func Test_browse()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3399 CheckFeature browse
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3400 call assert_fails('call browse([], "open", "x", "a.c")', 'E745:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3401 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3402
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3403 " Test for browsedir()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3404 func Test_browsedir()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3405 CheckFeature browse
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3406 call assert_fails('call browsedir("open", [])', 'E730:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3407 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3408
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3409 func HasDefault(msg = 'msg')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3410 return a:msg
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3411 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3412
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3413 func Test_default_arg_value()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3414 call assert_equal('msg', HasDefault())
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3415 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3416
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3417 " Test for gettext()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3418 func Test_gettext()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3419 call assert_fails('call gettext(1)', 'E1174:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3420 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3421
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3422 func Test_builtin_check()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3423 call assert_fails('let g:["trim"] = {x -> " " .. x}', 'E704:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3424 call assert_fails('let g:.trim = {x -> " " .. x}', 'E704:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3425 call assert_fails('let l:["trim"] = {x -> " " .. x}', 'E704:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3426 call assert_fails('let l:.trim = {x -> " " .. x}', 'E704:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3427 let lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3428 vim9script
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3429 var trim = (x) => " " .. x
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3430 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3431 call v9.CheckScriptFailure(lines, 'E704:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3432
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3433 call assert_fails('call extend(g:, #{foo: { -> "foo" }})', 'E704:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3434 let g:bar = 123
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3435 call extend(g:, #{bar: { -> "foo" }}, "keep")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3436 call assert_fails('call extend(g:, #{bar: { -> "foo" }}, "force")', 'E704:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3437 unlet g:bar
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3438
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3439 call assert_fails('call extend(l:, #{foo: { -> "foo" }})', 'E704:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3440 let bar = 123
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3441 call extend(l:, #{bar: { -> "foo" }}, "keep")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3442 call assert_fails('call extend(l:, #{bar: { -> "foo" }}, "force")', 'E704:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3443 unlet bar
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3444
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3445 call assert_fails('call extend(g:, #{foo: function("extend")})', 'E704:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3446 let g:bar = 123
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3447 call extend(g:, #{bar: function("extend")}, "keep")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3448 call assert_fails('call extend(g:, #{bar: function("extend")}, "force")', 'E704:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3449 unlet g:bar
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3450
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3451 call assert_fails('call extend(l:, #{foo: function("extend")})', 'E704:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3452 let bar = 123
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3453 call extend(l:, #{bar: function("extend")}, "keep")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3454 call assert_fails('call extend(l:, #{bar: function("extend")}, "force")', 'E704:')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3455 unlet bar
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3456 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3457
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3458 func Test_funcref_to_string()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3459 let Fn = funcref('g:Test_funcref_to_string')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3460 call assert_equal("function('g:Test_funcref_to_string')", string(Fn))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3461 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3462
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3463 " Test for isabsolutepath()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3464 func Test_isabsolutepath()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3465 call assert_false(isabsolutepath(''))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3466 call assert_false(isabsolutepath('.'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3467 call assert_false(isabsolutepath('../Foo'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3468 call assert_false(isabsolutepath('Foo/'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3469 if has('win32')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3470 call assert_true(isabsolutepath('A:\'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3471 call assert_true(isabsolutepath('A:\Foo'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3472 call assert_true(isabsolutepath('A:/Foo'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3473 call assert_false(isabsolutepath('A:Foo'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3474 call assert_false(isabsolutepath('\Windows'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3475 call assert_true(isabsolutepath('\\Server2\Share\Test\Foo.txt'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3476 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3477 call assert_true(isabsolutepath('/'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3478 call assert_true(isabsolutepath('/usr/share/'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3479 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3480 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3481
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3482 " Test for exepath()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3483 func Test_exepath()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3484 if has('win32')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3485 call assert_notequal(exepath('cmd'), '')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3486
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3487 let oldNoDefaultCurrentDirectoryInExePath = $NoDefaultCurrentDirectoryInExePath
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3488 call writefile(['@echo off', 'echo Evil'], 'vim-test-evil.bat')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3489 let $NoDefaultCurrentDirectoryInExePath = ''
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3490 call assert_notequal(exepath("vim-test-evil.bat"), '')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3491 let $NoDefaultCurrentDirectoryInExePath = '1'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3492 call assert_equal(exepath("vim-test-evil.bat"), '')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3493 let $NoDefaultCurrentDirectoryInExePath = oldNoDefaultCurrentDirectoryInExePath
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3494 call delete('vim-test-evil.bat')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3495 else
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3496 call assert_notequal(exepath('sh'), '')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3497 endif
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3498 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3499
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3500 " Test for virtcol()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3501 func Test_virtcol()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3502 enew!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3503 call setline(1, "the\tquick\tbrown\tfox")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3504 norm! 4|
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3505 call assert_equal(8, virtcol('.'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3506 call assert_equal(8, virtcol('.', v:false))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3507 call assert_equal([4, 8], virtcol('.', v:true))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3508 bwipe!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3509 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3510
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3511 func Test_delfunc_while_listing()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3512 CheckRunVimInTerminal
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3513
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3514 let lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3515 set nocompatible
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3516 for i in range(1, 999)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3517 exe 'func ' .. 'MyFunc' .. i .. '()'
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3518 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3519 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3520 au CmdlineLeave : call timer_start(0, {-> execute('delfunc MyFunc622')})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3521 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3522 call writefile(lines, 'Xfunctionclear', 'D')
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3523 let buf = RunVimInTerminal('-S Xfunctionclear', {'rows': 12})
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3524
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3525 " This was using freed memory. The height of the terminal must be so that
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3526 " the next function to be listed with "j" is the one that is deleted in the
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3527 " timer callback, tricky!
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3528 call term_sendkeys(buf, ":func /MyFunc\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3529 call TermWait(buf, 50)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3530 call term_sendkeys(buf, "j")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3531 call TermWait(buf, 50)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3532 call term_sendkeys(buf, "\<CR>")
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3533
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3534 call StopVimInTerminal(buf)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3535 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3536
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3537 " Test for the reverse() function with a string
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3538 func Test_string_reverse()
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3539 let lines =<< trim END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3540 call assert_equal('', reverse(test_null_string()))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3541 for [s1, s2] in [['', ''], ['a', 'a'], ['ab', 'ba'], ['abc', 'cba'],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3542 \ ['abcd', 'dcba'], ['«-«-»-»', '»-»-«-«'],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3543 \ ['🇦', '🇦'], ['🇦🇧', '🇧🇦'], ['🇦🇧🇨', '🇨🇧🇦'],
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3544 \ ['🇦«🇧-🇨»🇩', '🇩»🇨-🇧«🇦']]
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3545 call assert_equal(s2, reverse(s1))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3546 endfor
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3547 END
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3548 call v9.CheckLegacyAndVim9Success(lines)
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3549
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3550 " test in latin1 encoding
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3551 let save_enc = &encoding
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3552 set encoding=latin1
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3553 call assert_equal('dcba', reverse('abcd'))
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3554 let &encoding = save_enc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3555 endfunc
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3556
448aef880252 normalize line endings
Christian Brabandt <cb@256bit.org>
parents: 32595
diff changeset
3557 " vim: shiftwidth=2 sts=2 expandtab