aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ide_assists/src/handlers/replace_string_with_char.rs38
1 files changed, 37 insertions, 1 deletions
diff --git a/crates/ide_assists/src/handlers/replace_string_with_char.rs b/crates/ide_assists/src/handlers/replace_string_with_char.rs
index 317318c24..303c0dcbe 100644
--- a/crates/ide_assists/src/handlers/replace_string_with_char.rs
+++ b/crates/ide_assists/src/handlers/replace_string_with_char.rs
@@ -31,7 +31,9 @@ pub(crate) fn replace_string_with_char(acc: &mut Assists, ctx: &AssistContext) -
31 "Replace string with char", 31 "Replace string with char",
32 target, 32 target,
33 |edit| { 33 |edit| {
34 edit.replace(token.syntax().text_range(), format!("'{}'", value)); 34 let token_text = token.syntax().text();
35 let inner_text = &token_text[1..token_text.len() - 1];
36 edit.replace(token.syntax().text_range(), format!("'{}'", inner_text));
35 }, 37 },
36 ) 38 )
37} 39}
@@ -134,4 +136,38 @@ mod tests {
134 "##, 136 "##,
135 ) 137 )
136 } 138 }
139
140 #[test]
141 fn replace_string_with_char_newline() {
142 check_assist(
143 replace_string_with_char,
144 r#"
145 fn f() {
146 find($0"\n");
147 }
148 "#,
149 r##"
150 fn f() {
151 find('\n');
152 }
153 "##,
154 )
155 }
156
157 #[test]
158 fn replace_string_with_char_unicode_escape() {
159 check_assist(
160 replace_string_with_char,
161 r#"
162 fn f() {
163 find($0"\u{7FFF}");
164 }
165 "#,
166 r##"
167 fn f() {
168 find('\u{7FFF}');
169 }
170 "##,
171 )
172 }
137} 173}