Skip to content

Commit

Permalink
Add tests for "jump to definition" feature extension
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jun 17, 2022
1 parent db8d34b commit 1fa953e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/test/rustdoc-gui/source-anchor-scroll.goml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ size: (600, 800)
// We check that the scroll is at the top first.
assert-property: ("html", {"scrollTop": "0"})

click: '//a[text() = "barbar"]'
click: '//a[text() = "barbar" and @href="../../src/link_to_definition/lib.rs.html#4-6"]'
assert-property: ("html", {"scrollTop": "125"})
click: '//a[text() = "bar"]'
click: '//a[text() = "bar" and @href="../../src/link_to_definition/lib.rs.html#27-35"]'
assert-property: ("html", {"scrollTop": "166"})
click: '//a[text() = "sub_fn"]'
click: '//a[text() = "sub_fn" and @href="../../src/link_to_definition/lib.rs.html#1-3"]'
assert-property: ("html", {"scrollTop": "53"})

// We now check that clicking on lines doesn't change the scroll
Expand Down
4 changes: 2 additions & 2 deletions src/test/rustdoc/check-source-code-urls-to-def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ impl Foo {

fn babar() {}

// @has - '//a/@href' '/struct.String.html'
// @has - '//a/@href' '/string.rs.html'
// @has - '//a/@href' '/primitive.u32.html'
// @has - '//a/@href' '/primitive.str.html'
// @count - '//a[@href="../../src/foo/check-source-code-urls-to-def.rs.html#23"]' 5
// @has - '//a[@href="../../source_code/struct.SourceCode.html"]' 'source_code::SourceCode'
// @has - '//a[@href="../../src/source_code/source_code.rs.html#1"]' 'source_code::SourceCode'
pub fn foo(a: u32, b: &str, c: String, d: Foo, e: bar::Bar, f: source_code::SourceCode) {
let x = 12;
let y: Foo = Foo;
Expand Down
51 changes: 51 additions & 0 deletions src/test/rustdoc/jump-to-def-doc-links.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// compile-flags: -Zunstable-options --generate-link-to-definition

#![crate_name = "foo"]

// @has 'src/foo/jump-to-def-doc-links.rs.html'

// @has - '//a[@href="../../foo/struct.Bar.html"]' 'Bar'
// @has - '//a[@href="../../foo/struct.Foo.html"]' 'Foo'
pub struct Bar; pub struct Foo;

// @has - '//a[@href="../../foo/enum.Enum.html"]' 'Enum'
pub enum Enum {
Variant1(String),
Variant2(u8),
}

// @has - '//a[@href="../../foo/struct.Struct.html"]' 'Struct'
pub struct Struct {
pub a: u8,
b: Foo,
}

impl Struct {
pub fn foo() {}
pub fn foo2(&self) {}
fn bar() {}
fn bar(&self) {}
}

// @has - '//a[@href="../../foo/trait.Trait.html"]' 'Trait'
pub trait Trait {
fn foo();
}

impl Trait for Struct {
fn foo() {}
}

// @has - '//a[@href="../../foo/union.Union.html"]' 'Union'
pub union Union {
pub a: u16,
pub f: u32,
}

// @has - '//a[@href="../../foo/fn.bar.html"]' 'bar'
pub fn bar(b: Bar) {
let x = Foo;
}

// @has - '//a[@href="../../foo/bar/index.html"]' 'bar'
pub mod bar {}

0 comments on commit 1fa953e

Please sign in to comment.