Skip to content

Commit 66890d4

Browse files
committed
Add tests for extensions
1 parent 7a2573f commit 66890d4

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

test/index.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,67 @@ test('mdast-util-from-markdown', function (t) {
6262
'should parse a paragraph'
6363
)
6464

65+
t.equal(
66+
fromMarkdown(Buffer.from([0x62, 0x72, 0xc3, 0xa1, 0x76, 0x6f])).children[0]
67+
.children[0].value,
68+
'brávo',
69+
'should support buffers'
70+
)
71+
72+
t.equal(
73+
fromMarkdown(Buffer.from([0x62, 0x72, 0xc3, 0xa1, 0x76, 0x6f]), 'ascii')
74+
.children[0].children[0].value,
75+
'brC!vo',
76+
'should support encoding'
77+
)
78+
79+
t.deepEqual(
80+
fromMarkdown('a\nb', {
81+
mdastExtensions: [
82+
{
83+
// Unknown objects are used, but have no effect.
84+
unknown: undefined,
85+
enter: {lineEnding: lineEndingAsHardBreakEnter},
86+
exit: {lineEnding: lineEndingAsHardBreakExit}
87+
}
88+
]
89+
}).children[0].children,
90+
[
91+
{
92+
type: 'text',
93+
value: 'a',
94+
position: {
95+
start: {line: 1, column: 1, offset: 0},
96+
end: {line: 1, column: 2, offset: 1}
97+
}
98+
},
99+
{
100+
type: 'break',
101+
position: {
102+
start: {line: 1, column: 2, offset: 1},
103+
end: {line: 2, column: 1, offset: 2}
104+
}
105+
},
106+
{
107+
type: 'text',
108+
value: 'b',
109+
position: {
110+
start: {line: 2, column: 1, offset: 2},
111+
end: {line: 2, column: 2, offset: 3}
112+
}
113+
}
114+
],
115+
'should support extensions'
116+
)
117+
118+
function lineEndingAsHardBreakEnter(token) {
119+
this.enter({type: 'break'}, token)
120+
}
121+
122+
function lineEndingAsHardBreakExit(token) {
123+
this.exit(token)
124+
}
125+
65126
t.deepEqual(
66127
fromMarkdown('<tel:123>').children[0],
67128
{

0 commit comments

Comments
 (0)