Mercurial > vim
comparison src/testdir/test_listdict.vim @ 20109:e82996ad131f v8.2.0610
patch 8.2.0610: some tests are still old style
Commit: https://github.com/vim/vim/commit/08f4157c5cabc55bcb22f04dd7c717aba40caa34
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Apr 20 16:50:00 2020 +0200
patch 8.2.0610: some tests are still old style
Problem: Some tests are still old style.
Solution: Convert to new style tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5957)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 20 Apr 2020 17:00:04 +0200 |
parents | 2c4d9ca33769 |
children | 0b35a7ffceb2 |
comparison
equal
deleted
inserted
replaced
20108:8823765c60f2 | 20109:e82996ad131f |
---|---|
30 call assert_equal(['as''d', [1, 2, function('strlen')], {'a': 1}], l[1:]) | 30 call assert_equal(['as''d', [1, 2, function('strlen')], {'a': 1}], l[1:]) |
31 call assert_equal([1, 'as''d', [1, 2, function('strlen')]], l[:-2]) | 31 call assert_equal([1, 'as''d', [1, 2, function('strlen')]], l[:-2]) |
32 call assert_equal([1, 'as''d', [1, 2, function('strlen')], {'a': 1}], l[0:8]) | 32 call assert_equal([1, 'as''d', [1, 2, function('strlen')], {'a': 1}], l[0:8]) |
33 call assert_equal([], l[8:-1]) | 33 call assert_equal([], l[8:-1]) |
34 call assert_equal([], l[0:-10]) | 34 call assert_equal([], l[0:-10]) |
35 call assert_equal([], test_null_list()[:2]) | |
35 endfunc | 36 endfunc |
36 | 37 |
37 " List identity | 38 " List identity |
38 func Test_list_identity() | 39 func Test_list_identity() |
39 let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},] | 40 let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},] |
166 call extend(d, {'b':'bbb', 'c':'ccc'}, "keep") | 167 call extend(d, {'b':'bbb', 'c':'ccc'}, "keep") |
167 call assert_fails("call extend(d, {3:333,4:444}, 'error')", 'E737') | 168 call assert_fails("call extend(d, {3:333,4:444}, 'error')", 'E737') |
168 call assert_equal({'c': 'ccc', '1': 99, 'b': [1, 2, function('strlen')], '3': 33, '-1': {'a': 1}}, d) | 169 call assert_equal({'c': 'ccc', '1': 99, 'b': [1, 2, function('strlen')], '3': 33, '-1': {'a': 1}}, d) |
169 call filter(d, 'v:key =~ ''[ac391]''') | 170 call filter(d, 'v:key =~ ''[ac391]''') |
170 call assert_equal({'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}}, d) | 171 call assert_equal({'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}}, d) |
172 | |
173 " duplicate key | |
174 call assert_fails("let d = {'k' : 10, 'k' : 20}", 'E721:') | |
175 " missing comma | |
176 call assert_fails("let d = {'k' : 10 'k' : 20}", 'E722:') | |
177 " missing curly brace | |
178 call assert_fails("let d = {'k' : 10,", 'E723:') | |
179 " invalid key | |
180 call assert_fails('let d = #{++ : 10}', 'E15:') | |
181 " wrong type for key | |
182 call assert_fails('let d={[] : 10}', 'E730:') | |
183 " undefined variable as value | |
184 call assert_fails("let d={'k' : i}", 'E121:') | |
171 endfunc | 185 endfunc |
172 | 186 |
173 " Dictionary identity | 187 " Dictionary identity |
174 func Test_dict_identity() | 188 func Test_dict_identity() |
175 let d = {001: 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1},} | 189 let d = {001: 'asd', 'b': [1, 2, function('strlen')], -1: {'a': 1},} |
260 call insert(g:dict.foo, function('strlen')) | 274 call insert(g:dict.foo, function('strlen')) |
261 call assert_equal('g:dict.func-4', g:dict.func()) | 275 call assert_equal('g:dict.func-4', g:dict.func()) |
262 unlet g:dict | 276 unlet g:dict |
263 endfunc | 277 endfunc |
264 | 278 |
265 " Test removing items in la dictionary | 279 " Test removing items in a dictionary |
266 func Test_dict_func_remove() | 280 func Test_dict_func_remove() |
267 let d = {1:'a', 2:'b', 3:'c'} | 281 let d = {1:'a', 2:'b', 3:'c'} |
268 call assert_equal('b', remove(d, 2)) | 282 call assert_equal('b', remove(d, 2)) |
269 call assert_equal({1:'a', 3:'c'}, d) | 283 call assert_equal({1:'a', 3:'c'}, d) |
270 | 284 |
632 call assert_equal(['BAR', 'Bar', 'FOO', 'FOOBAR', 'Foo', 'bar', 'foo', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l))) | 646 call assert_equal(['BAR', 'Bar', 'FOO', 'FOOBAR', 'Foo', 'bar', 'foo', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}], sort(copy(l))) |
633 endif | 647 endif |
634 | 648 |
635 call assert_fails('call reverse("")', 'E899:') | 649 call assert_fails('call reverse("")', 'E899:') |
636 call assert_fails('call uniq([1, 2], {x, y -> []})', 'E882:') | 650 call assert_fails('call uniq([1, 2], {x, y -> []})', 'E882:') |
651 call assert_fails("call sort([1, 2], function('min'), 1)", "E715:") | |
652 call assert_fails("call sort([1, 2], function('invalid_func'))", "E700:") | |
653 call assert_fails("call sort([1, 2], function('min'))", "E702:") | |
654 call assert_equal(0, sort(test_null_list())) | |
655 call assert_equal(0, uniq(test_null_list())) | |
637 endfunc | 656 endfunc |
638 | 657 |
639 " splitting a string to a List using split() | 658 " splitting a string to a List using split() |
640 func Test_str_split() | 659 func Test_str_split() |
641 call assert_equal(['aa', 'bb'], split(' aa bb ')) | 660 call assert_equal(['aa', 'bb'], split(' aa bb ')) |
746 endif | 765 endif |
747 call assert_equal({'a': 'A', 'b': 'B'}, d) | 766 call assert_equal({'a': 'A', 'b': 'B'}, d) |
748 | 767 |
749 call assert_fails("call extend([1, 2], 1)", 'E712:') | 768 call assert_fails("call extend([1, 2], 1)", 'E712:') |
750 call assert_fails("call extend([1, 2], {})", 'E712:') | 769 call assert_fails("call extend([1, 2], {})", 'E712:') |
770 | |
771 " Extend g: dictionary with an invalid variable name | |
772 call assert_fails("call extend(g:, {'-!' : 10})", 'E461:') | |
751 endfunc | 773 endfunc |
752 | 774 |
753 func s:check_scope_dict(x, fixed) | 775 func s:check_scope_dict(x, fixed) |
754 func s:gen_cmd(cmd, x) | 776 func s:gen_cmd(cmd, x) |
755 return substitute(a:cmd, '\<x\ze:', a:x, 'g') | 777 return substitute(a:cmd, '\<x\ze:', a:x, 'g') |
869 call assert_fails('echo d[1:2]', 'E719:') | 891 call assert_fails('echo d[1:2]', 'E719:') |
870 call assert_fails("let v = [4, 6][{-> 1}]", 'E729:') | 892 call assert_fails("let v = [4, 6][{-> 1}]", 'E729:') |
871 call assert_fails("let v = range(5)[2:[]]", 'E730:') | 893 call assert_fails("let v = range(5)[2:[]]", 'E730:') |
872 call assert_fails("let v = range(5)[2:{-> 2}(]", 'E116:') | 894 call assert_fails("let v = range(5)[2:{-> 2}(]", 'E116:') |
873 call assert_fails("let v = range(5)[2:3", 'E111:') | 895 call assert_fails("let v = range(5)[2:3", 'E111:') |
896 call assert_fails("let l = insert([1,2,3], 4, 10)", 'E684:') | |
897 call assert_fails("let l = insert([1,2,3], 4, -10)", 'E684:') | |
898 call assert_fails("let l = insert([1,2,3], 4, [])", 'E745:') | |
899 endfunc | |
900 | |
901 " Test for a null list | |
902 func Test_null_list() | |
903 call assert_equal(0, join(test_null_list())) | |
904 call assert_fails('let s = join([1, 2], [])', 'E730:') | |
905 call assert_equal([], split(test_null_string())) | |
906 endfunc | |
907 | |
908 " Test for a null dict | |
909 func Test_null_dict() | |
910 call assert_equal(0, items(test_null_dict())) | |
911 call assert_equal(0, keys(test_null_dict())) | |
912 call assert_equal(0, values(test_null_dict())) | |
913 call assert_false(has_key(test_null_dict(), 'k')) | |
914 call assert_fails("let l = [] + test_null_list()", 'E15:') | |
915 call assert_fails("let l = test_null_list() + []", 'E15:') | |
874 endfunc | 916 endfunc |
875 | 917 |
876 " vim: shiftwidth=2 sts=2 expandtab | 918 " vim: shiftwidth=2 sts=2 expandtab |