-
Notifications
You must be signed in to change notification settings - Fork 6
/
compound.rs
58 lines (55 loc) · 1.45 KB
/
compound.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use super::foo::Link;
use unhtml::FromHtml;
#[derive(FromHtml, Debug, Eq, PartialEq)]
struct Websites {
#[html(selector = "#current_site")]
current: Option<Link>,
#[html(selector = "a")]
links: Vec<Link>,
}
#[test]
fn test_compound() {
assert_eq!(
Websites::from_html("").unwrap(),
Websites {
current: None,
links: vec![],
}
);
assert_eq!(
Websites::from_html(
r##"
<div>
<div>
<a href="https://github.com"> Github </a>
</div>
<div>
<a id="current_site" href="https://www.zjuqsc.com"> ZJU QSC </a>
</div>
<a href="https://google.com"> Google </a>
</div>
"##,
)
.unwrap(),
Websites {
current: Some(Link {
href: "https://www.zjuqsc.com".into(),
text: "ZJU QSC".into(),
}),
links: vec![
Link {
href: "https://github.com".into(),
text: "Github".into(),
},
Link {
href: "https://www.zjuqsc.com".into(),
text: "ZJU QSC".into(),
},
Link {
href: "https://google.com".into(),
text: "Google".into(),
},
]
}
);
}