packages feed

text-show 0.4 → 0.4.1

raw patch · 7 files changed

+82/−5 lines, 7 files

Files

CHANGELOG.md view
@@ -1,3 +1,6 @@+## 0.4.1.0+* Added the utility functions `toStrictText` and `toString` for working with `Builder`s.+ # 0.4 * Due to [GHC bug #5289](http://ghc.haskell.org/trac/ghc/ticket/5289), projects that depend on the `double-conversion` library (such as `text-format`, a dependency of `text-show`) may break due to GHC incorrectly linking against libstdc++. Therefore, `text-show` was changed so that it does not depend on `text-format` by default. This behavior can be changed by using the `-ftext-format` flag when using `cabal`. * Add `showbZonedTime` to `Text.Show.Text.Data.Time` (and corresponding `Show` instance for `ZonedTime`)@@ -5,7 +8,7 @@ * If using GHC 7.6 or earlier, depend on tagged so that Data.Proxy can be used * Refactor code to use Template Haskell derivations when possible -# 0.3.1.0+## 0.3.1.0 * Add `showList` and `showListLazy` * Don't use showbListDefault to show `containers` data types * Add the ability to splice `show` functions for arbitrary data types (even if they aren't `Show` instances). These functions are `mkShow`, `mkShowLazy`, `mkShowPrec`, `mkShowPrecLazy`, `mkShowb`, `mkShowbPrec`, `mkPrint`, `mkPrintLazy`, `mkHPrint`, and `mkHPrintLazy`.
src/Text/Show/Text.hs view
@@ -22,6 +22,8 @@     , showbParen       -- * 'Builder's     , module Data.Text.Lazy.Builder+    , toString+    , toText     , lengthB     , replicateB     , unlinesB@@ -39,4 +41,5 @@  import Text.Show.Text.Class import Text.Show.Text.Instances ()-import Text.Show.Text.Utils (lengthB, replicateB, unlinesB, unwordsB)+import Text.Show.Text.Utils (toString, toText, lengthB,+                             replicateB, unlinesB, unwordsB)
src/Text/Show/Text/Utils.hs view
@@ -14,7 +14,8 @@  import Data.Int (Int64) import Data.Monoid (Monoid(mappend, mempty))-import Data.Text.Lazy (length, replicate)+import Data.Text (Text)+import Data.Text.Lazy (length, replicate, toStrict, unpack) import Data.Text.Lazy.Builder (Builder, fromLazyText, singleton, toLazyText)  import GHC.Exts (Char(C#), Int(I#))@@ -51,6 +52,17 @@ replicateB :: Int64 -> Builder -> Builder replicateB n = fromLazyText . replicate n . toLazyText {-# INLINE replicateB #-}++-- | Convert a 'Builder' to a 'String' (without surrounding it with double quotes,+--   as 'show' would).+toString :: Builder -> String+toString = unpack . toLazyText+{-# INLINE toString #-}++-- | Convert a 'Builder' to a strict 'Text'.+toText :: Builder -> Text+toText = toStrict . toLazyText+{-# INLINE toText #-}  -- | Merges several 'Builder's, separating them by newlines. unlinesB :: [Builder] -> Builder
tests/Properties.hs view
@@ -12,6 +12,7 @@ module Main (main) where  import Properties.BaseAndFriends (baseAndFriendsTests)+import Properties.Builder        (builderTests) import Properties.Derived        (derivedTests) import Properties.MkShow         (mkShowTests) @@ -22,6 +23,7 @@  allTests :: [TestTree] allTests = concat [ baseAndFriendsTests+                  , builderTests                   , derivedTests                   , mkShowTests                   ]
tests/Properties/BaseAndFriends.hs view
@@ -11,7 +11,7 @@ -- Stability   :  Experimental -- Portability :  GHC -- --- @QuickCheck@ properties for for data types located in @base@ and other+-- @QuickCheck@ properties for data types located in @base@ and other -- common libraries. ---------------------------------------------------------------------------- module Properties.BaseAndFriends (baseAndFriendsTests) where
+ tests/Properties/Builder.hs view
@@ -0,0 +1,56 @@+-----------------------------------------------------------------------------+-- |+-- Module      :  Properties+-- Copyright   :  (C) 2014 Ryan Scott+-- License     :  BSD-style (see the file LICENSE)+-- Maintainer  :  Ryan Scott+-- Stability   :  Experimental+-- Portability :  GHC+-- +-- @QuickCheck@ properties for functions that manipulate 'Builder's.+----------------------------------------------------------------------------+module Properties.Builder (builderTests) where++import Instances.BaseAndFriends ()++import Test.Tasty (TestTree, testGroup)+import Test.Tasty.QuickCheck (testProperty)++import Text.Show.Text (Builder, fromString, fromText, lengthB, replicateB,+                       singleton, toString, toText, unlinesB, unwordsB)++-- | Verifies 'lengthB' and 'length' produce the same output.+prop_lengthB :: String -> Bool+prop_lengthB s = fromIntegral (lengthB $ fromString s) == length s++-- | Verifies 'replicateB' and 'replicate' produce the same output.+prop_replicateB :: Int -> Char -> Bool+prop_replicateB i c = replicateB (fromIntegral i) (singleton c) == fromString (replicate i c)++-- | Verifies @fromText . toText = id@.+prop_toText :: Builder -> Bool+prop_toText b = fromText (toText b) == b++-- | Verifies @fromString . toString = id@.+prop_toString :: Builder -> Bool+prop_toString b = fromString (toString b) == b++-- | Verifies 'unlinesB' and 'unlines' produce the same output.+prop_unlinesB :: [String] -> Bool+prop_unlinesB strs = unlinesB (map fromString strs) == fromString (unlines strs)++-- | Verifies 'unwordsB' and 'unwords' produce the same output.+prop_unwordsB :: [String] -> Bool+prop_unwordsB strs = unwordsB (map fromString strs) == fromString (unwords strs)++builderTests :: [TestTree]+builderTests =+    [ testGroup "Builder-related functions"+        [ testProperty "lengthB output"             prop_lengthB+        , testProperty "replicateB output"          prop_replicateB+        , testProperty "fromString . toString = id" prop_toString+        , testProperty "fromText . toText = id"     prop_toText+        , testProperty "unlinesB output"            prop_unlinesB+        , testProperty "unwordsB output"            prop_unwordsB+        ]+    ]
text-show.cabal view
@@ -1,5 +1,5 @@ name:                text-show-version:             0.4+version:             0.4.1 synopsis:            Efficient conversion of values into Text description:         @text-show@ offers a replacement for the @Show@ typeclass intended                      for use with @Text@ instead of @String@s. This package was created@@ -150,6 +150,7 @@   other-modules:       Instances.BaseAndFriends                        Instances.Derived                        Properties.BaseAndFriends+                       Properties.Builder                        Properties.Derived                        Properties.MkShow                        Properties.Utils