Explorar o código

Merge pull request #81 from blink1073/other-tests

Add latex helper tests
Dave Willmer %!s(int64=9) %!d(string=hai) anos
pai
achega
2df966ce65
Modificáronse 3 ficheiros con 87 adicións e 1 borrados
  1. 1 1
      src/renderers/latex.ts
  2. 1 0
      test/src/index.ts
  3. 85 0
      test/src/renderers/latex.spec.ts

+ 1 - 1
src/renderers/latex.ts

@@ -45,7 +45,7 @@ function removeMath(text: string): { text: string, math: string[] } {
   // source that will later be turned into code spans. While MathJax will not TeXify code spans,
   // we still have to consider them at this point; the following issue has happened several times:
   //
-  //     `$foo` and `$bar` are varibales.  -->  <code>$foo ` and `$bar</code> are variables.
+  //     `$foo` and `$bar` are variables.  -->  <code>$foo ` and `$bar</code> are variables.
   let hasCodeSpans = /`/.test(text);
   if (hasCodeSpans) {
     text = text.replace(/~/g, '~T').replace(/(^|[^\\])(`+)([^\n]*?[^`\n])\2(?!`)/gm, (wholematch) => wholematch.replace(/\$/g, '~D'));

+ 1 - 0
test/src/index.ts

@@ -9,3 +9,4 @@ import './filehandler/filehandler.spec';
 import './filehandler/registry.spec';
 import './renderers/renderers.spec';
 import './rendermime/rendermime.spec';
+import './renderers/latex.spec';

+ 85 - 0
test/src/renderers/latex.spec.ts

@@ -0,0 +1,85 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+'use strict';
+
+import expect = require('expect.js');
+
+import {
+  removeMath, replaceMath, typeset
+} from '../../../lib/renderers/latex';
+
+
+describe('jupyter-ui', () => {
+
+  describe('removeMath()', () => {
+
+    it('should split the text into text and math', () => {
+      let input = 'hello, $ /alpha $, there';
+      let { text, math } = removeMath(input);
+      expect(text).to.be('hello, @@0@@, there');
+      expect(math).to.eql(['$ /alpha $'])
+    });
+
+    it('should handle code spans', () => {
+      let input = '`$foo` and `$bar` are variables';
+      let { text, math } = removeMath(input);
+      expect(text).to.be(input);
+      expect(math).to.eql([]);
+    });
+
+    it('should handle math markers', () => {
+      let input = ' @@0@@ hello, $ /alpha $, there';
+      let { text, math } = removeMath(input);
+      expect(text).to.be(' @@0@@ hello, @@1@@, there');
+      expect(math).to.eql([ '@@0@@', '$ /alpha $' ])
+    });
+
+    it('should handle unbalanced braces', () => {
+      let input = 'hello, $ /alpha { $, there';
+      let { text, math } = removeMath(input);
+      expect(text).to.be('hello, @@0@@, there');
+      expect(math).to.eql(['$ /alpha { $' ])
+    });
+
+    it('should handle balanced braces', () => {
+      let input = 'hello, $ /alpha { } $, there';
+      let { text, math } = removeMath(input);
+      expect(text).to.be('hello, @@0@@, there');
+      expect(math).to.eql(['$ /alpha { } $' ])
+    });
+
+    it('should handle math blocks', () => {
+      let input = 'hello, $$\nfoo\n$$, there';
+      let { text, math } = removeMath(input);
+      expect(text).to.be('hello, @@0@@, there');
+      expect(math).to.eql(['$$\nfoo\n$$' ])
+    });
+
+    it('should handle begin statements', () => {
+      let input = 'hello, \\begin{align} \\end{align}, there';
+      let { text, math } = removeMath(input);
+      expect(text).to.be('hello, @@0@@, there');
+      expect(math).to.eql(['\\begin{align} \\end{align}'])
+    });
+
+  });
+
+  describe('replaceMath()', () => {
+
+    it('should recombine text split with removeMath', () => {
+      let input = 'hello, $ /alpha $, there';
+      let { text, math } = removeMath(input);
+      expect(replaceMath(text, math)).to.be(input);
+    });
+
+  });
+
+  describe('typeset()', () => {
+
+    it('should be a no-op if MathJax is not defined', () => {
+      typeset(document.body);
+    });
+
+  });
+
+});