File: padRight.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 (43 lines) | stat: -rw-r--r-- 1,114 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
var test = require('tape')
var fs = require('fs')

var padRight =  require('../utils').padRight

test('pad string with spaces up to len', function(t) {
  t.plan(1)
  t.equal(padRight('word', 10), 'word      ')
})

test('pad empty string with spaces up to len', function(t) {
  t.plan(1)
  t.equal(padRight('', 10), '          ')
})

test('leaves long strings along', function(t) {
  t.plan(1)
  t.equal(padRight('012345678910', 10), '012345678910')
})

test('custom padding', function(t) {
  t.plan(1)
  t.equal(padRight('', 10, '.'), '..........')
})

test('handling funky data with spaces up to len', function(t) {
  t.plan(5)
  t.equal(padRight(null, 10), '          ')
  t.equal(padRight(false, 10), 'false     ')
  t.equal(padRight(0, 10), '0         ')
  t.equal(padRight(10, 10), '10        ')
  t.equal(padRight([], 10), '          ')
})

test('pad string with paddingChr up to len', function(t) {
  t.plan(1)
  t.equal(padRight('word', 10, '.'), 'word......')
})

test('pad string with paddingChr of length >1, up to len', function(t) {
  t.plan(1)
  t.equal(padRight('words', 10, ' .'), 'words . . ')
})