" Test Vim9 classes
source check.vim
import './vim9.vim' as v9
def Test_class_basic()
var lines =<< trim END
class NotWorking
endclass
END
v9.CheckScriptFailure(lines, 'E1316:')
lines =<< trim END
vim9script
class notWorking
endclass
END
v9.CheckScriptFailure(lines, 'E1314:')
lines =<< trim END
vim9script
class Not@working
endclass
END
v9.CheckScriptFailure(lines, 'E1315:')
lines =<< trim END
vim9script
abstract noclass Something
endclass
END
v9.CheckScriptFailure(lines, 'E475:')
lines =<< trim END
vim9script
abstract classy Something
endclass
END
v9.CheckScriptFailure(lines, 'E475:')
lines =<< trim END
vim9script
class Something
endcl
END
v9.CheckScriptFailure(lines, 'E1065:')
lines =<< trim END
vim9script
class Something
endclass school's out
END
v9.CheckScriptFailure(lines, 'E488:')
lines =<< trim END
vim9script
class Something
endclass | echo 'done'
END
v9.CheckScriptFailure(lines, 'E488:')
lines =<< trim END
vim9script
class Something
this
endclass
END
v9.CheckScriptFailure(lines, 'E1317:')
lines =<< trim END
vim9script
class Something
this.
endclass
END
v9.CheckScriptFailure(lines, 'E1317:')
lines =<< trim END
vim9script
class Something
this .count
endclass
END
v9.CheckScriptFailure(lines, 'E1317:')
lines =<< trim END
vim9script
class Something
this. count
endclass
END
v9.CheckScriptFailure(lines, 'E1317:')
lines =<< trim END
vim9script
class Something
this.count: number
that.count
endclass
END
v9.CheckScriptFailure(lines, 'E1318: Not a valid command in a class: that.count')
lines =<< trim END
vim9script
class Something
this.count
endclass
END
v9.CheckScriptFailure(lines, 'E1022:')
lines =<< trim END
vim9script
class Something
def new()
this.state = 0
enddef
endclass
var obj = Something.new()
END
v9.CheckScriptFailure(lines, 'E1089:')
lines =<< trim END
vim9script
class Something
this.count : number
endclass
END
v9.CheckScriptFailure(lines, 'E1059:')
lines =<< trim END
vim9script
class Something
this.count:number
endclass
END
v9.CheckScriptFailure(lines, 'E1069:')
lines =<< trim END
vim9script
class TextPosition
this.lnum: number
this.col: number
# make a nicely formatted string
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())
assert_equal(v:t_class, type(TextPosition))
assert_equal(v:t_object, type(pos))
assert_equal('class<TextPosition>', typename(TextPosition))
assert_equal('object<TextPosition>', typename(pos))
END
v9.CheckScriptSuccess(lines)
enddef
def Test_class_interface_wrong_end()
var lines =<< trim END
vim9script
abstract class SomeName
this.member = 'text'
endinterface
END
v9.CheckScriptFailure(lines, 'E476: Invalid command: endinterface, expected endclass')
lines =<< trim END
vim9script
export interface AnotherName
this.member: string
endclass
END
v9.CheckScriptFailure(lines, 'E476: Invalid command: endclass, expected endinterface')
enddef
def Test_class_member_initializer()
var lines =<< trim END
vim9script
class TextPosition
this.lnum: