mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-26 13:56:27 +00:00
Extract function for parsing an ignore file
This commit is contained in:
parent
1f23f3f0cc
commit
7b5b02d9f1
@ -39,7 +39,7 @@ impl IgnoreCache {
|
|||||||
|
|
||||||
match file.read_to_string(&mut contents) {
|
match file.read_to_string(&mut contents) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let (patterns, mut _errors) = IgnorePatterns::parse_from_iter(contents.lines());
|
let patterns = file_lines_to_patterns(contents.lines());
|
||||||
entries.push((p.into(), patterns));
|
entries.push((p.into(), patterns));
|
||||||
}
|
}
|
||||||
Err(e) => debug!("Failed to read a .gitignore: {:?}", e)
|
Err(e) => debug!("Failed to read a .gitignore: {:?}", e)
|
||||||
@ -68,10 +68,32 @@ impl IgnoreCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn file_lines_to_patterns<'a, I>(iter: I) -> IgnorePatterns
|
||||||
|
where I: Iterator<Item=&'a str> {
|
||||||
|
// Errors are currently being ignored... not a good look
|
||||||
|
IgnorePatterns::parse_from_iter(iter).0
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_nothing() {
|
||||||
|
use std::iter::empty;
|
||||||
|
let (patterns, _) = IgnorePatterns::parse_from_iter(empty());
|
||||||
|
assert_eq!(patterns, file_lines_to_patterns(empty()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_some_globs() {
|
||||||
|
let stuff = vec![ "*.mp3", "README.md" ];
|
||||||
|
let (patterns, _) = IgnorePatterns::parse_from_iter(stuff.iter().cloned());
|
||||||
|
assert_eq!(patterns, file_lines_to_patterns(stuff.into_iter()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn empty() {
|
fn empty() {
|
||||||
let ignores = IgnoreCache::default();
|
let ignores = IgnoreCache::default();
|
||||||
|
Loading…
Reference in New Issue
Block a user