KWEqualMatcher.m 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // Licensed under the terms in License.txt
  3. //
  4. // Copyright 2010 Allen Ding. All rights reserved.
  5. //
  6. #import "KWEqualMatcher.h"
  7. #import "KWFormatter.h"
  8. #import "KWValue.h"
  9. @interface KWEqualMatcher()
  10. #pragma mark - Properties
  11. @property (nonatomic, readwrite, strong) id otherSubject;
  12. @end
  13. @implementation KWEqualMatcher
  14. #pragma mark - Initializing
  15. #pragma mark - Properties
  16. @synthesize otherSubject;
  17. #pragma mark - Getting Matcher Strings
  18. + (NSArray *)matcherStrings {
  19. return @[@"equal:"];
  20. }
  21. #pragma mark - Matching
  22. - (BOOL)evaluate {
  23. /** handle this as a special case; KWValue supports NSNumber equality but not vice-versa **/
  24. if ([self.subject isKindOfClass:[NSNumber class]] && [self.otherSubject isKindOfClass:[KWValue class]]) {
  25. return [self.otherSubject isEqual:self.subject];
  26. }
  27. return [self.subject isEqual:self.otherSubject];
  28. }
  29. #pragma mark - Getting Failure Messages
  30. - (NSString *)failureMessageForShould {
  31. return [NSString stringWithFormat:@"expected subject to equal %@, got %@",
  32. [KWFormatter formatObjectIncludingClass:self.otherSubject],
  33. [KWFormatter formatObjectIncludingClass:self.subject]];
  34. }
  35. - (NSString *)failureMessageForShouldNot {
  36. return [NSString stringWithFormat:@"expected subject not to equal %@",
  37. [KWFormatter formatObjectIncludingClass:self.otherSubject]];
  38. }
  39. - (NSString *)description
  40. {
  41. return [NSString stringWithFormat:@"equal %@", [KWFormatter formatObjectIncludingClass:self.otherSubject]];
  42. }
  43. #pragma mark - Configuring Matchers
  44. - (void)equal:(id)anObject {
  45. self.otherSubject = anObject;
  46. }
  47. @end