forked from mirrors/jj
matchers: simplify tests using hashset! macro and improve coverage
This commit is contained in:
parent
0d58060d34
commit
c8f2de1ecc
1 changed files with 44 additions and 23 deletions
|
@ -159,33 +159,35 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn dirs_empty() {
|
fn dirs_empty() {
|
||||||
let dirs = Dirs::new();
|
let dirs = Dirs::new();
|
||||||
assert_eq!(dirs.get_dirs(&DirRepoPath::root()), &HashSet::new());
|
assert_eq!(dirs.get_dirs(&DirRepoPath::root()), &hashset! {});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn dirs_root() {
|
fn dirs_root() {
|
||||||
let mut dirs = Dirs::new();
|
let mut dirs = Dirs::new();
|
||||||
dirs.add_dir(DirRepoPath::root());
|
dirs.add_dir(DirRepoPath::root());
|
||||||
assert_eq!(dirs.get_dirs(&DirRepoPath::root()), &HashSet::new());
|
assert_eq!(dirs.get_dirs(&DirRepoPath::root()), &hashset! {});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn dirs_dir() {
|
fn dirs_dir() {
|
||||||
let mut dirs = Dirs::new();
|
let mut dirs = Dirs::new();
|
||||||
dirs.add_dir(DirRepoPath::from("dir/"));
|
dirs.add_dir(DirRepoPath::from("dir/"));
|
||||||
let mut expected_root_dirs = HashSet::new();
|
assert_eq!(
|
||||||
expected_root_dirs.insert(DirRepoPathComponent::from("dir"));
|
dirs.get_dirs(&DirRepoPath::root()),
|
||||||
assert_eq!(dirs.get_dirs(&DirRepoPath::root()), &expected_root_dirs);
|
&hashset! {DirRepoPathComponent::from("dir")}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn dirs_file() {
|
fn dirs_file() {
|
||||||
let mut dirs = Dirs::new();
|
let mut dirs = Dirs::new();
|
||||||
dirs.add_file(&FileRepoPath::from("dir/file"));
|
dirs.add_file(&FileRepoPath::from("dir/file"));
|
||||||
let mut expected_root_dirs = HashSet::new();
|
assert_eq!(
|
||||||
expected_root_dirs.insert(DirRepoPathComponent::from("dir"));
|
dirs.get_dirs(&DirRepoPath::root()),
|
||||||
assert_eq!(dirs.get_dirs(&DirRepoPath::root()), &expected_root_dirs);
|
&hashset! {DirRepoPathComponent::from("dir")}
|
||||||
assert_eq!(dirs.get_files(&DirRepoPath::root()), &HashSet::new());
|
);
|
||||||
|
assert_eq!(dirs.get_files(&DirRepoPath::root()), &hashset! {});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -204,24 +206,43 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn filesmatcher_nonempty() {
|
fn filesmatcher_nonempty() {
|
||||||
let mut files = HashSet::new();
|
let m = FilesMatcher::new(hashset! {
|
||||||
files.insert(FileRepoPath::from("dir1/subdir1/file1"));
|
FileRepoPath::from("dir1/subdir1/file1"),
|
||||||
files.insert(FileRepoPath::from("dir1/subdir1/file2"));
|
FileRepoPath::from("dir1/subdir1/file2"),
|
||||||
files.insert(FileRepoPath::from("dir1/subdir2/file3"));
|
FileRepoPath::from("dir1/subdir2/file3"),
|
||||||
files.insert(FileRepoPath::from("file4"));
|
FileRepoPath::from("file4"),
|
||||||
let m = FilesMatcher::new(files);
|
});
|
||||||
|
|
||||||
let expected_root_files = vec![FileRepoPathComponent::from("file4")]
|
|
||||||
.into_iter()
|
|
||||||
.collect();
|
|
||||||
let expected_root_dirs = vec![DirRepoPathComponent::from("dir1")]
|
|
||||||
.into_iter()
|
|
||||||
.collect();
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
m.visit(&DirRepoPath::root()),
|
m.visit(&DirRepoPath::root()),
|
||||||
Visit {
|
Visit {
|
||||||
dirs: VisitDirs::Set(&expected_root_dirs),
|
dirs: VisitDirs::Set(&hashset! {DirRepoPathComponent::from("dir1")}),
|
||||||
files: VisitFiles::Set(&expected_root_files),
|
files: VisitFiles::Set(&hashset! {FileRepoPathComponent::from("file4")}),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
m.visit(&DirRepoPath::from("dir1/")),
|
||||||
|
Visit {
|
||||||
|
dirs: VisitDirs::Set(
|
||||||
|
&hashset! {DirRepoPathComponent::from("subdir1"), DirRepoPathComponent::from("subdir2")}
|
||||||
|
),
|
||||||
|
files: VisitFiles::Set(&hashset! {}),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
m.visit(&DirRepoPath::from("dir1/subdir1/")),
|
||||||
|
Visit {
|
||||||
|
dirs: VisitDirs::Set(&hashset! {}),
|
||||||
|
files: VisitFiles::Set(
|
||||||
|
&hashset! {FileRepoPathComponent::from("file1"), FileRepoPathComponent::from("file2")}
|
||||||
|
),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
m.visit(&DirRepoPath::from("dir1/subdir2/")),
|
||||||
|
Visit {
|
||||||
|
dirs: VisitDirs::Set(&hashset! {}),
|
||||||
|
files: VisitFiles::Set(&hashset! {FileRepoPathComponent::from("file3")}),
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue