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