diff --git a/Foundation/CPPredicate/_CPPredicate.j b/Foundation/CPPredicate/_CPPredicate.j index 5fd8ac967..8b66d3126 100644 --- a/Foundation/CPPredicate/_CPPredicate.j +++ b/Foundation/CPPredicate/_CPPredicate.j @@ -190,13 +190,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)