printalbe_test.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. var should = require('should');
  2. var pt = require('../');
  3. var source;
  4. describe('printable test', function() {
  5. describe('common print', function() {
  6. it('should print limit ok', function() {
  7. source = [['hello', 'world'], ['foo', 'bar']];
  8. var out = pt.print(source, '|', 10);
  9. out.should.equal('hello |world \nfoo |bar ');
  10. });
  11. it('should print unlimit ok', function() {
  12. var out = pt.print(source, '|')
  13. out.should.equal('hello|world\nfoo |bar ');
  14. });;
  15. it('should print limit cut ok', function() {
  16. var out = pt.print(source, ' | ', 3);
  17. out.should.equal('hel | wor\nfoo | bar');
  18. });
  19. it('should print border length ok',function() {
  20. var out = pt.print(source, 5);
  21. out.should.equal('hello world\nfoo bar ');
  22. });
  23. it('should print chinese ok', function() {
  24. source = [['hello', 'world'], ['你好', '世界']];
  25. var out = pt.print(source, '|');
  26. out.should.equal('hello|world\n你好 |世界 ');
  27. });
  28. it('should cut chinese ok', function() {
  29. var out = pt.print(source, '|', 3);
  30. out.should.equal('hel|wor\n你 |世 ');
  31. });
  32. });
  33. describe('!string print', function() {
  34. it('should print number ok', function() {
  35. source.push(['number', 123456789]);
  36. var out = pt.print(source, '|');
  37. out.should.equal('hello |world \n你好 |世界 \nnumber|123456789');
  38. });
  39. it('should print object ok', function() {
  40. source.push([{a:"1"}, ['我',2]]);
  41. var out = pt.print(source, '|');
  42. out.should.equal('hello |world \n你好 |世界 \nnumber |123456789\n{"a":"1"}|["我",2] ');
  43. });
  44. });
  45. });