From aa15d317223cc0d1f0d3267728132b7bdbf238df Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 27 Jan 2015 12:02:48 +0100 Subject: Expand previous unit test --- UnitTests/SPParserUtilsTest.m | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/UnitTests/SPParserUtilsTest.m b/UnitTests/SPParserUtilsTest.m index c760e8b5..5066f8f7 100644 --- a/UnitTests/SPParserUtilsTest.m +++ b/UnitTests/SPParserUtilsTest.m @@ -48,6 +48,13 @@ NSString *emptyString = [NSString stringWithCString:empty encoding:NSUTF8StringEncoding]; STAssertEquals(utf8strlen(empty),[emptyString length], @"empty string"); + // This is just a little safeguard. + // If any of those conditions fail, all of the following assumptions are moot. + const char *charSeq = "\xF0\x9F\x8D\x8F"; //🍏 + NSString *charString = [NSString stringWithCString:charSeq encoding:NSUTF8StringEncoding]; + STAssertEquals(strlen(charSeq), 4, @"assumption about storage for binary C string"); + STAssertEquals([charString length], 2, @"assumption about NSString internal storage of string"); + const char *singleByteSeq = "Hello World!"; NSString *singleByteString = [NSString stringWithCString:singleByteSeq encoding:NSUTF8StringEncoding]; STAssertEquals(utf8strlen(singleByteSeq), [singleByteString length], @"ASCII UTF-8 subset"); @@ -67,6 +74,11 @@ const char *mixedSeq = "\xE3\x81\x82\xE3\x82\x81\xE3\x80\x90\xE9\xA3\xB4\xE3\x80\x91\xF0\x9F\x8D\xAD \xE2\x89\x88 S\xC3\xBC\xC3\x9Figkeit"; // あめ【飴】🍭 ≈ Süßigkeit NSString *mixedString = [NSString stringWithCString:mixedSeq encoding:NSUTF8StringEncoding]; STAssertEquals(utf8strlen(mixedSeq), [mixedString length], @"utf8 characters with all 4 lengths mixed together."); + + //composed vs. decomposed chars + const char *decompSeq = "\xC3\xA4 - a\xCC\x88"; // ä - ä + NSString *decompString = [NSString stringWithCString:decompSeq encoding:NSUTF8StringEncoding]; + STAssertEquals(utf8strlen(decompSeq), [decompString length], @"\"LATIN SMALL LETTER A WITH DIAERESIS\" vs. \"LATIN SMALL LETTER A\" + \"COMBINING DIAERESIS\""); } @end -- cgit v1.2.3