Add tests for implementors associated types display

This commit is contained in:
Guillaume Gomez 2021-08-30 16:47:17 +02:00
parent eb91366433
commit d7159bdbad
5 changed files with 40 additions and 12 deletions

View File

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

View File

@ -1,7 +1,11 @@
pub trait Whatever {
type Foo;
fn method() {}
}
pub struct Struct;
impl Whatever for Struct {}
impl Whatever for Struct {
type Foo = u8;
}

View File

@ -38,7 +38,9 @@ impl Trait for Foo {
}
impl implementors::Whatever for Foo {}
impl implementors::Whatever for Foo {
type Foo = u32;
}
pub mod sub_mod {
/// ```txt

View File

@ -0,0 +1,13 @@
// This test ensures two things:
//
// 1. The implementors toggle are not open by default.
// 2. The "auto-collapse-implementors" setting is working as expected.
goto: file://|DOC_PATH|/implementors/trait.Whatever.html
// First, checking that they are not open by default.
assert-attribute-false: ("#implementors-list > details", {"open": ""}, ALL)
// Second, checking "auto-collapse-implementors" setting.
local-storage: {"rustdoc-auto-collapse-implementors": false}
reload:
assert-attribute: ("#implementors-list > details", {"open": ""}, ALL)

View File

@ -1,6 +1,6 @@
pub trait MyTrait {
type Assoc;
const VALUE: u32;
const VALUE: u32 = 12;
fn trait_function(&self);
fn defaulted(&self) {}
fn defaulted_override(&self) {}
@ -38,9 +38,11 @@ impl MyTrait for Vec<u8> {
}
impl MyTrait for MyStruct {
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="associatedtype.Assoc-3"]//a[@class="anchor"]/@href' #associatedtype.Assoc-3
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="associatedtype.Assoc"]//a[@class="type"]/@href' trait.MyTrait.html#associatedtype.Assoc
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="associatedtype.Assoc"]//a[@class="anchor"]/@href' #associatedtype.Assoc
type Assoc = bool;
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="associatedconstant.VALUE-3"]//a[@class="anchor"]/@href' #associatedconstant.VALUE-3
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="associatedconstant.VALUE"]//a[@class="constant"]/@href' trait.MyTrait.html#associatedconstant.VALUE
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//div[@id="associatedconstant.VALUE"]//a[@class="anchor"]/@href' #associatedconstant.VALUE
const VALUE: u32 = 20;
@ -55,3 +57,10 @@ impl MyTrait for MyStruct {
}
pub struct MyStruct;
// We check that associated items with default values aren't generated in the implementors list.
impl MyTrait for (u8, u8) {
// @!has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="associatedconstant.VALUE-4"]'
type Assoc = bool;
fn trait_function(&self) {}
}