Skip to content

Commit 9e107e3

Browse files
committed
Add more tests
1 parent d78a9f8 commit 9e107e3

File tree

1 file changed

+117
-235
lines changed

1 file changed

+117
-235
lines changed

test.js

Lines changed: 117 additions & 235 deletions
Original file line numberDiff line numberDiff line change
@@ -115,245 +115,10 @@ test('markdown -> mdast', function (t) {
115115
'should support autolink literals'
116116
)
117117

118-
t.deepEqual(
119-
fromMarkdown(
120-
`[http://localhost]: http://localhost "Open example on localhost"
121-
[https://dev.local]: https://dev.local "Open example on localhost"
122-
123-
Existing link [http://localhost][], [https://dev.local][] in paragraph.`,
124-
{
125-
extensions: [syntax],
126-
mdastExtensions: [autolinkLiterals.fromMarkdown]
127-
}
128-
),
129-
{
130-
type: 'root',
131-
children: [
132-
{
133-
type: 'definition',
134-
identifier: 'http://localhost',
135-
label: 'http://localhost',
136-
title: 'Open example on localhost',
137-
url: 'http://localhost',
138-
position: {
139-
start: {line: 1, column: 1, offset: 0},
140-
end: {line: 1, column: 65, offset: 64}
141-
}
142-
},
143-
{
144-
type: 'definition',
145-
identifier: 'https://dev.local',
146-
label: 'https://dev.local',
147-
title: 'Open example on localhost',
148-
url: 'https://dev.local',
149-
position: {
150-
start: {line: 2, column: 1, offset: 65},
151-
end: {line: 2, column: 67, offset: 131}
152-
}
153-
},
154-
{
155-
type: 'paragraph',
156-
children: [
157-
{
158-
type: 'text',
159-
value: 'Existing link ',
160-
position: {
161-
start: {line: 4, column: 1, offset: 133},
162-
end: {line: 4, column: 15, offset: 147}
163-
}
164-
},
165-
{
166-
type: 'linkReference',
167-
children: [
168-
{
169-
type: 'text',
170-
value: 'http://localhost',
171-
position: {
172-
start: {line: 4, column: 16, offset: 148},
173-
end: {line: 4, column: 32, offset: 164}
174-
}
175-
}
176-
],
177-
position: {
178-
start: {line: 4, column: 15, offset: 147},
179-
end: {line: 4, column: 35, offset: 167}
180-
},
181-
identifier: 'http://localhost',
182-
label: 'http://localhost',
183-
referenceType: 'collapsed'
184-
},
185-
{
186-
type: 'text',
187-
value: ', ',
188-
position: {
189-
start: {line: 4, column: 35, offset: 167},
190-
end: {line: 4, column: 37, offset: 169}
191-
}
192-
},
193-
{
194-
type: 'linkReference',
195-
children: [
196-
{
197-
type: 'text',
198-
value: 'https://dev.local',
199-
position: {
200-
start: {line: 4, column: 38, offset: 170},
201-
end: {line: 4, column: 55, offset: 187}
202-
}
203-
}
204-
],
205-
position: {
206-
start: {line: 4, column: 37, offset: 169},
207-
end: {line: 4, column: 58, offset: 190}
208-
},
209-
identifier: 'https://dev.local',
210-
label: 'https://dev.local',
211-
referenceType: 'collapsed'
212-
},
213-
{
214-
type: 'text',
215-
value: ' in paragraph.',
216-
position: {
217-
start: {line: 4, column: 58, offset: 190},
218-
end: {line: 4, column: 72, offset: 204}
219-
}
220-
}
221-
],
222-
position: {
223-
start: {line: 4, column: 1, offset: 133},
224-
end: {line: 4, column: 72, offset: 204}
225-
}
226-
}
227-
],
228-
position: {
229-
start: {line: 1, column: 1, offset: 0},
230-
end: {line: 4, column: 72, offset: 204}
231-
}
232-
},
233-
'should support existing link references with identifier as label'
234-
)
235-
236118
t.end()
237119
})
238120

239121
test('mdast -> markdown', function (t) {
240-
t.deepEqual(
241-
toMarkdown(
242-
{
243-
type: 'root',
244-
children: [
245-
{
246-
type: 'definition',
247-
identifier: 'http://localhost',
248-
label: 'http://localhost',
249-
title: 'Open example on localhost',
250-
url: 'http://localhost',
251-
position: {
252-
start: {line: 1, column: 1, offset: 0},
253-
end: {line: 1, column: 65, offset: 64}
254-
}
255-
},
256-
{
257-
type: 'definition',
258-
identifier: 'https://dev.local',
259-
label: 'https://dev.local',
260-
title: 'Open example on localhost',
261-
url: 'https://dev.local',
262-
position: {
263-
start: {line: 2, column: 1, offset: 65},
264-
end: {line: 2, column: 67, offset: 131}
265-
}
266-
},
267-
{
268-
type: 'paragraph',
269-
children: [
270-
{
271-
type: 'text',
272-
value: 'Existing link ',
273-
position: {
274-
start: {line: 4, column: 1, offset: 133},
275-
end: {line: 4, column: 15, offset: 147}
276-
}
277-
},
278-
{
279-
type: 'linkReference',
280-
children: [
281-
{
282-
type: 'text',
283-
value: 'http://localhost',
284-
position: {
285-
start: {line: 4, column: 16, offset: 148},
286-
end: {line: 4, column: 32, offset: 164}
287-
}
288-
}
289-
],
290-
position: {
291-
start: {line: 4, column: 15, offset: 147},
292-
end: {line: 4, column: 35, offset: 167}
293-
},
294-
identifier: 'http://localhost',
295-
label: 'http://localhost',
296-
referenceType: 'collapsed'
297-
},
298-
{
299-
type: 'text',
300-
value: ', ',
301-
position: {
302-
start: {line: 4, column: 35, offset: 167},
303-
end: {line: 4, column: 37, offset: 169}
304-
}
305-
},
306-
{
307-
type: 'linkReference',
308-
children: [
309-
{
310-
type: 'text',
311-
value: 'https://dev.local',
312-
position: {
313-
start: {line: 4, column: 38, offset: 170},
314-
end: {line: 4, column: 55, offset: 187}
315-
}
316-
}
317-
],
318-
position: {
319-
start: {line: 4, column: 37, offset: 169},
320-
end: {line: 4, column: 58, offset: 190}
321-
},
322-
identifier: 'https://dev.local',
323-
label: 'https://dev.local',
324-
referenceType: 'collapsed'
325-
},
326-
{
327-
type: 'text',
328-
value: ' in paragraph.',
329-
position: {
330-
start: {line: 4, column: 58, offset: 190},
331-
end: {line: 4, column: 72, offset: 204}
332-
}
333-
}
334-
],
335-
position: {
336-
start: {line: 4, column: 1, offset: 133},
337-
end: {line: 4, column: 72, offset: 204}
338-
}
339-
}
340-
],
341-
position: {
342-
start: {line: 1, column: 1, offset: 0},
343-
end: {line: 4, column: 72, offset: 204}
344-
}
345-
},
346-
{extensions: [autolinkLiterals.toMarkdown]}
347-
),
348-
`[http://localhost]: http://localhost "Open example on localhost"
349-
350-
[https://dev.local]: https://dev.local "Open example on localhost"
351-
352-
Existing link [http://localhost][], [https://dev.local][] in paragraph.
353-
`,
354-
'should not escape existing link text.'
355-
)
356-
357122
t.deepEqual(
358123
toMarkdown(
359124
{
@@ -429,5 +194,122 @@ Existing link [http://localhost][], [https://dev.local][] in paragraph.
429194
'should not escape colons if they appear in what can’t be a http protocol'
430195
)
431196

197+
t.deepEqual(
198+
toMarkdown(
199+
{type: 'definition', label: 'http://a'},
200+
{extensions: [autolinkLiterals.toMarkdown]}
201+
),
202+
'[http://a]: <>\n',
203+
'should not escape colons in definition labels'
204+
)
205+
206+
t.deepEqual(
207+
toMarkdown(
208+
{
209+
type: 'paragraph',
210+
children: [
211+
{
212+
type: 'linkReference',
213+
label: 'http://a',
214+
children: [{type: 'text', value: 'http://a'}]
215+
}
216+
]
217+
},
218+
{extensions: [autolinkLiterals.toMarkdown]}
219+
),
220+
'[http://a][]\n',
221+
'should not escape colons in link (reference) labels (shortcut)'
222+
)
223+
224+
t.deepEqual(
225+
toMarkdown(
226+
{
227+
type: 'paragraph',
228+
children: [
229+
{
230+
type: 'linkReference',
231+
label: 'a',
232+
children: [{type: 'text', value: 'http://a'}]
233+
}
234+
]
235+
},
236+
{extensions: [autolinkLiterals.toMarkdown]}
237+
),
238+
'[http://a][a]\n',
239+
'should not escape colons in link (reference) labels (text)'
240+
)
241+
242+
t.deepEqual(
243+
toMarkdown(
244+
{
245+
type: 'paragraph',
246+
children: [
247+
{
248+
type: 'linkReference',
249+
label: 'http://a',
250+
children: [{type: 'text', value: 'a'}]
251+
}
252+
]
253+
},
254+
{extensions: [autolinkLiterals.toMarkdown]}
255+
),
256+
'[a][http://a]\n',
257+
'should not escape colons in link (reference) labels (label)'
258+
)
259+
260+
t.deepEqual(
261+
toMarkdown(
262+
{
263+
type: 'paragraph',
264+
children: [
265+
{
266+
type: 'link',
267+
url: 'http://a',
268+
children: [{type: 'text', value: 'a'}]
269+
}
270+
]
271+
},
272+
{extensions: [autolinkLiterals.toMarkdown]}
273+
),
274+
'[a](http://a)\n',
275+
'should not escape colons in link (resource) labels'
276+
)
277+
278+
t.deepEqual(
279+
toMarkdown(
280+
{
281+
type: 'paragraph',
282+
children: [{type: 'imageReference', label: 'http://a', alt: 'a'}]
283+
},
284+
{extensions: [autolinkLiterals.toMarkdown]}
285+
),
286+
'![a][http://a]\n',
287+
'should not escape colons in image (reference) labels (label)'
288+
)
289+
290+
t.deepEqual(
291+
toMarkdown(
292+
{
293+
type: 'paragraph',
294+
children: [{type: 'imageReference', label: 'a', alt: 'http://a'}]
295+
},
296+
{extensions: [autolinkLiterals.toMarkdown]}
297+
),
298+
'![http://a][a]\n',
299+
'should not escape colons in image (reference) labels (alt)'
300+
)
301+
302+
t.deepEqual(
303+
toMarkdown(
304+
{
305+
type: 'paragraph',
306+
children: [{type: 'image', url: 'http://a', alt: 'a'}]
307+
},
308+
{extensions: [autolinkLiterals.toMarkdown]}
309+
),
310+
'![a](http://a)\n',
311+
'should not escape colons in image (resource) labels'
312+
)
313+
432314
t.end()
433315
})

0 commit comments

Comments
 (0)