Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

fix(tests): make Windows path spellings match folder-tree widget ids

mahmatiase3d2654bd291
diff --git a/crates/catalog/src/store.rs b/crates/catalog/src/store.rs
index 2f3dc4912..7382022cf 100644
--- a/crates/catalog/src/store.rs
+++ b/crates/catalog/src/store.rs
@@ -244,6 +244,8 @@ impl Store for MemStore {
#[cfg(test)]
mod tests_staging {
+ // the module's only test is unix-only; the import would be unused on windows
+ #[cfg(unix)]
use super::*;
/// A link planted at a staging name (`<name>.tmp`) is removed, never followed: the file it points to keeps its
diff --git a/crates/engine/src/tests_export.rs b/crates/engine/src/tests_export.rs
index 0ac8df804..e7afc1a8b 100644
--- a/crates/engine/src/tests_export.rs
+++ b/crates/engine/src/tests_export.rs
@@ -991,8 +991,13 @@ fn same_folder_as_original_exports_next_to_each_photo() {
let exists = |p: &str| std::path::Path::new(p).exists();
let files = crate::export::export_batch(&mut s, &ids, &o, &to, &mut crate::export::write_file, &exists).unwrap();
let written: Vec<&str> = files.iter().map(|f| f["path"].as_str().unwrap()).collect();
- let mut want = vec![a.join("Exports/IMG_1.jpg").to_string_lossy().to_string(), b.join("Exports/IMG_1.jpg").to_string_lossy().to_string()];
- let mut got: Vec<String> = written.iter().map(|p| p.to_string()).collect();
+ let norm = |s: &str| s.replace('\\', "/");
+ let mut want: Vec<String> =
+ [a.join("Exports/IMG_1.jpg").to_string_lossy().to_string(), b.join("Exports/IMG_1.jpg").to_string_lossy().to_string()]
+ .iter()
+ .map(|p| norm(p))
+ .collect();
+ let mut got: Vec<String> = written.iter().map(|p| norm(p)).collect();
want.sort();
got.sort();
assert_eq!(got, want);
diff --git a/crates/ui-egui/src/tests_folder_drop.rs b/crates/ui-egui/src/tests_folder_drop.rs
index 9b4cb860a..f4a761cec 100644
--- a/crates/ui-egui/src/tests_folder_drop.rs
+++ b/crates/ui-egui/src/tests_folder_drop.rs
@@ -50,8 +50,14 @@ fn widget(h: &Headless, id: &str) -> Option<Rect> {
h.app.widgets.iter().find(|(w, _)| w == id).map(|(_, r)| *r)
}
+/// A folder's path as its row writes it: `FolderNode.path` uses `/` on every platform, while
+/// `to_string_lossy` gives Windows `\`.
+fn row_path(dir: &Path) -> String {
+ dir.to_string_lossy().replace('\\', "/")
+}
+
fn folder_row(h: &Headless, dir: &Path) -> Option<Rect> {
- widget(h, &format!("source:libfolder:{}", dir.to_string_lossy()))
+ widget(h, &format!("source:libfolder:{}", row_path(dir)))
}
fn id_of(h: &Headless, file: &str) -> u64 {
@@ -180,7 +186,7 @@ fn photos_already_in_the_folder_stay_put() {
let (root, trip, home) = folders("here");
let mut h = app(&[(trip.join("beach.png"), false), (home.join("garden.png"), false)]);
// open the folder holding both
- let toggle = widget(&h, &format!("libraryFolderToggle:{}", root.to_string_lossy())).unwrap();
+ let toggle = widget(&h, &format!("libraryFolderToggle:{}", row_path(&root))).unwrap();
h.app.synthetic.push(egui::Event::PointerMoved(toggle.center()));
h.app.synthetic.push(egui::Event::PointerButton {
pos: toggle.center(),
@@ -284,7 +290,7 @@ fn cancelling_the_question_moves_nothing() {
let target = if folder_row(&h, &home).is_some() {
target
} else {
- click(&mut h, &format!("libraryFolderToggle:{}", root.to_string_lossy()));
+ click(&mut h, &format!("libraryFolderToggle:{}", row_path(&root)));
folder_row(&h, &home).unwrap()
};
let undo = h.app.session.undo.len();
@@ -302,7 +308,7 @@ fn dont_ask_again_moves_the_next_drop_at_once() {
let (root, trip, home) = folders("dont-ask");
std::fs::copy(trip.join("beach.png"), trip.join("dunes.png")).unwrap();
let mut h = app(&[(trip.join("beach.png"), false), (trip.join("dunes.png"), false), (home.join("garden.png"), false)]);
- click(&mut h, &format!("libraryFolderToggle:{}", root.to_string_lossy()));
+ click(&mut h, &format!("libraryFolderToggle:{}", row_path(&root)));
let target = folder_row(&h, &home).unwrap();
let beach = id_of(&h, "beach.png");
h.app.session.selection = lightcraft_engine::Selection::single(lightcraft_catalog::PhotoId(beach));
@@ -327,7 +333,7 @@ fn dont_ask_again_moves_the_next_drop_at_once() {
fn a_question_left_open_while_another_library_opens_moves_nothing() {
let (root, trip, home) = folders("other-library");
let mut h = app(&[(trip.join("beach.png"), false), (home.join("garden.png"), false)]);
- click(&mut h, &format!("libraryFolderToggle:{}", root.to_string_lossy()));
+ click(&mut h, &format!("libraryFolderToggle:{}", row_path(&root)));
let beach = id_of(&h, "beach.png");
let target = folder_row(&h, &home).unwrap();
drop_beach(&mut h, beach, target);