Permalink
Browse files

rustdoc: Move enum docs into the item tag

  • Loading branch information...
1 parent 40cbc89 commit d56a4dd04bf6fc3017f32cd4a6b4375c52e66a9c @brson brson committed Jan 28, 2012
View
@@ -294,7 +294,7 @@ fn fold_enum_should_extract_docs() {
let srv = astsrv::mk_srv_from_str(source);
let doc = extract::from_srv(srv, "");
let fold = fold::default_seq_fold(srv);
- let doc = fold_enum(fold, doc.topmod.enums[0]);
+ let doc = fold_enum(fold, doc.topmod.enums()[0]);
assert doc.brief == some("a");
assert doc.desc == some("b");
}
@@ -305,7 +305,7 @@ fn fold_enum_should_extract_variant_docs() {
let srv = astsrv::mk_srv_from_str(source);
let doc = extract::from_srv(srv, "");
let fold = fold::default_seq_fold(srv);
- let doc = fold_enum(fold, doc.topmod.enums[0]);
+ let doc = fold_enum(fold, doc.topmod.enums()[0]);
assert doc.variants[0].desc == some("c");
}
View
@@ -106,7 +106,7 @@ fn should_execute_op_on_enum_brief() {
let doc = extract::from_srv(srv, "");
let doc = attr_pass::mk_pass()(srv, doc);
let doc = mk_pass(str::trim)(srv, doc);
- assert doc.topmod.enums[0].brief == some("a");
+ assert doc.topmod.enums()[0].brief == some("a");
}
#[test]
@@ -116,7 +116,7 @@ fn should_execute_op_on_enum_desc() {
let doc = extract::from_srv(srv, "");
let doc = attr_pass::mk_pass()(srv, doc);
let doc = mk_pass(str::trim)(srv, doc);
- assert doc.topmod.enums[0].desc == some("a");
+ assert doc.topmod.enums()[0].desc == some("a");
}
#[test]
@@ -126,7 +126,7 @@ fn should_execute_op_on_variant_desc() {
let doc = extract::from_srv(srv, "");
let doc = attr_pass::mk_pass()(srv, doc);
let doc = mk_pass(str::trim)(srv, doc);
- assert doc.topmod.enums[0].variants[0].desc == some("a");
+ assert doc.topmod.enums()[0].variants[0].desc == some("a");
}
#[test]
@@ -123,8 +123,8 @@ fn should_promote_enum_desc() {
let doc = extract::from_srv(srv, "");
let doc = attr_pass::mk_pass()(srv, doc);
let doc = run(srv, doc);
- assert doc.topmod.enums[0].brief == some("desc");
- assert doc.topmod.enums[0].desc == none;
+ assert doc.topmod.enums()[0].brief == some("desc");
+ assert doc.topmod.enums()[0].desc == none;
}
#[test]
View
@@ -23,8 +23,7 @@ type moddoc = ~{
items: [itemtag],
mods: modlist,
fns: fnlist,
- consts: constlist,
- enums: enumlist
+ consts: constlist
};
type constdoc = ~{
@@ -84,9 +83,18 @@ type resdoc = ~{
enum modlist = [moddoc];
enum constlist = [constdoc];
enum fnlist = [fndoc];
-enum enumlist = [enumdoc];
impl util for moddoc {
+
+ fn enums() -> [enumdoc] {
+ vec::filter_map(self.items) {|itemtag|
+ alt itemtag {
+ enumtag(enumdoc) { some(enumdoc) }
+ _ { none }
+ }
+ }
+ }
+
fn resources() -> [resdoc] {
vec::filter_map(self.items) {|itemtag|
alt itemtag {
View
@@ -45,6 +45,11 @@ fn moddoc_from_mod(
desc: none,
items: vec::filter_map(module.items) {|item|
alt item.node {
+ ast::item_enum(variants, _) {
+ some(doc::enumtag(
+ enumdoc_from_enum(item.ident, item.id, variants)
+ ))
+ }
ast::item_res(decl, _, _, _, _) {
some(doc::restag(
resdoc_from_resource(decl, item.ident, item.id)
@@ -88,17 +93,6 @@ fn moddoc_from_mod(
none
}
}
- }),
- enums: doc::enumlist(
- vec::filter_map(module.items) {|item|
- alt item.node {
- ast::item_enum(variants, _) {
- some(enumdoc_from_enum(item.ident, item.id, variants))
- }
- _ {
- none
- }
- }
})
}
}
@@ -200,16 +194,16 @@ fn should_extract_enums() {
let source = "enum e { v }";
let ast = parse::from_str(source);
let doc = extract(ast, "");
- assert doc.topmod.enums[0].id != 0;
- assert doc.topmod.enums[0].name == "e";
+ assert doc.topmod.enums()[0].id != 0;
+ assert doc.topmod.enums()[0].name == "e";
}
#[test]
fn should_extract_enum_variants() {
let source = "enum e { v }";
let ast = parse::from_str(source);
let doc = extract(ast, "");
- assert doc.topmod.enums[0].variants[0].name == "v";
+ assert doc.topmod.enums()[0].variants[0].name == "v";
}
fn resdoc_from_resource(
View
@@ -24,8 +24,6 @@ type fold_modlist<T> = fn~(fold: fold<T>, list: doc::modlist) -> doc::modlist;
type fold_fnlist<T> = fn~(fold: fold<T>, list: doc::fnlist) -> doc::fnlist;
type fold_constlist<T> = fn~(
fold: fold<T>, list: doc::constlist) -> doc::constlist;
-type fold_enumlist<T> = fn~(
- fold: fold<T>, list: doc::enumlist) -> doc::enumlist;
type t<T> = {
ctxt: T,
@@ -37,8 +35,7 @@ type t<T> = {
fold_res: fold_res<T>,
fold_modlist: fold_modlist<T>,
fold_fnlist: fold_fnlist<T>,
- fold_constlist: fold_constlist<T>,
- fold_enumlist: fold_enumlist<T>,
+ fold_constlist: fold_constlist<T>
};
@@ -54,8 +51,7 @@ fn mk_fold<T:copy>(
fold_res: fold_res<T>,
fold_modlist: fold_modlist<T>,
fold_fnlist: fold_fnlist<T>,
- fold_constlist: fold_constlist<T>,
- fold_enumlist: fold_enumlist<T>
+ fold_constlist: fold_constlist<T>
) -> fold<T> {
fold({
ctxt: ctxt,
@@ -67,8 +63,7 @@ fn mk_fold<T:copy>(
fold_res: fold_res,
fold_modlist: fold_modlist,
fold_fnlist: fold_fnlist,
- fold_constlist: fold_constlist,
- fold_enumlist: fold_enumlist
+ fold_constlist: fold_constlist
})
}
@@ -83,8 +78,7 @@ fn default_seq_fold<T:copy>(ctxt: T) -> fold<T> {
{|f, d| default_seq_fold_res(f, d)},
{|f, d| default_seq_fold_modlist(f, d)},
{|f, d| default_seq_fold_fnlist(f, d)},
- {|f, d| default_seq_fold_constlist(f, d)},
- {|f, d| default_seq_fold_enumlist(f, d)}
+ {|f, d| default_seq_fold_constlist(f, d)}
)
}
@@ -104,15 +98,17 @@ fn default_seq_fold_mod<T>(
~{
items: vec::map(doc.items) {|itemtag|
alt itemtag {
+ doc::enumtag(enumdoc) {
+ doc::enumtag(fold.fold_enum(fold, enumdoc))
+ }
doc::restag(resdoc) {
doc::restag(fold.fold_res(fold, resdoc))
}
}
},
mods: fold.fold_modlist(fold, doc.mods),
fns: fold.fold_fnlist(fold, doc.fns),
- consts: fold.fold_constlist(fold, doc.consts),
- enums: fold.fold_enumlist(fold, doc.enums)
+ consts: fold.fold_constlist(fold, doc.consts)
with *doc
}
}
@@ -172,15 +168,6 @@ fn default_seq_fold_constlist<T>(
})
}
-fn default_seq_fold_enumlist<T>(
- fold: fold<T>,
- list: doc::enumlist
-) -> doc::enumlist {
- doc::enumlist(vec::map(*list) {|doc|
- fold.fold_enum(fold, doc)
- })
-}
-
#[test]
fn default_fold_should_produce_same_doc() {
let source = "mod a { fn b() { } mod c { fn d() { } } }";
@@ -85,10 +85,6 @@ fn write_mod_contents(
write_const(ctxt, constdoc);
}
- for enumdoc in *doc.enums {
- write_enum(ctxt, enumdoc);
- }
-
for fndoc in *doc.fns {
write_fn(ctxt, fndoc);
}
@@ -99,6 +95,7 @@ fn write_mod_contents(
for itemtag in doc.items {
alt itemtag {
+ doc::enumtag(enumdoc) { write_enum(ctxt, enumdoc) }
doc::restag(resdoc) { write_res(ctxt, resdoc) }
}
}
@@ -25,8 +25,7 @@ fn run(
fold_res: fold_res,
fold_modlist: fold_modlist,
fold_fnlist: fold_fnlist,
- fold_constlist: fold_constlist,
- fold_enumlist: fold_enumlist
+ fold_constlist: fold_constlist
with *fold::default_seq_fold(ctxt)
});
fold.fold_crate(fold, doc)
@@ -39,6 +38,14 @@ fn fold_mod(
let doc = ~{
items: vec::filter_map(doc.items) {|itemtag|
alt itemtag {
+ doc::enumtag(enumdoc) {
+ let doc = fold.fold_enum(fold, enumdoc);
+ if fold.ctxt.have_docs {
+ some(doc::enumtag(doc))
+ } else {
+ none
+ }
+ }
doc::restag(resdoc) {
let doc = fold.fold_res(fold, resdoc);
if fold.ctxt.have_docs {
@@ -253,28 +260,14 @@ fn fold_enum(fold: fold::fold<ctxt>, doc: doc::enumdoc) -> doc::enumdoc {
ret doc;
}
-fn fold_enumlist(
- fold: fold::fold<ctxt>,
- list: doc::enumlist
-) -> doc::enumlist {
- doc::enumlist(vec::filter_map(*list) {|doc|
- let doc = fold.fold_enum(fold, doc);
- if fold.ctxt.have_docs {
- some(doc)
- } else {
- none
- }
- })
-}
-
#[test]
fn should_elide_undocumented_enums() {
let source = "enum a { b }";
let srv = astsrv::mk_srv_from_str(source);
let doc = extract::from_srv(srv, "");
let doc = attr_pass::mk_pass()(srv, doc);
let doc = run(srv, doc);
- assert vec::is_empty(*doc.topmod.enums);
+ assert vec::is_empty(doc.topmod.enums());
}
#[test]
@@ -284,7 +277,7 @@ fn should_elide_undocumented_variants() {
let doc = extract::from_srv(srv, "");
let doc = attr_pass::mk_pass()(srv, doc);
let doc = run(srv, doc);
- assert vec::is_empty(doc.topmod.enums[0].variants);
+ assert vec::is_empty(doc.topmod.enums()[0].variants);
}
#[test]
@@ -294,7 +287,7 @@ fn should_not_elide_enums_with_documented_variants() {
let doc = extract::from_srv(srv, "");
let doc = attr_pass::mk_pass()(srv, doc);
let doc = run(srv, doc);
- assert vec::is_not_empty(*doc.topmod.enums);
+ assert vec::is_not_empty(doc.topmod.enums());
}
fn fold_res(fold: fold::fold<ctxt>, doc: doc::resdoc) -> doc::resdoc {
Oops, something went wrong.

0 comments on commit d56a4dd

Please sign in to comment.