Mercurial > vim
comparison src/testdir/test_vim9_assign.vim @ 29008:49d8b54802f3 v8.2.5026
patch 8.2.5026: Vim9: a few lines not covered by tests
Commit: https://github.com/vim/vim/commit/31d9948e3a2529c2f619d56bdb48291dc261233d
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu May 26 22:24:43 2022 +0100
patch 8.2.5026: Vim9: a few lines not covered by tests
Problem: Vim9: a few lines not covered by tests.
Solution: Delete dead code. Add a few test cases. make "12->func()" work.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 26 May 2022 23:30:05 +0200 |
parents | 99a7eb1881c7 |
children | 9f8dd1b77563 |
comparison
equal
deleted
inserted
replaced
29007:0e8c870971f7 | 29008:49d8b54802f3 |
---|---|
1119 var dict2: dict<number> = {one: 1, two: 2} | 1119 var dict2: dict<number> = {one: 1, two: 2} |
1120 var dict3: dict<string> = {key: 'value'} | 1120 var dict3: dict<string> = {key: 'value'} |
1121 var dict4: dict<any> = {one: 1, two: '2'} | 1121 var dict4: dict<any> = {one: 1, two: '2'} |
1122 var dict5: dict<blob> = {one: 0z01, two: 0z02} | 1122 var dict5: dict<blob> = {one: 0z01, two: 0z02} |
1123 | 1123 |
1124 # check the type is OK | |
1125 var events: dict<string> = v:event | |
1126 | |
1124 # overwrite | 1127 # overwrite |
1125 dict3['key'] = 'another' | 1128 dict3['key'] = 'another' |
1126 assert_equal(dict3, {key: 'another'}) | 1129 assert_equal(dict3, {key: 'another'}) |
1127 dict3.key = 'yet another' | 1130 dict3.key = 'yet another' |
1128 assert_equal(dict3, {key: 'yet another'}) | 1131 assert_equal(dict3, {key: 'yet another'}) |
2103 | 2106 |
2104 lines =<< trim END | 2107 lines =<< trim END |
2105 va foo = 123 | 2108 va foo = 123 |
2106 END | 2109 END |
2107 v9.CheckDefAndScriptFailure(lines, 'E1065:', 1) | 2110 v9.CheckDefAndScriptFailure(lines, 'E1065:', 1) |
2111 | |
2112 lines =<< trim END | |
2113 var foo: func(number | |
2114 END | |
2115 v9.CheckDefAndScriptFailure(lines, 'E110:', 1) | |
2116 | |
2117 lines =<< trim END | |
2118 var foo: func(number): func( | |
2119 END | |
2120 v9.CheckDefAndScriptFailure(lines, 'E110:', 1) | |
2121 | |
2122 for type in ['num_ber', | |
2123 'anys', 'ani', | |
2124 'bools', 'boel', | |
2125 'blobs', 'blub', | |
2126 'channels', 'channol', | |
2127 'dicts', 'duct', | |
2128 'floats', 'floot', | |
2129 'funcs', 'funk', | |
2130 'jobs', 'jop', | |
2131 'lists', 'last' | |
2132 'numbers', 'numbar', | |
2133 'strings', 'strung', | |
2134 'voids', 'viod'] | |
2135 v9.CheckDefAndScriptFailure([$'var foo: {type}'], 'E1010:', 1) | |
2136 endfor | |
2108 enddef | 2137 enddef |
2109 | 2138 |
2110 def Test_var_declaration_inferred() | 2139 def Test_var_declaration_inferred() |
2111 # check that type is set on the list so that extend() fails | 2140 # check that type is set on the list so that extend() fails |
2112 var lines =<< trim END | 2141 var lines =<< trim END |
2116 return l | 2145 return l |
2117 enddef | 2146 enddef |
2118 echo GetList()->extend(['x']) | 2147 echo GetList()->extend(['x']) |
2119 END | 2148 END |
2120 v9.CheckScriptFailure(lines, 'E1013:', 6) | 2149 v9.CheckScriptFailure(lines, 'E1013:', 6) |
2150 | |
2151 lines =<< trim END | |
2152 vim9script | |
2153 def GetNr(): number | |
2154 return 5 | |
2155 enddef | |
2156 def TestOne() | |
2157 var some = [function('len'), GetNr] | |
2158 g:res = typename(some) | |
2159 enddef | |
2160 TestOne() | |
2161 assert_equal('list<func(): number>', g:res) | |
2162 | |
2163 def TestTwo() | |
2164 var some = [function('len'), GetNr] | |
2165 g:res = typename(some) | |
2166 enddef | |
2167 TestTwo() | |
2168 assert_equal('list<func(): number>', g:res) | |
2169 unlet g:res | |
2170 | |
2171 # FIXME: why is the type different? | |
2172 var first = [function('len'), GetNr] | |
2173 assert_equal('list<func(...): number>', typename(first)) | |
2174 var second = [GetNr, function('len')] | |
2175 assert_equal('list<func(...): number>', typename(second)) | |
2176 END | |
2177 v9.CheckScriptSuccess(lines) | |
2121 enddef | 2178 enddef |
2122 | 2179 |
2123 def Test_script_local_in_legacy() | 2180 def Test_script_local_in_legacy() |
2124 # OK to define script-local later but before compiling | 2181 # OK to define script-local later but before compiling |
2125 var lines =<< trim END | 2182 var lines =<< trim END |