use super::{plain_text_summary, short_markdown_summary};
use super::{ErrorCodes, IdMap, Ignore, LangString, Markdown, MarkdownHtml};
use rustc_span::edition::{Edition, DEFAULT_EDITION};
-use std::cell::RefCell;
#[test]
fn test_unique_id() {
"assoc_type.Item-1",
];
- let map = RefCell::new(IdMap::new());
- let test = || {
- let mut map = map.borrow_mut();
- let actual: Vec<String> = input.iter().map(|s| map.derive(s.to_string())).collect();
- assert_eq!(&actual[..], expected);
- };
- test();
- map.borrow_mut().reset();
- test();
+ let mut map = IdMap::new();
+ let actual: Vec<String> = input.iter().map(|s| map.derive(s.to_string())).collect();
+ assert_eq!(&actual[..], expected);
}
#[test]
t(Default::default());
t(LangString { original: "rust".into(), ..Default::default() });
+ t(LangString { original: ".rust".into(), ..Default::default() });
+ t(LangString { original: "{rust}".into(), ..Default::default() });
+ t(LangString { original: "{.rust}".into(), ..Default::default() });
t(LangString { original: "sh".into(), rust: false, ..Default::default() });
t(LangString { original: "ignore".into(), ignore: Ignore::All, ..Default::default() });
t(LangString {
..Default::default()
});
t(LangString { original: "allow_fail".into(), allow_fail: true, ..Default::default() });
- t(LangString { original: "{.no_run .example}".into(), no_run: true, ..Default::default() });
+ t(LangString { original: "no_run,example".into(), no_run: true, ..Default::default() });
t(LangString {
- original: "{.sh .should_panic}".into(),
+ original: "sh,should_panic".into(),
should_panic: true,
rust: false,
..Default::default()
});
- t(LangString { original: "{.example .rust}".into(), ..Default::default() });
+ t(LangString { original: "example,rust".into(), ..Default::default() });
t(LangString {
- original: "{.test_harness .rust}".into(),
+ original: "test_harness,.rust".into(),
test_harness: true,
..Default::default()
});
rust: false,
..Default::default()
});
+ t(LangString {
+ original: "text,no_run, ".into(),
+ no_run: true,
+ rust: false,
+ ..Default::default()
+ });
+ t(LangString {
+ original: "text,no_run,".into(),
+ no_run: true,
+ rust: false,
+ ..Default::default()
+ });
t(LangString {
original: "edition2015".into(),
edition: Some(Edition::Edition2015),
});
}
+#[test]
+fn test_lang_string_tokenizer() {
+ fn case(lang_string: &str, want: &[&str]) {
+ let have = LangString::tokens(lang_string).collect::<Vec<&str>>();
+ assert_eq!(have, want, "Unexpected lang string split for `{}`", lang_string);
+ }
+
+ case("", &[]);
+ case("foo", &["foo"]);
+ case("foo,bar", &["foo", "bar"]);
+ case(".foo,.bar", &["foo", "bar"]);
+ case("{.foo,.bar}", &["foo", "bar"]);
+ case(" {.foo,.bar} ", &["foo", "bar"]);
+ case("foo bar", &["foo", "bar"]);
+ case("foo\tbar", &["foo", "bar"]);
+ case("foo\t, bar", &["foo", "bar"]);
+ case(" foo , bar ", &["foo", "bar"]);
+ case(",,foo,,bar,,", &["foo", "bar"]);
+ case("foo=bar", &["foo=bar"]);
+ case("a-b-c", &["a-b-c"]);
+ case("a_b_c", &["a_b_c"]);
+}
+
#[test]
fn test_header() {
fn t(input: &str, expect: &str) {
t("Hard-break \nsummary", "Hard-break summary");
t("hello [Rust] :)\n\n[Rust]: https://www.rust-lang.org", "hello Rust :)");
t("hello [Rust](https://www.rust-lang.org \"Rust\") :)", "hello Rust :)");
- t("code `let x = i32;` ...", "code <code>let x = i32;</code> ...");
- t("type `Type<'static>` ...", "type <code>Type<'static></code> ...");
+ t("code `let x = i32;` ...", "code <code>let x = i32;</code> …");
+ t("type `Type<'static>` ...", "type <code>Type<'static></code> …");
t("# top header", "top header");
+ t("# top header\n\nfollowed by a paragraph", "top header");
t("## header", "header");
t("first paragraph\n\nsecond paragraph", "first paragraph");
t("```\nfn main() {}\n```", "");
t("Hard-break \nsummary", "Hard-break summary");
t("hello [Rust] :)\n\n[Rust]: https://www.rust-lang.org", "hello Rust :)");
t("hello [Rust](https://www.rust-lang.org \"Rust\") :)", "hello Rust :)");
- t("code `let x = i32;` ...", "code `let x = i32;` ...");
- t("type `Type<'static>` ...", "type `Type<'static>` ...");
+ t("code `let x = i32;` ...", "code `let x = i32;` …");
+ t("type `Type<'static>` ...", "type `Type<'static>` …");
t("# top header", "top header");
+ t("# top header\n\nfollowed by some text", "top header");
t("## header", "header");
t("first paragraph\n\nsecond paragraph", "first paragraph");
t("```\nfn main() {}\n```", "");
}
t("`Struct<'a, T>`", "<p><code>Struct<'a, T></code></p>\n");
- t("Struct<'a, T>", "<p>Struct<'a, T></p>\n");
+ t("Struct<'a, T>", "<p>Struct<’a, T></p>\n");
t("Struct<br>", "<p>Struct<br></p>\n");
}