Skip to content

Commit bddcd1a

Browse files
j-f1d-ronnqvist
andcommitted
Add a basic test from @d-ronnqvist
Co-Authored-By: David Rönnqvist <[email protected]>
1 parent 2e238c1 commit bddcd1a

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2024 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
import Foundation
12+
13+
import XCTest
14+
@testable import SwiftDocC
15+
import SwiftDocCTestUtilities
16+
@testable import SymbolKit
17+
18+
class DoxygenTests: XCTestCase {
19+
func testDoxygenDiscussionAndNote() throws {
20+
let documentationLines: [SymbolGraph.LineList.Line] = """
21+
This is an abstract.
22+
23+
@discussion This is a discussion.
24+
25+
@note This is a note.
26+
"""
27+
.splitByNewlines
28+
.enumerated()
29+
.map { index, line in
30+
SymbolGraph.LineList.Line(
31+
text: line,
32+
range: .init(start: .init(line: 1 + index, character: 1), end: .init(line: 1 + index, character: 1 + line.utf8.count))
33+
)
34+
}
35+
36+
let tempURL = try createTempFolder(content: [
37+
Folder(name: "unit-test.docc", content: [
38+
JSONFile(name: "ModuleName.symbols.json", content: makeSymbolGraph(
39+
moduleName: "ModuleName",
40+
symbols: [
41+
SymbolGraph.Symbol(
42+
identifier: .init(precise: "some-class-id", interfaceLanguage: SourceLanguage.swift.id),
43+
names: .init(title: "SomeClass", navigator: nil, subHeading: nil, prose: nil),
44+
pathComponents: ["SomeClass"],
45+
docComment: .init(documentationLines),
46+
accessLevel: .public,
47+
kind: .init(parsedIdentifier: .class, displayName: "Kind Display Name"),
48+
mixins: [:]
49+
)
50+
]
51+
)),
52+
])
53+
])
54+
55+
let (_, bundle, context) = try loadBundle(from: tempURL)
56+
let reference = ResolvedTopicReference(bundleIdentifier: bundle.identifier, path: "/documentation/ModuleName/SomeClass", sourceLanguage: .swift)
57+
58+
// Verify the expected content in the in-memory model
59+
let node = try context.entity(with: reference)
60+
let symbol = try XCTUnwrap(node.semantic as? Symbol)
61+
62+
XCTAssertEqual(symbol.abstract?.format(), "This is an abstract.")
63+
XCTAssertEqual(symbol.discussion?.content.map { $0.format() }, ["This is a discussion.", "This is a note."])
64+
65+
// Verify the expected content in the render model
66+
var translator = RenderNodeTranslator(context: context, bundle: bundle, identifier: node.reference, source: nil)
67+
let renderNode = try XCTUnwrap(translator.visit(node.semantic) as? RenderNode)
68+
69+
XCTAssertEqual(renderNode.abstract, [.text("This is an abstract.")])
70+
XCTAssertEqual(renderNode.primaryContentSections.count, 1)
71+
72+
let overviewSection = try XCTUnwrap(renderNode.primaryContentSections.first as? ContentRenderSection)
73+
XCTAssertEqual(overviewSection.content.count, 3)
74+
75+
XCTAssertEqual(overviewSection.content, [
76+
.heading(.init(level: 2, text: "Overview", anchor: "overview")),
77+
78+
.paragraph(.init(inlineContent: [
79+
.text("This is a discussion.")
80+
])),
81+
82+
.aside(.init(style: .init(asideKind: .note), content: [
83+
.paragraph(.init(inlineContent: [
84+
.text("This is a note.")
85+
]))
86+
])),
87+
])
88+
}
89+
}

0 commit comments

Comments
 (0)