Skip to content

Commit b081e23

Browse files
committed
Cleanup tests
1 parent 0986301 commit b081e23

2 files changed

Lines changed: 4 additions & 67 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ dunce = { version = "1.0", default-features = false }
2828
serde = { version = "1.0", features = ["derive"], optional = true }
2929

3030
[dev-dependencies]
31-
dunce = { version = "1", default-features = false }
32-
uuid = { version = "1", features = ["v4"], default-features = false }
31+
uuid = { version = "1", features = ["v4"], default-features = false }
3332

3433
[features]
3534
default = ["runas"]

tests/roundtrip.rs

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use lnks::{Icon, Shortcut, WindowState};
22
use std::{
33
env,
4-
fmt::{self, Debug},
5-
path::{Path, PathBuf},
4+
path::PathBuf,
65
};
76

87
use crate::temp_path::TempPath;
@@ -27,67 +26,6 @@ fn notepad_path() -> PathBuf {
2726
path
2827
}
2928

30-
fn canonicalize(p: impl AsRef<Path>) -> PathBuf {
31-
let p = p.as_ref();
32-
dunce::canonicalize(p).unwrap_or(p.to_path_buf())
33-
}
34-
35-
pub struct CanonicalEq(pub PathBuf);
36-
37-
impl PartialEq for CanonicalEq {
38-
fn eq(&self, other: &Self) -> bool {
39-
let l = canonicalize(&self.0).into_os_string();
40-
let r = canonicalize(&other.0).into_os_string();
41-
l.eq_ignore_ascii_case(r)
42-
}
43-
}
44-
45-
impl Debug for CanonicalEq {
46-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47-
write!(f, "{}", self.0.display())
48-
}
49-
}
50-
51-
fn assert_path_option_eq(left: &Option<PathBuf>, right: &Option<PathBuf>, message: &str) {
52-
let left = left.as_ref().map(|l| CanonicalEq(l.to_path_buf()));
53-
let right = right.as_ref().map(|r| CanonicalEq(r.to_path_buf()));
54-
assert_eq!(left, right, "{}", message);
55-
}
56-
57-
fn assert_shortcut_eq(left: &Shortcut, right: &Shortcut) {
58-
assert_path_option_eq(
59-
&left.target_path,
60-
&right.target_path,
61-
"target paths do not match",
62-
);
63-
assert_eq!(left.arguments, right.arguments);
64-
assert_path_option_eq(
65-
&left.working_dir,
66-
&right.working_dir,
67-
"working directories do not match",
68-
);
69-
assert_eq!(
70-
left.description, right.description,
71-
"descriptions do not match"
72-
);
73-
assert_eq!(
74-
left.icon.as_ref().map(|l| l.index),
75-
right.icon.as_ref().map(|r| r.index),
76-
"icon indices do not match"
77-
);
78-
assert_path_option_eq(
79-
&left.icon.clone().map(|l| l.path),
80-
&right.icon.clone().map(|r| r.path),
81-
"icon paths do not match",
82-
);
83-
assert_eq!(
84-
left.window_state, right.window_state,
85-
"window states do not match"
86-
);
87-
assert_eq!(left.hotkey, right.hotkey, "hotkeys do not match");
88-
assert_eq!(left.run_as_admin, right.run_as_admin, "runas do not match");
89-
}
90-
9129
#[test]
9230
fn roundtrip_notepad() {
9331
let tmp = TempPath::new(function_name!(), "lnk");
@@ -109,7 +47,7 @@ fn roundtrip_notepad() {
10947
.expect("failed to create shortcut");
11048

11149
let actual = Shortcut::load(tmp.path()).expect("failed to load shortcut");
112-
assert_shortcut_eq(&expected, &actual);
50+
assert_eq!(expected, actual);
11351
}
11452

11553
#[test]
@@ -122,5 +60,5 @@ fn roundtrip_run_as_admin_bit() {
12260
.save(tmp.path())
12361
.expect("failed to create shortcut");
12462
let actual = Shortcut::load(tmp.path()).expect("failed to load shortcut");
125-
assert_shortcut_eq(&expected, &actual);
63+
assert_eq!(expected, actual);
12664
}

0 commit comments

Comments
 (0)