Graph-Easy

 view release on metacpan or  search on metacpan

t/graphml.t  view on Meta::CPAN

    </node>

    <edge source="A" target="B">
      <data key="d0">car</data>
    </edge>
    <edge source="A" target="C">
      <data key="d0">train</data>
    </edge>
  </graph>
</graphml>
EOT4
;

_compare($graph, $result, 'GraphML with attributes');

#############################################################################
# as_graphml() with groups (bug until v0.63):

$graph = Graph::Easy->new();
my $bonn  = Graph::Easy::Node->new('Bonn');
my $cities = $graph->add_group('Cities"');
$cities->add_nodes($bonn);

$result = <<EOT5
  <graph id="G" edgedefault="directed">
    <graph id="Cities&quot;" edgedefault="directed">
      <node id="Bonn">
      </node>
    </graph>
  </graph>
</graphml>
EOT5
;

_compare($graph, $result, 'GraphML with group');

# all tests done

#############################################################################
#############################################################################

sub _compare
  {
  my ($graph, $result, $name) = @_;

  my $graphml = $graph->as_graphml();
  $graphml =~ s/\n.*<!--.*-->\n//;

  $result = <<EOR
<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
     http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">

EOR
  . $result unless $result =~ /<\?xml/;

  if (!is ($graphml, $result, $name))
    {
    eval { require Test::Differences; };
    if (defined $Test::Differences::VERSION)
      {
      Test::Differences::eq_or_diff ($result, $graphml);
      }
    }
  }



( run in 3.394 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )