Viewer tests & rearrange test structure

This commit is contained in:
James-Yu 2022-12-30 10:17:55 +08:00
parent 93506b5657
commit b1e8f6d4e8
13 changed files with 627 additions and 440 deletions

View File

@ -1,2 +0,0 @@
{
}

View File

@ -3,8 +3,7 @@ import * as path from 'path'
import rimraf from 'rimraf'
import { Extension } from '../../src/main'
import { assertBuild, getExtension, runTest, waitBuild, writeTeX } from './utils'
import { sleep } from '../utils/ciutils'
import { sleep, assertBuild, getExtension, runTest, waitBuild, writeTeX } from './utils'
suite('Build TeX files test suite', () => {
@ -135,18 +134,19 @@ suite('Build TeX files test suite', () => {
await assertBuild({fixture, texFileName: 'sub/s.tex', pdfFileName: 'sub/s.pdf', extension})
})
runTest({suiteName, fixtureName, testName: 'build main.tex choosing it in QuickPick'}, async () => {
runTest({suiteName, fixtureName, testName: 'build main.tex with QuickPick'}, async () => {
await vscode.workspace.getConfiguration('latex-workshop').update('latex.rootFile.doNotPrompt', false)
await writeTeX('subfile', fixture)
await assertBuild({fixture, texFileName: 'sub/s.tex', pdfFileName: 'main.pdf', extension, build: async () => {
const wait = waitBuild(extension)
void vscode.commands.executeCommand('latex-workshop.build')
await sleep(1000)
await vscode.commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem')
await waitBuild(extension)
await wait
}})
})
runTest({suiteName, fixtureName, testName: 'build s.tex choosing it in QuickPick'}, async () => {
runTest({suiteName, fixtureName, testName: 'build s.tex with QuickPick'}, async () => {
await vscode.workspace.getConfiguration('latex-workshop').update('latex.rootFile.doNotPrompt', false)
await writeTeX('subfile', fixture)
await assertBuild({fixture, texFileName: 'sub/s.tex', pdfFileName: 'sub/s.pdf', extension, build: async () => {

View File

@ -3,8 +3,7 @@ import * as path from 'path'
import rimraf from 'rimraf'
import { Extension } from '../../src/main'
import { assertAutoBuild, assertBuild, getExtension, runTest, writeTeX } from './utils'
import { sleep } from '../utils/ciutils'
import { sleep, assertAutoBuild, assertBuild, getExtension, runTest, writeTeX } from './utils'
suite('Auto-build test suite', () => {

View File

@ -4,8 +4,7 @@ import rimraf from 'rimraf'
import * as assert from 'assert'
import { Extension } from '../../src/main'
import { assertRoot, getExtension, runTest, writeTeX } from './utils'
import { sleep } from '../utils/ciutils'
import { sleep, assertRoot, getExtension, runTest, writeTeX } from './utils'
suite('Find root file test suite', () => {

View File

@ -1,21 +1,35 @@
import * as vscode from 'vscode'
import * as fs from 'fs'
import * as path from 'path'
import rimraf from 'rimraf'
import * as assert from 'assert'
import rimraf from 'rimraf'
import glob from 'glob'
import { Extension } from '../../src/main'
import { getExtension, getIntellisense, runTest, writeTeX } from './utils'
import { sleep } from '../utils/ciutils'
import { sleep, getExtension, getIntellisense, runTest, writeTeX } from './utils'
import { EnvSnippetType, EnvType } from '../../src/providers/completer/environment'
import { CmdType } from '../../src/providers/completer/command'
import { PkgType } from '../../src/providers/completion'
import { isTriggerSuggestNeeded } from '../../src/providers/completer/commandlib/commandfinder'
function assertKeys(keys: string[], mendatory: string[], optional: string[] = [], message: string): void {
assert.ok(
keys.every(k => mendatory.includes(k) || optional.includes(k)) && mendatory.every(k => keys.includes(k)),
message
)
}
suite('Intellisense test suite', () => {
let extension: Extension
let extensionRoot = path.resolve(__dirname, '../../')
const suiteName = path.basename(__filename).replace('.test.js', '')
let fixture = path.resolve(__dirname, '../../../test/fixtures/testground')
const fixtureName = 'testground'
suiteSetup(async () => {
extension = await getExtension()
extensionRoot = extension.extensionRoot
fixture = path.resolve(extension.extensionRoot, 'test/fixtures/testground')
})
@ -36,6 +50,82 @@ suite('Intellisense test suite', () => {
}
})
runTest({suiteName, fixtureName, testName: 'check default environment .json completion file'}, () => {
const file = `${extensionRoot}/data/environments.json`
const envs = JSON.parse(fs.readFileSync(file, {encoding: 'utf8'})) as {[key: string]: EnvType}
assert.ok(Object.keys(envs).length > 0)
Object.keys(envs).forEach(name => {
assertKeys(
Object.keys(envs[name]),
['name'],
['snippet', 'detail'],
file + ': ' + JSON.stringify(envs[name])
)
})
})
runTest({suiteName, fixtureName, testName: 'check default commands .json completion file'}, () => {
const file = `${extensionRoot}/data/commands.json`
const cmds = JSON.parse(fs.readFileSync(file, {encoding: 'utf8'})) as {[key: string]: CmdType}
assert.ok(Object.keys(cmds).length > 0)
Object.keys(cmds).forEach(name => {
assertKeys(
Object.keys(cmds[name]),
['command'],
['snippet', 'documentation', 'detail', 'postAction', 'label'],
file + ': ' + JSON.stringify(cmds[name])
)
})
})
runTest({suiteName, fixtureName, testName: 'test default envs'}, () => {
assert.ok(extension)
let defaultEnvs = extension.completer.environment.getDefaultEnvs(EnvSnippetType.AsCommand).map(e => e.label)
assert.ok(defaultEnvs.includes('document'))
assert.ok(defaultEnvs.includes('align'))
defaultEnvs = extension.completer.environment.getDefaultEnvs(EnvSnippetType.AsName).map(e => e.label)
assert.ok(defaultEnvs.includes('document'))
assert.ok(defaultEnvs.includes('align'))
defaultEnvs = extension.completer.environment.getDefaultEnvs(EnvSnippetType.ForBegin).map(e => e.label)
assert.ok(defaultEnvs.includes('document'))
assert.ok(defaultEnvs.includes('align'))
})
runTest({suiteName, fixtureName, testName: 'test default cmds'}, () => {
assert.ok(extension)
const defaultCommands = extension.completer.command.getDefaultCmds().map(e => e.label)
assert.ok(defaultCommands.includes('\\begin'))
assert.ok(defaultCommands.includes('\\left('))
assert.ok(defaultCommands.includes('\\section{title}'))
})
runTest({suiteName, fixtureName, testName: 'check package .json completion file'}, () => {
const files = glob.sync('data/packages/*.json', {cwd: extensionRoot})
files.forEach(file => {
const pkg = JSON.parse(fs.readFileSync(path.join(extensionRoot, file), {encoding: 'utf8'})) as PkgType
Object.keys(pkg.cmds).forEach(name => {
assertKeys(
Object.keys(pkg.cmds[name]),
[],
['command', 'snippet', 'option', 'keyvals', 'keyvalindex', 'documentation', 'detail'],
file + ': ' + JSON.stringify(pkg.cmds[name])
)
})
Object.keys(pkg.envs).forEach(name => {
assertKeys(
Object.keys(pkg.envs[name]),
[],
['name', 'snippet', 'detail', 'option', 'keyvals', 'keyvalindex'],
file + ': ' + JSON.stringify(pkg.envs[name])
)
})
})
})
runTest({suiteName, fixtureName, testName: 'test isTriggerSuggestNeeded'}, () => {
assert.ok(!isTriggerSuggestNeeded('frac'))
})
runTest({suiteName, fixtureName, testName: 'basic completion'}, async () => {
await writeTeX('intellisense', fixture)
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(path.resolve(fixture, 'main.tex')))

View File

@ -0,0 +1,105 @@
import * as vscode from 'vscode'
import * as path from 'path'
import rimraf from 'rimraf'
import { Extension } from '../../src/main'
import { sleep, assertBuild, assertViewer, getExtension, runTest, waitBuild, writeTeX } from './utils'
suite('Find root file test suite', () => {
let extension: Extension
const suiteName = path.basename(__filename).replace('.test.js', '')
let fixture = path.resolve(__dirname, '../../../test/fixtures/testground')
const fixtureName = 'testground'
suiteSetup(async () => {
extension = await getExtension()
fixture = path.resolve(extension.extensionRoot, 'test/fixtures/testground')
})
setup(async () => {
await vscode.commands.executeCommand('latex-workshop.activate')
await vscode.workspace.getConfiguration().update('latex-workshop.view.pdf.viewer', 'tab')
})
teardown(async () => {
await vscode.commands.executeCommand('workbench.action.closeAllEditors')
extension.manager.rootFile = undefined
await vscode.workspace.getConfiguration().update('latex-workshop.latex.outDir', undefined)
await vscode.workspace.getConfiguration().update('latex-workshop.view.pdf.viewer', undefined)
await vscode.workspace.getConfiguration().update('latex-workshop.latex.rootFile.useSubFile', undefined)
await vscode.workspace.getConfiguration().update('latex-workshop.latex.rootFile.doNotPrompt', undefined)
await vscode.workspace.getConfiguration().update('latex-workshop.synctex.afterBuild.enabled', undefined)
if (path.basename(fixture) === 'testground') {
rimraf(fixture + '/{*,.vscode/*}', (e) => {if (e) {console.error(e)}})
await sleep(500) // Required for pooling
}
})
runTest({suiteName, fixtureName, testName: 'basic build and view'}, async () => {
await writeTeX('main', fixture)
await assertBuild({fixture, texFileName: 'main.tex', pdfFileName: 'main.pdf', extension})
await assertViewer({fixture, pdfFileName: 'main.pdf', extension})
})
runTest({suiteName, fixtureName, testName: 'build main.tex and view it'}, async () => {
await vscode.workspace.getConfiguration().update('latex-workshop.latex.rootFile.doNotPrompt', true)
await vscode.workspace.getConfiguration().update('latex-workshop.latex.rootFile.useSubFile', false)
await writeTeX('subfile', fixture)
await assertBuild({fixture, texFileName: 'sub/s.tex', pdfFileName: 'main.pdf', extension})
await assertViewer({fixture, pdfFileName: 'main.pdf', extension})
})
runTest({suiteName, fixtureName, testName: 'build a subfile and view it'}, async () => {
await vscode.workspace.getConfiguration().update('latex-workshop.latex.rootFile.doNotPrompt', true)
await vscode.workspace.getConfiguration().update('latex-workshop.latex.rootFile.useSubFile', true)
await writeTeX('subfile', fixture)
await assertBuild({fixture, texFileName: 'sub/s.tex', pdfFileName: 'sub/s.pdf', extension})
await assertViewer({fixture, pdfFileName: 'sub/s.pdf', extension})
})
runTest({suiteName, fixtureName, testName: 'build main.tex with QuickPick and view it'}, async () => {
await vscode.workspace.getConfiguration('latex-workshop').update('latex.rootFile.doNotPrompt', false)
await writeTeX('subfile', fixture)
await assertBuild({fixture, texFileName: 'sub/s.tex', pdfFileName: 'main.pdf', extension, build: async () => {
const wait = waitBuild(extension)
void vscode.commands.executeCommand('latex-workshop.build')
await sleep(1000)
await vscode.commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem')
await wait
}})
await assertViewer({fixture, pdfFileName: 'main.pdf', extension, action: async () => {
await sleep(1000)
await vscode.commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem')
}})
})
runTest({suiteName, fixtureName, testName: 'build s.tex with QuickPick and view it'}, async () => {
await vscode.workspace.getConfiguration('latex-workshop').update('latex.rootFile.doNotPrompt', false)
await writeTeX('subfile', fixture)
await assertBuild({fixture, texFileName: 'sub/s.tex', pdfFileName: 'sub/s.pdf', extension, build: async () => {
const wait = waitBuild(extension)
void vscode.commands.executeCommand('latex-workshop.build')
await sleep(1000)
await vscode.commands.executeCommand('workbench.action.quickOpenSelectNext')
await sleep(500)
await vscode.commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem')
await wait
}})
await assertViewer({fixture, pdfFileName: 'sub/s.pdf', extension, action: async () => {
await sleep(1000)
await vscode.commands.executeCommand('workbench.action.quickOpenSelectNext')
await sleep(500)
await vscode.commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem')
}})
})
runTest({only: true, suiteName, fixtureName, testName: 'build with outDir and view it'}, async () => {
await vscode.workspace.getConfiguration('latex-workshop').update('latex.outDir', './out')
await writeTeX('main', fixture)
await assertBuild({fixture, texFileName: 'main.tex', pdfFileName: 'out/main.pdf', extension})
await assertViewer({fixture, pdfFileName: 'out/main.pdf', extension})
})
})

View File

@ -0,0 +1,153 @@
import * as vscode from 'vscode'
import * as path from 'path'
import * as assert from 'assert'
import rimraf from 'rimraf'
import { Extension } from '../../src/main'
import { sleep, getExtension, runTest, writeTeX } from './utils'
import { SectionNodeProvider } from '../../src/providers/structure'
suite('Intellisense test suite', () => {
let extension: Extension
const suiteName = path.basename(__filename).replace('.test.js', '')
let fixture = path.resolve(__dirname, '../../../test/fixtures/testground')
const fixtureName = 'testground'
suiteSetup(async () => {
extension = await getExtension()
fixture = path.resolve(extension.extensionRoot, 'test/fixtures/testground')
})
setup(async () => {
await vscode.commands.executeCommand('latex-workshop.activate')
})
teardown(async () => {
await vscode.commands.executeCommand('workbench.action.closeAllEditors')
extension.manager.rootFile = undefined
await vscode.workspace.getConfiguration('latex-workshop').update('view.outline.numbers.enabled', undefined)
await vscode.workspace.getConfiguration('latex-workshop').update('view.outline.sections', undefined)
await vscode.workspace.getConfiguration('latex-workshop').update('view.outline.floats.enabled', undefined)
await vscode.workspace.getConfiguration('latex-workshop').update('view.outline.fastparse.enabled', undefined)
if (path.basename(fixture) === 'testground') {
rimraf(fixture + '/{*,.vscode/*}', (e) => {if (e) {console.error(e)}})
await sleep(500) // Required for pooling
}
})
runTest({suiteName, fixtureName, testName: 'test structure'}, async () => {
await writeTeX('structure', fixture)
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(path.resolve(fixture, 'main.tex')))
await vscode.window.showTextDocument(doc)
await extension.manager.findRoot()
assert.ok(extension)
const structure = new SectionNodeProvider(extension)
await structure.update(true)
const sections = structure.ds
assert.ok(sections)
assert.strictEqual(sections.length, 6)
assert.strictEqual(sections[0].children.length, 3)
assert.strictEqual(sections[0].children[1].children.length, 2)
assert.strictEqual(sections[0].children[1].children[0].label, '#label: sec11')
assert.strictEqual(sections[0].children[1].children[0].lineNumber, 5)
assert.strictEqual(sections[1].children.length, 1)
assert.strictEqual(sections[1].children[0].label, '2.0.1 2.0.1')
assert.strictEqual(sections[3].label, '4 4 A long title split over two lines')
assert.strictEqual(sections[4].label, '* No \\textit{Number} Section')
assert.strictEqual(sections[5].label, '5 Section pdf Caption')
assert.strictEqual(sections[5].children[0].label, 'Figure: Untitled')
assert.strictEqual(sections[5].children[1].label, 'Figure: Figure Caption')
assert.strictEqual(sections[5].children[2].label, 'Table: Table Caption')
assert.strictEqual(sections[5].children[3].label, 'Frame: Frame Title 1')
assert.strictEqual(sections[5].children[4].label, 'Frame: Frame Title 2')
assert.strictEqual(sections[5].children[5].label, 'Frame: Untitled')
})
runTest({suiteName, fixtureName, testName: 'test view.outline.numbers.enabled'}, async () => {
await vscode.workspace.getConfiguration('latex-workshop').update('view.outline.numbers.enabled', false)
await writeTeX('structure', fixture)
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(path.resolve(fixture, 'main.tex')))
await vscode.window.showTextDocument(doc)
await extension.manager.findRoot()
assert.ok(extension)
const structure = new SectionNodeProvider(extension)
await structure.update(true)
const sections = structure.ds
assert.ok(sections)
assert.strictEqual(sections[1].children[0].label, '2.0.1')
})
runTest({suiteName, fixtureName, testName: 'test view.outline.sections'}, async () => {
await vscode.workspace.getConfiguration('latex-workshop').update('view.outline.sections', ['section', 'altsection', 'subsubsection'])
await writeTeX('structure', fixture)
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(path.resolve(fixture, 'main.tex')))
await vscode.window.showTextDocument(doc)
await extension.manager.findRoot()
assert.ok(extension)
const structure = new SectionNodeProvider(extension)
await structure.update(true)
const sections = structure.ds
assert.ok(sections)
assert.strictEqual(sections[0].children.length, 2)
assert.strictEqual(sections[0].children[1].label, '1.1 1.1?')
})
runTest({suiteName, fixtureName, testName: 'test view.outline.floats.enabled'}, async () => {
await vscode.workspace.getConfiguration('latex-workshop').update('view.outline.floats.enabled', false)
await writeTeX('structure', fixture)
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(path.resolve(fixture, 'main.tex')))
await vscode.window.showTextDocument(doc)
await extension.manager.findRoot()
assert.ok(extension)
const structure = new SectionNodeProvider(extension)
await structure.update(true)
const sections = structure.ds
assert.ok(sections)
assert.strictEqual(sections[5].children.length, 3)
assert.strictEqual(sections[5].children[0].label, 'Frame: Frame Title 1')
assert.strictEqual(sections[5].children[1].label, 'Frame: Frame Title 2')
assert.strictEqual(sections[5].children[2].label, 'Frame: Untitled')
})
runTest({suiteName, fixtureName, testName: 'test view.outline.fastparse.enabled'}, async () => {
await vscode.workspace.getConfiguration('latex-workshop').update('view.outline.fastparse.enabled', true)
await writeTeX('structure', fixture)
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(path.resolve(fixture, 'main.tex')))
await vscode.window.showTextDocument(doc)
await extension.manager.findRoot()
assert.ok(extension)
const structure = new SectionNodeProvider(extension)
await structure.update(true)
const sections = structure.ds
assert.ok(sections)
assert.strictEqual(sections.length, 6)
assert.strictEqual(sections[0].children.length, 3)
assert.strictEqual(sections[0].children[1].children.length, 2)
assert.strictEqual(sections[0].children[1].children[0].label, '#label: sec11')
assert.strictEqual(sections[0].children[1].children[0].lineNumber, 5)
assert.strictEqual(sections[1].children.length, 1)
assert.strictEqual(sections[1].children[0].label, '2.0.1 2.0.1')
assert.strictEqual(sections[3].label, '4 4 A long title split over two lines')
assert.strictEqual(sections[4].label, '* No \\textit{Number} Section')
assert.strictEqual(sections[5].label, '5 Section pdf Caption')
assert.strictEqual(sections[5].children[0].label, 'Figure: Untitled')
assert.strictEqual(sections[5].children[1].label, 'Figure: Figure Caption')
assert.strictEqual(sections[5].children[2].label, 'Table: Table Caption')
assert.strictEqual(sections[5].children[3].label, 'Frame: Frame Title 1')
assert.strictEqual(sections[5].children[4].label, 'Frame: Frame Title 2')
assert.strictEqual(sections[5].children[5].label, 'Frame: Untitled')
})
})

View File

@ -0,0 +1,142 @@
import * as vscode from 'vscode'
import * as path from 'path'
import * as assert from 'assert'
import rimraf from 'rimraf'
import { Extension } from '../../src/main'
import { sleep, getExtension, runTest } from './utils'
import { TextDocumentLike } from '../../src/providers/preview/mathpreviewlib/textdocumentlike'
import { TeXMathEnvFinder } from '../../src/providers/preview/mathpreviewlib/texmathenvfinder'
import { CursorRenderer } from '../../src/providers/preview/mathpreviewlib/cursorrenderer'
suite('Intellisense test suite', () => {
let extension: Extension
const suiteName = path.basename(__filename).replace('.test.js', '')
let fixture = path.resolve(__dirname, '../../../test/fixtures/testground')
const fixtureName = 'testground'
suiteSetup(async () => {
extension = await getExtension()
fixture = path.resolve(extension.extensionRoot, 'test/fixtures/testground')
})
setup(async () => {
await vscode.commands.executeCommand('latex-workshop.activate')
})
teardown(async () => {
await vscode.commands.executeCommand('workbench.action.closeAllEditors')
extension.manager.rootFile = undefined
if (path.basename(fixture) === 'testground') {
rimraf(fixture + '/{*,.vscode/*}', (e) => {if (e) {console.error(e)}})
await sleep(500) // Required for pooling
}
})
runTest({suiteName, fixtureName, testName: 'mathpreviewlib/cursorrenderer: test insertCursor'}, async () => {
const docString = '$a+b$'
const doc = new TextDocumentLike(docString)
const finder = new TeXMathEnvFinder()
const cursorPos = new vscode.Position(0, 2)
const texMath = finder.findMathEnvIncludingPosition(doc, cursorPos)
assert.ok(texMath)
assert.ok(extension)
const renderer = new CursorRenderer(extension)
const result = texMath && await renderer.insertCursor(texMath, cursorPos, '|')
assert.strictEqual(result, '${~a|+b~}$')
})
runTest({suiteName, fixtureName, testName: 'mathpreviewlib/cursorrenderer: test shouldNotWriteCursor'}, () => {
const docString = '$a+b$'
const doc = new TextDocumentLike(docString)
const finder = new TeXMathEnvFinder()
const cursorPos = new vscode.Position(0, 0)
const texMath = finder.findMathEnvIncludingPosition(doc, cursorPos)
assert.ok(texMath)
assert.ok(extension)
const renderer = new CursorRenderer(extension)
const result = renderer.isCursorInsideTexMath(texMath.range, cursorPos)
assert.strictEqual(result, false)
const cursorPos1 = new vscode.Position(0, 1)
const result1 = renderer.isCursorInsideTexMath(texMath.range, cursorPos1)
assert.strictEqual(result1, true)
const cursorPos4 = new vscode.Position(0, 4)
const result4 = renderer.isCursorInsideTexMath(texMath.range, cursorPos4)
assert.strictEqual(result4, true)
const cursorPos5 = new vscode.Position(0, 5)
const result5 = renderer.isCursorInsideTexMath(texMath.range, cursorPos5)
assert.strictEqual(result5, false)
})
runTest({suiteName, fixtureName, testName: 'mathpreviewlib/cursorrenderer: test \\f|rac{1}{2}'}, async () => {
const docString = '$\\frac{1}{2}$'
const doc = new TextDocumentLike(docString)
const finder = new TeXMathEnvFinder()
const cursorPos = new vscode.Position(0, 3)
const texMath = finder.findMathEnvIncludingPosition(doc, cursorPos)
assert.ok(texMath)
assert.ok(extension)
const renderer = new CursorRenderer(extension)
const result = texMath && await renderer.insertCursor(texMath, cursorPos, '|')
assert.strictEqual(result, '$\\frac{1}{2}$')
})
runTest({suiteName, fixtureName, testName: 'mathpreviewlib/cursorrenderer: test a^|b'}, async () => {
const docString = '$a^b$'
const doc = new TextDocumentLike(docString)
const finder = new TeXMathEnvFinder()
const cursorPos = new vscode.Position(0, 3)
const texMath = finder.findMathEnvIncludingPosition(doc, cursorPos)
assert.ok(texMath)
assert.ok(extension)
const renderer = new CursorRenderer(extension)
const result = texMath && await renderer.insertCursor(texMath, cursorPos, '|')
assert.strictEqual(result, '$a^{~|b~}$')
})
runTest({suiteName, fixtureName, testName: 'mathpreviewlib/cursorrenderer: test $a^b| $'}, async () => {
const docString = '$a^b $'
const doc = new TextDocumentLike(docString)
const finder = new TeXMathEnvFinder()
const cursorPos = new vscode.Position(0, 4)
const texMath = finder.findMathEnvIncludingPosition(doc, cursorPos)
assert.ok(texMath)
assert.ok(extension)
const renderer = new CursorRenderer(extension)
const result = texMath && await renderer.insertCursor(texMath, cursorPos, '|')
assert.strictEqual(result, '${~a^b|~} $')
})
runTest({suiteName, fixtureName, testName: 'mathpreviewlib/cursorrenderer: test $a^{b} $'}, async () => {
const docString = '$a^{b} $'
const doc = new TextDocumentLike(docString)
const finder = new TeXMathEnvFinder()
const cursorPos = new vscode.Position(0, 5)
const texMath = finder.findMathEnvIncludingPosition(doc, cursorPos)
assert.ok(texMath)
assert.ok(extension)
const renderer = new CursorRenderer(extension)
const result = texMath && await renderer.insertCursor(texMath, cursorPos, '|')
assert.strictEqual(result, '$a^{~b|~} $')
})
runTest({suiteName, fixtureName, testName: 'mathpreviewlib/cursorrenderer: test a_|b'}, async () => {
const docString = '$a_b$'
const doc = new TextDocumentLike(docString)
const finder = new TeXMathEnvFinder()
const cursorPos = new vscode.Position(0, 3)
const texMath = finder.findMathEnvIncludingPosition(doc, cursorPos)
assert.ok(texMath)
assert.ok(extension)
const renderer = new CursorRenderer(extension)
const result = texMath && await renderer.insertCursor(texMath, cursorPos, '|')
assert.strictEqual(result, '$a_{~|b~}$')
})
})

View File

@ -0,0 +1,80 @@
import * as vscode from 'vscode'
import * as path from 'path'
import * as assert from 'assert'
import rimraf from 'rimraf'
import { Extension } from '../../src/main'
import { sleep, getExtension, runTest, writeTeX } from './utils'
import { ChkTeX } from '../../src/components/linterlib/chktex'
import { LaCheck } from '../../src/components/linterlib/lacheck'
suite('Intellisense test suite', () => {
let extension: Extension
const suiteName = path.basename(__filename).replace('.test.js', '')
let fixture = path.resolve(__dirname, '../../../test/fixtures/testground')
const fixtureName = 'testground'
suiteSetup(async () => {
extension = await getExtension()
fixture = path.resolve(extension.extensionRoot, 'test/fixtures/testground')
})
setup(async () => {
await vscode.commands.executeCommand('latex-workshop.activate')
})
teardown(async () => {
await vscode.commands.executeCommand('workbench.action.closeAllEditors')
extension.manager.rootFile = undefined
if (path.basename(fixture) === 'testground') {
rimraf(fixture + '/{*,.vscode/*}', (e) => {if (e) {console.error(e)}})
await sleep(500) // Required for pooling
}
})
runTest({suiteName, fixtureName, testName: 'test chktex log parser'}, async () => {
await writeTeX('structure', fixture)
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(path.resolve(fixture, 'main.tex')))
await vscode.window.showTextDocument(doc)
await extension.manager.findRoot()
assert.ok(extension)
const linter = new ChkTeX(extension)
const log = 'main.tex:5:18:1:Warning:24:Delete this space to maintain correct pagereferences.\nsub/s.tex:1:26:1:Warning:24:Delete this space to maintain correct pagereferences.\n'
linter.parseLog(log)
assert.strictEqual(linter.linterDiagnostics.get(vscode.Uri.file(path.resolve(fixture, 'main.tex')))?.length, 1)
assert.strictEqual(linter.linterDiagnostics.get(vscode.Uri.file(path.resolve(fixture, 'sub/s.tex')))?.length, 1)
assert.match(linter.linterDiagnostics.get(vscode.Uri.file(path.resolve(fixture, 'main.tex')))?.[0].message || '', /Delete this space/)
assert.match(linter.linterDiagnostics.get(vscode.Uri.file(path.resolve(fixture, 'sub/s.tex')))?.[0].message || '', /Delete this space/)
})
runTest({suiteName, fixtureName, testName: 'test lacheck'}, async () => {
await writeTeX('structure', fixture)
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(path.resolve(fixture, 'main.tex')))
await vscode.window.showTextDocument(doc)
await extension.manager.findRoot()
assert.ok(extension)
const linter = new LaCheck(extension)
await linter.lintRootFile()
assert.strictEqual(linter.linterDiagnostics.name, 'LaCheck')
})
runTest({suiteName, fixtureName, testName: 'test lacheck log parser'}, async () => {
await writeTeX('structure', fixture)
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(path.resolve(fixture, 'main.tex')))
await vscode.window.showTextDocument(doc)
await extension.manager.findRoot()
assert.ok(extension)
const linter = new LaCheck(extension)
const log = '"main.tex", line 7: double space at "~~"\n** sub/sub:\n"sub/s.tex", line 2: double space at "~~"\n'
linter.parseLog(log)
assert.strictEqual(linter.linterDiagnostics.get(vscode.Uri.file(path.resolve(fixture, 'main.tex')))?.length, 1)
assert.strictEqual(linter.linterDiagnostics.get(vscode.Uri.file(path.resolve(fixture, 'sub/s.tex')))?.length, 1)
assert.match(linter.linterDiagnostics.get(vscode.Uri.file(path.resolve(fixture, 'main.tex')))?.[0].message || '', /double space at/)
assert.match(linter.linterDiagnostics.get(vscode.Uri.file(path.resolve(fixture, 'sub/s.tex')))?.[0].message || '', /double space at/)
})
})

View File

@ -4,8 +4,7 @@ import rimraf from 'rimraf'
import * as assert from 'assert'
import { Extension } from '../../src/main'
import { runTest, writeTeX, assertBuild, touch, assertAutoBuild, writeTestFile, copyTestFile, getIntellisense, assertRoot, getExtension } from './utils'
import { sleep } from '../utils/ciutils'
import { sleep, runTest, writeTeX, assertBuild, touch, assertAutoBuild, writeTestFile, copyTestFile, getIntellisense, assertRoot, getExtension } from './utils'
suite('Multi-root workspace test suite', () => {

View File

@ -1,408 +0,0 @@
import * as vscode from 'vscode'
import * as fs from 'fs'
import * as path from 'path'
import * as assert from 'assert'
import rimraf from 'rimraf'
import glob from 'glob'
import { Extension } from '../../src/main'
import { getExtension, runTest, writeTeX } from './utils'
import type { PkgType } from '../../src/providers/completion'
import type { CmdType } from '../../src/providers/completer/command'
import { EnvSnippetType, EnvType } from '../../src/providers/completer/environment'
import { SectionNodeProvider } from '../../src/providers/structure'
import { TeXMathEnvFinder } from '../../src/providers/preview/mathpreviewlib/texmathenvfinder'
import { CursorRenderer } from '../../src/providers/preview/mathpreviewlib/cursorrenderer'
import { isTriggerSuggestNeeded } from '../../src/providers/completer/commandlib/commandfinder'
import { ChkTeX } from '../../src/components/linterlib/chktex'
import { LaCheck } from '../../src/components/linterlib/lacheck'
import { TextDocumentLike } from '../../src/providers/preview/mathpreviewlib/textdocumentlike'
import { sleep } from '../utils/ciutils'
suite('Unit test suite', () => {
let extension: Extension
let extensionRoot = path.resolve(__dirname, '../../')
const suiteName = path.basename(__filename).replace('.test.js', '')
let fixture = path.resolve(__dirname, '../../../test/fixtures/testground')
const fixtureName = 'testground'
suiteSetup(async () => {
extension = await getExtension()
extensionRoot = extension.extensionRoot
fixture = path.resolve(extension.extensionRoot, 'test/fixtures/testground')
})
teardown(async () => {
await vscode.commands.executeCommand('workbench.action.closeAllEditors')
extension.manager.rootFile = undefined
await vscode.workspace.getConfiguration('latex-workshop').update('latex.search.rootFiles.include', undefined)
await vscode.workspace.getConfiguration('latex-workshop').update('view.outline.numbers.enabled', undefined)
await vscode.workspace.getConfiguration('latex-workshop').update('view.outline.sections', undefined)
await vscode.workspace.getConfiguration('latex-workshop').update('view.outline.floats.enabled', undefined)
await vscode.workspace.getConfiguration('latex-workshop').update('view.outline.fastparse.enabled', undefined)
if (path.basename(fixture) === 'testground') {
rimraf(fixture + '/{*,.vscode/*}', (e) => {if (e) {console.error(e)}})
await sleep(500) // Required for pooling
}
})
function assertKeys(keys: string[], mendatory: string[], optional: string[] = [], message: string): void {
assert.ok(
keys.every(k => mendatory.includes(k) || optional.includes(k)) && mendatory.every(k => keys.includes(k)),
message
)
}
runTest({suiteName, fixtureName, testName: 'check default environment .json completion file'}, () => {
const file = `${extensionRoot}/data/environments.json`
const envs = JSON.parse(fs.readFileSync(file, {encoding: 'utf8'})) as {[key: string]: EnvType}
assert.ok(Object.keys(envs).length > 0)
Object.keys(envs).forEach(name => {
assertKeys(
Object.keys(envs[name]),
['name'],
['snippet', 'detail'],
file + ': ' + JSON.stringify(envs[name])
)
})
})
runTest({suiteName, fixtureName, testName: 'check default commands .json completion file'}, () => {
const file = `${extensionRoot}/data/commands.json`
const cmds = JSON.parse(fs.readFileSync(file, {encoding: 'utf8'})) as {[key: string]: CmdType}
assert.ok(Object.keys(cmds).length > 0)
Object.keys(cmds).forEach(name => {
assertKeys(
Object.keys(cmds[name]),
['command'],
['snippet', 'documentation', 'detail', 'postAction', 'label'],
file + ': ' + JSON.stringify(cmds[name])
)
})
})
runTest({suiteName, fixtureName, testName: 'test default envs'}, () => {
assert.ok(extension)
let defaultEnvs = extension.completer.environment.getDefaultEnvs(EnvSnippetType.AsCommand).map(e => e.label)
assert.ok(defaultEnvs.includes('document'))
assert.ok(defaultEnvs.includes('align'))
defaultEnvs = extension.completer.environment.getDefaultEnvs(EnvSnippetType.AsName).map(e => e.label)
assert.ok(defaultEnvs.includes('document'))
assert.ok(defaultEnvs.includes('align'))
defaultEnvs = extension.completer.environment.getDefaultEnvs(EnvSnippetType.ForBegin).map(e => e.label)
assert.ok(defaultEnvs.includes('document'))
assert.ok(defaultEnvs.includes('align'))
})
runTest({suiteName, fixtureName, testName: 'test default cmds'}, () => {
assert.ok(extension)
const defaultCommands = extension.completer.command.getDefaultCmds().map(e => e.label)
assert.ok(defaultCommands.includes('\\begin'))
assert.ok(defaultCommands.includes('\\left('))
assert.ok(defaultCommands.includes('\\section{title}'))
})
runTest({suiteName, fixtureName, testName: 'check package .json completion file'}, () => {
const files = glob.sync('data/packages/*.json', {cwd: extensionRoot})
files.forEach(file => {
const pkg = JSON.parse(fs.readFileSync(path.join(extensionRoot, file), {encoding: 'utf8'})) as PkgType
Object.keys(pkg.cmds).forEach(name => {
assertKeys(
Object.keys(pkg.cmds[name]),
[],
['command', 'snippet', 'option', 'keyvals', 'keyvalindex', 'documentation', 'detail'],
file + ': ' + JSON.stringify(pkg.cmds[name])
)
})
Object.keys(pkg.envs).forEach(name => {
assertKeys(
Object.keys(pkg.envs[name]),
[],
['name', 'snippet', 'detail', 'option', 'keyvals', 'keyvalindex'],
file + ': ' + JSON.stringify(pkg.envs[name])
)
})
})
})
runTest({suiteName, fixtureName, testName: 'test isTriggerSuggestNeeded'}, () => {
assert.ok(!isTriggerSuggestNeeded('frac'))
})
runTest({suiteName, fixtureName, testName: 'test structure'}, async () => {
await writeTeX('structure', fixture)
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(path.resolve(fixture, 'main.tex')))
await vscode.window.showTextDocument(doc)
await extension.manager.findRoot()
assert.ok(extension)
const structure = new SectionNodeProvider(extension)
await structure.update(true)
const sections = structure.ds
assert.ok(sections)
assert.strictEqual(sections.length, 6)
assert.strictEqual(sections[0].children.length, 3)
assert.strictEqual(sections[0].children[1].children.length, 2)
assert.strictEqual(sections[0].children[1].children[0].label, '#label: sec11')
assert.strictEqual(sections[0].children[1].children[0].lineNumber, 5)
assert.strictEqual(sections[1].children.length, 1)
assert.strictEqual(sections[1].children[0].label, '2.0.1 2.0.1')
assert.strictEqual(sections[3].label, '4 4 A long title split over two lines')
assert.strictEqual(sections[4].label, '* No \\textit{Number} Section')
assert.strictEqual(sections[5].label, '5 Section pdf Caption')
assert.strictEqual(sections[5].children[0].label, 'Figure: Untitled')
assert.strictEqual(sections[5].children[1].label, 'Figure: Figure Caption')
assert.strictEqual(sections[5].children[2].label, 'Table: Table Caption')
assert.strictEqual(sections[5].children[3].label, 'Frame: Frame Title 1')
assert.strictEqual(sections[5].children[4].label, 'Frame: Frame Title 2')
assert.strictEqual(sections[5].children[5].label, 'Frame: Untitled')
})
runTest({suiteName, fixtureName, testName: 'test view.outline.numbers.enabled'}, async () => {
await vscode.workspace.getConfiguration('latex-workshop').update('view.outline.numbers.enabled', false)
await writeTeX('structure', fixture)
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(path.resolve(fixture, 'main.tex')))
await vscode.window.showTextDocument(doc)
await extension.manager.findRoot()
assert.ok(extension)
const structure = new SectionNodeProvider(extension)
await structure.update(true)
const sections = structure.ds
assert.ok(sections)
assert.strictEqual(sections[1].children[0].label, '2.0.1')
})
runTest({suiteName, fixtureName, testName: 'test view.outline.sections'}, async () => {
await vscode.workspace.getConfiguration('latex-workshop').update('view.outline.sections', ['section', 'altsection', 'subsubsection'])
await writeTeX('structure', fixture)
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(path.resolve(fixture, 'main.tex')))
await vscode.window.showTextDocument(doc)
await extension.manager.findRoot()
assert.ok(extension)
const structure = new SectionNodeProvider(extension)
await structure.update(true)
const sections = structure.ds
assert.ok(sections)
assert.strictEqual(sections[0].children.length, 2)
assert.strictEqual(sections[0].children[1].label, '1.1 1.1?')
})
runTest({suiteName, fixtureName, testName: 'test view.outline.floats.enabled'}, async () => {
await vscode.workspace.getConfiguration('latex-workshop').update('view.outline.floats.enabled', false)
await writeTeX('structure', fixture)
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(path.resolve(fixture, 'main.tex')))
await vscode.window.showTextDocument(doc)
await extension.manager.findRoot()
assert.ok(extension)
const structure = new SectionNodeProvider(extension)
await structure.update(true)
const sections = structure.ds
assert.ok(sections)
assert.strictEqual(sections[5].children.length, 3)
assert.strictEqual(sections[5].children[0].label, 'Frame: Frame Title 1')
assert.strictEqual(sections[5].children[1].label, 'Frame: Frame Title 2')
assert.strictEqual(sections[5].children[2].label, 'Frame: Untitled')
})
runTest({suiteName, fixtureName, testName: 'test view.outline.fastparse.enabled'}, async () => {
await vscode.workspace.getConfiguration('latex-workshop').update('view.outline.fastparse.enabled', true)
await writeTeX('structure', fixture)
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(path.resolve(fixture, 'main.tex')))
await vscode.window.showTextDocument(doc)
await extension.manager.findRoot()
assert.ok(extension)
const structure = new SectionNodeProvider(extension)
await structure.update(true)
const sections = structure.ds
assert.ok(sections)
assert.strictEqual(sections.length, 6)
assert.strictEqual(sections[0].children.length, 3)
assert.strictEqual(sections[0].children[1].children.length, 2)
assert.strictEqual(sections[0].children[1].children[0].label, '#label: sec11')
assert.strictEqual(sections[0].children[1].children[0].lineNumber, 5)
assert.strictEqual(sections[1].children.length, 1)
assert.strictEqual(sections[1].children[0].label, '2.0.1 2.0.1')
assert.strictEqual(sections[3].label, '4 4 A long title split over two lines')
assert.strictEqual(sections[4].label, '* No \\textit{Number} Section')
assert.strictEqual(sections[5].label, '5 Section pdf Caption')
assert.strictEqual(sections[5].children[0].label, 'Figure: Untitled')
assert.strictEqual(sections[5].children[1].label, 'Figure: Figure Caption')
assert.strictEqual(sections[5].children[2].label, 'Table: Table Caption')
assert.strictEqual(sections[5].children[3].label, 'Frame: Frame Title 1')
assert.strictEqual(sections[5].children[4].label, 'Frame: Frame Title 2')
assert.strictEqual(sections[5].children[5].label, 'Frame: Untitled')
})
runTest({suiteName, fixtureName, testName: 'mathpreviewlib/cursorrenderer: test insertCursor'}, async () => {
const docString = '$a+b$'
const doc = new TextDocumentLike(docString)
const finder = new TeXMathEnvFinder()
const cursorPos = new vscode.Position(0, 2)
const texMath = finder.findMathEnvIncludingPosition(doc, cursorPos)
assert.ok(texMath)
assert.ok(extension)
const renderer = new CursorRenderer(extension)
const result = texMath && await renderer.insertCursor(texMath, cursorPos, '|')
assert.strictEqual(result, '${~a|+b~}$')
})
runTest({suiteName, fixtureName, testName: 'mathpreviewlib/cursorrenderer: test shouldNotWriteCursor'}, () => {
const docString = '$a+b$'
const doc = new TextDocumentLike(docString)
const finder = new TeXMathEnvFinder()
const cursorPos = new vscode.Position(0, 0)
const texMath = finder.findMathEnvIncludingPosition(doc, cursorPos)
assert.ok(texMath)
assert.ok(extension)
const renderer = new CursorRenderer(extension)
const result = renderer.isCursorInsideTexMath(texMath.range, cursorPos)
assert.strictEqual(result, false)
const cursorPos1 = new vscode.Position(0, 1)
const result1 = renderer.isCursorInsideTexMath(texMath.range, cursorPos1)
assert.strictEqual(result1, true)
const cursorPos4 = new vscode.Position(0, 4)
const result4 = renderer.isCursorInsideTexMath(texMath.range, cursorPos4)
assert.strictEqual(result4, true)
const cursorPos5 = new vscode.Position(0, 5)
const result5 = renderer.isCursorInsideTexMath(texMath.range, cursorPos5)
assert.strictEqual(result5, false)
})
runTest({suiteName, fixtureName, testName: 'mathpreviewlib/cursorrenderer: test \\f|rac{1}{2}'}, async () => {
const docString = '$\\frac{1}{2}$'
const doc = new TextDocumentLike(docString)
const finder = new TeXMathEnvFinder()
const cursorPos = new vscode.Position(0, 3)
const texMath = finder.findMathEnvIncludingPosition(doc, cursorPos)
assert.ok(texMath)
assert.ok(extension)
const renderer = new CursorRenderer(extension)
const result = texMath && await renderer.insertCursor(texMath, cursorPos, '|')
assert.strictEqual(result, '$\\frac{1}{2}$')
})
runTest({suiteName, fixtureName, testName: 'mathpreviewlib/cursorrenderer: test a^|b'}, async () => {
const docString = '$a^b$'
const doc = new TextDocumentLike(docString)
const finder = new TeXMathEnvFinder()
const cursorPos = new vscode.Position(0, 3)
const texMath = finder.findMathEnvIncludingPosition(doc, cursorPos)
assert.ok(texMath)
assert.ok(extension)
const renderer = new CursorRenderer(extension)
const result = texMath && await renderer.insertCursor(texMath, cursorPos, '|')
assert.strictEqual(result, '$a^{~|b~}$')
})
runTest({suiteName, fixtureName, testName: 'mathpreviewlib/cursorrenderer: test $a^b| $'}, async () => {
const docString = '$a^b $'
const doc = new TextDocumentLike(docString)
const finder = new TeXMathEnvFinder()
const cursorPos = new vscode.Position(0, 4)
const texMath = finder.findMathEnvIncludingPosition(doc, cursorPos)
assert.ok(texMath)
assert.ok(extension)
const renderer = new CursorRenderer(extension)
const result = texMath && await renderer.insertCursor(texMath, cursorPos, '|')
assert.strictEqual(result, '${~a^b|~} $')
})
runTest({suiteName, fixtureName, testName: 'mathpreviewlib/cursorrenderer: test $a^{b} $'}, async () => {
const docString = '$a^{b} $'
const doc = new TextDocumentLike(docString)
const finder = new TeXMathEnvFinder()
const cursorPos = new vscode.Position(0, 5)
const texMath = finder.findMathEnvIncludingPosition(doc, cursorPos)
assert.ok(texMath)
assert.ok(extension)
const renderer = new CursorRenderer(extension)
const result = texMath && await renderer.insertCursor(texMath, cursorPos, '|')
assert.strictEqual(result, '$a^{~b|~} $')
})
runTest({suiteName, fixtureName, testName: 'mathpreviewlib/cursorrenderer: test a_|b'}, async () => {
const docString = '$a_b$'
const doc = new TextDocumentLike(docString)
const finder = new TeXMathEnvFinder()
const cursorPos = new vscode.Position(0, 3)
const texMath = finder.findMathEnvIncludingPosition(doc, cursorPos)
assert.ok(texMath)
assert.ok(extension)
const renderer = new CursorRenderer(extension)
const result = texMath && await renderer.insertCursor(texMath, cursorPos, '|')
assert.strictEqual(result, '$a_{~|b~}$')
})
runTest({suiteName, fixtureName, testName: 'test chktex'}, async () => {
await writeTeX('structure', fixture)
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(path.resolve(fixture, 'main.tex')))
await vscode.window.showTextDocument(doc)
await extension.manager.findRoot()
assert.ok(extension)
const linter = new ChkTeX(extension)
await linter.lintRootFile()
assert.strictEqual(linter.linterDiagnostics.name, 'ChkTeX')
})
runTest({suiteName, fixtureName, testName: 'test chktex log parser'}, async () => {
await writeTeX('structure', fixture)
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(path.resolve(fixture, 'main.tex')))
await vscode.window.showTextDocument(doc)
await extension.manager.findRoot()
assert.ok(extension)
const linter = new ChkTeX(extension)
const log = 'main.tex:5:18:1:Warning:24:Delete this space to maintain correct pagereferences.\nsub/s.tex:1:26:1:Warning:24:Delete this space to maintain correct pagereferences.\n'
linter.parseLog(log)
assert.strictEqual(linter.linterDiagnostics.get(vscode.Uri.file(path.resolve(fixture, 'main.tex')))?.length, 1)
assert.strictEqual(linter.linterDiagnostics.get(vscode.Uri.file(path.resolve(fixture, 'sub/s.tex')))?.length, 1)
assert.match(linter.linterDiagnostics.get(vscode.Uri.file(path.resolve(fixture, 'main.tex')))?.[0].message || '', /Delete this space/)
assert.match(linter.linterDiagnostics.get(vscode.Uri.file(path.resolve(fixture, 'sub/s.tex')))?.[0].message || '', /Delete this space/)
})
runTest({suiteName, fixtureName, testName: 'test lacheck'}, async () => {
await writeTeX('structure', fixture)
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(path.resolve(fixture, 'main.tex')))
await vscode.window.showTextDocument(doc)
await extension.manager.findRoot()
assert.ok(extension)
const linter = new LaCheck(extension)
await linter.lintRootFile()
assert.strictEqual(linter.linterDiagnostics.name, 'LaCheck')
})
runTest({suiteName, fixtureName, testName: 'test lacheck log parser'}, async () => {
await writeTeX('structure', fixture)
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(path.resolve(fixture, 'main.tex')))
await vscode.window.showTextDocument(doc)
await extension.manager.findRoot()
assert.ok(extension)
const linter = new LaCheck(extension)
const log = '"main.tex", line 7: double space at "~~"\n** sub/sub:\n"sub/s.tex", line 2: double space at "~~"\n'
linter.parseLog(log)
assert.strictEqual(linter.linterDiagnostics.get(vscode.Uri.file(path.resolve(fixture, 'main.tex')))?.length, 1)
assert.strictEqual(linter.linterDiagnostics.get(vscode.Uri.file(path.resolve(fixture, 'sub/s.tex')))?.length, 1)
assert.match(linter.linterDiagnostics.get(vscode.Uri.file(path.resolve(fixture, 'main.tex')))?.[0].message || '', /double space at/)
assert.match(linter.linterDiagnostics.get(vscode.Uri.file(path.resolve(fixture, 'sub/s.tex')))?.[0].message || '', /double space at/)
})
})

View File

@ -8,7 +8,7 @@ export function run(): Promise<void> {
ui: 'tdd',
color: true,
timeout: 15000,
retries: 4
retries: process.env['LATEXWORKSHOP_CLI'] ? 3 : 0
})
return new Promise((resolve, reject) => {

View File

@ -6,7 +6,8 @@ import * as os from 'os'
import * as assert from 'assert'
import { Extension, activate } from '../../src/main'
import { BuildFinished } from '../../src/components/eventbus'
import { BuildFinished, PdfViewerPagesLoaded, PdfViewerStatusChanged } from '../../src/components/eventbus'
import type { EventName } from '../../src/components/eventbus'
export async function getExtension() {
await vscode.commands.executeCommand('latex-workshop.activate')
@ -107,9 +108,7 @@ type AssertBuildOption = {
texFileName: string,
pdfFileName: string,
extension: Extension,
build?: () => unknown,
nobuild?: boolean,
removepdf?: boolean
build?: () => unknown
}
export async function assertBuild(option: AssertBuildOption) {
@ -126,15 +125,6 @@ export async function assertBuild(option: AssertBuildOption) {
const files = glob.sync('**/**.pdf', { cwd: option.fixture })
assert.strictEqual(files.map(file => path.resolve(option.fixture, file)).join(','), option.pdfFileName === '' ? option.pdfFileName : pdfFilePath)
if (option.removepdf) {
files.forEach(async file => {
if (fs.existsSync(path.join(option.fixture, file))) {
fs.unlinkSync(path.join(option.fixture, file))
await sleep(250)
}
})
}
}
export async function assertAutoBuild(option: AssertBuildOption, mode?: ('skipFirstBuild' | 'noAutoBuild' | 'onSave')[]) {
@ -165,15 +155,19 @@ export async function assertAutoBuild(option: AssertBuildOption, mode?: ('skipFi
}
}
export async function waitBuild(extension: Extension) {
async function waitEvent(extension: Extension, event: EventName) {
return new Promise<void>((resolve, _) => {
const disposable = extension.eventBus.on(BuildFinished, () => {
const disposable = extension.eventBus.on(event, () => {
resolve()
disposable?.dispose()
})
})
}
export async function waitBuild(extension: Extension) {
return waitEvent(extension, BuildFinished)
}
type AssertRootOption = {
fixture: string,
openName: string,
@ -191,6 +185,42 @@ export async function assertRoot(option: AssertRootOption) {
assert.strictEqual(root, rootFilePath)
}
type AssertViewerOption = {
fixture: string,
pdfFileName: string,
extension: Extension,
action?: () => unknown
}
export async function assertViewer(option: AssertViewerOption) {
await sleep(500)
const wait = waitViewer(option.extension)
void vscode.commands.executeCommand('latex-workshop.view')
if (option.action) {
await option.action()
}
await wait
const status = getViewerStatus(option.extension, path.resolve(option.fixture, option.pdfFileName))
assert.strictEqual(status.pdfFileUri, vscode.Uri.file(path.resolve(option.fixture, option.pdfFileName)).toString(true))
}
async function waitViewer(extension: Extension) {
return Promise.all([
waitEvent(extension, PdfViewerPagesLoaded),
waitViewerChange(extension)
])
}
async function waitViewerChange(extension: Extension) {
return waitEvent(extension, PdfViewerStatusChanged)
}
function getViewerStatus(extension: Extension, pdfFilePath: string) {
const status = extension.viewer.getViewerState(vscode.Uri.file(pdfFilePath))[0]
assert.ok(status)
return status
}
type WriteTeXType = 'main' | 'makeindex' | 'makesubfileindex' | 'magicprogram' | 'magicoption' | 'magicroot' | 'magicinvalidprogram' |
'subfile' | 'subfileverbatim' | 'subfiletwomain' | 'subfilethreelayer' | 'importthreelayer' | 'bibtex' |
'input' | 'inputmacro' | 'inputfromfolder' | 'circularinclude' | 'intellisense' | 'structure' | 'linter'