summaryrefslogtreecommitdiffstats
path: root/src/testdir/test_vim9_class.vim
diff options
context:
space:
mode:
Diffstat (limited to 'src/testdir/test_vim9_class.vim')
-rw-r--r--src/testdir/test_vim9_class.vim54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim
index bd06c6e..e92fcc5 100644
--- a/src/testdir/test_vim9_class.vim
+++ b/src/testdir/test_vim9_class.vim
@@ -103,6 +103,18 @@ def Test_class_basic()
END
v9.CheckSourceFailure(lines, "E488: Trailing characters: | var y = 10", 3)
+ # Comments are allowed after an inline block
+ lines =<< trim END
+ vim9script
+ class Foo
+ static const bar = { # {{{
+ baz: 'qux'
+ } # }}}
+ endclass
+ assert_equal({baz: 'qux'}, Foo.bar)
+ END
+ v9.CheckSourceSuccess(lines)
+
# Try to define a class with the same name as an existing variable
lines =<< trim END
vim9script
@@ -533,6 +545,28 @@ def Test_using_null_class()
@_ = null_class.member
END
v9.CheckDefExecAndScriptFailure(lines, ['E715: Dictionary required', 'E1363: Incomplete type'])
+
+ # Test for using a null class as a value
+ lines =<< trim END
+ vim9script
+ echo empty(null_class)
+ END
+ v9.CheckSourceFailure(lines, 'E1405: Class "" cannot be used as a value', 2)
+
+ # Test for using a null class with string()
+ lines =<< trim END
+ vim9script
+ assert_equal('class [unknown]', string(null_class))
+ END
+ v9.CheckSourceSuccess(lines)
+
+ # Test for using a null class with type() and typename()
+ lines =<< trim END
+ vim9script
+ assert_equal(12, type(null_class))
+ assert_equal('class<Unknown>', typename(null_class))
+ END
+ v9.CheckSourceSuccess(lines)
enddef
def Test_class_interface_wrong_end()
@@ -10690,4 +10724,24 @@ def Test_class_definition_in_a_function()
v9.CheckScriptFailure(lines, 'E1429: Class can only be used in a script', 1)
enddef
+" Test for using [] with a class and an object
+def Test_class_object_index()
+ var lines =<< trim END
+ vim9script
+ class A
+ endclass
+ A[10] = 1
+ END
+ v9.CheckScriptFailure(lines, 'E689: Index not allowed after a class: A[10] = 1', 4)
+
+ lines =<< trim END
+ vim9script
+ class A
+ endclass
+ var a = A.new()
+ a[10] = 1
+ END
+ v9.CheckScriptFailure(lines, 'E689: Index not allowed after a object: a[10] = 1', 5)
+enddef
+
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker