Skip to content

Commit

Permalink
Merge pull request #3832 from Dretch/concatdocstrs
Browse files Browse the repository at this point in the history
Fix and test for issue #3780.
  • Loading branch information
brson committed Oct 22, 2012
2 parents 763a8e7 + 7947bb1 commit 586b22a
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions src/rustdoc/attr_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,6 @@ mod test {
}
}
fn doc_meta(
attrs: ~[ast::attribute]
) -> Option<@ast::meta_item> {
/*!
* Given a vec of attributes, extract the meta_items contained in the \
* doc attribute
*/
let doc_metas = doc_metas(attrs);
if vec::is_not_empty(doc_metas) {
if vec::len(doc_metas) != 1u {
warn!("ignoring %u doc attributes", vec::len(doc_metas) - 1u);
}
Some(doc_metas[0])
} else {
None
}

}

fn doc_metas(
attrs: ~[ast::attribute]
) -> ~[@ast::meta_item] {
Expand Down Expand Up @@ -102,11 +81,13 @@ fn should_not_extract_crate_name_if_no_name_value_in_link_attribute() {
}

fn parse_desc(attrs: ~[ast::attribute]) -> Option<~str> {
match doc_meta(attrs) {
Some(meta) => {
attr::get_meta_item_value_str(meta)
}
None => None
let doc_strs = do doc_metas(attrs).filter_map |meta| {
attr::get_meta_item_value_str(*meta)
};
if doc_strs.is_empty() {
None
} else {
Some(str::connect(doc_strs, "\n"))
}
}

Expand Down Expand Up @@ -158,3 +139,12 @@ fn should_not_parse_non_hidden_attribute() {
let attrs = test::parse_attributes(source);
assert parse_hidden(attrs) == false;
}

#[test]
fn should_concatenate_multiple_doc_comments() {
let source = ~"/// foo\n/// bar";
let desc = parse_desc(test::parse_attributes(source));
assert desc == Some(~"foo\nbar");
}


0 comments on commit 586b22a

Please sign in to comment.