import HelderCore import Testing @Suite struct MarkdownGrammarTests { @Test("headings read as keywords") func headings() { #expect(role("## Title", in: "## Title\ntext", .markdown) == .keyword) #expect(role("#hashtag", in: "#hashtag", .markdown) == .plain) } @Test("a fenced block is highlighted in its own language and closes on its fence") func fencedCode() { let text = "```php\n$x = new Agent();\n```\nafter $x" #expect(role("```php", in: text, .markdown) == .comment) #expect(role("$x", in: text, .markdown) == .variable) #expect(role("new", in: text, .markdown) == .keyword) #expect(role("$x", in: text, .markdown, occurrence: 1) == .plain) } @Test("a fence in an unknown language stays plain") func unknownFence() { let text = "~~~text\nif x\n~~~" #expect(role("if x", in: text, .markdown) == .plain) } @Test("a fenced block comment carries over lines inside the fence") func fenceCarriesState() { let text = "```js\n/* a\nb */ let c\n```" #expect(role("b */", in: text, .markdown) == .comment) #expect(role("let", in: text, .markdown) == .keyword) } @Test("inline code, link targets and autolinks") func inline() { let text = "Use `npm test` and [docs](https://x.test) or ." #expect(role("`npm test`", in: text, .markdown) == .keyword) #expect(role("(https://x.test)", in: text, .markdown) == .variable) #expect(role("docs", in: text, .markdown) == .plain) #expect(role("", in: text, .markdown) == .variable) } @Test("list markers, quotes and rules read as punctuation") func punctuation() { let text = "- one\n1. two\n> quote\n---" #expect(role("-", in: text, .markdown) == .comment) #expect(role("1.", in: text, .markdown) == .comment) #expect(role(">", in: text, .markdown) == .comment) #expect(role("---", in: text, .markdown) == .comment) } }