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

[qz-3635] Correct precedence when parsing join conditions #43

Merged
merged 1 commit into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 =
( testOutput ∷ TESTOUTPUT
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