diff --git a/Tests/AppKit/CPArrayControllerTest.j b/Tests/AppKit/CPArrayControllerTest.j index 276854bab..05e75a978 100644 --- a/Tests/AppKit/CPArrayControllerTest.j +++ b/Tests/AppKit/CPArrayControllerTest.j @@ -554,7 +554,7 @@ 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]; } diff --git a/Tests/Foundation/CPPredicateTest.j b/Tests/Foundation/CPPredicateTest.j index 569c445a4..0c1420dda 100644 --- a/Tests/Foundation/CPPredicateTest.j +++ b/Tests/Foundation/CPPredicateTest.j @@ -27,7 +27,7 @@ d = [CPDictionary dictionaryWithObjects:objects forKeys:keys]; [dict setObject:d forKey:@"Record2"]; - + simpleArray = [CPArray arrayWithObjects:@"a", @"b", @"ac", @"bc"]; } @@ -67,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]; @@ -82,11 +82,11 @@ - (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]; + 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]; @@ -102,14 +102,14 @@ { // Built-in function var args = [[CPExpression expressionForConstantValue:1], [CPExpression expressionForConstantValue:2], [CPExpression expressionForConstantValue:3]]; - var function_exp = [CPExpression expressionForFunction:"sum:" arguments:args]; + var 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]; + 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"]; @@ -140,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]; } @@ -183,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"]; } @@ -266,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]; @@ -387,12 +384,12 @@ - (void)testExpressionAndPredicateIsEqual { - var cexp1 = [CPExpression expressionForConstantValue:2]; - var cexp2 = [CPExpression expressionForConstantValue:2]; + var cexp1 = [CPExpression expressionForConstantValue:2], + cexp2 = [CPExpression expressionForConstantValue:2]; [self assert:cexp1 equals:cexp2]; - var exp1 = [CPExpression expressionForKeyPath:"path"]; - var exp2 = [CPExpression expressionForKeyPath:"path"]; + var exp1 = [CPExpression expressionForKeyPath:"path"], + exp2 = [CPExpression expressionForKeyPath:"path"]; [self assert:exp1 equals:exp2]; exp1 = [CPExpression expressionForEvaluatedObject]; @@ -403,8 +400,8 @@ 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"]]; + 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]]; @@ -414,16 +411,16 @@ 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]]; + 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'"]; - var pred2 = [CPPredicate predicateWithFormat:@"FUNCTION('toto', 'stringByReplacingOccurrencesOfString:withString:', 'o', 'a') == 'tata'"]; + 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"]; @@ -443,9 +440,9 @@ { 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]]; }