@@ -282,7 +282,6 @@ class RenderContentCompilerTests: XCTestCase {
282
282
```
283
283
"""#
284
284
let document = Document ( parsing: source)
285
-
286
285
let result = document. children. flatMap { compiler. visit ( $0) }
287
286
288
287
let renderCodeBlock = try XCTUnwrap ( result [ 0 ] as? RenderBlockContent )
@@ -316,4 +315,123 @@ class RenderContentCompilerTests: XCTestCase {
316
315
XCTAssertEqual ( codeListing. syntax, " swift, nocopy " )
317
316
XCTAssertEqual ( codeListing. copyToClipboard, false )
318
317
}
318
+
319
+ func testWrapAndHighlight( ) async throws {
320
+ enableFeatureFlag ( \. isExperimentalCodeBlockEnabled)
321
+
322
+ let ( bundle, context) = try await testBundleAndContext ( )
323
+ var compiler = RenderContentCompiler ( context: context, bundle: bundle, identifier: ResolvedTopicReference ( bundleID: bundle. id, path: " /path " , fragment: nil , sourceLanguage: . swift) )
324
+
325
+ let source = #"""
326
+ ```swift, wrap=20, highlight=[2]
327
+ let a = 1
328
+ let b = 2
329
+ let c = 3
330
+ let d = 4
331
+ let e = 5
332
+ ```
333
+ """#
334
+
335
+ let document = Document ( parsing: source)
336
+
337
+ let result = document. children. flatMap { compiler. visit ( $0) }
338
+
339
+ let renderCodeBlock = try XCTUnwrap ( result [ 0 ] as? RenderBlockContent )
340
+ guard case let . codeListing( codeListing) = renderCodeBlock else {
341
+ XCTFail ( " Expected RenderBlockContent.codeListing " )
342
+ return
343
+ }
344
+
345
+ XCTAssertEqual ( codeListing. syntax, " swift " )
346
+ XCTAssertEqual ( codeListing. wrap, 20 )
347
+ XCTAssertEqual ( codeListing. highlight, [ 2 ] )
348
+ }
349
+
350
+ func testHighlight( ) async throws {
351
+ enableFeatureFlag ( \. isExperimentalCodeBlockEnabled)
352
+
353
+ let ( bundle, context) = try await testBundleAndContext ( )
354
+ var compiler = RenderContentCompiler ( context: context, bundle: bundle, identifier: ResolvedTopicReference ( bundleID: bundle. id, path: " /path " , fragment: nil , sourceLanguage: . swift) )
355
+
356
+ let source = #"""
357
+ ```swift, highlight=[2]
358
+ let a = 1
359
+ let b = 2
360
+ let c = 3
361
+ let d = 4
362
+ let e = 5
363
+ ```
364
+ """#
365
+
366
+ let document = Document ( parsing: source)
367
+
368
+ let result = document. children. flatMap { compiler. visit ( $0) }
369
+
370
+ let renderCodeBlock = try XCTUnwrap ( result [ 0 ] as? RenderBlockContent )
371
+ guard case let . codeListing( codeListing) = renderCodeBlock else {
372
+ XCTFail ( " Expected RenderBlockContent.codeListing " )
373
+ return
374
+ }
375
+
376
+ XCTAssertEqual ( codeListing. syntax, " swift " )
377
+ XCTAssertEqual ( codeListing. highlight, [ 2 ] )
378
+ }
379
+
380
+ func testHighlightNoFeatureFlag( ) async throws {
381
+ let ( bundle, context) = try await testBundleAndContext ( )
382
+ var compiler = RenderContentCompiler ( context: context, bundle: bundle, identifier: ResolvedTopicReference ( bundleID: bundle. id, path: " /path " , fragment: nil , sourceLanguage: . swift) )
383
+
384
+ let source = #"""
385
+ ```swift, highlight=[2]
386
+ let a = 1
387
+ let b = 2
388
+ let c = 3
389
+ let d = 4
390
+ let e = 5
391
+ ```
392
+ """#
393
+
394
+ let document = Document ( parsing: source)
395
+
396
+ let result = document. children. flatMap { compiler. visit ( $0) }
397
+
398
+ let renderCodeBlock = try XCTUnwrap ( result [ 0 ] as? RenderBlockContent )
399
+ guard case let . codeListing( codeListing) = renderCodeBlock else {
400
+ XCTFail ( " Expected RenderBlockContent.codeListing " )
401
+ return
402
+ }
403
+
404
+ XCTAssertEqual ( codeListing. syntax, " swift, highlight=[2] " )
405
+ XCTAssertEqual ( codeListing. highlight, [ ] )
406
+ }
407
+
408
+ func testMultipleHighlight( ) async throws {
409
+ enableFeatureFlag ( \. isExperimentalCodeBlockEnabled)
410
+
411
+ let ( bundle, context) = try await testBundleAndContext ( )
412
+ var compiler = RenderContentCompiler ( context: context, bundle: bundle, identifier: ResolvedTopicReference ( bundleID: bundle. id, path: " /path " , fragment: nil , sourceLanguage: . swift) )
413
+
414
+ let source = #"""
415
+ ```swift, highlight=[1, 2, 3]
416
+ let a = 1
417
+ let b = 2
418
+ let c = 3
419
+ let d = 4
420
+ let e = 5
421
+ ```
422
+ """#
423
+
424
+ let document = Document ( parsing: source)
425
+
426
+ let result = document. children. flatMap { compiler. visit ( $0) }
427
+
428
+ let renderCodeBlock = try XCTUnwrap ( result [ 0 ] as? RenderBlockContent )
429
+ guard case let . codeListing( codeListing) = renderCodeBlock else {
430
+ XCTFail ( " Expected RenderBlockContent.codeListing " )
431
+ return
432
+ }
433
+
434
+ XCTAssertEqual ( codeListing. syntax, " swift " )
435
+ //XCTAssertEqual(codeListing.highlight, [1, 2, 3])
436
+ }
319
437
}
0 commit comments