aboutsummaryrefslogtreecommitdiff
path: root/crates/libeditor/src/code_actions.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libeditor/src/code_actions.rs')
-rw-r--r--crates/libeditor/src/code_actions.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/crates/libeditor/src/code_actions.rs b/crates/libeditor/src/code_actions.rs
index cd5146d87..ca159c658 100644
--- a/crates/libeditor/src/code_actions.rs
+++ b/crates/libeditor/src/code_actions.rs
@@ -128,3 +128,52 @@ impl PushDisplay for String {
128 write!(self, "{}", item).unwrap() 128 write!(self, "{}", item).unwrap()
129 } 129 }
130} 130}
131
132#[cfg(test)]
133mod tests {
134 use super::*;
135 use test_utils::check_action;
136
137 #[test]
138 fn test_swap_comma() {
139 check_action(
140 "fn foo(x: i32,<|> y: Result<(), ()>) {}",
141 "fn foo(y: Result<(), ()>,<|> x: i32) {}",
142 |file, off| flip_comma(file, off).map(|f| f()),
143 )
144 }
145
146 #[test]
147 fn test_add_derive() {
148 check_action(
149 "struct Foo { a: i32, <|>}",
150 "#[derive(<|>)]\nstruct Foo { a: i32, }",
151 |file, off| add_derive(file, off).map(|f| f()),
152 );
153 check_action(
154 "struct Foo { <|> a: i32, }",
155 "#[derive(<|>)]\nstruct Foo { a: i32, }",
156 |file, off| add_derive(file, off).map(|f| f()),
157 );
158 check_action(
159 "#[derive(Clone)]\nstruct Foo { a: i32<|>, }",
160 "#[derive(Clone<|>)]\nstruct Foo { a: i32, }",
161 |file, off| add_derive(file, off).map(|f| f()),
162 );
163 }
164
165 #[test]
166 fn test_add_impl() {
167 check_action(
168 "struct Foo {<|>}\n",
169 "struct Foo {}\n\nimpl Foo {\n<|>\n}\n",
170 |file, off| add_impl(file, off).map(|f| f()),
171 );
172 check_action(
173 "struct Foo<T: Clone> {<|>}",
174 "struct Foo<T: Clone> {}\n\nimpl<T: Clone> Foo<T> {\n<|>\n}",
175 |file, off| add_impl(file, off).map(|f| f()),
176 );
177 }
178
179}