formatting 6.3.6 → 6.3.7
raw patch · 6 files changed
+75/−9 lines, 6 filesdep ~bytestringdep ~textPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: bytestring, text
API changes (from Hackage documentation)
- Formatting.Buildable: instance Formatting.Buildable.Buildable a => Formatting.Buildable.Buildable (GHC.Base.Maybe a)
- Formatting.Internal: instance (a ~ r) => Data.String.IsString (Formatting.Internal.Format r a)
+ Formatting.Buildable: instance Formatting.Buildable.Buildable a => Formatting.Buildable.Buildable (GHC.Maybe.Maybe a)
+ Formatting.Buildable: instance Formatting.Buildable.Buildable a => Formatting.Buildable.Buildable [a]
+ Formatting.Internal: instance (a Data.Type.Equality.~ r) => Data.String.IsString (Formatting.Internal.Format r a)
- Formatting.Internal: Format :: (Builder -> r) -> a -> Format r a
+ Formatting.Internal: Format :: ((Builder -> r) -> a) -> Format r a
- Formatting.Internal.Raw: fixed :: (Real a) => Int -> a -> Builder
+ Formatting.Internal.Raw: fixed :: Real a => Int -> a -> Builder
- Formatting.Internal.Raw: shortest :: (Real a) => a -> Builder
+ Formatting.Internal.Raw: shortest :: Real a => a -> Builder
- Formatting.Time: days :: (RealFrac n) => Int -> Format r (n -> r)
+ Formatting.Time: days :: RealFrac n => Int -> Format r (n -> r)
- Formatting.Time: diff :: (RealFrac n) => Bool -> Format r (n -> r)
+ Formatting.Time: diff :: RealFrac n => Bool -> Format r (n -> r)
- Formatting.Time: hours :: (RealFrac n) => Int -> Format r (n -> r)
+ Formatting.Time: hours :: RealFrac n => Int -> Format r (n -> r)
- Formatting.Time: minutes :: (RealFrac n) => Int -> Format r (n -> r)
+ Formatting.Time: minutes :: RealFrac n => Int -> Format r (n -> r)
- Formatting.Time: seconds :: (RealFrac n) => Int -> Format r (n -> r)
+ Formatting.Time: seconds :: RealFrac n => Int -> Format r (n -> r)
- Formatting.Time: years :: (RealFrac n) => Int -> Format r (n -> r)
+ Formatting.Time: years :: RealFrac n => Int -> Format r (n -> r)
Files
- CHANGELOG.md +4/−0
- formatting.cabal +3/−3
- src/Formatting.hs +2/−3
- src/Formatting/Buildable.hs +9/−1
- src/Formatting/Formatters.hs +2/−2
- test/Spec.hs +55/−0
CHANGELOG.md view
@@ -1,3 +1,7 @@+6.3.7++* Introduced instance `Buildable a => Buildable [a]`.+ 6.3.6 * Bring back `int :: Integral a => Format r (a -> r)`
formatting.cabal view
@@ -1,5 +1,5 @@ name: formatting-version: 6.3.6+version: 6.3.7 synopsis: Combinator-based type-safe formatting (like printf() or FORMAT) description: Combinator-based type-safe formatting (like printf() or FORMAT), modelled from the HoleyMonoids package. license: BSD3@@ -41,7 +41,7 @@ ghc-prim, text >= 0.11.0.8, transformers,- bytestring,+ bytestring >=0.10.4, integer-gmp >= 0.2, semigroups @@ -53,7 +53,7 @@ type: exitcode-stdio-1.0 hs-source-dirs: test main-is: Spec.hs- build-depends: base, formatting, hspec, semigroups+ build-depends: base, formatting, hspec, semigroups, text ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N source-repository head
src/Formatting.hs view
@@ -33,10 +33,9 @@ bprint, fprint, hprint,+ formatToString, -- * Formatting library- module Formatting.Formatters,- -- * Other functions- formatToString+ module Formatting.Formatters ) where import Formatting.Formatters
src/Formatting/Buildable.hs view
@@ -21,9 +21,10 @@ import Data.Void (Void, absurd) #endif -import Data.Monoid (mempty)+import Data.Monoid (mempty, mconcat) import Data.Int (Int8, Int16, Int32, Int64) import Data.Fixed (Fixed, HasResolution, showFixed)+import Data.List (intersperse) import Data.Ratio (Ratio, denominator, numerator) import qualified Data.Text.Format.Functions as F ((<>)) import Data.Text.Format.Int (decimal, hexadecimal, integer)@@ -189,3 +190,10 @@ instance Buildable Bool where build True = fromText "True" build False = fromText "False"++#if MIN_VERSION_base(4,8,0)+instance {-# OVERLAPPABLE #-} Buildable a => Buildable [a] where+ build = \xs -> "[" F.<> mconcat (intersperse "," (map build xs)) F.<> "]"+ {-# INLINE build #-}+#endif+
src/Formatting/Formatters.hs view
@@ -199,9 +199,9 @@ ords :: Integral n => Format r (n -> r) ords = later go where go n- | tens > 3 && tens < 21 = T.shortest n <> "th"+ | tens > 3 && tens < 21 = T.fixed 0 n <> "th" | otherwise =- T.shortest n <>+ T.fixed 0 n <> case n `mod` 10 of 1 -> "st" 2 -> "nd"
test/Spec.hs view
@@ -1,8 +1,10 @@ {-# LANGUAGE OverloadedStrings #-} +import Control.Monad import Data.Int import qualified Data.Monoid import qualified Data.Semigroup+import qualified Data.Text.Lazy as LT import Formatting as F import Test.Hspec @@ -60,3 +62,56 @@ it "Variable" (shouldBe (format float (12.123456 :: Double)) "12.123456"))++ describe+ "Buildable a => Buildable [a]"+ (do it "\"\" :: [Char] (backwards compatibility)"+ (shouldBe (format build ("" :: String)) "")+ it "\"hi\" :: [Char] (backwards compatibility)"+ (shouldBe (format build ("hi" :: String)) "hi")+ it "[1,2,3] :: [Int]"+ (shouldBe (format build ([1,2,3] :: [Int])) "[1,2,3]")+ it "[] :: [Int]"+ (shouldBe (format build ([] :: [Int])) "[]"))++ describe "ords" $ do + let tests :: [(Int, String)]+ tests = [ ( 1, "1st")+ , ( 2, "2nd")+ , ( 3, "3rd")+ , ( 4, "4th")+ , ( 5, "5th")+ , ( 6, "6th")+ , ( 7, "7th")+ , ( 8, "8th")+ , ( 9, "9th")+ , (10, "10th")+ , (11, "11th")+ , (12, "12th")+ , (13, "13th")+ , (14, "14th")+ , (15, "15th")+ , (16, "16th")+ , (17, "17th")+ , (18, "18th")+ , (19, "19th")+ , (20, "20th")+ , (21, "21st")+ , (22, "22nd")+ , (23, "23rd")+ , (24, "24th")+ , (25, "25th")+ , (26, "26th")+ , (27, "27th")+ , (28, "28th")+ , (29, "29th")+ , (30, "30th")+ , (31, "31st")+ , (31, "31st")+ , (32, "32nd")+ , (33, "33rd")+ , (34, "34th")+ ]++ forM_ tests $ \(input, output) -> it output $ format ords input `shouldBe` (LT.pack output)+