diff options
Diffstat (limited to 'crates/hir_expand/src/builtin_derive.rs')
-rw-r--r-- | crates/hir_expand/src/builtin_derive.rs | 66 |
1 files changed, 29 insertions, 37 deletions
diff --git a/crates/hir_expand/src/builtin_derive.rs b/crates/hir_expand/src/builtin_derive.rs index b7f1aae8f..dfdb9cf59 100644 --- a/crates/hir_expand/src/builtin_derive.rs +++ b/crates/hir_expand/src/builtin_derive.rs | |||
@@ -267,13 +267,14 @@ fn partial_ord_expand( | |||
267 | #[cfg(test)] | 267 | #[cfg(test)] |
268 | mod tests { | 268 | mod tests { |
269 | use base_db::{fixture::WithFixture, CrateId, SourceDatabase}; | 269 | use base_db::{fixture::WithFixture, CrateId, SourceDatabase}; |
270 | use expect_test::{expect, Expect}; | ||
270 | use name::{known, Name}; | 271 | use name::{known, Name}; |
271 | 272 | ||
272 | use crate::{test_db::TestDB, AstId, MacroCallId, MacroCallKind, MacroCallLoc}; | 273 | use crate::{test_db::TestDB, AstId, MacroCallId, MacroCallKind, MacroCallLoc}; |
273 | 274 | ||
274 | use super::*; | 275 | use super::*; |
275 | 276 | ||
276 | fn expand_builtin_derive(s: &str, name: Name) -> String { | 277 | fn expand_builtin_derive(ra_fixture: &str, name: Name) -> String { |
277 | let expander = BuiltinDeriveExpander::find_by_name(&name).unwrap(); | 278 | let expander = BuiltinDeriveExpander::find_by_name(&name).unwrap(); |
278 | let fixture = format!( | 279 | let fixture = format!( |
279 | r#"//- /main.rs crate:main deps:core | 280 | r#"//- /main.rs crate:main deps:core |
@@ -282,7 +283,7 @@ $0 | |||
282 | //- /lib.rs crate:core | 283 | //- /lib.rs crate:core |
283 | // empty | 284 | // empty |
284 | "#, | 285 | "#, |
285 | s | 286 | ra_fixture |
286 | ); | 287 | ); |
287 | 288 | ||
288 | let (db, file_pos) = TestDB::with_position(&fixture); | 289 | let (db, file_pos) = TestDB::with_position(&fixture); |
@@ -314,66 +315,57 @@ $0 | |||
314 | parsed.text().to_string() | 315 | parsed.text().to_string() |
315 | } | 316 | } |
316 | 317 | ||
318 | fn check_derive(ra_fixture: &str, name: Name, expected: Expect) { | ||
319 | let expanded = expand_builtin_derive(ra_fixture, name); | ||
320 | expected.assert_eq(&expanded); | ||
321 | } | ||
322 | |||
317 | #[test] | 323 | #[test] |
318 | fn test_copy_expand_simple() { | 324 | fn test_copy_expand_simple() { |
319 | let expanded = expand_builtin_derive( | 325 | check_derive( |
320 | r#" | 326 | r#" |
321 | #[derive(Copy)] | 327 | #[derive(Copy)] |
322 | struct Foo; | 328 | struct Foo; |
323 | "#, | 329 | "#, |
324 | known::Copy, | 330 | known::Copy, |
331 | expect![["impl< >core::marker::CopyforFoo< >{}"]], | ||
325 | ); | 332 | ); |
326 | |||
327 | assert_eq!(expanded, "impl< >core::marker::CopyforFoo< >{}"); | ||
328 | } | 333 | } |
329 | 334 | ||
330 | #[test] | 335 | #[test] |
331 | fn test_copy_expand_with_type_params() { | 336 | fn test_copy_expand_with_type_params() { |
332 | let expanded = expand_builtin_derive( | 337 | check_derive( |
333 | r#" | 338 | r#" |
334 | #[derive(Copy)] | 339 | #[derive(Copy)] |
335 | struct Foo<A, B>; | 340 | struct Foo<A, B>; |
336 | "#, | 341 | "#, |
337 | known::Copy, | 342 | known::Copy, |
338 | ); | 343 | expect![["impl<T0:core::marker::Copy,T1:core::marker::Copy>core::marker::CopyforFoo<T0,T1>{}"]], |
339 | |||
340 | assert_eq!( | ||
341 | expanded, | ||
342 | "impl<T0:core::marker::Copy,T1:core::marker::Copy>core::marker::CopyforFoo<T0,T1>{}" | ||
343 | ); | 344 | ); |
344 | } | 345 | } |
345 | 346 | ||
346 | #[test] | 347 | #[test] |
347 | fn test_copy_expand_with_lifetimes() { | 348 | fn test_copy_expand_with_lifetimes() { |
348 | let expanded = expand_builtin_derive( | 349 | check_derive( |
349 | r#" | 350 | r#" |
350 | #[derive(Copy)] | 351 | #[derive(Copy)] |
351 | struct Foo<A, B, 'a, 'b>; | 352 | struct Foo<A, B, 'a, 'b>; |
352 | "#, | 353 | "#, |
353 | known::Copy, | 354 | known::Copy, |
354 | ); | 355 | // We currently just ignore lifetimes |
355 | 356 | expect![["impl<T0:core::marker::Copy,T1:core::marker::Copy>core::marker::CopyforFoo<T0,T1>{}"]], | |
356 | // We currently just ignore lifetimes | ||
357 | |||
358 | assert_eq!( | ||
359 | expanded, | ||
360 | "impl<T0:core::marker::Copy,T1:core::marker::Copy>core::marker::CopyforFoo<T0,T1>{}" | ||
361 | ); | 357 | ); |
362 | } | 358 | } |
363 | 359 | ||
364 | #[test] | 360 | #[test] |
365 | fn test_clone_expand() { | 361 | fn test_clone_expand() { |
366 | let expanded = expand_builtin_derive( | 362 | check_derive( |
367 | r#" | 363 | r#" |
368 | #[derive(Clone)] | 364 | #[derive(Clone)] |
369 | struct Foo<A, B>; | 365 | struct Foo<A, B>; |
370 | "#, | 366 | "#, |
371 | known::Clone, | 367 | known::Clone, |
372 | ); | 368 | expect![["impl<T0:core::clone::Clone,T1:core::clone::Clone>core::clone::CloneforFoo<T0,T1>{}"]], |
373 | |||
374 | assert_eq!( | ||
375 | expanded, | ||
376 | "impl<T0:core::clone::Clone,T1:core::clone::Clone>core::clone::CloneforFoo<T0,T1>{}" | ||
377 | ); | 369 | ); |
378 | } | 370 | } |
379 | } | 371 | } |