annotate src/testdir/test_expr.vim @ 31942:f5675b905d89 v9.0.1303

patch 9.0.1303: Motif: scrollbar width/height wrong when maximized Commit: https://github.com/vim/vim/commit/094b8473edcc7531c942ac726dd575d95f5b622c Author: qsmodo <75080827+qsmodo@users.noreply.github.com> Date: Sat Feb 11 19:12:57 2023 +0000 patch 9.0.1303: Motif: scrollbar width/height wrong when maximized Problem: Motif: scrollbar width/height wrong when maximized. Solution: Set the width/height when creating the scrollbar. (closes https://github.com/vim/vim/issues/11946)
author Bram Moolenaar <Bram@vim.org>
date Sat, 11 Feb 2023 20:15:03 +0100
parents 360f286b5869
children b9a8d1c453e1
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
20156
49694eceaa55 patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents: 20128
diff changeset
3 source check.vim
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
4 import './vim9.vim' as v9
20156
49694eceaa55 patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents: 20128
diff changeset
5
8635
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 func Test_equal()
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 let base = {}
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 func base.method()
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 func base.other() dict
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 return 1
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 endfunc
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 let instance = copy(base)
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 call assert_true(base.method == instance.method)
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 call assert_true([base.method] == [instance.method])
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 call assert_true(base.other == instance.other)
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 call assert_true([base.other] == [instance.other])
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 call assert_false(base.method == base.other)
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 call assert_false([base.method] == [base.other])
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 call assert_false(base.method == instance.other)
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 call assert_false([base.method] == [instance.other])
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 call assert_fails('echo base.method > instance.method')
20156
49694eceaa55 patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents: 20128
diff changeset
26 call assert_equal(0, test_null_function() == function('min'))
49694eceaa55 patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents: 20128
diff changeset
27 call assert_equal(1, test_null_function() == test_null_function())
20158
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
28 call assert_fails('eval 10 == test_unknown()', 'E685:')
8635
3a38d465f731 commit https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 endfunc
8742
03e5171c23e5 commit https://github.com/vim/vim/commit/819821c5a95fc60797ecbb5e5ca1302e397e3d9a
Christian Brabandt <cb@256bit.org>
parents: 8635
diff changeset
30
03e5171c23e5 commit https://github.com/vim/vim/commit/819821c5a95fc60797ecbb5e5ca1302e397e3d9a
Christian Brabandt <cb@256bit.org>
parents: 8635
diff changeset
31 func Test_version()
03e5171c23e5 commit https://github.com/vim/vim/commit/819821c5a95fc60797ecbb5e5ca1302e397e3d9a
Christian Brabandt <cb@256bit.org>
parents: 8635
diff changeset
32 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
33 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
34 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
35 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
36 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
37 call assert_true(has('patch-7.4.123'))
30986
360f286b5869 patch 9.0.0828: various typos
Bram Moolenaar <Bram@vim.org>
parents: 30940
diff changeset
38 call assert_true(has('patch-7.4.123 ')) " Trailing space can be allowed.
8742
03e5171c23e5 commit https://github.com/vim/vim/commit/819821c5a95fc60797ecbb5e5ca1302e397e3d9a
Christian Brabandt <cb@256bit.org>
parents: 8635
diff changeset
39
03e5171c23e5 commit https://github.com/vim/vim/commit/819821c5a95fc60797ecbb5e5ca1302e397e3d9a
Christian Brabandt <cb@256bit.org>
parents: 8635
diff changeset
40 call assert_false(has('patch-7'))
03e5171c23e5 commit https://github.com/vim/vim/commit/819821c5a95fc60797ecbb5e5ca1302e397e3d9a
Christian Brabandt <cb@256bit.org>
parents: 8635
diff changeset
41 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
42 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
43 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
44 call assert_false(has('patch-9.9.1'))
29544
80b4c435450a patch 9.0.0113: has() is not strict about parsing the patch version
Bram Moolenaar <Bram@vim.org>
parents: 29430
diff changeset
45
29430
90565e49a13e patch 9.0.0057: has('patch-xxx') returns true
Bram Moolenaar <Bram@vim.org>
parents: 28964
diff changeset
46 call assert_false(has('patch-abc'))
29544
80b4c435450a patch 9.0.0113: has() is not strict about parsing the patch version
Bram Moolenaar <Bram@vim.org>
parents: 29430
diff changeset
47 call assert_false(has('patchabc'))
80b4c435450a patch 9.0.0113: has() is not strict about parsing the patch version
Bram Moolenaar <Bram@vim.org>
parents: 29430
diff changeset
48
80b4c435450a patch 9.0.0113: has() is not strict about parsing the patch version
Bram Moolenaar <Bram@vim.org>
parents: 29430
diff changeset
49 call assert_false(has('patch-8x001'))
80b4c435450a patch 9.0.0113: has() is not strict about parsing the patch version
Bram Moolenaar <Bram@vim.org>
parents: 29430
diff changeset
50 call assert_false(has('patch-9X0X0'))
80b4c435450a patch 9.0.0113: has() is not strict about parsing the patch version
Bram Moolenaar <Bram@vim.org>
parents: 29430
diff changeset
51 call assert_false(has('patch-9-0-0'))
80b4c435450a patch 9.0.0113: has() is not strict about parsing the patch version
Bram Moolenaar <Bram@vim.org>
parents: 29430
diff changeset
52 call assert_false(has('patch-09.0.0'))
80b4c435450a patch 9.0.0113: has() is not strict about parsing the patch version
Bram Moolenaar <Bram@vim.org>
parents: 29430
diff changeset
53 call assert_false(has('patch-9.00.0'))
8742
03e5171c23e5 commit https://github.com/vim/vim/commit/819821c5a95fc60797ecbb5e5ca1302e397e3d9a
Christian Brabandt <cb@256bit.org>
parents: 8635
diff changeset
54 endfunc
8839
9fa567d13551 commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
55
27901
dd7d94b911fa patch 8.2.4476: operator name spelled wrong
Bram Moolenaar <Bram@vim.org>
parents: 27694
diff changeset
56 func Test_op_ternary()
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
57 let lines =<< trim END
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
58 call assert_equal('yes', 1 ? 'yes' : 'no')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
59 call assert_equal('no', 0 ? 'yes' : 'no')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
60
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
61 call assert_fails('echo [1] ? "yes" : "no"', 'E745:')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
62 call assert_fails('echo {} ? "yes" : "no"', 'E728:')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
63 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
64 call v9.CheckLegacyAndVim9Success(lines)
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
65
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
66 call assert_equal('no', 'x' ? 'yes' : 'no')
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
67 call v9.CheckDefAndScriptFailure(["'x' ? 'yes' : 'no'"], 'E1135:')
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
68 call assert_equal('yes', '1x' ? 'yes' : 'no')
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
69 call v9.CheckDefAndScriptFailure(["'1x' ? 'yes' : 'no'"], 'E1135:')
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
70 endfunc
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22492
diff changeset
71
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 21656
diff changeset
72 func Test_op_falsy()
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
73 let lines =<< trim END
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
74 call assert_equal(v:true, v:true ?? 456)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
75 call assert_equal(123, 123 ?? 456)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
76 call assert_equal('yes', 'yes' ?? 456)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
77 call assert_equal(0z00, 0z00 ?? 456)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
78 call assert_equal([1], [1] ?? 456)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
79 call assert_equal({'one': 1}, {'one': 1} ?? 456)
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
80 call assert_equal(0.1, 0.1 ?? 456)
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 21656
diff changeset
81
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
82 call assert_equal(456, v:false ?? 456)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
83 call assert_equal(456, 0 ?? 456)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
84 call assert_equal(456, '' ?? 456)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
85 call assert_equal(456, 0z ?? 456)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
86 call assert_equal(456, [] ?? 456)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
87 call assert_equal(456, {} ?? 456)
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
88 call assert_equal(456, 0.0 ?? 456)
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
89 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
90 call v9.CheckLegacyAndVim9Success(lines)
22492
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 21656
diff changeset
91 endfunc
0e03ef68e738 patch 8.2.1794: no falsy Coalescing operator
Bram Moolenaar <Bram@vim.org>
parents: 21656
diff changeset
92
8839
9fa567d13551 commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
93 func Test_dict()
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
94 let lines =<< trim END
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
95 VAR d = {'': 'empty', 'a': 'a', 0: 'zero'}
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
96 call assert_equal('empty', d[''])
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
97 call assert_equal('a', d['a'])
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
98 call assert_equal('zero', d[0])
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
99 call assert_true(has_key(d, ''))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
100 call assert_true(has_key(d, 'a'))
8839
9fa567d13551 commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
101
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
102 LET d[''] = 'none'
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
103 LET d['a'] = 'aaa'
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
104 call assert_equal('none', d[''])
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
105 call assert_equal('aaa', d['a'])
21622
1f2066e3975a patch 8.2.1361: error for white space after expression in assignment
Bram Moolenaar <Bram@vim.org>
parents: 21265
diff changeset
106
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
107 LET d[ 'b' ] = 'bbb'
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
108 call assert_equal('bbb', d[ 'b' ])
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
109 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
110 call v9.CheckLegacyAndVim9Success(lines)
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
111
29994
86eb4aba16c3 patch 9.0.0335: checks for Dictionary argument often give a vague error
Bram Moolenaar <Bram@vim.org>
parents: 29544
diff changeset
112 call v9.CheckLegacyAndVim9Failure(["VAR i = has_key([], 'a')"], ['E1206:', 'E1013:', 'E1206:'])
8839
9fa567d13551 commit https://github.com/vim/vim/commit/0921ecff1c5a74541bad6c073e8ade32247403d8
Christian Brabandt <cb@256bit.org>
parents: 8742
diff changeset
113 endfunc
8887
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
114
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
115 func Test_strgetchar()
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
116 let lines =<< trim END
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
117 call assert_equal(char2nr('a'), strgetchar('axb', 0))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
118 call assert_equal(char2nr('x'), 'axb'->strgetchar(1))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
119 call assert_equal(char2nr('b'), strgetchar('axb', 2))
8887
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
120
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
121 call assert_equal(-1, strgetchar('axb', -1))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
122 call assert_equal(-1, strgetchar('axb', 3))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
123 call assert_equal(-1, strgetchar('', 0))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
124 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
125 call v9.CheckLegacyAndVim9Success(lines)
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
126
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
127 call v9.CheckLegacyAndVim9Failure(["VAR c = strgetchar([], 1)"], ['E730:', 'E1013:', 'E1174:'])
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
128 call v9.CheckLegacyAndVim9Failure(["VAR c = strgetchar('axb', [])"], ['E745:', 'E1013:', 'E1210:'])
8887
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
129 endfunc
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
130
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
131 func Test_strcharpart()
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
132 let lines =<< trim END
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
133 call assert_equal('a', strcharpart('axb', 0, 1))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
134 call assert_equal('x', 'axb'->strcharpart(1, 1))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
135 call assert_equal('b', strcharpart('axb', 2, 1))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
136 call assert_equal('xb', strcharpart('axb', 1))
8887
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
137
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
138 call assert_equal('', strcharpart('axb', 1, 0))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
139 call assert_equal('', strcharpart('axb', 1, -1))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
140 call assert_equal('', strcharpart('axb', -1, 1))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
141 call assert_equal('', strcharpart('axb', -2, 2))
8887
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
142
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
143 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
144
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
145 call assert_equal('edit', "editor"[-10 : 3])
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
146 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
147 call v9.CheckLegacyAndVim9Success(lines)
8887
8bf855dea79e commit https://github.com/vim/vim/commit/58de0e2dcc1f2d251b74892a06d71a14973f3187
Christian Brabandt <cb@256bit.org>
parents: 8839
diff changeset
148 endfunc
8939
36cb3aff8c1c commit https://github.com/vim/vim/commit/517ffbee0d5b7b46320726faaa330b61f54e867c
Christian Brabandt <cb@256bit.org>
parents: 8895
diff changeset
149
36cb3aff8c1c commit https://github.com/vim/vim/commit/517ffbee0d5b7b46320726faaa330b61f54e867c
Christian Brabandt <cb@256bit.org>
parents: 8895
diff changeset
150 func Test_getreg_empty_list()
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
151 let lines =<< trim END
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
152 call assert_equal('', getreg('x'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
153 call assert_equal([], getreg('x', 1, 1))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
154 VAR x = getreg('x', 1, 1)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
155 VAR y = x
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
156 call add(x, 'foo')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
157 call assert_equal(['foo'], y)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
158 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
159 call v9.CheckLegacyAndVim9Success(lines)
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
160
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
161 call v9.CheckLegacyAndVim9Failure(['call getreg([])'], ['E730:', 'E1013:', 'E1174:'])
8939
36cb3aff8c1c commit https://github.com/vim/vim/commit/517ffbee0d5b7b46320726faaa330b61f54e867c
Christian Brabandt <cb@256bit.org>
parents: 8895
diff changeset
162 endfunc
9062
0aa90b84118c commit https://github.com/vim/vim/commit/d8585eded6359f1d7e1981e96ae775efd077c638
Christian Brabandt <cb@256bit.org>
parents: 8939
diff changeset
163
0aa90b84118c commit https://github.com/vim/vim/commit/d8585eded6359f1d7e1981e96ae775efd077c638
Christian Brabandt <cb@256bit.org>
parents: 8939
diff changeset
164 func Test_loop_over_null_list()
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
165 let lines =<< trim END
28002
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27901
diff changeset
166 VAR nulllist = test_null_list()
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27901
diff changeset
167 for i in nulllist
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
168 call assert_report('should not get here')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
169 endfor
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
170 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
171 call v9.CheckLegacyAndVim9Success(lines)
28002
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27901
diff changeset
172
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27901
diff changeset
173 let lines =<< trim END
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27901
diff changeset
174 var nulllist = null_list
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27901
diff changeset
175 for i in nulllist
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27901
diff changeset
176 call assert_report('should not get here')
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27901
diff changeset
177 endfor
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27901
diff changeset
178 END
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27901
diff changeset
179 call v9.CheckDefAndScriptSuccess(lines)
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27901
diff changeset
180
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27901
diff changeset
181 let lines =<< trim END
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27901
diff changeset
182 let nulllist = null_list
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27901
diff changeset
183 for i in nulllist
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27901
diff changeset
184 call assert_report('should not get here')
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27901
diff changeset
185 endfor
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27901
diff changeset
186 END
1012048eed26 patch 8.2.4526: Vim9: cannot set variables to a null value
Bram Moolenaar <Bram@vim.org>
parents: 27901
diff changeset
187 call v9.CheckScriptFailure(lines, 'E121: Undefined variable: null_list')
9062
0aa90b84118c commit https://github.com/vim/vim/commit/d8585eded6359f1d7e1981e96ae775efd077c638
Christian Brabandt <cb@256bit.org>
parents: 8939
diff changeset
188 endfunc
9127
1b41750311b6 commit https://github.com/vim/vim/commit/13ddc5c35921efa69e980284117b6db6465e019c
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
189
28011
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
190 func Test_compare_with_null()
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
191 let s:value = v:null
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
192 call assert_true(s:value == v:null)
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
193 let s:value = v:true
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
194 call assert_false(s:value == v:null)
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
195 let s:value = v:none
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
196 call assert_false(s:value == v:null)
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
197 let s:value = 0
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
198 call assert_true(s:value == v:null)
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
199 let s:value = 0.0
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
200 call assert_true(s:value == v:null)
28011
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
201 let s:value = ''
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
202 call assert_false(s:value == v:null)
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
203 let s:value = 0z
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
204 call assert_false(s:value == v:null)
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
205 let s:value = []
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
206 call assert_false(s:value == v:null)
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
207 let s:value = {}
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
208 call assert_false(s:value == v:null)
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
209 let s:value = function('len')
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
210 call assert_false(s:value == v:null)
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
211 if has('job')
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
212 let s:value = test_null_job()
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
213 call assert_true(s:value == v:null)
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
214 let s:value = test_null_channel()
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
215 call assert_true(s:value == v:null)
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
216 endif
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
217 unlet s:value
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
218 endfunc
d10d5cc8e657 patch 8.2.4530: making comparison with null work changes legacy behavior
Bram Moolenaar <Bram@vim.org>
parents: 28002
diff changeset
219
20158
94f05de75e9f patch 8.2.0634: crash with null partial and blob
Bram Moolenaar <Bram@vim.org>
parents: 20156
diff changeset
220 func Test_setreg_null_list()
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
221 let lines =<< trim END
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
222 call setreg('x', test_null_list())
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
223 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
224 call v9.CheckLegacyAndVim9Success(lines)
9127
1b41750311b6 commit https://github.com/vim/vim/commit/13ddc5c35921efa69e980284117b6db6465e019c
Christian Brabandt <cb@256bit.org>
parents: 9108
diff changeset
225 endfunc
9373
b88c573d8aa4 commit https://github.com/vim/vim/commit/1d90a5a5af84250e226f8a9121e771f7b72aa894
Christian Brabandt <cb@256bit.org>
parents: 9127
diff changeset
226
b88c573d8aa4 commit https://github.com/vim/vim/commit/1d90a5a5af84250e226f8a9121e771f7b72aa894
Christian Brabandt <cb@256bit.org>
parents: 9127
diff changeset
227 func Test_special_char()
b88c573d8aa4 commit https://github.com/vim/vim/commit/1d90a5a5af84250e226f8a9121e771f7b72aa894
Christian Brabandt <cb@256bit.org>
parents: 9127
diff changeset
228 " The failure is only visible using valgrind.
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
229 call v9.CheckLegacyAndVim9Failure(['echo "\<C-">'], ['E15:', 'E1004:', 'E1004:'])
9373
b88c573d8aa4 commit https://github.com/vim/vim/commit/1d90a5a5af84250e226f8a9121e771f7b72aa894
Christian Brabandt <cb@256bit.org>
parents: 9127
diff changeset
230 endfunc
9395
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
231
21032
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
232 func Test_method_with_prefix()
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
233 let lines =<< trim END
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
234 call assert_equal(TRUE, !range(5)->empty())
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
235 call assert_equal(FALSE, !-3)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
236 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
237 call v9.CheckLegacyAndVim9Success(lines)
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
238
21032
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
239 call assert_equal([0, 1, 2], --3->range())
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
240 call v9.CheckDefAndScriptFailure(['eval --3->range()'], 'E15')
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
241
21032
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
242 call assert_equal(1, !+-+0)
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
243 call v9.CheckDefAndScriptFailure(['eval !+-+0'], 'E15')
21032
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
244 endfunc
f80e822a310d patch 8.2.1067: expression "!expr->func()" does not work
Bram Moolenaar <Bram@vim.org>
parents: 20178
diff changeset
245
9395
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
246 func Test_option_value()
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
247 let lines =<< trim END
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
248 #" boolean
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
249 set bri
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
250 call assert_equal(TRUE, &bri)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
251 set nobri
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
252 call assert_equal(FALSE, &bri)
9395
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
253
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
254 #" number
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
255 set ts=1
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
256 call assert_equal(1, &ts)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
257 set ts=8
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
258 call assert_equal(8, &ts)
9395
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
259
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
260 #" string
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
261 exe "set cedit=\<Esc>"
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
262 call assert_equal("\<Esc>", &cedit)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
263 set cpo=
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
264 call assert_equal("", &cpo)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
265 set cpo=abcdefgi
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
266 call assert_equal("abcdefgi", &cpo)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
267 set cpo&vim
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
268 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
269 call v9.CheckLegacyAndVim9Success(lines)
9395
beab399e3883 commit https://github.com/vim/vim/commit/2acfbed9dbea990f129535de7ff3df360365130b
Christian Brabandt <cb@256bit.org>
parents: 9373
diff changeset
270 endfunc
9497
d18d71ae21e5 commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents: 9395
diff changeset
271
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
272 func Test_printf_misc()
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
273 let lines =<< trim END
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
274 call assert_equal('123', printf('123'))
13367
53f15c99a9fd patch 8.0.1557: printf() does not work with only one argument
Christian Brabandt <cb@256bit.org>
parents: 11183
diff changeset
275
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
276 call assert_equal('123', printf('%d', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
277 call assert_equal('123', printf('%i', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
278 call assert_equal('123', printf('%D', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
279 call assert_equal('123', printf('%U', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
280 call assert_equal('173', printf('%o', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
281 call assert_equal('173', printf('%O', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
282 call assert_equal('7b', printf('%x', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
283 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
284
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
285 call assert_equal('123', printf('%hd', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
286 call assert_equal('-123', printf('%hd', -123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
287 call assert_equal('-1', printf('%hd', 0xFFFF))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
288 call assert_equal('-1', printf('%hd', 0x1FFFFF))
15172
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
289
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
290 call assert_equal('123', printf('%hu', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
291 call assert_equal('65413', printf('%hu', -123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
292 call assert_equal('65535', printf('%hu', 0xFFFF))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
293 call assert_equal('65535', printf('%hu', 0x1FFFFF))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
294
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
295 call assert_equal('123', printf('%ld', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
296 call assert_equal('-123', printf('%ld', -123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
297 call assert_equal('65535', printf('%ld', 0xFFFF))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
298 call assert_equal('131071', printf('%ld', 0x1FFFF))
15172
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
299
27490
fb4c30606b4a patch 8.2.4273: the EBCDIC support is outdated
Bram Moolenaar <Bram@vim.org>
parents: 27457
diff changeset
300 call assert_equal('{', printf('%c', 123))
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
301 call assert_equal('abc', printf('%s', 'abc'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
302 call assert_equal('abc', printf('%S', 'abc'))
15172
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
303
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
304 call assert_equal('+123', printf('%+d', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
305 call assert_equal('-123', printf('%+d', -123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
306 call assert_equal('+123', printf('%+ d', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
307 call assert_equal(' 123', printf('% d', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
308 call assert_equal(' 123', printf('% d', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
309 call assert_equal('-123', printf('% d', -123))
9984
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
310
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
311 call assert_equal('123', printf('%2d', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
312 call assert_equal(' 123', printf('%6d', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
313 call assert_equal('000123', printf('%06d', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
314 call assert_equal('+00123', printf('%+06d', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
315 call assert_equal(' 00123', printf('% 06d', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
316 call assert_equal(' +123', printf('%+6d', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
317 call assert_equal(' 123', printf('% 6d', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
318 call assert_equal(' -123', printf('% 6d', -123))
9984
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
319
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
320 #" Test left adjusted.
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
321 call assert_equal('123 ', printf('%-6d', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
322 call assert_equal('+123 ', printf('%-+6d', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
323 call assert_equal(' 123 ', printf('%- 6d', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
324 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
325
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
326 call assert_equal(' 00123', printf('%7.5d', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
327 call assert_equal(' -00123', printf('%7.5d', -123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
328 call assert_equal(' +00123', printf('%+7.5d', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
329
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
330 #" Precision field should not be used when combined with %0
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
331 call assert_equal(' 00123', printf('%07.5d', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
332 call assert_equal(' -00123', printf('%07.5d', -123))
10015
5ac2dd61ca8f commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents: 9986
diff changeset
333
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
334 call assert_equal(' 123', printf('%*d', 5, 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
335 call assert_equal('123 ', printf('%*d', -5, 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
336 call assert_equal('00123', printf('%.*d', 5, 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
337 call assert_equal(' 123', printf('% *d', 5, 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
338 call assert_equal(' +123', printf('%+ *d', 5, 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
339
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
340 call assert_equal('foobar', printf('%.*s', 9, 'foobar'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
341 call assert_equal('foo', printf('%.*s', 3, 'foobar'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
342 call assert_equal('', printf('%.*s', 0, 'foobar'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
343 call assert_equal('foobar', printf('%.*s', -1, 'foobar'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
344
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
345 #" Simple quote (thousand grouping char) is ignored.
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
346 call assert_equal('+00123456', printf("%+'09d", 123456))
10038
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
347
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
348 #" Unrecognized format specifier kept as-is.
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
349 call assert_equal('_123', printf("%_%d", 123))
9984
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
350
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
351 #" Test alternate forms.
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
352 call assert_equal('0x7b', printf('%#x', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
353 call assert_equal('0X7B', printf('%#X', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
354 call assert_equal('0173', printf('%#o', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
355 call assert_equal('0173', printf('%#O', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
356 call assert_equal('abc', printf('%#s', 'abc'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
357 call assert_equal('abc', printf('%#S', 'abc'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
358 call assert_equal(' 0173', printf('%#6o', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
359 call assert_equal(' 00173', printf('%#6.5o', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
360 call assert_equal(' 0173', printf('%#6.2o', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
361 call assert_equal(' 0173', printf('%#6.2o', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
362 call assert_equal('0173', printf('%#2.2o', 123))
10038
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
363
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
364 call assert_equal(' 00123', printf('%6.5d', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
365 call assert_equal(' 0007b', printf('%6.5x', 123))
9984
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
366
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
367 call assert_equal('123', printf('%.2d', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
368 call assert_equal('0123', printf('%.4d', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
369 call assert_equal('0000000123', printf('%.10d', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
370 call assert_equal('123', printf('%.0d', 123))
15172
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
371
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
372 call assert_equal('abc', printf('%2s', 'abc'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
373 call assert_equal('abc', printf('%2S', 'abc'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
374 call assert_equal('abc', printf('%.4s', 'abc'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
375 call assert_equal('abc', printf('%.4S', 'abc'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
376 call assert_equal('ab', printf('%.2s', 'abc'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
377 call assert_equal('ab', printf('%.2S', 'abc'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
378 call assert_equal('', printf('%.0s', 'abc'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
379 call assert_equal('', printf('%.s', 'abc'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
380 call assert_equal(' abc', printf('%4s', 'abc'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
381 call assert_equal(' abc', printf('%4S', 'abc'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
382 call assert_equal('0abc', printf('%04s', 'abc'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
383 call assert_equal('0abc', printf('%04S', 'abc'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
384 call assert_equal('abc ', printf('%-4s', 'abc'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
385 call assert_equal('abc ', printf('%-4S', 'abc'))
9984
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
386
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
387 call assert_equal('🐍', printf('%.2S', '🐍🐍'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
388 call assert_equal('', printf('%.1S', '🐍🐍'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
389
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
390 call assert_equal('[ あいう]', printf('[%10.6S]', 'あいうえお'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
391 call assert_equal('[ あいうえ]', printf('[%10.8S]', 'あいうえお'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
392 call assert_equal('[あいうえお]', printf('[%10.10S]', 'あいうえお'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
393 call assert_equal('[あいうえお]', printf('[%10.12S]', 'あいうえお'))
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
394
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
395 call assert_equal('あいう', printf('%S', 'あいう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
396 call assert_equal('あいう', printf('%#S', 'あいう'))
26197
2093cc976da8 patch 8.2.3630: printf() with %S does not handle multi-byte correctly
Bram Moolenaar <Bram@vim.org>
parents: 25688
diff changeset
397
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
398 call assert_equal('あb', printf('%2S', 'あb'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
399 call assert_equal('あb', printf('%.4S', 'あb'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
400 call assert_equal('あ', printf('%.2S', 'あb'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
401 call assert_equal(' あb', printf('%4S', 'あb'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
402 call assert_equal('0あb', printf('%04S', 'あb'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
403 call assert_equal('あb ', printf('%-4S', 'あb'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
404 call assert_equal('あ ', printf('%-4.2S', 'あb'))
26264
ce6490cd6282 patch 8.2.3663: using %S in printf() does not work correctly
Bram Moolenaar <Bram@vim.org>
parents: 26197
diff changeset
405
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
406 call assert_equal('aい', printf('%2S', 'aい'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
407 call assert_equal('aい', printf('%.4S', 'aい'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
408 call assert_equal('a', printf('%.2S', 'aい'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
409 call assert_equal(' aい', printf('%4S', 'aい'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
410 call assert_equal('0aい', printf('%04S', 'aい'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
411 call assert_equal('aい ', printf('%-4S', 'aい'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
412 call assert_equal('a ', printf('%-4.2S', 'aい'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
413
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
414 call assert_equal('[あいう]', printf('[%05S]', 'あいう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
415 call assert_equal('[あいう]', printf('[%06S]', 'あいう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
416 call assert_equal('[0あいう]', printf('[%07S]', 'あいう'))
26264
ce6490cd6282 patch 8.2.3663: using %S in printf() does not work correctly
Bram Moolenaar <Bram@vim.org>
parents: 26197
diff changeset
417
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
418 call assert_equal('[あiう]', printf('[%05S]', 'あiう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
419 call assert_equal('[0あiう]', printf('[%06S]', 'あiう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
420 call assert_equal('[00あiう]', printf('[%07S]', 'あiう'))
26264
ce6490cd6282 patch 8.2.3663: using %S in printf() does not work correctly
Bram Moolenaar <Bram@vim.org>
parents: 26197
diff changeset
421
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
422 call assert_equal('[0あい]', printf('[%05.4S]', 'あいう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
423 call assert_equal('[00あい]', printf('[%06.4S]', 'あいう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
424 call assert_equal('[000あい]', printf('[%07.4S]', 'あいう'))
26264
ce6490cd6282 patch 8.2.3663: using %S in printf() does not work correctly
Bram Moolenaar <Bram@vim.org>
parents: 26197
diff changeset
425
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
426 call assert_equal('[00あi]', printf('[%05.4S]', 'あiう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
427 call assert_equal('[000あi]', printf('[%06.4S]', 'あiう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
428 call assert_equal('[0000あi]', printf('[%07.4S]', 'あiう'))
26264
ce6490cd6282 patch 8.2.3663: using %S in printf() does not work correctly
Bram Moolenaar <Bram@vim.org>
parents: 26197
diff changeset
429
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
430 call assert_equal('[0あい]', printf('[%05.5S]', 'あいう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
431 call assert_equal('[00あい]', printf('[%06.5S]', 'あいう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
432 call assert_equal('[000あい]', printf('[%07.5S]', 'あいう'))
26264
ce6490cd6282 patch 8.2.3663: using %S in printf() does not work correctly
Bram Moolenaar <Bram@vim.org>
parents: 26197
diff changeset
433
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
434 call assert_equal('[あiう]', printf('[%05.5S]', 'あiう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
435 call assert_equal('[0あiう]', printf('[%06.5S]', 'あiう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
436 call assert_equal('[00あiう]', printf('[%07.5S]', 'あiう'))
26264
ce6490cd6282 patch 8.2.3663: using %S in printf() does not work correctly
Bram Moolenaar <Bram@vim.org>
parents: 26197
diff changeset
437
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
438 call assert_equal('[0000000000]', printf('[%010.0S]', 'あいう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
439 call assert_equal('[0000000000]', printf('[%010.1S]', 'あいう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
440 call assert_equal('[00000000あ]', printf('[%010.2S]', 'あいう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
441 call assert_equal('[00000000あ]', printf('[%010.3S]', 'あいう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
442 call assert_equal('[000000あい]', printf('[%010.4S]', 'あいう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
443 call assert_equal('[000000あい]', printf('[%010.5S]', 'あいう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
444 call assert_equal('[0000あいう]', printf('[%010.6S]', 'あいう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
445 call assert_equal('[0000あいう]', printf('[%010.7S]', 'あいう'))
26264
ce6490cd6282 patch 8.2.3663: using %S in printf() does not work correctly
Bram Moolenaar <Bram@vim.org>
parents: 26197
diff changeset
446
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
447 call assert_equal('[0000000000]', printf('[%010.1S]', 'あiう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
448 call assert_equal('[00000000あ]', printf('[%010.2S]', 'あiう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
449 call assert_equal('[0000000あi]', printf('[%010.3S]', 'あiう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
450 call assert_equal('[0000000あi]', printf('[%010.4S]', 'あiう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
451 call assert_equal('[00000あiう]', printf('[%010.5S]', 'あiう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
452 call assert_equal('[00000あiう]', printf('[%010.6S]', 'あiう'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
453 call assert_equal('[00000あiう]', printf('[%010.7S]', 'あiう'))
26264
ce6490cd6282 patch 8.2.3663: using %S in printf() does not work correctly
Bram Moolenaar <Bram@vim.org>
parents: 26197
diff changeset
454
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
455 call assert_equal('1%', printf('%d%%', 1))
26759
31c23760d590 patch 8.2.3908: cannot use a script-local function for 'foldtext'
Bram Moolenaar <Bram@vim.org>
parents: 26721
diff changeset
456 call assert_notequal('', printf('%p', "abc"))
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
457 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
458 call v9.CheckLegacyAndVim9Success(lines)
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
459
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
460 call v9.CheckLegacyAndVim9Failure(["call printf('123', 3)"], "E767:")
9984
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
461 endfunc
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
462
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
463 func Test_printf_float()
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
464 let lines =<< trim END
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
465 call assert_equal('1.000000', printf('%f', 1))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
466 call assert_equal('1.230000', printf('%f', 1.23))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
467 call assert_equal('1.230000', printf('%F', 1.23))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
468 call assert_equal('9999999.9', printf('%g', 9999999.9))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
469 call assert_equal('9999999.9', printf('%G', 9999999.9))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
470 call assert_equal('1.00000001e7', printf('%.8g', 10000000.1))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
471 call assert_equal('1.00000001E7', printf('%.8G', 10000000.1))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
472 call assert_equal('1.230000e+00', printf('%e', 1.23))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
473 call assert_equal('1.230000E+00', printf('%E', 1.23))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
474 call assert_equal('1.200000e-02', printf('%e', 0.012))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
475 call assert_equal('-1.200000e-02', printf('%e', -0.012))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
476 call assert_equal('0.33', printf('%.2f', 1.0 / 3.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
477 call assert_equal(' 0.33', printf('%6.2f', 1.0 / 3.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
478 call assert_equal(' -0.33', printf('%6.2f', -1.0 / 3.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
479 call assert_equal('000.33', printf('%06.2f', 1.0 / 3.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
480 call assert_equal('-00.33', printf('%06.2f', -1.0 / 3.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
481 call assert_equal('-00.33', printf('%+06.2f', -1.0 / 3.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
482 call assert_equal('+00.33', printf('%+06.2f', 1.0 / 3.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
483 call assert_equal(' 00.33', printf('% 06.2f', 1.0 / 3.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
484 call assert_equal('000.33', printf('%06.2g', 1.0 / 3.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
485 call assert_equal('-00.33', printf('%06.2g', -1.0 / 3.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
486 call assert_equal('0.33', printf('%3.2f', 1.0 / 3.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
487 call assert_equal('003.33e-01', printf('%010.2e', 1.0 / 3.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
488 call assert_equal(' 03.33e-01', printf('% 010.2e', 1.0 / 3.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
489 call assert_equal('+03.33e-01', printf('%+010.2e', 1.0 / 3.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
490 call assert_equal('-03.33e-01', printf('%010.2e', -1.0 / 3.0))
10038
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
491
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
492 #" When precision is 0, the dot should be omitted.
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
493 call assert_equal(' 2', printf('%3.f', 7.0 / 3.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
494 call assert_equal(' 2', printf('%3.g', 7.0 / 3.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
495 call assert_equal(' 2e+00', printf('%7.e', 7.0 / 3.0))
10038
7cf4e210cf3c commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents: 10015
diff changeset
496
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
497 #" Float zero can be signed.
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
498 call assert_equal('+0.000000', printf('%+f', 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
499 call assert_equal('0.000000', printf('%f', 1.0 / (1.0 / 0.0)))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
500 call assert_equal('-0.000000', printf('%f', 1.0 / (-1.0 / 0.0)))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
501 call assert_equal('0.0', printf('%s', 1.0 / (1.0 / 0.0)))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
502 call assert_equal('-0.0', printf('%s', 1.0 / (-1.0 / 0.0)))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
503 call assert_equal('0.0', printf('%S', 1.0 / (1.0 / 0.0)))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
504 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
505
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
506 #" Float infinity can be signed.
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
507 call assert_equal('inf', printf('%f', 1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
508 call assert_equal('-inf', printf('%f', -1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
509 call assert_equal('inf', printf('%g', 1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
510 call assert_equal('-inf', printf('%g', -1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
511 call assert_equal('inf', printf('%e', 1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
512 call assert_equal('-inf', printf('%e', -1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
513 call assert_equal('INF', printf('%F', 1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
514 call assert_equal('-INF', printf('%F', -1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
515 call assert_equal('INF', printf('%E', 1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
516 call assert_equal('-INF', printf('%E', -1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
517 call assert_equal('INF', printf('%E', 1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
518 call assert_equal('-INF', printf('%G', -1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
519 call assert_equal('+inf', printf('%+f', 1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
520 call assert_equal('-inf', printf('%+f', -1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
521 call assert_equal(' inf', printf('% f', 1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
522 call assert_equal(' inf', printf('%6f', 1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
523 call assert_equal(' -inf', printf('%6f', -1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
524 call assert_equal(' inf', printf('%6g', 1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
525 call assert_equal(' -inf', printf('%6g', -1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
526 call assert_equal(' +inf', printf('%+6f', 1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
527 call assert_equal(' inf', printf('% 6f', 1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
528 call assert_equal(' +inf', printf('%+06f', 1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
529 call assert_equal('inf ', printf('%-6f', 1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
530 call assert_equal('-inf ', printf('%-6f', -1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
531 call assert_equal('+inf ', printf('%-+6f', 1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
532 call assert_equal(' inf ', printf('%- 6f', 1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
533 call assert_equal('-INF ', printf('%-6F', -1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
534 call assert_equal('+INF ', printf('%-+6F', 1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
535 call assert_equal(' INF ', printf('%- 6F', 1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
536 call assert_equal('INF ', printf('%-6G', 1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
537 call assert_equal('-INF ', printf('%-6G', -1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
538 call assert_equal('INF ', printf('%-6E', 1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
539 call assert_equal('-INF ', printf('%-6E', -1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
540 call assert_equal('inf', printf('%s', 1.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
541 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
542
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
543 #" Test special case where max precision is truncated at 340.
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
544 call assert_equal('1.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', printf('%.330f', 1.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
545 call assert_equal('1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', printf('%.340f', 1.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
546 call assert_equal('1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', printf('%.350f', 1.0))
15172
de7e90fb445c patch 8.1.0596: not all parts of printf() are tested
Bram Moolenaar <Bram@vim.org>
parents: 13367
diff changeset
547
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
548 #" Float nan (not a number) has no sign.
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
549 call assert_equal('nan', printf('%f', sqrt(-1.0)))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
550 call assert_equal('nan', printf('%f', 0.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
551 call assert_equal('nan', printf('%f', -0.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
552 call assert_equal('nan', printf('%g', 0.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
553 call assert_equal('nan', printf('%e', 0.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
554 call assert_equal('NAN', printf('%F', 0.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
555 call assert_equal('NAN', printf('%G', 0.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
556 call assert_equal('NAN', printf('%E', 0.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
557 call assert_equal('NAN', printf('%F', -0.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
558 call assert_equal('NAN', printf('%G', -0.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
559 call assert_equal('NAN', printf('%E', -0.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
560 call assert_equal(' nan', printf('%6f', 0.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
561 call assert_equal(' nan', printf('%06f', 0.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
562 call assert_equal('nan ', printf('%-6f', 0.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
563 call assert_equal('nan ', printf('%- 6f', 0.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
564 call assert_equal('nan', printf('%s', 0.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
565 call assert_equal('nan', printf('%s', -0.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
566 call assert_equal('nan', printf('%S', 0.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
567 call assert_equal('nan', printf('%S', -0.0 / 0.0))
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
568 END
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
569 call v9.CheckLegacyAndVim9Success(lines)
9984
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
570
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
571 call v9.CheckLegacyAndVim9Failure(['echo printf("%f", "a")'], 'E807:')
9984
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
572 endfunc
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
573
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
574 func Test_printf_errors()
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
575 call v9.CheckLegacyAndVim9Failure(['echo printf("%d", {})'], 'E728:')
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
576 call v9.CheckLegacyAndVim9Failure(['echo printf("%d", [])'], 'E745:')
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
577 call v9.CheckLegacyAndVim9Failure(['echo printf("%d", 1, 2)'], 'E767:')
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
578 call v9.CheckLegacyAndVim9Failure(['echo printf("%*d", 1)'], 'E766:')
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
579 call v9.CheckLegacyAndVim9Failure(['echo printf("%s")'], 'E766:')
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
580 call v9.CheckLegacyAndVim9Failure(['echo printf("%d", 1.2)'], 'E805:')
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
581 call v9.CheckLegacyAndVim9Failure(['echo printf("%f")'], 'E766:')
9984
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
582 endfunc
9c893592f9e6 commit https://github.com/vim/vim/commit/76efafba2af36ae5f6c7b79b56c537fcbcdb386c
Christian Brabandt <cb@256bit.org>
parents: 9923
diff changeset
583
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
584 func Test_printf_64bit()
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
585 let lines =<< trim END
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
586 call assert_equal("123456789012345", printf('%d', 123456789012345))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
587 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
588 call v9.CheckLegacyAndVim9Success(lines)
9497
d18d71ae21e5 commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents: 9395
diff changeset
589 endfunc
9589
bf204ab1ce7d commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Christian Brabandt <cb@256bit.org>
parents: 9497
diff changeset
590
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
591 func Test_printf_spec_s()
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
592 let lines =<< trim END
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
593 #" number
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
594 call assert_equal("1234567890", printf('%s', 1234567890))
9892
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
595
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
596 #" string
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
597 call assert_equal("abcdefgi", printf('%s', "abcdefgi"))
9892
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
598
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
599 #" float
30310
029c59bf78f1 patch 9.0.0491: no good reason to build without the float feature
Bram Moolenaar <Bram@vim.org>
parents: 29994
diff changeset
600 call assert_equal("1.23", printf('%s', 1.23))
9892
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
601
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
602 #" list
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
603 VAR lvalue = [1, 'two', ['three', 4]]
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
604 call assert_equal(string(lvalue), printf('%s', lvalue))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
605
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
606 #" dict
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
607 VAR dvalue = {'key1': 'value1', 'key2': ['list', 'lvalue'], 'key3': {'dict': 'lvalue'}}
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
608 call assert_equal(string(dvalue), printf('%s', dvalue))
9892
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
609
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
610 #" funcref
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
611 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
612
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
613 #" partial
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
614 call assert_equal(string(function('printf', ['%s'])), printf('%s', function('printf', ['%s'])))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
615 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
616 call v9.CheckLegacyAndVim9Success(lines)
9892
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
617 endfunc
41c5d59e7e10 commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents: 9772
diff changeset
618
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
619 func Test_printf_spec_b()
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
620 let lines =<< trim END
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
621 call assert_equal("0", printf('%b', 0))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
622 call assert_equal("00001100", printf('%08b', 12))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
623 call assert_equal("11111111", printf('%08b', 0xff))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
624 call assert_equal(" 1111011", printf('%10b', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
625 call assert_equal("0001111011", printf('%010b', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
626 call assert_equal(" 0b1111011", printf('%#10b', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
627 call assert_equal("0B01111011", printf('%#010B', 123))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
628 call assert_equal("1001001100101100000001011010010", printf('%b', 1234567890))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
629 call assert_equal("11100000100100010000110000011011101111101111001", printf('%b', 123456789012345))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
630 call assert_equal("1111111111111111111111111111111111111111111111111111111111111111", printf('%b', -1))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
631 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
632 call v9.CheckLegacyAndVim9Success(lines)
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
633 endfunc
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
634
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
635 func Test_max_min_errors()
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
636 call v9.CheckLegacyAndVim9Failure(['call max(v:true)'], ['E712:', 'E1013:', 'E1227:'])
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
637 call v9.CheckLegacyAndVim9Failure(['call max(v:true)'], ['max()', 'E1013:', 'E1227:'])
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
638 call v9.CheckLegacyAndVim9Failure(['call min(v:true)'], ['E712:', 'E1013:', 'E1227:'])
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
639 call v9.CheckLegacyAndVim9Failure(['call min(v:true)'], ['min()', 'E1013:', 'E1227:'])
9894
b01afb4e8f66 commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents: 9892
diff changeset
640 endfunc
b01afb4e8f66 commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents: 9892
diff changeset
641
9717
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9626
diff changeset
642 func Test_function_with_funcref()
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
643 let lines =<< trim END
27694
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
644 let s:F = function('type')
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
645 let s:Fref = function(s:F)
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
646 call assert_equal(v:t_string, s:Fref('x'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
647 call assert_fails("call function('s:F')", 'E700:')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
648
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
649 call assert_fails("call function('foo()')", 'E475:')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
650 call assert_fails("call function('foo()')", 'foo()')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
651 call assert_fails("function('')", 'E129:')
10207
9415453b7bbd commit https://github.com/vim/vim/commit/5582ef14384525e8cec86016876d97a6b32dd548
Christian Brabandt <cb@256bit.org>
parents: 10116
diff changeset
652
27694
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
653 let s:Len = {s -> strlen(s)}
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
654 call assert_equal(6, s:Len('foobar'))
27694
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
655 let name = string(s:Len)
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
656 " can evaluate "function('<lambda>99')"
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
657 call execute('let Ref = ' .. name)
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
658 call assert_equal(4, Ref('text'))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
659 END
27694
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
660 call v9.CheckScriptSuccess(lines)
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
661
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
662 let lines =<< trim END
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
663 vim9script
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
664 var F = function('type')
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
665 var Fref = function(F)
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
666 call assert_equal(v:t_string, Fref('x'))
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
667 call assert_fails("call function('F')", 'E700:')
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
668
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
669 call assert_fails("call function('foo()')", 'E475:')
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
670 call assert_fails("call function('foo()')", 'foo()')
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
671 call assert_fails("function('')", 'E129:')
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
672
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
673 var Len = (s) => strlen(s)
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
674 call assert_equal(6, Len('foobar'))
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
675 var name = string(Len)
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
676 # can evaluate "function('<lambda>99')"
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
677 call execute('var Ref = ' .. name)
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
678 call assert_equal(4, Ref('text'))
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
679 END
4af6dc1cc1c8 patch 8.2.4373: expression test fails
Bram Moolenaar <Bram@vim.org>
parents: 27671
diff changeset
680 call v9.CheckScriptSuccess(lines)
9717
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9626
diff changeset
681 endfunc
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
682
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
683 func Test_funcref()
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
684 func! One()
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
685 return 1
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
686 endfunc
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
687 let OneByName = function('One')
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
688 let OneByRef = funcref('One')
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
689 func! One()
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
690 return 2
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
691 endfunc
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
692 call assert_equal(2, OneByName())
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
693 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
694 let OneByRef = 'One'->funcref()
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
695 call assert_equal(2, OneByRef())
9919
885e3c9c0e10 commit https://github.com/vim/vim/commit/843b884461de1c79a1d2748549776fb13fc94360
Christian Brabandt <cb@256bit.org>
parents: 9894
diff changeset
696 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
697 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
698 call assert_fails('let OneByRef = funcref("One", repeat(["foo"], 21))', 'E118:')
19932
2c4d9ca33769 patch 8.2.0522: several errors are not tested for
Bram Moolenaar <Bram@vim.org>
parents: 19783
diff changeset
699 call assert_fails('echo function("min") =~ function("min")', 'E694:')
25688
c07b6c54146a patch 8.2.3380: crash when using NULL string for funcref()
Bram Moolenaar <Bram@vim.org>
parents: 24695
diff changeset
700 call assert_fails('echo test_null_function()->funcref()', 'E475: Invalid argument: NULL')
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
701 endfunc
9770
ba98d7ce0d74 commit https://github.com/vim/vim/commit/7dc5e2e486fe0287601968e535902a41a39f65bb
Christian Brabandt <cb@256bit.org>
parents: 9723
diff changeset
702
26721
9c9b8d95b05f patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents: 26654
diff changeset
703 " Test for calling function() and funcref() outside of a Vim script context.
9c9b8d95b05f patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents: 26654
diff changeset
704 func Test_function_outside_script()
9c9b8d95b05f patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents: 26654
diff changeset
705 let cleanup =<< trim END
9c9b8d95b05f patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents: 26654
diff changeset
706 call writefile([execute('messages')], 'Xtest.out')
9c9b8d95b05f patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents: 26654
diff changeset
707 qall
9c9b8d95b05f patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents: 26654
diff changeset
708 END
30405
ea38db8639eb patch 9.0.0538: manually deleting test temp files
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
709 call writefile(cleanup, 'Xverify.vim', 'D')
26721
9c9b8d95b05f patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents: 26654
diff changeset
710 call RunVim([], [], "-c \"echo function('s:abc')\" -S Xverify.vim")
9c9b8d95b05f patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents: 26654
diff changeset
711 call assert_match('E81: Using <SID> not in a', readfile('Xtest.out')[0])
9c9b8d95b05f patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents: 26654
diff changeset
712 call RunVim([], [], "-c \"echo funcref('s:abc')\" -S Xverify.vim")
9c9b8d95b05f patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents: 26654
diff changeset
713 call assert_match('E81: Using <SID> not in a', readfile('Xtest.out')[0])
9c9b8d95b05f patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents: 26654
diff changeset
714 call delete('Xtest.out')
9c9b8d95b05f patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents: 26654
diff changeset
715 endfunc
9c9b8d95b05f patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents: 26654
diff changeset
716
9770
ba98d7ce0d74 commit https://github.com/vim/vim/commit/7dc5e2e486fe0287601968e535902a41a39f65bb
Christian Brabandt <cb@256bit.org>
parents: 9723
diff changeset
717 func Test_setmatches()
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
718 let lines =<< trim END
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
719 hi def link 1 Comment
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
720 hi def link 2 PreProc
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
721 VAR set = [{"group": 1, "pattern": 2, "id": 3, "priority": 4}]
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
722 VAR exp = [{"group": '1', "pattern": '2', "id": 3, "priority": 4}]
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
723 if has('conceal')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
724 LET set[0]['conceal'] = 5
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
725 LET exp[0]['conceal'] = '5'
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
726 endif
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
727 eval set->setmatches()
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
728 call assert_equal(exp, getmatches())
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
729 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
730 call v9.CheckLegacyAndVim9Success(lines)
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
731
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
732 call v9.CheckLegacyAndVim9Failure(['VAR m = setmatches([], [])'], ['E745:', 'E1013:', 'E1210:'])
9770
ba98d7ce0d74 commit https://github.com/vim/vim/commit/7dc5e2e486fe0287601968e535902a41a39f65bb
Christian Brabandt <cb@256bit.org>
parents: 9723
diff changeset
733 endfunc
10924
053d4ad16f37 patch 8.0.0351: no test for concatenating an empty string
Christian Brabandt <cb@256bit.org>
parents: 10245
diff changeset
734
053d4ad16f37 patch 8.0.0351: no test for concatenating an empty string
Christian Brabandt <cb@256bit.org>
parents: 10245
diff changeset
735 func Test_empty_concatenate()
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
736 let lines =<< trim END
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
737 call assert_equal('b', 'a'[4 : 0] .. 'b')
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
738 call assert_equal('b', 'b' .. 'a'[4 : 0])
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
739 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
740 call v9.CheckLegacyAndVim9Success(lines)
10924
053d4ad16f37 patch 8.0.0351: no test for concatenating an empty string
Christian Brabandt <cb@256bit.org>
parents: 10245
diff changeset
741 endfunc
16706
77bcb5055fec patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents: 15172
diff changeset
742
77bcb5055fec patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents: 15172
diff changeset
743 func Test_broken_number()
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
744 call v9.CheckLegacyAndVim9Failure(['VAR X = "bad"', 'echo 1X'], 'E15:')
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
745 call v9.CheckLegacyAndVim9Failure(['VAR X = "bad"', 'echo 0b1X'], 'E15:')
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
746 call v9.CheckLegacyAndVim9Failure(['echo 0b12'], 'E15:')
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
747 call v9.CheckLegacyAndVim9Failure(['VAR X = "bad"', 'echo 0x1X'], 'E15:')
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
748 call v9.CheckLegacyAndVim9Failure(['VAR X = "bad"', 'echo 011X'], 'E15:')
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
749
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
750 call v9.CheckLegacyAndVim9Success(['call assert_equal(2, str2nr("2a"))'])
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
751
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
752 call v9.CheckLegacyAndVim9Failure(['inoremap <Char-0b1z> b'], 'E474:')
16706
77bcb5055fec patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents: 15172
diff changeset
753 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
754
90e24240904b patch 8.2.0265: "eval" after "if 0" doesn't check for following command
Bram Moolenaar <Bram@vim.org>
parents: 19249
diff changeset
755 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
756 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
757 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
758 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
759 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
760 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
761 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
762 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
763
30940
5bc99d85f773 patch 9.0.0804: crash when trying to divide a number by -1
Bram Moolenaar <Bram@vim.org>
parents: 30405
diff changeset
764 func Test_divide_by_zero()
5bc99d85f773 patch 9.0.0804: crash when trying to divide a number by -1
Bram Moolenaar <Bram@vim.org>
parents: 30405
diff changeset
765 " only tests that this doesn't crash, the result is not important
5bc99d85f773 patch 9.0.0804: crash when trying to divide a number by -1
Bram Moolenaar <Bram@vim.org>
parents: 30405
diff changeset
766 echo 0 / 0
5bc99d85f773 patch 9.0.0804: crash when trying to divide a number by -1
Bram Moolenaar <Bram@vim.org>
parents: 30405
diff changeset
767 echo 0 / 0 / -1
5bc99d85f773 patch 9.0.0804: crash when trying to divide a number by -1
Bram Moolenaar <Bram@vim.org>
parents: 30405
diff changeset
768 endfunc
5bc99d85f773 patch 9.0.0804: crash when trying to divide a number by -1
Bram Moolenaar <Bram@vim.org>
parents: 30405
diff changeset
769
19724
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
770 " 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
771 func Test_expr_completion()
23027
f74978697fb6 patch 8.2.2060: check for features implemented with "if"
Bram Moolenaar <Bram@vim.org>
parents: 22500
diff changeset
772 CheckFeature cmdline_compl
19724
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
773 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
774 \ '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
775 \ '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
776 \ 'if',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
777 \ 'elseif',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
778 \ 'while',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
779 \ 'for',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
780 \ 'echo',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
781 \ 'echon',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
782 \ 'execute',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
783 \ 'echomsg',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
784 \ 'echoerr',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
785 \ 'call',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
786 \ 'return',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
787 \ 'cexpr',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
788 \ 'caddexpr',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
789 \ 'cgetexpr',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
790 \ 'lexpr',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
791 \ 'laddexpr',
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
792 \ 'lgetexpr']
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
793 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
794 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
795 endfor
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
796
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
797 " 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
798 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
799 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
800
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
801 " 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
802 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
803 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
804 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
805 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
806 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
807
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
808 " 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
809 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
810 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
811 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
812 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
813 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
814
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
815 " 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
816 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
817 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
818 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
819 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
820 " 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
821 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
822 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
823
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
824 " 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
825 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
826 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
827 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
828 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
829 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
830 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
831
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
832 " 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
833 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
834 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
835 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
836 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
837
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
838 " 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
839 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
840 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
841
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
842 " 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
843 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
844 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
845 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
846 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
847 endfunc
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
848
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
849 " 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
850 func Test_expr_eval_error()
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
851 call v9.CheckLegacyAndVim9Failure(["VAR i = 'abc' .. []"], ['E730:', 'E1105:', 'E730:'])
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
852 call v9.CheckLegacyAndVim9Failure(["VAR l = [] + 10"], ['E745:', 'E1051:', 'E745'])
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
853 call v9.CheckLegacyAndVim9Failure(["VAR v = 10 + []"], ['E745:', 'E1051:', 'E745:'])
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
854 call v9.CheckLegacyAndVim9Failure(["VAR v = 10 / []"], ['E745:', 'E1036:', 'E745:'])
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
855 call v9.CheckLegacyAndVim9Failure(["VAR v = -{}"], ['E728:', 'E1012:', 'E728:'])
19724
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
856 endfunc
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
857
21656
c3f6006bf0ba patch 8.2.1378: cannot put space between function name and paren
Bram Moolenaar <Bram@vim.org>
parents: 21622
diff changeset
858 func Test_white_in_function_call()
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
859 let lines =<< trim END
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
860 VAR text = substitute ( 'some text' , 't' , 'T' , 'g' )
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
861 call assert_equal('some TexT', text)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
862 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
863 call v9.CheckTransLegacySuccess(lines)
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
864
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
865 let lines =<< trim END
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
866 var text = substitute ( 'some text' , 't' , 'T' , 'g' )
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
867 call assert_equal('some TexT', text)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
868 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
869 call v9.CheckDefAndScriptFailure(lines, ['E1001:', 'E121:'])
21656
c3f6006bf0ba patch 8.2.1378: cannot put space between function name and paren
Bram Moolenaar <Bram@vim.org>
parents: 21622
diff changeset
870 endfunc
c3f6006bf0ba patch 8.2.1378: cannot put space between function name and paren
Bram Moolenaar <Bram@vim.org>
parents: 21622
diff changeset
871
20156
49694eceaa55 patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents: 20128
diff changeset
872 " Test for float value comparison
49694eceaa55 patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents: 20128
diff changeset
873 func Test_float_compare()
26654
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
874 let lines =<< trim END
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
875 call assert_true(1.2 == 1.2)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
876 call assert_true(1.0 != 1.2)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
877 call assert_true(1.2 > 1.0)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
878 call assert_true(1.2 >= 1.2)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
879 call assert_true(1.0 < 1.2)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
880 call assert_true(1.2 <= 1.2)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
881 call assert_true(+0.0 == -0.0)
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
882 #" two NaNs (not a number) are not equal
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
883 call assert_true(sqrt(-4.01) != (0.0 / 0.0))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
884 #" two inf (infinity) are equal
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
885 call assert_true((1.0 / 0) == (2.0 / 0))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
886 #" two -inf (infinity) are equal
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
887 call assert_true(-(1.0 / 0) == -(2.0 / 0))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
888 #" +infinity != -infinity
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
889 call assert_true((1.0 / 0) != -(2.0 / 0))
e01607ab0fab patch 8.2.3856: Vim9: not enough tests
Bram Moolenaar <Bram@vim.org>
parents: 26348
diff changeset
890 END
27457
4c16acb2525f patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 26759
diff changeset
891 call v9.CheckLegacyAndVim9Success(lines)
20156
49694eceaa55 patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents: 20128
diff changeset
892 endfunc
49694eceaa55 patch 8.2.0633: crash when using null partial in filter()
Bram Moolenaar <Bram@vim.org>
parents: 20128
diff changeset
893
28718
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
894 func Test_string_interp()
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
895 let lines =<< trim END
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
896 call assert_equal('', $"")
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
897 call assert_equal('foobar', $"foobar")
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
898 #" Escaping rules.
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
899 call assert_equal('"foo"{bar}', $"\"foo\"{{bar}}")
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
900 call assert_equal('"foo"{bar}', $'"foo"{{bar}}')
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28718
diff changeset
901 call assert_equal('foobar', $"{"foo"}" .. $'{'bar'}')
28718
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
902 #" Whitespace before/after the expression.
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
903 call assert_equal('3', $"{ 1 + 2 }")
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
904 #" String conversion.
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
905 call assert_equal('hello from ' .. v:version, $"hello from {v:version}")
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
906 call assert_equal('hello from ' .. v:version, $'hello from {v:version}')
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
907 #" Paper over a small difference between VimScript behaviour.
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
908 call assert_equal(string(v:true), $"{v:true}")
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
909 call assert_equal('(1+1=2)', $"(1+1={1 + 1})")
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
910 #" Hex-escaped opening brace: char2nr('{') == 0x7b
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28718
diff changeset
911 call assert_equal('esc123ape', $"esc{123}ape")
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28718
diff changeset
912 call assert_equal('me{}me', $"me{"\x7b"}\x7dme")
28718
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
913 VAR var1 = "sun"
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
914 VAR var2 = "shine"
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
915 call assert_equal('sunshine', $"{var1}{var2}")
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
916 call assert_equal('sunsunsun', $"{var1->repeat(3)}")
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
917 #" Multibyte strings.
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
918 call assert_equal('say ハロー・ワールド', $"say {'ハロー・ワールド'}")
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
919 #" Nested.
28813
3626ca6a20ea patch 8.2.4930: interpolated string expression requires escaping
Bram Moolenaar <Bram@vim.org>
parents: 28718
diff changeset
920 call assert_equal('foobarbaz', $"foo{$"{'bar'}"}baz")
28718
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
921 #" Do not evaluate blocks when the expr is skipped.
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
922 VAR tmp = 0
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
923 if v:false
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
924 echo "${ LET tmp += 1 }"
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
925 endif
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
926 call assert_equal(0, tmp)
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
927
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
928 #" Stray closing brace.
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
929 call assert_fails('echo $"moo}"', 'E1278:')
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
930 #" Undefined variable in expansion.
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
931 call assert_fails('echo $"{moo}"', 'E121:')
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
932 #" Empty blocks are rejected.
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
933 call assert_fails('echo $"{}"', 'E15:')
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
934 call assert_fails('echo $"{ }"', 'E15:')
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
935 END
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
936 call v9.CheckLegacyAndVim9Success(lines)
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
937
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
938 let lines =<< trim END
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
939 call assert_equal('5', $"{({x -> x + 1})(4)}")
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
940 END
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
941 call v9.CheckLegacySuccess(lines)
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
942
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
943 let lines =<< trim END
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
944 call assert_equal('5', $"{((x) => x + 1)(4)}")
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
945 call assert_fails('echo $"{ # foo }"', 'E1279:')
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
946 END
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
947 call v9.CheckDefAndScriptSuccess(lines)
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
948 endfunc
723c7d940cba patch 8.2.4883: string interpolation only works in heredoc
Bram Moolenaar <Bram@vim.org>
parents: 28011
diff changeset
949
28962
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
950 " Test for bitwise left and right shift (<< and >>)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
951 func Test_bitwise_shift()
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
952 let lines =<< trim END
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
953 call assert_equal(16, 1 << 4)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
954 call assert_equal(2, 16 >> 3)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
955 call assert_equal(0, 0 << 2)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
956 call assert_equal(0, 0 >> 4)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
957 call assert_equal(3, 3 << 0)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
958 call assert_equal(3, 3 >> 0)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
959 call assert_equal(0, 0 >> 4)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
960 call assert_equal(0, 999999 >> 100)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
961 call assert_equal(0, 999999 << 100)
28964
8973f2f00872 patch 8.2.5004: right shift on negative number does not work as documented
Bram Moolenaar <Bram@vim.org>
parents: 28962
diff changeset
962 call assert_equal(-1, -1 >> 0)
8973f2f00872 patch 8.2.5004: right shift on negative number does not work as documented
Bram Moolenaar <Bram@vim.org>
parents: 28962
diff changeset
963 call assert_equal(-1, -1 << 0)
28962
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
964 VAR a = 8
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
965 VAR b = 2
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
966 call assert_equal(2, a >> b)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
967 call assert_equal(32, a << b)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
968 #" operator precedence
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
969 call assert_equal(48, 1 + 2 << 5 - 1)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
970 call assert_equal(3, 8 + 4 >> 4 - 2)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
971 call assert_true(1 << 2 < 1 << 3)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
972 call assert_true(1 << 4 > 1 << 3)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
973 VAR val = 0
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
974 for i in range(0, v:numbersize - 2)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
975 LET val = or(val, 1 << i)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
976 endfor
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
977 call assert_equal(v:numbermax, val)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
978 LET val = v:numbermax
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
979 for i in range(0, v:numbersize - 2)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
980 LET val = and(val, invert(1 << i))
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
981 endfor
28964
8973f2f00872 patch 8.2.5004: right shift on negative number does not work as documented
Bram Moolenaar <Bram@vim.org>
parents: 28962
diff changeset
982 #" -1 has all the bits set
8973f2f00872 patch 8.2.5004: right shift on negative number does not work as documented
Bram Moolenaar <Bram@vim.org>
parents: 28962
diff changeset
983 call assert_equal(-2, -1 << 1)
8973f2f00872 patch 8.2.5004: right shift on negative number does not work as documented
Bram Moolenaar <Bram@vim.org>
parents: 28962
diff changeset
984 call assert_equal(-4, -1 << 2)
8973f2f00872 patch 8.2.5004: right shift on negative number does not work as documented
Bram Moolenaar <Bram@vim.org>
parents: 28962
diff changeset
985 call assert_equal(-8, -1 << 3)
8973f2f00872 patch 8.2.5004: right shift on negative number does not work as documented
Bram Moolenaar <Bram@vim.org>
parents: 28962
diff changeset
986 if v:numbersize == 64
8973f2f00872 patch 8.2.5004: right shift on negative number does not work as documented
Bram Moolenaar <Bram@vim.org>
parents: 28962
diff changeset
987 call assert_equal(0x7fffffffffffffff, -1 >> 1)
8973f2f00872 patch 8.2.5004: right shift on negative number does not work as documented
Bram Moolenaar <Bram@vim.org>
parents: 28962
diff changeset
988 call assert_equal(0x3fffffffffffffff, -1 >> 2)
8973f2f00872 patch 8.2.5004: right shift on negative number does not work as documented
Bram Moolenaar <Bram@vim.org>
parents: 28962
diff changeset
989 call assert_equal(0x1fffffffffffffff, -1 >> 3)
8973f2f00872 patch 8.2.5004: right shift on negative number does not work as documented
Bram Moolenaar <Bram@vim.org>
parents: 28962
diff changeset
990 endif
28962
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
991 call assert_equal(0, val)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
992 #" multiple operators
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
993 call assert_equal(16, 1 << 2 << 2)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
994 call assert_equal(4, 64 >> 2 >> 2)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
995 call assert_true(1 << 2 << 2 == 256 >> 2 >> 2)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
996 END
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
997 call v9.CheckLegacyAndVim9Success(lines)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
998
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
999 call v9.CheckLegacyAndVim9Failure(['VAR v = 2 << -1'], ['E1283:', 'E1283:', 'E1283:'])
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
1000 call v9.CheckLegacyAndVim9Failure(['VAR a = 2', 'VAR b = -1', 'VAR v = a << b'], ['E1283:', 'E1283:', 'E1283:'])
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
1001 call v9.CheckLegacyAndVim9Failure(['VAR v = "8" >> 2'], ['E1282:', 'E1282:', 'E1282:'])
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
1002 call v9.CheckLegacyAndVim9Failure(['VAR v = 1 << "2"'], ['E1282:', 'E1282:', 'E1282:'])
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
1003 call v9.CheckLegacyAndVim9Failure(['VAR a = "8"', 'VAR b = 2', 'VAR v = a << b'], ['E1282:', 'E1012:', 'E1282:'])
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
1004 call v9.CheckLegacyAndVim9Failure(['VAR a = 8', 'VAR b = "2"', 'VAR v = a >> b'], ['E1282:', 'E1012:', 'E1282:'])
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
1005 call v9.CheckLegacyAndVim9Failure(['VAR v = ![] << 1'], ['E745:', 'E1012:', 'E1282:'])
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
1006 call v9.CheckLegacyAndVim9Failure(['VAR v = 1 << ![]'], ['E745:', 'E1012:', 'E1282:'])
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
1007 call v9.CheckLegacyAndVim9Failure(['VAR v = ![] >> 1'], ['E745:', 'E1012:', 'E1282:'])
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
1008 call v9.CheckLegacyAndVim9Failure(['VAR v = 1 >> ![]'], ['E745:', 'E1012:', 'E1282:'])
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
1009 call v9.CheckDefAndScriptFailure(['echo 1<< 2'], ['E1004:', 'E1004:'])
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
1010 call v9.CheckDefAndScriptFailure(['echo 1 <<2'], ['E1004:', 'E1004:'])
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
1011 call v9.CheckDefAndScriptFailure(['echo 1>> 2'], ['E1004:', 'E1004:'])
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
1012 call v9.CheckDefAndScriptFailure(['echo 1 >>2'], ['E1004:', 'E1004:'])
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
1013
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
1014 let lines =<< trim END
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
1015 var a = 1
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
1016 <<
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
1017 4
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
1018 assert_equal(16, a)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
1019 END
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
1020 call v9.CheckDefAndScriptSuccess(lines)
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
1021 endfunc
abdea69d21b6 patch 8.2.5003: cannot do bitwise shifts
Bram Moolenaar <Bram@vim.org>
parents: 28813
diff changeset
1022
19724
b3e93a05c3ca patch 8.2.0418: code in eval.c not sufficiently covered by tests
Bram Moolenaar <Bram@vim.org>
parents: 19427
diff changeset
1023 " vim: shiftwidth=2 sts=2 expandtab