diff --git a/src/commitmsgfmt.rs b/src/commitmsgfmt.rs index 7b4d814..a917921 100644 --- a/src/commitmsgfmt.rs +++ b/src/commitmsgfmt.rs @@ -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 = " diff --git a/src/parser.rs b/src/parser.rs index 923024f..304fbfa 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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()); diff --git a/src/worditer.rs b/src/worditer.rs index 69d3e0e..f754fd3 100644 --- a/src/worditer.rs +++ b/src/worditer.rs @@ -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>)> = 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); + } + } }