packages feed

sv 1.1 → 1.1.1

raw patch · 4 files changed

+54/−5 lines, 4 filesdep ~sv-corePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: sv-core

API changes (from Hackage documentation)

+ Data.Sv: (.:) :: Ord s => s -> Decode' s a -> NameDecode' s a
+ Data.Sv: (=:) :: () => Builder -> Encode a -> NameEncode a
+ Data.Sv: encodeNamed :: () => NameEncode a -> EncodeOptions -> [a] -> ByteString
+ Data.Sv: encodeNamedBuilder :: () => NameEncode a -> EncodeOptions -> [a] -> Builder
+ Data.Sv: encodeNamedToFile :: () => NameEncode a -> EncodeOptions -> [a] -> FilePath -> IO ()
+ Data.Sv: encodeNamedToHandle :: () => NameEncode a -> EncodeOptions -> [a] -> Handle -> IO ()
+ Data.Sv: infixl 5 .:

Files

changelog.md view
@@ -1,5 +1,9 @@ # Revision history for sv +## 1.1.1 -- 2018-08-10++* Depend on sv-core 0.2.1 to get column-name-based encoding+ ## 1.1 -- 2018-07-25  * Add column-name-based decoding by adding parseDecodeNamed and associated functions
src/Data/Sv.hs view
@@ -32,6 +32,7 @@   , decodeMay   , decodeEither   , decodeEither'+  , (.:)   , (>>==)   , (==<<)   , module Data.Sv.Parse@@ -43,7 +44,12 @@   , encodeToFile   , encodeToHandle   , encodeBuilder+  , encodeNamed+  , encodeNamedToFile+  , encodeNamedToHandle+  , encodeNamedBuilder   , encodeRow+  , (=:)   , module Data.Sv.Encode.Type   , module Data.Sv.Encode.Options 
sv.cabal view
@@ -1,5 +1,5 @@ name:                sv-version:             1.1+version:             1.1.1 license:             BSD3 license-file:        LICENCE author:              George Wilson@@ -46,6 +46,7 @@   * Decoding a real CSV: <https://github.com/qfpl/sv/blob/master/examples/src/Data/Sv/Example/Species.lhs Species.lhs>   * Decoding by column name: <https://github.com/qfpl/sv/blob/master/examples/src/Data/Sv/Example/Columnar.hs Columnar.hs>   * Encoding data to a CSV: <https://github.com/qfpl/sv/blob/master/examples/src/Data/Sv/Example/Encoding.hs Encoding.hs>+  * Encoding data to a CSV with a header: <https://github.com/qfpl/sv/blob/master/examples/src/Data/Sv/Example/EncodingWithHeader.hs EncodingWithHeader.hs>   * Handling NULL and Unknown occuring in a column of numbers: <https://github.com/qfpl/sv/blob/master/examples/src/Data/Sv/Example/Numbers.hs Numbers.hs>   * Dealing with non-rectangular data: <https://github.com/qfpl/sv/blob/master/examples/src/Data/Sv/Example/Ragged.hs Ragged.hs>   * Integrating with an existing attoparsec parser to read date stamps: <https://github.com/qfpl/sv/blob/master/examples/src/Data/Sv/Example/TableTennis.hs TableTennis.hs>@@ -97,7 +98,7 @@                        , contravariant >= 1.2 && < 1.6                        , hw-dsv >= 0.2.1 && < 0.3                        , semigroupoids >= 5 && <6-                       , sv-core >= 0.2 && < 0.3+                       , sv-core >= 0.2.1 && < 0.3                        , transformers >= 0.2 && < 0.6                        , utf8-string >= 1 && < 1.1                        , validation >= 1 && < 1.1
test/Data/Sv/EncodeTest.hs view
@@ -7,6 +7,7 @@ import Data.Functor.Contravariant import Data.Functor.Contravariant.Divisible import Data.Semigroup ((<>))+import Data.Text (Text) import Test.Tasty (TestTree, testGroup) import Test.Tasty.HUnit (testCase, (@?=)) @@ -21,9 +22,6 @@  data IntAndString = IAS { getInt :: Int, getString :: String } -intAndString :: Encode IntAndString-intAndString = contramap getInt E.int <> contramap getString E.string- test_Encode :: TestTree test_Encode =   testGroup "Encode" [@@ -31,8 +29,13 @@   , decidableTests   , encodeTests   , escapeTests+  , encodeNamedTests   ] +intAndString :: Encode IntAndString+intAndString = contramap getInt E.int <> contramap getString E.string++ opts :: EncodeOptions opts = defaultEncodeOptions @@ -86,4 +89,39 @@       encodeRow E.byteString opts "\"test\"ing\" " @?= "\"\"\"test\"\"ing\"\" \""   , testCase "bytestring - lazy" $       encodeRow E.lazyByteString opts "\"" @?= "\"\"\"\""+  ]++data Three = Three {+  int :: Int+, double :: Double+, text :: Text+} deriving (Eq, Ord, Show)++three :: NameEncode Three+three =+  E.named "first" (contramap int E.int)+    <> E.named "\"Second\"" (contramap double E.double)+    <> E.named "third" (contramap text E.text)++myInt :: NameEncode Int+myInt = E.named "my int" E.int++encodeNamedTests :: TestTree+encodeNamedTests = testGroup "named" [+    testCase "empty decoder" $+      encodeNamed mempty opts [] @?= ""+  , testCase "single column, zero rows" $+      encodeNamed myInt opts [] @?= "my int"+  , testCase "single column, one row" $+      encodeNamed myInt opts [5] @?= "my int\n5"+  , testCase "single column, many rows" $+      encodeNamed myInt opts [1..5] @?= "my int\n1\n2\n3\n4\n5"+  , testCase "multiple columns, zero rows" $+      encodeNamed three opts [] @?= "first,\"\"\"Second\"\"\",third"+  , testCase "multiple columns, one row" $+      encodeNamed three opts [Three 1 2 "th\"ree"]+        @?= "first,\"\"\"Second\"\"\",third\n1,2.0,\"th\"\"ree\""+  , testCase "multiple columns, multiple rows" $+      encodeNamed three opts [Three 1 2 "three", Three 4 5 "SIX"]+        @?= "first,\"\"\"Second\"\"\",third\n1,2.0,three\n4,5.0,SIX"   ]