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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use nom::{
|
||||
multi::{fold_many0, fold_many1},
|
||||
IResult,
|
||||
};
|
||||
use taskchampion::Status;
|
||||
use taskchampion::{Status, Tag};
|
||||
|
||||
/// A filter represents a selection of a particular set of tasks.
|
||||
///
|
||||
@@ -26,10 +26,10 @@ pub(crate) struct Filter {
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub(crate) enum Condition {
|
||||
/// Task has the given tag
|
||||
HasTag(String),
|
||||
HasTag(Tag),
|
||||
|
||||
/// Task does not have the given tag
|
||||
NoTag(String),
|
||||
NoTag(Tag),
|
||||
|
||||
/// Task has the given status
|
||||
Status(Status),
|
||||
@@ -68,15 +68,15 @@ impl Condition {
|
||||
}
|
||||
|
||||
fn parse_plus_tag(input: ArgList) -> IResult<ArgList, Condition> {
|
||||
fn to_condition(input: &str) -> Result<Condition, ()> {
|
||||
Ok(Condition::HasTag(input.to_owned()))
|
||||
fn to_condition(input: Tag) -> Result<Condition, ()> {
|
||||
Ok(Condition::HasTag(input))
|
||||
}
|
||||
map_res(arg_matching(plus_tag), to_condition)(input)
|
||||
}
|
||||
|
||||
fn parse_minus_tag(input: ArgList) -> IResult<ArgList, Condition> {
|
||||
fn to_condition(input: &str) -> Result<Condition, ()> {
|
||||
Ok(Condition::NoTag(input.to_owned()))
|
||||
fn to_condition(input: Tag) -> Result<Condition, ()> {
|
||||
Ok(Condition::NoTag(input))
|
||||
}
|
||||
map_res(arg_matching(minus_tag), to_condition)(input)
|
||||
}
|
||||
@@ -320,8 +320,8 @@ mod test {
|
||||
Filter {
|
||||
conditions: vec![
|
||||
Condition::IdList(vec![TaskId::WorkingSetId(1),]),
|
||||
Condition::HasTag("yes".into()),
|
||||
Condition::NoTag("no".into()),
|
||||
Condition::HasTag(tag!("yes")),
|
||||
Condition::NoTag(tag!("no")),
|
||||
],
|
||||
}
|
||||
);
|
||||
@@ -353,10 +353,10 @@ mod test {
|
||||
conditions: vec![
|
||||
// from first filter
|
||||
Condition::IdList(vec![TaskId::WorkingSetId(1), TaskId::WorkingSetId(2),]),
|
||||
Condition::HasTag("yes".into()),
|
||||
Condition::HasTag(tag!("yes")),
|
||||
// from second filter
|
||||
Condition::IdList(vec![TaskId::WorkingSetId(2), TaskId::WorkingSetId(3)]),
|
||||
Condition::HasTag("no".into()),
|
||||
Condition::HasTag(tag!("no")),
|
||||
],
|
||||
}
|
||||
);
|
||||
@@ -373,9 +373,9 @@ mod test {
|
||||
conditions: vec![
|
||||
// from first filter
|
||||
Condition::IdList(vec![TaskId::WorkingSetId(1), TaskId::WorkingSetId(2),]),
|
||||
Condition::HasTag("yes".into()),
|
||||
Condition::HasTag(tag!("yes")),
|
||||
// from second filter
|
||||
Condition::HasTag("no".into()),
|
||||
Condition::HasTag(tag!("no")),
|
||||
],
|
||||
}
|
||||
);
|
||||
@@ -390,8 +390,8 @@ mod test {
|
||||
both,
|
||||
Filter {
|
||||
conditions: vec![
|
||||
Condition::HasTag("yes".into()),
|
||||
Condition::HasTag("no".into()),
|
||||
Condition::HasTag(tag!("yes")),
|
||||
Condition::HasTag(tag!("no")),
|
||||
],
|
||||
}
|
||||
);
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::usage;
|
||||
use chrono::prelude::*;
|
||||
use nom::{branch::alt, combinator::*, multi::fold_many0, IResult};
|
||||
use std::collections::HashSet;
|
||||
use taskchampion::Status;
|
||||
use taskchampion::{Status, Tag};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub enum DescriptionMod {
|
||||
@@ -44,17 +44,17 @@ pub struct Modification {
|
||||
pub active: Option<bool>,
|
||||
|
||||
/// Add tags
|
||||
pub add_tags: HashSet<String>,
|
||||
pub add_tags: HashSet<Tag>,
|
||||
|
||||
/// Remove tags
|
||||
pub remove_tags: HashSet<String>,
|
||||
pub remove_tags: HashSet<Tag>,
|
||||
}
|
||||
|
||||
/// A single argument that is part of a modification, used internally to this module
|
||||
enum ModArg<'a> {
|
||||
Description(&'a str),
|
||||
PlusTag(&'a str),
|
||||
MinusTag(&'a str),
|
||||
PlusTag(Tag),
|
||||
MinusTag(Tag),
|
||||
Wait(Option<DateTime<Utc>>),
|
||||
}
|
||||
|
||||
@@ -71,10 +71,10 @@ impl Modification {
|
||||
}
|
||||
}
|
||||
ModArg::PlusTag(tag) => {
|
||||
acc.add_tags.insert(tag.to_owned());
|
||||
acc.add_tags.insert(tag);
|
||||
}
|
||||
ModArg::MinusTag(tag) => {
|
||||
acc.remove_tags.insert(tag.to_owned());
|
||||
acc.remove_tags.insert(tag);
|
||||
}
|
||||
ModArg::Wait(wait) => {
|
||||
acc.wait = Some(wait);
|
||||
@@ -105,14 +105,14 @@ impl Modification {
|
||||
}
|
||||
|
||||
fn plus_tag(input: ArgList) -> IResult<ArgList, ModArg> {
|
||||
fn to_modarg(input: &str) -> Result<ModArg, ()> {
|
||||
fn to_modarg(input: Tag) -> Result<ModArg<'static>, ()> {
|
||||
Ok(ModArg::PlusTag(input))
|
||||
}
|
||||
map_res(arg_matching(plus_tag), to_modarg)(input)
|
||||
}
|
||||
|
||||
fn minus_tag(input: ArgList) -> IResult<ArgList, ModArg> {
|
||||
fn to_modarg(input: &str) -> Result<ModArg, ()> {
|
||||
fn to_modarg(input: Tag) -> Result<ModArg<'static>, ()> {
|
||||
Ok(ModArg::MinusTag(input))
|
||||
}
|
||||
map_res(arg_matching(minus_tag), to_modarg)(input)
|
||||
@@ -198,7 +198,7 @@ mod test {
|
||||
assert_eq!(
|
||||
modification,
|
||||
Modification {
|
||||
add_tags: set![s!("abc"), s!("def")],
|
||||
add_tags: set![tag!("abc"), tag!("def")],
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
@@ -252,8 +252,8 @@ mod test {
|
||||
modification,
|
||||
Modification {
|
||||
description: DescriptionMod::Set(s!("new desc fun")),
|
||||
add_tags: set![s!("next")],
|
||||
remove_tags: set![s!("daytime")],
|
||||
add_tags: set![tag!("next")],
|
||||
remove_tags: set![tag!("daytime")],
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user