mirror of
https://github.com/supleed2/sv-filelist-parser.git
synced 2024-11-10 01:35:49 +00:00
Add empty line support
This commit is contained in:
parent
b6c346b61c
commit
032a64ef49
|
@ -84,6 +84,7 @@ pub fn parse_file(path: impl AsRef<Path>) -> Result<Filelist, Box<dyn Error>> {
|
||||||
}
|
}
|
||||||
LineType::Comment => filelist.comments_present = true,
|
LineType::Comment => filelist.comments_present = true,
|
||||||
LineType::Unknown => filelist.unknowns_present = true,
|
LineType::Unknown => filelist.unknowns_present = true,
|
||||||
|
LineType::Empty => (),
|
||||||
LineType::Filelist(path) => {
|
LineType::Filelist(path) => {
|
||||||
filelist.extend(parse_file(path)?);
|
filelist.extend(parse_file(path)?);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ pub enum LineType<'a> {
|
||||||
Filelist(&'a str),
|
Filelist(&'a str),
|
||||||
Comment,
|
Comment,
|
||||||
Unknown,
|
Unknown,
|
||||||
|
Empty,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_line(line: &str) -> LineType {
|
pub fn parse_line(line: &str) -> LineType {
|
||||||
|
@ -37,6 +38,8 @@ pub fn parse_line(line: &str) -> LineType {
|
||||||
LineType::Comment
|
LineType::Comment
|
||||||
} else if line.starts_with('-') || line.starts_with('+') {
|
} else if line.starts_with('-') || line.starts_with('+') {
|
||||||
LineType::Unknown
|
LineType::Unknown
|
||||||
|
} else if line.is_empty() {
|
||||||
|
LineType::Empty
|
||||||
} else {
|
} else {
|
||||||
// Mark everything else as a File
|
// Mark everything else as a File
|
||||||
LineType::File(line)
|
LineType::File(line)
|
||||||
|
@ -109,6 +112,16 @@ mod test {
|
||||||
assert_eq!(parse_line(line), LineType::Unknown);
|
assert_eq!(parse_line(line), LineType::Unknown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_line_empty() {
|
||||||
|
let line = "";
|
||||||
|
assert_eq!(parse_line(line), LineType::Empty);
|
||||||
|
let line = " ";
|
||||||
|
assert_eq!(parse_line(line), LineType::Empty);
|
||||||
|
let line = "\t";
|
||||||
|
assert_eq!(parse_line(line), LineType::Empty);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_line_file() {
|
fn parse_line_file() {
|
||||||
let line = "any_random_line_is_a_file";
|
let line = "any_random_line_is_a_file";
|
||||||
|
|
Loading…
Reference in a new issue