mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-12-03 03:24:22 +00:00
Completed isEqual: support for CPExpression & CPPredicate subclasses
This commit is contained in:
1 parent
80f5ab09f3
commit
08d690b65d
11 files changed
+103
-14
No files matched your search
@@ -318,7 +318,6 @@ var CPComparisonPredicateModifier,
|
||||
return _right;
|
||||
}
|
||||
|
||||
|
||||
- (CPString)predicateFormat
|
||||
{
|
||||
var modifier;
|
||||
@@ -398,6 +397,17 @@ var CPComparisonPredicateModifier,
|
||||
return [CPComparisonPredicate predicateWithLeftExpression:left rightExpression:right customSelector:_customSelector];
|
||||
}
|
||||
|
||||
- (BOOL)isEqual:(id)anObject
|
||||
{
|
||||
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]])
|
||||
return NO;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)_evaluateValue:lhs rightValue:rhs
|
||||
{
|
||||
var leftIsNil = (lhs == nil || [lhs isEqual:[CPNull null]]),
|
||||
|
||||
@@ -154,7 +154,7 @@ var CPCompoundPredicateType;
|
||||
i = 0;
|
||||
|
||||
if (count == 0)
|
||||
return @"TRUPREDICATE";
|
||||
return @"TRUEPREDICATE";
|
||||
|
||||
for (; i < count; i++)
|
||||
{
|
||||
@@ -228,6 +228,17 @@ var CPCompoundPredicateType;
|
||||
return result;
|
||||
}
|
||||
|
||||
- (BOOL)isEqual:(id)anObject
|
||||
{
|
||||
if (self === anObject)
|
||||
return YES;
|
||||
|
||||
if (object.isa !== self.isa || _type !== [anObject compoundPredicateType] || ![_predicates isEqualToArray:[anObject subpredicates]])
|
||||
return NO;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPCompoundPredicate (CPCoding)
|
||||
|
||||
@@ -39,10 +39,10 @@
|
||||
|
||||
- (BOOL)isEqual:(id)object
|
||||
{
|
||||
if (self == object)
|
||||
if (self === object)
|
||||
return YES;
|
||||
|
||||
if (object.isa != self.isa || [object expressionType] != [self expressionType] || ![[object collection] isEqual:[self collection]])
|
||||
if (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 expressionType] != [self expressionType] || ![[object constantValue] isEqual:[self constantValue]])
|
||||
if (object.isa !== self.isa || ![[object constantValue] isEqual:_value])
|
||||
return NO;
|
||||
|
||||
return YES;
|
||||
|
||||
@@ -69,10 +69,10 @@
|
||||
|
||||
- (BOOL)isEqual:(id)object
|
||||
{
|
||||
if (self == object)
|
||||
if (self === object)
|
||||
return YES;
|
||||
|
||||
if (object.isa != self.isa || [object expressionType] != [self expressionType] || ![[object _function] isEqualToString:[self _function]] || ![[object operand] isEqual:[self operand]] || ![[object arguments] isEqualToArray:[self arguments]])
|
||||
if (object.isa !== self.isa || ![[object _function] isEqual:_selector] || ![[object operand] isEqual:_operand] || ![[object arguments] isEqualToArray:_arguments])
|
||||
return NO;
|
||||
|
||||
return YES;
|
||||
|
||||
@@ -50,7 +50,10 @@
|
||||
if (object === self)
|
||||
return YES;
|
||||
|
||||
return ([object keyPath] == [self keyPath]); // If it appears that parsing generates nested keypaths with different targets and same keyPath, comparing -keyPath won't work.
|
||||
if (object.isa !== self.isa || ![[object keyPath] isEqualToString:[self keyPath]])
|
||||
return NO;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (CPExpression)pathExpression
|
||||
|
||||
@@ -44,10 +44,10 @@
|
||||
|
||||
- (BOOL)isEqual:(id)object
|
||||
{
|
||||
if (self == object)
|
||||
if (self === object)
|
||||
return YES;
|
||||
|
||||
if (object.isa != self.isa || [object expressionType] != [self expressionType] || ![[object leftExpression] isEqual:[self leftExpression]] || ![[object rightExpression] isEqual:[self rightExpression]])
|
||||
if (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 (![_collection isEqual:[object collection]] || ![_subpredicate isEqual:[object predicate]])
|
||||
if (object.isa !== self.isa || ![_collection isEqual:[object collection]] || ![_variableExpression isEqual:[object variableExpression]] || ![_subpredicate isEqual:[object predicate]])
|
||||
return NO;
|
||||
|
||||
return YES;
|
||||
@@ -113,6 +113,7 @@
|
||||
{
|
||||
return _variableExpression;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
var CPExpressionKey = @"CPExpression",
|
||||
|
||||
@@ -45,10 +45,10 @@
|
||||
|
||||
- (BOOL)isEqual:(id)object
|
||||
{
|
||||
if (self == object)
|
||||
if (self === object)
|
||||
return YES;
|
||||
|
||||
if (object.isa != self.isa || [object expressionType] != [self expressionType] || ![[object variable] isEqualToString:[self variable]])
|
||||
if (object.isa !== self.isa || ![[object variable] isEqual:_variable])
|
||||
return NO;
|
||||
|
||||
return YES;
|
||||
@@ -101,4 +101,3 @@ var CPVariableKey = @"CPVariable";
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -176,6 +176,17 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)isEqual:(id)anObject
|
||||
{
|
||||
if (self === anObject)
|
||||
return YES;
|
||||
|
||||
if (self.isa !== anObject.isa || _value !== [anObject evaluateObject:nil])
|
||||
return NO;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)evaluateObject:(id)object
|
||||
{
|
||||
return _value;
|
||||
|
||||
@@ -382,6 +382,60 @@
|
||||
[self assertTrue:[left isEqualToSet:result] message:"Expression eval " + left + " should be " + result];
|
||||
}
|
||||
|
||||
- (void)testExpressionAndPredicateIsEqual
|
||||
{
|
||||
var cexp1 = [CPExpression expressionForConstantValue:2];
|
||||
var cexp2 = [CPExpression expressionForConstantValue:2];
|
||||
[self assert:cexp1 equals:cexp2];
|
||||
|
||||
var exp1 = [CPExpression expressionForKeyPath:"path"];
|
||||
var exp2 = [CPExpression expressionForKeyPath:"path"];
|
||||
[self assert:exp1 equals:exp2];
|
||||
|
||||
exp1 = [CPExpression expressionForEvaluatedObject];
|
||||
exp2 = [CPExpression expressionForEvaluatedObject];
|
||||
[self assert:exp1 equals:exp2];
|
||||
|
||||
exp1 = [CPExpression expressionForVariable:"toto"];
|
||||
exp2 = [CPExpression expressionForVariable:"toto"];
|
||||
[self assert:exp1 equals:exp2];
|
||||
|
||||
var left = [CPExpression expressionForConstantValue:[CPSet setWithObjects:@"a",@"b",@"c"]];
|
||||
var right = [CPExpression expressionForConstantValue:[CPArray arrayWithObjects:@"a",@"b",@"d"]];
|
||||
|
||||
exp1 = [CPExpression expressionForIntersectSet:left with:right];
|
||||
exp2 = [CPExpression expressionForIntersectSet:[left copy] with:[right copy]];
|
||||
[self assert:exp1 equals:exp2];
|
||||
|
||||
exp1 = [CPExpression expressionForFunction:cexp1 selectorName:@"isEqual:" arguments:[CPArray arrayWithObjects:cexp2]];
|
||||
exp2 = [CPExpression expressionForFunction:cexp1 selectorName:@"isEqual:" arguments:[CPArray arrayWithObjects:cexp2]];
|
||||
[self assert:exp1 equals:exp2];
|
||||
|
||||
var aexp1 = [CPExpression expressionForAggregate:[CPArray arrayWithObjects:cexp1,cexp2]];
|
||||
var aexp2 = [CPExpression expressionForAggregate:[CPArray arrayWithObjects:cexp1,cexp2]];
|
||||
[self assert:aexp1 equals:aexp2];
|
||||
|
||||
exp1 = [CPExpression expressionForSubquery:right usingIteratorVariable:@"self" predicate:[CPPredicate predicateWithValue:YES]];
|
||||
exp2 = [CPExpression expressionForSubquery:right usingIteratorVariable:@"self" predicate:[CPPredicate predicateWithValue:YES]];
|
||||
[self assert:exp1 equals:exp2];
|
||||
|
||||
var pred1 = [CPPredicate predicateWithFormat:@"FUNCTION('toto', 'stringByReplacingOccurrencesOfString:withString:', 'o', 'a') == 'tata'"];
|
||||
var pred2 = [CPPredicate predicateWithFormat:@"FUNCTION('toto', 'stringByReplacingOccurrencesOfString:withString:', 'o', 'a') == 'tata'"];
|
||||
[self assert:pred1 equals:pred2];
|
||||
|
||||
pred1 = [CPPredicate predicateWithFormat:@"$record.$age = 34"];
|
||||
pred2 = [CPPredicate predicateWithFormat:@"$record.$age = 34"];
|
||||
[self assert:pred1 equals:pred2];
|
||||
|
||||
pred1 = [CPPredicate predicateWithFormat:@"SUBQUERY(Record1.Children, $x, $x BEGINSWITH 'Kid')[SIZE] = 2"];
|
||||
pred2 = [CPPredicate predicateWithFormat:@"SUBQUERY(Record1.Children, $x, $x BEGINSWITH 'Kid')[SIZE] = 2"];
|
||||
[self assert:pred1 equals:pred2];
|
||||
|
||||
pred1 = [CPPredicate predicateWithFormat:@"$x CONTAINS 'a'"];
|
||||
pred2 = [CPPredicate predicateWithFormat:@"$x CONTAINS 'a'"];
|
||||
[self assert:pred1 equals:pred2];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPObject (PredicateTesting)
|
||||
|
||||
Reference in new issue
Block a user