|
| 1 | +import * as assert from 'assert'; |
| 2 | +import * as fs from 'fs'; |
| 3 | +import * as os from 'os'; |
| 4 | +import * as path from 'path'; |
| 5 | +import * as proxyquire from 'proxyquire'; |
| 6 | + |
| 7 | +suite('Formatting Provider', () => { |
| 8 | + test('does not crash without workspace', () => { |
| 9 | + const tmp = path.join(os.tmpdir(), 'fmt.v'); |
| 10 | + fs.writeFileSync(tmp, 'module m; endmodule'); |
| 11 | + |
| 12 | + const vscodeStub = { |
| 13 | + workspace: { |
| 14 | + getConfiguration: () => ({ get: () => '/bin/true' }), |
| 15 | + workspaceFolders: undefined, |
| 16 | + }, |
| 17 | + Range: class { constructor(public start: any, public end: any) {} }, |
| 18 | + Position: class { constructor(public line: number, public char: number) {} }, |
| 19 | + TextEdit: { replace: (_r: any, _t: any) => ({}) }, |
| 20 | + }; |
| 21 | + |
| 22 | + const providerModule = proxyquire('../../providers/FormatPrivider', { |
| 23 | + vscode: vscodeStub, |
| 24 | + }); |
| 25 | + |
| 26 | + const Provider = providerModule.VerilogFormatProvider; |
| 27 | + const logger: any = { |
| 28 | + info: () => {}, |
| 29 | + error: () => {}, |
| 30 | + warn: () => {}, |
| 31 | + debug: () => {}, |
| 32 | + }; |
| 33 | + logger.getChild = () => logger; |
| 34 | + const provider = new Provider(logger); |
| 35 | + const doc = { |
| 36 | + uri: { fsPath: tmp }, |
| 37 | + getText: () => fs.readFileSync(tmp, 'utf8'), |
| 38 | + positionAt: (_o: number) => new vscodeStub.Position(0, 0), |
| 39 | + languageId: 'verilog', |
| 40 | + }; |
| 41 | + |
| 42 | + assert.doesNotThrow(() => provider.provideDocumentFormattingEdits(doc as any, {} as any, {} as any)); |
| 43 | + }); |
| 44 | +}); |
0 commit comments