This repository was archived by the owner on Jun 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 98
Fix nested type handling #62
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0bcbebb
Fixed handling of nested types defined in extensions
victor-pavlychko 7608652
Fix rendering of nested type relationships when no graph is available
victor-pavlychko ab24111
Adding test for nested type relationship detection
victor-pavlychko df3ab8a
Adding (disabled) tests for relationships section html generation.
victor-pavlychko 72ac56e
Extract relationship graph setup into a separate property.
victor-pavlychko eb3acc5
Code review comments:
victor-pavlychko b7f0eb9
Merge branch 'master' into fix/nested-types
mattt af8fe72
Update Tests/SwiftDocTests/NestedTypesTests.swift
victor-pavlychko ef9bb5d
Updating changelog
victor-pavlychko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import XCTest | ||
|
||
import SwiftDoc | ||
import SwiftSemantics | ||
import struct SwiftSemantics.Protocol | ||
import SwiftSyntax | ||
|
||
final class NestedTypesTests: XCTestCase { | ||
func testNestedTypes() throws { | ||
let source = #""" | ||
public class C { } | ||
|
||
extension C { | ||
public enum E { | ||
case c | ||
} | ||
} | ||
|
||
extension C.E { | ||
public static let tp = 0 | ||
} | ||
"""# | ||
|
||
let url = try temporaryFile(contents: source) | ||
let sourceFile = try SourceFile(file: url, relativeTo: url.deletingLastPathComponent()) | ||
let module = Module(name: "Module", sourceFiles: [sourceFile]) | ||
|
||
XCTAssertEqual(sourceFile.symbols.count, 4) | ||
|
||
// `class C` | ||
let `class` = sourceFile.symbols[0] | ||
XCTAssert(`class`.api is Class) | ||
|
||
// `enum E` | ||
let `enum` = sourceFile.symbols[1] | ||
XCTAssert(`enum`.api is Enumeration) | ||
|
||
// `case c` | ||
let `case` = sourceFile.symbols[2] | ||
XCTAssert(`case`.api is Enumeration.Case) | ||
|
||
// `let tp` | ||
let `let` = sourceFile.symbols[3] | ||
XCTAssert(`let`.api is Variable) | ||
|
||
// `class C` contains `enum E` | ||
let classRelationships = try XCTUnwrap(module.interface.relationshipsByObject[`class`.id]) | ||
XCTAssertEqual(classRelationships.count, 1) | ||
XCTAssertTrue(classRelationships.allSatisfy({ $0.predicate == .memberOf })) | ||
XCTAssertEqual(Set(classRelationships.map({ $0.subject.id })), Set([`enum`.id])) | ||
|
||
// `enum C` contains `case c` and `let tp` | ||
let enumRelationships = try XCTUnwrap(module.interface.relationshipsByObject[`enum`.id]) | ||
XCTAssertEqual(enumRelationships.count, 2) | ||
XCTAssertTrue(enumRelationships.allSatisfy({ $0.predicate == .memberOf })) | ||
XCTAssertEqual(Set(enumRelationships.map({ $0.subject.id })), Set([`case`.id, `let`.id])) | ||
|
||
// `case c` and `let tp` have no relationships | ||
XCTAssertNil(module.interface.relationshipsByObject[`case`.id]) | ||
XCTAssertNil(module.interface.relationshipsByObject[`let`.id]) | ||
|
||
// no other relationships present in module | ||
XCTAssertEqual( | ||
module.interface.relationships.count, | ||
[classRelationships, enumRelationships].joined().count | ||
) | ||
} | ||
|
||
#if false // Disabling tests for `swift-doc` code, executable targers are not testable. | ||
|
||
func testRelationshipsSectionWithNestedTypes() throws { | ||
let source = #""" | ||
public class C { | ||
public enum E { | ||
} | ||
} | ||
"""# | ||
|
||
let url = try temporaryFile(contents: source) | ||
let sourceFile = try SourceFile(file: url, relativeTo: url.deletingLastPathComponent()) | ||
let module = Module(name: "Module", sourceFiles: [sourceFile]) | ||
|
||
// `class C` | ||
let `class` = sourceFile.symbols[0] | ||
XCTAssert(`class`.api is Class) | ||
|
||
// `enum E` | ||
let `enum` = sourceFile.symbols[1] | ||
XCTAssert(`enum`.api is Enumeration) | ||
|
||
let classRelationships = Relationships(of: `class`, in: module) | ||
XCTAssertNotEqual(classRelationships.html, "") | ||
|
||
let enumRelationships = Relationships(of: `enum`, in: module) | ||
XCTAssertNotEqual(enumRelationships.html, "") | ||
} | ||
|
||
func testNoRelationshipsSection() throws { | ||
let source = #""" | ||
public class C { | ||
} | ||
|
||
public enum E { | ||
} | ||
"""# | ||
|
||
let url = try temporaryFile(contents: source) | ||
let sourceFile = try SourceFile(file: url, relativeTo: url.deletingLastPathComponent()) | ||
let module = Module(name: "Module", sourceFiles: [sourceFile]) | ||
|
||
// `class C` | ||
let `class` = sourceFile.symbols[0] | ||
XCTAssert(`class`.api is Class) | ||
|
||
// `enum E` | ||
let `enum` = sourceFile.symbols[1] | ||
XCTAssert(`enum`.api is Enumeration) | ||
|
||
let classRelationships = Relationships(of: `class`, in: module) | ||
XCTAssertEqual(classRelationships.html, "") | ||
|
||
let enumRelationships = Relationships(of: `enum`, in: module) | ||
XCTAssertEqual(enumRelationships.html, "") | ||
} | ||
|
||
#endif | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.