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-03-07 18:48:57 -06:00
|
|
|
import std::map::hashmap;
|
2012-01-16 18:05:59 -06:00
|
|
|
|
2012-01-17 18:12:50 -06:00
|
|
|
export mk_pass;
|
|
|
|
|
|
|
|
fn mk_pass() -> pass {
|
2012-02-27 20:07:16 -06:00
|
|
|
{
|
|
|
|
name: "attr",
|
|
|
|
f: run
|
|
|
|
}
|
2012-01-17 18:12:50 -06:00
|
|
|
}
|
2012-01-16 18:05:59 -06:00
|
|
|
|
|
|
|
fn run(
|
2012-01-17 18:12:31 -06:00
|
|
|
srv: astsrv::srv,
|
2012-03-02 20:33:25 -06:00
|
|
|
doc: doc::doc
|
|
|
|
) -> doc::doc {
|
2012-01-16 21:39:53 -06:00
|
|
|
let fold = fold::fold({
|
2012-01-19 02:14:41 -06:00
|
|
|
fold_crate: fold_crate,
|
2012-02-17 18:52:27 -06:00
|
|
|
fold_item: fold_item,
|
2012-01-24 02:31:14 -06:00
|
|
|
fold_fn: fold_fn,
|
2012-01-26 23:39:20 -06:00
|
|
|
fold_enum: fold_enum,
|
2012-01-30 18:25:39 -06:00
|
|
|
fold_res: fold_res,
|
2012-01-31 19:05:40 -06:00
|
|
|
fold_iface: fold_iface,
|
2012-02-17 18:52:27 -06:00
|
|
|
fold_impl: fold_impl
|
2012-02-21 00:24:59 -06:00
|
|
|
with *fold::default_any_fold(srv)
|
2012-01-16 21:39:53 -06:00
|
|
|
});
|
2012-03-02 20:33:25 -06:00
|
|
|
fold.fold_doc(fold, doc)
|
2012-01-16 21:39:53 -06:00
|
|
|
}
|
|
|
|
|
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-02-17 16:46:30 -06:00
|
|
|
item: {
|
|
|
|
name: option::from_maybe(doc.topmod.name(), attrs.name)
|
|
|
|
with doc.topmod.item
|
|
|
|
}
|
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() {
|
2012-01-31 20:32:37 -06:00
|
|
|
let doc = test::mk_doc("#[link(name = \"bond\")];");
|
2012-03-02 20:33:25 -06:00
|
|
|
assert doc.cratemod().name() == "bond";
|
2012-01-18 16:30:48 -06:00
|
|
|
}
|
|
|
|
|
2012-02-17 18:52:27 -06:00
|
|
|
fn fold_item(
|
|
|
|
fold: fold::fold<astsrv::srv>,
|
|
|
|
doc: doc::itemdoc
|
|
|
|
) -> doc::itemdoc {
|
|
|
|
|
|
|
|
let srv = fold.ctxt;
|
|
|
|
let doc = fold::default_seq_fold_item(fold, doc);
|
|
|
|
|
|
|
|
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_basic(ctxt.ast.node.attrs)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
parse_item_attrs(srv, doc.id, attr_parser::parse_basic)
|
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
brief: attrs.brief,
|
|
|
|
desc: attrs.desc
|
|
|
|
with doc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-20 18:56:56 -06:00
|
|
|
fn parse_item_attrs<T:send>(
|
2012-01-24 02:38:21 -06:00
|
|
|
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-02-03 02:53:37 -06:00
|
|
|
ast_map::node_item(item, _) { item.attrs }
|
2012-03-07 05:21:08 -06:00
|
|
|
ast_map::node_native_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
|
|
|
#[test]
|
2012-02-17 18:52:27 -06:00
|
|
|
fn should_should_extract_mod_attributes() {
|
2012-01-31 20:32:37 -06:00
|
|
|
let doc = test::mk_doc("#[doc = \"test\"] mod a { }");
|
2012-03-02 20:33:25 -06:00
|
|
|
assert doc.cratemod().mods()[0].desc() == some("test");
|
2012-01-18 20:51:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2012-02-17 18:52:27 -06:00
|
|
|
fn should_extract_top_mod_attributes() {
|
2012-01-31 20:32:37 -06:00
|
|
|
let doc = test::mk_doc("#[doc = \"test\"];");
|
2012-03-02 20:33:25 -06:00
|
|
|
assert doc.cratemod().desc() == some("test");
|
2012-01-18 20:51:04 -06:00
|
|
|
}
|
|
|
|
|
2012-02-24 16:22:13 -06:00
|
|
|
#[test]
|
|
|
|
fn should_extract_native_mod_attributes() {
|
|
|
|
let doc = test::mk_doc("#[doc = \"test\"] native mod a { }");
|
2012-03-02 20:33:25 -06:00
|
|
|
assert doc.cratemod().nmods()[0].desc() == some("test");
|
2012-02-24 16:22:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_extract_native_fn_attributes() {
|
|
|
|
let doc = test::mk_doc("native mod a { #[doc = \"test\"] fn a(); }");
|
2012-03-02 20:33:25 -06:00
|
|
|
assert doc.cratemod().nmods()[0].fns[0].desc() == some("test");
|
2012-02-24 16:22:13 -06:00
|
|
|
}
|
|
|
|
|
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-02-17 18:52:27 -06:00
|
|
|
let doc = fold::default_seq_fold_fn(fold, doc);
|
2012-02-17 16:46:30 -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-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] {
|
2012-02-27 01:47:27 -06:00
|
|
|
par::seqmap(docs) {|doc|
|
2012-01-30 18:25:39 -06:00
|
|
|
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]
|
2012-02-17 18:52:27 -06:00
|
|
|
fn should_extract_fn_attributes() {
|
2012-01-31 20:32:37 -06:00
|
|
|
let doc = test::mk_doc("#[doc = \"test\"] fn a() -> int { }");
|
2012-03-02 20:33:25 -06:00
|
|
|
assert doc.cratemod().fns()[0].desc() == some("test");
|
2012-01-16 18:05:59 -06:00
|
|
|
}
|
2012-01-19 00:24:29 -06:00
|
|
|
|
|
|
|
#[test]
|
2012-02-17 18:52:27 -06:00
|
|
|
fn should_extract_fn_arg_attributes() {
|
2012-01-31 20:32:37 -06:00
|
|
|
let doc = test::mk_doc("#[doc(args(a = \"b\"))] fn c(a: bool) { }");
|
2012-03-02 20:33:25 -06:00
|
|
|
assert doc.cratemod().fns()[0].args[0].desc == some("b");
|
2012-01-19 16:27:16 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2012-02-17 18:52:27 -06:00
|
|
|
fn should_extract_fn_return_attributes() {
|
2012-01-19 16:27:16 -06:00
|
|
|
let source = "#[doc(return = \"what\")] fn a() -> int { }";
|
2012-02-20 23:08:19 -06:00
|
|
|
astsrv::from_str(source) {|srv|
|
|
|
|
let doc = extract::from_srv(srv, "");
|
2012-02-27 20:07:16 -06:00
|
|
|
let doc = tystr_pass::mk_pass().f(srv, doc);
|
2012-02-27 00:55:05 -06:00
|
|
|
let fold = fold::default_any_fold(srv);
|
2012-03-02 20:33:25 -06:00
|
|
|
let doc = fold_fn(fold, doc.cratemod().fns()[0]);
|
2012-02-20 23:08:19 -06:00
|
|
|
assert doc.return.desc == some("what");
|
|
|
|
}
|
2012-01-19 20:58:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2012-02-17 18:52:27 -06:00
|
|
|
fn should_preserve_fn_sig() {
|
2012-01-19 20:58:44 -06:00
|
|
|
let source = "fn a() -> int { }";
|
2012-02-20 23:08:19 -06:00
|
|
|
astsrv::from_str(source) {|srv|
|
|
|
|
let doc = extract::from_srv(srv, "");
|
2012-02-27 20:07:16 -06:00
|
|
|
let doc = tystr_pass::mk_pass().f(srv, doc);
|
2012-02-27 00:55:05 -06:00
|
|
|
let fold = fold::default_any_fold(srv);
|
2012-03-02 20:33:25 -06:00
|
|
|
let doc = fold_fn(fold, doc.cratemod().fns()[0]);
|
2012-02-20 23:08:19 -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]
|
2012-02-17 18:52:27 -06:00
|
|
|
fn should_extract_fn_failure_conditions() {
|
2012-01-31 20:32:37 -06:00
|
|
|
let doc = test::mk_doc("#[doc(failure = \"what\")] fn a() { }");
|
2012-03-02 20:33:25 -06:00
|
|
|
assert doc.cratemod().fns()[0].failure == some("what");
|
2012-01-24 20:05:57 -06:00
|
|
|
}
|
|
|
|
|
2012-01-24 02:31:14 -06:00
|
|
|
#[test]
|
2012-02-17 18:52:27 -06:00
|
|
|
fn should_extract_const_docs() {
|
2012-01-31 20:32:37 -06:00
|
|
|
let doc = test::mk_doc("#[doc(brief = \"foo\", desc = \"bar\")]\
|
|
|
|
const a: bool = true;");
|
2012-03-02 20:33:25 -06:00
|
|
|
assert doc.cratemod().consts()[0].brief() == some("foo");
|
|
|
|
assert doc.cratemod().consts()[0].desc() == some("bar");
|
2012-01-24 02:31:14 -06:00
|
|
|
}
|
2012-01-25 20:23:21 -06:00
|
|
|
|
|
|
|
fn fold_enum(
|
|
|
|
fold: fold::fold<astsrv::srv>,
|
|
|
|
doc: doc::enumdoc
|
|
|
|
) -> doc::enumdoc {
|
2012-02-27 01:47:27 -06:00
|
|
|
|
2012-01-25 20:23:21 -06:00
|
|
|
let srv = fold.ctxt;
|
2012-02-27 01:47:27 -06:00
|
|
|
let doc_id = doc.id();
|
2012-02-17 18:52:27 -06:00
|
|
|
let doc = fold::default_seq_fold_enum(fold, doc);
|
2012-01-25 20:23:21 -06:00
|
|
|
|
2012-01-30 15:05:25 -06:00
|
|
|
{
|
2012-02-27 01:10:12 -06:00
|
|
|
variants: par::anymap(doc.variants) {|variant|
|
2012-01-25 20:23:21 -06:00
|
|
|
let attrs = astsrv::exec(srv) {|ctxt|
|
2012-02-27 01:47:27 -06:00
|
|
|
alt check ctxt.ast_map.get(doc_id) {
|
2012-01-25 20:23:21 -06:00
|
|
|
ast_map::node_item(@{
|
|
|
|
node: ast::item_enum(ast_variants, _), _
|
2012-02-03 02:53:37 -06:00
|
|
|
}, _) {
|
2012-01-25 20:23:21 -06:00
|
|
|
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 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]
|
2012-02-17 18:52:27 -06:00
|
|
|
fn should_extract_enum_docs() {
|
2012-01-31 20:32:37 -06:00
|
|
|
let doc = test::mk_doc("#[doc(brief = \"a\", desc = \"b\")]\
|
|
|
|
enum a { v }");
|
2012-03-02 20:33:25 -06:00
|
|
|
assert doc.cratemod().enums()[0].brief() == some("a");
|
|
|
|
assert doc.cratemod().enums()[0].desc() == some("b");
|
2012-01-25 20:23:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2012-02-17 18:52:27 -06:00
|
|
|
fn should_extract_variant_docs() {
|
2012-01-31 20:32:37 -06:00
|
|
|
let doc = test::mk_doc("enum a { #[doc = \"c\"] v }");
|
2012-03-02 20:33:25 -06:00
|
|
|
assert doc.cratemod().enums()[0].variants[0].desc == some("c");
|
2012-01-25 20:23:21 -06:00
|
|
|
}
|
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;
|
2012-02-17 18:52:27 -06:00
|
|
|
let doc = fold::default_seq_fold_res(fold, doc);
|
|
|
|
let attrs = parse_item_attrs(srv, doc.id(), attr_parser::parse_res);
|
2012-01-26 23:39:20 -06:00
|
|
|
|
2012-01-30 15:05:25 -06:00
|
|
|
{
|
2012-02-27 01:47:27 -06:00
|
|
|
args: par::seqmap(doc.args) {|doc|
|
2012-01-27 00:14:16 -06:00
|
|
|
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]
|
2012-02-17 18:52:27 -06:00
|
|
|
fn should_extract_res_docs() {
|
2012-01-31 20:32:37 -06:00
|
|
|
let doc = test::mk_doc("#[doc(brief = \"a\", desc = \"b\")]\
|
|
|
|
resource r(b: bool) { }");
|
2012-03-02 20:33:25 -06:00
|
|
|
assert doc.cratemod().resources()[0].brief() == some("a");
|
|
|
|
assert doc.cratemod().resources()[0].desc() == some("b");
|
2012-01-26 23:39:20 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2012-02-17 18:52:27 -06:00
|
|
|
fn should_extract_res_arg_docs() {
|
2012-01-31 20:32:37 -06:00
|
|
|
let doc = test::mk_doc("#[doc(args(a = \"b\"))]\
|
|
|
|
resource r(a: bool) { }");
|
2012-03-02 20:33:25 -06:00
|
|
|
assert doc.cratemod().resources()[0].args[0].name == "a";
|
|
|
|
assert doc.cratemod().resources()[0].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);
|
|
|
|
|
|
|
|
{
|
2012-02-17 16:46:30 -06:00
|
|
|
methods: merge_method_attrs(srv, doc.id(), doc.methods)
|
2012-01-30 18:25:39 -06:00
|
|
|
with doc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn merge_method_attrs(
|
|
|
|
srv: astsrv::srv,
|
|
|
|
item_id: doc::ast_id,
|
|
|
|
docs: [doc::methoddoc]
|
|
|
|
) -> [doc::methoddoc] {
|
2012-02-17 18:52:27 -06:00
|
|
|
|
|
|
|
type method_attrs = (attr_parser::basic_attrs,
|
|
|
|
attr_parser::method_attrs);
|
|
|
|
|
2012-01-30 18:25:39 -06:00
|
|
|
// Create an assoc list from method name to attributes
|
2012-02-17 18:52:27 -06:00
|
|
|
let attrs: [(str, method_attrs)] = astsrv::exec(srv) {|ctxt|
|
2012-01-30 18:25:39 -06:00
|
|
|
alt ctxt.ast_map.get(item_id) {
|
|
|
|
ast_map::node_item(@{
|
|
|
|
node: ast::item_iface(_, methods), _
|
2012-02-03 02:53:37 -06:00
|
|
|
}, _) {
|
2012-02-27 01:10:12 -06:00
|
|
|
par::seqmap(methods) {|method|
|
2012-02-17 18:52:27 -06:00
|
|
|
(method.ident,
|
|
|
|
(attr_parser::parse_basic(method.attrs),
|
|
|
|
attr_parser::parse_method(method.attrs)
|
|
|
|
))
|
2012-01-30 18:25:39 -06:00
|
|
|
}
|
|
|
|
}
|
2012-01-31 19:05:40 -06:00
|
|
|
ast_map::node_item(@{
|
|
|
|
node: ast::item_impl(_, _, _, methods), _
|
2012-02-03 02:53:37 -06:00
|
|
|
}, _) {
|
2012-02-27 01:10:12 -06:00
|
|
|
par::seqmap(methods) {|method|
|
2012-02-17 18:52:27 -06:00
|
|
|
(method.ident,
|
|
|
|
(attr_parser::parse_basic(method.attrs),
|
|
|
|
attr_parser::parse_method(method.attrs)
|
|
|
|
))
|
2012-01-31 19:05:40 -06:00
|
|
|
}
|
2012-01-30 23:00:57 -06:00
|
|
|
}
|
2012-01-31 19:05:40 -06:00
|
|
|
_ { fail "unexpected item" }
|
2012-01-30 18:25:39 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
vec::map2(docs, attrs) {|doc, attrs|
|
|
|
|
assert doc.name == tuple::first(attrs);
|
2012-02-17 18:52:27 -06:00
|
|
|
let basic_attrs = tuple::first(tuple::second(attrs));
|
|
|
|
let method_attrs = tuple::second(tuple::second(attrs));
|
2012-01-30 18:25:39 -06:00
|
|
|
|
|
|
|
{
|
2012-02-17 18:52:27 -06:00
|
|
|
brief: basic_attrs.brief,
|
|
|
|
desc: basic_attrs.desc,
|
|
|
|
args: merge_arg_attrs(doc.args, method_attrs.args),
|
|
|
|
return: merge_ret_attrs(doc.return, method_attrs.return),
|
|
|
|
failure: method_attrs.failure
|
2012-01-30 18:25:39 -06:00
|
|
|
with doc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_extract_iface_docs() {
|
2012-01-31 20:32:37 -06:00
|
|
|
let doc = test::mk_doc("#[doc = \"whatever\"] iface i { fn a(); }");
|
2012-03-02 20:33:25 -06:00
|
|
|
assert doc.cratemod().ifaces()[0].desc() == some("whatever");
|
2012-01-30 18:25:39 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_extract_iface_method_docs() {
|
2012-01-31 20:32:37 -06:00
|
|
|
let doc = test::mk_doc(
|
|
|
|
"iface i {\
|
|
|
|
#[doc(\
|
|
|
|
brief = \"brief\",\
|
|
|
|
desc = \"desc\",\
|
|
|
|
args(a = \"a\"),\
|
|
|
|
return = \"return\",\
|
|
|
|
failure = \"failure\")]\
|
|
|
|
fn f(a: bool) -> bool;\
|
|
|
|
}");
|
2012-03-02 20:33:25 -06:00
|
|
|
assert doc.cratemod().ifaces()[0].methods[0].brief == some("brief");
|
|
|
|
assert doc.cratemod().ifaces()[0].methods[0].desc == some("desc");
|
|
|
|
assert doc.cratemod().ifaces()[0].methods[0].args[0].desc == some("a");
|
|
|
|
assert doc.cratemod().ifaces()[0].methods[0].return.desc
|
|
|
|
== some("return");
|
|
|
|
assert doc.cratemod().ifaces()[0].methods[0].failure == some("failure");
|
2012-01-30 23:00:57 -06:00
|
|
|
}
|
2012-01-31 19:05:40 -06:00
|
|
|
|
|
|
|
|
|
|
|
fn fold_impl(
|
|
|
|
fold: fold::fold<astsrv::srv>,
|
|
|
|
doc: doc::impldoc
|
|
|
|
) -> doc::impldoc {
|
|
|
|
let srv = fold.ctxt;
|
|
|
|
let doc = fold::default_seq_fold_impl(fold, doc);
|
|
|
|
|
|
|
|
{
|
2012-02-17 16:46:30 -06:00
|
|
|
methods: merge_method_attrs(srv, doc.id(), doc.methods)
|
2012-01-31 19:05:40 -06:00
|
|
|
with doc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_extract_impl_docs() {
|
2012-01-31 20:32:37 -06:00
|
|
|
let doc = test::mk_doc(
|
|
|
|
"#[doc = \"whatever\"] impl i for int { fn a() { } }");
|
2012-03-02 20:33:25 -06:00
|
|
|
assert doc.cratemod().impls()[0].desc() == some("whatever");
|
2012-01-31 19:05:40 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_extract_impl_method_docs() {
|
2012-01-31 20:32:37 -06:00
|
|
|
let doc = test::mk_doc(
|
|
|
|
"impl i for int {\
|
|
|
|
#[doc(\
|
|
|
|
brief = \"brief\",\
|
|
|
|
desc = \"desc\",\
|
|
|
|
args(a = \"a\"),\
|
|
|
|
return = \"return\",\
|
|
|
|
failure = \"failure\")]\
|
|
|
|
fn f(a: bool) -> bool { }\
|
|
|
|
}");
|
2012-03-02 20:33:25 -06:00
|
|
|
assert doc.cratemod().impls()[0].methods[0].brief == some("brief");
|
|
|
|
assert doc.cratemod().impls()[0].methods[0].desc == some("desc");
|
|
|
|
assert doc.cratemod().impls()[0].methods[0].args[0].desc == some("a");
|
|
|
|
assert doc.cratemod().impls()[0].methods[0].return.desc == some("return");
|
|
|
|
assert doc.cratemod().impls()[0].methods[0].failure == some("failure");
|
2012-01-31 19:05:40 -06:00
|
|
|
}
|
2012-01-31 20:32:37 -06:00
|
|
|
|
2012-02-02 00:41:41 -06:00
|
|
|
#[test]
|
|
|
|
fn should_extract_type_docs() {
|
|
|
|
let doc = test::mk_doc(
|
|
|
|
"#[doc(brief = \"brief\", desc = \"desc\")]\
|
|
|
|
type t = int;");
|
2012-03-02 20:33:25 -06:00
|
|
|
assert doc.cratemod().types()[0].brief() == some("brief");
|
|
|
|
assert doc.cratemod().types()[0].desc() == some("desc");
|
2012-02-02 00:41:41 -06:00
|
|
|
}
|
|
|
|
|
2012-01-31 20:32:37 -06:00
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
2012-03-02 20:33:25 -06:00
|
|
|
fn mk_doc(source: str) -> doc::doc {
|
2012-02-20 23:08:19 -06:00
|
|
|
astsrv::from_str(source) {|srv|
|
|
|
|
let doc = extract::from_srv(srv, "");
|
|
|
|
run(srv, doc)
|
|
|
|
}
|
2012-01-31 20:32:37 -06:00
|
|
|
}
|
2012-03-07 18:48:57 -06:00
|
|
|
}
|