@@ -11,10 +11,6 @@ import XCTest
1111
1212
1313
14- internal let first5Fibonacci = [ 1 , 1 , 2 , 3 , 5 ]
15-
16-
17-
1814final class RangeOrNilTests : XCTestCase {
1915
2016
@@ -61,6 +57,14 @@ final class RangeOrNilTests: XCTestCase {
6157 XCTAssertNil ( first5Fibonacci [ orNil: 7 ..< 9 ] )
6258
6359
60+ XCTAssertEqual ( helloWorld [ orNil: helloWorld. startIndex ..< helloWorld. endIndex ] , " Hello, World! " )
61+ XCTAssertEqual ( helloWorld [ orNil: helloWorld. startIndex ..< helloWorld. index ( helloWorld. startIndex, offsetBy: 1 ) ] , " H " )
62+ XCTAssertEqual ( helloWorld [ orNil: helloWorld. index ( helloWorld. startIndex, offsetBy: 1 ) ..< helloWorld. index ( helloWorld. startIndex, offsetBy: 5 ) ] , " ello " )
63+ XCTAssertEqual ( helloWorld [ orNil: helloWorld. index ( helloWorld. startIndex, offsetBy: 5 ) ..< helloWorld. index ( helloWorld. startIndex, offsetBy: 5 ) ] , " " )
64+ XCTAssertEqual ( helloWorld [ orNil: helloWorld. index ( helloWorld. startIndex, offsetBy: 12 ) ..< helloWorld. index ( helloWorld. startIndex, offsetBy: 12 ) ] , " " )
65+ XCTAssertEqual ( helloWorld [ orNil: helloWorld. index ( helloWorld. startIndex, offsetBy: 11 ) ..< helloWorld. endIndex ] , " d! " )
66+
67+
6468 mutationTest { copy1, copy2 in
6569 copy2 [ 1 ..< 3 ] = [ 9 ]
6670 copy1 [ orNil: 1 ..< 3 ] = [ 9 ]
@@ -142,6 +146,16 @@ final class RangeOrNilTests: XCTestCase {
142146 XCTAssertNil ( first5Fibonacci [ orNil: 7 ... 9 ] )
143147
144148
149+ XCTAssertEqual ( helloWorld [ orNil: helloWorld. startIndex ... helloWorld. index ( helloWorld. startIndex, offsetBy: 12 ) ] , " Hello, World! " )
150+ XCTAssertEqual ( helloWorld [ orNil: helloWorld. startIndex ... helloWorld. index ( helloWorld. startIndex, offsetBy: 1 ) ] , " He " )
151+ XCTAssertEqual ( helloWorld [ orNil: helloWorld. index ( helloWorld. startIndex, offsetBy: 1 ) ... helloWorld. index ( helloWorld. startIndex, offsetBy: 5 ) ] , " ello, " )
152+ XCTAssertEqual ( helloWorld [ orNil: helloWorld. index ( helloWorld. startIndex, offsetBy: 12 ) ... helloWorld. index ( helloWorld. startIndex, offsetBy: 12 ) ] , " ! " )
153+ XCTAssertEqual ( helloWorld [ orNil: helloWorld. index ( helloWorld. startIndex, offsetBy: 11 ) ... helloWorld. index ( helloWorld. startIndex, offsetBy: 12 ) ] , " d! " )
154+
155+
156+ XCTAssertNil ( helloWorld [ orNil: helloWorld. startIndex ... helloWorld. index ( helloWorld. startIndex, offsetBy: 13 ) ] )
157+
158+
145159 mutationTest { copy1, copy2 in
146160 copy2 [ 1 ... 3 ] = [ 9 ]
147161 copy1 [ orNil: 1 ... 3 ] = [ 9 ]
@@ -293,6 +307,13 @@ final class RangeOrNilTests: XCTestCase {
293307 XCTAssertNil ( first5Fibonacci [ orNil: ..< ( - 10 ) ] )
294308 XCTAssertNil ( first5Fibonacci [ orNil: ..< ( 9 ) ] )
295309
310+ XCTAssertEqual ( helloWorld [ orNil: ..< helloWorld. startIndex ] , " " )
311+ XCTAssertEqual ( helloWorld [ orNil: ..< helloWorld. index ( helloWorld. startIndex, offsetBy: 1 ) ] , " H " )
312+ XCTAssertEqual ( helloWorld [ orNil: ..< helloWorld. index ( helloWorld. startIndex, offsetBy: 5 ) ] , " Hello " )
313+ XCTAssertEqual ( helloWorld [ orNil: ..< helloWorld. index ( helloWorld. startIndex, offsetBy: 12 ) ] , " Hello, World " )
314+ XCTAssertEqual ( helloWorld [ orNil: ..< helloWorld. index ( helloWorld. startIndex, offsetBy: 12 ) ] , " Hello, World " )
315+ XCTAssertEqual ( helloWorld [ orNil: ..< helloWorld. index ( helloWorld. startIndex, offsetBy: 13 ) ] , " Hello, World! " )
316+
296317
297318
298319 mutationTest { copy1, copy2 in
@@ -376,6 +397,12 @@ final class RangeOrNilTests: XCTestCase {
376397 XCTAssertNil ( first5Fibonacci [ orNil: ... ( 6 ) ] )
377398 XCTAssertNil ( first5Fibonacci [ orNil: ... ( - 10 ) ] )
378399 XCTAssertNil ( first5Fibonacci [ orNil: ... ( 9 ) ] )
400+
401+ XCTAssertEqual ( helloWorld [ orNil: ... helloWorld. startIndex ] , " H " )
402+ XCTAssertEqual ( helloWorld [ orNil: ... helloWorld. index ( helloWorld. startIndex, offsetBy: 1 ) ] , " He " )
403+ XCTAssertEqual ( helloWorld [ orNil: ... helloWorld. index ( helloWorld. startIndex, offsetBy: 5 ) ] , " Hello, " )
404+ XCTAssertEqual ( helloWorld [ orNil: ... helloWorld. index ( helloWorld. startIndex, offsetBy: 11 ) ] , " Hello, World " )
405+ XCTAssertEqual ( helloWorld [ orNil: ... helloWorld. index ( helloWorld. startIndex, offsetBy: 12 ) ] , " Hello, World! " )
379406
380407
381408
@@ -446,27 +473,3 @@ final class RangeOrNilTests: XCTestCase {
446473 ( " testSubscriptOrNil_PartialRangeUpThrough " , testSubscriptOrNil_PartialRangeUpThrough) ,
447474 ]
448475}
449-
450-
451-
452- internal func mutationTest< Value> ( with value: Value , do closure: ( _ copy: inout Value ) -> Void ) {
453- var copy = value
454- closure ( & copy)
455- }
456-
457-
458- internal func mutationTest( do test: ( _ copy: inout [ Int ] ) -> Void ) {
459- mutationTest ( with: first5Fibonacci, do: test)
460- }
461-
462-
463- internal func mutationTest< Value> ( with value: Value , do closure: ( _ copy1: inout Value , _ copy2: inout Value ) -> Void ) {
464- var copy1 = value
465- var copy2 = value
466- closure ( & copy1, & copy2)
467- }
468-
469-
470- internal func mutationTest( do test: ( _ copy1: inout [ Int ] , _ copy2: inout [ Int ] ) -> Void ) {
471- mutationTest ( with: first5Fibonacci, do: test)
472- }
0 commit comments