Skip to content

Commit cc78d8d

Browse files
committed
---
yaml --- r: 83434 b: refs/heads/try c: bcc7daa h: refs/heads/master v: v3
1 parent 19c2e62 commit cc78d8d

File tree

3 files changed

+43
-18
lines changed

3 files changed

+43
-18
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 0e4d1fc8cae42e15e00f71d9f439b01bb25a86ae
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6c08cc2db4f98e9f07ae7d50338396c4123c2f0a
5-
refs/heads/try: 35c0cdff5a5fc9e41468ce167c9304ba43028ac4
5+
refs/heads/try: bcc7daa6bcf9728eca36512975f9251a946618d7
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libextra/getopts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
//! that requires an input file to be specified, accepts an optional output
3030
//! file name following -o, and accepts both -h and --help as optional flags.
3131
//!
32-
//! ```
32+
//! ~~~{.rust}
3333
//! exter mod extra;
3434
//! use extra::getopts::*;
3535
//! use std::os;
@@ -75,7 +75,7 @@
7575
//! };
7676
//! do_work(input, output);
7777
//! }
78-
//! ```
78+
//! ~~~
7979
8080
use std::cmp::Eq;
8181
use std::result::{Err, Ok};

branches/try/src/libsyntax/parse/comments.rs

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,19 @@ pub fn strip_doc_comment_decoration(comment: &str) -> ~str {
5959
fn vertical_trim(lines: ~[~str]) -> ~[~str] {
6060
let mut i = 0u;
6161
let mut j = lines.len();
62+
// first line of all-stars should be omitted
63+
if lines.len() > 0 && lines[0].iter().all(|c| c == '*') {
64+
i += 1;
65+
}
6266
while i < j && lines[i].trim().is_empty() {
63-
i += 1u;
67+
i += 1;
68+
}
69+
// like the first, a last line of all stars should be omitted
70+
if j > i && lines[j - 1].iter().skip(1).all(|c| c == '*') {
71+
j -= 1;
6472
}
65-
while j > i && lines[j - 1u].trim().is_empty() {
66-
j -= 1u;
73+
while j > i && lines[j - 1].trim().is_empty() {
74+
j -= 1;
6775
}
6876
return lines.slice(i, j).to_owned();
6977
}
@@ -106,8 +114,12 @@ pub fn strip_doc_comment_decoration(comment: &str) -> ~str {
106114
}
107115
}
108116

109-
if comment.starts_with("//") {
110-
return comment.slice(3u, comment.len()).to_owned();
117+
// one-line comments lose their prefix
118+
static ONLINERS: &'static [&'static str] = &["///!", "///", "//!", "//"];
119+
for prefix in ONLINERS.iter() {
120+
if comment.starts_with(*prefix) {
121+
return comment.slice_from(prefix.len()).to_owned();
122+
}
111123
}
112124

113125
if comment.starts_with("/*") {
@@ -384,29 +396,42 @@ mod test {
384396

385397
#[test] fn test_block_doc_comment_1() {
386398
let comment = "/**\n * Test \n ** Test\n * Test\n*/";
387-
let correct_stripped = " Test \n* Test\n Test";
388399
let stripped = strip_doc_comment_decoration(comment);
389-
assert_eq!(stripped.slice(0, stripped.len()), correct_stripped);
400+
assert_eq!(stripped, ~" Test \n* Test\n Test");
390401
}
391402
392403
#[test] fn test_block_doc_comment_2() {
393404
let comment = "/**\n * Test\n * Test\n*/";
394-
let correct_stripped = " Test\n Test";
395405
let stripped = strip_doc_comment_decoration(comment);
396-
assert_eq!(stripped.slice(0, stripped.len()), correct_stripped);
406+
assert_eq!(stripped, ~" Test\n Test");
397407
}
398408
399409
#[test] fn test_block_doc_comment_3() {
400410
let comment = "/**\n let a: *int;\n *a = 5;\n*/";
401-
let correct_stripped = " let a: *int;\n *a = 5;";
402411
let stripped = strip_doc_comment_decoration(comment);
403-
assert_eq!(stripped.slice(0, stripped.len()), correct_stripped);
412+
assert_eq!(stripped, ~" let a: *int;\n *a = 5;");
404413
}
405414
406-
#[test] fn test_line_doc_comment() {
407-
let comment = "/// Test";
408-
let correct_stripped = " Test";
415+
#[test] fn test_block_doc_comment_4() {
416+
let comment = "/*******************\n test\n *********************/";
409417
let stripped = strip_doc_comment_decoration(comment);
410-
assert_eq!(stripped.slice(0, stripped.len()), correct_stripped);
418+
assert_eq!(stripped, ~" test");
419+
}
420+
421+
#[test] fn test_line_doc_comment() {
422+
let stripped = strip_doc_comment_decoration("/// test");
423+
assert_eq!(stripped, ~" test");
424+
let stripped = strip_doc_comment_decoration("///! test");
425+
assert_eq!(stripped, ~" test");
426+
let stripped = strip_doc_comment_decoration("// test");
427+
assert_eq!(stripped, ~" test");
428+
let stripped = strip_doc_comment_decoration("// test");
429+
assert_eq!(stripped, ~" test");
430+
let stripped = strip_doc_comment_decoration("///test");
431+
assert_eq!(stripped, ~"test");
432+
let stripped = strip_doc_comment_decoration("///!test");
433+
assert_eq!(stripped, ~"test");
434+
let stripped = strip_doc_comment_decoration("//test");
435+
assert_eq!(stripped, ~"test");
411436
}
412437
}

0 commit comments

Comments
 (0)