mirror of
https://github.com/James-Yu/LaTeX-Workshop.git
synced 2024-10-05 07:37:24 +03:00
Test all .json files for completion
This commit is contained in:
parent
92ca29054d
commit
fd5e022005
@ -1,13 +1,33 @@
|
||||
import * as assert from 'assert'
|
||||
import * as process from 'process'
|
||||
import * as vscode from 'vscode'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import * as glob from 'glob'
|
||||
|
||||
import {stripComments} from '../src/utils/utils'
|
||||
|
||||
import {
|
||||
runTestWithFixture,
|
||||
checkDictkeys as checkDictKeys
|
||||
} from './utils'
|
||||
|
||||
type EnvType = {
|
||||
name: string,
|
||||
snippet?: string,
|
||||
detail?: string,
|
||||
package?: string
|
||||
}
|
||||
|
||||
type CmdType = {
|
||||
command: string,
|
||||
snippet?: string,
|
||||
documentation?: string,
|
||||
package?: string,
|
||||
detail?: string,
|
||||
postAction?: string,
|
||||
label?: string
|
||||
}
|
||||
|
||||
suite('unit test suite', () => {
|
||||
|
||||
suiteSetup(() => {
|
||||
@ -18,11 +38,53 @@ suite('unit test suite', () => {
|
||||
return
|
||||
})
|
||||
|
||||
runTestWithFixture('fixture001', 'basic unit tests', () => {
|
||||
assert.strictEqual(
|
||||
stripComments('abc % comment'),
|
||||
'abc'
|
||||
)
|
||||
runTestWithFixture('fixture001', 'check default environment .json completion file', () => {
|
||||
const extensionRoot = path.resolve(__dirname, '../../')
|
||||
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 => {
|
||||
assert.ok(checkDictKeys(Object.keys(envs[name]), ['name'] , ['snippet', 'detail']), file + ': ' + JSON.stringify(envs[name]))
|
||||
})
|
||||
return Promise.resolve()
|
||||
})
|
||||
|
||||
runTestWithFixture('fixture001', 'check environments from package .json completion files', () => {
|
||||
const extensionRoot = path.resolve(__dirname, '../../')
|
||||
const files = glob.sync('data/packages/*_env.json', {cwd: extensionRoot})
|
||||
files.forEach(file => {
|
||||
const envs = JSON.parse(fs.readFileSync(path.join(extensionRoot, file), {encoding: 'utf8'})) as {[key: string]: EnvType}
|
||||
assert.ok(Object.keys(envs).length > 0)
|
||||
Object.keys(envs).forEach(name => {
|
||||
assert.ok(checkDictKeys(Object.keys(envs[name]), ['name', 'snippet', 'detail', 'package']), file + ': ' + JSON.stringify(envs[name]))
|
||||
})
|
||||
})
|
||||
return Promise.resolve()
|
||||
})
|
||||
|
||||
runTestWithFixture('fixture001', 'check default commands .json completion file', () => {
|
||||
const extensionRoot = path.resolve(__dirname, '../../')
|
||||
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 => {
|
||||
assert.ok(checkDictKeys(Object.keys(cmds[name]), ['command'] , ['snippet', 'documentation', 'detail', 'postAction', 'label']), file + ': ' + JSON.stringify(cmds[name]))
|
||||
})
|
||||
return Promise.resolve()
|
||||
})
|
||||
|
||||
runTestWithFixture('fixture001', 'check commands from package .json completion files', () => {
|
||||
const extensionRoot = path.resolve(__dirname, '../../')
|
||||
const files = glob.sync('data/packages/*_cmd.json', {cwd: extensionRoot})
|
||||
files.forEach(file => {
|
||||
const cmds = JSON.parse(fs.readFileSync(path.join(extensionRoot, file), {encoding: 'utf8'})) as {[key: string]: CmdType}
|
||||
assert.ok(Object.keys(cmds).length > 0)
|
||||
Object.keys(cmds).forEach(name => {
|
||||
assert.ok(checkDictKeys(Object.keys(cmds[name]), ['command', 'snippet'] , ['documentation', 'detail', 'postAction', 'package', 'label']), file + ': ' + JSON.stringify(cmds[name]))
|
||||
})
|
||||
})
|
||||
return Promise.resolve()
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
|
@ -178,3 +178,7 @@ export async function getViewerStatus(pdfFilePath: string) {
|
||||
}
|
||||
}, process.platform === 'win32' ? 600 : undefined)
|
||||
}
|
||||
|
||||
export function checkDictkeys(keys: string[], expectedKeys: string[], optKeys: string[] = []): boolean {
|
||||
return keys.every(k => expectedKeys.includes(k) || optKeys.includes(k)) && expectedKeys.every(k => keys.includes(k))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user