mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-10 14:40:47 +02:00
Merge pull request #3495 from overleaf/ae-prettier-2
Upgrade Prettier to v2 GitOrigin-RevId: 85aa3fa1acb6332c4f58c46165a43d1a51471f33
This commit is contained in:
@@ -15,55 +15,55 @@ const { expect } = require('chai')
|
||||
const modulePath = '../../../../app/src/Features/Documents/DocumentHelper.js'
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
|
||||
describe('DocumentHelper', function() {
|
||||
beforeEach(function() {
|
||||
describe('DocumentHelper', function () {
|
||||
beforeEach(function () {
|
||||
return (this.DocumentHelper = SandboxedModule.require(modulePath))
|
||||
})
|
||||
|
||||
describe('getTitleFromTexContent', function() {
|
||||
it('should return the title', function() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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(
|
||||
@@ -76,7 +76,7 @@ describe('DocumentHelper', function() {
|
||||
// document = "\\title{Second Year \\large{LaTeX} Exercise}"
|
||||
// expect(@DocumentHelper.getTitleFromTexContent(document)).to.equal "Second Year LaTeX Exercise"
|
||||
|
||||
it('should collapse whitespace', function() {
|
||||
it('should collapse whitespace', function () {
|
||||
const document = '\\title{Second Year LaTeX Exercise}'
|
||||
return expect(
|
||||
this.DocumentHelper.getTitleFromTexContent(document)
|
||||
@@ -84,27 +84,27 @@ describe('DocumentHelper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('detex', function() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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')
|
||||
@@ -112,35 +112,35 @@ describe('DocumentHelper', function() {
|
||||
return expect(this.DocumentHelper.detex('\\textit{e}')).to.equal('e')
|
||||
})
|
||||
|
||||
it('leaves basic math', function() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
it('should not allow non-whitespace before the documentclass', function () {
|
||||
const document = [
|
||||
'% line',
|
||||
'% line',
|
||||
@@ -152,7 +152,7 @@ describe('DocumentHelper', function() {
|
||||
).to.equal(false)
|
||||
})
|
||||
|
||||
it('should return false when there is no documentclass', function() {
|
||||
it('should return false when there is no documentclass', function () {
|
||||
const document = ['% line', '% line', '% line']
|
||||
return expect(
|
||||
this.DocumentHelper.contentHasDocumentclass(document)
|
||||
|
||||
Reference in New Issue
Block a user