stringTest.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * Created by Tony on 2017/4/7.
  3. */
  4. var test = require('tape');
  5. var strUtil = require('../../public/stringUtil');
  6. //test('some string test cases', function (t) {
  7. // var reg = /^\s*$/;
  8. // var foo = " ";
  9. // t.equal(reg.test(foo), true);
  10. // foo = null;
  11. // t.equal(reg.test(foo), true);
  12. // foo = undefined;
  13. // t.equal(reg.test(foo), true);
  14. // foo = "";
  15. // t.equal(reg.test(foo), true);
  16. // foo = 0;
  17. // t.equal(reg.test(foo), true);
  18. // t.end();
  19. //});
  20. //
  21. //test('check if string type', function(t){
  22. // var foo = "";
  23. // t.equal(typeof foo, 'string');
  24. // foo = " ";
  25. // t.equal(typeof foo, 'string');
  26. // foo = 0;
  27. // t.equal(typeof foo, 'number');
  28. // foo = true;
  29. // t.equal(typeof foo, 'boolean');
  30. // foo = {};
  31. // t.equal(typeof foo, 'object');
  32. // foo = function(){};
  33. // t.equal(typeof foo, 'function');
  34. // foo = [];
  35. // t.equal(Array.isArray(foo), true);
  36. // t.end();
  37. //})
  38. // test('test number to Chinese', function(t){
  39. // //t.equal(strUtil.convertNumToChinese(1, true), '壹');
  40. // //t.equal(strUtil.convertNumToChinese(1, false), '一');
  41. // t.equal(strUtil.convertNumToChinese(11, false), '一十一');
  42. // t.equal(strUtil.convertNumToChinese(12, false), '一十二');
  43. // t.equal(strUtil.convertNumToChinese(21, false), '二十一');
  44. // //console.log(strUtil.convertNumToChinese(102, false));
  45. // t.equal(strUtil.convertNumToChinese(102, false), '一百零二');
  46. // t.end();
  47. // });
  48. // test('test 拼音', function(t){
  49. // t.equal(strUtil.getPinYinCamelChars("招标清单"), "ZBQD");
  50. // t.equal(strUtil.getPinYinCamelChars("1. 招标清单"), "1. ZBQD");
  51. // t.end();
  52. // })
  53. // test('test typeof', function(t){
  54. // t.equal(typeof(true), "boolean");
  55. // t.equal((typeof("abc")).toUpperCase(), "STRING");
  56. // t.equal(typeof(1), "number");
  57. // t.end();
  58. // })
  59. test('test 千分位', function(t){
  60. let num = 123.01;
  61. t.equal( strUtil.comdify(num.toString()), "123.01");
  62. num = 123456.01;
  63. t.equal( strUtil.comdify(num.toString()), "123,456.01");
  64. num = 1234567.01;
  65. t.equal( strUtil.comdify(num.toString()), "1,234,567.01");
  66. num = 1234567;
  67. t.equal( strUtil.comdify(String(num)), "1,234,567");
  68. t.end();
  69. })
  70. test('test number to Chinese', function(t){
  71. t.equal(strUtil.convertToCaptionNum(0, false, false), '零');
  72. t.equal(strUtil.convertToCaptionNum(0, true, false), '零元整');
  73. t.equal(strUtil.convertToCaptionNum(0.68, true, false), '零元六角八分');
  74. t.equal(strUtil.convertToCaptionNum(0.68, true, true), '零元陆角捌分');
  75. t.equal(strUtil.convertToCaptionNum(10, false, false), '一十');
  76. t.equal(strUtil.convertToCaptionNum(10, false, true), '壹拾');
  77. t.equal(strUtil.convertToCaptionNum(11, false, false), '一十一');
  78. t.equal(strUtil.convertToCaptionNum(11, false, true), '壹拾壹');
  79. t.equal(strUtil.convertToCaptionNum(12, false, false), '一十二');
  80. t.equal(strUtil.convertToCaptionNum(12, false, true), '壹拾贰');
  81. t.equal(strUtil.convertToCaptionNum(21, false, false), '二十一');
  82. t.equal(strUtil.convertToCaptionNum(21, false, true), '贰拾壹');
  83. t.equal(strUtil.convertToCaptionNum(0.123456789, false, false), '零点一二三四五六七八九');
  84. t.equal(strUtil.convertToCaptionNum(10.123456789, false, false), '一十点一二三四五六七八九');
  85. t.equal(strUtil.convertToCaptionNum(123456789.15, false, false), '一亿二千三百四十五万六千七百八十九点一五');
  86. t.equal(strUtil.convertToCaptionNum(123456789.15, false, true), '壹億贰仟叁佰肆拾伍萬陆仟柒佰捌拾玖点壹伍');
  87. t.equal(strUtil.convertToCaptionNum(123456789.15, true, false), '一亿二千三百四十五万六千七百八十九元一角五分');
  88. t.equal(strUtil.convertToCaptionNum(123456789.15, true, true), '壹億贰仟叁佰肆拾伍萬陆仟柒佰捌拾玖元壹角伍分');
  89. t.end();
  90. })