From e18a97d80365fb80f21ef3826a9db338eafa5445 Mon Sep 17 00:00:00 2001 From: Zokhoi <20432565+Zokhoi@users.noreply.github.com> Date: Wed, 11 Sep 2024 14:36:16 +0800 Subject: [PATCH] Add unit test for parsing link extras --- src/tree/link.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/tree/link.rs b/src/tree/link.rs index 60829850..7d9e9417 100644 --- a/src/tree/link.rs +++ b/src/tree/link.rs @@ -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> {