import HelderCore import Testing @Suite struct CSSGrammarTests { @Test("selectors, properties and values") func basics() { let text = ".btn:hover > a, #main { color: #fff; margin: 0 4px 1.5em; display: flex !important; }" #expect(role(".btn", in: text, .css) == .number) #expect(role(":hover", in: text, .css) == .keyword) #expect(role(">", in: text, .css) == .keyword) #expect(role("#main", in: text, .css) == .number) #expect(role("color", in: text, .css) == .variable) #expect(role("#fff", in: text, .css) == .number) #expect(role("4px", in: text, .css) == .number) #expect(role("1.5em", in: text, .css) == .number) #expect(role("flex", in: text, .css) == .string) #expect(role("!important", in: text, .css) == .keyword) } @Test("at-rules, functions, urls and custom properties") func atRulesAndFunctions() { let text = "@media (max-width: 600px) {\n nav { background: url(img/x.png); width: calc(100% - var(--gap)); }\n}" #expect(role("@media", in: text, .css) == .keyword) #expect(role("img/x.png", in: text, .css) == .string) #expect(role("calc", in: text, .css) == .plain) #expect(role("100%", in: text, .css) == .number) #expect(role("--gap", in: text, .css) == .variable) #expect(role("nav", in: text, .css) == .number) } @Test("SCSS nesting tells a nested selector from a declaration") func scssNesting() { let text = ".card {\n $pad: 4px;\n padding: $pad;\n &:hover {\n color: red;\n }\n}" #expect(role("$pad", in: text, .css) == .variable) #expect(role("padding", in: text, .css) == .variable) #expect(role("&", in: text, .css) == .keyword) #expect(role(":hover", in: text, .css) == .keyword) #expect(role("color", in: text, .css) == .variable) } @Test("a value may continue on the next line") func multiLineValue() { let text = "a {\n grid-template-areas:\n \"head head\"\n main;\n color: red;\n}" #expect(role("\"head head\"", in: text, .css) == .string) #expect(role("main", in: text, .css) == .string) #expect(role("color", in: text, .css) == .variable) } @Test("comments, including SCSS line comments") func comments() { let text = "/* a\n b */\n// scss\na { b: c; }" #expect(role(" b */", in: text, .css) == .comment) #expect(role("// scss", in: text, .css) == .comment) } }