bottom 0.1.0.0 → 0.2.0.0
raw patch · 6 files changed
+26/−18 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Data.Encoding.Bottom: decode' :: ByteString -> Either Text Text
+ Data.Encoding.Bottom: decode' :: ByteString -> Either String Text
Files
- CHANGELOG.md +5/−0
- README.md +1/−1
- bottom.cabal +1/−1
- cmd/bottom/Main.hs +1/−1
- src/Data/Encoding/Bottom.hs +11/−11
- test/Main.hs +7/−4
CHANGELOG.md view
@@ -1,3 +1,8 @@+# 0.2.0.0 (2021-04-02)++Changed the error message type of `decode'` from `Text` to `String` to be more+idiomatic.+ # 0.1.0.0 (2021-03-21) Initial release.
README.md view
@@ -35,7 +35,7 @@ ## Usage as a library -See the generate Haddock documentation in Hackage for module documentation.+See the generated Haddock documentation in Hackage for module documentation. ## Development
bottom.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: bottom-version: 0.1.0.0+version: 0.2.0.0 synopsis: Encoding and decoding for the Bottom spec. description: Encoding and decoding for the [Bottom spec](https://github.com/bottom-software-foundation/spec).
cmd/bottom/Main.hs view
@@ -68,4 +68,4 @@ Bottomify -> putStrLn $ T.unpack $ decodeUtf8 $ unBottom $ encode text Regress -> case decode' $ encodeUtf8 text of Right decoded -> putStrLn $ T.unpack decoded- Left err -> putStrLn $ T.unpack err+ Left err -> putStrLn err
src/Data/Encoding/Bottom.hs view
@@ -20,7 +20,7 @@ import Data.ByteString (ByteString) import qualified Data.ByteString as BS import qualified Data.Foldable as F-import Data.List (unfoldr)+import Data.List (intercalate, unfoldr) import Data.List.NonEmpty (NonEmpty (..)) import qualified Data.List.NonEmpty as NE import Data.Text (Text)@@ -71,13 +71,13 @@ decode :: Bottom -> Text decode (Bottom bs) = case decode' bs of Right r -> r- Left err -> error "Data.Encoding.Bottom.decode: malformed Bottom: " <> err+ Left err -> error $ "Data.Encoding.Bottom.decode: malformed Bottom: " <> err type Parser = Parsec Void ByteString -- | 'decode'' decodes an arbitrary Bottom-encoded 'ByteString' into a 'Text',--- or returns a parse error if the 'ByteString' is malformed.-decode' :: ByteString -> Either Text Text+-- or returns a parse error message if the 'ByteString' is malformed.+decode' :: ByteString -> Either String Text decode' bs = case runParser bottomParser "" bs of Left err -> Left $ renderError err Right r -> Right r@@ -114,23 +114,23 @@ -- Custom error messages, because the default error messages print raw -- ByteStrings and don't render correctly.- renderError :: ParseErrorBundle ByteString Void -> Text+ renderError :: ParseErrorBundle ByteString Void -> String renderError ParseErrorBundle {bundleErrors = (TrivialError offset unexpected expected) :| []} =- unexpectedMessage <> expectedMessage <> " at offset " <> T.pack (show offset)+ unexpectedMessage <> expectedMessage <> " at offset " <> show offset where- renderErrorItem :: ErrorItem (Token ByteString) -> Text- renderErrorItem (Tokens tokens) = "\"" <> decodeUtf8 (BS.pack $ NE.toList tokens) <> "\""- renderErrorItem (Label name) = T.pack $ NE.toList name+ renderErrorItem :: ErrorItem (Token ByteString) -> String+ renderErrorItem (Tokens tokens) = T.unpack $ "\"" <> decodeUtf8 (BS.pack $ NE.toList tokens) <> "\""+ renderErrorItem (Label name) = NE.toList name renderErrorItem EndOfInput = "end of input" unexpectedMessage = case unexpected of Just unx -> "unexpected " <> renderErrorItem unx <> ": " Nothing -> "" - expectedMessage = "expected " <> (if length expecteds >= 2 then "one of " else "") <> T.intercalate ", " expecteds+ expectedMessage = "expected " <> (if length expecteds >= 2 then "one of " else "") <> intercalate ", " expecteds where expecteds = renderErrorItem <$> F.toList expected- renderError err = T.pack $ errorBundlePretty err+ renderError err = errorBundlePretty err -- Encoding functions.
test/Main.hs view
@@ -9,8 +9,10 @@ import Test.Hspec (Expectation, describe, hspec, it, shouldBe) import Test.Hspec.QuickCheck (prop) --- TODO: Why does using this character literally cause a GHC lexing error?--- Related to https://gitlab.haskell.org/ghc/ghc/-/issues/5518 ?+-- Using this character literally causes a GHC lexing error. I've opened a+-- ticket at https://gitlab.haskell.org/ghc/ghc/-/issues/19633.+--+-- TODO: Once this is fixed in GHC, clean up the test cases. twoHundred :: Text twoHundred = T.singleton '\129730' @@ -20,7 +22,7 @@ testDecode :: Text -> Text -> Expectation testDecode input expected = case decode' $ encodeUtf8 input of Right r -> encodeUtf8 r `shouldBe` encodeUtf8 expected- Left err -> error $ T.unpack err+ Left err -> error err testCases :: [(Text, Text)] testCases =@@ -36,7 +38,8 @@ <> "✨✨🥺,,👉👈💖💖✨✨🥺,,,,👉👈💖💖💖✨✨🥺,👉👈" <> twoHundred <> "✨✨🥺,,👉👈💖💖✨✨✨👉👈💖💖✨✨✨✨👉👈"- )+ ),+ ("\0", "❤️👉👈") ] main :: IO ()