|
1 |
| -/** |
2 |
| - * @typedef {import('mdast').Root} Root |
3 |
| - * @typedef {import('mdast').Paragraph} Paragraph |
4 |
| - */ |
5 |
| - |
6 | 1 | import assert from 'node:assert/strict'
|
7 | 2 | import test from 'node:test'
|
8 | 3 | import {u} from 'unist-builder'
|
9 | 4 | import {squeezeParagraphs} from './index.js'
|
10 | 5 |
|
11 |
| -test('squeezeParagraphs', () => { |
12 |
| - assert.deepEqual( |
13 |
| - squeezeParagraphs( |
14 |
| - /** @type {Root} */ ( |
15 |
| - u('root', [ |
16 |
| - u('paragraph', []), |
17 |
| - u('paragraph', [u('text', 'first')]), |
18 |
| - u('paragraph', []), |
19 |
| - u('paragraph', [u('text', ''), u('text', ' \n')]), |
20 |
| - u('paragraph', [ |
21 |
| - u('text', 'second'), |
22 |
| - u('text', ' '), |
23 |
| - u('text', 'value') |
24 |
| - ]), |
25 |
| - u('paragraph', []), |
26 |
| - u('list', {ordered: false, start: null, loose: false}, [ |
27 |
| - u('listItem', {loose: false}, [u('paragraph', [])]), |
28 |
| - u('listItem', {loose: false}, [ |
29 |
| - u('paragraph', [u('text', ' '), u('text', ' ')]) |
30 |
| - ]) |
31 |
| - ]) |
32 |
| - ]) |
33 |
| - ) |
34 |
| - ), |
35 |
| - u('root', [ |
| 6 | +test('squeezeParagraphs', async function (t) { |
| 7 | + await t.test('should work on a tree', async function () { |
| 8 | + const tree = u('root', [ |
| 9 | + u('paragraph', []), |
36 | 10 | u('paragraph', [u('text', 'first')]),
|
| 11 | + u('paragraph', []), |
| 12 | + u('paragraph', [u('text', ''), u('text', ' \n')]), |
37 | 13 | u('paragraph', [u('text', 'second'), u('text', ' '), u('text', 'value')]),
|
| 14 | + u('paragraph', []), |
38 | 15 | u('list', {ordered: false, start: null, loose: false}, [
|
39 |
| - u('listItem', {loose: false}, []), |
40 |
| - u('listItem', {loose: false}, []) |
| 16 | + u('listItem', {loose: false}, [u('paragraph', [])]), |
| 17 | + u('listItem', {loose: false}, [ |
| 18 | + u('paragraph', [u('text', ' '), u('text', ' ')]) |
| 19 | + ]) |
41 | 20 | ])
|
42 | 21 | ])
|
43 |
| - ) |
44 | 22 |
|
45 |
| - assert.deepEqual( |
46 |
| - squeezeParagraphs(/** @type {Paragraph} */ (u('paragraph', []))), |
47 |
| - null, |
48 |
| - 'should return `null` for empty paragraphs' |
49 |
| - ) |
| 23 | + assert.deepEqual( |
| 24 | + squeezeParagraphs(tree), |
| 25 | + u('root', [ |
| 26 | + u('paragraph', [u('text', 'first')]), |
| 27 | + u('paragraph', [ |
| 28 | + u('text', 'second'), |
| 29 | + u('text', ' '), |
| 30 | + u('text', 'value') |
| 31 | + ]), |
| 32 | + u('list', {ordered: false, start: null, loose: false}, [ |
| 33 | + u('listItem', {loose: false}, []), |
| 34 | + u('listItem', {loose: false}, []) |
| 35 | + ]) |
| 36 | + ]) |
| 37 | + ) |
| 38 | + }) |
| 39 | + |
| 40 | + await t.test('should return `null` for empty paragraphs', async function () { |
| 41 | + const tree = u('paragraph', []) |
| 42 | + |
| 43 | + assert.deepEqual(squeezeParagraphs(tree), null) |
| 44 | + }) |
50 | 45 | })
|
0 commit comments