update tests

This commit is contained in:
austaras 2022-08-26 18:12:38 +08:00
parent 0dd9eef1b9
commit f9c180ffd1
2 changed files with 58 additions and 8 deletions

View File

@ -14,13 +14,18 @@ use crate::{AssistContext, Assists};
// Replace `unwrap_or` with `unwrap_or_else` and `ok_or` with `ok_or_else`.
//
// ```
// let a = Some(1);
// a.unwra$0p_or(2);
// # //- minicore:option
// fn foo() {
// let a = Some(1);
// a.unwra$0p_or(2);
// }
// ```
// ->
// ```
// let a = Some(1);
// a.unwrap_or_else(|| 2);
// fn foo() {
// let a = Some(1);
// a.unwrap_or_else(|| 2);
// }
// ```
pub(crate) fn replace_or_with_or_else(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let call: ast::MethodCallExpr = ctx.find_node_at_offset()?;
@ -71,13 +76,18 @@ pub(crate) fn replace_or_with_or_else(acc: &mut Assists, ctx: &AssistContext<'_>
// Replace `unwrap_or_else` with `unwrap_or` and `ok_or_else` with `ok_or`.
//
// ```
// let a = Some(1);
// a.unwra$0p_or_else(|| 2);
// # //- minicore:option
// fn foo() {
// let a = Some(1);
// a.unwra$0p_or_else(|| 2);
// }
// ```
// ->
// ```
// let a = Some(1);
// a.unwrap_or(2);
// fn foo() {
// let a = Some(1);
// a.unwrap_or(2);
// }
// ```
pub(crate) fn replace_or_else_with_or(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
let call: ast::MethodCallExpr = ctx.find_node_at_offset()?;

View File

@ -2009,6 +2009,46 @@ fn handle(action: Action) {
)
}
#[test]
fn doctest_replace_or_else_with_or() {
check_doc_test(
"replace_or_else_with_or",
r#####"
//- minicore:option
fn foo() {
let a = Some(1);
a.unwra$0p_or_else(|| 2);
}
"#####,
r#####"
fn foo() {
let a = Some(1);
a.unwrap_or(2);
}
"#####,
)
}
#[test]
fn doctest_replace_or_with_or_else() {
check_doc_test(
"replace_or_with_or_else",
r#####"
//- minicore:option
fn foo() {
let a = Some(1);
a.unwra$0p_or(2);
}
"#####,
r#####"
fn foo() {
let a = Some(1);
a.unwrap_or_else(|| 2);
}
"#####,
)
}
#[test]
fn doctest_replace_qualified_name_with_use() {
check_doc_test(