11'use strict' ;
22
3- /* eslint-env node, mocha */
3+ /* eslint-env node */
44
55/*
66 * Dependencies.
77 */
88
9- var assert = require ( 'assert' ) ;
109var fs = require ( 'fs' ) ;
1110var path = require ( 'path' ) ;
11+ var test = require ( 'tape' ) ;
1212var remark = require ( 'remark' ) ;
1313var VFile = require ( 'vfile' ) ;
1414var Latin = require ( 'parse-latin' ) ;
@@ -50,53 +50,76 @@ function toFile(tree) {
5050 * Tests.
5151 */
5252
53- describe ( 'mdast-util-to-nlcst' , function ( ) {
54- it ( 'should fail when not given a file' , function ( ) {
55- assert . throws ( function ( ) {
53+ test ( 'mdast-util-to-nlcst' , function ( t ) {
54+ t . throws (
55+ function ( ) {
5656 toNLCST ( ) ;
57- } , / m d a s t - u t i l - t o - n l c s t e x p e c t e d f i l e / ) ;
57+ } ,
58+ / m d a s t - u t i l - t o - n l c s t e x p e c t e d f i l e / ,
59+ 'should fail when not given a file'
60+ ) ;
5861
59- assert . throws ( function ( ) {
62+ t . throws (
63+ function ( ) {
6064 toNLCST ( { } ) ;
61- } , / m d a s t - u t i l - t o - n l c s t e x p e c t e d f i l e / ) ;
62- } ) ;
65+ } ,
66+ / m d a s t - u t i l - t o - n l c s t e x p e c t e d f i l e / ,
67+ 'should fail when not given a file (#2)'
68+ ) ;
6369
64- it ( 'should fail when not given an AST' , function ( ) {
65- assert . throws ( function ( ) {
70+ t . throws (
71+ function ( ) {
6672 toNLCST ( toFile ( ) ) ;
67- } , / m d a s t - u t i l - t o - n l c s t e x p e c t e d n o d e / ) ;
73+ } ,
74+ / m d a s t - u t i l - t o - n l c s t e x p e c t e d n o d e / ,
75+ 'should fail when not given an AST'
76+ ) ;
6877
69- assert . throws ( function ( ) {
78+ t . throws (
79+ function ( ) {
7080 toNLCST ( toFile ( { } ) ) ;
71- } , / m d a s t - u t i l - t o - n l c s t e x p e c t e d n o d e / ) ;
72- } ) ;
73-
74- it ( 'should fail when not given a file' , function ( ) {
75- var node = {
76- 'type' : 'text' ,
77- 'value' : 'foo'
78- } ;
79-
80- assert . throws ( function ( ) {
81- toNLCST ( node ) ;
82- } , / m d a s t - u t i l - t o - n l c s t e x p e c t e d f i l e / ) ;
83-
84- assert . throws ( function ( ) {
85- toNLCST ( node , {
81+ } ,
82+ / m d a s t - u t i l - t o - n l c s t e x p e c t e d n o d e / ,
83+ 'should fail when not given an AST (#2)'
84+ ) ;
85+
86+ t . throws (
87+ function ( ) {
88+ toNLCST ( {
89+ 'type' : 'text' ,
90+ 'value' : 'foo'
91+ } ) ;
92+ } ,
93+ / m d a s t - u t i l - t o - n l c s t e x p e c t e d f i l e / ,
94+ 'should fail when not given a file'
95+ ) ;
96+
97+ t . throws (
98+ function ( ) {
99+ toNLCST ( {
100+ 'type' : 'text' ,
101+ 'value' : 'foo'
102+ } , {
86103 'foo' : 'bar'
87104 } ) ;
88- } , / m d a s t - u t i l - t o - n l c s t e x p e c t e d f i l e / ) ;
89- } ) ;
105+ } ,
106+ / m d a s t - u t i l - t o - n l c s t e x p e c t e d f i l e / ,
107+ 'should fail when not given a file (#2)'
108+ ) ;
90109
91- it ( 'should fail when not given positional information' , function ( ) {
92- assert . throws ( function ( ) {
110+ t . throws (
111+ function ( ) {
93112 toNLCST ( toFile ( {
94113 'type' : 'text' ,
95114 'value' : 'foo'
96115 } ) ) ;
97- } , / m d a s t - u t i l - t o - n l c s t e x p e c t e d p o s i t i o n o n n o d e s / ) ;
116+ } ,
117+ / m d a s t - u t i l - t o - n l c s t e x p e c t e d p o s i t i o n o n n o d e s / ,
118+ 'should fail when not given positional information'
119+ ) ;
98120
99- assert . throws ( function ( ) {
121+ t . throws (
122+ function ( ) {
100123 toNLCST ( toFile ( {
101124 'type' : 'text' ,
102125 'value' : 'foo' ,
@@ -105,10 +128,12 @@ describe('mdast-util-to-nlcst', function () {
105128 'end' : { }
106129 }
107130 } ) ) ;
108- } , / m d a s t - u t i l - t o - n l c s t e x p e c t e d p o s i t i o n o n n o d e s / ) ;
109- } ) ;
131+ } ,
132+ / m d a s t - u t i l - t o - n l c s t e x p e c t e d p o s i t i o n o n n o d e s / ,
133+ 'should fail when not given positional information (#2)'
134+ ) ;
110135
111- it ( 'should accept nodes without offsets' , function ( ) {
136+ t . test ( 'should accept nodes without offsets' , function ( st ) {
112137 var node = {
113138 'type' : 'text' ,
114139 'value' : 'foo' ,
@@ -126,11 +151,13 @@ describe('mdast-util-to-nlcst', function () {
126151
127152 toNLCST ( toFile ( node ) , Latin ) ;
128153
129- assert . equal ( node . position . start . offset , 0 ) ;
130- assert . equal ( node . position . end . offset , 3 ) ;
154+ st . equal ( node . position . start . offset , 0 ) ;
155+ st . equal ( node . position . end . offset , 3 ) ;
156+
157+ st . end ( ) ;
131158 } ) ;
132159
133- it ( 'should accept a parser' , function ( ) {
160+ t . test ( 'should accept a parser' , function ( st ) {
134161 var node = {
135162 'type' : 'text' ,
136163 'value' : 'foo' ,
@@ -146,58 +173,54 @@ describe('mdast-util-to-nlcst', function () {
146173 }
147174 } ;
148175
149- assert . throws ( function ( ) {
176+ st . throws ( function ( ) {
150177 toNLCST ( toFile ( node ) ) ;
151178 } , / m d a s t - u t i l - t o - n l c s t e x p e c t e d p a r s e r / ) ;
152179
153- assert . doesNotThrow ( function ( ) {
180+ st . doesNotThrow ( function ( ) {
154181 toNLCST ( toFile ( node ) , English ) ;
155182 } ) ;
156183
157- assert . doesNotThrow ( function ( ) {
184+ st . doesNotThrow ( function ( ) {
158185 toNLCST ( toFile ( node ) , Dutch ) ;
159186 } ) ;
160187
161- assert . doesNotThrow ( function ( ) {
188+ st . doesNotThrow ( function ( ) {
162189 toNLCST ( toFile ( node ) , new English ( ) ) ;
163190 } ) ;
164191
165- assert . doesNotThrow ( function ( ) {
192+ st . doesNotThrow ( function ( ) {
166193 toNLCST ( toFile ( node ) , new Dutch ( ) ) ;
167194 } ) ;
168- } ) ;
169- } ) ;
170195
171- /**
172- * Describe a fixture.
173- *
174- * @param {string } fixture - Name of fixture.
175- */
176- function describeFixture ( fixture ) {
177- it ( 'should work on `' + fixture + '`' , function ( done ) {
178- var filepath = join ( ROOT , fixture ) ;
179- var output = read ( join ( filepath , 'output.json' ) , 'utf-8' ) ;
180- var input = read ( join ( filepath , 'input.md' ) , 'utf-8' ) ;
181-
182- remark ( ) . process ( input , function ( err , file ) {
183- assert . deepEqual ( toNLCST ( file , Latin ) , JSON . parse ( output ) ) ;
184- done ( err ) ;
185- } ) ;
196+ st . end ( ) ;
186197 } ) ;
187- }
188-
189- /*
190- * Skip hidden files.
191- */
192-
193- fixtures = fixtures . filter ( function ( filepath ) {
194- return filepath . indexOf ( '.' ) !== 0 ;
195198} ) ;
196199
197200/*
198201 * Assert fixtures.
199202 */
200203
201- describe ( 'Fixtures' , function ( ) {
202- fixtures . forEach ( describeFixture ) ;
204+ test ( 'Fixtures' , function ( t ) {
205+ fixtures
206+ . filter ( function ( filepath ) {
207+ return filepath . indexOf ( '.' ) !== 0 ;
208+ } )
209+ . forEach ( function ( fixture ) {
210+ var filepath = join ( ROOT , fixture ) ;
211+ var output = read ( join ( filepath , 'output.json' ) , 'utf-8' ) ;
212+ var input = read ( join ( filepath , 'input.md' ) , 'utf-8' ) ;
213+
214+ remark ( ) . process ( input , function ( err , file ) {
215+ t . ifError ( err ) ;
216+
217+ t . deepEqual (
218+ toNLCST ( file , Latin ) ,
219+ JSON . parse ( output ) ,
220+ 'should work on `' + fixture + '`'
221+ ) ;
222+ } ) ;
223+ } ) ;
224+
225+ t . end ( ) ;
203226} ) ;
0 commit comments