diff src/testdir/test_vim9_class.vim @ 31416:f088f1d97eee v9.0.1041

patch 9.0.1041: cannot define a method in a class Commit: https://github.com/vim/vim/commit/ffdaca9e6f3d39af6857ac52ced9385df203a152 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Dec 9 21:41:48 2022 +0000 patch 9.0.1041: cannot define a method in a class Problem: Cannot define a method in a class. Solution: Implement defining an object method. Make calling an object method work.
author Bram Moolenaar <Bram@vim.org>
date Fri, 09 Dec 2022 22:45:03 +0100
parents 60b1d266548d
children e31fc75f6aff
line wrap: on
line diff
--- a/src/testdir/test_vim9_class.vim
+++ b/src/testdir/test_vim9_class.vim
@@ -130,12 +130,19 @@ def Test_class_basic()
       class TextPosition
         this.lnum: number
 	this.col: number
+
+        def ToString(): string
+          return $'({this.lnum}, {this.col})'
+        enddef
       endclass
 
       # use the automatically generated new() method
       var pos = TextPosition.new(2, 12)
       assert_equal(2, pos.lnum)
       assert_equal(12, pos.col)
+
+      # call an object method
+      assert_equal('(2, 12)', pos.ToString())
   END
   v9.CheckScriptSuccess(lines)
 enddef