stringTest.js 835 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * Created by Tony on 2017/4/7.
  3. */
  4. var test = require('tape');
  5. test('some string test cases', function (t) {
  6. var reg = /^\s*$/;
  7. var foo = " ";
  8. t.equal(reg.test(foo), true);
  9. foo = null;
  10. t.equal(reg.test(foo), true);
  11. foo = undefined;
  12. t.equal(reg.test(foo), true);
  13. foo = "";
  14. t.equal(reg.test(foo), true);
  15. foo = 0;
  16. t.equal(reg.test(foo), true);
  17. t.end();
  18. });
  19. test('check if string type', function(t){
  20. var foo = "";
  21. t.equal(typeof foo, 'string');
  22. foo = " ";
  23. t.equal(typeof foo, 'string');
  24. foo = 0;
  25. t.equal(typeof foo, 'number');
  26. foo = true;
  27. t.equal(typeof foo, 'boolean');
  28. foo = {};
  29. t.equal(typeof foo, 'object');
  30. foo = function(){};
  31. t.equal(typeof foo, 'function');
  32. foo = [];
  33. t.equal(Array.isArray(foo), true);
  34. t.end();
  35. })