aboutsummaryrefslogtreecommitdiff
path: root/tests/macros/mod.rs
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-05-10 07:02:34 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-05-10 07:02:34 +0000
commit4f2209441bb12841e86ea6e03c3485d350af152a (patch)
tree58f7f050cf3633807c295fb927d3752b7b5a1a0d /tests/macros/mod.rs
parent02c40db88ab3665f9039228409d8cb38fe3d92c8 (diff)
parenta69aad5c40038729e172d571c62881b9366382c7 (diff)
downloadserde_json-android13-mainline-resolv-release.tar.gz
Change-Id: I63310326f4d15a061c72cdacb6fea5c7a792d606
Diffstat (limited to 'tests/macros/mod.rs')
-rw-r--r--tests/macros/mod.rs59
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)
+ };
+}