diff --git a/cli/src/test.rs b/cli/src/test.rs index 752209cf..3e82c02a 100644 --- a/cli/src/test.rs +++ b/cli/src/test.rs @@ -16,7 +16,7 @@ use walkdir::WalkDir; lazy_static! { static ref HEADER_REGEX: ByteRegex = - ByteRegexBuilder::new(r"^===+(?P[^=\r\n][^\r\n]*)?\r?\n(?P[^=\r\n][^\r\n]*)\r?\n===+(?P[^=\r\n][^\r\n]*)?\r?\n") + ByteRegexBuilder::new(r"^===+(?P[^=\r\n][^\r\n]*)?\r?\n(?P([^=\r\n][^\r\n]*\r?\n)+)===+(?P[^=\r\n][^\r\n]*)?\r?\n") .multi_line(true) .build() .unwrap(); @@ -404,7 +404,7 @@ fn parse_test_content(name: String, content: String, file_path: Option) let header_range = c.get(0).unwrap().range(); let test_name = c .name("test_name") - .map(|c| String::from_utf8_lossy(c.as_bytes()).to_string()); + .map(|c| String::from_utf8_lossy(c.as_bytes()).trim_end().to_string()); Some((header_range, test_name)) } else { None @@ -791,4 +791,52 @@ NOT A TEST HEADER } ); } + + #[test] + fn test_parse_test_content_with_newlines_in_test_names() { + let entry = parse_test_content( + "the-filename".to_string(), + r#" +=============== +name +with +newlines +=============== +a +--- +(b) + +==================== +name with === signs +==================== +code with ---- +--- +(d) +"# + .to_string(), + None, + ); + + assert_eq!( + entry, + TestEntry::Group { + name: "the-filename".to_string(), + file_path: None, + children: vec![ + TestEntry::Example { + name: "name\nwith\nnewlines".to_string(), + input: b"a".to_vec(), + output: "(b)".to_string(), + has_fields: false, + }, + TestEntry::Example { + name: "name with === signs".to_string(), + input: b"code with ----".to_vec(), + output: "(d)".to_string(), + has_fields: false, + } + ] + } + ); + } }