Rollup merge of #80013 - poliorcetics:rustdoc-test-refactor, r=jyn514

Refactor test_lang_string_parse to make it clearer

Follows https://github.com/rust-lang/rust/pull/79454#discussion_r540190949

A small PR made to refactor a test in rustdoc that was becoming unwieldy.

``@rustbot`` label T-rustdoc
r? ``@jyn514``
This commit is contained in:
Guillaume Gomez 2020-12-14 14:43:47 +01:00 committed by GitHub
commit 2169094ab8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -51,82 +51,77 @@ fn test_unique_id() {
#[test] #[test]
fn test_lang_string_parse() { fn test_lang_string_parse() {
fn t( fn t(lg: LangString) {
s: &str, let s = &lg.original;
should_panic: bool, assert_eq!(LangString::parse(s, ErrorCodes::Yes, true, None), lg)
no_run: bool,
ignore: Ignore,
rust: bool,
test_harness: bool,
compile_fail: bool,
allow_fail: bool,
error_codes: Vec<String>,
edition: Option<Edition>,
) {
assert_eq!(
LangString::parse(s, ErrorCodes::Yes, true, None),
LangString {
should_panic,
no_run,
ignore,
rust,
test_harness,
compile_fail,
error_codes,
original: s.to_owned(),
allow_fail,
edition,
}
)
}
let ignore_foo = Ignore::Some(vec!["foo".to_string()]);
fn v() -> Vec<String> {
Vec::new()
} }
// marker | should_panic | no_run | ignore | rust | test_harness t(LangString::all_false());
// | compile_fail | allow_fail | error_codes | edition t(LangString { original: "rust".into(), ..LangString::all_false() });
t("", false, false, Ignore::None, true, false, false, false, v(), None); t(LangString { original: "sh".into(), rust: false, ..LangString::all_false() });
t("rust", false, false, Ignore::None, true, false, false, false, v(), None); t(LangString { original: "ignore".into(), ignore: Ignore::All, ..LangString::all_false() });
t("sh", false, false, Ignore::None, false, false, false, false, v(), None); t(LangString {
t("ignore", false, false, Ignore::All, true, false, false, false, v(), None); original: "ignore-foo".into(),
t("ignore-foo", false, false, ignore_foo, true, false, false, false, v(), None); ignore: Ignore::Some(vec!["foo".to_string()]),
t("should_panic", true, false, Ignore::None, true, false, false, false, v(), None); ..LangString::all_false()
t("no_run", false, true, Ignore::None, true, false, false, false, v(), None); });
t("test_harness", false, false, Ignore::None, true, true, false, false, v(), None); t(LangString {
t("compile_fail", false, true, Ignore::None, true, false, true, false, v(), None); original: "should_panic".into(),
t("allow_fail", false, false, Ignore::None, true, false, false, true, v(), None); should_panic: true,
t("{.no_run .example}", false, true, Ignore::None, true, false, false, false, v(), None); ..LangString::all_false()
t("{.sh .should_panic}", true, false, Ignore::None, false, false, false, false, v(), None); });
t("{.example .rust}", false, false, Ignore::None, true, false, false, false, v(), None); t(LangString { original: "no_run".into(), no_run: true, ..LangString::all_false() });
t("{.test_harness .rust}", false, false, Ignore::None, true, true, false, false, v(), None); t(LangString {
t("text, no_run", false, true, Ignore::None, false, false, false, false, v(), None); original: "test_harness".into(),
t("text,no_run", false, true, Ignore::None, false, false, false, false, v(), None); test_harness: true,
t( ..LangString::all_false()
"edition2015", });
false, t(LangString {
false, original: "compile_fail".into(),
Ignore::None, no_run: true,
true, compile_fail: true,
false, ..LangString::all_false()
false, });
false, t(LangString { original: "allow_fail".into(), allow_fail: true, ..LangString::all_false() });
v(), t(LangString {
Some(Edition::Edition2015), original: "{.no_run .example}".into(),
); no_run: true,
t( ..LangString::all_false()
"edition2018", });
false, t(LangString {
false, original: "{.sh .should_panic}".into(),
Ignore::None, should_panic: true,
true, rust: false,
false, ..LangString::all_false()
false, });
false, t(LangString { original: "{.example .rust}".into(), ..LangString::all_false() });
v(), t(LangString {
Some(Edition::Edition2018), original: "{.test_harness .rust}".into(),
); test_harness: true,
..LangString::all_false()
});
t(LangString {
original: "text, no_run".into(),
no_run: true,
rust: false,
..LangString::all_false()
});
t(LangString {
original: "text,no_run".into(),
no_run: true,
rust: false,
..LangString::all_false()
});
t(LangString {
original: "edition2015".into(),
edition: Some(Edition::Edition2015),
..LangString::all_false()
});
t(LangString {
original: "edition2018".into(),
edition: Some(Edition::Edition2018),
..LangString::all_false()
});
} }
#[test] #[test]