mirror of
https://github.com/supleed2/sv-filelist-parser.git
synced 2024-12-22 21:35:49 +00:00
Add checks for unknown commands
This commit is contained in:
parent
01d483331c
commit
f8e5601803
|
@ -13,6 +13,7 @@ pub struct Filelist {
|
|||
pub incdirs: Vec<PathBuf>,
|
||||
pub defines: HashMap<String, Option<String>>,
|
||||
pub comments_present: bool,
|
||||
pub unknowns_present: bool,
|
||||
}
|
||||
|
||||
impl Filelist {
|
||||
|
@ -22,6 +23,7 @@ impl Filelist {
|
|||
incdirs: Vec::new(),
|
||||
defines: HashMap::new(),
|
||||
comments_present: false,
|
||||
unknowns_present: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,6 +32,7 @@ impl Filelist {
|
|||
self.incdirs.extend(other.incdirs);
|
||||
self.defines.extend(other.defines);
|
||||
self.comments_present |= other.comments_present;
|
||||
self.unknowns_present |= other.unknowns_present;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,6 +61,7 @@ pub fn parse_file(path: &str) -> Result<Filelist, Box<dyn Error>> {
|
|||
}
|
||||
}
|
||||
LineType::Comment => filelist.comments_present = true,
|
||||
LineType::Unknown => filelist.unknowns_present = true,
|
||||
LineType::Filelist(path) => {
|
||||
filelist.extend(parse_file(path)?);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ pub enum LineType<'a> {
|
|||
Define(HashMap<&'a str, Option<&'a str>>),
|
||||
Filelist(&'a str),
|
||||
Comment,
|
||||
// Unknown,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
pub fn parse_line(line: &str) -> LineType {
|
||||
|
@ -35,6 +35,8 @@ pub fn parse_line(line: &str) -> LineType {
|
|||
LineType::IncDir(incdir_vec)
|
||||
} else if line.starts_with("//") {
|
||||
LineType::Comment
|
||||
} else if line.starts_with('-') || line.starts_with('+') {
|
||||
LineType::Unknown
|
||||
} else {
|
||||
// Mark everything else as a File
|
||||
LineType::File(line)
|
||||
|
@ -95,6 +97,18 @@ mod test {
|
|||
assert_eq!(parse_line(line), LineType::Comment);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_line_unknown_hyphen() {
|
||||
let line = "-funcmd";
|
||||
assert_eq!(parse_line(line), LineType::Unknown);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_line_unknown_plus() {
|
||||
let line = "+funcmd";
|
||||
assert_eq!(parse_line(line), LineType::Unknown);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_line_file() {
|
||||
let line = "any_random_line_is_a_file";
|
||||
|
|
|
@ -22,6 +22,7 @@ fn simple_test() {
|
|||
incdirs: vec![PathBuf::from("testcase/")],
|
||||
defines: defines,
|
||||
comments_present: true,
|
||||
unknowns_present: false,
|
||||
};
|
||||
|
||||
// Add env vars
|
||||
|
|
Loading…
Reference in a new issue