annotate src/testdir/test_expr.vim @ 19783:546bdeef35f1 v8.2.0448

patch 8.2.0448: various functions not properly tested Commit: https://github.com/vim/vim/commit/0e05de46226eb4e5ea580beefa71831f92d613d3 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Mar 25 22:23:46 2020 +0100 patch 8.2.0448: various functions not properly tested Problem: Various functions not properly tested. Solution: Add more tests, especially for failures. (Yegappan Lakshmanan, closes #5843)
author Bram Moolenaar <Bram@vim.org>
date Wed, 25 Mar 2020 22:30:04 +0100
parents b3e93a05c3ca
children 2c4d9ca33769
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8635
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Tests for expressions.
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 func Test_equal()
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 let base = {}
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 func base.method()
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 return 1
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 endfunc
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 func base.other() dict
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 return 1
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 endfunc
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 let instance = copy(base)
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 call assert_true(base.method == instance.method)
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 call assert_true([base.method] == [instance.method])
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 call assert_true(base.other == instance.other)
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 call assert_true([base.other] == [instance.other])
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 call assert_false(base.method == base.other)
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 call assert_false([base.method] == [base.other])
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 call assert_false(base.method == instance.other)
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 call assert_false([base.method] == [instance.other])
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 call assert_fails('echo base.method > instance.method')
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 endfunc
8742
03e5171c23e5 commit https://github.com/vim/vim/commit/819821c5a95fc60797ecbb5e5ca1302e397e3d9a
Christian Brabandt <cb@256bit.org>
parents: 8635
diff changeset
24
03e5171c23e5 commit https://github.com/vim/vim/commit/819821c5a95fc60797ecbb5e5ca1302e397e3d9a
Christian Brabandt <cb@256bit.org>
parents: 8635
diff changeset
25 func Test_version()
03e5171c23e5 commit https://github.com/vim/vim/commit/819821c5a95fc60797ecbb5e5ca1302e397e3d9a
Christian Brabandt <cb@256bit.org>
parents: 8635
diff changeset
26 call assert_true(has('patch-7.4.001'))
03e5171c23e5 commit https://github.com/vim/vim/commit/819821c5a95fc60797ecbb5e5ca1302e397e3d9a
Christian Brabandt <cb@256bit.org>
parents: 8635
diff changeset
27 call assert_true(has('patch-7.4.01'))
03e5171c23e5 commit https://github.com/vim/vim/commit/819821c5a95fc60797ecbb5e5ca1302e397e3d9a
Christian Brabandt <cb@256bit.org>
parents: 8635
diff changeset
28 call assert_true(has('patch-7.4.1'))
03e5171c23e5 commit https://github.com/vim/vim/commit/819821c5a95fc60797ecbb5e5ca1302e397e3d9a
Christian Brabandt <cb@256bit.org>
parents: 8635
diff changeset
29 call assert_true(has('patch-6.9.999'))
03e5171c23e5 commit https://github.com/vim/vim/commit/819821c5a95fc60797ecbb5e5ca1302e397e3d9a
Christian Brabandt <cb@256bit.org>
parents: 8635
diff changeset
30 call assert_true(has('patch-7.1.999'))
03e5171c23e5 commit https://github.com/vim/vim/commit/819821c5a95fc60797ecbb5e5ca1302e397e3d9a
Christian Brabandt <cb@256bit.org>
parents: 8635
diff changeset
31 call assert_true(has('patch-7.4.123'))
03e5171c23e5 commit https://github.com/vim/vim/commit/819821c5a95fc60797ecbb5e5ca1302e397e3d9a
Christian Brabandt <cb@256bit.org>
parents: 8635
diff changeset
32
03e5171c23e5 commit https://github.com/vim/vim/commit/819821c5a95fc60797ecbb5e5ca1302e397e3d9a
Christian Brabandt <cb@256bit.org>
parents: 8635
diff changeset
33 call assert_false(has('patch-7'))
03e5171c23e5 commit https://github.com/vim/vim/commit/819821c5a95fc60797ecbb5e5ca1302e397e3d9a
Christian Brabandt <cb@256bit.org>
parents: 8635
diff changeset
34 call assert_false(has('patch-7.4'))
03e5171c23e5 commit https://github.com/vim/vim/commit/819821c5a95fc60797ecbb5e5ca1302e397e3d9a
Christian Brabandt <cb@256bit.org>
parents: 8635
diff changeset
35 call assert_false(has('patch-7.4.'))
03e5171c23e5 commit https://github.com/vim/vim/commit/819821c5a95fc60797ecbb5e5ca1302e397e3d9a
Christian Brabandt <cb@256bit.org>
parents: 8635
diff changeset
36 call assert_false(has('patch-9.1.0'))
03e5171c23e5 commit https://github.com/vim/vim/commit/819821c5a95fc60797ecbb5e5ca1302e397e3d9a
Christian Brabandt <cb@256bit.org>
parents: 8635
diff changeset
37 call assert_false(has('patch-9.9.1'))
03e5171c23e5 commit https://github.com/vim/vim/commit/819821c5a95fc60797ecbb5e5ca1302e397e3d9a
Christian Brabandt <cb@256bit.org>
parents: 8635
diff changeset
38 endfunc
8839
9fa567d13551 commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
39
9fa567d13551 commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
40 func Test_dict()
9fa567d13551 commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
41 let d = {'': 'empty', 'a': 'a', 0: 'zero'}
9fa567d13551 commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
42 call assert_equal('empty', d[''])
9fa567d13551 commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
43 call assert_equal('a', d['a'])
9fa567d13551 commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
44 call assert_equal('zero', d[0])
9fa567d13551 commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
45 call assert_true(has_key(d, ''))
9fa567d13551 commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
46 call assert_true(has_key(d, 'a'))
9fa567d13551 commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
47
9fa567d13551 commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
48 let d[''] = 'none'
9fa567d13551 commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
49 let d['a'] = 'aaa'
9fa567d13551 commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
50 call assert_equal('none', d[''])
9fa567d13551 commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
51 call assert_equal('aaa', d['a'])
9fa567d13551 commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
52 endfunc
8887
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
53
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
54 func Test_strgetchar()
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
55 call assert_equal(char2nr('a'), strgetchar('axb', 0))
18017
988e5a868b60 patch 8.1.2004: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 18000
diff changeset
56 call assert_equal(char2nr('x'), 'axb'->strgetchar(1))
8887
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
57 call assert_equal(char2nr('b'), strgetchar('axb', 2))
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
58
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
59 call assert_equal(-1, strgetchar('axb', -1))
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
60 call assert_equal(-1, strgetchar('axb', 3))
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
61 call assert_equal(-1, strgetchar('', 0))
19783
546bdeef35f1 patch 8.2.0448: various functions not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 19724
diff changeset
62 call assert_fails("let c=strgetchar([], 1)", 'E730:')
546bdeef35f1 patch 8.2.0448: various functions not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 19724
diff changeset
63 call assert_fails("let c=strgetchar('axb', [])", 'E745:')
8887
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
64 endfunc
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
65
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
66 func Test_strcharpart()
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
67 call assert_equal('a', strcharpart('axb', 0, 1))
18017
988e5a868b60 patch 8.1.2004: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 18000
diff changeset
68 call assert_equal('x', 'axb'->strcharpart(1, 1))
8887
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
69 call assert_equal('b', strcharpart('axb', 2, 1))
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
70 call assert_equal('xb', strcharpart('axb', 1))
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
71
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
72 call assert_equal('', strcharpart('axb', 1, 0))
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
73 call assert_equal('', strcharpart('axb', 1, -1))
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
74 call assert_equal('', strcharpart('axb', -1, 1))
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
75 call assert_equal('', strcharpart('axb', -2, 2))
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
76
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
77 call assert_equal('a', strcharpart('axb', -1, 2))
19724
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
78
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
79 call assert_equal('edit', "editor"[-10:3])
8887
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
80 endfunc
8939
36cb3aff8c1c commit https://github.com/vim/vim/commit/517ffbee0d5b7b46320726faaa330b61f54e867c
Christian Brabandt <cb@256bit.org>
parents: 8895
diff changeset
81
36cb3aff8c1c commit https://github.com/vim/vim/commit/517ffbee0d5b7b46320726faaa330b61f54e867c
Christian Brabandt <cb@256bit.org>
parents: 8895
diff changeset
82 func Test_getreg_empty_list()
36cb3aff8c1c commit https://github.com/vim/vim/commit/517ffbee0d5b7b46320726faaa330b61f54e867c
Christian Brabandt <cb@256bit.org>
parents: 8895
diff changeset
83 call assert_equal('', getreg('x'))
36cb3aff8c1c commit https://github.com/vim/vim/commit/517ffbee0d5b7b46320726faaa330b61f54e867c
Christian Brabandt <cb@256bit.org>
parents: 8895
diff changeset
84 call assert_equal([], getreg('x', 1, 1))
36cb3aff8c1c commit https://github.com/vim/vim/commit/517ffbee0d5b7b46320726faaa330b61f54e867c
Christian Brabandt <cb@256bit.org>
parents: 8895
diff changeset
85 let x = getreg('x', 1, 1)
36cb3aff8c1c commit https://github.com/vim/vim/commit/517ffbee0d5b7b46320726faaa330b61f54e867c
Christian Brabandt <cb@256bit.org>
parents: 8895
diff changeset
86 let y = x
36cb3aff8c1c commit https://github.com/vim/vim/commit/517ffbee0d5b7b46320726faaa330b61f54e867c
Christian Brabandt <cb@256bit.org>
parents: 8895
diff changeset
87 call add(x, 'foo')
36cb3aff8c1c commit https://github.com/vim/vim/commit/517ffbee0d5b7b46320726faaa330b61f54e867c
Christian Brabandt <cb@256bit.org>
parents: 8895
diff changeset
88 call assert_equal(['foo'], y)
36cb3aff8c1c commit https://github.com/vim/vim/commit/517ffbee0d5b7b46320726faaa330b61f54e867c
Christian Brabandt <cb@256bit.org>
parents: 8895
diff changeset
89 endfunc
9062
0aa90b84118c commit https://github.com/vim/vim/commit/d8585eded6359f1d7e1981e96ae775efd077c638
Christian Brabandt <cb@256bit.org>
parents: 8939
diff changeset
90
0aa90b84118c commit https://github.com/vim/vim/commit/d8585eded6359f1d7e1981e96ae775efd077c638
Christian Brabandt <cb@256bit.org>
parents: 8939
diff changeset
91 func Test_loop_over_null_list()
9108
d319453f62b3 commit https://github.com/vim/vim/commit/574860b5ee9da281c875dad07a607454e135eaee
Christian Brabandt <cb@256bit.org>
parents: 9062
diff changeset
92 let null_list = test_null_list()
9062
0aa90b84118c commit https://github.com/vim/vim/commit/d8585eded6359f1d7e1981e96ae775efd077c638
Christian Brabandt <cb@256bit.org>
parents: 8939
diff changeset
93 for i in null_list
11183
1c4ebbae41d2 patch 8.0.0478: tests use assert_true(0) and assert_false(1) to report errors
Christian Brabandt <cb@256bit.org>
parents: 10924
diff changeset
94 call assert_report('should not get here')
9062
0aa90b84118c commit https://github.com/vim/vim/commit/d8585eded6359f1d7e1981e96ae775efd077c638
Christian Brabandt <cb@256bit.org>
parents: 8939
diff changeset
95 endfor
0aa90b84118c commit https://github.com/vim/vim/commit/d8585eded6359f1d7e1981e96ae775efd077c638
Christian Brabandt <cb@256bit.org>
parents: 8939
diff changeset
96 endfunc
9127
1b41750311b6 commit https://github.com/vim/vim/commit/13ddc5c35921efa69e980284117b6db6465e019c
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
97
1b41750311b6 commit https://github.com/vim/vim/commit/13ddc5c35921efa69e980284117b6db6465e019c
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
98 func Test_compare_null_dict()
1b41750311b6 commit https://github.com/vim/vim/commit/13ddc5c35921efa69e980284117b6db6465e019c
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
99 call assert_fails('let x = test_null_dict()[10]')
1b41750311b6 commit https://github.com/vim/vim/commit/13ddc5c35921efa69e980284117b6db6465e019c
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
100 call assert_equal({}, {})
1b41750311b6 commit https://github.com/vim/vim/commit/13ddc5c35921efa69e980284117b6db6465e019c
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
101 call assert_equal(test_null_dict(), test_null_dict())
1b41750311b6 commit https://github.com/vim/vim/commit/13ddc5c35921efa69e980284117b6db6465e019c
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
102 call assert_notequal({}, test_null_dict())
1b41750311b6 commit https://github.com/vim/vim/commit/13ddc5c35921efa69e980284117b6db6465e019c
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
103 endfunc
1b41750311b6 commit https://github.com/vim/vim/commit/13ddc5c35921efa69e980284117b6db6465e019c
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
104
1b41750311b6 commit https://github.com/vim/vim/commit/13ddc5c35921efa69e980284117b6db6465e019c
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
105 func Test_set_reg_null_list()
1b41750311b6 commit https://github.com/vim/vim/commit/13ddc5c35921efa69e980284117b6db6465e019c
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
106 call setreg('x', test_null_list())
1b41750311b6 commit https://github.com/vim/vim/commit/13ddc5c35921efa69e980284117b6db6465e019c
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
107 endfunc
9373
b88c573d8aa4 commit https://github.com/vim/vim/commit/1d90a5a5af84250e226f8a9121e771f7b72aa894
Christian Brabandt <cb@256bit.org>
parents: 9127
diff changeset
108
b88c573d8aa4 commit https://github.com/vim/vim/commit/1d90a5a5af84250e226f8a9121e771f7b72aa894
Christian Brabandt <cb@256bit.org>
parents: 9127
diff changeset
109 func Test_special_char()
b88c573d8aa4 commit https://github.com/vim/vim/commit/1d90a5a5af84250e226f8a9121e771f7b72aa894
Christian Brabandt <cb@256bit.org>
parents: 9127
diff changeset
110 " The failure is only visible using valgrind.
b88c573d8aa4 commit https://github.com/vim/vim/commit/1d90a5a5af84250e226f8a9121e771f7b72aa894
Christian Brabandt <cb@256bit.org>
parents: 9127
diff changeset
111 call assert_fails('echo "\<C-">')
b88c573d8aa4 commit https://github.com/vim/vim/commit/1d90a5a5af84250e226f8a9121e771f7b72aa894
Christian Brabandt <cb@256bit.org>
parents: 9127
diff changeset
112 endfunc
9395
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
113
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
114 func Test_option_value()
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
115 " boolean
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
116 set bri
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
117 call assert_equal(1, &bri)
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
118 set nobri
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
119 call assert_equal(0, &bri)
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
120
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
121 " number
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
122 set ts=1
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
123 call assert_equal(1, &ts)
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
124 set ts=8
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
125 call assert_equal(8, &ts)
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
126
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
127 " string
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
128 exe "set cedit=\<Esc>"
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
129 call assert_equal("\<Esc>", &cedit)
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
130 set cpo=
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
131 call assert_equal("", &cpo)
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
132 set cpo=abcdefgi
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
133 call assert_equal("abcdefgi", &cpo)
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
134 set cpo&vim
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
135 endfunc
9497
d18d71ae21e5 commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents: 9395
diff changeset
136
9984
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
137 function Test_printf_misc()
13367
53f15c99a9fd patch 8.0.1557: printf() does not work with only one argument
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
138 call assert_equal('123', printf('123'))
53f15c99a9fd patch 8.0.1557: printf() does not work with only one argument
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
139 call assert_fails("call printf('123', 3)", "E767:")
53f15c99a9fd patch 8.0.1557: printf() does not work with only one argument
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
140
9984
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
141 call assert_equal('123', printf('%d', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
142 call assert_equal('123', printf('%i', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
143 call assert_equal('123', printf('%D', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
144 call assert_equal('123', printf('%U', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
145 call assert_equal('173', printf('%o', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
146 call assert_equal('173', printf('%O', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
147 call assert_equal('7b', printf('%x', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
148 call assert_equal('7B', printf('%X', 123))
15172
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
149
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
150 call assert_equal('123', printf('%hd', 123))
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
151 call assert_equal('-123', printf('%hd', -123))
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
152 call assert_equal('-1', printf('%hd', 0xFFFF))
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
153 call assert_equal('-1', printf('%hd', 0x1FFFFF))
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
154
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
155 call assert_equal('123', printf('%hu', 123))
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
156 call assert_equal('65413', printf('%hu', -123))
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
157 call assert_equal('65535', printf('%hu', 0xFFFF))
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
158 call assert_equal('65535', printf('%hu', 0x1FFFFF))
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
159
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
160 call assert_equal('123', printf('%ld', 123))
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
161 call assert_equal('-123', printf('%ld', -123))
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
162 call assert_equal('65535', printf('%ld', 0xFFFF))
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
163 call assert_equal('131071', printf('%ld', 0x1FFFF))
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
164
9984
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
165 if has('ebcdic')
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
166 call assert_equal('#', printf('%c', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
167 else
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
168 call assert_equal('{', printf('%c', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
169 endif
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
170 call assert_equal('abc', printf('%s', 'abc'))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
171 call assert_equal('abc', printf('%S', 'abc'))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
172
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
173 call assert_equal('+123', printf('%+d', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
174 call assert_equal('-123', printf('%+d', -123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
175 call assert_equal('+123', printf('%+ d', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
176 call assert_equal(' 123', printf('% d', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
177 call assert_equal(' 123', printf('% d', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
178 call assert_equal('-123', printf('% d', -123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
179
10015
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
180 call assert_equal('123', printf('%2d', 123))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
181 call assert_equal(' 123', printf('%6d', 123))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
182 call assert_equal('000123', printf('%06d', 123))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
183 call assert_equal('+00123', printf('%+06d', 123))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
184 call assert_equal(' 00123', printf('% 06d', 123))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
185 call assert_equal(' +123', printf('%+6d', 123))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
186 call assert_equal(' 123', printf('% 6d', 123))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
187 call assert_equal(' -123', printf('% 6d', -123))
10038
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
188
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
189 " Test left adjusted.
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
190 call assert_equal('123 ', printf('%-6d', 123))
10015
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
191 call assert_equal('+123 ', printf('%-+6d', 123))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
192 call assert_equal(' 123 ', printf('%- 6d', 123))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
193 call assert_equal('-123 ', printf('%- 6d', -123))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
194
10038
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
195 call assert_equal(' 00123', printf('%7.5d', 123))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
196 call assert_equal(' -00123', printf('%7.5d', -123))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
197 call assert_equal(' +00123', printf('%+7.5d', 123))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
198 " Precision field should not be used when combined with %0
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
199 call assert_equal(' 00123', printf('%07.5d', 123))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
200 call assert_equal(' -00123', printf('%07.5d', -123))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
201
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
202 call assert_equal(' 123', printf('%*d', 5, 123))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
203 call assert_equal('123 ', printf('%*d', -5, 123))
9984
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
204 call assert_equal('00123', printf('%.*d', 5, 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
205 call assert_equal(' 123', printf('% *d', 5, 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
206 call assert_equal(' +123', printf('%+ *d', 5, 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
207
15172
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
208 call assert_equal('foobar', printf('%.*s', 9, 'foobar'))
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
209 call assert_equal('foo', printf('%.*s', 3, 'foobar'))
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
210 call assert_equal('', printf('%.*s', 0, 'foobar'))
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
211 call assert_equal('foobar', printf('%.*s', -1, 'foobar'))
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
212
10038
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
213 " Simple quote (thousand grouping char) is ignored.
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
214 call assert_equal('+00123456', printf("%+'09d", 123456))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
215
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
216 " Unrecognized format specifier kept as-is.
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
217 call assert_equal('_123', printf("%_%d", 123))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
218
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
219 " Test alternate forms.
9984
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
220 call assert_equal('0x7b', printf('%#x', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
221 call assert_equal('0X7B', printf('%#X', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
222 call assert_equal('0173', printf('%#o', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
223 call assert_equal('0173', printf('%#O', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
224 call assert_equal('abc', printf('%#s', 'abc'))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
225 call assert_equal('abc', printf('%#S', 'abc'))
10038
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
226 call assert_equal(' 0173', printf('%#6o', 123))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
227 call assert_equal(' 00173', printf('%#6.5o', 123))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
228 call assert_equal(' 0173', printf('%#6.2o', 123))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
229 call assert_equal(' 0173', printf('%#6.2o', 123))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
230 call assert_equal('0173', printf('%#2.2o', 123))
9984
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
231
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
232 call assert_equal(' 00123', printf('%6.5d', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
233 call assert_equal(' 0007b', printf('%6.5x', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
234
15172
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
235 call assert_equal('123', printf('%.2d', 123))
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
236 call assert_equal('0123', printf('%.4d', 123))
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
237 call assert_equal('0000000123', printf('%.10d', 123))
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
238 call assert_equal('123', printf('%.0d', 123))
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
239
9984
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
240 call assert_equal('abc', printf('%2s', 'abc'))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
241 call assert_equal('abc', printf('%2S', 'abc'))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
242 call assert_equal('abc', printf('%.4s', 'abc'))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
243 call assert_equal('abc', printf('%.4S', 'abc'))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
244 call assert_equal('ab', printf('%.2s', 'abc'))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
245 call assert_equal('ab', printf('%.2S', 'abc'))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
246 call assert_equal('', printf('%.0s', 'abc'))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
247 call assert_equal('', printf('%.s', 'abc'))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
248 call assert_equal(' abc', printf('%4s', 'abc'))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
249 call assert_equal(' abc', printf('%4S', 'abc'))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
250 call assert_equal('0abc', printf('%04s', 'abc'))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
251 call assert_equal('0abc', printf('%04S', 'abc'))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
252 call assert_equal('abc ', printf('%-4s', 'abc'))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
253 call assert_equal('abc ', printf('%-4S', 'abc'))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
254
18176
dfe9db84e326 patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()
Bram Moolenaar <Bram@vim.org>
parents: 18017
diff changeset
255 call assert_equal('🐍', printf('%.2S', '🐍🐍'))
dfe9db84e326 patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()
Bram Moolenaar <Bram@vim.org>
parents: 18017
diff changeset
256 call assert_equal('', printf('%.1S', '🐍🐍'))
dfe9db84e326 patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()
Bram Moolenaar <Bram@vim.org>
parents: 18017
diff changeset
257
9984
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
258 call assert_equal('1%', printf('%d%%', 1))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
259 endfunc
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
260
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
261 function Test_printf_float()
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
262 if has('float')
10038
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
263 call assert_equal('1.000000', printf('%f', 1))
9984
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
264 call assert_equal('1.230000', printf('%f', 1.23))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
265 call assert_equal('1.230000', printf('%F', 1.23))
10015
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
266 call assert_equal('9999999.9', printf('%g', 9999999.9))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
267 call assert_equal('9999999.9', printf('%G', 9999999.9))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
268 call assert_equal('1.00000001e7', printf('%.8g', 10000000.1))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
269 call assert_equal('1.00000001E7', printf('%.8G', 10000000.1))
9984
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
270 call assert_equal('1.230000e+00', printf('%e', 1.23))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
271 call assert_equal('1.230000E+00', printf('%E', 1.23))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
272 call assert_equal('1.200000e-02', printf('%e', 0.012))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
273 call assert_equal('-1.200000e-02', printf('%e', -0.012))
10015
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
274 call assert_equal('0.33', printf('%.2f', 1.0/3.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
275 call assert_equal(' 0.33', printf('%6.2f', 1.0/3.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
276 call assert_equal(' -0.33', printf('%6.2f', -1.0/3.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
277 call assert_equal('000.33', printf('%06.2f', 1.0/3.0))
10038
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
278 call assert_equal('-00.33', printf('%06.2f', -1.0/3.0))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
279 call assert_equal('-00.33', printf('%+06.2f', -1.0/3.0))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
280 call assert_equal('+00.33', printf('%+06.2f', 1.0/3.0))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
281 call assert_equal(' 00.33', printf('% 06.2f', 1.0/3.0))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
282 call assert_equal('000.33', printf('%06.2g', 1.0/3.0))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
283 call assert_equal('-00.33', printf('%06.2g', -1.0/3.0))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
284 call assert_equal('0.33', printf('%3.2f', 1.0/3.0))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
285 call assert_equal('003.33e-01', printf('%010.2e', 1.0/3.0))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
286 call assert_equal(' 03.33e-01', printf('% 010.2e', 1.0/3.0))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
287 call assert_equal('+03.33e-01', printf('%+010.2e', 1.0/3.0))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
288 call assert_equal('-03.33e-01', printf('%010.2e', -1.0/3.0))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
289
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
290 " When precision is 0, the dot should be omitted.
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
291 call assert_equal(' 2', printf('%3.f', 7.0/3.0))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
292 call assert_equal(' 2', printf('%3.g', 7.0/3.0))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
293 call assert_equal(' 2e+00', printf('%7.e', 7.0/3.0))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
294
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
295 " Float zero can be signed.
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
296 call assert_equal('+0.000000', printf('%+f', 0.0))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
297 call assert_equal('0.000000', printf('%f', 1.0/(1.0/0.0)))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
298 call assert_equal('-0.000000', printf('%f', 1.0/(-1.0/0.0)))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
299 call assert_equal('0.0', printf('%s', 1.0/(1.0/0.0)))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
300 call assert_equal('-0.0', printf('%s', 1.0/(-1.0/0.0)))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
301 call assert_equal('0.0', printf('%S', 1.0/(1.0/0.0)))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
302 call assert_equal('-0.0', printf('%S', 1.0/(-1.0/0.0)))
9984
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
303
10015
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
304 " Float infinity can be signed.
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
305 call assert_equal('inf', printf('%f', 1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
306 call assert_equal('-inf', printf('%f', -1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
307 call assert_equal('inf', printf('%g', 1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
308 call assert_equal('-inf', printf('%g', -1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
309 call assert_equal('inf', printf('%e', 1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
310 call assert_equal('-inf', printf('%e', -1.0/0.0))
10038
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
311 call assert_equal('INF', printf('%F', 1.0/0.0))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
312 call assert_equal('-INF', printf('%F', -1.0/0.0))
10015
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
313 call assert_equal('INF', printf('%E', 1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
314 call assert_equal('-INF', printf('%E', -1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
315 call assert_equal('INF', printf('%E', 1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
316 call assert_equal('-INF', printf('%G', -1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
317 call assert_equal('+inf', printf('%+f', 1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
318 call assert_equal('-inf', printf('%+f', -1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
319 call assert_equal(' inf', printf('% f', 1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
320 call assert_equal(' inf', printf('%6f', 1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
321 call assert_equal(' -inf', printf('%6f', -1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
322 call assert_equal(' inf', printf('%6g', 1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
323 call assert_equal(' -inf', printf('%6g', -1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
324 call assert_equal(' +inf', printf('%+6f', 1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
325 call assert_equal(' inf', printf('% 6f', 1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
326 call assert_equal(' +inf', printf('%+06f', 1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
327 call assert_equal('inf ', printf('%-6f', 1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
328 call assert_equal('-inf ', printf('%-6f', -1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
329 call assert_equal('+inf ', printf('%-+6f', 1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
330 call assert_equal(' inf ', printf('%- 6f', 1.0/0.0))
10038
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
331 call assert_equal('-INF ', printf('%-6F', -1.0/0.0))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
332 call assert_equal('+INF ', printf('%-+6F', 1.0/0.0))
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
333 call assert_equal(' INF ', printf('%- 6F', 1.0/0.0))
10015
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
334 call assert_equal('INF ', printf('%-6G', 1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
335 call assert_equal('-INF ', printf('%-6G', -1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
336 call assert_equal('INF ', printf('%-6E', 1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
337 call assert_equal('-INF ', printf('%-6E', -1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
338 call assert_equal('inf', printf('%s', 1.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
339 call assert_equal('-inf', printf('%s', -1.0/0.0))
9984
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
340
15172
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
341 " Test special case where max precision is truncated at 340.
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
342 call assert_equal('1.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', printf('%.330f', 1.0))
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
343 call assert_equal('1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', printf('%.340f', 1.0))
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
344 call assert_equal('1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', printf('%.350f', 1.0))
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
345
10015
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
346 " Float nan (not a number) has no sign.
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
347 call assert_equal('nan', printf('%f', sqrt(-1.0)))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
348 call assert_equal('nan', printf('%f', 0.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
349 call assert_equal('nan', printf('%f', -0.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
350 call assert_equal('nan', printf('%g', 0.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
351 call assert_equal('nan', printf('%e', 0.0/0.0))
10038
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
352 call assert_equal('NAN', printf('%F', 0.0/0.0))
10015
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
353 call assert_equal('NAN', printf('%G', 0.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
354 call assert_equal('NAN', printf('%E', 0.0/0.0))
10038
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
355 call assert_equal('NAN', printf('%F', -0.0/0.0))
10015
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
356 call assert_equal('NAN', printf('%G', -0.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
357 call assert_equal('NAN', printf('%E', -0.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
358 call assert_equal(' nan', printf('%6f', 0.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
359 call assert_equal(' nan', printf('%06f', 0.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
360 call assert_equal('nan ', printf('%-6f', 0.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
361 call assert_equal('nan ', printf('%- 6f', 0.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
362 call assert_equal('nan', printf('%s', 0.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
363 call assert_equal('nan', printf('%s', -0.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
364 call assert_equal('nan', printf('%S', 0.0/0.0))
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
365 call assert_equal('nan', printf('%S', -0.0/0.0))
9984
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
366
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
367 call assert_fails('echo printf("%f", "a")', 'E807:')
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
368 endif
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
369 endfunc
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
370
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
371 function Test_printf_errors()
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
372 call assert_fails('echo printf("%d", {})', 'E728:')
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
373 call assert_fails('echo printf("%d", [])', 'E745:')
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
374 call assert_fails('echo printf("%d", 1, 2)', 'E767:')
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
375 call assert_fails('echo printf("%*d", 1)', 'E766:')
19249
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
376 if has('float')
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
377 call assert_fails('echo printf("%d", 1.2)', 'E805:')
2a017e9dc6da patch 8.2.0183: tests fail when the float feature is disabled
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
378 endif
9984
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
379 endfunc
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
380
10116
a6068b90c873 commit https://github.com/vim/vim/commit/26b84339fd8766898bcf6a259cbc2e0c38689726
Christian Brabandt <cb@256bit.org>
parents: 10038
diff changeset
381 function Test_max_min_errors()
a6068b90c873 commit https://github.com/vim/vim/commit/26b84339fd8766898bcf6a259cbc2e0c38689726
Christian Brabandt <cb@256bit.org>
parents: 10038
diff changeset
382 call assert_fails('call max(v:true)', 'E712:')
a6068b90c873 commit https://github.com/vim/vim/commit/26b84339fd8766898bcf6a259cbc2e0c38689726
Christian Brabandt <cb@256bit.org>
parents: 10038
diff changeset
383 call assert_fails('call max(v:true)', 'max()')
a6068b90c873 commit https://github.com/vim/vim/commit/26b84339fd8766898bcf6a259cbc2e0c38689726
Christian Brabandt <cb@256bit.org>
parents: 10038
diff changeset
384 call assert_fails('call min(v:true)', 'E712:')
a6068b90c873 commit https://github.com/vim/vim/commit/26b84339fd8766898bcf6a259cbc2e0c38689726
Christian Brabandt <cb@256bit.org>
parents: 10038
diff changeset
385 call assert_fails('call min(v:true)', 'min()')
a6068b90c873 commit https://github.com/vim/vim/commit/26b84339fd8766898bcf6a259cbc2e0c38689726
Christian Brabandt <cb@256bit.org>
parents: 10038
diff changeset
386 endfunc
a6068b90c873 commit https://github.com/vim/vim/commit/26b84339fd8766898bcf6a259cbc2e0c38689726
Christian Brabandt <cb@256bit.org>
parents: 10038
diff changeset
387
9497
d18d71ae21e5 commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents: 9395
diff changeset
388 function Test_printf_64bit()
19427
fdfe44ac6a1a patch 8.2.0271: the "num64" feature is available everywhere
Bram Moolenaar <Bram@vim.org>
parents: 19415
diff changeset
389 call assert_equal("123456789012345", printf('%d', 123456789012345))
9497
d18d71ae21e5 commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents: 9395
diff changeset
390 endfunc
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
391
9892
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
392 function Test_printf_spec_s()
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
393 " number
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
394 call assert_equal("1234567890", printf('%s', 1234567890))
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
395
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
396 " string
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
397 call assert_equal("abcdefgi", printf('%s', "abcdefgi"))
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
398
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
399 " float
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
400 if has('float')
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
401 call assert_equal("1.23", printf('%s', 1.23))
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
402 endif
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
403
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
404 " list
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
405 let value = [1, 'two', ['three', 4]]
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
406 call assert_equal(string(value), printf('%s', value))
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
407
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
408 " dict
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
409 let value = {'key1' : 'value1', 'key2' : ['list', 'value'], 'key3' : {'dict' : 'value'}}
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
410 call assert_equal(string(value), printf('%s', value))
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
411
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
412 " funcref
17849
73ddc462979d patch 8.1.1921: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 16706
diff changeset
413 call assert_equal('printf', printf('%s', 'printf'->function()))
9892
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
414
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
415 " partial
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
416 call assert_equal(string(function('printf', ['%s'])), printf('%s', function('printf', ['%s'])))
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
417 endfunc
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
418
9894
b01afb4e8f66 commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents: 9892
diff changeset
419 function Test_printf_spec_b()
b01afb4e8f66 commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents: 9892
diff changeset
420 call assert_equal("0", printf('%b', 0))
b01afb4e8f66 commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents: 9892
diff changeset
421 call assert_equal("00001100", printf('%08b', 12))
b01afb4e8f66 commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents: 9892
diff changeset
422 call assert_equal("11111111", printf('%08b', 0xff))
b01afb4e8f66 commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents: 9892
diff changeset
423 call assert_equal(" 1111011", printf('%10b', 123))
b01afb4e8f66 commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents: 9892
diff changeset
424 call assert_equal("0001111011", printf('%010b', 123))
b01afb4e8f66 commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents: 9892
diff changeset
425 call assert_equal(" 0b1111011", printf('%#10b', 123))
b01afb4e8f66 commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents: 9892
diff changeset
426 call assert_equal("0B01111011", printf('%#010B', 123))
b01afb4e8f66 commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents: 9892
diff changeset
427 call assert_equal("1001001100101100000001011010010", printf('%b', 1234567890))
19427
fdfe44ac6a1a patch 8.2.0271: the "num64" feature is available everywhere
Bram Moolenaar <Bram@vim.org>
parents: 19415
diff changeset
428 call assert_equal("11100000100100010000110000011011101111101111001", printf('%b', 123456789012345))
fdfe44ac6a1a patch 8.2.0271: the "num64" feature is available everywhere
Bram Moolenaar <Bram@vim.org>
parents: 19415
diff changeset
429 call assert_equal("1111111111111111111111111111111111111111111111111111111111111111", printf('%b', -1))
9894
b01afb4e8f66 commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents: 9892
diff changeset
430 endfunc
b01afb4e8f66 commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents: 9892
diff changeset
431
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
432 func Test_substitute_expr()
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
433 let g:val = 'XXX'
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
434 call assert_equal('XXX', substitute('yyy', 'y*', '\=g:val', ''))
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
435 call assert_equal('XXX', substitute('yyy', 'y*', {-> g:val}, ''))
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
436 call assert_equal("-\u1b \uf2-", substitute("-%1b %f2-", '%\(\x\x\)',
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
437 \ '\=nr2char("0x" . submatch(1))', 'g'))
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
438 call assert_equal("-\u1b \uf2-", substitute("-%1b %f2-", '%\(\x\x\)',
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
439 \ {-> nr2char("0x" . submatch(1))}, 'g'))
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
440
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
441 call assert_equal('231', substitute('123', '\(.\)\(.\)\(.\)',
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
442 \ {-> submatch(2) . submatch(3) . submatch(1)}, ''))
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
443
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
444 func Recurse()
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10207
diff changeset
445 return substitute('yyy', 'y\(.\)y', {-> submatch(1)}, '')
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
446 endfunc
10245
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10207
diff changeset
447 " recursive call works
d76ccdacb41e commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents: 10207
diff changeset
448 call assert_equal('-y-x-', substitute('xxx', 'x\(.\)x', {-> '-' . Recurse() . '-' . submatch(1) . '-'}, ''))
19783
546bdeef35f1 patch 8.2.0448: various functions not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 19724
diff changeset
449
546bdeef35f1 patch 8.2.0448: various functions not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 19724
diff changeset
450 call assert_fails("let s=submatch([])", 'E745:')
546bdeef35f1 patch 8.2.0448: various functions not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 19724
diff changeset
451 call assert_fails("let s=submatch(2, [])", 'E745:')
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
452 endfunc
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
453
9923
935e13935848 commit https://github.com/vim/vim/commit/989f592f7ffcbafdc4ec35cee4dc65bd053e2077
Christian Brabandt <cb@256bit.org>
parents: 9919
diff changeset
454 func Test_invalid_submatch()
935e13935848 commit https://github.com/vim/vim/commit/989f592f7ffcbafdc4ec35cee4dc65bd053e2077
Christian Brabandt <cb@256bit.org>
parents: 9919
diff changeset
455 " This was causing invalid memory access in Vim-7.4.2232 and older
935e13935848 commit https://github.com/vim/vim/commit/989f592f7ffcbafdc4ec35cee4dc65bd053e2077
Christian Brabandt <cb@256bit.org>
parents: 9919
diff changeset
456 call assert_fails("call substitute('x', '.', {-> submatch(10)}, '')", 'E935:')
935e13935848 commit https://github.com/vim/vim/commit/989f592f7ffcbafdc4ec35cee4dc65bd053e2077
Christian Brabandt <cb@256bit.org>
parents: 9919
diff changeset
457 endfunc
935e13935848 commit https://github.com/vim/vim/commit/989f592f7ffcbafdc4ec35cee4dc65bd053e2077
Christian Brabandt <cb@256bit.org>
parents: 9919
diff changeset
458
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
459 func Test_substitute_expr_arg()
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
460 call assert_equal('123456789-123456789=', substitute('123456789',
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
461 \ '\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)',
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
462 \ {m -> m[0] . '-' . m[1] . m[2] . m[3] . m[4] . m[5] . m[6] . m[7] . m[8] . m[9] . '='}, ''))
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
463
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
464 call assert_equal('123456-123456=789', substitute('123456789',
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
465 \ '\(.\)\(.\)\(.\)\(a*\)\(n*\)\(.\)\(.\)\(.\)\(x*\)',
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
466 \ {m -> m[0] . '-' . m[1] . m[2] . m[3] . m[4] . m[5] . m[6] . m[7] . m[8] . m[9] . '='}, ''))
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
467
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
468 call assert_equal('123456789-123456789x=', substitute('123456789',
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
469 \ '\(.\)\(.\)\(.*\)',
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
470 \ {m -> m[0] . '-' . m[1] . m[2] . m[3] . 'x' . m[4] . m[5] . m[6] . m[7] . m[8] . m[9] . '='}, ''))
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
471
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
472 call assert_fails("call substitute('xxx', '.', {m -> string(add(m, 'x'))}, '')", 'E742:')
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
473 call assert_fails("call substitute('xxx', '.', {m -> string(insert(m, 'x'))}, '')", 'E742:')
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
474 call assert_fails("call substitute('xxx', '.', {m -> string(extend(m, ['x']))}, '')", 'E742:')
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
475 call assert_fails("call substitute('xxx', '.', {m -> string(remove(m, 1))}, '')", 'E742:')
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
476 endfunc
9717
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9626
diff changeset
477
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9626
diff changeset
478 func Test_function_with_funcref()
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9626
diff changeset
479 let s:f = function('type')
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9626
diff changeset
480 let s:fref = function(s:f)
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9626
diff changeset
481 call assert_equal(v:t_string, s:fref('x'))
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9626
diff changeset
482 call assert_fails("call function('s:f')", 'E700:')
10207
9415453b7bbd commit https://github.com/vim/vim/commit/5582ef14384525e8cec86016876d97a6b32dd548
Christian Brabandt <cb@256bit.org>
parents: 10116
diff changeset
483
9415453b7bbd commit https://github.com/vim/vim/commit/5582ef14384525e8cec86016876d97a6b32dd548
Christian Brabandt <cb@256bit.org>
parents: 10116
diff changeset
484 call assert_fails("call function('foo()')", 'E475:')
9415453b7bbd commit https://github.com/vim/vim/commit/5582ef14384525e8cec86016876d97a6b32dd548
Christian Brabandt <cb@256bit.org>
parents: 10116
diff changeset
485 call assert_fails("call function('foo()')", 'foo()')
19724
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
486 call assert_fails("function('')", 'E129:')
9717
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9626
diff changeset
487 endfunc
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
488
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
489 func Test_funcref()
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
490 func! One()
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
491 return 1
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
492 endfunc
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
493 let OneByName = function('One')
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
494 let OneByRef = funcref('One')
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
495 func! One()
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
496 return 2
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
497 endfunc
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
498 call assert_equal(2, OneByName())
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
499 call assert_equal(1, OneByRef())
17849
73ddc462979d patch 8.1.1921: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 16706
diff changeset
500 let OneByRef = 'One'->funcref()
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
501 call assert_equal(2, OneByRef())
9919
885e3c9c0e10 commit https://github.com/vim/vim/commit/843b884461de1c79a1d2748549776fb13fc94360
Christian Brabandt <cb@256bit.org>
parents: 9894
diff changeset
502 call assert_fails('echo funcref("{")', 'E475:')
18576
e9675870c480 patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents: 18176
diff changeset
503 let OneByRef = funcref("One", repeat(["foo"], 20))
e9675870c480 patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents: 18176
diff changeset
504 call assert_fails('let OneByRef = funcref("One", repeat(["foo"], 21))', 'E118:')
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
505 endfunc
9770
ba98d7ce0d74 commit https://github.com/vim/vim/commit/7dc5e2e486fe0287601968e535902a41a39f65bb
Christian Brabandt <cb@256bit.org>
parents: 9723
diff changeset
506
ba98d7ce0d74 commit https://github.com/vim/vim/commit/7dc5e2e486fe0287601968e535902a41a39f65bb
Christian Brabandt <cb@256bit.org>
parents: 9723
diff changeset
507 func Test_setmatches()
ba98d7ce0d74 commit https://github.com/vim/vim/commit/7dc5e2e486fe0287601968e535902a41a39f65bb
Christian Brabandt <cb@256bit.org>
parents: 9723
diff changeset
508 hi def link 1 Comment
ba98d7ce0d74 commit https://github.com/vim/vim/commit/7dc5e2e486fe0287601968e535902a41a39f65bb
Christian Brabandt <cb@256bit.org>
parents: 9723
diff changeset
509 hi def link 2 PreProc
9772
560291211303 commit https://github.com/vim/vim/commit/7ab6defcafe017a3ad58580a3e56dab705b1ed8b
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
510 let set = [{"group": 1, "pattern": 2, "id": 3, "priority": 4}]
560291211303 commit https://github.com/vim/vim/commit/7ab6defcafe017a3ad58580a3e56dab705b1ed8b
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
511 let exp = [{"group": '1', "pattern": '2', "id": 3, "priority": 4}]
560291211303 commit https://github.com/vim/vim/commit/7ab6defcafe017a3ad58580a3e56dab705b1ed8b
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
512 if has('conceal')
560291211303 commit https://github.com/vim/vim/commit/7ab6defcafe017a3ad58580a3e56dab705b1ed8b
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
513 let set[0]['conceal'] = 5
560291211303 commit https://github.com/vim/vim/commit/7ab6defcafe017a3ad58580a3e56dab705b1ed8b
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
514 let exp[0]['conceal'] = '5'
560291211303 commit https://github.com/vim/vim/commit/7ab6defcafe017a3ad58580a3e56dab705b1ed8b
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
515 endif
18000
7a19c8d6bb9e patch 8.1.1996: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17849
diff changeset
516 eval set->setmatches()
9770
ba98d7ce0d74 commit https://github.com/vim/vim/commit/7dc5e2e486fe0287601968e535902a41a39f65bb
Christian Brabandt <cb@256bit.org>
parents: 9723
diff changeset
517 call assert_equal(exp, getmatches())
ba98d7ce0d74 commit https://github.com/vim/vim/commit/7dc5e2e486fe0287601968e535902a41a39f65bb
Christian Brabandt <cb@256bit.org>
parents: 9723
diff changeset
518 endfunc
10924
053d4ad16f37 patch 8.0.0351: no test for concatenating an empty string
Christian Brabandt <cb@256bit.org>
parents: 10245
diff changeset
519
053d4ad16f37 patch 8.0.0351: no test for concatenating an empty string
Christian Brabandt <cb@256bit.org>
parents: 10245
diff changeset
520 func Test_empty_concatenate()
053d4ad16f37 patch 8.0.0351: no test for concatenating an empty string
Christian Brabandt <cb@256bit.org>
parents: 10245
diff changeset
521 call assert_equal('b', 'a'[4:0] . 'b')
053d4ad16f37 patch 8.0.0351: no test for concatenating an empty string
Christian Brabandt <cb@256bit.org>
parents: 10245
diff changeset
522 call assert_equal('b', 'b' . 'a'[4:0])
053d4ad16f37 patch 8.0.0351: no test for concatenating an empty string
Christian Brabandt <cb@256bit.org>
parents: 10245
diff changeset
523 endfunc
16706
77bcb5055fec patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents: 15172
diff changeset
524
77bcb5055fec patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents: 15172
diff changeset
525 func Test_broken_number()
77bcb5055fec patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents: 15172
diff changeset
526 let X = 'bad'
77bcb5055fec patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents: 15172
diff changeset
527 call assert_fails('echo 1X', 'E15:')
77bcb5055fec patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents: 15172
diff changeset
528 call assert_fails('echo 0b1X', 'E15:')
77bcb5055fec patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents: 15172
diff changeset
529 call assert_fails('echo 0b12', 'E15:')
77bcb5055fec patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents: 15172
diff changeset
530 call assert_fails('echo 0x1X', 'E15:')
77bcb5055fec patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents: 15172
diff changeset
531 call assert_fails('echo 011X', 'E15:')
77bcb5055fec patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents: 15172
diff changeset
532 call assert_equal(2, str2nr('2a'))
77bcb5055fec patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents: 15172
diff changeset
533 call assert_fails('inoremap <Char-0b1z> b', 'E474:')
77bcb5055fec patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents: 15172
diff changeset
534 endfunc
19415
90e24240904b patch 8.2.0265: "eval" after "if 0" doesn't check for following command
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
535
90e24240904b patch 8.2.0265: "eval" after "if 0" doesn't check for following command
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
536 func Test_eval_after_if()
90e24240904b patch 8.2.0265: "eval" after "if 0" doesn't check for following command
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
537 let s:val = ''
90e24240904b patch 8.2.0265: "eval" after "if 0" doesn't check for following command
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
538 func SetVal(x)
90e24240904b patch 8.2.0265: "eval" after "if 0" doesn't check for following command
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
539 let s:val ..= a:x
90e24240904b patch 8.2.0265: "eval" after "if 0" doesn't check for following command
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
540 endfunc
90e24240904b patch 8.2.0265: "eval" after "if 0" doesn't check for following command
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
541 if 0 | eval SetVal('a') | endif | call SetVal('b')
90e24240904b patch 8.2.0265: "eval" after "if 0" doesn't check for following command
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
542 call assert_equal('b', s:val)
90e24240904b patch 8.2.0265: "eval" after "if 0" doesn't check for following command
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
543 endfunc
19724
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
544
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
545 " Test for command-line completion of expressions
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
546 func Test_expr_completion()
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
547 if !has('cmdline_compl')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
548 return
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
549 endif
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
550 for cmd in [
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
551 \ 'let a = ',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
552 \ 'const a = ',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
553 \ 'if',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
554 \ 'elseif',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
555 \ 'while',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
556 \ 'for',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
557 \ 'echo',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
558 \ 'echon',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
559 \ 'execute',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
560 \ 'echomsg',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
561 \ 'echoerr',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
562 \ 'call',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
563 \ 'return',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
564 \ 'cexpr',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
565 \ 'caddexpr',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
566 \ 'cgetexpr',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
567 \ 'lexpr',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
568 \ 'laddexpr',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
569 \ 'lgetexpr']
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
570 call feedkeys(":" . cmd . " getl\<Tab>\<Home>\"\<CR>", 'xt')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
571 call assert_equal('"' . cmd . ' getline(', getreg(':'))
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
572 endfor
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
573
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
574 " completion for the expression register
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
575 call feedkeys(":\"\<C-R>=float2\t\"\<C-B>\"\<CR>", 'xt')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
576 call assert_equal('"float2nr("', @=)
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
577
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
578 " completion for window local variables
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
579 let w:wvar1 = 10
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
580 let w:wvar2 = 10
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
581 call feedkeys(":echo w:wvar\<C-A>\<C-B>\"\<CR>", 'xt')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
582 call assert_equal('"echo w:wvar1 w:wvar2', @:)
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
583 unlet w:wvar1 w:wvar2
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
584
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
585 " completion for tab local variables
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
586 let t:tvar1 = 10
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
587 let t:tvar2 = 10
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
588 call feedkeys(":echo t:tvar\<C-A>\<C-B>\"\<CR>", 'xt')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
589 call assert_equal('"echo t:tvar1 t:tvar2', @:)
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
590 unlet t:tvar1 t:tvar2
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
591
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
592 " completion for variables
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
593 let g:tvar1 = 1
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
594 let g:tvar2 = 2
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
595 call feedkeys(":let g:tv\<C-A>\<C-B>\"\<CR>", 'xt')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
596 call assert_equal('"let g:tvar1 g:tvar2', @:)
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
597 " completion for variables after a ||
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
598 call feedkeys(":echo 1 || g:tv\<C-A>\<C-B>\"\<CR>", 'xt')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
599 call assert_equal('"echo 1 || g:tvar1 g:tvar2', @:)
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
600
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
601 " completion for options
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
602 call feedkeys(":echo &compat\<C-A>\<C-B>\"\<CR>", 'xt')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
603 call assert_equal('"echo &compatible', @:)
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
604 call feedkeys(":echo 1 && &compat\<C-A>\<C-B>\"\<CR>", 'xt')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
605 call assert_equal('"echo 1 && &compatible', @:)
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
606 call feedkeys(":echo &g:equala\<C-A>\<C-B>\"\<CR>", 'xt')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
607 call assert_equal('"echo &g:equalalways', @:)
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
608
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
609 " completion for string
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
610 call feedkeys(":echo \"Hello\\ World\"\<C-A>\<C-B>\"\<CR>", 'xt')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
611 call assert_equal("\"echo \"Hello\\ World\"\<C-A>", @:)
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
612 call feedkeys(":echo 'Hello World'\<C-A>\<C-B>\"\<CR>", 'xt')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
613 call assert_equal("\"echo 'Hello World'\<C-A>", @:)
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
614
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
615 " completion for command after a |
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
616 call feedkeys(":echo 'Hello' | cwin\<C-A>\<C-B>\"\<CR>", 'xt')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
617 call assert_equal("\"echo 'Hello' | cwindow", @:)
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
618
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
619 " completion for environment variable
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
620 let $X_VIM_TEST_COMPLETE_ENV = 'foo'
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
621 call feedkeys(":let $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
622 call assert_match('"let $X_VIM_TEST_COMPLETE_ENV', @:)
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
623 unlet $X_VIM_TEST_COMPLETE_ENV
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
624 endfunc
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
625
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
626 " Test for errors in expression evaluation
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
627 func Test_expr_eval_error()
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
628 call assert_fails("let i = 'abc' . []", 'E730:')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
629 call assert_fails("let l = [] + 10", 'E745:')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
630 call assert_fails("let v = 10 + []", 'E745:')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
631 call assert_fails("let v = 10 / []", 'E745:')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
632 call assert_fails("let v = -{}", 'E728:')
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
633 endfunc
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
634
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
635 " vim: shiftwidth=2 sts=2 expandtab