Skip to content

Commit

Permalink
Merge branch 'main' into dfed--renamed-received-resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
dfed authored Jan 19, 2024
2 parents 99eb896 + 38c295c commit 12db159
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Sources/SafeDICore/Models/Scope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ final class Scope {
&& $0.property != property
}
.map(\.property)
).subtracting(
// We want the local version of any instantiated property.
propertiesToInstantiate.map(\.property)
+ instantiable
.dependencies
// We want the local version of any aliased property.
.filter { $0.fulfillingProperty != nil }
.map(\.property)
)
let scopeGenerator = ScopeGenerator(
instantiable: instantiable,
Expand Down
6 changes: 6 additions & 0 deletions Sources/SafeDICore/Models/TypeDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,12 @@ public struct UnorderedComparingCollection<Element: Codable & Hashable & Sendabl
lhs.set == rhs.set
}

// MARK: Hashable

public func hash(into hasher: inout Hasher) {
hasher.combine(set)
}

// MARK: Collection

public func makeIterator() -> IndexingIterator<Array<Element>> { array.makeIterator() }
Expand Down
7 changes: 7 additions & 0 deletions Tests/SafeDICoreTests/TypeDescriptionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,13 @@ final class TypeDescriptionTests: XCTestCase {
}
}

func test_UnorderedComparingCollection_hashesEquivalentCollectionsIdentically() {
XCTAssertEqual(
UnorderedComparingCollection([1, 2, 3]).hashValue,
UnorderedComparingCollection([2, 1, 3]).hashValue
)
}

// MARK: - Visitors

private final class TypeIdentifierSyntaxVisitor: SyntaxVisitor {
Expand Down
69 changes: 69 additions & 0 deletions Tests/SafeDIToolTests/SafeDIToolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1588,6 +1588,75 @@ final class SafeDIToolTests: XCTestCase {
)
}

func test_run_writesConvenienceExtensionOnRootOfTree_whenRootInstantiatesPropertiesWithSingleTreeThatInstantiateTheSamePropertyAtMultipleLevels() async throws {
let output = try await executeSystemUnderTest(
swiftFileContent: [
"""
@Instantiable
public final class Root {
@Instantiated
let child: Child
}
""",
"""
@Instantiable
public final class Recreated {}
""",
"""
@Instantiable
public final class Child {
@Instantiated
let grandchild: Grandchild
@Instantiated
let recreated: Recreated
}
""",
"""
@Instantiable
public final class Grandchild {
@Instantiated
let greatGrandchild: GreatGrandchild
@Instantiated
let recreated: Recreated
}
""",
"""
@Instantiable
public final class GreatGrandchild {
@Received
let recreated: Recreated
}
""",

],
buildDependencyTreeOutput: true
)

XCTAssertEqual(
try XCTUnwrap(output.dependencyTree),
"""
// This file was generated by the SafeDIGenerateDependencyTree build tool plugin.
// Any modifications made to this file will be overwritten on subsequent builds.
// Please refrain from editing this file directly.
extension Root {
public convenience init() {
let child = {
let grandchild = {
let recreated = Recreated()
let greatGrandchild = GreatGrandchild(recreated: recreated)
return Grandchild(greatGrandchild: greatGrandchild, recreated: recreated)
}()
let recreated = Recreated()
return Child(grandchild: grandchild, recreated: recreated)
}()
self.init(child: child)
}
}
"""
)
}

func test_run_writesConvenienceExtensionOnRootOfTree_whenRootInstantiatesPropertiesWithMultipleTreesThatInstantiateTheSamePropertyMultipleLayersDeep() async throws {
let output = try await executeSystemUnderTest(
swiftFileContent: [
Expand Down

0 comments on commit 12db159

Please sign in to comment.