@@ -55,7 +55,8 @@ main = do
55 testEmptyCommits,
55 testEmptyCommits,
56 testIntervalAtom,
56 testIntervalAtom,
57 testListConstructedAtom,
57 testListConstructedAtom,
58− testTypeChecker
58+ testTypeChecker,
59+ testRestrictionPredicateExprs
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)}"
493+--exercise expression parser
494+testRestrictionPredicateExprs :: Test
495+testRestrictionPredicateExprs = TestCase $ do
496+ (sessionId, dbconn) <- dateExamplesConnection emptyNotificationCallback
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
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