diff options
author | Sven-Hendrik Haase <svenstaro@gmail.com> | 2019-07-14 07:42:20 +0000 |
---|---|---|
committer | Sven-Hendrik Haase <svenstaro@gmail.com> | 2019-07-14 07:44:26 +0000 |
commit | 2a45e4d60793c9b90ec30b30431de699604b9129 (patch) | |
tree | ba850033e1c2289c2db6c81127508d208fbe865d /tests/utils/mod.rs | |
parent | Merge pull request #162 from svenstaro/dependabot/cargo/log-0.4.7 (diff) | |
download | miniserve-2a45e4d60793c9b90ec30b30431de699604b9129.tar.gz miniserve-2a45e4d60793c9b90ec30b30431de699604b9129.zip |
Add dir navigation tests
Diffstat (limited to 'tests/utils/mod.rs')
-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()) +} |