Add tests for search option.
This commit is contained in:
@@ -6,7 +6,9 @@ use nom::bytes::complete::take_until;
|
||||
use nom::character::complete::anychar;
|
||||
use nom::combinator::consumed;
|
||||
use nom::combinator::eof;
|
||||
use nom::combinator::map;
|
||||
use nom::combinator::map_parser;
|
||||
use nom::combinator::opt;
|
||||
use nom::combinator::peek;
|
||||
use nom::combinator::recognize;
|
||||
use nom::combinator::rest;
|
||||
@@ -58,6 +60,7 @@ fn regular_link_without_description<'b, 'g, 'r, 's>(
|
||||
link_type: path.link_type,
|
||||
path: path.path,
|
||||
raw_link: path.raw_link,
|
||||
search_option: path.search_option,
|
||||
},
|
||||
))
|
||||
}
|
||||
@@ -82,6 +85,7 @@ fn regular_link_with_description<'b, 'g, 'r, 's>(
|
||||
link_type: path.link_type,
|
||||
path: path.path,
|
||||
raw_link: path.raw_link,
|
||||
search_option: path.search_option,
|
||||
},
|
||||
))
|
||||
}
|
||||
@@ -90,6 +94,7 @@ struct PathReg<'s> {
|
||||
link_type: LinkType<'s>,
|
||||
path: &'s str,
|
||||
raw_link: &'s str,
|
||||
search_option: Option<&'s str>,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
@@ -123,13 +128,20 @@ fn parse_path_reg<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, PathReg<'s>> {
|
||||
}
|
||||
|
||||
fn file_path_reg<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, PathReg<'s>> {
|
||||
let (remaining, (raw_link, (_, path))) = consumed(tuple((tag("file:"), rest)))(input)?;
|
||||
let (remaining, (raw_link, (_, path, search_option))) = consumed(tuple((
|
||||
tag("file:"),
|
||||
recognize(many_till(anychar, alt((peek(tag("::")), eof)))),
|
||||
opt(map(tuple((tag("::"), rest)), |(_, search_option)| {
|
||||
search_option
|
||||
})),
|
||||
)))(input)?;
|
||||
Ok((
|
||||
remaining,
|
||||
PathReg {
|
||||
link_type: LinkType::File,
|
||||
path: path.into(),
|
||||
raw_link: raw_link.into(),
|
||||
search_option: search_option.map(Into::<&str>::into),
|
||||
},
|
||||
))
|
||||
}
|
||||
@@ -142,6 +154,7 @@ fn id_path_reg<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, PathReg<'s>> {
|
||||
link_type: LinkType::Id,
|
||||
path: path.into(),
|
||||
raw_link: raw_link.into(),
|
||||
search_option: None,
|
||||
},
|
||||
))
|
||||
}
|
||||
@@ -154,6 +167,7 @@ fn custom_id_path_reg<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, PathReg<'s
|
||||
link_type: LinkType::CustomId,
|
||||
path: path.into(),
|
||||
raw_link: raw_link.into(),
|
||||
search_option: None,
|
||||
},
|
||||
))
|
||||
}
|
||||
@@ -170,6 +184,7 @@ fn code_ref_path_reg<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, PathReg<'s>
|
||||
link_type: LinkType::CodeRef,
|
||||
path: path.into(),
|
||||
raw_link: raw_link.into(),
|
||||
search_option: None,
|
||||
},
|
||||
))
|
||||
}
|
||||
@@ -183,6 +198,7 @@ fn protocol_path_reg<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, PathReg<'s>
|
||||
link_type: LinkType::Protocol(protocol.into()),
|
||||
path: path.into(),
|
||||
raw_link: raw_link.into(),
|
||||
search_option: None,
|
||||
},
|
||||
))
|
||||
}
|
||||
@@ -195,6 +211,7 @@ fn fuzzy_path_reg<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, PathReg<'s>> {
|
||||
link_type: LinkType::Fuzzy,
|
||||
path: body.into(),
|
||||
raw_link: body.into(),
|
||||
search_option: None,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user