Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #43 from wemrysi/bug/join-cond-precedence
Browse files Browse the repository at this point in the history
[qz-3635] Correct precedence when parsing join conditions
  • Loading branch information
garyb authored Feb 2, 2018
2 parents d3a6cfa + efbf681 commit 2e2cd7a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/SqlSquared/Parser.purs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ stdJoinRelation = do
_ ← keyword "join"
right ← simpleRelation
_ ← keyword "on"
clause ← expr
clause ← definedExpr
pure \left →
Sig.JoinRelation
{ left
Expand Down
2 changes: 2 additions & 0 deletions test/src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Test.Constructors as Constructors
import Test.Argonaut as Argonaut
import Test.Gen as Gen
import Test.Parse as Parse
import Test.Precedence as Precedence

type Effects =
( testOutputTESTOUTPUT
Expand All @@ -30,5 +31,6 @@ main = do
Constructors.testSuite
Argonaut.testSuite
Parse.testSuite
Precedence.testSuite

Gen.test
32 changes: 32 additions & 0 deletions test/src/Precedence.purs
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

0 comments on commit 2e2cd7a

Please sign in to comment.