4
4
"fmt"
5
5
"os"
6
6
"path/filepath"
7
+ "slices"
7
8
"strings"
8
9
"testing"
9
10
@@ -52,15 +53,15 @@ services:
52
53
},
53
54
},
54
55
{
55
- name : "attribute recurses upwards" ,
56
+ name : "attribute recurses upwards for a match " ,
56
57
content : `
57
58
services:
58
59
web:
59
60
attach: true
60
61
web2:
61
62
extends: web
62
63
web3:
63
- extends: web
64
+ extends: web2
64
65
attach: false` ,
65
66
inlayHints : []protocol.InlayHint {
66
67
{
@@ -70,6 +71,60 @@ services:
70
71
},
71
72
},
72
73
},
74
+ {
75
+ name : "extension at different levels have the right value" ,
76
+ content : `
77
+ services:
78
+ web:
79
+ hostname: hostname1
80
+ web2:
81
+ extends: web
82
+ hostname: hostname2
83
+ web3:
84
+ extends: web2
85
+ hostname: hostname3` ,
86
+ inlayHints : []protocol.InlayHint {
87
+ {
88
+ Label : "(parent value: hostname1)" ,
89
+ PaddingLeft : types .CreateBoolPointer (true ),
90
+ Position : protocol.Position {Line : 6 , Character : 23 },
91
+ },
92
+ {
93
+ Label : "(parent value: hostname2)" ,
94
+ PaddingLeft : types .CreateBoolPointer (true ),
95
+ Position : protocol.Position {Line : 9 , Character : 23 },
96
+ },
97
+ },
98
+ },
99
+ {
100
+ name : "self recursion returns nothing" ,
101
+ content : `
102
+ services:
103
+ web:
104
+ hostname: hostname1
105
+ extends: web2` ,
106
+ inlayHints : []protocol.InlayHint {},
107
+ },
108
+ {
109
+ name : "self recursion does not affect other hints" ,
110
+ content : `
111
+ services:
112
+ web:
113
+ hostname: hostname1
114
+ web2:
115
+ extends: web
116
+ hostname: hostname2
117
+ web3:
118
+ extends: web3
119
+ hostname: hostname3` ,
120
+ inlayHints : []protocol.InlayHint {
121
+ {
122
+ Label : "(parent value: hostname1)" ,
123
+ PaddingLeft : types .CreateBoolPointer (true ),
124
+ Position : protocol.Position {Line : 6 , Character : 23 },
125
+ },
126
+ },
127
+ },
73
128
{
74
129
name : "extends as an object but without a file attribute" ,
75
130
content : `
@@ -118,6 +173,19 @@ services:
118
173
},
119
174
},
120
175
},
176
+ {
177
+ name : "unmatched tree structure should not render any hints" ,
178
+ content : `
179
+ services:
180
+ web:
181
+ build: .
182
+ context: abc
183
+ web2:
184
+ extends: web
185
+ build:
186
+ context: def` ,
187
+ inlayHints : []protocol.InlayHint {},
188
+ },
121
189
{
122
190
name : "sub-attributes unsupported" ,
123
191
content : `
@@ -138,6 +206,9 @@ services:
138
206
t .Run (tc .name , func (t * testing.T ) {
139
207
doc := document .NewComposeDocument (u , 1 , []byte (tc .content ))
140
208
inlayHints , err := InlayHint (doc , protocol.Range {})
209
+ slices .SortFunc (inlayHints , func (a protocol.InlayHint , b protocol.InlayHint ) int {
210
+ return int (a .Position .Line ) - int (b .Position .Line )
211
+ })
141
212
require .NoError (t , err )
142
213
require .Equal (t , tc .inlayHints , inlayHints )
143
214
})
0 commit comments