diff options
Diffstat (limited to 'crates/ra_hir_ty/src/tests.rs')
-rw-r--r-- | crates/ra_hir_ty/src/tests.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index c972bf845..5eaf25a77 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs | |||
@@ -10,6 +10,7 @@ mod display_source_code; | |||
10 | 10 | ||
11 | use std::sync::Arc; | 11 | use std::sync::Arc; |
12 | 12 | ||
13 | use expect::Expect; | ||
13 | use hir_def::{ | 14 | use hir_def::{ |
14 | body::{BodySourceMap, SyntheticSyntax}, | 15 | body::{BodySourceMap, SyntheticSyntax}, |
15 | child_by_source::ChildBySource, | 16 | child_by_source::ChildBySource, |
@@ -344,3 +345,29 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() { | |||
344 | assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events) | 345 | assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events) |
345 | } | 346 | } |
346 | } | 347 | } |
348 | |||
349 | // Infer with some common definitions and impls. | ||
350 | fn check_infer(ra_fixture: &str, expect: Expect) { | ||
351 | let defs = r#" | ||
352 | #[lang = "sized"] | ||
353 | pub trait Sized {} | ||
354 | #[lang = "unsize"] | ||
355 | pub trait Unsize<T: ?Sized> {} | ||
356 | #[lang = "coerce_unsized"] | ||
357 | pub trait CoerceUnsized<T> {} | ||
358 | |||
359 | impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {} | ||
360 | impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {} | ||
361 | "#; | ||
362 | |||
363 | // Append to the end to keep positions unchanged. | ||
364 | let mut actual = infer(&format!("{}{}", ra_fixture, defs)); | ||
365 | actual.push('\n'); | ||
366 | expect.assert_eq(&actual); | ||
367 | } | ||
368 | |||
369 | fn check_infer_with_mismatches(ra_fixture: &str, expect: Expect) { | ||
370 | let mut actual = infer_with_mismatches(ra_fixture, true); | ||
371 | actual.push('\n'); | ||
372 | expect.assert_eq(&actual); | ||
373 | } | ||