Inline main test function

This commit is contained in:
George Thomas 2025-12-02 14:35:17 +00:00
parent 40f7a8ee9a
commit ef54d8ffa9

View File

@ -23,25 +23,24 @@ main =
defaultMain defaultMain
. localOption (Always :: UseColor) . localOption (Always :: UseColor)
. testGroup "tests" . testGroup "tests"
$ ["examples", "real"] <&> \s -> $ ["examples", "real"] <&> \t ->
testGroup s $ testGroup t $
puzzleTest s [ puzzle1
<$> [ puzzle1 , puzzle2
, puzzle2 ]
] <&> \Puzzle{number, parser, parts} ->
let
puzzleTest :: FilePath -> Puzzle -> TestTree pt = show number
puzzleTest t Puzzle{number, parser, parts} = parseFile fp =
withResource (parseFile $ "inputs/" <> t <> "/" <> pt) mempty \input -> either (fail . ("parse failure: " <>) . errorBundlePretty) pure
testGroup pt $ . runParser (parser <* eof) fp
zip (map show [1 :: Int ..]) parts <&> \(n, pp) -> =<< T.readFile fp
goldenVsString n ("outputs/" <> t <> "/" <> pt <> "/" <> n) $ in
BL.fromStrict . encodeUtf8 . pp <$> input withResource (parseFile $ "inputs/" <> t <> "/" <> pt) mempty \input ->
where testGroup pt $
pt = show number zip (map show [1 :: Int ..]) parts <&> \(n, pp) ->
parseFile fp = goldenVsString n ("outputs/" <> t <> "/" <> pt <> "/" <> n) $
either (fail . ("parse failure: " <>) . errorBundlePretty) pure . runParser (parser <* eof) fp BL.fromStrict . encodeUtf8 . pp <$> input
=<< T.readFile fp
data Puzzle = forall input. Puzzle data Puzzle = forall input. Puzzle
{ number :: Word { number :: Word