@@ -81,7 +81,7 @@ final class QLAnchorTests: XCTestCase {
8181 XCTAssert ( ( receivedError as? QLCommon . Error) == QLCommon . Error. ThrownButNotSet)
8282 }
8383
84- func test_given_it_has_repeaters_with_default_filter_when_input_set_then_it_echoes_to_them_as_well ( ) {
84+ func test_given_it_has_early_repeaters_with_default_filter_when_input_set_then_it_echoes_to_them_as_well ( ) {
8585 var receivedVal0 : Int = - 1
8686 var receivedVal1 : Int = - 1
8787 var receivedVal2 : Int = - 1
@@ -90,7 +90,30 @@ final class QLAnchorTests: XCTestCase {
9090 let expectRepeater2 = expectation ( description: " should echo value to repeater2 " )
9191 let repeater1 = QLAnchor < Int > ( onChange: { receivedVal1 = $0!; expectRepeater1. fulfill ( ) } )
9292 let repeater2 = QLAnchor < Int > ( onChange: { receivedVal2 = $0!; expectRepeater2. fulfill ( ) } )
93- let subject = QLAnchor < Int > ( repeaters: repeater1, repeater2)
93+ let subject = QLAnchor < Int > ( earlyRepeaters: repeater1, repeater2)
94+ XCTAssertEqual ( subject. getRepeaters ( timing: . early) . count, 2 )
95+
96+ subject. onChange = { receivedVal0 = $0!; expectOriginal0. fulfill ( ) }
97+
98+ subject. value = 99
99+
100+ wait ( for: [ expectOriginal0, expectRepeater1, expectRepeater2] , timeout: 8.0 )
101+ XCTAssertEqual ( receivedVal0, 99 )
102+ XCTAssertEqual ( receivedVal1, 99 )
103+ XCTAssertEqual ( receivedVal2, 99 )
104+ }
105+
106+ func test_given_it_has_late_repeaters_with_default_filter_when_input_set_then_it_echoes_to_them_as_well( ) {
107+ var receivedVal0 : Int = - 1
108+ var receivedVal1 : Int = - 1
109+ var receivedVal2 : Int = - 1
110+ let expectOriginal0 = expectation ( description: " should dispatch value " )
111+ let expectRepeater1 = expectation ( description: " should echo value to repeater1 " )
112+ let expectRepeater2 = expectation ( description: " should echo value to repeater2 " )
113+ let repeater1 = QLAnchor < Int > ( onChange: { receivedVal1 = $0!; expectRepeater1. fulfill ( ) } )
114+ let repeater2 = QLAnchor < Int > ( onChange: { receivedVal2 = $0!; expectRepeater2. fulfill ( ) } )
115+ let subject = QLAnchor < Int > ( lateRepeaters: repeater1, repeater2)
116+ XCTAssertEqual ( subject. getRepeaters ( timing: . late) . count, 2 )
94117
95118 subject. onChange = { receivedVal0 = $0!; expectOriginal0. fulfill ( ) }
96119
@@ -113,7 +136,9 @@ final class QLAnchorTests: XCTestCase {
113136 onError: { receivedErr1 = $0; expectRepeater1. fulfill ( ) } )
114137 let repeater2 = QLAnchor < Int > ( onChange: { _ in } ,
115138 onError: { receivedErr2 = $0; expectRepeater2. fulfill ( ) } )
116- let subject = QLAnchor < Int > ( repeaters: repeater1, repeater2)
139+ let subject = QLAnchor < Int > ( earlyRepeaters: [ repeater1] , lateRepeaters: [ repeater2] )
140+ XCTAssertEqual ( subject. getRepeaters ( timing: . early) . count, 1 )
141+ XCTAssertEqual ( subject. getRepeaters ( timing: . late) . count, 1 )
117142
118143 subject. onError = { receivedErr0 = $0; expectOriginal0. fulfill ( ) }
119144
@@ -125,7 +150,34 @@ final class QLAnchorTests: XCTestCase {
125150 XCTAssertNotNil ( receivedErr2)
126151 }
127152
128- func test_given_it_has_repeaters_with_custom_filter_when_input_set_then_it_dispatches_then_echoes_to_them_conditionally( ) {
153+ func test_given_it_has_earlyRepeaters_with_custom_filter_when_input_set_then_it_dispatches_then_echoes_to_them_conditionally( ) {
154+ var receivedVal0 : Int = - 1
155+ var receivedVal1 : Int = - 1
156+ var receivedVal2 : Int = - 1
157+ let expectOriginal0 = expectation ( description: " should dispatch value " )
158+ let expectRepeater2 = expectation ( description: " should echo value to repeater2 " )
159+ let repeater1 = QLAnchor < Int > ( onChange: { receivedVal1 = $0! } )
160+ let repeater2 = QLAnchor < Int > ( onChange: { receivedVal2 = $0!; expectRepeater2. fulfill ( ) } )
161+
162+ let subject = QLAnchor < Int > (
163+ echoFilter: ( { val, repeater in
164+ return ( val == 11 && repeater === repeater1)
165+ || ( val == 22 && repeater === repeater2)
166+ } ) ,
167+ earlyRepeaters: repeater1, repeater2
168+ )
169+
170+ subject. onChange = { receivedVal0 = $0!; expectOriginal0. fulfill ( ) }
171+
172+ subject. value = 22
173+
174+ wait ( for: [ expectOriginal0, expectRepeater2] , timeout: 8.0 )
175+ XCTAssertEqual ( receivedVal0, 22 )
176+ XCTAssertEqual ( receivedVal1, - 1 )
177+ XCTAssertEqual ( receivedVal2, 22 )
178+ }
179+
180+ func test_given_it_has_lateRepeaters_with_custom_filter_when_input_set_then_it_dispatches_then_echoes_to_them_conditionally( ) {
129181 var receivedVal0 : Int = - 1
130182 var receivedVal1 : Int = - 1
131183 var receivedVal2 : Int = - 1
@@ -139,7 +191,7 @@ final class QLAnchorTests: XCTestCase {
139191 return ( val == 11 && repeater === repeater1)
140192 || ( val == 22 && repeater === repeater2)
141193 } ) ,
142- repeaters : repeater1, repeater2
194+ lateRepeaters : repeater1, repeater2
143195 )
144196
145197 subject. onChange = { receivedVal0 = $0!; expectOriginal0. fulfill ( ) }
0 commit comments