NSExpressionFBFormatTests.m 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 "NSExpression+FBFormat.h"
  11. #import "FBElementUtils.h"
  12. @interface NSExpressionFBFormatTests : XCTestCase
  13. @end
  14. @implementation NSExpressionFBFormatTests
  15. - (void)testFormattingForExistingProperty
  16. {
  17. NSExpression *expr = [NSExpression expressionWithFormat:@"wdName"];
  18. NSExpression *prop = [NSExpression fb_wdExpressionWithExpression:expr];
  19. XCTAssertEqualObjects([prop keyPath], @"wdName");
  20. }
  21. - (void)testFormattingForExistingPropertyShortcut
  22. {
  23. NSExpression *expr = [NSExpression expressionWithFormat:@"visible"];
  24. NSExpression *prop = [NSExpression fb_wdExpressionWithExpression:expr];
  25. XCTAssertEqualObjects([prop keyPath], @"isWDVisible");
  26. }
  27. - (void)testFormattingForValidExpressionWOKeys
  28. {
  29. NSExpression *expr = [NSExpression expressionWithFormat:@"1"];
  30. NSExpression *prop = [NSExpression fb_wdExpressionWithExpression:expr];
  31. XCTAssertEqualObjects([prop constantValue], [NSNumber numberWithInt:1]);
  32. }
  33. - (void)testFormattingForExistingComplexProperty
  34. {
  35. NSExpression *expr = [NSExpression expressionWithFormat:@"wdRect.x"];
  36. NSExpression *prop = [NSExpression fb_wdExpressionWithExpression:expr];
  37. XCTAssertEqualObjects([prop keyPath], @"wdRect.x");
  38. }
  39. - (void)testFormattingForExistingComplexPropertyWOPrefix
  40. {
  41. NSExpression *expr = [NSExpression expressionWithFormat:@"rect.x"];
  42. NSExpression *prop = [NSExpression fb_wdExpressionWithExpression:expr];
  43. XCTAssertEqualObjects([prop keyPath], @"wdRect.x");
  44. }
  45. - (void)testFormattingForPredicateWithUnknownKey
  46. {
  47. NSExpression *expr = [NSExpression expressionWithFormat:@"title"];
  48. XCTAssertThrowsSpecificNamed([NSExpression fb_wdExpressionWithExpression:expr], NSException, FBUnknownAttributeException);
  49. }
  50. @end