on master help sign in
fix critical tutoriald parsing bug involving compound restriction predicates
commit20bf246fb8790615971be6e2c1e4c3e8835540ec authorAgentM <agentm@themactionfaction.com> dateMon 30 Oct 2017, 00:20 (9 years ago) parent86c3b75
2 files changed+21−3
src/bin/TutorialD/Interpreter/Base.hs+1−1 test/TutorialD/Interpreter.hs+20−2
src/bin/TutorialD/Interpreter/Base.hs+1−1
@@ -51,7 +51,7 @@ reserved :: String -> Parser ()
5151reserved word = try (string word *> notFollowedBy opChar *> spaceConsumer)
5252
5353reservedOp :: String -> Parser ()
54−reservedOp op = try (string op *> notFollowedBy opChar *> spaceConsumer)
54+reservedOp op = try (spaceConsumer *> string op *> notFollowedBy opChar *> spaceConsumer)
5555
5656parens :: Parser a -> Parser a
5757parens = between (symbol "(") (symbol ")")
test/TutorialD/Interpreter.hs+20−2
@@ -55,7 +55,8 @@ main = do
5555 testEmptyCommits,
5656 testIntervalAtom,
5757 testListConstructedAtom,
58− testTypeChecker
58+ testTypeChecker,
59+ testRestrictionPredicateExprs
5960 ]
6061 simpleRelTests = [("x:=true", Right relationTrue),
6162 ("x:=false", Right relationFalse),
@@ -76,6 +77,8 @@ main = do
7677 ("x:=true where true or false", Right relationTrue),
7778 ("x:=true where false or false", Right relationFalse),
7879 ("x:=true where true and false", Right relationFalse),
80+ ("x:=true where false and true", Right relationFalse),
81+ ("x:=true where ^t and ^f", Right relationFalse),
7982 ("x:=true where true and true", Right relationTrue),
8083 ("x:=true=true", Right relationTrue),
8184 ("x:=true=false", Right relationFalse),
@@ -486,4 +489,19 @@ testTypeChecker = TestCase $ do
486489 (sessionId, dbconn) <- dateExamplesConnection emptyNotificationCallback
487490 let err1 = "AtomFunctionTypeError \"max\" 1 (RelationAtomType [Attribute \"_\" IntegerAtomType]) IntegerAtomType"
488491 expectTutorialDErr sessionId dbconn (T.isPrefixOf err1) "x:=relation{tuple{a 0}}:{b:=max(@a)}"
489−
492+
493+--exercise expression parser
494+testRestrictionPredicateExprs :: Test
495+testRestrictionPredicateExprs = TestCase $ do
496+ (sessionId, dbconn) <- dateExamplesConnection emptyNotificationCallback
497+ -- or
498+ executeTutorialD sessionId dbconn "x:=s where status=20 or status=10"
499+ eRvOr <- executeRelationalExpr sessionId dbconn (RelationVariable "x" ())
500+ let expectedRelOr = restrict (\tuple ->
501+ pure (elem (atomForAttributeName "status" tuple) [Right (IntegerAtom 10), Right (IntegerAtom 20)])) suppliersRel
502+ assertEqual "status 20 or 10" expectedRelOr eRvOr
503+ -- and
504+ executeTutorialD sessionId dbconn "x:=s where status=20 and status=10"
505+ eRvAnd <- executeRelationalExpr sessionId dbconn (RelationVariable "x" ())
506+ let expectedRelAnd = Right (emptyRelationWithAttrs (attributes suppliersRel))
507+ assertEqual "status 20 and 10" expectedRelAnd eRvAnd