Skip to content

Commit cc15898

Browse files
Add GUI test to ensure that negative impls are correctly sorted
1 parent d0ee71e commit cc15898

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

tests/rustdoc-gui/implementors.goml

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,45 @@
22
// have the same display than the "local" ones.
33
go-to: "file://" + |DOC_PATH| + "/implementors/trait.Whatever.html"
44
assert: "#implementors-list"
5-
// There are supposed to be two implementors listed.
6-
assert-count: ("#implementors-list .impl", 2)
5+
// There are supposed to be four implementors listed.
6+
assert-count: ("#implementors-list .impl", 4)
7+
// There are supposed to be two non-negative implementors.
8+
assert-count: ("#implementors-list .negative-marker ~ *", 2)
79
// 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-for-Struct"})
10-
assert-attribute: ("#implementors-list .impl:nth-child(1) > a.anchor", {"href": "#impl-Whatever-for-Struct"})
11-
assert: "#implementors-list .impl:nth-child(1) > .code-header"
10+
define-function: (
11+
"check-dom",
12+
[id],
13+
block {
14+
assert-attribute: (|id| + " > a.anchor", {"href": |id|})
15+
assert: |id| + " > .code-header"
16+
},
17+
)
18+
19+
call-function: ("check-dom", {"id": "#impl-Whatever-for-Struct2"})
20+
call-function: ("check-dom", {"id": "#impl-Whatever-2"})
21+
call-function: ("check-dom", {"id": "#impl-Whatever-for-Struct"})
22+
call-function: ("check-dom", {"id": "#impl-Whatever-3"})
1223

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"
24+
// Ensure that negative impl are sorted first.
25+
assert-property: (
26+
"#implementors-list > *:nth-child(1) > h3",
27+
{"textContent": "impl !Whatever for Struct2"},
28+
)
29+
assert-property: (
30+
"#implementors-list > *:nth-child(2) > h3",
31+
{"textContent": "impl !Whatever for StructToImplOnReexport"},
32+
)
33+
// Third one is the negative marker.
34+
assert-attribute: ("#implementors-list > *:nth-child(3)", {"class": "negative-marker"})
35+
// This one is a `<detail>` so the selector is a bit different.
36+
assert-property: (
37+
"#implementors-list > *:nth-child(4) section > h3",
38+
{"textContent": "impl Whatever for Struct"},
39+
)
40+
assert-property: (
41+
"#implementors-list > *:nth-child(5) > h3",
42+
{"textContent": "impl Whatever for Foo"},
43+
)
1744

1845
go-to: "file://" + |DOC_PATH| + "/test_docs/struct.HasEmptyTraits.html"
1946
compare-elements-position-near-false: (

tests/rustdoc-gui/src/lib2/implementors/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1+
#![feature(negative_impls)]
2+
13
pub trait Whatever {
24
type Foo;
35

46
fn method() {}
57
}
68

79
pub struct Struct;
10+
pub struct Struct2;
811

912
impl Whatever for Struct {
1013
type Foo = u8;
1114
}
1215

16+
impl !Whatever for Struct2 {}
17+
1318
impl http::HttpTrait for Struct {}
1419

1520
mod traits {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#![feature(doc_cfg)]
44
#![feature(doc_auto_cfg)]
5+
#![feature(negative_impls)]
56

67
pub mod another_folder;
78
pub mod another_mod;
@@ -61,6 +62,8 @@ impl implementors::Whatever for Foo {
6162
type Foo = u32;
6263
}
6364

65+
impl !implementors::Whatever for StructToImplOnReexport {}
66+
6467
#[doc(inline)]
6568
pub use implementors::TraitToReexport;
6669

0 commit comments

Comments
 (0)