mirror of
https://github.com/anoma/juvix.git
synced 2024-12-15 01:52:11 +03:00
de6fabf625
* add references to the syntax and cleanup code * [make] add .PHONY to Makefile targets * [parser] add parser / pretty for axiom backends * Pairing progress * [scoper] Add support for Axiom backends * [parser] Fix foreign block parsing * [ app ] adds --no-colors flag for the scope command * [ghc] upgrade to ghc 9.2.2 * use GHC2021 * [doc] Remove out-of-date comment * [test] Add ambiguity tests * [scoper] Improve resolution of local symbols * [error] WIP improving ambiguity error messages * [ clean-up ] new lab folder for experimentation * [ app ] ixes the lint warning * [ Termination ] removes Alga dependency * [error] Add message for ambiguous symbol error * [error] Add ambiguous module message * [scoper] Remove ErrGeneric * [test] Add test to suite * [test] show diff when ast's are different * [ lab ] folder organization * [ Makefile ] add targets with --watch option (stack cmds) and remove unused things * [ app ] add --version flag and fixed warnings and formatting * [test] remove fromRightIO to fix ambiguity error * [test] Add test of shadowing public open * [scoper] Add visibility annotation for Name * prepare buildIntoTable * [ Concrete ] add instance of hashable for refs. * add InfoTableBuilder effect * [ scoper ] add InfoTableBuilder effect * [ CHANGELOG ] updated v0.1.1 * [ README ] org version now Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com> Co-authored-by: Paul Cadman <git@paulcadman.dev>
105 lines
3.0 KiB
Haskell
105 lines
3.0 KiB
Haskell
module Scope.Positive where
|
|
|
|
import Base
|
|
import qualified MiniJuvix.Syntax.Concrete.Scoped.Pretty.Text as M
|
|
import qualified MiniJuvix.Syntax.Concrete.Scoped.Scoper as M
|
|
import MiniJuvix.Syntax.Concrete.Scoped.Utils
|
|
import qualified Data.HashMap.Strict as HashMap
|
|
import Text.Show.Pretty hiding (Html)
|
|
import Data.Algorithm.Diff
|
|
import Data.Algorithm.DiffOutput
|
|
|
|
|
|
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
|
|
let
|
|
fs :: HashMap FilePath Text
|
|
fs = HashMap.fromList
|
|
[ (getModuleFilePath m , M.renderPrettyCodeDefault m)
|
|
| m <- toList (getAllModules s) ]
|
|
|
|
step "Pretty"
|
|
let scopedPretty = M.renderPrettyCodeDefault s
|
|
let parsedPretty = M.renderPrettyCodeDefault p
|
|
|
|
step "Parse again"
|
|
p' <- parseTextModuleIO scopedPretty
|
|
parsedPretty' <- parseTextModuleIO parsedPretty
|
|
|
|
step "Scope again"
|
|
(_ , s') <- fromRightIO' printErrorAnsi $ return (M.scopeCheck1Pure fs "." p')
|
|
|
|
step "Checks"
|
|
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'
|
|
}
|
|
|
|
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
|
|
|
|
allTests :: TestTree
|
|
allTests = testGroup "Scope positive tests"
|
|
(map (mkTest . testDescr) tests)
|
|
|
|
tests :: [PosTest]
|
|
tests = [
|
|
PosTest "Inductive"
|
|
"." "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"
|
|
"StdlibList" "Data/List.mjuvix"
|
|
, PosTest "Operators (+)"
|
|
"." "Operators.mjuvix"
|
|
, PosTest "Literals"
|
|
"." "Literals.mjuvix"
|
|
, PosTest "Hello World backends"
|
|
"." "HelloWorld.mjuvix"
|
|
, PosTest "Axiom with backends"
|
|
"." "Axiom.mjuvix"
|
|
, PosTest "Foreign block parsing"
|
|
"." "Foreign.mjuvix"
|
|
, 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"
|
|
, PosTest "open overrides open public"
|
|
"." "ShadowPublicOpen.mjuvix"
|
|
]
|