From 70518556fb4f8fb828d766c4b521be7baad2b6e8 Mon Sep 17 00:00:00 2001 From: hmelder Date: Mon, 28 Oct 2024 13:37:31 +0100 Subject: [PATCH] NSString: More test cases --- Tests/base/NSString/common_prefix.m | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Tests/base/NSString/common_prefix.m diff --git a/Tests/base/NSString/common_prefix.m b/Tests/base/NSString/common_prefix.m new file mode 100644 index 000000000..447dc4507 --- /dev/null +++ b/Tests/base/NSString/common_prefix.m @@ -0,0 +1,39 @@ +#import +#import +#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]; +} +