@@ -44,39 +44,99 @@ final class MarkdownTokenizerComplexTests: XCTestCase {
4444 // MARK: - Complex Tests
4545
4646 func testComplexMarkdownStructures( ) {
47- let testCases : [ ( String , String ) ] = [
48- ( " # Heading with **bold** and *italic* " , " Heading with mixed formatting " ) ,
49- ( " Text with `inline code` and **bold** text " , " Mixed inline elements " ) ,
50- ( " Link with [text](url) and  " , " Links and images " ) ,
51- ( " List with - **bold** item and - *italic* item " , " Lists with formatting " ) ,
52- ( " Quote with > **bold** text and > *italic* text " , " Quotes with formatting " ) ,
53- ( " Math with $x = 1$ and code with `y = 2` " , " Math and code " ) ,
54- ( " HTML with <strong>bold</strong> and markdown **bold** " , " HTML and markdown " )
47+ let testCases : [ ( String , [ MarkdownTokenElement ] , String ) ] = [
48+ (
49+ " # Heading with **bold** and *italic* " ,
50+ [ . hash, . space, . text, . space, . text, . space, . asterisk, . asterisk, . text, . asterisk, . asterisk, . space, . text, . space, . asterisk, . text, . asterisk, . eof] ,
51+ " Heading with mixed formatting "
52+ ) ,
53+ (
54+ " Text with `inline code` and **bold** text " ,
55+ [ . text, . space, . text, . space, . inlineCode, . space, . text, . space, . asterisk, . asterisk, . text, . asterisk, . asterisk, . space, . text, . eof] ,
56+ " Mixed inline elements "
57+ ) ,
58+ (
59+ " Link with [text](url) and  " ,
60+ [ . text, . space, . text, . space, . leftBracket, . text, . rightBracket, . leftParen, . text, . rightParen, . space, . text, . space, . exclamation, . leftBracket, . text, . rightBracket, . leftParen, . text, . rightParen, . eof] ,
61+ " Links and images "
62+ ) ,
63+ (
64+ " List with - **bold** item and - *italic* item " ,
65+ [ . text, . space, . text, . space, . dash, . space, . asterisk, . asterisk, . text, . asterisk, . asterisk, . space, . text, . space, . text, . space, . dash, . space, . asterisk, . text, . asterisk, . space, . text, . eof] ,
66+ " Lists with formatting "
67+ ) ,
68+ (
69+ " Quote with > **bold** text and > *italic* text " ,
70+ [ . text, . space, . text, . space, . gt, . space, . asterisk, . asterisk, . text, . asterisk, . asterisk, . space, . text, . space, . text, . space, . gt, . space, . asterisk, . text, . asterisk, . space, . text, . eof] ,
71+ " Quotes with formatting "
72+ ) ,
73+ (
74+ " Math with $x = 1$ and code with `y = 2` " ,
75+ [ . text, . space, . text, . space, . formula, . space, . text, . space, . text, . space, . text, . space, . inlineCode, . eof] ,
76+ " Math and code "
77+ ) ,
78+ (
79+ " HTML with <strong>bold</strong> and markdown **bold** " ,
80+ [ . text, . space, . text, . space, . htmlBlock, . space, . text, . space, . text, . space, . asterisk, . asterisk, . text, . asterisk, . asterisk, . eof] ,
81+ " HTML and markdown "
82+ )
5583 ]
56-
57- for (input, description) in testCases {
84+
85+ for (input, expectedElements , description) in testCases {
5886 let tokens = tokenizer. tokenize ( input)
59- XCTAssertGreaterThan ( tokens . count , 1 , " Should tokenize: \( description ) " )
60- XCTAssertEqual ( tokens . last ? . element , . eof , " Should end with EOF : \( description) " )
87+ let actual = getTokenElements ( tokens )
88+ XCTAssertEqual ( actual , expectedElements , " Token sequence mismatch for : \( description) " )
6189 }
6290 }
6391
6492 func testMixedComplexSyntax( ) {
65- let testCases : [ ( String , String ) ] = [
66- ( " **Bold with `code` inside** " , " Bold with code " ) ,
67- ( " *Italic with **bold** inside* " , " Italic with bold " ) ,
68- ( " `Code with **bold** inside` " , " Code with bold " ) ,
69- ( " $Math with text inside$ " , " Math with text " ) ,
70- ( " <strong>HTML with `code` inside</strong> " , " HTML with code " ) ,
71- ( " <!-- Comment with **bold** inside --> " , " Comment with bold " ) ,
72- ( " & Entity with **bold** after " , " Entity with bold " ) ,
73- ( " # Heading with $math$ and [link](url) " , " Heading with math and link " )
93+ let testCases : [ ( String , [ MarkdownTokenElement ] , String ) ] = [
94+ (
95+ " **Bold with `code` inside** " ,
96+ [ . asterisk, . asterisk, . text, . space, . text, . space, . inlineCode, . space, . text, . asterisk, . asterisk, . eof] ,
97+ " Bold with code "
98+ ) ,
99+ (
100+ " *Italic with **bold** inside* " ,
101+ [ . asterisk, . text, . space, . text, . space, . asterisk, . asterisk, . text, . asterisk, . asterisk, . space, . text, . asterisk, . eof] ,
102+ " Italic with bold "
103+ ) ,
104+ (
105+ " `Code with **bold** inside` " ,
106+ [ . inlineCode, . eof] ,
107+ " Code with bold "
108+ ) ,
109+ (
110+ " $Math with text inside$ " ,
111+ [ . formula, . eof] ,
112+ " Math with text "
113+ ) ,
114+ (
115+ " <strong>HTML with `code` inside</strong> " ,
116+ [ . htmlBlock, . eof] ,
117+ " HTML with code "
118+ ) ,
119+ (
120+ " <!-- Comment with **bold** inside --> " ,
121+ [ . htmlComment, . eof] ,
122+ " Comment with bold "
123+ ) ,
124+ (
125+ " & Entity with **bold** after " ,
126+ [ . htmlEntity, . space, . text, . space, . text, . space, . asterisk, . asterisk, . text, . asterisk, . asterisk, . space, . text, . eof] ,
127+ " Entity with bold "
128+ ) ,
129+ (
130+ " # Heading with $math$ and [link](url) " ,
131+ [ . hash, . space, . text, . space, . text, . space, . formula, . space, . text, . space, . leftBracket, . text, . rightBracket, . leftParen, . text, . rightParen, . eof] ,
132+ " Heading with math and link "
133+ )
74134 ]
75-
76- for (input, description) in testCases {
135+
136+ for (input, expectedElements , description) in testCases {
77137 let tokens = tokenizer. tokenize ( input)
78- XCTAssertGreaterThan ( tokens . count , 1 , " Should tokenize: \( description ) " )
79- XCTAssertEqual ( tokens . last ? . element , . eof , " Should end with EOF : \( description) " )
138+ let actual = getTokenElements ( tokens )
139+ XCTAssertEqual ( actual , expectedElements , " Token sequence mismatch for : \( description) " )
80140 }
81141 }
82142
0 commit comments