aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver
diff options
context:
space:
mode:
Diffstat (limited to 'src/libserver')
-rw-r--r--src/libserver/css/css_parser.cxx11
-rw-r--r--src/libserver/css/css_value.cxx14
2 files changed, 15 insertions, 10 deletions
diff --git a/src/libserver/css/css_parser.cxx b/src/libserver/css/css_parser.cxx
index 776901ffe..e6213d30d 100644
--- a/src/libserver/css/css_parser.cxx
+++ b/src/libserver/css/css_parser.cxx
@@ -18,6 +18,7 @@
#include "css_tokeniser.hxx"
#include "css_selector.hxx"
#include "css_rule.hxx"
+#include "fmt/core.h"
#include <vector>
#include <unicode/utf8.h>
@@ -91,9 +92,7 @@ auto css_consumed_block::token_type_str(void) const -> const char *
}
auto css_consumed_block::debug_str(void) -> std::string {
- std::string ret = std::string(R"("type": ")") + token_type_str() + "\"";
-
- ret += ", \"value\": ";
+ std::string ret = fmt::format(R"("type": "{}", "value": )", token_type_str());
std::visit([&](auto& arg) {
using T = std::decay_t<decltype(arg)>;
@@ -119,9 +118,9 @@ auto css_consumed_block::debug_str(void) -> std::string {
}
else if constexpr (std::is_same_v<T, css_function_block>) {
/* Empty block */
- ret += R"({ "content": {"token": )";
- ret += "\"" + arg.function.debug_token_str() + "\", ";
- ret += R"("arguments": [)";
+ ret += fmt::format(R"({ "content": {"token": "{}", "arguments": [)",
+ arg.function.debug_token_str());
+
for (const auto &block : arg.args) {
ret += "{";
ret += block->debug_str();
diff --git a/src/libserver/css/css_value.cxx b/src/libserver/css/css_value.cxx
index a2b4ba5d7..5e482b58f 100644
--- a/src/libserver/css/css_value.cxx
+++ b/src/libserver/css/css_value.cxx
@@ -18,6 +18,7 @@
#include "css_colors_list.hxx"
#include "frozen/unordered_map.h"
#include "frozen/string.h"
+#include "libutil/util.h"
#include "contrib/robin-hood/robin_hood.h"
#include "fmt/core.h"
@@ -339,10 +340,8 @@ auto css_value::debug_str() const -> std::string {
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, css_color>) {
- ret += "color: r=" + std::to_string(arg.r) +
- "; g=" + std::to_string(arg.g) +
- "; b=" + std::to_string(arg.b) +
- "; a=" + std::to_string(arg.alpha);
+ ret += fmt::format("color: r={};g={};b={};alpha={}",
+ arg.r, arg.g, arg.b, arg.alpha);
}
else if constexpr (std::is_same_v<T, double>) {
ret += "size: " + std::to_string(arg);
@@ -386,6 +385,13 @@ TEST_SUITE("css values") {
CHECK(final_col == p.second);
}
}
+ TEST_CASE("css colors strings") {
+ for (const auto &p : css_colors_map) {
+ auto col_parsed = css_value::maybe_color_from_string(p.first);
+ auto final_col = col_parsed.value().to_color().value();
+ CHECK(final_col == p.second);
+ }
+ }
};
}