From 1746f21bc3720585d2fe877db8d69aae301ff02c Mon Sep 17 00:00:00 2001 From: Rowan Goemans Date: Sun, 31 Dec 2017 02:03:08 +0100 Subject: -- Added many unit tests for the C parser. Almost complete now -- Refactored project structure to allow for more overview once we add more languages. -- Renamed a lot of types in the CParser to be more explicit. -- Made configuration injectable into the classes that need them. This allows to unit test configuration variables. -- Added 2 new config params that allows to customize what gets returned for a bool return type. -- Small changes to the logic to make it more concise. --- src/test/Attributes.test.ts | 49 ------ src/test/CTests/Attributes.test.ts | 62 ++++++++ src/test/CTests/FunctionPointer.test.ts | 42 ++++++ src/test/CTests/Operators.test.ts | 256 ++++++++++++++++++++++++++++++++ src/test/CTests/ReturnTypes.test.ts | 99 ++++++++++++ src/test/CTests/Templates.test.ts | 51 +++++++ src/test/CTests/TestSetup.ts | 52 +++++++ src/test/CTests/TrailingReturns.test.ts | 39 +++++ src/test/FunctionPointer.test.ts | 42 ------ src/test/Operators.test.ts | 38 ----- src/test/ReturnTypes.test.ts | 99 ------------ src/test/Templates.test.ts | 44 ------ src/test/TrailingReturns.test.ts | 39 ----- src/test/Variadic.test.ts | 38 ----- src/test/tools/TestSetup.ts | 46 ------ 15 files changed, 601 insertions(+), 395 deletions(-) delete mode 100644 src/test/Attributes.test.ts create mode 100644 src/test/CTests/Attributes.test.ts create mode 100644 src/test/CTests/FunctionPointer.test.ts create mode 100644 src/test/CTests/Operators.test.ts create mode 100644 src/test/CTests/ReturnTypes.test.ts create mode 100644 src/test/CTests/Templates.test.ts create mode 100644 src/test/CTests/TestSetup.ts create mode 100644 src/test/CTests/TrailingReturns.test.ts delete mode 100644 src/test/FunctionPointer.test.ts delete mode 100644 src/test/Operators.test.ts delete mode 100644 src/test/ReturnTypes.test.ts delete mode 100644 src/test/Templates.test.ts delete mode 100644 src/test/TrailingReturns.test.ts delete mode 100644 src/test/Variadic.test.ts delete mode 100644 src/test/tools/TestSetup.ts (limited to 'src/test') diff --git a/src/test/Attributes.test.ts b/src/test/Attributes.test.ts deleted file mode 100644 index 680694a..0000000 --- a/src/test/Attributes.test.ts +++ /dev/null @@ -1,49 +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 "./tools/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); - }); -}); 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::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::value, T>::type \n */", result); + }); + + test("Template function", () => { + const result = testSetup.SetLine("template\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\ntemplate\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\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" + + "\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(*)();").GetResult(); + assert.equal("/**\n * @brief \n * \n * @return auto(*)() -> tmp(*)() \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); + }); +}); diff --git a/src/test/FunctionPointer.test.ts b/src/test/FunctionPointer.test.ts deleted file mode 100644 index dd1ead0..0000000 --- a/src/test/FunctionPointer.test.ts +++ /dev/null @@ -1,42 +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 "./tools/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/Operators.test.ts b/src/test/Operators.test.ts deleted file mode 100644 index 86c04b2..0000000 --- a/src/test/Operators.test.ts +++ /dev/null @@ -1,38 +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 "./tools/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("", () => { - const result = testSetup.SetLine("").GetResult(); - assert.equal("", result); - }); - - test("", () => { - const result = testSetup.SetLine("").GetResult(); - assert.equal("", result); - }); - - test("", () => { - const result = testSetup.SetLine("").GetResult(); - assert.equal("", result); - }); - - test("", () => { - const result = testSetup.SetLine("").GetResult(); - assert.equal("", result); - }); -}); diff --git a/src/test/ReturnTypes.test.ts b/src/test/ReturnTypes.test.ts deleted file mode 100644 index f38fb1f..0000000 --- a/src/test/ReturnTypes.test.ts +++ /dev/null @@ -1,99 +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 "./tools/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/Templates.test.ts b/src/test/Templates.test.ts deleted file mode 100644 index d4c0fe6..0000000 --- a/src/test/Templates.test.ts +++ /dev/null @@ -1,44 +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 "./tools/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::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::value, T>::type \n */", result); - }); - - test("template function", () => { - const result = testSetup.SetLine("template\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\ntemplate\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\n" - + "struct myStruct {").GetResult(); - assert.equal("/**\n * @brief \n * \n * @tparam T \n * @tparam m \n * @tparam n \n */", result); - }); -}); diff --git a/src/test/TrailingReturns.test.ts b/src/test/TrailingReturns.test.ts deleted file mode 100644 index 6c182f9..0000000 --- a/src/test/TrailingReturns.test.ts +++ /dev/null @@ -1,39 +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 "./tools/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(*)();").GetResult(); - assert.equal("/**\n * @brief \n * \n * @return auto(*)() -> tmp(*)() \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); - }); -}); diff --git a/src/test/Variadic.test.ts b/src/test/Variadic.test.ts deleted file mode 100644 index 2ded458..0000000 --- a/src/test/Variadic.test.ts +++ /dev/null @@ -1,38 +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 "./tools/TestSetup"; - -// Defines a Mocha test suite to group tests of similar kind together -suite("Variadic tests", () => { - const testSetup: TestSetup = new TestSetup("void foo();"); - - // Tests - test("", () => { - const result = testSetup.SetLine("").GetResult(); - assert.equal("", result); - }); - - test("", () => { - const result = testSetup.SetLine("").GetResult(); - assert.equal("", result); - }); - - test("", () => { - const result = testSetup.SetLine("").GetResult(); - assert.equal("", result); - }); - - test("", () => { - const result = testSetup.SetLine("").GetResult(); - assert.equal("", result); - }); -}); diff --git a/src/test/tools/TestSetup.ts b/src/test/tools/TestSetup.ts deleted file mode 100644 index 1270616..0000000 --- a/src/test/tools/TestSetup.ts +++ /dev/null @@ -1,46 +0,0 @@ -import * as vscode from "vscode"; -import CodeParser from "../../CodeParser/CodeParser"; -import CParser from "../../CodeParser/CParser/CParser"; -import { IDocGen } from "../../DocGen/DocGen"; -import * as myExtension from "../../extension"; -import MockDocument from "./MockDocument"; -import MockEditor from "./MockEditor"; -import MockLine from "./MockLine"; -import MockPosition from "./MockPosition"; -import MockSelection from "./MockSelection"; - -export default class TestSetup { - private editor: MockEditor; - - constructor(method: string) { - this.SetLine(method); - } - - public SetLine(method: string): TestSetup { - 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(); - - 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; - } -} -- cgit v1.2.3