#!/usr/bin/perl -w BEGIN { unshift @INC,'../lib'; } use Test::More tests=>18; 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 array', code => 'GraphViz::Data::Structure->new(\\[],graph=>{label=>"ref to zero-element array"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="ref to zero-element array"]; node [label="\\N"]; { graph [rank=same]; gvds_scalar0 [label="", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_array0 [label="\\[\\]", rank=1, shape=plaintext]; } gvds_scalar0 -> gvds_array0; } ) ) %% (name => 'ref to one-element array', code => 'GraphViz::Data::Structure->new(\\["test"],graph=>{label=>"ref to one-element array"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="ref to one-element array"]; node [label="\\N"]; { graph [rank=same]; gvds_scalar0 [label="", 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_scalar0 -> gvds_array0; } ) ) %% (name => 'ref to three-element array', code => 'GraphViz::Data::Structure->new(\\["larry","moe","curly"],graph=>{label=>"ref to three-element array"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="ref to three-element array"]; node [label="\\N"]; { graph [rank=same]; gvds_scalar0 [label="", 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_scalar0 -> gvds_array0; } ) ) %% (name => 'ref to vertical three-element array', code => 'GraphViz::Data::Structure->new(\\["larry","moe","curly"],Orientation=>"vertical",graph=>{label=>"ref to vertical three-element array"})->graph->as_canon', out => qq(digraph test { graph [rankdir=LR, ratio=fill, label="ref to vertical three-element array"]; node [label="\\N"]; { graph [rank=same]; gvds_scalar0 [label="", 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_scalar0 -> gvds_array0; } ) ) %% (name => 'single-element array ref to empty arrays', code => 'my @a=([]); GraphViz::Data::Structure->new(\\@a,%title)->graph->as_canon', out => qq(digraph test { graph [ratio=fill]; node [label="\\N"]; { graph [rank=same]; gvds_array0 [label=".", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_array1 [label="\\[\\]", rank=1, shape=plaintext]; } gvds_array0:port1 -> gvds_array1; } ) ) %% (name => 'three-element array ref to empty arrays', code => 'my @a=([],[],[]); GraphViz::Data::Structure->new(\\@a,graph=>{label=>"three-element array ref to empty arrays"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="three-element array ref to empty arrays"]; node [label="\\N"]; { graph [rank=same]; gvds_array0 [label="{.}|{.}|{.}", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_array1 [label="\\[\\]", rank=1, shape=plaintext]; gvds_array2 [label="\\[\\]", rank=1, shape=plaintext]; gvds_array3 [label="\\[\\]", rank=1, shape=plaintext]; } gvds_array0:port1 -> gvds_array1; gvds_array0:port2 -> gvds_array2; gvds_array0:port3 -> gvds_array3; } ) ) %% (name => 'single-element array ref to one-element arrays', code => 'my @a=(["test"]); GraphViz::Data::Structure->new(\\@a,graph=>{label=>"single-element array ref to one-element arrays"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="single-element array ref to one-element arrays"]; node [label="\\N"]; { graph [rank=same]; gvds_array0 [label=".", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_array1 [label="test", color=white, fontcolor=black, rank=1, shape=record, style=filled]; } gvds_array0:port1 -> gvds_array1; } ) ) %% (name => 'three-element array ref to one-element arrays', code => 'my @a=(["larry"],["moe"],["curly"]); GraphViz::Data::Structure->new(\\@a,graph=>{label=>"three-element array ref to one-element arrays"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="three-element array ref to one-element arrays"]; node [label="\\N"]; { graph [rank=same]; gvds_array0 [label="{.}|{.}|{.}", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; 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_array3 [label="curly", color=white, fontcolor=black, rank=1, shape=record, style=filled]; } gvds_array0:port1 -> gvds_array1; gvds_array0:port2 -> gvds_array2; gvds_array0:port3 -> gvds_array3; } ) ) %% (name => 'single-element array ref to three-element arrays', code => 'my @a=(["larry","moe","curly"]); GraphViz::Data::Structure->new(\\@a,graph=>{label=>"single-element array ref to three-element arrays"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="single-element array ref to three-element arrays"]; node [label="\\N"]; { graph [rank=same]; gvds_array0 [label=".", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_array1 [label="{larry}|{moe}|{curly}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; } gvds_array0:port1 -> gvds_array1; } ) ) %% (name => 'three-element array ref to three-element arrays', code => 'my @a=(["larry","moe","curly"], ["groucho","harpo","chico"], ["seagoon","bloodnok","eccles"]); GraphViz::Data::Structure->new(\\@a,graph=>{label=>"three-element array ref to three-element arrays"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="three-element array ref to three-element arrays"]; node [label="\\N"]; { graph [rank=same]; gvds_array0 [label="{.}|{.}|{.}", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_array1 [label="{larry}|{moe}|{curly}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; gvds_array2 [label="{groucho}|{harpo}|{chico}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; gvds_array3 [label="{seagoon}|{bloodnok}|{eccles}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; } gvds_array0:port1 -> gvds_array1; gvds_array0:port2 -> gvds_array2; gvds_array0:port3 -> gvds_array3; } ) ) %% (name => 'single-element array ref to empty hash', code => 'my @a=({}); GraphViz::Data::Structure->new(\\@a,graph=>{label=>"single-element array ref to empty hash"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="single-element array ref to empty hash"]; node [label="\\N"]; { graph [rank=same]; gvds_array0 [label=".", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_hash0 [label="\\{\\}", rank=1, shape=plaintext]; } gvds_array0:port1 -> gvds_hash0; } ) ) %% (name => 'three-element array ref to empty hashes', code => 'my @a=({},{},{}); GraphViz::Data::Structure->new(\\@a,graph=>{label=>"three-element array ref to empty hashes"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="three-element array ref to empty hashes"]; node [label="\\N"]; { graph [rank=same]; gvds_array0 [label="{.}|{.}|{.}", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_hash0 [label="\\{\\}", rank=1, shape=plaintext]; gvds_hash1 [label="\\{\\}", rank=1, shape=plaintext]; gvds_hash2 [label="\\{\\}", rank=1, shape=plaintext]; } gvds_array0:port1 -> gvds_hash0; gvds_array0:port2 -> gvds_hash1; gvds_array0:port3 -> gvds_hash2; } ) ) %% (name => 'single-element array ref to one-element hashes', code => 'my @a=({"test"=>1}); GraphViz::Data::Structure->new(\\@a,graph=>{label=>"single-element array ref to one-element hashes"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="single-element array ref to one-element hashes"]; node [label="\\N"]; { graph [rank=same]; gvds_array0 [label=".", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_hash0 [label="{test|1}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; } gvds_array0:port1 -> gvds_hash0; } ) ) %% (name => 'three-element array ref to one-element hashes', code => 'my @a=({"larry"=>2},{"moe"=>1},{"curly"=>3}); GraphViz::Data::Structure->new(\\@a,graph=>{label=>"three-element array ref to one-element hashes"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="three-element array ref to one-element hashes"]; node [label="\\N"]; { graph [rank=same]; gvds_array0 [label="{.}|{.}|{.}", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_hash0 [label="{larry|2}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; gvds_hash1 [label="{moe|1}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; gvds_hash2 [label="{curly|3}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; } gvds_array0:port1 -> gvds_hash0; gvds_array0:port2 -> gvds_hash1; gvds_array0:port3 -> gvds_hash2; } ) ) %% (name => 'single-element array ref to three-element hash', code => 'my @a=({"larry"=>2,"moe"=>1,"curly"=>3}); GraphViz::Data::Structure->new(\\@a,graph=>{label=>"single-element array ref to three-element hash"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="single-element array ref to three-element hash"]; node [label="\\N"]; { graph [rank=same]; gvds_array0 [label=".", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_hash0 [label="{curly|3}|{larry|2}|{moe|1}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; } gvds_array0:port1 -> gvds_hash0; } ) ) %% (name => 'three-element array ref to three-element hashes', code => 'my @a=({"larry"=>2,"moe"=>1,"curly"=>3}, {"groucho"=>1,"harpo"=>3,"chico"=>2}, {"seagoon"=>2,"bloodnok"=>1,"eccles"=>3}); GraphViz::Data::Structure->new(\\@a,graph=>{label=>"three-element array ref to three-element hashes"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="three-element array ref to three-element hashes"]; node [label="\\N"]; { graph [rank=same]; gvds_array0 [label="{.}|{.}|{.}", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_hash0 [label="{curly|3}|{larry|2}|{moe|1}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; gvds_hash1 [label="{chico|2}|{groucho|1}|{harpo|3}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; gvds_hash2 [label="{bloodnok|1}|{eccles|3}|{seagoon|2}", color=white, fontcolor=black, rank=1, shape=record, style=filled]; } gvds_array0:port1 -> gvds_hash0; gvds_array0:port2 -> gvds_hash1; gvds_array0:port3 -> gvds_hash2; } ) ) %% (name => 'verify port assignments', code => 'my @a=(Nil=>[],Nada=>[],Zip=>[]); GraphViz::Data::Structure->new(\\@a,graph=>{label=>"verify port assignments"})->graph->as_canon', out => qq(digraph test { graph [ratio=fill, label="verify port assignments"]; node [label="\\N"]; { graph [rank=same]; gvds_array0 [label="{Nil}|{.}|{Nada}|{.}|{Zip}|{.}", color=white, fontcolor=black, rank=0, shape=record, style=filled]; } { graph [rank=same]; gvds_array1 [label="\\[\\]", rank=1, shape=plaintext]; gvds_array2 [label="\\[\\]", rank=1, shape=plaintext]; gvds_array3 [label="\\[\\]", rank=1, shape=plaintext]; } gvds_array0:port2 -> gvds_array1; gvds_array0:port4 -> gvds_array2; gvds_array0:port6 -> gvds_array3; } ) ) %% (name => 'odd characters', code => 'my @a=(""=>[],"