produce Tag instances in the parser (#260)

and..
* fix usage-docs plugin
* upgrade mdbook
This commit is contained in:
Dustin J. Mitchell
2021-06-04 09:26:12 -04:00
committed by GitHub
parent 5a454a5dfd
commit 5f28eb3a74
12 changed files with 62 additions and 80 deletions

View File

@@ -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());
}

View File

@@ -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());
}

View File

@@ -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());
}
}