Skip to content

Commit 46e622b

Browse files
chansukepetrochenkov
authored andcommitted
Separate librustcdoc module
1 parent 638f63b commit 46e622b

File tree

6 files changed

+507
-510
lines changed

6 files changed

+507
-510
lines changed

src/librustdoc/html/markdown.rs

Lines changed: 1 addition & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,130 +1050,4 @@ fn test_unique_id() {
10501050
}
10511051

10521052
#[cfg(test)]
1053-
mod tests {
1054-
use super::{ErrorCodes, LangString, Markdown, MarkdownHtml, IdMap};
1055-
use super::plain_summary_line;
1056-
use std::cell::RefCell;
1057-
use syntax::edition::{Edition, DEFAULT_EDITION};
1058-
1059-
#[test]
1060-
fn test_lang_string_parse() {
1061-
fn t(s: &str,
1062-
should_panic: bool, no_run: bool, ignore: bool, rust: bool, test_harness: bool,
1063-
compile_fail: bool, allow_fail: bool, error_codes: Vec<String>,
1064-
edition: Option<Edition>) {
1065-
assert_eq!(LangString::parse(s, ErrorCodes::Yes), LangString {
1066-
should_panic,
1067-
no_run,
1068-
ignore,
1069-
rust,
1070-
test_harness,
1071-
compile_fail,
1072-
error_codes,
1073-
original: s.to_owned(),
1074-
allow_fail,
1075-
edition,
1076-
})
1077-
}
1078-
1079-
fn v() -> Vec<String> {
1080-
Vec::new()
1081-
}
1082-
1083-
// ignore-tidy-linelength
1084-
// marker | should_panic | no_run | ignore | rust | test_harness
1085-
// | compile_fail | allow_fail | error_codes | edition
1086-
t("", false, false, false, true, false, false, false, v(), None);
1087-
t("rust", false, false, false, true, false, false, false, v(), None);
1088-
t("sh", false, false, false, false, false, false, false, v(), None);
1089-
t("ignore", false, false, true, true, false, false, false, v(), None);
1090-
t("should_panic", true, false, false, true, false, false, false, v(), None);
1091-
t("no_run", false, true, false, true, false, false, false, v(), None);
1092-
t("test_harness", false, false, false, true, true, false, false, v(), None);
1093-
t("compile_fail", false, true, false, true, false, true, false, v(), None);
1094-
t("allow_fail", false, false, false, true, false, false, true, v(), None);
1095-
t("{.no_run .example}", false, true, false, true, false, false, false, v(), None);
1096-
t("{.sh .should_panic}", true, false, false, false, false, false, false, v(), None);
1097-
t("{.example .rust}", false, false, false, true, false, false, false, v(), None);
1098-
t("{.test_harness .rust}", false, false, false, true, true, false, false, v(), None);
1099-
t("text, no_run", false, true, false, false, false, false, false, v(), None);
1100-
t("text,no_run", false, true, false, false, false, false, false, v(), None);
1101-
t("edition2015", false, false, false, true, false, false, false, v(), Some(Edition::Edition2015));
1102-
t("edition2018", false, false, false, true, false, false, false, v(), Some(Edition::Edition2018));
1103-
}
1104-
1105-
#[test]
1106-
fn test_header() {
1107-
fn t(input: &str, expect: &str) {
1108-
let mut map = IdMap::new();
1109-
let output = Markdown(input, &[], RefCell::new(&mut map),
1110-
ErrorCodes::Yes, DEFAULT_EDITION).to_string();
1111-
assert_eq!(output, expect, "original: {}", input);
1112-
}
1113-
1114-
t("# Foo bar", "<h1 id=\"foo-bar\" class=\"section-header\">\
1115-
<a href=\"#foo-bar\">Foo bar</a></h1>");
1116-
t("## Foo-bar_baz qux", "<h2 id=\"foo-bar_baz-qux\" class=\"section-\
1117-
header\"><a href=\"#foo-bar_baz-qux\">Foo-bar_baz qux</a></h2>");
1118-
t("### **Foo** *bar* baz!?!& -_qux_-%",
1119-
"<h3 id=\"foo-bar-baz--qux-\" class=\"section-header\">\
1120-
<a href=\"#foo-bar-baz--qux-\"><strong>Foo</strong> \
1121-
<em>bar</em> baz!?!&amp; -<em>qux</em>-%</a></h3>");
1122-
t("#### **Foo?** & \\*bar?!* _`baz`_ ❤ #qux",
1123-
"<h4 id=\"foo--bar--baz--qux\" class=\"section-header\">\
1124-
<a href=\"#foo--bar--baz--qux\"><strong>Foo?</strong> &amp; *bar?!* \
1125-
<em><code>baz</code></em> ❤ #qux</a></h4>");
1126-
}
1127-
1128-
#[test]
1129-
fn test_header_ids_multiple_blocks() {
1130-
let mut map = IdMap::new();
1131-
fn t(map: &mut IdMap, input: &str, expect: &str) {
1132-
let output = Markdown(input, &[], RefCell::new(map),
1133-
ErrorCodes::Yes, DEFAULT_EDITION).to_string();
1134-
assert_eq!(output, expect, "original: {}", input);
1135-
}
1136-
1137-
t(&mut map, "# Example", "<h1 id=\"example\" class=\"section-header\">\
1138-
<a href=\"#example\">Example</a></h1>");
1139-
t(&mut map, "# Panics", "<h1 id=\"panics\" class=\"section-header\">\
1140-
<a href=\"#panics\">Panics</a></h1>");
1141-
t(&mut map, "# Example", "<h1 id=\"example-1\" class=\"section-header\">\
1142-
<a href=\"#example-1\">Example</a></h1>");
1143-
t(&mut map, "# Main", "<h1 id=\"main\" class=\"section-header\">\
1144-
<a href=\"#main\">Main</a></h1>");
1145-
t(&mut map, "# Example", "<h1 id=\"example-2\" class=\"section-header\">\
1146-
<a href=\"#example-2\">Example</a></h1>");
1147-
t(&mut map, "# Panics", "<h1 id=\"panics-1\" class=\"section-header\">\
1148-
<a href=\"#panics-1\">Panics</a></h1>");
1149-
}
1150-
1151-
#[test]
1152-
fn test_plain_summary_line() {
1153-
fn t(input: &str, expect: &str) {
1154-
let output = plain_summary_line(input);
1155-
assert_eq!(output, expect, "original: {}", input);
1156-
}
1157-
1158-
t("hello [Rust](https://www.rust-lang.org) :)", "hello Rust :)");
1159-
t("hello [Rust](https://www.rust-lang.org \"Rust\") :)", "hello Rust :)");
1160-
t("code `let x = i32;` ...", "code `let x = i32;` ...");
1161-
t("type `Type<'static>` ...", "type `Type<'static>` ...");
1162-
t("# top header", "top header");
1163-
t("## header", "header");
1164-
}
1165-
1166-
#[test]
1167-
fn test_markdown_html_escape() {
1168-
fn t(input: &str, expect: &str) {
1169-
let mut idmap = IdMap::new();
1170-
let output = MarkdownHtml(input, RefCell::new(&mut idmap),
1171-
ErrorCodes::Yes, DEFAULT_EDITION).to_string();
1172-
assert_eq!(output, expect, "original: {}", input);
1173-
}
1174-
1175-
t("`Struct<'a, T>`", "<p><code>Struct&lt;'a, T&gt;</code></p>\n");
1176-
t("Struct<'a, T>", "<p>Struct&lt;'a, T&gt;</p>\n");
1177-
t("Struct<br>", "<p>Struct&lt;br&gt;</p>\n");
1178-
}
1179-
}
1053+
mod tests;

src/librustdoc/html/markdown/tests.rs

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
use super::{ErrorCodes, LangString, Markdown, MarkdownHtml, IdMap};
2+
use super::plain_summary_line;
3+
use std::cell::RefCell;
4+
use syntax::edition::{Edition, DEFAULT_EDITION};
5+
6+
#[test]
7+
fn test_lang_string_parse() {
8+
fn t(s: &str,
9+
should_panic: bool, no_run: bool, ignore: bool, rust: bool, test_harness: bool,
10+
compile_fail: bool, allow_fail: bool, error_codes: Vec<String>,
11+
edition: Option<Edition>) {
12+
assert_eq!(LangString::parse(s, ErrorCodes::Yes), LangString {
13+
should_panic,
14+
no_run,
15+
ignore,
16+
rust,
17+
test_harness,
18+
compile_fail,
19+
error_codes,
20+
original: s.to_owned(),
21+
allow_fail,
22+
edition,
23+
})
24+
}
25+
26+
fn v() -> Vec<String> {
27+
Vec::new()
28+
}
29+
30+
// ignore-tidy-linelength
31+
// marker | should_panic | no_run | ignore | rust | test_harness
32+
// | compile_fail | allow_fail | error_codes | edition
33+
t("", false, false, false, true, false, false, false, v(), None);
34+
t("rust", false, false, false, true, false, false, false, v(), None);
35+
t("sh", false, false, false, false, false, false, false, v(), None);
36+
t("ignore", false, false, true, true, false, false, false, v(), None);
37+
t("should_panic", true, false, false, true, false, false, false, v(), None);
38+
t("no_run", false, true, false, true, false, false, false, v(), None);
39+
t("test_harness", false, false, false, true, true, false, false, v(), None);
40+
t("compile_fail", false, true, false, true, false, true, false, v(), None);
41+
t("allow_fail", false, false, false, true, false, false, true, v(), None);
42+
t("{.no_run .example}", false, true, false, true, false, false, false, v(), None);
43+
t("{.sh .should_panic}", true, false, false, false, false, false, false, v(), None);
44+
t("{.example .rust}", false, false, false, true, false, false, false, v(), None);
45+
t("{.test_harness .rust}", false, false, false, true, true, false, false, v(), None);
46+
t("text, no_run", false, true, false, false, false, false, false, v(), None);
47+
t("text,no_run", false, true, false, false, false, false, false, v(), None);
48+
t("edition2015", false, false, false, true, false, false, false, v(), Some(Edition::Edition2015));
49+
t("edition2018", false, false, false, true, false, false, false, v(), Some(Edition::Edition2018));
50+
}
51+
52+
#[test]
53+
fn test_header() {
54+
fn t(input: &str, expect: &str) {
55+
let mut map = IdMap::new();
56+
let output = Markdown(input, &[], RefCell::new(&mut map),
57+
ErrorCodes::Yes, DEFAULT_EDITION).to_string();
58+
assert_eq!(output, expect, "original: {}", input);
59+
}
60+
61+
t("# Foo bar", "<h1 id=\"foo-bar\" class=\"section-header\">\
62+
<a href=\"#foo-bar\">Foo bar</a></h1>");
63+
t("## Foo-bar_baz qux", "<h2 id=\"foo-bar_baz-qux\" class=\"section-\
64+
header\"><a href=\"#foo-bar_baz-qux\">Foo-bar_baz qux</a></h2>");
65+
t("### **Foo** *bar* baz!?!& -_qux_-%",
66+
"<h3 id=\"foo-bar-baz--qux-\" class=\"section-header\">\
67+
<a href=\"#foo-bar-baz--qux-\"><strong>Foo</strong> \
68+
<em>bar</em> baz!?!&amp; -<em>qux</em>-%</a></h3>");
69+
t("#### **Foo?** & \\*bar?!* _`baz`_ ❤ #qux",
70+
"<h4 id=\"foo--bar--baz--qux\" class=\"section-header\">\
71+
<a href=\"#foo--bar--baz--qux\"><strong>Foo?</strong> &amp; *bar?!* \
72+
<em><code>baz</code></em> ❤ #qux</a></h4>");
73+
}
74+
75+
#[test]
76+
fn test_header_ids_multiple_blocks() {
77+
let mut map = IdMap::new();
78+
fn t(map: &mut IdMap, input: &str, expect: &str) {
79+
let output = Markdown(input, &[], RefCell::new(map),
80+
ErrorCodes::Yes, DEFAULT_EDITION).to_string();
81+
assert_eq!(output, expect, "original: {}", input);
82+
}
83+
84+
t(&mut map, "# Example", "<h1 id=\"example\" class=\"section-header\">\
85+
<a href=\"#example\">Example</a></h1>");
86+
t(&mut map, "# Panics", "<h1 id=\"panics\" class=\"section-header\">\
87+
<a href=\"#panics\">Panics</a></h1>");
88+
t(&mut map, "# Example", "<h1 id=\"example-1\" class=\"section-header\">\
89+
<a href=\"#example-1\">Example</a></h1>");
90+
t(&mut map, "# Main", "<h1 id=\"main\" class=\"section-header\">\
91+
<a href=\"#main\">Main</a></h1>");
92+
t(&mut map, "# Example", "<h1 id=\"example-2\" class=\"section-header\">\
93+
<a href=\"#example-2\">Example</a></h1>");
94+
t(&mut map, "# Panics", "<h1 id=\"panics-1\" class=\"section-header\">\
95+
<a href=\"#panics-1\">Panics</a></h1>");
96+
}
97+
98+
#[test]
99+
fn test_plain_summary_line() {
100+
fn t(input: &str, expect: &str) {
101+
let output = plain_summary_line(input);
102+
assert_eq!(output, expect, "original: {}", input);
103+
}
104+
105+
t("hello [Rust](https://www.rust-lang.org) :)", "hello Rust :)");
106+
t("hello [Rust](https://www.rust-lang.org \"Rust\") :)", "hello Rust :)");
107+
t("code `let x = i32;` ...", "code `let x = i32;` ...");
108+
t("type `Type<'static>` ...", "type `Type<'static>` ...");
109+
t("# top header", "top header");
110+
t("## header", "header");
111+
}
112+
113+
#[test]
114+
fn test_markdown_html_escape() {
115+
fn t(input: &str, expect: &str) {
116+
let mut idmap = IdMap::new();
117+
let output = MarkdownHtml(input, RefCell::new(&mut idmap),
118+
ErrorCodes::Yes, DEFAULT_EDITION).to_string();
119+
assert_eq!(output, expect, "original: {}", input);
120+
}
121+
122+
t("`Struct<'a, T>`", "<p><code>Struct&lt;'a, T&gt;</code></p>\n");
123+
t("Struct<'a, T>", "<p>Struct&lt;'a, T&gt;</p>\n");
124+
t("Struct<br>", "<p>Struct&lt;br&gt;</p>\n");
125+
}

src/librustdoc/html/toc.rs

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -188,85 +188,4 @@ impl fmt::Display for Toc {
188188
}
189189

190190
#[cfg(test)]
191-
mod tests {
192-
use super::{TocBuilder, Toc, TocEntry};
193-
194-
#[test]
195-
fn builder_smoke() {
196-
let mut builder = TocBuilder::new();
197-
198-
// this is purposely not using a fancy macro like below so
199-
// that we're sure that this is doing the correct thing, and
200-
// there's been no macro mistake.
201-
macro_rules! push {
202-
($level: expr, $name: expr) => {
203-
assert_eq!(builder.push($level,
204-
$name.to_string(),
205-
"".to_string()),
206-
$name);
207-
}
208-
}
209-
push!(2, "0.1");
210-
push!(1, "1");
211-
{
212-
push!(2, "1.1");
213-
{
214-
push!(3, "1.1.1");
215-
push!(3, "1.1.2");
216-
}
217-
push!(2, "1.2");
218-
{
219-
push!(3, "1.2.1");
220-
push!(3, "1.2.2");
221-
}
222-
}
223-
push!(1, "2");
224-
push!(1, "3");
225-
{
226-
push!(4, "3.0.0.1");
227-
{
228-
push!(6, "3.0.0.1.0.1");
229-
}
230-
push!(4, "3.0.0.2");
231-
push!(2, "3.1");
232-
{
233-
push!(4, "3.1.0.1");
234-
}
235-
}
236-
237-
macro_rules! toc {
238-
($(($level: expr, $name: expr, $(($sub: tt))* )),*) => {
239-
Toc {
240-
entries: vec![
241-
$(
242-
TocEntry {
243-
level: $level,
244-
name: $name.to_string(),
245-
sec_number: $name.to_string(),
246-
id: "".to_string(),
247-
children: toc!($($sub),*)
248-
}
249-
),*
250-
]
251-
}
252-
}
253-
}
254-
let expected = toc!(
255-
(2, "0.1", ),
256-
257-
(1, "1",
258-
((2, "1.1", ((3, "1.1.1", )) ((3, "1.1.2", ))))
259-
((2, "1.2", ((3, "1.2.1", )) ((3, "1.2.2", ))))
260-
),
261-
262-
(1, "2", ),
263-
264-
(1, "3",
265-
((4, "3.0.0.1", ((6, "3.0.0.1.0.1", ))))
266-
((4, "3.0.0.2", ))
267-
((2, "3.1", ((4, "3.1.0.1", ))))
268-
)
269-
);
270-
assert_eq!(expected, builder.into_toc());
271-
}
272-
}
191+
mod tests;

0 commit comments

Comments
 (0)