Skip to content

Commit

Permalink
KWBeEvaluatedMatcher -> removed duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
trimmurrti committed May 3, 2016
1 parent 1d448fd commit d7b62d0
Showing 1 changed file with 42 additions and 49 deletions.
91 changes: 42 additions & 49 deletions Classes/Matchers/KWBeEvaluatedMatcher.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@
#import "KWWorkarounds.h"
#import "KWProxyBlock.h"

#define KWStartVAList(listName, argument) \
va_list listName; \
va_start(listName, argument);

#define KWMessagePatternWithVAListAndSignature(list, argument, signature) \
[KWBlockMessagePattern messagePatternWithSignature:(signature) \
firstArgumentFilter:argument \
argumentList:list]

#define KWBeEvaluatedWithCount(argument, type, countValue, signature) \
do { \
KWStartVAList(args, argument); \
[(id)self beEvaluatedWithMessagePattern:KWMessagePatternWithVAListAndSignature(args, argument, (signature)) \
countType:type \
count:countValue]; \
} while(0)

#define KWBeEvaluatedWithUnspecifiedCount(argument, signature) \
do { \
KWStartVAList(args, firstArgument) \
id pattern = KWMessagePatternWithVAListAndSignature(args, firstArgument, (signature)); \
[(id)self beEvaluatedWithUnspecifiedCountOfMessagePattern:pattern]; \
} while(0)

@implementation KWBeEvaluatedMatcher

#pragma mark - Getting Matcher Strings
Expand Down Expand Up @@ -62,44 +86,26 @@ - (void)beEvaluatedWithUnspecifiedCountOfMessagePattern:(KWBlockMessagePattern *
[self beEvaluatedWithCountType:countType count:1];
}

#define KWStartVAListWithVariableName(listName) \
va_list listName; \
va_start(listName, firstArgument);

- (void)beEvaluatedWithArguments:(id)firstArgument, ... {
va_list argumentList;
va_start(argumentList, firstArgument);

id pattern = [KWBlockMessagePattern messagePatternWithSignature:[self subjectSignature]
firstArgumentFilter:firstArgument
argumentList:argumentList];

[self beEvaluatedWithUnspecifiedCountOfMessagePattern:pattern];
KWBeEvaluatedWithUnspecifiedCount(firstArgument, [self subjectSignature]);
}

#define KWReceiveVAListMessagePatternWithCountType(aCountType) \
do { \
KWStartVAListWithVariableName(argumentList); \
id pattern = [KWBlockMessagePattern messagePatternWithSignature:[self subjectSignature] \
firstArgumentFilter:firstArgument \
argumentList:argumentList]; \
[self beEvaluatedWithMessagePattern:pattern countType:aCountType count:aCount]; \
} while(0)
#define KWBeEvaluatedWithCountType(type) \
KWBeEvaluatedWithCount(firstArgument, type, aCount, [self subjectSignature])

- (void)beEvaluatedWithCount:(NSUInteger)aCount arguments:(id)firstArgument, ... {
KWReceiveVAListMessagePatternWithCountType(KWCountTypeExact);
KWBeEvaluatedWithCountType(KWCountTypeExact);
}

- (void)beEvaluatedWithCountAtLeast:(NSUInteger)aCount arguments:(id)firstArgument, ... {
KWReceiveVAListMessagePatternWithCountType(KWCountTypeAtLeast);
KWBeEvaluatedWithCountType(KWCountTypeAtLeast);
}

- (void)beEvaluatedWithCountAtMost:(NSUInteger)aCount arguments:(id)firstArgument, ... {
KWReceiveVAListMessagePatternWithCountType(KWCountTypeAtMost);
KWBeEvaluatedWithCountType(KWCountTypeAtMost);
}

#undef KWReceiveVAListMessagePatternWithCountType
#undef KWArgumentList
#undef KWBeEvaluatedWithCountType

#pragma mark - Message Pattern Receiving

Expand Down Expand Up @@ -140,47 +146,34 @@ @implementation KWMatchVerifier (KWBeEvaluatedMatcherAdditions)

#pragma mark - Verifying

#define KWStartVAListWithVariableName(listName) \
va_list listName; \
va_start(listName, firstArgument);

- (void)beEvaluatedWithArguments:(id)firstArgument, ... {
KWStartVAListWithVariableName(argumentList)

id pattern = [KWBlockMessagePattern messagePatternWithSignature:[self beEvaluated_subjectSignature]
firstArgumentFilter:firstArgument
argumentList:argumentList];

[(id)self beEvaluatedWithUnspecifiedCountOfMessagePattern:pattern];
KWBeEvaluatedWithUnspecifiedCount(firstArgument, [self beEvaluated_subjectSignature]);
}

#define KWReceiveVAListMessagePatternWithCountType(aCountType) \
do { \
KWStartVAListWithVariableName(argumentList); \
id pattern = [KWBlockMessagePattern messagePatternWithSignature:[self beEvaluated_subjectSignature] \
firstArgumentFilter:firstArgument \
argumentList:argumentList]; \
[(id)self beEvaluatedWithMessagePattern:pattern countType:aCountType count:aCount]; \
} while(0)
#define KWBeEvaluatedWithCountType(type) \
KWBeEvaluatedWithCount(firstArgument, type, aCount, [self beEvaluated_subjectSignature])

- (void)beEvaluatedWithCount:(NSUInteger)aCount arguments:(id)firstArgument, ... {
KWReceiveVAListMessagePatternWithCountType(KWCountTypeExact);
KWBeEvaluatedWithCountType(KWCountTypeExact);
}

- (void)beEvaluatedWithCountAtLeast:(NSUInteger)aCount arguments:(id)firstArgument, ... {
KWReceiveVAListMessagePatternWithCountType(KWCountTypeAtLeast);
KWBeEvaluatedWithCountType(KWCountTypeAtLeast);
}

- (void)beEvaluatedWithCountAtMost:(NSUInteger)aCount arguments:(id)firstArgument, ... {
KWReceiveVAListMessagePatternWithCountType(KWCountTypeAtMost);
KWBeEvaluatedWithCountType(KWCountTypeAtMost);
}

#undef KWReceiveVAListMessagePatternWithCountType
#undef KWArgumentList
#undef KWBeEvaluatedWithCountType

- (NSMethodSignature *)beEvaluated_subjectSignature {
return [self.subject methodSignature];
}

@end

#undef KWBeEvaluatedWithUnspecifiedCount
#undef KWBeEvaluatedWithCount
#undef KWMessagePatternWithVAListAndSignature
#undef KWStartVAList

0 comments on commit d7b62d0

Please sign in to comment.