0
0
mirror of https://github.com/vim/vim.git synced 2025-10-04 05:25:06 -04:00

patch 9.0.1123: class function not implemented yet

Problem:    Class function not implemented yet.
Solution:   Implement defining and calling a class function.
This commit is contained in:
Bram Moolenaar
2023-01-01 12:58:33 +00:00
parent 9f2d97efe2
commit 6bafdd41cb
6 changed files with 174 additions and 72 deletions

View File

@@ -377,7 +377,7 @@ def Test_class_member_access()
static _secret = 7
public static anybody = 42
def AddToCounter(nr: number)
static def AddToCounter(nr: number)
counter += nr
enddef
endclass
@@ -403,6 +403,32 @@ def Test_class_member_access()
v9.CheckScriptSuccess(lines)
enddef
def Test_class_function()
var lines =<< trim END
vim9script
class Value
this.value = 0
static objects = 0
def new(v: number)
this.value = v
++objects
enddef
static def GetCount(): number
return objects
enddef
endclass
assert_equal(0, Value.GetCount())
var v1 = Value.new(2)
assert_equal(1, Value.GetCount())
var v2 = Value.new(7)
assert_equal(2, Value.GetCount())
END
v9.CheckScriptSuccess(lines)
enddef
def Test_class_object_to_string()
var lines =<< trim END
vim9script