tests: add test for param transformation

This commit is contained in:
winstxnhdw 2024-06-21 05:11:34 +08:00
parent 67f7eb505e
commit 21c63abec7
No known key found for this signature in database
GPG key ID: 28C6693A1379DAE9

View file

@ -517,6 +517,98 @@ mod tests {
use crate::tests::{check_assist, check_assist_not_applicable};
#[test]
fn parameter_with_first_param_usage() {
check_assist(
bool_to_enum,
r#"
fn function($0foo: bool, bar: bool) {
if foo {
println!("foo");
}
}
"#,
r#"
#[derive(PartialEq, Eq)]
enum Bool { True, False }
fn function(foo: Bool, bar: bool) {
if foo == Bool::True {
println!("foo");
}
}
"#,
)
}
#[test]
fn parameter_with_last_param_usage() {
check_assist(
bool_to_enum,
r#"
fn function(foo: bool, $0bar: bool) {
if bar {
println!("bar");
}
}
"#,
r#"
#[derive(PartialEq, Eq)]
enum Bool { True, False }
fn function(foo: bool, bar: Bool) {
if bar == Bool::True {
println!("bar");
}
}
"#,
)
}
#[test]
fn parameter_with_middle_param_usage() {
check_assist(
bool_to_enum,
r#"
fn function(foo: bool, $0bar: bool, baz: bool) {
if bar {
println!("bar");
}
}
"#,
r#"
#[derive(PartialEq, Eq)]
enum Bool { True, False }
fn function(foo: bool, bar: Bool, baz: bool) {
if bar == Bool::True {
println!("bar");
}
}
"#,
)
}
#[test]
fn parameter_with_closure_usage() {
check_assist(
bool_to_enum,
r#"
fn main() {
let foo = |$0bar: bool| bar;
}
"#,
r#"
#[derive(PartialEq, Eq)]
enum Bool { True, False }
fn main() {
let foo = |bar: Bool| bar == Bool::True;
}
"#,
)
}
#[test]
fn local_variable_with_usage() {
check_assist(
@ -784,7 +876,6 @@ fn main() {
#[test]
fn local_variable_non_ident_pat() {
cov_mark::check!(not_applicable_in_non_ident_pat);
check_assist_not_applicable(
bool_to_enum,
r#"