Repository: nushell/nushell
File: crates/nu-cli/tests/completions/mod.rs (Rust)

Code before:
    ];

    // Test source completion
    let completion_str = "source-env ".to_string();
    let suggestions = completer.complete(&completion_str, completion_str.len());

    match_suggestions(&expected, &suggestions);

    // Test use completion
    let completion_str = "use ".to_string();
    let suggestions = completer.complete(&completion_str, completion_str.len());

    match_suggestions(&expected, &suggestions);

    // Test overlay use completion
    let completion_str = "overlay use ".to_string();
    let suggestions = completer.complete(&completion_str, completion_str.len());

    match_suggestions(&expected, &suggestions);

    // Test special paths
    #[cfg(windows)]
    let completion_str = "use \\".to_string();
    #[cfg(not(windows))]
    let completion_str = "use /b".to_string();
    let suggestions = completer.complete(&completion_str, completion_str.len());

    assert!(!suggestions.is_empty());

    let completion_str = "use ~".to_string();
    let suggestions = completer.complete(&completion_str, completion_str.len());

    assert!(!suggestions.is_empty());
}

#[test]
#[ignore]
fn external_completer_trailing_space() {
    // https://github.com/nushell/nushell/issues/6378
    let block = "{|spans| $spans}";
    let input = "gh alias ".to_string();

    let suggestions = run_external_completion(block, &input);
    assert_eq!(3, suggestions.len());
    assert_eq!("gh", suggestions.first().unwrap().value);
    assert_eq!("alias", suggestions.get(1).unwrap().value);
    assert_eq!("", suggestions.get(2).unwrap().value);
}

#[test]
fn external_completer_no_trailing_space() {

Review comment (bug):
Few problems with this:
1. `use \\` and `use /b` test different things
2. `use /b` should also work on Windows, no need for the `#[cfg(not(windows))]`
3. Just checking if the suggestions are empty isn't great. The suggestions could be totally wrong.
4. This test function's starting to get a bit long. It's not a huge problem, and it's not your fault anyway, but it would be best to pull them into a new test function. These new tests don't depend on the `expected` variable above anyway

I think you could have the following tests:
1. Get all files in `/` and make sure that they match completions for `use /` (make this test run on all platforms but also test `use \` for just Windows) 
2. Get the absolute path to the current folder and make sure that completions for `use /absolute/path/to/cwd/` are as expected (again, make a version of this test using backslashes for just Windows)

Additionally, it would be good to set `NU_LIB_DIRS` to something before these tests, just to make sure that files from folders in `NU_LIB_DIRS` aren't suggested for absolute paths. Files from folders in `NU_LIB_DIRS` should also not be suggested for `use ./foo/<TAB>`.

Code after:
            "mod.nu".into(),
            #[cfg(windows)]
            "sub module\\`".into(),
            #[cfg(not(windows))]
            "sub module/`".into(),
        ],
        &suggestions,
    );

    // Test nested nu script, with ending '`'
    #[cfg(windows)]
    let completion_str = "use `.\\dir_module\\sub module\\`".to_string();
    #[cfg(not(windows))]
    let completion_str = "use `./dir_module/sub module/`".to_string();
    let suggestions = completer.complete(&completion_str, completion_str.len());

    match_suggestions(&vec!["sub.nu`".into()], &suggestions);

    let expected = vec![
        "asdf.nu".into(),
        "bar.nu".into(),
        "bat.nu".into(),
        "baz.nu".into(),
        #[cfg(windows)]
        "dir_module\\".into(),
        #[cfg(not(windows))]
        "dir_module/".into(),
        "foo.nu".into(),
        #[cfg(windows)]
        "lib-dir1\\".into(),
        #[cfg(not(windows))]
        "lib-dir1/".into(),
        #[cfg(windows)]
        "lib-dir2\\".into(),
        #[cfg(not(windows))]
        "lib-dir2/".into(),
        #[cfg(windows)]
        "lib-dir3\\".into(),
        #[cfg(not(windows))]
        "lib-dir3/".into(),
        "spam.nu".into(),
        "xyzzy.nu".into(),
    ];

    // Test source completion
    let completion_str = "source-env ".to_string();
    let suggestions = completer.complete(&completion_str, completion_str.len());

    match_suggestions(&expected, &suggestions);

    // Test use completion