Skip to content

Commit

Permalink
Fix for changes in @types/unist
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jul 26, 2021
1 parent ced059f commit 73bccbb
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* @typedef {import('mdast').Root} Root
*/

import assert from 'assert'
import test from 'tape'
import remark from 'remark'
import {headingStyle} from './index.js'
Expand All @@ -18,95 +23,101 @@ test('headingStyle', function (t) {
'should NOT fail on undetectable nodes'
)

t.equal(
headingStyle(remark.parse('# ATX').children[0]),
'atx',
'should detect atx'
)
t.equal(headingStyle(parseFirstNode('# ATX')), 'atx', 'should detect atx')

t.equal(
headingStyle(remark.parse('# ATX #').children[0]),
headingStyle(parseFirstNode('# ATX #')),
'atx-closed',
'should detect closed atx'
)

t.equal(
headingStyle(remark.parse('ATX\n===').children[0]),
headingStyle(parseFirstNode('ATX\n===')),
'setext',
'should detect closed setext'
)

t.equal(
headingStyle(remark.parse('### ATX').children[0]),
headingStyle(parseFirstNode('### ATX')),
null,
'should work on ambiguous nodes'
)

t.equal(
headingStyle(remark.parse('### ATX').children[0], 'atx'),
headingStyle(parseFirstNode('### ATX'), 'atx'),
'atx',
'should work on ambiguous nodes (preference to atx)'
)

t.equal(
headingStyle(remark.parse('### ATX').children[0], 'setext'),
headingStyle(parseFirstNode('### ATX'), 'setext'),
'setext',
'should work on ambiguous nodes (preference to setext)'
)

t.equal(
headingStyle(remark.parse('###### ######').children[0]),
headingStyle(parseFirstNode('###### ######')),
'atx-closed',
'should work on empty nodes (#1)'
)

t.equal(
headingStyle(remark.parse('### ###').children[0]),
headingStyle(parseFirstNode('### ###')),
'atx-closed',
'should work on empty nodes (#2)'
)

t.equal(
headingStyle(remark.parse('# #').children[0]),
headingStyle(parseFirstNode('# #')),
'atx-closed',
'should work on empty nodes (#3)'
)

t.equal(
headingStyle(remark.parse('###### ').children[0], 'atx'),
headingStyle(parseFirstNode('###### '), 'atx'),
'atx',
'should work on empty nodes (#4)'
)

t.equal(
headingStyle(remark.parse('### ').children[0], 'atx'),
headingStyle(parseFirstNode('### '), 'atx'),
'atx',
'should work on empty nodes (#5)'
)

t.equal(
headingStyle(remark.parse('## ').children[0]),
headingStyle(parseFirstNode('## ')),
'atx',
'should work on empty nodes (#6)'
)

t.equal(
headingStyle(remark.parse('###### ').children[0], 'setext'),
headingStyle(parseFirstNode('###### '), 'setext'),
'setext',
'should work on empty nodes (#7)'
)

t.equal(
headingStyle(remark.parse('### ').children[0], 'setext'),
headingStyle(parseFirstNode('### '), 'setext'),
'setext',
'should work on empty nodes (#8)'
)

t.equal(
headingStyle(remark.parse('## ').children[0], 'setext'),
headingStyle(parseFirstNode('## '), 'setext'),
'atx',
'should work on empty nodes (#9)'
)

t.end()
})

/**
* @param {string} doc
*/
function parseFirstNode(doc) {
const tree = /** @type {Root} */ (remark.parse(doc))
const head = tree.children[0]
assert(head.type === 'heading')
return head
}

0 comments on commit 73bccbb

Please sign in to comment.