File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
Sources/FunctionalConfigurator
Tests/FunctionalConfigurationTests Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ import Foundation
2+
3+ public protocol CustomConfigurable { }
4+
5+ extension CustomConfigurable {
6+ public typealias Config = Configurator < Self >
7+
8+ public func configured( using configuration: ( Config . Type ) -> Config ) -> Self {
9+ configured ( using: configuration ( Config . self) )
10+ }
11+
12+ public func configured( using configurator: Config ) -> Self {
13+ configurator. configure ( self )
14+ }
15+ }
16+
17+ extension CustomConfigurable where Self: AnyObject {
18+ public func configure( using configuration: ( Config . Type ) -> Config ) {
19+ configure ( using: configuration ( Config . self) )
20+ }
21+
22+ public func configure( using configurator: Config ) {
23+ configurator. configure ( self )
24+ }
25+ }
26+
27+ extension NSObject : CustomConfigurable { }
Original file line number Diff line number Diff line change @@ -68,4 +68,27 @@ final class ConfiguratorTests: XCTestCase {
6868 XCTAssertEqual ( actual1. value, expected. value)
6969 XCTAssertEqual ( actual1. wrapped, expected. wrapped)
7070 }
71+
72+ func testCustomConfigurable( ) {
73+ struct TestConfigurable : CustomConfigurable {
74+ struct Wrapped : Equatable {
75+ var value = 0
76+ }
77+
78+ var value = false
79+ var wrapped = Wrapped ( )
80+ }
81+
82+ let initial = TestConfigurable ( )
83+ let expected = TestConfigurable ( value: true , wrapped: . init( value: 1 ) )
84+ let actual = TestConfigurable ( ) . configured { $0
85+ . value ( true )
86+ . wrapped ( . init( value: 1 ) )
87+ }
88+
89+ XCTAssertNotEqual ( actual. value, initial. value)
90+ XCTAssertNotEqual ( actual. wrapped, initial. wrapped)
91+ XCTAssertEqual ( actual. value, expected. value)
92+ XCTAssertEqual ( actual. wrapped, expected. wrapped)
93+ }
7194}
You can’t perform that action at this time.
0 commit comments