-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84ee58e
commit 197cbde
Showing
17 changed files
with
73 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module Test.Interpreter.InterpreterSpec (spec) where | ||
|
||
import Data.Foldable (traverse_) | ||
import Data.Text (Text) | ||
import Smol.Core | ||
import Smol.Core.Interpreter.Types.Stack | ||
import Smol.Core.Typecheck.FromParsedExpr | ||
import Test.Helpers | ||
import Test.Hspec | ||
|
||
-- | interpret without typechecking etc | ||
doBasicInterpret :: Text -> Expr ResolvedDep () | ||
doBasicInterpret = | ||
fmap edAnnotation | ||
. discardLeft | ||
. interpret mempty | ||
. addEmptyStackFrames | ||
. fromParsedExpr | ||
. unsafeParseExpr | ||
|
||
discardLeft :: (Show e) => Either e a -> a | ||
discardLeft (Left e) = error (show e) | ||
discardLeft (Right a) = a | ||
|
||
spec :: Spec | ||
spec = do | ||
describe "InterpreterSpec" $ do | ||
describe "interpret" $ do | ||
let cases = | ||
[ ("1 + 1", "2"), | ||
("-11 + 1", "-10"), | ||
("(\\a -> a + 1) 41", "42"), | ||
("(\\a -> if a then 1 else 2) False", "2"), | ||
("(\\a -> if a then 1 else 2) True", "1"), | ||
("let a = 41 in a + 1", "42"), | ||
("Just (1 + 1)", "Just 2"), | ||
("case (Just 1) { Just a -> a + 41, Nothing -> 0 }", "42"), | ||
("case Nothing { Just a -> a + 41, Nothing -> 0 }", "0"), | ||
("let stuff = { x: 1, y : 2 }; stuff.x + stuff.y", "3"), | ||
("let id = \\a -> a; (id 1, id 2, id 3)", "(1,2,3)"), | ||
("[1,2 + 3]", "[1,5]"), | ||
("case [1,2,3] { [_, ...rest] -> rest, _ -> [42] }", "[2,3]"), | ||
("let f = \\a -> if a == 10 then a else a + f (a + 1); f 0", "55") | ||
] | ||
traverse_ | ||
( \(input, expect) -> | ||
it (show input <> " = " <> show expect) $ do | ||
doBasicInterpret input | ||
`shouldBe` fromParsedExpr (unsafeParseExpr expect) | ||
) | ||
cases |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,5 +55,3 @@ spec = do | |
result `shouldSatisfy` isRight | ||
) | ||
testInputs | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
module Test.ParserSpec (spec) where | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters