Skip to content

Commit a5638fd

Browse files
author
yggverse
committed
implement tests
1 parent d72575f commit a5638fd

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/line/header/gemtext.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,42 @@ impl Gemtext for str {
6060
format!("{} {}", level.as_tag(), self.trim())
6161
}
6262
}
63+
64+
#[test]
65+
fn test() {
66+
const VALUE: &str = "H";
67+
let mut value: Option<&str> = Some(VALUE);
68+
for t in ["#", "##", "###", "####"] {
69+
if t.len() > 3 {
70+
value = None;
71+
}
72+
assert_eq!(format!("{t}{VALUE}").as_value(), value);
73+
assert_eq!(format!("{t}{VALUE} ").as_value(), value);
74+
assert_eq!(format!("{t} {VALUE}").as_value(), value);
75+
assert_eq!(format!("{t} {VALUE} ").as_value(), value);
76+
}
77+
78+
fn to_source(level: &Level) {
79+
assert_eq!(
80+
VALUE.to_source(level),
81+
format!("{} {VALUE}", level.as_tag())
82+
);
83+
}
84+
to_source(&Level::H1);
85+
to_source(&Level::H2);
86+
to_source(&Level::H3);
87+
88+
fn to_level(l: &Level) {
89+
fn assert(s: String, l: &str) {
90+
assert_eq!(s.to_level().unwrap().as_tag(), l);
91+
}
92+
let t = l.as_tag();
93+
assert(format!("{t} {VALUE}"), t);
94+
assert(format!("{t} {VALUE} "), t);
95+
assert(format!("{t}{VALUE} "), t);
96+
assert(format!("{t} {VALUE} "), t);
97+
}
98+
to_level(&Level::H1);
99+
to_level(&Level::H2);
100+
to_level(&Level::H3);
101+
}

0 commit comments

Comments
 (0)