Index: new_tests/Makefile ================================================================== --- new_tests/Makefile +++ new_tests/Makefile @@ -1,11 +1,12 @@ include ../extra.mk SUBDIRS = ${TESTPLUGIN} PROG_NOINST = tests${PROG_SUFFIX} -SRCS = OFColorTests.m \ +SRCS = OFCharacterSetTests.m \ + OFColorTests.m \ OFIRITests.m \ OFNumberTests.m \ OFPBKDF2Tests.m \ OFPropertyListTests.m \ OFScryptTests.m \ ADDED new_tests/OFCharacterSetTests.m Index: new_tests/OFCharacterSetTests.m ================================================================== --- new_tests/OFCharacterSetTests.m +++ new_tests/OFCharacterSetTests.m @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "ObjFW.h" +#import "ObjFWTest.h" + +#import "OFCharacterSet.h" +#import "OFBitSetCharacterSet.h" +#import "OFRangeCharacterSet.h" + +@interface OFCharacterSetTests: OTTestCase +@end + +@interface CustomCharacterSet: OFCharacterSet +@end + +@implementation CustomCharacterSet +- (bool)characterIsMember: (OFUnichar)character +{ + return (character % 2 == 0); +} +@end + +@implementation OFCharacterSetTests +- (void)testCustomCharacterSet +{ + OFCharacterSet *characterSet = + [[[CustomCharacterSet alloc] init] autorelease]; + + for (OFUnichar c = 0; c < 65536; c++) + if (c % 2 == 0) + OTAssertTrue([characterSet characterIsMember: c]); + else + OTAssertFalse([characterSet characterIsMember: c]); +} + +- (void)testBitSetCharacterSet +{ + OFCharacterSet *characterSet = + [OFCharacterSet characterSetWithCharactersInString: @"0123456789"]; + + OTAssertTrue( + [characterSet isKindOfClass: [OFBitSetCharacterSet class]]); + + for (OFUnichar c = 0; c < 65536; c++) + if (c >= '0' && c <= '9') + OTAssertTrue([characterSet characterIsMember: c]); + else if ([characterSet characterIsMember: c]) + OTAssertFalse([characterSet characterIsMember: c]); +} + +- (void)testRangeCharacterSet +{ + OFCharacterSet *characterSet = + [OFCharacterSet characterSetWithRange: OFMakeRange('0', 10)]; + + OTAssertTrue( + [characterSet isKindOfClass: [OFRangeCharacterSet class]]); + + for (OFUnichar c = 0; c < 65536; c++) + if (c >= '0' && c <= '9') + OTAssertTrue([characterSet characterIsMember: c]); + else + OTAssertFalse([characterSet characterIsMember: c]); +} + +- (void)testInvertedCharacterSet +{ + OFCharacterSet *characterSet = [[OFCharacterSet + characterSetWithRange: OFMakeRange('0', 10)] invertedSet]; + + for (OFUnichar c = 0; c < 65536; c++) + if (c >= '0' && c <= '9') + OTAssertFalse([characterSet characterIsMember: c]); + else + OTAssertTrue([characterSet characterIsMember: c]); +} + +- (void)testInvertingInvertedSetReturnsOriginal +{ + OFCharacterSet *characterSet = + [OFCharacterSet characterSetWithRange: OFMakeRange('0', 10)]; + + OTAssertEqual(characterSet, characterSet.invertedSet.invertedSet); +} +@end Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -17,11 +17,10 @@ PROG_NOINST = tests${PROG_SUFFIX} STATIC_LIB_NOINST = ${TESTS_STATIC_LIB} SRCS = ForwardingTests.m \ OFArrayTests.m \ ${OF_BLOCK_TESTS_M} \ - OFCharacterSetTests.m \ OFDataTests.m \ OFDateTests.m \ OFDictionaryTests.m \ OFHMACTests.m \ OFINIFileTests.m \ DELETED tests/OFCharacterSetTests.m Index: tests/OFCharacterSetTests.m ================================================================== --- tests/OFCharacterSetTests.m +++ tests/OFCharacterSetTests.m @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#import "TestsAppDelegate.h" - -#import "OFCharacterSet.h" -#import "OFBitSetCharacterSet.h" -#import "OFRangeCharacterSet.h" - -static OFString *module; - -@interface SimpleCharacterSet: OFCharacterSet -@end - -@implementation SimpleCharacterSet -- (bool)characterIsMember: (OFUnichar)character -{ - return (character % 2 == 0); -} -@end - -@implementation TestsAppDelegate (OFCharacterSetTests) -- (void)characterSetTests -{ - void *pool = objc_autoreleasePoolPush(); - OFCharacterSet *characterSet, *invertedCharacterSet; - bool ok; - - module = @"OFCharacterSet"; - - characterSet = [[[SimpleCharacterSet alloc] init] autorelease]; - - ok = true; - for (OFUnichar c = 0; c < 65536; c++) { - if (c % 2 == 0) { - if (![characterSet characterIsMember: c]) - ok = false; - } else if ([characterSet characterIsMember: c]) - ok = false; - } - TEST(@"-[characterIsMember:]", ok); - - module = @"OFBitSetCharacterSet"; - - TEST(@"+[characterSetWithCharactersInString:]", - (characterSet = [OFCharacterSet characterSetWithCharactersInString: - @"0123456789"]) && - [characterSet isKindOfClass: [OFBitSetCharacterSet class]]) - - ok = true; - for (OFUnichar c = 0; c < 65536; c++) { - if (c >= '0' && c <= '9') { - if (![characterSet characterIsMember: c]) - ok = false; - } else if ([characterSet characterIsMember: c]) - ok = false; - } - TEST(@"-[characterIsMember:]", ok); - - module = @"OFRangeCharacterSet"; - - TEST(@"+[characterSetWithRange:]", - (characterSet = [OFCharacterSet - characterSetWithRange: OFMakeRange('0', 10)]) && - [characterSet isKindOfClass: [OFRangeCharacterSet class]]) - - ok = true; - for (OFUnichar c = 0; c < 65536; c++) { - if (c >= '0' && c <= '9') { - if (![characterSet characterIsMember: c]) - ok = false; - } else if ([characterSet characterIsMember: c]) - ok = false; - } - TEST(@"-[characterIsMember:]", ok); - - ok = true; - invertedCharacterSet = characterSet.invertedSet; - for (OFUnichar c = 0; c < 65536; c++) { - if (c >= '0' && c <= '9') { - if ([invertedCharacterSet characterIsMember: c]) - ok = false; - } else if (![invertedCharacterSet characterIsMember: c]) - ok = false; - } - TEST(@"-[invertedSet]", ok); - - TEST(@"Inverting -[invertedSet] returns original set", - invertedCharacterSet.invertedSet == characterSet) - - objc_autoreleasePoolPop(pool); -} -@end Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -65,14 +65,10 @@ @interface TestsAppDelegate (OFBlockTests) - (void)blockTests; @end -@interface TestsAppDelegate (OFCharacterSetTests) -- (void)characterSetTests; -@end - @interface TestsAppDelegate (OFDDPSocketTests) - (void)DDPSocketTests; @end @interface TestsAppDelegate (OFDNSResolverTests) Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -380,11 +380,10 @@ [self forwardingTests]; #ifdef OF_HAVE_BLOCKS [self blockTests]; #endif [self stringTests]; - [self characterSetTests]; [self dataTests]; [self arrayTests]; [self dictionaryTests]; [self listTests]; [self setTests];