diff options
| author | Rowan Goemans <RB.Goemans@student.han.nl> | 2017-12-29 00:15:59 +0100 |
|---|---|---|
| committer | Christoph Schlosser <christophschlosser@users.noreply.github.com> | 2018-02-20 22:02:22 +0100 |
| commit | b446b9e596fc0487b88597d8e818dae61512f309 (patch) | |
| tree | c7ac9e158964dd88d4cc1839f5ed0da8acce3369 /src/test | |
| parent | 5b0912d99732536ae18d3c70730cc6df2ed3af24 (diff) | |
| download | doxdocgen-b446b9e596fc0487b88597d8e818dae61512f309.tar.gz | |
-- Added more unit tests.
-- Added support for alignas.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/Attributes.test.ts | 49 | ||||
| -rw-r--r-- | src/test/FunctionPointer.test.ts (renamed from src/test/functionPointer.test.ts) | 16 | ||||
| -rw-r--r-- | src/test/Operators.test.ts | 38 | ||||
| -rw-r--r-- | src/test/ReturnTypes.test.ts | 99 | ||||
| -rw-r--r-- | src/test/Templates.test.ts | 44 | ||||
| -rw-r--r-- | src/test/TrailingReturns.test.ts | 39 | ||||
| -rw-r--r-- | src/test/Variadic.test.ts | 38 | ||||
| -rw-r--r-- | src/test/simpleReturn.test.ts | 79 | ||||
| -rw-r--r-- | src/test/tools/MockDocument.ts (renamed from src/test/MockDocument.ts) | 0 | ||||
| -rw-r--r-- | src/test/tools/MockEditor.ts (renamed from src/test/MockEditor.ts) | 0 | ||||
| -rw-r--r-- | src/test/tools/MockLine.ts (renamed from src/test/MockLine.ts) | 0 | ||||
| -rw-r--r-- | src/test/tools/MockPosition.ts (renamed from src/test/MockPosition.ts) | 0 | ||||
| -rw-r--r-- | src/test/tools/MockSelection.ts (renamed from src/test/MockSelection.ts) | 0 | ||||
| -rw-r--r-- | src/test/tools/MockTextEditorEdit.ts (renamed from src/test/MockTextEditorEdit.ts) | 0 | ||||
| -rw-r--r-- | src/test/tools/TestSetup.ts (renamed from src/test/TestSetup.ts) | 12 |
15 files changed, 321 insertions, 93 deletions
diff --git a/src/test/Attributes.test.ts b/src/test/Attributes.test.ts new file mode 100644 index 0000000..680694a --- /dev/null +++ b/src/test/Attributes.test.ts @@ -0,0 +1,49 @@ +// +// 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/functionPointer.test.ts b/src/test/FunctionPointer.test.ts index 3b6b857..dd1ead0 100644 --- a/src/test/functionPointer.test.ts +++ b/src/test/FunctionPointer.test.ts @@ -9,34 +9,34 @@ 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"; +import TestSetup from "./tools/TestSetup"; // Defines a Mocha test suite to group tests of similar kind together -suite("Function pointer tests", () => { +suite("Function pointer Tests", () => { const testSetup: TestSetup = new TestSetup("void foo();"); // Tests test("function pointer return", () => { - const result = testSetup.SetMethod("int (*idputs(int a, int b))(char *);").GetResult(); + 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.SetMethod("int (*(*(*foo(int a, int b))(int))(double))(float);").GetResult(); + 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.SetMethod("int foo(int (*puts)(const char *));").GetResult(); + 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 parameter", () => { - const result = testSetup.SetMethod("struct foo (*idputs(int (*puts)(const char *), const" + 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 struct foo(*)(const char*) \n */", result); + + "\n * @return const struct foo(*)(const char*) \n */", result); }); }); diff --git a/src/test/Operators.test.ts b/src/test/Operators.test.ts new file mode 100644 index 0000000..86c04b2 --- /dev/null +++ b/src/test/Operators.test.ts @@ -0,0 +1,38 @@ +// +// 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 new file mode 100644 index 0000000..f38fb1f --- /dev/null +++ b/src/test/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 "./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 new file mode 100644 index 0000000..d4c0fe6 --- /dev/null +++ b/src/test/Templates.test.ts @@ -0,0 +1,44 @@ +// +// 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<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); + }); +}); diff --git a/src/test/TrailingReturns.test.ts b/src/test/TrailingReturns.test.ts new file mode 100644 index 0000000..6c182f9 --- /dev/null +++ b/src/test/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 "./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<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); + }); +}); diff --git a/src/test/Variadic.test.ts b/src/test/Variadic.test.ts new file mode 100644 index 0000000..2ded458 --- /dev/null +++ b/src/test/Variadic.test.ts @@ -0,0 +1,38 @@ +// +// 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/simpleReturn.test.ts b/src/test/simpleReturn.test.ts deleted file mode 100644 index 8f3e5d1..0000000 --- a/src/test/simpleReturn.test.ts +++ /dev/null @@ -1,79 +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 "./TestSetup"; - -// Defines a Mocha test suite to group tests of similar kind together -suite("Arguments tests", () => { - - const testSetup: TestSetup = new TestSetup("void foo();"); - - // Tests - test("void return", () => { - const result = testSetup.SetMethod("void foo();").GetResult(); - assert.equal("/**\n * @brief \n * \n */", result); - }); - - test("simple type return", () => { - const result = testSetup.SetMethod("int foo();").GetResult(); - assert.equal("/**\n * @brief \n * \n * @return int \n */", result); - }); - - test("bool return type", () => { - const result = testSetup.SetMethod("bool foo();").GetResult(); - assert.equal("/**\n * @brief \n * \n * @return true \n * @return false \n */", result); - }); - - test("pointer return type", () => { - const result = testSetup.SetMethod("int* foo();").GetResult(); - assert.equal("/**\n * @brief \n * \n * @return int* \n */", result); - }); - - test("bool pointer return type", () => { - const result = testSetup.SetMethod("bool* foo();").GetResult(); - assert.equal("/**\n * @brief \n * \n * @return true \n * @return false \n * @return null \n */", result); - }); - - test("Fundamental return type with modifiers", () => { - let result = testSetup.SetMethod("unsigned int foo();").GetResult(); - assert.equal("/**\n * @brief \n * \n * @return unsigned int \n */", result); - - result = testSetup.SetMethod("unsigned short int foo();").GetResult(); - assert.equal("/**\n * @brief \n * \n * @return unsigned short int \n */", result); - - result = testSetup.SetMethod("signed short foo();").GetResult(); - assert.equal("/**\n * @brief \n * \n * @return signed short \n */", result); - - result = testSetup.SetMethod("long foo();").GetResult(); - assert.equal("/**\n * @brief \n * \n * @return long \n */", result); - - result = testSetup.SetMethod("unsigned long long int foo();").GetResult(); - assert.equal("/**\n * @brief \n * \n * @return unsigned long long int \n */", result); - - result = testSetup.SetMethod("signed foo();").GetResult(); - assert.equal("/**\n * @brief \n * \n * @return signed \n */", result); - - result = testSetup.SetMethod("unsigned foo();").GetResult(); - assert.equal("/**\n * @brief \n * \n * @return unsigned \n */", result); - - result = testSetup.SetMethod("unsigned char foo();").GetResult(); - assert.equal("/**\n * @brief \n * \n * @return unsigned char \n */", result); - - result = testSetup.SetMethod("long double foo();").GetResult(); - assert.equal("/**\n * @brief \n * \n * @return long double \n */", result); - }); - - test("struct return type", () => { - const result = testSetup.SetMethod("struct my_struct foo();").GetResult(); - assert.equal("/**\n * @brief \n * \n * @return struct my_struct \n */", result); - }); - -}); diff --git a/src/test/MockDocument.ts b/src/test/tools/MockDocument.ts index cb6bbfe..cb6bbfe 100644 --- a/src/test/MockDocument.ts +++ b/src/test/tools/MockDocument.ts diff --git a/src/test/MockEditor.ts b/src/test/tools/MockEditor.ts index 5368fb8..5368fb8 100644 --- a/src/test/MockEditor.ts +++ b/src/test/tools/MockEditor.ts diff --git a/src/test/MockLine.ts b/src/test/tools/MockLine.ts index 7196a38..7196a38 100644 --- a/src/test/MockLine.ts +++ b/src/test/tools/MockLine.ts diff --git a/src/test/MockPosition.ts b/src/test/tools/MockPosition.ts index 0753670..0753670 100644 --- a/src/test/MockPosition.ts +++ b/src/test/tools/MockPosition.ts diff --git a/src/test/MockSelection.ts b/src/test/tools/MockSelection.ts index e72ff8b..e72ff8b 100644 --- a/src/test/MockSelection.ts +++ b/src/test/tools/MockSelection.ts diff --git a/src/test/MockTextEditorEdit.ts b/src/test/tools/MockTextEditorEdit.ts index e751182..e751182 100644 --- a/src/test/MockTextEditorEdit.ts +++ b/src/test/tools/MockTextEditorEdit.ts diff --git a/src/test/TestSetup.ts b/src/test/tools/TestSetup.ts index 2f4f64a..1270616 100644 --- a/src/test/TestSetup.ts +++ b/src/test/tools/TestSetup.ts @@ -1,8 +1,8 @@ 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 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"; @@ -13,10 +13,10 @@ export default class TestSetup { private editor: MockEditor; constructor(method: string) { - this.SetMethod(method); + this.SetLine(method); } - public SetMethod(method: string): TestSetup { + public SetLine(method: string): TestSetup { let position: MockPosition; position = new MockPosition(0, 0); |