diff --git a/ChangeLog b/ChangeLog index 661cd3b6f7..39a2a8ecf2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2023-10-08 Richard Frith-Macdonald + + * Source/NSPredicate.m: fixup for array access keywords + * Tests/base/NSPredicate/basic.m: add simple testcases for array + 2023-10-07 Gregory John Casamento * Headers/Foundation/NSKeyValueObserving.h diff --git a/Source/NSPredicate.m b/Source/NSPredicate.m index f38622638f..366984111e 100644 --- a/Source/NSPredicate.m +++ b/Source/NSPredicate.m @@ -2634,17 +2634,17 @@ - (NSExpression *) parseFunctionalExpression if ([self scanPredicateKeyword: @"FIRST"]) { left = [NSExpression expressionForFunction: @"_first" - arguments: [NSArray arrayWithObject: [self parseExpression]]]; + arguments: [NSArray arrayWithObject: left]]; } else if ([self scanPredicateKeyword: @"LAST"]) { left = [NSExpression expressionForFunction: @"_last" - arguments: [NSArray arrayWithObject: [self parseExpression]]]; + arguments: [NSArray arrayWithObject: left]]; } else if ([self scanPredicateKeyword: @"SIZE"]) { left = [NSExpression expressionForFunction: @"count" - arguments: [NSArray arrayWithObject: [self parseExpression]]]; + arguments: [NSArray arrayWithObject: left]]; } else { diff --git a/Tests/base/NSPredicate/basic.m b/Tests/base/NSPredicate/basic.m index 3f07691c18..3d35863701 100644 --- a/Tests/base/NSPredicate/basic.m +++ b/Tests/base/NSPredicate/basic.m @@ -151,6 +151,28 @@ # endif END_SET("Block predicates"); } + +void testArray(void) +{ + NSArray *array; + NSPredicate *predicate; + + array = [NSArray arrayWithObjects: + [NSNumber numberWithInteger: 1], + [NSNumber numberWithInteger: 2], + [NSNumber numberWithInteger: 0], + nil]; + + predicate = [NSPredicate predicateWithFormat: @"SELF[FIRST] = 1"]; + PASS([predicate evaluateWithObject: array], "first is one") + + predicate = [NSPredicate predicateWithFormat: @"SELF[LAST] = 0"]; + PASS([predicate evaluateWithObject: array], "last is zero") + + predicate = [NSPredicate predicateWithFormat: @"SELF[SIZE] = 3"]; + PASS([predicate evaluateWithObject: array], "size is three") +} + int main() { NSArray *filtered; @@ -257,6 +279,8 @@ int main() PASS_EQUAL([a description], @"(yes)", "predicate created with format can filter an array") + testArray(); + END_SET("basic") return 0;