Skip to content

Commit

Permalink
Merge pull request #12 from Easyoakland/fix-ci-err
Browse files Browse the repository at this point in the history
fix ci not currently not passing the source
  • Loading branch information
jsdw authored Oct 25, 2023
2 parents c95a4de + d7ec97c commit b1ca3ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ fn object(toks: &mut impl Tokens<Item = char>) -> Option<Result<HashMap<String,

// If we hit any errors above, return it.
let Ok(values) = values else {
return Some(values)
return Some(values);
};

skip_whitespace(&mut *toks);
Expand Down
26 changes: 13 additions & 13 deletions src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -999,31 +999,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 @@ -1035,39 +1035,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 @@ -1101,25 +1101,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 b1ca3ac

Please sign in to comment.