1
Fork 0

rustdoc: Extract doc nodes for native mods

This commit is contained in:
Brian Anderson 2012-02-24 13:50:40 -08:00
parent ba173d8409
commit fdea1c414c
3 changed files with 45 additions and 2 deletions

View file

@ -57,6 +57,11 @@ fn moddoc_from_mod(
moddoc_from_mod(itemdoc, m)
))
}
ast::item_native_mod(nm) {
some(doc::nmodtag(
nmoddoc_from_mod(itemdoc, nm)
))
}
ast::item_fn(decl, _, _) {
some(doc::fntag(
fndoc_from_fn(itemdoc, decl)
@ -100,6 +105,23 @@ fn moddoc_from_mod(
}
}
fn nmoddoc_from_mod(
itemdoc: doc::itemdoc,
module: ast::native_mod
) -> doc::nmoddoc {
{
item: itemdoc,
fns: vec::map(module.items) {|item|
let itemdoc = mk_itemdoc(item.id, item.ident);
alt item.node {
ast::native_item_fn(decl, _) {
fndoc_from_fn(itemdoc, decl)
}
}
}
}
}
fn fndoc_from_fn(
itemdoc: doc::itemdoc,
decl: ast::fn_decl
@ -341,6 +363,18 @@ mod test {
assert doc.topmod.mods()[0].mods()[1].name() == "c";
}
#[test]
fn extract_native_mods() {
let doc = mk_doc("native mod a { }");
assert doc.topmod.nmods()[0].name() == "a";
}
#[test]
fn extract_fns_from_native_mods() {
let doc = mk_doc("native mod a { fn a(); }");
assert doc.topmod.nmods()[0].fns[0].name() == "a";
}
#[test]
fn extract_mods_deep() {
let doc = mk_doc("mod a { mod b { mod c { } } }");