]> git.lizzy.rs Git - rust.git/blob - tests/ui/proc-macro/span-api-tests.rs
Rollup merge of #106816 - TimNN:rental-remap, r=oli-obj
[rust.git] / tests / 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 // compile-flags: -Ztranslate-remapped-path-to-local-path=yes
6
7 #[macro_use]
8 extern crate span_test_macros;
9
10 extern crate span_api_tests;
11
12 // FIXME(69775): Investigate `assert_fake_source_file`.
13
14 use span_api_tests::{reemit, assert_source_file, macro_stringify};
15
16 macro_rules! say_hello {
17     ($macname:ident) => ( $macname! { "Hello, world!" })
18 }
19
20 assert_source_file! { "Hello, world!" }
21
22 say_hello! { assert_source_file }
23
24 reemit_legacy! {
25     assert_source_file! { "Hello, world!" }
26 }
27
28 say_hello_extern! { assert_source_file }
29
30 reemit! {
31     assert_source_file! { "Hello, world!" }
32 }
33
34 fn main() {
35     let s = macro_stringify!(Hello, world!);
36     assert_eq!(s, "Hello, world!");
37     assert_eq!(macro_stringify!(Hello, world!), "Hello, world!");
38     assert_eq!(reemit_legacy!(macro_stringify!(Hello, world!)), "Hello, world!");
39     reemit_legacy!(assert_eq!(macro_stringify!(Hello, world!), "Hello, world!"));
40     // reemit change the span to be that of the call site
41     assert_eq!(
42         reemit!(macro_stringify!(Hello, world!)),
43         "reemit!(macro_stringify!(Hello, world!))"
44     );
45     let r = "reemit!(assert_eq!(macro_stringify!(Hello, world!), r))";
46     reemit!(assert_eq!(macro_stringify!(Hello, world!), r));
47
48     assert_eq!(macro_stringify!(
49         Hello,
50         world!
51     ), "Hello,\n        world!");
52
53     assert_eq!(macro_stringify!(Hello, /*world */ !), "Hello, /*world */ !");
54         assert_eq!(macro_stringify!(
55         Hello,
56         // comment
57         world!
58     ), "Hello,\n        // comment\n        world!");
59
60     assert_eq!(say_hello! { macro_stringify }, "\"Hello, world!\"");
61     assert_eq!(say_hello_extern! { macro_stringify }, "\"Hello, world!\"");
62 }