mirror of
https://github.com/anoma/juvix.git
synced 2024-12-15 01:52:11 +03:00
3b3ea45da9
* Renaming MiniJuvix to Juvix * Make Ormolu happy * Make Hlint happy * Remove redundant imports * Fix shell tests and add target ci to our Makefile * Make pre-commit happy
88 lines
2.3 KiB
Haskell
88 lines
2.3 KiB
Haskell
module Arity.Negative (allTests) where
|
|
|
|
import Base
|
|
import Juvix.Pipeline
|
|
import Juvix.Syntax.MicroJuvix.ArityChecker.Error
|
|
|
|
type FailMsg = String
|
|
|
|
data NegTest = NegTest
|
|
{ _name :: String,
|
|
_relDir :: FilePath,
|
|
_file :: FilePath,
|
|
_checkErr :: ArityCheckerError -> Maybe FailMsg
|
|
}
|
|
|
|
testDescr :: NegTest -> TestDescr
|
|
testDescr NegTest {..} =
|
|
let tRoot = root </> _relDir
|
|
in TestDescr
|
|
{ _testName = _name,
|
|
_testRoot = tRoot,
|
|
_testAssertion = Single $ do
|
|
let entryPoint = defaultEntryPoint _file
|
|
result <- runIOEither (upToMicroJuvixArity entryPoint)
|
|
case mapLeft fromJuvixError result of
|
|
Left (Just tyError) -> whenJust (_checkErr tyError) assertFailure
|
|
Left Nothing -> assertFailure "The arity checker did not find an error."
|
|
Right _ -> assertFailure "An error ocurred but it was not in the arity checker."
|
|
}
|
|
|
|
allTests :: TestTree
|
|
allTests =
|
|
testGroup
|
|
"Arity checker negative tests"
|
|
(map (mkTest . testDescr) tests)
|
|
|
|
root :: FilePath
|
|
root = "tests/negative"
|
|
|
|
wrongError :: Maybe FailMsg
|
|
wrongError = Just "Incorrect error"
|
|
|
|
tests :: [NegTest]
|
|
tests =
|
|
[ NegTest
|
|
"Too many arguments in expression"
|
|
"MicroJuvix"
|
|
"TooManyArguments.juvix"
|
|
$ \case
|
|
ErrTooManyArguments {} -> Nothing
|
|
_ -> wrongError,
|
|
NegTest
|
|
"Pattern match a function type"
|
|
"MicroJuvix"
|
|
"FunctionPattern.juvix"
|
|
$ \case
|
|
ErrPatternFunction {} -> Nothing
|
|
_ -> wrongError,
|
|
NegTest
|
|
"Function type (* → *) application"
|
|
"MicroJuvix"
|
|
"FunctionApplied.juvix"
|
|
$ \case
|
|
ErrFunctionApplied {} -> Nothing
|
|
_ -> wrongError,
|
|
NegTest
|
|
"Expected explicit pattern"
|
|
"MicroJuvix"
|
|
"ExpectedExplicitPattern.juvix"
|
|
$ \case
|
|
ErrExpectedExplicitPattern {} -> Nothing
|
|
_ -> wrongError,
|
|
NegTest
|
|
"Expected explicit argument"
|
|
"MicroJuvix"
|
|
"ExpectedExplicitArgument.juvix"
|
|
$ \case
|
|
ErrExpectedExplicitArgument {} -> Nothing
|
|
_ -> wrongError,
|
|
NegTest
|
|
"Function clause with two many patterns in the lhs"
|
|
"MicroJuvix"
|
|
"LhsTooManyPatterns.juvix"
|
|
$ \case
|
|
ErrLhsTooManyPatterns {} -> Nothing
|
|
_ -> wrongError
|
|
]
|