From 24d6e581a63575a1560314f2e37f7ef4b504e3a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Wallstro=CC=88m?= Date: Thu, 3 Jan 2013 11:04:53 +0100 Subject: [PATCH] Fixed: CPPredicate: TRUEPREDICATE didn't work CPPredicate_BOOL didn't implement any methods necessary for TRUEPREDICATE to evaluate to true. --- Foundation/CPPredicate/CPPredicate.j | 9 +++++++-- Tests/Foundation/CPPredicateTest.j | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Foundation/CPPredicate/CPPredicate.j b/Foundation/CPPredicate/CPPredicate.j index 36c5b2002..693d312a8 100644 --- a/Foundation/CPPredicate/CPPredicate.j +++ b/Foundation/CPPredicate/CPPredicate.j @@ -181,13 +181,18 @@ if (self === anObject) return YES; - if (self.isa !== anObject.isa || _value !== [anObject evaluateObject:nil]) + if (self.isa !== anObject.isa || _value !== [anObject evaluateWithObject:nil]) return NO; return YES; } -- (BOOL)evaluateObject:(id)object +- (BOOL)evaluateWithObject:(id)object +{ + return _value; +} + +- (BOOL)evaluateWithObject:(id)object substitutionVariables:(CPDictionary)variables { return _value; } diff --git a/Tests/Foundation/CPPredicateTest.j b/Tests/Foundation/CPPredicateTest.j index c68cbe8f4..58d6066ae 100644 --- a/Tests/Foundation/CPPredicateTest.j +++ b/Tests/Foundation/CPPredicateTest.j @@ -450,6 +450,23 @@ [self assertTrue:([filtered count] == 2) message:@"Count should be 2 and is " + [filtered count]]; } +- (void)testTruepredicate +{ + var data = [1, 2, 3], + result; + + var tpred = [CPPredicate predicateWithFormat:@"TRUEPREDICATE"]; + var ctpred = [CPCompoundPredicate andPredicateWithSubpredicates:[tpred]]; + + // fails if evaluateWithObject: isn't implemented in CPPredicate_BOOL + result = [tpred evaluateWithObject:"gazonk"]; + [self assertTrue:result message:"'" + [tpred description] + "' should evaluate to true"]; + + // fails if evaluateWithObject:substitutionVariables: isn't implemented in CPPredicate_BOOL + result = [data filteredArrayUsingPredicate:ctpred]; + [self assertTrue:[result isEqual:data] message:"[1, 2, 3] filtered with '" + [ctpred description] + "' should return [1, 2, 3]"]; +} + @end @implementation CPObject (PredicateTesting)