|
| 1 | +#[test] |
| 2 | +fn baseline() -> crate::Result { |
| 3 | + baseline::validate("basics") |
| 4 | +} |
| 5 | + |
| 6 | +mod baseline { |
| 7 | + use bstr::{BStr, ByteSlice}; |
| 8 | + use gix_attributes::StateRef; |
| 9 | + |
| 10 | + pub fn validate(name: &str) -> crate::Result { |
| 11 | + let dir = gix_testtools::scripted_fixture_read_only("make_attributes_baseline.sh")?; |
| 12 | + let repo_dir = dir.join(name); |
| 13 | + let input = std::fs::read(repo_dir.join("baseline"))?; |
| 14 | + // TODO: everything with ignorecase (tolower, expect same results) |
| 15 | + |
| 16 | + for (rela_path, attributes) in (Expectations { lines: input.lines() }) { |
| 17 | + dbg!(rela_path, attributes); |
| 18 | + } |
| 19 | + |
| 20 | + Ok(()) |
| 21 | + } |
| 22 | + |
| 23 | + pub struct Expectations<'a> { |
| 24 | + pub lines: bstr::Lines<'a>, |
| 25 | + } |
| 26 | + |
| 27 | + impl<'a> Iterator for Expectations<'a> { |
| 28 | + type Item = ( |
| 29 | + &'a BStr, |
| 30 | + // Names might refer to attributes or macros |
| 31 | + Vec<(gix_attributes::NameRef<'a>, gix_attributes::StateRef<'a>)>, |
| 32 | + ); |
| 33 | + |
| 34 | + fn next(&mut self) -> Option<Self::Item> { |
| 35 | + let path = self.lines.next()?; |
| 36 | + let mut assignments = Vec::new(); |
| 37 | + loop { |
| 38 | + let line = self.lines.next()?; |
| 39 | + if line.is_empty() { |
| 40 | + return Some((path.as_bstr(), assignments)); |
| 41 | + } |
| 42 | + |
| 43 | + let mut prev = None; |
| 44 | + let mut tokens = line.splitn(3, |b| { |
| 45 | + let is_match = *b == b' ' && prev.take() == Some(b':'); |
| 46 | + prev = Some(*b); |
| 47 | + is_match |
| 48 | + }); |
| 49 | + |
| 50 | + if let Some(((_path, attr), info)) = tokens.next().zip(tokens.next()).zip(tokens.next()) { |
| 51 | + let state = match info { |
| 52 | + b"set" => StateRef::Set, |
| 53 | + b"unset" => StateRef::Unset, |
| 54 | + b"unspecified" => StateRef::Unspecified, |
| 55 | + _ => StateRef::Value(info.as_bstr()), |
| 56 | + }; |
| 57 | + let attr = attr.trim_end_with(|b| b == ':'); |
| 58 | + assignments.push(( |
| 59 | + gix_attributes::NameRef::try_from(attr.as_bstr()).expect("valid attributes"), |
| 60 | + state, |
| 61 | + )); |
| 62 | + } else { |
| 63 | + unreachable!("invalid line format: {line:?}", line = line.as_bstr()) |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | +} |
0 commit comments