1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-15 01:52:11 +03:00
juvix/test/Scope/Negative.hs

125 lines
3.3 KiB
Haskell
Raw Normal View History

2022-02-15 16:12:53 +03:00
module Scope.Negative (allTests) where
import Base
2022-02-18 15:01:42 +03:00
import MiniJuvix.Syntax.Concrete.Scoped.Error
2022-02-15 16:12:53 +03:00
import qualified MiniJuvix.Syntax.Concrete.Scoped.Scoper as M
type FailMsg = String
data NegTest = NegTest {
name :: String,
relDir :: FilePath,
2022-02-15 16:12:53 +03:00
file :: FilePath,
checkErr :: ScopeError -> Maybe FailMsg
}
2022-02-18 15:01:42 +03:00
testDescr :: NegTest -> TestDescr
testDescr NegTest {..} = TestDescr {
testName = name,
testRoot = root </> relDir,
testAssertion = Single $ do
p <- parseModuleIO file >>= M.scopeCheck1IO "."
2022-02-18 15:01:42 +03:00
case p of
Left err -> whenJust (checkErr err) assertFailure
Right _ -> assertFailure "The scope checker did not find an error."
}
2022-02-15 16:12:53 +03:00
2022-02-18 15:01:42 +03:00
allTests :: TestTree
allTests = testGroup "Scope negative tests"
(map (mkTest . testDescr) tests)
2022-02-16 22:15:14 +03:00
2022-02-15 16:12:53 +03:00
root :: FilePath
root = "tests/negative"
wrongError :: Maybe FailMsg
2022-02-15 16:12:53 +03:00
wrongError = Just "Incorrect error"
tests :: [NegTest]
tests = [
NegTest "Not in scope" "."
"NotInScope.mjuvix" $ \case
ErrSymNotInScope{} -> Nothing
_ -> wrongError
, NegTest "Multiple declarations" "."
"MultipleDeclarations.mjuvix" $ \case
ErrMultipleDeclarations{} -> Nothing
_ -> wrongError
2022-02-16 22:15:14 +03:00
, NegTest "Import cycle" "ImportCycle"
"A.mjuvix" $ \case
ErrImportCycle {} -> Nothing
_ -> wrongError
, NegTest "Binding group conflict (function clause)"
"BindGroupConflict"
"Clause.mjuvix" $ \case
ErrBindGroup {} -> Nothing
_ -> wrongError
, NegTest "Binding group conflict (lambda clause)"
"BindGroupConflict"
"Lambda.mjuvix" $ \case
ErrBindGroup {} -> Nothing
_ -> wrongError
, NegTest "Infix error (expression)"
"."
"InfixError.mjuvix" $ \case
ErrInfixParser {} -> Nothing
_ -> wrongError
, NegTest "Infix error (pattern)"
"."
"InfixErrorP.mjuvix" $ \case
ErrInfixPattern {} -> Nothing
_ -> wrongError
2022-02-16 22:15:14 +03:00
, NegTest "Duplicate fixity declaration"
"."
"DuplicateFixity.mjuvix" $ \case
ErrDuplicateFixity {} -> Nothing
_ -> wrongError
2022-02-16 22:15:14 +03:00
, NegTest "Multiple export conflict"
"."
"MultipleExportConflict.mjuvix" $ \case
ErrMultipleExport {} -> Nothing
_ -> wrongError
2022-02-17 15:40:19 +03:00
, NegTest "Module not in scope"
"."
"ModuleNotInScope.mjuvix" $ \case
ErrModuleNotInScope {} -> Nothing
_ -> wrongError
, NegTest "Unused operator syntax definition"
"."
"UnusedOperatorDef.mjuvix" $ \case
ErrUnusedOperatorDef {} -> Nothing
_ -> wrongError
, NegTest "Ambiguous symbol"
"."
"AmbiguousSymbol.mjuvix" $ \case
ErrAmbiguousSym {} -> Nothing
_ -> wrongError
, NegTest "Lacks function clause"
"."
"LacksFunctionClause.mjuvix" $ \case
ErrLacksFunctionClause {} -> Nothing
_ -> wrongError
, NegTest "Incorrect top module path"
"."
"WrongModuleName.mjuvix" $ \case
ErrWrongTopModuleName {} -> Nothing
_ -> wrongError
2022-03-24 13:22:03 +03:00
, NegTest "Ambiguous export"
"."
"AmbiguousExport.mjuvix" $ \case
ErrMultipleExport {} -> Nothing
_ -> wrongError
2022-03-24 17:45:49 +03:00
, NegTest "Ambiguous nested modules"
"."
"AmbiguousModule.mjuvix" $ \case
ErrAmbiguousModuleSym {} -> Nothing
_ -> wrongError
2022-03-24 17:59:39 +03:00
, NegTest "Ambiguous nested constructors"
"."
"AmbiguousConstructor.mjuvix" $ \case
ErrAmbiguousSym {} -> Nothing
_ -> wrongError
2022-02-16 22:15:14 +03:00
]