spec :: Spec
spec = do
    let tests = "toml-test/tests"

    validPaths <- runIO $ globDir1 (compile "*.toml") $ tests </> "valid"
    invalidPaths <- runIO $ globDir1 (compile "*.toml") $ tests </> "invalid"

    forM_ validPaths $ \fp -> do
        toml <- runIO $ T.readFile fp
        json <- runIO $ BS.readFile $ asJSON fp

        it (makeRelative tests fp) $ do
            let Right value = eitherDecode json :: Either String Value
                eparsed = toJSON <$> parseToml fp toml

            case eparsed of
                Right parsed | parsed /= value ->
                    expectationFailure $ unlines
                        [ "Decoding mismatch"
                        , "Input TOML:"
                        , T.unpack toml
                        , "", "Expected JSON:"
                        , C8.unpack $ encodePretty value
                        , "", "Actual JSON:"
                        , C8.unpack $ encodePretty parsed
                        ]

                Left err ->
                    expectationFailure $ unlines
                        [ "Decoding error:"
                        , "Input TOML:"
                        , T.unpack toml
                        , "", "Expected JSON:"
                        , C8.unpack $ encodePretty value
                        , "", "Error:"
                        , err
                        ]

                _ -> return () -- success

    forM_ invalidPaths $ \fp -> do
        toml <- runIO $ T.readFile fp

        it (makeRelative tests fp) $ do
            let eparsed = toJSON <$> parseToml fp toml

            case eparsed of
                Right parsed ->
                    expectationFailure $ unlines
                        [ "Decoding success, expected failure"
                        , "Input TOML:"
                        , T.unpack toml
                        , "", "Unexpected JSON:"
                        , C8.unpack $ encodePretty parsed
                        ]

                Left _ -> return () -- success
spec :: Spec
spec = do
    let tests = "toml-test/tests"

    validPaths <- runIO $ globDir1 (compile "*.toml") $ tests </> "valid"
    invalidPaths <- runIO $ globDir1 (compile "*.toml") $ tests </> "invalid"

    forM_ validPaths $ \fp -> do
        toml <- runIO $ T.readFile fp
        json <- runIO $ BS.readFile $ asJSON fp

        it (makeRelative tests fp) $ do
            let Right value = eitherDecode json :: Either String Value
                eparsed = toJSON <$> parseToml fp toml

            case eparsed of
                Right parsed | parsed /= value ->
                    expectationFailure $ unlines
                        [ "Decoding mismatch"
                        , "Input TOML:"
                        , T.unpack toml
                        , "", "Expected JSON:"
                        , C8.unpack $ encodePretty value
                        , "", "Actual JSON:"
                        , C8.unpack $ encodePretty parsed
                        ]

                Left err ->
                    expectationFailure $ unlines
                        [ "Decoding error:"
                        , "Input TOML:"
                        , T.unpack toml
                        , "", "Expected JSON:"
                        , C8.unpack $ encodePretty value
                        , "", "Error:"
                        , err
                        ]

                _ -> return () -- success

    forM_ invalidPaths $ \fp -> do
        toml <- runIO $ T.readFile fp

        it (makeRelative tests fp) $ do
            let eparsed = toJSON <$> parseToml fp toml

            case eparsed of
                Right parsed ->
                    expectationFailure $ unlines
                        [ "Decoding success, expected failure"
                        , "Input TOML:"
                        , T.unpack toml
                        , "", "Unexpected JSON:"
                        , C8.unpack $ encodePretty parsed
                        ]

                Left _ -> return () -- success
spec = do
    let tests = "toml-test/tests"

    validPaths <- runIO $ globDir1 (compile "*.toml") $ tests </> "valid"
    invalidPaths <- runIO $ globDir1 (compile "*.toml") $ tests </> "invalid"

    forM_ validPaths $ \fp -> do
        toml <- runIO $ T.readFile fp
        json <- runIO $ BS.readFile $ asJSON fp

        it (makeRelative tests fp) $ do
            let Right value = eitherDecode json :: Either String Value
                eparsed = toJSON <$> parseToml fp toml

            case eparsed of
                Right parsed | parsed /= value ->
                    expectationFailure $ unlines
                        [ "Decoding mismatch"
                        , "Input TOML:"
                        , T.unpack toml
                        , "", "Expected JSON:"
                        , C8.unpack $ encodePretty value
                        , "", "Actual JSON:"
                        , C8.unpack $ encodePretty parsed
                        ]

                Left err ->
                    expectationFailure $ unlines
                        [ "Decoding error:"
                        , "Input TOML:"
                        , T.unpack toml
                        , "", "Expected JSON:"
                        , C8.unpack $ encodePretty value
                        , "", "Error:"
                        , err
                        ]

                _ -> return () -- success

    forM_ invalidPaths $ \fp -> do
        toml <- runIO $ T.readFile fp

        it (makeRelative tests fp) $ do
            let eparsed = toJSON <$> parseToml fp toml

            case eparsed of
                Right parsed ->
                    expectationFailure $ unlines
                        [ "Decoding success, expected failure"
                        , "Input TOML:"
                        , T.unpack toml
                        , "", "Unexpected JSON:"
                        , C8.unpack $ encodePretty parsed
                        ]

                Left _ -> return () -- success