Skip to content

Commit ec3f677

Browse files
author
Jesse Haigh
committed
test showLineNumbers
1 parent b49c6e2 commit ec3f677

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

Tests/SwiftDocCTests/Rendering/RenderContentCompilerTests.swift

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,62 @@ class RenderContentCompilerTests: XCTestCase {
341341
XCTAssertEqual(codeListing.copyToClipboard, false)
342342
}
343343

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+
344400
func testWrapAndHighlight() async throws {
345401
enableFeatureFlag(\.isExperimentalCodeBlockEnabled)
346402

@@ -498,7 +554,7 @@ class RenderContentCompilerTests: XCTestCase {
498554
var compiler = RenderContentCompiler(context: context, bundle: bundle, identifier: ResolvedTopicReference(bundleID: bundle.id, path: "/path", fragment: nil, sourceLanguage: .swift))
499555

500556
let source = #"""
501-
```highlight=[1, 2, 3], swift, wrap=20, strikeout=[3]
557+
```showLineNumbers, highlight=[1, 2, 3], swift, wrap=20, strikeout=[3]
502558
let a = 1
503559
let b = 2
504560
let c = 3
@@ -517,6 +573,7 @@ class RenderContentCompilerTests: XCTestCase {
517573
return
518574
}
519575

576+
XCTAssertEqual(codeListing.showLineNumbers, true)
520577
XCTAssertEqual(codeListing.highlight, [1, 2, 3])
521578
// we expect the language to be the first option in the language line, otherwise it remains nil.
522579
XCTAssertEqual(codeListing.syntax, nil)

0 commit comments

Comments
 (0)