NSPredicateFBFormatTests.m 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. */
  9. #import <XCTest/XCTest.h>
  10. #import "NSPredicate+FBFormat.h"
  11. @interface NSPredicateFBFormatTests : XCTestCase
  12. @end
  13. @implementation NSPredicateFBFormatTests
  14. - (void)testFormattingForExistingProperty
  15. {
  16. NSPredicate *expr = [NSPredicate predicateWithFormat:@"wdName == 'blabla'"];
  17. XCTAssertNotNil([NSPredicate fb_formatSearchPredicate:expr]);
  18. }
  19. - (void)testFormattingForExistingPropertyOnTheRightSide
  20. {
  21. NSPredicate *expr = [NSPredicate predicateWithFormat:@"0 == wdAccessible"];
  22. XCTAssertNotNil([NSPredicate fb_formatSearchPredicate:expr]);
  23. }
  24. - (void)testFormattingForExistingPropertyShortcut
  25. {
  26. NSPredicate *expr = [NSPredicate predicateWithFormat:@"visible == 1"];
  27. XCTAssertNotNil([NSPredicate fb_formatSearchPredicate:expr]);
  28. }
  29. - (void)testFormattingForComplexExpression
  30. {
  31. NSPredicate *expr = [NSPredicate predicateWithFormat:@"visible == 1 AND NOT (type == 'blabla' OR NOT (label IN {'3', '4'}))"];
  32. XCTAssertNotNil([NSPredicate fb_formatSearchPredicate:expr]);
  33. }
  34. - (void)testFormattingForValidExpressionWOKeys
  35. {
  36. NSPredicate *expr = [NSPredicate predicateWithFormat:@"1 = 1"];
  37. XCTAssertNotNil([NSPredicate fb_formatSearchPredicate:expr]);
  38. }
  39. - (void)testFormattingForExistingComplexProperty
  40. {
  41. NSPredicate *expr = [NSPredicate predicateWithFormat:@"wdRect.x == '0'"];
  42. XCTAssertNotNil([NSPredicate fb_formatSearchPredicate:expr]);
  43. }
  44. - (void)testFormattingForExistingComplexPropertyWOPrefix
  45. {
  46. NSPredicate *expr = [NSPredicate predicateWithFormat:@"rect.x == '0'"];
  47. XCTAssertNotNil([NSPredicate fb_formatSearchPredicate:expr]);
  48. }
  49. - (void)testFormattingForPredicateWithUnknownKey
  50. {
  51. NSPredicate *expr = [NSPredicate predicateWithFormat:@"title == 'blabla'"];
  52. XCTAssertThrows([NSPredicate fb_formatSearchPredicate:expr]);
  53. }
  54. - (void)testBlockPredicateCreation
  55. {
  56. NSPredicate *expr = [NSPredicate predicateWithFormat:@"rect.x == '0'"];
  57. XCTAssertNotNil([NSPredicate fb_snapshotBlockPredicateWithPredicate:expr]);
  58. }
  59. @end