Skip to content

Commit

Permalink
Fix tests line
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Nov 16, 2019
1 parent 7fe3b21 commit 339e29a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 38 deletions.
19 changes: 4 additions & 15 deletions Cargo.lock
Expand Up @@ -480,7 +480,7 @@ dependencies = [
"itertools 0.8.0",
"lazy_static 1.3.0",
"matches",
"pulldown-cmark 0.6.1",
"pulldown-cmark",
"quine-mc_cluskey",
"regex-syntax",
"semver",
Expand Down Expand Up @@ -1972,7 +1972,7 @@ dependencies = [
"log",
"memchr",
"open",
"pulldown-cmark 0.6.1",
"pulldown-cmark",
"regex",
"serde",
"serde_derive",
Expand All @@ -1999,7 +1999,7 @@ dependencies = [
"log",
"mdbook",
"percent-encoding 2.1.0",
"pulldown-cmark 0.6.1",
"pulldown-cmark",
"rayon",
"regex",
"reqwest",
Expand Down Expand Up @@ -2641,17 +2641,6 @@ dependencies = [
"url 2.1.0",
]

[[package]]
name = "pulldown-cmark"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77043da1282374688ee212dc44b3f37ff929431de9c9adc3053bd3cee5630357"
dependencies = [
"bitflags",
"memchr",
"unicase",
]

[[package]]
name = "pulldown-cmark"
version = "0.6.1"
Expand Down Expand Up @@ -3902,7 +3891,7 @@ name = "rustdoc"
version = "0.0.0"
dependencies = [
"minifier",
"pulldown-cmark 0.6.1",
"pulldown-cmark",
"rustc-rayon 0.3.0",
"tempfile",
]
Expand Down
39 changes: 17 additions & 22 deletions src/librustdoc/html/markdown.rs
Expand Up @@ -554,9 +554,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for Footnotes<'a, I> {
pub fn find_testable_code<T: test::Tester>(doc: &str, tests: &mut T, error_codes: ErrorCodes,
enable_per_target_ignores: bool) {
let mut parser = Parser::new(doc).into_offset_iter();
let mut nb_lines = 0;
let mut register_header = None;
let mut prev_offset = 0;
while let Some((event, offset)) = parser.next() {
match event {
Event::Start(Tag::CodeBlock(s)) => {
Expand All @@ -578,10 +576,10 @@ pub fn find_testable_code<T: test::Tester>(doc: &str, tests: &mut T, error_codes
.map(|l| map_line(l).for_code())
.collect::<Vec<Cow<'_, str>>>()
.join("\n");
nb_lines += doc[prev_offset..offset.end].lines().count();
// "+ 1" is to take into account the start of the code block
let nb_lines = doc[..offset.start].lines().count() + 1;
let line = tests.get_line() + nb_lines;
tests.add_test(text, block_info, line);
prev_offset = offset.start;
}
Event::Start(Tag::Heading(level)) => {
register_header = Some(level as u32);
Expand Down Expand Up @@ -927,8 +925,8 @@ crate fn rust_code_blocks(md: &str) -> Vec<RustCodeBlock> {
let mut code_block = None;
let mut code_start = 0;
let mut is_fenced = false;
let mut previous_offset = Range { start: 0, end: 0 };
let mut in_rust_code_block = false;
let mut previous_offset = Range { start: 0, end: 0 };
while let Some((event, offset_range)) = p.next() {
match event {
Event::Start(Tag::CodeBlock(syntax)) => {
Expand All @@ -942,35 +940,31 @@ crate fn rust_code_blocks(md: &str) -> Vec<RustCodeBlock> {
in_rust_code_block = true;
code_block = Some(offset_range.clone());

code_start = match md[offset_range.clone()].find("```") {
Some(_) => {
is_fenced = true;
offset_range.start + md[offset_range.clone()]
.lines()
.next()
.map_or(0, |x| x.len() + 1)
}
None => {
is_fenced = false;
offset_range.start
}
code_start = if !md[previous_offset.end..offset_range.start].ends_with(" ") {
is_fenced = true;
offset_range.start + md[offset_range.clone()]
.lines()
.next()
.map_or(0, |x| x.len() + 1)
} else {
is_fenced = false;
offset_range.start
};
previous_offset = Range { start: code_start, end: offset_range.end };
}
}
Event::End(Tag::CodeBlock(syntax)) if in_rust_code_block => {
in_rust_code_block = false;

let code_end = if is_fenced {
let last_len = md[previous_offset.clone()]
let last_len = md[offset_range.clone()]
.lines()
.last()
.filter(|l| l.ends_with("```"))
.map_or(0, |l| l.len());
previous_offset.end - last_len
offset_range.end - last_len
} else {
previous_offset.end
offset_range.end
};

code_blocks.push(RustCodeBlock {
is_fenced,
range: code_block.clone().unwrap(),
Expand All @@ -987,6 +981,7 @@ crate fn rust_code_blocks(md: &str) -> Vec<RustCodeBlock> {
}
_ => (),
}
previous_offset = offset_range;
}

code_blocks
Expand Down
3 changes: 2 additions & 1 deletion src/test/rustdoc-ui/invalid-syntax.stderr
Expand Up @@ -115,7 +115,8 @@ warning: could not parse code block as Rust code
LL | /// code with bad syntax
| _________^
LL | | /// \_
| |__________^
LL | | ///
| |_

error: unknown start of token: `
--> <doctest>:1:1
Expand Down

0 comments on commit 339e29a

Please sign in to comment.