Skip to content

Commit ab22ba4

Browse files
committed
Add cases for flatParse with empty and incomplete structures
1 parent 8cd1b4b commit ab22ba4

1 file changed

Lines changed: 108 additions & 0 deletions

File tree

test/parse/flat-parse.spec.js

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ describe('flat-parse', () => {
6161

6262
deepEqual(actual, expected)
6363
})
64+
65+
test('without last </DL>', () => {
66+
const initial = fragments.folder.replace('</DL><p>', '')
67+
const actual = flatParse(initial)
68+
69+
deepEqual(actual, expected)
70+
})
6471
})
6572

6673
test('empty fragment', () => {
@@ -77,6 +84,107 @@ describe('flat-parse', () => {
7784
deepEqual(actual, expected)
7885
})
7986

87+
test('skip empty folder', () => {
88+
const initial = `
89+
<DT><H3>JavaScript</H3>
90+
<DL><p>
91+
<DT><A HREF="https://tc39.es/">TC39 - Specifying JavaScript.</A>
92+
<DT><H3>Engines</H3>
93+
<DL><p>
94+
<DT><A HREF="https://v8.dev/">V8 JavaScript engine</A>
95+
</DL><p>
96+
<DT><H3>Runtimes</H3>
97+
<DL><p>
98+
</DL><p>
99+
</DL><p>
100+
`
101+
102+
const actual = flatParse(initial)
103+
104+
const expected = [
105+
{
106+
folder: [
107+
{
108+
title: 'JavaScript'
109+
}
110+
],
111+
href: 'https://tc39.es/',
112+
title: 'TC39 - Specifying JavaScript.'
113+
},
114+
{
115+
folder: [
116+
{
117+
title: 'JavaScript'
118+
},
119+
{
120+
title: 'Engines'
121+
}
122+
],
123+
href: 'https://v8.dev/',
124+
title: 'V8 JavaScript engine'
125+
}
126+
]
127+
128+
deepEqual(actual, expected)
129+
})
130+
131+
test('without closing </DL> at all', () => {
132+
const initial = `
133+
<DT><H3>Folder1</H3>
134+
<DL><p>
135+
<DT><A HREF="https://developer.mozilla.org/">MDN Web Docs</A>
136+
<DT><H3>Folder2</H3>
137+
<DL><p>
138+
<DT><A HREF="https://tc39.es/">TC39 - Specifying JavaScript.</A>
139+
<DT><H3>Folder3</H3>
140+
<DL><p>
141+
<DT><A HREF="https://v8.dev/">V8 JavaScript engine</A>
142+
`
143+
144+
const actual = flatParse(initial)
145+
146+
const expected = [
147+
{
148+
folder: [
149+
{
150+
title: 'Folder1'
151+
}
152+
],
153+
href: 'https://developer.mozilla.org/',
154+
title: 'MDN Web Docs'
155+
},
156+
{
157+
folder: [
158+
{
159+
title: 'Folder1'
160+
},
161+
{
162+
title: 'Folder2'
163+
}
164+
],
165+
href: 'https://tc39.es/',
166+
title: 'TC39 - Specifying JavaScript.'
167+
},
168+
{
169+
folder: [
170+
{
171+
title: 'Folder1'
172+
},
173+
{
174+
title: 'Folder2'
175+
},
176+
{
177+
title: 'Folder3'
178+
}
179+
],
180+
href: 'https://v8.dev/',
181+
title: 'V8 JavaScript engine'
182+
}
183+
]
184+
185+
deepEqual(actual, expected)
186+
})
187+
80188
describe('bookmarks-1.html', () => {
81189
const initial = readFile('./bookmarks-1.html')
82190

0 commit comments

Comments
 (0)