2012-01-17 19:44:32 -06:00
|
|
|
#[doc(
|
|
|
|
brief = "The attribute parsing pass",
|
|
|
|
desc =
|
|
|
|
"Traverses the document tree, pulling relevant documention out of the \
|
|
|
|
corresponding AST nodes. The information gathered here is the basis \
|
|
|
|
of the natural-language documentation for a crate."
|
|
|
|
)];
|
|
|
|
|
2012-01-16 18:05:59 -06:00
|
|
|
import rustc::syntax::ast;
|
2012-01-16 21:39:53 -06:00
|
|
|
import rustc::middle::ast_map;
|
2012-01-16 18:05:59 -06:00
|
|
|
|
2012-01-17 18:12:50 -06:00
|
|
|
export mk_pass;
|
|
|
|
|
|
|
|
fn mk_pass() -> pass {
|
|
|
|
run
|
|
|
|
}
|
2012-01-16 18:05:59 -06:00
|
|
|
|
|
|
|
fn run(
|
2012-01-17 18:12:31 -06:00
|
|
|
srv: astsrv::srv,
|
2012-01-16 21:39:53 -06:00
|
|
|
doc: doc::cratedoc
|
2012-01-16 18:05:59 -06:00
|
|
|
) -> doc::cratedoc {
|
2012-01-16 21:39:53 -06:00
|
|
|
let fold = fold::fold({
|
2012-01-19 02:14:41 -06:00
|
|
|
fold_crate: fold_crate,
|
|
|
|
fold_mod: fold_mod,
|
2012-01-24 02:31:14 -06:00
|
|
|
fold_fn: fold_fn,
|
2012-01-25 20:23:21 -06:00
|
|
|
fold_const: fold_const,
|
2012-01-26 23:39:20 -06:00
|
|
|
fold_enum: fold_enum,
|
2012-01-30 18:25:39 -06:00
|
|
|
fold_res: fold_res,
|
|
|
|
fold_iface: fold_iface
|
2012-01-16 21:39:53 -06:00
|
|
|
with *fold::default_seq_fold(srv)
|
|
|
|
});
|
|
|
|
fold.fold_crate(fold, doc)
|
|
|
|
}
|
|
|
|
|
2012-01-18 16:30:48 -06:00
|
|
|
fn fold_crate(
|
|
|
|
fold: fold::fold<astsrv::srv>,
|
|
|
|
doc: doc::cratedoc
|
|
|
|
) -> doc::cratedoc {
|
|
|
|
|
|
|
|
let srv = fold.ctxt;
|
|
|
|
let doc = fold::default_seq_fold_crate(fold, doc);
|
|
|
|
|
|
|
|
let attrs = astsrv::exec(srv) {|ctxt|
|
|
|
|
let attrs = ctxt.ast.node.attrs;
|
|
|
|
attr_parser::parse_crate(attrs)
|
|
|
|
};
|
|
|
|
|
2012-01-30 15:05:25 -06:00
|
|
|
{
|
|
|
|
topmod: {
|
2012-01-23 18:23:08 -06:00
|
|
|
name: option::from_maybe(doc.topmod.name, attrs.name)
|
2012-01-30 15:05:25 -06:00
|
|
|
with doc.topmod
|
2012-01-18 16:30:48 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_replace_top_module_name_with_crate_name() {
|
|
|
|
let source = "#[link(name = \"bond\")];";
|
|
|
|
let srv = astsrv::mk_srv_from_str(source);
|
|
|
|
let doc = extract::from_srv(srv, "");
|
|
|
|
let fold = fold::default_seq_fold(srv);
|
|
|
|
let doc = fold_crate(fold, doc);
|
|
|
|
assert doc.topmod.name == "bond";
|
|
|
|
}
|
|
|
|
|
2012-01-24 02:38:21 -06:00
|
|
|
fn parse_item_attrs<T>(
|
|
|
|
srv: astsrv::srv,
|
|
|
|
id: doc::ast_id,
|
|
|
|
parse_attrs: fn~([ast::attribute]) -> T) -> T {
|
|
|
|
astsrv::exec(srv) {|ctxt|
|
2012-01-25 23:21:21 -06:00
|
|
|
let attrs = alt ctxt.ast_map.get(id) {
|
2012-01-24 02:38:21 -06:00
|
|
|
ast_map::node_item(item) { item.attrs }
|
2012-01-30 23:00:57 -06:00
|
|
|
_ {
|
|
|
|
fail "parse_item_attrs: not an item";
|
|
|
|
}
|
2012-01-24 02:38:21 -06:00
|
|
|
};
|
|
|
|
parse_attrs(attrs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-18 20:51:04 -06:00
|
|
|
fn fold_mod(fold: fold::fold<astsrv::srv>, doc: doc::moddoc) -> doc::moddoc {
|
|
|
|
let srv = fold.ctxt;
|
|
|
|
let attrs = if doc.id == ast::crate_node_id {
|
|
|
|
// This is the top-level mod, use the crate attributes
|
|
|
|
astsrv::exec(srv) {|ctxt|
|
|
|
|
attr_parser::parse_mod(ctxt.ast.node.attrs)
|
|
|
|
}
|
|
|
|
} else {
|
2012-01-24 02:38:21 -06:00
|
|
|
parse_item_attrs(srv, doc.id, attr_parser::parse_mod)
|
2012-01-18 20:51:04 -06:00
|
|
|
};
|
|
|
|
let doc = fold::default_seq_fold_mod(fold, doc);
|
|
|
|
ret merge_mod_attrs(doc, attrs);
|
|
|
|
|
|
|
|
fn merge_mod_attrs(
|
|
|
|
doc: doc::moddoc,
|
|
|
|
attrs: attr_parser::mod_attrs
|
|
|
|
) -> doc::moddoc {
|
2012-01-30 15:05:25 -06:00
|
|
|
{
|
2012-01-18 20:51:04 -06:00
|
|
|
brief: attrs.brief,
|
|
|
|
desc: attrs.desc
|
2012-01-30 15:05:25 -06:00
|
|
|
with doc
|
2012-01-18 20:51:04 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fold_mod_should_extract_mod_attributes() {
|
|
|
|
let source = "#[doc = \"test\"] mod a { }";
|
|
|
|
let srv = astsrv::mk_srv_from_str(source);
|
|
|
|
let doc = extract::from_srv(srv, "");
|
|
|
|
let fold = fold::default_seq_fold(srv);
|
2012-01-29 15:08:18 -06:00
|
|
|
let doc = fold_mod(fold, doc.topmod.mods()[0]);
|
2012-01-18 20:51:04 -06:00
|
|
|
assert doc.desc == some("test");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fold_mod_should_extract_top_mod_attributes() {
|
|
|
|
let source = "#[doc = \"test\"];";
|
|
|
|
let srv = astsrv::mk_srv_from_str(source);
|
|
|
|
let doc = extract::from_srv(srv, "");
|
|
|
|
let fold = fold::default_seq_fold(srv);
|
|
|
|
let doc = fold_mod(fold, doc.topmod);
|
|
|
|
assert doc.desc == some("test");
|
|
|
|
}
|
|
|
|
|
2012-01-16 21:39:53 -06:00
|
|
|
fn fold_fn(
|
2012-01-17 18:12:31 -06:00
|
|
|
fold: fold::fold<astsrv::srv>,
|
2012-01-16 21:39:53 -06:00
|
|
|
doc: doc::fndoc
|
|
|
|
) -> doc::fndoc {
|
|
|
|
|
|
|
|
let srv = fold.ctxt;
|
|
|
|
|
2012-01-24 02:38:21 -06:00
|
|
|
let attrs = parse_item_attrs(srv, doc.id, attr_parser::parse_fn);
|
2012-01-16 21:39:53 -06:00
|
|
|
ret merge_fn_attrs(doc, attrs);
|
|
|
|
|
|
|
|
fn merge_fn_attrs(
|
|
|
|
doc: doc::fndoc,
|
|
|
|
attrs: attr_parser::fn_attrs
|
|
|
|
) -> doc::fndoc {
|
2012-01-30 15:05:25 -06:00
|
|
|
ret {
|
2012-01-16 21:39:53 -06:00
|
|
|
brief: attrs.brief,
|
|
|
|
desc: attrs.desc,
|
2012-01-18 23:57:18 -06:00
|
|
|
args: merge_arg_attrs(doc.args, attrs.args),
|
2012-01-24 20:05:57 -06:00
|
|
|
return: merge_ret_attrs(doc.return, attrs.return),
|
|
|
|
failure: attrs.failure
|
2012-01-30 15:05:25 -06:00
|
|
|
with doc
|
2012-01-16 21:39:53 -06:00
|
|
|
};
|
|
|
|
}
|
2012-01-30 18:25:39 -06:00
|
|
|
}
|
2012-01-16 21:39:53 -06:00
|
|
|
|
2012-01-30 18:25:39 -06:00
|
|
|
fn merge_arg_attrs(
|
|
|
|
docs: [doc::argdoc],
|
|
|
|
attrs: [attr_parser::arg_attrs]
|
|
|
|
) -> [doc::argdoc] {
|
|
|
|
vec::map(docs) {|doc|
|
|
|
|
alt vec::find(attrs) {|attr|
|
|
|
|
attr.name == doc.name
|
|
|
|
} {
|
|
|
|
some(attr) {
|
|
|
|
{
|
|
|
|
desc: some(attr.desc)
|
|
|
|
with doc
|
2012-01-19 00:24:29 -06:00
|
|
|
}
|
|
|
|
}
|
2012-01-30 18:25:39 -06:00
|
|
|
none { doc }
|
2012-01-19 00:24:29 -06:00
|
|
|
}
|
2012-01-16 21:39:53 -06:00
|
|
|
}
|
2012-01-30 18:25:39 -06:00
|
|
|
// FIXME: Warning when documenting a non-existent arg
|
|
|
|
}
|
2012-01-16 21:39:53 -06:00
|
|
|
|
2012-01-30 18:25:39 -06:00
|
|
|
|
|
|
|
fn merge_ret_attrs(
|
|
|
|
doc: doc::retdoc,
|
|
|
|
attrs: option<str>
|
|
|
|
) -> doc::retdoc {
|
|
|
|
{
|
|
|
|
desc: attrs
|
|
|
|
with doc
|
2012-01-16 21:39:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fold_fn_should_extract_fn_attributes() {
|
|
|
|
let source = "#[doc = \"test\"] fn a() -> int { }";
|
2012-01-17 18:12:31 -06:00
|
|
|
let srv = astsrv::mk_srv_from_str(source);
|
2012-01-16 21:39:53 -06:00
|
|
|
let doc = extract::from_srv(srv, "");
|
|
|
|
let fold = fold::default_seq_fold(srv);
|
2012-01-29 14:43:21 -06:00
|
|
|
let doc = fold_fn(fold, doc.topmod.fns()[0]);
|
2012-01-16 21:39:53 -06:00
|
|
|
assert doc.desc == some("test");
|
2012-01-16 18:05:59 -06:00
|
|
|
}
|
2012-01-19 00:24:29 -06:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fold_fn_should_extract_arg_attributes() {
|
|
|
|
let source = "#[doc(args(a = \"b\"))] fn c(a: bool) { }";
|
|
|
|
let srv = astsrv::mk_srv_from_str(source);
|
|
|
|
let doc = extract::from_srv(srv, "");
|
|
|
|
let fold = fold::default_seq_fold(srv);
|
2012-01-29 14:43:21 -06:00
|
|
|
let doc = fold_fn(fold, doc.topmod.fns()[0]);
|
2012-01-19 00:24:29 -06:00
|
|
|
assert doc.args[0].desc == some("b");
|
2012-01-19 16:27:16 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fold_fn_should_extract_return_attributes() {
|
|
|
|
let source = "#[doc(return = \"what\")] fn a() -> int { }";
|
|
|
|
let srv = astsrv::mk_srv_from_str(source);
|
|
|
|
let doc = extract::from_srv(srv, "");
|
|
|
|
let doc = tystr_pass::mk_pass()(srv, doc);
|
|
|
|
let fold = fold::default_seq_fold(srv);
|
2012-01-29 14:43:21 -06:00
|
|
|
let doc = fold_fn(fold, doc.topmod.fns()[0]);
|
2012-01-19 21:14:12 -06:00
|
|
|
assert doc.return.desc == some("what");
|
2012-01-19 20:58:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fold_fn_should_preserve_sig() {
|
|
|
|
let source = "fn a() -> int { }";
|
|
|
|
let srv = astsrv::mk_srv_from_str(source);
|
|
|
|
let doc = extract::from_srv(srv, "");
|
|
|
|
let doc = tystr_pass::mk_pass()(srv, doc);
|
|
|
|
let fold = fold::default_seq_fold(srv);
|
2012-01-29 14:43:21 -06:00
|
|
|
let doc = fold_fn(fold, doc.topmod.fns()[0]);
|
2012-01-19 20:58:44 -06:00
|
|
|
assert doc.sig == some("fn a() -> int");
|
2012-01-24 02:31:14 -06:00
|
|
|
}
|
|
|
|
|
2012-01-24 20:05:57 -06:00
|
|
|
#[test]
|
|
|
|
fn fold_fn_should_extract_failure_conditions() {
|
|
|
|
let source = "#[doc(failure = \"what\")] fn a() { }";
|
|
|
|
let srv = astsrv::mk_srv_from_str(source);
|
|
|
|
let doc = extract::from_srv(srv, "");
|
|
|
|
let fold = fold::default_seq_fold(srv);
|
2012-01-29 14:43:21 -06:00
|
|
|
let doc = fold_fn(fold, doc.topmod.fns()[0]);
|
2012-01-24 20:05:57 -06:00
|
|
|
assert doc.failure == some("what");
|
|
|
|
}
|
|
|
|
|
2012-01-24 02:31:14 -06:00
|
|
|
fn fold_const(
|
|
|
|
fold: fold::fold<astsrv::srv>,
|
|
|
|
doc: doc::constdoc
|
|
|
|
) -> doc::constdoc {
|
|
|
|
let srv = fold.ctxt;
|
2012-01-29 15:22:09 -06:00
|
|
|
let attrs = parse_item_attrs(srv, doc.id, attr_parser::parse_const);
|
2012-01-24 02:31:14 -06:00
|
|
|
|
2012-01-30 15:05:25 -06:00
|
|
|
{
|
2012-01-24 02:31:14 -06:00
|
|
|
brief: attrs.brief,
|
|
|
|
desc: attrs.desc
|
2012-01-30 15:05:25 -06:00
|
|
|
with doc
|
2012-01-24 02:31:14 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fold_const_should_extract_docs() {
|
|
|
|
let source = "#[doc(brief = \"foo\", desc = \"bar\")]\
|
|
|
|
const a: bool = true;";
|
|
|
|
let srv = astsrv::mk_srv_from_str(source);
|
|
|
|
let doc = extract::from_srv(srv, "");
|
|
|
|
let fold = fold::default_seq_fold(srv);
|
2012-01-28 17:45:19 -06:00
|
|
|
let doc = fold_const(fold, doc.topmod.consts()[0]);
|
2012-01-24 02:31:14 -06:00
|
|
|
assert doc.brief == some("foo");
|
|
|
|
assert doc.desc == some("bar");
|
|
|
|
}
|
2012-01-25 20:23:21 -06:00
|
|
|
|
|
|
|
fn fold_enum(
|
|
|
|
fold: fold::fold<astsrv::srv>,
|
|
|
|
doc: doc::enumdoc
|
|
|
|
) -> doc::enumdoc {
|
|
|
|
let srv = fold.ctxt;
|
|
|
|
let attrs = parse_item_attrs(srv, doc.id, attr_parser::parse_enum);
|
|
|
|
|
2012-01-30 15:05:25 -06:00
|
|
|
{
|
2012-01-25 20:23:21 -06:00
|
|
|
brief: attrs.brief,
|
|
|
|
desc: attrs.desc,
|
|
|
|
variants: vec::map(doc.variants) {|variant|
|
|
|
|
let attrs = astsrv::exec(srv) {|ctxt|
|
2012-01-25 23:21:21 -06:00
|
|
|
alt ctxt.ast_map.get(doc.id) {
|
2012-01-25 20:23:21 -06:00
|
|
|
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
|
|
|
|
});
|
|
|
|
|
|
|
|
attr_parser::parse_variant(ast_variant.node.attrs)
|
|
|
|
}
|
2012-01-30 23:00:57 -06:00
|
|
|
_ { fail "fold_enum: undocumented invariant"; }
|
2012-01-25 20:23:21 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-30 15:05:25 -06:00
|
|
|
{
|
2012-01-25 20:23:21 -06:00
|
|
|
desc: attrs.desc
|
2012-01-30 15:05:25 -06:00
|
|
|
with variant
|
2012-01-25 20:23:21 -06:00
|
|
|
}
|
|
|
|
}
|
2012-01-30 15:05:25 -06:00
|
|
|
with doc
|
2012-01-25 20:23:21 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fold_enum_should_extract_docs() {
|
|
|
|
let source = "#[doc(brief = \"a\", desc = \"b\")]\
|
|
|
|
enum a { v }";
|
|
|
|
let srv = astsrv::mk_srv_from_str(source);
|
|
|
|
let doc = extract::from_srv(srv, "");
|
|
|
|
let fold = fold::default_seq_fold(srv);
|
2012-01-28 17:04:36 -06:00
|
|
|
let doc = fold_enum(fold, doc.topmod.enums()[0]);
|
2012-01-25 20:23:21 -06:00
|
|
|
assert doc.brief == some("a");
|
|
|
|
assert doc.desc == some("b");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fold_enum_should_extract_variant_docs() {
|
|
|
|
let source = "enum a { #[doc = \"c\"] v }";
|
|
|
|
let srv = astsrv::mk_srv_from_str(source);
|
|
|
|
let doc = extract::from_srv(srv, "");
|
|
|
|
let fold = fold::default_seq_fold(srv);
|
2012-01-28 17:04:36 -06:00
|
|
|
let doc = fold_enum(fold, doc.topmod.enums()[0]);
|
2012-01-25 20:23:21 -06:00
|
|
|
assert doc.variants[0].desc == some("c");
|
|
|
|
}
|
2012-01-26 23:39:20 -06:00
|
|
|
|
|
|
|
fn fold_res(
|
|
|
|
fold: fold::fold<astsrv::srv>,
|
|
|
|
doc: doc::resdoc
|
|
|
|
) -> doc::resdoc {
|
|
|
|
|
|
|
|
let srv = fold.ctxt;
|
|
|
|
let attrs = parse_item_attrs(srv, doc.id, attr_parser::parse_fn);
|
|
|
|
|
2012-01-30 15:05:25 -06:00
|
|
|
{
|
2012-01-26 23:39:20 -06:00
|
|
|
brief: attrs.brief,
|
|
|
|
desc: attrs.desc,
|
2012-01-27 00:14:16 -06:00
|
|
|
args: vec::map(doc.args) {|doc|
|
|
|
|
alt vec::find(attrs.args) {|attr|
|
|
|
|
attr.name == doc.name
|
|
|
|
} {
|
|
|
|
some(attr) {
|
2012-01-30 15:05:25 -06:00
|
|
|
{
|
2012-01-27 00:14:16 -06:00
|
|
|
desc: some(attr.desc)
|
2012-01-30 15:05:25 -06:00
|
|
|
with doc
|
2012-01-27 00:14:16 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
none { doc }
|
2012-01-26 23:39:20 -06:00
|
|
|
}
|
|
|
|
}
|
2012-01-30 15:05:25 -06:00
|
|
|
with doc
|
2012-01-26 23:39:20 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fold_res_should_extract_docs() {
|
|
|
|
let source = "#[doc(brief = \"a\", desc = \"b\")]\
|
|
|
|
resource r(b: bool) { }";
|
|
|
|
let srv = astsrv::mk_srv_from_str(source);
|
|
|
|
let doc = extract::from_srv(srv, "");
|
|
|
|
let fold = fold::default_seq_fold(srv);
|
2012-01-28 16:36:35 -06:00
|
|
|
let doc = fold_res(fold, doc.topmod.resources()[0]);
|
2012-01-26 23:39:20 -06:00
|
|
|
assert doc.brief == some("a");
|
|
|
|
assert doc.desc == some("b");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fold_res_should_extract_arg_docs() {
|
|
|
|
let source = "#[doc(args(a = \"b\"))]\
|
|
|
|
resource r(a: bool) { }";
|
|
|
|
let srv = astsrv::mk_srv_from_str(source);
|
|
|
|
let doc = extract::from_srv(srv, "");
|
|
|
|
let fold = fold::default_seq_fold(srv);
|
2012-01-28 16:36:35 -06:00
|
|
|
let doc = fold_res(fold, doc.topmod.resources()[0]);
|
2012-01-26 23:39:20 -06:00
|
|
|
assert doc.args[0].name == "a";
|
|
|
|
assert doc.args[0].desc == some("b");
|
2012-01-30 18:25:39 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn fold_iface(
|
|
|
|
fold: fold::fold<astsrv::srv>,
|
|
|
|
doc: doc::ifacedoc
|
|
|
|
) -> doc::ifacedoc {
|
|
|
|
let srv = fold.ctxt;
|
|
|
|
let doc = fold::default_seq_fold_iface(fold, doc);
|
|
|
|
let attrs = parse_item_attrs(srv, doc.id, attr_parser::parse_iface);
|
|
|
|
|
|
|
|
{
|
|
|
|
brief: attrs.brief,
|
|
|
|
desc: attrs.desc,
|
|
|
|
methods: merge_method_attrs(srv, doc.id, doc.methods)
|
|
|
|
with doc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn merge_method_attrs(
|
|
|
|
srv: astsrv::srv,
|
|
|
|
item_id: doc::ast_id,
|
|
|
|
docs: [doc::methoddoc]
|
|
|
|
) -> [doc::methoddoc] {
|
|
|
|
// Create an assoc list from method name to attributes
|
|
|
|
let attrs = astsrv::exec(srv) {|ctxt|
|
|
|
|
alt ctxt.ast_map.get(item_id) {
|
|
|
|
ast_map::node_item(@{
|
|
|
|
node: ast::item_iface(_, methods), _
|
|
|
|
}) {
|
|
|
|
vec::map(methods) {|method|
|
|
|
|
(method.ident, attr_parser::parse_method(method.attrs))
|
|
|
|
}
|
|
|
|
}
|
2012-01-30 23:00:57 -06:00
|
|
|
_ {
|
|
|
|
fail "Undocumented invariant in merge_method_attrs";
|
|
|
|
}
|
2012-01-30 18:25:39 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
vec::map2(docs, attrs) {|doc, attrs|
|
|
|
|
assert doc.name == tuple::first(attrs);
|
|
|
|
let attrs = tuple::second(attrs);
|
|
|
|
|
|
|
|
{
|
|
|
|
brief: attrs.brief,
|
|
|
|
desc: attrs.desc,
|
|
|
|
args: merge_arg_attrs(doc.args, attrs.args),
|
|
|
|
return: merge_ret_attrs(doc.return, attrs.return),
|
|
|
|
failure: attrs.failure
|
|
|
|
with doc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_extract_iface_docs() {
|
|
|
|
let source = "#[doc = \"whatever\"] iface i { fn a(); }";
|
|
|
|
let srv = astsrv::mk_srv_from_str(source);
|
|
|
|
let doc = extract::from_srv(srv, "");
|
|
|
|
let doc = run(srv, doc);
|
|
|
|
assert doc.topmod.ifaces()[0].desc == some("whatever");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_extract_iface_method_docs() {
|
|
|
|
let source = "iface i {\
|
|
|
|
#[doc(\
|
|
|
|
brief = \"brief\",\
|
|
|
|
desc = \"desc\",\
|
|
|
|
args(a = \"a\"),\
|
|
|
|
return = \"return\",\
|
|
|
|
failure = \"failure\")]\
|
|
|
|
fn f(a: bool) -> bool;\
|
|
|
|
}";
|
|
|
|
let srv = astsrv::mk_srv_from_str(source);
|
|
|
|
let doc = extract::from_srv(srv, "");
|
|
|
|
let doc = run(srv, doc);
|
|
|
|
assert doc.topmod.ifaces()[0].methods[0].brief == some("brief");
|
|
|
|
assert doc.topmod.ifaces()[0].methods[0].desc == some("desc");
|
|
|
|
assert doc.topmod.ifaces()[0].methods[0].args[0].desc == some("a");
|
|
|
|
assert doc.topmod.ifaces()[0].methods[0].return.desc == some("return");
|
|
|
|
assert doc.topmod.ifaces()[0].methods[0].failure == some("failure");
|
2012-01-30 23:00:57 -06:00
|
|
|
}
|