mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
Use expect in never_type tests
This commit is contained in:
parent
b82899ad76
commit
3b6979be77
3 changed files with 185 additions and 186 deletions
|
@ -10,6 +10,7 @@ mod display_source_code;
|
|||
|
||||
use std::sync::Arc;
|
||||
|
||||
use expect::Expect;
|
||||
use hir_def::{
|
||||
body::{BodySourceMap, SyntheticSyntax},
|
||||
child_by_source::ChildBySource,
|
||||
|
@ -344,3 +345,29 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
|
|||
assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events)
|
||||
}
|
||||
}
|
||||
|
||||
// Infer with some common definitions and impls.
|
||||
fn check_infer(ra_fixture: &str, expect: Expect) {
|
||||
let defs = r#"
|
||||
#[lang = "sized"]
|
||||
pub trait Sized {}
|
||||
#[lang = "unsize"]
|
||||
pub trait Unsize<T: ?Sized> {}
|
||||
#[lang = "coerce_unsized"]
|
||||
pub trait CoerceUnsized<T> {}
|
||||
|
||||
impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
|
||||
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
|
||||
"#;
|
||||
|
||||
// Append to the end to keep positions unchanged.
|
||||
let mut actual = infer(&format!("{}{}", ra_fixture, defs));
|
||||
actual.push('\n');
|
||||
expect.assert_eq(&actual);
|
||||
}
|
||||
|
||||
fn check_infer_with_mismatches(ra_fixture: &str, expect: Expect) {
|
||||
let mut actual = infer_with_mismatches(ra_fixture, true);
|
||||
actual.push('\n');
|
||||
expect.assert_eq(&actual);
|
||||
}
|
||||
|
|
|
@ -1,32 +1,7 @@
|
|||
use expect::expect;
|
||||
use test_utils::mark;
|
||||
|
||||
use expect::{expect, Expect};
|
||||
|
||||
// Infer with some common definitions and impls.
|
||||
fn check_infer(ra_fixture: &str, expect: Expect) {
|
||||
let defs = r#"
|
||||
#[lang = "sized"]
|
||||
pub trait Sized {}
|
||||
#[lang = "unsize"]
|
||||
pub trait Unsize<T: ?Sized> {}
|
||||
#[lang = "coerce_unsized"]
|
||||
pub trait CoerceUnsized<T> {}
|
||||
|
||||
impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
|
||||
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
|
||||
"#;
|
||||
|
||||
// Append to the end to keep positions unchanged.
|
||||
let mut actual = super::infer(&format!("{}{}", ra_fixture, defs));
|
||||
actual.push('\n');
|
||||
expect.assert_eq(&actual);
|
||||
}
|
||||
|
||||
fn check_infer_with_mismatches(ra_fixture: &str, expect: Expect) {
|
||||
let mut actual = super::infer_with_mismatches(ra_fixture, true);
|
||||
actual.push('\n');
|
||||
expect.assert_eq(&actual);
|
||||
}
|
||||
use super::{check_infer, check_infer_with_mismatches};
|
||||
|
||||
#[test]
|
||||
fn infer_block_expr_type_mismatch() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use insta::assert_snapshot;
|
||||
use expect::expect;
|
||||
|
||||
use super::{check_types, infer_with_mismatches};
|
||||
use super::{check_infer_with_mismatches, check_types};
|
||||
|
||||
#[test]
|
||||
fn infer_never1() {
|
||||
|
@ -240,8 +240,8 @@ fn test(a: i32) {
|
|||
|
||||
#[test]
|
||||
fn diverging_expression_1() {
|
||||
let t = infer_with_mismatches(
|
||||
r#"
|
||||
check_infer_with_mismatches(
|
||||
r"
|
||||
//- /main.rs
|
||||
fn test1() {
|
||||
let x: u32 = return;
|
||||
|
@ -261,10 +261,8 @@ fn test5() {
|
|||
fn test6() {
|
||||
let x: u32 = { let y: u32 = { loop {}; }; };
|
||||
}
|
||||
"#,
|
||||
true,
|
||||
);
|
||||
assert_snapshot!(t, @r###"
|
||||
",
|
||||
expect![[r"
|
||||
11..39 '{ ...urn; }': ()
|
||||
21..22 'x': u32
|
||||
30..36 'return': !
|
||||
|
@ -299,12 +297,13 @@ fn test6() {
|
|||
292..304 '{ loop {}; }': u32
|
||||
294..301 'loop {}': !
|
||||
299..301 '{}': ()
|
||||
"###);
|
||||
"]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn diverging_expression_2() {
|
||||
let t = infer_with_mismatches(
|
||||
check_infer_with_mismatches(
|
||||
r#"
|
||||
//- /main.rs
|
||||
fn test1() {
|
||||
|
@ -312,9 +311,7 @@ fn test1() {
|
|||
let x: u32 = { loop {}; "foo" };
|
||||
}
|
||||
"#,
|
||||
true,
|
||||
);
|
||||
assert_snapshot!(t, @r###"
|
||||
expect![[r#"
|
||||
11..84 '{ ..." }; }': ()
|
||||
54..55 'x': u32
|
||||
63..81 '{ loop...foo" }': &str
|
||||
|
@ -323,13 +320,14 @@ fn test1() {
|
|||
74..79 '"foo"': &str
|
||||
63..81: expected u32, got &str
|
||||
74..79: expected u32, got &str
|
||||
"###);
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn diverging_expression_3_break() {
|
||||
let t = infer_with_mismatches(
|
||||
r#"
|
||||
check_infer_with_mismatches(
|
||||
r"
|
||||
//- /main.rs
|
||||
fn test1() {
|
||||
// should give type mismatch
|
||||
|
@ -351,10 +349,8 @@ fn test3() {
|
|||
// should give type mismatch as well
|
||||
let x: u32 = { while true { return; }; };
|
||||
}
|
||||
"#,
|
||||
true,
|
||||
);
|
||||
assert_snapshot!(t, @r###"
|
||||
",
|
||||
expect![[r"
|
||||
11..85 '{ ...} }; }': ()
|
||||
54..55 'x': u32
|
||||
63..82 '{ loop...k; } }': ()
|
||||
|
@ -408,5 +404,6 @@ fn test3() {
|
|||
407..433: expected u32, got ()
|
||||
546..564: expected u32, got ()
|
||||
624..651: expected u32, got ()
|
||||
"###);
|
||||
"]],
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue