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::collections::HashMap;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use regex::Regex;
|
|
||||||
|
|
||||||
use crate::line_parser;
|
use crate::line_parser;
|
||||||
use crate::line_parser::LineType;
|
use crate::line_parser::LineType;
|
||||||
|
@ -45,11 +45,13 @@ pub fn parse_file(path: &str) -> Result<Filelist, Box<dyn Error>> {
|
||||||
LineType::Define(define_map) => {
|
LineType::Define(define_map) => {
|
||||||
for (d, t) in define_map.into_iter() {
|
for (d, t) in define_map.into_iter() {
|
||||||
match t {
|
match t {
|
||||||
Some(text) => filelist.defines.insert(d.to_string(), Some(text.to_string())),
|
Some(text) => filelist
|
||||||
None => filelist.defines.insert(d.to_string(), None)
|
.defines
|
||||||
|
.insert(d.to_string(), Some(text.to_string())),
|
||||||
|
None => filelist.defines.insert(d.to_string(), None),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
LineType::IncDir(incdirs) => {
|
LineType::IncDir(incdirs) => {
|
||||||
for dir in incdirs {
|
for dir in incdirs {
|
||||||
filelist.incdirs.push(PathBuf::from(dir));
|
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::Comment => filelist.comments_present = true,
|
||||||
LineType::Filelist(path) => {
|
LineType::Filelist(path) => {
|
||||||
filelist.extend(parse_file(path)?);
|
filelist.extend(parse_file(path)?);
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(filelist)
|
Ok(filelist)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
pub mod line_parser;
|
|
||||||
pub mod file_parser;
|
pub mod file_parser;
|
||||||
|
pub mod line_parser;
|
||||||
|
|
||||||
pub use file_parser::Filelist;
|
pub use file_parser::Filelist;
|
||||||
use std::error::Error;
|
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 defines = line.trim_start_matches("+define+").trim_end_matches('+');
|
||||||
let mut define_map = HashMap::new();
|
let mut define_map = HashMap::new();
|
||||||
for define in defines.split('+') {
|
for define in defines.split('+') {
|
||||||
if let Some(pos) = define.find("=") {
|
if let Some(pos) = define.find('=') {
|
||||||
let (d, t) = define.split_at(pos);
|
let (d, t) = define.split_at(pos);
|
||||||
define_map.insert(d, Some(&t[1..]));
|
define_map.insert(d, Some(&t[1..]));
|
||||||
} else {
|
} else {
|
||||||
|
@ -98,6 +98,9 @@ mod test {
|
||||||
#[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";
|
||||||
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::env;
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::path::PathBuf;
|
||||||
use sv_filelist_parser;
|
use sv_filelist_parser;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
|
|
||||||
let filelist = sv_filelist_parser::parse(&args[1])
|
let filelist = sv_filelist_parser::parse(&args[1]).expect("Error parsing");
|
||||||
.expect("Error parsing");
|
|
||||||
println!("{:#?}", filelist);
|
println!("{:#?}", filelist);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use sv_filelist_parser;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use sv_filelist_parser;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn simple_test() {
|
fn simple_test() {
|
||||||
|
@ -21,14 +21,13 @@ fn simple_test() {
|
||||||
],
|
],
|
||||||
incdirs: vec![PathBuf::from("testcase/")],
|
incdirs: vec![PathBuf::from("testcase/")],
|
||||||
defines: defines,
|
defines: defines,
|
||||||
comments_present : true
|
comments_present: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add env vars
|
// Add env vars
|
||||||
std::env::set_var("VAR1", "ENV_VAR1");
|
std::env::set_var("VAR1", "ENV_VAR1");
|
||||||
std::env::set_var("VAR2", "ENV_VAR2");
|
std::env::set_var("VAR2", "ENV_VAR2");
|
||||||
|
|
||||||
let filelist = sv_filelist_parser::parse("testcase/files.f")
|
let filelist = sv_filelist_parser::parse("testcase/files.f").expect("Error parsing");
|
||||||
.expect("Error parsing");
|
|
||||||
assert_eq!(filelist_exp, filelist);
|
assert_eq!(filelist_exp, filelist);
|
||||||
}
|
}
|
Loading…
Reference in a new issue