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

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

test('lines under max are ok', function(t) {
  t.plan(1)
  t.deepEqual(splitIntoLines('dinosaur cabbages', 32), ['dinosaur cabbages'])
})

test('lines at max are ok', function(t) {
  t.plan(1)
  t.deepEqual(splitIntoLines('dinosaur cabbages', 17), ['dinosaur cabbages'])
})

test('lines at max with multiple spaces are ok', function(t) {
  t.plan(1)
  t.deepEqual(splitIntoLines('dinosaur cabbages mechanic', 26), ['dinosaur cabbages mechanic'])
})

test('lines over max will be split', function(t) {
  t.plan(1)
  t.deepEqual(splitIntoLines('dinosaur cabbages', 16), ['dinosaur', 'cabbages'])
})

test('splits lines under max onto multiple lines', function(t) {
  t.plan(1)
  t.deepEqual(splitIntoLines('dinosaur cabbages', 7), ['dinosaur', 'cabbages'])
})

test('can put multiple words per line', function(t) {
  t.plan(1)
  t.deepEqual(splitIntoLines('dog cat cow bat mat', 7), [
    'dog cat',
    'cow bat',
    'mat'
  ])
})

test('single existing newline is preserved', function(t) {
  t.plan(1)
  t.deepEqual(splitIntoLines('dog\n cat cow bat mat', 7), [
    'dog',
    'cat cow',
    'bat mat'
  ])
})

test('multiple existing newlines are preserved', function(t) {
  t.plan(1)
  t.deepEqual(splitIntoLines('dog\n\n cat\n cow \nbat mat', 7), [
    'dog',
    '',
    'cat',
    'cow',
    'bat mat'
  ])
})