#!/usr/bin/perl -w BEGIN { unshift @INC,'../lib'; } use Test::More tests=>17; use GraphViz::Data::Structure; while (my $current = get_current()) { %hash = eval $current; my $result = eval $hash{'code'}; die $@ if $@; is (normalize($result), normalize($hash{'out'}), $hash{'name'}); } sub get_current { my $code = ""; while () { last if /%%/; $code .= $_; } $code; } sub normalize { } __DATA__ (name => 'ref to zero-element hash', code => 'GraphViz::Data::Structure->new(\\{},graph=>{label=>"ref to zero-element hash"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="ref to zero-element hash"]; node [label="\\N"]; { graph [rank=same]; gvds_scalar0 [label="", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_hash0 [label="\\{\\}", rank=1, shape=plaintext]; } gvds_scalar0 -> gvds_hash0; } ) ) %% (name => 'ref to one-element hash', code => 'GraphViz::Data::Structure->new(\\{"test"=>"me"},graph=>{label=>"ref to one-element hash"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="ref to one-element hash"]; node [label="\\N"]; { graph [rank=same]; gvds_scalar0 [label="", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_hash0 [label="{test|me}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; } gvds_scalar0 -> gvds_hash0; } ) ) %% (name => 'ref to three-element hash', code => 'GraphViz::Data::Structure->new(\\{"larry"=>"fuzz","moe"=>"mop","curly"=>"none"}, graph=>{label=>"ref to three-element hash"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="ref to three-element hash"]; node [label="\\N"]; { graph [rank=same]; gvds_scalar0 [label="", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_hash0 [label="{curly|none}|{larry|fuzz}|{moe|mop}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; } gvds_scalar0 -> gvds_hash0; } ) ) %% (name => 'ref to vertical three-element hash', code => 'GraphViz::Data::Structure->new(\\{"larry"=>"fuzz","moe"=>"mop","curly"=>"none"}, Orientation=>"vertical",graph=>{label=>"ref to vertical three-element hash"})->graph->as_canon', out => qq(digraph test { graph [rankdir=LR, ratio=fill, label="ref to vertical three-element hash"]; node [label="\\N"]; { graph [rank=same]; gvds_scalar0 [label="", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_hash0 [label="{{curly|larry|moe}|{none|fuzz|mop}}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; } gvds_scalar0 -> gvds_hash0; } ) ) %% (name => 'single-element hash ref to empty arrays', code => 'my %a=(Empty=>[]); GraphViz::Data::Structure->new(\\%a,graph=>{label=>"single-element hash ref to empty arrays"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="single-element hash ref to empty arrays"]; node [label="\\N"]; { graph [rank=same]; gvds_hash0 [label="{Empty|.}", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_array0 [label="\\[\\]", rank=1, shape=plaintext]; } gvds_hash0:port2 -> gvds_array0; } ) ) %% (name => 'three-element hash ref to empty arrays', code => 'my %a=(Nil=>[],Nada=>[],Zip=>[]); GraphViz::Data::Structure->new(\\%a,graph=>{label=>"three-element hash ref to empty arrays"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="three-element hash ref to empty arrays"]; node [label="\\N"]; { graph [rank=same]; gvds_hash0 [label="{Nada|.}|{Nil|.}|{Zip|.}", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_array0 [label="\\[\\]", rank=1, shape=plaintext]; gvds_array1 [label="\\[\\]", rank=1, shape=plaintext]; gvds_array2 [label="\\[\\]", rank=1, shape=plaintext]; } gvds_hash0:port2 -> gvds_array0; gvds_hash0:port4 -> gvds_array1; gvds_hash0:port6 -> gvds_array2; } ) ) %% (name => 'single-element hash ref to one-element arrays', code => 'my %a=(Pointer=>["test"]); GraphViz::Data::Structure->new(\\%a,graph=>{label=>"single-element hash ref to one-element arrays"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="single-element hash ref to one-element arrays"]; node [label="\\N"]; { graph [rank=same]; gvds_hash0 [label="{Pointer|.}", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_array0 [label="test", color=white, fontcolor=black, rank=1, shape=record, style=filled]; } gvds_hash0:port2 -> gvds_array0; } ) ) %% (name => 'three-element hash ref to one-element arrays', code => 'my %a=(Fuzz=>["larry"],Mop=>["moe"],Bald=>["curly"]); GraphViz::Data::Structure->new(\\%a,graph=>{label=>"three-element hash ref to one-element arrays"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="three-element hash ref to one-element arrays"]; node [label="\\N"]; { graph [rank=same]; gvds_hash0 [label="{Bald|.}|{Fuzz|.}|{Mop|.}", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_array0 [label="curly", color=white, fontcolor=black, rank=1, shape=record, style=filled]; gvds_array1 [label="larry", color=white, fontcolor=black, rank=1, shape=record, style=filled]; gvds_array2 [label="moe", color=white, fontcolor=black, rank=1, shape=record, style=filled]; } gvds_hash0:port2 -> gvds_array0; gvds_hash0:port4 -> gvds_array1; gvds_hash0:port6 -> gvds_array2; } ) ) %% (name => 'single-element hash ref to three-element arrays', code => 'my %a=(Stooges=>["larry","moe","curly"]); GraphViz::Data::Structure->new(\\%a,graph=>{label=>"single-element hash ref to three-element arrays"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="single-element hash ref to three-element arrays"]; node [label="\\N"]; { graph [rank=same]; gvds_hash0 [label="{Stooges|.}", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_array0 [label="{larry}|{moe}|{curly}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; } gvds_hash0:port2 -> gvds_array0; } ) ) %% (name => 'three-element hash ref to three-element arrays', code => 'my %a=(Stooges=>["larry","moe","curly"], MarxBros=>["groucho","harpo","chico"], Goons=>["seagoon","bloodnok","eccles"]); GraphViz::Data::Structure->new(\\%a,graph=>{label=>"three-element hash ref to three-element arrays"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="three-element hash ref to three-element arrays"]; node [label="\\N"]; { graph [rank=same]; gvds_hash0 [label="{Goons|.}|{MarxBros|.}|{Stooges|.}", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_array0 [label="{seagoon}|{bloodnok}|{eccles}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; gvds_array1 [label="{groucho}|{harpo}|{chico}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; gvds_array2 [label="{larry}|{moe}|{curly}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; } gvds_hash0:port2 -> gvds_array0; gvds_hash0:port4 -> gvds_array1; gvds_hash0:port6 -> gvds_array2; } ) ) %% (name => 'single-element hash ref to empty hashes', code => 'my %a=(Nil=>{}); GraphViz::Data::Structure->new(\\%a,graph=>{label=>"single-element hash ref to empty hashes"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="single-element hash ref to empty hashes"]; node [label="\\N"]; { graph [rank=same]; gvds_hash0 [label="{Nil|.}", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_hash1 [label="\\{\\}", rank=1, shape=plaintext]; } gvds_hash0:port2 -> gvds_hash1; } ) ) %% (name => 'three-element hash ref to empty hashes', code => 'my %a=(Nada=>{},Zilch=>{},Zip=>{}); GraphViz::Data::Structure->new(\\%a,graph=>{label=>"three-element hash ref to empty hashes"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="three-element hash ref to empty hashes"]; node [label="\\N"]; { graph [rank=same]; gvds_hash0 [label="{Nada|.}|{Zilch|.}|{Zip|.}", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_hash1 [label="\\{\\}", rank=1, shape=plaintext]; gvds_hash2 [label="\\{\\}", rank=1, shape=plaintext]; gvds_hash3 [label="\\{\\}", rank=1, shape=plaintext]; } gvds_hash0:port2 -> gvds_hash1; gvds_hash0:port4 -> gvds_hash2; gvds_hash0:port6 -> gvds_hash3; } ) ) %% (name => 'single-element hash ref to one-element hashes', code => 'my %a=(One=>{"test"=>"2"}); GraphViz::Data::Structure->new(\\%a,graph=>{label=>"single-element hash ref to one-element hashes"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="single-element hash ref to one-element hashes"]; node [label="\\N"]; { graph [rank=same]; gvds_hash0 [label="{One|.}", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_hash1 [label="{test|2}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; } gvds_hash0:port2 -> gvds_hash1; } ) ) %% (name => 'three-element hash ref to one-element hashes', code => 'my %a=(One=>{"larry"=>"fuzz"}, Two=>{"moe"=>"mop"}, Three=>{"curly"=>"none"}); GraphViz::Data::Structure->new(\\%a,graph=>{label=>"three-element hash ref to one-element hashes"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="three-element hash ref to one-element hashes"]; node [label="\\N"]; { graph [rank=same]; gvds_hash0 [label="{One|.}|{Three|.}|{Two|.}", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_hash1 [label="{larry|fuzz}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; gvds_hash2 [label="{curly|none}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; gvds_hash3 [label="{moe|mop}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; } gvds_hash0:port2 -> gvds_hash1; gvds_hash0:port4 -> gvds_hash2; gvds_hash0:port6 -> gvds_hash3; } ) ) %% (name => 'single-element hash ref to three-element hashes', code => 'my %a=(Stooges=>{"larry"=>"fuzz","moe"=>"mop","curly"=>"none"}); GraphViz::Data::Structure->new(\\%a,graph=>{label=>"single-element hash ref to three-element hashes"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="single-element hash ref to three-element hashes"]; node [label="\\N"]; { graph [rank=same]; gvds_hash0 [label="{Stooges|.}", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_hash1 [label="{curly|none}|{larry|fuzz}|{moe|mop}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; } gvds_hash0:port2 -> gvds_hash1; } ) ) %% (name => 'three-element hash ref to three-element hashes', code => 'my %a=(Stooges=>{"larry"=>1,"moe"=>2,"curly"=>3}, MarxBros=>{"groucho"=>1,"harpo"=>2,"chico"=>3}, Goons=>{"seagoon"=>1,"bloodnok"=>2,"eccles"=>3}); GraphViz::Data::Structure->new(\\%a,graph=>{label=>"three-element hash ref to three-element hashes"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="three-element hash ref to three-element hashes"]; node [label="\\N"]; { graph [rank=same]; gvds_hash0 [label="{Goons|.}|{MarxBros|.}|{Stooges|.}", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_hash1 [label="{bloodnok|2}|{eccles|3}|{seagoon|1}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; gvds_hash2 [label="{chico|3}|{groucho|1}|{harpo|2}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; gvds_hash3 [label="{curly|3}|{larry|1}|{moe|2}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; } gvds_hash0:port2 -> gvds_hash1; gvds_hash0:port4 -> gvds_hash2; gvds_hash0:port6 -> gvds_hash3; } ) ) %% (name => 'odd characters in parent', code => 'my %a=(""=>{"larry"=>1,"moe"=>2,"curly"=>3}, "