-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from willowtreeapps/feature/value-types-support
Add support for value types
- Loading branch information
Showing
5 changed files
with
105 additions
and
28 deletions.
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
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
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
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
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,42 @@ | ||
// | ||
// GroveValueTypeDependencyTests.swift | ||
// | ||
// | ||
// Created by Raf Cabezas on 1/26/24. | ||
// | ||
|
||
import XCTest | ||
@testable import Grove | ||
|
||
private protocol TestEnumProtocol { | ||
var value: String { get } | ||
} | ||
|
||
private enum TestEnum: String, TestEnumProtocol { | ||
case g, r, o, v, e | ||
|
||
var value: String { rawValue } | ||
} | ||
|
||
private enum NotProtocolConformingTestEnum { | ||
case a, b, c | ||
} | ||
|
||
final class GroveValueTypeDependencyTests: XCTestCase { | ||
|
||
/// Tests registering a value type and resolving it. | ||
func testDirectTypeRegistration() { | ||
Grove.defaultContainer.register(value: NotProtocolConformingTestEnum.b) | ||
|
||
@Resolve var testEnum: NotProtocolConformingTestEnum | ||
XCTAssertEqual(testEnum, .b) | ||
} | ||
|
||
/// Tests registering a value type as a protocol and resolving it as a protocol. | ||
func testValueTypeAsProtocolRegistration() { | ||
Grove.defaultContainer.register(as: TestEnumProtocol.self, value: TestEnum.v) | ||
|
||
@Resolve var testEnum: TestEnumProtocol | ||
XCTAssertEqual(testEnum.value, "v") | ||
} | ||
} |