mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-24 23:45:52 +00:00
Merge branch 'master' of git://github.com/cappuccino/cappuccino into CPRulePredicateEditor
This commit is contained in:
commit
0aae4f2627
15 files changed
+227
-116
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)
|
||||
|
||||
@@ -105,7 +105,7 @@ CPMinusSetExpressionType = 9;
|
||||
*/
|
||||
+ (CPExpression)expressionForConstantValue:(id)value
|
||||
{
|
||||
return [[CPExpression_constant alloc] initWithValue:value];
|
||||
return [[_CPConstantValueExpression alloc] initWithValue:value];
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -114,7 +114,7 @@ CPMinusSetExpressionType = 9;
|
||||
*/
|
||||
+ (CPExpression)expressionForEvaluatedObject
|
||||
{
|
||||
return [CPExpression_self evaluatedObject];
|
||||
return [_CPSelfExpression evaluatedObject];
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -124,7 +124,7 @@ CPMinusSetExpressionType = 9;
|
||||
*/
|
||||
+ (CPExpression)expressionForVariable:(CPString)string
|
||||
{
|
||||
return [[CPExpression_variable alloc] initWithVariable:string];
|
||||
return [[_CPVariableExpression alloc] initWithVariable:string];
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -134,7 +134,7 @@ CPMinusSetExpressionType = 9;
|
||||
*/
|
||||
+ (CPExpression)expressionForKeyPath:(CPString)keyPath
|
||||
{
|
||||
return [[CPExpression_keypath alloc] initWithKeyPath:keyPath];
|
||||
return [[_CPKeyPathExpression alloc] initWithKeyPath:keyPath];
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -144,7 +144,7 @@ CPMinusSetExpressionType = 9;
|
||||
*/
|
||||
+ (CPExpression)expressionForAggregate:(CPArray)collection
|
||||
{
|
||||
return [[CPExpression_aggregate alloc] initWithAggregate:collection];
|
||||
return [[_CPAggregateExpression alloc] initWithAggregate:collection];
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -155,7 +155,7 @@ CPMinusSetExpressionType = 9;
|
||||
*/
|
||||
+ (CPExpression)expressionForUnionSet:(CPExpression)left with:(CPExpression)right
|
||||
{
|
||||
return [[CPExpression_set alloc] initWithType:CPUnionSetExpressionType left:left right:right];
|
||||
return [[_CPSetExpression alloc] initWithType:CPUnionSetExpressionType left:left right:right];
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -166,7 +166,7 @@ CPMinusSetExpressionType = 9;
|
||||
*/
|
||||
+ (CPExpression)expressionForIntersectSet:(CPExpression)left with:(CPExpression)right
|
||||
{
|
||||
return [[CPExpression_set alloc] initWithType:CPIntersectSetExpressionType left:left right:right];
|
||||
return [[_CPSetExpression alloc] initWithType:CPIntersectSetExpressionType left:left right:right];
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -177,7 +177,7 @@ CPMinusSetExpressionType = 9;
|
||||
*/
|
||||
+ (CPExpression)expressionForMinusSet:(CPExpression)left with:(CPExpression)right
|
||||
{
|
||||
return [[CPExpression_set alloc] initWithType:CPMinusSetExpressionType left:left right:right];
|
||||
return [[_CPSetExpression alloc] initWithType:CPMinusSetExpressionType left:left right:right];
|
||||
}
|
||||
|
||||
// Creating an Expression for a Function
|
||||
@@ -230,7 +230,7 @@ CPMinusSetExpressionType = 9;
|
||||
*/
|
||||
+ (CPExpression)expressionForFunction:(CPString)function_name arguments:(CPArray)parameters
|
||||
{
|
||||
return [[CPExpression_function alloc] initWithSelector:CPSelectorFromString(function_name) arguments:parameters];
|
||||
return [[_CPFunctionExpression alloc] initWithSelector:CPSelectorFromString(function_name) arguments:parameters];
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -244,7 +244,7 @@ CPMinusSetExpressionType = 9;
|
||||
*/
|
||||
+ (CPExpression)expressionForFunction:(CPExpression)target selectorName:(CPString)selectorName arguments:(CPArray)parameters
|
||||
{
|
||||
return [[CPExpression_function alloc] initWithTarget:target selector:CPSelectorFromString(selectorName) arguments:parameters];
|
||||
return [[_CPFunctionExpression alloc] initWithTarget:target selector:CPSelectorFromString(selectorName) arguments:parameters];
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -256,7 +256,7 @@ CPMinusSetExpressionType = 9;
|
||||
*/
|
||||
+ (CPExpression)expressionForSubquery:(CPExpression)expression usingIteratorVariable:(CPString)variable predicate:(CPPredicate)predicate
|
||||
{
|
||||
return [[CPExpression_subquery alloc] initWithExpression:expression usingIteratorVariable:variable predicate:predicate];
|
||||
return [[_CPSubqueryExpression alloc] initWithExpression:expression usingIteratorVariable:variable predicate:predicate];
|
||||
}
|
||||
|
||||
// Getting Information About an Expression
|
||||
@@ -387,11 +387,11 @@ CPMinusSetExpressionType = 9;
|
||||
|
||||
@end
|
||||
|
||||
@import "CPExpression_constant.j"
|
||||
@import "CPExpression_self.j"
|
||||
@import "CPExpression_variable.j"
|
||||
@import "CPExpression_keypath.j"
|
||||
@import "CPExpression_function.j"
|
||||
@import "CPExpression_aggregate.j"
|
||||
@import "CPExpression_set.j"
|
||||
@import "CPExpression_subquery.j"
|
||||
@import "_CPConstantValueExpression.j"
|
||||
@import "_CPSelfExpression.j"
|
||||
@import "_CPVariableExpression.j"
|
||||
@import "_CPKeyPathExpression.j"
|
||||
@import "_CPFunctionExpression.j"
|
||||
@import "_CPAggregateExpression.j"
|
||||
@import "_CPSetExpression.j"
|
||||
@import "_CPSubqueryExpression.j"
|
||||
@@ -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;
|
||||
@@ -199,7 +210,7 @@
|
||||
|
||||
for (; i < count; i++)
|
||||
{
|
||||
var object = self[i];
|
||||
var object = [self objectAtIndex:i];
|
||||
if ([predicate evaluateWithObject:object])
|
||||
result.push(object);
|
||||
}
|
||||
@@ -213,7 +224,7 @@
|
||||
|
||||
while (count--)
|
||||
{
|
||||
if (![predicate evaluateWithObject:self[count]])
|
||||
if (![predicate evaluateWithObject:[self objectAtIndex:count]])
|
||||
splice(count, 1);
|
||||
}
|
||||
}
|
||||
@@ -737,7 +748,7 @@ function(newValue)\
|
||||
if (![self scanString:@")" intoString:NULL])
|
||||
CPRaiseParseError(self, @"expression");
|
||||
|
||||
return [[CPExpression_subquery alloc] initWithExpression:collection usingIteratorExpression:variableExpression predicate:subpredicate];
|
||||
return [[_CPSubqueryExpression alloc] initWithExpression:collection usingIteratorExpression:variableExpression predicate:subpredicate];
|
||||
}
|
||||
|
||||
if ([self scanString:@"FUNCTION" intoString:NULL])
|
||||
@@ -777,7 +788,7 @@ function(newValue)\
|
||||
expressionType = [right expressionType];
|
||||
|
||||
if (expressionType == CPKeyPathExpressionType)
|
||||
left = [[CPExpression_keypath alloc] initWithOperand:left andKeyPath:[right keyPath]];
|
||||
left = [[_CPKeyPathExpression alloc] initWithOperand:left andKeyPath:[right keyPath]];
|
||||
else if (expressionType == CPVariableExpressionType)
|
||||
left = [CPExpression expressionForFunction:left selectorName:@"valueForKey:" arguments:[right]];
|
||||
else
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* CPExpression_aggregate.j
|
||||
* _CPAggregateExpression.j
|
||||
*
|
||||
* Created by cacaodev.
|
||||
* Copyright 2010.
|
||||
@@ -23,7 +23,7 @@
|
||||
@import "CPExpression.j"
|
||||
@import "CPString.j"
|
||||
|
||||
@implementation CPExpression_aggregate : CPExpression
|
||||
@implementation _CPAggregateExpression : CPExpression
|
||||
{
|
||||
CPArray _aggregate;
|
||||
}
|
||||
@@ -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;
|
||||
@@ -98,7 +98,7 @@
|
||||
|
||||
var CPCollectionKey = @"CPCollection";
|
||||
|
||||
@implementation CPExpression_aggregate (CPCoding)
|
||||
@implementation _CPAggregateExpression (CPCoding)
|
||||
|
||||
- (id)initWithCoder:(CPCoder)coder
|
||||
{
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* CPExpression_constant.j
|
||||
* _CPConstantValueExpression.j
|
||||
*
|
||||
* Portions based on NSExpression_constant.m in Cocotron (http://www.cocotron.org/)
|
||||
* Copyright (c) 2006-2007 Christopher J. W. Lloyd
|
||||
@@ -25,7 +25,7 @@
|
||||
@import "CPDictionary.j"
|
||||
@import "CPExpression.j"
|
||||
|
||||
@implementation CPExpression_constant : CPExpression
|
||||
@implementation _CPConstantValueExpression : CPExpression
|
||||
{
|
||||
id _value;
|
||||
}
|
||||
@@ -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;
|
||||
@@ -73,7 +73,7 @@
|
||||
|
||||
var CPConstantValueKey = @"CPConstantValue";
|
||||
|
||||
@implementation CPExpression_constant (CPCoding)
|
||||
@implementation _CPConstantValueExpression (CPCoding)
|
||||
|
||||
- (id)initWithCoder:(CPCoder)coder
|
||||
{
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* CPExpression_function.j
|
||||
* _CPFunctionExpression.j
|
||||
*
|
||||
* Created by cacaodev.
|
||||
* Copyright 2010.
|
||||
@@ -26,7 +26,7 @@
|
||||
@import "CPExpression.j"
|
||||
@import "CPString.j"
|
||||
|
||||
@implementation CPExpression_function : CPExpression
|
||||
@implementation _CPFunctionExpression : CPExpression
|
||||
{
|
||||
CPExpression _operand;
|
||||
SEL _selector;
|
||||
@@ -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;
|
||||
@@ -159,7 +159,7 @@ var CPSelectorNameKey = @"CPSelectorName",
|
||||
CPOperandKey = @"CPOperand",
|
||||
CPExpressionTypeKey = @"CPExpressionType";
|
||||
|
||||
@implementation CPExpression_function (CPCoding)
|
||||
@implementation _CPFunctionExpression (CPCoding)
|
||||
|
||||
- (id)initWithCoder:(CPCoder)coder
|
||||
{
|
||||
+8
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* CPExpression_keypath.j
|
||||
* _CPKeyPathExpression.j
|
||||
*
|
||||
* Portions based on NSExpression_keypath.m in Cocotron (http://www.cocotron.org/)
|
||||
* Copyright (c) 2006-2007 Christopher J. W. Lloyd
|
||||
@@ -23,11 +23,11 @@
|
||||
*/
|
||||
|
||||
@import "CPExpression.j"
|
||||
@import "CPExpression_function.j"
|
||||
@import "_CPFunctionExpression.j"
|
||||
@import "CPKeyValueCoding.j"
|
||||
@import "CPString.j"
|
||||
|
||||
@implementation CPExpression_keypath : CPExpression_function
|
||||
@implementation _CPKeyPathExpression : _CPFunctionExpression
|
||||
{
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -75,7 +78,7 @@
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPExpression_constant (KeyPath)
|
||||
@implementation _CPConstantValueExpression (KeyPath)
|
||||
|
||||
- (CPString)keyPath
|
||||
{
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* CPExpression_self.j
|
||||
* _CPSelfExpression.j
|
||||
*
|
||||
* Created by cacaodev.
|
||||
* Copyright 2010.
|
||||
@@ -25,14 +25,14 @@
|
||||
|
||||
var evaluatedObject = nil;
|
||||
|
||||
@implementation CPExpression_self : CPExpression
|
||||
@implementation _CPSelfExpression : CPExpression
|
||||
{
|
||||
}
|
||||
|
||||
+ (id)evaluatedObject
|
||||
{
|
||||
if (evaluatedObject == nil)
|
||||
evaluatedObject = [CPExpression_self new];
|
||||
evaluatedObject = [_CPSelfExpression new];
|
||||
|
||||
return evaluatedObject;
|
||||
}
|
||||
@@ -46,7 +46,7 @@ var evaluatedObject = nil;
|
||||
|
||||
- (id)initWithCoder:(CPCoder)coder
|
||||
{
|
||||
return [CPExpression_self evaluatedObject];
|
||||
return [_CPSelfExpression evaluatedObject];
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(CPCoder)coder
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* CPExpression_set.j
|
||||
* _CPSetExpression.j
|
||||
*
|
||||
* Created by cacaodev.
|
||||
* Copyright 2010.
|
||||
@@ -23,7 +23,7 @@
|
||||
@import "CPExpression.j"
|
||||
@import "CPSet.j"
|
||||
|
||||
@implementation CPExpression_set : CPExpression
|
||||
@implementation _CPSetExpression : CPExpression
|
||||
{
|
||||
CPExpression _left;
|
||||
CPExpression _right;
|
||||
@@ -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;
|
||||
@@ -121,7 +121,7 @@ var CPLeftExpressionKey = @"CPLeftExpression",
|
||||
CPRightExpressionKey = @"CPRightExpression",
|
||||
CPExpressionType = @"CPExpressionType";
|
||||
|
||||
@implementation CPExpression_set (CPCoding)
|
||||
@implementation _CPSetExpression (CPCoding)
|
||||
|
||||
- (id)initWithCoder:(CPCoder)coder
|
||||
{
|
||||
+6
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* CPExpression_subquery.j
|
||||
* _CPSubqueryExpression.j
|
||||
*
|
||||
* Created by cacaodev.
|
||||
* Copyright 2010.
|
||||
@@ -24,7 +24,7 @@
|
||||
@import "CPExpression.j"
|
||||
@import "CPPredicate.j"
|
||||
|
||||
@implementation CPExpression_subquery : CPExpression
|
||||
@implementation _CPSubqueryExpression : CPExpression
|
||||
{
|
||||
CPExpression _collection;
|
||||
CPExpression _variableExpression;
|
||||
@@ -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;
|
||||
@@ -86,7 +86,7 @@
|
||||
|
||||
- (id)copy
|
||||
{
|
||||
return [[CPExpression_subquery alloc] initWithExpression:[_collection copy] usingIteratorExpression:[_variableExpression copy] predicate:[_subpredicate copy]];
|
||||
return [[_CPSubqueryExpression alloc] initWithExpression:[_collection copy] usingIteratorExpression:[_variableExpression copy] predicate:[_subpredicate copy]];
|
||||
}
|
||||
|
||||
- (CPPredicate)predicate
|
||||
@@ -113,13 +113,14 @@
|
||||
{
|
||||
return _variableExpression;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
var CPExpressionKey = @"CPExpression",
|
||||
CPSubpredicateKey = @"CPSubpredicate",
|
||||
CPVariableKey = @"CPVariable";
|
||||
|
||||
@implementation CPExpression_subquery (CPCoding)
|
||||
@implementation _CPSubqueryExpression (CPCoding)
|
||||
|
||||
- (id)initWithCoder:(CPCoder)coder
|
||||
{
|
||||
+5
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* CPExpression_variable.j
|
||||
* _CPVariableExpression.j
|
||||
*
|
||||
* Portions based on NSExpression_variable.m in Cocotron (http://www.cocotron.org/)
|
||||
* Copyright (c) 2006-2007 Christopher J. W. Lloyd
|
||||
@@ -27,7 +27,7 @@
|
||||
@import "CPExpression.j"
|
||||
@import "CPString.j"
|
||||
|
||||
@implementation CPExpression_variable : CPExpression
|
||||
@implementation _CPVariableExpression : CPExpression
|
||||
{
|
||||
CPString _variable;
|
||||
}
|
||||
@@ -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;
|
||||
@@ -87,7 +87,7 @@
|
||||
|
||||
var CPVariableKey = @"CPVariable";
|
||||
|
||||
@implementation CPExpression_variable (CPCoding)
|
||||
@implementation _CPVariableExpression (CPCoding)
|
||||
|
||||
- (id)initWithCoder:(CPCoder)coder
|
||||
{
|
||||
@@ -101,4 +101,3 @@ var CPVariableKey = @"CPVariable";
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -547,6 +547,18 @@
|
||||
[self assertTrue:[[arrayController arrangedObjects] count] > 0];
|
||||
}
|
||||
|
||||
- (void)testArrangedObjectsWithPredicateFilteringAfterContentArrayBinding
|
||||
{
|
||||
_contentArray = [self makeTestArray];
|
||||
|
||||
var arrayController = [[CPArrayController alloc] init];
|
||||
[arrayController bind:@"contentArray" toObject:self withKeyPath:@"_contentArray" options:nil];
|
||||
[arrayController setFilterPredicate:[CPPredicate predicateWithFormat:@"department.name BEGINSWITH 'Capp'"]];
|
||||
|
||||
var arrangedCount = [[arrayController arrangedObjects] count];
|
||||
[self assertTrue:(arrangedCount == 2) message:@"Count should be 2 and is " + arrangedCount];
|
||||
}
|
||||
|
||||
/**
|
||||
In a table with arranged contents like [1, 1, 2, 1], selecting the second '1' and removing it
|
||||
should result in [1, 2, 1] - not [2]. E.g. we don't use removeObject:1 but only remove the
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
@implementation CPPredicateTest : OJTestCase
|
||||
{
|
||||
CPDictionary dict;
|
||||
CPArray simpleArray;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
@@ -27,6 +28,8 @@
|
||||
d = [CPDictionary dictionaryWithObjects:objects forKeys:keys];
|
||||
[dict setObject:d forKey:@"Record2"];
|
||||
|
||||
simpleArray = [CPArray arrayWithObjects:@"a", @"b", @"ac", @"bc"];
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -64,10 +67,10 @@
|
||||
var expression_subquery = [CPExpression expressionForSubquery:expression_collection usingIteratorVariable:@"self" predicate:[CPPredicate predicateWithValue:YES]];
|
||||
[self assertNotNull:expression_subquery message:"Subquery Expression should not be nil"];
|
||||
|
||||
var set = [CPExpression expressionForConstantValue:[CPSet setWithObjects:@"a",@"b",@"c"]];
|
||||
var array = [CPExpression expressionForConstantValue:[CPArray arrayWithObjects:@"a",@"b",@"d"]];
|
||||
var set = [CPExpression expressionForConstantValue:[CPSet setWithObjects:@"a",@"b",@"c"]],
|
||||
array = [CPExpression expressionForConstantValue:[CPArray arrayWithObjects:@"a",@"b",@"d"]],
|
||||
expression_intersect = [CPExpression expressionForIntersectSet:set with:array];
|
||||
|
||||
var expression_intersect = [CPExpression expressionForIntersectSet:set with:array];
|
||||
[self assertNotNull:expression_intersect message:"IntersectSet Expression should not be nil"];
|
||||
|
||||
var expression_unionset = [CPExpression expressionForUnionSet:set with:array];
|
||||
@@ -79,16 +82,16 @@
|
||||
|
||||
- (void)testSetExpressionEvaluation
|
||||
{
|
||||
var left = [CPExpression expressionForConstantValue:[CPSet setWithObjects:@"a",@"b",@"c"]];
|
||||
var right = [CPExpression expressionForConstantValue:[CPArray arrayWithObjects:@"a",@"b",@"d"]];
|
||||
var left = [CPExpression expressionForConstantValue:[CPSet setWithObjects:@"a", @"b", @"c"]],
|
||||
right = [CPExpression expressionForConstantValue:[CPArray arrayWithObjects:@"a", @"b", @"d"]];
|
||||
|
||||
var expression = [CPExpression expressionForIntersectSet:left with:right];
|
||||
var eval = [expression expressionValueWithObject:nil context:nil];
|
||||
[self assertTrue:[eval isEqualToSet:[CPSet setWithObjects:@"a",@"b"]] message:"Result should be {(a, b)}, is " + eval];
|
||||
var expression = [CPExpression expressionForIntersectSet:left with:right],
|
||||
eval = [expression expressionValueWithObject:nil context:nil];
|
||||
[self assertTrue:[eval isEqualToSet:[CPSet setWithObjects:@"a", @"b"]] message:"Result should be {(a, b)}, is " + eval];
|
||||
|
||||
expression = [CPExpression expressionForUnionSet:left with:right];
|
||||
eval = [expression expressionValueWithObject:nil context:nil];
|
||||
[self assertTrue:[eval isEqualToSet:[CPSet setWithObjects:@"a",@"b",@"c",@"d"]] message:"Result should be {(a, b, c, d)}, is " + eval];
|
||||
[self assertTrue:[eval isEqualToSet:[CPSet setWithObjects:@"a", @"b", @"c", @"d"]] message:"Result should be {(a, b, c, d)}, is " + eval];
|
||||
|
||||
expression = [CPExpression expressionForMinusSet:left with:right];
|
||||
eval = [expression expressionValueWithObject:nil context:nil];
|
||||
@@ -97,16 +100,16 @@
|
||||
|
||||
- (void)testFunctionExpressionEvaluation
|
||||
{
|
||||
// Built-in function
|
||||
var args = [[CPExpression expressionForConstantValue:1], [CPExpression expressionForConstantValue:2], [CPExpression expressionForConstantValue:3]];
|
||||
var function_exp = [CPExpression expressionForFunction:"sum:" arguments:args];
|
||||
// Built-in function
|
||||
var args = [[CPExpression expressionForConstantValue:1], [CPExpression expressionForConstantValue:2], [CPExpression expressionForConstantValue:3]],
|
||||
function_exp = [CPExpression expressionForFunction:"sum:" arguments:args],
|
||||
pred = [[CPComparisonPredicate alloc] initWithLeftExpression:function_exp rightExpression:[CPExpression expressionForConstantValue:6] modifier:CPDirectPredicateModifier type:CPEqualToPredicateOperatorType options:0];
|
||||
|
||||
var pred = [[CPComparisonPredicate alloc] initWithLeftExpression:function_exp rightExpression:[CPExpression expressionForConstantValue:6] modifier:CPDirectPredicateModifier type:CPEqualToPredicateOperatorType options:0];
|
||||
[self assertTrue:[pred evaluateWithObject:nil] message:[pred description] + " should be true"];
|
||||
|
||||
// Custom function
|
||||
var operand = [CPExpression expressionForConstantValue:@"text"];
|
||||
var arg = [CPExpression expressionForConstantValue:2];
|
||||
// Custom function
|
||||
var operand = [CPExpression expressionForConstantValue:@"text"],
|
||||
arg = [CPExpression expressionForConstantValue:2];
|
||||
function_exp = [CPExpression expressionForFunction:operand selectorName:@"substringFromIndex:" arguments:[arg]];
|
||||
pred = [[CPComparisonPredicate alloc] initWithLeftExpression:function_exp rightExpression:[CPExpression expressionForConstantValue:@"xt"] modifier:CPDirectPredicateModifier type:CPEqualToPredicateOperatorType options:0];
|
||||
[self assertTrue:[pred evaluateWithObject:nil] message:[pred description] + " should be true"];
|
||||
@@ -137,10 +140,9 @@
|
||||
iteratorVariable = @"x",
|
||||
predicate = [CPPredicate predicateWithFormat:@"$x BEGINSWITH 'Kid'"];
|
||||
|
||||
var expression = [CPExpression expressionForSubquery:collection usingIteratorVariable:iteratorVariable predicate:predicate];
|
||||
|
||||
var eval = [expression expressionValueWithObject:dict context:nil];
|
||||
var expected = [CPArray arrayWithObjects:"Kid1", "Kid2"];
|
||||
var expression = [CPExpression expressionForSubquery:collection usingIteratorVariable:iteratorVariable predicate:predicate],
|
||||
eval = [expression expressionValueWithObject:dict context:nil],
|
||||
expected = [CPArray arrayWithObjects:"Kid1", "Kid2"];
|
||||
[self assertTrue:([eval isEqual:expected]) message:"'"+ [expression predicateFormat] + "' result is "+ eval + "but should be " + expected];
|
||||
}
|
||||
|
||||
@@ -180,11 +182,9 @@
|
||||
|
||||
- (void)testCompoundPredicate
|
||||
{
|
||||
var predOne = [[CPComparisonPredicate alloc] initWithLeftExpression:[CPExpression expressionForKeyPath:@"Record1.Name"] rightExpression:[CPExpression expressionForConstantValue:@"J"] modifier:CPDirectPredicateModifier type:CPBeginsWithPredicateOperatorType options:0];
|
||||
|
||||
var predTwo = [[CPComparisonPredicate alloc] initWithLeftExpression:[CPExpression expressionForKeyPath:@"Record1.Age"] rightExpression:[CPExpression expressionForConstantValue:[CPNumber numberWithInt:40]] modifier:CPDirectPredicateModifier type:CPLessThanPredicateOperatorType options:0];
|
||||
|
||||
var pred = [[CPCompoundPredicate alloc] initWithType:CPAndPredicateType subpredicates:[CPArray arrayWithObjects:predOne,predTwo]];
|
||||
var predOne = [[CPComparisonPredicate alloc] initWithLeftExpression:[CPExpression expressionForKeyPath:@"Record1.Name"] rightExpression:[CPExpression expressionForConstantValue:@"J"] modifier:CPDirectPredicateModifier type:CPBeginsWithPredicateOperatorType options:0],
|
||||
predTwo = [[CPComparisonPredicate alloc] initWithLeftExpression:[CPExpression expressionForKeyPath:@"Record1.Age"] rightExpression:[CPExpression expressionForConstantValue:[CPNumber numberWithInt:40]] modifier:CPDirectPredicateModifier type:CPLessThanPredicateOperatorType options:0],
|
||||
pred = [[CPCompoundPredicate alloc] initWithType:CPAndPredicateType subpredicates:[CPArray arrayWithObjects:predOne,predTwo]];
|
||||
|
||||
[self assertTrue:[pred evaluateWithObject:dict] message:"'"+ [pred description] + "' should be true"];
|
||||
}
|
||||
@@ -263,7 +263,7 @@
|
||||
predicate = [CPPredicate predicateWithFormat: @"%K < %d", @"Record1.Age", 40];
|
||||
[self assertTrue:[predicate evaluateWithObject:dict] message:[predicate description] + " should be true"];
|
||||
|
||||
predicate = [CPPredicate predicateWithFormat: @"%K BETWEEN %@", @"Record1.Age", [CPArray arrayWithObjects:[CPNumber numberWithInt: 20], [CPNumber numberWithInt:40]]];
|
||||
predicate = [CPPredicate predicateWithFormat: @"%K BETWEEN %@", @"Record1.Age", [CPArray arrayWithObjects:[CPNumber numberWithInt:20], [CPNumber numberWithInt:40]]];
|
||||
[self assertTrue:[predicate evaluateWithObject:dict] message:[predicate description] + " should be true"];
|
||||
|
||||
predicate = [CPPredicate predicateWithFormat: @"Record1.Age BETWEEN {%f,%f}", 20, 40];
|
||||
@@ -382,6 +382,70 @@
|
||||
[self assertTrue:[left isEqualToSet:result] message:"Expression eval " + left + " should be " + result];
|
||||
}
|
||||
|
||||
- (void)testExpressionAndPredicateIsEqual
|
||||
{
|
||||
var cexp1 = [CPExpression expressionForConstantValue:2],
|
||||
cexp2 = [CPExpression expressionForConstantValue:2];
|
||||
[self assert:cexp1 equals:cexp2];
|
||||
|
||||
var exp1 = [CPExpression expressionForKeyPath:"path"],
|
||||
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"]],
|
||||
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]],
|
||||
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'"],
|
||||
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];
|
||||
}
|
||||
|
||||
- (void)testProxyArrayFiltering
|
||||
{
|
||||
var proxyArray = [self mutableArrayValueForKey:@"simpleArray"],
|
||||
predicate = [CPPredicate predicateWithFormat:@"SELF CONTAINS 'a'"];
|
||||
|
||||
var filtered = [proxyArray filteredArrayUsingPredicate:predicate];
|
||||
|
||||
[self assertTrue:([filtered count] == 2) message:@"Count should be 2 and is " + [filtered count]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPObject (PredicateTesting)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
@import <Foundation/CPExpression.j>
|
||||
|
||||
@implementation NSKeyPathExpression : CPExpression_keypath
|
||||
@implementation NSKeyPathExpression : _CPKeyPathExpression
|
||||
{
|
||||
}
|
||||
|
||||
@@ -11,12 +11,12 @@
|
||||
|
||||
- (Class)classForKeyedArchiver
|
||||
{
|
||||
return [CPExpression_keypath class];
|
||||
return [_CPKeyPathExpression class];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPKeyPathSpecifierExpression : CPExpression_constant
|
||||
@implementation _CPKeyPathSpecifierExpression : _CPConstantValueExpression
|
||||
{
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSKeyPathSpecifierExpression : CPKeyPathSpecifierExpression
|
||||
@implementation NSKeyPathSpecifierExpression : _CPKeyPathSpecifierExpression
|
||||
{
|
||||
}
|
||||
|
||||
@@ -40,22 +40,22 @@
|
||||
|
||||
- (Class)classForKeyedArchiver
|
||||
{
|
||||
return [CPExpression_constant class];
|
||||
return [_CPConstantValueExpression class];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPExpression_constant (NSCoding)
|
||||
@implementation _CPConstantValueExpression (NSCoding)
|
||||
|
||||
- (id)NS_initWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
var value = [aCoder decodeObjectForKey:@"NSConstantValue"];
|
||||
var value = [aCoder decodeObjectForKey:@"NSConstantValue"];
|
||||
return [self initWithValue:value];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSConstantValueExpression : CPExpression_constant
|
||||
@implementation NSConstantValueExpression : _CPConstantValueExpression
|
||||
{
|
||||
}
|
||||
|
||||
@@ -66,26 +66,26 @@
|
||||
|
||||
- (Class)classForKeyedArchiver
|
||||
{
|
||||
return [CPExpression_constant class];
|
||||
return [_CPConstantValueExpression class];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPExpression_function (NSCoding)
|
||||
@implementation _CPFunctionExpression (NSCoding)
|
||||
|
||||
- (id)NS_initWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
{
|
||||
var type = [aCoder decodeIntForKey:@"NSExpressionType"],
|
||||
operand = [aCoder decodeObjectForKey:@"NSOperand"],
|
||||
selector = CPSelectorFromString([aCoder decodeObjectForKey:@"NSSelectorName"]),
|
||||
args = [aCoder decodeObjectForKey:@"NSArguments"];
|
||||
|
||||
|
||||
return [self initWithTarget:operand selector:selector arguments:args type:type];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSFunctionExpression : CPExpression_function
|
||||
@implementation NSFunctionExpression : _CPFunctionExpression
|
||||
{
|
||||
}
|
||||
|
||||
@@ -96,25 +96,25 @@
|
||||
|
||||
- (Class)classForKeyedArchiver
|
||||
{
|
||||
return [CPExpression_function class];
|
||||
return [_CPFunctionExpression class];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPExpression_set (NSCoding)
|
||||
@implementation _CPSetExpression (NSCoding)
|
||||
|
||||
- (id)NS_initWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
var type = [aCoder decodeIntForKey:@"NSExpressionType"],
|
||||
left = [aCoder decodeObjectForKey:@"NSLeftExpression"],
|
||||
right = [aCoder decodeObjectForKey:@"NSRightExpression"];
|
||||
|
||||
|
||||
return [self initWithType:type left:left right:right];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSSetExpression : CPExpression_set
|
||||
@implementation NSSetExpression : _CPSetExpression
|
||||
{
|
||||
}
|
||||
|
||||
@@ -125,12 +125,12 @@
|
||||
|
||||
- (Class)classForKeyedArchiver
|
||||
{
|
||||
return [CPExpression_set class];
|
||||
return [_CPSetExpression class];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSSelfExpression : CPExpression_self
|
||||
@implementation NSSelfExpression : _CPSelfExpression
|
||||
{
|
||||
}
|
||||
|
||||
@@ -141,12 +141,12 @@
|
||||
|
||||
- (Class)classForKeyedArchiver
|
||||
{
|
||||
return [CPExpression_self class];
|
||||
return [_CPSelfExpression class];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPExpression_variable (NSCoding)
|
||||
@implementation _CPVariableExpression (NSCoding)
|
||||
|
||||
- (id)NS_initWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
@@ -156,7 +156,7 @@
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSVariableExpression : CPExpression_variable
|
||||
@implementation NSVariableExpression : _CPVariableExpression
|
||||
{
|
||||
}
|
||||
|
||||
@@ -167,12 +167,12 @@
|
||||
|
||||
- (Class)classForKeyedArchiver
|
||||
{
|
||||
return [CPExpression_variable class];
|
||||
return [_CPVariableExpression class];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPExpression_aggregate (NSCoding)
|
||||
@implementation _CPAggregateExpression (NSCoding)
|
||||
|
||||
- (id)NS_initWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
@@ -182,7 +182,7 @@
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSAggregateExpression : CPExpression_aggregate
|
||||
@implementation NSAggregateExpression : _CPAggregateExpression
|
||||
{
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@
|
||||
|
||||
- (Class)classForKeyedArchiver
|
||||
{
|
||||
return [CPExpression_aggregate class];
|
||||
return [_CPAggregateExpression class];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user