From a1e0b0e5071f851c865ae567de7a28014a1eafc4 Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Sun, 22 Mar 2026 16:05:42 +0100 Subject: Add strings handling --- .../haskell/test/Minilang/Lambda/DeBruijnSpec.hs | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'lambda-calcul/haskell/test/Minilang/Lambda/DeBruijnSpec.hs') 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") -- cgit v1.3.1