/core/externals/update-engine/externals/google-toolbox-for-mac/Foundation/GTMNSString+ReplaceTest.m

http://macfuse.googlecode.com/ · Objective C · 59 lines · 28 code · 14 blank · 17 comment · 0 complexity · a4673b7629c3185dc9f1df341c3a5980 MD5 · raw file

  1. //
  2. // GTMNSString+ReplaceTest.m
  3. //
  4. // Copyright 2006-2008 Google Inc.
  5. //
  6. // Licensed under the Apache License, Version 2.0 (the "License"); you may not
  7. // use this file except in compliance with the License. You may obtain a copy
  8. // of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15. // License for the specific language governing permissions and limitations under
  16. // the License.
  17. //
  18. #import "GTMSenTestCase.h"
  19. #import "GTMNSString+Replace.h"
  20. @interface GTMNSString_ReplaceTest : GTMTestCase
  21. @end
  22. @implementation GTMNSString_ReplaceTest
  23. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  24. - (void)testStringByReplacingStringWithString {
  25. NSString *testString = @"a bc debc gh";
  26. NSString *result;
  27. result = [testString gtm_stringByReplacingString:@"bc" withString:@"BC"];
  28. STAssertEqualObjects(@"a BC deBC gh", result,
  29. @"'bc' wasn't replaced with 'BC'");
  30. result = [testString gtm_stringByReplacingString:@"bc" withString:@""];
  31. STAssertEqualObjects(@"a de gh", result, @"'bc' wasn't replaced with ''");
  32. result = [testString gtm_stringByReplacingString:@"bc" withString:nil];
  33. STAssertEqualObjects(@"a de gh", result, @"'bc' wasn't replaced with (nil)");
  34. result = [testString gtm_stringByReplacingString:@" " withString:@"S"];
  35. STAssertEqualObjects(@"aSbcSdebcSgh", result, @"' ' wasn't replaced with 'S'");
  36. result = [testString gtm_stringByReplacingString:nil withString:@"blah"];
  37. STAssertEqualObjects(testString, result, @"(nil) wasn't replaced with 'blah'");
  38. result = [testString gtm_stringByReplacingString:nil withString:nil];
  39. STAssertEqualObjects(testString, result, @"(nil) wasn't replaced with (nil)");
  40. result = [testString gtm_stringByReplacingString:@"" withString:@"X"];
  41. STAssertEqualObjects(testString, result,
  42. @"replacing '' with anything should yield the original string");
  43. }
  44. #endif // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  45. @end