Skip to content

Commit

Permalink
Use Node test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Mar 30, 2023
1 parent 336d9e8 commit ee1e481
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 38 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@
},
"devDependencies": {
"@types/node": "^18.0.0",
"@types/tape": "^4.0.0",
"c8": "^7.0.0",
"micromark": "^3.0.0",
"micromark-build": "^1.0.0",
"prettier": "^2.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^5.0.0",
"xo": "^0.53.0"
Expand Down
71 changes: 35 additions & 36 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import test from 'tape'
import assert from 'node:assert/strict'
import test from 'node:test'
import katex from 'katex'
import {micromark} from 'micromark'
import {math as syntax, mathHtml as html} from 'micromark-extension-math'
Expand All @@ -7,8 +8,8 @@ import {math as syntax, mathHtml as html} from 'micromark-extension-math'
// @ts-expect-error: types are incorrect.
const renderToString = katex.renderToString

test('markdown -> html (micromark)', (t) => {
t.equal(
test('markdown -> html (micromark)', () => {
assert.equal(
micromark('$a$, $$b$$, $$$c$$$', {
extensions: [syntax()],
htmlExtensions: [html()]
Expand All @@ -23,7 +24,7 @@ test('markdown -> html (micromark)', (t) => {
'should support one, two, or more dollars by default'
)

t.equal(
assert.equal(
micromark('$a$, $$b$$, $$$c$$$', {
extensions: [syntax({singleDollarTextMath: false})],
htmlExtensions: [html()]
Expand All @@ -36,37 +37,37 @@ test('markdown -> html (micromark)', (t) => {
'should support two or more dollars w/ `singleDollarTextMath: false`, but not one'
)

t.equal(
assert.equal(
micromark('a \\$b$', {extensions: [syntax()], htmlExtensions: [html()]}),
'<p>a $b$</p>',
'should support an escaped dollar sign which would otherwise open math'
)

t.throws(
assert.throws(
() => {
micromark('a $b\\$', {extensions: [syntax()], htmlExtensions: [html()]})
},
/KaTeX parse error: Unexpected character: '\\' at position 2/,
'should not support escaped dollar signs in math (text)'
)

t.equal(
assert.equal(
micromark('a \\$$b$', {extensions: [syntax()], htmlExtensions: [html()]}),
'<p>a $<span class="math math-inline">' +
renderToString('b') +
'</span></p>',
'should support math (text) right after an escaped dollar sign'
)

t.throws(
assert.throws(
() => {
micromark('a $$ $ $$', {extensions: [syntax()], htmlExtensions: [html()]})
},
/KaTeX parse error: Can't use function '\$' in math mode at position 1/,
'should support a single dollar in math (text) w/ padding and two dollar signs'
)

t.equal(
assert.equal(
micromark('a $$\\raisebox{0.25em}{$\\frac a b$}$$ b', {
extensions: [syntax()],
htmlExtensions: [html()]
Expand All @@ -77,7 +78,7 @@ test('markdown -> html (micromark)', (t) => {
'should support nested math by using more dollars outside of math (text)'
)

t.equal(
assert.equal(
micromark('a $$ \\$ $$ b', {
extensions: [syntax()],
htmlExtensions: [html()]
Expand All @@ -88,7 +89,7 @@ test('markdown -> html (micromark)', (t) => {
'should support an “escaped” dollar right on the KaTeX level, not on the Markdown level'
)

t.equal(
assert.equal(
micromark('a $$\na\\$ $$ b', {
extensions: [syntax()],
htmlExtensions: [html()]
Expand All @@ -99,31 +100,31 @@ test('markdown -> html (micromark)', (t) => {
'should support padding with a line ending in math (text)'
)

t.equal(
assert.equal(
micromark('a $b$', {extensions: [syntax()], htmlExtensions: [html()]}),
'<p>a <span class="math math-inline">' +
renderToString('b') +
'</span></p>',
'should support math (text) w/ one dollar sign'
)

t.equal(
assert.equal(
micromark('a $$b$$', {extensions: [syntax()], htmlExtensions: [html()]}),
'<p>a <span class="math math-inline">' +
renderToString('b') +
'</span></p>',
'should support math (text) w/ two dollar signs'
)

t.equal(
assert.equal(
micromark('a $$$b$$$', {extensions: [syntax()], htmlExtensions: [html()]}),
'<p>a <span class="math math-inline">' +
renderToString('b') +
'</span></p>',
'should support math (text) w/ three dollar signs'
)

t.equal(
assert.equal(
micromark('a $b\nc\rd\r\ne$ f', {
extensions: [syntax()],
htmlExtensions: [html()]
Expand All @@ -134,7 +135,7 @@ test('markdown -> html (micromark)', (t) => {
'should support EOLs in math'
)

t.equal(
assert.equal(
micromark('$\na\n$', {
extensions: [syntax()],
htmlExtensions: [html()]
Expand All @@ -143,7 +144,7 @@ test('markdown -> html (micromark)', (t) => {
'should not support math (flow) w/ one dollar sign'
)

t.equal(
assert.equal(
micromark('$$\na\n$$', {
extensions: [syntax()],
htmlExtensions: [html()]
Expand All @@ -154,7 +155,7 @@ test('markdown -> html (micromark)', (t) => {
'should support math (flow) w/ two dollar sign'
)

t.equal(
assert.equal(
micromark('$$$\na\n$$$', {
extensions: [syntax()],
htmlExtensions: [html()]
Expand All @@ -165,7 +166,7 @@ test('markdown -> html (micromark)', (t) => {
'should support math (flow) w/ three dollar sign'
)

t.equal(
assert.equal(
micromark('$$\n$$', {
extensions: [syntax()],
htmlExtensions: [html()]
Expand All @@ -176,7 +177,7 @@ test('markdown -> html (micromark)', (t) => {
'should support math (flow) w/o content'
)

t.equal(
assert.equal(
micromark('$$\na', {
extensions: [syntax()],
htmlExtensions: [html()]
Expand All @@ -187,7 +188,7 @@ test('markdown -> html (micromark)', (t) => {
'should support math (flow) w/o closing fence'
)

t.equal(
assert.equal(
micromark('$$\na\n', {
extensions: [syntax()],
htmlExtensions: [html()]
Expand All @@ -198,7 +199,7 @@ test('markdown -> html (micromark)', (t) => {
'should support math (flow) w/o closing fence ending at an EOL'
)

t.equal(
assert.equal(
micromark('$$asd &amp; \\& asd\na\n$$', {
extensions: [syntax()],
htmlExtensions: [html()]
Expand All @@ -209,7 +210,7 @@ test('markdown -> html (micromark)', (t) => {
'should support math (flow) w/ a meta string'
)

t.equal(
assert.equal(
micromark('$$asd$asd\na\n$$', {
extensions: [syntax()],
htmlExtensions: [html()]
Expand All @@ -220,7 +221,7 @@ test('markdown -> html (micromark)', (t) => {
'should not support math (flow) w/ a dollar sign in the meta string'
)

t.throws(
assert.throws(
() => {
micromark('$$\na\n$$ b', {
extensions: [syntax()],
Expand All @@ -231,7 +232,7 @@ test('markdown -> html (micromark)', (t) => {
'should not support math (flow) w/ content on the closing fence'
)

t.equal(
assert.equal(
micromark('$$\na\n$$ ', {
extensions: [syntax()],
htmlExtensions: [html()]
Expand All @@ -242,7 +243,7 @@ test('markdown -> html (micromark)', (t) => {
'should support whitespace on the closing fence'
)

t.equal(
assert.equal(
micromark(' $$\n\ta\n b\n c\nd\n$$', {
extensions: [syntax()],
htmlExtensions: [html()]
Expand All @@ -253,7 +254,7 @@ test('markdown -> html (micromark)', (t) => {
'should strip the prefix of the opening fence from content lines'
)

t.equal(
assert.equal(
micromark('> $$\n> a\n> $$\n> b', {
extensions: [syntax()],
htmlExtensions: [html()]
Expand All @@ -267,7 +268,7 @@ test('markdown -> html (micromark)', (t) => {
'should support math (flow) in a block quote'
)

t.equal(
assert.equal(
micromark('* $$\n a\n $$\n b', {
extensions: [syntax()],
htmlExtensions: [html()]
Expand All @@ -283,7 +284,7 @@ test('markdown -> html (micromark)', (t) => {
'should support math (flow) in a list (item)'
)

t.equal(
assert.equal(
micromark('a $\\sum_{\\substack{0<i<m\\\\0<j<n}}$ b', {
extensions: [syntax()],
htmlExtensions: [html()]
Expand All @@ -294,7 +295,7 @@ test('markdown -> html (micromark)', (t) => {
'should support `<`'
)

t.equal(
assert.equal(
micromark('a $\\text{a \\"{a} c}$ b', {
extensions: [syntax()],
htmlExtensions: [html()]
Expand All @@ -305,7 +306,7 @@ test('markdown -> html (micromark)', (t) => {
'should support `"`'
)

t.equal(
assert.equal(
micromark('a $$ $ $$', {
extensions: [syntax()],
htmlExtensions: [html({throwOnError: false})]
Expand All @@ -314,7 +315,7 @@ test('markdown -> html (micromark)', (t) => {
'should support options'
)

t.equal(
assert.equal(
micromark('> $$\na\n$$', {
extensions: [syntax()],
htmlExtensions: [html()]
Expand All @@ -327,7 +328,7 @@ test('markdown -> html (micromark)', (t) => {
'should not support laziness (1)'
)

t.equal(
assert.equal(
micromark('> $$\n> a\n$$', {
extensions: [syntax()],
htmlExtensions: [html()]
Expand All @@ -340,7 +341,7 @@ test('markdown -> html (micromark)', (t) => {
'should not support laziness (2)'
)

t.equal(
assert.equal(
micromark('a\n> $$', {
extensions: [syntax()],
htmlExtensions: [html()]
Expand All @@ -350,6 +351,4 @@ test('markdown -> html (micromark)', (t) => {
'</div>\n</blockquote>',
'should not support laziness (3)'
)

t.end()
})

0 comments on commit ee1e481

Please sign in to comment.