Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/expr_store/tests.rs')
-rw-r--r--crates/hir-def/src/expr_store/tests.rs88
1 files changed, 84 insertions, 4 deletions
diff --git a/crates/hir-def/src/expr_store/tests.rs b/crates/hir-def/src/expr_store/tests.rs
index 5ce9a67f9b..8936456044 100644
--- a/crates/hir-def/src/expr_store/tests.rs
+++ b/crates/hir-def/src/expr_store/tests.rs
@@ -1,10 +1,12 @@
mod block;
+use base_db::Upcast;
use expect_test::{expect, Expect};
use la_arena::RawIdx;
use test_fixture::WithFixture;
+use tracing::Instrument;
-use crate::{test_db::TestDB, ModuleDefId};
+use crate::{db::InternDatabase, test_db::TestDB, ModuleDefId};
use super::*;
@@ -446,7 +448,6 @@ fn foo() {
);
}
-#[test]
fn skip_skips_body() {
let (db, body, owner) = lower(
r#"
@@ -461,7 +462,7 @@ async fn foo(a: (), b: i32) -> u32 {
.assert_eq(&printed);
}
-fn abc() {
+fn test1() {
let (db, body, owner) = lower(
r#"
pub const L: i32 = 6;
@@ -470,8 +471,46 @@ mod x {
}
const fn f(x: i32) -> i32 {
match x {
- -1..=5 => x * 10,
L..=x::R => x * 100,
+ -1..=5 => x * 10,
+ _ => x,
+ }
+}"#,
+ );
+
+ let pat = body
+ .pats
+ .iter()
+ .find_map(|pat| {
+ if let Pat::Range { .. } = pat.1 {
+ return Some(pat.1);
+ }
+
+ None
+ })
+ .unwrap();
+
+ match pat {
+ Pat::Range { start, end } => {
+ dbg!(&body.exprs[start.unwrap()]);
+ dbg!(&body.exprs[end.unwrap()]);
+ }
+ _ => {}
+ }
+}
+
+#[test]
+fn test2() {
+ let (db, body, owner) = lower(
+ r#"
+pub const L: i32 = 6;
+mod x {
+ pub const R: i32 = 100;
+}
+const fn f(x: i32) -> i32 {
+ match x {
+ -1..=5 => x * 10,
+ ::std::i32::MIN..=x::R => x * 100,
_ => x,
}
}"#,
@@ -503,3 +542,44 @@ const fn f(x: i32) -> i32 {
}
}
}
+
+#[test]
+fn test3() {
+ let (db, body, owner) = lower(
+ r#"
+const A: u32 = 0;
+
+fn bar(v: u32) {
+ match v {
+ 0..=A => {}
+ _ => {}
+ }
+}"#,
+ );
+
+ for (pat_id, pat) in body.pats.iter() {
+ match pat {
+ Pat::Range { start, end } => {
+ let pretty = body.pretty_print_pat(&db, owner, pat_id, false, Edition::Edition2021);
+ eprintln!("RANGE {}", pretty);
+
+ if let Some(start) = start {
+ eprintln!("START");
+ let expr = body.exprs[*start].clone();
+ dbg!(expr);
+ } else {
+ eprintln!("START is None");
+ }
+
+ if let Some(end) = end {
+ eprintln!("END");
+ let expr = body.exprs[*end].clone();
+ dbg!(expr);
+ } else {
+ eprintln!("END is None");
+ }
+ }
+ _ => {}
+ }
+ }
+}