]> git.proxmox.com Git - rustc.git/blob - vendor/serde_json/tests/macros/mod.rs
New upstream version 1.60.0+dfsg1
[rustc.git] / vendor / serde_json / tests / macros / mod.rs
1 macro_rules! json_str {
2 ([]) => {
3 "[]"
4 };
5 ([ $e0:tt $(, $e:tt)* $(,)? ]) => {
6 concat!("[",
7 json_str!($e0),
8 $(",", json_str!($e),)*
9 "]")
10 };
11 ({}) => {
12 "{}"
13 };
14 ({ $k0:tt : $v0:tt $(, $k:tt : $v:tt)* $(,)? }) => {
15 concat!("{",
16 stringify!($k0), ":", json_str!($v0),
17 $(",", stringify!($k), ":", json_str!($v),)*
18 "}")
19 };
20 (($other:tt)) => {
21 $other
22 };
23 ($other:tt) => {
24 stringify!($other)
25 };
26 }
27
28 macro_rules! pretty_str {
29 ($json:tt) => {
30 pretty_str_impl!("", $json)
31 };
32 }
33
34 macro_rules! pretty_str_impl {
35 ($indent:expr, []) => {
36 "[]"
37 };
38 ($indent:expr, [ $e0:tt $(, $e:tt)* $(,)? ]) => {
39 concat!("[\n ",
40 $indent, pretty_str_impl!(concat!(" ", $indent), $e0),
41 $(",\n ", $indent, pretty_str_impl!(concat!(" ", $indent), $e),)*
42 "\n", $indent, "]")
43 };
44 ($indent:expr, {}) => {
45 "{}"
46 };
47 ($indent:expr, { $k0:tt : $v0:tt $(, $k:tt : $v:tt)* $(,)? }) => {
48 concat!("{\n ",
49 $indent, stringify!($k0), ": ", pretty_str_impl!(concat!(" ", $indent), $v0),
50 $(",\n ", $indent, stringify!($k), ": ", pretty_str_impl!(concat!(" ", $indent), $v),)*
51 "\n", $indent, "}")
52 };
53 ($indent:expr, ($other:tt)) => {
54 $other
55 };
56 ($indent:expr, $other:tt) => {
57 stringify!($other)
58 };
59 }