diff options
author | Mike Gerwitz <gerwitzm@lovullo.com> | 2016-11-30 11:03:33 -0500 |
---|---|---|
committer | Mike Gerwitz <gerwitzm@lovullo.com> | 2016-12-01 08:43:46 -0500 |
commit | 5947e7646e2a0955a4ab799db69bdc909d8d0ea3 (patch) | |
tree | fd1555d534622d721cc1bd71585e3d7596f93f52 /test/validate | |
parent | 6db99c8632e7e61f6e96404344f2d48b518e8878 (diff) | |
download | liza-5947e7646e2a0955a4ab799db69bdc909d8d0ea3.tar.gz liza-5947e7646e2a0955a4ab799db69bdc909d8d0ea3.tar.bz2 liza-5947e7646e2a0955a4ab799db69bdc909d8d0ea3.zip |
Add scale to Number formatter
* src/validate/formatter/Number.js
(__mixin): Add mixin ctor.
(parse): Handle scale.
(styleNumber): Handle scale.
(scale, split): Add methods.
* test/validate/formatter/NumberTest.js: Modified accordingly.
Diffstat (limited to 'test/validate')
-rw-r--r-- | test/validate/formatter/NumberTest.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/validate/formatter/NumberTest.js b/test/validate/formatter/NumberTest.js index 74d2595..7945b70 100644 --- a/test/validate/formatter/NumberTest.js +++ b/test/validate/formatter/NumberTest.js @@ -27,8 +27,10 @@ var liza = require( '../../../' ), describe( 'validate.formatter.Number', function() { + // default case, no decimal places common.testValidate( EchoFormatter.use( Sut )(), { "1": [ "1", "1" ], + "001": [ "1", "1" ], "123": [ "123", "123" ], "12345": [ "12345", "12,345" ], "12,345": [ "12345", "12,345" ], @@ -36,6 +38,47 @@ describe( 'validate.formatter.Number', function() "12,345,": [ "12345", "12,345" ], " 12,345 ,": [ "12345", "12,345" ], " 1, ,": [ "1", "1" ], + + // strip decimals + "1.234": [ "1", "1" ], + " 1, ,.": [ "1", "1" ], + } ); + + + // decimal places + common.testValidate( EchoFormatter.use( Sut( 3 ) )(), { + "1": [ "1.000", "1.000" ], + "001": [ "1.000", "1.000" ], + "123": [ "123.000", "123.000" ], + "123.1": [ "123.100", "123.100" ], + "0123.1": [ "123.100", "123.100" ], + "123.155": [ "123.155", "123.155" ], + "123.": [ "123.000", "123.000" ], + ".123": [ "0.123", "0.123" ], + + // truncate, not round (leave that to another formatter) + "123.1554": [ "123.155", "123.155" ], + "123.1556": [ "123.155", "123.155" ], + + "12,345": [ "12345.000", "12,345.000" ], + " 1, ,.": [ "1.000", "1.000" ], + } ); + + + // really long decimals should be unstyled + common.testValidate( EchoFormatter.use( Sut( 10 ) )(), { + "0.1234567890": [ true, true ], + } ); + + + // negative scale strips trailing zeroes + common.testValidate( EchoFormatter.use( Sut( -5 ) )(), { + "1": [ "1", "1" ], + "01": [ "1", "1" ], + "1.0": [ "1", "1" ], + "1.0100": [ "1.01", "1.01" ], + "123.155": [ "123.155", "123.155" ], + "123.123456": [ "123.12345", "123.12345" ], } ); |