Skip to content

Commit 3b6979b

Browse files
committed
Use expect in never_type tests
1 parent b82899a commit 3b6979b

File tree

3 files changed

+185
-186
lines changed

3 files changed

+185
-186
lines changed

crates/ra_hir_ty/src/tests.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mod display_source_code;
1010

1111
use std::sync::Arc;
1212

13+
use expect::Expect;
1314
use hir_def::{
1415
body::{BodySourceMap, SyntheticSyntax},
1516
child_by_source::ChildBySource,
@@ -344,3 +345,29 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
344345
assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events)
345346
}
346347
}
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+
}

crates/ra_hir_ty/src/tests/coercion.rs

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,7 @@
1+
use expect::expect;
12
use test_utils::mark;
23

3-
use expect::{expect, Expect};
4-
5-
// Infer with some common definitions and impls.
6-
fn check_infer(ra_fixture: &str, expect: Expect) {
7-
let defs = r#"
8-
#[lang = "sized"]
9-
pub trait Sized {}
10-
#[lang = "unsize"]
11-
pub trait Unsize<T: ?Sized> {}
12-
#[lang = "coerce_unsized"]
13-
pub trait CoerceUnsized<T> {}
14-
15-
impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
16-
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
17-
"#;
18-
19-
// Append to the end to keep positions unchanged.
20-
let mut actual = super::infer(&format!("{}{}", ra_fixture, defs));
21-
actual.push('\n');
22-
expect.assert_eq(&actual);
23-
}
24-
25-
fn check_infer_with_mismatches(ra_fixture: &str, expect: Expect) {
26-
let mut actual = super::infer_with_mismatches(ra_fixture, true);
27-
actual.push('\n');
28-
expect.assert_eq(&actual);
29-
}
4+
use super::{check_infer, check_infer_with_mismatches};
305

316
#[test]
327
fn infer_block_expr_type_mismatch() {

0 commit comments

Comments
 (0)