mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-30 10:22:03 +00:00
Fixed with CPPredicate tests: [CPArray arrayWithObjects] don't take a final nil anymore in Cappuccino.
This commit is contained in:
1 parent
63dfb8a227
commit
1b5efdfc5b
1 file changed
+45
-45
@@ -12,21 +12,21 @@
|
||||
{
|
||||
var d,
|
||||
objects;
|
||||
|
||||
|
||||
dict = [[CPDictionary alloc] init];
|
||||
[dict setObject: @"A Title" forKey:@"title"];
|
||||
|
||||
var keys = [CPArray arrayWithObjects:@"Name",@"Age",@"Children",nil];
|
||||
objects = [CPArray arrayWithObjects:@"John",[CPNumber numberWithInt:34],[CPArray arrayWithObjects:@"Kid1", @"Kid2", nil],nil];
|
||||
|
||||
d = [CPDictionary dictionaryWithObjects:objects forKeys:keys];
|
||||
[dict setObject:d forKey:@"Record1"];
|
||||
|
||||
objects = [CPArray arrayWithObjects:@"Mary",[CPNumber numberWithInt:30],[CPArray arrayWithObjects:@"Kid1", @"Girl1", nil],nil];
|
||||
|
||||
d = [CPDictionary dictionaryWithObjects:objects forKeys:keys];
|
||||
var keys = [CPArray arrayWithObjects:@"Name",@"Age",@"Children"];
|
||||
objects = [CPArray arrayWithObjects:@"John",[CPNumber numberWithInt:34],[CPArray arrayWithObjects:@"Kid1", @"Kid2"]];
|
||||
|
||||
d = [CPDictionary dictionaryWithObjects:objects forKeys:keys];
|
||||
[dict setObject:d forKey:@"Record1"];
|
||||
|
||||
objects = [CPArray arrayWithObjects:@"Mary",[CPNumber numberWithInt:30],[CPArray arrayWithObjects:@"Kid1", @"Girl1"]];
|
||||
|
||||
d = [CPDictionary dictionaryWithObjects:objects forKeys:keys];
|
||||
[dict setObject:d forKey:@"Record2"];
|
||||
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -35,34 +35,34 @@
|
||||
{
|
||||
var expression_keypath = [CPExpression expressionForKeyPath:@"name"];
|
||||
[self assertNotNull:expression_keypath message:"KeyPath Expression should not be nil"];
|
||||
|
||||
|
||||
var expression_str = [CPExpression expressionForConstantValue:@"j[a-z]an"];
|
||||
[self assertNotNull:expression_str message:"ConstantValue Expression should not be nil"];
|
||||
|
||||
|
||||
var expression_num = [CPExpression expressionForConstantValue:[CPNumber numberWithInt:1]];
|
||||
[self assertNotNull:expression_num message:"ConstantValue Expression should not be nil"];
|
||||
|
||||
var expression_collection = [CPExpression expressionForConstantValue:[CPArray arrayWithObjects:@"a",@"b",@"d",nil]];
|
||||
|
||||
var expression_collection = [CPExpression expressionForConstantValue:[CPArray arrayWithObjects:@"a",@"b",@"d"]];
|
||||
[self assertNotNull:expression_collection message:"ConstantValue Expression should not be nil"];
|
||||
|
||||
|
||||
var expression_var = [CPExpression expressionForVariable:@"variable"];
|
||||
[self assertNotNull:expression_var message:"Variable Expression should not be nil"];
|
||||
|
||||
var expression_function = [CPExpression expressionForFunction:@"sum:" arguments:[CPArray arrayWithObjects:expression_num,expression_num,nil]];
|
||||
var expression_function = [CPExpression expressionForFunction:@"sum:" arguments:[CPArray arrayWithObjects:expression_num,expression_num]];
|
||||
[self assertNotNull:expression_function message:"Function Expression should not be nil"];
|
||||
|
||||
var expression_self = [CPExpression expressionForEvaluatedObject];
|
||||
[self assertNotNull:expression_self message:"Function Expression should not be nil"];
|
||||
|
||||
var expression_aggregate = [CPExpression expressionForAggregate:[CPArray arrayWithObjects:expression_str,expression_num,expression_function,nil]];
|
||||
var expression_aggregate = [CPExpression expressionForAggregate:[CPArray arrayWithObjects:expression_str,expression_num,expression_function]];
|
||||
[self assertNotNull:expression_aggregate message:"Aggregate Expression should not be nil"];
|
||||
|
||||
|
||||
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 = [CPSet setWithObjects:@"a",@"b",@"d",nil];
|
||||
var array = [CPArray arrayWithObjects:@"a",@"b",@"d",nil];
|
||||
|
||||
|
||||
var set = [CPSet setWithObjects:@"a",@"b",@"d"];
|
||||
var array = [CPArray arrayWithObjects:@"a",@"b",@"d"];
|
||||
|
||||
var expression_intersect = [CPExpression expressionForIntersectSet:set with:array];
|
||||
[self assertNotNull:expression_intersect message:"IntersectSet Expression should not be nil"];
|
||||
|
||||
@@ -75,10 +75,10 @@
|
||||
|
||||
- (void)testFunctionExpression
|
||||
{
|
||||
var function_exp = [CPExpression expressionForFunction:"sum:" arguments:[CPArray arrayWithObjects:[CPExpression expressionForConstantValue:1],[CPExpression expressionForConstantValue:2],[CPExpression expressionForConstantValue:3],nil]];
|
||||
var function_exp = [CPExpression expressionForFunction:"sum:" arguments:[CPArray arrayWithObjects:[CPExpression expressionForConstantValue:1],[CPExpression expressionForConstantValue:2],[CPExpression expressionForConstantValue:3]]];
|
||||
|
||||
var pred = [[CPComparisonPredicate alloc] initWithLeftExpression:function_exp rightExpression:[CPExpression expressionForConstantValue:3] modifier:CPDirectPredicateModifier type:CPGreaterThanPredicateOperatorType options:0];
|
||||
|
||||
|
||||
[self assertTrue:[pred evaluateWithObject:nil] message:[pred description] + " should be true"];
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
var pred = [[CPComparisonPredicate alloc] initWithLeftExpression:[CPExpression expressionForKeyPath:@"Record1.Age"] rightExpression:variable_exp modifier:CPDirectPredicateModifier type:CPGreaterThanPredicateOperatorType options:0];
|
||||
|
||||
var variables = [CPDictionary dictionaryWithObject:20 forKey:@"variable"];
|
||||
|
||||
|
||||
[self assertTrue:[pred evaluateWithObject:dict substitutionVariables:variables] message:"'"+ [pred description] + "' should be true"];
|
||||
}
|
||||
|
||||
@@ -96,17 +96,17 @@
|
||||
{
|
||||
var pred = [[CPComparisonPredicate alloc] initWithLeftExpression:[CPExpression expressionForConstantValue:@"àa"] rightExpression:[CPExpression expressionForConstantValue:@"aà"] modifier:CPDirectPredicateModifier type:CPLikePredicateOperatorType options:3];
|
||||
[self assertTrue:[pred evaluateWithObject:nil] message:"/"+ [pred description] + "/ should be true"];
|
||||
|
||||
|
||||
pred = [[CPComparisonPredicate alloc] initWithLeftExpression:[CPExpression expressionForConstantValue:@"aB"] rightExpression:[CPExpression expressionForConstantValue:@"Ab"] modifier:CPDirectPredicateModifier type:CPLikePredicateOperatorType options:1];
|
||||
[self assertTrue:[pred evaluateWithObject:nil] message:"/"+ [pred description] + "/ should be true"];
|
||||
[self assertTrue:[pred evaluateWithObject:nil] message:"/"+ [pred description] + "/ should be true"];
|
||||
}
|
||||
|
||||
- (void)testModifier
|
||||
{
|
||||
var pred = [[CPComparisonPredicate alloc] initWithLeftExpression:[CPExpression expressionForKeyPath:@"Record2.Children"] rightExpression:[CPExpression expressionForConstantValue:@"Gi"] modifier:CPAnyPredicateModifier type:CPBeginsWithPredicateOperatorType options:0];
|
||||
var pred = [[CPComparisonPredicate alloc] initWithLeftExpression:[CPExpression expressionForKeyPath:@"Record2.Children"] rightExpression:[CPExpression expressionForConstantValue:@"Gi"] modifier:CPAnyPredicateModifier type:CPBeginsWithPredicateOperatorType options:0];
|
||||
[self assertTrue:[pred evaluateWithObject:dict] message:"'"+ [pred description] + "' should be true"];
|
||||
|
||||
pred = [[CPComparisonPredicate alloc] initWithLeftExpression:[CPExpression expressionForKeyPath:@"Record1.Children"] rightExpression:[CPExpression expressionForConstantValue:@"Kid"] modifier:CPAllPredicateModifier type:CPBeginsWithPredicateOperatorType options:0];
|
||||
|
||||
pred = [[CPComparisonPredicate alloc] initWithLeftExpression:[CPExpression expressionForKeyPath:@"Record1.Children"] rightExpression:[CPExpression expressionForConstantValue:@"Kid"] modifier:CPAllPredicateModifier type:CPBeginsWithPredicateOperatorType options:0];
|
||||
[self assertTrue:[pred evaluateWithObject:dict] message:"'"+ [pred description] + "' should be true"];
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@
|
||||
|
||||
pred = [[CPComparisonPredicate alloc] initWithLeftExpression:[CPExpression expressionForConstantValue:@"Aa"] rightExpression:[CPExpression expressionForConstantValue:@"ab"] modifier:CPDirectPredicateModifier type:CPLessThanPredicateOperatorType options:0];
|
||||
[self assertTrue:[pred evaluateWithObject:nil] message:"'"+ [pred description] + "' should be true"];
|
||||
|
||||
|
||||
pred = [[CPComparisonPredicate alloc] initWithLeftExpression:[CPExpression expressionForConstantValue:@"Ac"] rightExpression:[CPExpression expressionForConstantValue:@"ab"] modifier:CPDirectPredicateModifier type:CPLessThanPredicateOperatorType options:2];
|
||||
[self assertTrue:[pred evaluateWithObject:nil] message:"'"+ [pred description] + "' should be true"];
|
||||
|
||||
@@ -129,11 +129,11 @@
|
||||
- (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,nil]];
|
||||
|
||||
|
||||
var pred = [[CPCompoundPredicate alloc] initWithType:CPAndPredicateType subpredicates:[CPArray arrayWithObjects:predOne,predTwo]];
|
||||
|
||||
[self assertTrue:[pred evaluateWithObject:dict] message:"'"+ [pred description] + "' should be true"];
|
||||
}
|
||||
|
||||
@@ -143,33 +143,33 @@
|
||||
// TEST String
|
||||
predicate = [CPPredicate predicateWithFormat: @"%K == %@", @"Record1.Name", @"John"];
|
||||
[self assertTrue:[predicate evaluateWithObject:dict] message:[predicate description] + " should be true"];
|
||||
|
||||
|
||||
predicate = [CPPredicate predicateWithFormat: @"%K MATCHES[c] %@", @"Record1.Name", @"john"];
|
||||
[self assertTrue:[predicate evaluateWithObject:dict] message:[predicate description] + " should be true"];
|
||||
|
||||
|
||||
predicate = [CPPredicate predicateWithFormat: @"%K BEGINSWITH %@", @"Record1.Name", @"Jo"];
|
||||
[self assertTrue:[predicate evaluateWithObject:dict] message:[predicate description] + " should be true"];
|
||||
|
||||
|
||||
predicate = [CPPredicate predicateWithFormat: @"(%K == %@) AND (%K == %@)", @"Record1.Name", @"John", @"Record2.Name", @"Mary"];
|
||||
[self assertTrue:[predicate evaluateWithObject:dict] message:[predicate description] + " should be true"];
|
||||
|
||||
// TEST integer
|
||||
predicate = [CPPredicate predicateWithFormat: @"%K == %d", @"Record1.Age", 34];
|
||||
[self assertTrue:[predicate evaluateWithObject:dict] message:[predicate description] + " should be true"];
|
||||
|
||||
|
||||
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], nil]];
|
||||
|
||||
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];
|
||||
[self assertTrue:[predicate evaluateWithObject:dict] message:[predicate description] + " should be true"];
|
||||
|
||||
|
||||
predicate = [CPPredicate predicateWithFormat: @"(%K == %d) OR (%K == %d)", @"Record1.Age", 34, @"Record2.Age", 34];
|
||||
[self assertTrue:[predicate evaluateWithObject:dict] message:[predicate description] + " should be true"];
|
||||
|
||||
// TEST float
|
||||
// TEST float
|
||||
predicate = [CPPredicate predicateWithFormat: @"%K < %f", @"Record1.Age", 40.5];
|
||||
[self assertTrue:[predicate evaluateWithObject:dict] message:[predicate description] + " should be true"];
|
||||
|
||||
@@ -181,7 +181,7 @@
|
||||
[self assertTrue:[predicate evaluateWithObject:dict] message:[predicate description] + " should be true"];
|
||||
|
||||
predicate = [CPPredicate predicateWithFormat: @"ANY %K == %@", @"Record2.Children", @"Girl1"];
|
||||
[self assertTrue:[predicate evaluateWithObject:dict] message:[predicate description] + " should be true"];
|
||||
[self assertTrue:[predicate evaluateWithObject:dict] message:[predicate description] + " should be true"];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user