-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
pass.rs
274 lines (233 loc) · 7.27 KB
/
pass.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#![no_implicit_prelude]
#![recursion_limit = "128"]
// Shadow primitives
#[allow(non_camel_case_types)]
pub struct bool;
#[allow(non_camel_case_types)]
pub struct char;
#[allow(non_camel_case_types)]
pub struct f32;
#[allow(non_camel_case_types)]
pub struct f64;
#[allow(non_camel_case_types)]
pub struct i128;
#[allow(non_camel_case_types)]
pub struct i16;
#[allow(non_camel_case_types)]
pub struct i32;
#[allow(non_camel_case_types)]
pub struct i64;
#[allow(non_camel_case_types)]
pub struct i8;
#[allow(non_camel_case_types)]
pub struct isize;
#[allow(non_camel_case_types)]
pub struct str;
#[allow(non_camel_case_types)]
pub struct u128;
#[allow(non_camel_case_types)]
pub struct u16;
#[allow(non_camel_case_types)]
pub struct u32;
#[allow(non_camel_case_types)]
pub struct u64;
#[allow(non_camel_case_types)]
pub struct u8;
#[allow(non_camel_case_types)]
pub struct usize;
mod t1 {
#[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)]
pub struct Props<T: ::std::clone::Clone + ::std::default::Default + ::std::cmp::PartialEq> {
#[prop_or_default]
value: T,
}
fn optional_prop_generics_should_work() {
use ::yew::Properties;
Props::<::std::primitive::bool>::builder().build();
Props::<::std::primitive::bool>::builder().value(true).build();
}
}
mod t2 {
#[derive(::std::clone::Clone, ::std::cmp::PartialEq)]
struct Value;
#[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)]
pub struct Props<T: ::std::clone::Clone + ::std::cmp::PartialEq> {
value: T,
}
fn required_prop_generics_should_work() {
use ::yew::Properties;
Props::<Value>::builder().value(Value).build();
}
}
mod t3 {
#[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)]
pub struct Props {
b: ::std::primitive::i32,
#[prop_or_default]
a: ::std::primitive::i32,
}
fn order_is_alphabetized() {
use ::yew::Properties;
Props::builder().b(1).build();
Props::builder().a(1).b(2).build();
}
}
mod t4 {
#[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)]
pub struct Props<T>
where
T: ::std::clone::Clone + ::std::default::Default + ::std::cmp::PartialEq,
{
#[prop_or_default]
value: T,
}
fn optional_prop_generics_should_work() {
use ::yew::Properties;
Props::<::std::primitive::bool>::builder().build();
Props::<::std::primitive::bool>::builder().value(true).build();
}
}
mod t5 {
#[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)]
pub struct Props<
'a,
T: ::std::clone::Clone + ::std::default::Default + ::std::cmp::PartialEq + 'a,
> {
#[prop_or_default]
static_value: &'static ::std::primitive::str,
value: &'a T,
}
fn optional_prop_generics_with_lifetime_should_work() {
use ::std::{convert::From, string::String};
use ::yew::Properties;
Props::<String>::builder().value(&String::from("")).build();
Props::<String>::builder()
.static_value("")
.value(&String::from(""))
.build();
}
}
mod t6 {
#[derive(::yew::Properties, ::std::clone::Clone, ::std::cmp::PartialEq)]
pub struct Props<T: ::std::str::FromStr + ::std::clone::Clone + ::std::cmp::PartialEq>
where
<T as ::std::str::FromStr>::Err: ::std::clone::Clone + ::std::cmp::PartialEq,
{
value: ::std::result::Result<T, <T as ::std::str::FromStr>::Err>,
}
fn required_prop_generics_with_where_clause_should_work() {
use ::std::{convert::From, result::Result::Ok, string::String};
use ::yew::Properties;
Props::<String>::builder()
.value(Ok(String::from("")))
.build();
}
}
mod t7 {
#[derive(::std::clone::Clone, Debug, Eq, ::std::cmp::PartialEq)]
pub enum Foo {
One,
Two,
}
#[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)]
pub struct Props {
#[prop_or(Foo::One)]
value: Foo,
}
fn prop_or_value_should_work() {
use ::std::assert_eq;
use ::yew::Properties;
let props = Props::builder().build();
assert_eq!(props.value, Foo::One);
Props::builder().value(Foo::Two).build();
}
}
mod t8 {
#[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)]
pub struct Props {
#[prop_or_else(|| 123)]
value: ::std::primitive::i32,
}
fn prop_or_else_closure_should_work() {
use ::std::assert_eq;
use ::yew::Properties;
let props = Props::builder().build();
assert_eq!(props.value, 123);
Props::builder().value(123).build();
}
}
mod t9 {
#[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)]
pub struct Props<T: ::std::str::FromStr + ::std::clone::Clone + ::std::cmp::PartialEq>
where
<T as ::std::str::FromStr>::Err: ::std::clone::Clone + ::std::cmp::PartialEq,
{
#[prop_or_else(default_value)]
value: ::std::result::Result<T, <T as ::std::str::FromStr>::Err>,
}
fn default_value<T: ::std::str::FromStr + ::std::clone::Clone>(
) -> ::std::result::Result<T, <T as ::std::str::FromStr>::Err>
where
<T as ::std::str::FromStr>::Err: ::std::clone::Clone,
{
"123".parse()
}
fn prop_or_else_function_with_generics_should_work() {
use ::std::{assert_eq, result::Result::Ok};
use ::yew::Properties;
let props = Props::<::std::primitive::i32>::builder().build();
assert_eq!(props.value, Ok(123));
Props::<i32>::builder().value(Ok(456)).build();
}
}
mod t10 {
// this test makes sure that Yew handles generic params with default values properly.
#[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)]
pub struct Foo<S, M = S>
where
S: ::std::clone::Clone + ::std::cmp::PartialEq,
M: ::std::clone::Clone + ::std::cmp::PartialEq,
{
bar: S,
baz: M,
}
}
mod t11 {
// this test makes sure that Yew handles generic params with const generics properly.
#[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)]
pub struct Foo<T, const N: usize>
where
T: ::std::clone::Clone + ::std::cmp::PartialEq,
{
bar: [T; N],
}
}
mod t12 {
#[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)]
pub struct Props<T: ::std::clone::Clone + ::std::cmp::PartialEq> {
value: ::std::option::Option<T>,
}
fn optional_prop_generics_should_work() {
use ::yew::Properties;
Props::<::std::primitive::bool>::builder().build();
Props::<::std::primitive::bool>::builder().value(true).build();
}
}
#[deny(non_snake_case, dead_code)]
mod t13 {
#[derive(::std::cmp::PartialEq, ::yew::Properties)]
#[allow(non_snake_case)] // putting this on fields directly does not work, even in normal rust
struct Props {
#[allow(dead_code)]
create_message: ::std::option::Option<bool>,
NonSnakeCase: u32,
}
}
mod raw_field_names {
#[derive(::yew::Properties, ::std::cmp::PartialEq)]
pub struct Props {
r#true: u32,
r#pointless_raw_name: u32,
}
}
fn main() {}