aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_assists/src/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_assists/src/handlers')
-rw-r--r--crates/ide_assists/src/handlers/apply_demorgan.rs114
1 files changed, 66 insertions, 48 deletions
diff --git a/crates/ide_assists/src/handlers/apply_demorgan.rs b/crates/ide_assists/src/handlers/apply_demorgan.rs
index c93959e66..e2bd6e456 100644
--- a/crates/ide_assists/src/handlers/apply_demorgan.rs
+++ b/crates/ide_assists/src/handlers/apply_demorgan.rs
@@ -147,74 +147,92 @@ fn opposite_logic_op(kind: ast::BinOp) -> Option<&'static str> {
147 147
148#[cfg(test)] 148#[cfg(test)]
149mod tests { 149mod tests {
150 use ide_db::helpers::FamousDefs;
151
152 use super::*;
153
154 use crate::tests::{check_assist, check_assist_not_applicable}; 150 use crate::tests::{check_assist, check_assist_not_applicable};
155 151
156 const ORDABLE_FIXTURE: &'static str = r" 152 use super::*;
157//- /lib.rs deps:core crate:ordable
158struct NonOrderable;
159struct Orderable;
160impl core::cmp::Ord for Orderable {}
161";
162
163 fn check(ra_fixture_before: &str, ra_fixture_after: &str) {
164 let before = &format!(
165 "//- /main.rs crate:main deps:core,ordable\n{}\n{}{}",
166 ra_fixture_before,
167 FamousDefs::FIXTURE,
168 ORDABLE_FIXTURE
169 );
170 check_assist(apply_demorgan, before, &format!("{}\n", ra_fixture_after));
171 }
172 153
173 #[test] 154 #[test]
174 fn demorgan_handles_leq() { 155 fn demorgan_handles_leq() {
175 check( 156 check_assist(
176 r"use ordable::Orderable; 157 apply_demorgan,
158 r#"
159//- minicore: ord, derive
160#[derive(PartialEq, Eq, PartialOrd, Ord)]
161struct S;
162
177fn f() { 163fn f() {
178 Orderable < Orderable &&$0 Orderable <= Orderable 164 S < S &&$0 S <= S
179}", 165}
180 r"use ordable::Orderable; 166"#,
167 r#"
168#[derive(PartialEq, Eq, PartialOrd, Ord)]
169struct S;
170
181fn f() { 171fn f() {
182 !(Orderable >= Orderable || Orderable > Orderable) 172 !(S >= S || S > S)
183}", 173}
174"#,
184 ); 175 );
185 check( 176
186 r"use ordable::NonOrderable; 177 check_assist(
178 apply_demorgan,
179 r#"
180//- minicore: ord, derive
181struct S;
182
187fn f() { 183fn f() {
188 NonOrderable < NonOrderable &&$0 NonOrderable <= NonOrderable 184 S < S &&$0 S <= S
189}", 185}
190 r"use ordable::NonOrderable; 186"#,
187 r#"
188struct S;
189
191fn f() { 190fn f() {
192 !(!(NonOrderable < NonOrderable) || !(NonOrderable <= NonOrderable)) 191 !(!(S < S) || !(S <= S))
193}", 192}
193"#,
194 ); 194 );
195 } 195 }
196 196
197 #[test] 197 #[test]
198 fn demorgan_handles_geq() { 198 fn demorgan_handles_geq() {
199 check( 199 check_assist(
200 r"use ordable::Orderable; 200 apply_demorgan,
201 r#"
202//- minicore: ord, derive
203#[derive(PartialEq, Eq, PartialOrd, Ord)]
204struct S;
205
201fn f() { 206fn f() {
202 Orderable > Orderable &&$0 Orderable >= Orderable 207 S > S &&$0 S >= S
203}", 208}
204 r"use ordable::Orderable; 209"#,
210 r#"
211#[derive(PartialEq, Eq, PartialOrd, Ord)]
212struct S;
213
205fn f() { 214fn f() {
206 !(Orderable <= Orderable || Orderable < Orderable) 215 !(S <= S || S < S)
207}", 216}
217"#,
208 ); 218 );
209 check( 219 check_assist(
210 r"use ordable::NonOrderable; 220 apply_demorgan,
221 r#"
222//- minicore: ord, derive
223struct S;
224
211fn f() { 225fn f() {
212 Orderable > Orderable &&$0 Orderable >= Orderable 226 S > S &&$0 S >= S
213}", 227}
214 r"use ordable::NonOrderable; 228"#,
229 r#"
230struct S;
231
215fn f() { 232fn f() {
216 !(!(Orderable > Orderable) || !(Orderable >= Orderable)) 233 !(!(S > S) || !(S >= S))
217}", 234}
235"#,
218 ); 236 );
219 } 237 }
220 238