File: truncate-string-maxlinewidth.js

package info (click to toggle)
node-columnify 1.5.4-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 29,684 kB
  • sloc: makefile: 9
file content (78 lines) | stat: -rw-r--r-- 1,818 bytes parent folder | download | duplicates (2)
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
var test = require('tape')
var fs = require('fs')

var columnify =  require('../')

var data = [{
  name: 'alongnameshouldbesplitovermultiplelines',
  description: 'some description',
  version: '0.0.1'
}, {
  name: 'module-two',
  description: 'another description larger than the max',
  version: '0.2.0',
}, {
  name: 'module-three',
  description: 'thisisaverylongwordandshouldbetruncated',
  version: '0.2.0',
}, {
  name: '这是一个很长的名字的模块',
  description: '这真的是一个描述的内容这个描述很长',
  version: "0.3.3"
}]

test('specific columns can be truncated, while others not', function(t) {
  var expected = fs.readFileSync(__dirname + '/truncate-string-maxlinewidth-expected.txt', 'utf8')

  t.equal(columnify(data, {
    maxLineWidth: 34,
    config: {
      name: {
        truncate: false,
        maxWidth: 9,
        truncateMarker: ''
      },
      description: {
        truncate: true,
        maxWidth: 20
      }
    }
  }).trim(), expected.trim())
  t.end()
})

test('when no maxLineWidth, nothing is changed', function(t) {
  t.equal(columnify(data, {
    config: {
      name: {
        truncate: false,
        maxWidth: 9,
        truncateMarker: ''
      },
      description: {
        truncate: true,
        maxWidth: 20
      }
    }
  }).trim(), fs.readFileSync(__dirname + '/truncate-column-expected.txt', 'utf8').trim())

  t.end()
})

test('maxLineWidth: "auto" with column max widths', function(t) {
  t.equal(columnify(data, {
    maxLineWidth: 'auto',
    config: {
      name: {
        truncate: false,
        maxWidth: 9,
        truncateMarker: ''
      },
      description: {
        truncate: true,
        maxWidth: 20
      }
    }
  }).trim(), fs.readFileSync(__dirname + '/truncate-column-expected.txt', 'utf8').trim())
  t.end()
})