@@ -4,18 +4,32 @@ import v.util.diff
44
55const vroot = os.real_path (@VMODROOT)
66const tmp_dir = os.real_path (os.temp_dir ())
7+ const text_file = os.join_path (vroot, 'vlib' , 'v' , 'tests' , 'vls' , 'sample_text.vv' )
78
8- const text_file_orig = os.join_path (vroot, 'vlib' , 'v' , 'tests' , 'vls' , 'sample_text.vv' )
9- const text_file = os.join_path (tmp_dir, 'sample_text.v' )
10- const text_file_result = $if windows { text_file.replace ('\\ ' , '/' ) } $else { text_file }
9+ const autocomplete_info_for_mod_sample_mod1 = '{"details" : [
10+ {"kind":3,"label":"public_fn1","detail":"string","documentation":""},
11+ {"kind":22,"label":"PublicStruct1","detail":"","documentation":""},
12+ {"kind":13,"label":"PublicEnum1","detail":"","documentation":""},
13+ {"kind":8,"label":"PublicInterface1","detail":"","documentation":""},
14+ {"kind":7,"label":"PublicAlias1_1","detail":"","documentation":""},
15+ {"kind":7,"label":"PublicAlias1_2","detail":"","documentation":""},
16+ {"kind":21,"label":"public_const1","detail":"","documentation":""}
17+ ]}'
1118
12- fn testsuite_begin () {
13- eprintln ('testsuite_begin, text_file = ${text_file} ' )
14- os.cp (text_file_orig, text_file) or { panic (err) }
15- }
19+ const autocomplete_info_for_mod_sample_mod2 = '{"details" : [
20+ {"kind":3,"label":"public_fn2","detail":"string","documentation":""},
21+ {"kind":22,"label":"PublicStruct2","detail":"","documentation":""},
22+ {"kind":13,"label":"PublicEnum2","detail":"","documentation":""},
23+ {"kind":8,"label":"PublicInterface2","detail":"","documentation":""},
24+ {"kind":7,"label":"PublicAlias2","detail":"","documentation":""},
25+ {"kind":21,"label":"public_const2","detail":"","documentation":""}
26+ ]}'
1627
17- fn testsuite_end () {
18- }
28+ const autocomplete_info_for_mod_struct = '{"details" : [
29+ {"kind":5,"label":"a","detail":"int","documentation":""},
30+ {"kind":5,"label":"b","detail":"string","documentation":""},
31+ {"kind":2,"label":"add","detail":"void","documentation":""}
32+ ]}'
1933
2034struct TestData {
2135 cmd string
@@ -24,110 +38,144 @@ struct TestData {
2438
2539const test_data = [
2640 TestData{
27- cmd: 'v -check -json-errors -nocolor -vls-mode -line-info "${text_file} :18:3" ${os.quoted_path(text_file)} '
28- output: '{"details" : [
29- {"kind":3,"label":"public_fn1","detail":"string","documentation":""},
30- {"kind":22,"label":"PublicStruct1","detail":"","documentation":""},
31- {"kind":13,"label":"PublicEnum1","detail":"","documentation":""},
32- {"kind":8,"label":"PublicInterface1","detail":"","documentation":""},
33- {"kind":7,"label":"PublicAlias1_1","detail":"","documentation":""},
34- {"kind":7,"label":"PublicAlias1_2","detail":"","documentation":""},
35- {"kind":21,"label":"public_const1","detail":"","documentation":""}
36- ]}'
41+ cmd: 'v -check -json-errors -nocolor -vls-mode -line-info "${text_file} :19:3" ${os.quoted_path(text_file)} '
42+ output: autocomplete_info_for_mod_sample_mod1
43+ },
44+ TestData{
45+ cmd: 'v -check -json-errors -nocolor -vls-mode -line-info "${text_file} :20:13" ${os.quoted_path(text_file)} '
46+ output: autocomplete_info_for_mod_sample_mod2
47+ },
48+ TestData{
49+ cmd: 'v -check -json-errors -nocolor -vls-mode -line-info "${text_file} :22:3" ${os.quoted_path(text_file)} '
50+ output: autocomplete_info_for_mod_struct
51+ },
52+ TestData{
53+ cmd: 'v -check -json-errors -nocolor -vls-mode -line-info "${text_file} :23:3" ${os.quoted_path(text_file)} '
54+ output: autocomplete_info_for_mod_sample_mod1
55+ },
56+ TestData{
57+ cmd: 'v -check -json-errors -nocolor -vls-mode -line-info "${text_file} :26:28" ${os.quoted_path(text_file)} '
58+ output: autocomplete_info_for_mod_sample_mod1
59+ },
60+ TestData{
61+ cmd: 'v -check -json-errors -nocolor -vls-mode -line-info "${text_file} :27:8" ${os.quoted_path(text_file)} '
62+ output: ''
63+ },
64+ TestData{
65+ cmd: 'v -check -json-errors -nocolor -vls-mode -line-info "${text_file} :28:9" ${os.quoted_path(text_file)} '
66+ output: 'unresolved type, maybe "builtin" was not defined. otherwise this is a bug, should never happen; please report'
3767 },
3868 TestData{
3969 cmd: 'v -w -vls-mode -check -json-errors ${os.quoted_path(text_file)} '
4070 output: '[
4171{
4272"path":"${text_file} ",
43- "message":"undefined ident: `a `",
44- "line_nr":14 ,
73+ "message":"unexpected token `:=`, expecting `) `",
74+ "line_nr":26 ,
4575"col":4,
4676"len":0
4777}
4878,
4979{
5080"path":"${text_file} ",
51- "message":"operator `+=` not defined on left operand type `void`",
52- "line_nr":14,
53- "col":4,
81+ "message":"unexpected name `strings`, expecting `)`",
82+ "line_nr":27,
83+ "col":2,
84+ "len":0
85+ }
86+ ,
87+ {
88+ "path":"${text_file} ",
89+ "message":"undefined ident: ``",
90+ "line_nr":19,
91+ "col":3,
92+ "len":0
93+ }
94+ ,
95+ {
96+ "path":"${text_file} ",
97+ "message":"undefined ident: ``",
98+ "line_nr":20,
99+ "col":13,
54100"len":0
55101}
56102,
57103{
58104"path":"${text_file} ",
59- "message":"cannot assign to `a`: expected `void`, not `int `",
60- "line_nr":14 ,
61- "col":9 ,
105+ "message":"undefined ident: ` `",
106+ "line_nr":23 ,
107+ "col":3 ,
62108"len":0
63109}
64110,
65111{
66112"path":"${text_file} ",
67- "message":"undefined ident: `s`",
68- "line_nr":18,
113+ "message":"cannot use `main.MyS` as `string` in argument 1 to `string.all_before_last`",
114+ "line_nr":26,
115+ "col":2,
116+ "len":0
117+ }
118+ ,
119+ {
120+ "path":"${text_file} ",
121+ "message":"undefined ident: ``",
122+ "line_nr":26,
123+ "col":28,
124+ "len":0
125+ }
126+ ,
127+ {
128+ "path":"${text_file} ",
129+ "message":"`` (no value) used as value in argument 1 to `string.all_before_last`",
130+ "line_nr":26,
131+ "col":27,
132+ "len":0
133+ }
134+ ,
135+ {
136+ "path":"${text_file} ",
137+ "message":"`string` has no property ``",
138+ "line_nr":26,
139+ "col":11,
140+ "len":0
141+ }
142+ ,
143+ {
144+ "path":"${text_file} ",
145+ "message":"undefined ident: `builtin`",
146+ "line_nr":28,
147+ "col":2,
148+ "len":0
149+ }
150+ ,
151+ {
152+ "path":"${text_file} ",
153+ "message":"`builtin` does not return a value",
154+ "line_nr":28,
69155"col":2,
70156"len":0
71157}
72158]
73- '
74- },
75- TestData{
76- cmd: 'v -check -nocolor -vls-mode ${os.quoted_path(text_file)} '
77- output: '${text_file_result} :14:4: error: undefined ident: `a`
78- 12 | // add add `val` to `a`
79- 13 | fn (mut m MyS) add(val int) {
80- 14 | m.a += val
81- | ^
82- 15 | }
83- 16 |
84- ${text_file_result} :14:4: error: operator `+=` not defined on left operand type `void`
85- 12 | // add add `val` to `a`
86- 13 | fn (mut m MyS) add(val int) {
87- 14 | m.a += val
88- | ^
89- 15 | }
90- 16 |
91- ${text_file_result} :14:9: error: cannot assign to `a`: expected `void`, not `int`
92- 12 | // add add `val` to `a`
93- 13 | fn (mut m MyS) add(val int) {
94- 14 | m.a += val
95- | ~~~
96- 15 | }
97- 16 |
98- ${text_file_result} :18:2: error: undefined ident: `s`
99- 16 |
100- 17 | fn main() {
101- 18 | s.
102- | ^
103- 19 | //sample_mod2.
104- 20 | //mut k := MyS{}
105- ${text_file_result} :5:8: warning: module \' sample_mod2 (v.tests.vls.sample_mod2)\' is imported but never used
106- 3 |
107- 4 | import v.tests.vls.sample_mod1 as s
108- 5 | import v.tests.vls.sample_mod2
109- | ~~~~~~~~~~~~~~~~~~~~~~~
110- 6 |
111- 7 | struct MyS{
112159'
113160 },
114161]
115162
116163fn test_main () {
117164 mut total_errors := 0
118165
166+ dump (text_file)
119167 for t in test_data {
120168 res := os.execute (t.cmd)
121169 if res.exit_code < 0 {
122170 println ('fail execute ${t.cmd} ' )
123171 panic (res.output)
124172 }
125173 res_output := $if windows {
126- res.output.replace ('\r\n ' , '\n ' )
174+ res.output.replace ('\r\n ' , '\n ' ). trim_space ()
127175 } $else {
128- res.output
176+ res.output. trim_space ()
129177 }
130- if t.output != res_output {
178+ if t.output. trim_space () != res_output {
131179 println ('${term.red('FAIL')} ${t.cmd} ' )
132180 if diff_ := diff.compare_text (t.output, res_output) {
133181 println (term.header ('difference:' , '-' ))
0 commit comments