KWGenericMatcher.m 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // KWGenericMatcher.m
  3. // Kiwi
  4. //
  5. // Created by Luke Redpath on 24/01/2011.
  6. // Copyright 2011 Allen Ding. All rights reserved.
  7. //
  8. #import "KWGenericMatcher.h"
  9. #import "KWGenericMatchEvaluator.h"
  10. @interface KWGenericMatcher ()
  11. @property (nonatomic, strong) id<KWGenericMatching> matcher;
  12. @end
  13. @implementation KWGenericMatcher
  14. #pragma mark - Matching
  15. - (BOOL)evaluate {
  16. if ([KWGenericMatchEvaluator isGenericMatcher:self.matcher]) {
  17. return [KWGenericMatchEvaluator genericMatcher:self.matcher matches:self.subject];
  18. } else {
  19. return [self.matcher isEqual:self.subject];
  20. }
  21. }
  22. - (NSString *)failureMessageForShould {
  23. return [NSString stringWithFormat:@"expected subject to match %@", self.matcher];
  24. }
  25. - (NSString *)description
  26. {
  27. return [NSString stringWithFormat:@"match %@", [self.matcher description]];
  28. }
  29. #pragma mark - Getting Matcher Strings
  30. + (NSArray *)matcherStrings {
  31. return @[@"match:"];
  32. }
  33. #pragma mark - Configuring Matchers
  34. - (void)match:(id)aMatcher;
  35. {
  36. self.matcher = aMatcher;
  37. }
  38. @end