Commit 4c409525 authored by Sebastian Erdweg's avatar Sebastian Erdweg

add test "should hide variables bound in a choice test from the else branch"

parent 0cef4834
......@@ -53,6 +53,11 @@ spec = do
eval (Scope ["y"] (Match "z")) M.empty tenv term2 `shouldBe`
success (termEnv [("x", term1), ("z", term2)],term2)
it "should hide variables bound in a choice's test from the else branch" $
let or1 = Build (T.Cons "Zero" []) `Seq` Match "x" `Seq` T.Fail in
let or2 = Match "x" in
eval (or1 `leftChoice` or2) M.empty (termEnv []) term1 `shouldBe` success (termEnv [("x", term1)], term1)
describe "let" $
it "should support recursion" $ do
let t = convertToList (NumberLiteral <$> [2, 3, 4])
......
......@@ -7,6 +7,7 @@ import GrammarSemantics
import SharedSemantics
import Soundness
import Syntax hiding (Fail)
import Syntax as T
import Control.Arrow
......@@ -265,6 +266,12 @@ spec = do
geval 2 (Scope ["y"] (Match "z")) tenv (numberGrammar 42) `shouldBe`
Lower (success (termEnv [("x", numberGrammar 42), ("z", numberGrammar 42)], numberGrammar 42))
it "should hide variables bound in a choice's test from the else branch" $
let or1 = Build (T.Cons "Zero" []) `Seq` Match "x" `Seq` T.Fail in
let or2 = Match "x" in
geval 0 (or1 `leftChoice` or2) (termEnv []) (Term zeroOne) `shouldBe`
Lower (success (termEnv [("x", Term zeroOne)], Term zeroOne))
describe "Let" $ do
it "should apply a single function call" $ do
let t = grammar "S" (M.fromList [("S", [ Ctor (Constr "Tuple") ["F", "G"] ])
......@@ -371,6 +378,10 @@ spec = do
, ("String", [ Ctor (Constr "String") [] ])
]
zeroOne = grammar "S" $ M.fromList [
("S", [ Ctor (Constr "Zero") [], Ctor (Constr "One") []])
]
swap' = Strategy [] [] (Scope ["x","y"] (
Match (Cons "Tuple" ["x","y"])
`Seq`
......
......@@ -9,6 +9,7 @@ import Prelude hiding (exp)
-- import Soundness
-- import Sort (SortId(..))
import Syntax hiding (Fail)
import Syntax as T
import SortSemantics -- hiding (sortContext)
import SortContext(Context,Sort(..))
import qualified SortContext as Ctx
......@@ -246,6 +247,13 @@ spec = do
seval' 0 (Scope ["y"] (Match "z")) tenv numerical `shouldBe`
success (termEnv [("x", numerical), ("z", numerical)], numerical)
it "should hide variables bound in a choice's test from the else branch" $
let ?ctx = Ctx.fromList [("Zero",[],"Exp"), ("One",[],"Exp")] in
let exp = term "Exp" in
let or1 = Build (T.Cons "Zero" []) `Seq` Match "x" `Seq` T.Fail in
let or2 = Match "x" in
seval 0 (or1 `leftChoice` or2) exp `shouldBe` success (termEnv' [("x", must exp)], exp)
describe "Let" $ do
it "should apply a single function call" $
let ?ctx = Ctx.empty in
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment