|
1 | 1 | 'use strict' |
2 | 2 |
|
3 | | -var assert = require('assert') |
4 | 3 | var test = require('tape') |
5 | 4 | var remark = require('remark') |
6 | 5 | var findBefore = require('.') |
@@ -28,82 +27,138 @@ test('unist-util-find-before', function (t) { |
28 | 27 | 'should fail without parent node' |
29 | 28 | ) |
30 | 29 |
|
31 | | - t.doesNotThrow(function () { |
32 | | - assert.throws(function () { |
| 30 | + t.throws( |
| 31 | + function () { |
33 | 32 | findBefore({type: 'foo', children: []}) |
34 | | - }, /Expected positive finite index or child node/) |
| 33 | + }, |
| 34 | + /Expected child node or index/, |
| 35 | + 'should fail without index (#1)' |
| 36 | + ) |
35 | 37 |
|
36 | | - assert.throws(function () { |
| 38 | + t.throws( |
| 39 | + function () { |
37 | 40 | findBefore({type: 'foo', children: []}, -1) |
38 | | - }, /Expected positive finite index or child node/) |
| 41 | + }, |
| 42 | + /Expected positive finite number as index/, |
| 43 | + 'should fail without index (#2)' |
| 44 | + ) |
39 | 45 |
|
40 | | - assert.throws(function () { |
| 46 | + t.throws( |
| 47 | + function () { |
41 | 48 | findBefore({type: 'foo', children: []}, {type: 'bar'}) |
42 | | - }, /Expected positive finite index or child node/) |
43 | | - }, 'should fail without index') |
| 49 | + }, |
| 50 | + /Expected child node or index/, |
| 51 | + 'should fail without index (#3)' |
| 52 | + ) |
44 | 53 |
|
45 | | - t.doesNotThrow(function () { |
46 | | - assert.throws(function () { |
47 | | - findBefore( |
48 | | - { |
49 | | - type: 'foo', |
50 | | - children: [{type: 'bar'}] |
51 | | - }, |
52 | | - 1, |
53 | | - false |
54 | | - ) |
55 | | - }, /Expected function, string, or object as test/) |
| 54 | + t.throws( |
| 55 | + function () { |
| 56 | + findBefore({type: 'foo', children: [{type: 'bar'}]}, 1, false) |
| 57 | + }, |
| 58 | + /Expected function, string, or object as test/, |
| 59 | + 'should fail for invalid `test` (#1)' |
| 60 | + ) |
56 | 61 |
|
57 | | - assert.throws(function () { |
58 | | - findBefore( |
59 | | - { |
60 | | - type: 'foo', |
61 | | - children: [{type: 'bar'}] |
62 | | - }, |
63 | | - 1, |
64 | | - true |
65 | | - ) |
66 | | - }, /Expected function, string, or object as test/) |
67 | | - }, 'should fail for invalid `test`') |
| 62 | + t.throws( |
| 63 | + function () { |
| 64 | + findBefore({type: 'foo', children: [{type: 'bar'}]}, 1, true) |
| 65 | + }, |
| 66 | + /Expected function, string, or object as test/, |
| 67 | + 'should fail for invalid `test` (#2)' |
| 68 | + ) |
68 | 69 |
|
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`') |
| 70 | + t.strictEqual( |
| 71 | + findBefore(paragraph, children[1]), |
| 72 | + children[0], |
| 73 | + 'should return the preceding node when without `test` (#1)' |
| 74 | + ) |
| 75 | + t.strictEqual( |
| 76 | + findBefore(paragraph, 1), |
| 77 | + children[0], |
| 78 | + 'should return the preceding node when without `test` (#2)' |
| 79 | + ) |
| 80 | + t.strictEqual( |
| 81 | + findBefore(paragraph, 0), |
| 82 | + null, |
| 83 | + 'should return the preceding node when without `test` (#3)' |
| 84 | + ) |
74 | 85 |
|
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') |
| 86 | + t.strictEqual( |
| 87 | + findBefore(paragraph, 100, children[0]), |
| 88 | + children[0], |
| 89 | + 'should return `node` when given a `node` and existing (#1)' |
| 90 | + ) |
| 91 | + t.strictEqual( |
| 92 | + findBefore(paragraph, children[1], children[0]), |
| 93 | + children[0], |
| 94 | + 'should return `node` when given a `node` and existing (#2)' |
| 95 | + ) |
| 96 | + t.strictEqual( |
| 97 | + findBefore(paragraph, 1, children[0]), |
| 98 | + children[0], |
| 99 | + 'should return `node` when given a `node` and existing (#3)' |
| 100 | + ) |
| 101 | + t.strictEqual( |
| 102 | + findBefore(paragraph, children[0], children[0]), |
| 103 | + null, |
| 104 | + 'should return `node` when given a `node` and existing (#4)' |
| 105 | + ) |
| 106 | + t.strictEqual( |
| 107 | + findBefore(paragraph, 0, children[0]), |
| 108 | + null, |
| 109 | + 'should return `node` when given a `node` and existing (#5)' |
| 110 | + ) |
| 111 | + t.strictEqual( |
| 112 | + findBefore(paragraph, 1, children[1]), |
| 113 | + null, |
| 114 | + 'should return `node` when given a `node` and existing (#6)' |
| 115 | + ) |
86 | 116 |
|
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') |
| 117 | + t.strictEqual( |
| 118 | + findBefore(paragraph, 100, 'strong'), |
| 119 | + children[3], |
| 120 | + 'should return a child when given a `type` and existing (#1)' |
| 121 | + ) |
| 122 | + t.strictEqual( |
| 123 | + findBefore(paragraph, 3, 'strong'), |
| 124 | + null, |
| 125 | + 'should return a child when given a `type` and existing (#2)' |
| 126 | + ) |
| 127 | + t.strictEqual( |
| 128 | + findBefore(paragraph, children[4], 'strong'), |
| 129 | + children[3], |
| 130 | + 'should return a child when given a `type` and existing (#3)' |
| 131 | + ) |
| 132 | + t.strictEqual( |
| 133 | + findBefore(paragraph, children[3], 'strong'), |
| 134 | + null, |
| 135 | + 'should return a child when given a `type` and existing (#4)' |
| 136 | + ) |
96 | 137 |
|
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) |
| 138 | + t.strictEqual( |
| 139 | + findBefore(paragraph, 100, test), |
| 140 | + children[3], |
| 141 | + 'should return a child when given a `test` and existing (#1)' |
| 142 | + ) |
| 143 | + t.strictEqual( |
| 144 | + findBefore(paragraph, 3, test), |
| 145 | + null, |
| 146 | + 'should return a child when given a `test` and existing (#2)' |
| 147 | + ) |
| 148 | + t.strictEqual( |
| 149 | + findBefore(paragraph, children[4], test), |
| 150 | + children[3], |
| 151 | + 'should return a child when given a `test` and existing (#3)' |
| 152 | + ) |
| 153 | + t.strictEqual( |
| 154 | + findBefore(paragraph, children[3], test), |
| 155 | + null, |
| 156 | + 'should return a child when given a `test` and existing (#4)' |
| 157 | + ) |
102 | 158 |
|
103 | | - function test(node, n) { |
104 | | - return n === 3 |
105 | | - } |
106 | | - }, 'should return a child when given a `test` and existing') |
| 159 | + function test(node, n) { |
| 160 | + return n === 3 |
| 161 | + } |
107 | 162 |
|
108 | 163 | t.end() |
109 | 164 | }) |
0 commit comments