-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c1f97a
commit 55df7f9
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
47 changes: 47 additions & 0 deletions
47
Tests/SpeziTests/DependenciesTests/DependencyBuilderTests.swift
This file contains 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,47 @@ | ||
// | ||
// This source file is part of the Stanford Spezi open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2023 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import Spezi | ||
import XCTRuntimeAssertions | ||
|
||
private protocol ExampleTypeConstraint: Module {} | ||
|
||
private final class ExampleDependencyModule: ExampleTypeConstraint {} | ||
|
||
@resultBuilder | ||
private enum ExampleDependencyBuilder: DependencyCollectionBuilder { | ||
/// An auto-closure expression, providing the default dependency value, building the ``DependencyCollection``. | ||
public static func buildExpression<L: ExampleTypeConstraint>(_ expression: @escaping @autoclosure () -> L) -> DependencyCollection { | ||
Check failure on line 19 in Tests/SpeziTests/DependenciesTests/DependencyBuilderTests.swift GitHub Actions / SwiftLint / SwiftLint / SwiftLint
|
||
DependencyCollection(singleEntry: expression) | ||
} | ||
} | ||
|
||
private class ExampleModule: Module { | ||
@Dependency var dependencies: [any Module] | ||
|
||
|
||
public init( | ||
Check failure on line 28 in Tests/SpeziTests/DependenciesTests/DependencyBuilderTests.swift GitHub Actions / SwiftLint / SwiftLint / SwiftLint
|
||
@ExampleDependencyBuilder _ dependencies: () -> DependencyCollection | ||
) { | ||
self._dependencies = Dependency(dependencies) | ||
} | ||
} | ||
|
||
private class ExampleConfiguration { | ||
Check failure on line 35 in Tests/SpeziTests/DependenciesTests/DependencyBuilderTests.swift GitHub Actions / SwiftLint / SwiftLint / SwiftLint
|
||
static let exampleModule = ExampleModule { | ||
ExampleDependencyModule() | ||
} | ||
} | ||
|
||
|
||
final class DependencyBuilderTests: XCTestCase { | ||
func testDependencyBuilder() throws { | ||
XCTAssertEqual(ExampleConfiguration.exampleModule.dependencies.count, 1) | ||
_ = try XCTUnwrap(ExampleConfiguration.exampleModule.dependencies[0] as? ExampleDependencyModule) | ||
} | ||
} |