57 lines
2.4 KiB
Swift
57 lines
2.4 KiB
Swift
import HelderCore
|
|
import Testing
|
|
|
|
@Suite struct MarkupGrammarTests {
|
|
@Test("tags, attributes, values and entities")
|
|
func basics() {
|
|
let text = "<a href=\"/x\" data-id=1 hidden>Tom & Jerry</a>"
|
|
#expect(paintedRuns(text, .markup) == [
|
|
"a:number", "href:variable", "\"/x\":string", "data-id:variable", "1:string", "hidden:variable",
|
|
"&:variable", "a:number",
|
|
])
|
|
}
|
|
|
|
@Test("comments, doctype and CDATA read as comments")
|
|
func comments() {
|
|
let text = "<!DOCTYPE html>\n<!-- a\n b -->\n<![CDATA[ x ]]>\n<p>"
|
|
#expect(role("<!DOCTYPE html>", in: text, .markup) == .comment)
|
|
#expect(role(" b -->", in: text, .markup) == .comment)
|
|
#expect(role("<![CDATA[ x ]]>", in: text, .markup) == .comment)
|
|
#expect(role("p", in: text, .markup) == .number)
|
|
}
|
|
|
|
@Test("a script body is JavaScript and a style body is CSS")
|
|
func embedded() {
|
|
let text = "<script>\nconst a = 1 // c\n</script>\n<style>\n.b { color: red; }\n</style>\n<p>const</p>"
|
|
#expect(role("const", in: text, .markup) == .keyword)
|
|
#expect(role("// c", in: text, .markup) == .comment)
|
|
#expect(role("script", in: text, .markup, occurrence: 1) == .number)
|
|
#expect(role(".b", in: text, .markup) == .number)
|
|
#expect(role("color", in: text, .markup) == .variable)
|
|
#expect(role("const", in: text, .markup, occurrence: 1) == .plain)
|
|
}
|
|
|
|
@Test("a JavaScript line comment stops at the closing script tag")
|
|
func scriptCloseInsideComment() {
|
|
let text = "<script>// x</script><p>"
|
|
#expect(role("// x", in: text, .markup) == .comment)
|
|
#expect(role("p", in: text, .markup) == .number)
|
|
}
|
|
|
|
@Test("a tag may wrap over lines, with a value that wraps too")
|
|
func multiLineTag() {
|
|
let text = "<img\n alt=\"a\n b\"\n src=\"x\">\nafter"
|
|
#expect(role(" b\"", in: text, .markup) == .string)
|
|
#expect(role("src", in: text, .markup) == .variable)
|
|
#expect(role("after", in: text, .markup) == .plain)
|
|
}
|
|
|
|
@Test("Vue single-file components read their script block")
|
|
func vue() {
|
|
let text = "<template><div :class=\"a\" @click=\"go\"/></template>\n<script setup>\nimport x from 'y'\n</script>"
|
|
#expect(role(":class", in: text, .markup) == .variable)
|
|
#expect(role("@click", in: text, .markup) == .variable)
|
|
#expect(role("import", in: text, .markup) == .keyword)
|
|
}
|
|
}
|