From 16e4ed410f2bc29e528bf6ec872bdf92478749a7 Mon Sep 17 00:00:00 2001 From: Rowan Goemans Date: Sun, 31 Dec 2017 02:54:54 +0100 Subject: -- 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. --- package.json | 5 --- src/Config.ts | 3 +- src/Lang/C/CDocGen.ts | 17 +++------ src/Lang/C/CParser.ts | 2 +- src/test/CTests/Con-AndDestructor.test.ts | 63 +++++++++++++++++++++++++++++++ src/test/CTests/ReturnTypes.test.ts | 2 +- 6 files changed, 72 insertions(+), 20 deletions(-) create mode 100644 src/test/CTests/Con-AndDestructor.test.ts diff --git a/package.json b/package.json index 67b83b8..20e5ab5 100644 --- a/package.json +++ b/package.json @@ -64,11 +64,6 @@ "type": "boolean", "default": true }, - "doxdocgen.generic.boolPointerReturnsNull": { - "description": "If this is enabled a pointer to a bool return value will include a null return param.", - "type": "boolean", - "default": true - }, "doxdocgen.generic.briefTemplate": { "description": "The template of the brief DoxyGen line that is generated. If empty it won't get generated at all.", "type": "string", 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("triggerSequence", values.triggerSequence); values.firstLine = cfg.get("firstLine", values.firstLine); values.commentPrefix = cfg.get("commentPrefix", values.commentPrefix); values.lastLine = cfg.get("lastLine", values.lastLine); @@ -14,7 +15,6 @@ export class Config { values.newLineAfterTParams = cfg.get("newLineAfterTParams", values.newLineAfterTParams); values.includeTypeAtReturn = cfg.get("includeTypeAtReturn", values.includeTypeAtReturn); values.boolReturnsTrueFalse = cfg.get("boolReturnsTrueFalse", values.boolReturnsTrueFalse); - values.boolPointerReturnsNull = cfg.get("boolPointerReturnsNull", values.boolPointerReturnsNull); values.briefTemplate = cfg.get("briefTemplate", values.briefTemplate); values.paramTemplate = cfg.get("paramTemplate", values.paramTemplate); values.tparamTemplate = cfg.get("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", () => { -- cgit v1.2.3