From 8125e4cdafe7d84d91b74f15412178037bfaabf7 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Mon, 10 Jan 2022 14:51:18 +0700 Subject: [PATCH] add value with function pointer tests --- manuals/meta_examples/variables_example.cpp | 4 +- untests/meta_utilities/value_tests.cpp | 47 ++++++++++++++++++--- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/manuals/meta_examples/variables_example.cpp b/manuals/meta_examples/variables_example.cpp index 54da4d7..87578cf 100644 --- a/manuals/meta_examples/variables_example.cpp +++ b/manuals/meta_examples/variables_example.cpp @@ -8,8 +8,8 @@ namespace { - const double pi_v = 3.1415926536; - const double sqrt2_v = 1.4142135624; + const double pi_v{3.1415926536}; + const double sqrt2_v{1.4142135624}; } TEST_CASE("meta/meta_examples/variables/usage") { diff --git a/untests/meta_utilities/value_tests.cpp b/untests/meta_utilities/value_tests.cpp index 602c13b..3a6b09d 100644 --- a/untests/meta_utilities/value_tests.cpp +++ b/untests/meta_utilities/value_tests.cpp @@ -12,9 +12,9 @@ namespace int x{}; int y{}; - [[maybe_unused]] ivec2() = default; - [[maybe_unused]] explicit ivec2(int v): x{v}, y{v} {} - [[maybe_unused]] ivec2(int x, int y): x{x}, y{y} {} + ivec2() = default; + explicit ivec2(int v): x{v}, y{v} {} + ivec2(int x, int y): x{x}, y{y} {} ivec2(ivec2&& other) noexcept : x{other.x} @@ -40,15 +40,32 @@ namespace int ivec2::move_ctor_counter{0}; int ivec2::copy_ctor_counter{0}; - [[maybe_unused]] bool operator<(const ivec2& l, const ivec2& r) noexcept { + ivec2 iadd2(ivec2 l, ivec2 r) { + return {l.x + r.x, l.y + r.y}; + } + + bool operator<(const ivec2& l, const ivec2& r) noexcept { return (l.x < r.x) || (l.x == r.x && l.y < r.y); } - [[maybe_unused]] bool operator==(const ivec2& l, const ivec2& r) noexcept { + bool operator==(const ivec2& l, const ivec2& r) noexcept { return l.x == r.x && l.y == r.y; } } +TEST_CASE("meta/meta_utilities/value/ivec2") { + namespace meta = meta_hpp; + + meta::class_() + .ctor_<>() + .ctor_() + .ctor_() + .ctor_() + .ctor_() + .member_("x", &ivec2::x) + .member_("y", &ivec2::y); +} + TEST_CASE("meta/meta_utilities/value") { namespace meta = meta_hpp; using namespace std::string_literals; @@ -303,7 +320,8 @@ TEST_CASE("meta/meta_utilities/value") { class empty_class1 {}; class empty_class2 {}; - CHECK((operator<(meta::value{empty_class1{}}, meta::value{empty_class2{}}) || operator<(meta::value{empty_class2{}}, meta::value{empty_class1{}}))); + CHECK((operator<(meta::value{empty_class1{}}, meta::value{empty_class2{}}) + || operator<(meta::value{empty_class2{}}, meta::value{empty_class1{}}))); CHECK_THROWS(std::ignore = operator<(meta::value{empty_class1{}}, meta::value{empty_class1{}})); } } @@ -327,3 +345,20 @@ TEST_CASE("meta/meta_utilities/value") { } } } + +TEST_CASE("meta/meta_utilities/value/functions") { + namespace meta = meta_hpp; + + SUBCASE("iadd2") { + { + const meta::value v{iadd2}; + CHECK(v.get_type() == meta::resolve_type()); + CHECK(v.cast()(ivec2{1,2}, ivec2{3,4}) == ivec2{4,6}); + } + { + const meta::value v{&iadd2}; + CHECK(v.get_type() == meta::resolve_type()); + CHECK(v.cast()(ivec2{1,2}, ivec2{3,4}) == ivec2{4,6}); + } + } +}