diff options
| author | John Turner <jturner.usa@gmail.com> | 2025-11-14 20:38:31 +0000 |
|---|---|---|
| committer | John Turner <jturner.usa@gmail.com> | 2025-11-14 20:38:31 +0000 |
| commit | 17684d17428d1fcab12f4ea363d44dd24f4680a0 (patch) | |
| tree | 6088badb47563fcc49c20091f5f57747fa52ce81 /tests/porthole.rs | |
| parent | 85853ada1e3c8ecfdffa72fad4fcf34860661f35 (diff) | |
| download | gentoo-utils-debugging.tar.gz | |
debuggingdebugging
Diffstat (limited to 'tests/porthole.rs')
| -rw-r--r-- | tests/porthole.rs | 93 |
1 files changed, 67 insertions, 26 deletions
diff --git a/tests/porthole.rs b/tests/porthole.rs index 3efbffe..2c55ffe 100644 --- a/tests/porthole.rs +++ b/tests/porthole.rs @@ -2,9 +2,9 @@ use std::cmp::Ordering; use gentoo_utils::{ Parseable, - atom::{Atom, Cpv}, + atom::{Cp, Cpv}, }; -use mon::{Parser, input::InputIter, tag}; +use mon::{Parser, ParserIter, input::InputIter, tag}; static PORTHOLE_TXT: &'static str = include_str!(concat!( env!("CARGO_MANIFEST_DIR"), @@ -12,29 +12,38 @@ static PORTHOLE_TXT: &'static str = include_str!(concat!( )); enum Operator { - Comment, - Yes, - No, + Cpv(bool), + Cp(bool), Eq, + Ne, Gt, Lt, } fn parse_operator<'a>() -> impl Parser<&'a str, Output = Operator> { - let comment = tag("***").map(|_| Operator::Comment); - let yes = tag("+").map(|_| Operator::Yes); - let no = tag("-").map(|_| Operator::No); + let cpvyes = tag("cpv+").map(|_: &str| Operator::Cpv(true)); + let cpvno = tag("cpv-").map(|_: &str| Operator::Cpv(false)); + let cpyes = tag("cp+").map(|_| Operator::Cp(true)); + let cpno = tag("cp-").map(|_: &str| Operator::Cp(false)); let eq = tag("=").map(|_| Operator::Eq); + let ne = tag("!=").map(|_: &str| Operator::Ne); let gt = tag(">").map(|_| Operator::Gt); let lt = tag("<").map(|_| Operator::Lt); - comment.or(yes).or(no).or(eq).or(gt).or(lt) + cpvyes + .or(cpvno) + .or(cpyes) + .or(cpno) + .or(eq) + .or(ne) + .or(gt) + .or(lt) } #[test] fn test_porthole() { for line in PORTHOLE_TXT.lines() { - if line.is_empty() { + if line.is_empty() || line.starts_with("*") { continue; } @@ -45,29 +54,62 @@ fn test_porthole() { .unwrap(); match &operator { - Operator::Comment => continue, - Operator::Yes => { - let a = Atom::parser() + Operator::Cpv(is_err) => { + let col = line.split_ascii_whitespace().nth(1).unwrap(); + + let cpv = Cpv::parser().parse_finished(InputIter::new(col)); + + match (dbg!(cpv), is_err) { + (Ok(cpv), true) => { + assert_eq!(&cpv.to_string(), col); + } + (Err(_), false) => (), + _ => { + panic!("{line}"); + } + }; + } + + Operator::Cp(is_err) => { + let col = line.split_ascii_whitespace().nth(1).unwrap(); + + let cp = Cp::parser().parse_finished(InputIter::new(col)); + + match (cp, is_err) { + (Ok(cp), true) => { + assert_eq!(&cp.to_string(), col); + } + (Err(_), false) => (), + _ => { + panic!("{line}"); + } + }; + } + + Operator::Eq | Operator::Ne => { + let a = Cpv::parser() .parse_finished(InputIter::new( line.split_ascii_whitespace().nth(1).unwrap(), )) .unwrap(); + let b = Cpv::parser() + .parse_finished(InputIter::new( + line.split_ascii_whitespace().nth(2).unwrap(), + )) + .unwrap(); + assert_eq!( - line.split_ascii_whitespace().nth(1).unwrap(), - &a.to_string() - ); - } - Operator::No => { - assert!( - Atom::parser() - .parse_finished(InputIter::new( - line.split_ascii_whitespace().nth(1).unwrap() - )) - .is_err() + a.eq(&b), + match &operator { + Operator::Eq => true, + Operator::Ne => false, + _ => unreachable!(), + } ); } - Operator::Eq | Operator::Gt | Operator::Lt => { + + Operator::Gt | Operator::Lt => { let a = Cpv::parser() .parse_finished(InputIter::new( line.split_ascii_whitespace().nth(1).unwrap(), @@ -83,7 +125,6 @@ fn test_porthole() { assert_eq!( a.partial_cmp(&b).unwrap(), match &operator { - Operator::Eq => Ordering::Equal, Operator::Gt => Ordering::Greater, Operator::Lt => Ordering::Less, _ => unreachable!(), |
