From f9c180ffd1702dfded1e0cd6c6d3e12a40e14d0a Mon Sep 17 00:00:00 2001 From: austaras Date: Fri, 26 Aug 2022 18:12:38 +0800 Subject: [PATCH] update tests --- .../src/handlers/replace_or_with_or_else.rs | 26 ++++++++---- crates/ide-assists/src/tests/generated.rs | 40 +++++++++++++++++++ 2 files changed, 58 insertions(+), 8 deletions(-) diff --git a/crates/ide-assists/src/handlers/replace_or_with_or_else.rs b/crates/ide-assists/src/handlers/replace_or_with_or_else.rs index 96314263c973..bc1122a9d234 100644 --- a/crates/ide-assists/src/handlers/replace_or_with_or_else.rs +++ b/crates/ide-assists/src/handlers/replace_or_with_or_else.rs @@ -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()?; diff --git a/crates/ide-assists/src/tests/generated.rs b/crates/ide-assists/src/tests/generated.rs index 22319f36134f..15992722b14f 100644 --- a/crates/ide-assists/src/tests/generated.rs +++ b/crates/ide-assists/src/tests/generated.rs @@ -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(