annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Test Vim9 classes
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 source check.vim
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 import './vim9.vim' as v9
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 def Test_class_basic()
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 var lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 class NotWorking
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 v9.CheckScriptFailure(lines, 'E1316:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 class notWorking
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 v9.CheckScriptFailure(lines, 'E1314:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 class Not@working
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 v9.CheckScriptFailure(lines, 'E1315:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 abstract noclass Something
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 v9.CheckScriptFailure(lines, 'E475:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 abstract classy Something
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 v9.CheckScriptFailure(lines, 'E475:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 class Something
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 endcl
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 v9.CheckScriptFailure(lines, 'E1065:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 class Something
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 endclass school's out
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 v9.CheckScriptFailure(lines, 'E488:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 class Something
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 endclass | echo 'done'
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 v9.CheckScriptFailure(lines, 'E488:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 class Something
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 this
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 v9.CheckScriptFailure(lines, 'E1317:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 class Something
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 this.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 v9.CheckScriptFailure(lines, 'E1317:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 class Something
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 this .count
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 v9.CheckScriptFailure(lines, 'E1317:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 class Something
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 this. count
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 v9.CheckScriptFailure(lines, 'E1317:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 class Something
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 this.count: number
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 that.count
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 v9.CheckScriptFailure(lines, 'E1318: Not a valid command in a class: that.count')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 class Something
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 this.count
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 v9.CheckScriptFailure(lines, 'E1022:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 class Something
31517
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
114 def new()
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
115 this.state = 0
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
116 enddef
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
117 endclass
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
118 var obj = Something.new()
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
119 END
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
120 v9.CheckScriptFailure(lines, 'E1089:')
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
121
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
122 lines =<< trim END
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
123 vim9script
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
124 class Something
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 this.count : number
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 v9.CheckScriptFailure(lines, 'E1059:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 class Something
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 this.count:number
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 v9.CheckScriptFailure(lines, 'E1069:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 class TextPosition
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 this.lnum: number
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
143 this.col: number
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31404
diff changeset
144
31501
560ba934725f patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents: 31483
diff changeset
145 # make a nicely formatted string
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31404
diff changeset
146 def ToString(): string
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31404
diff changeset
147 return $'({this.lnum}, {this.col})'
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31404
diff changeset
148 enddef
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150
31404
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
151 # use the automatically generated new() method
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
152 var pos = TextPosition.new(2, 12)
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
153 assert_equal(2, pos.lnum)
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
154 assert_equal(12, pos.col)
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31404
diff changeset
155
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31404
diff changeset
156 # call an object method
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31404
diff changeset
157 assert_equal('(2, 12)', pos.ToString())
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 v9.CheckScriptSuccess(lines)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 enddef
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
162 def Test_class_member_initializer()
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
163 var lines =<< trim END
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
164 vim9script
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
165
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
166 class TextPosition
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
167 this.lnum: number = 1
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
168 this.col: number = 1
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
169
31501
560ba934725f patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents: 31483
diff changeset
170 # constructor with only the line number
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
171 def new(lnum: number)
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
172 this.lnum = lnum
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
173 enddef
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
174 endclass
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
175
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
176 var pos = TextPosition.new(3)
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
177 assert_equal(3, pos.lnum)
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
178 assert_equal(1, pos.col)
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
179
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
180 var instr = execute('disassemble TextPosition.new')
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
181 assert_match('new\_s*' ..
31426
92afb904fbee patch 9.0.1046: class method disassemble test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 31424
diff changeset
182 '0 NEW TextPosition size \d\+\_s*' ..
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
183 '\d PUSHNR 1\_s*' ..
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
184 '\d STORE_THIS 0\_s*' ..
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
185 '\d PUSHNR 1\_s*' ..
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
186 '\d STORE_THIS 1\_s*' ..
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
187 'this.lnum = lnum\_s*' ..
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
188 '\d LOAD arg\[-1]\_s*' ..
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
189 '\d PUSHNR 0\_s*' ..
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
190 '\d LOAD $0\_s*' ..
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
191 '\d\+ STOREINDEX object\_s*' ..
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
192 '\d\+ RETURN object.*',
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
193 instr)
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
194 END
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
195 v9.CheckScriptSuccess(lines)
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
196 enddef
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
197
31441
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
198 def Test_class_default_new()
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
199 var lines =<< trim END
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
200 vim9script
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
201
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
202 class TextPosition
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
203 this.lnum: number = 1
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
204 this.col: number = 1
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
205 endclass
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
206
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
207 var pos = TextPosition.new()
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
208 assert_equal(1, pos.lnum)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
209 assert_equal(1, pos.col)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
210
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
211 pos = TextPosition.new(v:none, v:none)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
212 assert_equal(1, pos.lnum)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
213 assert_equal(1, pos.col)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
214
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
215 pos = TextPosition.new(3, 22)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
216 assert_equal(3, pos.lnum)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
217 assert_equal(22, pos.col)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
218
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
219 pos = TextPosition.new(v:none, 33)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
220 assert_equal(1, pos.lnum)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
221 assert_equal(33, pos.col)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
222 END
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
223 v9.CheckScriptSuccess(lines)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
224
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
225 lines =<< trim END
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
226 vim9script
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
227 class Person
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
228 this.name: string
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
229 this.age: number = 42
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
230 this.education: string = "unknown"
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
231
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
232 def new(this.name, this.age = v:none, this.education = v:none)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
233 enddef
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
234 endclass
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
235
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
236 var piet = Person.new("Piet")
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
237 assert_equal("Piet", piet.name)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
238 assert_equal(42, piet.age)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
239 assert_equal("unknown", piet.education)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
240
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
241 var chris = Person.new("Chris", 4, "none")
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
242 assert_equal("Chris", chris.name)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
243 assert_equal(4, chris.age)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
244 assert_equal("none", chris.education)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
245 END
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
246 v9.CheckScriptSuccess(lines)
31443
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
247
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
248 lines =<< trim END
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
249 vim9script
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
250 class Person
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
251 this.name: string
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
252 this.age: number = 42
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
253 this.education: string = "unknown"
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
254
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
255 def new(this.name, this.age = v:none, this.education = v:none)
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
256 enddef
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
257 endclass
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
258
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
259 var missing = Person.new()
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
260 END
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
261 v9.CheckScriptFailure(lines, 'E119:')
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
262 enddef
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
263
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
264 def Test_class_object_member_inits()
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
265 var lines =<< trim END
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
266 vim9script
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
267 class TextPosition
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
268 this.lnum: number
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
269 this.col = 1
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
270 this.addcol: number = 2
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
271 endclass
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
272
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
273 var pos = TextPosition.new()
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
274 assert_equal(0, pos.lnum)
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
275 assert_equal(1, pos.col)
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
276 assert_equal(2, pos.addcol)
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
277 END
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
278 v9.CheckScriptSuccess(lines)
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
279
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
280 lines =<< trim END
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
281 vim9script
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
282 class TextPosition
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
283 this.lnum
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
284 this.col = 1
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
285 endclass
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
286 END
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
287 v9.CheckScriptFailure(lines, 'E1022:')
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
288
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
289 lines =<< trim END
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
290 vim9script
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
291 class TextPosition
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
292 this.lnum = v:none
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
293 this.col = 1
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
294 endclass
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
295 END
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
296 v9.CheckScriptFailure(lines, 'E1330:')
31441
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
297 enddef
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
298
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
299 def Test_class_object_member_access()
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
300 var lines =<< trim END
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
301 vim9script
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
302 class Triple
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
303 this._one = 1
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
304 this.two = 2
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
305 public this.three = 3
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
306
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
307 def GetOne(): number
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
308 return this._one
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
309 enddef
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
310 endclass
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
311
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
312 var trip = Triple.new()
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
313 assert_equal(1, trip.GetOne())
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
314 assert_equal(2, trip.two)
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
315 assert_equal(3, trip.three)
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
316 assert_fails('echo trip._one', 'E1333')
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
317
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
318 assert_fails('trip._one = 11', 'E1333')
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
319 assert_fails('trip.two = 22', 'E1335')
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
320 trip.three = 33
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
321 assert_equal(33, trip.three)
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
322
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
323 assert_fails('trip.four = 4', 'E1334')
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
324 END
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
325 v9.CheckScriptSuccess(lines)
31521
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
326
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
327 lines =<< trim END
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
328 vim9script
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
329
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
330 class MyCar
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
331 this.make: string
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
332
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
333 def new(make_arg: string)
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
334 this.make = make_arg
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
335 enddef
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
336
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
337 def GetMake(): string
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
338 return $"make = {this.make}"
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
339 enddef
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
340 endclass
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
341
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
342 var c = MyCar.new("abc")
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
343 assert_equal('make = abc', c.GetMake())
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
344
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
345 c = MyCar.new("def")
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
346 assert_equal('make = def', c.GetMake())
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
347
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
348 var c2 = MyCar.new("123")
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
349 assert_equal('make = 123', c2.GetMake())
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
350 END
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
351 v9.CheckScriptSuccess(lines)
31525
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
352
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
353 lines =<< trim END
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
354 vim9script
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
355
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
356 class MyCar
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
357 this.make: string
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
358
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
359 def new(make_arg: string)
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
360 this.make = make_arg
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
361 enddef
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
362 endclass
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
363
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
364 var c = MyCar.new("abc")
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
365 var c = MyCar.new("def")
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
366 END
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
367 v9.CheckScriptFailure(lines, 'E1041:')
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
368 enddef
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
369
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
370 def Test_class_member_access()
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
371 var lines =<< trim END
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
372 vim9script
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
373 class TextPos
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
374 this.lnum = 1
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
375 this.col = 1
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
376 static counter = 0
31580
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
377 static _secret = 7
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
378 public static anybody = 42
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
379
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
380 static def AddToCounter(nr: number)
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
381 counter += nr
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
382 enddef
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
383 endclass
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
384
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
385 assert_equal(0, TextPos.counter)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
386 TextPos.AddToCounter(3)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
387 assert_equal(3, TextPos.counter)
31517
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
388 assert_fails('echo TextPos.noSuchMember', 'E1338:')
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
389
31517
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
390 assert_fails('TextPos.noSuchMember = 2', 'E1337:')
31580
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
391 assert_fails('TextPos.counter = 5', 'E1335:')
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
392 assert_fails('TextPos.counter += 5', 'E1335:')
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
393
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
394 assert_fails('echo TextPos._secret', 'E1333:')
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
395 assert_fails('TextPos._secret = 8', 'E1333:')
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
396
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
397 assert_equal(42, TextPos.anybody)
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
398 TextPos.anybody = 12
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
399 assert_equal(12, TextPos.anybody)
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
400 TextPos.anybody += 5
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
401 assert_equal(17, TextPos.anybody)
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
402 END
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
403 v9.CheckScriptSuccess(lines)
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
404 enddef
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
405
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
406 def Test_class_function()
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
407 var lines =<< trim END
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
408 vim9script
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
409 class Value
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
410 this.value = 0
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
411 static objects = 0
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
412
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
413 def new(v: number)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
414 this.value = v
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
415 ++objects
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
416 enddef
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
417
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
418 static def GetCount(): number
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
419 return objects
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
420 enddef
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
421 endclass
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
422
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
423 assert_equal(0, Value.GetCount())
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
424 var v1 = Value.new(2)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
425 assert_equal(1, Value.GetCount())
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
426 var v2 = Value.new(7)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
427 assert_equal(2, Value.GetCount())
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
428 END
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
429 v9.CheckScriptSuccess(lines)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
430 enddef
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
431
31451
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
432 def Test_class_object_to_string()
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
433 var lines =<< trim END
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
434 vim9script
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
435 class TextPosition
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
436 this.lnum = 1
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
437 this.col = 22
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
438 endclass
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
439
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
440 assert_equal("class TextPosition", string(TextPosition))
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
441
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
442 var pos = TextPosition.new()
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
443 assert_equal("object of TextPosition {lnum: 1, col: 22}", string(pos))
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
444 END
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
445 v9.CheckScriptSuccess(lines)
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
446 enddef
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447
31443
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
448
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker