diff options
Diffstat (limited to 'src/testdir')
-rw-r--r-- | src/testdir/test_blob.vim | 130 | ||||
-rw-r--r-- | src/testdir/vim9.vim | 35 |
2 files changed, 105 insertions, 60 deletions
diff --git a/src/testdir/test_blob.vim b/src/testdir/test_blob.vim index 3eff715d05..34ed0caf2f 100644 --- a/src/testdir/test_blob.vim +++ b/src/testdir/test_blob.vim @@ -1,5 +1,7 @@ " Tests for the Blob types +source vim9.vim + func TearDown() " Run garbage collection after every test call test_garbagecollect_now() @@ -9,73 +11,81 @@ endfunc " Blob creation from constant func Test_blob_create() - let b = 0zDEADBEEF - call assert_equal(v:t_blob, type(b)) - call assert_equal(4, len(b)) - call assert_equal(0xDE, b[0]) - call assert_equal(0xAD, b[1]) - call assert_equal(0xBE, b[2]) - call assert_equal(0xEF, b[3]) - call assert_fails('let x = b[4]') - - call assert_equal(0xDE, get(b, 0)) - call assert_equal(0xEF, get(b, 3)) - - call assert_fails('let b = 0z1', 'E973:') - call assert_fails('let b = 0z1x', 'E973:') - call assert_fails('let b = 0z12345', 'E973:') - - call assert_equal(0z, test_null_blob()) - - let b = 0z001122.33445566.778899.aabbcc.dd - call assert_equal(0z00112233445566778899aabbccdd, b) - call assert_fails('let b = 0z1.1') - call assert_fails('let b = 0z.') - call assert_fails('let b = 0z001122.') - call assert_fails('call get("", 1)', 'E896:') - call assert_equal(0, len(test_null_blob())) + let lines =<< trim END + VAR b = 0zDEADBEEF + call assert_equal(v:t_blob, type(b)) + call assert_equal(4, len(b)) + call assert_equal(0xDE, b[0]) + call assert_equal(0xAD, b[1]) + call assert_equal(0xBE, b[2]) + call assert_equal(0xEF, b[3]) + call assert_fails('VAR x = b[4]') + + call assert_equal(0xDE, get(b, 0)) + call assert_equal(0xEF, get(b, 3)) + + call assert_fails('VAR b = 0z1', 'E973:') + call assert_fails('VAR b = 0z1x', 'E973:') + call assert_fails('VAR b = 0z12345', 'E973:') + + call assert_equal(0z, test_null_blob()) + + LET b = 0z001122.33445566.778899.aabbcc.dd + call assert_equal(0z00112233445566778899aabbccdd, b) + call assert_fails('VAR b = 0z1.1') + call assert_fails('VAR b = 0z.') + call assert_fails('VAR b = 0z001122.') + call assert_fails('call get("", 1)', 'E896:') + call assert_equal(0, len(test_null_blob())) + END + call CheckLegacyAndVim9Success(lines) endfunc " assignment to a blob func Test_blob_assign() + let lines =<< trim END + VAR b = 0zDEADBEEF + VAR b2 = b[1 : 2] + call assert_equal(0zADBE, b2) + + VAR bcopy = b[:] + call assert_equal(b, bcopy) + call assert_false(b is bcopy) + + LET b = 0zDEADBEEF + LET b2 = b + call assert_true(b is b2) + LET b[:] = 0z11223344 + call assert_equal(0z11223344, b) + call assert_equal(0z11223344, b2) + call assert_true(b is b2) + + LET b = 0zDEADBEEF + LET b[3 :] = 0z66 + call assert_equal(0zDEADBE66, b) + LET b[: 1] = 0z8899 + call assert_equal(0z8899BE66, b) + + LET b = 0zDEADBEEF + LET b += 0z99 + call assert_equal(0zDEADBEEF99, b) + + VAR l = [0z12] + VAR m = deepcopy(l) + LET m[0] = 0z34 #" E742 or E741 should not occur. + END + call CheckLegacyAndVim9Success(lines) + + " TODO: move to above once it works let b = 0zDEADBEEF - let b2 = b[1:2] - call assert_equal(0zADBE, b2) - - let bcopy = b[:] - call assert_equal(b, bcopy) - call assert_false(b is bcopy) - - let b = 0zDEADBEEF - let b2 = b - call assert_true(b is b2) - let b[:] = 0z11223344 - call assert_equal(0z11223344, b) - call assert_equal(0z11223344, b2) - call assert_true(b is b2) + call assert_fails('let b[2 : 3] = 0z112233', 'E972:') + call assert_fails('let b[2 : 3] = 0z11', 'E972:') + call assert_fails('let b[3 : 2] = 0z', 'E979:') - let b = 0zDEADBEEF - let b[3:] = 0z66 - call assert_equal(0zDEADBE66, b) - let b[:1] = 0z8899 - call assert_equal(0z8899BE66, b) - - call assert_fails('let b[2:3] = 0z112233', 'E972:') - call assert_fails('let b[2:3] = 0z11', 'E972:') - call assert_fails('let b[3:2] = 0z', 'E979:') - - let b = 0zDEADBEEF - let b += 0z99 - call assert_equal(0zDEADBEEF99, b) - - call assert_fails('let b .= 0z33', 'E734:') - call assert_fails('let b .= "xx"', 'E734:') + call assert_fails('let b ..= 0z33', 'E734:') + call assert_fails('let b ..= "xx"', 'E734:') call assert_fails('let b += "xx"', 'E734:') - call assert_fails('let b[1:1] .= 0z55', 'E734:') - - let l = [0z12] - let m = deepcopy(l) - let m[0] = 0z34 " E742 or E741 should not occur. + call assert_fails('let b[1 : 1] ..= 0z55', 'E734:') endfunc func Test_blob_get_range() diff --git a/src/testdir/vim9.vim b/src/testdir/vim9.vim index f17f141dba..e05f8590bb 100644 --- a/src/testdir/vim9.vim +++ b/src/testdir/vim9.vim @@ -133,3 +133,38 @@ def CheckDefExecAndScriptFailure2( CheckDefExecFailure(lines, errorDef, lnum) CheckScriptFailure(['vim9script'] + lines, errorScript, lnum + 1) enddef + + +" Check that "lines" inside a legacy function has no error. +func CheckLegacySuccess(lines) + let cwd = getcwd() + let fname = 'XlegacySuccess' .. s:sequence + let s:sequence += 1 + call writefile(['func Func()'] + a:lines + ['endfunc'], fname) + try + exe 'so ' .. fname + call Func() + delfunc! Func + finally + call chdir(cwd) + call delete(fname) + endtry +endfunc + +" Execute "lines" in a legacy function, :def function and Vim9 script. +" Use 'VAR' for a declaration. +" Use 'LET' for an assignment +" Use ' #"' for a comment +def CheckLegacyAndVim9Success(lines: list<string>) + var legacylines = lines->mapnew((_, v) => + v->substitute('\<VAR\>', 'let', 'g') + ->substitute('\<LET\>', 'let', 'g') + ->substitute('#"', ' "', 'g')) + CheckLegacySuccess(legacylines) + + var vim9lines = lines->mapnew((_, v) => + v->substitute('\<VAR\>', 'var', 'g') + ->substitute('\<LET ', '', 'g')) + CheckDefSuccess(vim9lines) + CheckScriptSuccess(['vim9script'] + vim9lines) +enddef |