]> git.lizzy.rs Git - rust.git/blob - tests/target/macros.rs
Handle special-case macros
[rust.git] / tests / target / macros.rs
1 // rustfmt-normalize_comments: true
2 itemmacro!(this, is.now().formatted(yay));
3
4 itemmacro!(
5     really,
6     long.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbb()
7         .is
8         .formatted()
9 );
10
11 itemmacro!{this, is.bracket().formatted()}
12
13 peg_file! modname("mygrammarfile.rustpeg");
14
15 fn main() {
16     foo!();
17
18     bar!(a, b, c);
19
20     bar!(a, b, c,);
21
22     baz!(1 + 2 + 3, quux.kaas());
23
24     quux!(
25         AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,
26         BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
27     );
28
29     kaas!(
30         // comments
31         a, // post macro
32         b  // another
33     );
34
35     trailingcomma!(a, b, c,);
36     // Preserve trailing comma only when necessary.
37     ok!(file.seek(SeekFrom::Start(
38         table.map(|table| fixture.offset(table)).unwrap_or(0),
39     )));
40
41     noexpr!( i am not an expression, OK? );
42
43     vec![a, b, c];
44
45     vec![
46         AAAAAA,
47         AAAAAA,
48         AAAAAA,
49         AAAAAA,
50         AAAAAA,
51         AAAAAA,
52         AAAAAA,
53         AAAAAA,
54         AAAAAA,
55         BBBBB,
56         5,
57         100 - 30,
58         1.33,
59         b,
60         b,
61         b,
62     ];
63
64     vec![a /* comment */];
65
66     // Trailing spaces after a comma
67     vec![a];
68
69     vec![a; b];
70     vec![a; b];
71     vec![a; b];
72
73     vec![a, b; c];
74     vec![a; b, c];
75
76     vec![
77         a;
78         (|x| {
79             let y = x + 1;
80             let z = y + 1;
81             z
82         })(2)
83     ];
84     vec![
85         a;
86         xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
87     ];
88     vec![a; unsafe { x + 1 }];
89
90     unknown_bracket_macro__comma_should_not_be_stripped![a,];
91
92     foo(makro!(1, 3));
93
94     hamkaas!{ () };
95
96     macrowithbraces! {dont,    format, me}
97
98     x!(fn);
99
100     some_macro!();
101
102     some_macro![];
103
104     some_macro!{
105         // comment
106     };
107
108     some_macro!{
109         // comment
110     };
111
112     some_macro!(
113         // comment
114         not function like
115     );
116
117     // #1712
118     let image = gray_image!(
119         00, 01, 02;
120         10, 11, 12;
121         20, 21, 22);
122
123     // #1092
124     chain!(input, a:take!(max_size), || []);
125 }
126
127 impl X {
128     empty_invoc!{}
129 }
130
131 fn issue_1279() {
132     println!("dsfs"); // a comment
133 }
134
135 fn issue_1555() {
136     let hello = &format!(
137         "HTTP/1.1 200 OK\r\nServer: {}\r\n\r\n{}",
138         "65454654654654654654654655464",
139         "4"
140     );
141 }
142
143 fn issue1178() {
144     macro_rules! foo {
145         (#[$attr:meta] $name:ident) => {}
146     }
147
148     foo!(
149         #[doc = "bar"]
150         baz
151     );
152 }
153
154 fn issue1739() {
155     sql_function!(
156         add_rss_item,
157         add_rss_item_t,
158         (
159             a: types::Integer,
160             b: types::Timestamptz,
161             c: types::Text,
162             d: types::Text,
163             e: types::Text
164         )
165     );
166
167     w.slice_mut(s![
168         ..,
169         init_size[1] - extreeeeeeeeeeeeeeeeeeeeeeeem..init_size[1],
170         ..
171     ]).par_map_inplace(|el| *el = 0.);
172 }
173
174 fn issue_1885() {
175     let threads = people
176         .into_iter()
177         .map(|name| {
178             chan_select! {
179                 rx.recv() => {}
180             }
181         })
182         .collect::<Vec<_>>();
183 }
184
185 fn issue_1917() {
186     mod x {
187         quickcheck! {
188             fn test(a: String, s: String, b: String) -> TestResult {
189                 if a.find(&s).is_none() {
190
191                     TestResult::from_bool(true)
192                 } else {
193                     TestResult::discard()
194                 }
195             }
196         }
197     }
198 }
199
200 fn issue_1921() {
201     // Macro with tabs.
202     lazy_static! {
203         static ref ONE: u32 = 1;
204         static ref TWO: u32 = 2;
205         static ref THREE: u32 = 3;
206         static ref FOUR: u32 = {
207             let mut acc = 1;
208             acc += 1;
209             acc += 2;
210             acc
211         }
212     }
213 }
214
215 // #1577
216 fn issue1577() {
217     let json = json!({
218         "foo": "bar",
219     });
220 }
221
222 gfx_pipeline!(pipe {
223     vbuf: gfx::VertexBuffer<Vertex> = (),
224     out: gfx::RenderTarget<ColorFormat> = "Target0",
225 });
226
227 // #1919
228 #[test]
229 fn __bindgen_test_layout_HandleWithDtor_open0_int_close0_instantiation() {
230     assert_eq!(
231         ::std::mem::size_of::<HandleWithDtor<::std::os::raw::c_int>>(),
232         8usize,
233         concat!(
234             "Size of template specialization: ",
235             stringify!(HandleWithDtor<::std::os::raw::c_int>)
236         )
237     );
238     assert_eq!(
239         ::std::mem::align_of::<HandleWithDtor<::std::os::raw::c_int>>(),
240         8usize,
241         concat!(
242             "Alignment of template specialization: ",
243             stringify!(HandleWithDtor<::std::os::raw::c_int>)
244         )
245     );
246 }
247
248 // #878
249 macro_rules! try_opt {
250     ($expr:expr) => (match $expr {
251         Some(val) => val,
252
253         None => { return None; }
254     })
255 }
256
257 // #2214
258 // macro call whose argument is an array with trailing comma.
259 fn issue2214() {
260     make_test!(
261         str_searcher_ascii_haystack,
262         "bb",
263         "abbcbbd",
264         [
265             Reject(0, 1),
266             Match(1, 3),
267             Reject(3, 4),
268             Match(4, 6),
269             Reject(6, 7),
270         ]
271     );
272 }
273
274 fn special_case_macros() {
275     // format!
276     let s = format!(
277         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
278         result, input, expected
279     );
280
281     // assert!
282     assert!(
283         result,
284         "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')",
285         result, input, expected
286     );
287 }