lw.cache.loadFlsFile and lw.cache.parseFlsContent tests

This commit is contained in:
James Yu 2024-06-09 17:16:07 +01:00
parent bd3834e7e7
commit 4678265b4b
17 changed files with 86 additions and 0 deletions

View File

@ -0,0 +1,2 @@
INPUT ./main.aux
INPUT ./main.out

View File

@ -0,0 +1,2 @@
INPUT /article.tex
OUTPUT /article.tex

View File

@ -0,0 +1 @@
INPUT ../main.bbl

View File

@ -0,0 +1 @@
INPUT ./not-exist.tex

View File

@ -0,0 +1 @@
INPUT ../main.tex

View File

@ -0,0 +1,2 @@
INPUT ../main.tex
INPUT ../another.tex

View File

@ -0,0 +1 @@
INPUT ../main.pdf

View File

@ -0,0 +1 @@
INPUT ./self_include.tex

View File

@ -532,4 +532,79 @@ describe(path.basename(__filename).split('.')[0] + ':', () => {
assert.ok(lw.watcher.bib.has(bibPath))
})
})
describe('lw.cache.loadFlsFile and lw.cache.parseFlsContent', () => {
it('should do nothing if no .fls is found', async () => {
await lw.cache.loadFlsFile(texPathAnother)
assert.ok(!hasLog('Parsing .fls '))
})
it('should not consider files that are both INPUT and OUTPUT', async () => {
const toParse = getPath(fixture, 'load_fls_file', 'both_input_output.tex')
await lw.cache.refreshCache(toParse)
await lw.cache.loadFlsFile(toParse)
assert.strictEqual(lw.cache.get(toParse)?.children.length, 0)
})
it('should not consider files that are excluded', async () => {
const toParse = getPath(fixture, 'load_fls_file', 'excluded_file.tex')
await lw.cache.refreshCache(toParse)
await lw.cache.loadFlsFile(toParse)
assert.strictEqual(lw.cache.get(toParse)?.children.length, 0)
})
it('should not consider files that do not exist', async () => {
const toParse = getPath(fixture, 'load_fls_file', 'file_not_exist.tex')
await lw.cache.refreshCache(toParse)
await lw.cache.loadFlsFile(toParse)
assert.strictEqual(lw.cache.get(toParse)?.children.length, 0)
})
it('should not consider the file itself if listed in .fls', async () => {
const toParse = getPath(fixture, 'load_fls_file', 'self_include.tex')
await lw.cache.refreshCache(toParse)
await lw.cache.loadFlsFile(toParse)
assert.strictEqual(lw.cache.get(toParse)?.children.length, 0)
})
it('should not consider files that already been cached', async () => {
lw.cache.add(texPath)
await lw.cache.refreshCache(texPath)
const toParse = getPath(fixture, 'load_fls_file', 'include_main.tex')
await lw.cache.refreshCache(toParse)
await lw.cache.loadFlsFile(toParse)
assert.strictEqual(lw.cache.get(toParse)?.children.length, 0)
})
it('should add file as child if all checks passed', async () => {
const toParse = getPath(fixture, 'load_fls_file', 'include_main.tex')
await lw.cache.loadFlsFile(toParse)
assert.strictEqual(lw.cache.get(toParse)?.children.length, 1)
})
it('should add multiple files as children if all checks passed', async () => {
const toParse = getPath(fixture, 'load_fls_file', 'include_many.tex')
await lw.cache.loadFlsFile(toParse)
assert.strictEqual(lw.cache.get(toParse)?.children.length, 2)
})
it('should watch added .tex files', async () => {
const toParse = getPath(fixture, 'load_fls_file', 'include_main.tex')
await lw.cache.loadFlsFile(toParse)
assert.ok(lw.watcher.src.has(texPath))
})
it('should watch added non-.tex files', async () => {
const toParse = getPath(fixture, 'load_fls_file', 'non_tex_input.tex')
await lw.cache.loadFlsFile(toParse)
assert.ok(lw.watcher.src.has(pdfPath))
})
it('should watch added non-.tex files, except for aux or out files', async () => {
const toParse = getPath(fixture, 'load_fls_file', 'aux_out_input.tex')
await lw.cache.loadFlsFile(toParse)
assert.ok(!lw.watcher.src.has(getPath(fixture, 'load_fls_file', 'main.aux')))
assert.ok(!lw.watcher.src.has(getPath(fixture, 'load_fls_file', 'main.out')))
})
})
})