From 30ffa3d5ba8f5c2e9b542d61a44b4c05cf596c44 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 2 Aug 2020 21:38:45 -0700 Subject: [PATCH] Add shebang tests --- tests/test_shebang.rs | 59 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/test_shebang.rs diff --git a/tests/test_shebang.rs b/tests/test_shebang.rs new file mode 100644 index 0000000000..e76e1803da --- /dev/null +++ b/tests/test_shebang.rs @@ -0,0 +1,59 @@ +#[macro_use] +mod macros; + +#[test] +fn test_basic() { + let content = "#!/usr/bin/env rustx\nfn main() {}"; + let file = syn::parse_file(content).unwrap(); + snapshot!(file, @r###" + File { + shebang: Some("#!/usr/bin/env rustx"), + items: [ + Item::Fn { + vis: Inherited, + sig: Signature { + ident: "main", + generics: Generics, + output: Default, + }, + block: Block, + }, + ], + } + "###); +} + +#[test] +fn test_comment() { + let content = "#!//am/i/a/comment\n[allow(dead_code)] fn main() {}"; + let file = syn::parse_file(content).unwrap(); + snapshot!(file, @r###" + File { + attrs: [ + Attribute { + style: Inner, + path: Path { + segments: [ + PathSegment { + ident: "allow", + arguments: None, + }, + ], + }, + tokens: TokenStream(`( dead_code )`), + }, + ], + items: [ + Item::Fn { + vis: Inherited, + sig: Signature { + ident: "main", + generics: Generics, + output: Default, + }, + block: Block, + }, + ], + } + "###); +}