11'use strict'
22
3- var assert = require ( 'assert' )
43var test = require ( 'tape' )
54var remark = require ( 'remark' )
65var findAllAfter = require ( '.' )
@@ -26,105 +25,170 @@ test('unist-util-find-all-after', function (t) {
2625 'should fail without parent node'
2726 )
2827
29- t . doesNotThrow ( function ( ) {
30- assert . throws ( function ( ) {
28+ t . throws (
29+ function ( ) {
3130 findAllAfter ( { 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 / )
33- } , 'should fail without index' )
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'
34+ )
3435
35- t . doesNotThrow ( function ( ) {
36- assert . throws ( function ( ) {
36+ t . throws (
37+ function ( ) {
3738 findAllAfter ( { type : 'foo' , children : [ ] } , - 1 )
38- } , / 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 / )
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 with invalid index (#1)'
42+ )
3943
40- assert . throws ( function ( ) {
44+ t . throws (
45+ function ( ) {
4146 findAllAfter ( { type : 'foo' , children : [ ] } , Infinity )
42- } , / 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 / )
47+ } ,
48+ / 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 / ,
49+ 'should fail with invalid index (#2)'
50+ )
4351
44- assert . throws ( function ( ) {
52+ t . throws (
53+ function ( ) {
4554 findAllAfter ( { type : 'foo' , children : [ ] } , false )
46- } , / 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 / )
55+ } ,
56+ / E x p e c t e d c h i l d n o d e o r i n d e x / ,
57+ 'should fail with invalid index (#3)'
58+ )
4759
48- assert . throws ( function ( ) {
49- findAllAfter ( { type : 'foo' , children : [ ] } , '' )
50- } , / 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 / )
60+ t . throws (
61+ function ( ) {
62+ findAllAfter ( { type : 'foo' , children : [ ] } , - 1 )
63+ } ,
64+ / 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 / ,
65+ 'should fail with invalid index (#4)'
66+ )
5167
52- assert . throws ( function ( ) {
68+ t . throws (
69+ function ( ) {
5370 findAllAfter ( { type : 'foo' , children : [ ] } , { type : 'bar' } )
54- } , / E x p e c t e d c h i l d n o d e / )
55- } , 'should fail with invalid index' )
71+ } ,
72+ / E x p e c t e d c h i l d n o d e / ,
73+ 'should fail with invalid index (#5)'
74+ )
5675
57- t . doesNotThrow ( function ( ) {
58- assert . throws ( function ( ) {
76+ t . throws (
77+ function ( ) {
5978 findAllAfter (
60- {
61- type : 'foo' ,
62- children : [ { type : 'bar' } , { type : 'baz' } ]
63- } ,
79+ { type : 'foo' , children : [ { type : 'bar' } , { type : 'baz' } ] } ,
6480 0 ,
6581 false
6682 )
67- } , / 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 / )
83+ } ,
84+ / 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 / ,
85+ 'should fail for invalid `test` (#1)'
86+ )
6887
69- assert . throws ( function ( ) {
88+ t . throws (
89+ function ( ) {
7090 findAllAfter (
71- {
72- type : 'foo' ,
73- children : [ { type : 'bar' } , { type : 'baz' } ]
74- } ,
91+ { type : 'foo' , children : [ { type : 'bar' } , { type : 'baz' } ] } ,
7592 0 ,
7693 true
7794 )
78- } , / 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 / )
79- } , 'should fail for invalid `test`' )
80-
81- t . doesNotThrow ( function ( ) {
82- var result = children . slice ( 2 )
83-
84- assert . deepStrictEqual ( findAllAfter ( paragraph , children [ 1 ] ) , result )
85- assert . deepStrictEqual ( findAllAfter ( paragraph , 1 ) , result )
86- assert . deepStrictEqual ( findAllAfter ( paragraph , 7 ) , [ ] )
87- } , 'should return the following node when without `test`' )
88-
89- t . doesNotThrow ( function ( ) {
90- assert . deepStrictEqual ( findAllAfter ( paragraph , 0 , children [ 6 ] ) , [
91- children [ 6 ]
92- ] )
93- assert . deepStrictEqual ( findAllAfter ( paragraph , children [ 0 ] , children [ 1 ] ) , [
94- children [ 1 ]
95- ] )
96- assert . deepStrictEqual ( findAllAfter ( paragraph , 0 , children [ 1 ] ) , [
97- children [ 1 ]
98- ] )
99- assert . deepStrictEqual (
100- findAllAfter ( paragraph , children [ 0 ] , children [ 0 ] ) ,
101- [ ]
102- )
103- assert . deepStrictEqual ( findAllAfter ( paragraph , 0 , children [ 0 ] ) , [ ] )
104- assert . deepStrictEqual ( findAllAfter ( paragraph , 1 , children [ 1 ] ) , [ ] )
105- } , 'should return `node` when given a `node` and existing' )
106-
107- t . doesNotThrow ( function ( ) {
108- assert . deepStrictEqual ( findAllAfter ( paragraph , 0 , 'strong' ) , [ children [ 3 ] ] )
109- assert . deepStrictEqual ( findAllAfter ( paragraph , 3 , 'strong' ) , [ ] )
110- assert . deepStrictEqual ( findAllAfter ( paragraph , children [ 0 ] , 'strong' ) , [
111- children [ 3 ]
112- ] )
113- assert . deepStrictEqual ( findAllAfter ( paragraph , children [ 3 ] , 'strong' ) , [ ] )
114- } , 'should return a child when given a `type` and existing' )
115-
116- t . doesNotThrow ( function ( ) {
117- var result = children . slice ( 5 )
118-
119- assert . deepStrictEqual ( findAllAfter ( paragraph , 0 , test ) , result )
120- assert . deepStrictEqual ( findAllAfter ( paragraph , 6 , test ) , [ ] )
121- assert . deepStrictEqual ( findAllAfter ( paragraph , children [ 4 ] , test ) , result )
122- assert . deepStrictEqual ( findAllAfter ( paragraph , children [ 6 ] , test ) , [ ] )
123-
124- function test ( node , n ) {
125- return n >= 5
126- }
127- } , 'should return a child when given a `test` and existing' )
95+ } ,
96+ / 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 / ,
97+ 'should fail for invalid `test` (#2)'
98+ )
99+
100+ t . deepEqual (
101+ findAllAfter ( paragraph , children [ 1 ] ) ,
102+ children . slice ( 2 ) ,
103+ 'should return the following node when without `test` (#1)'
104+ )
105+ t . deepEqual (
106+ findAllAfter ( paragraph , 1 ) ,
107+ children . slice ( 2 ) ,
108+ 'should return the following node when without `test` (#1)'
109+ )
110+ t . deepEqual (
111+ findAllAfter ( paragraph , 7 ) ,
112+ [ ] ,
113+ 'should return the following node when without `test` (#1)'
114+ )
115+
116+ t . deepEqual (
117+ findAllAfter ( paragraph , 0 , children [ 6 ] ) ,
118+ [ children [ 6 ] ] ,
119+ 'should return `node` when given a `node` and existing (#1)'
120+ )
121+ t . deepEqual (
122+ findAllAfter ( paragraph , children [ 0 ] , children [ 1 ] ) ,
123+ [ children [ 1 ] ] ,
124+ 'should return `node` when given a `node` and existing (#2)'
125+ )
126+ t . deepEqual (
127+ findAllAfter ( paragraph , 0 , children [ 1 ] ) ,
128+ [ children [ 1 ] ] ,
129+ 'should return `node` when given a `node` and existing (#3)'
130+ )
131+ t . deepEqual (
132+ findAllAfter ( paragraph , children [ 0 ] , children [ 0 ] ) ,
133+ [ ] ,
134+ 'should return `node` when given a `node` and existing (#4)'
135+ )
136+ t . deepEqual (
137+ findAllAfter ( paragraph , 0 , children [ 0 ] ) ,
138+ [ ] ,
139+ 'should return `node` when given a `node` and existing (#5)'
140+ )
141+ t . deepEqual (
142+ findAllAfter ( paragraph , 1 , children [ 1 ] ) ,
143+ [ ] ,
144+ 'should return `node` when given a `node` and existing (#6)'
145+ )
146+
147+ t . deepEqual (
148+ findAllAfter ( paragraph , 0 , 'strong' ) ,
149+ [ children [ 3 ] ] ,
150+ 'should return a child when given a `type` and existing (#1)'
151+ )
152+ t . deepEqual (
153+ findAllAfter ( paragraph , 3 , 'strong' ) ,
154+ [ ] ,
155+ 'should return a child when given a `type` and existing (#2)'
156+ )
157+ t . deepEqual (
158+ findAllAfter ( paragraph , children [ 0 ] , 'strong' ) ,
159+ [ children [ 3 ] ] ,
160+ 'should return a child when given a `type` and existing (#3)'
161+ )
162+ t . deepEqual (
163+ findAllAfter ( paragraph , children [ 3 ] , 'strong' ) ,
164+ [ ] ,
165+ 'should return a child when given a `type` and existing (#4)'
166+ )
167+
168+ t . deepEqual (
169+ findAllAfter ( paragraph , 0 , test ) ,
170+ children . slice ( 5 ) ,
171+ 'should return a child when given a `test` and existing (#1)'
172+ )
173+ t . deepEqual (
174+ findAllAfter ( paragraph , 6 , test ) ,
175+ [ ] ,
176+ 'should return a child when given a `test` and existing (#2)'
177+ )
178+ t . deepEqual (
179+ findAllAfter ( paragraph , children [ 4 ] , test ) ,
180+ children . slice ( 5 ) ,
181+ 'should return a child when given a `test` and existing (#3)'
182+ )
183+ t . deepEqual (
184+ findAllAfter ( paragraph , children [ 6 ] , test ) ,
185+ [ ] ,
186+ 'should return a child when given a `test` and existing (#4)'
187+ )
188+
189+ function test ( node , n ) {
190+ return n >= 5
191+ }
128192
129193 t . end ( )
130194} )
0 commit comments