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

Code before:
        "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();
    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);


Review comment (suggestion):
`use /` should be tested on all platforms, including Windows

Code after:
        &vec![
            "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);