From f02ffe9ef55e9b43326f05bc1d48c402135b97a6 Mon Sep 17 00:00:00 2001 From: bilel Date: Wed, 8 Mar 2023 14:26:07 +0100 Subject: [PATCH 1/2] [ADD] test compilation conditinal --- .../Parser/Compilation/CompilationTests.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/unit-tests/CompilationLib/Parser/Compilation/CompilationTests.hs diff --git a/tests/unit-tests/CompilationLib/Parser/Compilation/CompilationTests.hs b/tests/unit-tests/CompilationLib/Parser/Compilation/CompilationTests.hs new file mode 100644 index 0000000..96aaf10 --- /dev/null +++ b/tests/unit-tests/CompilationLib/Parser/Compilation/CompilationTests.hs @@ -0,0 +1,16 @@ +module CompilationLib.Compilation.CompilationTest where +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.HUnit (testCase, (@=?)) +import qualified Parsing.Ast as Ast + +testCompileConditional :: TestTree +testCompileConditional = testGroup "compileConditional" + [ testCase "simple conditional" $ + let ast = Ast.Call "if" [ Ast.Boolean True, Ast.Num 1, Ast.Num 2 ] + reg = (["foo"], []) + RetVal instrs blocks reg' = compileConditional ast reg + in do + assertEqual "instructions" [Conditional (Boolean True) (Num 1) (Num 2)] instrs + assertEqual "blocks" [] blocks + assertEqual "registry" reg reg' + ] \ No newline at end of file From c22465d23392c3b3121938b9ace8b26bc15583b6 Mon Sep 17 00:00:00 2001 From: Nydragon <6582485n@proton.me> Date: Wed, 8 Mar 2023 14:35:02 +0100 Subject: [PATCH 2/2] [Fix] tests --- GLaDOS2023.cabal | 1 + tests/unit-tests/CompilationLib.hs | 4 +++- .../Compilation/CompilationTests.hs | 21 +++++++++++++++++++ .../Parser/Compilation/CompilationTests.hs | 16 -------------- 4 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 tests/unit-tests/CompilationLib/Compilation/CompilationTests.hs delete mode 100644 tests/unit-tests/CompilationLib/Parser/Compilation/CompilationTests.hs diff --git a/GLaDOS2023.cabal b/GLaDOS2023.cabal index bbe2afc..ae22633 100644 --- a/GLaDOS2023.cabal +++ b/GLaDOS2023.cabal @@ -123,6 +123,7 @@ test-suite unit-tests CompilationLib.Parser.CptTests, CompilationLib.Parser.AstTests, CompilationLib.Parser.InfixTests, + CompilationLib.Compilation.CompilationTests, ExecLib.Exec.Infer, ExecLib.Exec.Instructions, ExecLib.Exec.Utils, diff --git a/tests/unit-tests/CompilationLib.hs b/tests/unit-tests/CompilationLib.hs index ef3ebfb..8cb275e 100644 --- a/tests/unit-tests/CompilationLib.hs +++ b/tests/unit-tests/CompilationLib.hs @@ -8,6 +8,7 @@ import CompilationLib.Parser.ArgsTests ( argsSuite ) import CompilationLib.Parser.AstTests ( astSuite ) import CompilationLib.Parser.TokenTests ( tokenSuite ) import CompilationLib.Parser.InfixTests ( infixSuite ) +import CompilationLib.Compilation.CompilationTests (testCompileConditional) compilationLibSuite :: TestTree compilationLibSuite = testGroup "Parsing Testsuite" [ @@ -15,5 +16,6 @@ compilationLibSuite = testGroup "Parsing Testsuite" [ tokenSuite, cptSuite, astSuite, - infixSuite + infixSuite, + testCompileConditional ] \ No newline at end of file diff --git a/tests/unit-tests/CompilationLib/Compilation/CompilationTests.hs b/tests/unit-tests/CompilationLib/Compilation/CompilationTests.hs new file mode 100644 index 0000000..d53ca5c --- /dev/null +++ b/tests/unit-tests/CompilationLib/Compilation/CompilationTests.hs @@ -0,0 +1,21 @@ +module CompilationLib.Compilation.CompilationTests where + +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.HUnit (testCase, (@=?), assertEqual) +import qualified Parsing.Ast as Ast +import Compilation.RetVal (RetVal(RetVal)) +import Parsing.Ast (Expr(Num)) +import qualified Exec.InferType as Type +import qualified Instruction as Type +import Compilation.Compile (compileConditional) +import Instruction (Instruction(Push)) + +testCompileConditional :: TestTree +testCompileConditional = testGroup "compileConditional" + [ testCase "simple conditional" $ + let ast = Ast.Call "if" [ Ast.Boolean True, Ast.Num 1, Ast.Num 2 ] + reg = (["foo"], []) + RetVal instrs blocks reg' = compileConditional ast reg + in do + assertEqual "instructions" [Type.Conditional [Push "#t"] [Push "1"] [Push "2"]] instrs + ] \ No newline at end of file diff --git a/tests/unit-tests/CompilationLib/Parser/Compilation/CompilationTests.hs b/tests/unit-tests/CompilationLib/Parser/Compilation/CompilationTests.hs deleted file mode 100644 index 96aaf10..0000000 --- a/tests/unit-tests/CompilationLib/Parser/Compilation/CompilationTests.hs +++ /dev/null @@ -1,16 +0,0 @@ -module CompilationLib.Compilation.CompilationTest where -import Test.Tasty (TestTree, testGroup) -import Test.Tasty.HUnit (testCase, (@=?)) -import qualified Parsing.Ast as Ast - -testCompileConditional :: TestTree -testCompileConditional = testGroup "compileConditional" - [ testCase "simple conditional" $ - let ast = Ast.Call "if" [ Ast.Boolean True, Ast.Num 1, Ast.Num 2 ] - reg = (["foo"], []) - RetVal instrs blocks reg' = compileConditional ast reg - in do - assertEqual "instructions" [Conditional (Boolean True) (Num 1) (Num 2)] instrs - assertEqual "blocks" [] blocks - assertEqual "registry" reg reg' - ] \ No newline at end of file