aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/SPTableFilterParser.m12
-rw-r--r--UnitTests/SPTableFilterParserTest.m57
-rw-r--r--sequel-pro.xcodeproj/project.pbxproj8
3 files changed, 72 insertions, 5 deletions
diff --git a/Source/SPTableFilterParser.m b/Source/SPTableFilterParser.m
index 96ba8368..f7c9ed62 100644
--- a/Source/SPTableFilterParser.m
+++ b/Source/SPTableFilterParser.m
@@ -50,8 +50,10 @@
{
self = [super init];
if (self) {
- numberOfArguments = numArgs;
- _clause = [filter copy];
+ numberOfArguments = numArgs;
+ _clause = [filter copy];
+ caseSensitive = NO;
+ suppressLeadingTablePlaceholder = NO;
}
return self;
}
@@ -73,7 +75,7 @@
NSString *filterString;
// argument if Filter requires only one argument
- NSMutableString *argument = [[NSMutableString alloc] initWithString:_argument];
+ NSMutableString *argument = [[NSMutableString alloc] initWithString:(_argument? _argument : @"")];
// If the filter field is empty and the selected filter does not require
// only one argument, then no filtering is required - return nil.
@@ -83,8 +85,8 @@
}
// arguments if Filter requires two arguments
- NSMutableString *firstBetweenArgument = [[NSMutableString alloc] initWithString:_firstBetweenArgument];
- NSMutableString *secondBetweenArgument = [[NSMutableString alloc] initWithString:_secondBetweenArgument];
+ NSMutableString *firstBetweenArgument = [[NSMutableString alloc] initWithString:(_firstBetweenArgument? _firstBetweenArgument : @"")];
+ NSMutableString *secondBetweenArgument = [[NSMutableString alloc] initWithString:(_secondBetweenArgument? _secondBetweenArgument : @"")];
// If filter requires two arguments and either of the argument fields are empty
// return nil.
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
diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj
index 9b319e1e..ee3b0018 100644
--- a/sequel-pro.xcodeproj/project.pbxproj
+++ b/sequel-pro.xcodeproj/project.pbxproj
@@ -180,6 +180,9 @@
4DECC4910EC2B436008D359E /* Growl.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = 4DECC3340EC2A170008D359E /* Growl.framework */; };
501B1D181728A3DA0017C92E /* SPCharsetCollationHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 501B1D171728A3DA0017C92E /* SPCharsetCollationHelper.m */; };
503B02CA1AE82C5E0060CAB1 /* SPTableFilterParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 503B02C91AE82C5E0060CAB1 /* SPTableFilterParser.m */; };
+ 503B02CF1AE95C2C0060CAB1 /* SPTableFilterParserTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 503B02CE1AE95C2C0060CAB1 /* SPTableFilterParserTest.m */; };
+ 503B02D11AE95DD40060CAB1 /* SPTableFilterParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 503B02C91AE82C5E0060CAB1 /* SPTableFilterParser.m */; };
+ 503B02D21AE95E010060CAB1 /* SPConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 173284E91088FEDE0062E892 /* SPConstants.m */; };
503CDBB21ACDC204004F8A2F /* Quartz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 503CDBB11ACDC204004F8A2F /* Quartz.framework */; };
506CE9311A311C6C0039F736 /* SPTableContentFilterController.m in Sources */ = {isa = PBXBuildFile; fileRef = 506CE9301A311C6C0039F736 /* SPTableContentFilterController.m */; };
50A9F8B119EAD4B90053E571 /* SPGotoDatabaseController.m in Sources */ = {isa = PBXBuildFile; fileRef = 50A9F8B019EAD4B90053E571 /* SPGotoDatabaseController.m */; };
@@ -890,6 +893,7 @@
501B1D171728A3DA0017C92E /* SPCharsetCollationHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPCharsetCollationHelper.m; sourceTree = "<group>"; };
503B02C81AE82C5E0060CAB1 /* SPTableFilterParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPTableFilterParser.h; sourceTree = "<group>"; };
503B02C91AE82C5E0060CAB1 /* SPTableFilterParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPTableFilterParser.m; sourceTree = "<group>"; };
+ 503B02CE1AE95C2C0060CAB1 /* SPTableFilterParserTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPTableFilterParserTest.m; sourceTree = "<group>"; };
503CDBB11ACDC204004F8A2F /* Quartz.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quartz.framework; path = System/Library/Frameworks/Quartz.framework; sourceTree = SDKROOT; };
506CE92F1A311C6C0039F736 /* SPTableContentFilterController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPTableContentFilterController.h; sourceTree = "<group>"; };
506CE9301A311C6C0039F736 /* SPTableContentFilterController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPTableContentFilterController.m; sourceTree = "<group>"; };
@@ -2363,6 +2367,7 @@
isa = PBXGroup;
children = (
50D3C35B1A771C4C00B5429C /* SPParserUtilsTest.m */,
+ 503B02CE1AE95C2C0060CAB1 /* SPTableFilterParserTest.m */,
);
name = Other;
sourceTree = "<group>";
@@ -3045,6 +3050,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 503B02D21AE95E010060CAB1 /* SPConstants.m in Sources */,
+ 503B02D11AE95DD40060CAB1 /* SPTableFilterParser.m in Sources */,
+ 503B02CF1AE95C2C0060CAB1 /* SPTableFilterParserTest.m in Sources */,
50EA92681AB23EFC008D3C4F /* SPTableCopy.m in Sources */,
50EA926A1AB246B8008D3C4F /* SPDatabaseActionTest.m in Sources */,
50EA92651AB23EC8008D3C4F /* SPDatabaseAction.m in Sources */,