Skip to content

Commit 2c10968

Browse files
committed
Merge branch 'push-tnzvlkpmptkz' into 'master'
Support multi char comment strings See merge request mkjeldsen/commitmsgfmt!81
2 parents bdd9621 + eaf9f91 commit 2c10968

File tree

4 files changed

+148
-133
lines changed

4 files changed

+148
-133
lines changed

src/commitmsgfmt.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ use unicode_segmentation::UnicodeSegmentation;
77
pub struct CommitMsgFmt {
88
/// Max width of the message body; not used for the subject line.
99
width: usize,
10-
/// The character that identifies a comment when used in column 0 of a line.
11-
comment_char: char,
10+
/// The string that identifies a comment when started in column 0 of a line.
11+
comment_string: String,
1212
}
1313

1414
impl CommitMsgFmt {
15-
pub fn new(width: usize, comment_char: char) -> CommitMsgFmt {
15+
pub fn new(width: usize, comment_string: &str) -> CommitMsgFmt {
1616
CommitMsgFmt {
1717
width,
18-
comment_char,
18+
comment_string: comment_string.into(),
1919
}
2020
}
2121

2222
pub fn filter(&self, input: &str) -> String {
23-
let msg = parse(input, self.comment_char);
23+
let msg = parse(input, &self.comment_string);
2424
// The output size can be less than the input size only if the input contains characters
2525
// that will be trimmed, such as leading whitespace, which is improbable. It is more likely
2626
// the output size will exceed the input size due to injected linefeeds and continuation
@@ -76,7 +76,7 @@ impl CommitMsgFmt {
7676
None => self.width,
7777
};
7878
let mut cur_line_len = 0;
79-
for word in WordIter::new(paragraph, self.comment_char) {
79+
for word in WordIter::new(paragraph, &self.comment_string) {
8080
let word_len = word.graphemes(true).count();
8181

8282
// Not a new line so we need to fiddle with whitespace.
@@ -105,7 +105,7 @@ mod tests {
105105
use pretty_assertions::assert_eq;
106106

107107
fn filter(w: usize, s: &str) -> String {
108-
CommitMsgFmt::new(w, '#').filter(&s)
108+
CommitMsgFmt::new(w, "#").filter(s)
109109
}
110110

111111
#[test]
@@ -160,7 +160,7 @@ format this
160160
öööö ü";
161161

162162
assert_eq!(
163-
filter(5, &s),
163+
filter(5, s),
164164
"
165165
ääääääääääääääääääääääääääääääääääääääääääääääääääääääääääääääääääääääääääääääääääääääääää
166166
@@ -185,7 +185,7 @@ Signed-off-by: Some Guy <[email protected]>
185185
Cc: Abominable Snowman <[email protected]>
186186
";
187187

188-
assert_eq!(filter(10, &msg), msg, "print trailers literally");
188+
assert_eq!(filter(10, msg), msg, "print trailers literally");
189189
}
190190

191191
#[test]
@@ -212,7 +212,7 @@ foo
212212
\t\tcontinuation
213213
";
214214

215-
assert_eq!(filter(72, &input), expected);
215+
assert_eq!(filter(72, input), expected);
216216
}
217217

218218
#[test]
@@ -239,7 +239,7 @@ block
239239
```
240240
";
241241

242-
assert_eq!(filter(72, &input), expected);
242+
assert_eq!(filter(72, input), expected);
243243
}
244244

245245
#[test]
@@ -264,7 +264,7 @@ backtick
264264
b
265265
";
266266

267-
assert_eq!(filter(72, &input), expected);
267+
assert_eq!(filter(72, input), expected);
268268
}
269269

270270
#[test]
@@ -288,7 +288,7 @@ foo
288288
~~~ tilde fenced code block not supported ~~~
289289
";
290290

291-
assert_eq!(filter(72, &input), expected);
291+
assert_eq!(filter(72, input), expected);
292292
}
293293

294294
#[test]
@@ -302,7 +302,7 @@ paragraph
302302

303303
let expected = input;
304304

305-
assert_eq!(filter(72, &input), expected);
305+
assert_eq!(filter(72, input), expected);
306306
}
307307

308308
#[test]
@@ -317,7 +317,7 @@ paragraph
317317

318318
let expected = input;
319319

320-
assert_eq!(filter(72, &input), expected);
320+
assert_eq!(filter(72, input), expected);
321321
}
322322

323323
#[test]
@@ -357,7 +357,7 @@ xx xx xxxxxx xxxxxxx
357357
xxxxxxxxxxxxxx.
358358
";
359359

360-
assert_eq!(filter(30, &input), expected);
360+
assert_eq!(filter(30, input), expected);
361361
}
362362

363363
#[test]
@@ -395,7 +395,7 @@ paragraph
395395
footnote key
396396
";
397397

398-
assert_eq!(filter(20, &msg), expected);
398+
assert_eq!(filter(20, msg), expected);
399399
}
400400

401401
#[test]
@@ -435,7 +435,7 @@ w
435435
www [4] .
436436
";
437437

438-
assert_eq!(filter(8, &msg), expected);
438+
assert_eq!(filter(8, msg), expected);
439439
}
440440

441441
#[test]
@@ -481,7 +481,7 @@ foo
481481
- ääääääääääääääëëëëëëëëëëëëëëö
482482
";
483483

484-
assert_eq!(filter(16, &input), expected);
484+
assert_eq!(filter(16, input), expected);
485485
}
486486

487487
#[test]
@@ -506,7 +506,7 @@ foo
506506
that should be realigned
507507
";
508508

509-
assert_eq!(filter(34, &input), expected);
509+
assert_eq!(filter(34, input), expected);
510510
}
511511

512512
#[test]
@@ -525,7 +525,7 @@ foo
525525
[1] note
526526
note
527527
";
528-
assert_eq!(filter(3, &input), expected);
528+
assert_eq!(filter(3, input), expected);
529529
}
530530

531531
#[test]
@@ -543,7 +543,7 @@ foo
543543
- list item that should not have been wrapped
544544
";
545545

546-
assert_eq!(filter(72, &input), expected);
546+
assert_eq!(filter(72, input), expected);
547547
}
548548

549549
#[test]
@@ -565,7 +565,7 @@ foo
565565
- list item
566566
";
567567

568-
assert_eq!(filter(72, &input), expected);
568+
assert_eq!(filter(72, input), expected);
569569
}
570570

571571
#[test]
@@ -587,7 +587,7 @@ foo
587587
- literal
588588
";
589589

590-
assert_eq!(filter(72, &input), expected);
590+
assert_eq!(filter(72, input), expected);
591591
}
592592

593593
#[test]
@@ -608,7 +608,7 @@ foo
608608
7 numbered
609609
";
610610

611-
assert_eq!(filter(72, &msg), msg);
611+
assert_eq!(filter(72, msg), msg);
612612
}
613613

614614
#[test]
@@ -637,7 +637,7 @@ preserve
637637
638638
content
639639
";
640-
assert_eq!(filter(72, &input), expected);
640+
assert_eq!(filter(72, input), expected);
641641
}
642642

643643
#[test]
@@ -653,11 +653,11 @@ foo
653653
654654
# comment
655655
";
656-
assert_eq!(filter(2, &input), expected);
656+
assert_eq!(filter(2, input), expected);
657657
}
658658

659659
#[test]
660-
fn preserves_scissored_content_with_custom_comment_char() {
660+
fn preserves_scissored_content_with_custom_comment_string() {
661661
let input = "
662662
foo
663663
@@ -683,8 +683,8 @@ preserve
683683
684684
content
685685
";
686-
let fmt = CommitMsgFmt::new(72, ';');
687-
assert_eq!(fmt.filter(&input), expected);
686+
let fmt = CommitMsgFmt::new(72, ";");
687+
assert_eq!(fmt.filter(input), expected);
688688
}
689689

690690
#[test]
@@ -711,7 +711,7 @@ b\tc\u{00a0}d\u{2003}e\u{2009}\u{2009}f\u{202f}g
711711
712712
a b\tc\u{00a0}d\u{2003}e\u{2009}f\u{202f}g
713713
";
714-
assert_eq!(filter(2, &input), expected);
714+
assert_eq!(filter(2, input), expected);
715715
}
716716

717717
#[test]
@@ -746,7 +746,7 @@ https://a.really-long-url.example
746746
747747
[1] https://a.really-long-url.example
748748
";
749-
assert_eq!(filter(10, &input), expected);
749+
assert_eq!(filter(10, input), expected);
750750
}
751751

752752
#[test]
@@ -772,6 +772,6 @@ wup
772772
[qux] note
773773
[2] note
774774
";
775-
assert_eq!(filter(2, &input), expected);
775+
assert_eq!(filter(2, input), expected);
776776
}
777777
}

0 commit comments

Comments
 (0)