1 use super::plain_summary_line;
2 use super::{ErrorCodes, IdMap, Ignore, LangString, Markdown, MarkdownHtml};
3 use rustc_span::edition::{Edition, DEFAULT_EDITION};
4 use std::cell::RefCell;
41 let map = RefCell::new(IdMap::new());
43 let mut map = map.borrow_mut();
44 let actual: Vec<String> = input.iter().map(|s| map.derive(s.to_string())).collect();
45 assert_eq!(&actual[..], expected);
48 map.borrow_mut().reset();
53 fn test_lang_string_parse() {
63 error_codes: Vec<String>,
64 edition: Option<Edition>,
67 LangString::parse(s, ErrorCodes::Yes, true, None),
76 original: s.to_owned(),
82 let ignore_foo = Ignore::Some(vec!["foo".to_string()]);
84 fn v() -> Vec<String> {
88 // marker | should_panic | no_run | ignore | rust | test_harness
89 // | compile_fail | allow_fail | error_codes | edition
90 t("", false, false, Ignore::None, true, false, false, false, v(), None);
91 t("rust", false, false, Ignore::None, true, false, false, false, v(), None);
92 t("sh", false, false, Ignore::None, false, false, false, false, v(), None);
93 t("ignore", false, false, Ignore::All, true, false, false, false, v(), None);
94 t("ignore-foo", false, false, ignore_foo, true, false, false, false, v(), None);
95 t("should_panic", true, false, Ignore::None, true, false, false, false, v(), None);
96 t("no_run", false, true, Ignore::None, true, false, false, false, v(), None);
97 t("test_harness", false, false, Ignore::None, true, true, false, false, v(), None);
98 t("compile_fail", false, true, Ignore::None, true, false, true, false, v(), None);
99 t("allow_fail", false, false, Ignore::None, true, false, false, true, v(), None);
100 t("{.no_run .example}", false, true, Ignore::None, true, false, false, false, v(), None);
101 t("{.sh .should_panic}", true, false, Ignore::None, false, false, false, false, v(), None);
102 t("{.example .rust}", false, false, Ignore::None, true, false, false, false, v(), None);
103 t("{.test_harness .rust}", false, false, Ignore::None, true, true, false, false, v(), None);
104 t("text, no_run", false, true, Ignore::None, false, false, false, false, v(), None);
105 t("text,no_run", false, true, Ignore::None, false, false, false, false, v(), None);
116 Some(Edition::Edition2015),
128 Some(Edition::Edition2018),
134 fn t(input: &str, expect: &str) {
135 let mut map = IdMap::new();
137 Markdown(input, &[], &mut map, ErrorCodes::Yes, DEFAULT_EDITION, &None).to_string();
138 assert_eq!(output, expect, "original: {}", input);
143 "<h1 id=\"foo-bar\" class=\"section-header\">\
144 <a href=\"#foo-bar\">Foo bar</a></h1>",
147 "## Foo-bar_baz qux",
148 "<h2 id=\"foo-bar_baz-qux\" class=\"section-\
149 header\"><a href=\"#foo-bar_baz-qux\">Foo-bar_baz qux</a></h2>",
152 "### **Foo** *bar* baz!?!& -_qux_-%",
153 "<h3 id=\"foo-bar-baz--qux-\" class=\"section-header\">\
154 <a href=\"#foo-bar-baz--qux-\"><strong>Foo</strong> \
155 <em>bar</em> baz!?!& -<em>qux</em>-%</a></h3>",
158 "#### **Foo?** & \\*bar?!* _`baz`_ ❤ #qux",
159 "<h4 id=\"foo--bar--baz--qux\" class=\"section-header\">\
160 <a href=\"#foo--bar--baz--qux\"><strong>Foo?</strong> & *bar?!* \
161 <em><code>baz</code></em> ❤ #qux</a></h4>",
166 fn test_header_ids_multiple_blocks() {
167 let mut map = IdMap::new();
168 fn t(map: &mut IdMap, input: &str, expect: &str) {
169 let output = Markdown(input, &[], map, ErrorCodes::Yes, DEFAULT_EDITION, &None).to_string();
170 assert_eq!(output, expect, "original: {}", input);
176 "<h1 id=\"example\" class=\"section-header\">\
177 <a href=\"#example\">Example</a></h1>",
182 "<h1 id=\"panics\" class=\"section-header\">\
183 <a href=\"#panics\">Panics</a></h1>",
188 "<h1 id=\"example-1\" class=\"section-header\">\
189 <a href=\"#example-1\">Example</a></h1>",
194 "<h1 id=\"main\" class=\"section-header\">\
195 <a href=\"#main\">Main</a></h1>",
200 "<h1 id=\"example-2\" class=\"section-header\">\
201 <a href=\"#example-2\">Example</a></h1>",
206 "<h1 id=\"panics-1\" class=\"section-header\">\
207 <a href=\"#panics-1\">Panics</a></h1>",
212 fn test_plain_summary_line() {
213 fn t(input: &str, expect: &str) {
214 let output = plain_summary_line(input);
215 assert_eq!(output, expect, "original: {}", input);
218 t("hello [Rust](https://www.rust-lang.org) :)", "hello Rust :)");
219 t("hello [Rust](https://www.rust-lang.org \"Rust\") :)", "hello Rust :)");
220 t("code `let x = i32;` ...", "code `let x = i32;` ...");
221 t("type `Type<'static>` ...", "type `Type<'static>` ...");
222 t("# top header", "top header");
223 t("## header", "header");
227 fn test_markdown_html_escape() {
228 fn t(input: &str, expect: &str) {
229 let mut idmap = IdMap::new();
231 MarkdownHtml(input, &mut idmap, ErrorCodes::Yes, DEFAULT_EDITION, &None).to_string();
232 assert_eq!(output, expect, "original: {}", input);
235 t("`Struct<'a, T>`", "<p><code>Struct<'a, T></code></p>\n");
236 t("Struct<'a, T>", "<p>Struct<'a, T></p>\n");
237 t("Struct<br>", "<p>Struct<br></p>\n");