Skip to content

Commit 7d6cf37

Browse files
committed
rustdoc: Extract impl doc nodes from AST
1 parent acb11f4 commit 7d6cf37

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

src/rustdoc/extract.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ fn moddoc_from_mod(
7575
ifacedoc_from_iface(methods, item.ident, item.id)
7676
))
7777
}
78+
ast::item_impl(_, _, _, methods) {
79+
some(doc::impltag(
80+
impldoc_from_impl(methods, item.ident, item.id)
81+
))
82+
}
7883
_ {
7984
none
8085
}
@@ -275,6 +280,67 @@ fn should_extract_iface_method_args() {
275280
assert doc.topmod.ifaces()[0].methods[0].args[0].name == "a";
276281
}
277282

283+
fn impldoc_from_impl(
284+
methods: [@ast::method],
285+
name: str,
286+
id: ast::node_id
287+
) -> doc::impldoc {
288+
{
289+
id: id,
290+
name: name,
291+
brief: none,
292+
desc: none,
293+
iface_ty: none,
294+
for_ty: none,
295+
methods: vec::map(methods) {|method|
296+
{
297+
name: method.ident,
298+
brief: none,
299+
desc: none,
300+
args: argdocs_from_args(method.decl.inputs),
301+
return: {
302+
desc: none,
303+
ty: none
304+
},
305+
failure: none,
306+
sig: none
307+
}
308+
}
309+
}
310+
}
311+
312+
#[test]
313+
fn should_extract_impls_with_names() {
314+
let source = "impl i for int { fn a() { } }";
315+
let ast = parse::from_str(source);
316+
let doc = extract(ast, "");
317+
assert doc.topmod.impls()[0].name == "i";
318+
}
319+
320+
#[test]
321+
fn should_extract_impls_without_names() {
322+
let source = "impl of i for int { fn a() { } }";
323+
let ast = parse::from_str(source);
324+
let doc = extract(ast, "");
325+
assert doc.topmod.impls()[0].name == "i";
326+
}
327+
328+
#[test]
329+
fn should_extract_impl_methods() {
330+
let source = "impl i for int { fn f() { } }";
331+
let ast = parse::from_str(source);
332+
let doc = extract(ast, "");
333+
assert doc.topmod.impls()[0].methods[0].name == "f";
334+
}
335+
336+
#[test]
337+
fn should_extract_impl_method_args() {
338+
let source = "impl i for int { fn f(a: bool) { } }";
339+
let ast = parse::from_str(source);
340+
let doc = extract(ast, "");
341+
assert doc.topmod.impls()[0].methods[0].args[0].name == "a";
342+
}
343+
278344
#[cfg(test)]
279345
mod tests {
280346

0 commit comments

Comments
 (0)