mirror of
https://github.com/supleed2/sv-filelist-parser.git
synced 2024-12-22 21:35:49 +00:00
Clippy and rustfmt run
This commit is contained in:
parent
4061408e5c
commit
73554ac998
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use sv_filelist_parser;
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
use sv_filelist_parser;
|
||||
|
||||
#[test]
|
||||
fn simple_test() {
|
||||
|
@ -13,22 +13,21 @@ fn simple_test() {
|
|||
defines.insert("RTL".to_string(), None);
|
||||
|
||||
let filelist_exp = sv_filelist_parser::Filelist {
|
||||
files : vec![
|
||||
files: vec![
|
||||
PathBuf::from("testcase/file1.sv"),
|
||||
PathBuf::from("testcase/file2.sv"),
|
||||
PathBuf::from("testcase/file3.sv"),
|
||||
PathBuf::from("testcase/file4.sv"),
|
||||
],
|
||||
incdirs : vec![PathBuf::from("testcase/")],
|
||||
defines : defines,
|
||||
comments_present : true
|
||||
incdirs: vec![PathBuf::from("testcase/")],
|
||||
defines: defines,
|
||||
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);
|
||||
}
|
Loading…
Reference in a new issue