]> git.lizzy.rs Git - rust.git/blob - src/test/ui/proc-macro/span-api-tests.rs
Rollup merge of #69945 - contrun:fix-outdated-comment, r=petrochenkov
[rust.git] / src / test / ui / proc-macro / span-api-tests.rs
1 // run-pass
2 // aux-build:span-api-tests.rs
3 // aux-build:span-test-macros.rs
4
5 // ignore-pretty
6
7 #![feature(proc_macro_hygiene)]
8
9 #[macro_use]
10 extern crate span_test_macros;
11
12 extern crate span_api_tests;
13
14 // FIXME(69775): Investigate `assert_fake_source_file`.
15
16 use span_api_tests::{reemit, assert_source_file, macro_stringify};
17
18 macro_rules! say_hello {
19     ($macname:ident) => ( $macname! { "Hello, world!" })
20 }
21
22 assert_source_file! { "Hello, world!" }
23
24 say_hello! { assert_source_file }
25
26 reemit_legacy! {
27     assert_source_file! { "Hello, world!" }
28 }
29
30 say_hello_extern! { assert_source_file }
31
32 reemit! {
33     assert_source_file! { "Hello, world!" }
34 }
35
36 fn main() {
37     let s = macro_stringify!(Hello, world!);
38     assert_eq!(s, "Hello, world!");
39     assert_eq!(macro_stringify!(Hello, world!), "Hello, world!");
40     assert_eq!(reemit_legacy!(macro_stringify!(Hello, world!)), "Hello, world!");
41     reemit_legacy!(assert_eq!(macro_stringify!(Hello, world!), "Hello, world!"));
42     // reemit change the span to be that of the call site
43     assert_eq!(
44         reemit!(macro_stringify!(Hello, world!)),
45         "reemit!(macro_stringify!(Hello, world!))"
46     );
47     let r = "reemit!(assert_eq!(macro_stringify!(Hello, world!), r));";
48     reemit!(assert_eq!(macro_stringify!(Hello, world!), r));
49
50     assert_eq!(macro_stringify!(
51         Hello,
52         world!
53     ), "Hello,\n        world!");
54
55     assert_eq!(macro_stringify!(Hello, /*world */ !), "Hello, /*world */ !");
56         assert_eq!(macro_stringify!(
57         Hello,
58         // comment
59         world!
60     ), "Hello,\n        // comment\n        world!");
61
62     assert_eq!(say_hello! { macro_stringify }, "\"Hello, world!\"");
63     assert_eq!(say_hello_extern! { macro_stringify }, "\"Hello, world!\"");
64 }