File: layouter.t

package info (click to toggle)
libgraph-easy-perl 0.76-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 4,264 kB
  • sloc: perl: 23,869; makefile: 7
file content (82 lines) | stat: -rw-r--r-- 1,670 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/perl -w

use Test::More;
use strict;

# Test parsing and laying out the graphs (with no strict checks on the
# output except that it should work). Tests all inputs with the four
# flow directions.


BEGIN
   {
   plan tests => 34;
   chdir 't' if -d 't';
   use lib '../lib';
   use_ok ("Graph::Easy") or die($@);
   use_ok ("Graph::Easy::Parser") or die($@);
   };

#############################################################################
# parser object

my $parser = Graph::Easy::Parser->new( debug => 0);

is (ref($parser), 'Graph::Easy::Parser');
is ($parser->error(), '', 'no error yet');

opendir DIR, "layouter" or die ("Cannot read dir 'in': $!");
my @files = readdir(DIR); closedir(DIR);

foreach my $f (sort @files)
  {
  next unless -f "layouter/$f";			# only files

  next unless $f =~ /\.txt/;			# ignore anything else

  print "# at $f\n";

  my $txt = readfile("layouter/$f");

  for my $flow (qw/down up right west left/)
    {

    my $t = "graph { flow: $flow; }\n" . $txt;

    my $graph = $parser->from_text($t);		# reuse parser object

#    $graph->debug(1);

    if (!defined $graph)
      {
      fail ("Graph input was invalid: " . $parser->error());
      next;
      }

    my $ascii = $graph->as_ascii();

    is ($graph->error(), '', 'no error on layout');

    # print a debug output
    $ascii =~ s/\n/\n# /g;
    $t =~ s/\n/\n# /g;
    print "# Input:\n#\n# $t\n";
    print "# Generated:\n#\n# $ascii\n";

    } # for all directions

  }

1;

sub readfile
  {
  my ($file) = @_;

  open FILE, $file or die ("Cannot read file $file: $!");
  local $/ = undef;				# slurp mode
  my $doc = <FILE>;
  close FILE;

  $doc;
  }