mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 14:21:16 +00:00
Fix Struct::iterator test to be order agnostic
This commit is contained in:
parent
715c9f407e
commit
b51549ab58
2 changed files with 17 additions and 12 deletions
|
@ -120,6 +120,8 @@ public:
|
|||
/// references become invalid when the iterator or the Struct is changed, so make sure to make
|
||||
/// copies if you want to retain the name or value.
|
||||
///
|
||||
/// Note that the order in which the iterator exposes the fields is not defined.
|
||||
///
|
||||
/// If you're using C++ 17, you can use the convenience destructuring syntax to extract the name
|
||||
/// and value in one go:
|
||||
///
|
||||
|
|
|
@ -226,19 +226,22 @@ SCENARIO("Struct field iteration")
|
|||
auto end = struc.end();
|
||||
REQUIRE(it != end);
|
||||
|
||||
{
|
||||
auto [key, value] = *it;
|
||||
REQUIRE(key == "field_a");
|
||||
REQUIRE(value == Value(true));
|
||||
auto check_valid_entry = [](const auto &key, const auto &value) -> bool {
|
||||
if (key == "field_a")
|
||||
return value == Value(true);
|
||||
if (key == "field_b")
|
||||
return value == Value(42.0);
|
||||
return false;
|
||||
};
|
||||
|
||||
std::set<std::string> seen_fields;
|
||||
|
||||
for (; it != end; ++it) {
|
||||
const auto [key, value] = *it;
|
||||
REQUIRE(check_valid_entry(key, value));
|
||||
auto [insert_it, value_inserted] = seen_fields.insert(std::string(key));
|
||||
REQUIRE(value_inserted);
|
||||
}
|
||||
++it;
|
||||
{
|
||||
auto [key, value] = *it;
|
||||
REQUIRE(key == "field_b");
|
||||
REQUIRE(value == Value(42.0));
|
||||
}
|
||||
++it;
|
||||
REQUIRE(it == end);
|
||||
}
|
||||
|
||||
SCENARIO("Component Compiler")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue