Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit f9c180f

Browse files
committed
update tests
1 parent 0dd9eef commit f9c180f

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

crates/ide-assists/src/handlers/replace_or_with_or_else.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@ use crate::{AssistContext, Assists};
1414
// Replace `unwrap_or` with `unwrap_or_else` and `ok_or` with `ok_or_else`.
1515
//
1616
// ```
17-
// let a = Some(1);
18-
// a.unwra$0p_or(2);
17+
// # //- minicore:option
18+
// fn foo() {
19+
// let a = Some(1);
20+
// a.unwra$0p_or(2);
21+
// }
1922
// ```
2023
// ->
2124
// ```
22-
// let a = Some(1);
23-
// a.unwrap_or_else(|| 2);
25+
// fn foo() {
26+
// let a = Some(1);
27+
// a.unwrap_or_else(|| 2);
28+
// }
2429
// ```
2530
pub(crate) fn replace_or_with_or_else(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
2631
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<'_>
7176
// Replace `unwrap_or_else` with `unwrap_or` and `ok_or_else` with `ok_or`.
7277
//
7378
// ```
74-
// let a = Some(1);
75-
// a.unwra$0p_or_else(|| 2);
79+
// # //- minicore:option
80+
// fn foo() {
81+
// let a = Some(1);
82+
// a.unwra$0p_or_else(|| 2);
83+
// }
7684
// ```
7785
// ->
7886
// ```
79-
// let a = Some(1);
80-
// a.unwrap_or(2);
87+
// fn foo() {
88+
// let a = Some(1);
89+
// a.unwrap_or(2);
90+
// }
8191
// ```
8292
pub(crate) fn replace_or_else_with_or(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
8393
let call: ast::MethodCallExpr = ctx.find_node_at_offset()?;

crates/ide-assists/src/tests/generated.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,6 +2009,46 @@ fn handle(action: Action) {
20092009
)
20102010
}
20112011

2012+
#[test]
2013+
fn doctest_replace_or_else_with_or() {
2014+
check_doc_test(
2015+
"replace_or_else_with_or",
2016+
r#####"
2017+
//- minicore:option
2018+
fn foo() {
2019+
let a = Some(1);
2020+
a.unwra$0p_or_else(|| 2);
2021+
}
2022+
"#####,
2023+
r#####"
2024+
fn foo() {
2025+
let a = Some(1);
2026+
a.unwrap_or(2);
2027+
}
2028+
"#####,
2029+
)
2030+
}
2031+
2032+
#[test]
2033+
fn doctest_replace_or_with_or_else() {
2034+
check_doc_test(
2035+
"replace_or_with_or_else",
2036+
r#####"
2037+
//- minicore:option
2038+
fn foo() {
2039+
let a = Some(1);
2040+
a.unwra$0p_or(2);
2041+
}
2042+
"#####,
2043+
r#####"
2044+
fn foo() {
2045+
let a = Some(1);
2046+
a.unwrap_or_else(|| 2);
2047+
}
2048+
"#####,
2049+
)
2050+
}
2051+
20122052
#[test]
20132053
fn doctest_replace_qualified_name_with_use() {
20142054
check_doc_test(

0 commit comments

Comments
 (0)