2023-02-14 18:27:11 +03:00
|
|
|
module Format where
|
|
|
|
|
|
|
|
import Base
|
2023-11-03 14:51:45 +03:00
|
|
|
import Juvix.Formatter
|
2023-02-14 18:27:11 +03:00
|
|
|
|
|
|
|
data PosTest = PosTest
|
|
|
|
{ _name :: String,
|
|
|
|
_dir :: Path Abs Dir,
|
2023-11-03 14:51:45 +03:00
|
|
|
_file :: Path Abs File,
|
|
|
|
_expectedFile :: Maybe (Path Abs File),
|
|
|
|
_force :: Bool
|
2023-02-14 18:27:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
makeLenses ''PosTest
|
|
|
|
|
|
|
|
root :: Path Abs Dir
|
|
|
|
root = relToProject $(mkRelDir "tests/positive")
|
|
|
|
|
2023-11-03 14:51:45 +03:00
|
|
|
posTest :: String -> Path Rel Dir -> Path Rel File -> Maybe (Path Rel File) -> Bool -> PosTest
|
|
|
|
posTest _name rdir rfile efile _force =
|
2023-02-14 18:27:11 +03:00
|
|
|
let _dir = root <//> rdir
|
|
|
|
_file = _dir <//> rfile
|
2023-11-03 14:51:45 +03:00
|
|
|
_expectedFile = (_dir <//>) <$> efile
|
2023-02-14 18:27:11 +03:00
|
|
|
in PosTest {..}
|
|
|
|
|
|
|
|
testDescr :: PosTest -> TestDescr
|
|
|
|
testDescr PosTest {..} =
|
|
|
|
TestDescr
|
|
|
|
{ _testName = _name,
|
|
|
|
_testRoot = _dir,
|
|
|
|
_testAssertion = Steps $ \step -> do
|
2023-12-06 20:24:59 +03:00
|
|
|
entryPoint <- testDefaultEntryPointIO _dir _file
|
2023-12-30 22:15:35 +03:00
|
|
|
let maybeFile = entryPoint ^. entryPointModulePath
|
2023-04-27 18:33:08 +03:00
|
|
|
f <- fromMaybeM (assertFailure "Not a module") (return maybeFile)
|
2023-11-03 14:51:45 +03:00
|
|
|
|
2024-02-19 19:33:58 +03:00
|
|
|
original :: Text <- readFile f
|
2023-11-03 14:51:45 +03:00
|
|
|
|
2023-12-30 22:15:35 +03:00
|
|
|
step "Parsing & scoping"
|
2024-07-01 19:05:24 +03:00
|
|
|
PipelineResult {..} <- snd <$> testRunIO entryPoint upToScopingEntry
|
2023-02-14 18:27:11 +03:00
|
|
|
|
2023-12-30 22:15:35 +03:00
|
|
|
let formatted = formatScoperResult' _force original _pipelineResult
|
2023-11-03 14:51:45 +03:00
|
|
|
case _expectedFile of
|
|
|
|
Nothing -> do
|
|
|
|
step "Format"
|
|
|
|
assertEqDiffText "check: pretty . scope . parse = id" original formatted
|
|
|
|
Just eFile -> do
|
|
|
|
step "Checking against expected output file"
|
2024-02-19 19:33:58 +03:00
|
|
|
expFile :: Text <- readFile eFile
|
2023-11-03 14:51:45 +03:00
|
|
|
assertEqDiffText "Compare to expected output" formatted expFile
|
2023-02-14 18:27:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
allTests :: TestTree
|
|
|
|
allTests =
|
|
|
|
testGroup
|
|
|
|
"Format positive tests"
|
|
|
|
(map (mkTest . testDescr) tests)
|
|
|
|
|
|
|
|
tests :: [PosTest]
|
|
|
|
tests =
|
|
|
|
[ posTest
|
|
|
|
"Format"
|
|
|
|
$(mkRelDir ".")
|
2023-11-03 14:51:45 +03:00
|
|
|
$(mkRelFile "Format.juvix")
|
|
|
|
Nothing
|
|
|
|
False,
|
2023-09-07 17:20:14 +03:00
|
|
|
posTest
|
2023-11-03 14:51:45 +03:00
|
|
|
"TrailingWhitespace"
|
2023-09-07 17:20:14 +03:00
|
|
|
$(mkRelDir ".")
|
2023-11-03 14:51:45 +03:00
|
|
|
$(mkRelFile "LocalModWithAxiom.juvix")
|
|
|
|
(Just $(mkRelFile "LocalModWithAxiom.juvix.formatted"))
|
|
|
|
True
|
2023-02-14 18:27:11 +03:00
|
|
|
]
|