This repository has been archived by the owner on Jun 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from wemrysi/bug/join-cond-precedence
[qz-3635] Correct precedence when parsing join conditions
- Loading branch information
Showing
3 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Test.Precedence where | ||
|
||
import Prelude | ||
|
||
import Data.Either as E | ||
import Matryoshka (project) | ||
|
||
import SqlSquared as S | ||
|
||
import Test.Unit (suite, test, Test, TestSuite) | ||
import Test.Unit.Assert as Assert | ||
|
||
testParsedSql ∷ ∀ e. (S.Sql → Test e) → String → Test e | ||
testParsedSql f s = | ||
case S.prettyParse S.parse s of | ||
E.Left err → Assert.assert ("\n" <> err) false | ||
E.Right sql → f sql | ||
|
||
limitedJoinQuery ∷ String | ||
limitedJoinQuery = "select * from a inner join b on a.id = b.id limit 10" | ||
|
||
expectLimit ∷ S.Sql → Boolean | ||
expectLimit sql = | ||
case project sql of | ||
(S.Binop { lhs: _, rhs: _, op: S.Limit }) → true | ||
_ → false | ||
|
||
testSuite ∷ ∀ e. TestSuite e | ||
testSuite = do | ||
suite "tests for parser precedence" do | ||
test "limit should have higher precedence than join condition" | ||
$ testParsedSql (Assert.assert "limit parsed incorrectly" <<< expectLimit) limitedJoinQuery |