Skip to content

Commit

Permalink
Add unit test for parsing link extras
Browse files Browse the repository at this point in the history
  • Loading branch information
Zokhoi committed Sep 11, 2024
1 parent 4b47310 commit e18a97d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/tree/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,36 @@ fn test_link_location() {
check!("page:multiple:category" => None, "page:multiple:category");
}

#[test]
fn test_link_extra() {
macro_rules! check {
($input:expr => $expected:expr) => {{
let actual = LinkLocation::parse_extra(cow!($input));
let expected = match $expected {
None => None,
Some(extra) => Some(cow!(extra))
};

assert_eq!(
actual, expected,
"Actual link extra segment doesn't match expected",
);
}};
}

check!("" => None);
check!("page" => None);
check!("page/edit" => Some("/edit"));
check!("page#toc0" => Some("#toc0"));
check!("page/edit#toc0" => Some("/edit#toc0"));

check!("/" => None);
check!("/page" => None);
check!("/#/page" => None);
check!("#" => None);
check!("#anchor" => None);
}

#[derive(Serialize, Deserialize, Debug, Hash, Clone, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
pub enum LinkLabel<'a> {
Expand Down

0 comments on commit e18a97d

Please sign in to comment.