comparison 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
comparison
equal deleted inserted replaced
31415:4fd33db887f2 31416:f088f1d97eee
128 vim9script 128 vim9script
129 129
130 class TextPosition 130 class TextPosition
131 this.lnum: number 131 this.lnum: number
132 this.col: number 132 this.col: number
133
134 def ToString(): string
135 return $'({this.lnum}, {this.col})'
136 enddef
133 endclass 137 endclass
134 138
135 # use the automatically generated new() method 139 # use the automatically generated new() method
136 var pos = TextPosition.new(2, 12) 140 var pos = TextPosition.new(2, 12)
137 assert_equal(2, pos.lnum) 141 assert_equal(2, pos.lnum)
138 assert_equal(12, pos.col) 142 assert_equal(12, pos.col)
143
144 # call an object method
145 assert_equal('(2, 12)', pos.ToString())
139 END 146 END
140 v9.CheckScriptSuccess(lines) 147 v9.CheckScriptSuccess(lines)
141 enddef 148 enddef
142 149
143 150