forked from jupyterlab/jupyterlab
/
latex.spec.ts
98 lines (85 loc) · 3.24 KB
/
latex.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import { expect } from 'chai';
import { removeMath, replaceMath } from '@jupyterlab/rendermime';
describe('jupyter-ui', () => {
describe('removeMath()', () => {
it('should split the text into text and math', () => {
const input = 'hello, $ /alpha $, there';
const { text, math } = removeMath(input);
expect(text).to.equal('hello, @@0@@, there');
expect(math).to.deep.equal(['$ /alpha $']);
});
it('should handle code spans', () => {
const input = '`$foo` and `$bar` are variables';
const { text, math } = removeMath(input);
expect(text).to.equal(input);
expect(math).to.deep.equal([]);
});
it('should handle math markers', () => {
const input = ' @@0@@ hello, $ /alpha $, there';
const { text, math } = removeMath(input);
expect(text).to.equal(' @@0@@ hello, @@1@@, there');
expect(math).to.deep.equal(['@@0@@', '$ /alpha $']);
});
it('should handle unbalanced braces', () => {
const input = 'hello, $ /alpha { $, there';
const { text, math } = removeMath(input);
expect(text).to.equal('hello, @@0@@, there');
expect(math).to.deep.equal(['$ /alpha { $']);
});
it('should handle balanced braces', () => {
const input = 'hello, $ /alpha { } $, there';
const { text, math } = removeMath(input);
expect(text).to.equal('hello, @@0@@, there');
expect(math).to.deep.equal(['$ /alpha { } $']);
});
it('should handle math blocks', () => {
const input = 'hello, $$\nfoo\n$$, there';
const { text, math } = removeMath(input);
expect(text).to.equal('hello, @@0@@, there');
expect(math).to.deep.equal(['$$\nfoo\n$$']);
});
it('should handle begin statements', () => {
const input = 'hello, \\begin{align} \\end{align}, there';
const { text, math } = removeMath(input);
expect(text).to.equal('hello, @@0@@, there');
expect(math).to.deep.equal(['\\begin{align} \\end{align}']);
});
it('should handle `\\(` delimiters in GFM', () => {
const input = `
\`\`\`
Some \\(text
\'\'\'
**bold**
## header
`;
const { text, math } = removeMath(input);
expect(text).to.equal(input);
expect(math).to.deep.equal([]);
});
it('should handle `\\\\(` delimiters for math', () => {
const input = `hello, \\\\\(
/alpha
\\\\\), there`;
const { text, math } = removeMath(input);
expect(text).to.equal('hello, @@0@@, there');
expect(math).to.deep.equal(['\\\\(\n /alpha\n \\\\)']);
});
it('should handle `\\\\[` delimiters for math', () => {
const input = `hello, \\\\\[
/alpha
\\\\\], there`;
const { text, math } = removeMath(input);
expect(text).to.equal('hello, @@0@@, there');
expect(math).to.deep.equal(['\\\\[\n /alpha\n \\\\]']);
});
});
describe('replaceMath()', () => {
it('should recombine text split with removeMath', () => {
const input = 'hello, $ /alpha $, there';
const { text, math } = removeMath(input);
expect(replaceMath(text, math)).to.equal(input);
});
});
});