aboutsummaryrefslogtreecommitdiffstats
path: root/UnitTests
diff options
context:
space:
mode:
authorAbhi Beckert <abhi@Twist-of-Lemon-2.local>2015-05-16 08:06:06 +1000
committerAbhi Beckert <abhi@Twist-of-Lemon-2.local>2015-05-16 08:06:06 +1000
commit57a6f6c73bdaa202164645370d37fcbe5d14a092 (patch)
treedd30aa6156064f1d4c0e10ea87059625470fc2f9 /UnitTests
parentb5e972f4504043dfb9c358e272e93fb59ae2127f (diff)
parent0f0c43eb74408b6a65a42e2c6fd46f4142ef8e3f (diff)
downloadsequelpro-57a6f6c73bdaa202164645370d37fcbe5d14a092.tar.gz
sequelpro-57a6f6c73bdaa202164645370d37fcbe5d14a092.tar.bz2
sequelpro-57a6f6c73bdaa202164645370d37fcbe5d14a092.zip
Merge remote-tracking branch 'sequelpro/master'
Diffstat (limited to 'UnitTests')
-rw-r--r--UnitTests/SPDatabaseActionTest.m92
-rw-r--r--UnitTests/SPDatabaseCopyTest.h40
-rw-r--r--UnitTests/SPDatabaseCopyTest.m11
-rw-r--r--UnitTests/SPDatabaseRenameTest.h40
-rw-r--r--UnitTests/SPDatabaseRenameTest.m11
-rw-r--r--UnitTests/SPMenuAdditionsTests.h45
-rw-r--r--UnitTests/SPMenuAdditionsTests.m17
-rw-r--r--UnitTests/SPMutableArrayAdditionsTests.h42
-rw-r--r--UnitTests/SPMutableArrayAdditionsTests.m14
-rw-r--r--UnitTests/SPParserUtilsTest.m87
-rw-r--r--UnitTests/SPStringAdditionsTests.h39
-rw-r--r--UnitTests/SPStringAdditionsTests.m81
-rw-r--r--UnitTests/SPTableCopyTest.h39
-rw-r--r--UnitTests/SPTableCopyTest.m12
-rw-r--r--UnitTests/SPTableFilterParserTest.m57
15 files changed, 375 insertions, 252 deletions
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 <https://github.com/sequelpro/sequelpro>
+
+#import <OCMock/OCMock.h>
+#import <SenTestingKit/SenTestingKit.h>
+
+
+#import "SPDatabaseAction.h"
+#import <SPMySQL/SPMySQL.h>
+
+
+@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
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 <https://github.com/sequelpro/sequelpro>
-
-#define USE_APPLICATION_UNIT_TEST 1
-
-#import <SenTestingKit/SenTestingKit.h>
-
-@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 <https://github.com/sequelpro/sequelpro>
+#define USE_APPLICATION_UNIT_TEST 1
+
#import <OCMock/OCMock.h>
+#import <SenTestingKit/SenTestingKit.h>
#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 <https://github.com/sequelpro/sequelpro>
-
-#define USE_APPLICATION_UNIT_TEST 1
-
-#import <SenTestingKit/SenTestingKit.h>
-
-@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 <https://github.com/sequelpro/sequelpro>
-#import "SPDatabaseRenameTest.h"
+#define USE_APPLICATION_UNIT_TEST 1
+
#import "SPDatabaseRename.h"
#import "SPTableCopy.h"
#import "SPLogger.h"
#import <OCMock/OCMock.h>
+#import <SenTestingKit/SenTestingKit.h>
+
+@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 <https://github.com/sequelpro/sequelpro>
-
-#import <SenTestingKit/SenTestingKit.h>
-
-/**
- * @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 <https://github.com/sequelpro/sequelpro>
-#import "SPMenuAdditionsTests.h"
#import "SPMenuAdditions.h"
+#import <SenTestingKit/SenTestingKit.h>
+
+/**
+ * @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 <https://github.com/sequelpro/sequelpro>
-
-#import <SenTestingKit/SenTestingKit.h>
-
-/**
- * @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 <https://github.com/sequelpro/sequelpro>
-#import "SPMutableArrayAdditionsTests.h"
#import "SPMutableArrayAdditions.h"
+#import <SenTestingKit/SenTestingKit.h>
+
+/**
+ * @class SPMutableArrayAdditionsTest SPMutableArrayAdditionsTest.h
+ *
+ * @author Stuart Connolly http://stuconnolly.com/
+ *
+ * SPMutableArrayAdditions tests class.
+ */
+@interface SPMutableArrayAdditionsTests : SenTestCase
+
+@end
+
@implementation SPMutableArrayAdditionsTests
/**
diff --git a/UnitTests/SPParserUtilsTest.m b/UnitTests/SPParserUtilsTest.m
new file mode 100644
index 00000000..994b166a
--- /dev/null
+++ b/UnitTests/SPParserUtilsTest.m
@@ -0,0 +1,87 @@
+//
+// 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 <https://github.com/sequelpro/sequelpro>
+
+#define USE_APPLICATION_UNIT_TEST 1
+
+#import <Cocoa/Cocoa.h>
+#import <SenTestingKit/SenTestingKit.h>
+
+#include "SPParserUtils.h"
+
+@interface SPParserUtilsTest : SenTestCase
+
+- (void)testUtf8strlen;
+
+@end
+
+@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");
+
+ // 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), (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];
+ 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.");
+
+ //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
diff --git a/UnitTests/SPStringAdditionsTests.h b/UnitTests/SPStringAdditionsTests.h
deleted file mode 100644
index d6854dbe..00000000
--- a/UnitTests/SPStringAdditionsTests.h
+++ /dev/null
@@ -1,39 +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 <https://github.com/sequelpro/sequelpro>
-
-#import <SenTestingKit/SenTestingKit.h>
-
-@interface SPStringAdditionsTests : SenTestCase
-
-- (void)testStringByRemovingCharactersInSet;
-- (void)testStringWithNewUUID;
-- (void)testCreateViewSyntaxPrettifier;
-
-@end
diff --git a/UnitTests/SPStringAdditionsTests.m b/UnitTests/SPStringAdditionsTests.m
index af22df77..b0528ec7 100644
--- a/UnitTests/SPStringAdditionsTests.m
+++ b/UnitTests/SPStringAdditionsTests.m
@@ -28,10 +28,20 @@
//
// More info at <https://github.com/sequelpro/sequelpro>
-#import "SPStringAdditionsTests.h"
#import "SPStringAdditions.h"
#import "RegexKitLite.h"
+#import <SenTestingKit/SenTestingKit.h>
+
+@interface SPStringAdditionsTests : SenTestCase
+
+- (void)testStringByRemovingCharactersInSet;
+- (void)testStringWithNewUUID;
+- (void)testCreateViewSyntaxPrettifier;
+- (void)testNonConsecutivelySearchStringMatchingRanges;
+
+@end
+
@implementation SPStringAdditionsTests
/**
@@ -86,4 +96,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
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 <https://github.com/sequelpro/sequelpro>
-
-#define USE_APPLICATION_UNIT_TEST 1
-
-#import <SenTestingKit/SenTestingKit.h>
-
-@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 <https://github.com/sequelpro/sequelpro>
#import "SPTableCopy.h"
-#import "SPTableCopyTest.h"
+#import <SPMySQL/SPMySQL.h>
+#import <SenTestingKit/SenTestingKit.h>
#import <OCMock/OCMock.h>
-#import <SPMySQL/SPMySQL.h>
+
+#define USE_APPLICATION_UNIT_TEST 1
+
+@interface SPTableCopyTest : SenTestCase
+
+- (void)testCopyTableFromToWithData;
+
+@end
@implementation SPTableCopyTest
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 <Foundation/Foundation.h>
+#import "SPTableFilterParser.h"
+
+#define USE_APPLICATION_UNIT_TEST 1
+
+#import <Cocoa/Cocoa.h>
+#import <SenTestingKit/SenTestingKit.h>
+
+@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