diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c69d4fd59..ad46be186 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -15,6 +15,9 @@ set(AVAILABLE_TESTS FailingAssert Bitfields Math + RValues + Namespaces + ExtraSemicolon ) diff --git a/tests/include/test_patterns/test_pattern_extra_semicolon.hpp b/tests/include/test_patterns/test_pattern_extra_semicolon.hpp new file mode 100644 index 000000000..e58a8c605 --- /dev/null +++ b/tests/include/test_patterns/test_pattern_extra_semicolon.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include "test_pattern.hpp" + +namespace hex::test { + + class TestPatternExtraSemicolon : public TestPattern { + public: + TestPatternExtraSemicolon() : TestPattern("ExtraSemicolon") { + + } + ~TestPatternExtraSemicolon() override = default; + + [[nodiscard]] + std::string getSourceCode() const override { + return R"( + struct Test { + u32 x;;; + u8 y; + float z;; + };; + + struct Test2 { + u32 x; + u32 y; + }; + + Test test @ 0x00;;; + Test test2 @ 0x10; + )"; + } + + }; + +} \ No newline at end of file diff --git a/tests/include/test_patterns/test_pattern_math.hpp b/tests/include/test_patterns/test_pattern_math.hpp index 2f628d85d..b2bf5d4ea 100644 --- a/tests/include/test_patterns/test_pattern_math.hpp +++ b/tests/include/test_patterns/test_pattern_math.hpp @@ -56,14 +56,18 @@ namespace hex::test { std::assert(sizeof(typeTest) == 3 * 4, "sizeof operator error"); // Properties - std::assert(100 * 200 == 200 * 100, "+ operator commutativity error"); - std::assert(100 * 200 == 200 * 100, "* operator commutativity error"); + std::assert(100 + 200 == 200 + 100, "+ operator commutativity error"); + std::assert(100 - 200 != 200 - 100, "- operator commutativity error"); std::assert(100 * 200 == 200 * 100, "* operator commutativity error"); + std::assert(100F / 200F != 200F / 100F, "/ operator commutativity error"); std::assert(10 + (20 + 30) == (10 + 20) + 30, "+ operator associativity error"); + std::assert(10 - (20 - 30) != (10 - 20) - 30, "- operator associativity error"); std::assert(10 * (20 * 30) == (10 * 20) * 30, "* operator associativity error"); + std::assert(10F / (20F / 30F) != (10F / 20F) / 30F, "/ operator associativity error"); - std::assert(10 * (20 + 30) == 10 * 20 + 10 * 30, "Operator distributivity error"); + std::assert(10 * (20 + 30) == 10 * 20 + 10 * 30, "* operator distributivity error"); + std::assert(10F / (20F + 30F) != 10F / 20F + 10F / 30F, "/ operator distributivity error"); )"; } diff --git a/tests/include/test_patterns/test_pattern_namespaces.hpp b/tests/include/test_patterns/test_pattern_namespaces.hpp new file mode 100644 index 000000000..d6e15bdac --- /dev/null +++ b/tests/include/test_patterns/test_pattern_namespaces.hpp @@ -0,0 +1,42 @@ +#pragma once + +#include "test_pattern.hpp" + +namespace hex::test { + + class TestPatternNamespaces : public TestPattern { + public: + TestPatternNamespaces() : TestPattern("Namespaces") { + + } + ~TestPatternNamespaces() override = default; + + [[nodiscard]] + std::string getSourceCode() const override { + return R"( + namespace A { + struct Test { + u32 x; + }; + } + + namespace B { + struct Test { + u16 x; + }; + } + + using ATest = A::Test; + + A::Test test1 @ 0x10; + ATest test2 @ 0x20; + B::Test test3 @ 0x20; + + std::assert(sizeof(test1) == sizeof(test2), "error using namespaced type"); + std::assert(sizeof(test2) != sizeof(test3), "error differentiating two namespace types with same name"); + )"; + } + + }; + +} \ No newline at end of file diff --git a/tests/include/test_patterns/test_pattern_rvalues.hpp b/tests/include/test_patterns/test_pattern_rvalues.hpp new file mode 100644 index 000000000..b7c55bb24 --- /dev/null +++ b/tests/include/test_patterns/test_pattern_rvalues.hpp @@ -0,0 +1,40 @@ +#pragma once + +#include "test_pattern.hpp" + +namespace hex::test { + + class TestPatternRValues : public TestPattern { + public: + TestPatternRValues() : TestPattern("RValues") { + + } + ~TestPatternRValues() override = default; + + [[nodiscard]] + std::string getSourceCode() const override { + return R"( + union C { + u8 y; + u8 array[parent.parent.x]; + }; + + struct B { + C *c : u8; + }; + + struct A { + u8 x; + B b; + }; + + A a @ 0x00; + + std::assert(sizeof(a.b.c) == a.x && a.x != 0x00, "RValue parent test failed!"); + std::assert(a.b.c.y == a.b.c.array[0], "RValue array access test failed!"); + )"; + } + + }; + +} \ No newline at end of file diff --git a/tests/source/tests.cpp b/tests/source/tests.cpp index debdba94d..833ba72bd 100644 --- a/tests/source/tests.cpp +++ b/tests/source/tests.cpp @@ -10,6 +10,9 @@ #include "test_patterns/test_pattern_failing_assert.hpp" #include "test_patterns/test_pattern_bitfields.hpp" #include "test_patterns/test_pattern_math.hpp" +#include "test_patterns/test_pattern_rvalues.hpp" +#include "test_patterns/test_pattern_namespaces.hpp" +#include "test_patterns/test_pattern_extra_semicolon.hpp" std::array Tests = { TEST(Placement), @@ -21,5 +24,8 @@ std::array Tests = { TEST(SucceedingAssert), TEST(FailingAssert), TEST(Bitfields), - TEST(Math) + TEST(Math), + TEST(RValues), + TEST(Namespaces), + TEST(ExtraSemicolon) }; \ No newline at end of file