srctree

Robin Linden parent 1dbbfe2c f4602764
css: Add a space for rules to keep their custom properties

css/rule.cpp added: 28, removed: 6, total 22
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Mikael Larsson <c.mikael.larsson@gmail.com>
// SPDX-FileCopyrightText: 2023 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2023-2024 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: BSD-2-Clause
 
@@ -37,6 +37,14 @@ std::string to_string(Rule const &rule) {
ss << " " << to_string(property) << ": " << value << '\n';
}
}
 
if (!rule.custom_properties.empty()) {
ss << "Custom properties:\n";
for (auto const &[property, value] : rule.custom_properties) {
ss << " " << property << ": " << value << '\n';
}
}
 
if (rule.media_query.has_value()) {
ss << "Media query:\n";
ss << " " << to_string(*rule.media_query) << '\n';
 
css/rule.h added: 28, removed: 6, total 22
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2021-2023 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2021-2024 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2022 Mikael Larsson <c.mikael.larsson@gmail.com>
//
// SPDX-License-Identifier: BSD-2-Clause
@@ -20,6 +20,7 @@ struct Rule {
std::vector<std::string> selectors;
std::map<PropertyId, std::string> declarations;
std::map<PropertyId, std::string> important_declarations;
std::map<std::string, std::string> custom_properties;
std::optional<MediaQuery> media_query;
[[nodiscard]] bool operator==(Rule const &) const = default;
};
 
css/rule_test.cpp added: 28, removed: 6, total 22
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Mikael Larsson <c.mikael.larsson@gmail.com>
// SPDX-FileCopyrightText: 2023 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2023-2024 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: BSD-2-Clause
 
@@ -72,5 +72,18 @@ int main() {
expect_eq(css::to_string(rule), expected);
});
 
etest::test("rule to string, custom property", [] {
css::Rule rule;
rule.selectors.emplace_back("div");
rule.custom_properties.emplace("--ping", "pong");
 
auto const *expected =
"Selectors: div\n"
"Declarations:\n"
"Custom properties:\n"
" --ping: pong\n";
expect_eq(css::to_string(rule), expected);
});
 
return etest::run_all_tests();
}