diff options
| author | austaras <austaras@outlook.com> | 2022-08-26 18:12:38 +0800 |
|---|---|---|
| committer | austaras <austaras@outlook.com> | 2022-08-29 00:24:56 +0800 |
| commit | f9c180ffd1702dfded1e0cd6c6d3e12a40e14d0a (patch) | |
| tree | 341e1a2ad51dc468af3a9dd60ae057edb23a1e51 | |
| parent | 0dd9eef1b9bce0b5b6260c620f5e37f50b618ae5 (diff) | |
| download | rust-f9c180ffd1702dfded1e0cd6c6d3e12a40e14d0a.tar.gz rust-f9c180ffd1702dfded1e0cd6c6d3e12a40e14d0a.zip | |
update tests
| -rw-r--r-- | crates/ide-assists/src/handlers/replace_or_with_or_else.rs | 26 | ||||
| -rw-r--r-- | 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 96314263c97..bc1122a9d23 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 22319f36134..15992722b14 100644 --- a/crates/ide-assists/src/tests/generated.rs +++ b/crates/ide-assists/src/tests/generated.rs @@ -2010,6 +2010,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( "replace_qualified_name_with_use", |
