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

Code before:

    // 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 /".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]
fn dotnu_completions_const_nu_lib_dirs() {
    let (_, _, engine, stack) = new_dotnu_engine();
    let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));

    // file in `lib-dir1/`
    let completion_str = "use xyzz".to_string();
    let suggestions = completer.complete(&completion_str, completion_str.len());
    match_suggestions(&vec!["xyzzy.nu".into()], &suggestions);

    // file in `lib-dir2/`
    let completion_str = "use asdf".to_string();
    let suggestions = completer.complete(&completion_str, completion_str.len());
    match_suggestions(&vec!["asdf.nu".into()], &suggestions);

    // if `./` specified by user, file in `lib-dir*` should be ignored
    #[cfg(windows)]
    {
        let completion_str = "use .\\asdf".to_string();
        let suggestions = completer.complete(&completion_str, completion_str.len());
        assert!(suggestions.is_empty());
    }
    let completion_str = "use ./asdf".to_string();

Review comment (suggestion):
Once the symlink issue is fixed, these tests should use something like `std::fs::read_dir` to make sure that all files in `/` or `~` are listed. If you don't feel like implementing that just to `#[ignore]` it, you can just leave a `// TODO` in there for now and it can be handled in a later PR.

Code after:
    );

    // 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
    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();