2022-02-18 15:01:42 +03:00
|
|
|
module Scope.Positive where
|
|
|
|
|
|
|
|
import Base
|
|
|
|
import qualified MiniJuvix.Syntax.Concrete.Scoped.Pretty.Text as M
|
2022-02-18 19:48:21 +03:00
|
|
|
import qualified MiniJuvix.Syntax.Concrete.Scoped.Scoper as M
|
|
|
|
import MiniJuvix.Syntax.Concrete.Scoped.Utils
|
|
|
|
import qualified Data.HashMap.Strict as HashMap
|
2022-03-24 19:04:22 +03:00
|
|
|
import Text.Show.Pretty hiding (Html)
|
|
|
|
import Data.Algorithm.Diff
|
|
|
|
import Data.Algorithm.DiffOutput
|
2022-02-18 15:01:42 +03:00
|
|
|
|
|
|
|
|
|
|
|
data PosTest = PosTest {
|
|
|
|
name :: String,
|
|
|
|
relDir :: FilePath,
|
|
|
|
file :: FilePath
|
|
|
|
}
|
|
|
|
|
|
|
|
root :: FilePath
|
|
|
|
root = "tests/positive"
|
|
|
|
|
|
|
|
testDescr :: PosTest -> TestDescr
|
|
|
|
testDescr PosTest {..} = TestDescr {
|
|
|
|
testName = name,
|
|
|
|
testRoot = root </> relDir,
|
|
|
|
testAssertion = Steps $ \step -> do
|
|
|
|
step "Parse"
|
|
|
|
p <- parseModuleIO file
|
|
|
|
|
|
|
|
step "Scope"
|
|
|
|
s <- scopeModuleIO p
|
2022-02-18 19:48:21 +03:00
|
|
|
let
|
|
|
|
fs :: HashMap FilePath Text
|
|
|
|
fs = HashMap.fromList
|
|
|
|
[ (getModuleFilePath m , M.renderPrettyCodeDefault m)
|
|
|
|
| m <- toList (getAllModules s) ]
|
2022-02-18 15:01:42 +03:00
|
|
|
|
|
|
|
step "Pretty"
|
2022-03-17 14:10:45 +03:00
|
|
|
let scopedPretty = M.renderPrettyCodeDefault s
|
|
|
|
let parsedPretty = M.renderPrettyCodeDefault p
|
2022-02-18 15:01:42 +03:00
|
|
|
|
|
|
|
step "Parse again"
|
2022-03-17 14:10:45 +03:00
|
|
|
p' <- parseTextModuleIO scopedPretty
|
|
|
|
parsedPretty' <- parseTextModuleIO parsedPretty
|
2022-02-18 15:01:42 +03:00
|
|
|
|
|
|
|
step "Scope again"
|
2022-03-25 19:44:32 +03:00
|
|
|
(_ , s') <- fromRightIO' printErrorAnsi $ return (M.scopeCheck1Pure fs "." p')
|
2022-02-21 18:38:39 +03:00
|
|
|
|
|
|
|
step "Checks"
|
2022-03-24 19:04:22 +03:00
|
|
|
assertEqDiff "check: scope . parse . pretty . scope . parse = scope . parse" s s'
|
|
|
|
assertEqDiff "check: parse . pretty . scope . parse = parse" p p'
|
|
|
|
assertEqDiff "check: parse . pretty . parse = parse" p parsedPretty'
|
2022-02-18 15:01:42 +03:00
|
|
|
}
|
|
|
|
|
2022-03-24 19:04:22 +03:00
|
|
|
assertEqDiff :: (Eq a, Show a) => String -> a -> a -> Assertion
|
|
|
|
assertEqDiff msg a b
|
|
|
|
| a == b = return ()
|
|
|
|
| otherwise = do
|
|
|
|
putStrLn (pack $ ppDiff (getGroupedDiff pa pb))
|
|
|
|
putStrLn "End diff"
|
|
|
|
fail msg
|
|
|
|
where
|
|
|
|
pa = lines $ ppShow a
|
|
|
|
pb = lines $ ppShow b
|
|
|
|
|
2022-02-18 15:01:42 +03:00
|
|
|
allTests :: TestTree
|
|
|
|
allTests = testGroup "Scope positive tests"
|
|
|
|
(map (mkTest . testDescr) tests)
|
|
|
|
|
|
|
|
tests :: [PosTest]
|
|
|
|
tests = [
|
2022-02-18 19:48:21 +03:00
|
|
|
PosTest "Inductive"
|
2022-02-19 00:02:57 +03:00
|
|
|
"." "Inductive.mjuvix"
|
|
|
|
, PosTest "Imports and qualified names"
|
|
|
|
"Imports" "A.mjuvix"
|
|
|
|
, PosTest "Data.Bool from the stdlib"
|
|
|
|
"StdlibList" "Data/Bool.mjuvix"
|
|
|
|
, PosTest "Data.Nat from the stdlib"
|
|
|
|
"StdlibList" "Data/Nat.mjuvix"
|
|
|
|
, PosTest "Data.Ord from the stdlib"
|
|
|
|
"StdlibList" "Data/Ord.mjuvix"
|
|
|
|
, PosTest "Data.Product from the stdlib"
|
|
|
|
"StdlibList" "Data/Product.mjuvix"
|
|
|
|
, PosTest "Data.List and friends from the stdlib"
|
2022-02-18 19:57:04 +03:00
|
|
|
"StdlibList" "Data/List.mjuvix"
|
2022-02-23 12:59:56 +03:00
|
|
|
, PosTest "Operators (+)"
|
|
|
|
"." "Operators.mjuvix"
|
2022-03-15 14:37:33 +03:00
|
|
|
, PosTest "Literals"
|
|
|
|
"." "Literals.mjuvix"
|
2022-03-23 15:24:53 +03:00
|
|
|
, PosTest "Hello World backends"
|
|
|
|
"." "HelloWorld.mjuvix"
|
2022-03-23 18:05:52 +03:00
|
|
|
, PosTest "Axiom with backends"
|
|
|
|
"." "Axiom.mjuvix"
|
2022-03-23 18:34:08 +03:00
|
|
|
, PosTest "Foreign block parsing"
|
|
|
|
"." "Foreign.mjuvix"
|
2022-03-24 13:22:03 +03:00
|
|
|
, PosTest "Multiple modules non-ambiguous symbol - same file"
|
|
|
|
"QualifiedSymbol" "M.mjuvix"
|
|
|
|
, PosTest "Multiple modules non-ambiguous symbol"
|
|
|
|
"QualifiedSymbol2" "N.mjuvix"
|
|
|
|
, PosTest "Multiple modules constructor non-ambiguous symbol"
|
|
|
|
"QualifiedConstructor" "M.mjuvix"
|
2022-03-25 12:30:05 +03:00
|
|
|
, PosTest "open overrides open public"
|
|
|
|
"." "ShadowPublicOpen.mjuvix"
|
2022-02-18 15:01:42 +03:00
|
|
|
]
|