diff options
author | jikstra <jikstra@disroot.org> | 2021-09-10 21:34:25 +0000 |
---|---|---|
committer | jikstra <jikstra@disroot.org> | 2021-09-10 21:43:05 +0000 |
commit | aed508732a9d9b9e27e301e2934af6917df3e6e1 (patch) | |
tree | d7f4a244d53f184720f3d4dfc69162d62087699c /tests/utils/mod.rs | |
parent | Remove unused imports and files (diff) | |
download | miniserve-aed508732a9d9b9e27e301e2934af6917df3e6e1.tar.gz miniserve-aed508732a9d9b9e27e301e2934af6917df3e6e1.zip |
Fix tests
Diffstat (limited to '')
-rw-r--r-- | tests/utils/mod.rs | 12 |
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()) +} |