Permalink
Browse files

Added expecta matchers for tests

  • Loading branch information...
1 parent ecdb738 commit cff03044c52c399c6d3365c945f948036f3d9f36 @blackgold9 blackgold9 committed Sep 6, 2012
Showing with 1,413 additions and 0 deletions.
  1. +42 −0 Project Files/Third Party/expecta/EXPBackwardCompatibility.h
  2. +17 −0 Project Files/Third Party/expecta/EXPBackwardCompatibility.m
  3. +25 −0 Project Files/Third Party/expecta/EXPBlockDefinedMatcher.h
  4. +50 −0 Project Files/Third Party/expecta/EXPBlockDefinedMatcher.m
  5. +17 −0 Project Files/Third Party/expecta/EXPDefines.h
  6. +13 −0 Project Files/Third Party/expecta/EXPDoubleTuple.h
  7. +42 −0 Project Files/Third Party/expecta/EXPDoubleTuple.m
  8. +42 −0 Project Files/Third Party/expecta/EXPExpect.h
  9. +192 −0 Project Files/Third Party/expecta/EXPExpect.m
  10. +13 −0 Project Files/Third Party/expecta/EXPFloatTuple.h
  11. +42 −0 Project Files/Third Party/expecta/EXPFloatTuple.m
  12. +20 −0 Project Files/Third Party/expecta/EXPMatcher.h
  13. +11 −0 Project Files/Third Party/expecta/EXPUnsupportedObject.h
  14. +20 −0 Project Files/Third Party/expecta/EXPUnsupportedObject.m
  15. +3 −0 Project Files/Third Party/expecta/Expecta-Prefix.pch
  16. +27 −0 Project Files/Third Party/expecta/Expecta.h
  17. +15 −0 Project Files/Third Party/expecta/Expecta.m
  18. +47 −0 Project Files/Third Party/expecta/ExpectaSupport.h
  19. +161 −0 Project Files/Third Party/expecta/ExpectaSupport.m
  20. +5 −0 Project Files/Third Party/expecta/NSObject+Expecta.h
  21. +8 −0 Project Files/Third Party/expecta/NSValue+Expecta.h
  22. +21 −0 Project Files/Third Party/expecta/NSValue+Expecta.m
  23. +4 −0 Project Files/Third Party/expecta/matchers/EXPMatcherHelpers.h
  24. +9 −0 Project Files/Third Party/expecta/matchers/EXPMatcherHelpers.m
  25. +7 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beCloseTo.h
  26. +43 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beCloseTo.m
  27. +3 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beFalsy.h
  28. +24 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beFalsy.m
  29. +6 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beGreaterThan.h
  30. +20 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beGreaterThan.m
  31. +6 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beGreaterThanOrEqualTo.h
  32. +20 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beGreaterThanOrEqualTo.m
  33. +9 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beIdenticalTo.h
  34. +24 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beIdenticalTo.m
  35. +6 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beInTheRangeOf.h
  36. +30 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beInTheRangeOf.m
  37. +7 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beInstanceOf.h
  38. +27 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beInstanceOf.m
  39. +5 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beKindOf.h
  40. +27 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beKindOf.m
  41. +6 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beLessThan.h
  42. +20 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beLessThan.m
  43. +6 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beLessThanOrEqualTo.h
  44. +20 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beLessThanOrEqualTo.m
  45. +5 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beNil.h
  46. +16 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beNil.m
  47. +5 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beSubclassOf.h
  48. +27 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beSubclassOf.m
  49. +3 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beTruthy.h
  50. +24 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+beTruthy.m
  51. +5 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+contain.h
  52. +38 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+contain.m
  53. +5 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+equal.h
  54. +24 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+equal.m
  55. +10 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+haveCountOf.h
  56. +38 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+haveCountOf.m
  57. +4 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+raise.h
  58. +30 −0 Project Files/Third Party/expecta/matchers/EXPMatchers+raise.m
  59. +17 −0 Project Files/Third Party/expecta/matchers/EXPMatchers.h
@@ -0,0 +1,42 @@
+#import "EXPExpect.h"
+
+@interface EXPExpect (BackwardCompatiblity)
+
+@property(nonatomic, readonly) EXPExpect *Not;
+@property(nonatomic, readonly) EXPExpect *isGoing;
+@property(nonatomic, readonly) EXPExpect *isNotGoing;
+
+@end
+
+#define toBeFalsy beFalsy
+#define toBeGreaterThan beGreaterThan
+#define toBeGreaterThanOrEqualTo beGreaterThanOrEqualTo
+#define toBeIdenticalTo beIdenticalTo
+#define toBeInTheRangeOf beInTheRangeOf
+#define toBeInstanceOf beInstanceOf
+#define toBeAnInstanceOf beInstanceOf
+#define toBeMemberOf beInstanceOf
+#define toBeAMemberOf beInstanceOf
+#define toBeKindOf beKindOf
+#define toBeAKindOf beKindOf
+#define toBeLessThan beLessThan
+#define toBeLessThanOrEqualTo beLessThanOrEqualTo
+#define toBeNil beNil
+#define toBeNull beNil
+#define toBeSubclassOf beSubclassOf
+#define toBeASubclassOf beSubclassOf
+#define toBeTruthy beTruthy
+#define toBeFalsy beFalsy
+#define toContain contain
+#define toEqual equal
+#define toBeCloseTo beCloseTo
+#define toBeCloseToWithin beCloseToWithin
+#define toHaveCount haveCountOf
+#define toHaveCountOf haveCountOf
+#define toHaveACountOf haveCountOf
+#define toHaveLength haveCountOf
+#define toHaveLengthOf haveCountOf
+#define toHaveALengthOf haveCountOf
+#define toBeEmpty beEmpty
+#define toRaise raise
+#define toRaiseAny raiseAny
@@ -0,0 +1,17 @@
+#import "EXPBackwardCompatibility.h"
+
+@implementation EXPExpect (BackwardCompatiblity)
+
+- (EXPExpect *)Not {
+ return self.toNot;
+}
+
+- (EXPExpect *)isGoing {
+ return self.will;
+}
+
+- (EXPExpect *)isNotGoing {
+ return self.willNot;
+}
+
+@end
@@ -0,0 +1,25 @@
+//
+// EXPRuntimeMatcher.h
+// Expecta
+//
+// Created by Luke Redpath on 26/03/2012.
+// Copyright (c) 2012 Peter Jihoon Kim. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import "EXPMatcher.h"
+#import "EXPDefines.h"
+
+@interface EXPBlockDefinedMatcher : NSObject <EXPMatcher> {
+ EXPBoolBlock prerequisiteBlock;
+ EXPBoolBlock matchBlock;
+ EXPStringBlock failureMessageForToBlock;
+ EXPStringBlock failureMessageForNotToBlock;
+}
+
+@property(nonatomic, copy) EXPBoolBlock prerequisiteBlock;
+@property(nonatomic, copy) EXPBoolBlock matchBlock;
+@property(nonatomic, copy) EXPStringBlock failureMessageForToBlock;
+@property(nonatomic, copy) EXPStringBlock failureMessageForNotToBlock;
+
+@end
@@ -0,0 +1,50 @@
+//
+// EXPRuntimeMatcher.m
+// Expecta
+//
+// Created by Luke Redpath on 26/03/2012.
+// Copyright (c) 2012 Peter Jihoon Kim. All rights reserved.
+//
+
+#import "EXPBlockDefinedMatcher.h"
+
+@implementation EXPBlockDefinedMatcher
+
+@synthesize prerequisiteBlock;
+@synthesize matchBlock;
+@synthesize failureMessageForToBlock;
+@synthesize failureMessageForNotToBlock;
+
+- (BOOL)meetsPrerequesiteFor:(id)actual
+{
+ if (self.prerequisiteBlock) {
+ return self.prerequisiteBlock();
+ }
+ return YES;
+}
+
+- (BOOL)matches:(id)actual
+{
+ if (self.matchBlock) {
+ return self.matchBlock();
+ }
+ return YES;
+}
+
+- (NSString *)failureMessageForTo:(id)actual
+{
+ if (self.failureMessageForToBlock) {
+ return self.failureMessageForToBlock();
+ }
+ return nil;
+}
+
+- (NSString *)failureMessageForNotTo:(id)actual
+{
+ if (self.failureMessageForNotToBlock) {
+ return self.failureMessageForNotToBlock();
+ }
+ return nil;
+}
+
+@end
@@ -0,0 +1,17 @@
+//
+// EXPDefines.h
+// Expecta
+//
+// Created by Luke Redpath on 26/03/2012.
+// Copyright (c) 2012 Peter Jihoon Kim. All rights reserved.
+//
+
+#ifndef Expecta_EXPDefines_h
+#define Expecta_EXPDefines_h
+
+typedef void (^EXPBasicBlock)();
+typedef id (^EXPIdBlock)();
+typedef BOOL (^EXPBoolBlock)();
+typedef NSString *(^EXPStringBlock)();
+
+#endif
@@ -0,0 +1,13 @@
+#import <Foundation/Foundation.h>
+
+@interface EXPDoubleTuple : NSObject {
+ double *_values;
+ size_t _size;
+}
+
+@property (nonatomic, assign) double *values;
+@property (nonatomic, assign) size_t size;
+
+- (id)initWithDoubleValues:(double *)values size:(size_t)size;
+
+@end
@@ -0,0 +1,42 @@
+#import "EXPDoubleTuple.h"
+
+@implementation EXPDoubleTuple
+
+@synthesize values = _values, size = _size;
+
+- (id)initWithDoubleValues:(double *)values size:(size_t)size {
+ if ((self = [super init])) {
+ self.values = malloc(sizeof(double) * size);
+ memcpy(self.values, values, sizeof(double) * size);
+ self.size = size;
+ }
+ return self;
+}
+
+- (void)dealloc {
+ free(self.values);
+ [super dealloc];
+}
+
+- (BOOL)isEqual:(id)object {
+ if (![object isKindOfClass:[EXPDoubleTuple class]]) return NO;
+ EXPDoubleTuple *other = (EXPDoubleTuple *)object;
+ if (self.size == other.size) {
+ for (int i = 0; i < self.size; ++i) {
+ if (self.values[i] != other.values[i]) return NO;
+ }
+ return YES;
+ }
+ return NO;
+}
+
+- (NSString *)description {
+ if (self.size == 2) {
+ return [NSString stringWithFormat:@"Double tuple: {%f, %f}", self.values[0], self.values[1]];
+ } else if (self.size == 4) {
+ return [NSString stringWithFormat:@"Double tuple: {%f, %f, %f, %f}", self.values[0], self.values[1], self.values[2], self.values[3]];
+ }
+ return [NSString stringWithFormat:@"Double tuple of unexpected size %d, sadly", self.size];
+}
+
+@end
@@ -0,0 +1,42 @@
+#import <Foundation/Foundation.h>
+#import "EXPMatcher.h"
+#import "EXPDefines.h"
+
+@interface EXPExpect : NSObject {
+ EXPIdBlock _actualBlock;
+ id _testCase;
+ int _lineNumber;
+ char *_fileName;
+ BOOL _negative;
+ BOOL _asynchronous;
+}
+
+@property(nonatomic, copy) EXPIdBlock actualBlock;
+@property(nonatomic, readonly) id actual;
+@property(nonatomic, assign) id testCase;
+@property(nonatomic) int lineNumber;
+@property(nonatomic) char *fileName;
+@property(nonatomic) BOOL negative;
+@property(nonatomic) BOOL asynchronous;
+
+@property(nonatomic, readonly) EXPExpect *to;
+@property(nonatomic, readonly) EXPExpect *toNot;
+@property(nonatomic, readonly) EXPExpect *notTo;
+@property(nonatomic, readonly) EXPExpect *will;
+@property(nonatomic, readonly) EXPExpect *willNot;
+
+- (id)initWithActualBlock:(id)actualBlock testCase:(id)testCase lineNumber:(int)lineNumber fileName:(char *)fileName;
++ (EXPExpect *)expectWithActualBlock:(id)actualBlock testCase:(id)testCase lineNumber:(int)lineNumber fileName:(char *)fileName;
+
+- (void)applyMatcher:(id<EXPMatcher>)matcher;
+- (void)applyMatcher:(id<EXPMatcher>)matcher to:(NSObject **)actual;
+
+@end
+
+@interface EXPDynamicPredicateMatcher : NSObject <EXPMatcher> {
+ EXPExpect *_expectation;
+ SEL _selector;
+}
+- (id)initWithExpectation:(EXPExpect *)expectation selector:(SEL)selector;
+- (void (^)(void))dispatch;
+@end
Oops, something went wrong.

0 comments on commit cff0304

Please sign in to comment.