123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- /**
- * Created by Tony on 2017/4/7.
- */
- var test = require('tape');
- var strUtil = require('../../public/stringUtil');
- //test('some string test cases', function (t) {
- // var reg = /^\s*$/;
- // var foo = " ";
- // t.equal(reg.test(foo), true);
- // foo = null;
- // t.equal(reg.test(foo), true);
- // foo = undefined;
- // t.equal(reg.test(foo), true);
- // foo = "";
- // t.equal(reg.test(foo), true);
- // foo = 0;
- // t.equal(reg.test(foo), true);
- // t.end();
- //});
- //
- //test('check if string type', function(t){
- // var foo = "";
- // t.equal(typeof foo, 'string');
- // foo = " ";
- // t.equal(typeof foo, 'string');
- // foo = 0;
- // t.equal(typeof foo, 'number');
- // foo = true;
- // t.equal(typeof foo, 'boolean');
- // foo = {};
- // t.equal(typeof foo, 'object');
- // foo = function(){};
- // t.equal(typeof foo, 'function');
- // foo = [];
- // t.equal(Array.isArray(foo), true);
- // t.end();
- //})
- // test('test number to Chinese', function(t){
- // //t.equal(strUtil.convertNumToChinese(1, true), '壹');
- // //t.equal(strUtil.convertNumToChinese(1, false), '一');
- // t.equal(strUtil.convertNumToChinese(11, false), '一十一');
- // t.equal(strUtil.convertNumToChinese(12, false), '一十二');
- // t.equal(strUtil.convertNumToChinese(21, false), '二十一');
- // //console.log(strUtil.convertNumToChinese(102, false));
- // t.equal(strUtil.convertNumToChinese(102, false), '一百零二');
- // t.end();
- // });
- // test('test 拼音', function(t){
- // t.equal(strUtil.getPinYinCamelChars("招标清单"), "ZBQD");
- // t.equal(strUtil.getPinYinCamelChars("1. 招标清单"), "1. ZBQD");
- // t.end();
- // })
- // test('test typeof', function(t){
- // t.equal(typeof(true), "boolean");
- // t.equal((typeof("abc")).toUpperCase(), "STRING");
- // t.equal(typeof(1), "number");
- // t.end();
- // })
- test('test 千分位', function(t){
- let num = 123.01;
- t.equal( strUtil.comdify(num.toString()), "123.01");
- num = 123456.01;
- t.equal( strUtil.comdify(num.toString()), "123,456.01");
- num = 1234567.01;
- t.equal( strUtil.comdify(num.toString()), "1,234,567.01");
- num = 1234567;
- t.equal( strUtil.comdify(String(num)), "1,234,567");
- t.end();
- })
- test('test number to Chinese', function(t){
- t.equal(strUtil.convertToCaptionNum(0, false, false), '零');
- t.equal(strUtil.convertToCaptionNum(0, true, false), '零元整');
- t.equal(strUtil.convertToCaptionNum(0.68, true, false), '零元六角八分');
- t.equal(strUtil.convertToCaptionNum(0.68, true, true), '零元陆角捌分');
- t.equal(strUtil.convertToCaptionNum(10, false, false), '一十');
- t.equal(strUtil.convertToCaptionNum(10, false, true), '壹拾');
- t.equal(strUtil.convertToCaptionNum(11, false, false), '一十一');
- t.equal(strUtil.convertToCaptionNum(11, false, true), '壹拾壹');
- t.equal(strUtil.convertToCaptionNum(12, false, false), '一十二');
- t.equal(strUtil.convertToCaptionNum(12, false, true), '壹拾贰');
- t.equal(strUtil.convertToCaptionNum(21, false, false), '二十一');
- t.equal(strUtil.convertToCaptionNum(21, false, true), '贰拾壹');
- t.equal(strUtil.convertToCaptionNum(0.123456789, false, false), '零点一二三四五六七八九');
- t.equal(strUtil.convertToCaptionNum(10.123456789, false, false), '一十点一二三四五六七八九');
- t.equal(strUtil.convertToCaptionNum(123456789.15, false, false), '一亿二千三百四十五万六千七百八十九点一五');
- t.equal(strUtil.convertToCaptionNum(123456789.15, false, true), '壹億贰仟叁佰肆拾伍萬陆仟柒佰捌拾玖点壹伍');
- t.equal(strUtil.convertToCaptionNum(123456789.15, true, false), '一亿二千三百四十五万六千七百八十九元一角五分');
- t.equal(strUtil.convertToCaptionNum(123456789.15, true, true), '壹億贰仟叁佰肆拾伍萬陆仟柒佰捌拾玖元壹角伍分');
- t.end();
- })
|