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

Code before:
}

#[test]
fn exact_match() {
    let (dir, _, engine, stack) = new_partial_engine();

    let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));

    let target_dir = format!("open {}", folder(dir.join("pArTiAL")));
    let suggestions = completer.complete(&target_dir, target_dir.len());

    // Since it's an exact match, only 'partial' should be suggested, not
    // 'partial-a' and stuff. Implemented in #13302
    match_suggestions(
        &vec![file(dir.join("partial").join("hello.txt")).as_str()],
        &suggestions,
    );

    let target_dir_2 = format!("open {}", file(dir.join("partial").join("hello"))); // No trailing slash
    let suggestions_2 = completer.complete(&target_dir_2, target_dir_2.len());

    // Despite no trailing slash, since it's an exact match, only 'partial/hello.txt' should be suggested, not
    // 'partial-a/hello' and stuff. Implemented in #15387
    match_suggestions(
        &vec![file(dir.join("partial").join("hello.txt")).as_str()],
        &suggestions_2,
    );
}

#[ignore = "was reverted, still needs fixing"]
#[rstest]
fn alias_offset_bug_7648() {
    let (_, _, mut engine, mut stack) = new_engine();

    // Create an alias
    let alias = r#"alias ea = ^$env.EDITOR /tmp/test.s"#;
    assert!(support::merge_input(alias.as_bytes(), &mut engine, &mut stack).is_ok());

    let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));

    // Issue #7648
    // Nushell crashes when an alias name is shorter than the alias command
    // and the alias command is a external command
    // This happens because of offset is not correct.
    // This crashes before PR #7779
    let _suggestions = completer.complete("e", 1);
}

#[ignore = "was reverted, still needs fixing"]
#[rstest]
fn alias_offset_bug_7754() {

Review comment (suggestion):
Rust lets you shadow variables, so you can call these `target_dir` and `suggestions` too.
```suggestion
    let target_dir = format!("open {}", file(dir.join("partial").join("hello"))); // No trailing slash
    let suggestions = completer.complete(&target_dir, target_dir.len());

    // Despite no trailing slash, since it's an exact match, only 'partial/hello.txt' should be suggested, not
    // 'partial-a/hello' and stuff. Implemented in #15387
    match_suggestions(
        &vec![file(dir.join("partial").join("hello.txt")).as_str()],
        &suggestions,
```
The comment also isn't really necessary, but it's fine to leave it in. In general, there's no need to mention which PR a test comes from. I think I just mentioned #13302 above because #13302 implemented the exact match behavior and then I later added a test in a different PR.

Code after:
}

#[test]
fn exact_match() {
    let (dir, _, engine, stack) = new_partial_engine();

    let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));

    let target_dir = format!("open {}", folder(dir.join("pArTiAL")));
    let suggestions = completer.complete(&target_dir, target_dir.len());

    // Since it's an exact match, only 'partial' should be suggested, not
    // 'partial-a' and stuff. Implemented in #13302
    match_suggestions(
        &vec![file(dir.join("partial").join("hello.txt")).as_str()],
        &suggestions,
    );

    let target_dir = format!("open {}", file(dir.join("partial").join("hello"))); // No trailing slash
    let suggestions = completer.complete(&target_dir, target_dir.len());

    // Despite no trailing slash, since it's an exact match, only 'partial/hello.txt' should be suggested, not
    // 'partial-a/hello' and stuff. See issue #14794 for details.
    match_suggestions(
        &vec![file(dir.join("partial").join("hello.txt")).as_str()],
        &suggestions,
    );
}

#[ignore = "was reverted, still needs fixing"]
#[rstest]
fn alias_offset_bug_7648() {
    let (_, _, mut engine, mut stack) = new_engine();

    // Create an alias
    let alias = r#"alias ea = ^$env.EDITOR /tmp/test.s"#;
    assert!(support::merge_input(alias.as_bytes(), &mut engine, &mut stack).is_ok());

    let mut completer = NuCompleter::new(Arc::new(engine), Arc::new(stack));

    // Issue #7648
    // Nushell crashes when an alias name is shorter than the alias command
    // and the alias command is a external command
    // This happens because of offset is not correct.
    // This crashes before PR #7779
    let _suggestions = completer.complete("e", 1);
}

#[ignore = "was reverted, still needs fixing"]
#[rstest]
fn alias_offset_bug_7754() {