Clippy and rustfmt run

This commit is contained in:
Raamakrishnan 2020-01-31 21:39:17 +05:30
parent 4061408e5c
commit 73554ac998
5 changed files with 24 additions and 21 deletions

View file

@ -1,8 +1,8 @@
use regex::Regex;
use std::collections::HashMap;
use std::error::Error;
use std::fs;
use std::path::PathBuf;
use regex::Regex;
use crate::line_parser;
use crate::line_parser::LineType;
@ -45,11 +45,13 @@ pub fn parse_file(path: &str) -> Result<Filelist, Box<dyn Error>> {
LineType::Define(define_map) => {
for (d, t) in define_map.into_iter() {
match t {
Some(text) => filelist.defines.insert(d.to_string(), Some(text.to_string())),
None => filelist.defines.insert(d.to_string(), None)
Some(text) => filelist
.defines
.insert(d.to_string(), Some(text.to_string())),
None => filelist.defines.insert(d.to_string(), None),
};
}
},
}
LineType::IncDir(incdirs) => {
for dir in incdirs {
filelist.incdirs.push(PathBuf::from(dir));
@ -58,7 +60,7 @@ pub fn parse_file(path: &str) -> Result<Filelist, Box<dyn Error>> {
LineType::Comment => filelist.comments_present = true,
LineType::Filelist(path) => {
filelist.extend(parse_file(path)?);
},
}
}
}
Ok(filelist)

View file

@ -1,5 +1,5 @@
pub mod line_parser;
pub mod file_parser;
pub mod line_parser;
pub use file_parser::Filelist;
use std::error::Error;

View file

@ -20,7 +20,7 @@ pub fn parse_line(line: &str) -> LineType {
let defines = line.trim_start_matches("+define+").trim_end_matches('+');
let mut define_map = HashMap::new();
for define in defines.split('+') {
if let Some(pos) = define.find("=") {
if let Some(pos) = define.find('=') {
let (d, t) = define.split_at(pos);
define_map.insert(d, Some(&t[1..]));
} else {
@ -98,6 +98,9 @@ mod test {
#[test]
fn parse_line_file() {
let line = "any_random_line_is_a_file";
assert_eq!(parse_line(line), LineType::File("any_random_line_is_a_file"));
assert_eq!(
parse_line(line),
LineType::File("any_random_line_is_a_file")
);
}
}

View file

@ -1,12 +1,11 @@
use std::env;
use std::path::PathBuf;
use std::fs;
use std::path::PathBuf;
use sv_filelist_parser;
fn main() {
let args: Vec<String> = env::args().collect();
let filelist = sv_filelist_parser::parse(&args[1])
.expect("Error parsing");
let filelist = sv_filelist_parser::parse(&args[1]).expect("Error parsing");
println!("{:#?}", filelist);
}

View file

@ -1,6 +1,6 @@
use sv_filelist_parser;
use std::collections::HashMap;
use std::path::PathBuf;
use sv_filelist_parser;
#[test]
fn simple_test() {
@ -21,14 +21,13 @@ fn simple_test() {
],
incdirs: vec![PathBuf::from("testcase/")],
defines: defines,
comments_present : true
comments_present: true,
};
// Add env vars
std::env::set_var("VAR1", "ENV_VAR1");
std::env::set_var("VAR2", "ENV_VAR2");
let filelist = sv_filelist_parser::parse("testcase/files.f")
.expect("Error parsing");
let filelist = sv_filelist_parser::parse("testcase/files.f").expect("Error parsing");
assert_eq!(filelist_exp, filelist);
}