diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-01-24 00:31:14 -0800 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-01-24 00:38:35 -0800 |
| commit | fbd704e77d35a0e1ccf2279b28f94aeee1b56213 (patch) | |
| tree | dc492aaedad792a8f687529d0a9be42163b8bd9e | |
| parent | c93c6358cbc3d072b12a38053e1e079835db821f (diff) | |
| download | rust-fbd704e77d35a0e1ccf2279b28f94aeee1b56213.tar.gz rust-fbd704e77d35a0e1ccf2279b28f94aeee1b56213.zip | |
rustdoc: Add const attr docs to doc tree
| -rw-r--r-- | src/rustdoc/attr_pass.rs | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/rustdoc/attr_pass.rs b/src/rustdoc/attr_pass.rs index 4c945a7869f..30adc40c420 100644 --- a/src/rustdoc/attr_pass.rs +++ b/src/rustdoc/attr_pass.rs @@ -22,7 +22,8 @@ fn run( let fold = fold::fold({ fold_crate: fold_crate, fold_mod: fold_mod, - fold_fn: fold_fn + fold_fn: fold_fn, + fold_const: fold_const with *fold::default_seq_fold(srv) }); fold.fold_crate(fold, doc) @@ -208,4 +209,35 @@ fn fold_fn_should_preserve_sig() { let fold = fold::default_seq_fold(srv); let doc = fold_fn(fold, doc.topmod.fns[0]); assert doc.sig == some("fn a() -> int"); -} \ No newline at end of file +} + +fn fold_const( + fold: fold::fold<astsrv::srv>, + doc: doc::constdoc +) -> doc::constdoc { + let srv = fold.ctxt; + let attrs = astsrv::exec(srv) {|ctxt| + let attrs = alt ctxt.map.get(doc.id) { + ast_map::node_item(item) { item.attrs } + }; + attr_parser::parse_mod(attrs) + }; + + ~{ + brief: attrs.brief, + desc: attrs.desc + with *doc + } +} + +#[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); + let doc = fold_const(fold, doc.topmod.consts[0]); + assert doc.brief == some("foo"); + assert doc.desc == some("bar"); +} |
