@@ -341,6 +341,62 @@ class RenderContentCompilerTests: XCTestCase {
341
341
XCTAssertEqual ( codeListing. copyToClipboard, false )
342
342
}
343
343
344
+ func testShowLineNumbers( ) async throws {
345
+ enableFeatureFlag ( \. isExperimentalCodeBlockEnabled)
346
+
347
+ let ( bundle, context) = try await testBundleAndContext ( )
348
+ var compiler = RenderContentCompiler ( context: context, bundle: bundle, identifier: ResolvedTopicReference ( bundleID: bundle. id, path: " /path " , fragment: nil , sourceLanguage: . swift) )
349
+
350
+ let source = #"""
351
+ ```swift, showLineNumbers
352
+ let a = 1
353
+ let b = 2
354
+ let c = 3
355
+ let d = 4
356
+ let e = 5
357
+ ```
358
+ """#
359
+ let document = Document ( parsing: source)
360
+
361
+ let result = document. children. flatMap { compiler. visit ( $0) }
362
+
363
+ let renderCodeBlock = try XCTUnwrap ( result [ 0 ] as? RenderBlockContent )
364
+ guard case let . codeListing( codeListing) = renderCodeBlock else {
365
+ XCTFail ( " Expected RenderBlockContent.codeListing " )
366
+ return
367
+ }
368
+
369
+ XCTAssertEqual ( codeListing. showLineNumbers, true )
370
+ }
371
+
372
+ func testLowercaseShowLineNumbers( ) async throws {
373
+ enableFeatureFlag ( \. isExperimentalCodeBlockEnabled)
374
+
375
+ let ( bundle, context) = try await testBundleAndContext ( )
376
+ var compiler = RenderContentCompiler ( context: context, bundle: bundle, identifier: ResolvedTopicReference ( bundleID: bundle. id, path: " /path " , fragment: nil , sourceLanguage: . swift) )
377
+
378
+ let source = #"""
379
+ ```swift, showlinenumbers
380
+ let a = 1
381
+ let b = 2
382
+ let c = 3
383
+ let d = 4
384
+ let e = 5
385
+ ```
386
+ """#
387
+ let document = Document ( parsing: source)
388
+
389
+ let result = document. children. flatMap { compiler. visit ( $0) }
390
+
391
+ let renderCodeBlock = try XCTUnwrap ( result [ 0 ] as? RenderBlockContent )
392
+ guard case let . codeListing( codeListing) = renderCodeBlock else {
393
+ XCTFail ( " Expected RenderBlockContent.codeListing " )
394
+ return
395
+ }
396
+
397
+ XCTAssertEqual ( codeListing. showLineNumbers, true )
398
+ }
399
+
344
400
func testWrapAndHighlight( ) async throws {
345
401
enableFeatureFlag ( \. isExperimentalCodeBlockEnabled)
346
402
@@ -498,7 +554,7 @@ class RenderContentCompilerTests: XCTestCase {
498
554
var compiler = RenderContentCompiler ( context: context, bundle: bundle, identifier: ResolvedTopicReference ( bundleID: bundle. id, path: " /path " , fragment: nil , sourceLanguage: . swift) )
499
555
500
556
let source = #"""
501
- ```highlight=[1, 2, 3], swift, wrap=20, strikeout=[3]
557
+ ```showLineNumbers, highlight=[1, 2, 3], swift, wrap=20, strikeout=[3]
502
558
let a = 1
503
559
let b = 2
504
560
let c = 3
@@ -517,6 +573,7 @@ class RenderContentCompilerTests: XCTestCase {
517
573
return
518
574
}
519
575
576
+ XCTAssertEqual ( codeListing. showLineNumbers, true )
520
577
XCTAssertEqual ( codeListing. highlight, [ 1 , 2 , 3 ] )
521
578
// we expect the language to be the first option in the language line, otherwise it remains nil.
522
579
XCTAssertEqual ( codeListing. syntax, nil )
0 commit comments