aboutsummaryrefslogtreecommitdiff
path: root/crates/libeditor/src/completion.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libeditor/src/completion.rs')
-rw-r--r--crates/libeditor/src/completion.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/crates/libeditor/src/completion.rs b/crates/libeditor/src/completion.rs
index cea2d14d1..c6ce62661 100644
--- a/crates/libeditor/src/completion.rs
+++ b/crates/libeditor/src/completion.rs
@@ -37,3 +37,55 @@ fn complete(name_ref: ast::NameRef, scopes: &FnScopes) -> Vec<CompletionItem> {
37 }) 37 })
38 .collect() 38 .collect()
39} 39}
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44 use test_utils::{assert_eq_dbg, extract_offset};
45
46 fn do_check(code: &str, expected_completions: &str) {
47 let (off, code) = extract_offset(&code);
48 let file = File::parse(&code);
49 let completions = scope_completion(&file, off).unwrap();
50 assert_eq_dbg(expected_completions, &completions);
51 }
52
53 #[test]
54 fn test_completion_let_scope() {
55 do_check(r"
56 fn quux(x: i32) {
57 let y = 92;
58 1 + <|>;
59 let z = ();
60 }
61 ", r#"[CompletionItem { name: "y" },
62 CompletionItem { name: "x" }]"#);
63 }
64
65 #[test]
66 fn test_completion_if_let_scope() {
67 do_check(r"
68 fn quux() {
69 if let Some(x) = foo() {
70 let y = 92;
71 };
72 if let Some(a) = bar() {
73 let b = 62;
74 1 + <|>
75 }
76 }
77 ", r#"[CompletionItem { name: "b" },
78 CompletionItem { name: "a" }]"#);
79 }
80
81 #[test]
82 fn test_completion_for_scope() {
83 do_check(r"
84 fn quux() {
85 for x in &[1, 2, 3] {
86 <|>
87 }
88 }
89 ", r#"[CompletionItem { name: "x" }]"#);
90 }
91}