Skip to content

Commit

Permalink
Fix ci: Merge branch 'master' into buffered-parse
Browse files Browse the repository at this point in the history
  • Loading branch information
Easyoakland committed Oct 27, 2023
2 parents 3c03bbd + b1ca3ac commit 02a0293
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,31 +1036,31 @@ mod test {
fn test_many() {
// No input:
let mut t = "".into_tokens();
let abs: Vec<_> = t.many(|t| parse_ab(t)).collect();
let abs: Vec<_> = t.many(parse_ab).collect();
let rest: Vec<char> = t.as_iter().collect();

assert_eq!(abs.len(), 0);
assert_eq!(rest, vec![]);

// Invalid input after half is consumed:
let mut t = "acabab".into_tokens();
let abs: Vec<_> = t.many(|t| parse_ab(t)).collect();
let abs: Vec<_> = t.many(parse_ab).collect();
let rest: Vec<char> = t.as_iter().collect();

assert_eq!(abs.len(), 0);
assert_eq!(rest, vec!['a', 'c', 'a', 'b', 'a', 'b']);

// 3 valid and then 1 half-invalid:
let mut t = "abababaa".into_tokens();
let abs: Vec<_> = t.many(|t| parse_ab(t)).collect();
let abs: Vec<_> = t.many(parse_ab).collect();
let rest: Vec<char> = t.as_iter().collect();

assert_eq!(abs.len(), 3);
assert_eq!(rest, vec!['a', 'a']);

// End of tokens before can parse the fourth:
let mut t = "abababa".into_tokens();
let abs: Vec<_> = t.many(|t| parse_ab(t)).collect();
let abs: Vec<_> = t.many(parse_ab).collect();
let rest: Vec<char> = t.as_iter().collect();

assert_eq!(abs.len(), 3);
Expand All @@ -1072,39 +1072,39 @@ mod test {
fn test_many_err() {
// No input:
let mut t = "".into_tokens();
let abs: Vec<_> = t.many_err(|t| parse_ab_err(t)).collect();
let abs: Vec<_> = t.many_err(parse_ab_err).collect();
let rest: Vec<char> = t.as_iter().collect();

assert_eq!(abs, vec![Err(ABErr::NotEnoughTokens)]);
assert_eq!(rest, vec![]);

// Invalid input immediately:
let mut t = "ccabab".into_tokens();
let abs: Vec<_> = t.many_err(|t| parse_ab_err(t)).collect();
let abs: Vec<_> = t.many_err(parse_ab_err).collect();
let rest: Vec<char> = t.as_iter().collect();

assert_eq!(abs, vec![Err(ABErr::IsNotA)]);
assert_eq!(rest, vec!['c', 'c', 'a', 'b', 'a', 'b']);

// Invalid input after half is consumed:
let mut t = "acabab".into_tokens();
let abs: Vec<_> = t.many_err(|t| parse_ab_err(t)).collect();
let abs: Vec<_> = t.many_err(parse_ab_err).collect();
let rest: Vec<char> = t.as_iter().collect();

assert_eq!(abs, vec![Err(ABErr::IsNotB)]);
assert_eq!(rest, vec!['a', 'c', 'a', 'b', 'a', 'b']);

// 3 valid and then 1 half-invalid:
let mut t = "abababaa".into_tokens();
let abs: Vec<_> = t.many_err(|t| parse_ab_err(t)).collect();
let abs: Vec<_> = t.many_err(parse_ab_err).collect();
let rest: Vec<char> = t.as_iter().collect();

assert_eq!(abs, vec![Ok(AB), Ok(AB), Ok(AB), Err(ABErr::IsNotB)]);
assert_eq!(rest, vec!['a', 'a']);

// End of tokens before can parse the fourth:
let mut t = "abababa".into_tokens();
let abs: Vec<_> = t.many_err(|t| parse_ab_err(t)).collect();
let abs: Vec<_> = t.many_err(parse_ab_err).collect();
let rest: Vec<char> = t.as_iter().collect();

assert_eq!(
Expand Down Expand Up @@ -1138,25 +1138,25 @@ mod test {
#[test]
fn test_skip_many1() {
let mut t = "".into_tokens();
let res = t.skip_many1(|t| parse_ab_err(t));
let res = t.skip_many1(parse_ab_err);
let rest: String = t.as_iter().collect();
assert_eq!(res, Err(ABErr::NotEnoughTokens));
assert_eq!(&*rest, "");

let mut t = "acabab".into_tokens();
let res = t.skip_many1(|t| parse_ab_err(t));
let res = t.skip_many1(parse_ab_err);
let rest: String = t.as_iter().collect();
assert_eq!(res, Err(ABErr::IsNotB));
assert_eq!(&*rest, "acabab");

let mut t = "abcbab".into_tokens();
let res = t.skip_many1(|t| parse_ab_err(t));
let res = t.skip_many1(parse_ab_err);
let rest: String = t.as_iter().collect();
assert_eq!(res, Ok(1));
assert_eq!(&*rest, "cbab");

let mut t = "ababcbab".into_tokens();
let res = t.skip_many1(|t| parse_ab_err(t));
let res = t.skip_many1(parse_ab_err);
let rest: String = t.as_iter().collect();
assert_eq!(res, Ok(2));
assert_eq!(&*rest, "cbab");
Expand Down

0 comments on commit 02a0293

Please sign in to comment.