@@ -382,6 +382,71 @@ - (void)testCanHaveMultipleMutationsWhileOffline {
382
382
]));
383
383
}
384
384
385
+ - (void )testQueriesCanUseNotEqualFilters {
386
+ // These documents are ordered by value in "zip" since notEquals filter is an inequality, which
387
+ // results in documents being sorted by value.
388
+ NSDictionary *testDocs = @{
389
+ @" a" : @{@" zip" : @(NAN)},
390
+ @" b" : @{@" zip" : @91102 },
391
+ @" c" : @{@" zip" : @98101 },
392
+ @" d" : @{@" zip" : @98103 },
393
+ @" e" : @{@" zip" : @[ @98101 ]},
394
+ @" f" : @{@" zip" : @[ @98101 , @98102 ]},
395
+ @" g" : @{@" zip" : @[ @" 98101" , @{@" zip" : @98101 } ]},
396
+ @" h" : @{@" zip" : @{@" code" : @500 }},
397
+ @" i" : @{@" zip" : [NSNull null ]},
398
+ @" j" : @{@" code" : @500 },
399
+ };
400
+ FIRCollectionReference *collection = [self collectionRefWithDocuments: testDocs];
401
+
402
+ // Search for zips not matching 98101.
403
+ FIRQuerySnapshot *snapshot = [self readDocumentSetForRef: [collection queryWhereField: @" zip"
404
+ isNotEqualTo: @98101 ]];
405
+ XCTAssertEqualObjects (FIRQuerySnapshotGetData (snapshot), (@[
406
+ testDocs[@" a" ], testDocs[@" b" ], testDocs[@" d" ], testDocs[@" e" ],
407
+ testDocs[@" f" ], testDocs[@" g" ], testDocs[@" h" ]
408
+ ]));
409
+
410
+ // With objects.
411
+ snapshot = [self readDocumentSetForRef: [collection queryWhereField: @" zip"
412
+ isNotEqualTo: @{@" code" : @500 }]];
413
+ XCTAssertEqualObjects (FIRQuerySnapshotGetData (snapshot), (@[
414
+ testDocs[@" a" ], testDocs[@" b" ], testDocs[@" c" ], testDocs[@" d" ],
415
+ testDocs[@" e" ], testDocs[@" f" ], testDocs[@" g" ]
416
+ ]));
417
+
418
+ // With null.
419
+ snapshot = [self readDocumentSetForRef: [collection queryWhereField: @" zip"
420
+ isNotEqualTo: @[ [NSNull null ] ]]];
421
+ XCTAssertEqualObjects (FIRQuerySnapshotGetData (snapshot), (@[
422
+ testDocs[@" a" ], testDocs[@" b" ], testDocs[@" c" ], testDocs[@" d" ],
423
+ testDocs[@" e" ], testDocs[@" f" ], testDocs[@" g" ], testDocs[@" h" ]
424
+ ]));
425
+
426
+ // With NAN.
427
+ snapshot = [self readDocumentSetForRef: [collection queryWhereField: @" zip" isNotEqualTo: @(NAN)]];
428
+ XCTAssertEqualObjects (FIRQuerySnapshotGetData (snapshot), (@[
429
+ testDocs[@" b" ], testDocs[@" c" ], testDocs[@" d" ], testDocs[@" e" ],
430
+ testDocs[@" f" ], testDocs[@" g" ], testDocs[@" h" ]
431
+ ]));
432
+ }
433
+
434
+ - (void )testQueriesCanUseNotEqualFiltersWithDocIds {
435
+ NSDictionary *testDocs = @{
436
+ @" aa" : @{@" key" : @" aa" },
437
+ @" ab" : @{@" key" : @" ab" },
438
+ @" ba" : @{@" key" : @" ba" },
439
+ @" bb" : @{@" key" : @" bb" },
440
+ };
441
+ FIRCollectionReference *collection = [self collectionRefWithDocuments: testDocs];
442
+
443
+ FIRQuerySnapshot *snapshot =
444
+ [self readDocumentSetForRef: [collection queryWhereFieldPath: [FIRFieldPath documentID ]
445
+ isNotEqualTo: @" aa" ]];
446
+ XCTAssertEqualObjects (FIRQuerySnapshotGetData (snapshot),
447
+ (@[ testDocs[@" ab" ], testDocs[@" ba" ], testDocs[@" bb" ] ]));
448
+ }
449
+
385
450
- (void )testQueriesCanUseArrayContainsFilters {
386
451
NSDictionary *testDocs = @{
387
452
@" a" : @{@" array" : @[ @42 ]},
@@ -441,6 +506,74 @@ - (void)testQueriesCanUseInFiltersWithDocIds {
441
506
XCTAssertEqualObjects (FIRQuerySnapshotGetData (snapshot), (@[ testDocs[@" aa" ], testDocs[@" ab" ] ]));
442
507
}
443
508
509
+ - (void )testQueriesCanUseNotInFilters {
510
+ NSDictionary *testDocs = @{
511
+ @" a" : @{@" zip" : @98101 },
512
+ @" b" : @{@" zip" : @91102 },
513
+ @" c" : @{@" zip" : @98103 },
514
+ @" d" : @{@" zip" : @[ @98101 ]},
515
+ @" e" : @{@" zip" : @[ @" 98101" , @{@" zip" : @98101 } ]},
516
+ @" f" : @{@" zip" : @{@" code" : @500 }},
517
+ @" g" : @{@" zip" : @[ @98101 , @98102 ]},
518
+ @" h" : @{@" code" : @500 },
519
+ @" i" : @{@" zip" : [NSNull null ]},
520
+ @" j" : @{@" zip" : @(NAN)},
521
+ };
522
+ FIRCollectionReference *collection = [self collectionRefWithDocuments: testDocs];
523
+
524
+ // Search for zips not matching 98101, 98103, and [98101, 98102].
525
+ FIRQuerySnapshot *snapshot = [self
526
+ readDocumentSetForRef: [collection queryWhereField: @" zip"
527
+ notIn: @[ @98101 , @98103 , @[ @98101 , @98102 ] ]]];
528
+ XCTAssertEqualObjects (FIRQuerySnapshotGetData (snapshot), (@[
529
+ testDocs[@" b" ], testDocs[@" d" ], testDocs[@" e" ], testDocs[@" f" ],
530
+ testDocs[@" i" ], testDocs[@" j" ]
531
+ ]));
532
+
533
+ // With objects.
534
+ snapshot = [self readDocumentSetForRef: [collection queryWhereField: @" zip"
535
+ notIn: @[ @{@" code" : @500 } ]]];
536
+ XCTAssertEqualObjects (FIRQuerySnapshotGetData (snapshot), (@[
537
+ testDocs[@" a" ], testDocs[@" b" ], testDocs[@" c" ], testDocs[@" d" ],
538
+ testDocs[@" e" ], testDocs[@" g" ], testDocs[@" i" ], testDocs[@" j" ]
539
+ ]));
540
+
541
+ // With null.
542
+ snapshot = [self readDocumentSetForRef: [collection queryWhereField: @" zip"
543
+ notIn: @[ [NSNull null ] ]]];
544
+ XCTAssertTrue (snapshot.isEmpty );
545
+
546
+ // With NAN.
547
+ snapshot = [self readDocumentSetForRef: [collection queryWhereField: @" zip" notIn: @[ @(NAN) ]]];
548
+ XCTAssertEqualObjects (FIRQuerySnapshotGetData (snapshot), (@[
549
+ testDocs[@" a" ], testDocs[@" b" ], testDocs[@" c" ], testDocs[@" d" ],
550
+ testDocs[@" e" ], testDocs[@" f" ], testDocs[@" g" ], testDocs[@" i" ]
551
+ ]));
552
+
553
+ // With NAN and a number.
554
+ snapshot = [self readDocumentSetForRef: [collection queryWhereField: @" zip"
555
+ notIn: @[ @(NAN), @98101 ]]];
556
+ XCTAssertEqualObjects (FIRQuerySnapshotGetData (snapshot), (@[
557
+ testDocs[@" b" ], testDocs[@" c" ], testDocs[@" d" ], testDocs[@" e" ],
558
+ testDocs[@" f" ], testDocs[@" g" ], testDocs[@" i" ]
559
+ ]));
560
+ }
561
+
562
+ - (void )testQueriesCanUseNotInFiltersWithDocIds {
563
+ NSDictionary *testDocs = @{
564
+ @" aa" : @{@" key" : @" aa" },
565
+ @" ab" : @{@" key" : @" ab" },
566
+ @" ba" : @{@" key" : @" ba" },
567
+ @" bb" : @{@" key" : @" bb" },
568
+ };
569
+ FIRCollectionReference *collection = [self collectionRefWithDocuments: testDocs];
570
+
571
+ FIRQuerySnapshot *snapshot =
572
+ [self readDocumentSetForRef: [collection queryWhereFieldPath: [FIRFieldPath documentID ]
573
+ notIn: @[ @" aa" , @" ab" ]]];
574
+ XCTAssertEqualObjects (FIRQuerySnapshotGetData (snapshot), (@[ testDocs[@" ba" ], testDocs[@" bb" ] ]));
575
+ }
576
+
444
577
- (void )testQueriesCanUseArrayContainsAnyFilters {
445
578
NSDictionary *testDocs = @{
446
579
@" a" : @{@" array" : @[ @42 ]},
0 commit comments