mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-27 18:38:49 +00:00
Merge pull request #1914 from mrcarlberg/predicate_expression_equals_nil
CPExpression and CPPredicate can't handle nil as argument in method isEqual:
This commit is contained in:
commit
d7c676893d
12 files changed
+75
-10
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"],
|
||||
|
||||
Reference in new issue
Block a user