diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-06-17 22:31:05 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-06-17 22:31:05 +0100 |
commit | 916384a1ea50323e8d44d8024ede1d39244fbb7c (patch) | |
tree | 76a5268851cf7b79447d5de79514c0d0b579e823 /crates/ide_assists/src/handlers/apply_demorgan.rs | |
parent | 9b013ffcae672595aeb1aee9de907e05fb7ca065 (diff) | |
parent | ebb591a5704f767d783d57af7022272f665318ac (diff) |
Merge #9319
9319: internal: add derive and ord support to minicore r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ide_assists/src/handlers/apply_demorgan.rs')
-rw-r--r-- | crates/ide_assists/src/handlers/apply_demorgan.rs | 114 |
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)] |
149 | mod tests { | 149 | mod 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 | ||
158 | struct NonOrderable; | ||
159 | struct Orderable; | ||
160 | impl 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)] | ||
161 | struct S; | ||
162 | |||
177 | fn f() { | 163 | fn 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)] | ||
169 | struct S; | ||
170 | |||
181 | fn f() { | 171 | fn 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 | ||
181 | struct S; | ||
182 | |||
187 | fn f() { | 183 | fn f() { |
188 | NonOrderable < NonOrderable &&$0 NonOrderable <= NonOrderable | 184 | S < S &&$0 S <= S |
189 | }", | 185 | } |
190 | r"use ordable::NonOrderable; | 186 | "#, |
187 | r#" | ||
188 | struct S; | ||
189 | |||
191 | fn f() { | 190 | fn 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)] | ||
204 | struct S; | ||
205 | |||
201 | fn f() { | 206 | fn 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)] | ||
212 | struct S; | ||
213 | |||
205 | fn f() { | 214 | fn 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 | ||
223 | struct S; | ||
224 | |||
211 | fn f() { | 225 | fn f() { |
212 | Orderable > Orderable &&$0 Orderable >= Orderable | 226 | S > S &&$0 S >= S |
213 | }", | 227 | } |
214 | r"use ordable::NonOrderable; | 228 | "#, |
229 | r#" | ||
230 | struct S; | ||
231 | |||
215 | fn f() { | 232 | fn f() { |
216 | !(!(Orderable > Orderable) || !(Orderable >= Orderable)) | 233 | !(!(S > S) || !(S >= S)) |
217 | }", | 234 | } |
235 | "#, | ||
218 | ); | 236 | ); |
219 | } | 237 | } |
220 | 238 | ||