Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bv-little.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ library
, mono-traversable
, primitive
, QuickCheck
, text-show

if !impl(ghc >= 8.0)

Expand Down Expand Up @@ -109,6 +110,7 @@ Test-Suite test-suite
, tasty
, tasty-hunit
, tasty-quickcheck
, text-show

if !impl(ghc >= 8.0)

Expand Down
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### Unreleased Changes

* None
* Added textshow instance and tests for it


### [v0.1.2][1]
Expand Down
10 changes: 9 additions & 1 deletion src/Data/BitVector/LittleEndian.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
--
-----------------------------------------------------------------------------

{-# LANGUAGE BangPatterns, DeriveDataTypeable, DeriveGeneric, MagicHash #-}
{-# LANGUAGE BangPatterns, DeriveDataTypeable, DeriveGeneric, MagicHash, OverloadedStrings #-}
{-# LANGUAGE Trustworthy, TypeFamilies #-}

module Data.BitVector.LittleEndian
Expand Down Expand Up @@ -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))


-- |
Expand Down Expand Up @@ -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.
--
Expand Down
14 changes: 13 additions & 1 deletion test/TestSuite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand All @@ -39,6 +40,7 @@ testSuite = testGroup "BitVector tests"
, orderingProperties
, semigroupProperties
, showProperties
, textshowProperties
, bitVectorProperties
]

Expand Down Expand Up @@ -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"
Expand Down