patch 8.2.0522: several errors are not tested for

Problem:    Several errors are not tested for.
Solution:   Add tests. (Yegappan Lakshmanan, closes #5892)
diff --git a/src/testdir/test_vimscript.vim b/src/testdir/test_vimscript.vim
index 72eae7c..9bc6702 100644
--- a/src/testdir/test_vimscript.vim
+++ b/src/testdir/test_vimscript.vim
@@ -1998,6 +1998,9 @@
   endtry
   call assert_equal(1, caught_e733)
 
+  " Using endfunc with :if
+  call assert_fails('exe "if 1 | endfunc | endif"', 'E193:')
+
   " Missing 'in' in a :for statement
   call assert_fails('for i range(1) | endfor', 'E690:')
 endfunc
@@ -2044,6 +2047,15 @@
       @a
       let @a = ''
     endfunc
+
+    " Deep nesting of function ... endfunction
+    func Test5()
+      let @a = join(repeat(['function X()'], 51), "\n")
+      let @a ..= "\necho v:true\n"
+      let @a ..= join(repeat(['endfunction'], 51), "\n")
+      @a
+      let @a = ''
+    endfunc
   [SCRIPT]
   call writefile(lines, 'Xscript')
 
@@ -2051,20 +2063,31 @@
 
   " Deep nesting of if ... endif
   call term_sendkeys(buf, ":call Test1()\n")
+  call term_wait(buf)
   call WaitForAssert({-> assert_match('^E579:', term_getline(buf, 5))})
 
   " Deep nesting of for ... endfor
   call term_sendkeys(buf, ":call Test2()\n")
+  call term_wait(buf)
   call WaitForAssert({-> assert_match('^E585:', term_getline(buf, 5))})
 
   " Deep nesting of while ... endwhile
   call term_sendkeys(buf, ":call Test3()\n")
+  call term_wait(buf)
   call WaitForAssert({-> assert_match('^E585:', term_getline(buf, 5))})
 
   " Deep nesting of try ... endtry
   call term_sendkeys(buf, ":call Test4()\n")
+  call term_wait(buf)
   call WaitForAssert({-> assert_match('^E601:', term_getline(buf, 5))})
 
+  " Deep nesting of function ... endfunction
+  call term_sendkeys(buf, ":call Test5()\n")
+  call term_wait(buf)
+  call WaitForAssert({-> assert_match('^E1058:', term_getline(buf, 4))})
+  call term_sendkeys(buf, "\<C-C>\n")
+  call term_wait(buf)
+
   "let l = ''
   "for i in range(1, 6)
   "  let l ..= term_getline(buf, i) . "\n"