@@ -73,4 +73,147 @@ class AsideTests: XCTestCase {
73
73
XCTAssertTrue ( aside. content [ 0 ] . root. isIdentical ( to: document) )
74
74
}
75
75
76
+ func testConversionStrategySingleWord( ) throws {
77
+ do {
78
+ let source = """
79
+ > This is a regular block quote.
80
+ """
81
+ let document = Document ( parsing: source)
82
+ let blockQuote = document. child ( at: 0 ) as! BlockQuote
83
+ XCTAssertNil ( Aside ( blockQuote, tagRequirement: . requireSingleWordTag) )
84
+ }
85
+
86
+ do {
87
+ let source = " > See Also: A different topic. "
88
+ let document = Document ( parsing: source)
89
+ let blockQuote = document. child ( at: 0 ) as! BlockQuote
90
+ XCTAssertNil ( Aside ( blockQuote, tagRequirement: . requireSingleWordTag) )
91
+ }
92
+
93
+ do {
94
+ let source = " > Important: This is an aside. "
95
+ let expectedRootDump = """
96
+ Document @/path/to/some-file.md:1:1-/path/to/some-file.md:1:31
97
+ └─ BlockQuote @/path/to/some-file.md:1:1-/path/to/some-file.md:1:31
98
+ └─ Paragraph @/path/to/some-file.md:1:3-/path/to/some-file.md:1:31
99
+ └─ Text @/path/to/some-file.md:1:14-/path/to/some-file.md:1:31 " This is an aside. "
100
+ """
101
+ try assertAside (
102
+ source: source,
103
+ conversionStrategy: . requireSingleWordTag,
104
+ expectedKind: . init( rawValue: " Important " ) !,
105
+ expectedRootDump: expectedRootDump)
106
+ }
107
+ }
108
+
109
+ func testConversionStrategyMultipleWords( ) throws {
110
+ do {
111
+ let source = """
112
+ > This is a regular block quote.
113
+ """
114
+ let document = Document ( parsing: source)
115
+ let blockQuote = document. child ( at: 0 ) as! BlockQuote
116
+ XCTAssertNil ( Aside ( blockQuote, tagRequirement: . requireAnyLengthTag) )
117
+ }
118
+
119
+ do {
120
+ let source = " > See Also: A different topic. "
121
+ let expectedRootDump = """
122
+ Document @/path/to/some-file.md:1:1-/path/to/some-file.md:1:31
123
+ └─ BlockQuote @/path/to/some-file.md:1:1-/path/to/some-file.md:1:31
124
+ └─ Paragraph @/path/to/some-file.md:1:3-/path/to/some-file.md:1:31
125
+ └─ Text @/path/to/some-file.md:1:13-/path/to/some-file.md:1:31 " A different topic. "
126
+ """
127
+ try assertAside (
128
+ source: source,
129
+ conversionStrategy: . requireAnyLengthTag,
130
+ expectedKind: . init( rawValue: " See Also " ) !,
131
+ expectedRootDump: expectedRootDump)
132
+ }
133
+
134
+ do {
135
+ let source = " > Important: This is an aside. "
136
+ let expectedRootDump = """
137
+ Document @/path/to/some-file.md:1:1-/path/to/some-file.md:1:31
138
+ └─ BlockQuote @/path/to/some-file.md:1:1-/path/to/some-file.md:1:31
139
+ └─ Paragraph @/path/to/some-file.md:1:3-/path/to/some-file.md:1:31
140
+ └─ Text @/path/to/some-file.md:1:14-/path/to/some-file.md:1:31 " This is an aside. "
141
+ """
142
+ try assertAside (
143
+ source: source,
144
+ conversionStrategy: . requireAnyLengthTag,
145
+ expectedKind: . init( rawValue: " Important " ) !,
146
+ expectedRootDump: expectedRootDump)
147
+ }
148
+ }
149
+
150
+ func testConversionStrategyAllowNoLabel( ) throws {
151
+ do {
152
+ let source = """
153
+ > This is a regular block quote.
154
+ """
155
+ let expectedRootDump = """
156
+ Document @/path/to/some-file.md:1:1-/path/to/some-file.md:1:33
157
+ └─ BlockQuote @/path/to/some-file.md:1:1-/path/to/some-file.md:1:33
158
+ └─ Paragraph @/path/to/some-file.md:1:3-/path/to/some-file.md:1:33
159
+ └─ Text @/path/to/some-file.md:1:3-/path/to/some-file.md:1:33 " This is a regular block quote. "
160
+ """
161
+ try assertAside (
162
+ source: source,
163
+ conversionStrategy: . tagNotRequired,
164
+ expectedKind: . note,
165
+ expectedRootDump: expectedRootDump)
166
+ }
167
+
168
+ do {
169
+ let source = " > See Also: A different topic. "
170
+ let expectedRootDump = """
171
+ Document @/path/to/some-file.md:1:1-/path/to/some-file.md:1:31
172
+ └─ BlockQuote @/path/to/some-file.md:1:1-/path/to/some-file.md:1:31
173
+ └─ Paragraph @/path/to/some-file.md:1:3-/path/to/some-file.md:1:31
174
+ └─ Text @/path/to/some-file.md:1:13-/path/to/some-file.md:1:31 " A different topic. "
175
+ """
176
+ try assertAside (
177
+ source: source,
178
+ conversionStrategy: . tagNotRequired,
179
+ expectedKind: . init( rawValue: " See Also " ) !,
180
+ expectedRootDump: expectedRootDump)
181
+ }
182
+
183
+ do {
184
+ let source = " > Important: This is an aside. "
185
+ let expectedRootDump = """
186
+ Document @/path/to/some-file.md:1:1-/path/to/some-file.md:1:31
187
+ └─ BlockQuote @/path/to/some-file.md:1:1-/path/to/some-file.md:1:31
188
+ └─ Paragraph @/path/to/some-file.md:1:3-/path/to/some-file.md:1:31
189
+ └─ Text @/path/to/some-file.md:1:14-/path/to/some-file.md:1:31 " This is an aside. "
190
+ """
191
+ try assertAside (
192
+ source: source,
193
+ conversionStrategy: . tagNotRequired,
194
+ expectedKind: . init( rawValue: " Important " ) !,
195
+ expectedRootDump: expectedRootDump)
196
+ }
197
+ }
198
+
199
+ func assertAside( source: String , conversionStrategy: Aside . TagRequirement , expectedKind: Aside . Kind , expectedRootDump: String , file: StaticString = #file, line: UInt = #line) throws {
200
+ let fakeFileLocation = URL ( fileURLWithPath: " /path/to/some-file.md " )
201
+ let document = Document ( parsing: source, source: fakeFileLocation)
202
+ let blockQuote = document. child ( at: 0 ) as! BlockQuote
203
+ let aside = try XCTUnwrap ( Aside ( blockQuote, tagRequirement: conversionStrategy) )
204
+
205
+ XCTAssertEqual (
206
+ blockQuote. range? . lowerBound. source,
207
+ aside. content. first? . range? . lowerBound. source,
208
+ " The parsed aside should not lose source file information " ,
209
+ file: file, line: line
210
+ )
211
+
212
+ XCTAssertEqual ( expectedKind, aside. kind, file: file, line: line)
213
+ XCTAssertEqual (
214
+ expectedRootDump,
215
+ aside. content [ 0 ] . root. debugDescription ( options: . printSourceLocations) ,
216
+ file: file, line: line
217
+ )
218
+ }
76
219
}
0 commit comments