Skip to content

Commit 00e19c5

Browse files
committed
Update for changes in mdast
1 parent fc3826e commit 00e19c5

11 files changed

+157
-52
lines changed

index.js

+41-21
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ var zwitch = require('zwitch')
66
var mapz = require('mapz')
77
var unist = require('unist-util-assert')
88

9-
/* Construct. */
9+
// Construct.
1010
var mdast = zwitch('type')
1111

12-
/* Expose. */
12+
// Expose.
1313
exports = unist.wrap(mdast)
1414
module.exports = exports
1515

@@ -19,11 +19,11 @@ exports.void = unist.void
1919
exports.wrap = unist.wrap
2020
exports.all = mapz(exports, {key: 'children', indices: false})
2121

22-
/* Core interface. */
22+
// Core interface.
2323
mdast.unknown = unknown
2424
mdast.invalid = unknown
2525

26-
/* Per-type handling. */
26+
// Per-type handling.
2727
mdast.handlers = {
2828
root: unist.wrap(root),
2929
paragraph: exports.parent,
@@ -39,6 +39,7 @@ mdast.handlers = {
3939
text: exports.text,
4040
inlineCode: exports.text,
4141
yaml: exports.text,
42+
toml: exports.text,
4243
code: unist.wrap(code),
4344
thematicBreak: exports.void,
4445
break: exports.void,
@@ -72,11 +73,11 @@ function root(node, ancestor) {
7273
function list(node) {
7374
parent(node)
7475

75-
if (node.loose != null) {
76+
if (node.spread != null) {
7677
assert.strictEqual(
77-
typeof node.loose,
78+
typeof node.spread,
7879
'boolean',
79-
'`loose` must be `boolean`'
80+
'`spread` must be `boolean`'
8081
)
8182
}
8283

@@ -103,11 +104,11 @@ function list(node) {
103104
function listItem(node) {
104105
parent(node)
105106

106-
if (node.loose != null) {
107+
if (node.spread != null) {
107108
assert.strictEqual(
108-
typeof node.loose,
109+
typeof node.spread,
109110
'boolean',
110-
'`loose` must be `boolean`'
111+
'`spread` must be `boolean`'
111112
)
112113
}
113114

@@ -133,6 +134,11 @@ function code(node) {
133134
if (node.lang != null) {
134135
assert.strictEqual(typeof node.lang, 'string', '`lang` must be `string`')
135136
}
137+
138+
if (node.meta != null) {
139+
assert.ok(node.lang != null, 'code with `meta` must also have `lang`')
140+
assert.strictEqual(typeof node.meta, 'string', '`meta` must be `string`')
141+
}
136142
}
137143

138144
function footnoteDefinition(node) {
@@ -143,6 +149,10 @@ function footnoteDefinition(node) {
143149
'string',
144150
'`footnoteDefinition` must have `identifier`'
145151
)
152+
153+
if (node.label != null) {
154+
assert.strictEqual(typeof node.label, 'string', '`label` must be `string`')
155+
}
146156
}
147157

148158
function definition(node) {
@@ -154,10 +164,12 @@ function definition(node) {
154164
'`identifier` must be `string`'
155165
)
156166

157-
if (node.url != null) {
158-
assert.strictEqual(typeof node.url, 'string', '`url` must be `string`')
167+
if (node.label != null) {
168+
assert.strictEqual(typeof node.label, 'string', '`label` must be `string`')
159169
}
160170

171+
assert.strictEqual(typeof node.url, 'string', '`url` must be `string`')
172+
161173
if (node.title != null) {
162174
assert.strictEqual(typeof node.title, 'string', '`title` must be `string`')
163175
}
@@ -166,9 +178,7 @@ function definition(node) {
166178
function link(node) {
167179
parent(node)
168180

169-
if (node.url != null) {
170-
assert.strictEqual(typeof node.url, 'string', '`url` must be `string`')
171-
}
181+
assert.strictEqual(typeof node.url, 'string', '`url` must be `string`')
172182

173183
if (node.title != null) {
174184
assert.strictEqual(typeof node.title, 'string', '`title` must be `string`')
@@ -178,17 +188,15 @@ function link(node) {
178188
function image(node) {
179189
unist.void(node)
180190

181-
if (node.url != null) {
182-
assert.strictEqual(typeof node.url, 'string', '`url` must be `string`')
191+
assert.strictEqual(typeof node.url, 'string', '`url` must be `string`')
192+
193+
if (node.title != null) {
194+
assert.strictEqual(typeof node.title, 'string', '`title` must be `string`')
183195
}
184196

185197
if (node.alt != null) {
186198
assert.strictEqual(typeof node.alt, 'string', '`alt` must be `string`')
187199
}
188-
189-
if (node.title != null) {
190-
assert.strictEqual(typeof node.title, 'string', '`title` must be `string`')
191-
}
192200
}
193201

194202
function linkReference(node) {
@@ -200,6 +208,10 @@ function linkReference(node) {
200208
'`identifier` must be `string`'
201209
)
202210

211+
if (node.label != null) {
212+
assert.strictEqual(typeof node.label, 'string', '`label` must be `string`')
213+
}
214+
203215
if (node.referenceType != null) {
204216
assert.notStrictEqual(
205217
['shortcut', 'collapsed', 'full'].indexOf(node.referenceType),
@@ -218,6 +230,10 @@ function imageReference(node) {
218230
'`identifier` must be `string`'
219231
)
220232

233+
if (node.label != null) {
234+
assert.strictEqual(typeof node.label, 'string', '`label` must be `string`')
235+
}
236+
221237
if (node.alt != null) {
222238
assert.strictEqual(typeof node.alt, 'string', '`alt` must be `string`')
223239
}
@@ -239,6 +255,10 @@ function footnoteReference(node) {
239255
'string',
240256
'`identifier` must be `string`'
241257
)
258+
259+
if (node.label != null) {
260+
assert.strictEqual(typeof node.label, 'string', '`label` must be `string`')
261+
}
242262
}
243263

244264
function table(node) {

test/code.js

+16
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,21 @@ test('assert(code)', function(t) {
2424
'should throw if `lang` is not a string'
2525
)
2626

27+
t.throws(
28+
function() {
29+
assert({type: 'code', lang: 'js', meta: 1, value: ''})
30+
},
31+
/`meta` must be `string`: `{ type: 'code', lang: 'js', meta: 1, value: '' }`$/,
32+
'should throw if `meta` is not a string'
33+
)
34+
35+
t.throws(
36+
function() {
37+
assert({type: 'code', meta: '', value: ''})
38+
},
39+
/code with `meta` must also have `lang`: `{ type: 'code', meta: '', value: '' }`$/,
40+
'should throw if `meta` is defined but not `lang`'
41+
)
42+
2743
t.end()
2844
})

test/definition.js

+23-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ test('assert(definition)', function(t) {
1212
'should throw if `definition` has no `identifier`'
1313
)
1414

15+
t.throws(
16+
function() {
17+
assert({type: 'definition', identifier: '1'})
18+
},
19+
/`url` must be `string`: `{ type: 'definition', identifier: '1' }`$/,
20+
'should throw if `definition` has no `url`'
21+
)
22+
1523
t.throws(
1624
function() {
1725
assert({type: 'definition', identifier: 1})
@@ -20,24 +28,32 @@ test('assert(definition)', function(t) {
2028
'should throw if `identifier` is not a `string`'
2129
)
2230

31+
t.throws(
32+
function() {
33+
assert({type: 'definition', url: 1})
34+
},
35+
/`identifier` must be `string`: `{ type: 'definition', url: 1 }`$/,
36+
'should throw if `url` is not a `string`'
37+
)
38+
2339
t.doesNotThrow(function() {
24-
assert({type: 'definition', identifier: '1'})
40+
assert({type: 'definition', identifier: '1', url: '1'})
2541
}, 'should not throw if `definition` has no other properties')
2642

2743
t.throws(
2844
function() {
29-
assert({type: 'definition', identifier: '1', url: 1})
45+
assert({type: 'definition', identifier: '1', url: '1', title: 1})
3046
},
31-
/`url` must be `string`: `{ type: 'definition', identifier: '1', url: 1 }`$/,
32-
'should throw if `identifier` is not a `string`'
47+
/`title` must be `string`: `{ type: 'definition', identifier: '1', url: '1', title: 1 }`$/,
48+
'should throw if `title` is not a `string`'
3349
)
3450

3551
t.throws(
3652
function() {
37-
assert({type: 'definition', identifier: '1', title: 1})
53+
assert({type: 'definition', identifier: '1', url: '1', label: 1})
3854
},
39-
/`title` must be `string`: `{ type: 'definition', identifier: '1', title: 1 }`$/,
40-
'should throw if `title` is not a `string`'
55+
/`label` must be `string`: `{ type: 'definition', identifier: '1', url: '1', label: 1 }`$/,
56+
'should throw if `label` is not a `string`'
4157
)
4258

4359
t.end()

test/footnote-definition.js

+13
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,18 @@ test('assert(footnoteDefinition)', function(t) {
3232
assert({type: 'footnoteDefinition', identifier: '1', children: []})
3333
}, 'should not throw if `footnoteDefinition` has an identifier')
3434

35+
t.throws(
36+
function() {
37+
assert({
38+
type: 'footnoteDefinition',
39+
identifier: '1',
40+
label: 1,
41+
children: []
42+
})
43+
},
44+
/`label` must be `string`: `{ type: 'footnoteDefinition',\s+identifier: '1',\s+label: 1,\s+children: \[] }`$/,
45+
'should throw if `label` is not a `string`'
46+
)
47+
3548
t.end()
3649
})

test/footnote-reference.js

+8
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,13 @@ test('assert(footnoteReference)', function(t) {
2424
assert({type: 'footnoteReference', identifier: '1'})
2525
}, 'should not throw if `footnoteReference` has no other properties')
2626

27+
t.throws(
28+
function() {
29+
assert({type: 'footnoteReference', identifier: '1', label: 1})
30+
},
31+
/`label` must be `string`: `{ type: 'footnoteReference', identifier: '1', label: 1 }`$/,
32+
'should throw if `label` is not a `string`'
33+
)
34+
2735
t.end()
2836
})

test/image-reference.js

+8
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,13 @@ test('assert(imageReference)', function(t) {
4848
})
4949
}, 'should not throw if `referenceType` is valid')
5050

51+
t.throws(
52+
function() {
53+
assert({type: 'imageReference', identifier: '1', label: 1})
54+
},
55+
/`label` must be `string`: `{ type: 'imageReference', identifier: '1', label: 1 }`$/,
56+
'should throw if `label` is not a `string`'
57+
)
58+
5159
t.end()
5260
})

test/image.js

+16-8
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,39 @@ var test = require('tape')
44
var assert = require('..')
55

66
test('assert(image)', function(t) {
7-
t.doesNotThrow(function() {
8-
assert({type: 'image'})
9-
}, 'should not throw if `image` has no other properties')
7+
t.throws(
8+
function() {
9+
assert({type: 'image'})
10+
},
11+
/`url` must be `string`: `{ type: 'image' }`$/,
12+
'should throw without `url`'
13+
)
1014

1115
t.throws(
1216
function() {
1317
assert({type: 'image', url: 1})
1418
},
1519
/`url` must be `string`: `{ type: 'image', url: 1 }`$/,
16-
'should throw if `identifier` is not a `string`'
20+
'should throw if `url` is not a `string`'
1721
)
1822

23+
t.doesNotThrow(function() {
24+
assert({type: 'image', url: '1'})
25+
}, 'should not throw if `image` has no other properties')
26+
1927
t.throws(
2028
function() {
21-
assert({type: 'image', title: 1})
29+
assert({type: 'image', url: '1', title: 1})
2230
},
23-
/`title` must be `string`: `{ type: 'image', title: 1 }`$/,
31+
/`title` must be `string`: `{ type: 'image', url: '1', title: 1 }`$/,
2432
'should throw if `title` is not a `string`'
2533
)
2634

2735
t.throws(
2836
function() {
29-
assert({type: 'image', alt: 1})
37+
assert({type: 'image', url: '1', alt: 1})
3038
},
31-
/`alt` must be `string`: `{ type: 'image', alt: 1 }`$/,
39+
/`alt` must be `string`: `{ type: 'image', url: '1', alt: 1 }`$/,
3240
'should throw if `alt` is not a `string`'
3341
)
3442

test/link-reference.js

+8
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,13 @@ test('assert(linkReference)', function(t) {
5454
})
5555
}, 'should not throw if `referenceType` is valid')
5656

57+
t.throws(
58+
function() {
59+
assert({type: 'linkReference', identifier: '1', children: [], label: 1})
60+
},
61+
/`label` must be `string`: `{ type: 'linkReference', identifier: '1', children: \[], label: 1 }`$/,
62+
'should throw if `label` is not a `string`'
63+
)
64+
5765
t.end()
5866
})

test/link.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,31 @@ test('assert(link)', function(t) {
1212
'should throw if `link` is not a parent'
1313
)
1414

15-
t.doesNotThrow(function() {
16-
assert({type: 'link', children: []})
17-
}, 'should not throw if `link` has no other properties')
15+
t.throws(
16+
function() {
17+
assert({type: 'link', children: []})
18+
},
19+
/`url` must be `string`: `{ type: 'link', children: \[] }`$/,
20+
'should throw without `url`'
21+
)
1822

1923
t.throws(
2024
function() {
2125
assert({type: 'link', children: [], url: 1})
2226
},
2327
/`url` must be `string`: `{ type: 'link', children: \[], url: 1 }`$/,
24-
'should throw if `identifier` is not a `string`'
28+
'should throw if `url` is not a `string`'
2529
)
2630

31+
t.doesNotThrow(function() {
32+
assert({type: 'link', children: [], url: '1'})
33+
}, 'should not throw if `link` has no other properties')
34+
2735
t.throws(
2836
function() {
29-
assert({type: 'link', children: [], title: 1})
37+
assert({type: 'link', children: [], url: '1', title: 1})
3038
},
31-
/`title` must be `string`: `{ type: 'link', children: \[], title: 1 }`$/,
39+
/`title` must be `string`: `{ type: 'link', children: \[], url: '1', title: 1 }`$/,
3240
'should throw if `title` is not a `string`'
3341
)
3442

0 commit comments

Comments
 (0)