summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/cli-table2/test/table-test.js
blob: 4bc3e055d93f7ce22b5a3b1343f81690c5b667ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
describe('@api Table ',function(){
  var chai = require('chai');
  var expect = chai.expect;
  var Table = require('..');
  var colors = require('colors/safe');

  it('wordWrap with colored text',function(){
    var table = new Table({style:{border:[],head:[]},wordWrap:true,colWidths:[7,9]});

    table.push([colors.red('Hello how are you?'),colors.blue('I am fine thanks!')]);

    var expected = [
        '┌───────┬─────────┐'
      , '│ ' + colors.red('Hello') + ' │ ' + colors.blue('I am') + '    │'
      , '│ ' + colors.red('how') + '   │ ' + colors.blue('fine') + '    │'
      , '│ ' + colors.red('are') + '   │ ' + colors.blue('thanks!') + ' │'
      , '│ ' + colors.red('you?') + '  │         │'
      , '└───────┴─────────┘'
    ];

    expect(table.toString()).to.equal(expected.join('\n'));
  });

  it('allows numbers as `content` property of cells defined using object notation', function() {
    var table = new Table({style:{border:[],head:[]}});

    table.push([{content: 12}]);

     var expected = [
       '┌────┐'
     , '│ 12 │'
     , '└────┘'
     ];

    expect(table.toString()).to.equal(expected.join('\n'));
  });

  it('throws if content is not a string or number', function() {
    var table = new Table({style:{border:[],head:[]}});

    expect(function() {
      table.push([{content: {a:'b'}}]);
      table.toString();
    }).to.throw();

  });

  it('works with CJK values', function () {
    var table = new Table({style: {border:[],head:[]}, colWidths: [5, 10, 5]});

    table.push(
      ['foobar', 'English test', 'baz']
      , ['foobar', '中文测试', 'baz']
      , ['foobar', '日本語テスト', 'baz']
      , ['foobar', '한국어테스트', 'baz']
    );

    var expected = [
        '┌─────┬──────────┬─────┐'
      , '│ fo… │ English… │ baz │'
      , '├─────┼──────────┼─────┤'
      , '│ fo… │ 中文测试 │ baz │'
      , '├─────┼──────────┼─────┤'
      , '│ fo… │ 日本語…  │ baz │'
      , '├─────┼──────────┼─────┤'
      , '│ fo… │ 한국어…  │ baz │'
      , '└─────┴──────────┴─────┘'
    ];

    expect(table.toString()).to.equal(expected.join("\n"));
  });
});


/*

 var expected = [
   '┌──┬───┬──┬──┐'
 , '│  │   │  │  │'
 , '├──┼───┼──┼──┤'
 , '│  │ … │  │  │'
 , '├──┼───┼──┼──┤'
 , '│  │ … │  │  │'
 , '└──┴───┴──┴──┘'
 ];

 */