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

Code before:
    let suggestions = extern_completer.complete("spam -b ", 8);
    let expected: Vec<_> = vec!["cat", "dog", "eel"];
    match_suggestions(&expected, &suggestions);
}

/// When we're completing the flag name itself, not its value,
/// custom completions should not be used
#[rstest]
fn custom_completion_flag_name_not_value(mut extern_completer: NuCompleter) {
    let suggestions = extern_completer.complete("spam --f", 8);
    assert!(
        suggestions.iter().any(|s| s.value == "--foo"),
        "Should contain --foo flag"
    );
    let should_not_contain: Vec<_> = vec!["cat", "dog", "eel"];
    for item in should_not_contain {
        assert!(
            !suggestions.iter().any(|s| s.value == item),
            "Should not contain custom completion {}",
            item
        );
    }

    // Also test with partial short flag
    let suggestions = extern_completer.complete("spam -f", 7);
    assert_eq!(1, suggestions.len(), "Should only have one suggestion");
    assert_eq!("-f", suggestions[0].value, "Should suggest -f flag");
}

#[rstest]
fn extern_complete_flags(mut extern_completer: NuCompleter) {
    let suggestions = extern_completer.complete("spam -", 6);
    let expected: Vec<_> = vec!["--foo", "-b", "-f"];
    match_suggestions(&expected, &suggestions);
}

#[rstest]
fn custom_completer_triggers_cursor_before_word(mut custom_completer: NuCompleter) {
    let suggestions = custom_completer.complete("cmd foo  bar", 8);
    let expected: Vec<_> = vec!["cmd", "foo", ""];
    match_suggestions(&expected, &suggestions);
}

#[rstest]
fn custom_completer_triggers_cursor_on_word_left_boundary(mut custom_completer: NuCompleter) {
    let suggestions = custom_completer.complete("cmd foo bar", 8);
    let expected: Vec<_> = vec!["cmd", "foo", ""];
    match_suggestions(&expected, &suggestions);
}

#[rstest]

Review comment (suggestion):
Apart from flags, I'd like to also see a test case for a command like `def foo [ ...rest: string@completer ]`, to make sure that completions for rest parameters work. I couldn't find any such tests already in this file

Code after:
    match_suggestions(&expected, &suggestions);
}

#[rstest]
fn extern_custom_completion_long_flag_2(mut extern_completer: NuCompleter) {
    let suggestions = extern_completer.complete("spam --foo ", 11);
    let expected: Vec<_> = vec!["cat", "dog", "eel"];
    match_suggestions(&expected, &suggestions);
}

#[rstest]
fn extern_custom_completion_long_flag_short(mut extern_completer: NuCompleter) {
    let suggestions = extern_completer.complete("spam -f ", 8);
    let expected: Vec<_> = vec!["cat", "dog", "eel"];
    match_suggestions(&expected, &suggestions);
}

#[rstest]
fn extern_custom_completion_short_flag(mut extern_completer: NuCompleter) {
    let suggestions = extern_completer.complete("spam -b ", 8);
    let expected: Vec<_> = vec!["cat", "dog", "eel"];
    match_suggestions(&expected, &suggestions);
}

/// When we're completing the flag name itself, not its value,
/// custom completions should not be used
#[rstest]
fn custom_completion_flag_name_not_value(mut extern_completer: NuCompleter) {
    let suggestions = extern_completer.complete("spam --f", 8);
    match_suggestions(&vec!["--foo"], &suggestions);
    // Also test with partial short flag
    let suggestions = extern_completer.complete("spam -f", 7);
    match_suggestions(&vec!["-f"], &suggestions);
}

#[rstest]
fn extern_complete_flags(mut extern_completer: NuCompleter) {
    let suggestions = extern_completer.complete("spam -", 6);
    let expected: Vec<_> = vec!["--foo", "-b", "-f"];
    match_suggestions(&expected, &suggestions);
}

#[rstest]
fn custom_completer_triggers_cursor_before_word(mut custom_completer: NuCompleter) {
    let suggestions = custom_completer.complete("cmd foo  bar", 8);
    let expected: Vec<_> = vec!["cmd", "foo", ""];
    match_suggestions(&expected, &suggestions);
}

#[rstest]
fn custom_completer_triggers_cursor_on_word_left_boundary(mut custom_completer: NuCompleter) {