Add checks for unknown commands

This commit is contained in:
Raamakrishnan 2020-02-02 11:49:05 +05:30
parent 01d483331c
commit f8e5601803
3 changed files with 20 additions and 1 deletions

View file

@ -13,6 +13,7 @@ pub struct Filelist {
pub incdirs: Vec<PathBuf>, pub incdirs: Vec<PathBuf>,
pub defines: HashMap<String, Option<String>>, pub defines: HashMap<String, Option<String>>,
pub comments_present: bool, pub comments_present: bool,
pub unknowns_present: bool,
} }
impl Filelist { impl Filelist {
@ -22,6 +23,7 @@ impl Filelist {
incdirs: Vec::new(), incdirs: Vec::new(),
defines: HashMap::new(), defines: HashMap::new(),
comments_present: false, comments_present: false,
unknowns_present: false,
} }
} }
@ -30,6 +32,7 @@ impl Filelist {
self.incdirs.extend(other.incdirs); self.incdirs.extend(other.incdirs);
self.defines.extend(other.defines); self.defines.extend(other.defines);
self.comments_present |= other.comments_present; 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::Comment => filelist.comments_present = true,
LineType::Unknown => filelist.unknowns_present = true,
LineType::Filelist(path) => { LineType::Filelist(path) => {
filelist.extend(parse_file(path)?); filelist.extend(parse_file(path)?);
} }

View file

@ -7,7 +7,7 @@ pub enum LineType<'a> {
Define(HashMap<&'a str, Option<&'a str>>), Define(HashMap<&'a str, Option<&'a str>>),
Filelist(&'a str), Filelist(&'a str),
Comment, Comment,
// Unknown, Unknown,
} }
pub fn parse_line(line: &str) -> LineType { pub fn parse_line(line: &str) -> LineType {
@ -35,6 +35,8 @@ pub fn parse_line(line: &str) -> LineType {
LineType::IncDir(incdir_vec) LineType::IncDir(incdir_vec)
} else if line.starts_with("//") { } else if line.starts_with("//") {
LineType::Comment LineType::Comment
} else if line.starts_with('-') || line.starts_with('+') {
LineType::Unknown
} else { } else {
// Mark everything else as a File // Mark everything else as a File
LineType::File(line) LineType::File(line)
@ -95,6 +97,18 @@ mod test {
assert_eq!(parse_line(line), LineType::Comment); 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] #[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";

View file

@ -22,6 +22,7 @@ fn simple_test() {
incdirs: vec![PathBuf::from("testcase/")], incdirs: vec![PathBuf::from("testcase/")],
defines: defines, defines: defines,
comments_present: true, comments_present: true,
unknowns_present: false,
}; };
// Add env vars // Add env vars