HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.52.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 15 06:39:08 EDT 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //root/.cpanm/latest-build/YAML-Syck-1.34/t/json-circular-ref.t
use strict;
use warnings;
use Test::More tests => 8;

use JSON::Syck;

{    # Impossible circular blessed references in JSON
    my $foo = bless {}, "Foo";
    my $bar = bless { foo => $foo }, "Bar";
    $foo->{bar} = $bar;

    my $result = eval { JSON::Syck::Dump($foo) };
    is( $result, undef, "A Structure should come back on a JSON dump with circular blessed references" );
    like( $@, qr/^Dumping circular structures is not supported with JSON::Syck/, "Die is thrown when the circular blessed ref happens" );
}

{    # Circular references broken regardless of blessing
    my $foo = {};
    my $bar = { foo => $foo };
    $foo->{bar} = $bar;

    my $result = eval { JSON::Syck::Dump($foo) };
    is( $result, undef, "A Structure should come back on a JSON dump with duplicate references" );
    like( $@, qr/^Dumping circular structures is not supported with JSON::Syck/, "Die is thrown when the circular ref happens" );
}

{
    my $foo = {};

    my $result = eval { JSON::Syck::Dump( [ $foo, $foo ] ) };
    is( $result, '[{},{}]', "A Structure should come back on a JSON dump with duplicate references" );
    is( $@,      '',        "No die is thrown when the circular ref happens" );
}

{
    my $foo = { 'a' => [ 1, 2 ] };

    my $result = eval { JSON::Syck::Dump( [ $foo, $foo ] ) };
    is( $result, '[{"a":[1,2]},{"a":[1,2]}]', "A Complex structure should come back on a JSON dump with duplicate references" );
    is( $@, '', "No die is thrown when the circular ref happens" );
}