Skip to content

Commit

Permalink
Small array keyword fixes for NSPredicate
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Frith-Macdonald committed Oct 8, 2023
1 parent e58b83c commit 531d3b8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2023-10-08 Richard Frith-Macdonald <[email protected]>

* Source/NSPredicate.m: fixup for array access keywords
* Tests/base/NSPredicate/basic.m: add simple testcases for array

2023-10-07 Gregory John Casamento <[email protected]>

* Headers/Foundation/NSKeyValueObserving.h
Expand Down
6 changes: 3 additions & 3 deletions Source/NSPredicate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
24 changes: 24 additions & 0 deletions Tests/base/NSPredicate/basic.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 531d3b8

Please sign in to comment.