@@ -43,12 +43,17 @@ async fn test_open_path_prompt(cx: &mut TestAppContext) {
insert_query(query, &picker, cx).await;
assert_eq!(collect_match_candidates(&picker, cx), vec!["root"]);
+ #[cfg(not(windows))]
+ let expected_separator = "./";
+ #[cfg(windows)]
+ let expected_separator = ".\\";
+
// If the query ends with a slash, the picker should show the contents of the directory.
let query = path!("/root/");
insert_query(query, &picker, cx).await;
assert_eq!(
collect_match_candidates(&picker, cx),
- vec!["a1", "a2", "a3", "dir1", "dir2"]
+ vec![expected_separator, "a1", "a2", "a3", "dir1", "dir2"]
);
// Show candidates for the query "a".
@@ -72,7 +77,7 @@ async fn test_open_path_prompt(cx: &mut TestAppContext) {
insert_query(query, &picker, cx).await;
assert_eq!(
collect_match_candidates(&picker, cx),
- vec!["c", "d1", "d2", "d3", "dir3", "dir4"]
+ vec![expected_separator, "c", "d1", "d2", "d3", "dir3", "dir4"]
);
// Show candidates for the query "d".
@@ -116,71 +121,86 @@ async fn test_open_path_prompt_completion(cx: &mut TestAppContext) {
// Confirm completion for the query "/root", since it's a directory, it should add a trailing slash.
let query = path!("/root");
insert_query(query, &picker, cx).await;
- assert_eq!(confirm_completion(query, 0, &picker, cx), path!("/root/"));
+ assert_eq!(
+ confirm_completion(query, 0, &picker, cx).unwrap(),
+ path!("/root/")
+ );
// Confirm completion for the query "/root/", selecting the first candidate "a", since it's a file, it should not add a trailing slash.
let query = path!("/root/");
insert_query(query, &picker, cx).await;
- assert_eq!(confirm_completion(query, 0, &picker, cx), path!("/root/a"));
+ assert_eq!(
+ confirm_completion(query, 0, &picker, cx),
+ None,
+ "First entry is `./` and when we confirm completion, it is tabbed below"
+ );
+ assert_eq!(
+ confirm_completion(query, 1, &picker, cx).unwrap(),
+ path!("/root/a"),
+ "Second entry is the first entry of a directory that we want to be completed"
+ );
// Confirm completion for the query "/root/", selecting the second candidate "dir1", since it's a directory, it should add a trailing slash.
let query = path!("/root/");
insert_query(query, &picker, cx).await;
assert_eq!(
- confirm_completion(query, 1, &picker, cx),
+ confirm_completion(query, 2, &picker, cx).unwrap(),
path!("/root/dir1/")
);
let query = path!("/root/a");
insert_query(query, &picker, cx).await;
- assert_eq!(confirm_completion(query, 0, &picker, cx), path!("/root/a"));
+ assert_eq!(
+ confirm_completion(query, 0, &picker, cx).unwrap(),
+ path!("/root/a")
+ );
let query = path!("/root/d");
insert_query(query, &picker, cx).await;
assert_eq!(
- confirm_completion(query, 1, &picker, cx),
+ confirm_completion(query, 1, &picker, cx).unwrap(),
path!("/root/dir2/")
);
let query = path!("/root/dir2");
insert_query(query, &picker, cx).await;
assert_eq!(
- confirm_completion(query, 0, &picker, cx),
+ confirm_completion(query, 0, &picker, cx).unwrap(),
path!("/root/dir2/")
);
let query = path!("/root/dir2/");
insert_query(query, &picker, cx).await;
assert_eq!(
- confirm_completion(query, 0, &picker, cx),
+ confirm_completion(query, 1, &picker, cx).unwrap(),
path!("/root/dir2/c")
);
let query = path!("/root/dir2/");
insert_query(query, &picker, cx).await;
assert_eq!(
- confirm_completion(query, 2, &picker, cx),
+ confirm_completion(query, 3, &picker, cx).unwrap(),
path!("/root/dir2/dir3/")
);
let query = path!("/root/dir2/d");
insert_query(query, &picker, cx).await;
assert_eq!(
- confirm_completion(query, 0, &picker, cx),
+ confirm_completion(query, 0, &picker, cx).unwrap(),
path!("/root/dir2/d")
);
let query = path!("/root/dir2/d");
insert_query(query, &picker, cx).await;
assert_eq!(
- confirm_completion(query, 1, &picker, cx),
+ confirm_completion(query, 1, &picker, cx).unwrap(),
path!("/root/dir2/dir3/")
);
let query = path!("/root/dir2/di");
insert_query(query, &picker, cx).await;
assert_eq!(
- confirm_completion(query, 1, &picker, cx),
+ confirm_completion(query, 1, &picker, cx).unwrap(),
path!("/root/dir2/dir4/")
);
}
@@ -211,42 +231,63 @@ async fn test_open_path_prompt_on_windows(cx: &mut TestAppContext) {
insert_query(query, &picker, cx).await;
assert_eq!(
collect_match_candidates(&picker, cx),
- vec!["a", "dir1", "dir2"]
+ vec![".\\", "a", "dir1", "dir2"]
+ );
+ assert_eq!(
+ confirm_completion(query, 0, &picker, cx),
+ None,
+ "First entry is `.\\` and when we confirm completion, it is tabbed below"
+ );
+ assert_eq!(
+ confirm_completion(query, 1, &picker, cx).unwrap(),
+ "C:/root/a",
+ "Second entry is the first entry of a directory that we want to be completed"
);
- assert_eq!(confirm_completion(query, 0, &picker, cx), "C:/root/a");
let query = "C:\\root/";
insert_query(query, &picker, cx).await;
assert_eq!(
collect_match_candidates(&picker, cx),
- vec!["a", "dir1", "dir2"]
+ vec![".\\", "a", "dir1", "dir2"]
+ );
+ assert_eq!(
+ confirm_completion(query, 1, &picker, cx).unwrap(),
+ "C:\\root/a"
);
- assert_eq!(confirm_completion(query, 0, &picker, cx), "C:\\root/a");
let query = "C:\\root\\";
insert_query(query, &picker, cx).await;
assert_eq!(
collect_match_candidates(&picker, cx),
- vec!["a", "dir1", "dir2"]
+ vec![".\\", "a", "dir1", "dir2"]
+ );
+ assert_eq!(
+ confirm_completion(query, 1, &picker, cx).unwrap(),
+ "C:\\root\\a"
);
- assert_eq!(confirm_completion(query, 0, &picker, cx), "C:\\root\\a");
// Confirm completion for the query "C:/root/d", selecting the second candidate "dir2", since it's a directory, it should add a trailing slash.
let query = "C:/root/d";
insert_query(query, &picker, cx).await;
assert_eq!(collect_match_candidates(&picker, cx), vec!["dir1", "dir2"]);
- assert_eq!(confirm_completion(query, 1, &picker, cx), "C:/root/dir2\\");
+ assert_eq!(
+ confirm_completion(query, 1, &picker, cx).unwrap(),
+ "C:/root/dir2\\"
+ );
let query = "C:\\root/d";
insert_query(query, &picker, cx).await;
assert_eq!(collect_match_candidates(&picker, cx), vec!["dir1", "dir2"]);
- assert_eq!(confirm_completion(query, 0, &picker, cx), "C:\\root/dir1\\");
+ assert_eq!(
+ confirm_completion(query, 0, &picker, cx).unwrap(),
+ "C:\\root/dir1\\"
+ );
let query = "C:\\root\\d";
insert_query(query, &picker, cx).await;
assert_eq!(collect_match_candidates(&picker, cx), vec!["dir1", "dir2"]);
assert_eq!(
- confirm_completion(query, 0, &picker, cx),
+ confirm_completion(query, 0, &picker, cx).unwrap(),
"C:\\root\\dir1\\"
);
}
@@ -276,20 +317,29 @@ async fn test_open_path_prompt_on_windows_with_remote(cx: &mut TestAppContext) {
insert_query(query, &picker, cx).await;
assert_eq!(
collect_match_candidates(&picker, cx),
- vec!["a", "dir1", "dir2"]
+ vec!["./", "a", "dir1", "dir2"]
+ );
+ assert_eq!(
+ confirm_completion(query, 1, &picker, cx).unwrap(),
+ "/root/a"
);
- assert_eq!(confirm_completion(query, 0, &picker, cx), "/root/a");
// Confirm completion for the query "/root/d", selecting the second candidate "dir2", since it's a directory, it should add a trailing slash.
let query = "/root/d";
insert_query(query, &picker, cx).await;
assert_eq!(collect_match_candidates(&picker, cx), vec!["dir1", "dir2"]);
- assert_eq!(confirm_completion(query, 1, &picker, cx), "/root/dir2/");
+ assert_eq!(
+ confirm_completion(query, 1, &picker, cx).unwrap(),
+ "/root/dir2/"
+ );
let query = "/root/d";
insert_query(query, &picker, cx).await;
assert_eq!(collect_match_candidates(&picker, cx), vec!["dir1", "dir2"]);
- assert_eq!(confirm_completion(query, 0, &picker, cx), "/root/dir1/");
+ assert_eq!(
+ confirm_completion(query, 0, &picker, cx).unwrap(),
+ "/root/dir1/"
+ );
}
#[gpui::test]
@@ -396,15 +446,13 @@ fn confirm_completion(
select: usize,
picker: &Entity<Picker<OpenPathDelegate>>,
cx: &mut VisualTestContext,
-) -> String {
- picker
- .update_in(cx, |f, window, cx| {
- if f.delegate.selected_index() != select {
- f.delegate.set_selected_index(select, window, cx);
- }
- f.delegate.confirm_completion(query.to_string(), window, cx)
- })
- .unwrap()
+) -> Option<String> {
+ picker.update_in(cx, |f, window, cx| {
+ if f.delegate.selected_index() != select {
+ f.delegate.set_selected_index(select, window, cx);
+ }
+ f.delegate.confirm_completion(query.to_string(), window, cx)
+ })
}
fn collect_match_candidates(