mirror of
https://github.com/anoma/juvix.git
synced 2024-12-04 17:07:28 +03:00
75bce8f665
* Closes #2392 Changes checklist ----------------- * [X] Abstract out data types for stored module representation (`ModuleInfo` in `Juvix.Compiler.Store.Language`) * [X] Adapt the parser to operate per-module * [X] Adapt the scoper to operate per-module * [X] Adapt the arity checker to operate per-module * [X] Adapt the type checker to operate per-module * [x] Adapt Core transformations to operate per-module * [X] Adapt the pipeline functions in `Juvix.Compiler.Pipeline` * [X] Add `Juvix.Compiler.Pipeline.Driver` which drives the per-module compilation process * [x] Implement module saving / loading in `Pipeline.Driver` * [x] Detect cyclic module dependencies in `Pipeline.Driver` * [x] Cache visited modules in memory in `Pipeline.Driver` to avoid excessive disk operations and repeated hash re-computations * [x] Recompile a module if one of its dependencies needs recompilation and contains functions that are always inlined. * [x] Fix identifier dependencies for mutual block creation in `Internal.fromConcrete` - Fixed by making textually later definitions depend on earlier ones. - Now instances are used for resolution only after the textual point of their definition. - Similarly, type synonyms will be unfolded only after the textual point of their definition. * [x] Fix CLI * [x] Fix REPL * [x] Fix highlighting * [x] Fix HTML generation * [x] Adapt test suite
73 lines
1.9 KiB
Haskell
73 lines
1.9 KiB
Haskell
module Format where
|
|
|
|
import Base
|
|
import Juvix.Formatter
|
|
|
|
data PosTest = PosTest
|
|
{ _name :: String,
|
|
_dir :: Path Abs Dir,
|
|
_file :: Path Abs File,
|
|
_expectedFile :: Maybe (Path Abs File),
|
|
_force :: Bool
|
|
}
|
|
|
|
makeLenses ''PosTest
|
|
|
|
root :: Path Abs Dir
|
|
root = relToProject $(mkRelDir "tests/positive")
|
|
|
|
posTest :: String -> Path Rel Dir -> Path Rel File -> Maybe (Path Rel File) -> Bool -> PosTest
|
|
posTest _name rdir rfile efile _force =
|
|
let _dir = root <//> rdir
|
|
_file = _dir <//> rfile
|
|
_expectedFile = (_dir <//>) <$> efile
|
|
in PosTest {..}
|
|
|
|
testDescr :: PosTest -> TestDescr
|
|
testDescr PosTest {..} =
|
|
TestDescr
|
|
{ _testName = _name,
|
|
_testRoot = _dir,
|
|
_testAssertion = Steps $ \step -> do
|
|
entryPoint <- testDefaultEntryPointIO _dir _file
|
|
let maybeFile = entryPoint ^. entryPointModulePath
|
|
f <- fromMaybeM (assertFailure "Not a module") (return maybeFile)
|
|
|
|
original :: Text <- readFile (toFilePath f)
|
|
|
|
step "Parsing & scoping"
|
|
PipelineResult {..} <- snd <$> testRunIO entryPoint upToScoping
|
|
|
|
let formatted = formatScoperResult' _force original _pipelineResult
|
|
case _expectedFile of
|
|
Nothing -> do
|
|
step "Format"
|
|
assertEqDiffText "check: pretty . scope . parse = id" original formatted
|
|
Just eFile -> do
|
|
step "Checking against expected output file"
|
|
expFile :: Text <- readFile (toFilePath eFile)
|
|
assertEqDiffText "Compare to expected output" formatted expFile
|
|
}
|
|
|
|
allTests :: TestTree
|
|
allTests =
|
|
testGroup
|
|
"Format positive tests"
|
|
(map (mkTest . testDescr) tests)
|
|
|
|
tests :: [PosTest]
|
|
tests =
|
|
[ posTest
|
|
"Format"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "Format.juvix")
|
|
Nothing
|
|
False,
|
|
posTest
|
|
"TrailingWhitespace"
|
|
$(mkRelDir ".")
|
|
$(mkRelFile "LocalModWithAxiom.juvix")
|
|
(Just $(mkRelFile "LocalModWithAxiom.juvix.formatted"))
|
|
True
|
|
]
|