aboutsummaryrefslogtreecommitdiffstats
path: root/tests/utils/mod.rs
diff options
context:
space:
mode:
authorjikstra <jikstra@disroot.org>2021-09-10 21:34:25 +0000
committerjikstra <jikstra@disroot.org>2021-09-10 21:43:05 +0000
commitaed508732a9d9b9e27e301e2934af6917df3e6e1 (patch)
treed7f4a244d53f184720f3d4dfc69162d62087699c /tests/utils/mod.rs
parentRemove unused imports and files (diff)
downloadminiserve-aed508732a9d9b9e27e301e2934af6917df3e6e1.tar.gz
miniserve-aed508732a9d9b9e27e301e2934af6917df3e6e1.zip
Fix tests
Diffstat (limited to '')
-rw-r--r--tests/utils/mod.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/utils/mod.rs b/tests/utils/mod.rs
new file mode 100644
index 0000000..b724945
--- /dev/null
+++ b/tests/utils/mod.rs
@@ -0,0 +1,12 @@
+use select::document::Document;
+use select::node::Node;
+use select::predicate::Name;
+use select::predicate::Predicate;
+
+/// Return the href attribute content for the closest anchor found by `text`.
+pub fn get_link_from_text(document: &Document, text: &str) -> Option<String> {
+ let a_elem = document
+ .find(Name("a").and(|x: &Node| x.children().any(|x| x.text() == text)))
+ .next()?;
+ Some(a_elem.attr("href")?.to_string())
+}