Skip to content

Commit 08310a5

Browse files
Add test for copy block code
1 parent 5c773e4 commit 08310a5

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/librustdoc/html/highlight/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ use self::whatever;
5555
let x = super::b::foo;
5656
let y = Self::whatever;";
5757

58+
let src = once(Line::Shown(Cow::Borrowed(src)));
5859
let mut html = Buffer::new();
5960
write_code(&mut html, src, Edition::Edition2018, None);
6061
expect_file!["fixtures/highlight.html"].assert_eq(&html.into_inner());
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
goto: file://|DOC_PATH|/lib2/trait.Trait.html
2+
// We set the parameter to display line numbers on code blocks.
3+
local-storage: {"rustdoc-line-numbers": "true"}
4+
// We reload the page so they're displayed.
5+
reload:
6+
wait-for: ".line-number"
7+
assert: ".top-doc .line-number"
8+
assert-text: (".top-doc .line-number", "1\n2\n3\n4")
9+
// We check that the hidden content is present
10+
assert: ".top-doc .rust-example-rendered span.hidden"
11+
assert-text: (".top-doc .rust-example-rendered span.hidden", "fn main() {\n")
12+
assert-text: (".methods .line-number", "1\n2\n3\n4\n5\n6\n7")
13+
// We unset the parameter to be sure it won't affect other tests.
14+
local-storage: {"rustdoc-line-numbers": ""}

src/test/rustdoc-gui/src/lib2/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,30 @@ impl Foo {
2525
pub fn a_method(&self) {}
2626
}
2727

28+
// This is used to ensure the line numbers are correctly set.
29+
/// ```
30+
/// # fn main() {
31+
/// let x = 12;
32+
/// let y = 13;
33+
/// # let z = 14;
34+
///
35+
/// println!("hello");
36+
/// # }
37+
/// ```
2838
pub trait Trait {
2939
type X;
3040
const Y: u32;
3141

42+
// This is used to ensure the line numbers are correctly set.
43+
/// ```
44+
/// fn main() {
45+
/// let x = 12;
46+
/// let y = 13;
47+
/// let z = 14;
48+
///
49+
/// println!("hello");
50+
/// }
51+
/// ```
3252
fn foo() {}
3353
}
3454

0 commit comments

Comments
 (0)