CPComparisonPredicate :

Fixed a bug where *lhs custom_selector: nil* was always returning false.
Test nil on left and/or right with some operators.
This commit is contained in:
cacaodev authored and Alexander Ljungberg committed 2010-08-05 16:18:18 -04:00
1 parent df358ccc42
commit 750cd3c258
2 files changed
+40 -2

No files matched your search

@@ -388,7 +388,7 @@ var CPPredicateOperatorType;
var leftIsNil = (lhs == nil || [lhs isEqual:[CPNull null]]),
rightIsNil = (rhs == nil || [rhs isEqual:[CPNull null]]);
if (leftIsNil || rightIsNil)
if ((leftIsNil || rightIsNil) && _type != CPCustomSelectorPredicateOperatorType)
return (leftIsNil == rightIsNil &&
(_type == CPEqualToPredicateOperatorType ||
_type == CPLessThanOrEqualToPredicateOperatorType ||
+39 -1
View File
@@ -137,6 +137,35 @@
[self assertTrue:[pred evaluateWithObject:dict] message:"'"+ [pred description] + "' should be true"];
}
- (void)testNilComparisons
{
// Custom Selector Predicate
var pred = [[CPComparisonPredicate alloc] initWithLeftExpression:[CPExpression expressionForKeyPath:@"Record1.Name"] rightExpression:[CPExpression expressionForConstantValue:nil] customSelector:@selector(yes:)];
[self assertTrue:[pred evaluateWithObject:dict] message:"'"+ [pred description] + "' should be true"];
pred = [[CPComparisonPredicate alloc] initWithLeftExpression:[CPExpression expressionForConstantValue:nil] rightExpression:[CPExpression expressionForConstantValue:nil] customSelector:@selector(yes:)];
[self assertFalse:[pred evaluateWithObject:dict] message:"'"+ [pred description] + "' should be false"];
pred = [[CPComparisonPredicate alloc] initWithLeftExpression:[CPExpression expressionForKeyPath:@"Record1.Name"] rightExpression:[CPExpression expressionForConstantValue:nil] modifier:CPDirectPredicateModifier type:CPBeginsWithPredicateOperatorType options:0];
[self assertFalse:[pred evaluateWithObject:dict] message:"'"+ [pred description] + "' should be false"];
// Predicates with operators
pred = [[CPComparisonPredicate alloc] initWithLeftExpression:[CPExpression expressionForKeyPath:@"Record1.Age"] rightExpression:[CPExpression expressionForConstantValue:nil] modifier:CPDirectPredicateModifier type:CPGreaterThanPredicateOperatorType options:0];
[self assertFalse:[pred evaluateWithObject:dict] message:"'"+ [pred description] + "' should be false"];
pred = [[CPComparisonPredicate alloc] initWithLeftExpression:[CPExpression expressionForConstantValue:nil] rightExpression:[CPExpression expressionForConstantValue:nil] modifier:CPDirectPredicateModifier type:CPGreaterThanOrEqualToPredicateOperatorType options:0];
[self assertTrue:[pred evaluateWithObject:dict] message:"'"+ [pred description] + "' should be true"];
pred = [[CPComparisonPredicate alloc] initWithLeftExpression:[CPExpression expressionForConstantValue:nil] rightExpression:[CPExpression expressionForConstantValue:nil] modifier:CPDirectPredicateModifier type:CPBeginsWithPredicateOperatorType options:0];
[self assertFalse:[pred evaluateWithObject:dict] message:"'"+ [pred description] + "' should be false"];
}
- (void)testPredicateParsing
{
var predicate;
@@ -184,4 +213,13 @@
[self assertTrue:[predicate evaluateWithObject:dict] message:[predicate description] + " should be true"];
}
@end
@end
@implementation CPObject (PredicateTesting)
- (BOOL)yes:(id)object
{
return YES;
}
@end