2382 lines · 73.7 KB · Rust
RawDownload
use crate::{    code_context_menus::{CompletionsMenu, SortableMatch},    editor_settings::SnippetSortOrder,};use fuzzy::StringMatch;use gpui::TestAppContext; #[gpui::test]fn test_sort_matches_local_variable_over_global_variable(_cx: &mut TestAppContext) {    // Case 1: "foo"    let query: Option<&str> = Some("foo");    let mut matches: Vec<SortableMatch<'_>> = vec![        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.2727272727272727,                positions: vec![],                string: "foo_bar_baz".to_string(),            },            is_snippet: false,            sort_text: Some("7fffffff"),            sort_kind: 2,            sort_label: "foo_bar_baz",        },        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.2727272727272727,                positions: vec![],                string: "foo_bar_qux".to_string(),            },            is_snippet: false,            sort_text: Some("7ffffffe"),            sort_kind: 1,            sort_label: "foo_bar_qux",        },        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.22499999999999998,                positions: vec![],                string: "floorf64".to_string(),            },            is_snippet: false,            sort_text: Some("80000000"),            sort_kind: 2,            sort_label: "floorf64",        },        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.22499999999999998,                positions: vec![],                string: "floorf32".to_string(),            },            is_snippet: false,            sort_text: Some("80000000"),            sort_kind: 2,            sort_label: "floorf32",        },        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.22499999999999998,                positions: vec![],                string: "floorf16".to_string(),            },            is_snippet: false,            sort_text: Some("80000000"),            sort_kind: 2,            sort_label: "floorf16",        },        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.2,                positions: vec![],                string: "floorf128".to_string(),            },            is_snippet: false,            sort_text: Some("80000000"),            sort_kind: 2,            sort_label: "floorf128",        },    ];    CompletionsMenu::sort_matches(&mut matches, query, SnippetSortOrder::default());    assert_eq!(        matches[0].string_match.string.as_str(),        "foo_bar_qux",        "Match order not expected"    );    assert_eq!(        matches[1].string_match.string.as_str(),        "foo_bar_baz",        "Match order not expected"    );    assert_eq!(        matches[2].string_match.string.as_str(),        "floorf16",        "Match order not expected"    );    assert_eq!(        matches[3].string_match.string.as_str(),        "floorf32",        "Match order not expected"    );     // Case 2: "foobar"    let query: Option<&str> = Some("foobar");    let mut matches: Vec<SortableMatch<'_>> = vec![        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.4363636363636364,                positions: vec![],                string: "foo_bar_baz".to_string(),            },            is_snippet: false,            sort_text: Some("7fffffff"),            sort_kind: 2,            sort_label: "foo_bar_baz",        },        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.4363636363636364,                positions: vec![],                string: "foo_bar_qux".to_string(),            },            is_snippet: false,            sort_text: Some("7ffffffe"),            sort_kind: 1,            sort_label: "foo_bar_qux",        },    ];    CompletionsMenu::sort_matches(&mut matches, query, SnippetSortOrder::default());    assert_eq!(        matches[0].string_match.string.as_str(),        "foo_bar_qux",        "Match order not expected"    );    assert_eq!(        matches[1].string_match.string.as_str(),        "foo_bar_baz",        "Match order not expected"    );} #[gpui::test]fn test_sort_matches_local_variable_over_global_enum(_cx: &mut TestAppContext) {    // Case 1: "ele"    let query: Option<&str> = Some("ele");    let mut matches: Vec<SortableMatch<'_>> = vec![        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.2727272727272727,                positions: vec![],                string: "ElementType".to_string(),            },            is_snippet: false,            sort_text: Some("7fffffff"),            sort_kind: 2,            sort_label: "ElementType",        },        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.25,                positions: vec![],                string: "element_type".to_string(),            },            is_snippet: false,            sort_text: Some("7ffffffe"),            sort_kind: 1,            sort_label: "element_type",        },        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.16363636363636364,                positions: vec![],                string: "simd_select".to_string(),            },            is_snippet: false,            sort_text: Some("80000000"),            sort_kind: 2,            sort_label: "simd_select",        },        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.16,                positions: vec![],                string: "while let".to_string(),            },            is_snippet: false,            sort_text: Some("7fffffff"),            sort_kind: 0,            sort_label: "while let",        },    ];    CompletionsMenu::sort_matches(&mut matches, query, SnippetSortOrder::default());    assert_eq!(        matches[0].string_match.string.as_str(),        "element_type",        "Match order not expected"    );    assert_eq!(        matches[1].string_match.string.as_str(),        "ElementType",        "Match order not expected"    );     // Case 2: "eleme"    let query: Option<&str> = Some("eleme");    let mut matches: Vec<SortableMatch<'_>> = vec![        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.4545454545454546,                positions: vec![],                string: "ElementType".to_string(),            },            is_snippet: false,            sort_text: Some("7fffffff"),            sort_kind: 2,            sort_label: "ElementType",        },        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.41666666666666663,                positions: vec![],                string: "element_type".to_string(),            },            is_snippet: false,            sort_text: Some("7ffffffe"),            sort_kind: 1,            sort_label: "element_type",        },        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.04714285714285713,                positions: vec![],                string: "REPLACEMENT_CHARACTER".to_string(),            },            is_snippet: false,            sort_text: Some("80000000"),            sort_kind: 2,            sort_label: "REPLACEMENT_CHARACTER",        },    ];    CompletionsMenu::sort_matches(&mut matches, query, SnippetSortOrder::default());    assert_eq!(        matches[0].string_match.string.as_str(),        "element_type",        "Match order not expected"    );    assert_eq!(        matches[1].string_match.string.as_str(),        "ElementType",        "Match order not expected"    );     // Case 3: "Elem"    let query: Option<&str> = Some("Elem");    let mut matches: Vec<SortableMatch<'_>> = vec![        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.36363636363636365,                positions: vec![],                string: "ElementType".to_string(),            },            is_snippet: false,            sort_text: Some("7fffffff"),            sort_kind: 2,            sort_label: "ElementType",        },        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.0003333333333333333,                positions: vec![],                string: "element_type".to_string(),            },            is_snippet: false,            sort_text: Some("7ffffffe"),            sort_kind: 1,            sort_label: "element_type",        },    ];    CompletionsMenu::sort_matches(&mut matches, query, SnippetSortOrder::default());    assert_eq!(        matches[0].string_match.string.as_str(),        "ElementType",        "Match order not expected"    );    assert_eq!(        matches[1].string_match.string.as_str(),        "element_type",        "Match order not expected"    );} #[gpui::test]fn test_sort_matches_for_unreachable(_cx: &mut TestAppContext) {    // Case 1: "unre"    let query: Option<&str> = Some("unre");    let mut matches: Vec<SortableMatch<'_>> = vec![        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.36363636363636365,                positions: vec![],                string: "unreachable".to_string(),            },            is_snippet: false,            sort_text: Some("80000000"),            sort_kind: 2,            sort_label: "unreachable",        },        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.26666666666666666,                positions: vec![],                string: "unreachable!(…)".to_string(),            },            is_snippet: true,            sort_text: Some("7fffffff"),            sort_kind: 2,            sort_label: "unreachable!(…)",        },        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.24615384615384617,                positions: vec![],                string: "unchecked_rem".to_string(),            },            is_snippet: false,            sort_text: Some("80000000"),            sort_kind: 2,            sort_label: "unchecked_rem",        },        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.19047619047619047,                positions: vec![],                string: "unreachable_unchecked".to_string(),            },            is_snippet: false,            sort_text: Some("80000000"),            sort_kind: 2,            sort_label: "unreachable_unchecked",        },    ];    CompletionsMenu::sort_matches(&mut matches, query, SnippetSortOrder::default());    assert_eq!(        matches[0].string_match.string.as_str(),        "unreachable!(…)",        "Match order not expected"    );     // Case 2: "unrea"    let query: Option<&str> = Some("unrea");    let mut matches: Vec<SortableMatch<'_>> = vec![        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.4545454545454546,                positions: vec![],                string: "unreachable".to_string(),            },            is_snippet: true,            sort_text: Some("80000000"),            sort_kind: 3,            sort_label: "unreachable",        },        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.3333333333333333,                positions: vec![],                string: "unreachable!(…)".to_string(),            },            is_snippet: true,            sort_text: Some("7fffffff"),            sort_kind: 3,            sort_label: "unreachable!(…)",        },        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.23809523809523808,                positions: vec![],                string: "unreachable_unchecked".to_string(),            },            is_snippet: true,            sort_text: Some("80000000"),            sort_kind: 3,            sort_label: "unreachable_unchecked",        },    ];    CompletionsMenu::sort_matches(&mut matches, query, SnippetSortOrder::default());    assert_eq!(        matches[0].string_match.string.as_str(),        "unreachable!(…)",        "Match order not expected"    );     // Case 3: "unreach"    let query: Option<&str> = Some("unreach");    let mut matches: Vec<SortableMatch<'_>> = vec![        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.6363636363636364,                positions: vec![],                string: "unreachable".to_string(),            },            is_snippet: false,            sort_text: Some("80000000"),            sort_kind: 2,            sort_label: "unreachable",        },        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.4666666666666667,                positions: vec![],                string: "unreachable!(…)".to_string(),            },            is_snippet: true,            sort_text: Some("7fffffff"),            sort_kind: 2,            sort_label: "unreachable!(…)",        },        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.3333333333333333,                positions: vec![],                string: "unreachable_unchecked".to_string(),            },            is_snippet: false,            sort_text: Some("80000000"),            sort_kind: 2,            sort_label: "unreachable_unchecked",        },    ];    CompletionsMenu::sort_matches(&mut matches, query, SnippetSortOrder::default());    assert_eq!(        matches[0].string_match.string.as_str(),        "unreachable!(…)",        "Match order not expected"    );     // Case 4: "unreachabl"    let query: Option<&str> = Some("unreachable");    let mut matches: Vec<SortableMatch<'_>> = vec![        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.9090909090909092,                positions: vec![],                string: "unreachable".to_string(),            },            is_snippet: false,            sort_text: Some("80000000"),            sort_kind: 3,            sort_label: "unreachable",        },        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.6666666666666666,                positions: vec![],                string: "unreachable!(…)".to_string(),            },            is_snippet: false,            sort_text: Some("7fffffff"),            sort_kind: 3,            sort_label: "unreachable!(…)",        },        SortableMatch {            string_match: StringMatch {                candidate_id: 0,                score: 0.47619047619047616,                positions: vec![],                string: "unreachable_unchecked".to_string(),            },            is_snippet: false,            sort_text: Some("80000000"),            sort_kind: 3,            sort_label: "unreachable_unchecked",

Lines 1–500 of 2382.