Files
KaTeX/test/__snapshots__/katex-spec.js.snap
ylemkimon 71035c7111 Refactor test helpers (#1336)
* Refactor test helpers

* Combine common codes from `parse` and `build`, and dispatch using
`Mode`
* Remove `toNotBuild` and `toNotParse` and use `expect.not`
* Remove `Warning` and instead mock `console.warn`
* Add `expect.toHavePassed` and check whether parse/build succeeded
lazily
* Improve failed test `message`:
  - Use color
  - Print stack traces(excluding internals)
  - Print diff
  - Follow jest matcher output style

* Update helpers.js

* Remove toBeTruthy checks

getParsed throws an error if parsing fails.

* Used tagged literals

* Use .toHaveLength

* Use tagged literals

* Use to{Build,Parse}Like where possible

* Remove compareParseTree

* Use snapshot where possible

* Join into one line where <88 chars

* Revert console.warn() to throw an error

Merge `expectToWarn` to `expectKaTeX`, like
`expect.toFailWithParseError`

* Remove call to console.warn from stack traces

* Fix merge errors

* Remove `getTree`

* Move `_getBuilt` into `getBuilt`
* Move default settings and tagging literal support in to `getParsed` 
and `getBuilt`
* Remove stack traces clean-up
* Remove `toHavePassed` matcher

* Extract `expected` string construction into `printExpectedResult`
2018-07-21 19:06:07 -07:00

910 lines
18 KiB
Plaintext
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`A begin/end parser should grab \\arraystretch 1`] = `
[
{
"type": "array",
"mode": "math",
"value": {
"type": "array",
"arraystretch": 1.5,
"body": [
[
{
"type": "styling",
"mode": "math",
"value": {
"type": "styling",
"style": "text",
"value": [
{
"type": "ordgroup",
"mode": "math",
"value": [
{
"type": "mathord",
"loc": {
"end": 37,
"lexer": {
"input": "\\\\def\\\\arraystretch{1.5}\\\\begin{matrix}a&b\\\\\\\\c&d\\\\end{matrix}",
"tokenRegex": {
"lastIndex": 56
}
},
"start": 36
},
"mode": "math",
"value": "a"
}
]
}
]
}
},
{
"type": "styling",
"mode": "math",
"value": {
"type": "styling",
"style": "text",
"value": [
{
"type": "ordgroup",
"mode": "math",
"value": [
{
"type": "mathord",
"loc": {
"end": 39,
"lexer": {
"input": "\\\\def\\\\arraystretch{1.5}\\\\begin{matrix}a&b\\\\\\\\c&d\\\\end{matrix}",
"tokenRegex": {
"lastIndex": 56
}
},
"start": 38
},
"mode": "math",
"value": "b"
}
]
}
]
}
}
],
[
{
"type": "styling",
"mode": "math",
"value": {
"type": "styling",
"style": "text",
"value": [
{
"type": "ordgroup",
"mode": "math",
"value": [
{
"type": "mathord",
"loc": {
"end": 42,
"lexer": {
"input": "\\\\def\\\\arraystretch{1.5}\\\\begin{matrix}a&b\\\\\\\\c&d\\\\end{matrix}",
"tokenRegex": {
"lastIndex": 56
}
},
"start": 41
},
"mode": "math",
"value": "c"
}
]
}
]
}
},
{
"type": "styling",
"mode": "math",
"value": {
"type": "styling",
"style": "text",
"value": [
{
"type": "ordgroup",
"mode": "math",
"value": [
{
"type": "mathord",
"loc": {
"end": 44,
"lexer": {
"input": "\\\\def\\\\arraystretch{1.5}\\\\begin{matrix}a&b\\\\\\\\c&d\\\\end{matrix}",
"tokenRegex": {
"lastIndex": 56
}
},
"start": 43
},
"mode": "math",
"value": "d"
}
]
}
]
}
}
]
],
"hLinesBeforeRow": [
[
],
[
],
[
]
],
"hskipBeforeAndAfter": false,
"rowGaps": [
null
]
}
}
]
`;
exports[`A font parser \\boldsymbol should inherit mbin/mrel from argument 1`] = `
[
{
"classes": [
"mord",
"mathit"
],
"depth": 0,
"height": 0.43056,
"italic": 0,
"maxFontSize": 1,
"skew": 0,
"style": {
},
"value": "a",
"width": 0.52859
},
{
"attributes": {
},
"children": [
{
"attributes": {
},
"children": [
],
"classes": [
"mord"
],
"depth": 0,
"height": 0,
"maxFontSize": 0,
"style": {
}
}
],
"classes": [
"mord"
],
"depth": 0,
"height": 0,
"maxFontSize": 0,
"style": {
}
},
{
"classes": [
"mord",
"mathit"
],
"depth": 0,
"height": 0.69444,
"italic": 0,
"maxFontSize": 1,
"skew": 0,
"style": {
},
"value": "b",
"width": 0.42917
},
{
"attributes": {
},
"children": [
],
"classes": [
"mspace"
],
"depth": 0,
"height": 0,
"maxFontSize": 0,
"style": {
"marginRight": "0.2777777777777778em"
}
},
{
"attributes": {
},
"children": [
{
"attributes": {
},
"children": [
{
"classes": [
"mrel",
"mathbf"
],
"depth": -0.10889,
"height": 0.39111,
"italic": 0,
"maxFontSize": 1,
"skew": 0,
"style": {
},
"value": "=",
"width": 0.89444
}
],
"classes": [
"mord"
],
"depth": 0,
"height": 0.39111,
"maxFontSize": 1,
"style": {
}
}
],
"classes": [
"mrel"
],
"depth": 0,
"height": 0.39111,
"maxFontSize": 1,
"style": {
}
},
{
"attributes": {
},
"children": [
],
"classes": [
"mspace"
],
"depth": 0,
"height": 0,
"maxFontSize": 0,
"style": {
"marginRight": "0.2777777777777778em"
}
},
{
"classes": [
"mord",
"mathit"
],
"depth": 0,
"height": 0.43056,
"italic": 0,
"maxFontSize": 1,
"skew": 0.05556,
"style": {
},
"value": "c",
"width": 0.43276
},
{
"attributes": {
},
"children": [
],
"classes": [
"mspace"
],
"depth": 0,
"height": 0,
"maxFontSize": 0,
"style": {
"marginRight": "0.2222222222222222em"
}
},
{
"attributes": {
},
"children": [
{
"attributes": {
},
"children": [
{
"classes": [
"mord",
"mathbf"
],
"depth": 0.13333,
"height": 0.63333,
"italic": 0,
"maxFontSize": 1,
"skew": 0,
"style": {
},
"value": "+",
"width": 0.89444
}
],
"classes": [
"mord"
],
"depth": 0.13333,
"height": 0.63333,
"maxFontSize": 1,
"style": {
}
}
],
"classes": [
"mbin"
],
"depth": 0.13333,
"height": 0.63333,
"maxFontSize": 1,
"style": {
}
},
{
"attributes": {
},
"children": [
],
"classes": [
"mspace"
],
"depth": 0,
"height": 0,
"maxFontSize": 0,
"style": {
"marginRight": "0.2222222222222222em"
}
},
{
"classes": [
"mord",
"mathit"
],
"depth": 0,
"height": 0.69444,
"italic": 0,
"maxFontSize": 1,
"skew": 0.16667,
"style": {
},
"value": "d",
"width": 0.52049
},
{
"attributes": {
},
"children": [
],
"classes": [
"mspace"
],
"depth": 0,
"height": 0,
"maxFontSize": 0,
"style": {
"marginRight": "0.2222222222222222em"
}
},
{
"attributes": {
},
"children": [
{
"attributes": {
},
"children": [
{
"classes": [
"mord",
"mathbf"
],
"depth": 0.13333,
"height": 0.63333,
"italic": 0,
"maxFontSize": 1,
"skew": 0,
"style": {
},
"value": "+",
"width": 0.89444
},
{
"classes": [
"mord",
"mathbf"
],
"depth": 0.13333,
"height": 0.63333,
"italic": 0,
"maxFontSize": 1,
"skew": 0,
"style": {
},
"value": "+",
"width": 0.89444
}
],
"classes": [
"mord"
],
"depth": 0.13333,
"height": 0.63333,
"maxFontSize": 1,
"style": {
}
}
],
"classes": [
"mbin"
],
"depth": 0.13333,
"height": 0.63333,
"maxFontSize": 1,
"style": {
}
},
{
"attributes": {
},
"children": [
],
"classes": [
"mspace"
],
"depth": 0,
"height": 0,
"maxFontSize": 0,
"style": {
"marginRight": "0.2222222222222222em"
}
},
{
"classes": [
"mord",
"mathit"
],
"depth": 0,
"height": 0.43056,
"italic": 0,
"maxFontSize": 1,
"skew": 0.05556,
"style": {
},
"value": "e",
"width": 0.46563
},
{
"attributes": {
},
"children": [
{
"attributes": {
},
"children": [
{
"classes": [
"mord",
"boldsymbol"
],
"depth": 0,
"height": 0.44444,
"italic": 0,
"maxFontSize": 1,
"skew": 0,
"style": {
},
"value": "x",
"width": 0.65903
},
{
"classes": [
"mord",
"boldsymbol"
],
"depth": 0.19444,
"height": 0.44444,
"italic": 0.03704,
"maxFontSize": 1,
"skew": 0,
"style": {
},
"value": "y",
"width": 0.59028
},
{
"classes": [
"mord",
"boldsymbol"
],
"depth": 0,
"height": 0.44444,
"italic": 0.04213,
"maxFontSize": 1,
"skew": 0,
"style": {
},
"value": "z",
"width": 0.55509
}
],
"classes": [
"mord"
],
"depth": 0.19444,
"height": 0.44444,
"maxFontSize": 1,
"style": {
}
}
],
"classes": [
"mord"
],
"depth": 0.19444,
"height": 0.44444,
"maxFontSize": 1,
"style": {
}
},
{
"classes": [
"mord",
"mathit"
],
"depth": 0.19444,
"height": 0.69444,
"italic": 0.10764,
"maxFontSize": 1,
"skew": 0.16667,
"style": {
},
"value": "f",
"width": 0.48959
}
]
`;
exports[`A parse tree generator generates a tree 1`] = `
[
{
"type": "supsub",
"mode": "math",
"value": {
"type": "supsub",
"base": {
"type": "mathord",
"mode": "math",
"value": "\\\\sigma"
},
"sup": {
"type": "textord",
"mode": "math",
"value": "2"
}
}
}
]
`;
exports[`A parser that does not throw on unsupported commands should build katex-error span for other type of KaTeX error 1`] = `
{
"attributes": {
"style": "color:#933",
"title": "ParseError: KaTeX parse error: Double superscript at position 4: 2^2^̲2"
},
"children": [
{
"classes": [
],
"depth": 0,
"height": 0,
"italic": 0,
"maxFontSize": 0,
"skew": 0,
"style": {
},
"value": "2^2^2",
"width": 0
}
],
"classes": [
"katex-error"
],
"depth": 0,
"height": 0,
"maxFontSize": 0,
"style": {
}
}
`;
exports[`A parser that does not throw on unsupported commands should properly escape LaTeX in errors 1`] = `
<span class="katex-error"
title="ParseError: KaTeX parse error: Expected group after &#x27;^&#x27; at position 2: 2^̲&amp;&quot;&lt;&gt;"
style="color:#933"
>
2^&amp;&quot;&lt;&gt;
</span>
`;
exports[`An implicit group parser within optional groups should work style commands \\sqrt[\\textstyle 3]{x} 1`] = `
[
{
"type": "sqrt",
"mode": "math",
"value": {
"type": "sqrt",
"body": {
"type": "ordgroup",
"mode": "math",
"value": [
{
"type": "mathord",
"mode": "math",
"value": "x"
}
]
},
"index": {
"type": "ordgroup",
"mode": "math",
"value": [
{
"type": "styling",
"mode": "math",
"value": {
"type": "styling",
"style": "text",
"value": [
{
"type": "textord",
"mode": "math",
"value": "3"
}
]
}
}
]
}
}
}
]
`;
exports[`An implicit group parser within optional groups should work with \\color: \\sqrt[\\color{red} 3]{x} 1`] = `
[
{
"type": "sqrt",
"mode": "math",
"value": {
"type": "sqrt",
"body": {
"type": "ordgroup",
"mode": "math",
"value": [
{
"type": "mathord",
"mode": "math",
"value": "x"
}
]
},
"index": {
"type": "ordgroup",
"mode": "math",
"value": [
{
"type": "color",
"mode": "math",
"value": {
"type": "color",
"color": "red",
"value": [
{
"type": "textord",
"mode": "math",
"value": "3"
}
]
}
}
]
}
}
}
]
`;
exports[`An implicit group parser within optional groups should work with old font functions: \\sqrt[\\tt 3]{x} 1`] = `
[
{
"type": "sqrt",
"mode": "math",
"value": {
"type": "sqrt",
"body": {
"type": "ordgroup",
"mode": "math",
"value": [
{
"type": "mathord",
"mode": "math",
"value": "x"
}
]
},
"index": {
"type": "ordgroup",
"mode": "math",
"value": [
{
"type": "font",
"mode": "math",
"value": {
"type": "font",
"body": {
"type": "ordgroup",
"mode": "math",
"value": [
{
"type": "textord",
"mode": "math",
"value": "3"
}
]
},
"font": "mathtt"
}
}
]
}
}
}
]
`;
exports[`An implicit group parser within optional groups should work with sizing commands: \\sqrt[\\small 3]{x} 1`] = `
[
{
"type": "sqrt",
"mode": "math",
"value": {
"type": "sqrt",
"body": {
"type": "ordgroup",
"mode": "math",
"value": [
{
"type": "mathord",
"mode": "math",
"value": "x"
}
]
},
"index": {
"type": "ordgroup",
"mode": "math",
"value": [
{
"type": "sizing",
"mode": "math",
"value": {
"type": "sizing",
"size": 5,
"value": [
{
"type": "textord",
"mode": "math",
"value": "3"
}
]
}
}
]
}
}
}
]
`;
exports[`Extending katex by new fonts and symbols Add new font class to new extended symbols 1`] = `
<span class="katex">
<span class="katex-mathml">
<math>
<semantics>
<mrow>
<mi mathvariant="normal">
۹
</mi>
<msup>
<mi mathvariant="normal">
۹
</mi>
<mrow>
<mi mathvariant="normal">
۱
</mi>
<mi mathvariant="normal">
۱
</mi>
</mrow>
</msup>
</mrow>
<annotation encoding="application/x-tex">
۹۹^{۱۱}
</annotation>
</semantics>
</math>
</span>
<span class="katex-html"
aria-hidden="true"
>
<span class="base">
<span class="strut"
style="height:0.84425em;vertical-align:0em;"
>
</span>
<span class="mord mockEasternArabicFont-Regular">
۹
</span>
<span class="mord">
<span class="mord mockEasternArabicFont-Regular">
۹
</span>
<span class="msupsub">
<span class="vlist-t">
<span class="vlist-r">
<span class="vlist"
style="height:0.84425em;"
>
<span style="top:-3.063em;margin-right:0.05em;">
<span class="pstrut"
style="height:2.7em;"
>
</span>
<span class="sizing reset-size6 size3 mtight">
<span class="mord mtight">
<span class="mord mockEasternArabicFont-Regular mtight">
۱
</span>
<span class="mord mockEasternArabicFont-Regular mtight">
۱
</span>
</span>
</span>
</span>
</span>
</span>
</span>
</span>
</span>
</span>
</span>
</span>
`;