lens-toml-parser 0.1.0.0 → 0.1.0.1
raw patch · 5 files changed
+57/−29 lines, 5 filesdep +lens-familydep −lens-simplePVP ok
version bump matches the API change (PVP)
Dependencies added: lens-family
Dependencies removed: lens-simple
API changes (from Hackage documentation)
Files
- ChangeLog.md +5/−0
- README.md +8/−0
- lens-toml-parser.cabal +4/−2
- src/TOML/Lens.hs +10/−0
- tests/Main.hs +30/−27
ChangeLog.md view
@@ -3,3 +3,8 @@ ## 0.1.0.0 -- 2017-08-14 * First version. Released on an unsuspecting world.++## 0.1.0.1 -- 2017-10-07++* Added `INLINE` pragmas.+* Updated tests.
+ README.md view
@@ -0,0 +1,8 @@+# lens-toml-parser++[](https://travis-ci.org/xngns/lens-toml-parser)+[](http://hackage.haskell.org/package/lens-toml-parser)++Lenses for [toml-parser](https://hackage.haskell.org/package/toml-parser).++See the [tests](https://github.com/xngns/lens-toml-parser/blob/master/tests/Main.hs) for usage examples.
lens-toml-parser.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: lens-toml-parser-version: 0.1.0.0+version: 0.1.0.1 synopsis: Lenses for toml-parser description: Lenses for toml-parser license: ISC@@ -20,6 +20,7 @@ .gitignore .travis.yml ChangeLog.md+ README.md example/example-v0.4.0.toml source-repository head@@ -47,7 +48,7 @@ , text >=1.2 && <1.3 , dwergaz >=0.2 && <0.3 , toml-parser >=0.1 && <0.2- , lens-simple >=0.1 && <0.2+ , lens-family >=1.2 && <1.3 , lens-toml-parser hs-source-dirs: tests default-language: Haskell2010@@ -60,3 +61,4 @@ , hlint >= 1.9 hs-source-dirs: tests default-language: Haskell2010+ ghc-options: -Wall
src/TOML/Lens.hs view
@@ -58,6 +58,7 @@ prism Table $ \ n -> case n of Table v -> pure v _ -> Left n+{-# INLINE _Table #-} -- | @_List :: Prism' Value [Value]@ _List@@ -68,6 +69,7 @@ prism List $ \ n -> case n of List v -> pure v _ -> Left n+{-# INLINE _List #-} -- | @_Double :: Prism' Value Double@ _Double@@ -78,6 +80,7 @@ prism Double $ \ n -> case n of Double v -> pure v _ -> Left n+{-# INLINE _Double #-} -- | @_Integer :: Prism' Value Integer@ _Integer@@ -88,6 +91,7 @@ prism Integer $ \ n -> case n of Integer v -> pure v _ -> Left n+{-# INLINE _Integer #-} -- | @_String :: Prism' Value T.Text@ _String@@ -98,6 +102,7 @@ prism String $ \ n -> case n of String v -> pure v _ -> Left n+{-# INLINE _String #-} -- | @_Bool :: Prism' Value Bool@ _Bool@@ -108,6 +113,7 @@ prism Bool $ \ n -> case n of Bool v -> pure v _ -> Left n+{-# INLINE _Bool #-} -- | @_ZonedTimeV :: Prism' Value ZonedTime@ _ZonedTimeV@@ -118,6 +124,7 @@ prism ZonedTimeV $ \ n -> case n of ZonedTimeV v -> pure v _ -> Left n+{-# INLINE _ZonedTimeV #-} -- | @_LocalTimeV :: Prism' Value LocalTime@ _LocalTimeV@@ -128,6 +135,7 @@ prism LocalTimeV $ \ n -> case n of LocalTimeV v -> pure v _ -> Left n+{-# INLINE _LocalTimeV #-} -- | @_DayV :: Prism' Value Day@ _DayV@@ -138,6 +146,7 @@ prism DayV $ \ n -> case n of DayV v -> pure v _ -> Left n+{-# INLINE _DayV #-} -- | @_TimeOfDayV :: Prism' Value TimeOfDay@ _TimeOfDayV@@ -148,3 +157,4 @@ prism TimeOfDayV $ \ n -> case n of TimeOfDayV v -> pure v _ -> Left n+{-# INLINE _TimeOfDayV #-}
tests/Main.hs view
@@ -2,25 +2,28 @@ module Main (main) where -import Control.Monad (unless)-import qualified Data.Map.Lazy as Map-import qualified Data.Text as T-import Data.Text.IO (readFile)-import Lens.Simple-import Prelude hiding (readFile)-import System.Exit (exitFailure)+import Control.Monad (unless)+import qualified Data.Map.Lazy as Map+import qualified Data.Text as T+import Data.Text.IO (readFile)+import Lens.Family2+import Lens.Family2.Stock (at, _Just)+import Lens.Family2.Unchecked (iso)+import Prelude hiding (readFile)+import System.Exit (exitFailure) import Test.Dwergaz import qualified TOML import TOML.Lens -alist :: Ord k => [(k, v)] -> Map.Map k v-alist = Map.fromList+allEqual :: Eq a => [a] -> Bool+allEqual (x:xs) = all (== x) xs+allEqual [] = error "allEqual: empty list" -alistLens+alist :: (Ord k1, Ord k2, Functor f) => LensLike f [(k1, v1)] [(k2, v2)] (Map.Map k1 v1) (Map.Map k2 v2)-alistLens = iso Map.fromList Map.toList+alist = iso Map.fromList Map.toList mapAt :: Applicative f@@ -28,7 +31,7 @@ -> (Map.Map T.Text TOML.Value -> f (Map.Map T.Text TOML.Value)) -> Map.Map T.Text TOML.Value -> f (Map.Map T.Text TOML.Value)-mapAt k = at k . _Just . _Table . alistLens+mapAt k = at k . _Just . _Table . alist listAt :: Applicative f@@ -44,7 +47,7 @@ (==) expected actual where expected = Just "value"- actual = alist kv ^? mapAt "table" . at "key" . _Just . _String+ actual = kv ^? alist . mapAt "table" . at "key" . _Just . _String testTableZoo :: [(T.Text, TOML.Value)] -> Test testTableZoo kv@@ -52,7 +55,7 @@ (==) expected actual where expected = Nothing- actual = alist kv ^? mapAt "table" . at "zoo" . _Just . _String+ actual = kv ^? alist . mapAt "table" . at "zoo" . _Just . _String testTableSubtableKey :: [(T.Text, TOML.Value)] -> Test testTableSubtableKey kv@@ -60,7 +63,7 @@ (==) expected actual where expected = Just "another value"- actual = alist kv ^? mapAt "table" . mapAt "subtable" . at "key" . _Just . _String+ actual = kv ^? alist . mapAt "table" . mapAt "subtable" . at "key" . _Just . _String testTableInlineNameFirst :: [(T.Text, TOML.Value)] -> Test testTableInlineNameFirst kv@@ -68,7 +71,7 @@ (==) expected actual where expected = Just "Tom"- actual = alist kv ^? mapAt "table" . mapAt "inline" . mapAt "name" . at "first" . _Just . _String+ actual = kv ^? alist . mapAt "table" . mapAt "inline" . mapAt "name" . at "first" . _Just . _String testTableInlinePointY :: [(T.Text, TOML.Value)] -> Test testTableInlinePointY kv@@ -76,7 +79,7 @@ (==) expected actual where expected = Just 2- actual = alist kv ^? mapAt "table" . mapAt "inline" . mapAt "point" . at "y" . _Just . _Integer+ actual = kv ^? alist . mapAt "table" . mapAt "inline" . mapAt "point" . at "y" . _Just . _Integer testStringBasicBasic :: [(T.Text, TOML.Value)] -> Test testStringBasicBasic kv@@ -84,27 +87,27 @@ (==) expected actual where expected = Just "I'm a string. \"You can quote me\". Name\tJos\233\nLocation\tSF."- actual = alist kv ^? mapAt "string" . mapAt "basic" . at "basic" . _Just . _String+ actual = kv ^? alist . mapAt "string" . mapAt "basic" . at "basic" . _Just . _String testStringMultiline :: [(T.Text, TOML.Value)] -> Test testStringMultiline kv = Predicate "'key1', 'key2', and 'key3' from 'multiline' from 'string' are all the same"- (\ xs -> all (== head xs) (tail xs))+ allEqual [actual1, actual2, actual3] where- actual1 = alist kv ^? mapAt "string" . mapAt "multiline" . at "key1" . _Just . _String- actual2 = alist kv ^? mapAt "string" . mapAt "multiline" . at "key2" . _Just . _String- actual3 = alist kv ^? mapAt "string" . mapAt "multiline" . at "key3" . _Just . _String+ actual1 = kv ^? alist . mapAt "string" . mapAt "multiline" . at "key1" . _Just . _String+ actual2 = kv ^? alist . mapAt "string" . mapAt "multiline" . at "key2" . _Just . _String+ actual3 = kv ^? alist . mapAt "string" . mapAt "multiline" . at "key3" . _Just . _String testStringMultilineContinued :: [(T.Text, TOML.Value)] -> Test testStringMultilineContinued kv = Predicate "'key1', 'key2', and 'key3' from 'continued' from 'multiline' from 'string' are all the same"- (\ xs -> all (== head xs) (tail xs))+ allEqual [actual1, actual2, actual3] where- actual1 = alist kv ^? mapAt "string" . mapAt "multiline" . mapAt "continued" . at "key1" . _Just . _String- actual2 = alist kv ^? mapAt "string" . mapAt "multiline" . mapAt "continued" . at "key2" . _Just . _String- actual3 = alist kv ^? mapAt "string" . mapAt "multiline" . mapAt "continued" . at "key3" . _Just . _String+ actual1 = kv ^? alist . mapAt "string" . mapAt "multiline" . mapAt "continued" . at "key1" . _Just . _String+ actual2 = kv ^? alist . mapAt "string" . mapAt "multiline" . mapAt "continued" . at "key2" . _Just . _String+ actual3 = kv ^? alist . mapAt "string" . mapAt "multiline" . mapAt "continued" . at "key3" . _Just . _String testArrayKey1 :: [(T.Text, TOML.Value)] -> Test testArrayKey1 kv@@ -112,7 +115,7 @@ (==) expected actual where expected = [1, 2, 3]- actual = alist kv ^.. mapAt "array" . listAt "key1" . traverse . _Integer+ actual = kv ^.. alist . mapAt "array" . listAt "key1" . traverse . _Integer runTests :: [(T.Text, TOML.Value)] -> [Result] runTests kv = runTest . ($ kv) <$> tests