@@ -221,4 +221,204 @@ class TaskGroupTests: XCTestCase {
221
221
XCTAssertEqual ( " https://www.example.com " , links [ 1 ] . destination)
222
222
}
223
223
}
224
+
225
+ func testSupportedLanguages( ) throws {
226
+ let markupSource = """
227
+ # Title
228
+
229
+ Abstract.
230
+
231
+ ## Topics
232
+
233
+ ### Something Swift only
234
+
235
+ This link is only for Swift
236
+
237
+ @SupportedLanguage(swift)
238
+
239
+ - ``Link1``
240
+
241
+ ### Something Objective-C only
242
+
243
+ This link is only for Objective-C
244
+
245
+ @SupportedLanguage(objc)
246
+
247
+ - ``Link1``
248
+
249
+ ### Something for both
250
+
251
+ This link is for both Swift and Objective-C
252
+
253
+ @SupportedLanguage(objc)
254
+ @SupportedLanguage(swift)
255
+
256
+ - ``Link3``
257
+
258
+ ### Something without a language filter
259
+
260
+ This link is for all languages
261
+
262
+ - ``Link4``
263
+ """
264
+ let document = Document ( parsing: markupSource, options: [ . parseBlockDirectives, . parseSymbolLinks] )
265
+ let markupModel = DocumentationMarkup ( markup: document)
266
+
267
+ XCTAssertEqual ( " Abstract. " , Paragraph ( markupModel. abstractSection? . content. compactMap { $0 as? InlineMarkup } ?? [ ] ) . detachedFromParent. format ( ) )
268
+
269
+ let topicSection = try XCTUnwrap ( markupModel. topicsSection)
270
+ XCTAssertEqual ( topicSection. taskGroups. count, 4 )
271
+
272
+ do {
273
+ let taskGroup = try XCTUnwrap ( topicSection. taskGroups. first)
274
+ XCTAssertEqual ( taskGroup. heading? . detachedFromParent. format ( ) , " ### Something Swift only " )
275
+ XCTAssertEqual ( taskGroup. abstract? . paragraph. detachedFromParent. format ( ) , " This link is only for Swift " )
276
+ XCTAssertEqual ( taskGroup. directives. count, 1 )
277
+ for directive in taskGroup. directives {
278
+ XCTAssertEqual ( directive. name, " SupportedLanguage " )
279
+ XCTAssertEqual ( directive. arguments ( ) . count, 1 )
280
+ }
281
+ XCTAssertEqual ( taskGroup. links. count, 1 )
282
+ }
283
+
284
+ do {
285
+ let taskGroup = try XCTUnwrap ( topicSection. taskGroups. dropFirst ( ) . first)
286
+ XCTAssertEqual ( taskGroup. heading? . detachedFromParent. format ( ) , " ### Something Objective-C only " )
287
+ XCTAssertEqual ( taskGroup. abstract? . paragraph. detachedFromParent. format ( ) , " This link is only for Objective-C " )
288
+ XCTAssertEqual ( taskGroup. directives. count, 1 )
289
+ for directive in taskGroup. directives {
290
+ XCTAssertEqual ( directive. name, " SupportedLanguage " )
291
+ XCTAssertEqual ( directive. arguments ( ) . count, 1 )
292
+ }
293
+ XCTAssertEqual ( taskGroup. links. count, 1 )
294
+ }
295
+
296
+ do {
297
+ let taskGroup = try XCTUnwrap ( topicSection. taskGroups. dropFirst ( 2 ) . first)
298
+ XCTAssertEqual ( taskGroup. heading? . detachedFromParent. format ( ) , " ### Something for both " )
299
+ XCTAssertEqual ( taskGroup. abstract? . paragraph. detachedFromParent. format ( ) , " This link is for both Swift and Objective-C " )
300
+ XCTAssertEqual ( taskGroup. directives. count, 2 )
301
+ for directive in taskGroup. directives {
302
+ XCTAssertEqual ( directive. name, " SupportedLanguage " )
303
+ XCTAssertEqual ( directive. arguments ( ) . count, 1 )
304
+ }
305
+ XCTAssertEqual ( taskGroup. links. count, 1 )
306
+ }
307
+
308
+ do {
309
+ let taskGroup = try XCTUnwrap ( topicSection. taskGroups. dropFirst ( 3 ) . first)
310
+ XCTAssertEqual ( taskGroup. heading? . detachedFromParent. format ( ) , " ### Something without a language filter " )
311
+ XCTAssertEqual ( taskGroup. abstract? . paragraph. detachedFromParent. format ( ) , " This link is for all languages " )
312
+ XCTAssert ( taskGroup. directives. isEmpty)
313
+ XCTAssertEqual ( taskGroup. links. count, 1 )
314
+ }
315
+ }
316
+
317
+ func testTopicContentOrder( ) throws {
318
+ func assertExpectedParsedTaskGroupContent( _ content: String , file: StaticString = #file, line: UInt = #line) throws {
319
+ let document = Document ( parsing: """
320
+ # Title
321
+
322
+ Abstract.
323
+
324
+ ## Topics
325
+
326
+ \( content)
327
+
328
+ """ , options: [ . parseBlockDirectives, . parseSymbolLinks] )
329
+ let markupModel = DocumentationMarkup ( markup: document)
330
+
331
+ let topicSection = try XCTUnwrap ( markupModel. topicsSection, file: file, line: line)
332
+ XCTAssertEqual ( topicSection. taskGroups. count, 1 , file: file, line: line)
333
+
334
+ let taskGroup = try XCTUnwrap ( topicSection. taskGroups. first, file: file, line: line)
335
+
336
+ XCTAssertEqual ( taskGroup. heading? . title, " Topic name " , file: file, line: line)
337
+ XCTAssertEqual ( taskGroup. abstract? . paragraph. detachedFromParent. format ( ) , " Abstract paragraph " , file: file, line: line)
338
+ XCTAssertEqual ( taskGroup. discussion? . content. map { $0. detachedFromParent. format ( ) } , [
339
+ " Discussion paragraph 1 " ,
340
+ " Discussion paragraph 2 " ,
341
+ ] , file: file, line: line)
342
+ XCTAssertEqual ( taskGroup. directives. count, 1 , file: file, line: line)
343
+ XCTAssertEqual ( taskGroup. directives. first? . name, " SupportedLanguage " , file: file, line: line)
344
+ XCTAssertEqual ( taskGroup. directives. first? . arguments ( ) . count, 1 , file: file, line: line)
345
+ XCTAssertEqual ( taskGroup. links. map ( \. destination) , [ " Link1 " , " Link2 " ] , file: file, line: line)
346
+ }
347
+
348
+ try assertExpectedParsedTaskGroupContent ( """
349
+ ### Topic name
350
+
351
+ Abstract paragraph
352
+
353
+ Discussion paragraph 1
354
+
355
+ Discussion paragraph 2
356
+
357
+ @SupportedLanguage(swift)
358
+
359
+ - ``Link1``
360
+ - ``Link2``
361
+ """ )
362
+
363
+ try assertExpectedParsedTaskGroupContent ( """
364
+ ### Topic name
365
+
366
+ Abstract paragraph
367
+
368
+ @SupportedLanguage(swift)
369
+
370
+ Discussion paragraph 1
371
+
372
+ Discussion paragraph 2
373
+
374
+ - ``Link1``
375
+ - ``Link2``
376
+ """ )
377
+
378
+ try assertExpectedParsedTaskGroupContent ( """
379
+ ### Topic name
380
+
381
+ @SupportedLanguage(swift)
382
+
383
+ Abstract paragraph
384
+
385
+ Discussion paragraph 1
386
+
387
+ Discussion paragraph 2
388
+
389
+ - ``Link1``
390
+ - ``Link2``
391
+ """ )
392
+
393
+ try assertExpectedParsedTaskGroupContent ( """
394
+ ### Topic name
395
+
396
+ Abstract paragraph
397
+
398
+ Discussion paragraph 1
399
+
400
+ @SupportedLanguage(swift)
401
+
402
+ Discussion paragraph 2
403
+
404
+ - ``Link1``
405
+ - ``Link2``
406
+ """ )
407
+
408
+ try assertExpectedParsedTaskGroupContent ( """
409
+ ### Topic name
410
+
411
+ Abstract paragraph
412
+
413
+ Discussion paragraph 1
414
+
415
+ Discussion paragraph 2
416
+
417
+ - ``Link1``
418
+ - ``Link2``
419
+
420
+ @SupportedLanguage(swift)
421
+ """ )
422
+
423
+ }
224
424
}
0 commit comments