Permalink
Browse files

Expand previous unit test

  • Loading branch information...
dmoagx committed Jan 27, 2015
1 parent c9c96af commit aa15d317223cc0d1f0d3267728132b7bdbf238df
Showing with 12 additions and 0 deletions.
  1. +12 −0 UnitTests/SPParserUtilsTest.m
@@ -48,6 +48,13 @@ - (void)testUtf8strlen {
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 @@ - (void)testUtf8strlen {
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

0 comments on commit aa15d31

Please sign in to comment.