# Pastebin AJwgukSD {-# LANGUAGE OverloadedStrings #-} import Data.ByteString.Lazy (ByteString) import qualified Data.ByteString.Lazy.Char8 as BC import Lib import ParseProgram import System.FilePath (takeBaseName, takeDirectory, ()) import Test.Tasty (TestTree, defaultMain, testGroup) import Test.Tasty.Golden (findByExtension, goldenVsStringDiff) import Text.Megaparsec import Text.Megaparsec.Error (errorBundlePretty) main :: IO () main = defaultMain =<< sedReplacementTests sedReplacementTests :: IO TestTree sedReplacementTests = do srcs <- findByExtension [".sedx"] "test/examples" pure $ testGroup ".sedx golden tests" (aTest <$> srcs) where aTest sedxFile = goldenVsStringDiff testName -- test name diff sedOutputGolden -- golden file path (runSedxAndReplace sedxFile sedInput) -- action whose result is tested where testName = takeDirectory sedxFile sedOutputGolden = testName "expected" sedInput = testName "input" diff ref new = ["diff", "-u", ref, new] runSedxAndReplace :: String -> String -> IO ByteString runSedxAndReplace sedxFile sedInput = do prog <- either (fail . errorBundlePretty) pure =<< (parse pProgram sedxFile <$> readFile sedxFile) pure . BC.pack $ printMatchAndSub prog