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