summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRowan Goemans <RB.Goemans@student.han.nl>2018-01-01 21:22:18 +0100
committerChristoph Schlosser <christophschlosser@users.noreply.github.com>2018-02-20 22:02:22 +0100
commit8711b0fb2c8f88a6864096de7813e63fd6cf9f7a (patch)
tree212fd2fb67cfd2f778e42ae955f869bc444afdb2
parentd9cef62f8778fcdc39d26802d5d7457c97e9dfc0 (diff)
downloaddoxdocgen-8711b0fb2c8f88a6864096de7813e63fd6cf9f7a.tar.gz
-- Added tests for the configuration options.
-- Expanded the mock classes to allow for more dynamic setting of the contents.
-rw-r--r--src/Lang/Cpp/CppDocGen.ts7
-rw-r--r--src/test/CppTests/Config.test.ts83
-rw-r--r--src/test/CppTests/Config.tests.ts19
-rw-r--r--src/test/CppTests/TestSetup.ts26
-rw-r--r--src/test/tools/MockDocument.ts15
5 files changed, 109 insertions, 41 deletions
diff --git a/src/Lang/Cpp/CppDocGen.ts b/src/Lang/Cpp/CppDocGen.ts
index e715583..b98abea 100644
--- a/src/Lang/Cpp/CppDocGen.ts
+++ b/src/Lang/Cpp/CppDocGen.ts
@@ -55,8 +55,7 @@ export default class CppDocGen implements IDocGen {
Implementation
***************************************************************************/
protected getIndentation(): string {
- const line: TextLine = this.activeEditor.document.lineAt(this.activeEditor.selection.start.line);
- return line.text.slice(0, line.firstNonWhitespaceCharacterIndex - 1);
+ return this.activeEditor.document.lineAt(this.activeEditor.selection.start.line).text.match("^\\s*")[0];
}
protected getTemplatedString(replace: string, template: string, param: string): string {
@@ -81,6 +80,10 @@ export default class CppDocGen implements IDocGen {
}
protected generateReturnParams(): string[] {
+ if (this.cfg.includeTypeAtReturn === false) {
+ return [""];
+ }
+
const params: string[] = [];
// Check if return type is a pointer
diff --git a/src/test/CppTests/Config.test.ts b/src/test/CppTests/Config.test.ts
new file mode 100644
index 0000000..d33b5c1
--- /dev/null
+++ b/src/test/CppTests/Config.test.ts
@@ -0,0 +1,83 @@
+//
+// 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 { Config } from "../../Config";
+import TestSetup from "./TestSetup";
+
+// Defines a Mocha test suite to group tests of similar kind together
+suite("C++ - Configuration Tests", () => {
+ const testSetup: TestSetup = new TestSetup("void foo();");
+
+ // Tests
+ test("Default config", () => {
+ testSetup.cfg = new Config();
+ const result = testSetup.SetLine("template<typename T> bool foo(T a);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @tparam T \n * @param a \n * "
+ + "@return true \n * @return false \n */", result);
+ });
+
+ test("Modified template", () => {
+ testSetup.cfg = new Config();
+
+ testSetup.cfg.firstLine = "";
+ testSetup.cfg.lastLine = "";
+ testSetup.cfg.commentPrefix = "/// ";
+ testSetup.cfg.briefTemplate = "\\brief ";
+ testSetup.cfg.paramTemplate = "\\param {param} ";
+ testSetup.cfg.tparamTemplate = "\\tparam {param} ";
+ testSetup.cfg.returnTemplate = "\\return {type} ";
+
+ const result = testSetup.SetLine("template<typename T> bool foo(T a);").GetResult();
+ assert.equal("/// \\brief \n/// \n/// \\tparam T \n/// \\param a \n"
+ + "/// \\return true \n/// \\return false ", result);
+
+ });
+
+ test("Disable true false on bool", () => {
+ testSetup.cfg = new Config();
+ testSetup.cfg.boolReturnsTrueFalse = false;
+ const result = testSetup.SetLine("template<typename T> bool foo(T a);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @tparam T \n * @param a \n"
+ + " * @return bool \n */", result);
+ });
+
+ test("Disable including return type.", () => {
+ testSetup.cfg = new Config();
+ testSetup.cfg.includeTypeAtReturn = false;
+
+ const result = testSetup.SetLine("template<typename T> bool foo(T a);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @tparam T \n * @param a \n"
+ + " * @return \n */", result);
+ });
+
+ test("Newlines after params and tparams but not after brief", () => {
+ testSetup.cfg = new Config();
+ testSetup.cfg.newLineAfterBrief = false;
+ testSetup.cfg.newLineAfterParams = true;
+ testSetup.cfg.newLineAfterTParams = true;
+
+ const result = testSetup.SetLine("template<typename T> bool foo(T a);").GetResult();
+ assert.equal("/**\n * @brief \n * @tparam T \n * \n * @param a \n * \n"
+ + " * @return true \n * @return false \n */", result);
+ });
+
+ test("Indentation test", () => {
+ testSetup.cfg = new Config();
+ let result = testSetup.SetLine("\ttemplate<typename T> bool foo(T a);").GetResult();
+ assert.equal("/**\n\t * @brief \n\t * \n\t * @tparam T \n\t * @param a \n\t * "
+ + "@return true \n\t * @return false \n\t */", result);
+
+ result = testSetup.SetLine(" template<typename T> bool foo(T a);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @tparam T "
+ + "\n * @param a \n * "
+ + "@return true \n * @return false \n */", result);
+ });
+});
diff --git a/src/test/CppTests/Config.tests.ts b/src/test/CppTests/Config.tests.ts
deleted file mode 100644
index 0143341..0000000
--- a/src/test/CppTests/Config.tests.ts
+++ /dev/null
@@ -1,19 +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 TestSetup from "./TestSetup";
-
-// Defines a Mocha test suite to group tests of similar kind together
-suite("C++ - Configuration Tests", () => {
- const testSetup: TestSetup = new TestSetup("void foo();");
-
- // Tests
-});
diff --git a/src/test/CppTests/TestSetup.ts b/src/test/CppTests/TestSetup.ts
index 068cff2..ee7256d 100644
--- a/src/test/CppTests/TestSetup.ts
+++ b/src/test/CppTests/TestSetup.ts
@@ -17,23 +17,29 @@ export default class TestSetup {
private editor: MockEditor;
constructor(method: string) {
+ this.cfg = new Config();
this.SetLine(method);
}
public SetLine(method: string): TestSetup {
- this.cfg = new Config();
+ return this.SetLines([method]);
+ }
- let position: MockPosition;
- position = new MockPosition(0, 0);
+ public SetLines(lines: string[]): TestSetup {
+ let mockLines: MockLine[];
- let selection: MockSelection;
- selection = new MockSelection(position);
+ // Add two empty lines with just the indentation
+ // since one is for the triggersequence line.
+ // And the other is if the next empty line.
+ if (lines.length > 0) {
+ const indent: string = lines[0].match("^\\s*")[0];
- let line: MockLine;
- line = new MockLine(method);
+ mockLines = [indent, indent].concat(lines)
+ .map((l) => new MockLine(l));
+ }
- let doc: MockDocument;
- doc = new MockDocument(line);
+ const selection: MockSelection = new MockSelection(new MockPosition(0, 0));
+ const doc: MockDocument = new MockDocument(mockLines);
this.editor = new MockEditor(selection, doc);
@@ -42,7 +48,7 @@ export default class TestSetup {
public GetResult(): string {
let parser: CodeParser;
- parser = new CppParser(new Config());
+ parser = new CppParser(this.cfg);
const gen: IDocGen = parser.Parse(this.editor);
gen.GenerateDoc(new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 0)));
diff --git a/src/test/tools/MockDocument.ts b/src/test/tools/MockDocument.ts
index cb6bbfe..781dbfe 100644
--- a/src/test/tools/MockDocument.ts
+++ b/src/test/tools/MockDocument.ts
@@ -11,24 +11,19 @@ export default class MockDocument implements vscode.TextDocument {
public isClosed: boolean;
public eol: vscode.EndOfLine;
public lineCount: number;
- private line: vscode.TextLine;
- private callCount: number;
- public constructor(line: vscode.TextLine) {
- this.line = line;
- this.callCount = 0;
+ private lines: vscode.TextLine[];
+ public constructor(lines: vscode.TextLine[]) {
+ this.lines = lines;
}
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.callCount === 1) {
- return new MockLine("");
- } else if (this.callCount === 2) {
- return this.line;
- } else {
+ if (position >= this.lines.length) {
return new MockLine(";");
}
+ return this.lines[position];
}
public offsetAt(position: vscode.Position): number {
throw new Error("Method not implemented.");