|
5 | 5 | QuickSpecBegin(OFExtensionSpec) |
6 | 6 |
|
7 | 7 | describe(@"NSBlockOperation+AsyncBlock", ^{ |
8 | | - context(@"when several operations in queue", ^{ |
9 | | - it(@"is max concurent operation in queue equal one", ^{ |
| 8 | + context(@"when use serial queue", ^{ |
| 9 | + it(@"run async operation in series", ^{ |
10 | 10 | __block NSString *testString = @""; |
11 | 11 | NSOperationQueue *testOperationQueue = [[NSOperationQueue alloc]init]; |
12 | 12 | testOperationQueue.maxConcurrentOperationCount = 1; |
13 | 13 | [testOperationQueue addOperationWithAsyncBlock:^(OFAsyncBlockFinish _Nonnull finish) { |
14 | | - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
15 | | - testString = @"first operation"; |
| 14 | + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
| 15 | + testString = [testString stringByAppendingString:@"1"]; |
16 | 16 | finish(); |
17 | 17 | }); |
18 | 18 | }]; |
19 | 19 | [testOperationQueue addOperationWithAsyncBlock:^(OFAsyncBlockFinish _Nonnull finish) { |
20 | | - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
21 | | - testString = @"second operation"; |
| 20 | + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
| 21 | + testString = [testString stringByAppendingString:@"2"]; |
22 | 22 | finish(); |
23 | 23 | }); |
24 | 24 | }]; |
25 | 25 | [testOperationQueue addOperationWithAsyncBlock:^(OFAsyncBlockFinish _Nonnull finish) { |
26 | 26 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
27 | | - testString = @"third operation"; |
| 27 | + testString = [testString stringByAppendingString:@"3"]; |
28 | 28 | finish(); |
29 | 29 | }); |
30 | 30 | }]; |
31 | | - expect(testString).withTimeout(1.5).toEventually(equal(@"third operation")); |
| 31 | + expect(testString).toEventually(equal(@"123")); |
32 | 32 | }); |
33 | | - |
34 | | - it(@"is max concurent operation in queue equal two", ^{ |
| 33 | + }); |
| 34 | + context(@"when use parallel queue", ^{ |
| 35 | + it(@"run async operation in parallel", ^{ |
35 | 36 | __block NSString *testString = @""; |
36 | 37 | NSOperationQueue *testOperationQueue = [[NSOperationQueue alloc]init]; |
37 | | - testOperationQueue.maxConcurrentOperationCount = 2; |
| 38 | + testOperationQueue.maxConcurrentOperationCount = 3; |
38 | 39 | [testOperationQueue addOperationWithAsyncBlock:^(OFAsyncBlockFinish _Nonnull finish) { |
39 | | - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
40 | | - testString = @"first operation"; |
| 40 | + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
| 41 | + testString = [testString stringByAppendingString:@"1"]; |
41 | 42 | finish(); |
42 | 43 | }); |
43 | 44 | }]; |
44 | 45 | [testOperationQueue addOperationWithAsyncBlock:^(OFAsyncBlockFinish _Nonnull finish) { |
45 | | - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
46 | | - testString = @"second operation"; |
| 46 | + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
| 47 | + testString = [testString stringByAppendingString:@"2"]; |
47 | 48 | finish(); |
48 | 49 | }); |
49 | 50 | }]; |
50 | 51 | [testOperationQueue addOperationWithAsyncBlock:^(OFAsyncBlockFinish _Nonnull finish) { |
51 | | - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
52 | | - testString = @"third operation"; |
| 52 | + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
| 53 | + testString = [testString stringByAppendingString:@"3"]; |
53 | 54 | finish(); |
54 | 55 | }); |
55 | 56 | }]; |
56 | | - expect(testString).withTimeout(1.5).toEventually(equal(@"second operation")); |
| 57 | + expect(testString).toEventually(equal(@"132")); |
57 | 58 | }); |
58 | 59 | }); |
59 | 60 | }); |
60 | 61 |
|
61 | 62 | describe(@"NSString+Regex", ^{ |
62 | 63 | context(@"when the string is checked for regex", ^{ |
63 | 64 | NSString *testString = @"This is test string."; |
64 | | - it(@"is match regex", ^{ |
| 65 | + it(@"match regex", ^{ |
65 | 66 | NSString *testRegex = @".*"; |
66 | 67 | expect(@([testString matchRegex:testRegex])).to(beTrue()); |
67 | 68 | }); |
68 | 69 |
|
69 | | - it(@"is first match of regex", ^{ |
70 | | - NSString *testRegex = @"[t]"; |
71 | | - NSString *testResult = @"t"; |
72 | | - expect([testString firstMatchOfRegex:testRegex]).to(equal(testResult)); |
| 70 | + it(@"has first match of regex", ^{ |
| 71 | + NSString *testRegex = @"is"; |
| 72 | + expect([testString firstMatchOfRegex:testRegex]).toNot(beNil()); |
73 | 73 | }); |
74 | 74 |
|
75 | | - it(@"is all matches of regex", ^{ |
76 | | - NSString *testRegex = @"[t]"; |
77 | | - NSString *testResult = @"ttt"; |
78 | | - expect([[testString allMatchesOfRegex:testRegex] componentsJoinedByString:@""]).to(equal(testResult)); |
| 75 | + it(@"has all matches of regex", ^{ |
| 76 | + NSString *testRegex = @"is"; |
| 77 | + NSInteger resultCount = 2; |
| 78 | + expect(@([testString allMatchesOfRegex:testRegex].count)).to(equal(@(resultCount))); |
79 | 79 | }); |
80 | 80 |
|
81 | | - it(@"is match email", ^{ |
82 | | - NSString *testEmail = @"test@gmail.com"; |
| 81 | + it(@"has match email", ^{ |
| 82 | + NSString *testEmail = @"test@mail.com"; |
83 | 83 | expect(@([testEmail matchEmailString])).to(beTrue()); |
84 | 84 | }); |
85 | 85 | }); |
| 86 | + context(@"when the string is not checked for regex", ^{ |
| 87 | + NSString *testString = @"This is test string."; |
| 88 | + it(@"not match regex", ^{ |
| 89 | + NSString *testRegex = @"This"; |
| 90 | + expect(@([testString matchRegex:testRegex])).toNot(beTrue()); |
| 91 | + }); |
| 92 | + it(@"has not first match of regex", ^{ |
| 93 | + NSString *testRegex = @"testing"; |
| 94 | + expect([testString firstMatchOfRegex:testRegex]).to(beNil()); |
| 95 | + }); |
| 96 | + |
| 97 | + it(@"has not all matches of regex", ^{ |
| 98 | + NSString *testRegex = @"testing"; |
| 99 | + expect([testString firstMatchOfRegex:testRegex]).to(beNil()); |
| 100 | + }); |
| 101 | + |
| 102 | + it(@"has not match email", ^{ |
| 103 | + NSString *testEmail = @"testmail.com"; |
| 104 | + expect(@([testEmail matchEmailString])).toNot(beTrue()); |
| 105 | + }); |
| 106 | + }); |
86 | 107 | }); |
87 | 108 |
|
88 | 109 | describe(@"UIColor+HexString", ^{ |
89 | | - context(@"when color setted by hex string", ^{ |
90 | | - |
91 | | - it(@"is converting hex string to color", ^{ |
92 | | - // alizarin color |
93 | | - // hex(#e74c3c) |
94 | | - // rgba(231, 76, 60,1.0) |
| 110 | + context(@"when valid hex string", ^{ |
| 111 | + it(@"create color", ^{ |
95 | 112 | NSString *testStringColor = @"#e74c3c"; |
96 | 113 | CGFloat testR = 231/256.0f, testG = 76/256.0f,testB = 60/256.0f,testA = 1.0f; |
97 | 114 | UIColor *testColor = [UIColor colorWithHexString:testStringColor alpha:1.0f]; |
|
102 | 119 | expect(@(b)).to(equal(@(testB))); |
103 | 120 | expect(@(a)).to(equal(@(testA))); |
104 | 121 | }); |
| 122 | + context(@"when NOT valid hex string", ^{ |
| 123 | + it(@"create NIL color", ^{ |
| 124 | + NSString *testStringColor = @"#888e74c3c"; |
| 125 | + expect([UIColor colorWithHexString:testStringColor alpha:1.0f]).to(beNil()); |
| 126 | + }); |
| 127 | + }); |
| 128 | + |
105 | 129 | }); |
106 | 130 | }); |
107 | 131 |
|
108 | 132 | QuickSpecEnd |
| 133 | + |
0 commit comments