mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 00:11:26 +00:00
NSPredicate: Check if predicates with NSNull work as expected
This commit is contained in:
parent
4e45c968d5
commit
7b657f4777
1 changed files with 34 additions and 0 deletions
34
Tests/base/NSPredicate/nsnull.m
Normal file
34
Tests/base/NSPredicate/nsnull.m
Normal file
|
@ -0,0 +1,34 @@
|
|||
#import "ObjectTesting.h"
|
||||
#import "Foundation/NSAutoreleasePool.h"
|
||||
#import "Foundation/NSPredicate.h"
|
||||
#import "Foundation/NSArray.h"
|
||||
#import "Foundation/NSNull.h"
|
||||
|
||||
int main(void) {
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
NSArray *array, *filtered;
|
||||
NSPredicate *predicate;
|
||||
|
||||
// Basic filtering with NSPredicate
|
||||
array = @[@{@"key": @"value1"}, @{@"key": @"value2"}, [NSNull null]];
|
||||
predicate = [NSPredicate predicateWithFormat:@"key == %@", @"value2"];
|
||||
filtered = [array filteredArrayUsingPredicate: predicate];
|
||||
|
||||
PASS(filtered.count == 1 && [filtered[0][@"key"] isEqualToString:@"value2"],
|
||||
"NSPredicate should correctly filter array including NSNull");
|
||||
|
||||
// Filtering with NSPredicate where no match is found
|
||||
predicate = [NSPredicate predicateWithFormat:@"key == %@", @"nonexistent"];
|
||||
filtered = [array filteredArrayUsingPredicate: predicate];
|
||||
PASS(filtered.count == 0,
|
||||
"NSPredicate should return an empty array when no match is found");
|
||||
|
||||
// Filtering with NSPredicate with a different key
|
||||
predicate = [NSPredicate predicateWithFormat:@"anotherKey == %@", @"value1"];
|
||||
filtered = [array filteredArrayUsingPredicate: predicate];
|
||||
PASS(filtered.count == 0,
|
||||
"NSPredicate should return an empty array when filtering with a non-existent key");
|
||||
|
||||
[arp release];
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue