diff --git a/Foundation/CPPredicate/CPComparisonPredicate.j b/Foundation/CPPredicate/CPComparisonPredicate.j index ffe374e7a..a7843308e 100644 --- a/Foundation/CPPredicate/CPComparisonPredicate.j +++ b/Foundation/CPPredicate/CPComparisonPredicate.j @@ -275,7 +275,7 @@ var CPComparisonPredicateModifier, if (self === anObject) return YES; - if (anObject.isa !== self.isa || _modifier !== [anObject comparisonPredicateModifier] || _type !== [anObject predicateOperatorType] || _options !== [anObject options] || _customSelector !== [anObject customSelector] || ![_left isEqual:[anObject leftExpression]] || ![_right isEqual:[anObject rightExpression]]) + if (anObject === nil || anObject.isa !== self.isa || _modifier !== [anObject comparisonPredicateModifier] || _type !== [anObject predicateOperatorType] || _options !== [anObject options] || _customSelector !== [anObject customSelector] || ![_left isEqual:[anObject leftExpression]] || ![_right isEqual:[anObject rightExpression]]) return NO; return YES; diff --git a/Foundation/CPPredicate/CPCompoundPredicate.j b/Foundation/CPPredicate/CPCompoundPredicate.j index 8eaeb709f..e36ceb0d0 100644 --- a/Foundation/CPPredicate/CPCompoundPredicate.j +++ b/Foundation/CPPredicate/CPCompoundPredicate.j @@ -215,7 +215,7 @@ var CPCompoundPredicateType; if (self === anObject) return YES; - if (anObject.isa !== self.isa || _type !== [anObject compoundPredicateType] || ![_predicates isEqualToArray:[anObject subpredicates]]) + if (anObject === nil || anObject.isa !== self.isa || _type !== [anObject compoundPredicateType] || ![_predicates isEqualToArray:[anObject subpredicates]]) return NO; return YES; diff --git a/Foundation/CPPredicate/_CPAggregateExpression.j b/Foundation/CPPredicate/_CPAggregateExpression.j index b010881a7..688166398 100644 --- a/Foundation/CPPredicate/_CPAggregateExpression.j +++ b/Foundation/CPPredicate/_CPAggregateExpression.j @@ -42,7 +42,7 @@ if (self === object) return YES; - if (object.isa !== self.isa || ![[object collection] isEqual:_aggregate]) + if (object === nil || object.isa !== self.isa || ![[object collection] isEqual:_aggregate]) return NO; return YES; diff --git a/Foundation/CPPredicate/_CPConstantValueExpression.j b/Foundation/CPPredicate/_CPConstantValueExpression.j index 5ffa9e07a..617c9b10a 100644 --- a/Foundation/CPPredicate/_CPConstantValueExpression.j +++ b/Foundation/CPPredicate/_CPConstantValueExpression.j @@ -45,7 +45,7 @@ if (self === object) return YES; - if (object.isa !== self.isa || ![[object constantValue] isEqual:_value]) + if (object === nil || object.isa !== self.isa || ![[object constantValue] isEqual:_value]) return NO; return YES; diff --git a/Foundation/CPPredicate/_CPFunctionExpression.j b/Foundation/CPPredicate/_CPFunctionExpression.j index 75b1619fc..394c93612 100644 --- a/Foundation/CPPredicate/_CPFunctionExpression.j +++ b/Foundation/CPPredicate/_CPFunctionExpression.j @@ -72,7 +72,7 @@ if (self === object) return YES; - if (object.isa !== self.isa || ![[object _function] isEqual:_selector] || ![[object operand] isEqual:_operand] || ![[object arguments] isEqualToArray:_arguments]) + if (object === nil || object.isa !== self.isa || ![[object _function] isEqual:_selector] || ![[object operand] isEqual:_operand] || ![[object arguments] isEqualToArray:_arguments]) return NO; return YES; diff --git a/Foundation/CPPredicate/_CPKeyPathExpression.j b/Foundation/CPPredicate/_CPKeyPathExpression.j index c0694b395..0f9ece8b6 100644 --- a/Foundation/CPPredicate/_CPKeyPathExpression.j +++ b/Foundation/CPPredicate/_CPKeyPathExpression.j @@ -51,7 +51,7 @@ if (object === self) return YES; - if (object.isa !== self.isa || ![[object keyPath] isEqualToString:[self keyPath]]) + if (object === nil || object.isa !== self.isa || ![[object keyPath] isEqualToString:[self keyPath]]) return NO; return YES; diff --git a/Foundation/CPPredicate/_CPPredicate.j b/Foundation/CPPredicate/_CPPredicate.j index d2d8544db..367b65f48 100644 --- a/Foundation/CPPredicate/_CPPredicate.j +++ b/Foundation/CPPredicate/_CPPredicate.j @@ -190,7 +190,7 @@ if (self === anObject) return YES; - if (self.isa !== anObject.isa || _value !== [anObject evaluateWithObject:nil]) + if (anObject === nil || self.isa !== anObject.isa || _value !== [anObject evaluateWithObject:nil]) return NO; return YES; diff --git a/Foundation/CPPredicate/_CPSetExpression.j b/Foundation/CPPredicate/_CPSetExpression.j index f7d4e673b..a0e9df3bb 100644 --- a/Foundation/CPPredicate/_CPSetExpression.j +++ b/Foundation/CPPredicate/_CPSetExpression.j @@ -47,7 +47,7 @@ if (self === object) return YES; - if (object.isa !== self.isa || ![[object leftExpression] isEqual:_left] || ![[object rightExpression] isEqual:_right]) + if (object === nil || object.isa !== self.isa || ![[object leftExpression] isEqual:_left] || ![[object rightExpression] isEqual:_right]) return NO; return YES; diff --git a/Foundation/CPPredicate/_CPSubqueryExpression.j b/Foundation/CPPredicate/_CPSubqueryExpression.j index 78b50be94..a94d88d2c 100644 --- a/Foundation/CPPredicate/_CPSubqueryExpression.j +++ b/Foundation/CPPredicate/_CPSubqueryExpression.j @@ -73,7 +73,7 @@ if (self === object) return YES; - if (object.isa !== self.isa || ![_collection isEqual:[object collection]] || ![_variableExpression isEqual:[object variableExpression]] || ![_subpredicate isEqual:[object predicate]]) + if (object === nil || object.isa !== self.isa || ![_collection isEqual:[object collection]] || ![_variableExpression isEqual:[object variableExpression]] || ![_subpredicate isEqual:[object predicate]]) return NO; return YES; diff --git a/Foundation/CPPredicate/_CPVariableExpression.j b/Foundation/CPPredicate/_CPVariableExpression.j index c426d6c60..910ef23d5 100644 --- a/Foundation/CPPredicate/_CPVariableExpression.j +++ b/Foundation/CPPredicate/_CPVariableExpression.j @@ -48,7 +48,7 @@ if (self === object) return YES; - if (object.isa !== self.isa || ![[object variable] isEqual:_variable]) + if (object === nil || object.isa !== self.isa || ![[object variable] isEqual:_variable]) return NO; return YES; diff --git a/Tests/Foundation/CPObjectTest.j b/Tests/Foundation/CPObjectTest.j index 926a00238..c10293124 100644 --- a/Tests/Foundation/CPObjectTest.j +++ b/Tests/Foundation/CPObjectTest.j @@ -59,6 +59,13 @@ [self assertTrue:d.indexOf("access:") !== -1 message:"Can't find 'access:' in description of json " + d]; } +- (void)testCPObjectNotEqualToNil +{ + var anObject = [[CPObject alloc] init]; + + [self assert:anObject notEqual:nil]; +} + @end @implementation SuperReceiver : CPObject diff --git a/Tests/Foundation/CPPredicateTest.j b/Tests/Foundation/CPPredicateTest.j index 58d6066ae..f810b4fde 100644 --- a/Tests/Foundation/CPPredicateTest.j +++ b/Tests/Foundation/CPPredicateTest.j @@ -440,6 +440,64 @@ [self assert:pred1 equals:pred2]; } +- (void)testExpressionAndPredicateIsNotEqualToNil +{ + var cexp1 = [CPExpression expressionForConstantValue:2], + cexp2 = [CPExpression expressionForConstantValue:2]; + [self assert:cexp1 notEqual:nil]; + + var exp1 = [CPExpression expressionForKeyPath:"path"]; + + [self assert:exp1 notEqual:nil]; + + exp1 = [CPExpression expressionForEvaluatedObject]; + + [self assert:exp1 notEqual:nil]; + + exp1 = [CPExpression expressionForVariable:"toto"]; + + [self assert:exp1 notEqual:nil]; + + var left = [CPExpression expressionForConstantValue:[CPSet setWithObjects:@"a",@"b",@"c"]], + right = [CPExpression expressionForConstantValue:[CPArray arrayWithObjects:@"a",@"b",@"d"]]; + + exp1 = [CPExpression expressionForIntersectSet:left with:right]; + + [self assert:exp1 notEqual:nil]; + + exp1 = [CPExpression expressionForFunction:cexp1 selectorName:@"isEqual:" arguments:[CPArray arrayWithObjects:cexp2]]; + + [self assert:exp1 notEqual:nil]; + + var aexp1 = [CPExpression expressionForAggregate:[CPArray arrayWithObjects:cexp1,cexp2]]; + + [self assert:aexp1 notEqual:nil]; + + exp1 = [CPExpression expressionForSubquery:right usingIteratorVariable:@"self" predicate:[CPPredicate predicateWithValue:YES]]; + + [self assert:exp1 notEqual:nil]; + + var pred1 = [CPPredicate predicateWithFormat:@"FUNCTION('toto', 'stringByReplacingOccurrencesOfString:withString:', 'o', 'a') == 'tata'"]; + + [self assert:pred1 notEqual:nil]; + + pred1 = [CPPredicate predicateWithFormat:@"$record.$age = 34"]; + + [self assert:pred1 notEqual:nil]; + + pred1 = [CPPredicate predicateWithFormat:@"SUBQUERY(Record1.Children, $x, $x BEGINSWITH 'Kid')[SIZE] = 2"]; + + [self assert:pred1 notEqual:nil]; + + pred1 = [CPPredicate predicateWithFormat:@"$x CONTAINS 'a'"]; + + [self assert:pred1 notEqual:nil]; + + pred1 = [CPPredicate predicateWithFormat:@"a = 'a' AND b = 'b'"]; + + [self assert:pred1 notEqual:nil]; +} + - (void)testProxyArrayFiltering { var proxyArray = [self mutableArrayValueForKey:@"simpleArray"],