1
0
mirror of synced 2024-11-24 15:50:16 +01:00

tests: Added RValue, Namespaces and extra semicolon test

This commit is contained in:
WerWolv 2021-09-13 10:49:24 +02:00
parent 01670e5e85
commit 22a904baf4
6 changed files with 134 additions and 4 deletions

View File

@ -15,6 +15,9 @@ set(AVAILABLE_TESTS
FailingAssert
Bitfields
Math
RValues
Namespaces
ExtraSemicolon
)

View File

@ -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;
)";
}
};
}

View File

@ -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");
)";
}

View File

@ -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");
)";
}
};
}

View File

@ -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!");
)";
}
};
}

View File

@ -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)
};