Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/syntax/src/ast/make.rs')
-rw-r--r--crates/syntax/src/ast/make.rs97
1 files changed, 96 insertions, 1 deletions
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs
index dba39204e3..4a7afed61e 100644
--- a/crates/syntax/src/ast/make.rs
+++ b/crates/syntax/src/ast/make.rs
@@ -1016,7 +1016,19 @@ pub fn item_static(
}
pub fn unnamed_param(ty: ast::Type) -> ast::Param {
- ast_from_text(&format!("fn f({ty}) {{ }}"))
+ quote! {
+ Param {
+ #ty
+ }
+ }
+}
+
+pub fn untyped_param(pat: ast::Pat) -> ast::Param {
+ quote! {
+ Param {
+ #pat
+ }
+ }
}
pub fn param(pat: ast::Pat, ty: ast::Type) -> ast::Param {
@@ -1456,3 +1468,86 @@ pub mod tokens {
}
}
}
+
+#[cfg(test)]
+mod tests {
+ use expect_test::expect;
+
+ use super::*;
+
+ #[track_caller]
+ fn check(node: impl AstNode, expect: expect_test::Expect) {
+ let node_debug = format!("{:#?}", node.syntax());
+ expect.assert_eq(&node_debug);
+ }
+
+ #[test]
+ fn test_unnamed_param() {
+ check(
+ unnamed_param(ty("Vec")),
+ expect![[r#"
+ "#]],
+ );
+
+ check(
+ unnamed_param(ty("Vec<T>")),
+ expect![[r#"
+ "#]],
+ );
+ }
+
+ #[test]
+ fn test_untyped_param() {
+ check(
+ untyped_param(path_pat(ext::ident_path("name"))),
+ expect![[r#"
+ "#]],
+ );
+
+ check(
+ untyped_param(
+ range_pat(
+ Some(path_pat(ext::ident_path("start"))),
+ Some(path_pat(ext::ident_path("end"))),
+ )
+ .into(),
+ ),
+ expect![[r#"
+ "#]],
+ );
+ }
+}