1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-12 14:28:08 +03:00
juvix/test/Typecheck/Positive.hs

182 lines
4.9 KiB
Haskell
Raw Normal View History

module Typecheck.Positive where
import Base
import Juvix.Compiler.Builtins (iniState)
import Juvix.Compiler.Pipeline
import Typecheck.Negative qualified as N
data PosTest = PosTest
2022-04-08 13:46:37 +03:00
{ _name :: String,
2022-12-20 15:05:40 +03:00
_relDir :: Path Rel Dir,
_file :: Path Rel File
}
2022-12-20 15:05:40 +03:00
root :: Path Abs Dir
root = relToProject $(mkRelDir "tests/positive")
testDescr :: PosTest -> TestDescr
testDescr PosTest {..} =
2022-12-20 15:05:40 +03:00
let tRoot = root <//> _relDir
file' = tRoot <//> _file
2022-04-08 13:46:37 +03:00
in TestDescr
{ _testName = _name,
_testRoot = tRoot,
_testAssertion = Single $ do
2022-12-20 15:05:40 +03:00
let entryPoint = defaultEntryPoint tRoot file'
(void . runIO' iniState entryPoint) upToInternalTyped
2022-04-08 13:46:37 +03:00
}
--------------------------------------------------------------------------------
-- Testing --no-positivity flag with all related negative tests
--------------------------------------------------------------------------------
2022-12-20 15:05:40 +03:00
rootNegTests :: Path Abs Dir
rootNegTests = relToProject $(mkRelDir "tests/negative/")
testNoPositivityFlag :: N.NegTest -> TestDescr
testNoPositivityFlag N.NegTest {..} =
2022-12-20 15:05:40 +03:00
let tRoot = rootNegTests <//> _relDir
file' = tRoot <//> _file
in TestDescr
{ _testName = _name,
_testRoot = tRoot,
_testAssertion = Single $ do
let entryPoint =
2022-12-20 15:05:40 +03:00
(defaultEntryPoint tRoot file')
2022-08-19 17:57:07 +03:00
{ _entryPointNoPositivity = True
}
(void . runIO' iniState entryPoint) upToInternal
}
negPositivityTests :: [N.NegTest]
negPositivityTests = N.negPositivityTests
testPositivityKeyword :: [PosTest]
testPositivityKeyword =
[ PosTest
"Mark T0 data type as strictly positive"
2022-12-20 15:05:40 +03:00
$(mkRelDir "Internal/Positivity")
$(mkRelFile "E5.juvix")
]
positivityTestGroup :: TestTree
positivityTestGroup =
testGroup
"Positive tests for the positivity condition"
[ testGroup
"Bypass positivity checking using --non-positivity flag on negative tests"
(map (mkTest . testNoPositivityFlag) negPositivityTests),
testGroup
"Usages of the positive keyword"
(map (mkTest . testDescr) testPositivityKeyword)
]
--------------------------------------------------------------------------------
allTests :: TestTree
allTests =
testGroup
"Typecheck positive tests"
[ testGroup
"General typechecking tests"
(map (mkTest . testDescr) tests),
positivityTestGroup
]
tests :: [PosTest]
tests =
[ PosTest
"Simple"
2022-12-20 15:05:40 +03:00
$(mkRelDir "Internal")
$(mkRelFile "Simple.juvix"),
PosTest
"Literal String matches any type"
2022-12-20 15:05:40 +03:00
$(mkRelDir "Internal")
$(mkRelFile "LiteralString.juvix"),
PosTest
"Box type"
2022-12-20 15:05:40 +03:00
$(mkRelDir "Internal")
$(mkRelFile "Box.juvix"),
PosTest
"Literal Int matches any type"
2022-12-20 15:05:40 +03:00
$(mkRelDir "Internal")
$(mkRelFile "LiteralInt.juvix"),
PosTest
"PolySimpleFungibleToken"
2022-12-20 15:05:40 +03:00
$(mkRelDir "FullExamples")
$(mkRelFile "SimpleFungibleTokenImplicit.juvix"),
PosTest
"GHC backend MonoSimpleFungibleToken"
2022-12-20 15:05:40 +03:00
$(mkRelDir "FullExamples")
$(mkRelFile "MonoSimpleFungibleToken.juvix"),
PosTest
"Axiom"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "Axiom.juvix"),
PosTest
"Inductive"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "Inductive.juvix"),
PosTest
"Operators"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "Operators.juvix"),
PosTest
"Holes in type signature"
2022-12-20 15:05:40 +03:00
$(mkRelDir "Internal")
$(mkRelFile "HoleInSignature.juvix"),
PosTest
"Polymorphism and higher rank functions"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "Polymorphism.juvix"),
PosTest
"Polymorphism and higher rank functions with explicit holes"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "PolymorphismHoles.juvix"),
PosTest
"Implicit arguments"
2022-12-20 15:05:40 +03:00
$(mkRelDir "Internal")
$(mkRelFile "Implicit.juvix"),
PosTest
"Simple type alias"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "TypeAlias.juvix"),
PosTest
"Refine hole in type signature"
2022-12-20 15:05:40 +03:00
$(mkRelDir "272")
$(mkRelFile "M.juvix"),
PosTest
"Pattern match a hole type"
2022-12-20 15:05:40 +03:00
$(mkRelDir "265")
$(mkRelFile "M.juvix"),
PosTest
"Pattern match type synonym"
2022-12-20 15:05:40 +03:00
$(mkRelDir "issue1466")
$(mkRelFile "M.juvix"),
PosTest
"Import a builtin multiple times"
2022-12-20 15:05:40 +03:00
$(mkRelDir "BuiltinsMultiImport")
$(mkRelFile "Input.juvix"),
PosTest
"Basic lambda functions"
2022-12-20 15:05:40 +03:00
$(mkRelDir "Internal")
$(mkRelFile "Lambda.juvix"),
2022-09-26 20:14:17 +03:00
PosTest
"Simple mutual inference"
2022-12-20 15:05:40 +03:00
$(mkRelDir "Internal")
$(mkRelFile "Mutual.juvix"),
PosTest
"open import a builtin multiple times"
2022-12-20 15:05:40 +03:00
$(mkRelDir "BuiltinsMultiOpenImport")
$(mkRelFile "Input.juvix"),
2022-10-27 13:17:03 +03:00
PosTest
"As Patterns"
2022-12-20 15:05:40 +03:00
$(mkRelDir "Internal")
2023-01-09 20:56:28 +03:00
$(mkRelFile "AsPattern.juvix"),
PosTest
"Issue 1693 (Inference and higher order functions)"
$(mkRelDir "issue1693")
$(mkRelFile "M.juvix")
]