Skip to content

Commit b4e06a7

Browse files
Add regression test for item-decl highlighting
1 parent a1d4ebe commit b4e06a7

File tree

3 files changed

+98
-5
lines changed

3 files changed

+98
-5
lines changed
+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// This test ensures that the color of the items in the type decl are working as expected.
2+
define-function: (
3+
"check-colors",
4+
(
5+
theme,
6+
attr_color,
7+
trait_color,
8+
struct_color,
9+
enum_color,
10+
primitive_color,
11+
constant_color,
12+
fn_color,
13+
assoc_type_color,
14+
),
15+
[
16+
("goto", "file://" + |DOC_PATH| + "/test_docs/struct.WithGenerics.html"),
17+
("show-text", true),
18+
("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
19+
("reload"),
20+
("assert-css", (".item-decl .code-attribute", {"color": |attr_color|}, ALL)),
21+
("assert-css", (".item-decl .trait", {"color": |trait_color|}, ALL)),
22+
// We need to add `code` here because otherwise it would select the parent too.
23+
("assert-css", (".item-decl code .struct", {"color": |struct_color|}, ALL)),
24+
("assert-css", (".item-decl .enum", {"color": |enum_color|}, ALL)),
25+
("assert-css", (".item-decl .primitive", {"color": |primitive_color|}, ALL)),
26+
("goto", "file://" + |DOC_PATH| + "/test_docs/trait.TraitWithoutGenerics.html"),
27+
("assert-css", (".item-decl .constant", {"color": |constant_color|}, ALL)),
28+
("assert-css", (".item-decl .fnname", {"color": |fn_color|}, ALL)),
29+
("assert-css", (".item-decl .associatedtype", {"color": |assoc_type_color|}, ALL)),
30+
],
31+
)
32+
33+
call-function: (
34+
"check-colors",
35+
{
36+
"theme": "ayu",
37+
"attr_color": "rgb(153, 153, 153)",
38+
"trait_color": "rgb(57, 175, 215)",
39+
"struct_color": "rgb(255, 160, 165)",
40+
"enum_color": "rgb(255, 160, 165)",
41+
"primitive_color": "rgb(255, 160, 165)",
42+
"constant_color": "rgb(57, 175, 215)",
43+
"fn_color": "rgb(253, 214, 135)",
44+
"assoc_type_color": "rgb(57, 175, 215)",
45+
},
46+
)
47+
call-function: (
48+
"check-colors",
49+
{
50+
"theme": "dark",
51+
"attr_color": "rgb(153, 153, 153)",
52+
"trait_color": "rgb(183, 140, 242)",
53+
"struct_color": "rgb(45, 191, 184)",
54+
"enum_color": "rgb(45, 191, 184)",
55+
"primitive_color": "rgb(45, 191, 184)",
56+
"constant_color": "rgb(210, 153, 29)",
57+
"fn_color": "rgb(43, 171, 99)",
58+
"assoc_type_color": "rgb(210, 153, 29)",
59+
},
60+
)
61+
call-function: (
62+
"check-colors",
63+
{
64+
"theme": "light",
65+
"attr_color": "rgb(153, 153, 153)",
66+
"trait_color": "rgb(110, 79, 201)",
67+
"struct_color": "rgb(173, 55, 138)",
68+
"enum_color": "rgb(173, 55, 138)",
69+
"primitive_color": "rgb(173, 55, 138)",
70+
"constant_color": "rgb(56, 115, 173)",
71+
"fn_color": "rgb(173, 124, 55)",
72+
"assoc_type_color": "rgb(56, 115, 173)",
73+
},
74+
)

src/test/rustdoc-gui/sidebar.goml

+6-5
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ assert-text: (".sidebar-elems section ul > li:nth-child(2)", "Modules")
1919
assert-text: (".sidebar-elems section ul > li:nth-child(3)", "Macros")
2020
assert-text: (".sidebar-elems section ul > li:nth-child(4)", "Structs")
2121
assert-text: (".sidebar-elems section ul > li:nth-child(5)", "Enums")
22-
assert-text: (".sidebar-elems section ul > li:nth-child(6)", "Traits")
23-
assert-text: (".sidebar-elems section ul > li:nth-child(7)", "Functions")
24-
assert-text: (".sidebar-elems section ul > li:nth-child(8)", "Type Definitions")
25-
assert-text: (".sidebar-elems section ul > li:nth-child(9)", "Unions")
26-
assert-text: (".sidebar-elems section ul > li:nth-child(10)", "Keywords")
22+
assert-text: (".sidebar-elems section ul > li:nth-child(6)", "Constants")
23+
assert-text: (".sidebar-elems section ul > li:nth-child(7)", "Traits")
24+
assert-text: (".sidebar-elems section ul > li:nth-child(8)", "Functions")
25+
assert-text: (".sidebar-elems section ul > li:nth-child(9)", "Type Definitions")
26+
assert-text: (".sidebar-elems section ul > li:nth-child(10)", "Unions")
27+
assert-text: (".sidebar-elems section ul > li:nth-child(11)", "Keywords")
2728
assert-text: ("#structs + .item-table .item-left > a", "Foo")
2829
click: "#structs + .item-table .item-left > a"
2930

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

+18
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![crate_name = "test_docs"]
66
#![feature(rustdoc_internals)]
77
#![feature(doc_cfg)]
8+
#![feature(associated_type_defaults)]
89

910
/*!
1011
Enable the feature <span class="stab portability"><code>some-feature</code></span> to enjoy
@@ -386,3 +387,20 @@ impl TypeWithNoDocblocks {
386387
pub unsafe fn unsafe_fn() {}
387388

388389
pub fn safe_fn() {}
390+
391+
#[repr(C)]
392+
pub struct WithGenerics<T: TraitWithNoDocblocks, S = String, E = WhoLetTheDogOut, P = i8> {
393+
s: S,
394+
t: T,
395+
e: E,
396+
p: P,
397+
}
398+
399+
pub const CONST: u8 = 0;
400+
401+
pub trait TraitWithoutGenerics {
402+
const C: u8 = CONST;
403+
type T = SomeType;
404+
405+
fn foo();
406+
}

0 commit comments

Comments
 (0)