Mercurial > vim
diff src/testdir/test_vim9_class.vim @ 31582:8bbc932fbd09 v9.0.1123
patch 9.0.1123: class function not implemented yet
Commit: https://github.com/vim/vim/commit/6bafdd41cbf8c06bc00f19dcf4e1c8292460b4dd
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 1 12:58:33 2023 +0000
patch 9.0.1123: class function not implemented yet
Problem: Class function not implemented yet.
Solution: Implement defining and calling a class function.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 01 Jan 2023 14:00:07 +0100 |
parents | 9f2a9dd57226 |
children | aee868b9229a |
line wrap: on
line diff
--- a/src/testdir/test_vim9_class.vim +++ b/src/testdir/test_vim9_class.vim @@ -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