Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/proc-macro-srv/src/tests/mod.rs')
| -rw-r--r-- | crates/proc-macro-srv/src/tests/mod.rs | 272 |
1 files changed, 269 insertions, 3 deletions
diff --git a/crates/proc-macro-srv/src/tests/mod.rs b/crates/proc-macro-srv/src/tests/mod.rs index a81fea7bec..3a6ce639d1 100644 --- a/crates/proc-macro-srv/src/tests/mod.rs +++ b/crates/proc-macro-srv/src/tests/mod.rs @@ -11,8 +11,24 @@ fn test_derive_empty() { assert_expand( "DeriveEmpty", r#"struct S;"#, - expect!["SUBTREE $$ 1 1"], - expect!["SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024"], + expect![[r#" + SUBTREE $$ 1 1 + IDENT struct 1 + IDENT S 1 + PUNCH ; [alone] 1 + + + + SUBTREE $$ 1 1"#]], + expect![[r#" + SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 + IDENT struct 42:[email protected]#ROOT2024 + IDENT S 42:[email protected]#ROOT2024 + PUNCH ; [alone] 42:[email protected]#ROOT2024 + + + + SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024"#]], ); } @@ -23,6 +39,13 @@ fn test_derive_error() { r#"struct S;"#, expect![[r#" SUBTREE $$ 1 1 + IDENT struct 1 + IDENT S 1 + PUNCH ; [alone] 1 + + + + SUBTREE $$ 1 1 IDENT compile_error 1 PUNCH ! [alone] 1 SUBTREE () 1 1 @@ -30,6 +53,13 @@ fn test_derive_error() { PUNCH ; [alone] 1"#]], expect![[r#" SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 + IDENT struct 42:[email protected]#ROOT2024 + IDENT S 42:[email protected]#ROOT2024 + PUNCH ; [alone] 42:[email protected]#ROOT2024 + + + + SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 IDENT compile_error 42:[email protected]#ROOT2024 PUNCH ! [alone] 42:[email protected]#ROOT2024 SUBTREE () 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 @@ -51,6 +81,17 @@ fn test_fn_like_macro_noop() { PUNCH , [alone] 1 LITERAL Integer 1 1 PUNCH , [alone] 1 + SUBTREE [] 1 1 + + + + SUBTREE $$ 1 1 + IDENT ident 1 + PUNCH , [alone] 1 + LITERAL Integer 0 1 + PUNCH , [alone] 1 + LITERAL Integer 1 1 + PUNCH , [alone] 1 SUBTREE [] 1 1"#]], expect![[r#" SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 @@ -60,6 +101,17 @@ fn test_fn_like_macro_noop() { PUNCH , [alone] 42:[email protected]#ROOT2024 LITERAL Integer 1 42:[email protected]#ROOT2024 PUNCH , [alone] 42:[email protected]#ROOT2024 + SUBTREE [] 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 + + + + SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 + IDENT ident 42:[email protected]#ROOT2024 + PUNCH , [alone] 42:[email protected]#ROOT2024 + LITERAL Integer 0 42:[email protected]#ROOT2024 + PUNCH , [alone] 42:[email protected]#ROOT2024 + LITERAL Integer 1 42:[email protected]#ROOT2024 + PUNCH , [alone] 42:[email protected]#ROOT2024 SUBTREE [] 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024"#]], ); } @@ -73,12 +125,26 @@ fn test_fn_like_macro_clone_ident_subtree() { SUBTREE $$ 1 1 IDENT ident 1 PUNCH , [alone] 1 + SUBTREE [] 1 1 + + + + SUBTREE $$ 1 1 + IDENT ident 1 + PUNCH , [alone] 1 SUBTREE [] 1 1"#]], expect![[r#" SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 IDENT ident 42:[email protected]#ROOT2024 PUNCH , [alone] 42:[email protected]#ROOT2024 - SUBTREE [] 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024"#]], + SUBTREE [] 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 + + + + SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 + IDENT ident 42:[email protected]#ROOT2024 + PUNCH , [alone] 42:[email protected]#ROOT2024 + SUBTREE [] 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024"#]], ); } @@ -89,9 +155,19 @@ fn test_fn_like_macro_clone_raw_ident() { "r#async", expect![[r#" SUBTREE $$ 1 1 + IDENT r#async 1 + + + + SUBTREE $$ 1 1 IDENT r#async 1"#]], expect![[r#" SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 + IDENT r#async 42:[email protected]#ROOT2024 + + + + SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 IDENT r#async 42:[email protected]#ROOT2024"#]], ); } @@ -103,9 +179,21 @@ fn test_fn_like_fn_like_span_join() { "foo bar", expect![[r#" SUBTREE $$ 1 1 + IDENT foo 1 + IDENT bar 1 + + + + SUBTREE $$ 1 1 IDENT r#joined 1"#]], expect![[r#" SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 + IDENT foo 42:[email protected]#ROOT2024 + IDENT bar 42:[email protected]#ROOT2024 + + + + SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 IDENT r#joined 42:[email protected]#ROOT2024"#]], ); } @@ -117,11 +205,25 @@ fn test_fn_like_fn_like_span_ops() { "set_def_site resolved_at_def_site start_span", expect![[r#" SUBTREE $$ 1 1 + IDENT set_def_site 1 + IDENT resolved_at_def_site 1 + IDENT start_span 1 + + + + SUBTREE $$ 1 1 IDENT set_def_site 0 IDENT resolved_at_def_site 1 IDENT start_span 1"#]], expect![[r#" SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 + IDENT set_def_site 42:[email protected]#ROOT2024 + IDENT resolved_at_def_site 42:[email protected]#ROOT2024 + IDENT start_span 42:[email protected]#ROOT2024 + + + + SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 IDENT set_def_site 41:[email protected]#ROOT2024 IDENT resolved_at_def_site 42:[email protected]#ROOT2024 IDENT start_span 42:[email protected]#ROOT2024"#]], @@ -135,21 +237,47 @@ fn test_fn_like_mk_literals() { r#""#, expect![[r#" SUBTREE $$ 1 1 + + + + SUBTREE $$ 1 1 LITERAL ByteStr byte_string 1 LITERAL Char c 1 LITERAL Str string 1 + LITERAL CStr cstring 1 LITERAL Float 3.14f64 1 + PUNCH - [alone] 1 + LITERAL Float 3.14f64 1 + LITERAL Float 3.14 1 + PUNCH - [alone] 1 LITERAL Float 3.14 1 LITERAL Integer 123i64 1 + PUNCH - [alone] 1 + LITERAL Integer 123i64 1 + LITERAL Integer 123 1 + PUNCH - [alone] 1 LITERAL Integer 123 1"#]], expect![[r#" SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 + + + + SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 LITERAL ByteStr byte_string 42:[email protected]#ROOT2024 LITERAL Char c 42:[email protected]#ROOT2024 LITERAL Str string 42:[email protected]#ROOT2024 + LITERAL CStr cstring 42:[email protected]#ROOT2024 + LITERAL Float 3.14f64 42:[email protected]#ROOT2024 + PUNCH - [alone] 42:[email protected]#ROOT2024 LITERAL Float 3.14f64 42:[email protected]#ROOT2024 LITERAL Float 3.14 42:[email protected]#ROOT2024 + PUNCH - [alone] 42:[email protected]#ROOT2024 + LITERAL Float 3.14 42:[email protected]#ROOT2024 + LITERAL Integer 123i64 42:[email protected]#ROOT2024 + PUNCH - [alone] 42:[email protected]#ROOT2024 LITERAL Integer 123i64 42:[email protected]#ROOT2024 + LITERAL Integer 123 42:[email protected]#ROOT2024 + PUNCH - [alone] 42:[email protected]#ROOT2024 LITERAL Integer 123 42:[email protected]#ROOT2024"#]], ); } @@ -161,10 +289,18 @@ fn test_fn_like_mk_idents() { r#""#, expect![[r#" SUBTREE $$ 1 1 + + + + SUBTREE $$ 1 1 IDENT standard 1 IDENT r#raw 1"#]], expect![[r#" SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 + + + + SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 IDENT standard 42:[email protected]#ROOT2024 IDENT r#raw 42:[email protected]#ROOT2024"#]], ); @@ -196,6 +332,30 @@ fn test_fn_like_macro_clone_literals() { PUNCH , [alone] 1 LITERAL Byte b 1 PUNCH , [alone] 1 + LITERAL CStr null 1 + + + + SUBTREE $$ 1 1 + LITERAL Integer 1u16 1 + PUNCH , [alone] 1 + LITERAL Integer 2_u32 1 + PUNCH , [alone] 1 + PUNCH - [alone] 1 + LITERAL Integer 4i64 1 + PUNCH , [alone] 1 + LITERAL Float 3.14f32 1 + PUNCH , [alone] 1 + LITERAL Str hello bridge 1 + PUNCH , [alone] 1 + LITERAL Str suffixedsuffix 1 + PUNCH , [alone] 1 + LITERAL StrRaw(2) raw 1 + PUNCH , [alone] 1 + LITERAL Char a 1 + PUNCH , [alone] 1 + LITERAL Byte b 1 + PUNCH , [alone] 1 LITERAL CStr null 1"#]], expect![[r#" SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 @@ -218,11 +378,99 @@ fn test_fn_like_macro_clone_literals() { PUNCH , [alone] 42:[email protected]#ROOT2024 LITERAL Byte b 42:[email protected]#ROOT2024 PUNCH , [alone] 42:[email protected]#ROOT2024 + LITERAL CStr null 42:[email protected]#ROOT2024 + + + + SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 + LITERAL Integer 1u16 42:[email protected]#ROOT2024 + PUNCH , [alone] 42:[email protected]#ROOT2024 + LITERAL Integer 2_u32 42:[email protected]#ROOT2024 + PUNCH , [alone] 42:[email protected]#ROOT2024 + PUNCH - [alone] 42:[email protected]#ROOT2024 + LITERAL Integer 4i64 42:[email protected]#ROOT2024 + PUNCH , [alone] 42:[email protected]#ROOT2024 + LITERAL Float 3.14f32 42:[email protected]#ROOT2024 + PUNCH , [alone] 42:[email protected]#ROOT2024 + LITERAL Str hello bridge 42:[email protected]#ROOT2024 + PUNCH , [alone] 42:[email protected]#ROOT2024 + LITERAL Str suffixedsuffix 42:[email protected]#ROOT2024 + PUNCH , [alone] 42:[email protected]#ROOT2024 + LITERAL StrRaw(2) raw 42:[email protected]#ROOT2024 + PUNCH , [alone] 42:[email protected]#ROOT2024 + LITERAL Char a 42:[email protected]#ROOT2024 + PUNCH , [alone] 42:[email protected]#ROOT2024 + LITERAL Byte b 42:[email protected]#ROOT2024 + PUNCH , [alone] 42:[email protected]#ROOT2024 LITERAL CStr null 42:[email protected]#ROOT2024"#]], ); } #[test] +fn test_fn_like_macro_negative_literals() { + assert_expand( + "fn_like_clone_tokens", + r###"-1u16, - 2_u32, -3.14f32, - 2.7"###, + expect![[r#" + SUBTREE $$ 1 1 + PUNCH - [alone] 1 + LITERAL Integer 1u16 1 + PUNCH , [alone] 1 + PUNCH - [alone] 1 + LITERAL Integer 2_u32 1 + PUNCH , [alone] 1 + PUNCH - [alone] 1 + LITERAL Float 3.14f32 1 + PUNCH , [alone] 1 + PUNCH - [alone] 1 + LITERAL Float 2.7 1 + + + + SUBTREE $$ 1 1 + PUNCH - [alone] 1 + LITERAL Integer 1u16 1 + PUNCH , [alone] 1 + PUNCH - [alone] 1 + LITERAL Integer 2_u32 1 + PUNCH , [alone] 1 + PUNCH - [alone] 1 + LITERAL Float 3.14f32 1 + PUNCH , [alone] 1 + PUNCH - [alone] 1 + LITERAL Float 2.7 1"#]], + expect![[r#" + SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 + PUNCH - [alone] 42:[email protected]#ROOT2024 + LITERAL Integer 1u16 42:[email protected]#ROOT2024 + PUNCH , [alone] 42:[email protected]#ROOT2024 + PUNCH - [alone] 42:[email protected]#ROOT2024 + LITERAL Integer 2_u32 42:[email protected]#ROOT2024 + PUNCH , [alone] 42:[email protected]#ROOT2024 + PUNCH - [alone] 42:[email protected]#ROOT2024 + LITERAL Float 3.14f32 42:[email protected]#ROOT2024 + PUNCH , [alone] 42:[email protected]#ROOT2024 + PUNCH - [alone] 42:[email protected]#ROOT2024 + LITERAL Float 2.7 42:[email protected]#ROOT2024 + + + + SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 + PUNCH - [alone] 42:[email protected]#ROOT2024 + LITERAL Integer 1u16 42:[email protected]#ROOT2024 + PUNCH , [alone] 42:[email protected]#ROOT2024 + PUNCH - [alone] 42:[email protected]#ROOT2024 + LITERAL Integer 2_u32 42:[email protected]#ROOT2024 + PUNCH , [alone] 42:[email protected]#ROOT2024 + PUNCH - [alone] 42:[email protected]#ROOT2024 + LITERAL Float 3.14f32 42:[email protected]#ROOT2024 + PUNCH , [alone] 42:[email protected]#ROOT2024 + PUNCH - [alone] 42:[email protected]#ROOT2024 + LITERAL Float 2.7 42:[email protected]#ROOT2024"#]], + ); +} + +#[test] fn test_attr_macro() { // Corresponds to // #[proc_macro_test::attr_error(some arguments)] @@ -233,6 +481,15 @@ fn test_attr_macro() { r#"some arguments"#, expect![[r#" SUBTREE $$ 1 1 + IDENT mod 1 + IDENT m 1 + SUBTREE {} 1 1 + + SUBTREE $$ 1 1 + IDENT some 1 + IDENT arguments 1 + + SUBTREE $$ 1 1 IDENT compile_error 1 PUNCH ! [alone] 1 SUBTREE () 1 1 @@ -240,6 +497,15 @@ fn test_attr_macro() { PUNCH ; [alone] 1"#]], expect![[r#" SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 + IDENT mod 42:[email protected]#ROOT2024 + IDENT m 42:[email protected]#ROOT2024 + SUBTREE {} 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 + + SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 + IDENT some 42:[email protected]#ROOT2024 + IDENT arguments 42:[email protected]#ROOT2024 + + SUBTREE $$ 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 IDENT compile_error 42:[email protected]#ROOT2024 PUNCH ! [alone] 42:[email protected]#ROOT2024 SUBTREE () 42:[email protected]#ROOT2024 42:[email protected]#ROOT2024 |