Skip to content

Commit 2e39d47

Browse files
committed
More tests
1 parent bb71ebb commit 2e39d47

File tree

1 file changed

+81
-39
lines changed

1 file changed

+81
-39
lines changed

crates/ide/src/doc_links.rs

Lines changed: 81 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ mod tests {
463463
use super::*;
464464

465465
#[test]
466-
fn test_doc_url_crate() {
466+
fn external_docs_doc_url_crate() {
467467
check_external_docs(
468468
r#"
469469
//- /main.rs crate:main deps:test
@@ -476,7 +476,7 @@ pub struct Foo;
476476
}
477477

478478
#[test]
479-
fn test_doc_url_struct() {
479+
fn external_docs_doc_url_struct() {
480480
check_external_docs(
481481
r#"
482482
pub struct Fo$0o;
@@ -486,7 +486,19 @@ pub struct Fo$0o;
486486
}
487487

488488
#[test]
489-
fn test_doc_url_fn() {
489+
fn external_docs_doc_url_struct_field() {
490+
check_external_docs(
491+
r#"
492+
pub struct Foo {
493+
field$0: ()
494+
}
495+
"#,
496+
expect![[r##"https://docs.rs/test/*/test/struct.Foo.html#structfield.field"##]],
497+
);
498+
}
499+
500+
#[test]
501+
fn external_docs_doc_url_fn() {
490502
check_external_docs(
491503
r#"
492504
pub fn fo$0o() {}
@@ -496,73 +508,119 @@ pub fn fo$0o() {}
496508
}
497509

498510
#[test]
499-
fn test_doc_url_inherent_method() {
511+
fn external_docs_doc_url_impl_assoc() {
500512
check_external_docs(
501513
r#"
502514
pub struct Foo;
503515
impl Foo {
504-
pub fn met$0hod() {}
516+
pub fn method$0() {}
505517
}
506518
"#,
507519
expect![[r##"https://docs.rs/test/*/test/struct.Foo.html#method.method"##]],
508520
);
521+
check_external_docs(
522+
r#"
523+
pub struct Foo;
524+
impl Foo {
525+
const CONST$0: () = ();
526+
}
527+
"#,
528+
expect![[r##"https://docs.rs/test/*/test/struct.Foo.html#associatedconstant.CONST"##]],
529+
);
509530
}
510531

511532
#[test]
512-
fn test_doc_url_impl_trait_method() {
533+
fn external_docs_doc_url_impl_trait_assoc() {
513534
check_external_docs(
514535
r#"
515536
pub struct Foo;
516537
pub trait Trait {
517-
fn met hod();
538+
fn method() {}
518539
}
519540
impl Trait for Foo {
520-
pub fn met$0hod() {}
541+
pub fn method$0() {}
521542
}
522543
"#,
523544
expect![[r##"https://docs.rs/test/*/test/struct.Foo.html#method.method"##]],
524545
);
546+
check_external_docs(
547+
r#"
548+
pub struct Foo;
549+
pub trait Trait {
550+
const CONST: () = ();
551+
}
552+
impl Trait for Foo {
553+
const CONST$0: () = ();
554+
}
555+
"#,
556+
expect![[r##"https://docs.rs/test/*/test/struct.Foo.html#associatedconstant.CONST"##]],
557+
);
558+
check_external_docs(
559+
r#"
560+
pub struct Foo;
561+
pub trait Trait {
562+
type Type;
563+
}
564+
impl Trait for Foo {
565+
type Type$0 = ();
566+
}
567+
"#,
568+
expect![[r##"https://docs.rs/test/*/test/struct.Foo.html#associatedtype.Type"##]],
569+
);
525570
}
526571

527572
#[test]
528-
fn test_doc_url_trait_required_method() {
573+
fn external_docs_doc_url_trait_assoc() {
529574
check_external_docs(
530575
r#"
531576
pub trait Foo {
532-
fn met$0hod();
577+
fn method$0();
533578
}
534579
"#,
535580
expect![[r##"https://docs.rs/test/*/test/trait.Foo.html#tymethod.method"##]],
536581
);
582+
check_external_docs(
583+
r#"
584+
pub trait Foo {
585+
const CONST$0: ();
586+
}
587+
"#,
588+
expect![[r##"https://docs.rs/test/*/test/trait.Foo.html#associatedconstant.CONST"##]],
589+
);
590+
check_external_docs(
591+
r#"
592+
pub trait Foo {
593+
type Type$0;
594+
}
595+
"#,
596+
expect![[r##"https://docs.rs/test/*/test/trait.Foo.html#associatedtype.Type"##]],
597+
);
537598
}
538599

539600
#[test]
540-
fn test_doc_url_field() {
601+
fn external_docs_trait() {
541602
check_external_docs(
542603
r#"
543-
pub struct Foo {
544-
pub fie$0ld: ()
545-
}
546-
604+
trait Trait$0 {}
547605
"#,
548-
expect![[r##"https://docs.rs/test/*/test/struct.Foo.html#structfield.field"##]],
549-
);
606+
expect![[r#"https://docs.rs/test/*/test/trait.Trait.html"#]],
607+
)
550608
}
551609

552610
#[test]
553-
fn test_module() {
611+
fn external_docs_module() {
554612
check_external_docs(
555613
r#"
556614
pub mod foo {
557615
pub mod ba$0r {}
558616
}
559-
"#,
617+
"#,
560618
expect![[r#"https://docs.rs/test/*/test/foo/bar/index.html"#]],
561619
)
562620
}
563621

564622
#[test]
565-
fn test_reexport_order() {
623+
fn external_docs_reexport_order() {
566624
check_external_docs(
567625
r#"
568626
pub mod wrapper {
@@ -603,7 +661,7 @@ trait Trait$0 {
603661
}
604662

605663
#[test]
606-
fn test_rewrite_html_root_url() {
664+
fn rewrite_html_root_url() {
607665
check_rewrite(
608666
r#"
609667
#![doc(arbitrary_attribute = "test", html_root_url = "https:/example.com", arbitrary_attribute2)]
@@ -619,7 +677,7 @@ pub struct B$0ar
619677
}
620678

621679
#[test]
622-
fn test_rewrite_on_field() {
680+
fn rewrite_on_field() {
623681
// FIXME: Should be
624682
// [Foo](https://docs.rs/test/*/test/struct.Foo.html)
625683
check_rewrite(
@@ -634,7 +692,7 @@ pub struct Foo {
634692
}
635693

636694
#[test]
637-
fn test_rewrite_struct() {
695+
fn rewrite_struct() {
638696
check_rewrite(
639697
r#"
640698
/// [Foo]
@@ -674,22 +732,6 @@ pub struct $0Foo;
674732
);
675733
}
676734

677-
#[test]
678-
fn test_rewrite() {
679-
check_rewrite(
680-
r#"
681-
pub trait Foo {
682-
fn buzz() -> usize;
683-
}
684-
/// [Foo][buzz]
685-
///
686-
/// [buzz]: Foo::buzz
687-
pub struct Bar$0;
688-
"#,
689-
expect![[r###"[Foo](https://docs.rs/test/*/test/trait.Foo.html#tymethod.buzz)"###]],
690-
)
691-
}
692-
693735
fn check_external_docs(ra_fixture: &str, expect: Expect) {
694736
let (analysis, position) = fixture::position(ra_fixture);
695737
let url = analysis.external_docs(position).unwrap().expect("could not find url for symbol");

0 commit comments

Comments
 (0)