mirror of
https://github.com/supleed2/sv-filelist-parser.git
synced 2024-12-22 13:25:49 +00:00
Add empty line support
This commit is contained in:
parent
b6c346b61c
commit
032a64ef49
|
@ -45,11 +45,11 @@ impl Filelist {
|
|||
}
|
||||
|
||||
/// Parses a filelist file.
|
||||
///
|
||||
/// Environment variables represented with paranthesis or
|
||||
///
|
||||
/// Environment variables represented with paranthesis or
|
||||
/// curly braces (i.e. `$()` or `${}`) will be automatically
|
||||
/// substituted.
|
||||
///
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `path` - The path to the filelist
|
||||
|
@ -84,6 +84,7 @@ pub fn parse_file(path: impl AsRef<Path>) -> Result<Filelist, Box<dyn Error>> {
|
|||
}
|
||||
LineType::Comment => filelist.comments_present = true,
|
||||
LineType::Unknown => filelist.unknowns_present = true,
|
||||
LineType::Empty => (),
|
||||
LineType::Filelist(path) => {
|
||||
filelist.extend(parse_file(path)?);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ pub enum LineType<'a> {
|
|||
Filelist(&'a str),
|
||||
Comment,
|
||||
Unknown,
|
||||
Empty,
|
||||
}
|
||||
|
||||
pub fn parse_line(line: &str) -> LineType {
|
||||
|
@ -37,6 +38,8 @@ pub fn parse_line(line: &str) -> LineType {
|
|||
LineType::Comment
|
||||
} else if line.starts_with('-') || line.starts_with('+') {
|
||||
LineType::Unknown
|
||||
} else if line.is_empty() {
|
||||
LineType::Empty
|
||||
} else {
|
||||
// Mark everything else as a File
|
||||
LineType::File(line)
|
||||
|
@ -109,6 +112,16 @@ mod test {
|
|||
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]
|
||||
fn parse_line_file() {
|
||||
let line = "any_random_line_is_a_file";
|
||||
|
|
Loading…
Reference in a new issue