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

Commit 06f4167

Browse files
committed
Add testComputedPropertiesInPublicExtension
1 parent 49ce9c6 commit 06f4167

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Tests/SwiftDocTests/InterfaceTypeTests.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,33 @@ final class InterfaceTypeTests: XCTestCase {
9797
XCTAssertEqual(module.interface.symbols[1].name, "b()", "Function `b()` should be in documented interface")
9898
}
9999

100+
func testComputedPropertiesInPublicExtension() throws {
101+
let source = #"""
102+
public extension Int {
103+
var a: Int { 1 }
104+
public var b: Int { 1 }
105+
internal var c: Int { 1 }
106+
fileprivate var d: Int { 1 }
107+
private var e: Int { 1 }
108+
}
109+
"""#
110+
111+
let url = try temporaryFile(contents: source)
112+
let sourceFile = try SourceFile(file: url, relativeTo: url.deletingLastPathComponent())
113+
let module = Module(name: "Module", sourceFiles: [sourceFile])
114+
115+
XCTAssertEqual(sourceFile.symbols.count, 5)
116+
XCTAssertTrue(sourceFile.symbols[0].isPublic, "Property `a` should BE marked as public - its visibility is specified by extension")
117+
XCTAssertTrue(sourceFile.symbols[1].isPublic, "Property `b` should BE marked as public - its visibility is public")
118+
XCTAssertFalse(sourceFile.symbols[2].isPublic, "Property `c` should NOT be marked as public - its visibility is internal")
119+
XCTAssertFalse(sourceFile.symbols[3].isPublic, "Property `d` should NOT be marked as public - its visibility is fileprivate")
120+
XCTAssertFalse(sourceFile.symbols[4].isPublic, "Property `e` should NOT be marked as public - its visibility is private")
121+
122+
XCTAssertEqual(module.interface.symbols.count, 2)
123+
XCTAssertEqual(module.interface.symbols[0].name, "a", "Property `a` should be in documented interface")
124+
XCTAssertEqual(module.interface.symbols[1].name, "b", "Property `b` should be in documented interface")
125+
}
126+
100127
func testNestedPropertiesInPublicExtension() throws {
101128
let source = #"""
102129
public class RootController {}

0 commit comments

Comments
 (0)