Add tests for the content syntax parser

This commit is contained in:
Juno Takano 2025-12-26 04:19:21 -03:00
commit e50bbd468d
12 changed files with 383 additions and 120 deletions

View file

@ -1,5 +1,3 @@
use std::fmt::Display;
use crate::syntax::content::{Parseable, parser::lexeme::Lexeme};
#[derive(Debug, Clone)]
@ -65,8 +63,33 @@ impl Anchor {
}
}
impl Display for Anchor {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "Anchor: <{}> to <{:?}>", &self.text, &self.destination)
#[cfg(test)]
mod tests {
use super::*;
use crate::syntax::content::parser::read;
#[test]
fn render_anchor() {
let anchor = Anchor::new("AnchorText", "AnchorDest", true);
assert_eq!(
anchor.render(),
r#"<a href="/node/AnchorDest">AnchorText</a>"#
);
}
#[test]
#[should_panic(
expected = "Attempt to lex an anchor directly from a lexeme"
)]
fn lex() {
Anchor::lex(&Lexeme::new("", ""));
}
#[test]
#[should_panic(expected = "without knowing its destination")]
fn unknown_destination_render() {
let anchor = Anchor::empty();
drop(anchor.render());
}
}