rustdoc: Extract variant signatures

This commit is contained in:
Brian Anderson 2012-01-25 17:22:19 -08:00
parent b7b8455e54
commit 0b9f2a8215
2 changed files with 46 additions and 3 deletions

View File

@ -97,7 +97,8 @@ fn default_seq_fold_mod<T>(
~{
mods: fold.fold_modlist(fold, doc.mods),
fns: fold.fold_fnlist(fold, doc.fns),
consts: fold.fold_constlist(fold, doc.consts)
consts: fold.fold_constlist(fold, doc.consts),
enums: fold.fold_enumlist(fold, doc.enums)
with *doc
}
}

View File

@ -17,7 +17,8 @@ fn run(
) -> doc::cratedoc {
let fold = fold::fold({
fold_fn: fold_fn,
fold_const: fold_const
fold_const: fold_const,
fold_enum: fold_enum
with *fold::default_seq_fold(srv)
});
fold.fold_crate(fold, doc)
@ -180,3 +181,44 @@ fn should_add_const_types() {
let doc = run(srv, doc);
assert doc.topmod.consts[0].ty == some("bool");
}
fn fold_enum(
fold: fold::fold<astsrv::srv>,
doc: doc::enumdoc
) -> doc::enumdoc {
let srv = fold.ctxt;
~{
variants: vec::map(doc.variants) {|variant|
let sig = astsrv::exec(srv) {|ctxt|
alt ctxt.map.get(doc.id) {
ast_map::node_item(@{
node: ast::item_enum(ast_variants, _), _
}) {
let ast_variant = option::get(
vec::find(ast_variants) {|v|
v.node.name == variant.name
});
pprust::variant_to_str(ast_variant)
}
}
};
~{
sig: some(sig)
with *variant
}
}
with *doc
}
}
#[test]
fn should_add_variant_sigs() {
let source = "enum a { b(int) }";
let srv = astsrv::mk_srv_from_str(source);
let doc = extract::from_srv(srv, "");
let doc = run(srv, doc);
assert doc.topmod.enums[0].variants[0].sig == some("b(int)");
}