produce Tag instances in the parser (#260)
and.. * fix usage-docs plugin * upgrade mdbook
This commit is contained in:
committed by
GitHub
parent
5a454a5dfd
commit
5f28eb3a74
@@ -44,7 +44,7 @@ mod test {
|
||||
fn test_arg_matching() {
|
||||
assert_eq!(
|
||||
arg_matching(plus_tag)(argv!["+foo", "bar"]).unwrap(),
|
||||
(argv!["bar"], "foo")
|
||||
(argv!["bar"], tag!("foo"))
|
||||
);
|
||||
assert!(arg_matching(plus_tag)(argv!["foo", "bar"]).is_err());
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ mod test {
|
||||
fn test_arg_matching() {
|
||||
assert_eq!(
|
||||
arg_matching(plus_tag)(argv!["+foo", "bar"]).unwrap(),
|
||||
(argv!["bar"], "foo")
|
||||
(argv!["bar"], tag!("foo"))
|
||||
);
|
||||
assert!(arg_matching(plus_tag)(argv!["foo", "bar"]).is_err());
|
||||
}
|
||||
|
||||
@@ -3,31 +3,13 @@ use std::convert::TryFrom;
|
||||
use taskchampion::Tag;
|
||||
|
||||
/// Recognizes a tag prefixed with `+` and returns the tag value
|
||||
pub(crate) fn plus_tag(input: &str) -> IResult<&str, &str> {
|
||||
fn to_tag(input: (char, &str)) -> Result<&str, ()> {
|
||||
Ok(input.1)
|
||||
}
|
||||
map_res(
|
||||
all_consuming(tuple((
|
||||
char('+'),
|
||||
recognize(verify(rest, |s: &str| Tag::try_from(s).is_ok())),
|
||||
))),
|
||||
to_tag,
|
||||
)(input)
|
||||
pub(crate) fn plus_tag(input: &str) -> IResult<&str, Tag> {
|
||||
preceded(char('+'), map_res(rest, Tag::try_from))(input)
|
||||
}
|
||||
|
||||
/// Recognizes a tag prefixed with `-` and returns the tag value
|
||||
pub(crate) fn minus_tag(input: &str) -> IResult<&str, &str> {
|
||||
fn to_tag(input: (char, &str)) -> Result<&str, ()> {
|
||||
Ok(input.1)
|
||||
}
|
||||
map_res(
|
||||
all_consuming(tuple((
|
||||
char('-'),
|
||||
recognize(verify(rest, |s: &str| Tag::try_from(s).is_ok())),
|
||||
))),
|
||||
to_tag,
|
||||
)(input)
|
||||
pub(crate) fn minus_tag(input: &str) -> IResult<&str, Tag> {
|
||||
preceded(char('-'), map_res(rest, Tag::try_from))(input)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -36,21 +18,17 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_plus_tag() {
|
||||
assert_eq!(plus_tag("+abc").unwrap().1, "abc");
|
||||
assert_eq!(plus_tag("+abc123").unwrap().1, "abc123");
|
||||
assert_eq!(plus_tag("+abc").unwrap().1, tag!("abc"));
|
||||
assert_eq!(plus_tag("+abc123").unwrap().1, tag!("abc123"));
|
||||
assert!(plus_tag("-abc123").is_err());
|
||||
assert!(plus_tag("+abc123 ").is_err());
|
||||
assert!(plus_tag(" +abc123").is_err());
|
||||
assert!(plus_tag("+1abc").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_minus_tag() {
|
||||
assert_eq!(minus_tag("-abc").unwrap().1, "abc");
|
||||
assert_eq!(minus_tag("-abc123").unwrap().1, "abc123");
|
||||
assert_eq!(minus_tag("-abc").unwrap().1, tag!("abc"));
|
||||
assert_eq!(minus_tag("-abc123").unwrap().1, tag!("abc123"));
|
||||
assert!(minus_tag("+abc123").is_err());
|
||||
assert!(minus_tag("-abc123 ").is_err());
|
||||
assert!(minus_tag(" -abc123").is_err());
|
||||
assert!(minus_tag("-1abc").is_err());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user