diff options
author | Florian Diebold <[email protected]> | 2019-01-12 17:47:43 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-01-19 14:49:48 +0000 |
commit | 415cdc52108807126f0339fbf812856582f01c18 (patch) | |
tree | 2eb0dd8f216ab034c180d7c2ab3a463075ce073e /crates/ra_hir/src/ty/tests.rs | |
parent | bade91db081a3465dea3547ab8ab669f78fde9dc (diff) |
Add some tests
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index fc4054159..c590a09db 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -418,6 +418,69 @@ fn test() { | |||
418 | ); | 418 | ); |
419 | } | 419 | } |
420 | 420 | ||
421 | #[test] | ||
422 | fn infer_struct_generics() { | ||
423 | check_inference( | ||
424 | r#" | ||
425 | struct A<T> { | ||
426 | x: T, | ||
427 | } | ||
428 | |||
429 | fn test(a1: A<u32>, i: i32) { | ||
430 | a1.x; | ||
431 | let a2 = A { x: i }; | ||
432 | a2.x; | ||
433 | let a3 = A::<i128> { x: 1 }; | ||
434 | a3.x; | ||
435 | } | ||
436 | "#, | ||
437 | "struct_generics.txt", | ||
438 | ); | ||
439 | } | ||
440 | |||
441 | #[test] | ||
442 | fn infer_function_generics() { | ||
443 | check_inference( | ||
444 | r#" | ||
445 | fn id<T>(t: T) -> T { t } | ||
446 | |||
447 | fn test() { | ||
448 | id(1u32); | ||
449 | id::<i128>(1); | ||
450 | let x: u64 = id(1); | ||
451 | } | ||
452 | "#, | ||
453 | "function_generics.txt", | ||
454 | ); | ||
455 | } | ||
456 | |||
457 | #[test] | ||
458 | fn infer_generic_chain() { | ||
459 | check_inference( | ||
460 | r#" | ||
461 | struct A<T> { | ||
462 | x: T, | ||
463 | } | ||
464 | impl<T2> A<T2> { | ||
465 | fn x(self) -> T2 { | ||
466 | self.x | ||
467 | } | ||
468 | } | ||
469 | fn id<T>(t: T) -> T { t } | ||
470 | |||
471 | fn test() -> i128 { | ||
472 | let x = 1; | ||
473 | let y = id(x); | ||
474 | let a = A { x: id(y) }; | ||
475 | let z = id(a.x); | ||
476 | let b = A { x: z }; | ||
477 | b.x() | ||
478 | } | ||
479 | "#, | ||
480 | "generic_chain.txt", | ||
481 | ); | ||
482 | } | ||
483 | |||
421 | fn infer(content: &str) -> String { | 484 | fn infer(content: &str) -> String { |
422 | let (db, _, file_id) = MockDatabase::with_single_file(content); | 485 | let (db, _, file_id) = MockDatabase::with_single_file(content); |
423 | let source_file = db.source_file(file_id); | 486 | let source_file = db.source_file(file_id); |