text-builder-dev 0.3.9.1 → 0.3.10
raw patch · 7 files changed
+189/−225 lines, 7 filesdep ~criteriondep ~rerebase
Dependency ranges changed: criterion, rerebase
Files
- bench/Main.hs +78/−0
- benchmark-char/Main.hs +0/−58
- benchmark-text/Main.hs +0/−57
- library/TextBuilderDev.hs +44/−36
- library/TextBuilderDev/Prelude.hs +0/−1
- test/Main.hs +51/−51
- text-builder-dev.cabal +16/−22
+ bench/Main.hs view
@@ -0,0 +1,78 @@+module Main where++import Criterion.Main+import qualified Data.Text.Lazy as C+import qualified Data.Text.Lazy.Builder as B+import qualified TextBuilderDev as A+import Prelude++main :: IO ()+main =+ defaultMain+ [ bgroup+ "Left-biased mappend"+ let {-# NOINLINE sampleBySize #-}+ sampleBySize :: (Monoid a, IsString a) => Int -> (a -> Text) -> Text+ sampleBySize size compile =+ "фывапролдж"+ & replicate size+ & foldl' (<>) mempty+ & compile+ in [ bgroup+ "1kB"+ let sample = sampleBySize 100+ in [ bench "TextBuilderDev" (nf sample A.toText),+ bench "Data.Text.Lazy.Builder" (nf sample (C.toStrict . B.toLazyText))+ ],+ bgroup+ "1MB"+ let sample = sampleBySize 100_000+ in [ bench "TextBuilderDev" (nf sample A.toText),+ bench "Data.Text.Lazy.Builder" (nf sample (C.toStrict . B.toLazyText))+ ]+ ],+ bgroup+ "Right-biased mappend"+ let {-# NOINLINE sampleBySize #-}+ sampleBySize :: (Monoid a, IsString a) => Int -> (a -> Text) -> Text+ sampleBySize size compile =+ "фывапролдж"+ & replicate size+ & foldl' (flip (<>)) mempty+ & compile+ in [ bgroup+ "1kB"+ let sample = sampleBySize 100+ in [ bench "TextBuilderDev" (nf sample A.toText),+ bench "Data.Text.Lazy.Builder" (nf sample (C.toStrict . B.toLazyText))+ ],+ bgroup+ "1MB"+ let sample = sampleBySize 100_000+ in [ bench "TextBuilderDev" (nf sample A.toText),+ bench "Data.Text.Lazy.Builder" (nf sample (C.toStrict . B.toLazyText))+ ]+ ],+ bgroup+ "mconcat"+ let {-# NOINLINE sampleBySize #-}+ sampleBySize :: (Monoid a, IsString a) => Int -> (a -> Text) -> Text+ sampleBySize size compile =+ "фывапролдж"+ & replicate size+ & mconcat+ & compile+ in [ bgroup+ "1kB"+ let sample = sampleBySize 100+ in [ bench "TextBuilderDev" (nf sample A.toText),+ bench "Data.Text.Lazy.Builder" (nf sample (C.toStrict . B.toLazyText))+ ],+ bgroup+ "1MB"+ let sample = sampleBySize 100_000+ in [ bench "TextBuilderDev" (nf sample A.toText),+ bench "Data.Text.Lazy.Builder" (nf sample (C.toStrict . B.toLazyText))+ ]+ ]+ ]
− benchmark-char/Main.hs
@@ -1,58 +0,0 @@-module Main where--import Criterion.Main-import qualified Data.Text as D-import qualified Data.Text.Lazy as C-import qualified Data.Text.Lazy.Builder as B-import qualified TextBuilderDev as A-import Prelude--main :: IO ()-main =- defaultMain- $ [ subjectBenchmark "builderSubject" builderSubject,- subjectBenchmark "lazyTextBuilderDevSubject" lazyTextBuilderDevSubject,- subjectBenchmark "plainTextPackingSubject" plainTextPackingSubject- ]--subjectBenchmark :: String -> Subject -> Benchmark-subjectBenchmark title subject =- bgroup title- $ [ benchmark "Small input" smallInput subject,- benchmark "Medium input" mediumInput subject,- benchmark "Large input" largeInput subject- ]--benchmark :: String -> [Int] -> Subject -> Benchmark-benchmark title input subject =- bench title $ nf subject $ input--type Subject =- [Int] -> Text--builderSubject :: Subject-builderSubject =- A.buildText . A.string . map chr--lazyTextBuilderDevSubject :: Subject-lazyTextBuilderDevSubject =- C.toStrict . B.toLazyText . B.fromString . map chr--plainTextPackingSubject :: Subject-plainTextPackingSubject =- D.pack . map chr--{-# NOINLINE smallInput #-}-smallInput :: [Int]-smallInput =- map ord ['a', 'b', 'Ф', '漢', chr 0x11000]--{-# NOINLINE mediumInput #-}-mediumInput :: [Int]-mediumInput =- mconcat (replicate 1000 smallInput)--{-# NOINLINE largeInput #-}-largeInput :: [Int]-largeInput =- mconcat (replicate 100000 smallInput)
− benchmark-text/Main.hs
@@ -1,57 +0,0 @@-module Main where--import Criterion.Main-import qualified Data.Text.Lazy as C-import qualified Data.Text.Lazy.Builder as B-import qualified TextBuilderDev as A-import Prelude--main :: IO ()-main =- defaultMain- $ [ subjectBenchmark "builderSubject" builderSubject,- subjectBenchmark "lazyTextBuilderDevSubject" lazyTextBuilderDevSubject- ]--subjectBenchmark :: String -> Subject -> Benchmark-subjectBenchmark title subject =- bgroup title- $ [ benchmark "Small input" smallSample subject,- benchmark "Large input" largeSample subject- ]--benchmark :: String -> Sample -> Subject -> Benchmark-benchmark title sample subject =- bench title $ nf sample $ subject--data Subject- = forall a. Subject (Text -> a) (a -> a -> a) a (a -> Text)--type Sample =- Subject -> Text--builderSubject :: Subject-builderSubject =- Subject A.text mappend mempty A.buildText--lazyTextBuilderDevSubject :: Subject-lazyTextBuilderDevSubject =- Subject B.fromText mappend mempty (C.toStrict . B.toLazyText)--{-# NOINLINE smallSample #-}-smallSample :: Sample-smallSample (Subject text (<>) _ run) =- run- $ text "abcd"- <> (text "ABCD" <> text "Фываолдж")- <> text "漢"--{-# NOINLINE largeSample #-}-largeSample :: Sample-largeSample (Subject text (<>) mempty run) =- run- $ foldl' (<>) mempty- $ replicate 100000- $ text "abcd"- <> (text "ABCD" <> text "Фываолдж")- <> text "漢"
library/TextBuilderDev.hs view
@@ -4,6 +4,7 @@ ( TextBuilder, -- * Accessors+ toText, buildText, length, null,@@ -88,6 +89,7 @@ import qualified Data.Text.Lazy as TextLazy import qualified Data.Text.Lazy.Builder as TextLazyBuilder import qualified DeferredFolds.Unfoldr as Unfoldr+import qualified IsomorphismClass import qualified LawfulConversions import qualified Test.QuickCheck.Gen as QcGen import qualified TextBuilderDev.Allocator as Allocator@@ -157,10 +159,10 @@ fromString = string instance Show TextBuilder where- show = Text.unpack . buildText+ show = Text.unpack . toText instance Eq TextBuilder where- (==) = on (==) buildText+ (==) = on (==) toText instance Arbitrary TextBuilder where arbitrary =@@ -201,19 +203,19 @@ instance IsomorphicToTextBuilder Text where toTextBuilder = text- fromTextBuilder = buildText+ fromTextBuilder = toText -instance IsomorphicTo TextBuilder Text where+instance IsomorphismClass.IsomorphicTo TextBuilder Text where to = TextBuilderDev.text -instance IsomorphicTo Text TextBuilder where- to = TextBuilderDev.buildText+instance IsomorphismClass.IsomorphicTo Text TextBuilder where+ to = TextBuilderDev.toText instance LawfulConversions.IsSome TextBuilder Text where to = TextBuilderDev.text instance LawfulConversions.IsSome Text TextBuilder where- to = TextBuilderDev.buildText+ to = TextBuilderDev.toText instance LawfulConversions.IsMany TextBuilder Text @@ -227,10 +229,10 @@ instance IsomorphicToTextBuilder String where toTextBuilder = fromString- fromTextBuilder = Text.unpack . buildText+ fromTextBuilder = Text.unpack . toText instance LawfulConversions.IsSome String TextBuilder where- to = Text.unpack . buildText+ to = Text.unpack . toText maybeFrom = fmap text . LawfulConversions.maybeFrom instance LawfulConversions.IsMany String TextBuilder where@@ -240,19 +242,19 @@ instance IsomorphicToTextBuilder TextLazy.Text where toTextBuilder = lazyText- fromTextBuilder = TextLazy.fromStrict . buildText+ fromTextBuilder = TextLazy.fromStrict . toText -instance IsomorphicTo TextBuilder TextLazy.Text where+instance IsomorphismClass.IsomorphicTo TextBuilder TextLazy.Text where to = TextBuilderDev.lazyText -instance IsomorphicTo TextLazy.Text TextBuilder where- to = to . to @Text+instance IsomorphismClass.IsomorphicTo TextLazy.Text TextBuilder where+ to = IsomorphismClass.to . IsomorphismClass.to @Text instance LawfulConversions.IsSome TextBuilder TextLazy.Text where to = lazyText instance LawfulConversions.IsSome TextLazy.Text TextBuilder where- to = TextLazy.fromStrict . buildText+ to = TextLazy.fromStrict . toText instance LawfulConversions.IsMany TextBuilder TextLazy.Text @@ -266,19 +268,19 @@ instance IsomorphicToTextBuilder TextLazyBuilder.Builder where toTextBuilder = text . TextLazy.toStrict . TextLazyBuilder.toLazyText- fromTextBuilder = TextLazyBuilder.fromText . buildText+ fromTextBuilder = TextLazyBuilder.fromText . toText -instance IsomorphicTo TextBuilder TextLazyBuilder.Builder where- to = to . to @TextLazy.Text+instance IsomorphismClass.IsomorphicTo TextBuilder TextLazyBuilder.Builder where+ to = IsomorphismClass.to . IsomorphismClass.to @TextLazy.Text -instance IsomorphicTo TextLazyBuilder.Builder TextBuilder where- to = to . to @Text+instance IsomorphismClass.IsomorphicTo TextLazyBuilder.Builder TextBuilder where+ to = IsomorphismClass.to . IsomorphismClass.to @Text instance LawfulConversions.IsSome TextBuilder TextLazyBuilder.Builder where to = text . TextLazy.toStrict . TextLazyBuilder.toLazyText instance LawfulConversions.IsSome TextLazyBuilder.Builder TextBuilder where- to = TextLazyBuilder.fromText . buildText+ to = TextLazyBuilder.fromText . toText instance LawfulConversions.IsMany TextBuilder TextLazyBuilder.Builder @@ -296,11 +298,11 @@ toTextBuilder = toTextBuilder . TextEncoding.strictBuilderToText fromTextBuilder = TextEncoding.textToStrictBuilder . fromTextBuilder -instance IsomorphicTo TextBuilder TextEncoding.StrictTextBuilder where- to = to . TextEncoding.strictBuilderToText+instance IsomorphismClass.IsomorphicTo TextBuilder TextEncoding.StrictTextBuilder where+ to = IsomorphismClass.to . TextEncoding.strictBuilderToText -instance IsomorphicTo TextEncoding.StrictTextBuilder TextBuilder where- to = TextEncoding.textToStrictBuilder . to+instance IsomorphismClass.IsomorphicTo TextEncoding.StrictTextBuilder TextBuilder where+ to = TextEncoding.textToStrictBuilder . IsomorphismClass.to instance LawfulConversions.IsSome TextBuilder TextEncoding.StrictTextBuilder where to = toTextBuilder . TextEncoding.strictBuilderToText@@ -322,11 +324,11 @@ toTextBuilder = toTextBuilder . TextEncoding.strictBuilderToText fromTextBuilder = TextEncoding.textToStrictBuilder . fromTextBuilder -instance IsomorphicTo TextBuilder TextEncoding.StrictBuilder where- to = to . TextEncoding.strictBuilderToText+instance IsomorphismClass.IsomorphicTo TextBuilder TextEncoding.StrictBuilder where+ to = IsomorphismClass.to . TextEncoding.strictBuilderToText -instance IsomorphicTo TextEncoding.StrictBuilder TextBuilder where- to = TextEncoding.textToStrictBuilder . to+instance IsomorphismClass.IsomorphicTo TextEncoding.StrictBuilder TextBuilder where+ to = TextEncoding.textToStrictBuilder . IsomorphismClass.to instance LawfulConversions.IsSome TextBuilder TextEncoding.StrictBuilder where to = toTextBuilder . TextEncoding.strictBuilderToText@@ -356,28 +358,34 @@ null :: TextBuilder -> Bool null = (== 0) . length --- | Execute a builder producing a strict text.-buildText :: TextBuilder -> Text-buildText (TextBuilder allocator _) =+-- | Execute the builder producing a strict text.+toText :: TextBuilder -> Text+toText (TextBuilder allocator _) = Allocator.allocate allocator +{-# DEPRECATED buildText "Use toText instead" #-}++-- | Alias to 'toText'.+buildText :: TextBuilder -> Text+buildText = toText+ -- ** Output IO -- | Put builder, to stdout. putToStdOut :: TextBuilder -> IO ()-putToStdOut = Text.hPutStr stdout . buildText+putToStdOut = Text.hPutStr stdout . toText -- | Put builder, to stderr. putToStdErr :: TextBuilder -> IO ()-putToStdErr = Text.hPutStr stderr . buildText+putToStdErr = Text.hPutStr stderr . toText -- | Put builder, followed by a line, to stdout. putLnToStdOut :: TextBuilder -> IO ()-putLnToStdOut = Text.hPutStrLn stdout . buildText+putLnToStdOut = Text.hPutStrLn stdout . toText -- | Put builder, followed by a line, to stderr. putLnToStdErr :: TextBuilder -> IO ()-putLnToStdErr = Text.hPutStrLn stderr . buildText+putLnToStdErr = Text.hPutStrLn stderr . toText -- * Constructors @@ -389,7 +397,7 @@ -- since it's virtually a single call @memcopy@. {-# INLINE force #-} force :: TextBuilder -> TextBuilder-force = text . buildText+force = text . toText -- | Unicode character. {-# INLINE char #-}
library/TextBuilderDev/Prelude.hs view
@@ -62,7 +62,6 @@ import GHC.Exts as Exports (groupWith, inline, lazy, sortWith) import GHC.Generics as Exports (Generic) import GHC.IO.Exception as Exports-import IsomorphismClass as Exports import Numeric as Exports import Numeric.Natural as Exports (Natural) import System.Environment as Exports
test/Main.hs view
@@ -27,44 +27,44 @@ return (ByteString.pack list) in forAll gen $ \chunks -> mconcat chunks- === Text.encodeUtf8 (B.buildText (foldMap B.asciiByteString chunks)),+ === Text.encodeUtf8 (B.toText (foldMap B.asciiByteString chunks)), testProperty "Intercalation has the same effect as in Text" $ \separator texts -> Text.intercalate separator texts- === B.buildText (B.intercalate (B.text separator) (fmap B.text texts)),+ === B.toText (B.intercalate (B.text separator) (fmap B.text texts)), testProperty "intercalateMap sep mapper == intercalate sep . fmap mapper" $ \separator ints -> Text.intercalate separator (fmap (fromString . show @Int) ints)- === B.buildText (B.intercalateMap (B.text separator) B.decimal ints),+ === B.toText (B.intercalateMap (B.text separator) B.decimal ints), testProperty "Packing a list of chars is isomorphic to appending a list of builders" $ \chars -> Text.pack chars- === B.buildText (foldMap B.char chars),+ === B.toText (foldMap B.char chars), testProperty "Concatting a list of texts is isomorphic to fold-mapping with builders" $ \texts -> mconcat texts- === B.buildText (foldMap B.text texts),+ === B.toText (foldMap B.text texts), testProperty "Concatting a list of texts is isomorphic to concatting a list of builders" $ \texts -> mconcat texts- === B.buildText (mconcat (map B.text texts)),+ === B.toText (mconcat (map B.text texts)), testProperty "Concatting a list of trimmed texts is isomorphic to concatting a list of builders" $ \texts -> let trimmedTexts = fmap (Text.drop 3) texts in mconcat trimmedTexts- === B.buildText (mconcat (map B.text trimmedTexts)),+ === B.toText (mconcat (map B.text trimmedTexts)), testProperty "TextBuilderDev.null is isomorphic to Text.null" $ \(text :: Text) -> B.null (B.toTextBuilder text) === Text.null text, testProperty "(TextBuilderDev.unicodeCodePoint <>) is isomorphic to Text.cons" $ withMaxSuccess bigTest $ \(text :: Text) (c :: Char) ->- B.buildText (B.unicodeCodePoint (Char.ord c) <> B.text text) === Text.cons c text,+ B.toText (B.unicodeCodePoint (Char.ord c) <> B.text text) === Text.cons c text, testGroup "Time interval"- $ [ testCase "59s" $ assertEqual "" "00:00:00:59" $ B.buildText $ B.intervalInSeconds @Double 59,- testCase "minute" $ assertEqual "" "00:00:01:00" $ B.buildText $ B.intervalInSeconds @Double 60,- testCase "90s" $ assertEqual "" "00:00:01:30" $ B.buildText $ B.intervalInSeconds @Double 90,- testCase "hour" $ assertEqual "" "00:01:00:00" $ B.buildText $ B.intervalInSeconds @Double 3600,- testCase "day" $ assertEqual "" "01:00:00:00" $ B.buildText $ B.intervalInSeconds @Double 86400+ $ [ testCase "59s" $ assertEqual "" "00:00:00:59" $ B.toText $ B.intervalInSeconds @Double 59,+ testCase "minute" $ assertEqual "" "00:00:01:00" $ B.toText $ B.intervalInSeconds @Double 60,+ testCase "90s" $ assertEqual "" "00:00:01:30" $ B.toText $ B.intervalInSeconds @Double 90,+ testCase "hour" $ assertEqual "" "00:01:00:00" $ B.toText $ B.intervalInSeconds @Double 3600,+ testCase "day" $ assertEqual "" "01:00:00:00" $ B.toText $ B.intervalInSeconds @Double 86400 ], testGroup "By function name" $ [ testGroup "utf8CodeUnitsN"@@ -81,7 +81,7 @@ -- Use Data.Text.Encoding for comparison codeUnits = Text.encodeUtf8 $ Text.singleton c cuAt = (codeUnits `ByteString.index`)- in B.buildText (cuBuilder <> B.text text) === Text.cons c text,+ in B.toText (cuBuilder <> B.text text) === Text.cons c text, testProperty "Text.singleton isomorphism" $ withMaxSuccess bigTest $ \(c :: Char) ->@@ -95,7 +95,7 @@ | otherwise = B.utf8CodeUnits4 (cuAt 0) (cuAt 1) (cuAt 2) (cuAt 3) where cuAt = ByteString.index codeUnits- in B.buildText cuBuilder === text+ in B.toText cuBuilder === text ], testGroup "utf16CodeUnitsN" $ [ testProperty "is isomorphic to Text.cons"@@ -111,61 +111,61 @@ cuAt i = (fromIntegral $ codeUnits `ByteString.index` (2 * i)) .|. ((fromIntegral $ codeUnits `ByteString.index` (2 * i + 1)) `shiftL` 8)- in B.buildText (cuBuilder <> B.text text) === Text.cons c text+ in B.toText (cuBuilder <> B.text text) === Text.cons c text ], testCase "thousandSeparatedUnsignedDecimal" $ do- assertEqual "" "0" (B.buildText (B.thousandSeparatedUnsignedDecimal @Integer ',' 0))- assertEqual "" "123" (B.buildText (B.thousandSeparatedUnsignedDecimal @Integer ',' 123))- assertEqual "" "1,234" (B.buildText (B.thousandSeparatedUnsignedDecimal @Integer ',' 1234))- assertEqual "" "1,234,567" (B.buildText (B.thousandSeparatedUnsignedDecimal @Integer ',' 1234567)),+ assertEqual "" "0" (B.toText (B.thousandSeparatedUnsignedDecimal @Integer ',' 0))+ assertEqual "" "123" (B.toText (B.thousandSeparatedUnsignedDecimal @Integer ',' 123))+ assertEqual "" "1,234" (B.toText (B.thousandSeparatedUnsignedDecimal @Integer ',' 1234))+ assertEqual "" "1,234,567" (B.toText (B.thousandSeparatedUnsignedDecimal @Integer ',' 1234567)), testCase "padFromLeft" $ do- assertEqual "" "00" (B.buildText (B.padFromLeft 2 '0' ""))- assertEqual "" "00" (B.buildText (B.padFromLeft 2 '0' "0"))- assertEqual "" "01" (B.buildText (B.padFromLeft 2 '0' "1"))- assertEqual "" "12" (B.buildText (B.padFromLeft 2 '0' "12"))- assertEqual "" "123" (B.buildText (B.padFromLeft 2 '0' "123")),+ assertEqual "" "00" (B.toText (B.padFromLeft 2 '0' ""))+ assertEqual "" "00" (B.toText (B.padFromLeft 2 '0' "0"))+ assertEqual "" "01" (B.toText (B.padFromLeft 2 '0' "1"))+ assertEqual "" "12" (B.toText (B.padFromLeft 2 '0' "12"))+ assertEqual "" "123" (B.toText (B.padFromLeft 2 '0' "123")), testCase "padFromRight" $ do- assertEqual "" "00" (B.buildText (B.padFromRight 2 '0' ""))- assertEqual "" "00" (B.buildText (B.padFromRight 2 '0' "0"))- assertEqual "" "10" (B.buildText (B.padFromRight 2 '0' "1"))- assertEqual "" "12" (B.buildText (B.padFromRight 2 '0' "12"))- assertEqual "" "123" (B.buildText (B.padFromRight 2 '0' "123"))- assertEqual "" "1 " (B.buildText (B.padFromRight 3 ' ' "1")),+ assertEqual "" "00" (B.toText (B.padFromRight 2 '0' ""))+ assertEqual "" "00" (B.toText (B.padFromRight 2 '0' "0"))+ assertEqual "" "10" (B.toText (B.padFromRight 2 '0' "1"))+ assertEqual "" "12" (B.toText (B.padFromRight 2 '0' "12"))+ assertEqual "" "123" (B.toText (B.padFromRight 2 '0' "123"))+ assertEqual "" "1 " (B.toText (B.padFromRight 3 ' ' "1")), testProperty "decimal" $ \(x :: Integer) ->- (fromString . show) x === (B.buildText (B.decimal x)),+ (fromString . show) x === (B.toText (B.decimal x)), testGroup "hexadecimal" $ [ testProperty "show isomorphism" $ \(x :: Integer) -> x >= 0 ==>- (fromString . showHex x) "" === (B.buildText . B.hexadecimal @Integer) x,+ (fromString . showHex x) "" === (B.toText . B.hexadecimal @Integer) x, testCase "Positive"- $ assertEqual "" "1f23" (B.buildText (B.hexadecimal @Integer 0x01f23)),+ $ assertEqual "" "1f23" (B.toText (B.hexadecimal @Integer 0x01f23)), testCase "Negative"- $ assertEqual "" "-1f23" (B.buildText (B.hexadecimal @Integer (-0x01f23)))+ $ assertEqual "" "-1f23" (B.toText (B.hexadecimal @Integer (-0x01f23))) ], testCase "dataSizeInBytesInDecimal" $ do- assertEqual "" "999B" (B.buildText (B.dataSizeInBytesInDecimal @Integer ',' 999))- assertEqual "" "1kB" (B.buildText (B.dataSizeInBytesInDecimal @Integer ',' 1000))- assertEqual "" "1.1kB" (B.buildText (B.dataSizeInBytesInDecimal @Integer ',' 1100))- assertEqual "" "1.1MB" (B.buildText (B.dataSizeInBytesInDecimal @Integer ',' 1150000))- assertEqual "" "9.9MB" (B.buildText (B.dataSizeInBytesInDecimal @Integer ',' 9990000))- assertEqual "" "10MB" (B.buildText (B.dataSizeInBytesInDecimal @Integer ',' 10100000))- assertEqual "" "1,000YB" (B.buildText (B.dataSizeInBytesInDecimal @Integer ',' 1000000000000000000000000000)),+ assertEqual "" "999B" (B.toText (B.dataSizeInBytesInDecimal @Integer ',' 999))+ assertEqual "" "1kB" (B.toText (B.dataSizeInBytesInDecimal @Integer ',' 1000))+ assertEqual "" "1.1kB" (B.toText (B.dataSizeInBytesInDecimal @Integer ',' 1100))+ assertEqual "" "1.1MB" (B.toText (B.dataSizeInBytesInDecimal @Integer ',' 1150000))+ assertEqual "" "9.9MB" (B.toText (B.dataSizeInBytesInDecimal @Integer ',' 9990000))+ assertEqual "" "10MB" (B.toText (B.dataSizeInBytesInDecimal @Integer ',' 10100000))+ assertEqual "" "1,000YB" (B.toText (B.dataSizeInBytesInDecimal @Integer ',' 1000000000000000000000000000)), testCase "fixedDouble" $ do- assertEqual "" "0.0" (B.buildText (B.fixedDouble 1 0.05))- assertEqual "" "0.1" (B.buildText (B.fixedDouble 1 0.06))- assertEqual "" "10.0000" (B.buildText (B.fixedDouble 4 10))- assertEqual "" "0.9000" (B.buildText (B.fixedDouble 4 0.9)),+ assertEqual "" "0.0" (B.toText (B.fixedDouble 1 0.05))+ assertEqual "" "0.1" (B.toText (B.fixedDouble 1 0.06))+ assertEqual "" "10.0000" (B.toText (B.fixedDouble 4 10))+ assertEqual "" "0.9000" (B.toText (B.fixedDouble 4 0.9)), testCase "doublePercent" $ do- assertEqual "" "90.4%" (B.buildText (B.doublePercent 1 0.904)),+ assertEqual "" "90.4%" (B.toText (B.doublePercent 1 0.904)), testGroup "unsignedBinary" $ [ testProperty "Produces the same output as showBin" $ \(x :: Natural) -> fromString (showBin x "")- === B.buildText (B.unsignedBinary x)+ === B.toText (B.unsignedBinary x) ], testGroup "finiteBitsUnsignedBinary" $ [ testProperty "Produces the same output as showBin" $ \(x :: Word) -> fromString (showBin x "")- === B.buildText (B.finiteBitsUnsignedBinary x)+ === B.toText (B.finiteBitsUnsignedBinary x) ], testGroup "fixedUnsignedDecimal" $ [ testProperty "Same as printf" $ \(size :: Word8, val :: Natural) ->@@ -177,14 +177,14 @@ then drop (renderedLength - intSize) rendered else replicate (intSize - renderedLength) '0' <> rendered in fromString padded- === B.buildText (B.fixedUnsignedDecimal (fromIntegral size) val)+ === B.toText (B.fixedUnsignedDecimal (fromIntegral size) val) ], testGroup "utcTimeInIso8601" $ [ testProperty "Same as iso8601Show" $ \x -> let roundedToSecondsTime = x {utctDayTime = (fromIntegral @Int . round . utctDayTime) x} in (fromString . flip mappend "Z" . take 19 . iso8601Show) roundedToSecondsTime- === B.buildText (B.utcTimeInIso8601 roundedToSecondsTime)+ === B.toText (B.utcTimeInIso8601 roundedToSecondsTime) ] ], testGroup "IsomorphicToTextBuilder instances"
text-builder-dev.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: text-builder-dev-version: 0.3.9.1+version: 0.3.10 category: Text, Builders synopsis: Edge of developments for "text-builder" description:@@ -22,9 +22,11 @@ type: git location: https://github.com/nikita-volkov/text-builder-dev -common base-settings+common base+ default-language: Haskell2010 default-extensions: BangPatterns+ BlockArguments ConstraintKinds DataKinds DefaultSignatures@@ -39,7 +41,6 @@ FunctionalDependencies GADTs GeneralizedNewtypeDeriving- InstanceSigs LambdaCase LiberalTypeSynonyms MagicHash@@ -61,12 +62,11 @@ TypeApplications TypeFamilies TypeOperators+ UnboxedTuples ViewPatterns - default-language: Haskell2010- library- import: base-settings+ import: base hs-source-dirs: library exposed-modules: TextBuilderDev other-modules:@@ -90,7 +90,7 @@ transformers >=0.5 && <0.7, test-suite test- import: base-settings+ import: base type: exitcode-stdio-1.0 hs-source-dirs: test main-is: Main.hs@@ -106,24 +106,18 @@ tasty-quickcheck >=0.10.1 && <0.12, text-builder-dev, -benchmark benchmark-text- import: base-settings+benchmark bench+ import: base type: exitcode-stdio-1.0- ghc-options: -O2- hs-source-dirs: benchmark-text- main-is: Main.hs- build-depends:- criterion >=1.5.13.0 && <2,- rerebase >=1 && <2,- text-builder-dev,+ hs-source-dirs: bench+ ghc-options:+ -O2+ -threaded+ -with-rtsopts=-N+ -funbox-strict-fields -benchmark benchmark-char- import: base-settings- type: exitcode-stdio-1.0- ghc-options: -O2- hs-source-dirs: benchmark-char main-is: Main.hs build-depends:- criterion >=1.5.13.0 && <2,+ criterion >=1.5.6.1 && <2, rerebase >=1 && <2, text-builder-dev,