mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Add tests for env var completion
This commit is contained in:
parent
ddf68ea7c3
commit
bc7080884c
@ -61,21 +61,55 @@ fn is_env_macro(string: &ast::String) -> bool {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use expect_test::{expect, Expect};
|
use crate::tests::{check_edit, completion_list};
|
||||||
use crate::tests::{check_edit};
|
|
||||||
|
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]
|
#[test]
|
||||||
fn completes_env_variables() {
|
fn completes_env_variable_in_option_env() {
|
||||||
check_edit("CARGO",
|
check("option_env");
|
||||||
r#"
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn doesnt_complete_in_random_strings() {
|
||||||
|
let fixture = r#"
|
||||||
fn main() {
|
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() {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user