2023-02-14 18:27:11 +03:00
|
|
|
module Format where
|
|
|
|
|
|
|
|
import Base
|
|
|
|
import Juvix.Compiler.Concrete qualified as Concrete
|
|
|
|
import Juvix.Compiler.Concrete.Print qualified as P
|
|
|
|
import Juvix.Compiler.Concrete.Translation.FromParsed.Analysis.Scoping qualified as Scoper
|
|
|
|
import Juvix.Compiler.Concrete.Translation.FromSource qualified as Parser
|
|
|
|
import Juvix.Compiler.Pipeline.Setup
|
|
|
|
import Juvix.Prelude.Pretty
|
|
|
|
|
|
|
|
data PosTest = PosTest
|
|
|
|
{ _name :: String,
|
|
|
|
_dir :: Path Abs Dir,
|
|
|
|
_file :: Path Abs File
|
|
|
|
}
|
|
|
|
|
|
|
|
makeLenses ''PosTest
|
|
|
|
|
|
|
|
root :: Path Abs Dir
|
|
|
|
root = relToProject $(mkRelDir "tests/positive")
|
|
|
|
|
|
|
|
renderCode :: (HasLoc a, P.PrettyPrint a) => P.Comments -> a -> Text
|
2023-05-31 10:53:08 +03:00
|
|
|
renderCode c = toPlainText . P.ppOutDefault c
|
2023-02-14 18:27:11 +03:00
|
|
|
|
|
|
|
posTest :: String -> Path Rel Dir -> Path Rel File -> PosTest
|
|
|
|
posTest _name rdir rfile =
|
|
|
|
let _dir = root <//> rdir
|
|
|
|
_file = _dir <//> rfile
|
|
|
|
in PosTest {..}
|
|
|
|
|
|
|
|
testDescr :: PosTest -> TestDescr
|
|
|
|
testDescr PosTest {..} =
|
|
|
|
TestDescr
|
|
|
|
{ _testName = _name,
|
|
|
|
_testRoot = _dir,
|
|
|
|
_testAssertion = Steps $ \step -> do
|
2023-04-13 12:27:39 +03:00
|
|
|
entryPoint <- defaultEntryPointCwdIO _file
|
2023-04-27 18:33:08 +03:00
|
|
|
let maybeFile = entryPoint ^? entryPointModulePaths . _head
|
|
|
|
f <- fromMaybeM (assertFailure "Not a module") (return maybeFile)
|
|
|
|
original :: Text <- readFile (toFilePath f)
|
2023-02-14 18:27:11 +03:00
|
|
|
step "Parsing"
|
2023-03-30 14:39:27 +03:00
|
|
|
p :: Parser.ParserResult <- snd <$> runIO' entryPoint upToParsing
|
2023-02-14 18:27:11 +03:00
|
|
|
|
|
|
|
step "Scoping"
|
|
|
|
s :: Scoper.ScoperResult <-
|
|
|
|
snd
|
|
|
|
<$> runIO'
|
|
|
|
entryPoint
|
|
|
|
( do
|
2023-10-03 19:09:13 +03:00
|
|
|
void (entrySetup defaultDependenciesConfig)
|
2023-02-14 18:27:11 +03:00
|
|
|
Concrete.fromParsed p
|
|
|
|
)
|
|
|
|
|
|
|
|
let formatted :: Text
|
|
|
|
formatted = renderCode (s ^. Scoper.comments) (s ^. Scoper.mainModule)
|
|
|
|
|
|
|
|
step "Format"
|
|
|
|
assertEqDiffText "check: pretty . scope . parse = id" original formatted
|
|
|
|
}
|
|
|
|
|
|
|
|
allTests :: TestTree
|
|
|
|
allTests =
|
|
|
|
testGroup
|
|
|
|
"Format positive tests"
|
|
|
|
(map (mkTest . testDescr) tests)
|
|
|
|
|
|
|
|
tests :: [PosTest]
|
|
|
|
tests =
|
|
|
|
[ posTest
|
|
|
|
"Format"
|
|
|
|
$(mkRelDir ".")
|
2023-09-07 17:20:14 +03:00
|
|
|
$(mkRelFile "Format.juvix"),
|
|
|
|
posTest
|
|
|
|
"Records"
|
|
|
|
$(mkRelDir ".")
|
2023-02-14 18:27:11 +03:00
|
|
|
$(mkRelFile "Format.juvix")
|
|
|
|
]
|