@@ -59,6 +59,23 @@ withFixture('v4/basic', (c) => {
59
59
} )
60
60
}
61
61
62
+ function testInline ( fixture , { code, expected, language = 'html' } ) {
63
+ test ( fixture , async ( ) => {
64
+ let promise = new Promise ( ( resolve ) => {
65
+ c . onNotification ( 'textDocument/publishDiagnostics' , ( { diagnostics } ) => {
66
+ resolve ( diagnostics )
67
+ } )
68
+ } )
69
+
70
+ let doc = await c . openDocument ( { text : code , lang : language } )
71
+ let diagnostics = await promise
72
+
73
+ expected = JSON . parse ( JSON . stringify ( expected ) . replaceAll ( '{{URI}}' , doc . uri ) )
74
+
75
+ expect ( diagnostics ) . toEqual ( expected )
76
+ } )
77
+ }
78
+
62
79
testFixture ( 'css-conflict/simple' )
63
80
testFixture ( 'css-conflict/variants-negative' )
64
81
testFixture ( 'css-conflict/variants-positive' )
@@ -69,5 +86,171 @@ withFixture('v4/basic', (c) => {
69
86
// testFixture('css-conflict/css-multi-rule')
70
87
// testFixture('css-conflict/css-multi-prop')
71
88
// testFixture('invalid-screen/simple')
72
- // testFixture('invalid-theme/simple')
89
+
90
+ testInline ( 'simple typos in theme keys (in key)' , {
91
+ code : '.test { color: theme(--color-red-901) }' ,
92
+ language : 'css' ,
93
+ expected : [
94
+ {
95
+ code : 'invalidConfigPath' ,
96
+ range : { start : { line : 0 , character : 21 } , end : { line : 0 , character : 36 } } ,
97
+ severity : 1 ,
98
+ message : "'--color-red-901' does not exist in your theme. Did you mean '--color-red-900'?" ,
99
+ suggestions : [ '--color-red-900' ] ,
100
+ } ,
101
+ ] ,
102
+ } )
103
+
104
+ testInline ( 'simple typos in theme keys (in namespace)' , {
105
+ code : '.test { color: theme(--colors-red-901) }' ,
106
+ language : 'css' ,
107
+ expected : [
108
+ {
109
+ code : 'invalidConfigPath' ,
110
+ range : { start : { line : 0 , character : 21 } , end : { line : 0 , character : 37 } } ,
111
+ severity : 1 ,
112
+ message : "'--colors-red-901' does not exist in your theme. Did you mean '--color-red-900'?" ,
113
+ suggestions : [ '--color-red-900' ] ,
114
+ } ,
115
+ ] ,
116
+ } )
117
+
118
+ testInline ( 'No similar theme key exists' , {
119
+ code : '.test { color: theme(--font-obliqueness-90) }' ,
120
+ language : 'css' ,
121
+ expected : [
122
+ {
123
+ code : 'invalidConfigPath' ,
124
+ range : { start : { line : 0 , character : 21 } , end : { line : 0 , character : 42 } } ,
125
+ severity : 1 ,
126
+ message : "'--font-obliqueness-90' does not exist in your theme." ,
127
+ suggestions : [ ] ,
128
+ } ,
129
+ ] ,
130
+ } )
131
+
132
+ testInline ( 'valid theme keys dont issue diagnostics' , {
133
+ code : '.test { color: theme(--color-red-900) }' ,
134
+ language : 'css' ,
135
+ expected : [ ] ,
136
+ } )
137
+
138
+ testInline ( 'types in legacy theme config paths' , {
139
+ code : '.test { color: theme(colors.red.901) }' ,
140
+ language : 'css' ,
141
+ expected : [
142
+ {
143
+ code : 'invalidConfigPath' ,
144
+ range : { start : { line : 0 , character : 21 } , end : { line : 0 , character : 35 } } ,
145
+ severity : 1 ,
146
+ message : "'colors.red.901' does not exist in your theme config." ,
147
+ suggestions : [ ] ,
148
+ } ,
149
+ ] ,
150
+ } )
151
+
152
+ testInline ( 'valid legacy theme config paths' , {
153
+ code : '.test { color: theme(colors.red.900) }' ,
154
+ language : 'css' ,
155
+ expected : [ ] ,
156
+ } )
157
+ } )
158
+
159
+ withFixture ( 'v4/with-prefix' , ( c ) => {
160
+ function testInline ( fixture , { code, expected, language = 'html' } ) {
161
+ test ( fixture , async ( ) => {
162
+ let promise = new Promise ( ( resolve ) => {
163
+ c . onNotification ( 'textDocument/publishDiagnostics' , ( { diagnostics } ) => {
164
+ resolve ( diagnostics )
165
+ } )
166
+ } )
167
+
168
+ let doc = await c . openDocument ( { text : code , lang : language } )
169
+ let diagnostics = await promise
170
+
171
+ expected = JSON . parse ( JSON . stringify ( expected ) . replaceAll ( '{{URI}}' , doc . uri ) )
172
+
173
+ expect ( diagnostics ) . toEqual ( expected )
174
+ } )
175
+ }
176
+
177
+ // testFixture('css-conflict/simple')
178
+ // testFixture('css-conflict/variants-negative')
179
+ // testFixture('css-conflict/variants-positive')
180
+ // testFixture('css-conflict/jsx-concat-negative')
181
+ // testFixture('css-conflict/jsx-concat-positive')
182
+ // testFixture('css-conflict/vue-style-lang-sass')
183
+
184
+ // testFixture('css-conflict/css')
185
+ // testFixture('css-conflict/css-multi-rule')
186
+ // testFixture('css-conflict/css-multi-prop')
187
+ // testFixture('invalid-screen/simple')
188
+
189
+ testInline ( 'simple typos in theme keys (in key)' , {
190
+ code : '.test { color: theme(--color-red-901) }' ,
191
+ language : 'css' ,
192
+ expected : [
193
+ {
194
+ code : 'invalidConfigPath' ,
195
+ range : { start : { line : 0 , character : 21 } , end : { line : 0 , character : 36 } } ,
196
+ severity : 1 ,
197
+ message : "'--color-red-901' does not exist in your theme. Did you mean '--color-red-900'?" ,
198
+ suggestions : [ '--color-red-900' ] ,
199
+ } ,
200
+ ] ,
201
+ } )
202
+
203
+ testInline ( 'simple typos in theme keys (in namespace)' , {
204
+ code : '.test { color: theme(--colors-red-901) }' ,
205
+ language : 'css' ,
206
+ expected : [
207
+ {
208
+ code : 'invalidConfigPath' ,
209
+ range : { start : { line : 0 , character : 21 } , end : { line : 0 , character : 37 } } ,
210
+ severity : 1 ,
211
+ message : "'--colors-red-901' does not exist in your theme. Did you mean '--color-red-900'?" ,
212
+ suggestions : [ '--color-red-900' ] ,
213
+ } ,
214
+ ] ,
215
+ } )
216
+
217
+ testInline ( 'No similar theme key exists' , {
218
+ code : '.test { color: theme(--font-obliqueness-90) }' ,
219
+ language : 'css' ,
220
+ expected : [
221
+ {
222
+ code : 'invalidConfigPath' ,
223
+ range : { start : { line : 0 , character : 21 } , end : { line : 0 , character : 42 } } ,
224
+ severity : 1 ,
225
+ message : "'--font-obliqueness-90' does not exist in your theme." ,
226
+ suggestions : [ ] ,
227
+ } ,
228
+ ] ,
229
+ } )
230
+
231
+ testInline ( 'valid theme keys dont issue diagnostics' , {
232
+ code : '.test { color: theme(--color-red-900) }' ,
233
+ language : 'css' ,
234
+ expected : [ ] ,
235
+ } )
236
+
237
+ testInline ( 'types in legacy theme config paths' , {
238
+ code : '.test { color: theme(colors.red.901) }' ,
239
+ language : 'css' ,
240
+ expected : [
241
+ {
242
+ code : 'invalidConfigPath' ,
243
+ range : { start : { line : 0 , character : 21 } , end : { line : 0 , character : 35 } } ,
244
+ severity : 1 ,
245
+ message : "'colors.red.901' does not exist in your theme config." ,
246
+ suggestions : [ ] ,
247
+ } ,
248
+ ] ,
249
+ } )
250
+
251
+ testInline ( 'valid legacy theme config paths' , {
252
+ code : '.test { color: theme(colors.red.900) }' ,
253
+ language : 'css' ,
254
+ expected : [ ] ,
255
+ } )
73
256
} )
0 commit comments