Refactor to use wildcard

This commit is contained in:
George Thomas 2025-12-02 11:20:00 +00:00
parent bd4d350e76
commit c25b6062c6
2 changed files with 5 additions and 4 deletions

View File

@ -16,6 +16,7 @@ executable aoc
NoFieldSelectors NoFieldSelectors
OverloadedRecordDot OverloadedRecordDot
OverloadedStrings OverloadedStrings
RecordWildCards
ViewPatterns ViewPatterns
ghc-options: ghc-options:
-Wall -Wall

View File

@ -29,18 +29,18 @@ main =
] ]
puzzleTest :: Puzzle a -> TestTree puzzleTest :: Puzzle a -> TestTree
puzzleTest p = puzzleTest Puzzle{..} =
testGroup pt $ testGroup pt $
["examples", "real"] <&> \t -> ["examples", "real"] <&> \t ->
withResource (parseFile $ "inputs/" <> t <> "/" <> pt) mempty \input -> withResource (parseFile $ "inputs/" <> t <> "/" <> pt) mempty \input ->
testGroup t $ testGroup t $
zip (map show [1 :: Int ..]) p.parts <&> \(n, pp) -> zip (map show [1 :: Int ..]) parts <&> \(n, pp) ->
goldenVsString n ("outputs/" <> t <> "/" <> pt <> "/" <> n) $ goldenVsString n ("outputs/" <> t <> "/" <> pt <> "/" <> n) $
BL.fromStrict . encodeUtf8 . pp <$> input BL.fromStrict . encodeUtf8 . pp <$> input
where where
pt = show p.number pt = show number
parseFile fp = parseFile fp =
either (fail . ("parse failure: " <>) . errorBundlePretty) pure . runParser (p.parser <* eof) fp either (fail . ("parse failure: " <>) . errorBundlePretty) pure . runParser (parser <* eof) fp
=<< T.readFile fp =<< T.readFile fp
data Puzzle input = Puzzle data Puzzle input = Puzzle