fn main() -> Result<ExitCode> { if !std::path::Path::new("tests/yaml-test-suite").is_dir() {
eprintln!("===================================================================");
eprintln!("/!\\ yaml-test-suite directory not found, Skipping tests /!\\");
eprintln!("If you intend to contribute to the library, restore the test suite.");
eprintln!("==================================================================="); return Ok(ExitCode::SUCCESS);
}
letmut arguments = Arguments::from_args(); if arguments.test_threads.is_none() {
arguments.test_threads = Some(1);
} let tests: Vec<Vec<_>> = std::fs::read_dir("tests/yaml-test-suite/src")?
.map(|entry| -> Result<_> { let entry = entry?; let tests = load_tests_from_file(&entry)?;
Ok(tests)
})
.collect::<Result<_>>()?; let tests: Vec<_> = tests.into_iter().flatten().collect();
fn load_tests_from_file(entry: &DirEntry) -> Result<Vec<Trial>> { let file_name = entry.file_name().to_string_lossy().to_string(); let test_name = file_name
.strip_suffix(".yaml")
.ok_or("unexpected filename")?; let tests = YamlLoader::load_from_str(&fs::read_to_string(entry.path())?)?; let tests = tests[0].as_vec().ok_or("no test list found in file")?;
letmut result = vec![]; letmut current_test = yaml::Hash::new(); for (idx, test_data) in tests.iter().enumerate() { let name = if tests.len() > 1 {
format!("{test_name}-{idx:02}")
} else {
test_name.to_string()
};
// Test fields except `fail` are "inherited" let test_data = test_data.as_hash().unwrap();
current_test.remove(&Yaml::String("fail".into())); for (key, value) in test_data.clone() {
current_test.insert(key, value);
}
let current_test = Yaml::Hash(current_test.clone()); // Much better indexing
if current_test["skip"] != Yaml::BadValue { continue;
}
fn events_differ(actual: &[String], expected: &str) -> Option<String> { let actual = actual.iter().map(Some).chain(std::iter::repeat(None)); let expected = expected_events(expected); let expected = expected.iter().map(Some).chain(std::iter::repeat(None)); for (idx, (act, exp)) in actual.zip(expected).enumerate() { returnmatch (act, exp) {
(Some(act), Some(exp)) => { if act == exp { continue;
} else {
Some(format!( "line {idx} differs: \n=> expected `{exp}`\n=> found `{act}`",
))
}
}
(Some(a), None) => Some(format!("extra actual line: {a:?}")),
(None, Some(e)) => Some(format!("extra expected line: {e:?}")),
(None, None) => None,
};
}
unreachable!()
}
/// Convert the snippets from "visual" to "actual" representation fn visual_to_raw(yaml: &str) -> String { letmut yaml = yaml.to_owned(); for (pat, replacement) in [
("␣", " "),
("»", "\t"),
("—", ""), // Tab line continuation ——»
("←", "\r"),
("⇔", "\u{FEFF}"),
("↵", ""), // Trailing newline marker
("∎\n", ""),
] {
yaml = yaml.replace(pat, replacement);
}
yaml
}
/// Adapt the expectations to the yaml-rust reasonable limitations /// /// Drop information on node styles (flow/block) and anchor names. /// Both are things that can be omitted according to spec. fn expected_events(expected_tree: &str) -> Vec<String> { letmut anchors = vec![];
expected_tree
.split('\n')
.map(|s| s.trim_start().to_owned())
.filter(|s| !s.is_empty())
.map(|mut s| { // Anchor name-to-number conversion iflet Some(start) = s.find('&') { if s[..start].find(':').is_none() { let len = s[start..].find(' ').unwrap_or(s[start..].len());
anchors.push(s[start + 1..start + len].to_owned());
s = s.replace(&s[start..start + len], &format!("&{}", anchors.len()));
}
} // Alias nodes name-to-number if s.starts_with("=ALI") { let start = s.find('*').unwrap(); let name = &s[start + 1..]; let idx = anchors
.iter()
.enumerate()
.filter(|(_, v)| v == &name)
.next_back()
.unwrap()
.0;
s = s.replace(&s[start..], &format!("*{}", idx + 1));
} // Dropping style information match &*s { "+DOC ---" => "+DOC".into(), "-DOC ..." => "-DOC".into(),
s if s.starts_with("+SEQ []") => s.replacen("+SEQ []", "+SEQ", 1),
s if s.starts_with("+MAP {}") => s.replacen("+MAP {}", "+MAP", 1),
s => s.into(),
}
})
.collect()
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.