Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jfx2006 committed Dec 1, 2024
1 parent 91df05b commit 2fef04c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 61 deletions.
2 changes: 1 addition & 1 deletion extension/test/async_utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe("AsyncUtils", function () {

describe("getHljsStylesheet", function () {
it("should return some css", async function () {
const KNOWN_PREFIX = "/*!\n Theme: a11y-dark\n"
const KNOWN_PREFIX = "pre code.hljs {\n"
let data = await getHljsStylesheet("a11y-dark.css")
expect(data.slice(0, KNOWN_PREFIX.length)).to.equal(KNOWN_PREFIX)
})
Expand Down
71 changes: 14 additions & 57 deletions extension/test/markdown-render-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,41 +87,19 @@ describe("Markdown-Render", function () {
expect(await markdownRender(md)).to.equal(target)
})

// Test issue #84: Math: single-character formula won't render
// https://github.com/adam-p/markdown-here/issues/84
it("should render single-character math formulae", async function () {
const userprefs = {
"math-value":
'<img class="mdh-math" src="https://chart.googleapis.com/chart?cht=tx&chl={urlmathcode}" alt="{mathcode}">',
"math-renderer": "gchart",
}
await resetMarked(userprefs)

var md = "$x$"
var target =
'<p><img class="mdh-math" src="https://chart.googleapis.com/chart?cht=tx&chl=x" alt="x"></p>\n'
expect(await markdownRender(md)).to.equal(target)

// Make sure we haven't broken multi-character forumlae
md = "$xx$"
target =
'<p><img class="mdh-math" src="https://chart.googleapis.com/chart?cht=tx&chl=xx" alt="xx"></p>\n'
expect(await markdownRender(md)).to.equal(target)
})

it("should render single-character math formulae via texzilla", async function () {
const userprefs = {
"math-renderer": "texzilla",
}
await resetMarked(userprefs)

var md = "$x$"
var target = '<p><img alt="x" src="data:image/png;ba'
var target = '<p><img width="18" height="16" alt="x"'
expect((await markdownRender(md)).slice(0, target.length)).to.equal(target)

// Make sure we haven't broken multi-character forumlae
md = "$xx$"
target = '<p><img alt="xx" src="data:image/png;b'
target = '<p><img width="27" height="16" alt="xx'
expect((await markdownRender(md)).slice(0, target.length)).to.equal(target)
})

Expand Down Expand Up @@ -199,7 +177,8 @@ describe("Markdown-Render", function () {
const mdText = await mdHtmlToText.preprocess()
let renderedMarkdown = await markdownRender(mdText)
renderedMarkdown = mdHtmlToText.postprocess(renderedMarkdown)
return renderedMarkdown
renderedMarkdown = renderedMarkdown.replace(/(<p>)?<div class="mdhr-raw".*/, "")
return renderedMarkdown.replaceAll("\n", "")
}

it("should be okay with an empty string", async function () {
Expand Down Expand Up @@ -236,17 +215,17 @@ describe("Markdown-Render", function () {

tests.push([
'asdf <a href="http://www.aaa.com">bbb</a> asdf',
'<p>asdf <a href="http://www.aaa.com">bbb</a> asdf</p>\n',
'<p>asdf <a href="http://www.aaa.com">bbb</a> asdf',
])

tests.push(['<a href="aaa">bbb</a>', '<p><a href="https://aaa">bbb</a></p>\n'])
tests.push(['<a href="aaa">bbb</a>', '<p><a href="https://aaa">bbb</a>'])

tests.push([
'[xxx](yyy) <a href="aaa">bbb</a>',
'<p><a href="https://yyy">xxx</a> <a href="https://aaa">bbb</a></p>\n',
'<p><a href="https://yyy">xxx</a> <a href="https://aaa">bbb</a>',
])

tests.push(['asdf (<a href="aaa">bbb</a>)', '<p>asdf (<a href="https://aaa">bbb</a>)</p>\n'])
tests.push(['asdf (<a href="aaa">bbb</a>)', '<p>asdf (<a href="https://aaa">bbb</a>)'])

for (i = 0; i < tests.length; i++) {
expect(await fullRender(tests[i][0])).to.equal(tests[i][1])
Expand All @@ -257,69 +236,47 @@ describe("Markdown-Render", function () {
it("should add the schema to links missing it", async function () {
var md = "asdf [aaa](bbb) asdf [ccc](ftp://ddd) asdf"
var target =
'<p>asdf <a href="https://bbb">aaa</a> asdf <a href="ftp://ddd">ccc</a> asdf</p>\n'
'<p>asdf <a href="https://bbb">aaa</a> asdf <a href="ftp://ddd">ccc</a> asdf'
expect(await fullRender(md)).to.equal(target)
})

it("should *not* add the schema to anchor links", async function () {
var md = "asdf [aaa](#bbb) asdf [ccc](ftp://ddd) asdf"
var target = '<p>asdf <a href="#bbb">aaa</a> asdf <a href="ftp://ddd">ccc</a> asdf</p>\n'
var target = '<p>asdf <a href="#bbb">aaa</a> asdf <a href="ftp://ddd">ccc</a> asdf'
expect(await fullRender(md)).to.equal(target)
})

// Test issue #87: https://github.com/adam-p/markdown-here/issues/87
it("should smartypants apostrophes properly", async function () {
var md = "Adam's parents' place"
var target = "<p>Adam\u2019s parents\u2019 place</p>\n"
var target = "<p>Adam\u2019s parents\u2019 place"
expect(await fullRender(md)).to.equal(target)
})

// Test issue #83: https://github.com/adam-p/markdown-here/issues/83
it("should not alter MD-link-looking text in code blocks", async function () {
var md = "`[a](b)`"
var target = "<p><code>[a](b)</code></p>\n"
var target = "<p><code>[a](b)</code>"
expect(await fullRender(md)).to.equal(target)

md = "```<br>\n[a](b)<br>\n```<br>\n"
target = "<pre><code>[a](b)\n</code></pre>"
expect(await fullRender(md)).to.equal(target)
})

// Test issue #84: Math: single-character formula won't render
// https://github.com/adam-p/markdown-here/issues/84
it("should render single-character math formulae", async function () {
const userprefs = {
"math-value":
'<img class="mdh-math" src="https://chart.googleapis.com/chart?cht=tx&chl={urlmathcode}" alt="{mathcode}">',
"math-renderer": "gchart",
}
await resetMarked(userprefs)

var md = "$x$"
var target =
'<p><img class="mdh-math" src="https://chart.googleapis.com/chart?cht=tx&chl=x" alt="x"></p>\n'
expect(await fullRender(md)).to.equal(target)

// Make sure we haven't broken multi-character forumlae
md = "$xx$"
target =
'<p><img class="mdh-math" src="https://chart.googleapis.com/chart?cht=tx&chl=xx" alt="xx"></p>\n'
expect(await fullRender(md)).to.equal(target)
})

it("should render single-character math formulae via texzilla", async function () {
const userprefs = {
"math-renderer": "texzilla",
}
await resetMarked(userprefs)

var md = "$x$"
var target = '<p><img alt="x" src="data:image/png;ba'
var target = '<p><img width="18" height="16" alt="x"'
expect((await fullRender(md)).slice(0, target.length)).to.equal(target)

// Make sure we haven't broken multi-character forumlae
md = "$xx$"
target = '<p><img alt="xx" src="data:image/png;b'
target = '<p><img width="27" height="16" alt="xx'
expect((await fullRender(md)).slice(0, target.length)).to.equal(target)
})
})
Expand Down
9 changes: 6 additions & 3 deletions extension/test/mdhr-mangle-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,20 @@ describe("MdhrMangle", function () {
async function get(mdHTML) {
const doc = parser.parseFromString(mdHTML, "text/html")
const mdHtmlToText = new MdhrMangle(doc)
return await mdHtmlToText.preprocess()
const mangled = await mdHtmlToText.preprocess()
return mangled.replace(/MDHR-[0-9a-z]+/, "")
}

// FIXME: Mangle does not work with strings!
it("should be okay with an empty string", async function () {
expect(await get("")).to.equal("")
})

// Test some cases with bare text nodes
it("should properly handle bare text nodes", async function () {
let html = ""
let target = ""
let html, target
/html = ""
target = ""
expect(await get(html)).to.equal(target)

html = "asdf"
Expand Down

0 comments on commit 2fef04c

Please sign in to comment.