on master help sign in
fix critical tutoriald parsing bug involving compound restriction predicates
20bf246AgentM
src/bin/TutorialD/Interpreter/Base.hs+1−1
@@ -51,7 +51,7 @@ reserved :: String -> Parser ()
51reserved word = try (string word *> notFollowedBy opChar *> spaceConsumer)
51reserved word = try (string word *> notFollowedBy opChar *> spaceConsumer)
52
52
53reservedOp :: String -> Parser ()
53reservedOp :: String -> Parser ()
54−reservedOp op = try (string op *> notFollowedBy opChar *> spaceConsumer)
54+reservedOp op = try (spaceConsumer *> string op *> notFollowedBy opChar *> spaceConsumer)
55
55
56parens :: Parser a -> Parser a
56parens :: Parser a -> Parser a
57parens = between (symbol "(") (symbol ")")
57parens = between (symbol "(") (symbol ")")
test/TutorialD/Interpreter.hs+20−2
@@ -55,7 +55,8 @@ main = do
55 testEmptyCommits,
55 testEmptyCommits,
56 testIntervalAtom,
56 testIntervalAtom,
57 testListConstructedAtom,
57 testListConstructedAtom,
58− testTypeChecker
58+ testTypeChecker,
59+ testRestrictionPredicateExprs
59 ]
60 ]
60 simpleRelTests = [("x:=true", Right relationTrue),
61 simpleRelTests = [("x:=true", Right relationTrue),
61 ("x:=false", Right relationFalse),
62 ("x:=false", Right relationFalse),
@@ -76,6 +77,8 @@ main = do
76 ("x:=true where true or false", Right relationTrue),
77 ("x:=true where true or false", Right relationTrue),
77 ("x:=true where false or false", Right relationFalse),
78 ("x:=true where false or false", Right relationFalse),
78 ("x:=true where true and false", Right relationFalse),
79 ("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),
79 ("x:=true where true and true", Right relationTrue),
82 ("x:=true where true and true", Right relationTrue),
80 ("x:=true=true", Right relationTrue),
83 ("x:=true=true", Right relationTrue),
81 ("x:=true=false", Right relationFalse),
84 ("x:=true=false", Right relationFalse),
@@ -486,4 +489,19 @@ testTypeChecker = TestCase $ do
486 (sessionId, dbconn) <- dateExamplesConnection emptyNotificationCallback
489 (sessionId, dbconn) <- dateExamplesConnection emptyNotificationCallback
487 let err1 = "AtomFunctionTypeError \"max\" 1 (RelationAtomType [Attribute \"_\" IntegerAtomType]) IntegerAtomType"
490 let err1 = "AtomFunctionTypeError \"max\" 1 (RelationAtomType [Attribute \"_\" IntegerAtomType]) IntegerAtomType"
488 expectTutorialDErr sessionId dbconn (T.isPrefixOf err1) "x:=relation{tuple{a 0}}:{b:=max(@a)}"
491 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