Skip to content

Commit 61922fe

Browse files
GuillaumeGomezMark-Simulacrum
authored andcommitted
Add tests for implementors associated types display
1 parent 938bbdb commit 61922fe

File tree

5 files changed

+40
-12
lines changed

5 files changed

+40
-12
lines changed

src/test/rustdoc-gui/implementors.goml

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
goto: file://|DOC_PATH|/implementors/trait.Whatever.html
44
assert: "#implementors-list"
55
// There are supposed to be two implementors listed.
6-
assert-count: ("#implementors-list > .impl", 2)
6+
assert-count: ("#implementors-list .impl", 2)
77
// Now we check that both implementors have an anchor, an ID and a similar DOM.
8-
assert: ("#implementors-list > .impl:nth-child(1) > a.anchor")
9-
assert-attribute: ("#implementors-list > .impl:nth-child(1)", {"id": "impl-Whatever"})
10-
assert-attribute: ("#implementors-list > .impl:nth-child(1) > a.anchor", {"href": "#impl-Whatever"})
11-
assert: "#implementors-list > .impl:nth-child(1) > .code-header.in-band"
8+
assert: ("#implementors-list .impl:nth-child(1) > a.anchor")
9+
assert-attribute: ("#implementors-list .impl:nth-child(1)", {"id": "impl-Whatever"})
10+
assert-attribute: ("#implementors-list .impl:nth-child(1) > a.anchor", {"href": "#impl-Whatever"})
11+
assert: "#implementors-list .impl:nth-child(1) > .code-header.in-band"
1212

13-
assert: ("#implementors-list > .impl:nth-child(2) > a.anchor")
14-
assert-attribute: ("#implementors-list > .impl:nth-child(2)", {"id": "impl-Whatever-1"})
15-
assert-attribute: ("#implementors-list > .impl:nth-child(2) > a.anchor", {"href": "#impl-Whatever-1"})
16-
assert: "#implementors-list > .impl:nth-child(2) > .code-header.in-band"
13+
assert: ("#implementors-list .impl:nth-child(2) > a.anchor")
14+
assert-attribute: ("#implementors-list .impl:nth-child(2)", {"id": "impl-Whatever-1"})
15+
assert-attribute: ("#implementors-list .impl:nth-child(2) > a.anchor", {"href": "#impl-Whatever-1"})
16+
assert: "#implementors-list .impl:nth-child(2) > .code-header.in-band"
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
pub trait Whatever {
2+
type Foo;
3+
24
fn method() {}
35
}
46

57
pub struct Struct;
68

7-
impl Whatever for Struct {}
9+
impl Whatever for Struct {
10+
type Foo = u8;
11+
}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ impl Trait for Foo {
3838
}
3939

4040

41-
impl implementors::Whatever for Foo {}
41+
impl implementors::Whatever for Foo {
42+
type Foo = u32;
43+
}
4244

4345
pub mod sub_mod {
4446
/// ```txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This test ensures two things:
2+
//
3+
// 1. The implementors toggle are not open by default.
4+
// 2. The "auto-collapse-implementors" setting is working as expected.
5+
goto: file://|DOC_PATH|/implementors/trait.Whatever.html
6+
7+
// First, checking that they are not open by default.
8+
assert-attribute-false: ("#implementors-list > details", {"open": ""}, ALL)
9+
10+
// Second, checking "auto-collapse-implementors" setting.
11+
local-storage: {"rustdoc-auto-collapse-implementors": false}
12+
reload:
13+
assert-attribute: ("#implementors-list > details", {"open": ""}, ALL)

src/test/rustdoc/trait-impl-items-links-and-anchors.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pub trait MyTrait {
22
type Assoc;
3-
const VALUE: u32;
3+
const VALUE: u32 = 12;
44
fn trait_function(&self);
55
fn defaulted(&self) {}
66
fn defaulted_override(&self) {}
@@ -38,9 +38,11 @@ impl MyTrait for Vec<u8> {
3838
}
3939

4040
impl MyTrait for MyStruct {
41+
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="associatedtype.Assoc-3"]//a[@class="anchor"]/@href' #associatedtype.Assoc-3
4142
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="associatedtype.Assoc"]//a[@class="type"]/@href' trait.MyTrait.html#associatedtype.Assoc
4243
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="associatedtype.Assoc"]//a[@class="anchor"]/@href' #associatedtype.Assoc
4344
type Assoc = bool;
45+
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="associatedconstant.VALUE-3"]//a[@class="anchor"]/@href' #associatedconstant.VALUE-3
4446
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="associatedconstant.VALUE"]//a[@class="constant"]/@href' trait.MyTrait.html#associatedconstant.VALUE
4547
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="associatedconstant.VALUE"]//a[@class="anchor"]/@href' #associatedconstant.VALUE
4648
const VALUE: u32 = 20;
@@ -55,3 +57,10 @@ impl MyTrait for MyStruct {
5557
}
5658

5759
pub struct MyStruct;
60+
61+
// We check that associated items with default values aren't generated in the implementors list.
62+
impl MyTrait for (u8, u8) {
63+
// @!has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="associatedconstant.VALUE-4"]'
64+
type Assoc = bool;
65+
fn trait_function(&self) {}
66+
}

0 commit comments

Comments
 (0)