tests: Added RValue, Namespaces and extra semicolon test
This commit is contained in:
parent
01670e5e85
commit
22a904baf4
@ -15,6 +15,9 @@ set(AVAILABLE_TESTS
|
|||||||
FailingAssert
|
FailingAssert
|
||||||
Bitfields
|
Bitfields
|
||||||
Math
|
Math
|
||||||
|
RValues
|
||||||
|
Namespaces
|
||||||
|
ExtraSemicolon
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
35
tests/include/test_patterns/test_pattern_extra_semicolon.hpp
Normal file
35
tests/include/test_patterns/test_pattern_extra_semicolon.hpp
Normal 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;
|
||||||
|
)";
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
@ -56,14 +56,18 @@ namespace hex::test {
|
|||||||
std::assert(sizeof(typeTest) == 3 * 4, "sizeof operator error");
|
std::assert(sizeof(typeTest) == 3 * 4, "sizeof operator error");
|
||||||
|
|
||||||
// Properties
|
// 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(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(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");
|
||||||
)";
|
)";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
42
tests/include/test_patterns/test_pattern_namespaces.hpp
Normal file
42
tests/include/test_patterns/test_pattern_namespaces.hpp
Normal 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");
|
||||||
|
)";
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
40
tests/include/test_patterns/test_pattern_rvalues.hpp
Normal file
40
tests/include/test_patterns/test_pattern_rvalues.hpp
Normal 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!");
|
||||||
|
)";
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
@ -10,6 +10,9 @@
|
|||||||
#include "test_patterns/test_pattern_failing_assert.hpp"
|
#include "test_patterns/test_pattern_failing_assert.hpp"
|
||||||
#include "test_patterns/test_pattern_bitfields.hpp"
|
#include "test_patterns/test_pattern_bitfields.hpp"
|
||||||
#include "test_patterns/test_pattern_math.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 = {
|
std::array Tests = {
|
||||||
TEST(Placement),
|
TEST(Placement),
|
||||||
@ -21,5 +24,8 @@ std::array Tests = {
|
|||||||
TEST(SucceedingAssert),
|
TEST(SucceedingAssert),
|
||||||
TEST(FailingAssert),
|
TEST(FailingAssert),
|
||||||
TEST(Bitfields),
|
TEST(Bitfields),
|
||||||
TEST(Math)
|
TEST(Math),
|
||||||
|
TEST(RValues),
|
||||||
|
TEST(Namespaces),
|
||||||
|
TEST(ExtraSemicolon)
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user