From aef1c4966f0399e348465a39cca3d138cd93dce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20St=C3=BChrk?= Date: Mon, 26 Apr 2021 15:19:30 +0200 Subject: [PATCH] Fix toplevel symbols (#260) * Add failing tests for top level symbols. * Fix top level symbols. * Update Sources/SwiftDoc/Interface.swift * Remove print statement Co-authored-by: Mattt --- Sources/SwiftDoc/Interface.swift | 2 +- Tests/SwiftDocTests/InterfaceTypeTests.swift | 29 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftDoc/Interface.swift b/Sources/SwiftDoc/Interface.swift index b5a0ad3a..8f5137ed 100644 --- a/Sources/SwiftDoc/Interface.swift +++ b/Sources/SwiftDoc/Interface.swift @@ -24,7 +24,7 @@ public final class Interface { return false } - return symbol.id.pathComponents.isEmpty + return symbol.id.context.isEmpty } self.relationships = { diff --git a/Tests/SwiftDocTests/InterfaceTypeTests.swift b/Tests/SwiftDocTests/InterfaceTypeTests.swift index 58ee31c3..78efd0f4 100644 --- a/Tests/SwiftDocTests/InterfaceTypeTests.swift +++ b/Tests/SwiftDocTests/InterfaceTypeTests.swift @@ -359,4 +359,33 @@ final class InterfaceTypeTests: XCTestCase { XCTAssertEqual(members[0].name, "someMethod()") XCTAssertEqual(members[1].name, "someExtensionMethod()") } + + public func testToplevelSymbols() throws { + let source = #""" + public class SomeClass { + public func someMethod() { } + } + + public infix operator ≠ + + public typealias OtherClass = SomeClass + + public func someFunction() { } + + public extension OtherClass { + func someExtensionMethod() { } + } + """# + + let url = try temporaryFile(contents: source) + let sourceFile = try SourceFile(file: url, relativeTo: url.deletingLastPathComponent()) + let module = Module(name: "Module", sourceFiles: [sourceFile]) + + XCTAssertEqual(module.interface.topLevelSymbols.count, 4) + + XCTAssertEqual(module.interface.topLevelSymbols[0].name, "SomeClass") + XCTAssertEqual(module.interface.topLevelSymbols[1].name, "≠") + XCTAssertEqual(module.interface.topLevelSymbols[2].name, "OtherClass") + XCTAssertEqual(module.interface.topLevelSymbols[3].name, "someFunction()") + } }