Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Fix toplevel symbols (#260)
Browse files Browse the repository at this point in the history
* Add failing tests for top level symbols.

* Fix top level symbols.

* Update Sources/SwiftDoc/Interface.swift

* Remove print statement

Co-authored-by: Mattt <[email protected]>
  • Loading branch information
Lukas-Stuehrk and mattt committed Apr 26, 2021
1 parent c0e49f7 commit aef1c49
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/SwiftDoc/Interface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final class Interface {
return false
}

return symbol.id.pathComponents.isEmpty
return symbol.id.context.isEmpty
}

self.relationships = {
Expand Down
29 changes: 29 additions & 0 deletions Tests/SwiftDocTests/InterfaceTypeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()")
}
}

0 comments on commit aef1c49

Please sign in to comment.