commit e26d49a: [Project] Css: Add simple selectors unit tests
Vsevolod Stakhov
vsevolod at highsecure.ru
Tue Mar 16 20:49:09 UTC 2021
Author: Vsevolod Stakhov
Date: 2021-03-16 20:41:42 +0000
URL: https://github.com/rspamd/rspamd/commit/e26d49a3abec0bfb4a0986e66193874cde5d94d2 (HEAD -> master)
[Project] Css: Add simple selectors unit tests
---
src/libserver/css/css_selector.cxx | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/src/libserver/css/css_selector.cxx b/src/libserver/css/css_selector.cxx
index a1ed0e234..48914dc1e 100644
--- a/src/libserver/css/css_selector.cxx
+++ b/src/libserver/css/css_selector.cxx
@@ -16,6 +16,8 @@
#include "css_selector.hxx"
#include "fmt/core.h"
+#define DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL
+#include "doctest/doctest.h"
namespace rspamd::css {
@@ -184,5 +186,35 @@ css_selector::debug_str() const -> std::string
return ret;
}
+TEST_SUITE("css selectors") {
+ TEST_CASE("simple css selectors") {
+ const std::vector<std::pair<const char *, std::vector<css_selector::selector_type>>> cases{
+ {"em", {css_selector::selector_type::SELECTOR_ELEMENT}},
+ {"*", {css_selector::selector_type::SELECTOR_ALL}},
+ {".class", {css_selector::selector_type::SELECTOR_CLASS}},
+ {"#id", {css_selector::selector_type::SELECTOR_ID}},
+ {"em,.class,#id", {css_selector::selector_type::SELECTOR_ELEMENT,
+ css_selector::selector_type::SELECTOR_CLASS,
+ css_selector::selector_type::SELECTOR_ID}},
+ };
+
+ auto *pool = rspamd_mempool_new(rspamd_mempool_suggest_size(),
+ "css", 0);
+
+ for (const auto &c : cases) {
+ auto res = process_selector_tokens(pool,
+ get_selectors_parser_functor(pool, c.first));
+
+ CHECK(c.second.size() == res.size());
+
+ for (auto i = 0; i < c.second.size(); i ++) {
+ CHECK(res[i]->type == c.second[i]);
+ }
+ }
+
+ rspamd_mempool_delete(pool);
+ }
+}
+
}
More information about the Commits
mailing list