about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbtwotwo <10519967+btwotwo@users.noreply.github.com>2022-10-06 16:27:53 +0200
committerbtwotwo <10519967+btwotwo@users.noreply.github.com>2022-10-06 16:32:20 +0200
commitbc7080884c92148fdb47701067d1f1dbdef4ed1d (patch)
treec52ab226ff13bc7264e8e3f7d89526c9077e4d63
parentddf68ea7c330ec4fef8564062af2a2e15dd5f45e (diff)
downloadrust-bc7080884c92148fdb47701067d1f1dbdef4ed1d.tar.gz
rust-bc7080884c92148fdb47701067d1f1dbdef4ed1d.zip
Add tests for env var completion
-rw-r--r--crates/ide-completion/src/completions/env_vars.rs54
1 files changed, 44 insertions, 10 deletions
diff --git a/crates/ide-completion/src/completions/env_vars.rs b/crates/ide-completion/src/completions/env_vars.rs
index eba39bba3d5..43d67f093e9 100644
--- a/crates/ide-completion/src/completions/env_vars.rs
+++ b/crates/ide-completion/src/completions/env_vars.rs
@@ -61,21 +61,55 @@ fn is_env_macro(string: &ast::String) -> bool {
 
 #[cfg(test)]
 mod tests {
-    use expect_test::{expect, Expect};
-    use crate::tests::{check_edit};
+    use crate::tests::{check_edit, completion_list};
+
+    fn check(macro_name: &str) {
+        check_edit("CARGO_BIN_NAME",&format!(r#"
+            fn main() {{
+                let foo = {}!("CAR$0");
+            }}
+        "#, macro_name), &format!(r#"
+            fn main() {{
+                let foo = {}!("CARGO_BIN_NAME");
+            }}
+        "#, macro_name));
+    }
+    #[test]
+    fn completes_env_variable_in_env() {
+        check("env")
+    }
 
     #[test]
-    fn completes_env_variables() {
-        check_edit("CARGO", 
-        r#"
+    fn completes_env_variable_in_option_env() {
+        check("option_env");
+    }
+
+    #[test]
+    fn doesnt_complete_in_random_strings() {
+        let fixture = r#"
             fn main() {
-                let foo = env!("CA$0);
+                let foo = "CA$0";
             }
-        "#
-        ,r#"
+        "#;
+
+        let completions = completion_list(fixture);
+        assert!(completions.is_empty(), "Completions weren't empty: {}", completions);
+    }
+
+    #[test]
+    fn doesnt_complete_in_random_macro() {
+        let fixture = r#"
+            macro_rules! bar {
+                ($($arg:tt)*) => { 0 }
+            }
+
             fn main() {
-                let foo = env!("CARGO);
+                let foo = bar!("CA$0");
+
             }
-        "#)
+        "#;
+
+        let completions = completion_list(fixture);
+        assert!(completions.is_empty(), "Completions weren't empty: {}", completions);
     }
 }
\ No newline at end of file