File: common_prefix.m

package info (click to toggle)
gnustep-base 1.31.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,580 kB
  • sloc: objc: 239,446; ansic: 36,519; cpp: 122; sh: 112; makefile: 100; xml: 32
file content (41 lines) | stat: -rw-r--r-- 1,463 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSString.h>
#import "Testing.h"

int main()
{
  NSAutoreleasePool *arp = [NSAutoreleasePool new];
  NSString *result;

  result = [@"abc" commonPrefixWithString:nil options:0];
  PASS_EQUAL(result, @"", "common prefix of some string with nil is empty string");

  result = [@"abc" commonPrefixWithString:@"abc" options:0];
  PASS_EQUAL(result, @"abc", "common prefix of identical strings is the entire string");

  result = [@"abc" commonPrefixWithString:@"abx" options:0];
  PASS_EQUAL(result, @"ab", "common prefix of 'abc' and 'abx' is 'ab'");

  result = [@"abc" commonPrefixWithString:@"def" options:0];
  PASS_EQUAL(result, @"", "common prefix of completely different strings is empty");

  result = [@"abc" commonPrefixWithString:@"" options:0];
  PASS_EQUAL(result, @"", "common prefix with an empty string is empty");

  result = [@"abc" commonPrefixWithString:@"a" options:0];
  PASS_EQUAL(result, @"a", "common prefix of 'abc' and 'a' is 'a'");

  result = [@"abc" commonPrefixWithString:@"aöç" options:0];
  PASS_EQUAL(result, @"a", "common prefix of 'abc' and 'aöç' is 'a'");

  result = [@"" commonPrefixWithString:@"abc" options:0];
  PASS_EQUAL(result, @"", "common prefix with an empty base string is empty");

  result = [@"abc" commonPrefixWithString:@"abcx" options:0];
  PASS_EQUAL(result, @"abc", "common prefix of 'abc' and 'abcx' is 'abc'");

  [arp drain];

  return 0;
}