Skip to content

Commit

Permalink
Add test case for ignore_path
Browse files Browse the repository at this point in the history
  • Loading branch information
sasurau4 authored and calebcartwright committed Dec 19, 2020
1 parent d788dde commit 38b4f82
Showing 1 changed file with 40 additions and 14 deletions.
54 changes: 40 additions & 14 deletions src/formatting/syntux/session/ignore_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,48 @@ mod test {

use super::IgnorePathSet;
use crate::config::{Config, FileName};
use crate::is_nightly_channel;

#[test]
fn test_ignore_path_set() {
match option_env!("CFG_RELEASE_CHANNEL") {
// this test requires nightly
None | Some("nightly") => {
let config =
Config::from_toml(r#"ignore = ["foo.rs", "bar_dir/*"]"#, Path::new(""))
.unwrap();
let ignore_path_set = IgnorePathSet::from_ignore_list(&config.ignore()).unwrap();

assert!(ignore_path_set.is_match(&FileName::Real(PathBuf::from("src/foo.rs"))));
assert!(ignore_path_set.is_match(&FileName::Real(PathBuf::from("bar_dir/baz.rs"))));
assert!(!ignore_path_set.is_match(&FileName::Real(PathBuf::from("src/bar.rs"))));
}
_ => {}
};
if !is_nightly_channel!() {
// This test requires nightly
return;
}
let config =
Config::from_toml(r#"ignore = ["foo.rs", "bar_dir/*"]"#, Path::new("")).unwrap();
let ignore_path_set = IgnorePathSet::from_ignore_list(&config.ignore()).unwrap();

assert!(ignore_path_set.is_match(&FileName::Real(PathBuf::from("src/foo.rs"))));
assert!(ignore_path_set.is_match(&FileName::Real(PathBuf::from("bar_dir/baz.rs"))));
assert!(!ignore_path_set.is_match(&FileName::Real(PathBuf::from("src/bar.rs"))));
}
#[test]
fn test_ignore_path_set_with_dir() {
if !is_nightly_channel!() {
// This test requires nightly
return;
}
let config = Config::from_toml(
r#"ignore = ["tests/**/foo/bar.rs"]"#,
Path::new("tests/config/"),
)
.unwrap();
info!(
"rustfmt_toml_path: {:?}",
&config.ignore().rustfmt_toml_path()
);
let ignore_path_set = IgnorePathSet::from_ignore_list(&config.ignore()).unwrap();

assert_eq!(
ignore_path_set.is_match(&FileName::Real(PathBuf::from("tests/source/foo/bar.rs"))),
false
);
assert_eq!(
ignore_path_set.is_match(&FileName::Real(PathBuf::from(
"tests/tests/source/foo/bar.rs"
))),
true
);
}
}

0 comments on commit 38b4f82

Please sign in to comment.