Created
May 23, 2020 22:12
-
-
Save kritzcreek/c67ea9cb7ac43dfcb527b05bacf66814 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Prelude | |
import Control.Monad | |
import Data.Foldable | |
import Language.PureScript.CST.Types as CST | |
import Language.PureScript.CST.Parser as CST | |
import Language.PureScript.CST.Print as CST | |
import Data.Text (Text) | |
import Data.Text.IO as Text | |
import System.Directory | |
import System.FilePath | |
import System.IO (hSetEncoding, stdout, stderr, utf8) | |
readModule :: FilePath -> IO (Text, Maybe (CST.Module ())) | |
readModule path = do | |
contents <- BS.fromStrict . Text.encodeUtf8 path | |
module_ <- case snd $ CST.parse contents of | |
Left err -> print (show err) *> pure Nothing | |
Right module_ -> pure $ Just module_ | |
pure (contents, module_) | |
roundtripParser :: IO () | |
roundtripParser = do | |
hSetEncoding stdout utf8 | |
hSetEncoding stderr utf8 | |
let dir = "lib/purescript-cst/tests/purs/layout" | |
-- let dir = "tests/purs/passing" | |
files <- listDirectory dir | |
for_ files $ \path -> when (isExtensionOf "purs" path) $ do | |
print path | |
(content, module_) <- readModule (dir </> path) | |
for_ module_ $ \module_ -> if content == CST.printModule module_ then pure () else error path | |
pure () | |
main = roundtripParser |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment