@@ -4,81 +4,75 @@ var fs = require('fs')
4
4
var path = require ( 'path' )
5
5
var test = require ( 'tape' )
6
6
var remark = require ( 'remark' )
7
+ var gfm = require ( 'remark-gfm' )
7
8
var frontmatter = require ( 'remark-frontmatter' )
8
- var vfile = require ( 'vfile' )
9
+ var vfile = require ( 'to- vfile' )
9
10
var Latin = require ( 'parse-latin' )
10
11
var Dutch = require ( 'parse-dutch' )
11
12
var English = require ( 'parse-english' )
12
13
var negate = require ( 'negate' )
13
14
var hidden = require ( 'is-hidden' )
14
- var toNLCST = require ( '..' )
15
-
16
- var read = fs . readFileSync
17
- var join = path . join
18
-
19
- var ROOT = join ( __dirname , 'fixtures' )
20
-
21
- var fixtures = fs . readdirSync ( ROOT )
15
+ var toNlcst = require ( '..' )
22
16
23
17
test ( 'mdast-util-to-nlcst' , function ( t ) {
24
18
t . throws (
25
19
function ( ) {
26
- toNLCST ( )
20
+ toNlcst ( )
27
21
} ,
28
22
/ 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 / ,
29
23
'should fail when not given an AST'
30
24
)
31
25
32
26
t . throws (
33
27
function ( ) {
34
- toNLCST ( { } )
28
+ toNlcst ( { } )
35
29
} ,
36
30
/ 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 / ,
37
31
'should fail when not given an AST (#2)'
38
32
)
39
33
40
34
t . throws (
41
35
function ( ) {
42
- toNLCST ( { type : 'foo' } )
36
+ toNlcst ( { type : 'foo' } )
43
37
} ,
44
38
/ 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 / ,
45
39
'should fail when not given a file'
46
40
)
47
41
48
42
t . throws (
49
43
function ( ) {
50
- toNLCST ( { type : 'foo' } )
44
+ toNlcst ( { type : 'foo' } )
51
45
} ,
52
46
/ 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 / ,
53
47
'should fail when not given a file (#2)'
54
48
)
55
49
56
50
t . throws (
57
51
function ( ) {
58
- toNLCST ( { type : 'text' , value : 'foo' } , { foo : 'bar' } )
52
+ toNlcst ( { type : 'text' , value : 'foo' } , { foo : 'bar' } )
59
53
} ,
60
54
/ 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 / ,
61
55
'should fail when not given a file (#3)'
62
56
)
63
57
64
58
t . throws (
65
59
function ( ) {
66
- toNLCST ( { type : 'text' , value : 'foo' } , vfile ( 'foo' ) )
60
+ toNlcst ( { type : 'text' , value : 'foo' } , vfile ( { contents : 'foo' } ) )
67
61
} ,
68
62
/ 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 / ,
69
63
'should fail without parser'
70
64
)
71
65
72
66
t . throws (
73
67
function ( ) {
74
- toNLCST ( { type : 'text' , value : 'foo' } , vfile ( ) , Latin )
68
+ toNlcst ( { type : 'text' , value : 'foo' } , vfile ( ) , Latin )
75
69
} ,
76
70
/ 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 / ,
77
71
'should fail when not given positional information'
78
72
)
79
73
80
74
t . doesNotThrow ( function ( ) {
81
- toNLCST (
75
+ toNlcst (
82
76
{
83
77
type : 'text' ,
84
78
value : 'foo' ,
@@ -90,7 +84,7 @@ test('mdast-util-to-nlcst', function (t) {
90
84
} , 'should accept a parser constructor' )
91
85
92
86
t . doesNotThrow ( function ( ) {
93
- toNLCST (
87
+ toNlcst (
94
88
{
95
89
type : 'text' ,
96
90
value : 'foo' ,
@@ -103,7 +97,7 @@ test('mdast-util-to-nlcst', function (t) {
103
97
104
98
t . throws (
105
99
function ( ) {
106
- toNLCST (
100
+ toNlcst (
107
101
{
108
102
type : 'text' ,
109
103
value : 'foo' ,
@@ -118,13 +112,13 @@ test('mdast-util-to-nlcst', function (t) {
118
112
)
119
113
120
114
t . test ( 'should accept nodes without offsets' , function ( st ) {
121
- var node = toNLCST (
115
+ var node = toNlcst (
122
116
{
123
117
type : 'text' ,
124
118
value : 'foo' ,
125
119
position : { start : { line : 1 , column : 1 } , end : { line : 1 , column : 4 } }
126
120
} ,
127
- vfile ( 'foo' ) ,
121
+ vfile ( { contents : 'foo' } ) ,
128
122
Latin
129
123
)
130
124
@@ -138,27 +132,32 @@ test('mdast-util-to-nlcst', function (t) {
138
132
} )
139
133
140
134
test ( 'Fixtures' , function ( t ) {
141
- fixtures . filter ( negate ( hidden ) ) . forEach ( function ( fixture ) {
142
- var filepath = join ( ROOT , fixture )
143
- var output = read ( join ( filepath , 'output.json' ) , 'utf-8' )
144
- var input = read ( join ( filepath , 'input.md' ) , 'utf-8' )
145
- var options
146
-
147
- try {
148
- options = JSON . parse ( read ( join ( filepath , 'options.json' ) ) )
149
- } catch ( _ ) { }
150
-
151
- t . deepEqual (
152
- toNLCST (
153
- remark ( ) . use ( frontmatter ) . parse ( input ) ,
154
- vfile ( input ) ,
155
- Latin ,
156
- options
157
- ) ,
158
- JSON . parse ( output ) ,
159
- 'should work on `' + fixture + '`'
160
- )
161
- } )
135
+ var base = path . join ( __dirname , 'fixtures' )
136
+
137
+ fs . readdirSync ( base )
138
+ . filter ( negate ( hidden ) )
139
+ . forEach ( function ( name ) {
140
+ var input = vfile . readSync ( path . join ( base , name , 'input.md' ) )
141
+ var expected = JSON . parse (
142
+ vfile . readSync ( path . join ( base , name , 'output.json' ) )
143
+ )
144
+ var options
145
+
146
+ try {
147
+ options = JSON . parse (
148
+ vfile . readSync ( path . join ( base , name , 'options.json' ) )
149
+ )
150
+ } catch ( _ ) { }
151
+
152
+ var mdast = remark ( )
153
+ . use ( options && options . useRemarkGfm ? gfm : [ ] )
154
+ . use ( options && options . useRemarkFrontmatter ? frontmatter : [ ] )
155
+ . parse ( input )
156
+
157
+ var actual = toNlcst ( mdast , input , Latin , options )
158
+
159
+ t . deepEqual ( actual , expected , 'should work on `' + name + '`' )
160
+ } )
162
161
163
162
t . end ( )
164
163
} )
0 commit comments