Move doc_links tests from hover to doc_links

This commit is contained in:
Lukas Wirth 2021-07-20 17:57:47 +02:00
parent a35687fe1f
commit bb71ebb985
2 changed files with 72 additions and 383 deletions

View File

@ -602,6 +602,78 @@ trait Trait$0 {
)
}
#[test]
fn test_rewrite_html_root_url() {
check_rewrite(
r#"
#![doc(arbitrary_attribute = "test", html_root_url = "https:/example.com", arbitrary_attribute2)]
pub mod foo {
pub struct Foo;
}
/// [Foo](foo::Foo)
pub struct B$0ar
"#,
expect![[r#"[Foo](https://example.com/test/foo/struct.Foo.html)"#]],
);
}
#[test]
fn test_rewrite_on_field() {
// FIXME: Should be
// [Foo](https://docs.rs/test/*/test/struct.Foo.html)
check_rewrite(
r#"
pub struct Foo {
/// [Foo](struct.Foo.html)
fie$0ld: ()
}
"#,
expect![[r#"[Foo](struct.Foo.html)"#]],
);
}
#[test]
fn test_rewrite_struct() {
check_rewrite(
r#"
/// [Foo]
pub struct $0Foo;
"#,
expect![[r#"[Foo](https://docs.rs/test/*/test/struct.Foo.html)"#]],
);
check_rewrite(
r#"
/// [`Foo`]
pub struct $0Foo;
"#,
expect![[r#"[`Foo`](https://docs.rs/test/*/test/struct.Foo.html)"#]],
);
check_rewrite(
r#"
/// [Foo](struct.Foo.html)
pub struct $0Foo;
"#,
expect![[r#"[Foo](https://docs.rs/test/*/test/struct.Foo.html)"#]],
);
check_rewrite(
r#"
/// [struct Foo](struct.Foo.html)
pub struct $0Foo;
"#,
expect![[r#"[struct Foo](https://docs.rs/test/*/test/struct.Foo.html)"#]],
);
check_rewrite(
r#"
/// [my Foo][foo]
///
/// [foo]: Foo
pub struct $0Foo;
"#,
expect![[r#"[my Foo](https://docs.rs/test/*/test/struct.Foo.html)"#]],
);
}
#[test]
fn test_rewrite() {
check_rewrite(

View File

@ -1779,335 +1779,6 @@ struct Bar
);
}
#[test]
fn test_hover_path_link() {
check(
r#"
pub struct Foo;
/// [Foo](struct.Foo.html)
pub struct B$0ar
"#,
expect![[r#"
*Bar*
```rust
test
```
```rust
pub struct Bar
```
---
[Foo](https://docs.rs/test/*/test/struct.Foo.html)
"#]],
);
}
#[test]
fn test_hover_path_link_no_strip() {
check(
r#"
pub struct Foo;
/// [struct Foo](struct.Foo.html)
pub struct B$0ar
"#,
expect![[r#"
*Bar*
```rust
test
```
```rust
pub struct Bar
```
---
[struct Foo](https://docs.rs/test/*/test/struct.Foo.html)
"#]],
);
}
#[test]
fn test_hover_path_link_field() {
// FIXME: Should be
// [Foo](https://docs.rs/test/*/test/struct.Foo.html)
check(
r#"
pub struct Foo;
pub struct Bar {
/// [Foo](struct.Foo.html)
fie$0ld: ()
}
"#,
expect![[r#"
*field*
```rust
test::Bar
```
```rust
field: ()
```
---
[Foo](struct.Foo.html)
"#]],
);
}
#[test]
fn test_hover_intra_link() {
check(
r#"
pub mod foo {
pub struct Foo;
}
/// [Foo](foo::Foo)
pub struct B$0ar
"#,
expect![[r#"
*Bar*
```rust
test
```
```rust
pub struct Bar
```
---
[Foo](https://docs.rs/test/*/test/foo/struct.Foo.html)
"#]],
);
}
#[test]
fn test_hover_intra_link_html_root_url() {
check(
r#"
#![doc(arbitrary_attribute = "test", html_root_url = "https:/example.com", arbitrary_attribute2)]
pub mod foo {
pub struct Foo;
}
/// [Foo](foo::Foo)
pub struct B$0ar
"#,
expect![[r#"
*Bar*
```rust
test
```
```rust
pub struct Bar
```
---
[Foo](https://example.com/test/foo/struct.Foo.html)
"#]],
);
}
#[test]
fn test_hover_intra_link_shortlink() {
check(
r#"
pub struct Foo;
/// [Foo]
pub struct B$0ar
"#,
expect![[r#"
*Bar*
```rust
test
```
```rust
pub struct Bar
```
---
[Foo](https://docs.rs/test/*/test/struct.Foo.html)
"#]],
);
}
#[test]
fn test_hover_intra_link_shortlink_code() {
check(
r#"
pub struct Foo;
/// [`Foo`]
pub struct B$0ar
"#,
expect![[r#"
*Bar*
```rust
test
```
```rust
pub struct Bar
```
---
[`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
"#]],
);
}
#[test]
fn test_hover_intra_link_namespaced() {
check(
r#"
pub struct Foo;
fn Foo() {}
/// [Foo()]
pub struct B$0ar
"#,
expect![[r#"
*Bar*
```rust
test
```
```rust
pub struct Bar
```
---
[Foo](https://docs.rs/test/*/test/struct.Foo.html)
"#]],
);
}
#[test]
fn test_hover_intra_link_shortlink_namspaced_code() {
check(
r#"
pub struct Foo;
/// [`struct Foo`]
pub struct B$0ar
"#,
expect![[r#"
*Bar*
```rust
test
```
```rust
pub struct Bar
```
---
[`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
"#]],
);
}
#[test]
fn test_hover_intra_link_shortlink_namspaced_code_with_at() {
check(
r#"
pub struct Foo;
/// [`struct@Foo`]
pub struct B$0ar
"#,
expect![[r#"
*Bar*
```rust
test
```
```rust
pub struct Bar
```
---
[`Foo`](https://docs.rs/test/*/test/struct.Foo.html)
"#]],
);
}
#[test]
fn test_hover_intra_link_reference() {
check(
r#"
pub struct Foo;
/// [my Foo][foo]
///
/// [foo]: Foo
pub struct B$0ar
"#,
expect![[r#"
*Bar*
```rust
test
```
```rust
pub struct Bar
```
---
[my Foo](https://docs.rs/test/*/test/struct.Foo.html)
"#]],
);
}
#[test]
fn test_hover_intra_link_reference_to_trait_method() {
check(
r#"
pub trait Foo {
fn buzz() -> usize;
}
/// [Foo][buzz]
///
/// [buzz]: Foo::buzz
pub struct B$0ar
"#,
expect![[r##"
*Bar*
```rust
test
```
```rust
pub struct Bar
```
---
[Foo](https://docs.rs/test/*/test/trait.Foo.html#tymethod.buzz)
"##]],
);
}
#[test]
fn test_hover_external_url() {
check(
@ -2161,60 +1832,6 @@ pub struct Bar
);
}
#[test]
fn test_doc_links_enum_variant() {
check(
r#"
enum E {
/// [E]
V$0 { field: i32 }
}
"#,
expect![[r#"
*V*
```rust
test::E
```
```rust
V { field: i32 }
```
---
[E](https://docs.rs/test/*/test/enum.E.html)
"#]],
);
}
#[test]
fn test_doc_links_field() {
check(
r#"
struct S {
/// [`S`]
field$0: i32
}
"#,
expect![[r#"
*field*
```rust
test::S
```
```rust
field: i32
```
---
[`S`](https://docs.rs/test/*/test/struct.S.html)
"#]],
);
}
#[test]
fn test_hover_no_links() {
check_hover_no_links(