2023-01-12 13:22:32 +03:00
|
|
|
module Compilation.Positive where
|
|
|
|
|
|
|
|
import Base
|
|
|
|
import Compilation.Base
|
|
|
|
|
|
|
|
data PosTest = PosTest
|
|
|
|
{ _name :: String,
|
2023-01-17 11:41:07 +03:00
|
|
|
_dir :: Path Abs Dir,
|
|
|
|
_file :: Path Abs File,
|
2023-03-21 17:34:46 +03:00
|
|
|
_assertionMode :: CompileAssertionMode,
|
2023-01-17 11:41:07 +03:00
|
|
|
_expectedFile :: Path Abs File
|
2023-01-12 13:22:32 +03:00
|
|
|
}
|
|
|
|
|
2023-01-17 11:41:07 +03:00
|
|
|
makeLenses ''PosTest
|
|
|
|
|
2023-01-12 13:22:32 +03:00
|
|
|
fromTest :: PosTest -> TestTree
|
|
|
|
fromTest = mkTest . toTestDescr
|
|
|
|
|
|
|
|
root :: Path Abs Dir
|
|
|
|
root = relToProject $(mkRelDir "tests/Compilation/positive/")
|
|
|
|
|
|
|
|
toTestDescr :: PosTest -> TestDescr
|
|
|
|
toTestDescr PosTest {..} =
|
2023-01-17 11:41:07 +03:00
|
|
|
let tRoot = _dir
|
|
|
|
file' = _file
|
|
|
|
expected' = _expectedFile
|
2023-01-12 13:22:32 +03:00
|
|
|
in TestDescr
|
|
|
|
{ _testName = _name,
|
|
|
|
_testRoot = tRoot,
|
2023-03-21 17:34:46 +03:00
|
|
|
_testAssertion = Steps $ compileAssertion _assertionMode file' expected'
|
2023-01-12 13:22:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
allTests :: TestTree
|
|
|
|
allTests =
|
|
|
|
testGroup
|
|
|
|
"Juvix compilation pipeline positive tests"
|
2023-03-14 18:24:07 +03:00
|
|
|
(map (mkTest . toTestDescr) tests)
|
2023-01-12 13:22:32 +03:00
|
|
|
|
2023-03-21 17:34:46 +03:00
|
|
|
posTest' :: CompileAssertionMode -> String -> Path Rel Dir -> Path Rel File -> Path Rel File -> PosTest
|
|
|
|
posTest' _assertionMode _name rdir rfile routfile =
|
2023-01-17 11:41:07 +03:00
|
|
|
let _dir = root <//> rdir
|
|
|
|
_file = _dir <//> rfile
|
|
|
|
_expectedFile = root <//> routfile
|
|
|
|
in PosTest {..}
|
|
|
|
|
2023-03-21 17:34:46 +03:00
|
|
|
posTestStdin :: String -> Path Rel Dir -> Path Rel File -> Path Rel File -> Text -> PosTest
|
|
|
|
posTestStdin _name rdir rfile routfile _stdinText =
|
|
|
|
let t = posTest _name rdir rfile routfile
|
|
|
|
in t
|
|
|
|
{ _assertionMode = CompileOnly _stdinText
|
|
|
|
}
|
|
|
|
|
2023-03-14 18:24:07 +03:00
|
|
|
posTest :: String -> Path Rel Dir -> Path Rel File -> Path Rel File -> PosTest
|
2023-03-21 17:34:46 +03:00
|
|
|
posTest = posTest' EvalAndCompile
|
2023-03-14 18:24:07 +03:00
|
|
|
|
|
|
|
-- tests which use large integers are only evaluated but not compiled
|
|
|
|
posTestEval :: String -> Path Rel Dir -> Path Rel File -> Path Rel File -> PosTest
|
2023-03-21 17:34:46 +03:00
|
|
|
posTestEval = posTest' EvalOnly
|
2023-03-14 18:24:07 +03:00
|
|
|
|
2023-01-12 13:22:32 +03:00
|
|
|
tests :: [PosTest]
|
|
|
|
tests =
|
2023-01-17 11:41:07 +03:00
|
|
|
[ posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test001: Arithmetic operators"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test001.juvix")
|
|
|
|
$(mkRelFile "out/test001.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test002: Arithmetic operators inside lambdas"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test002.juvix")
|
|
|
|
$(mkRelFile "out/test002.out"),
|
2023-01-19 12:47:12 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test003: Integer arithmetic"
|
2023-01-19 12:47:12 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test003.juvix")
|
|
|
|
$(mkRelFile "out/test003.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test004: IO builtins"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test004.juvix")
|
|
|
|
$(mkRelFile "out/test004.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test005: Higher-order functions"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test005.juvix")
|
|
|
|
$(mkRelFile "out/test005.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test006: If-then-else and lazy boolean operators"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test006.juvix")
|
|
|
|
$(mkRelFile "out/test006.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test007: Pattern matching and lambda-case"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test007.juvix")
|
|
|
|
$(mkRelFile "out/test007.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test008: Recursion"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test008.juvix")
|
|
|
|
$(mkRelFile "out/test008.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test009: Tail recursion"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test009.juvix")
|
|
|
|
$(mkRelFile "out/test009.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test010: Let"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test010.juvix")
|
|
|
|
$(mkRelFile "out/test010.out"),
|
2023-03-14 18:24:07 +03:00
|
|
|
posTestEval
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test011: Tail recursion: Fibonacci numbers in linear time"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test011.juvix")
|
|
|
|
$(mkRelFile "out/test011.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test012: Trees"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test012.juvix")
|
|
|
|
$(mkRelFile "out/test012.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test013: Functions returning functions with variable capture"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test013.juvix")
|
|
|
|
$(mkRelFile "out/test013.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test014: Arithmetic"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test014.juvix")
|
|
|
|
$(mkRelFile "out/test014.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test015: Local functions with free variables"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test015.juvix")
|
|
|
|
$(mkRelFile "out/test015.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test016: Recursion through higher-order functions"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test016.juvix")
|
|
|
|
$(mkRelFile "out/test016.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test017: Tail recursion through higher-order functions"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test017.juvix")
|
|
|
|
$(mkRelFile "out/test017.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test018: Higher-order functions and recursion"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test018.juvix")
|
|
|
|
$(mkRelFile "out/test018.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test019: Self-application"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test019.juvix")
|
|
|
|
$(mkRelFile "out/test019.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test020: Recursive functions: McCarthy's 91 function, subtraction by increments"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test020.juvix")
|
|
|
|
$(mkRelFile "out/test020.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test021: Fast exponentiation"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test021.juvix")
|
|
|
|
$(mkRelFile "out/test021.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test022: Lists"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test022.juvix")
|
|
|
|
$(mkRelFile "out/test022.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test023: Mutual recursion"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test023.juvix")
|
|
|
|
$(mkRelFile "out/test023.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test024: Nested binders with variable capture"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test024.juvix")
|
|
|
|
$(mkRelFile "out/test024.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test025: Euclid's algorithm"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test025.juvix")
|
|
|
|
$(mkRelFile "out/test025.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test026: Functional queues"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test026.juvix")
|
|
|
|
$(mkRelFile "out/test026.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test027: Church numerals"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test027.juvix")
|
|
|
|
$(mkRelFile "out/test027.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test028: Streams without memoization"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test028.juvix")
|
|
|
|
$(mkRelFile "out/test028.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test029: Ackermann function"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test029.juvix")
|
|
|
|
$(mkRelFile "out/test029.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test030: Ackermann function (higher-order definition)"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test030.juvix")
|
|
|
|
$(mkRelFile "out/test030.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test031: Nested lists"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test031.juvix")
|
|
|
|
$(mkRelFile "out/test031.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test032: Merge sort"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test032.juvix")
|
|
|
|
$(mkRelFile "out/test032.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test033: Eta-expansion of builtins and constructors"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test033.juvix")
|
|
|
|
$(mkRelFile "out/test033.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test034: Recursive let"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test034.juvix")
|
|
|
|
$(mkRelFile "out/test034.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test035: Pattern matching"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test035.juvix")
|
|
|
|
$(mkRelFile "out/test035.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test036: Eta-expansion"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test036.juvix")
|
|
|
|
$(mkRelFile "out/test036.out"),
|
2023-01-17 11:41:07 +03:00
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test037: Applications with lets and cases in function position"
|
2023-01-12 13:22:32 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test037.juvix")
|
2023-02-15 13:30:12 +03:00
|
|
|
$(mkRelFile "out/test037.out"),
|
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test038: Simple case expression"
|
2023-02-15 13:30:12 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test038.juvix")
|
2023-03-17 14:05:55 +03:00
|
|
|
$(mkRelFile "out/test038.out"),
|
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test039: Mutually recursive let expression"
|
2023-03-17 14:05:55 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test039.juvix")
|
2023-03-18 02:30:51 +03:00
|
|
|
$(mkRelFile "out/test039.out"),
|
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test040: Pattern matching nullary constructor"
|
2023-03-18 02:30:51 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test040.juvix")
|
2023-03-20 13:00:22 +03:00
|
|
|
$(mkRelFile "out/test040.out"),
|
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test041: Use a builtin inductive in an inductive constructor"
|
2023-03-20 13:00:22 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test041.juvix")
|
2023-03-20 15:01:35 +03:00
|
|
|
$(mkRelFile "out/test041.out"),
|
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test042: Builtin string-to-nat"
|
2023-03-20 15:01:35 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test042.juvix")
|
|
|
|
$(mkRelFile "out/test042.out"),
|
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test043: Builtin trace"
|
2023-03-20 15:01:35 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test043.juvix")
|
2023-03-21 17:34:46 +03:00
|
|
|
$(mkRelFile "out/test043.out"),
|
|
|
|
posTestStdin
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test044: Builtin readline"
|
2023-03-21 17:34:46 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test044.juvix")
|
|
|
|
$(mkRelFile "out/test044.out")
|
2023-03-24 12:29:57 +03:00
|
|
|
"a\n",
|
|
|
|
posTest
|
2023-03-30 20:56:07 +03:00
|
|
|
"Test045: Implicit builtin bool"
|
2023-03-24 12:29:57 +03:00
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test045.juvix")
|
2023-03-30 20:56:07 +03:00
|
|
|
$(mkRelFile "out/test045.out"),
|
|
|
|
posTest
|
|
|
|
"Test046: Polymorphic type arguments"
|
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test046.juvix")
|
2023-03-31 16:57:37 +03:00
|
|
|
$(mkRelFile "out/test046.out"),
|
|
|
|
posTest
|
|
|
|
"Test047: Local Modules"
|
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test047.juvix")
|
2023-04-04 12:29:02 +03:00
|
|
|
$(mkRelFile "out/test047.out"),
|
|
|
|
posTest
|
|
|
|
"Test048: String quoting"
|
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test048.juvix")
|
2023-04-13 10:16:49 +03:00
|
|
|
$(mkRelFile "out/test048.out"),
|
|
|
|
posTest
|
|
|
|
"Test049: Builtin Int"
|
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test049.juvix")
|
|
|
|
$(mkRelFile "out/test049.out"),
|
|
|
|
posTest
|
|
|
|
"Test050: Pattern matching with integers"
|
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test050.juvix")
|
2023-04-26 13:56:44 +03:00
|
|
|
$(mkRelFile "out/test050.out"),
|
|
|
|
posTest
|
|
|
|
"Test051: Local recursive function using IO >>"
|
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test051.juvix")
|
2023-05-15 14:02:09 +03:00
|
|
|
$(mkRelFile "out/test051.out"),
|
|
|
|
posTest
|
|
|
|
"Test052: Mutually recursive types, simple lambda calculus"
|
|
|
|
$(mkRelDir ".")
|
|
|
|
$(mkRelFile "test052.juvix")
|
|
|
|
$(mkRelFile "out/test052.out")
|
2023-01-12 13:22:32 +03:00
|
|
|
]
|