-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add paddedDecimal, for zero-padding.
This doesn't currently specialise as well as `decimal`, but it should be easy to give it an analogous structure if that would help. In the absence of benchmarks, I've left it in the simpler form.
- Loading branch information
1 parent
09971cf
commit 551a092
Showing
6 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
-- | Tests for specific cases. | ||
-- | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module Tests.Unit | ||
( | ||
tests | ||
) where | ||
|
||
import Data.Int (Int8) | ||
import Test.HUnit ((@?=)) | ||
import qualified Data.Text.Lazy as TL | ||
import qualified Data.Text.Lazy.Builder as TB | ||
import qualified Data.Text.Lazy.Builder.Int as Int | ||
import qualified Test.Framework as F | ||
import qualified Test.Framework.Providers.HUnit as F | ||
|
||
paddedDecimalTests :: F.Test | ||
paddedDecimalTests = F.testGroup "paddedDecimal" | ||
[ tI 3 12 "012" | ||
, tI 3 1234 "1234" | ||
, tI 3 (-123) "-123" | ||
, tI 3 (-12) "-012" | ||
, tI 3 0 "000" | ||
, tI 0 0 "0" | ||
, tI 3 10 "010" | ||
, tI 3 (-10) "-010" | ||
, tI 3 (-1) "-001" | ||
, tI 7 1234 "0001234" | ||
, tI (-3) 12 "12" | ||
, tI 1 (-3) "-3" | ||
, tI8 5 (-128) "-00128" | ||
, tI8 3 (-128) "-128" | ||
, tI8 2 (-128) "-128" | ||
] | ||
where | ||
tI :: Int -> Int -> TL.Text -> F.Test | ||
tI padLen input expected = F.testCase ("Int " ++ show (padLen, input)) $ | ||
TB.toLazyText (Int.paddedDecimal padLen input) @?= expected | ||
|
||
tI8 :: Int -> Int8 -> TL.Text -> F.Test | ||
tI8 padLen input expected = F.testCase ("Int8 " ++ show (padLen, input)) $ | ||
TB.toLazyText (Int.paddedDecimal padLen input) @?= expected | ||
|
||
tests :: F.Test | ||
tests = F.testGroup "unit tests" | ||
[ paddedDecimalTests | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters