-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
home.rs
77 lines (70 loc) Β· 1.57 KB
/
home.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use super::*;
#[derive(Display)]
pub(crate) struct HomeHtml {
last: u64,
blocks: Vec<(&'static str, BlockHash)>,
}
impl HomeHtml {
pub(crate) fn new(blocks: Vec<(u64, BlockHash)>) -> Self {
Self {
last: blocks
.get(0)
.map(|(height, _)| height)
.cloned()
.unwrap_or(0),
blocks: blocks
.into_iter()
.map(|(height, hash)| (Height(height).starting_ordinal().rarity(), hash))
.collect(),
}
}
}
impl Content for HomeHtml {
fn title(&self) -> String {
"Ordinals".to_string()
}
}
#[cfg(test)]
mod tests {
use {super::*, regex::Regex};
macro_rules! assert_regex_match {
($pattern:expr, $string:expr $(,)?) => {
let regex = Regex::new(&format!("^(?s){}$", $pattern)).unwrap();
let string = $string;
if !regex.is_match(string) {
panic!(
"Regex:\n\n{}\n\nβ¦did not match string:\n\n{}",
regex, string
);
}
};
}
#[test]
fn home_html() {
assert_regex_match!(
"<h1>Ordinals</h1>
<nav>.*</nav>
<h2>Recent Blocks</h2>
<ol start=1 reversed>
<li><a href=/block/1{64} class=uncommon>1{64}</a></li>
<li><a href=/block/0{64} class=mythic>0{64}</a></li>
</ol>
",
&HomeHtml::new(vec![
(
1,
"1111111111111111111111111111111111111111111111111111111111111111"
.parse()
.unwrap()
),
(
0,
"0000000000000000000000000000000000000000000000000000000000000000"
.parse()
.unwrap()
)
],)
.to_string()
);
}
}