diff --git a/bv-little.cabal b/bv-little.cabal index b86d01f..cf2632f 100644 --- a/bv-little.cabal +++ b/bv-little.cabal @@ -44,6 +44,7 @@ library , mono-traversable , primitive , QuickCheck + , text-show if !impl(ghc >= 8.0) @@ -109,6 +110,7 @@ Test-Suite test-suite , tasty , tasty-hunit , tasty-quickcheck + , text-show if !impl(ghc >= 8.0) diff --git a/changelog.md b/changelog.md index 36116ef..4e133c3 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,6 @@ ### Unreleased Changes - * None + * Added textshow instance and tests for it ### [v0.1.2][1] diff --git a/src/Data/BitVector/LittleEndian.hs b/src/Data/BitVector/LittleEndian.hs index 04a8ce6..09e80f0 100644 --- a/src/Data/BitVector/LittleEndian.hs +++ b/src/Data/BitVector/LittleEndian.hs @@ -36,7 +36,7 @@ -- ----------------------------------------------------------------------------- -{-# LANGUAGE BangPatterns, DeriveDataTypeable, DeriveGeneric, MagicHash #-} +{-# LANGUAGE BangPatterns, DeriveDataTypeable, DeriveGeneric, MagicHash, OverloadedStrings #-} {-# LANGUAGE Trustworthy, TypeFamilies #-} module Data.BitVector.LittleEndian @@ -73,6 +73,7 @@ import GHC.Integer.GMP.Internals import GHC.Integer.Logarithms import GHC.Natural import Test.QuickCheck (Arbitrary(..), CoArbitrary(..), NonNegative(..), suchThat, variant) +import TextShow(TextShow(showb)) -- | @@ -393,6 +394,13 @@ instance Show BitVector where show (BV w n) = mconcat [ "[", show w, "]", show n ] +-- | +-- /Since: ?.?.?.? / +instance TextShow BitVector where + + showb (BV w n) = mconcat [ "[", showb w, "]", showb n ] + + -- | -- Create a bit vector from a /little-endian/ list of bits. -- diff --git a/test/TestSuite.hs b/test/TestSuite.hs index 8d85863..5942597 100644 --- a/test/TestSuite.hs +++ b/test/TestSuite.hs @@ -20,6 +20,7 @@ import Data.Semigroup import Test.Tasty import Test.Tasty.HUnit import Test.Tasty.QuickCheck hiding ((.&.)) +import TextShow (TextShow(showb), toString) main :: IO () @@ -39,6 +40,7 @@ testSuite = testGroup "BitVector tests" , orderingProperties , semigroupProperties , showProperties + , textshowProperties , bitVectorProperties ] @@ -391,7 +393,17 @@ showProperties = testGroup "Properties of Show" nonNullString :: BitVector -> Bool nonNullString = not . null . show - + +textshowProperties :: TestTree +textshowProperties = testGroup "Properties of TextShow" + [ testProperty "textshow and show result agree" textshowCoherence + ] + where + textshowCoherence :: BitVector -> Property + textshowCoherence bv = + (toString . showb $ bv) === show bv + + bitVectorProperties :: TestTree bitVectorProperties = testGroup "BitVector properties"