This commit is contained in:
Antoine Mercadal
2013-02-04 13:09:09 -08:00
2 changed files with 24 additions and 2 deletions
+7 -2
View File
@@ -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;
}
+17
View File
@@ -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)