Unnamed repository; edit this file 'description' to name the repository.
minor: Add a mbe test for parsing negative literals
Lukas Wirth 12 months ago
parent b3e086a · commit 9d1364b
-rw-r--r--crates/hir-def/src/nameres/path_resolution.rs1
-rw-r--r--crates/mbe/src/tests.rs117
2 files changed, 118 insertions, 0 deletions
diff --git a/crates/hir-def/src/nameres/path_resolution.rs b/crates/hir-def/src/nameres/path_resolution.rs
index 2ad5e9eca0..74ce33a641 100644
--- a/crates/hir-def/src/nameres/path_resolution.rs
+++ b/crates/hir-def/src/nameres/path_resolution.rs
@@ -483,6 +483,7 @@ impl DefMap {
curr_per_ns = match curr.def {
ModuleDefId::ModuleId(module) => {
if module.krate != self.krate {
+ // FIXME: Inefficient
let path = ModPath::from_segments(
PathKind::SELF,
path.segments()[i..].iter().cloned(),
diff --git a/crates/mbe/src/tests.rs b/crates/mbe/src/tests.rs
index a5672e4e05..3369dfff28 100644
--- a/crates/mbe/src/tests.rs
+++ b/crates/mbe/src/tests.rs
@@ -356,3 +356,120 @@ fn expr_2021() {
;"#]],
);
}
+
+#[test]
+fn minus_belongs_to_literal() {
+ let decl = r#"
+(-1) => {-1};
+(- 2) => {- 2};
+(- 3.0) => {- 3.0};
+(@$lit:literal) => {$lit}
+"#;
+ let check = |args, expect| check(Edition::CURRENT, Edition::CURRENT, decl, args, expect);
+ check(
+ "-1",
+ expect![[r#"
+ SUBTREE $$ 1:[email protected]#ROOT2024 1:[email protected]#ROOT2024
+ PUNCH - [alone] 0:[email protected]#ROOT2024
+ LITERAL Integer 1 0:[email protected]#ROOT2024
+
+ -1"#]],
+ );
+ check(
+ "- 1",
+ expect![[r#"
+ SUBTREE $$ 1:[email protected]#ROOT2024 1:[email protected]#ROOT2024
+ PUNCH - [alone] 0:[email protected]#ROOT2024
+ LITERAL Integer 1 0:[email protected]#ROOT2024
+
+ -1"#]],
+ );
+ check(
+ "-2",
+ expect![[r#"
+ SUBTREE $$ 1:[email protected]#ROOT2024 1:[email protected]#ROOT2024
+ PUNCH - [alone] 0:[email protected]#ROOT2024
+ LITERAL Integer 2 0:[email protected]#ROOT2024
+
+ -2"#]],
+ );
+ check(
+ "- 2",
+ expect![[r#"
+ SUBTREE $$ 1:[email protected]#ROOT2024 1:[email protected]#ROOT2024
+ PUNCH - [alone] 0:[email protected]#ROOT2024
+ LITERAL Integer 2 0:[email protected]#ROOT2024
+
+ -2"#]],
+ );
+ check(
+ "-3.0",
+ expect![[r#"
+ SUBTREE $$ 1:[email protected]#ROOT2024 1:[email protected]#ROOT2024
+ PUNCH - [alone] 0:[email protected]#ROOT2024
+ LITERAL Float 3.0 0:[email protected]#ROOT2024
+
+ -3.0"#]],
+ );
+ check(
+ "- 3.0",
+ expect![[r#"
+ SUBTREE $$ 1:[email protected]#ROOT2024 1:[email protected]#ROOT2024
+ PUNCH - [alone] 0:[email protected]#ROOT2024
+ LITERAL Float 3.0 0:[email protected]#ROOT2024
+
+ -3.0"#]],
+ );
+ check(
+ "@1",
+ expect![[r#"
+ SUBTREE $$ 1:[email protected]#ROOT2024 1:[email protected]#ROOT2024
+ LITERAL Integer 1 1:[email protected]#ROOT2024
+
+ 1"#]],
+ );
+ check(
+ "@-1",
+ expect![[r#"
+ SUBTREE $$ 1:[email protected]#ROOT2024 1:[email protected]#ROOT2024
+ PUNCH - [alone] 1:[email protected]#ROOT2024
+ LITERAL Integer 1 1:[email protected]#ROOT2024
+
+ -1"#]],
+ );
+ check(
+ "@1.0",
+ expect![[r#"
+ SUBTREE $$ 1:[email protected]#ROOT2024 1:[email protected]#ROOT2024
+ LITERAL Float 1.0 1:[email protected]#ROOT2024
+
+ 1.0"#]],
+ );
+ check(
+ "@-1.0",
+ expect![[r#"
+ SUBTREE $$ 1:[email protected]#ROOT2024 1:[email protected]#ROOT2024
+ PUNCH - [alone] 1:[email protected]#ROOT2024
+ LITERAL Float 1.0 1:[email protected]#ROOT2024
+
+ -1.0"#]],
+ );
+ check(
+ "@--1.0",
+ expect![[r#"
+ ExpandError {
+ inner: (
+ 1:[email protected]#ROOT2024,
+ BindingError(
+ "expected literal",
+ ),
+ ),
+ }
+
+ SUBTREE $$ 1:[email protected]#ROOT2024 1:[email protected]#ROOT2024
+ PUNCH - [joint] 1:[email protected]#ROOT2024
+ PUNCH - [alone] 1:[email protected]#ROOT2024
+
+ --"#]],
+ );
+}