changeset 19511:7e76d5fba19f v8.2.0313

patch 8.2.0313: Vim9: insufficient script tests Commit: https://github.com/vim/vim/commit/fa29c8abd62c2733d5505563600ea35dddf73dca Author: Bram Moolenaar <Bram@vim.org> Date: Sun Feb 23 22:35:05 2020 +0100 patch 8.2.0313: Vim9: insufficient script tests Problem: Vim9: insufficient script tests. Solution: Add tests. Make import of alphanumeric name work.
author Bram Moolenaar <Bram@vim.org>
date Sun, 23 Feb 2020 22:45:04 +0100
parents 8a070de5d840
children 8e63e95fca06
files src/testdir/test_vim9_script.vim src/version.c src/vim9script.c
diffstat 3 files changed, 55 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -352,6 +352,50 @@ def Test_vim9script()
   writefile(import_star_lines, 'Ximport.vim')
   assert_fails('source Ximport.vim', 'E1045:')
 
+  " try to import something that exists but is not exported
+  let import_not_exported_lines =<< trim END
+    vim9script
+    import name from './Xexport.vim'
+  END
+  writefile(import_not_exported_lines, 'Ximport.vim')
+  assert_fails('source Ximport.vim', 'E1049:')
+
+  " import a very long name, requires making a copy
+  let import_long_name_lines =<< trim END
+    vim9script
+    import name012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 from './Xexport.vim'
+  END
+  writefile(import_long_name_lines, 'Ximport.vim')
+  assert_fails('source Ximport.vim', 'E1048:')
+
+  let import_no_from_lines =<< trim END
+    vim9script
+    import name './Xexport.vim'
+  END
+  writefile(import_no_from_lines, 'Ximport.vim')
+  assert_fails('source Ximport.vim', 'E1070:')
+
+  let import_invalid_string_lines =<< trim END
+    vim9script
+    import name from Xexport.vim
+  END
+  writefile(import_invalid_string_lines, 'Ximport.vim')
+  assert_fails('source Ximport.vim', 'E1071:')
+
+  let import_wrong_name_lines =<< trim END
+    vim9script
+    import name from './XnoExport.vim'
+  END
+  writefile(import_wrong_name_lines, 'Ximport.vim')
+  assert_fails('source Ximport.vim', 'E1053:')
+
+  let import_missing_comma_lines =<< trim END
+    vim9script
+    import {exported name} from './Xexport.vim'
+  END
+  writefile(import_missing_comma_lines, 'Ximport.vim')
+  assert_fails('source Ximport.vim', 'E1046:')
+
   delete('Ximport.vim')
   delete('Xexport.vim')
 
--- a/src/version.c
+++ b/src/version.c
@@ -739,6 +739,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    313,
+/**/
     312,
 /**/
     311,
--- a/src/vim9script.c
+++ b/src/vim9script.c
@@ -172,7 +172,7 @@ find_exported(
     scriptitem_T *script = SCRIPT_ITEM(sid);
 
     // isolate one name
-    while (eval_isnamec1(*arg))
+    while (eval_isnamec(*arg))
 	++arg;
     *name_len = (int)(arg - name);
 
@@ -262,9 +262,9 @@ handle_import(char_u *arg_start, garray_
     {
 	if (*arg == '*')
 	    arg = skipwhite(arg + 1);
-	else
+	else if (eval_isnamec1(*arg))
 	{
-	    while (eval_isnamec1(*arg))
+	    while (eval_isnamec(*arg))
 		++arg;
 	    arg = skipwhite(arg);
 	}
@@ -273,8 +273,9 @@ handle_import(char_u *arg_start, garray_
 	    // skip over "as Name "
 	    arg = skipwhite(arg + 2);
 	    as_ptr = arg;
-	    while (eval_isnamec1(*arg))
-		++arg;
+	    if (eval_isnamec1(*arg))
+		while (eval_isnamec(*arg))
+		    ++arg;
 	    as_len = (int)(arg - as_ptr);
 	    arg = skipwhite(arg);
 	}
@@ -286,7 +287,7 @@ handle_import(char_u *arg_start, garray_
     }
     if (STRNCMP("from", arg, 4) != 0 || !VIM_ISWHITE(arg[4]))
     {
-	emsg(_("E1045: Missing \"from\""));
+	emsg(_("E1070: Missing \"from\""));
 	return NULL;
     }
     from_ptr = arg;
@@ -299,7 +300,7 @@ handle_import(char_u *arg_start, garray_
 	ret = get_string_tv(&arg, &tv, TRUE);
     if (ret == FAIL || tv.vval.v_string == NULL || *tv.vval.v_string == NUL)
     {
-	emsg(_("E1045: Invalid string after \"from\""));
+	emsg(_("E1071: Invalid string after \"from\""));
 	return NULL;
     }
     cmd_end = arg;
@@ -423,6 +424,7 @@ handle_import(char_u *arg_start, garray_
 	}
 	if (arg != from_ptr)
 	{
+	    // cannot happen, just in case the above has a flaw
 	    emsg(_("E1047: syntax error in import"));
 	    return NULL;
 	}