Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions test/unit-tests/expression/function/help.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@ import assert from 'assert'
import math from '../../../../src/defaultInstance.js'
import { embeddedDocs } from '../../../../src/expression/embeddedDocs/embeddedDocs.js'

const mathDocs = math.create(math.all)
const originalConfig = mathDocs.config()
// if a function has errors in the examples of the embedded docs and it's OK,
// add it to the skipDocs array
const skipDocs = ['import']

function runExamplesInDocs (name) {
mathDocs.config(originalConfig)
if (skipDocs.includes(name)) {
return
}
// every funciton should have doc.examples
const examples = mathDocs.evaluate(`help("${name}")`).doc.examples
try {
// validate if the examples run without errors
mathDocs.evaluate(examples)
return
} catch {
}
// if they still have errors try with a new math instance
const math2 = math.create(math.all)
math2.evaluate(examples)
}

describe('help', function () {
it('should find documentation for a function by its name', function () {
const help = math.help('sin')
Expand Down Expand Up @@ -66,4 +90,10 @@ describe('help', function () {
const expression = math.parse('help(parse)')
assert.strictEqual(expression.toTex(), '\\mathrm{help}\\left( parse\\right)')
})

for (const name of Object.keys(embeddedDocs)) {
it(`should not throw an error when the examples for ${name} are run`, function () {
assert.doesNotThrow(() => runExamplesInDocs(name))
})
}
})