NSStringRACKeyPathUtilitiesSpec.m 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // NSStringRACKeyPathUtilitiesSpec.m
  3. // ReactiveCocoa
  4. //
  5. // Created by Uri Baghin on 05/05/2013.
  6. // Copyright (c) 2013 GitHub, Inc. All rights reserved.
  7. //
  8. #import <Quick/Quick.h>
  9. #import <Nimble/Nimble.h>
  10. #import "NSString+RACKeyPathUtilities.h"
  11. QuickSpecBegin(NSStringRACKeyPathUtilitiesSpec)
  12. qck_describe(@"-keyPathComponents", ^{
  13. qck_it(@"should return components in the key path", ^{
  14. expect(@"self.test.key.path".rac_keyPathComponents).to(equal((@[@"self", @"test", @"key", @"path"])));
  15. });
  16. qck_it(@"should return nil if given an empty string", ^{
  17. expect(@"".rac_keyPathComponents).to(beNil());
  18. });
  19. });
  20. qck_describe(@"-keyPathByDeletingLastKeyPathComponent", ^{
  21. qck_it(@"should return the parent key path", ^{
  22. expect(@"grandparent.parent.child".rac_keyPathByDeletingLastKeyPathComponent).to(equal(@"grandparent.parent"));
  23. });
  24. qck_it(@"should return nil if given an empty string", ^{
  25. expect(@"".rac_keyPathByDeletingLastKeyPathComponent).to(beNil());
  26. });
  27. qck_it(@"should return nil if given a key path with only one component", ^{
  28. expect(@"self".rac_keyPathByDeletingLastKeyPathComponent).to(beNil());
  29. });
  30. });
  31. qck_describe(@"-keyPathByDeletingFirstKeyPathComponent", ^{
  32. qck_it(@"should return the remaining key path", ^{
  33. expect(@"first.second.third".rac_keyPathByDeletingFirstKeyPathComponent).to(equal(@"second.third"));
  34. });
  35. qck_it(@"should return nil if given an empty string", ^{
  36. expect(@"".rac_keyPathByDeletingFirstKeyPathComponent).to(beNil());
  37. });
  38. qck_it(@"should return nil if given a key path with only one component", ^{
  39. expect(@"self".rac_keyPathByDeletingFirstKeyPathComponent).to(beNil());
  40. });
  41. });
  42. QuickSpecEnd