aeson-combinators 0.1.2.1 → 0.1.2.2
raw patch · 4 files changed
+115/−100 lines, 4 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- CHANGELOG.md +5/−2
- aeson-combinators.cabal +7/−5
- lib/Data/Aeson/Combinators/Decode.hs +2/−2
- test/JSONDecodeSpec.hs +101/−91
CHANGELOG.md view
@@ -1,9 +1,12 @@ # Revision history for aeson-combinators -## 0.1.1.0 -- 2023-12-29+## 0.1.2.2 -- 2025-09-21+* Test suite compatibility with text-2.1.2++## 0.1.2.1 -- 2023-12-29 * lower bound for aeson-parser dependecy to fix build of documentation in hackage -## 0.1.1.0 -- 2023-12-28+## 0.1.2.0 -- 2023-12-28 * Aeson 2.2.x compatibility ## 0.1.1.0 -- 2023-09-03
aeson-combinators.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.10 name: aeson-combinators-version: 0.1.2.1+version: 0.1.2.2 synopsis: Aeson combinators for dead simple JSON decoding description: Low overhead value space `Decoder`@@ -20,8 +20,10 @@ homepage: https://github.com/turboMaCk/aeson-combinators tested-with: GHC == 8.10.7 , GHC == 9.0.2- , GHC == 9.2.5+ , GHC == 9.2.8+ , GHC == 9.4.8 , GHC == 9.8.1+ , GHC == 9.10.2 , GHCJS == 8.6.0.1 Flag doctest@@ -60,7 +62,7 @@ type: exitcode-stdio-1.0 main-is: Main.hs hs-source-dirs: benchmarks- build-depends: base+ build-depends: base >= 4 && < 5 , aeson , aeson-combinators , bytestring@@ -76,7 +78,7 @@ main-is: Spec.hs other-modules: JSONDecodeSpec , JSONEncodeSpec- build-depends: base+ build-depends: base >= 4 && < 5 , hspec , aeson-combinators , bytestring@@ -95,7 +97,7 @@ if !flag(doctest) buildable: False else- build-depends: base+ build-depends: base >= 4 && < 5 , doctest source-repository head
lib/Data/Aeson/Combinators/Decode.hs view
@@ -155,7 +155,7 @@ -- >>> :set -XOverloadedStrings -- >>> :set -XDeriveGeneric ----- > import Data.Text+-- > import Data.Text (Text) -- > import Data.ByteString.Lazy (ByteString) -- > import Data.Aeson.Types -- > import qualified Data.Aeson.Combinators.Decode as ACD@@ -199,7 +199,7 @@ -- -- If you like elm style decoding you can avoid using 'FromJSON' type class altogher. ----- > import Data.Text+-- > import Data.Text (Text) -- > import qualified Data.Aeson.Combinators.Decode as ACD -- > -- > data Person = Person
test/JSONDecodeSpec.hs view
@@ -1,18 +1,18 @@-{-# LANGUAGE DeriveGeneric #-}-{-# LANGUAGE FlexibleContexts #-}-{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} module JSONDecodeSpec where -import Control.Applicative+import Control.Applicative import qualified Data.Aeson.Combinators.Decode as JD-import Data.Aeson.Types (FromJSON (..))-import Data.ByteString.Lazy-import Data.ByteString.Lazy.UTF8 (fromString)-import Data.Text-import GHC.Generics-import Test.Hspec+import Data.Aeson.Types (FromJSON (..))+import Data.ByteString.Lazy+import Data.ByteString.Lazy.UTF8 (fromString)+import Data.Text (Text)+import GHC.Generics+import Test.Hspec data Object = Object { name :: Text@@ -27,9 +27,9 @@ decoder :: JD.Decoder Object decoder =- Object- <$> JD.key "name" JD.text- <*> JD.key "nick" JD.text+ Object+ <$> JD.key "name" JD.text+ <*> JD.key "nick" JD.text json :: ByteString json = "{\"name\":\"Jany Doe\",\"nick\": \"jany\"}"@@ -39,114 +39,124 @@ objectSpec :: Spec objectSpec = do- describe "field" $ do- let res = Just $ Object "Jany Doe" "jany"+ describe "field" $ do+ let res = Just $ Object "Jany Doe" "jany" - it "should decode object" $ do- JD.decode decoder json `shouldBe` res+ it "should decode object" $ do+ JD.decode decoder json `shouldBe` res - it "should decode nested object" $ do- JD.decode (JD.key "data" decoder) jsonNested- `shouldBe` res+ it "should decode nested object" $ do+ JD.decode (JD.key "data" decoder) jsonNested+ `shouldBe` res - it "should be possible to use default decoder" $ do- JD.decode JD.auto json `shouldBe` res+ it "should be possible to use default decoder" $ do+ JD.decode JD.auto json `shouldBe` res - describe "at" $ do- let- nest' :: Int -> ByteString -> ByteString- nest' n inner =- if n <= 0 then- inner- else- nest' (n - 1) ("{\"level-" <> fromString (show n) <> "\":" <> inner <> "}")- let nest n = nest' n json- let res = Just $ Object "Jany Doe" "jany"+ describe "at" $ do+ let+ nest' :: Int -> ByteString -> ByteString+ nest' n inner =+ if n <= 0+ then+ inner+ else+ nest' (n - 1) ("{\"level-" <> fromString (show n) <> "\":" <> inner <> "}")+ let nest n = nest' n json+ let res = Just $ Object "Jany Doe" "jany" - it "should decode object directly for empty list" $ do- JD.decode (JD.at [] decoder) json- `shouldBe` res+ it "should decode object directly for empty list" $ do+ JD.decode (JD.at [] decoder) json+ `shouldBe` res - it "should decode 2 level json" $ do- let jdata = nest 2+ it "should decode 2 level json" $ do+ let jdata = nest 2 - JD.decode (JD.at ["level-1", "level-2"] decoder) jdata- `shouldBe` res+ JD.decode (JD.at ["level-1", "level-2"] decoder) jdata+ `shouldBe` res - it "should decode 10 level json" $ do- let jdata = nest 10- let path = ["level-1", "level-2", "level-3", "level-4", "level-5"- , "level-6", "level-7", "level-8", "level-9", "level-10"- ]+ it "should decode 10 level json" $ do+ let jdata = nest 10+ let path =+ [ "level-1"+ , "level-2"+ , "level-3"+ , "level-4"+ , "level-5"+ , "level-6"+ , "level-7"+ , "level-8"+ , "level-9"+ , "level-10"+ ] - JD.decode (JD.at path decoder) jdata `shouldBe` res+ JD.decode (JD.at path decoder) jdata `shouldBe` res arraySpec :: Spec arraySpec = do- describe "index" $ do- it "decode singleton by index" $ do- JD.decode (JD.index 0 decoder) "[{\"name\": \"Sanders\", \"nick\": \"bern\"}]"- `shouldBe` Just (Object "Sanders" "bern")+ describe "index" $ do+ it "decode singleton by index" $ do+ JD.decode (JD.index 0 decoder) "[{\"name\": \"Sanders\", \"nick\": \"bern\"}]"+ `shouldBe` Just (Object "Sanders" "bern") - it "should decode nth index" $ do- JD.decode (JD.index 1 decoder) "[false, {\"name\": \"Sanders\", \"nick\": \"bern\"}, true]"- `shouldBe` Just (Object "Sanders" "bern")+ it "should decode nth index" $ do+ JD.decode (JD.index 1 decoder) "[false, {\"name\": \"Sanders\", \"nick\": \"bern\"}, true]"+ `shouldBe` Just (Object "Sanders" "bern") monadSpec :: Spec monadSpec =- describe "monadic decoding" $ do- let fromText v =- case v of- "foo" -> pure Foo- "bar" -> pure Bar- _ -> fail "unknown"+ describe "monadic decoding" $ do+ let fromText v =+ case v of+ "foo" -> pure Foo+ "bar" -> pure Bar+ _ -> fail "unknown" - it "should work as a dummy value" $ do- JD.decode (JD.string >>= pure) "\"foo\""- `shouldBe` Just "foo"+ it "should work as a dummy value" $ do+ JD.decode (JD.string >>= pure) "\"foo\""+ `shouldBe` Just "foo" - it "should turn string to sum" $ do- JD.decode (JD.string >>= fromText) "\"foo\""- `shouldBe` Just Foo+ it "should turn string to sum" $ do+ JD.decode (JD.string >>= fromText) "\"foo\""+ `shouldBe` Just Foo - it "should fail with right error" $ do- JD.eitherDecode (JD.string >>= fromText) "\"foobar\""- `shouldBe` Left "Error in $: unknown"+ it "should fail with right error" $ do+ JD.eitherDecode (JD.string >>= fromText) "\"foobar\""+ `shouldBe` Left "Error in $: unknown" alternativeSpec :: Spec alternativeSpec =- describe "alternative (<|>)" $ do- let (dec :: JD.Decoder (Either Bool Object)) =- Left <$> JD.bool <|> Right <$> decoder+ describe "alternative (<|>)" $ do+ let (dec :: JD.Decoder (Either Bool Object)) =+ Left <$> JD.bool <|> Right <$> decoder - it "should decode first alternative" $ do- JD.decode dec "false" `shouldBe` Just (Left False)+ it "should decode first alternative" $ do+ JD.decode dec "false" `shouldBe` Just (Left False) - it "should decode second alternative" $ do- JD.decode dec "{\"name\": \"Joe\",\"nick\": \"jd\"}"- `shouldBe` Just (Right $ Object "Joe" "jd")+ it "should decode second alternative" $ do+ JD.decode dec "{\"name\": \"Joe\",\"nick\": \"jd\"}"+ `shouldBe` Just (Right $ Object "Joe" "jd") jsonNullSpec :: Spec jsonNullSpec =- describe "jsonNull" $ do- let barDec txt =- case txt of- "bar" -> pure Bar- _ -> fail $ "Unknown value" <> show txt+ describe "jsonNull" $ do+ let barDec txt =+ case txt of+ "bar" -> pure Bar+ _ -> fail $ "Unknown value" <> show txt - let (dec :: JD.Decoder FooBar) =- JD.jsonNull Foo <|> (barDec =<< JD.text)+ let (dec :: JD.Decoder FooBar) =+ JD.jsonNull Foo <|> (barDec =<< JD.text) - it "should decode Foo from null" $ do- JD.decode dec "null" `shouldBe` Just Foo+ it "should decode Foo from null" $ do+ JD.decode dec "null" `shouldBe` Just Foo - it "should decode Bar from string" $ do- JD.decode dec "\"bar\"" `shouldBe` Just Bar+ it "should decode Bar from string" $ do+ JD.decode dec "\"bar\"" `shouldBe` Just Bar spec :: Spec spec = do- objectSpec- arraySpec- monadSpec- alternativeSpec- jsonNullSpec+ objectSpec+ arraySpec+ monadSpec+ alternativeSpec+ jsonNullSpec