summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/MockDocument.ts9
-rw-r--r--src/test/TestSetup.ts46
-rw-r--r--src/test/extension.test.ts149
-rw-r--r--src/test/functionPointer.test.ts42
-rw-r--r--src/test/simpleReturn.test.ts79
5 files changed, 172 insertions, 153 deletions
diff --git a/src/test/MockDocument.ts b/src/test/MockDocument.ts
index 447adc9..cb6bbfe 100644
--- a/src/test/MockDocument.ts
+++ b/src/test/MockDocument.ts
@@ -12,18 +12,19 @@ export default class MockDocument implements vscode.TextDocument {
public eol: vscode.EndOfLine;
public lineCount: number;
private line: vscode.TextLine;
- private firstCall: boolean;
+ private callCount: number;
public constructor(line: vscode.TextLine) {
this.line = line;
- this.firstCall = true;
+ this.callCount = 0;
}
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;
+ if (++this.callCount === 1) {
+ return new MockLine("");
+ } else if (this.callCount === 2) {
return this.line;
} else {
return new MockLine(";");
diff --git a/src/test/TestSetup.ts b/src/test/TestSetup.ts
new file mode 100644
index 0000000..2f4f64a
--- /dev/null
+++ b/src/test/TestSetup.ts
@@ -0,0 +1,46 @@
+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";
+
+export default class TestSetup {
+ private editor: MockEditor;
+
+ constructor(method: string) {
+ this.SetMethod(method);
+ }
+
+ public SetMethod(method: string): TestSetup {
+ 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);
+
+ this.editor = new MockEditor(selection, doc);
+
+ return this;
+ }
+
+ public GetResult(): string {
+ let parser: CodeParser;
+ parser = new CParser();
+
+ const gen: IDocGen = parser.Parse(this.editor);
+ gen.GenerateDoc(new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 0)));
+
+ return this.editor.editBuilder.text;
+ }
+}
diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts
deleted file mode 100644
index da2819d..0000000
--- a/src/test/extension.test.ts
+++ /dev/null
@@ -1,149 +0,0 @@
-//
-// Note: This example test is leveraging the Mocha test framework.
-// Please refer to their documentation on https://mochajs.org/ for help.
-//
-
-// The module 'assert' provides assertion methods from node
-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("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);
- });
-
- test("int main()", () => {
- const gen: IDocGen = setup("int main()");
-
- gen.GenerateDoc(new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 0)));
-
- assert.equal("/**\n * @brief \n * \n * @return int \n */",
- editor.editBuilder.text);
- });
-
- test("void foo(std::string str, std::vector<std::string> lst)", () => {
- const gen: IDocGen = setup("void foo(std::string str, std::vector<std::string> lst)");
-
- gen.GenerateDoc(new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 0)));
-
- assert.equal("/**\n * @brief \n * \n * @param str \n * @param lst \n */",
- editor.editBuilder.text);
- });
-
- test("std::vector<int> foo()", () => {
- const gen: IDocGen = setup("std::vector<int> foo()");
-
- gen.GenerateDoc(new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 0)));
-
- assert.equal("/**\n * @brief \n * \n * @return std::vector<int> \n */",
- editor.editBuilder.text);
- });
-
- test("myClass(int i)", () => {
- const gen: IDocGen = setup("myClass(int i)");
-
- gen.GenerateDoc(new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 0)));
-
- assert.equal("/**\n * @brief \n * \n * @param i \n */",
- editor.editBuilder.text);
- });
-
- test("myClass(int i) : i(i)", () => {
- const gen: IDocGen = setup("myClass(int i) : i(i)");
-
- gen.GenerateDoc(new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 0)));
-
- assert.equal("/**\n * @brief \n * \n * @param i \n */",
- editor.editBuilder.text);
- });
-
- test("virtual ~myClass()", () => {
- const gen: IDocGen = setup("virtual ~myClass()");
-
- gen.GenerateDoc(new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 0)));
-
- assert.equal("/**\n * @brief \n * \n */",
- editor.editBuilder.text);
- });
-
- test("static inline unsigned int rewind_tospace(const unsigned char* chunk, unsigned int len)", () => {
- // tslint:disable-next-line:max-line-length
- const gen: IDocGen = setup("static inline unsigned int rewind_tospace(const unsigned char* chunk, unsigned int len)");
-
- gen.GenerateDoc(new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 0)));
-
- assert.equal("/**\n * @brief \n * \n * @param chunk \n * @param len \n * @return unsigned int \n */",
- editor.editBuilder.text);
- });
-
- test("void foo_bar(void (*my_function_pointer) (unsigned int arg1, char arg2))", () => {
- const gen: IDocGen = setup("void foo_bar(void (*my_function_pointer) (unsigned int arg1, char arg2))");
-
- gen.GenerateDoc(new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 0)));
-
- assert.equal("/**\n * @brief \n * \n * @param my_function_pointer \n */",
- editor.editBuilder.text);
- });
-
- test("int (*idputs(int (*puts)(const char *)))(const char *)", () => {
- const gen: IDocGen = setup("int (*idputs(int (*puts)(const char *)))(const char *)");
-
- gen.GenerateDoc(new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 0)));
-
- assert.equal("/**\n * @brief \n * \n * @param puts \n * @return int(*)(const char*) \n */",
- editor.editBuilder.text);
- });
-});
diff --git a/src/test/functionPointer.test.ts b/src/test/functionPointer.test.ts
new file mode 100644
index 0000000..3b6b857
--- /dev/null
+++ b/src/test/functionPointer.test.ts
@@ -0,0 +1,42 @@
+//
+// Note: This example test is leveraging the Mocha test framework.
+// Please refer to their documentation on https://mochajs.org/ for help.
+//
+
+// The module 'assert' provides assertion methods from node
+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 TestSetup from "./TestSetup";
+
+// Defines a Mocha test suite to group tests of similar kind together
+suite("Function pointer tests", () => {
+ const testSetup: TestSetup = new TestSetup("void foo();");
+
+ // Tests
+ test("function pointer return", () => {
+ const result = testSetup.SetMethod("int (*idputs(int a, int b))(char *);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param a \n * @param b \n * @return int(*)(char*) \n */", result);
+ });
+
+ test("nested function pointer return", () => {
+ const result = testSetup.SetMethod("int (*(*(*foo(int a, int b))(int))(double))(float);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param a \n * @param b \n"
+ + " * @return int(*(*(*)(int))(double))(float) \n */", result);
+ });
+
+ test("function pointer parameter", () => {
+ const result = testSetup.SetMethod("int foo(int (*puts)(const char *));").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param puts \n * @return int \n */", result);
+ });
+
+ test("struct function pointer return with struct FP parameter", () => {
+ const result = testSetup.SetMethod("struct foo (*idputs(int (*puts)(const char *), const"
+ + " struct test(*str)(int *, const struct test(*str2))))(const char *);").GetResult();
+
+ assert.equal("/**\n * @brief \n * \n * @param puts \n * @param str "
+ + "\n * @return struct foo(*)(const char*) \n */", result);
+ });
+});
diff --git a/src/test/simpleReturn.test.ts b/src/test/simpleReturn.test.ts
new file mode 100644
index 0000000..8f3e5d1
--- /dev/null
+++ b/src/test/simpleReturn.test.ts
@@ -0,0 +1,79 @@
+//
+// Note: This example test is leveraging the Mocha test framework.
+// Please refer to their documentation on https://mochajs.org/ for help.
+//
+
+// The module 'assert' provides assertion methods from node
+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 TestSetup from "./TestSetup";
+
+// Defines a Mocha test suite to group tests of similar kind together
+suite("Arguments tests", () => {
+
+ const testSetup: TestSetup = new TestSetup("void foo();");
+
+ // Tests
+ test("void return", () => {
+ const result = testSetup.SetMethod("void foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n */", result);
+ });
+
+ test("simple type return", () => {
+ const result = testSetup.SetMethod("int foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return int \n */", result);
+ });
+
+ test("bool return type", () => {
+ const result = testSetup.SetMethod("bool foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return true \n * @return false \n */", result);
+ });
+
+ test("pointer return type", () => {
+ const result = testSetup.SetMethod("int* foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return int* \n */", result);
+ });
+
+ test("bool pointer return type", () => {
+ const result = testSetup.SetMethod("bool* foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return true \n * @return false \n * @return null \n */", result);
+ });
+
+ test("Fundamental return type with modifiers", () => {
+ let result = testSetup.SetMethod("unsigned int foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return unsigned int \n */", result);
+
+ result = testSetup.SetMethod("unsigned short int foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return unsigned short int \n */", result);
+
+ result = testSetup.SetMethod("signed short foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return signed short \n */", result);
+
+ result = testSetup.SetMethod("long foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return long \n */", result);
+
+ result = testSetup.SetMethod("unsigned long long int foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return unsigned long long int \n */", result);
+
+ result = testSetup.SetMethod("signed foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return signed \n */", result);
+
+ result = testSetup.SetMethod("unsigned foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return unsigned \n */", result);
+
+ result = testSetup.SetMethod("unsigned char foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return unsigned char \n */", result);
+
+ result = testSetup.SetMethod("long double foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return long double \n */", result);
+ });
+
+ test("struct return type", () => {
+ const result = testSetup.SetMethod("struct my_struct foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return struct my_struct \n */", result);
+ });
+
+});