diff options
author | stuconnolly <stuart02@gmail.com> | 2012-07-09 09:27:48 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2012-07-09 09:27:48 +0000 |
commit | c1bab7abd666d809aa01c330a66c53e1b6abe6c4 (patch) | |
tree | 075fcdeb4b371e0fd1a21e74fa14ebf705860e2e /Frameworks/QueryKit/Tests/QKSelectQueryTests.m | |
parent | a434272a852db341a6ea4421e388ef924b6a99d7 (diff) | |
download | sequelpro-c1bab7abd666d809aa01c330a66c53e1b6abe6c4.tar.gz sequelpro-c1bab7abd666d809aa01c330a66c53e1b6abe6c4.tar.bz2 sequelpro-c1bab7abd666d809aa01c330a66c53e1b6abe6c4.zip |
Improve QueryKit's handling of quotes by making it on by default. Also, add a bunch more tests.
Diffstat (limited to 'Frameworks/QueryKit/Tests/QKSelectQueryTests.m')
-rw-r--r-- | Frameworks/QueryKit/Tests/QKSelectQueryTests.m | 56 |
1 files changed, 41 insertions, 15 deletions
diff --git a/Frameworks/QueryKit/Tests/QKSelectQueryTests.m b/Frameworks/QueryKit/Tests/QKSelectQueryTests.m index cb2d3599..75cf7ed2 100644 --- a/Frameworks/QueryKit/Tests/QKSelectQueryTests.m +++ b/Frameworks/QueryKit/Tests/QKSelectQueryTests.m @@ -29,20 +29,12 @@ // OTHER DEALINGS IN THE SOFTWARE. #import "QKSelectQueryTests.h" - -static NSString *QKTestTableName = @"test_table"; - -static NSString *QKTestFieldOne = @"test_field1"; -static NSString *QKTestFieldTwo = @"test_field2"; -static NSString *QKTestFieldThree = @"test_field3"; -static NSString *QKTestFieldFour = @"test_field4"; - -static NSUInteger QKTestParameterOne = 10; +#import "QKTestConstants.h" @implementation QKSelectQueryTests #pragma mark - -#pragma mark Setup & tear down +#pragma mark Setup - (void)setUp { @@ -61,21 +53,55 @@ static NSUInteger QKTestParameterOne = 10; - (void)testSelectQueryTypeIsCorrect { - STAssertTrue([[_query query] hasPrefix:@"SELECT"], @"query type"); + STAssertTrue([[_query query] hasPrefix:@"SELECT"], @"select query type"); +} + +- (void)testSelectQueryFieldIsCorrect +{ + NSString *query = [NSString stringWithFormat:@"SELECT `%@`", QKTestFieldOne]; + + STAssertTrue([[_query query] hasPrefix:query], @"select query field"); +} + +- (void)testSelectQueryFieldWithoutQuotesIsCorrect +{ + [_query setUseQuotes:NO]; + + NSString *query = [NSString stringWithFormat:@"SELECT %@", QKTestFieldOne]; + + STAssertTrue([[_query query] hasPrefix:query], @"select query field without quotes"); +} + +- (void)testSelectQueryMultipleFieldsWhenQuotedAreCorrect +{ + NSString *query = [NSString stringWithFormat:@"SELECT `%@`, `%@`, `%@`, `%@`", QKTestFieldOne, QKTestFieldTwo, QKTestFieldThree, QKTestFieldFour]; + + STAssertTrue([[_query query] hasPrefix:query], @"select query multiple fields"); } -- (void)testSelectQueryFieldsAreCorrect +- (void)testSelectQueryMultipleFieldsWithoutQuotesAreCorrect { + [_query setUseQuotes:NO]; + NSString *query = [NSString stringWithFormat:@"SELECT %@, %@, %@, %@", QKTestFieldOne, QKTestFieldTwo, QKTestFieldThree, QKTestFieldFour]; - - STAssertTrue([[_query query] hasPrefix:query], @"query fields"); + + STAssertTrue([[_query query] hasPrefix:query], @"select query multiple fields without quotes"); } - (void)testSelectQueryConstraintsAreCorrect { + NSString *query = [NSString stringWithFormat:@"WHERE `%@` %@ %@", QKTestFieldOne, [QKQueryUtilities operatorRepresentationForType:QKEqualityOperator], [NSNumber numberWithUnsignedInteger:QKTestParameterOne]]; + + STAssertTrue(([[_query query] rangeOfString:query].location != NSNotFound), @"select query constraint"); +} + +- (void)testSelectQueryConstraintsWithoutQuotesAreCorrect +{ + [_query setUseQuotes:NO]; + NSString *query = [NSString stringWithFormat:@"WHERE %@ %@ %@", QKTestFieldOne, [QKQueryUtilities operatorRepresentationForType:QKEqualityOperator], [NSNumber numberWithUnsignedInteger:QKTestParameterOne]]; - STAssertTrue(([[_query query] rangeOfString:query].location != NSNotFound), @"query constraints"); + STAssertTrue(([[_query query] rangeOfString:query].location != NSNotFound), @"select query constraint without quotes"); } @end |