srctree

Robin Linden parent d9d7a859 46bdb16d
css: Add a place to keep important declarations

inlinesplit
css/rule.cpp added: 24, removed: 3, total 21
@@ -31,6 +31,12 @@ std::string to_string(Rule const &rule) {
for (auto const &[property, value] : rule.declarations) {
ss << " " << to_string(property) << ": " << value << '\n';
}
if (!rule.important_declarations.empty()) {
ss << "Important declarations:\n";
for (auto const &[property, value] : rule.important_declarations) {
ss << " " << to_string(property) << ": " << value << '\n';
}
}
if (rule.media_query.has_value()) {
ss << "Media query:\n";
ss << " " << to_string(*rule.media_query) << '\n';
 
css/rule.h added: 24, removed: 3, total 21
@@ -19,6 +19,7 @@ namespace css {
struct Rule {
std::vector<std::string> selectors;
std::map<PropertyId, std::string> declarations;
std::map<PropertyId, std::string> important_declarations;
std::optional<MediaQuery> media_query;
[[nodiscard]] bool operator==(Rule const &) const = default;
};
 
css/rule_test.cpp added: 24, removed: 3, total 21
@@ -1,4 +1,5 @@
// SPDX-FileCopyrightText: 2022 Mikael Larsson <c.mikael.larsson@gmail.com>
// SPDX-FileCopyrightText: 2023 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: BSD-2-Clause
 
@@ -57,5 +58,18 @@ int main() {
expect_eq(css::to_string(rule), expected);
});
 
etest::test("rule to string, important declaration", [] {
css::Rule rule;
rule.selectors.emplace_back("div");
rule.important_declarations.emplace(css::PropertyId::BackgroundColor, "black");
 
auto const *expected =
"Selectors: div\n"
"Declarations:\n"
"Important declarations:\n"
" background-color: black\n";
expect_eq(css::to_string(rule), expected);
});
 
return etest::run_all_tests();
}