Skip to content

Commit 3a0727e

Browse files
Add more tests for doc aliases
1 parent cf41b1d commit 3a0727e

File tree

2 files changed

+317
-0
lines changed

2 files changed

+317
-0
lines changed

src/test/rustdoc-js/doc-alias.js

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
// exact-check
2+
3+
const QUERY = [
4+
'StructItem',
5+
'StructFieldItem',
6+
'StructMethodItem',
7+
'ImplTraitItem',
8+
'ImplAssociatedConstItem',
9+
'ImplTraitFunction',
10+
'EnumItem',
11+
'VariantItem',
12+
'EnumMethodItem',
13+
'TypedefItem',
14+
'TraitItem',
15+
'TraitTypeItem',
16+
'AssociatedConstItem',
17+
'TraitFunctionItem',
18+
'FunctionItem',
19+
'ModuleItem',
20+
'ConstItem',
21+
'StaticItem',
22+
'UnionItem',
23+
'UnionFieldItem',
24+
'UnionMethodItem',
25+
'MacroItem',
26+
];
27+
28+
const EXPECTED = [
29+
{
30+
'others': [
31+
{
32+
'path': 'doc_alias',
33+
'name': 'Struct',
34+
'alias': 'StructItem',
35+
'href': '../doc_alias/struct.Struct.html'
36+
},
37+
],
38+
},
39+
{
40+
'others': [
41+
{
42+
'path': 'doc_alias::Struct',
43+
'name': 'field',
44+
'alias': 'StructFieldItem',
45+
'href': '../doc_alias/struct.Struct.html#structfield.field'
46+
},
47+
],
48+
},
49+
{
50+
'others': [
51+
{
52+
'path': 'doc_alias::Struct',
53+
'name': 'method',
54+
'alias': 'StructMethodItem',
55+
'href': '../doc_alias/struct.Struct.html#method.method'
56+
},
57+
],
58+
},
59+
{
60+
// ImplTraitItem
61+
'others': [],
62+
},
63+
{
64+
// ImplAssociatedConstItem
65+
'others': [],
66+
},
67+
{
68+
// ImplTraitFunction
69+
'others': [],
70+
},
71+
{
72+
'others': [
73+
{
74+
'path': 'doc_alias',
75+
'name': 'Enum',
76+
'alias': 'EnumItem',
77+
'href': '../doc_alias/enum.Enum.html'
78+
},
79+
],
80+
},
81+
{
82+
'others': [
83+
{
84+
'path': 'doc_alias::Enum',
85+
'name': 'Variant',
86+
'alias': 'VariantItem',
87+
'href': '../doc_alias/enum.Enum.html#variant.Variant'
88+
},
89+
],
90+
},
91+
{
92+
'others': [
93+
{
94+
'path': 'doc_alias::Enum',
95+
'name': 'method',
96+
'alias': 'EnumMethodItem',
97+
'href': '../doc_alias/enum.Enum.html#method.method'
98+
},
99+
],
100+
},
101+
{
102+
'others': [
103+
{
104+
'path': 'doc_alias',
105+
'name': 'Typedef',
106+
'alias': 'TypedefItem',
107+
'href': '../doc_alias/type.Typedef.html'
108+
},
109+
],
110+
},
111+
{
112+
'others': [
113+
{
114+
'path': 'doc_alias',
115+
'name': 'Trait',
116+
'alias': 'TraitItem',
117+
'href': '../doc_alias/trait.Trait.html'
118+
},
119+
],
120+
},
121+
{
122+
'others': [
123+
{
124+
'path': 'doc_alias::Trait',
125+
'name': 'Target',
126+
'alias': 'TraitTypeItem',
127+
'href': '../doc_alias/trait.Trait.html#associatedtype.Target'
128+
},
129+
],
130+
},
131+
{
132+
'others': [
133+
{
134+
'path': 'doc_alias::Trait',
135+
'name': 'AssociatedConst',
136+
'alias': 'AssociatedConstItem',
137+
'href': '../doc_alias/trait.Trait.html#associatedconstant.AssociatedConst'
138+
},
139+
],
140+
},
141+
{
142+
'others': [
143+
{
144+
'path': 'doc_alias::Trait',
145+
'name': 'function',
146+
'alias': 'TraitFunctionItem',
147+
'href': '../doc_alias/trait.Trait.html#tymethod.function'
148+
},
149+
],
150+
},
151+
{
152+
'others': [
153+
{
154+
'path': 'doc_alias',
155+
'name': 'function',
156+
'alias': 'FunctionItem',
157+
'href': '../doc_alias/fn.function.html'
158+
},
159+
],
160+
},
161+
{
162+
'others': [
163+
{
164+
'path': 'doc_alias',
165+
'name': 'Module',
166+
'alias': 'ModuleItem',
167+
'href': '../doc_alias/Module/index.html'
168+
},
169+
],
170+
},
171+
{
172+
'others': [
173+
{
174+
'path': 'doc_alias',
175+
'name': 'Const',
176+
'alias': 'ConstItem',
177+
'href': '../doc_alias/constant.Const.html'
178+
},
179+
],
180+
},
181+
{
182+
'others': [
183+
{
184+
'path': 'doc_alias',
185+
'name': 'Static',
186+
'alias': 'StaticItem',
187+
'href': '../doc_alias/static.Static.html'
188+
},
189+
],
190+
},
191+
{
192+
'others': [
193+
{
194+
'path': 'doc_alias',
195+
'name': 'Union',
196+
'alias': 'UnionItem',
197+
'href': '../doc_alias/union.Union.html'
198+
},
199+
// Not an alias!
200+
{
201+
'path': 'doc_alias::Union',
202+
'name': 'union_item',
203+
'href': '../doc_alias/union.Union.html#structfield.union_item'
204+
},
205+
],
206+
},
207+
{
208+
'others': [
209+
{
210+
'path': 'doc_alias::Union',
211+
'name': 'union_item',
212+
'alias': 'UnionFieldItem',
213+
'href': '../doc_alias/union.Union.html#structfield.union_item'
214+
},
215+
],
216+
},
217+
{
218+
'others': [
219+
{
220+
'path': 'doc_alias::Union',
221+
'name': 'method',
222+
'alias': 'UnionMethodItem',
223+
'href': '../doc_alias/union.Union.html#method.method'
224+
},
225+
],
226+
},
227+
{
228+
'others': [
229+
{
230+
'path': 'doc_alias',
231+
'name': 'Macro',
232+
'alias': 'MacroItem',
233+
'href': '../doc_alias/macro.Macro.html'
234+
},
235+
],
236+
},
237+
];

src/test/rustdoc-js/doc-alias.rs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#![feature(doc_alias)]
2+
3+
#[doc(alias = "StructItem")]
4+
pub struct Struct {
5+
#[doc(alias = "StructFieldItem")]
6+
pub field: u32,
7+
}
8+
9+
impl Struct {
10+
#[doc(alias = "StructMethodItem")]
11+
pub fn method(&self) {}
12+
}
13+
14+
impl Trait for Struct {
15+
// Shouldn't be listed in aliases!
16+
#[doc(alias = "ImplTraitItem")]
17+
type Target = u32;
18+
// Shouldn't be listed in aliases!
19+
#[doc(alias = "ImplAssociatedConstItem")]
20+
const AssociatedConst: i32 = 12;
21+
22+
// Shouldn't be listed in aliases!
23+
#[doc(alias = "ImplTraitFunction")]
24+
fn function() -> Self::Target { 0 }
25+
}
26+
27+
#[doc(alias = "EnumItem")]
28+
pub enum Enum {
29+
#[doc(alias = "VariantItem")]
30+
Variant,
31+
}
32+
33+
impl Enum {
34+
#[doc(alias = "EnumMethodItem")]
35+
pub fn method(&self) {}
36+
}
37+
38+
#[doc(alias = "TypedefItem")]
39+
pub type Typedef = i32;
40+
41+
#[doc(alias = "TraitItem")]
42+
pub trait Trait {
43+
#[doc(alias = "TraitTypeItem")]
44+
type Target;
45+
#[doc(alias = "AssociatedConstItem")]
46+
const AssociatedConst: i32;
47+
48+
#[doc(alias = "TraitFunctionItem")]
49+
fn function() -> Self::Target;
50+
}
51+
52+
#[doc(alias = "FunctionItem")]
53+
pub fn function() {}
54+
55+
#[doc(alias = "ModuleItem")]
56+
pub mod Module {}
57+
58+
#[doc(alias = "ConstItem")]
59+
pub const Const: u32 = 0;
60+
61+
#[doc(alias = "StaticItem")]
62+
pub static Static: u32 = 0;
63+
64+
#[doc(alias = "UnionItem")]
65+
pub union Union {
66+
#[doc(alias = "UnionFieldItem")]
67+
pub union_item: u32,
68+
pub y: f32,
69+
}
70+
71+
impl Union {
72+
#[doc(alias = "UnionMethodItem")]
73+
pub fn method(&self) {}
74+
}
75+
76+
#[doc(alias = "MacroItem")]
77+
#[macro_export]
78+
macro_rules! Macro {
79+
() => {}
80+
}

0 commit comments

Comments
 (0)