summaryrefslogtreecommitdiff
path: root/lambda-calcul/haskell/test/Minilang/Lambda/DeBruijnSpec.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lambda-calcul/haskell/test/Minilang/Lambda/DeBruijnSpec.hs')
-rw-r--r--lambda-calcul/haskell/test/Minilang/Lambda/DeBruijnSpec.hs34
1 files changed, 34 insertions, 0 deletions
diff --git a/lambda-calcul/haskell/test/Minilang/Lambda/DeBruijnSpec.hs b/lambda-calcul/haskell/test/Minilang/Lambda/DeBruijnSpec.hs
index eaff77c..f1802da 100644
--- a/lambda-calcul/haskell/test/Minilang/Lambda/DeBruijnSpec.hs
+++ b/lambda-calcul/haskell/test/Minilang/Lambda/DeBruijnSpec.hs
@@ -81,3 +81,37 @@ spec = do
it "lookup of '+' in builtin env yields FBuiltin" $
eval' benv (FV "+") `shouldBe` FBuiltin "+"
+
+ describe "string literals and builtins" $ do
+ let benv = builtinDeBruijnEnv :: Env Text
+
+ it "FStr self-evaluates" $
+ eval' benv (FStr "hello") `shouldBe` FStr "hello"
+
+ it "(str-concat \"foo\" \"bar\") reduces to FStr \"foobar\"" $
+ eval' benv (App (App (FBuiltin "str-concat") (FStr "foo")) (FStr "bar"))
+ `shouldBe` FStr "foobar"
+
+ it "(str-length \"hello\") reduces to FNum 5" $
+ eval' benv (App (FBuiltin "str-length") (FStr "hello"))
+ `shouldBe` FNum 5
+
+ it "(str-slice 1 3 \"abcde\") reduces to FStr \"bc\"" $
+ eval' benv (App (App (App (FBuiltin "str-slice") (FNum 1)) (FNum 3)) (FStr "abcde"))
+ `shouldBe` FStr "bc"
+
+ it "(str= \"abc\" \"abc\") reduces to Church True" $
+ eval' benv (App (App (FBuiltin "str=") (FStr "abc")) (FStr "abc"))
+ `shouldBe` Lam "f" (Lam "t" (Var "t" 0))
+
+ it "(str= \"abc\" \"xyz\") reduces to Church False" $
+ eval' benv (App (App (FBuiltin "str=") (FStr "abc")) (FStr "xyz"))
+ `shouldBe` Lam "f" (Lam "t" (Var "f" 1))
+
+ it "(str< \"a\" \"b\") reduces to Church True" $
+ eval' benv (App (App (FBuiltin "str<") (FStr "a")) (FStr "b"))
+ `shouldBe` Lam "f" (Lam "t" (Var "t" 0))
+
+ it "(str-concat \"hello\") is partial: stays as App spine" $
+ eval' benv (App (FBuiltin "str-concat") (FStr "hello"))
+ `shouldBe` App (FBuiltin "str-concat") (FStr "hello")