]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Add some more tests
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 15 Mar 2021 17:04:59 +0000 (17:04 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 15 Mar 2021 17:04:59 +0000 (17:04 +0000)
src/libserver/css/css_parser.cxx
src/libserver/css/css_value.cxx

index 776901ffee9a24cd94f1d56baa7aa237275dabc6..e6213d30d59094cfa519ee69bb6a2587805dc928 100644 (file)
@@ -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();
index a2b4ba5d7257fc9bb4466607f98eb970d15bcba5..5e482b58f2947034cf87f3a3cb02021c5fc7cd4e 100644 (file)
@@ -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);
+               }
+       }
 };
 
 }