summaryrefslogtreecommitdiffstats
path: root/src/test/CTests
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/CTests')
-rw-r--r--src/test/CTests/Attributes.test.ts62
-rw-r--r--src/test/CTests/FunctionPointer.test.ts42
-rw-r--r--src/test/CTests/Operators.test.ts256
-rw-r--r--src/test/CTests/ReturnTypes.test.ts99
-rw-r--r--src/test/CTests/Templates.test.ts51
-rw-r--r--src/test/CTests/TestSetup.ts52
-rw-r--r--src/test/CTests/TrailingReturns.test.ts39
7 files changed, 601 insertions, 0 deletions
diff --git a/src/test/CTests/Attributes.test.ts b/src/test/CTests/Attributes.test.ts
new file mode 100644
index 0000000..b4cffbb
--- /dev/null
+++ b/src/test/CTests/Attributes.test.ts
@@ -0,0 +1,62 @@
+//
+// 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("Attributes Tests", () => {
+ const testSetup: TestSetup = new TestSetup("void foo();");
+
+ // Tests
+ test("Attributes on parameter", () => {
+ const result = testSetup.SetLine("int foo([[maybe_unused]] int a, [[maybe_unused]]double& b);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param a \n * @param b \n * @return int \n */", result);
+ });
+
+ test("Attributes on function", () => {
+ const result = testSetup.SetLine("[[nodiscard]] int foo(int a, double& b);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param a \n * @param b \n * @return int \n */", result);
+ });
+
+ test("Multiple attributes on parameter", () => {
+ const result = testSetup.SetLine("int foo([[maybe_unused]] [[carries_dependency]]"
+ + " int a, double& b);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param a \n * @param b \n * @return int \n */", result);
+ });
+
+ test("Multiple attributes on function", () => {
+ const result = testSetup.SetLine("[[nodiscard]][[deprecated(\"old\")]] int foo(int a, double& b);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param a \n * @param b \n * @return int \n */", result);
+ });
+
+ test("Specifier and attribute on class", () => {
+ const result = testSetup.SetLine("class [[nodiscard]] alignas(8) Matrix {").GetResult();
+ assert.equal("/**\n * @brief \n * \n */", result);
+ });
+
+ test("Specifier and attribute on struct", () => {
+ const result = testSetup.SetLine("struct [[nodiscard]] alignas(8) Matrix {").GetResult();
+ assert.equal("/**\n * @brief \n * \n */", result);
+ });
+
+ test("Noexcept on function", () => {
+ let result = testSetup.SetLine("constexpr int foo(int a, double& b) noexcept(true);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param a \n * @param b \n * @return constexpr int \n */", result);
+
+ result = testSetup.SetLine("constexpr int foo(int a, double& b) noexcept;").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param a \n * @param b \n * @return constexpr int \n */", result);
+ });
+
+ test("Throw on function", () => {
+ const result = testSetup.SetLine("constexpr int foo(int a, double& b) throw(std::except);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param a \n * @param b \n * @return constexpr int \n */", result);
+ });
+});
diff --git a/src/test/CTests/FunctionPointer.test.ts b/src/test/CTests/FunctionPointer.test.ts
new file mode 100644
index 0000000..b5cd3bb
--- /dev/null
+++ b/src/test/CTests/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.SetLine("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.SetLine("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.SetLine("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 parameters and keywords", () => {
+ const result = testSetup.SetLine("const 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 const struct foo(*)(const char*) \n */", result);
+ });
+});
diff --git a/src/test/CTests/Operators.test.ts b/src/test/CTests/Operators.test.ts
new file mode 100644
index 0000000..dd2aa5b
--- /dev/null
+++ b/src/test/CTests/Operators.test.ts
@@ -0,0 +1,256 @@
+//
+// 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("Operators Tests", () => {
+ const testSetup: TestSetup = new TestSetup("void foo();");
+
+ // Tests
+ test("+ operator", () => {
+ const result = testSetup.SetLine("T operator +(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return T \n */", result);
+ });
+
+ test("- operator", () => {
+ const result = testSetup.SetLine("T operator- (const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return T \n */", result);
+ });
+
+ test("* operator", () => {
+ const result = testSetup.SetLine("T operator*(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return T \n */", result);
+ });
+
+ test("/ operator", () => {
+ const result = testSetup.SetLine("T operator/(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return T \n */", result);
+ });
+
+ test("% operator", () => {
+ const result = testSetup.SetLine("T operator%(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return T \n */", result);
+ });
+
+ test("^ operator", () => {
+ const result = testSetup.SetLine("T operator^(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return T \n */", result);
+ });
+
+ test("& operator", () => {
+ const result = testSetup.SetLine("T operator&(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return T \n */", result);
+ });
+
+ test("| operator", () => {
+ const result = testSetup.SetLine("T operator|(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return T \n */", result);
+ });
+
+ test("~ operator", () => {
+ const result = testSetup.SetLine("T operator~(const T& t);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param t \n * @return T \n */", result);
+ });
+
+ test("<< operator", () => {
+ const result = testSetup.SetLine("T operator<<(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return T \n */", result);
+ });
+
+ test(">> operator", () => {
+ const result = testSetup.SetLine("T operator>>(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return T \n */", result);
+ });
+
+ test("! operator", () => {
+ const result = testSetup.SetLine("bool operator!(const T& t);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param t \n * @return true \n * @return false \n */", result);
+ });
+
+ test("&& operator", () => {
+ const result = testSetup.SetLine("bool operator&&(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return true \n"
+ + " * @return false \n */", result);
+ });
+
+ test("|| operator", () => {
+ const result = testSetup.SetLine("bool operator||(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return true \n"
+ + " * @return false \n */", result);
+ });
+
+ test("!= operator", () => {
+ const result = testSetup.SetLine("bool operator!=(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return true \n"
+ + " * @return false \n */", result);
+ });
+
+ test("== operator", () => {
+ const result = testSetup.SetLine("bool operator==(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return true \n"
+ + " * @return false \n */", result);
+ });
+
+ test("<= operator", () => {
+ const result = testSetup.SetLine("bool operator<=(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return true \n"
+ + " * @return false \n */", result);
+ });
+
+ test(">= operator", () => {
+ const result = testSetup.SetLine("bool operator>=(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return true \n"
+ + " * @return false \n */", result);
+ });
+
+ test("< operator", () => {
+ const result = testSetup.SetLine("bool operator<(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return true \n"
+ + " * @return false \n */", result);
+ });
+
+ test("> operator", () => {
+ const result = testSetup.SetLine("bool operator>(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return true \n"
+ + " * @return false \n */", result);
+ });
+
+ test("= operator", () => {
+ const result = testSetup.SetLine("T& operator=(const T& t);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param t \n * @return T& \n */", result);
+ });
+
+ test("+= operator", () => {
+ const result = testSetup.SetLine("T& operator+=(const T& t);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param t \n * @return T& \n */", result);
+ });
+
+ test("-= operator", () => {
+ const result = testSetup.SetLine("T& operator-=(const T& t);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param t \n * @return T& \n */", result);
+ });
+
+ test("*= operator", () => {
+ const result = testSetup.SetLine("T& operator*=(const T& t);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param t \n * @return T& \n */", result);
+ });
+
+ test("/= operator", () => {
+ const result = testSetup.SetLine("T& operator/=(const T& t);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param t \n * @return T& \n */", result);
+ });
+
+ test("%= operator", () => {
+ const result = testSetup.SetLine("T& operator%=(const T& t);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param t \n * @return T& \n */", result);
+ });
+
+ test("^= operator", () => {
+ const result = testSetup.SetLine("T& operator^=(const T& t);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param t \n * @return T& \n */", result);
+ });
+
+ test("&= operator", () => {
+ const result = testSetup.SetLine("T& operator&=(const T& t);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param t \n * @return T& \n */", result);
+ });
+
+ test("|= operator", () => {
+ const result = testSetup.SetLine("T& operator|=(const T& t);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param t \n * @return T& \n */", result);
+ });
+
+ test(">>= operator", () => {
+ const result = testSetup.SetLine("T& operator>>=(const T& t);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param t \n * @return T& \n */", result);
+ });
+
+ test("<<= operator", () => {
+ const result = testSetup.SetLine("T& operator<<=(const T& t);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param t \n * @return T& \n */", result);
+ });
+
+ test("prefix ++ operator", () => {
+ const result = testSetup.SetLine("T& operator++();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return T& \n */", result);
+ });
+
+ test("prefix -- operator", () => {
+ const result = testSetup.SetLine("T& operator--();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return T& \n */", result);
+ });
+
+ test("postfix ++ operator", () => {
+ const result = testSetup.SetLine("T operator++(int);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return T \n */", result);
+ });
+
+ test("postfix -- operator", () => {
+ const result = testSetup.SetLine("T operator--(int);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return T \n */", result);
+ });
+
+ test(", operator", () => {
+ const result = testSetup.SetLine("T operator+(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return T \n */", result);
+ });
+
+ test("->* operator", () => {
+ const result = testSetup.SetLine("T operator+(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return T \n */", result);
+ });
+
+ test("-> operator", () => {
+ const result = testSetup.SetLine("T operator+(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return T \n */", result);
+ });
+
+ test("[] operator", () => {
+ const result = testSetup.SetLine("T operator+(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return T \n */", result);
+ });
+
+ test("() operator", () => {
+ const result = testSetup.SetLine("T operator+(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return T \n */", result);
+ });
+
+ test("new operator", () => {
+ const result = testSetup.SetLine("T operator+(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return T \n */", result);
+ });
+
+ test("new[] operator", () => {
+ const result = testSetup.SetLine("T operator+(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return T \n */", result);
+ });
+
+ test("delete operator", () => {
+ const result = testSetup.SetLine("T operator+(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return T \n */", result);
+ });
+
+ test("delete[] operator", () => {
+ const result = testSetup.SetLine("T operator+(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return T \n */", result);
+ });
+
+ test("user literal operator", () => {
+ const result = testSetup.SetLine("T operator+(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return T \n */", result);
+ });
+
+ test("conversion operator", () => {
+ const result = testSetup.SetLine("T operator+(const T& lhs, const T2& rhs);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param lhs \n * @param rhs \n * @return T \n */", result);
+ });
+});
diff --git a/src/test/CTests/ReturnTypes.test.ts b/src/test/CTests/ReturnTypes.test.ts
new file mode 100644
index 0000000..7d823d1
--- /dev/null
+++ b/src/test/CTests/ReturnTypes.test.ts
@@ -0,0 +1,99 @@
+//
+// 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("Return type Tests", () => {
+
+ const testSetup: TestSetup = new TestSetup("void foo();");
+
+ // Tests
+ test("Void return", () => {
+ const result = testSetup.SetLine("void foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n */", result);
+ });
+
+ test("Void pointer return", () => {
+ const result = testSetup.SetLine("void* foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return void* \n */", result);
+ });
+
+ test("Reference return", () => {
+ const result = testSetup.SetLine("int& foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return int& \n */", result);
+ });
+
+ test("Simple type return", () => {
+ const result = testSetup.SetLine("int foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return int \n */", result);
+ });
+
+ test("Bool return type", () => {
+ const result = testSetup.SetLine("bool foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return true \n * @return false \n */", result);
+ });
+
+ test("Pointer return type", () => {
+ const result = testSetup.SetLine("int* foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return int* \n */", result);
+ });
+
+ 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);
+ });
+
+ test("Struct pointer return type", () => {
+ const result = testSetup.SetLine("struct foo* foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return struct foo* \n */", result);
+ });
+
+ test("Struct return type", () => {
+ const result = testSetup.SetLine("struct Bar* foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return struct Bar* \n */", result);
+ });
+
+ test("Return type with keywords and noexcept", () => {
+ const result = testSetup.SetLine("static constexpr inline struct Bar* foo() "
+ + "const noexcept(false);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return constexpr struct Bar* \n */", result);
+ });
+
+ test("Fundamental return type with modifiers", () => {
+ let result = testSetup.SetLine("unsigned int foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return unsigned int \n */", result);
+
+ result = testSetup.SetLine("unsigned short int foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return unsigned short int \n */", result);
+
+ result = testSetup.SetLine("signed short foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return signed short \n */", result);
+
+ result = testSetup.SetLine("long foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return long \n */", result);
+
+ result = testSetup.SetLine("unsigned long long int foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return unsigned long long int \n */", result);
+
+ result = testSetup.SetLine("signed foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return signed \n */", result);
+
+ result = testSetup.SetLine("unsigned foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return unsigned \n */", result);
+
+ result = testSetup.SetLine("unsigned char foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return unsigned char \n */", result);
+
+ result = testSetup.SetLine("long double foo();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return long double \n */", result);
+ });
+});
diff --git a/src/test/CTests/Templates.test.ts b/src/test/CTests/Templates.test.ts
new file mode 100644
index 0000000..2fbd9b1
--- /dev/null
+++ b/src/test/CTests/Templates.test.ts
@@ -0,0 +1,51 @@
+//
+// 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("Template tests", () => {
+ const testSetup: TestSetup = new TestSetup("void foo();");
+
+ // Tests
+ test("Template class", () => {
+ const result = testSetup.SetLine("template<typename T, std::size_t M, std::size_t N,"
+ + "typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>"
+ + "class matrix {").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @tparam T \n * @tparam M \n * @tparam N \n * "
+ + "@tparam std::enable_if<std::is_arithmetic<T>::value, T>::type \n */", result);
+ });
+
+ test("Template function", () => {
+ const result = testSetup.SetLine("template<typename T, typename S>\nT f(T a, S b);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @tparam T \n * @tparam S \n * @param a \n * "
+ + "@param b \n * @return T \n */", result);
+ });
+
+ test("Double template", () => {
+ const result = testSetup.SetLine("template<typename T>\ntemplate<typename S>\nT f(T a, S b);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @tparam T \n * @tparam S \n * @param a \n * "
+ + "@param b \n * @return T \n */", result);
+ });
+
+ test("Template struct", () => {
+ const result = testSetup.SetLine("template<typename T, std::size_t m, std::size_t n>\n"
+ + "struct myStruct {").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @tparam T \n * @tparam m \n * @tparam n \n */", result);
+ });
+
+ test("Variadic template", () => {
+ const result = testSetup.SetLine("template<typename T, typename... Args>"
+ + "\nT adder(T first, Args... args);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @tparam T \n * @tparam Args \n *"
+ + " @param first \n * @param args \n * @return T \n */", result);
+ });
+});
diff --git a/src/test/CTests/TestSetup.ts b/src/test/CTests/TestSetup.ts
new file mode 100644
index 0000000..1eb9c86
--- /dev/null
+++ b/src/test/CTests/TestSetup.ts
@@ -0,0 +1,52 @@
+import * as vscode from "vscode";
+
+import CodeParser from "../../Common/ICodeParser";
+import { IDocGen } from "../../Common/IDocGen";
+import { Config } from "../../Config";
+import * as myExtension from "../../extension";
+import CParser from "../../Lang/C/CParser";
+import MockDocument from "../tools/MockDocument";
+import MockEditor from "../tools/MockEditor";
+import MockLine from "../tools/MockLine";
+import MockPosition from "../tools/MockPosition";
+import MockSelection from "../tools/MockSelection";
+
+export default class TestSetup {
+ public cfg: Config;
+
+ private editor: MockEditor;
+
+ constructor(method: string) {
+ this.SetLine(method);
+ }
+
+ public SetLine(method: string): TestSetup {
+ this.cfg = new Config();
+
+ 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(new Config());
+
+ 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/CTests/TrailingReturns.test.ts b/src/test/CTests/TrailingReturns.test.ts
new file mode 100644
index 0000000..8ad5799
--- /dev/null
+++ b/src/test/CTests/TrailingReturns.test.ts
@@ -0,0 +1,39 @@
+//
+// 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("Trailing returns tests", () => {
+ const testSetup: TestSetup = new TestSetup("void foo();");
+
+ // tests
+ test("Trailing return", () => {
+ const result = testSetup.SetLine("auto foo() -> int;").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return int \n */", result);
+ });
+
+ test("Trailing return with decltype", () => {
+ const result = testSetup.SetLine("auto foo(int a, double b) -> decltype(a + b);").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param a \n * @param b \n * @return decltype(a + b) \n */", result);
+ });
+
+ test("Multiple trailing returns", () => {
+ const result = testSetup.SetLine("auto foo() -> auto(*)() -> tmp<int>(*)();").GetResult();
+ assert.equal("/**\n * @brief \n * \n * @return auto(*)() -> tmp<int>(*)() \n */", result);
+ });
+
+ test("Trailing return with keywords", () => {
+ const result = testSetup.SetLine("auto foo(const int& a, const double* b) const noexcept -> const double&;")
+ .GetResult();
+ assert.equal("/**\n * @brief \n * \n * @param a \n * @param b \n * @return const double& \n */", result);
+ });
+});