| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- /* eslint-disable
- max-len,
- no-return-assign,
- no-unused-vars,
- */
- // TODO: This file was created by bulk-decaffeinate.
- // Fix any style issues and re-enable lint.
- /*
- * decaffeinate suggestions:
- * DS102: Remove unnecessary code created because of implicit returns
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
- */
- const sinon = require('sinon')
- const { expect } = require('chai')
- const modulePath = '../../../../app/src/Features/Documents/DocumentHelper.js'
- const SandboxedModule = require('sandboxed-module')
- describe('DocumentHelper', function () {
- beforeEach(function () {
- return (this.DocumentHelper = SandboxedModule.require(modulePath))
- })
- describe('getTitleFromTexContent', function () {
- it('should return the title', function () {
- const document = '\\begin{document}\n\\title{foo}\n\\end{document}'
- return expect(
- this.DocumentHelper.getTitleFromTexContent(document)
- ).to.equal('foo')
- })
- it('should return the title if surrounded by space', function () {
- const document = '\\begin{document}\n \\title{foo} \n\\end{document}'
- return expect(
- this.DocumentHelper.getTitleFromTexContent(document)
- ).to.equal('foo')
- })
- it('should return null if there is no title', function () {
- const document = '\\begin{document}\n\\end{document}'
- return expect(
- this.DocumentHelper.getTitleFromTexContent(document)
- ).to.eql(null)
- })
- it('should accept an array', function () {
- const document = ['\\begin{document}', '\\title{foo}', '\\end{document}']
- return expect(
- this.DocumentHelper.getTitleFromTexContent(document)
- ).to.equal('foo')
- })
- it('should parse out formatting elements from the title', function () {
- const document = '\\title{\\textbf{\\large{Second Year LaTeX Exercise}}}'
- return expect(
- this.DocumentHelper.getTitleFromTexContent(document)
- ).to.equal('Second Year LaTeX Exercise')
- })
- it('should ignore junk after the title', function () {
- const document = '\\title{wombat} potato'
- return expect(
- this.DocumentHelper.getTitleFromTexContent(document)
- ).to.equal('wombat')
- })
- it('should ignore junk before the title', function () {
- const document =
- '% this is something that v1 relied on, even though it seems odd \\title{wombat}'
- return expect(
- this.DocumentHelper.getTitleFromTexContent(document)
- ).to.equal('wombat')
- })
- // NICETOHAVE: Current implementation doesn't do this
- // it "should keep content that surrounds formatting elements", ->
- // document = "\\title{Second Year \\large{LaTeX} Exercise}"
- // expect(@DocumentHelper.getTitleFromTexContent(document)).to.equal "Second Year LaTeX Exercise"
- it('should collapse whitespace', function () {
- const document = '\\title{Second Year LaTeX Exercise}'
- return expect(
- this.DocumentHelper.getTitleFromTexContent(document)
- ).to.equal('Second Year LaTeX Exercise')
- })
- })
- describe('detex', function () {
- // note, there are a number of tests for getTitleFromTexContent that also test cases here
- it('leaves a non-TeX string unchanged', function () {
- expect(this.DocumentHelper.detex('')).to.equal('')
- expect(this.DocumentHelper.detex('a')).to.equal('a')
- return expect(this.DocumentHelper.detex('a a')).to.equal('a a')
- })
- it('collapses spaces', function () {
- expect(this.DocumentHelper.detex('a a')).to.equal('a a')
- return expect(this.DocumentHelper.detex('a \n a')).to.equal('a \n a')
- })
- it('replaces named commands', function () {
- expect(this.DocumentHelper.detex('\\LaTeX')).to.equal('LaTeX')
- expect(this.DocumentHelper.detex('\\TikZ')).to.equal('TikZ')
- expect(this.DocumentHelper.detex('\\TeX')).to.equal('TeX')
- return expect(this.DocumentHelper.detex('\\BibTeX')).to.equal('BibTeX')
- })
- it('removes general commands', function () {
- expect(this.DocumentHelper.detex('\\foo')).to.equal('')
- expect(this.DocumentHelper.detex('\\foo{}')).to.equal('')
- expect(this.DocumentHelper.detex('\\foo~Test')).to.equal('Test')
- expect(this.DocumentHelper.detex('\\"e')).to.equal('e')
- return expect(this.DocumentHelper.detex('\\textit{e}')).to.equal('e')
- })
- it('leaves basic math', function () {
- return expect(this.DocumentHelper.detex('$\\cal{O}(n^2)$')).to.equal(
- 'O(n^2)'
- )
- })
- it('removes line spacing commands', function () {
- return expect(this.DocumentHelper.detex('a \\\\[1.50cm] b')).to.equal(
- 'a b'
- )
- })
- })
- describe('contentHasDocumentclass', function () {
- it('should return true if the content has a documentclass', function () {
- const document = ['% line', '% line', '% line', '\\documentclass']
- return expect(
- this.DocumentHelper.contentHasDocumentclass(document)
- ).to.equal(true)
- })
- it('should allow whitespace before the documentclass', function () {
- const document = ['% line', '% line', '% line', ' \\documentclass']
- return expect(
- this.DocumentHelper.contentHasDocumentclass(document)
- ).to.equal(true)
- })
- it('should not allow non-whitespace before the documentclass', function () {
- const document = [
- '% line',
- '% line',
- '% line',
- ' asdf \\documentclass',
- ]
- return expect(
- this.DocumentHelper.contentHasDocumentclass(document)
- ).to.equal(false)
- })
- it('should return false when there is no documentclass', function () {
- const document = ['% line', '% line', '% line']
- return expect(
- this.DocumentHelper.contentHasDocumentclass(document)
- ).to.equal(false)
- })
- })
- })
|