patch 8.2.2765: Vim9: not all blob operations work

Problem:    Vim9: not all blob operations work.
Solution:   Run more tests also with Vim9 script and :def functions.  Fix what
            doesn't work.
diff --git a/src/testdir/test_blob.vim b/src/testdir/test_blob.vim
index 34ed0ca..3699f3b 100644
--- a/src/testdir/test_blob.vim
+++ b/src/testdir/test_blob.vim
@@ -76,16 +76,47 @@
   END
   call CheckLegacyAndVim9Success(lines)
 
-  " TODO: move to above once it works
-  let b = 0zDEADBEEF
-  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 lines =<< trim END
+      VAR b = 0zDEADBEEF
+      LET b[2 : 3] = 0z112233
+  END
+  call CheckLegacyAndVim9Failure(lines, 'E972:')
 
-  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 lines =<< trim END
+      VAR b = 0zDEADBEEF
+      LET b[2 : 3] = 0z11
+  END
+  call CheckLegacyAndVim9Failure(lines, 'E972:')
+
+  let lines =<< trim END
+      VAR b = 0zDEADBEEF
+      LET b[3 : 2] = 0z
+  END
+  call CheckLegacyAndVim9Failure(lines, 'E979:')
+
+  let lines =<< trim END
+      VAR b = 0zDEADBEEF
+      LET b ..= 0z33
+  END
+  call CheckLegacyAndVim9Failure(lines, ['E734:', 'E1019:', 'E734:'])
+
+  let lines =<< trim END
+      VAR b = 0zDEADBEEF
+      LET b ..= "xx"
+  END
+  call CheckLegacyAndVim9Failure(lines, ['E734:', 'E1019:', 'E734:'])
+
+  let lines =<< trim END
+      VAR b = 0zDEADBEEF
+      LET b += "xx"
+  END
+  call CheckLegacyAndVim9Failure(lines, ['E734:', 'E1012:', 'E734:'])
+
+  let lines =<< trim END
+      VAR b = 0zDEADBEEF
+      LET b[1 : 1] ..= 0z55
+  END
+  call CheckLegacyAndVim9Failure(lines, ['E734:', 'E1183:', 'E734:'])
 endfunc
 
 func Test_blob_get_range()
diff --git a/src/testdir/vim9.vim b/src/testdir/vim9.vim
index e05f859..9efa655 100644
--- a/src/testdir/vim9.vim
+++ b/src/testdir/vim9.vim
@@ -144,8 +144,23 @@
   try
     exe 'so ' .. fname
     call Func()
-    delfunc! Func
   finally
+    delfunc! Func
+    call chdir(cwd)
+    call delete(fname)
+  endtry
+endfunc
+
+" Check that "lines" inside a legacy function results in the expected error
+func CheckLegacyFailure(lines, error)
+  let cwd = getcwd()
+  let fname = 'XlegacyFails' .. s:sequence
+  let s:sequence += 1
+  call writefile(['func Func()'] + a:lines + ['endfunc', 'call Func()'], fname)
+  try
+    call assert_fails('so ' .. fname, a:error)
+  finally
+    delfunc! Func
     call chdir(cwd)
     call delete(fname)
   endtry
@@ -168,3 +183,35 @@
   CheckDefSuccess(vim9lines)
   CheckScriptSuccess(['vim9script'] + vim9lines)
 enddef
+
+" 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 CheckLegacyAndVim9Failure(lines: list<string>, error: any)
+  var legacyError: string
+  var defError: string
+  var scriptError: string
+
+  if type(error) == type('string')
+    legacyError = error
+    defError = error
+    scriptError = error
+  else
+    legacyError = error[0]
+    defError = error[1]
+    scriptError = error[2]
+  endif
+
+  var legacylines = lines->mapnew((_, v) =>
+  				v->substitute('\<VAR\>', 'let', 'g')
+		           	 ->substitute('\<LET\>', 'let', 'g')
+		           	 ->substitute('#"', ' "', 'g'))
+  CheckLegacyFailure(legacylines, legacyError)
+
+  var vim9lines = lines->mapnew((_, v) =>
+  				v->substitute('\<VAR\>', 'var', 'g')
+		           	 ->substitute('\<LET ', '', 'g'))
+  CheckDefExecFailure(vim9lines, defError)
+  CheckScriptFailure(['vim9script'] + vim9lines, scriptError)
+enddef