File: edge_cell.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 (134 lines) | stat: -rw-r--r-- 3,117 bytes parent folder | download | duplicates (5)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/perl -w

# Test Graph::Easy::Edge::Cell

use Test::More;
use strict;

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

can_ok ("Graph::Easy::Edge::Cell", qw/
  new
  as_ascii as_html
  error
  pos
  x
  y
  label
  width
  height
  style
  type

  edge_type

  _draw_cross
  _draw_ver
  _draw_hor
  _draw_corner
  _make_cross

  /);

use Graph::Easy::Edge::Cell qw/
  EDGE_SHORT_W EDGE_CROSS EDGE_END_N EDGE_START_E EDGE_HOR EDGE_VER
  EDGE_N_W_S
  /;
use Graph::Easy::Edge;

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

my $edge = Graph::Easy::Edge->new();

my $path = Graph::Easy::Edge::Cell->new( edge => $edge );

is (ref($path), 'Graph::Easy::Edge::Cell');

is ($path->error(), '', 'no error yet');

is ($path->x(), 0, 'x == 0');
is ($path->y(), 0, 'x == 0');
is ($path->label(), '', 'no label');
is (join(",", $path->pos()), "0,0", 'pos = 0,0');
is ($path->width(), undef, 'w = undef');	# no graph => thus no width yet

$path = Graph::Easy::Edge::Cell->new( edge => $edge, type => EDGE_SHORT_W);

is ($path->type(), EDGE_SHORT_W, 'edge to the left');

#############################################################################
# attribute()

$edge->set_attribute( color => 'blue', border => 'none');

$path = Graph::Easy::Edge::Cell->new( type => EDGE_SHORT_W, edge => $edge);

is ($path->attribute('color'), 'blue');

#############################################################################
# as_txt/as_ascii

$path->_correct_size();

is ($path->{w}, 5, 'w == 5');
is ($path->{h}, 3, 'h == 3');

my $ascii = $path->as_ascii(0,0);
$ascii =~ s/^\s+//;
$ascii =~ s/\s+\z//;

is ($ascii, "<--", 'as ascii');

# rendering of seems
$edge = Graph::Easy::Edge->new( style => 'dot-dash' );
$path = Graph::Easy::Edge::Cell->new( type => EDGE_HOR, edge => $edge);
$path->{w} = 10;

$ascii = $path->as_ascii(0,0);
$ascii =~ s/^\s+//;
$ascii =~ s/\s+\z//;

is ($ascii, ".-.-.-.-.-", 'as ascii');

$ascii = $path->as_ascii(1,0);
$ascii =~ s/^\s+//;
$ascii =~ s/\s+\z//;

is ($ascii, "-.-.-.-.-.", 'as ascii');

my $other = Graph::Easy::Edge->new( style => 'dashed' );

$path->{type} = EDGE_HOR;
$path->_make_cross($other);

$ascii = $path->as_ascii();
is ($ascii, "  '       \n.-+-.-.-.-\n  '       ", 'crossing between dot-dash and dashed');

$path->{style} = 'dotted';
$path->{style_ver} = 'solid';

$ascii = $path->as_ascii();
is ($ascii, "  |       \n..!.......\n  |       ", 'crossing between dotted and solid');

#############################################################################
# edge_type()

my $et = 'Graph::Easy::Edge::Cell::edge_type';

{
  no strict 'refs';
  is (&$et( EDGE_HOR() ), 'horizontal', 'EDGE_HOR');
  is (&$et( EDGE_VER() ), 'vertical', 'EDGE_VER');
  is (&$et( EDGE_CROSS() ), 'crossing', 'EDGE_CROSS');
  is (&$et( EDGE_SHORT_W() ), 'horizontal, ending west, starting east', 'EDGE_SHORT_W');
  is (&$et( EDGE_N_W_S() ), 'selfloop, northwards', 'EDGE_N_W_S');
}