-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmacros_json_array.rs
More file actions
42 lines (37 loc) · 909 Bytes
/
macros_json_array.rs
File metadata and controls
42 lines (37 loc) · 909 Bytes
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
// error-pattern: expected type, found `440.0`
macro_rules! json {
(null) => {
Json::Null
};
([ $( $element:expr ),* ]) => {
Json::Array(vec![ $( $element ),* ])
};
}
macro_rules! strip_test {
(#[test] $( $rest:tt )*) => {
$( $rest )*
}
}
strip_test! {
#[test]
fn json_array_with_json_element() {
let macro_generated_value = json!(
[
// valid JSON that doesn't match `$element:expr`
{
"pitch": 440.0
}
]
);
let hand_coded_value =
Json::Array(vec![
Json::Object(Box::new(vec![
("pitch".to_string(), Json::Number(440.0))
].collect()))
]);
assert_eq!(macro_generated_value, hand_coded_value);
}
}
fn main() {
json_array_with_json_element();
}