mirror of
https://github.com/YGGverse/ggemtext.git
synced 2026-03-31 17:15:33 +00:00
implement tests
This commit is contained in:
parent
d72575fdc5
commit
a5638fde33
1 changed files with 39 additions and 0 deletions
|
|
@ -60,3 +60,42 @@ impl Gemtext for str {
|
|||
format!("{} {}", level.as_tag(), self.trim())
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
const VALUE: &str = "H";
|
||||
let mut value: Option<&str> = Some(VALUE);
|
||||
for t in ["#", "##", "###", "####"] {
|
||||
if t.len() > 3 {
|
||||
value = None;
|
||||
}
|
||||
assert_eq!(format!("{t}{VALUE}").as_value(), value);
|
||||
assert_eq!(format!("{t}{VALUE} ").as_value(), value);
|
||||
assert_eq!(format!("{t} {VALUE}").as_value(), value);
|
||||
assert_eq!(format!("{t} {VALUE} ").as_value(), value);
|
||||
}
|
||||
|
||||
fn to_source(level: &Level) {
|
||||
assert_eq!(
|
||||
VALUE.to_source(level),
|
||||
format!("{} {VALUE}", level.as_tag())
|
||||
);
|
||||
}
|
||||
to_source(&Level::H1);
|
||||
to_source(&Level::H2);
|
||||
to_source(&Level::H3);
|
||||
|
||||
fn to_level(l: &Level) {
|
||||
fn assert(s: String, l: &str) {
|
||||
assert_eq!(s.to_level().unwrap().as_tag(), l);
|
||||
}
|
||||
let t = l.as_tag();
|
||||
assert(format!("{t} {VALUE}"), t);
|
||||
assert(format!("{t} {VALUE} "), t);
|
||||
assert(format!("{t}{VALUE} "), t);
|
||||
assert(format!("{t} {VALUE} "), t);
|
||||
}
|
||||
to_level(&Level::H1);
|
||||
to_level(&Level::H2);
|
||||
to_level(&Level::H3);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue