Skip to content

Commit

Permalink
Merge branch 'llvm-cov' into 'master'
Browse files Browse the repository at this point in the history
llvm-cov: 3x 100%

See merge request mkjeldsen/commitmsgfmt!72
  • Loading branch information
commonquail committed Nov 7, 2023
2 parents a209fe7 + d44703b commit 0aa2117
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/commitmsgfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,22 @@ content
assert_eq!(filter(72, &input), expected);
}

#[test]
fn preserves_comment() {
let input = "
foo
# comment
";

let expected = "
foo
# comment
";
assert_eq!(filter(2, &input), expected);
}

#[test]
fn preserves_scissored_content_with_custom_comment_char() {
let input = "
Expand Down
54 changes: 54 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,60 @@ mod tests {
super::parse(s, '#')
}

#[test]
fn llvmcov_impl_debug() {
let actual = ListItem(ListIndent("a"), ListType("b"), "c".into());
assert_eq!(
r#"ListItem(ListIndent("a"), ListType("b"), "c")"#,
format!("{:?}", actual)
);
}

#[test]
fn llvmcov_line_as_list_item() {
let matrix = [
("1. ", None),
("11. a", Some(("", "11. ", "a"))),
("1. a", Some(("", "1. ", "a"))),
(" 1. a", Some((" ", "1. ", "a"))),
(" 1. a", Some((" ", "1. ", "a"))),
(" 1. a", None),
("(1) a", Some(("", "(1) ", "a"))),
("(1)a", None),
("(1a", None),
("(1", None),
("(a) b", None),
("1) d", Some(("", "1) ", "d"))),
("1: a", Some(("", "1: ", "a"))),
("1] a", Some(("", "1] ", "a"))),
("* b", Some(("", "* ", "b"))),
("- c", Some(("", "- ", "c"))),
];
for (input, expected) in matrix.iter() {
let expected = expected.map(|e| ListItem(ListIndent(e.0), ListType(e.1), e.2.into()));
let actual = line_as_list_item(&input);
assert_eq!(expected, actual, "'{}'=>{:?}", input, expected);
}
}

#[test]
fn llvmcov_is_line_footnote() {
let matrix = [
("[", false),
("]", false),
("[]", false),
("[a", false),
("[a]", false),
("[a] ", false),
("[a] b", true),
("[a]: b", true),
];
for (input, expected) in matrix.iter() {
let actual = is_line_footnote(&input);
assert_eq!(expected, &actual, "'{}'=>{}", input, expected);
}
}

#[test]
fn parses_empty_str() {
assert!(parse("").is_empty());
Expand Down
12 changes: 12 additions & 0 deletions src/worditer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,16 @@ mod tests {
let res = iter_collect(&text);
assert_eq!(res, expect);
}

#[test]
fn llvmcov_is_non_breaking_word() {
let matrix: Vec<(&str, Vec<Cow<'_, str>>)> = vec![
("a [", vec!["a".into(), "[".into()]),
("a [b", vec!["a".into(), "[b".into()]),
];
for (input, expected) in matrix.iter() {
let actual = iter_collect(&input);
assert_eq!(expected, &actual);
}
}
}

0 comments on commit 0aa2117

Please sign in to comment.