-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtest.js
69 lines (58 loc) · 1.83 KB
/
test.js
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
import test from 'ava';
import indentString from './index.js';
test('throw if input is not a string', t => {
t.throws(() => {
indentString(5);
}, {
message: 'Expected `input` to be a `string`, got `number`'
});
t.throws(() => {
indentString(true);
}, {
message: 'Expected `input` to be a `string`, got `boolean`'
});
});
test('throw if count is not a number', t => {
t.throws(() => {
indentString('foo', 'bar');
}, {
message: 'Expected `count` to be a `number`, got `string`'
});
});
test('throw if count is a negative', t => {
t.throws(() => {
indentString('foo', -1);
}, {
message: 'Expected `count` to be at least 0, got `-1`'
});
});
test('throw if indent is not a string', t => {
t.throws(() => {
indentString('foo', 1, {indent: 1});
}, {
message: 'Expected `options.indent` to be a `string`, got `number`'
});
});
test('indent each line in a string', t => {
t.is(indentString('foo\nbar'), ' foo\n bar');
t.is(indentString('foo\nbar', 1), ' foo\n bar');
t.is(indentString('foo\r\nbar', 1), ' foo\r\n bar');
t.is(indentString('foo\nbar', 4), ' foo\n bar');
});
test('not indent whitespace only lines', t => {
t.is(indentString('foo\nbar\n', 1), ' foo\n bar\n');
t.is(indentString('foo\nbar\n', 1, {includeEmptyLines: false}), ' foo\n bar\n');
t.is(indentString('foo\nbar\n', 1, {includeEmptyLines: null}), ' foo\n bar\n');
});
test('indent every line if options.includeEmptyLines is true', t => {
t.is(indentString('foo\n\nbar\n ', 1, {includeEmptyLines: true}), ' foo\n \n bar\n ');
});
test('indent with leading whitespace', t => {
t.is(indentString(' foo\n bar\n', 1), ' foo\n bar\n');
});
test('indent with custom string', t => {
t.is(indentString('foo\nbar\n', 1, {indent: '♥'}), '♥foo\n♥bar\n');
});
test('not indent when count is 0', t => {
t.is(indentString('foo\nbar\n', 0), 'foo\nbar\n');
});