Skip to content

Commit 2070390

Browse files
kennypetechrisbra
authored andcommitted
patch 9.2.0541: Vim9: endclass/endenum/endinterface can give errors
Problem: Vim9: ":endclass", ":endenum" and ":endinterface" can give a "command cannot be shortened" error, because the full-name check compares against the line start instead of the command word. Solution: Skip a leading colon and white space before checking the end command name, update tests (Peter Kenny). related: #20032 related: #20191 closes: #20253 Signed-off-by: Peter Kenny <github.com@k1w1.cyou> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent c3e975d commit 2070390

5 files changed

Lines changed: 155 additions & 64 deletions

File tree

src/testdir/test_vim9_class.vim

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
" Test Vim9 classes
1+
" Tests for Vim9 script classes
22

33
import './util/vim9.vim' as v9
44

@@ -50,6 +50,14 @@ def Test_class_basic()
5050
END
5151
v9.CheckSourceFailure(lines, 'E1065: Command cannot be shortened: endcl', 3)
5252

53+
# "endclass" cannot be shortened (variant incl. whitespace and colon)
54+
lines =<< trim END
55+
vim9script
56+
class Something
57+
: endcla
58+
END
59+
v9.CheckSourceFailure(lines, 'E1065: Command cannot be shortened: endcla', 3)
60+
5361
# Additional words after "endclass"
5462
lines =<< trim END
5563
vim9script
@@ -11869,4 +11877,19 @@ func Test_class_member_lambda()
1186911877
call v9.CheckSourceSuccess(lines)
1187011878
endfunc
1187111879

11880+
" Test for colon and whitespace before class, endclass, static, and abstract
11881+
def Test_colon_whitespace()
11882+
var lines =<< trim END
11883+
: vim9script
11884+
: class C
11885+
# TODO: Fix :public - gives E1065
11886+
# : public var p = true
11887+
: static var s = true
11888+
: endclass
11889+
: abstract class A
11890+
: endclass
11891+
END
11892+
v9.CheckSourceSuccess(lines)
11893+
enddef
11894+
1187211895
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

src/testdir/test_vim9_enum.vim

Lines changed: 61 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
" Test Vim9 enums
1+
" Tests for Vim9 script enums
22

33
import './util/vim9.vim' as v9
44

5-
" Test for parsing an enum definition
5+
" Test for parsing an enum definition {{{1
66
def Test_enum_parse()
77
# enum supported only in a Vim9 script
88
var lines =<< trim END
@@ -11,6 +11,14 @@ def Test_enum_parse()
1111
END
1212
v9.CheckSourceFailure(lines, 'E1414: Enum can only be defined in Vim9 script', 1)
1313

14+
# ":enum" and ":endenum"
15+
lines =<< trim END
16+
vim9script
17+
:enum Foo
18+
:endenum
19+
END
20+
v9.CheckSourceSuccess(lines)
21+
1422
# First character in an enum name should be capitalized.
1523
lines =<< trim END
1624
vim9script
@@ -46,10 +54,10 @@ def Test_enum_parse()
4654
# The complete "enum" should be specified.
4755
lines =<< trim END
4856
vim9script
49-
enu Something
57+
enu Nah
5058
endenum
5159
END
52-
v9.CheckSourceFailure(lines, 'E1065: Command cannot be shortened: enu', 2)
60+
v9.CheckSourceFailure(lines, 'E1065: Command cannot be shortened: enu Nah', 2)
5361

5462
# The complete "endenum" should be specified.
5563
lines =<< trim END
@@ -59,6 +67,14 @@ def Test_enum_parse()
5967
END
6068
v9.CheckSourceFailure(lines, 'E1065: Command cannot be shortened: enden', 3)
6169

70+
# "endenum" cannot be shortened (variant incl. whitespace and colon)
71+
lines =<< trim END
72+
vim9script
73+
enum NoAbbrev
74+
: endenu
75+
END
76+
v9.CheckSourceFailure(lines, 'E1065: Command cannot be shortened: endenu', 3)
77+
6278
# Only the complete word "endenum" should be recognized
6379
lines =<< trim END
6480
vim9script
@@ -271,6 +287,16 @@ def Test_enum_parse()
271287
END
272288
v9.CheckSourceFailure(lines, 'E1418: Invalid enum value declaration: $%@', 4)
273289

290+
# Additional command after "enumvalue"
291+
lines =<< trim END
292+
vim9script
293+
enum NoAdditionalCmd
294+
One, | var y = 10
295+
Two
296+
endenum
297+
END
298+
v9.CheckSourceFailure(lines, "E1418: Invalid enum value declaration: | var y = 10", 3)
299+
274300
# Duplicate enum value
275301
lines =<< trim END
276302
vim9script
@@ -352,6 +378,7 @@ def Test_enum_parse()
352378
v9.CheckSourceFailure(lines, 'E1123: Missing comma before argument: n: number = 10', 3)
353379
enddef
354380

381+
" Test for basic enum declaration and errors {{{1
355382
def Test_basic_enum()
356383
# Declare a simple enum
357384
var lines =<< trim END
@@ -493,7 +520,7 @@ def Test_basic_enum()
493520
v9.CheckSourceFailure(lines, 'E1421: Enum "Fruit" cannot be used as a value', 6)
494521
enddef
495522

496-
" Test for type() and typename() of an enum
523+
" Test for type() and typename() of an enum {{{1
497524
def Test_enum_type()
498525
var lines =<< trim END
499526
vim9script
@@ -525,7 +552,7 @@ def Test_enum_type()
525552
v9.CheckSourceSuccess(lines)
526553
enddef
527554

528-
" Try modifying an enum or an enum item
555+
" Test for trying to modify an enum or an enum item {{{1
529556
def Test_enum_modify()
530557
# Try assigning an unsupported value to an enum
531558
var lines =<< trim END
@@ -652,7 +679,7 @@ def Test_enum_modify()
652679
v9.CheckSourceFailure(lines, 'E1423: Enum value "Foo.Apple" cannot be modified', 1)
653680
enddef
654681

655-
" Test for using enum in an expression
682+
" Test for using enum in an expression {{{1
656683
def Test_enum_expr()
657684
var lines =<< trim END
658685
vim9script
@@ -691,7 +718,7 @@ def Test_enum_expr()
691718
v9.CheckSourceFailure(lines, 'E1425: Using an Enum "Color" as a String', 5)
692719
enddef
693720

694-
" Using an enum in a lambda function
721+
" Test for using an enum in a lambda function {{{1
695722
def Test_enum_lambda()
696723
var lines =<< trim END
697724
vim9script
@@ -708,7 +735,7 @@ def Test_enum_lambda()
708735
v9.CheckSourceSuccess(lines)
709736
enddef
710737

711-
" Comparison using enums
738+
" Test for comparison using enums {{{1
712739
def Test_enum_compare()
713740
var lines =<< trim END
714741
vim9script
@@ -761,7 +788,7 @@ def Test_enum_compare()
761788
v9.CheckSourceSuccess(lines)
762789
enddef
763790

764-
" Test for using an enum as a default argument to a function
791+
" Test for using an enum as a default argument to a function {{{1
765792
def Test_enum_default_arg()
766793
var lines =<< trim END
767794
vim9script
@@ -777,7 +804,7 @@ def Test_enum_default_arg()
777804
v9.CheckSourceSuccess(lines)
778805
enddef
779806

780-
" Test for enum garbage collection
807+
" Test for enum garbage collection {{{1
781808
func Test_enum_garbagecollect()
782809
let lines =<< trim END
783810
vim9script
@@ -826,7 +853,7 @@ func Test_enum_garbagecollect()
826853
call v9.CheckSourceSuccess(lines)
827854
endfunc
828855

829-
" Test for the enum values class variable
856+
" Test for the enum values class variable {{{1
830857
def Test_enum_values()
831858
var lines =<< trim END
832859
vim9script
@@ -912,7 +939,7 @@ def Test_enum_values()
912939
v9.CheckSourceSuccess(lines)
913940
enddef
914941

915-
" Test comments in enums
942+
" Test for using comments in enums {{{1
916943
def Test_enum_comments()
917944
var lines =<< trim END
918945
vim9script
@@ -951,7 +978,7 @@ def Test_enum_comments()
951978
v9.CheckSourceFailure(lines, 'E1170: Cannot use #{ to start a comment', 4)
952979
enddef
953980

954-
" Test trailing whitespace after enum values
981+
" Test for trailing whitespace after enum values {{{1
955982
def Test_enum_whitespace()
956983
var lines =<< trim END
957984
vim9script
@@ -966,15 +993,15 @@ def Test_enum_whitespace()
966993
lines =<< trim END
967994
vim9script
968995
enum Car
969-
Honda(),
996+
Honda(),
970997
Ford()
971998
endenum
972999
defcompile
9731000
END
9741001
v9.CheckSourceSuccess(lines)
9751002
enddef
9761003

977-
" Test string() with enums
1004+
" Test for using string() with enums {{{1
9781005
def Test_enum_string()
9791006
var lines =<< trim END
9801007
vim9script
@@ -1004,7 +1031,7 @@ def Test_enum_string()
10041031
v9.CheckSourceSuccess(lines)
10051032
enddef
10061033

1007-
" Test for importing an enum
1034+
" Test for importing an enum {{{1
10081035
def Test_enum_import()
10091036
var lines =<< trim END
10101037
vim9script
@@ -1040,7 +1067,7 @@ def Test_enum_import()
10401067
v9.CheckScriptSuccess(lines)
10411068
enddef
10421069

1043-
" Test for using test_refcount() with enum
1070+
" Test for using test_refcount() with enum {{{1
10441071
def Test_enum_refcount()
10451072
var lines =<< trim END
10461073
vim9script
@@ -1099,7 +1126,7 @@ def Test_enum_refcount()
10991126
v9.CheckSourceSuccess(lines)
11001127
enddef
11011128

1102-
" Test for defining an enum with additional object variables and methods
1129+
" Test for defining an enum with additional object variables and methods {{{1
11031130
def Test_enum_enhanced()
11041131
var lines =<< trim END
11051132
vim9script
@@ -1140,7 +1167,7 @@ def Test_enum_enhanced()
11401167
v9.CheckSourceSuccess(lines)
11411168
enddef
11421169

1143-
" Test for the enum value 'name' variable
1170+
" Test for the enum value 'name' variable {{{1
11441171
def Test_enum_name()
11451172
# Check the names of enum values
11461173
var lines =<< trim END
@@ -1221,7 +1248,7 @@ def Test_enum_name()
12211248
v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: name', 4)
12221249
enddef
12231250

1224-
" Test for the enum value 'ordinal' variable
1251+
" Test for the enum value 'ordinal' variable {{{1
12251252
def Test_enum_ordinal()
12261253
# Check the ordinal values of enum items
12271254
var lines =<< trim END
@@ -1302,7 +1329,7 @@ def Test_enum_ordinal()
13021329
v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: ordinal', 4)
13031330
enddef
13041331

1305-
" Test for trying to create a new enum object using the constructor
1332+
" Test for trying to create a new enum object using the constructor {{{1
13061333
def Test_enum_invoke_constructor()
13071334
var lines =<< trim END
13081335
vim9script
@@ -1360,7 +1387,7 @@ def Test_enum_invoke_constructor()
13601387
v9.CheckSourceFailureList(lines, ['E1100:', 'E1100:'], 1)
13611388
enddef
13621389

1363-
" Test for checking "this" in an enum constructor
1390+
" Test for checking "this" in an enum constructor {{{1
13641391
def Test_enum_this_in_constructor()
13651392
var lines =<< trim END
13661393
vim9script
@@ -1378,7 +1405,7 @@ def Test_enum_this_in_constructor()
13781405
v9.CheckSourceSuccess(lines)
13791406
enddef
13801407

1381-
" Test for using member variables in an enum object
1408+
" Test for using member variables in an enum object {{{1
13821409
def Test_enum_object_variable()
13831410
var lines =<< trim END
13841411
vim9script
@@ -1483,7 +1510,7 @@ def Test_enum_object_variable()
14831510
v9.CheckSourceFailure(lines, 'E119: Not enough arguments for function: new', 8)
14841511
enddef
14851512

1486-
" Test for using a custom constructor with an enum
1513+
" Test for using a custom constructor with an enum {{{1
14871514
def Test_enum_custom_constructor()
14881515
# space before "("
14891516
var lines =<< trim END
@@ -1556,7 +1583,7 @@ def Test_enum_custom_constructor()
15561583
v9.CheckSourceSuccess(lines)
15571584
enddef
15581585

1559-
" Test for using class variables in an enum class
1586+
" Test for using class variables in an enum class {{{1
15601587
def Test_enum_class_variable()
15611588
var lines =<< trim END
15621589
vim9script
@@ -1571,7 +1598,7 @@ def Test_enum_class_variable()
15711598
v9.CheckSourceSuccess(lines)
15721599
enddef
15731600

1574-
" Test for converting a string to an enum value
1601+
" Test for converting a string to an enum value {{{1
15751602
def Test_enum_eval()
15761603
var lines =<< trim END
15771604
vim9script
@@ -1588,7 +1615,7 @@ def Test_enum_eval()
15881615
v9.CheckSourceSuccess(lines)
15891616
enddef
15901617

1591-
" Test for using "values" in an enum class variable
1618+
" Test for using "values" in an enum class variable {{{1
15921619
def Test_use_enum_values_in_class_variable()
15931620
var lines =<< trim END
15941621
vim9script
@@ -1601,7 +1628,7 @@ def Test_use_enum_values_in_class_variable()
16011628
v9.CheckSourceSuccess(lines)
16021629
enddef
16031630

1604-
" Test for using lambda block in enums
1631+
" Test for using lambda block in enums {{{1
16051632
def Test_lambda_block_in_enum()
16061633
# This used to crash Vim
16071634
var lines =<< trim END
@@ -1632,7 +1659,7 @@ def Test_lambda_block_in_enum()
16321659
v9.CheckScriptSuccess(lines)
16331660
enddef
16341661

1635-
" Echo an enum
1662+
" Test for echoing an enum {{{1
16361663
def Test_enum_echo()
16371664
var lines =<< trim END
16381665
vim9script
@@ -1647,8 +1674,8 @@ def Test_enum_echo()
16471674
v9.CheckScriptSuccess(lines)
16481675
enddef
16491676

1650-
" Test for garbage collecting an enum with a complex member variables.
1651-
func Test_class_selfref_gc()
1677+
" Test for garbage collecting an enum with a complex member variables {{{1
1678+
func Test_enum_selfref_gc()
16521679
let lines =<< trim END
16531680
vim9script
16541681
enum Foo
@@ -1664,7 +1691,7 @@ func Test_class_selfref_gc()
16641691
call v9.CheckSourceSuccess(lines)
16651692
endfunc
16661693

1667-
" Test for defining an enum in a function
1694+
" Test for defining an enum in a function {{{1
16681695
def Test_enum_defined_in_function()
16691696
var lines =<< trim END
16701697
vim9script
@@ -1678,5 +1705,5 @@ def Test_enum_defined_in_function()
16781705
END
16791706
v9.CheckScriptFailure(lines, 'E1435: Enum can only be used in a script', 2)
16801707
enddef
1681-
1708+
" }}}
16821709
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

0 commit comments

Comments
 (0)