From c9c96aff2a9e7201859f9ac6c46c0d9986f22ac3 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 27 Jan 2015 03:34:49 +0100 Subject: Adding a unit test that should fail right now (if I could get Xcode to **actually** run the tests instead of only showing green checkmarks, that is) --- UnitTests/SPParserUtilsTest.m | 72 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 UnitTests/SPParserUtilsTest.m (limited to 'UnitTests') diff --git a/UnitTests/SPParserUtilsTest.m b/UnitTests/SPParserUtilsTest.m new file mode 100644 index 00000000..c760e8b5 --- /dev/null +++ b/UnitTests/SPParserUtilsTest.m @@ -0,0 +1,72 @@ +// +// SPParserUtilsTest.m +// sequel-pro +// +// Created by Max Lohrmann on 27.01.15. +// Copyright (c) 2015 Max Lohrmann. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// +// More info at + +#define USE_APPLICATION_UNIT_TEST 1 + +#import +#import + +#include "SPParserUtils.h" + +@interface SPParserUtilsTest : SenTestCase + +- (void)testUtf8strlen; + +@end + +@implementation SPParserUtilsTest + +- (void)testUtf8strlen { + const char *empty = ""; + NSString *emptyString = [NSString stringWithCString:empty encoding:NSUTF8StringEncoding]; + STAssertEquals(utf8strlen(empty),[emptyString length], @"empty string"); + + const char *singleByteSeq = "Hello World!"; + NSString *singleByteString = [NSString stringWithCString:singleByteSeq encoding:NSUTF8StringEncoding]; + STAssertEquals(utf8strlen(singleByteSeq), [singleByteString length], @"ASCII UTF-8 subset"); + + const char *twoByteSeq = "H\xC3\xA4ll\xC3\xB6 W\xC3\x9Crld\xC3\x9F!"; // Hällö WÜrldß! + NSString *twoByteString = [NSString stringWithCString:twoByteSeq encoding:NSUTF8StringEncoding]; + STAssertEquals(utf8strlen(twoByteSeq), [twoByteString length], @"String containing two-byte utf8 characters"); + + const char *threeByteSeq = "\xE3\x81\x93.\xE3\x82\x93.\xE3\x81\xAB.\xE3\x81\xA1.\xE3\x81\xAF"; // こ.ん.に.ち.は + NSString *threeByteString = [NSString stringWithCString:threeByteSeq encoding:NSUTF8StringEncoding]; + STAssertEquals(utf8strlen(threeByteSeq), [threeByteString length], @"String containing three-byte utf8 characters"); + + const char *fourByteSeq = "\xF0\x9F\x8D\x8F\xF0\x9F\x8D\x8B\xF0\x9F\x8D\x92"; //🍏🍋🍒 + NSString *fourByteString = [NSString stringWithCString:fourByteSeq encoding:NSUTF8StringEncoding]; + STAssertEquals(utf8strlen(fourByteSeq), [fourByteString length], @"String containing only 4-byte utf8 characters (outside BMP)"); + + 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."); +} + +@end -- cgit v1.2.3 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(+) (limited to 'UnitTests') 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 From 2ab2ddf5356117d16d1b0e9f78f9c74b6fdb2dc1 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 28 Jan 2015 22:42:47 +0100 Subject: Fix syntax highlighting for emoji et al. #2044 Voodoo magic provided by @Bibiko ;) --- UnitTests/SPParserUtilsTest.m | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'UnitTests') diff --git a/UnitTests/SPParserUtilsTest.m b/UnitTests/SPParserUtilsTest.m index 5066f8f7..994b166a 100644 --- a/UnitTests/SPParserUtilsTest.m +++ b/UnitTests/SPParserUtilsTest.m @@ -44,6 +44,9 @@ @implementation SPParserUtilsTest - (void)testUtf8strlen { + // NOTE!!: Those test do not verify that the utf8strlen() function works according to spec, + // but whether it produces the same results as NSString for the same input. + const char *empty = ""; NSString *emptyString = [NSString stringWithCString:empty encoding:NSUTF8StringEncoding]; STAssertEquals(utf8strlen(empty),[emptyString length], @"empty string"); @@ -52,8 +55,8 @@ // 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"); + STAssertEquals(strlen(charSeq), (size_t)4, @"assumption about storage for binary C string"); + STAssertEquals([charString length], (NSUInteger)2, @"assumption about NSString internal storage of string"); const char *singleByteSeq = "Hello World!"; NSString *singleByteString = [NSString stringWithCString:singleByteSeq encoding:NSUTF8StringEncoding]; -- cgit v1.2.3 From 96b765ffbcb6c7fda058fbe8028b2e128007134a Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 7 Mar 2015 20:48:55 +0100 Subject: Added an internal algorithm for fuzzy string matching * This works similar to a regex matching "abc" as /a.*b.*c/ (ie. all characters of $needle need to be contained in $haystack in the correct order but not neccesarily consecutive). Additionaly some unicode equivalencies are handled. * Changed a tiny helper function from ObjC to plain C --- UnitTests/SPStringAdditionsTests.h | 1 + UnitTests/SPStringAdditionsTests.m | 69 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) (limited to 'UnitTests') diff --git a/UnitTests/SPStringAdditionsTests.h b/UnitTests/SPStringAdditionsTests.h index d6854dbe..56b5c6f9 100644 --- a/UnitTests/SPStringAdditionsTests.h +++ b/UnitTests/SPStringAdditionsTests.h @@ -35,5 +35,6 @@ - (void)testStringByRemovingCharactersInSet; - (void)testStringWithNewUUID; - (void)testCreateViewSyntaxPrettifier; +- (void)testNonConsecutivelySearchStringMatchingRanges; @end diff --git a/UnitTests/SPStringAdditionsTests.m b/UnitTests/SPStringAdditionsTests.m index af22df77..f455066f 100644 --- a/UnitTests/SPStringAdditionsTests.m +++ b/UnitTests/SPStringAdditionsTests.m @@ -86,4 +86,73 @@ STAssertEqualObjects([actualSyntax description], [expectedSyntax description], @"Actual view syntax '%@' does not equal expected syntax '%@'", actualSyntax, expectedSyntax); } +- (void)testNonConsecutivelySearchStringMatchingRanges +{ + //basic tests + { + NSArray *matches = nil; + STAssertTrue([@"" nonConsecutivelySearchString:@"" matchingRanges:&matches], @"Equality of empty strings"); + STAssertTrue(([matches count] == 1) && NSEqualRanges(NSMakeRange(0, 0), [(NSValue *)[matches objectAtIndex:0] rangeValue]), @"Returned matches in empty string"); + } + + { + NSArray *matches = (void *)0xdeadbeef; + STAssertFalse([@"" nonConsecutivelySearchString:@"R" matchingRanges:&matches], @"Inequality with empty left side"); + STAssertTrue((matches == (void *)0xdeadbeef), @"out variable not touched by mismatch"); + } + + STAssertFalse([@"L" nonConsecutivelySearchString:@"" matchingRanges:NULL], @"Inequality with empty right side"); + + { + NSArray *matches = nil; + STAssertTrue([@"left" nonConsecutivelySearchString:@"le" matchingRanges:&matches], @"Anchored match left"); + STAssertTrue(([matches count] == 1) && NSEqualRanges(NSMakeRange(0, 2), [(NSValue *)[matches objectAtIndex:0] rangeValue]), @"Returned matches in anchored left match"); + } + + { + NSArray *matches = nil; + STAssertTrue([@"right" nonConsecutivelySearchString:@"ht" matchingRanges:&matches], @"Anchored match right"); + STAssertTrue(([matches count] == 1) && NSEqualRanges(NSMakeRange(3, 2), [(NSValue *)[matches objectAtIndex:0] rangeValue]), @"Returned matches in anchroed right match"); + } + + STAssertFalse([@"ht" nonConsecutivelySearchString:@"right" matchingRanges:NULL], @"Left and Right are not commutative"); + + //real tests + { + NSArray *matches = nil; + STAssertTrue([@"... is not secure anymore!" nonConsecutivelySearchString:@"NSA" matchingRanges:&matches], @"Non-consecutive match, ignoring case"); + STAssertTrue(([matches count] == 3) && + (NSEqualRanges(NSMakeRange(7, 1), [(NSValue *)[matches objectAtIndex:0] rangeValue])) && + (NSEqualRanges(NSMakeRange(11, 1), [(NSValue *)[matches objectAtIndex:1] rangeValue])) && + (NSEqualRanges(NSMakeRange(18, 1), [(NSValue *)[matches objectAtIndex:2] rangeValue])), @"Returned matches in non-consecutive string"); + } + + STAssertFalse([@"Deoxyribonucleic Acid" nonConsecutivelySearchString:@"DNS" matchingRanges:NULL], @"Non-consecutive mismatch"); + + { + NSArray *matches = nil; + STAssertTrue([@"Turn left, then right at the corner" nonConsecutivelySearchString:@"left right" matchingRanges:&matches], @"Partly consecutive match"); + STAssertTrue(([matches count] == 3) && + (NSEqualRanges(NSMakeRange(5, 4), [(NSValue *)[matches objectAtIndex:0] rangeValue])) && + (NSEqualRanges(NSMakeRange(10, 1), [(NSValue *)[matches objectAtIndex:1] rangeValue])) && + (NSEqualRanges(NSMakeRange(16, 5), [(NSValue *)[matches objectAtIndex:2] rangeValue])), @"Returned matches in partly-consecutive string"); + } + + //advanced tests + + // LATIN CAPITAL LETTER A == LATIN SMALL LETTER A + // LATIN SMALL LETTER O WITH DIAERESIS == LATIN SMALL LETTER O + // FULLWIDTH LATIN SMALL LETTER b == LATIN SMALL LETTER B + STAssertTrue([@"A:\xC3\xB6:\xEF\xBD\x82" nonConsecutivelySearchString:@"aob" matchingRanges:NULL], @"Fuzzy matching of defined characters"); + + //all bytes on the right are contained on the left, but on a character level "ä" is not contained in "Hütte Ф" + STAssertFalse([@"H\xC3\xBCtte \xD0\xA4" nonConsecutivelySearchString:@"\xC3\xA4" matchingRanges:NULL], @"Mismatch of composed characters with same prefix"); + + // ":😥:𠘄:" vs "😄" (according to wikipedia "𠘄" is the arachic variant of "印") + // TECHNICALLY THIS SHOULD NOT MATCH! + // However Apple doesn't correctly handle characters in the 4-Byte UTF range, so let's use this test to check for changes in Apples behaviour :) + STAssertTrue([@":\xF0\x9F\x98\x84:\xF0\xA0\x98\x84:" nonConsecutivelySearchString:@"\xF0\x9F\x98\x84" matchingRanges:NULL], @"Mismatch of composed characters (4-byte) with same prefix"); + +} + @end -- cgit v1.2.3 From 0dc8d023f39c1bd03f51e62d90b6be7693955e53 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 16 Mar 2015 21:48:15 +0100 Subject: Updated OCMock framework and added a unit test --- UnitTests/SPDatabaseActionTest.m | 92 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 UnitTests/SPDatabaseActionTest.m (limited to 'UnitTests') diff --git a/UnitTests/SPDatabaseActionTest.m b/UnitTests/SPDatabaseActionTest.m new file mode 100644 index 00000000..f7704df5 --- /dev/null +++ b/UnitTests/SPDatabaseActionTest.m @@ -0,0 +1,92 @@ +// +// SPDatabaseActionTest.m +// sequel-pro +// +// Created by Max Lohrmann on 12.03.15. +// Copyright (c) 2015 Max Lohrmann. All rights reserved. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// +// More info at + +#import +#import + + +#import "SPDatabaseAction.h" +#import + + +@interface SPDatabaseActionTest : SenTestCase + +- (void)testCreateDatabase_01_emptyName; +- (void)testCreateDatabase_02_allParams; +- (void)testCreateDatabase_03_nameOnly; + +@end + +@implementation SPDatabaseActionTest + +- (void)testCreateDatabase_01_emptyName +{ + id mockConnection = OCMStrictClassMock([SPMySQLConnection class]); + //OCMStrictClassMock would fail on any call, which is desired here + + SPDatabaseAction *createDb = [[[SPDatabaseAction alloc] init] autorelease]; + [createDb setConnection:mockConnection]; + STAssertFalse([createDb createDatabase:@"" withEncoding:nil collation:nil],@"create database = NO with empty db name"); + + OCMVerifyAll(mockConnection); +} + + +- (void)testCreateDatabase_02_allParams +{ + id mockConnection = OCMStrictClassMock([SPMySQLConnection class]); + + OCMExpect([mockConnection queryString:@"CREATE DATABASE `target_name` DEFAULT CHARACTER SET = `utf8` DEFAULT COLLATE = `utf8_bin_ci`"]); + OCMStub([mockConnection queryErrored]).andReturn(NO); + + SPDatabaseAction *createDb = [[[SPDatabaseAction alloc] init] autorelease]; + [createDb setConnection:mockConnection]; + + STAssertTrue([createDb createDatabase:@"target_name" withEncoding:@"utf8" collation:@"utf8_bin_ci"], @"create database return"); + + OCMVerifyAll(mockConnection); +} + +- (void)testCreateDatabase_03_nameOnly +{ + id mockConnection = OCMStrictClassMock([SPMySQLConnection class]); + + OCMExpect([mockConnection queryString:@"CREATE DATABASE `target_name`"]); + OCMStub([mockConnection queryErrored]).andReturn(NO); + + SPDatabaseAction *createDb = [[[SPDatabaseAction alloc] init] autorelease]; + [createDb setConnection:mockConnection]; + + STAssertTrue([createDb createDatabase:@"target_name" withEncoding:@"" collation:nil], @"create database return"); + + OCMVerifyAll(mockConnection); +} + +@end -- cgit v1.2.3 From 73919a3bc0b80ee45c284045dbeac47846331bff Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 16 Mar 2015 21:57:22 +0100 Subject: Remove .h files for unit tests There is really no point in having them as unit tests don't have an interface someone would want to #import. (and they are disabled right now anyway ;)) --- UnitTests/SPDatabaseCopyTest.h | 40 ---------------------------- UnitTests/SPDatabaseCopyTest.m | 11 +++++++- UnitTests/SPDatabaseRenameTest.h | 40 ---------------------------- UnitTests/SPDatabaseRenameTest.m | 11 +++++++- UnitTests/SPMenuAdditionsTests.h | 45 -------------------------------- UnitTests/SPMenuAdditionsTests.m | 17 +++++++++++- UnitTests/SPMutableArrayAdditionsTests.h | 42 ----------------------------- UnitTests/SPMutableArrayAdditionsTests.m | 14 +++++++++- UnitTests/SPStringAdditionsTests.h | 40 ---------------------------- UnitTests/SPStringAdditionsTests.m | 12 ++++++++- UnitTests/SPTableCopyTest.h | 39 --------------------------- UnitTests/SPTableCopyTest.m | 12 +++++++-- 12 files changed, 70 insertions(+), 253 deletions(-) delete mode 100644 UnitTests/SPDatabaseCopyTest.h delete mode 100644 UnitTests/SPDatabaseRenameTest.h delete mode 100644 UnitTests/SPMenuAdditionsTests.h delete mode 100644 UnitTests/SPMutableArrayAdditionsTests.h delete mode 100644 UnitTests/SPStringAdditionsTests.h delete mode 100644 UnitTests/SPTableCopyTest.h (limited to 'UnitTests') diff --git a/UnitTests/SPDatabaseCopyTest.h b/UnitTests/SPDatabaseCopyTest.h deleted file mode 100644 index 2ed193a3..00000000 --- a/UnitTests/SPDatabaseCopyTest.h +++ /dev/null @@ -1,40 +0,0 @@ -// -// SPDatabaseCopyTest.h -// sequel-pro -// -// Created by David Rekowski. -// Copyright (c) 2010 David Rekowski. All rights reserved. -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// -// More info at - -#define USE_APPLICATION_UNIT_TEST 1 - -#import - -@interface SPDatabaseCopyTest : SenTestCase - -- (void)testCopyDatabase; -- (void)testCreateDatabase; - -@end diff --git a/UnitTests/SPDatabaseCopyTest.m b/UnitTests/SPDatabaseCopyTest.m index 2ab44bea..036a1869 100644 --- a/UnitTests/SPDatabaseCopyTest.m +++ b/UnitTests/SPDatabaseCopyTest.m @@ -28,14 +28,23 @@ // // More info at +#define USE_APPLICATION_UNIT_TEST 1 + #import +#import #import "SPAlertSheets.h" -#import "SPDatabaseCopyTest.h" #import "SPDatabaseCopy.h" #import "SPTableCopy.h" #import "SPLogger.h" +@interface SPDatabaseCopyTest : SenTestCase + +- (void)testCopyDatabase; +- (void)testCreateDatabase; + +@end + @implementation SPDatabaseCopyTest - (SPDatabaseCopy *)getDatabaseCopyFixture diff --git a/UnitTests/SPDatabaseRenameTest.h b/UnitTests/SPDatabaseRenameTest.h deleted file mode 100644 index 138b0e11..00000000 --- a/UnitTests/SPDatabaseRenameTest.h +++ /dev/null @@ -1,40 +0,0 @@ -// -// SPDatabaseRenameTest.h -// sequel-pro -// -// Created by David Rekowski. -// Copyright (c) 2010 David Rekowski. All rights reserved. -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// -// More info at - -#define USE_APPLICATION_UNIT_TEST 1 - -#import - -@interface SPDatabaseRenameTest : SenTestCase - -- (void)testRenameDatabase; -- (void)testCreateDatabase; - -@end diff --git a/UnitTests/SPDatabaseRenameTest.m b/UnitTests/SPDatabaseRenameTest.m index ce826e13..0c29ad0a 100644 --- a/UnitTests/SPDatabaseRenameTest.m +++ b/UnitTests/SPDatabaseRenameTest.m @@ -28,12 +28,21 @@ // // More info at -#import "SPDatabaseRenameTest.h" +#define USE_APPLICATION_UNIT_TEST 1 + #import "SPDatabaseRename.h" #import "SPTableCopy.h" #import "SPLogger.h" #import +#import + +@interface SPDatabaseRenameTest : SenTestCase + +- (void)testRenameDatabase; +- (void)testCreateDatabase; + +@end @implementation SPDatabaseRenameTest diff --git a/UnitTests/SPMenuAdditionsTests.h b/UnitTests/SPMenuAdditionsTests.h deleted file mode 100644 index fbc4d653..00000000 --- a/UnitTests/SPMenuAdditionsTests.h +++ /dev/null @@ -1,45 +0,0 @@ -// -// SPMenuAdditionsTests.h -// sequel-pro -// -// Created by Stuart Connolly (stuconnolly.com) on March 20, 2011. -// Copyright (c) 2011 Stuart Connolly. All rights reserved. -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// -// More info at - -#import - -/** - * @class SPMenuAdditionsTests SPMenuAdditionsTests.h - * - * @author Stuart Connolly http://stuconnolly.com/ - * - * SPMenuAdditionsTests tests class. - */ -@interface SPMenuAdditionsTests : SenTestCase -{ - NSMenu *menu; -} - -@end diff --git a/UnitTests/SPMenuAdditionsTests.m b/UnitTests/SPMenuAdditionsTests.m index e33920e7..83647e6f 100644 --- a/UnitTests/SPMenuAdditionsTests.m +++ b/UnitTests/SPMenuAdditionsTests.m @@ -28,9 +28,24 @@ // // More info at -#import "SPMenuAdditionsTests.h" #import "SPMenuAdditions.h" +#import + +/** + * @class SPMenuAdditionsTests SPMenuAdditionsTests.h + * + * @author Stuart Connolly http://stuconnolly.com/ + * + * SPMenuAdditionsTests tests class. + */ +@interface SPMenuAdditionsTests : SenTestCase +{ + NSMenu *menu; +} + +@end + static NSString *SPTestMenuItemTitle = @"Menu Item"; @implementation SPMenuAdditionsTests diff --git a/UnitTests/SPMutableArrayAdditionsTests.h b/UnitTests/SPMutableArrayAdditionsTests.h deleted file mode 100644 index d96ef285..00000000 --- a/UnitTests/SPMutableArrayAdditionsTests.h +++ /dev/null @@ -1,42 +0,0 @@ -// -// SPMutableArrayAdditionsTests.h -// sequel-pro -// -// Created by Stuart Connolly (stuconnolly.com) on February 2, 2011. -// Copyright (c) 2011 Stuart Connolly. All rights reserved. -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// -// More info at - -#import - -/** - * @class SPMutableArrayAdditionsTest SPMutableArrayAdditionsTest.h - * - * @author Stuart Connolly http://stuconnolly.com/ - * - * SPMutableArrayAdditions tests class. - */ -@interface SPMutableArrayAdditionsTests : SenTestCase - -@end diff --git a/UnitTests/SPMutableArrayAdditionsTests.m b/UnitTests/SPMutableArrayAdditionsTests.m index a2890d8f..e09f00a4 100644 --- a/UnitTests/SPMutableArrayAdditionsTests.m +++ b/UnitTests/SPMutableArrayAdditionsTests.m @@ -28,9 +28,21 @@ // // More info at -#import "SPMutableArrayAdditionsTests.h" #import "SPMutableArrayAdditions.h" +#import + +/** + * @class SPMutableArrayAdditionsTest SPMutableArrayAdditionsTest.h + * + * @author Stuart Connolly http://stuconnolly.com/ + * + * SPMutableArrayAdditions tests class. + */ +@interface SPMutableArrayAdditionsTests : SenTestCase + +@end + @implementation SPMutableArrayAdditionsTests /** diff --git a/UnitTests/SPStringAdditionsTests.h b/UnitTests/SPStringAdditionsTests.h deleted file mode 100644 index 56b5c6f9..00000000 --- a/UnitTests/SPStringAdditionsTests.h +++ /dev/null @@ -1,40 +0,0 @@ -// -// SPStringAdditionsTests.h -// sequel-pro -// -// Created by Jim Knight on May 17, 2009. -// Copyright (c) 2009 Jim Knight. All rights reserved. -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// -// More info at - -#import - -@interface SPStringAdditionsTests : SenTestCase - -- (void)testStringByRemovingCharactersInSet; -- (void)testStringWithNewUUID; -- (void)testCreateViewSyntaxPrettifier; -- (void)testNonConsecutivelySearchStringMatchingRanges; - -@end diff --git a/UnitTests/SPStringAdditionsTests.m b/UnitTests/SPStringAdditionsTests.m index f455066f..b0528ec7 100644 --- a/UnitTests/SPStringAdditionsTests.m +++ b/UnitTests/SPStringAdditionsTests.m @@ -28,10 +28,20 @@ // // More info at -#import "SPStringAdditionsTests.h" #import "SPStringAdditions.h" #import "RegexKitLite.h" +#import + +@interface SPStringAdditionsTests : SenTestCase + +- (void)testStringByRemovingCharactersInSet; +- (void)testStringWithNewUUID; +- (void)testCreateViewSyntaxPrettifier; +- (void)testNonConsecutivelySearchStringMatchingRanges; + +@end + @implementation SPStringAdditionsTests /** diff --git a/UnitTests/SPTableCopyTest.h b/UnitTests/SPTableCopyTest.h deleted file mode 100644 index 29c5eea4..00000000 --- a/UnitTests/SPTableCopyTest.h +++ /dev/null @@ -1,39 +0,0 @@ -// -// SPTableCopyTest.h -// sequel-pro -// -// Created by David Rekowski. -// Copyright (c) 2010 David Rekowski. All rights reserved. -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -// -// More info at - -#define USE_APPLICATION_UNIT_TEST 1 - -#import - -@interface SPTableCopyTest : SenTestCase - -- (void)testCopyTableFromToWithData; - -@end diff --git a/UnitTests/SPTableCopyTest.m b/UnitTests/SPTableCopyTest.m index 099066bc..76a2fe45 100644 --- a/UnitTests/SPTableCopyTest.m +++ b/UnitTests/SPTableCopyTest.m @@ -29,10 +29,18 @@ // More info at #import "SPTableCopy.h" -#import "SPTableCopyTest.h" +#import +#import #import -#import + +#define USE_APPLICATION_UNIT_TEST 1 + +@interface SPTableCopyTest : SenTestCase + +- (void)testCopyTableFromToWithData; + +@end @implementation SPTableCopyTest -- cgit v1.2.3 From d828290bdc4229db1beb7e8e2f9df0b8f0a35a72 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 23 Apr 2015 21:34:15 +0200 Subject: Added some basic unit tests for SPTableFilterParser --- UnitTests/SPTableFilterParserTest.m | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 UnitTests/SPTableFilterParserTest.m (limited to 'UnitTests') diff --git a/UnitTests/SPTableFilterParserTest.m b/UnitTests/SPTableFilterParserTest.m new file mode 100644 index 00000000..d5f46969 --- /dev/null +++ b/UnitTests/SPTableFilterParserTest.m @@ -0,0 +1,57 @@ +// +// SPTableFilterParserTest.m +// sequel-pro +// +// Created by Max Lohrmann on 23.04.15. +// +// + +#import +#import "SPTableFilterParser.h" + +#define USE_APPLICATION_UNIT_TEST 1 + +#import +#import + +@interface SPTableFilterParserTest : SenTestCase + +- (void)testFilterString; + +@end + +@implementation SPTableFilterParserTest + +- (void)testFilterString { + //simple zero argument case + { + SPTableFilterParser *p = [[[SPTableFilterParser alloc] initWithFilterClause:@" constant $BINARY string" numberOfArguments:0] autorelease]; + [p setCurrentField:@"FLD"]; + + // binary matches as "$BINARY ", eating the one additional whitespace + STAssertEqualObjects([p filterString],@"`FLD` constant string", @"Constant replacement"); + } + //simple one argument case with binary + { + SPTableFilterParser *p = [[[SPTableFilterParser alloc] initWithFilterClause:@"= FOO($BINARY ${})" numberOfArguments:1] autorelease]; + [p setCurrentField:@"FLD2"]; + [p setCaseSensitive:YES]; + [p setArgument:@"arg1"]; + + STAssertEqualObjects([p filterString], @"`FLD2` = FOO(BINARY arg1)", @"One Argument, $BINARY variable"); + } + //simple two argument case with explicit current field + { + SPTableFilterParser *p = [[[SPTableFilterParser alloc] initWithFilterClause:@"MIN($CURRENT_FIELD,${}) = ${}" numberOfArguments:2] autorelease]; + [p setCurrentField:@"FLD3"]; + [p setSuppressLeadingTablePlaceholder:YES]; + [p setFirstBetweenArgument:@"LA"]; + [p setSecondBetweenArgument:@"RA"]; + + STAssertEqualObjects([p filterString], @"MIN(`FLD3`,LA) = RA", @"Two Arguments, $CURRENT_FIELD variable"); + } + +} + + +@end -- cgit v1.2.3