From 2af50bd62c2e26975a46b499c1c687be42be80a1 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser <2466365+cschlosser@users.noreply.github.com> Date: Sat, 3 Oct 2020 16:50:43 +0200 Subject: Fix default value in tparams (#172) --- CHANGELOG.md | 6 ++++++ package.json | 2 +- src/Lang/Cpp/CppParser.ts | 3 +++ src/test/CppTests/Templates.test.ts | 7 +++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59a8401..d1c6992 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## [UNRELEASED] + +### Fix + +- Incorrect parameter name of template (#170) + ## [0.7.2] ### Fix diff --git a/package.json b/package.json index bf7ecd3..ec2301a 100644 --- a/package.json +++ b/package.json @@ -254,7 +254,7 @@ }, "devDependencies": { "@types/mocha": "^5.2.7", - "@types/node": "^12.7.1", + "@types/node": "12.7.1", "decache": "^4.5.1", "handlebars": "^4.7.3", "istanbul": "^0.4.5", diff --git a/src/Lang/Cpp/CppParser.ts b/src/Lang/Cpp/CppParser.ts index 0fef5dc..8ed4bc8 100644 --- a/src/Lang/Cpp/CppParser.ts +++ b/src/Lang/Cpp/CppParser.ts @@ -808,6 +808,9 @@ export default class CppParser implements ICodeParser { // Remove <> and add a comma to the end to remove edge case. template = template.slice(template.indexOf("<") + 1, template.lastIndexOf(">")).replace(/^\s+|\s+$/g, "") + ","; + // Remove = and everything to the right until a , comes up + template = template.replace(/(\W*=\W*\S*\,)/gm, ","); + const nestedCounts: { [key: string]: number; } = { "(": 0, "<": 0, diff --git a/src/test/CppTests/Templates.test.ts b/src/test/CppTests/Templates.test.ts index 07a2144..0c4e1b6 100644 --- a/src/test/CppTests/Templates.test.ts +++ b/src/test/CppTests/Templates.test.ts @@ -48,4 +48,11 @@ suite("C++ - Template tests", () => { assert.equal("/**\n * @brief \n * \n * @tparam T \n * @tparam Args \n *" + " @param first \n * @param args \n * @return T \n */", result); }); + + test("Default template param value", () => { + const result = testSetup.SetLine("template " + + "\nstruct Foo;").GetResult(); + assert.equal("/**\n * @brief \n * \n * @tparam is_foo \n * @tparam is_bar \n *" + + " @tparam is_nothrow \n */", result); + }); }); -- cgit v1.2.3