annotate src/testdir/test_expr.vim @ 9984:9c893592f9e6 v7.4.2265

commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c Author: Bram Moolenaar <Bram@vim.org> Date: Sat Aug 27 14:21:21 2016 +0200 patch 7.4.2265 Problem: printf() isn't tested much. Solution: Add more tests for printf(). (Dominique Pelle)
author Christian Brabandt <cb@256bit.org>
date Sat, 27 Aug 2016 14:30:05 +0200
parents 935e13935848
children 9bef7b5d02cb
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))
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
56 call assert_equal(char2nr('x'), strgetchar('axb', 1))
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))
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
62 endfunc
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
63
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
64 func Test_strcharpart()
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
65 call assert_equal('a', strcharpart('axb', 0, 1))
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
66 call assert_equal('x', strcharpart('axb', 1, 1))
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
67 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
68 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
69
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
70 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
71 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
72 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
73 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
74
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
75 call assert_equal('a', strcharpart('axb', -1, 2))
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
76 endfunc
8939
36cb3aff8c1c commit https://github.com/vim/vim/commit/517ffbee0d5b7b46320726faaa330b61f54e867c
Christian Brabandt <cb@256bit.org>
parents: 8895
diff changeset
77
36cb3aff8c1c commit https://github.com/vim/vim/commit/517ffbee0d5b7b46320726faaa330b61f54e867c
Christian Brabandt <cb@256bit.org>
parents: 8895
diff changeset
78 func Test_getreg_empty_list()
36cb3aff8c1c commit https://github.com/vim/vim/commit/517ffbee0d5b7b46320726faaa330b61f54e867c
Christian Brabandt <cb@256bit.org>
parents: 8895
diff changeset
79 call assert_equal('', getreg('x'))
36cb3aff8c1c commit https://github.com/vim/vim/commit/517ffbee0d5b7b46320726faaa330b61f54e867c
Christian Brabandt <cb@256bit.org>
parents: 8895
diff changeset
80 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
81 let x = getreg('x', 1, 1)
36cb3aff8c1c commit https://github.com/vim/vim/commit/517ffbee0d5b7b46320726faaa330b61f54e867c
Christian Brabandt <cb@256bit.org>
parents: 8895
diff changeset
82 let y = x
36cb3aff8c1c commit https://github.com/vim/vim/commit/517ffbee0d5b7b46320726faaa330b61f54e867c
Christian Brabandt <cb@256bit.org>
parents: 8895
diff changeset
83 call add(x, 'foo')
36cb3aff8c1c commit https://github.com/vim/vim/commit/517ffbee0d5b7b46320726faaa330b61f54e867c
Christian Brabandt <cb@256bit.org>
parents: 8895
diff changeset
84 call assert_equal(['foo'], y)
36cb3aff8c1c commit https://github.com/vim/vim/commit/517ffbee0d5b7b46320726faaa330b61f54e867c
Christian Brabandt <cb@256bit.org>
parents: 8895
diff changeset
85 endfunc
9062
0aa90b84118c commit https://github.com/vim/vim/commit/d8585eded6359f1d7e1981e96ae775efd077c638
Christian Brabandt <cb@256bit.org>
parents: 8939
diff changeset
86
0aa90b84118c commit https://github.com/vim/vim/commit/d8585eded6359f1d7e1981e96ae775efd077c638
Christian Brabandt <cb@256bit.org>
parents: 8939
diff changeset
87 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
88 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
89 for i in null_list
0aa90b84118c commit https://github.com/vim/vim/commit/d8585eded6359f1d7e1981e96ae775efd077c638
Christian Brabandt <cb@256bit.org>
parents: 8939
diff changeset
90 call assert_true(0, 'should not get here')
0aa90b84118c commit https://github.com/vim/vim/commit/d8585eded6359f1d7e1981e96ae775efd077c638
Christian Brabandt <cb@256bit.org>
parents: 8939
diff changeset
91 endfor
0aa90b84118c commit https://github.com/vim/vim/commit/d8585eded6359f1d7e1981e96ae775efd077c638
Christian Brabandt <cb@256bit.org>
parents: 8939
diff changeset
92 endfunc
9127
1b41750311b6 commit https://github.com/vim/vim/commit/13ddc5c35921efa69e980284117b6db6465e019c
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
93
1b41750311b6 commit https://github.com/vim/vim/commit/13ddc5c35921efa69e980284117b6db6465e019c
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
94 func Test_compare_null_dict()
1b41750311b6 commit https://github.com/vim/vim/commit/13ddc5c35921efa69e980284117b6db6465e019c
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
95 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
96 call assert_equal({}, {})
1b41750311b6 commit https://github.com/vim/vim/commit/13ddc5c35921efa69e980284117b6db6465e019c
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
97 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
98 call assert_notequal({}, test_null_dict())
1b41750311b6 commit https://github.com/vim/vim/commit/13ddc5c35921efa69e980284117b6db6465e019c
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
99 endfunc
1b41750311b6 commit https://github.com/vim/vim/commit/13ddc5c35921efa69e980284117b6db6465e019c
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
100
1b41750311b6 commit https://github.com/vim/vim/commit/13ddc5c35921efa69e980284117b6db6465e019c
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
101 func Test_set_reg_null_list()
1b41750311b6 commit https://github.com/vim/vim/commit/13ddc5c35921efa69e980284117b6db6465e019c
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
102 call setreg('x', test_null_list())
1b41750311b6 commit https://github.com/vim/vim/commit/13ddc5c35921efa69e980284117b6db6465e019c
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
103 endfunc
9373
b88c573d8aa4 commit https://github.com/vim/vim/commit/1d90a5a5af84250e226f8a9121e771f7b72aa894
Christian Brabandt <cb@256bit.org>
parents: 9127
diff changeset
104
b88c573d8aa4 commit https://github.com/vim/vim/commit/1d90a5a5af84250e226f8a9121e771f7b72aa894
Christian Brabandt <cb@256bit.org>
parents: 9127
diff changeset
105 func Test_special_char()
b88c573d8aa4 commit https://github.com/vim/vim/commit/1d90a5a5af84250e226f8a9121e771f7b72aa894
Christian Brabandt <cb@256bit.org>
parents: 9127
diff changeset
106 " 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
107 call assert_fails('echo "\<C-">')
b88c573d8aa4 commit https://github.com/vim/vim/commit/1d90a5a5af84250e226f8a9121e771f7b72aa894
Christian Brabandt <cb@256bit.org>
parents: 9127
diff changeset
108 endfunc
9395
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
109
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
110 func Test_option_value()
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
111 " boolean
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
112 set bri
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
113 call assert_equal(1, &bri)
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
114 set nobri
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
115 call assert_equal(0, &bri)
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
116
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
117 " number
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
118 set ts=1
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
119 call assert_equal(1, &ts)
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
120 set ts=8
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
121 call assert_equal(8, &ts)
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
122
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
123 " string
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
124 exe "set cedit=\<Esc>"
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
125 call assert_equal("\<Esc>", &cedit)
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
126 set cpo=
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
127 call assert_equal("", &cpo)
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
128 set cpo=abcdefgi
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
129 call assert_equal("abcdefgi", &cpo)
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
130 set cpo&vim
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
131 endfunc
9497
d18d71ae21e5 commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents: 9395
diff changeset
132
9984
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
133 function Test_printf_misc()
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
134 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
135 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
136 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
137 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
138 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
139 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
140 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
141 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
142 if has('ebcdic')
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
143 call assert_equal('#', printf('%c', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
144 else
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
145 call assert_equal('{', printf('%c', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
146 endif
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
147 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
148 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
149
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
150 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
151 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
152 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
153 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
154 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
155 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
156
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
157 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
158 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
159 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
160
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
161 call assert_equal('123', printf('%2d', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
162 call assert_equal(' 123', printf('%5d', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
163 call assert_equal('00123', printf('%05d', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
164 call assert_equal('123 ', printf('%-5d', 123))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
165 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
166 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
167 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
168 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
169 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
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
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
172 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
173 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
174
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
175 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
176 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
177 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
178 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
179 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
180 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
181 call assert_equal('', printf('%.0s', 'abc'))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
182 call assert_equal('', printf('%.s', 'abc'))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
183 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
184 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
185 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
186 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
187 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
188 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
189
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
190 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
191 endfunc
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
192
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
193 function Test_printf_float()
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
194 if has('float')
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
195 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
196 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
197 call assert_equal('1.23', printf('%g', 1.23))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
198 call assert_equal('1.23', printf('%G', 1.23))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
199 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
200 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
201 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
202 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
203 call assert_equal('1.2', printf('%.1f', 1.23))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
204
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
205 call assert_equal('inf', printf('%f', 1.0/0.0))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
206
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
207 " This prints inf but shouldn't it print -inf instead?
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
208 call assert_match('^-\?inf$', printf('%f', -1.0/0.0))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
209
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
210 " This prints -nan but shouldn't it print nan instead?
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
211 call assert_match('^-\?nan$', printf('%f', sqrt(-1.0)))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
212 call assert_match('^-\?nan$', printf('%f', 0.0/0.0))
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
213
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
214 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
215 endif
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
216 endfunc
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
217
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
218 function Test_printf_errors()
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
219 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
220 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
221 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
222 call assert_fails('echo printf("%*d", 1)', 'E766:')
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
223 call assert_fails('echo printf("%d", 1.2)', 'E805:')
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
224 endfunc
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
225
9497
d18d71ae21e5 commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents: 9395
diff changeset
226 function Test_printf_64bit()
d18d71ae21e5 commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents: 9395
diff changeset
227 if has('num64')
d18d71ae21e5 commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents: 9395
diff changeset
228 call assert_equal("123456789012345", printf('%d', 123456789012345))
d18d71ae21e5 commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents: 9395
diff changeset
229 endif
d18d71ae21e5 commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents: 9395
diff changeset
230 endfunc
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
231
9892
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
232 function Test_printf_spec_s()
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
233 " number
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
234 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
235
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
236 " string
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
237 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
238
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
239 " float
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
240 if has('float')
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
241 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
242 endif
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
243
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
244 " list
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
245 let value = [1, 'two', ['three', 4]]
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
246 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
247
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
248 " dict
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
249 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
250 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
251
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
252 " funcref
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
253 call assert_equal('printf', printf('%s', function('printf')))
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
254
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
255 " partial
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
256 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
257 endfunc
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
258
9894
b01afb4e8f66 commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents: 9892
diff changeset
259 function Test_printf_spec_b()
b01afb4e8f66 commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents: 9892
diff changeset
260 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
261 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
262 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
263 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
264 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
265 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
266 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
267 call assert_equal("1001001100101100000001011010010", printf('%b', 1234567890))
b01afb4e8f66 commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents: 9892
diff changeset
268 if has('num64')
b01afb4e8f66 commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents: 9892
diff changeset
269 call assert_equal("11100000100100010000110000011011101111101111001", printf('%b', 123456789012345))
b01afb4e8f66 commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents: 9892
diff changeset
270 call assert_equal("1111111111111111111111111111111111111111111111111111111111111111", printf('%b', -1))
b01afb4e8f66 commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents: 9892
diff changeset
271 else
b01afb4e8f66 commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents: 9892
diff changeset
272 call assert_equal("11111111111111111111111111111111", printf('%b', -1))
b01afb4e8f66 commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents: 9892
diff changeset
273 endif
b01afb4e8f66 commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents: 9892
diff changeset
274 endfunc
b01afb4e8f66 commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents: 9892
diff changeset
275
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
276 func Test_substitute_expr()
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
277 let g:val = 'XXX'
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
278 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
279 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
280 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
281 \ '\=nr2char("0x" . submatch(1))', 'g'))
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
282 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
283 \ {-> nr2char("0x" . submatch(1))}, 'g'))
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
284
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
285 call assert_equal('231', substitute('123', '\(.\)\(.\)\(.\)',
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
286 \ {-> submatch(2) . submatch(3) . submatch(1)}, ''))
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
287
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
288 func Recurse()
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
289 return substitute('yyy', 'y*', {-> g:val}, '')
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
290 endfunc
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
291 call assert_equal('--', substitute('xxx', 'x*', {-> '-' . Recurse() . '-'}, ''))
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
292 endfunc
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
293
9923
935e13935848 commit https://github.com/vim/vim/commit/989f592f7ffcbafdc4ec35cee4dc65bd053e2077
Christian Brabandt <cb@256bit.org>
parents: 9919
diff changeset
294 func Test_invalid_submatch()
935e13935848 commit https://github.com/vim/vim/commit/989f592f7ffcbafdc4ec35cee4dc65bd053e2077
Christian Brabandt <cb@256bit.org>
parents: 9919
diff changeset
295 " 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
296 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
297 endfunc
935e13935848 commit https://github.com/vim/vim/commit/989f592f7ffcbafdc4ec35cee4dc65bd053e2077
Christian Brabandt <cb@256bit.org>
parents: 9919
diff changeset
298
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
299 func Test_substitute_expr_arg()
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
300 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
301 \ '\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)',
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
302 \ {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
303
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
304 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
305 \ '\(.\)\(.\)\(.\)\(a*\)\(n*\)\(.\)\(.\)\(.\)\(x*\)',
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
306 \ {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
307
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
308 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
309 \ '\(.\)\(.\)\(.*\)',
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
310 \ {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
311
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9589
diff changeset
312 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
313 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
314 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
315 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
316 endfunc
9717
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9626
diff changeset
317
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9626
diff changeset
318 func Test_function_with_funcref()
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9626
diff changeset
319 let s:f = function('type')
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9626
diff changeset
320 let s:fref = function(s:f)
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9626
diff changeset
321 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
322 call assert_fails("call function('s:f')", 'E700:')
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9626
diff changeset
323 endfunc
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
324
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
325 func Test_funcref()
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
326 func! One()
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
327 return 1
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
328 endfunc
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
329 let OneByName = function('One')
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
330 let OneByRef = funcref('One')
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
331 func! One()
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
332 return 2
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
333 endfunc
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
334 call assert_equal(2, OneByName())
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
335 call assert_equal(1, OneByRef())
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
336 let OneByRef = funcref('One')
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
337 call assert_equal(2, OneByRef())
9919
885e3c9c0e10 commit https://github.com/vim/vim/commit/843b884461de1c79a1d2748549776fb13fc94360
Christian Brabandt <cb@256bit.org>
parents: 9894
diff changeset
338 call assert_fails('echo funcref("{")', 'E475:')
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
339 endfunc
9770
ba98d7ce0d74 commit https://github.com/vim/vim/commit/7dc5e2e486fe0287601968e535902a41a39f65bb
Christian Brabandt <cb@256bit.org>
parents: 9723
diff changeset
340
ba98d7ce0d74 commit https://github.com/vim/vim/commit/7dc5e2e486fe0287601968e535902a41a39f65bb
Christian Brabandt <cb@256bit.org>
parents: 9723
diff changeset
341 func Test_setmatches()
ba98d7ce0d74 commit https://github.com/vim/vim/commit/7dc5e2e486fe0287601968e535902a41a39f65bb
Christian Brabandt <cb@256bit.org>
parents: 9723
diff changeset
342 hi def link 1 Comment
ba98d7ce0d74 commit https://github.com/vim/vim/commit/7dc5e2e486fe0287601968e535902a41a39f65bb
Christian Brabandt <cb@256bit.org>
parents: 9723
diff changeset
343 hi def link 2 PreProc
9772
560291211303 commit https://github.com/vim/vim/commit/7ab6defcafe017a3ad58580a3e56dab705b1ed8b
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
344 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
345 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
346 if has('conceal')
560291211303 commit https://github.com/vim/vim/commit/7ab6defcafe017a3ad58580a3e56dab705b1ed8b
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
347 let set[0]['conceal'] = 5
560291211303 commit https://github.com/vim/vim/commit/7ab6defcafe017a3ad58580a3e56dab705b1ed8b
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
348 let exp[0]['conceal'] = '5'
560291211303 commit https://github.com/vim/vim/commit/7ab6defcafe017a3ad58580a3e56dab705b1ed8b
Christian Brabandt <cb@256bit.org>
parents: 9770
diff changeset
349 endif
9770
ba98d7ce0d74 commit https://github.com/vim/vim/commit/7dc5e2e486fe0287601968e535902a41a39f65bb
Christian Brabandt <cb@256bit.org>
parents: 9723
diff changeset
350 call setmatches(set)
ba98d7ce0d74 commit https://github.com/vim/vim/commit/7dc5e2e486fe0287601968e535902a41a39f65bb
Christian Brabandt <cb@256bit.org>
parents: 9723
diff changeset
351 call assert_equal(exp, getmatches())
ba98d7ce0d74 commit https://github.com/vim/vim/commit/7dc5e2e486fe0287601968e535902a41a39f65bb
Christian Brabandt <cb@256bit.org>
parents: 9723
diff changeset
352 endfunc