-
Notifications
You must be signed in to change notification settings - Fork 537
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Glossary unit tests, fix a few caching issues in previous ones
- Loading branch information
Showing
12 changed files
with
221 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import * as vscode from 'vscode' | ||
import * as path from 'path' | ||
import * as sinon from 'sinon' | ||
import { lw } from '../../src/lw' | ||
import { assert, get, mock, set } from './utils' | ||
import { provider } from '../../src/completion/completer/glossary' | ||
|
||
describe(path.basename(__filename).split('.')[0] + ':', () => { | ||
const fixture = path.basename(__filename).split('.')[0] | ||
const texPath = get.path(fixture, 'main.tex') | ||
const glsPath = get.path(fixture, 'gls.tex') | ||
let readStub: sinon.SinonStub | ||
|
||
before(() => { | ||
mock.init(lw, 'root', 'cache', 'parser', 'completion') | ||
readStub = sinon.stub(lw.file, 'read') | ||
}) | ||
|
||
beforeEach(() => { | ||
set.root(texPath) | ||
}) | ||
|
||
after(() => { | ||
sinon.restore() | ||
}) | ||
|
||
describe('lw.completion->glossary', () => { | ||
function getSuggestions() { | ||
return provider.from(['', ''], { | ||
uri: vscode.Uri.file(texPath), | ||
langId: 'latex', | ||
line: '', | ||
position: new vscode.Position(0, 0), | ||
}) | ||
} | ||
|
||
it('should parse and provide \\newacronym definition', async () => { | ||
readStub.resolves('\\newacronym{rf}{RF}{radio-frequency}') | ||
await lw.cache.refreshCache(texPath) | ||
|
||
const suggestions = getSuggestions() | ||
|
||
assert.ok(suggestions.some(s => s.label === 'rf')) | ||
assert.strictEqual(suggestions.find(s => s.label === 'rf')?.detail, 'radio-frequency') | ||
}) | ||
|
||
it('should reject ill-formed glossary definitions', async () => { | ||
readStub.resolves('\\newacronym[argopt]{EPE_x}{E} % ill-formed entry') | ||
await lw.cache.refreshCache(texPath) | ||
|
||
const suggestions = getSuggestions() | ||
|
||
assert.ok(!suggestions.some(s => s.label === 'EPE_x')) | ||
}) | ||
|
||
it('should parse and provide \\newglossaryentry definition', async () => { | ||
readStub.resolves('\\newglossaryentry{vs_code}{name=VSCode, description=Editor}') | ||
await lw.cache.refreshCache(texPath) | ||
|
||
const suggestions = getSuggestions() | ||
|
||
assert.ok(suggestions.some(s => s.label === 'vs_code')) | ||
assert.strictEqual(suggestions.find(s => s.label === 'vs_code')?.detail, 'Editor') | ||
}) | ||
|
||
it('should parse and provide \\newglossaryentry definition with curly brace fence', async () => { | ||
readStub.resolves('\\newglossaryentry{lw}{name={LaTeX Workshop}, description={What this extension is $\\mathbb{A}$}}') | ||
await lw.cache.refreshCache(texPath) | ||
|
||
const suggestions = getSuggestions() | ||
|
||
assert.ok(suggestions.some(s => s.label === 'lw')) | ||
assert.strictEqual(suggestions.find(s => s.label === 'lw')?.detail, 'What this extension is $\\mathbb{A}$') | ||
}) | ||
|
||
it('should parse and provide \\newabbr definition', async () => { | ||
readStub.resolves('\\newabbr{abbr_x}{Ebbr}{A first abbreviation}') | ||
await lw.cache.refreshCache(texPath) | ||
|
||
const suggestions = getSuggestions() | ||
|
||
assert.ok(suggestions.some(s => s.label === 'abbr_x')) | ||
assert.strictEqual(suggestions.find(s => s.label === 'abbr_x')?.detail, 'A first abbreviation') | ||
}) | ||
|
||
it('should parse and provide \\newabbreviation definition', async () => { | ||
readStub.resolves('\\newabbreviation[optional arg]{abbr_y}{Ybbr}{A second abbreviation}') | ||
await lw.cache.refreshCache(texPath) | ||
|
||
const suggestions = getSuggestions() | ||
|
||
assert.ok(suggestions.some(s => s.label === 'abbr_y')) | ||
assert.strictEqual(suggestions.find(s => s.label === 'abbr_y')?.detail, 'A second abbreviation') | ||
}) | ||
|
||
it('should parse and provide glossary definitions in another file given in \\loadglsentries', async () => { | ||
const stub = sinon.stub(lw.file, 'exists').resolves({ type: 1, ctime: 0, mtime: 0, size: 0 }) | ||
readStub.resolves('\\newacronym{rf}{RF}{radio-frequency}') | ||
readStub.withArgs(texPath).resolves('\\loadglsentries{gls}') | ||
await lw.cache.refreshCache(texPath) | ||
await lw.cache.refreshCache(glsPath) | ||
stub.restore() | ||
|
||
const suggestions = getSuggestions() | ||
|
||
assert.ok(suggestions.some(s => s.label === 'rf')) | ||
assert.strictEqual(suggestions.find(s => s.label === 'rf')?.detail, 'radio-frequency') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters