diff --git a/test/src/System/Vector2.cpp b/test/src/System/Vector2.cpp index bb3b28ea7..2b78dc31f 100644 --- a/test/src/System/Vector2.cpp +++ b/test/src/System/Vector2.cpp @@ -1,5 +1,6 @@ #include #include "SystemUtil.hpp" +#include // Use sf::Vector2i for tests. Test coverage is given, as there are no template specializations. @@ -145,4 +146,47 @@ TEST_CASE("sf::Vector2 class template", "[system]") CHECK_FALSE(firstEqualVector != secondEqualVector); } } + + SECTION("Structured bindings") + { + sf::Vector2i vector(1, 2); + + SECTION("destructure by value") + { + auto [x, y] = vector; + + CHECK(x == 1); + CHECK(y == 2); + + static_assert(std::is_same_v); + + x = 3; + + CHECK(x == 3); + CHECK(vector.x == 1); + } + + SECTION("destructure by ref") + { + auto& [x, y] = vector; + + CHECK(x == 1); + CHECK(y == 2); + + static_assert(std::is_same_v); + + x = 3; + + CHECK(x == 3); + CHECK(vector.x == 3); + } + } + + SECTION("Constexpr support") + { + constexpr sf::Vector2i vector(1, 2); + static_assert(vector.x == 1); + static_assert(vector.y == 2); + static_assert(vector + sf::Vector2i(2, 1) == sf::Vector2i(3, 3)); + } } diff --git a/test/src/System/Vector3.cpp b/test/src/System/Vector3.cpp index 948a0ff7c..beefa4bcf 100644 --- a/test/src/System/Vector3.cpp +++ b/test/src/System/Vector3.cpp @@ -1,5 +1,6 @@ #include #include "SystemUtil.hpp" +#include // Use sf::Vector3i for tests. Test coverage is given, as there are no template specializations. @@ -158,4 +159,50 @@ TEST_CASE("sf::Vector3 class template", "[system]") CHECK_FALSE(firstEqualVector != secondEqualVector); } } + + SECTION("Structured bindings") + { + sf::Vector3i vector(1, 2, 3); + + SECTION("destructure by value") + { + auto [x, y, z] = vector; + + CHECK(x == 1); + CHECK(y == 2); + CHECK(z == 3); + + static_assert(std::is_same_v); + + x = 3; + + CHECK(x == 3); + CHECK(vector.x == 1); + } + + SECTION("destructure by ref") + { + auto& [x, y, z] = vector; + + CHECK(x == 1); + CHECK(y == 2); + CHECK(z == 3); + + static_assert(std::is_same_v); + + x = 3; + + CHECK(x == 3); + CHECK(vector.x == 3); + } + } + + SECTION("Constexpr support") + { + constexpr sf::Vector3i vector(1, 2, 3); + static_assert(vector.x == 1); + static_assert(vector.y == 2); + static_assert(vector.z == 3); + static_assert(vector + sf::Vector3i(3, 2, 1) == sf::Vector3i(4, 4, 4)); + } }