-
Notifications
You must be signed in to change notification settings - Fork 29
Adding the a test for combined tokens #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
3ec11ff
3315407
f8b891e
ae813ad
f5b28b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,9 +28,9 @@ public function testToken() | |
/** | ||
* @dataProvider dataTestStringTokenization | ||
*/ | ||
public function testStringTokenization() | ||
public function testStringTokenization(string $query) | ||
{ | ||
$scanner = new Sql2Scanner('SELECT page.* FROM [nt:unstructured] AS page WHERE name ="Hello world"'); | ||
$scanner = new Sql2Scanner($query); | ||
$expected = [ | ||
'SELECT', | ||
'page', | ||
|
@@ -49,7 +49,7 @@ public function testStringTokenization() | |
$this->expectTokensFromScanner($scanner, $expected); | ||
} | ||
|
||
public function dataTestStringTokenization() | ||
public function dataTestStringTokenization(): array | ||
{ | ||
$multilineQuery = <<<'SQL' | ||
SELECT page.* | ||
|
@@ -124,6 +124,57 @@ public function testSQLEscapedStrings2() | |
$this->expectTokensFromScanner($scanner, $expected); | ||
} | ||
|
||
public function testSquareBrackets() | ||
{ | ||
$sql = 'WHERE ISSAMENODE(file, ["/home node"])'; | ||
|
||
$scanner = new Sql2Scanner($sql); | ||
$expected = [ | ||
'WHERE', | ||
'ISSAMENODE', | ||
'(', | ||
'file', | ||
',', | ||
'["/home node"]', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think the quotes need to completely be removed while scanning (not sure exactly what the old logic did). maybe we need to backport the test to a version with the old scanner and make the test assert the result of that scanner, and then make the new scanner do the same behaviour? when i run the tests with this branch, i get:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we didn't have tests before. I couldn't tell that I changed the logic. Would have probably made more sense to create the tests first. I can check the previous implementation though. But I that shouldn't be too hard to implement. The question still remains then though, what about invalid strings inside those brackets. Should they be validated? |
||
')', | ||
]; | ||
|
||
$this->expectTokensFromScanner($scanner, $expected); | ||
} | ||
|
||
public function testSquareBracketsWithoutQuotes() | ||
{ | ||
$sql = 'WHERE ISSAMENODE(file, [/home node])'; | ||
|
||
$scanner = new Sql2Scanner($sql); | ||
$expected = [ | ||
'WHERE', | ||
'ISSAMENODE', | ||
'(', | ||
'file', | ||
',', | ||
'[/home node]', | ||
')', | ||
]; | ||
|
||
$this->expectTokensFromScanner($scanner, $expected); | ||
} | ||
|
||
public function testTokenizingWithMissingSpaces() | ||
{ | ||
$sql = 'SELECT * AS"all"'; | ||
|
||
$scanner = new Sql2Scanner($sql); | ||
$expected = [ | ||
'SELECT', | ||
'*', | ||
'AS', | ||
'"all"', | ||
]; | ||
|
||
$this->expectTokensFromScanner($scanner, $expected); | ||
} | ||
|
||
public function testThrowingErrorOnUnclosedString() | ||
{ | ||
$this->expectException(InvalidQueryException::class); | ||
|
Uh oh!
There was an error while loading. Please reload this page.