Skip to content

Commit 7809149

Browse files
committed
test: Move tests to their own module
1 parent 265da88 commit 7809149

File tree

2 files changed

+75
-73
lines changed

2 files changed

+75
-73
lines changed

src/utils.rs

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -13,76 +13,4 @@ pub fn path_name(path: &Path) -> OsStringDisplay {
1313
}
1414

1515
#[cfg(test)]
16-
use pretty_assertions::assert_eq;
17-
#[cfg(test)]
18-
use std::path::PathBuf;
19-
20-
#[test]
21-
fn empty() {
22-
let actual = path_name(&PathBuf::new());
23-
let expected = OsStringDisplay::os_string_from(".");
24-
assert_eq!(actual, expected);
25-
}
26-
27-
#[test]
28-
fn current_dir() {
29-
let actual = path_name(&PathBuf::from("."));
30-
let expected = OsStringDisplay::os_string_from(".");
31-
assert_eq!(actual, expected);
32-
}
33-
34-
#[cfg(unix)]
35-
#[test]
36-
fn root_dir() {
37-
let actual = path_name(&PathBuf::from("/"));
38-
let expected = OsStringDisplay::os_string_from("/");
39-
assert_eq!(actual, expected);
40-
}
41-
42-
#[cfg(windows)]
43-
#[test]
44-
fn root_dir() {
45-
let actual = path_name(&PathBuf::from("C:\\"));
46-
let expected = OsStringDisplay::os_string_from("c:");
47-
assert_eq!(actual, expected);
48-
}
49-
50-
#[cfg(unix)]
51-
#[test]
52-
fn normal_relative() {
53-
let actual = path_name(&PathBuf::from("abc/def/ghi"));
54-
let expected = OsStringDisplay::os_string_from("ghi");
55-
assert_eq!(actual, expected);
56-
}
57-
58-
#[cfg(unix)]
59-
#[test]
60-
fn normal_absolute() {
61-
let actual = path_name(&PathBuf::from("/abc/def/ghi"));
62-
let expected = OsStringDisplay::os_string_from("ghi");
63-
assert_eq!(actual, expected);
64-
}
65-
66-
#[cfg(unix)]
67-
#[test]
68-
fn normal_trailing_separator() {
69-
let actual = path_name(&PathBuf::from("abc/def/ghi/"));
70-
let expected = OsStringDisplay::os_string_from("ghi");
71-
assert_eq!(actual, expected);
72-
}
73-
74-
#[cfg(unix)]
75-
#[test]
76-
fn parent_dir() {
77-
let actual = path_name(&PathBuf::from(".."));
78-
let expected = OsStringDisplay::os_string_from("..");
79-
assert_eq!(actual, expected);
80-
}
81-
82-
#[cfg(unix)]
83-
#[test]
84-
fn grandparent_dir() {
85-
let actual = path_name(&PathBuf::from("../.."));
86-
let expected = OsStringDisplay::os_string_from("../..");
87-
assert_eq!(actual, expected);
88-
}
16+
mod test_path_name;

src/utils/test_path_name.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
use super::path_name;
2+
use crate::os_string_display::OsStringDisplay;
3+
use pretty_assertions::assert_eq;
4+
use std::path::PathBuf;
5+
6+
#[test]
7+
fn empty() {
8+
let actual = path_name(&PathBuf::new());
9+
let expected = OsStringDisplay::os_string_from(".");
10+
assert_eq!(actual, expected);
11+
}
12+
13+
#[test]
14+
fn current_dir() {
15+
let actual = path_name(&PathBuf::from("."));
16+
let expected = OsStringDisplay::os_string_from(".");
17+
assert_eq!(actual, expected);
18+
}
19+
20+
#[cfg(unix)]
21+
#[test]
22+
fn root_dir() {
23+
let actual = path_name(&PathBuf::from("/"));
24+
let expected = OsStringDisplay::os_string_from("/");
25+
assert_eq!(actual, expected);
26+
}
27+
28+
#[cfg(windows)]
29+
#[test]
30+
fn root_dir() {
31+
let actual = path_name(&PathBuf::from("C:\\"));
32+
let expected = OsStringDisplay::os_string_from("c:");
33+
assert_eq!(actual, expected);
34+
}
35+
36+
#[cfg(unix)]
37+
#[test]
38+
fn normal_relative() {
39+
let actual = path_name(&PathBuf::from("abc/def/ghi"));
40+
let expected = OsStringDisplay::os_string_from("ghi");
41+
assert_eq!(actual, expected);
42+
}
43+
44+
#[cfg(unix)]
45+
#[test]
46+
fn normal_absolute() {
47+
let actual = path_name(&PathBuf::from("/abc/def/ghi"));
48+
let expected = OsStringDisplay::os_string_from("ghi");
49+
assert_eq!(actual, expected);
50+
}
51+
52+
#[cfg(unix)]
53+
#[test]
54+
fn normal_trailing_separator() {
55+
let actual = path_name(&PathBuf::from("abc/def/ghi/"));
56+
let expected = OsStringDisplay::os_string_from("ghi");
57+
assert_eq!(actual, expected);
58+
}
59+
60+
#[cfg(unix)]
61+
#[test]
62+
fn parent_dir() {
63+
let actual = path_name(&PathBuf::from(".."));
64+
let expected = OsStringDisplay::os_string_from("..");
65+
assert_eq!(actual, expected);
66+
}
67+
68+
#[cfg(unix)]
69+
#[test]
70+
fn grandparent_dir() {
71+
let actual = path_name(&PathBuf::from("../.."));
72+
let expected = OsStringDisplay::os_string_from("../..");
73+
assert_eq!(actual, expected);
74+
}

0 commit comments

Comments
 (0)