From bb71ebb985bc7869028d922d37d1edc4464e4aa8 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 20 Jul 2021 17:57:47 +0200 Subject: [PATCH] Move doc_links tests from hover to doc_links --- crates/ide/src/doc_links.rs | 72 +++++++ crates/ide/src/hover.rs | 383 ------------------------------------ 2 files changed, 72 insertions(+), 383 deletions(-) diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index ca97d67268c7..10fceda71c30 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs @@ -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( diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index e9ba825c0333..653833dd346d 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -1779,335 +1779,6 @@ fn foo() { let bar = Ba$0r; } ); } - #[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 B$0ar ); } - #[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(