mirror of
https://github.com/James-Yu/LaTeX-Workshop.git
synced 2025-01-07 09:47:04 +03:00
BibTeX formatter tests
This commit is contained in:
parent
7b2f1d074f
commit
a2eff0cfc7
32
test/fixtures/armory/formatter/bibtex_base.bib
vendored
Normal file
32
test/fixtures/armory/formatter/bibtex_base.bib
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
@article{art1,
|
||||
title = {A fake article},
|
||||
author = {Davis, J. and Jones, M.},
|
||||
journal = {Journal of CI tests},
|
||||
year = {2022},
|
||||
description = {hintFake}
|
||||
}
|
||||
|
||||
@book{lamport1994latex,
|
||||
title = {LATEX: A Document Preparation System : User's Guide and Reference Manual},
|
||||
author = {Lamport, L. and Bibby, D. and Pearson Education},
|
||||
isbn = {9780201529838},
|
||||
lccn = {93039691},
|
||||
series = {Addison-Wesley Series on Tools},
|
||||
url = {https://books.google.ch/books?id=khVUAAAAMAAJ},
|
||||
year = {1994},
|
||||
publisher = {Addison-Wesley},
|
||||
description = {hintLaTex}
|
||||
}
|
||||
|
||||
@book{MR1241645,
|
||||
author = {Rubinstein, Reuven Y. and Shapiro, Alexander},
|
||||
title = {Discrete event systems},
|
||||
series = {Wiley Series in Probability and Mathematical Statistics:
|
||||
Probability and Mathematical Statistics},
|
||||
note = {Sensitivity analysis and stochastic optimization by the score
|
||||
function method},
|
||||
publisher = {John Wiley \& Sons Ltd.},
|
||||
address = {Chichester},
|
||||
year = 1993,
|
||||
description = {hintRubi}
|
||||
}
|
15
test/fixtures/armory/formatter/bibtex_dup.bib
vendored
Normal file
15
test/fixtures/armory/formatter/bibtex_dup.bib
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
@article{art1,
|
||||
title = {A fake article},
|
||||
author = {Davis, J. and Jones, M.},
|
||||
journal = {Journal of CI tests},
|
||||
year = {2022},
|
||||
description = {hintFake}
|
||||
}
|
||||
|
||||
@article{art1,
|
||||
title = {A fake article},
|
||||
author = {Davis, J. and Jones, M.},
|
||||
journal = {Journal of CI tests},
|
||||
year = {2022},
|
||||
description = {hintFake}
|
||||
}
|
@ -132,7 +132,7 @@ suite('Build TeX files test suite', () => {
|
||||
await test.assert.build(fixture, 'main.tex', 'main.pdf')
|
||||
})
|
||||
|
||||
test.only(suiteName, fixtureName, 'build a subfile when main.tex opened', async () => {
|
||||
test.run(suiteName, fixtureName, 'build a subfile when main.tex opened', async () => {
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('latex.rootFile.doNotPrompt', true)
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('latex.rootFile.useSubFile', true)
|
||||
await test.load(fixture, [
|
||||
|
@ -27,6 +27,14 @@ suite('Formatter test suite', () => {
|
||||
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('latexindent.path', undefined)
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('latexindent.args', undefined)
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.tab', undefined)
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.surround', undefined)
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.case', undefined)
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.trailingComma', undefined)
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.sortby', undefined)
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.handleDuplicates', undefined)
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.sort.enabled', undefined)
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.align-equal.enabled', undefined)
|
||||
|
||||
if (path.basename(fixture) === 'testground') {
|
||||
rimraf(fixture + '/{*,.vscode/*}', (e) => {if (e) {console.error(e)}})
|
||||
@ -35,9 +43,7 @@ suite('Formatter test suite', () => {
|
||||
})
|
||||
|
||||
test.run(suiteName, fixtureName, 'test latex formatter', async () => {
|
||||
await test.load(fixture, [
|
||||
{src: 'formatter/latex_base.tex', dst: 'main.tex'}
|
||||
])
|
||||
await test.load(fixture, [{src: 'formatter/latex_base.tex', dst: 'main.tex'}])
|
||||
await test.open(fixture, 'main.tex')
|
||||
const original = vscode.window.activeTextEditor?.document.getText()
|
||||
await vscode.commands.executeCommand('editor.action.formatDocument')
|
||||
@ -48,9 +54,7 @@ suite('Formatter test suite', () => {
|
||||
|
||||
test.run(suiteName, fixtureName, 'change latexindent.path on the fly', async () => {
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('latexindent.path', 'echo')
|
||||
await test.load(fixture, [
|
||||
{src: 'formatter/latex_base.tex', dst: 'main.tex'}
|
||||
])
|
||||
await test.load(fixture, [{src: 'formatter/latex_base.tex', dst: 'main.tex'}])
|
||||
await test.open(fixture, 'main.tex')
|
||||
const original = vscode.window.activeTextEditor?.document.getText()
|
||||
// echo add a new \n to the end of stdin
|
||||
@ -67,4 +71,206 @@ suite('Formatter test suite', () => {
|
||||
const formatted = vscode.window.activeTextEditor?.document.getText()
|
||||
assert.notStrictEqual(original, formatted)
|
||||
})
|
||||
|
||||
test.run(suiteName, fixtureName, 'test bibtex formatter', async () => {
|
||||
await test.load(fixture, [{src: 'formatter/bibtex_base.bib', dst: 'main.bib'}])
|
||||
await test.open(fixture, 'main.bib')
|
||||
const original = vscode.window.activeTextEditor?.document.getText()
|
||||
await vscode.commands.executeCommand('editor.action.formatDocument')
|
||||
await test.sleep(1000)
|
||||
const formatted = vscode.window.activeTextEditor?.document.getText()
|
||||
assert.notStrictEqual(original, formatted)
|
||||
})
|
||||
|
||||
test.run(suiteName, fixtureName, 'test bibtex formatter with `bibtex-format.tab`', async () => {
|
||||
await test.load(fixture, [{src: 'formatter/bibtex_base.bib', dst: 'main.bib'}])
|
||||
await test.open(fixture, 'main.bib')
|
||||
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.tab', 'tab')
|
||||
await vscode.commands.executeCommand('editor.action.formatDocument')
|
||||
await test.sleep(1000)
|
||||
let lines = vscode.window.activeTextEditor?.document.getText().split('\n')
|
||||
assert.ok(lines)
|
||||
assert.strictEqual(lines[1].slice(0, 1), '\t')
|
||||
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.tab', '2 spaces')
|
||||
await vscode.commands.executeCommand('editor.action.formatDocument')
|
||||
await test.sleep(1000)
|
||||
lines = vscode.window.activeTextEditor?.document.getText().split('\n')
|
||||
assert.ok(lines)
|
||||
assert.strictEqual(lines[1].slice(0, 2), ' ')
|
||||
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.tab', '4')
|
||||
await vscode.commands.executeCommand('editor.action.formatDocument')
|
||||
await test.sleep(1000)
|
||||
lines = vscode.window.activeTextEditor?.document.getText().split('\n')
|
||||
assert.ok(lines)
|
||||
assert.strictEqual(lines[1].slice(0, 4), ' ')
|
||||
})
|
||||
|
||||
test.run(suiteName, fixtureName, 'test bibtex formatter with `bibtex-format.surround`', async () => {
|
||||
await test.load(fixture, [{src: 'formatter/bibtex_base.bib', dst: 'main.bib'}])
|
||||
await test.open(fixture, 'main.bib')
|
||||
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.surround', 'Curly braces')
|
||||
await vscode.commands.executeCommand('editor.action.formatDocument')
|
||||
await test.sleep(1000)
|
||||
let lines = vscode.window.activeTextEditor?.document.getText().split('\n')
|
||||
assert.ok(lines)
|
||||
assert.strictEqual(lines[1].slice(-2, -1), '}')
|
||||
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.surround', 'Quotation marks')
|
||||
await vscode.commands.executeCommand('editor.action.formatDocument')
|
||||
await test.sleep(1000)
|
||||
lines = vscode.window.activeTextEditor?.document.getText().split('\n')
|
||||
assert.ok(lines)
|
||||
assert.strictEqual(lines[1].slice(-2, -1), '"')
|
||||
})
|
||||
|
||||
test.run(suiteName, fixtureName, 'test bibtex formatter with `bibtex-format.case`', async () => {
|
||||
await test.load(fixture, [{src: 'formatter/bibtex_base.bib', dst: 'main.bib'}])
|
||||
await test.open(fixture, 'main.bib')
|
||||
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.case', 'UPPERCASE')
|
||||
await vscode.commands.executeCommand('editor.action.formatDocument')
|
||||
await test.sleep(1000)
|
||||
let lines = vscode.window.activeTextEditor?.document.getText().split('\n')
|
||||
assert.ok(lines)
|
||||
assert.ok(lines[1].trim().slice(0, 1).match(/[A-Z]/))
|
||||
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.case', 'lowercase')
|
||||
await vscode.commands.executeCommand('editor.action.formatDocument')
|
||||
await test.sleep(1000)
|
||||
lines = vscode.window.activeTextEditor?.document.getText().split('\n')
|
||||
assert.ok(lines)
|
||||
assert.ok(lines[1].trim().slice(0, 1).match(/[a-z]/))
|
||||
})
|
||||
|
||||
test.run(suiteName, fixtureName, 'test bibtex formatter with `bibtex-format.trailingComma`', async () => {
|
||||
await test.load(fixture, [{src: 'formatter/bibtex_base.bib', dst: 'main.bib'}])
|
||||
await test.open(fixture, 'main.bib')
|
||||
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.trailingComma', true)
|
||||
await vscode.commands.executeCommand('editor.action.formatDocument')
|
||||
await test.sleep(1000)
|
||||
let lines = vscode.window.activeTextEditor?.document.getText().split('\n')
|
||||
assert.ok(lines)
|
||||
assert.strictEqual(lines[5].trim().slice(-1), ',')
|
||||
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.trailingComma', false)
|
||||
await vscode.commands.executeCommand('editor.action.formatDocument')
|
||||
await test.sleep(1000)
|
||||
lines = vscode.window.activeTextEditor?.document.getText().split('\n')
|
||||
assert.ok(lines)
|
||||
assert.notStrictEqual(lines[5].trim().slice(-1), ',')
|
||||
})
|
||||
|
||||
test.run(suiteName, fixtureName, 'test bibtex sort with `bibtex-format.sortby`', async () => {
|
||||
await test.load(fixture, [{src: 'formatter/bibtex_base.bib', dst: 'main.bib'}])
|
||||
await test.open(fixture, 'main.bib')
|
||||
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.sortby', ['key'])
|
||||
await vscode.commands.executeCommand('latex-workshop.bibsort')
|
||||
await test.sleep(1000)
|
||||
let lines = vscode.window.activeTextEditor?.document.getText().split('\n')
|
||||
assert.ok(lines)
|
||||
let entries = lines.filter(line => line.includes('@'))
|
||||
assert.ok(entries[0].includes('art1'))
|
||||
assert.ok(entries[1].includes('lamport1994latex'))
|
||||
assert.ok(entries[2].includes('MR1241645'))
|
||||
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.sortby', ['year'])
|
||||
await vscode.commands.executeCommand('latex-workshop.bibsort')
|
||||
await test.sleep(1000)
|
||||
lines = vscode.window.activeTextEditor?.document.getText().split('\n')
|
||||
assert.ok(lines)
|
||||
entries = lines.filter(line => line.includes('@'))
|
||||
assert.ok(entries[2].includes('art1'))
|
||||
assert.ok(entries[1].includes('lamport1994latex'))
|
||||
assert.ok(entries[0].includes('MR1241645'))
|
||||
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.sortby', ['author'])
|
||||
await vscode.commands.executeCommand('latex-workshop.bibsort')
|
||||
await test.sleep(1000)
|
||||
lines = vscode.window.activeTextEditor?.document.getText().split('\n')
|
||||
assert.ok(lines)
|
||||
entries = lines.filter(line => line.includes('@'))
|
||||
assert.ok(entries[0].includes('art1'))
|
||||
assert.ok(entries[1].includes('lamport1994latex'))
|
||||
assert.ok(entries[2].includes('MR1241645'))
|
||||
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.sortby', ['year-desc'])
|
||||
await vscode.commands.executeCommand('latex-workshop.bibsort')
|
||||
await test.sleep(1000)
|
||||
lines = vscode.window.activeTextEditor?.document.getText().split('\n')
|
||||
assert.ok(lines)
|
||||
entries = lines.filter(line => line.includes('@'))
|
||||
assert.ok(entries[0].includes('art1'))
|
||||
assert.ok(entries[1].includes('lamport1994latex'))
|
||||
assert.ok(entries[2].includes('MR1241645'))
|
||||
})
|
||||
|
||||
test.run(suiteName, fixtureName, 'test bibtex formatter with `bibtex-format.handleDuplicates`', async () => {
|
||||
await test.load(fixture, [{src: 'formatter/bibtex_dup.bib', dst: 'main.bib'}])
|
||||
await test.open(fixture, 'main.bib')
|
||||
|
||||
await vscode.commands.executeCommand('latex-workshop.bibsort')
|
||||
await test.sleep(1000)
|
||||
let lines = vscode.window.activeTextEditor?.document.getText().split('\n')
|
||||
assert.ok(lines)
|
||||
assert.strictEqual(lines.filter(line => line.includes('@')).length, 2)
|
||||
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.handleDuplicates', 'Comment Duplicates')
|
||||
await vscode.commands.executeCommand('latex-workshop.bibsort')
|
||||
await test.sleep(1000)
|
||||
lines = vscode.window.activeTextEditor?.document.getText().split('\n')
|
||||
assert.ok(lines)
|
||||
assert.strictEqual(lines.filter(line => line.includes('@')).length, 1)
|
||||
})
|
||||
|
||||
test.run(suiteName, fixtureName, 'test bibtex formatter with `bibtex-format.sort.enabled`', async () => {
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.sortby', ['year'])
|
||||
await test.load(fixture, [{src: 'formatter/bibtex_base.bib', dst: 'main.bib'}])
|
||||
await test.open(fixture, 'main.bib')
|
||||
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.sort.enabled', false)
|
||||
await vscode.commands.executeCommand('editor.action.formatDocument')
|
||||
await test.sleep(1000)
|
||||
let lines = vscode.window.activeTextEditor?.document.getText().split('\n')
|
||||
assert.ok(lines)
|
||||
let entries = lines.filter(line => line.includes('@'))
|
||||
assert.ok(entries[0].includes('art1'))
|
||||
assert.ok(entries[1].includes('lamport1994latex'))
|
||||
assert.ok(entries[2].includes('MR1241645'))
|
||||
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.sort.enabled', true)
|
||||
await vscode.commands.executeCommand('editor.action.formatDocument')
|
||||
await test.sleep(1000)
|
||||
lines = vscode.window.activeTextEditor?.document.getText().split('\n')
|
||||
assert.ok(lines)
|
||||
entries = lines.filter(line => line.includes('@'))
|
||||
assert.ok(entries[2].includes('art1'))
|
||||
assert.ok(entries[1].includes('lamport1994latex'))
|
||||
assert.ok(entries[0].includes('MR1241645'))
|
||||
})
|
||||
|
||||
test.only(suiteName, fixtureName, 'test bibtex formatter with `bibtex-format.align-equal.enabled`', async () => {
|
||||
await test.load(fixture, [{src: 'formatter/bibtex_base.bib', dst: 'main.bib'}])
|
||||
await test.open(fixture, 'main.bib')
|
||||
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.align-equal.enabled', false)
|
||||
await vscode.commands.executeCommand('editor.action.formatDocument')
|
||||
await test.sleep(1000)
|
||||
let lines = vscode.window.activeTextEditor?.document.getText().split('\n')
|
||||
assert.ok(lines)
|
||||
const allEqual = (arr: number[]) => arr.every(val => val === arr[0])
|
||||
assert.ok(!allEqual(lines.slice(9, 18).map(line => line.indexOf('='))))
|
||||
|
||||
await vscode.workspace.getConfiguration('latex-workshop').update('bibtex-format.align-equal.enabled', true)
|
||||
await vscode.commands.executeCommand('editor.action.formatDocument')
|
||||
await test.sleep(1000)
|
||||
lines = vscode.window.activeTextEditor?.document.getText().split('\n')
|
||||
assert.ok(lines)
|
||||
assert.ok(allEqual(lines.slice(9, 18).map(line => line.indexOf('='))))
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user