diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-05-10 07:02:34 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-05-10 07:02:34 +0000 |
commit | 4f2209441bb12841e86ea6e03c3485d350af152a (patch) | |
tree | 58f7f050cf3633807c295fb927d3752b7b5a1a0d /tests/macros/mod.rs | |
parent | 02c40db88ab3665f9039228409d8cb38fe3d92c8 (diff) | |
parent | a69aad5c40038729e172d571c62881b9366382c7 (diff) | |
download | serde_json-android13-mainline-resolv-release.tar.gz |
Snap for 8564071 from a69aad5c40038729e172d571c62881b9366382c7 to mainline-resolv-releaseaml_res_331820000aml_res_331611010aml_res_331512000aml_res_331314010aml_res_331114000aml_res_331011050aml_res_330910000aml_res_330810000android13-mainline-resolv-release
Change-Id: I63310326f4d15a061c72cdacb6fea5c7a792d606
Diffstat (limited to 'tests/macros/mod.rs')
-rw-r--r-- | tests/macros/mod.rs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/macros/mod.rs b/tests/macros/mod.rs new file mode 100644 index 0000000..8ac4619 --- /dev/null +++ b/tests/macros/mod.rs @@ -0,0 +1,59 @@ +macro_rules! json_str { + ([]) => { + "[]" + }; + ([ $e0:tt $(, $e:tt)* $(,)? ]) => { + concat!("[", + json_str!($e0), + $(",", json_str!($e),)* + "]") + }; + ({}) => { + "{}" + }; + ({ $k0:tt : $v0:tt $(, $k:tt : $v:tt)* $(,)? }) => { + concat!("{", + stringify!($k0), ":", json_str!($v0), + $(",", stringify!($k), ":", json_str!($v),)* + "}") + }; + (($other:tt)) => { + $other + }; + ($other:tt) => { + stringify!($other) + }; +} + +macro_rules! pretty_str { + ($json:tt) => { + pretty_str_impl!("", $json) + }; +} + +macro_rules! pretty_str_impl { + ($indent:expr, []) => { + "[]" + }; + ($indent:expr, [ $e0:tt $(, $e:tt)* $(,)? ]) => { + concat!("[\n ", + $indent, pretty_str_impl!(concat!(" ", $indent), $e0), + $(",\n ", $indent, pretty_str_impl!(concat!(" ", $indent), $e),)* + "\n", $indent, "]") + }; + ($indent:expr, {}) => { + "{}" + }; + ($indent:expr, { $k0:tt : $v0:tt $(, $k:tt : $v:tt)* $(,)? }) => { + concat!("{\n ", + $indent, stringify!($k0), ": ", pretty_str_impl!(concat!(" ", $indent), $v0), + $(",\n ", $indent, stringify!($k), ": ", pretty_str_impl!(concat!(" ", $indent), $v),)* + "\n", $indent, "}") + }; + ($indent:expr, ($other:tt)) => { + $other + }; + ($indent:expr, $other:tt) => { + stringify!($other) + }; +} |