|
1 |
| -'use strict'; |
| 1 | +'use strict' |
2 | 2 |
|
3 |
| -var assert = require('assert'); |
4 |
| -var test = require('tape'); |
5 |
| -var remark = require('remark'); |
6 |
| -var findBefore = require('.'); |
| 3 | +var assert = require('assert') |
| 4 | +var test = require('tape') |
| 5 | +var remark = require('remark') |
| 6 | +var findBefore = require('.') |
7 | 7 |
|
8 |
| -var tree = remark().parse('Some *emphasis*, **importance**, and `code`.'); |
9 |
| -var paragraph = tree.children[0]; |
10 |
| -var children = paragraph.children; |
| 8 | +var tree = remark().parse('Some *emphasis*, **importance**, and `code`.') |
| 9 | +var paragraph = tree.children[0] |
| 10 | +var children = paragraph.children |
11 | 11 |
|
12 |
| -test('unist-util-find-before', function (t) { |
| 12 | +test('unist-util-find-before', function(t) { |
13 | 13 | t.throws(
|
14 |
| - function () { |
15 |
| - findBefore(); |
| 14 | + function() { |
| 15 | + findBefore() |
16 | 16 | },
|
17 | 17 | /Expected parent node/,
|
18 | 18 | 'should fail without parent'
|
19 |
| - ); |
| 19 | + ) |
20 | 20 |
|
21 | 21 | t.throws(
|
22 |
| - function () { |
| 22 | + function() { |
23 | 23 | findBefore({
|
24 | 24 | type: 'foo'
|
25 |
| - }); |
| 25 | + }) |
26 | 26 | },
|
27 | 27 | /Expected parent node/,
|
28 | 28 | 'should fail without parent node'
|
29 |
| - ); |
| 29 | + ) |
30 | 30 |
|
31 |
| - t.doesNotThrow( |
32 |
| - function () { |
33 |
| - assert.throws( |
34 |
| - function () { |
35 |
| - findBefore({type: 'foo', children: []}); |
36 |
| - }, |
37 |
| - /Expected positive finite index or child node/ |
38 |
| - ); |
| 31 | + t.doesNotThrow(function() { |
| 32 | + assert.throws(function() { |
| 33 | + findBefore({type: 'foo', children: []}) |
| 34 | + }, /Expected positive finite index or child node/) |
39 | 35 |
|
40 |
| - assert.throws( |
41 |
| - function () { |
42 |
| - findBefore({type: 'foo', children: []}, -1); |
43 |
| - }, |
44 |
| - /Expected positive finite index or child node/ |
45 |
| - ); |
| 36 | + assert.throws(function() { |
| 37 | + findBefore({type: 'foo', children: []}, -1) |
| 38 | + }, /Expected positive finite index or child node/) |
46 | 39 |
|
47 |
| - assert.throws( |
48 |
| - function () { |
49 |
| - findBefore({type: 'foo', children: []}, {type: 'bar'}); |
50 |
| - }, |
51 |
| - /Expected positive finite index or child node/ |
52 |
| - ); |
53 |
| - }, |
54 |
| - 'should fail without index' |
55 |
| - ); |
| 40 | + assert.throws(function() { |
| 41 | + findBefore({type: 'foo', children: []}, {type: 'bar'}) |
| 42 | + }, /Expected positive finite index or child node/) |
| 43 | + }, 'should fail without index') |
56 | 44 |
|
57 |
| - t.doesNotThrow( |
58 |
| - function () { |
59 |
| - assert.throws( |
60 |
| - function () { |
61 |
| - findBefore({ |
62 |
| - type: 'foo', |
63 |
| - children: [{type: 'bar'}] |
64 |
| - }, 1, false); |
| 45 | + t.doesNotThrow(function() { |
| 46 | + assert.throws(function() { |
| 47 | + findBefore( |
| 48 | + { |
| 49 | + type: 'foo', |
| 50 | + children: [{type: 'bar'}] |
65 | 51 | },
|
66 |
| - /Expected function, string, or object as test/ |
67 |
| - ); |
| 52 | + 1, |
| 53 | + false |
| 54 | + ) |
| 55 | + }, /Expected function, string, or object as test/) |
68 | 56 |
|
69 |
| - assert.throws( |
70 |
| - function () { |
71 |
| - findBefore({ |
72 |
| - type: 'foo', |
73 |
| - children: [{type: 'bar'}] |
74 |
| - }, 1, true); |
| 57 | + assert.throws(function() { |
| 58 | + findBefore( |
| 59 | + { |
| 60 | + type: 'foo', |
| 61 | + children: [{type: 'bar'}] |
75 | 62 | },
|
76 |
| - /Expected function, string, or object as test/ |
77 |
| - ); |
78 |
| - }, |
79 |
| - 'should fail for invalid `test`' |
80 |
| - ); |
| 63 | + 1, |
| 64 | + true |
| 65 | + ) |
| 66 | + }, /Expected function, string, or object as test/) |
| 67 | + }, 'should fail for invalid `test`') |
81 | 68 |
|
82 |
| - t.doesNotThrow( |
83 |
| - function () { |
84 |
| - assert.strictEqual(findBefore(paragraph, children[1]), children[0]); |
85 |
| - assert.strictEqual(findBefore(paragraph, 1), children[0]); |
86 |
| - assert.strictEqual(findBefore(paragraph, 0), null); |
87 |
| - }, |
88 |
| - 'should return the preceding node when without `test`' |
89 |
| - ); |
| 69 | + t.doesNotThrow(function() { |
| 70 | + assert.strictEqual(findBefore(paragraph, children[1]), children[0]) |
| 71 | + assert.strictEqual(findBefore(paragraph, 1), children[0]) |
| 72 | + assert.strictEqual(findBefore(paragraph, 0), null) |
| 73 | + }, 'should return the preceding node when without `test`') |
90 | 74 |
|
91 |
| - t.doesNotThrow( |
92 |
| - function () { |
93 |
| - assert.strictEqual(findBefore(paragraph, 100, children[0]), children[0]); |
94 |
| - assert.strictEqual(findBefore(paragraph, children[1], children[0]), children[0]); |
95 |
| - assert.strictEqual(findBefore(paragraph, 1, children[0]), children[0]); |
96 |
| - assert.strictEqual(findBefore(paragraph, children[0], children[0]), null); |
97 |
| - assert.strictEqual(findBefore(paragraph, 0, children[0]), null); |
98 |
| - assert.strictEqual(findBefore(paragraph, 1, children[1]), null); |
99 |
| - }, |
100 |
| - 'should return `node` when given a `node` and existing' |
101 |
| - ); |
| 75 | + t.doesNotThrow(function() { |
| 76 | + assert.strictEqual(findBefore(paragraph, 100, children[0]), children[0]) |
| 77 | + assert.strictEqual( |
| 78 | + findBefore(paragraph, children[1], children[0]), |
| 79 | + children[0] |
| 80 | + ) |
| 81 | + assert.strictEqual(findBefore(paragraph, 1, children[0]), children[0]) |
| 82 | + assert.strictEqual(findBefore(paragraph, children[0], children[0]), null) |
| 83 | + assert.strictEqual(findBefore(paragraph, 0, children[0]), null) |
| 84 | + assert.strictEqual(findBefore(paragraph, 1, children[1]), null) |
| 85 | + }, 'should return `node` when given a `node` and existing') |
102 | 86 |
|
103 |
| - t.doesNotThrow( |
104 |
| - function () { |
105 |
| - assert.strictEqual(findBefore(paragraph, 100, 'strong'), children[3]); |
106 |
| - assert.strictEqual(findBefore(paragraph, 3, 'strong'), null); |
107 |
| - assert.strictEqual(findBefore(paragraph, children[4], 'strong'), children[3]); |
108 |
| - assert.strictEqual(findBefore(paragraph, children[3], 'strong'), null); |
109 |
| - }, |
110 |
| - 'should return a child when given a `type` and existing' |
111 |
| - ); |
| 87 | + t.doesNotThrow(function() { |
| 88 | + assert.strictEqual(findBefore(paragraph, 100, 'strong'), children[3]) |
| 89 | + assert.strictEqual(findBefore(paragraph, 3, 'strong'), null) |
| 90 | + assert.strictEqual( |
| 91 | + findBefore(paragraph, children[4], 'strong'), |
| 92 | + children[3] |
| 93 | + ) |
| 94 | + assert.strictEqual(findBefore(paragraph, children[3], 'strong'), null) |
| 95 | + }, 'should return a child when given a `type` and existing') |
112 | 96 |
|
113 |
| - t.doesNotThrow( |
114 |
| - function () { |
115 |
| - assert.strictEqual(findBefore(paragraph, 100, test), children[3]); |
116 |
| - assert.strictEqual(findBefore(paragraph, 3, test), null); |
117 |
| - assert.strictEqual(findBefore(paragraph, children[4], test), children[3]); |
118 |
| - assert.strictEqual(findBefore(paragraph, children[3], test), null); |
| 97 | + t.doesNotThrow(function() { |
| 98 | + assert.strictEqual(findBefore(paragraph, 100, test), children[3]) |
| 99 | + assert.strictEqual(findBefore(paragraph, 3, test), null) |
| 100 | + assert.strictEqual(findBefore(paragraph, children[4], test), children[3]) |
| 101 | + assert.strictEqual(findBefore(paragraph, children[3], test), null) |
119 | 102 |
|
120 |
| - function test(node, n) { |
121 |
| - return n === 3; |
122 |
| - } |
123 |
| - }, |
124 |
| - 'should return a child when given a `test` and existing' |
125 |
| - ); |
| 103 | + function test(node, n) { |
| 104 | + return n === 3 |
| 105 | + } |
| 106 | + }, 'should return a child when given a `test` and existing') |
126 | 107 |
|
127 |
| - t.end(); |
128 |
| -}); |
| 108 | + t.end() |
| 109 | +}) |
0 commit comments