]> git.lizzy.rs Git - rust.git/blob - tests/source/macros.rs
caccd75a700a2ada7d4d0eb778575c3bbd12e734
[rust.git] / tests / source / macros.rs
1 // rustfmt-normalize_comments: true
2 itemmacro!(this, is.now() .formatted(yay));
3
4 itemmacro!(really, long.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbb() .is.formatted());
5
6 itemmacro!{this, is.bracket().formatted()}
7
8 peg_file!   modname  ("mygrammarfile.rustpeg");
9
10 fn main() {
11     foo! ( );
12
13     bar!( a , b , c );
14
15     bar!( a , b , c , );
16
17     baz!(1+2+3, quux. kaas());
18
19     quux!(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB);
20
21     kaas!(/* comments */ a /* post macro */, b /* another */);
22
23     trailingcomma!( a , b , c , );
24
25     noexpr!( i am not an expression, OK? );
26
27     vec! [ a , b , c];
28
29     vec! [AAAAAA, AAAAAA, AAAAAA, AAAAAA, AAAAAA, AAAAAA, AAAAAA, AAAAAA, AAAAAA,
30           BBBBB, 5, 100-30, 1.33, b, b, b];
31
32     vec! [a /* comment */];
33
34     // Trailing spaces after a comma
35     vec![
36     a,   
37     ];
38     
39     vec![a; b];
40     vec!(a; b);
41     vec!{a; b};
42
43     vec![a, b; c];
44     vec![a; b, c];
45
46     vec![a; (|x| { let y = x + 1; let z = y + 1; z })(2)];
47     vec![a; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx];
48     vec![a; unsafe {
49         x + 1
50     }];
51
52     unknown_bracket_macro__comma_should_not_be_stripped![
53     a,
54     ];
55     
56     foo(makro!(1,   3));
57
58     hamkaas!{ () };
59
60     macrowithbraces! {dont,    format, me}
61
62     x!(fn);
63
64     some_macro!(
65         
66     );
67
68     some_macro![
69     ];
70
71     some_macro!{
72         // comment
73     };
74
75     some_macro!{
76         // comment
77     };
78
79     some_macro!(
80         // comment
81         not function like
82     );
83
84     // #1712
85     let image = gray_image!(
86         00, 01, 02;
87         10, 11, 12;
88         20, 21, 22);
89
90     // #1092
91     chain!(input, a:take!(max_size), || []);
92 }
93
94 impl X {
95     empty_invoc!{}
96 }
97
98 fn issue_1279() {
99     println!("dsfs"); // a comment
100 }
101
102 fn issue_1555() {
103     let hello = &format!("HTTP/1.1 200 OK\r\nServer: {}\r\n\r\n{}",
104                          "65454654654654654654654655464",
105                          "4");
106 }
107
108 fn issue1178() {
109     macro_rules! foo {
110         (#[$attr:meta] $name:ident) => {}
111     }
112
113     foo!(#[doc = "bar"] baz);
114 }
115
116 fn issue1739() {
117     sql_function!(add_rss_item,
118                   add_rss_item_t,
119                   (a: types::Integer,
120                    b: types::Timestamptz,
121                    c: types::Text,
122                    d: types::Text,
123                    e: types::Text));
124
125     w.slice_mut(s![.., init_size[1] - extreeeeeeeeeeeeeeeeeeeeeeeem..init_size[1], ..])
126         .par_map_inplace(|el| *el = 0.);
127 }
128
129 fn issue_1885() {
130     let threads = people.into_iter().map(|name| {
131         chan_select! {
132             rx.recv() => {}
133         }
134     }).collect::<Vec<_>>();
135 }
136
137 fn issue_1917() {
138     mod x {
139         quickcheck! {
140             fn test(a: String, s: String, b: String) -> TestResult {
141                 if a.find(&s).is_none() {
142
143                     TestResult::from_bool(true)
144                 } else {
145                     TestResult::discard()
146                 }
147             }
148         }
149     }
150 }
151
152 fn issue_1921() {
153     // Macro with tabs.
154     lazy_static! {
155         static ref ONE: u32 = 1;
156         static ref TWO: u32 = 2;
157         static ref THREE: u32 = 3;
158         static ref FOUR: u32 = {
159                 let mut acc = 1;
160                 acc += 1;
161                 acc += 2;
162                 acc
163         }
164 }
165 }
166
167 // Put the following tests with macro invocations whose arguments cannot be parsed as expressioins
168 // at the end of the file for now.
169
170 // #1577
171 fn issue1577() {
172     let json = json!({
173         "foo": "bar",
174     });
175 }
176
177 gfx_pipeline!(pipe {
178     vbuf: gfx::VertexBuffer<Vertex> = (),
179     out: gfx::RenderTarget<ColorFormat> = "Target0",
180 });