From 404f950b09c65ff49c4997cc4b646a24cb8ca651 Mon Sep 17 00:00:00 2001 From: wongjiahau Date: Wed, 22 Mar 2023 09:08:51 +0800 Subject: [PATCH] fix(tests/explorer/new_folder): failing on Windows Co-authored-by: LEI Reference: https://github.com/helix-editor/helix/pull/5768#discussion_r1143991188 --- helix-term/src/ui/explorer.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/helix-term/src/ui/explorer.rs b/helix-term/src/ui/explorer.rs index 5d6bc1ce..5dc53d90 100644 --- a/helix-term/src/ui/explorer.rs +++ b/helix-term/src/ui/explorer.rs @@ -994,17 +994,22 @@ mod test_explorer { // 0. Open the add file/folder prompt explorer.handle_events("a").unwrap(); let prompt = &explorer.prompt.as_ref().unwrap().1; - fn sanitize(s: &str) -> String { + fn to_forward_slash(s: &str) -> String { s.replace(std::path::MAIN_SEPARATOR, "/") } + fn to_os_main_separator(s: &str) -> String { + s.replace('/', format!("{}", std::path::MAIN_SEPARATOR).as_str()) + } assert_eq!( - sanitize(&prompt.prompt()), + to_forward_slash(&prompt.prompt()), " New file or folder (ends with '/'): " ); - assert_eq!(sanitize(prompt.line()), "test_explorer/new_folder/"); + assert_eq!(to_forward_slash(prompt.line()), "test_explorer/new_folder/"); // 1. Add a new folder at the root - explorer.handle_events(&sanitize("yoyo/")).unwrap(); + explorer + .handle_events(&to_os_main_separator("yoyo/")) + .unwrap(); // 1a. Expect the new folder is added, and is focused assert_eq!( @@ -1027,7 +1032,7 @@ mod test_explorer { // 3. Add a new folder explorer - .handle_events(&sanitize("asus.sass/")) + .handle_events(&to_os_main_separator("asus.sass/")) .unwrap(); // 3a. Expect the new folder is added under "styles", although "styles" is not opened @@ -1050,7 +1055,9 @@ mod test_explorer { assert!(fs::read_dir(path.join("styles/sus.sass")).is_ok()); // 4. Add a new folder with non-existent parents - explorer.handle_events(&sanitize("aa/b/c/")).unwrap(); + explorer + .handle_events(&to_os_main_separator("aa/b/c/")) + .unwrap(); // 4a. Expect the non-existent parents are created, // and the new folder is created, @@ -1078,7 +1085,9 @@ mod test_explorer { explorer.handle_events("j").unwrap(); // 6. Add a new folder here - explorer.handle_events(&sanitize("afoobar/")).unwrap(); + explorer + .handle_events(&to_os_main_separator("afoobar/")) + .unwrap(); // 6a. Expect the folder is added under "styles", // because the folder of the current item, "style.css" is "styles/"