Skip to content

Commit cb4a383

Browse files
committed
rustdoc: Extract iface doc nodes from the AST
1 parent d3aa174 commit cb4a383

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/rustdoc/extract.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ fn moddoc_from_mod(
7070
resdoc_from_resource(decl, item.ident, item.id)
7171
))
7272
}
73+
ast::item_iface(_, methods) {
74+
some(doc::ifacetag(
75+
ifacedoc_from_iface(methods, item.ident, item.id)
76+
))
77+
}
7378
_ {
7479
none
7580
}
@@ -219,6 +224,57 @@ fn should_extract_resource_args() {
219224
assert doc.topmod.resources()[0].args[0].name == "b";
220225
}
221226

227+
fn ifacedoc_from_iface(
228+
methods: [ast::ty_method],
229+
name: str,
230+
id: ast::node_id
231+
) -> doc::ifacedoc {
232+
{
233+
id: id,
234+
name: name,
235+
brief: none,
236+
desc: none,
237+
methods: vec::map(methods) {|method|
238+
{
239+
name: method.ident,
240+
brief: none,
241+
desc: none,
242+
args: argdocs_from_args(method.decl.inputs),
243+
return: {
244+
desc: none,
245+
ty: none
246+
},
247+
failure: none,
248+
sig: none
249+
}
250+
}
251+
}
252+
}
253+
254+
#[test]
255+
fn should_extract_ifaces() {
256+
let source = "iface i { fn f(); }";
257+
let ast = parse::from_str(source);
258+
let doc = extract(ast, "");
259+
assert doc.topmod.ifaces()[0].name == "i";
260+
}
261+
262+
#[test]
263+
fn should_extract_iface_methods() {
264+
let source = "iface i { fn f(); }";
265+
let ast = parse::from_str(source);
266+
let doc = extract(ast, "");
267+
assert doc.topmod.ifaces()[0].methods[0].name == "f";
268+
}
269+
270+
#[test]
271+
fn should_extract_iface_method_args() {
272+
let source = "iface i { fn f(a: bool); }";
273+
let ast = parse::from_str(source);
274+
let doc = extract(ast, "");
275+
assert doc.topmod.ifaces()[0].methods[0].args[0].name == "a";
276+
}
277+
222278
#[cfg(test)]
223279
mod tests {
224280

0 commit comments

Comments
 (0)