Explicit local bindings for let/where
This commit is contained in:
26
test/Spec.hs
26
test/Spec.hs
@@ -336,7 +336,7 @@ parser = testGroup "Parser Tests"
|
||||
|
||||
, testCase "Parse let expression" $ do
|
||||
let input = "let x = t t in x"
|
||||
expect = SApp (SLambda ["x"] (SVar "x" Nothing)) (SApp TLeaf TLeaf)
|
||||
expect = SLet "x" (SApp TLeaf TLeaf) (SVar "x" Nothing)
|
||||
parseSingle input @?= expect
|
||||
|
||||
, testCase "Evaluate let expression" $ do
|
||||
@@ -344,18 +344,36 @@ parser = testGroup "Parser Tests"
|
||||
|
||||
, testCase "Parse let function binding" $ do
|
||||
let input = "let f x = x in f t"
|
||||
expect = SApp (SLambda ["f"] (SApp (SVar "f" Nothing) TLeaf))
|
||||
(SLambda ["x"] (SVar "x" Nothing))
|
||||
expect = SLet "f" (SLambda ["x"] (SVar "x" Nothing))
|
||||
(SApp (SVar "f" Nothing) TLeaf)
|
||||
parseSingle input @?= expect
|
||||
|
||||
, testCase "Parse where expression" $ do
|
||||
let input = "x where x = t t"
|
||||
expect = SApp (SLambda ["x"] (SVar "x" Nothing)) (SApp TLeaf TLeaf)
|
||||
expect = SLet "x" (SApp TLeaf TLeaf) (SVar "x" Nothing)
|
||||
parseSingle input @?= expect
|
||||
|
||||
, testCase "Evaluate where expression" $ do
|
||||
tricuTestString "x where x = 1" @?= "Fork (Stem Leaf) Leaf"
|
||||
|
||||
, testCase "Parse where binding with arguments (SLet)" $ do
|
||||
let input = "f 3 where f x = x"
|
||||
expect = SLet "f" (SLambda ["x"] (SVar "x" Nothing))
|
||||
(SApp (SVar "f" Nothing) (SInt 3))
|
||||
parseSingle input @?= expect
|
||||
|
||||
, testCase "Evaluate where binding with arguments matches applied lambda" $ do
|
||||
tricuTestString "f (t t) where f x = t x x"
|
||||
@?= tricuTestString "(f : f (t t)) (x : t x x)"
|
||||
|
||||
, testCase "Evaluate nested let bindings" $ do
|
||||
tricuTestString "let a = t t in let b = t in t a b"
|
||||
@?= tricuTestString "t (t t) t"
|
||||
|
||||
, testCase "Inner let binding shadows outer binding" $ do
|
||||
tricuTestString "let x = t in let x = t t in x"
|
||||
@?= tricuTestString "t t"
|
||||
|
||||
, testCase "Parse indented multiline definition body" $ do
|
||||
let input = "x =\n t\n t"
|
||||
expect = SDef "x" [] (SApp TLeaf TLeaf)
|
||||
|
||||
Reference in New Issue
Block a user