|
91 | 91 | import io.sf.carte.doc.style.css.property.LexicalValue; |
92 | 92 | import io.sf.carte.doc.style.css.property.NumberValue; |
93 | 93 | import io.sf.carte.doc.style.css.property.StyleValue; |
94 | | -import io.sf.carte.doc.style.css.property.VarValue; |
95 | 94 | import nu.validator.htmlparser.common.XmlViolationPolicy; |
96 | 95 | import nu.validator.htmlparser.sax.HtmlParser; |
97 | 96 |
|
@@ -304,29 +303,48 @@ public void testUsageNativeDOM() throws Exception { |
304 | 303 |
|
305 | 304 | // Check the primitive type |
306 | 305 | CSSValue.Type primiType1 = color.getPrimitiveType(); |
307 | | - // It is a var() |
308 | | - assertEquals(CSSValue.Type.VAR, primiType1); |
| 306 | + // It is a LEXICAL value (var() or attr()) |
| 307 | + assertEquals(CSSValue.Type.LEXICAL, primiType1); |
| 308 | + |
309 | 309 | // Obtain the custom property name |
310 | | - VarValue varValue = (VarValue) color; |
311 | | - String customPropertyName = varValue.getName(); |
| 310 | + LexicalValue varValue = (LexicalValue) color; |
| 311 | + LexicalUnit lexUnit = varValue.getLexicalUnit(); |
| 312 | + // It is a var() |
| 313 | + assertEquals(LexicalType.VAR, lexUnit.getLexicalUnitType()); |
| 314 | + |
| 315 | + // Obtain function parameters |
| 316 | + LexicalUnit param = lexUnit.getParameters(); |
| 317 | + // Let's see its unit type |
| 318 | + LexicalType luType = param.getLexicalUnitType(); |
| 319 | + // It is IDENT (identifier) |
| 320 | + assertEquals(LexicalType.IDENT, param.getLexicalUnitType()); |
| 321 | + String customPropertyName = param.getStringValue(); |
312 | 322 | // Name is --myColor |
313 | 323 | assertEquals("--myColor", customPropertyName); |
314 | 324 |
|
| 325 | + // Continue with the lexical chain |
| 326 | + param = param.getNextLexicalUnit(); |
| 327 | + // Let's see its unit type |
| 328 | + luType = param.getLexicalUnitType(); |
| 329 | + // It is OPERATOR_COMMA |
| 330 | + assertEquals(LexicalType.OPERATOR_COMMA, param.getLexicalUnitType()); |
| 331 | + |
315 | 332 | // In this case we have a fallback value (otherwise next line returns null) |
316 | | - LexicalUnit lexUnit = varValue.getFallback(); |
| 333 | + param = param.getNextLexicalUnit(); |
317 | 334 | // Let's see its unit type |
318 | | - LexicalType luType = lexUnit.getLexicalUnitType(); |
| 335 | + luType = param.getLexicalUnitType(); |
319 | 336 | // It is a RGBCOLOR |
320 | 337 | assertEquals(LexicalType.RGBCOLOR, luType); |
321 | 338 | // And the color is... |
322 | | - String strColor = lexUnit.getCssText(); |
| 339 | + String strColor = param.getCssText(); |
323 | 340 | // Is '#46f' |
324 | 341 | assertEquals("#46f", strColor); |
325 | 342 |
|
326 | 343 | // Access the color components: |
327 | 344 | // RGB colors are accessed as a rgb() function, so we retrieve |
328 | | - // the function parameters: |
329 | | - LexicalUnit firstComponent = lexUnit.getParameters(); |
| 345 | + // the function parameters as a doubly-linked list: |
| 346 | + LexicalUnit firstComponent = param.getParameters(); |
| 347 | + |
330 | 348 | // Let's see the lexical type to see how we access the value |
331 | 349 | LexicalType firstLexUnitType = firstComponent.getLexicalUnitType(); |
332 | 350 | // It is a LexicalType.INTEGER (RGB components could be PERCENTAGE as well) |
|
0 commit comments