Improve testing and handling of some Anchor edge cases
This commit is contained in:
parent
f9ef9a56a1
commit
21ab00b3eb
3 changed files with 166 additions and 33 deletions
|
|
@ -5,6 +5,7 @@ pub struct Anchor {
|
|||
pub text: String,
|
||||
pub destination: Option<String>,
|
||||
pub leading: bool,
|
||||
pub external: bool,
|
||||
}
|
||||
|
||||
impl Parseable for Anchor {
|
||||
|
|
@ -39,11 +40,17 @@ impl Parseable for Anchor {
|
|||
}
|
||||
|
||||
impl Anchor {
|
||||
pub fn new(text: &str, destination: &str, spaced: bool) -> Anchor {
|
||||
pub fn new(
|
||||
text: &str,
|
||||
destination: &str,
|
||||
leading: bool,
|
||||
external: bool,
|
||||
) -> Anchor {
|
||||
Anchor {
|
||||
text: text.to_owned(),
|
||||
destination: Some(Anchor::resolve_destination(destination)),
|
||||
leading: spaced,
|
||||
leading,
|
||||
external,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -54,14 +61,6 @@ impl Anchor {
|
|||
format!("/node/{raw}")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn empty() -> Anchor {
|
||||
Anchor {
|
||||
text: String::new(),
|
||||
destination: None,
|
||||
leading: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
@ -71,7 +70,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn render_anchor() {
|
||||
let anchor = Anchor::new("AnchorText", "AnchorDest", true);
|
||||
let anchor = Anchor::new("AnchorText", "AnchorDest", true, false);
|
||||
assert_eq!(
|
||||
anchor.render(),
|
||||
r#"<a href="/node/AnchorDest">AnchorText</a>"#
|
||||
|
|
@ -89,7 +88,7 @@ mod tests {
|
|||
#[test]
|
||||
#[should_panic(expected = "without knowing its destination")]
|
||||
fn unknown_destination_render() {
|
||||
let anchor = Anchor::empty();
|
||||
let anchor = Anchor::default();
|
||||
drop(anchor.render());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue