diff --git a/packages.dhall b/packages.dhall index 3c3fffa..b29971f 100644 --- a/packages.dhall +++ b/packages.dhall @@ -173,7 +173,7 @@ let additions = , "web-uievents" ] , repo = "https://github.com/input-output-hk/purescript-web-common" - , version = "v1.1.0" + , version = "v1.1.1" } } diff --git a/src/Text/Pretty.purs b/src/Text/Pretty.purs index 280c325..736a3f4 100644 --- a/src/Text/Pretty.purs +++ b/src/Text/Pretty.purs @@ -17,6 +17,7 @@ module Text.Pretty import Prelude import Data.BigInt.Argonaut (BigInt) +import Data.BigInt.Argonaut as BigInt import Data.Foldable (any, intercalate) import Data.Generic.Rep (class Generic, Argument(..), Constructor(..), NoArguments, Product(..), Sum(..), from) import Data.String.Extra (repeat) @@ -62,7 +63,7 @@ instance prettyString :: Pretty String where pretty = text <<< show instance prettyBigInt :: Pretty BigInt where - pretty = text <<< show + pretty = text <<< BigInt.toString instance prettyNoArguments :: Pretty NoArguments where pretty _ = mempty diff --git a/test/Data/BigInt/Argonaut/Spec.purs b/test/Data/BigInt/Argonaut/Spec.purs index 5aa6ece..eb68a51 100644 --- a/test/Data/BigInt/Argonaut/Spec.purs +++ b/test/Data/BigInt/Argonaut/Spec.purs @@ -8,17 +8,24 @@ import Data.Argonaut.Decode (JsonDecodeError) import Data.Argonaut.Extra (encodeStringifyJson, parseDecodeJson) import Data.BigInt as BI import Data.BigInt.Argonaut (BigInt, fromInt, withJsonPatch) +import Data.BigInt.Argonaut as BigInt +import Data.Generic.Rep (class Generic) import Data.Newtype (unwrap) import Data.String (codePointFromChar, dropWhile, null) import Data.String.Gen (genDigitString) import Test.QuickCheck (class Arbitrary, (===)) import Test.QuickCheck.Gen (suchThat) import Test.Spec (Spec, around_, describe, it) -import Test.Spec.Assertions (shouldNotEqual) +import Test.Spec.Assertions (shouldEqual, shouldNotEqual) import Test.Spec.QuickCheck (quickCheck) +import Text.Pretty (genericPretty, pretty) newtype DigitString = DigitString String +data TestData = TestData String BigInt + +derive instance genericTestData :: Generic TestData _ + instance arbitraryDigitString :: Arbitrary DigitString where arbitrary = map DigitString @@ -52,3 +59,11 @@ bigIntSpec = (unwrap <<< add (fromInt 10)) <$> decoded === (add (BI.fromInt 10) <<< unwrap) <$> decoded + it "Renders prettily as just the integer value" do + show (pretty $ BigInt.fromInt 10) `shouldEqual` "10" + it "Renders from withing genericPretty" do + show (genericPretty $ TestData "hello" $ BigInt.fromInt 10) + `shouldEqual` + "TestData \"hello\" 10" + it "Renders with \"fromString\" with show" do + show (BigInt.fromInt 10) `shouldEqual` "fromString \"10\""