packages feed

safe-money-serialise 0.1 → 0.1.1

raw patch · 4 files changed

+28/−18 lines, 4 filesdep ~safe-moneyPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: safe-money

API changes (from Hackage documentation)

+ Money.Serialise: instance Codec.Serialise.Class.Serialise Money.Internal.Scale

Files

changelog.md view
@@ -1,4 +1,9 @@+# Version 0.1.1++* Require `safe-money>=0.8`.++ # Version 0.1 -* This first release of @safe-money-serialise@ includes the same-  @serialise@ support and tests that were present in @safe-money-0.6@.+* This first release of `safe-money-serialise` includes the same+  `serialise` support and tests that were present in `safe-money-0.6`.
safe-money-serialise.cabal view
@@ -1,5 +1,5 @@ name: safe-money-serialise-version: 0.1+version: 0.1.1 license: BSD3 license-file: LICENSE copyright: Copyright (c) Renzo Carbonara 2016-2018@@ -33,7 +33,7 @@   build-depends:     base (>=4.8 && <5.0),     bytestring,-    safe-money,+    safe-money >=0.8,     serialise   exposed-modules:     Money.Serialise
src/Money/Serialise.hs view
@@ -42,6 +42,17 @@   decode = maybe (fail "ExchangeRate") pure              =<< fmap Money.fromSomeExchangeRate Ser.decode +instance Ser.Serialise Money.Scale where+  encode = \s ->+    let r = Money.scaleToRational s+    in Ser.encode (numerator r) <>+       Ser.encode (denominator r)+  decode = maybe (fail "Scale") pure =<< do+    n :: Integer <- Ser.decode+    d :: Integer <- Ser.decode+    when (d == 0) (fail "denominator is zero")+    pure (MoneyI.scaleFromRational (n % d))+ -- | Compatible with 'Money.Dense'. instance Ser.Serialise Money.SomeDense where   encode = \sd ->@@ -59,18 +70,14 @@ -- | Compatible with 'Money.Discrete'. instance Ser.Serialise Money.SomeDiscrete where   encode = \sd ->-    let r = Money.someDiscreteScale sd-    in Ser.encode (MoneyI.someDiscreteCurrency' sd) <>-       Ser.encode (numerator r) <>-       Ser.encode (denominator r) <>-       Ser.encode (Money.someDiscreteAmount sd)-  decode = maybe (fail "SomeDiscrete") pure =<< do+    Ser.encode (MoneyI.someDiscreteCurrency' sd) <>+    Ser.encode (Money.someDiscreteScale sd) <>+    Ser.encode (Money.someDiscreteAmount sd)+  decode = do     c :: String <- Ser.decode-    n :: Integer <- Ser.decode-    d :: Integer <- Ser.decode-    when (d == 0) (fail "denominator is zero")+    s :: Money.Scale <- Ser.decode     a :: Integer <- Ser.decode-    pure (MoneyI.mkSomeDiscrete' c (n % d) a)+    pure (MoneyI.mkSomeDiscrete' c s a)  -- | Compatible with 'Money.ExchangeRate'. instance Ser.Serialise Money.SomeExchangeRate where
test/Main.hs view
@@ -55,10 +55,8 @@ testCurrencyUnits :: Tasty.TestTree testCurrencyUnits =   Tasty.testGroup "Currency units"-  [ testDiscrete (Proxy :: Proxy "BTC") (Proxy :: Proxy "BTC")-  , testDiscrete (Proxy :: Proxy "BTC") (Proxy :: Proxy "satoshi")+  [ testDiscrete (Proxy :: Proxy "BTC") (Proxy :: Proxy "satoshi")   , testDiscrete (Proxy :: Proxy "BTC") (Proxy :: Proxy "bitcoin")-  , testDiscrete (Proxy :: Proxy "USD") (Proxy :: Proxy "USD")   , testDiscrete (Proxy :: Proxy "USD") (Proxy :: Proxy "cent")   , testDiscrete (Proxy :: Proxy "USD") (Proxy :: Proxy "dollar")   , testDiscrete (Proxy :: Proxy "VUV") (Proxy :: Proxy "vatu")@@ -112,7 +110,7 @@  testDiscrete   :: forall (currency :: Symbol) (unit :: Symbol)-  .  ( Money.GoodScale (Money.Scale currency unit)+  .  ( Money.GoodScale (Money.UnitScale currency unit)      , KnownSymbol currency      , KnownSymbol unit )   => Proxy currency