summaryrefslogtreecommitdiff
path: root/t/circular.t
diff options
context:
space:
mode:
Diffstat (limited to 't/circular.t')
-rw-r--r--t/circular.t34
1 files changed, 34 insertions, 0 deletions
diff --git a/t/circular.t b/t/circular.t
new file mode 100644
index 0000000..4b35d85
--- /dev/null
+++ b/t/circular.t
@@ -0,0 +1,34 @@
+use strict;
+use warnings;
+use Test::More;
+
+use Data::Dumper::Compact;
+
+my $can_j = eval { require JSON::Dumper::Compact; 1 };
+
+my $circular = {
+ quux => { bar => 73 },
+ foo => { baz => [ 42 ] },
+};
+
+$circular->{foo}{baz}[1] = $circular->{foo};
+
+is(
+ Data::Dumper::Compact->dump($circular),
+ '{ foo => { baz => [ 42, $_->{foo} ] }, quux => { bar => 73 } }'."\n"
+);
+
+if ($can_j) {
+ is(
+ JSON::Dumper::Compact->dump($circular),
+ '{
+ "foo": { "baz": [
+ 42, { "$ref": "#/foo" }
+ ,
+ ] },
+ "quux": { "bar": 73 },
+}
+');
+}
+
+done_testing;