mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
Add tests for 'Vector' destructuring and 'constexpr' support
This commit is contained in:
parent
6cb10856c6
commit
ae3a38345d
@ -1,5 +1,6 @@
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include "SystemUtil.hpp"
|
||||
#include <type_traits>
|
||||
|
||||
// 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<decltype(x), decltype(vector.x)>);
|
||||
|
||||
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<decltype(x), decltype(vector.x)>);
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <SFML/System/Vector3.hpp>
|
||||
#include "SystemUtil.hpp"
|
||||
#include <type_traits>
|
||||
|
||||
// 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<decltype(x), decltype(vector.x)>);
|
||||
|
||||
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<decltype(x), decltype(vector.x)>);
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user