1" Tests for various functions.
2
3func Test_empty()
4  call assert_equal(1, empty(''))
5  call assert_equal(0, empty('a'))
6
7  call assert_equal(1, empty(0))
8  call assert_equal(1, empty(-0))
9  call assert_equal(0, empty(1))
10  call assert_equal(0, empty(-1))
11
12  call assert_equal(1, empty(0.0))
13  call assert_equal(1, empty(-0.0))
14  call assert_equal(0, empty(1.0))
15  call assert_equal(0, empty(-1.0))
16  call assert_equal(0, empty(1.0/0.0))
17  call assert_equal(0, empty(0.0/0.0))
18
19  call assert_equal(1, empty([]))
20  call assert_equal(0, empty(['a']))
21
22  call assert_equal(1, empty({}))
23  call assert_equal(0, empty({'a':1}))
24
25  call assert_equal(1, empty(v:null))
26  call assert_equal(1, empty(v:none))
27  call assert_equal(1, empty(v:false))
28  call assert_equal(0, empty(v:true))
29
30  call assert_equal(0, empty(function('Test_empty')))
31endfunc
32
33func Test_len()
34  call assert_equal(1, len(0))
35  call assert_equal(2, len(12))
36
37  call assert_equal(0, len(''))
38  call assert_equal(2, len('ab'))
39
40  call assert_equal(0, len([]))
41  call assert_equal(2, len([2, 1]))
42
43  call assert_equal(0, len({}))
44  call assert_equal(2, len({'a': 1, 'b': 2}))
45
46  call assert_fails('call len(v:none)', 'E701:')
47  call assert_fails('call len({-> 0})', 'E701:')
48endfunc
49
50func Test_max()
51  call assert_equal(0, max([]))
52  call assert_equal(2, max([2]))
53  call assert_equal(2, max([1, 2]))
54  call assert_equal(2, max([1, 2, v:null]))
55
56  call assert_equal(0, max({}))
57  call assert_equal(2, max({'a':1, 'b':2}))
58
59  call assert_fails('call max(1)', 'E712:')
60  call assert_fails('call max(v:none)', 'E712:')
61endfunc
62
63func Test_min()
64  call assert_equal(0, min([]))
65  call assert_equal(2, min([2]))
66  call assert_equal(1, min([1, 2]))
67  call assert_equal(0, min([1, 2, v:null]))
68
69  call assert_equal(0, min({}))
70  call assert_equal(1, min({'a':1, 'b':2}))
71
72  call assert_fails('call min(1)', 'E712:')
73  call assert_fails('call min(v:none)', 'E712:')
74endfunc
75
76func Test_str2nr()
77  call assert_equal(0, str2nr(''))
78  call assert_equal(1, str2nr('1'))
79  call assert_equal(1, str2nr(' 1 '))
80
81  call assert_equal(1, str2nr('+1'))
82  call assert_equal(1, str2nr('+ 1'))
83  call assert_equal(1, str2nr(' + 1 '))
84
85  call assert_equal(-1, str2nr('-1'))
86  call assert_equal(-1, str2nr('- 1'))
87  call assert_equal(-1, str2nr(' - 1 '))
88
89  call assert_equal(123456789, str2nr('123456789'))
90  call assert_equal(-123456789, str2nr('-123456789'))
91
92  call assert_equal(5, str2nr('101', 2))
93  call assert_equal(5, str2nr('0b101', 2))
94  call assert_equal(5, str2nr('0B101', 2))
95  call assert_equal(-5, str2nr('-101', 2))
96  call assert_equal(-5, str2nr('-0b101', 2))
97  call assert_equal(-5, str2nr('-0B101', 2))
98
99  call assert_equal(65, str2nr('101', 8))
100  call assert_equal(65, str2nr('0101', 8))
101  call assert_equal(-65, str2nr('-101', 8))
102  call assert_equal(-65, str2nr('-0101', 8))
103
104  call assert_equal(11259375, str2nr('abcdef', 16))
105  call assert_equal(11259375, str2nr('ABCDEF', 16))
106  call assert_equal(-11259375, str2nr('-ABCDEF', 16))
107  call assert_equal(11259375, str2nr('0xabcdef', 16))
108  call assert_equal(11259375, str2nr('0Xabcdef', 16))
109  call assert_equal(11259375, str2nr('0XABCDEF', 16))
110  call assert_equal(-11259375, str2nr('-0xABCDEF', 16))
111
112  call assert_equal(0, str2nr('0x10'))
113  call assert_equal(0, str2nr('0b10'))
114  call assert_equal(1, str2nr('12', 2))
115  call assert_equal(1, str2nr('18', 8))
116  call assert_equal(1, str2nr('1g', 16))
117
118  call assert_equal(0, str2nr(v:null))
119  call assert_equal(0, str2nr(v:none))
120
121  call assert_fails('call str2nr([])', 'E730:')
122  call assert_fails('call str2nr({->2})', 'E729:')
123  call assert_fails('call str2nr(1.2)', 'E806:')
124  call assert_fails('call str2nr(10, [])', 'E474:')
125endfunc
126
127func Test_strftime()
128  if !exists('*strftime')
129    return
130  endif
131  " Format of strftime() depends on system. We assume
132  " that basic formats tested here are available and
133  " identical on all systems which support strftime().
134  "
135  " The 2nd parameter of strftime() is a local time, so the output day
136  " of strftime() can be 17 or 18, depending on timezone.
137  call assert_match('^2017-01-1[78]$', strftime('%Y-%m-%d', 1484695512))
138  "
139  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\)$', strftime('%Y-%m-%d %H:%M:%S'))
140
141  call assert_fails('call strftime([])', 'E730:')
142  call assert_fails('call strftime("%Y", [])', 'E745:')
143endfunc
144
145func Test_simplify()
146  call assert_equal('',            simplify(''))
147  call assert_equal('/',           simplify('/'))
148  call assert_equal('/',           simplify('/.'))
149  call assert_equal('/',           simplify('/..'))
150  call assert_equal('/...',        simplify('/...'))
151  call assert_equal('./dir/file',  simplify('./dir/file'))
152  call assert_equal('./dir/file',  simplify('.///dir//file'))
153  call assert_equal('./dir/file',  simplify('./dir/./file'))
154  call assert_equal('./file',      simplify('./dir/../file'))
155  call assert_equal('../dir/file', simplify('dir/../../dir/file'))
156  call assert_equal('./file',      simplify('dir/.././file'))
157
158  call assert_fails('call simplify({->0})', 'E729:')
159  call assert_fails('call simplify([])', 'E730:')
160  call assert_fails('call simplify({})', 'E731:')
161  call assert_fails('call simplify(1.2)', 'E806:')
162endfunc
163
164func Test_tolower()
165  call assert_equal("", tolower(""))
166
167  " Test with all printable ASCII characters.
168  call assert_equal(' !"#$%&''()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz[\]^_`abcdefghijklmnopqrstuvwxyz{|}~',
169          \ tolower(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'))
170
171  if !has('multi_byte')
172    return
173  endif
174
175  " Test with a few uppercase diacritics.
176  call assert_equal("aàáâãäåāăąǎǟǡả", tolower("AÀÁÂÃÄÅĀĂĄǍǞǠẢ"))
177  call assert_equal("bḃḇ", tolower("BḂḆ"))
178  call assert_equal("cçćĉċč", tolower("CÇĆĈĊČ"))
179  call assert_equal("dďđḋḏḑ", tolower("DĎĐḊḎḐ"))
180  call assert_equal("eèéêëēĕėęěẻẽ", tolower("EÈÉÊËĒĔĖĘĚẺẼ"))
181  call assert_equal("fḟ ", tolower("FḞ "))
182  call assert_equal("gĝğġģǥǧǵḡ", tolower("GĜĞĠĢǤǦǴḠ"))
183  call assert_equal("hĥħḣḧḩ", tolower("HĤĦḢḦḨ"))
184  call assert_equal("iìíîïĩīĭįiǐỉ", tolower("IÌÍÎÏĨĪĬĮİǏỈ"))
185  call assert_equal("jĵ", tolower("JĴ"))
186  call assert_equal("kķǩḱḵ", tolower("KĶǨḰḴ"))
187  call assert_equal("lĺļľŀłḻ", tolower("LĹĻĽĿŁḺ"))
188  call assert_equal("mḿṁ", tolower("MḾṀ"))
189  call assert_equal("nñńņňṅṉ", tolower("NÑŃŅŇṄṈ"))
190  call assert_equal("oòóôõöøōŏőơǒǫǭỏ", tolower("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ"))
191  call assert_equal("pṕṗ", tolower("PṔṖ"))
192  call assert_equal("q", tolower("Q"))
193  call assert_equal("rŕŗřṙṟ", tolower("RŔŖŘṘṞ"))
194  call assert_equal("sśŝşšṡ", tolower("SŚŜŞŠṠ"))
195  call assert_equal("tţťŧṫṯ", tolower("TŢŤŦṪṮ"))
196  call assert_equal("uùúûüũūŭůűųưǔủ", tolower("UÙÚÛÜŨŪŬŮŰŲƯǓỦ"))
197  call assert_equal("vṽ", tolower("VṼ"))
198  call assert_equal("wŵẁẃẅẇ", tolower("WŴẀẂẄẆ"))
199  call assert_equal("xẋẍ", tolower("XẊẌ"))
200  call assert_equal("yýŷÿẏỳỷỹ", tolower("YÝŶŸẎỲỶỸ"))
201  call assert_equal("zźżžƶẑẕ", tolower("ZŹŻŽƵẐẔ"))
202
203  " Test with a few lowercase diacritics, which should remain unchanged.
204  call assert_equal("aàáâãäåāăąǎǟǡả", tolower("aàáâãäåāăąǎǟǡả"))
205  call assert_equal("bḃḇ", tolower("bḃḇ"))
206  call assert_equal("cçćĉċč", tolower("cçćĉċč"))
207  call assert_equal("dďđḋḏḑ", tolower("dďđḋḏḑ"))
208  call assert_equal("eèéêëēĕėęěẻẽ", tolower("eèéêëēĕėęěẻẽ"))
209  call assert_equal("fḟ", tolower("fḟ"))
210  call assert_equal("gĝğġģǥǧǵḡ", tolower("gĝğġģǥǧǵḡ"))
211  call assert_equal("hĥħḣḧḩẖ", tolower("hĥħḣḧḩẖ"))
212  call assert_equal("iìíîïĩīĭįǐỉ", tolower("iìíîïĩīĭįǐỉ"))
213  call assert_equal("jĵǰ", tolower("jĵǰ"))
214  call assert_equal("kķǩḱḵ", tolower("kķǩḱḵ"))
215  call assert_equal("lĺļľŀłḻ", tolower("lĺļľŀłḻ"))
216  call assert_equal("mḿṁ ", tolower("mḿṁ "))
217  call assert_equal("nñńņňʼnṅṉ", tolower("nñńņňʼnṅṉ"))
218  call assert_equal("oòóôõöøōŏőơǒǫǭỏ", tolower("oòóôõöøōŏőơǒǫǭỏ"))
219  call assert_equal("pṕṗ", tolower("pṕṗ"))
220  call assert_equal("q", tolower("q"))
221  call assert_equal("rŕŗřṙṟ", tolower("rŕŗřṙṟ"))
222  call assert_equal("sśŝşšṡ", tolower("sśŝşšṡ"))
223  call assert_equal("tţťŧṫṯẗ", tolower("tţťŧṫṯẗ"))
224  call assert_equal("uùúûüũūŭůűųưǔủ", tolower("uùúûüũūŭůűųưǔủ"))
225  call assert_equal("vṽ", tolower("vṽ"))
226  call assert_equal("wŵẁẃẅẇẘ", tolower("wŵẁẃẅẇẘ"))
227  call assert_equal("ẋẍ", tolower("ẋẍ"))
228  call assert_equal("yýÿŷẏẙỳỷỹ", tolower("yýÿŷẏẙỳỷỹ"))
229  call assert_equal("zźżžƶẑẕ", tolower("zźżžƶẑẕ"))
230
231  " According to https://twitter.com/jifa/status/625776454479970304
232  " Ⱥ (U+023A) and Ⱦ (U+023E) are the *only* code points to increase
233  " in length (2 to 3 bytes) when lowercased. So let's test them.
234  call assert_equal("ⱥ ⱦ", tolower("Ⱥ Ⱦ"))
235endfunc
236
237func Test_toupper()
238  call assert_equal("", toupper(""))
239
240  " Test with all printable ASCII characters.
241  call assert_equal(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ{|}~',
242          \ toupper(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'))
243
244  if !has('multi_byte')
245    return
246  endif
247
248  " Test with a few lowercase diacritics.
249  call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", toupper("aàáâãäåāăąǎǟǡả"))
250  call assert_equal("BḂḆ", toupper("bḃḇ"))
251  call assert_equal("CÇĆĈĊČ", toupper("cçćĉċč"))
252  call assert_equal("DĎĐḊḎḐ", toupper("dďđḋḏḑ"))
253  call assert_equal("EÈÉÊËĒĔĖĘĚẺẼ", toupper("eèéêëēĕėęěẻẽ"))
254  call assert_equal("FḞ", toupper("fḟ"))
255  call assert_equal("GĜĞĠĢǤǦǴḠ", toupper("gĝğġģǥǧǵḡ"))
256  call assert_equal("HĤĦḢḦḨẖ", toupper("hĥħḣḧḩẖ"))
257  call assert_equal("IÌÍÎÏĨĪĬĮǏỈ", toupper("iìíîïĩīĭįǐỉ"))
258  call assert_equal("JĴǰ", toupper("jĵǰ"))
259  call assert_equal("KĶǨḰḴ", toupper("kķǩḱḵ"))
260  call assert_equal("LĹĻĽĿŁḺ", toupper("lĺļľŀłḻ"))
261  call assert_equal("MḾṀ ", toupper("mḿṁ "))
262  call assert_equal("NÑŃŅŇʼnṄṈ", toupper("nñńņňʼnṅṉ"))
263  call assert_equal("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ", toupper("oòóôõöøōŏőơǒǫǭỏ"))
264  call assert_equal("PṔṖ", toupper("pṕṗ"))
265  call assert_equal("Q", toupper("q"))
266  call assert_equal("RŔŖŘṘṞ", toupper("rŕŗřṙṟ"))
267  call assert_equal("SŚŜŞŠṠ", toupper("sśŝşšṡ"))
268  call assert_equal("TŢŤŦṪṮẗ", toupper("tţťŧṫṯẗ"))
269  call assert_equal("UÙÚÛÜŨŪŬŮŰŲƯǓỦ", toupper("uùúûüũūŭůűųưǔủ"))
270  call assert_equal("VṼ", toupper("vṽ"))
271  call assert_equal("WŴẀẂẄẆẘ", toupper("wŵẁẃẅẇẘ"))
272  call assert_equal("ẊẌ", toupper("ẋẍ"))
273  call assert_equal("YÝŸŶẎẙỲỶỸ", toupper("yýÿŷẏẙỳỷỹ"))
274  call assert_equal("ZŹŻŽƵẐẔ", toupper("zźżžƶẑẕ"))
275
276  " Test that uppercase diacritics, which should remain unchanged.
277  call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", toupper("AÀÁÂÃÄÅĀĂĄǍǞǠẢ"))
278  call assert_equal("BḂḆ", toupper("BḂḆ"))
279  call assert_equal("CÇĆĈĊČ", toupper("CÇĆĈĊČ"))
280  call assert_equal("DĎĐḊḎḐ", toupper("DĎĐḊḎḐ"))
281  call assert_equal("EÈÉÊËĒĔĖĘĚẺẼ", toupper("EÈÉÊËĒĔĖĘĚẺẼ"))
282  call assert_equal("FḞ ", toupper("FḞ "))
283  call assert_equal("GĜĞĠĢǤǦǴḠ", toupper("GĜĞĠĢǤǦǴḠ"))
284  call assert_equal("HĤĦḢḦḨ", toupper("HĤĦḢḦḨ"))
285  call assert_equal("IÌÍÎÏĨĪĬĮİǏỈ", toupper("IÌÍÎÏĨĪĬĮİǏỈ"))
286  call assert_equal("JĴ", toupper("JĴ"))
287  call assert_equal("KĶǨḰḴ", toupper("KĶǨḰḴ"))
288  call assert_equal("LĹĻĽĿŁḺ", toupper("LĹĻĽĿŁḺ"))
289  call assert_equal("MḾṀ", toupper("MḾṀ"))
290  call assert_equal("NÑŃŅŇṄṈ", toupper("NÑŃŅŇṄṈ"))
291  call assert_equal("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ", toupper("OÒÓÔÕÖØŌŎŐƠǑǪǬỎ"))
292  call assert_equal("PṔṖ", toupper("PṔṖ"))
293  call assert_equal("Q", toupper("Q"))
294  call assert_equal("RŔŖŘṘṞ", toupper("RŔŖŘṘṞ"))
295  call assert_equal("SŚŜŞŠṠ", toupper("SŚŜŞŠṠ"))
296  call assert_equal("TŢŤŦṪṮ", toupper("TŢŤŦṪṮ"))
297  call assert_equal("UÙÚÛÜŨŪŬŮŰŲƯǓỦ", toupper("UÙÚÛÜŨŪŬŮŰŲƯǓỦ"))
298  call assert_equal("VṼ", toupper("VṼ"))
299  call assert_equal("WŴẀẂẄẆ", toupper("WŴẀẂẄẆ"))
300  call assert_equal("XẊẌ", toupper("XẊẌ"))
301  call assert_equal("YÝŶŸẎỲỶỸ", toupper("YÝŶŸẎỲỶỸ"))
302  call assert_equal("ZŹŻŽƵẐẔ", toupper("ZŹŻŽƵẐẔ"))
303
304  call assert_equal("Ⱥ Ⱦ", toupper("ⱥ ⱦ"))
305endfunc
306
307" Tests for the mode() function
308let current_modes = ''
309func! Save_mode()
310  let g:current_modes = mode(0) . '-' . mode(1)
311  return ''
312endfunc
313
314func! Test_mode()
315  new
316  call append(0, ["Blue Ball Black", "Brown Band Bowl", ""])
317
318  inoremap <F2> <C-R>=Save_mode()<CR>
319
320  normal! 3G
321  exe "normal i\<F2>\<Esc>"
322  call assert_equal('i-i', g:current_modes)
323  " i_CTRL-P: Multiple matches
324  exe "normal i\<C-G>uBa\<C-P>\<F2>\<Esc>u"
325  call assert_equal('i-ic', g:current_modes)
326  " i_CTRL-P: Single match
327  exe "normal iBro\<C-P>\<F2>\<Esc>u"
328  call assert_equal('i-ic', g:current_modes)
329  " i_CTRL-X
330  exe "normal iBa\<C-X>\<F2>\<Esc>u"
331  call assert_equal('i-ix', g:current_modes)
332  " i_CTRL-X CTRL-P: Multiple matches
333  exe "normal iBa\<C-X>\<C-P>\<F2>\<Esc>u"
334  call assert_equal('i-ic', g:current_modes)
335  " i_CTRL-X CTRL-P: Single match
336  exe "normal iBro\<C-X>\<C-P>\<F2>\<Esc>u"
337  call assert_equal('i-ic', g:current_modes)
338  " i_CTRL-X CTRL-P + CTRL-P: Single match
339  exe "normal iBro\<C-X>\<C-P>\<C-P>\<F2>\<Esc>u"
340  call assert_equal('i-ic', g:current_modes)
341  " i_CTRL-X CTRL-L: Multiple matches
342  exe "normal i\<C-X>\<C-L>\<F2>\<Esc>u"
343  call assert_equal('i-ic', g:current_modes)
344  " i_CTRL-X CTRL-L: Single match
345  exe "normal iBlu\<C-X>\<C-L>\<F2>\<Esc>u"
346  call assert_equal('i-ic', g:current_modes)
347  " i_CTRL-P: No match
348  exe "normal iCom\<C-P>\<F2>\<Esc>u"
349  call assert_equal('i-ic', g:current_modes)
350  " i_CTRL-X CTRL-P: No match
351  exe "normal iCom\<C-X>\<C-P>\<F2>\<Esc>u"
352  call assert_equal('i-ic', g:current_modes)
353  " i_CTRL-X CTRL-L: No match
354  exe "normal iabc\<C-X>\<C-L>\<F2>\<Esc>u"
355  call assert_equal('i-ic', g:current_modes)
356
357  " R_CTRL-P: Multiple matches
358  exe "normal RBa\<C-P>\<F2>\<Esc>u"
359  call assert_equal('R-Rc', g:current_modes)
360  " R_CTRL-P: Single match
361  exe "normal RBro\<C-P>\<F2>\<Esc>u"
362  call assert_equal('R-Rc', g:current_modes)
363  " R_CTRL-X
364  exe "normal RBa\<C-X>\<F2>\<Esc>u"
365  call assert_equal('R-Rx', g:current_modes)
366  " R_CTRL-X CTRL-P: Multiple matches
367  exe "normal RBa\<C-X>\<C-P>\<F2>\<Esc>u"
368  call assert_equal('R-Rc', g:current_modes)
369  " R_CTRL-X CTRL-P: Single match
370  exe "normal RBro\<C-X>\<C-P>\<F2>\<Esc>u"
371  call assert_equal('R-Rc', g:current_modes)
372  " R_CTRL-X CTRL-P + CTRL-P: Single match
373  exe "normal RBro\<C-X>\<C-P>\<C-P>\<F2>\<Esc>u"
374  call assert_equal('R-Rc', g:current_modes)
375  " R_CTRL-X CTRL-L: Multiple matches
376  exe "normal R\<C-X>\<C-L>\<F2>\<Esc>u"
377  call assert_equal('R-Rc', g:current_modes)
378  " R_CTRL-X CTRL-L: Single match
379  exe "normal RBlu\<C-X>\<C-L>\<F2>\<Esc>u"
380  call assert_equal('R-Rc', g:current_modes)
381  " R_CTRL-P: No match
382  exe "normal RCom\<C-P>\<F2>\<Esc>u"
383  call assert_equal('R-Rc', g:current_modes)
384  " R_CTRL-X CTRL-P: No match
385  exe "normal RCom\<C-X>\<C-P>\<F2>\<Esc>u"
386  call assert_equal('R-Rc', g:current_modes)
387  " R_CTRL-X CTRL-L: No match
388  exe "normal Rabc\<C-X>\<C-L>\<F2>\<Esc>u"
389  call assert_equal('R-Rc', g:current_modes)
390
391  call assert_equal('n', mode(0))
392  call assert_equal('n', mode(1))
393
394  " How to test operator-pending mode?
395
396  call feedkeys("v", 'xt')
397  call assert_equal('v', mode())
398  call assert_equal('v', mode(1))
399  call feedkeys("\<Esc>V", 'xt')
400  call assert_equal('V', mode())
401  call assert_equal('V', mode(1))
402  call feedkeys("\<Esc>\<C-V>", 'xt')
403  call assert_equal("\<C-V>", mode())
404  call assert_equal("\<C-V>", mode(1))
405  call feedkeys("\<Esc>", 'xt')
406
407  call feedkeys("gh", 'xt')
408  call assert_equal('s', mode())
409  call assert_equal('s', mode(1))
410  call feedkeys("\<Esc>gH", 'xt')
411  call assert_equal('S', mode())
412  call assert_equal('S', mode(1))
413  call feedkeys("\<Esc>g\<C-H>", 'xt')
414  call assert_equal("\<C-S>", mode())
415  call assert_equal("\<C-S>", mode(1))
416  call feedkeys("\<Esc>", 'xt')
417
418  call feedkeys(":echo \<C-R>=Save_mode()\<C-U>\<CR>", 'xt')
419  call assert_equal('c-c', g:current_modes)
420  call feedkeys("gQecho \<C-R>=Save_mode()\<CR>\<CR>vi\<CR>", 'xt')
421  call assert_equal('c-cv', g:current_modes)
422  " How to test Ex mode?
423
424  bwipe!
425  iunmap <F2>
426endfunc
427
428func Test_getbufvar()
429  let bnr = bufnr('%')
430  let b:var_num = '1234'
431  let def_num = '5678'
432  call assert_equal('1234', getbufvar(bnr, 'var_num'))
433  call assert_equal('1234', getbufvar(bnr, 'var_num', def_num))
434
435  let bd = getbufvar(bnr, '')
436  call assert_equal('1234', bd['var_num'])
437  call assert_true(exists("bd['changedtick']"))
438  call assert_equal(2, len(bd))
439
440  let bd2 = getbufvar(bnr, '', def_num)
441  call assert_equal(bd, bd2)
442
443  unlet b:var_num
444  call assert_equal(def_num, getbufvar(bnr, 'var_num', def_num))
445  call assert_equal('', getbufvar(bnr, 'var_num'))
446
447  let bd = getbufvar(bnr, '')
448  call assert_equal(1, len(bd))
449  let bd = getbufvar(bnr, '',def_num)
450  call assert_equal(1, len(bd))
451
452  call assert_equal('', getbufvar(9, ''))
453  call assert_equal(def_num, getbufvar(9, '', def_num))
454  unlet def_num
455
456  call assert_equal(0, getbufvar(bnr, '&autoindent'))
457  call assert_equal(0, getbufvar(bnr, '&autoindent', 1))
458
459  " Open new window with forced option values
460  set fileformats=unix,dos
461  new ++ff=dos ++bin ++enc=iso-8859-2
462  call assert_equal('dos', getbufvar(bufnr('%'), '&fileformat'))
463  call assert_equal(1, getbufvar(bufnr('%'), '&bin'))
464  call assert_equal('iso-8859-2', getbufvar(bufnr('%'), '&fenc'))
465  close
466
467  set fileformats&
468endfunc
469
470func Test_balloon_show()
471  if has('balloon_eval')
472    " This won't do anything but must not crash either.
473    call balloon_show('hi!')
474  endif
475endfunc
476