diff options
| -rw-r--r-- | src/test/MockDocument.ts | 51 | ||||
| -rw-r--r-- | src/test/MockEditor.ts | 43 | ||||
| -rw-r--r-- | src/test/MockLine.ts | 13 | ||||
| -rw-r--r-- | src/test/MockPosition.ts | 39 | ||||
| -rw-r--r-- | src/test/MockSelection.ts | 35 | ||||
| -rw-r--r-- | src/test/MockTextEditorEdit.ts | 18 | ||||
| -rw-r--r-- | src/test/extension.test.ts | 85 |
7 files changed, 279 insertions, 5 deletions
diff --git a/src/test/MockDocument.ts b/src/test/MockDocument.ts new file mode 100644 index 0000000..447adc9 --- /dev/null +++ b/src/test/MockDocument.ts @@ -0,0 +1,51 @@ +import * as vscode from "vscode"; +import MockLine from "./MockLine"; + +export default class MockDocument implements vscode.TextDocument { + public uri: vscode.Uri; + public fileName: string; + public isUntitled: boolean; + public languageId: string; + public version: number; + public isDirty: boolean; + public isClosed: boolean; + public eol: vscode.EndOfLine; + public lineCount: number; + private line: vscode.TextLine; + private firstCall: boolean; + public constructor(line: vscode.TextLine) { + this.line = line; + this.firstCall = true; + } + public save(): Thenable<boolean> { + throw new Error("Method not implemented."); + } + public lineAt(line: number | vscode.Position): vscode.TextLine; + public lineAt(position: any): any { + if (this.firstCall) { + this.firstCall = false; + return this.line; + } else { + return new MockLine(";"); + } + } + public offsetAt(position: vscode.Position): number { + throw new Error("Method not implemented."); + } + public positionAt(offset: number): vscode.Position { + throw new Error("Method not implemented."); + } + public getText(range?: vscode.Range): string { + throw new Error("Method not implemented."); + } + public getWordRangeAtPosition(position: vscode.Position, regex?: RegExp): vscode.Range { + throw new Error("Method not implemented."); + } + public validateRange(range: vscode.Range): vscode.Range { + throw new Error("Method not implemented."); + } + public validatePosition(position: vscode.Position): vscode.Position { + throw new Error("Method not implemented."); + } + +} diff --git a/src/test/MockEditor.ts b/src/test/MockEditor.ts new file mode 100644 index 0000000..5368fb8 --- /dev/null +++ b/src/test/MockEditor.ts @@ -0,0 +1,43 @@ +import * as vscode from "vscode"; +import { TextEditor } from "vscode"; +import MockDocument from "./MockDocument"; +import MockSelection from "./MockSelection"; +import MockTextEditorEdit from "./MockTextEditorEdit"; + +export default class MockEditor implements TextEditor { + public document: vscode.TextDocument; + public selection: vscode.Selection; + public selections: vscode.Selection[]; + public options: vscode.TextEditorOptions; + public viewColumn?: vscode.ViewColumn; + public editBuilder: MockTextEditorEdit; + public constructor(s: MockSelection, d: MockDocument) { + this.selection = s; + this.document = d; + this.editBuilder = new MockTextEditorEdit(); + } + + public edit(callback: (editBuilder: vscode.TextEditorEdit) => void, + options?: { undoStopBefore: boolean; undoStopAfter: boolean; }): Thenable<boolean> { + callback(this.editBuilder); + return Promise.resolve(true); + } + public insertSnippet(snippet: vscode.SnippetString, + location?: vscode.Position | vscode.Range | vscode.Position[] | vscode.Range[], + options?: { undoStopBefore: boolean; undoStopAfter: boolean; }): Thenable<boolean> { + throw new Error("Method not implemented."); + } + public setDecorations(decorationType: vscode.TextEditorDecorationType, + rangesOrOptions: vscode.Range[] | vscode.DecorationOptions[]): void { + throw new Error("Method not implemented."); + } + public revealRange(range: vscode.Range, revealType?: vscode.TextEditorRevealType): void { + throw new Error("Method not implemented."); + } + public show(column?: vscode.ViewColumn): void { + throw new Error("Method not implemented."); + } + public hide(): void { + throw new Error("Method not implemented."); + } +} diff --git a/src/test/MockLine.ts b/src/test/MockLine.ts new file mode 100644 index 0000000..7196a38 --- /dev/null +++ b/src/test/MockLine.ts @@ -0,0 +1,13 @@ +import * as vscode from "vscode"; + +export default class MockLine implements vscode.TextLine { + public lineNumber: number; + public text: string; + public range: vscode.Range; + public rangeIncludingLineBreak: vscode.Range; + public firstNonWhitespaceCharacterIndex: number; + public isEmptyOrWhitespace: boolean; + public constructor(text: string) { + this.text = text; + } +} diff --git a/src/test/MockPosition.ts b/src/test/MockPosition.ts new file mode 100644 index 0000000..0753670 --- /dev/null +++ b/src/test/MockPosition.ts @@ -0,0 +1,39 @@ +import * as vscode from "vscode"; + +export default class MockPosition implements vscode.Position { + public line: number; + public character: number; + public constructor(l: number, c: number) { + this.line = l; + this.character = c; + } + public isBefore(other: vscode.Position): boolean { + throw new Error("Method not implemented."); + } + public isBeforeOrEqual(other: vscode.Position): boolean { + throw new Error("Method not implemented."); + } + public isAfter(other: vscode.Position): boolean { + throw new Error("Method not implemented."); + } + public isAfterOrEqual(other: vscode.Position): boolean { + throw new Error("Method not implemented."); + } + public isEqual(other: vscode.Position): boolean { + throw new Error("Method not implemented."); + } + public compareTo(other: vscode.Position): number { + throw new Error("Method not implemented."); + } + public translate(lineDelta?: number, characterDelta?: number): vscode.Position; + public translate(change: { lineDelta?: number; characterDelta?: number; }): vscode.Position; + public translate(lineDelta?: any, characterDelta?: any): any { + throw new Error("Method not implemented."); + } + public with(line?: number, character?: number): vscode.Position; + public with(change: { line?: number; character?: number; }): vscode.Position; + public with(line?: any, character?: any): any { + throw new Error("Method not implemented."); + } + +} diff --git a/src/test/MockSelection.ts b/src/test/MockSelection.ts new file mode 100644 index 0000000..e72ff8b --- /dev/null +++ b/src/test/MockSelection.ts @@ -0,0 +1,35 @@ +import * as vscode from "vscode"; +import MockPosition from "./MockPosition"; + +export default class MockSelection implements vscode.Selection { + public anchor: vscode.Position; + public active: vscode.Position; + public isReversed: boolean; + public start: vscode.Position; + public end: vscode.Position; + public isEmpty: boolean; + public isSingleLine: boolean; + + public constructor(a: MockPosition) { + this.active = a; + this.start = a; + } + + public contains(positionOrRange: vscode.Range | vscode.Position): boolean { + throw new Error("Method not implemented."); + } + public isEqual(other: vscode.Range): boolean { + throw new Error("Method not implemented."); + } + public intersection(range: vscode.Range): vscode.Range { + throw new Error("Method not implemented."); + } + public union(other: vscode.Range): vscode.Range { + throw new Error("Method not implemented."); + } + public with(start?: vscode.Position, end?: vscode.Position): vscode.Range; + public with(change: { start?: vscode.Position; end?: vscode.Position; }): vscode.Range; + public with(start?: any, end?: any): any { + throw new Error("Method not implemented."); + } +} diff --git a/src/test/MockTextEditorEdit.ts b/src/test/MockTextEditorEdit.ts new file mode 100644 index 0000000..e751182 --- /dev/null +++ b/src/test/MockTextEditorEdit.ts @@ -0,0 +1,18 @@ +import * as vscode from "vscode"; + +export default class MockTextEditorEdit implements vscode.TextEditorEdit { + public text: string; + public replace(location: vscode.Position | vscode.Range | vscode.Selection, value: string): void { + this.text = value; + } + public insert(location: vscode.Position, value: string): void { + throw new Error("Method not implemented."); + } + public delete(location: vscode.Range | vscode.Selection): void { + throw new Error("Method not implemented."); + } + public setEndOfLine(endOfLine: vscode.EndOfLine): void { + throw new Error("Method not implemented."); + } + +} diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts index 35bf33f..f9d9c5a 100644 --- a/src/test/extension.test.ts +++ b/src/test/extension.test.ts @@ -9,14 +9,89 @@ import * as assert from "assert"; // You can import and use all API from the 'vscode' module // as well as import your extension to test it import * as vscode from "vscode"; +import CodeParser from "../CodeParser/CodeParser"; +import CParser from "../CodeParser/CParser/CParser"; +import { IDocGen } from "../DocGen/DocGen"; import * as myExtension from "../extension"; +import MockDocument from "./MockDocument"; +import MockEditor from "./MockEditor"; +import MockLine from "./MockLine"; +import MockPosition from "./MockPosition"; +import MockSelection from "./MockSelection"; // Defines a Mocha test suite to group tests of similar kind together -suite("Extension Tests", () => { +suite("Comment parsing", () => { - // Defines a Mocha unit test - test("Something 1", () => { - assert.equal(-1, [1, 2, 3].indexOf(5)); - assert.equal(-1, [1, 2, 3].indexOf(0)); + function setup(method: string): IDocGen { + let parser: CodeParser; + parser = new CParser(); + + let position: MockPosition; + position = new MockPosition(0, 0); + + let selection: MockSelection; + selection = new MockSelection(position); + + let line: MockLine; + line = new MockLine(method); + + let doc: MockDocument; + doc = new MockDocument(line); + + let editor: vscode.TextEditor; + editor = new MockEditor(selection, doc); + + const gen: IDocGen = parser.Parse(editor); + + return gen; + } + + // Tests +}); + +// Defines a Mocha test suite to group tests of similar kind together +suite("Comment generation", () => { + + let editor: MockEditor; + + function setup(method: string): IDocGen { + let parser: CodeParser; + parser = new CParser(); + + let position: MockPosition; + position = new MockPosition(0, 0); + + let selection: MockSelection; + selection = new MockSelection(position); + + let line: MockLine; + line = new MockLine(method); + + let doc: MockDocument; + doc = new MockDocument(line); + + editor = new MockEditor(selection, doc); + + const gen: IDocGen = parser.Parse(editor); + + return gen; + } + + // Tests + test("void main(int argc, char **argv)", () => { + const gen: IDocGen = setup("void main(int argc, char **argv)"); + + gen.GenerateDoc(new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 0))); + + assert.equal("/**\n * @brief \n * \n * @param argc \n * @param argv \n */", editor.editBuilder.text); + }); + + test("bool fuzzy_equal(const matrix<T, M, N>& mat, T fuzz) const", () => { + const gen: IDocGen = setup("bool fuzzy_equal(const matrix<T, M, N>& mat, T fuzz) const"); + + gen.GenerateDoc(new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 0))); + + assert.equal("/**\n * @brief \n * \n * @param mat \n * @param fuzz \n * @return true \n * @return false \n */", + editor.editBuilder.text); }); }); |