summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRowan Goemans <RB.Goemans@student.han.nl>2017-12-31 02:54:54 +0100
committerChristoph Schlosser <christophschlosser@users.noreply.github.com>2018-02-20 22:02:22 +0100
commit16e4ed410f2bc29e528bf6ec872bdf92478749a7 (patch)
tree9f9a661c150460de78fc8f88796158d2cb32f362 /src
parent1746f21bc3720585d2fe877db8d69aae301ff02c (diff)
downloaddoxdocgen-16e4ed410f2bc29e528bf6ec872bdf92478749a7.tar.gz
-- Added test for constructors and destructors.
-- Removed config value for null on bool pointer return. I think it's to confusing for users. -- Fixed some small remaining refactor bugs.
Diffstat (limited to 'src')
-rw-r--r--src/Config.ts3
-rw-r--r--src/Lang/C/CDocGen.ts17
-rw-r--r--src/Lang/C/CParser.ts2
-rw-r--r--src/test/CTests/Con-AndDestructor.test.ts63
-rw-r--r--src/test/CTests/ReturnTypes.test.ts2
5 files changed, 72 insertions, 15 deletions
diff --git a/src/Config.ts b/src/Config.ts
index 6297a66..cce8f72 100644
--- a/src/Config.ts
+++ b/src/Config.ts
@@ -6,6 +6,7 @@ export class Config {
const cfg = workspace.getConfiguration("doxdocgen.generic");
+ values.triggerSequence = cfg.get<string>("triggerSequence", values.triggerSequence);
values.firstLine = cfg.get<string>("firstLine", values.firstLine);
values.commentPrefix = cfg.get<string>("commentPrefix", values.commentPrefix);
values.lastLine = cfg.get<string>("lastLine", values.lastLine);
@@ -14,7 +15,6 @@ export class Config {
values.newLineAfterTParams = cfg.get<boolean>("newLineAfterTParams", values.newLineAfterTParams);
values.includeTypeAtReturn = cfg.get<boolean>("includeTypeAtReturn", values.includeTypeAtReturn);
values.boolReturnsTrueFalse = cfg.get<boolean>("boolReturnsTrueFalse", values.boolReturnsTrueFalse);
- values.boolPointerReturnsNull = cfg.get<boolean>("boolPointerReturnsNull", values.boolPointerReturnsNull);
values.briefTemplate = cfg.get<string>("briefTemplate", values.briefTemplate);
values.paramTemplate = cfg.get<string>("paramTemplate", values.paramTemplate);
values.tparamTemplate = cfg.get<string>("tparamTemplate", values.tparamTemplate);
@@ -35,7 +35,6 @@ export class Config {
public newLineAfterTParams: boolean = false;
public includeTypeAtReturn: boolean = true;
public boolReturnsTrueFalse: boolean = true;
- public boolPointerReturnsNull: boolean = true;
public briefTemplate: string = "@brief ";
public paramTemplate: string = "@param {param} ";
public tparamTemplate: string = "@tparam {param} ";
diff --git a/src/Lang/C/CDocGen.ts b/src/Lang/C/CDocGen.ts
index 87d59fb..5488020 100644
--- a/src/Lang/C/CDocGen.ts
+++ b/src/Lang/C/CDocGen.ts
@@ -56,7 +56,7 @@ export default class CDocGen implements IDocGen {
***************************************************************************/
protected getIndentation(): string {
const line: TextLine = this.activeEditor.document.lineAt(this.activeEditor.selection.start.line);
- return line.text.slice(0, line.firstNonWhitespaceCharacterIndex);
+ return line.text.slice(0, line.firstNonWhitespaceCharacterIndex - 1);
}
protected getTemplatedString(replace: string, template: string, param: string): string {
@@ -72,7 +72,7 @@ export default class CDocGen implements IDocGen {
templateWith.forEach((element: string) => {
// Ignore null values
- if (element !== null && element !== undefined && element !== "") {
+ if (element !== null) {
line = this.cfg.commentPrefix;
line += this.getTemplatedString(replace, template, element);
lines.push(line);
@@ -95,14 +95,9 @@ export default class CDocGen implements IDocGen {
const boolReturnIndex: number = this.func.type.nodes
.findIndex((n) => n instanceof CToken && n.type === CTokenType.Symbol && n.value === "bool");
- if (boolReturnIndex !== -1) {
- if (this.cfg.boolReturnsTrueFalse === true) {
- params.push("true");
- params.push("false");
- }
- if (ptrReturnIndex !== -1 && this.cfg.boolPointerReturnsNull === true) {
- params.push("null");
- }
+ if (boolReturnIndex !== -1 && this.cfg.boolReturnsTrueFalse === true) {
+ params.push("true");
+ params.push("false");
} else if (voidReturnIndex !== -1 && ptrReturnIndex !== -1) {
params.push(this.cfg.includeTypeAtReturn === true ? this.func.type.Yield() : "");
} else if (voidReturnIndex === -1 && this.func.type.nodes.length > 0) {
@@ -130,7 +125,7 @@ export default class CDocGen implements IDocGen {
this.generateFromTemplate(
lines,
this.cfg.paramTemplateReplace,
- this.cfg.paramTemplate,
+ this.cfg.tparamTemplate,
this.templateParams,
);
if (this.cfg.newLineAfterTParams === true) {
diff --git a/src/Lang/C/CParser.ts b/src/Lang/C/CParser.ts
index 6d3d85b..859dc6b 100644
--- a/src/Lang/C/CParser.ts
+++ b/src/Lang/C/CParser.ts
@@ -297,7 +297,7 @@ export default class CParser implements ICodeParser {
const func = this.GetArgument(tree);
// check if it is a constructor or descructor since these have no name..
// and reverse the assignment of type and name.
- if (func.name === undefined) {
+ if (func.name === null) {
if (func.type.nodes.length !== 1) {
throw new Error("Too many symbols found for constructor/descructor.");
} else if (func.type.nodes[0] instanceof CParseTree) {
diff --git a/src/test/CTests/Con-AndDestructor.test.ts b/src/test/CTests/Con-AndDestructor.test.ts
new file mode 100644
index 0000000..f1663dd
--- /dev/null
+++ b/src/test/CTests/Con-AndDestructor.test.ts
@@ -0,0 +1,63 @@
+//
+// 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("Con- and Destructor Tests", () => {
+ const testSetup: TestSetup = new TestSetup("void foo();");
+
+ // Tests
+ test("Normal Constructor", () => {
+ const result = testSetup.SetLine("Foo(int a);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param a \n */", result);
+ });
+
+ test("Constructor with initializer list", () => {
+ const result = testSetup.SetLine("Foo(int a) : m_a(a) {").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param a \n */", result);
+ });
+
+ test("Explicit Constructor", () => {
+ const result = testSetup.SetLine("explicit Foo(int a);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param a \n */", result);
+ });
+
+ test("Deleted Constructor", () => {
+ const result = testSetup.SetLine("Foo(int a) = delete;").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param a \n */", result);
+ });
+
+ test("Default Constructor", () => {
+ const result = testSetup.SetLine("Foo() = default;").GetResult();
+ assert.equal("/**\n * @brief \n * \n */", result);
+ });
+
+ test("Destructor", () => {
+ const result = testSetup.SetLine("~Foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n */", result);
+ });
+
+ test("Virtual Destructor", () => {
+ const result = testSetup.SetLine("virtual ~Foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n */", result);
+ });
+
+ test("Deleted Destructor", () => {
+ const result = testSetup.SetLine("virtual ~Foo() = 0").GetResult();
+ assert.equal("/**\n * @brief \n * \n */", result);
+ });
+
+ test("Default Destructor", () => {
+ const result = testSetup.SetLine("~Foo() = default;").GetResult();
+ assert.equal("/**\n * @brief \n * \n */", result);
+ });
+});
diff --git a/src/test/CTests/ReturnTypes.test.ts b/src/test/CTests/ReturnTypes.test.ts
index 7d823d1..81a99c6 100644
--- a/src/test/CTests/ReturnTypes.test.ts
+++ b/src/test/CTests/ReturnTypes.test.ts
@@ -49,7 +49,7 @@ suite("Return type Tests", () => {
test("Bool pointer return type", () => {
const result = testSetup.SetLine("bool* foo();").GetResult();
- assert.equal("/**\n * @brief \n * \n * @return true \n * @return false \n * @return null \n */", result);
+ assert.equal("/**\n * @brief \n * \n * @return true \n * @return false \n */", result);
});
test("Struct pointer return type", () => {