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