|
5 | 5 | QuickSpecBegin(OFExtensionSpec) |
6 | 6 |
|
7 | 7 | describe(@"NSBlockOperation+AsyncBlock", ^{ |
8 | | - |
9 | | -}) |
| 8 | + context(@"when several operations in queue", ^{ |
| 9 | + it(@"is max concurent operation in queue equal one", ^{ |
| 10 | + __block NSString *testString = @""; |
| 11 | + NSOperationQueue *testOperationQueue = [[NSOperationQueue alloc]init]; |
| 12 | + testOperationQueue.maxConcurrentOperationCount = 1; |
| 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"; |
| 16 | + finish(); |
| 17 | + }); |
| 18 | + }]; |
| 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"; |
| 22 | + finish(); |
| 23 | + }); |
| 24 | + }]; |
| 25 | + [testOperationQueue addOperationWithAsyncBlock:^(OFAsyncBlockFinish _Nonnull finish) { |
| 26 | + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
| 27 | + testString = @"third operation"; |
| 28 | + finish(); |
| 29 | + }); |
| 30 | + }]; |
| 31 | + expect(testString).withTimeout(1.5).toEventually(equal(@"third operation")); |
| 32 | + }); |
| 33 | + |
| 34 | + it(@"is max concurent operation in queue equal two", ^{ |
| 35 | + __block NSString *testString = @""; |
| 36 | + NSOperationQueue *testOperationQueue = [[NSOperationQueue alloc]init]; |
| 37 | + testOperationQueue.maxConcurrentOperationCount = 2; |
| 38 | + [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"; |
| 41 | + finish(); |
| 42 | + }); |
| 43 | + }]; |
| 44 | + [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"; |
| 47 | + finish(); |
| 48 | + }); |
| 49 | + }]; |
| 50 | + [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"; |
| 53 | + finish(); |
| 54 | + }); |
| 55 | + }]; |
| 56 | + expect(testString).withTimeout(1.5).toEventually(equal(@"second operation")); |
| 57 | + }); |
| 58 | + }); |
| 59 | +}); |
10 | 60 |
|
11 | 61 | describe(@"NSString+Regex", ^{ |
12 | | - |
13 | | -}) |
| 62 | + context(@"when the string is checked for regex", ^{ |
| 63 | + NSString *testString = @"This is test string."; |
| 64 | + it(@"is match regex", ^{ |
| 65 | + NSString *testRegex = @".*"; |
| 66 | + expect(@([testString matchRegex:testRegex])).to(beTrue()); |
| 67 | + }); |
| 68 | + |
| 69 | + it(@"is first match of regex", ^{ |
| 70 | + NSString *testRegex = @"[t]"; |
| 71 | + NSString *testResult = @"t"; |
| 72 | + expect([testString firstMatchOfRegex:testRegex]).to(equal(testResult)); |
| 73 | + }); |
| 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)); |
| 79 | + }); |
| 80 | + |
| 81 | + it(@"is match email", ^{ |
| 82 | + NSString *testEmail = @"test@gmail.com"; |
| 83 | + expect(@([testEmail matchEmailString])).to(beTrue()); |
| 84 | + }); |
| 85 | + }); |
| 86 | +}); |
14 | 87 |
|
15 | 88 | describe(@"UIColor+HexString", ^{ |
16 | | - |
17 | | -}) |
| 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) |
| 95 | + NSString *testStringColor = @"#e74c3c"; |
| 96 | + CGFloat testR = 231/256.0f, testG = 76/256.0f,testB = 60/256.0f,testA = 1.0f; |
| 97 | + UIColor *testColor = [UIColor colorWithHexString:testStringColor alpha:1.0f]; |
| 98 | + CGFloat r, g, b, a; |
| 99 | + [testColor getRed:&r green:&g blue:&b alpha:&a]; |
| 100 | + expect(@(r)).to(equal(@(testR))); |
| 101 | + expect(@(g)).to(equal(@(testG))); |
| 102 | + expect(@(b)).to(equal(@(testB))); |
| 103 | + expect(@(a)).to(equal(@(testA))); |
| 104 | + }); |
| 105 | + }); |
| 106 | +}); |
18 | 107 |
|
19 | 108 | QuickSpecEnd |
0 commit comments