packages feed

toml-reader 0.2.1.0 → 0.2.2.0

raw patch · 5 files changed

+37/−12 lines, 5 filesdep ~base

Dependency ranges changed: base

Files

CHANGELOG.md view
@@ -1,3 +1,9 @@+## v0.2.2.0++* Add support for GHC 9.10 + 9.12+* Fix context when decoding `Map`+* Add `getTableOf`+ ## v0.2.1.0  * Drop support for GHC < 9.0
src/TOML/Decode.hs view
@@ -29,6 +29,7 @@   getFieldOptWith,   getFieldsOptWith,   getArrayOf,+  getTableOf,    -- ** Build custom Decoder   DecodeM (..),@@ -391,6 +392,15 @@     Array vs -> zipWithM (\i -> addContextItem (Index i) . runDecoder decoder) [0 ..] vs     v -> typeMismatch v +-- |+-- Decode a table of values using a given 'Decoder', returning the+-- results as a 'Text'-indexed 'Map'.+getTableOf :: Decoder a -> Decoder (Map Text a)+getTableOf decoder =+  makeDecoder $ \case+    Table t -> Map.traverseWithKey (\k -> addContextItem (Key k) . runDecoder decoder) t+    v -> typeMismatch v+ {--- DecodeTOML ---}  -- |@@ -591,10 +601,7 @@ instance (DecodeTOML a) => DecodeTOML [a] where   tomlDecoder = getArrayOf tomlDecoder instance (IsString k, Ord k, DecodeTOML v) => DecodeTOML (Map k v) where-  tomlDecoder =-    makeDecoder $ \case-      Table o -> Map.mapKeys (fromString . Text.unpack) <$> mapM (runDecoder tomlDecoder) o-      v -> typeMismatch v+  tomlDecoder = Map.mapKeys (fromString . Text.unpack) <$> getTableOf tomlDecoder instance (DecodeTOML a) => DecodeTOML (NonEmpty a) where   tomlDecoder = maybe raiseEmpty pure . NonEmpty.nonEmpty =<< tomlDecoder     where
src/TOML/Parser.hs view
@@ -22,7 +22,10 @@ import Data.Bifunctor (bimap) import Data.Char (chr, isDigit, isSpace, ord) import Data.Fixed (Fixed (..))-import Data.Foldable (foldl', foldlM)+import Data.Foldable (foldlM)+#if !MIN_VERSION_base(4,20,0)+import Data.Foldable (foldl')+#endif import Data.Functor (($>)) import Data.List.NonEmpty (NonEmpty) import qualified Data.List.NonEmpty as NonEmpty
test/tasty/TOML/DecodeTest.hs view
@@ -5,6 +5,8 @@ module TOML.DecodeTest (test) where  import Data.Int (Int8)+import Data.Map.Strict (Map)+import qualified Data.Map.Strict as Map import qualified Data.Text as Text import qualified Data.Time as Time import Numeric.Natural (Natural)@@ -237,9 +239,16 @@         decodeWith (getField @() "a") "a = []" @?= Right ()     , testCase "(a, b)" $         decodeWith (getField @(Int, Double) "a") "a = [1, 2.5]" @?= Right (1, 2.5)+    , testCase "Map" $+        decodeWith (getField @(Map Text.Text Int) "a") "a = {x = 1, y = 2}"+          @?= Right (Map.fromList [("x", 1), ("y", 2)])     , testCase "Tuples show errors with index" $         case decodeWith (getField @(Int, Double) "a") "a = [1, true]" of           Left (DecodeError [Key "a", Index 1] _) -> return ()+          result -> unexpectedResult result+    , testCase "Maps show errors with key" $+        case decodeWith (getField @(Map Text.Text Int) "a") "a = {x = true}" of+          Left (DecodeError [Key "a", Key "x"] _) -> return ()           result -> unexpectedResult result     ]   where
toml-reader.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.35.2.+-- This file has been generated from package.yaml by hpack version 0.37.0. -- -- see: https://github.com/sol/hpack  name:           toml-reader-version:        0.2.1.0+version:        0.2.2.0 synopsis:       TOML format parser compliant with v1.0.0. description:    TOML format parser compliant with v1.0.0. See README.md for more details. category:       TOML, Text, Configuration@@ -52,11 +52,11 @@   ghc-options: -Wall -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wnoncanonical-monad-instances -Wunused-packages   build-depends:       base >=4.15 && <5-    , containers <0.7-    , megaparsec <9.5-    , parser-combinators <1.4-    , text <2.1-    , time <1.13+    , containers+    , megaparsec+    , parser-combinators+    , text+    , time   default-language: Haskell2010  test-suite parser-validator