Mercurial > vim
comparison src/testdir/test_vim9_expr.vim @ 22936:00b0275ffe7f v8.2.2015
patch 8.2.2015: Vim9: literal dict #{} is not like any other language
Commit: https://github.com/vim/vim/commit/2bede173a177e227e6224a8713f5b88a38d011af
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Nov 19 18:53:18 2020 +0100
patch 8.2.2015: Vim9: literal dict #{} is not like any other language
Problem: Vim9: literal dict #{} is not like any other language.
Solution: Support the JavaScript syntax.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 19 Nov 2020 19:00:06 +0100 |
parents | 87b62395a4d1 |
children | a0a998d2e443 |
comparison
equal
deleted
inserted
replaced
22935:da7ce666cf1f | 22936:00b0275ffe7f |
---|---|
1881 assert_equal(123, FuncRef()) | 1881 assert_equal(123, FuncRef()) |
1882 END | 1882 END |
1883 CheckDefAndScriptSuccess(lines) | 1883 CheckDefAndScriptSuccess(lines) |
1884 enddef | 1884 enddef |
1885 | 1885 |
1886 let g:test_space_dict = {'': 'empty', ' ': 'space'} | |
1887 let g:test_hash_dict = #{one: 1, two: 2} | |
1888 | |
1886 def Test_expr7_dict() | 1889 def Test_expr7_dict() |
1887 # dictionary | 1890 # dictionary |
1888 var lines =<< trim END | 1891 var lines =<< trim END |
1889 assert_equal(g:dict_empty, {}) | 1892 assert_equal(g:dict_empty, {}) |
1890 assert_equal(g:dict_empty, { }) | 1893 assert_equal(g:dict_empty, { }) |
1891 assert_equal(g:dict_one, {'one': 1}) | 1894 assert_equal(g:dict_one, {'one': 1}) |
1892 var key = 'one' | 1895 var key = 'one' |
1893 var val = 1 | 1896 var val = 1 |
1894 assert_equal(g:dict_one, {key: val}) | 1897 assert_equal(g:dict_one, {[key]: val}) |
1895 | 1898 |
1896 var numbers: dict<number> = #{a: 1, b: 2, c: 3} | 1899 var numbers: dict<number> = {a: 1, b: 2, c: 3} |
1897 numbers = #{a: 1} | 1900 numbers = #{a: 1} |
1898 numbers = #{} | 1901 numbers = #{} |
1899 | 1902 |
1900 var strings: dict<string> = #{a: 'a', b: 'b', c: 'c'} | 1903 var strings: dict<string> = {a: 'a', b: 'b', c: 'c'} |
1901 strings = #{a: 'x'} | 1904 strings = #{a: 'x'} |
1902 strings = #{} | 1905 strings = #{} |
1903 | 1906 |
1904 var mixed: dict<any> = #{a: 'a', b: 42} | 1907 var mixed: dict<any> = {a: 'a', b: 42} |
1905 mixed = #{a: 'x'} | 1908 mixed = #{a: 'x'} |
1906 mixed = #{a: 234} | 1909 mixed = #{a: 234} |
1907 mixed = #{} | 1910 mixed = #{} |
1908 | 1911 |
1909 var dictlist: dict<list<string>> = #{absent: [], present: ['hi']} | 1912 var dictlist: dict<list<string>> = #{absent: [], present: ['hi']} |
1913 var dictdict: dict<dict<string>> = #{one: #{a: 'text'}, two: #{}} | 1916 var dictdict: dict<dict<string>> = #{one: #{a: 'text'}, two: #{}} |
1914 dictdict = #{one: #{}, two: #{a: 'text'}} | 1917 dictdict = #{one: #{}, two: #{a: 'text'}} |
1915 dictdict = #{one: #{}, two: #{}} | 1918 dictdict = #{one: #{}, two: #{}} |
1916 | 1919 |
1917 assert_equal({'': 0}, {matchstr('string', 'wont match'): 0}) | 1920 assert_equal({'': 0}, {matchstr('string', 'wont match'): 0}) |
1921 | |
1922 assert_equal(g:test_space_dict, {['']: 'empty', [' ']: 'space'}) | |
1923 assert_equal(g:test_hash_dict, {one: 1, two: 2}) | |
1918 END | 1924 END |
1919 CheckDefAndScriptSuccess(lines) | 1925 CheckDefAndScriptSuccess(lines) |
1920 | 1926 |
1921 CheckDefFailure(["var x = #{a:8}"], 'E1069:', 1) | 1927 CheckDefFailure(["var x = #{a:8}"], 'E1069:', 1) |
1922 CheckDefFailure(["var x = #{a : 8}"], 'E1068:', 1) | 1928 CheckDefFailure(["var x = #{a : 8}"], 'E1068:', 1) |
1927 CheckDefFailure(["var x = #{8: 8}"], 'E1014:', 1) | 1933 CheckDefFailure(["var x = #{8: 8}"], 'E1014:', 1) |
1928 CheckDefFailure(["var x = #{xxx}"], 'E720:', 1) | 1934 CheckDefFailure(["var x = #{xxx}"], 'E720:', 1) |
1929 CheckDefFailure(["var x = #{xxx: 1", "var y = 2"], 'E722:', 2) | 1935 CheckDefFailure(["var x = #{xxx: 1", "var y = 2"], 'E722:', 2) |
1930 CheckDefFailure(["var x = #{xxx: 1,"], 'E723:', 2) | 1936 CheckDefFailure(["var x = #{xxx: 1,"], 'E723:', 2) |
1931 CheckDefFailure(["var x = {'a': xxx}"], 'E1001:', 1) | 1937 CheckDefFailure(["var x = {'a': xxx}"], 'E1001:', 1) |
1932 CheckDefFailure(["var x = {xxx: 8}"], 'E1001:', 1) | 1938 CheckDefFailure(["var x = {xx-x: 8}"], 'E1001:', 1) |
1933 CheckDefFailure(["var x = #{a: 1, a: 2}"], 'E721:', 1) | 1939 CheckDefFailure(["var x = #{a: 1, a: 2}"], 'E721:', 1) |
1934 CheckDefFailure(["var x = #"], 'E1015:', 1) | 1940 CheckDefFailure(["var x = #"], 'E1015:', 1) |
1935 CheckDefExecFailure(["var x = g:anint.member"], 'E715:', 1) | 1941 CheckDefExecFailure(["var x = g:anint.member"], 'E715:', 1) |
1936 CheckDefExecFailure(["var x = g:dict_empty.member"], 'E716:', 1) | 1942 CheckDefExecFailure(["var x = g:dict_empty.member"], 'E716:', 1) |
1937 | 1943 |