diff options
| author | bors <bors@rust-lang.org> | 2013-09-25 15:40:52 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-09-25 15:40:52 -0700 |
| commit | 41826c48eddfb964b830229dff6f0480ac649827 (patch) | |
| tree | b072ac06adc084acd477fb8f90971e79497313b7 /src/libsyntax/parse | |
| parent | 24d46a0f45b4a0d6198b9d23dad2f7faa5a05d92 (diff) | |
| parent | 3d5873fa421356ad936e6fc6ab61773c60646357 (diff) | |
| download | rust-41826c48eddfb964b830229dff6f0480ac649827.tar.gz rust-41826c48eddfb964b830229dff6f0480ac649827.zip | |
auto merge of #9475 : alexcrichton/rust/rustdoc++, r=cmr
The commit messages are a good technical summary, a good visual summary (contrib is this version): Pub use statements now rendered. Notice how almost all components are also clickable! * http://static.rust-lang.org/doc/master/std/prelude/index.html * http://www.contrib.andrew.cmu.edu/~acrichto/doc/std/prelude/index.html Private things hidden by default (for at least some approximation of privacy). I hope to improve this once privacy is totally ironed out. * http://static.rust-lang.org/doc/master/std/hashmap/struct.HashMap.html * http://www.contrib.andrew.cmu.edu/~acrichto/doc/std/hashmap/struct.HashMap.html Unindentation now works properly: * http://static.rust-lang.org/doc/master/extra/getopts/index.html * http://www.contrib.andrew.cmu.edu/~acrichto/doc/extra/getopts/index.html Also sundown has massively reduced compilation time (of docs, not the of the crates)
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/comments.rs | 55 |
1 files changed, 40 insertions, 15 deletions
diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs index f13bd6d9123..88c9fc3e0f7 100644 --- a/src/libsyntax/parse/comments.rs +++ b/src/libsyntax/parse/comments.rs @@ -59,11 +59,19 @@ pub fn strip_doc_comment_decoration(comment: &str) -> ~str { fn vertical_trim(lines: ~[~str]) -> ~[~str] { let mut i = 0u; let mut j = lines.len(); + // first line of all-stars should be omitted + if lines.len() > 0 && lines[0].iter().all(|c| c == '*') { + i += 1; + } while i < j && lines[i].trim().is_empty() { - i += 1u; + i += 1; + } + // like the first, a last line of all stars should be omitted + if j > i && lines[j - 1].iter().skip(1).all(|c| c == '*') { + j -= 1; } - while j > i && lines[j - 1u].trim().is_empty() { - j -= 1u; + while j > i && lines[j - 1].trim().is_empty() { + j -= 1; } return lines.slice(i, j).to_owned(); } @@ -106,8 +114,12 @@ pub fn strip_doc_comment_decoration(comment: &str) -> ~str { } } - if comment.starts_with("//") { - return comment.slice(3u, comment.len()).to_owned(); + // one-line comments lose their prefix + static ONLINERS: &'static [&'static str] = &["///!", "///", "//!", "//"]; + for prefix in ONLINERS.iter() { + if comment.starts_with(*prefix) { + return comment.slice_from(prefix.len()).to_owned(); + } } if comment.starts_with("/*") { @@ -384,29 +396,42 @@ mod test { #[test] fn test_block_doc_comment_1() { let comment = "/**\n * Test \n ** Test\n * Test\n*/"; - let correct_stripped = " Test \n* Test\n Test"; let stripped = strip_doc_comment_decoration(comment); - assert_eq!(stripped.slice(0, stripped.len()), correct_stripped); + assert_eq!(stripped, ~" Test \n* Test\n Test"); } #[test] fn test_block_doc_comment_2() { let comment = "/**\n * Test\n * Test\n*/"; - let correct_stripped = " Test\n Test"; let stripped = strip_doc_comment_decoration(comment); - assert_eq!(stripped.slice(0, stripped.len()), correct_stripped); + assert_eq!(stripped, ~" Test\n Test"); } #[test] fn test_block_doc_comment_3() { let comment = "/**\n let a: *int;\n *a = 5;\n*/"; - let correct_stripped = " let a: *int;\n *a = 5;"; let stripped = strip_doc_comment_decoration(comment); - assert_eq!(stripped.slice(0, stripped.len()), correct_stripped); + assert_eq!(stripped, ~" let a: *int;\n *a = 5;"); } - #[test] fn test_line_doc_comment() { - let comment = "/// Test"; - let correct_stripped = " Test"; + #[test] fn test_block_doc_comment_4() { + let comment = "/*******************\n test\n *********************/"; let stripped = strip_doc_comment_decoration(comment); - assert_eq!(stripped.slice(0, stripped.len()), correct_stripped); + assert_eq!(stripped, ~" test"); + } + + #[test] fn test_line_doc_comment() { + let stripped = strip_doc_comment_decoration("/// test"); + assert_eq!(stripped, ~" test"); + let stripped = strip_doc_comment_decoration("///! test"); + assert_eq!(stripped, ~" test"); + let stripped = strip_doc_comment_decoration("// test"); + assert_eq!(stripped, ~" test"); + let stripped = strip_doc_comment_decoration("// test"); + assert_eq!(stripped, ~" test"); + let stripped = strip_doc_comment_decoration("///test"); + assert_eq!(stripped, ~"test"); + let stripped = strip_doc_comment_decoration("///!test"); + assert_eq!(stripped, ~"test"); + let stripped = strip_doc_comment_decoration("//test"); + assert_eq!(stripped, ~"test"); } } |
