move contents of taskchampion repo to tc/

This commit is contained in:
Dustin J. Mitchell
2022-05-08 19:01:20 +00:00
parent 73baefa0a5
commit 2a92b2a4b9
219 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
use nom::bytes::complete::tag as nomtag;
use nom::{character::complete::*, combinator::*, sequence::*, IResult};
/// Recognizes any argument
pub(crate) fn any(input: &str) -> IResult<&str, &str> {
rest(input)
}
/// Recognizes a report name
pub(crate) fn report_name(input: &str) -> IResult<&str, &str> {
all_consuming(recognize(pair(alpha1, alphanumeric0)))(input)
}
/// Recognizes a literal string
pub(crate) fn literal(literal: &'static str) -> impl Fn(&str) -> IResult<&str, &str> {
move |input: &str| all_consuming(nomtag(literal))(input)
}
#[cfg(test)]
mod test {
use super::super::*;
use super::*;
use pretty_assertions::assert_eq;
#[test]
fn test_arg_matching() {
assert_eq!(
arg_matching(plus_tag)(argv!["+foo", "bar"]).unwrap(),
(argv!["bar"], tag!("foo"))
);
assert!(arg_matching(plus_tag)(argv!["foo", "bar"]).is_err());
}
#[test]
fn test_literal() {
assert_eq!(literal("list")("list").unwrap().1, "list");
assert!(literal("list")("listicle").is_err());
assert!(literal("list")(" list ").is_err());
assert!(literal("list")("LiSt").is_err());
assert!(literal("list")("denylist").is_err());
}
}