File tree Expand file tree Collapse file tree 1 file changed +44
-10
lines changed
crates/ide-completion/src/completions Expand file tree Collapse file tree 1 file changed +44
-10
lines changed Original file line number Diff line number Diff line change @@ -61,21 +61,55 @@ fn is_env_macro(string: &ast::String) -> bool {
6161
6262#[ cfg( test) ]
6363mod tests {
64- use expect_test:: { expect, Expect } ;
65- use crate :: tests:: { check_edit} ;
64+ use crate :: tests:: { check_edit, completion_list} ;
65+
66+ fn check ( macro_name : & str ) {
67+ check_edit ( "CARGO_BIN_NAME" , & format ! ( r#"
68+ fn main() {{
69+ let foo = {}!("CAR$0");
70+ }}
71+ "# , macro_name) , & format ! ( r#"
72+ fn main() {{
73+ let foo = {}!("CARGO_BIN_NAME");
74+ }}
75+ "# , macro_name) ) ;
76+ }
77+ #[ test]
78+ fn completes_env_variable_in_env ( ) {
79+ check ( "env" )
80+ }
6681
6782 #[ test]
68- fn completes_env_variables ( ) {
69- check_edit ( "CARGO" ,
70- r#"
83+ fn completes_env_variable_in_option_env ( ) {
84+ check ( "option_env" ) ;
85+ }
86+
87+ #[ test]
88+ fn doesnt_complete_in_random_strings ( ) {
89+ let fixture = r#"
7190 fn main() {
72- let foo = env!( "CA$0) ;
91+ let foo = "CA$0" ;
7392 }
74- "#
75- , r#"
93+ "# ;
94+
95+ let completions = completion_list ( fixture) ;
96+ assert ! ( completions. is_empty( ) , "Completions weren't empty: {}" , completions) ;
97+ }
98+
99+ #[ test]
100+ fn doesnt_complete_in_random_macro ( ) {
101+ let fixture = r#"
102+ macro_rules! bar {
103+ ($($arg:tt)*) => { 0 }
104+ }
105+
76106 fn main() {
77- let foo = env!("CARGO);
107+ let foo = bar!("CA$0");
108+
78109 }
79- "# )
110+ "# ;
111+
112+ let completions = completion_list ( fixture) ;
113+ assert ! ( completions. is_empty( ) , "Completions weren't empty: {}" , completions) ;
80114 }
81115}
You can’t perform that action at this time.
0 commit comments