-
Notifications
You must be signed in to change notification settings - Fork 38
/
anon.t
116 lines (85 loc) · 2.98 KB
/
anon.t
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
#!/usr/bin/perl -w
# test anonymous nodes
use Test::More;
use strict;
BEGIN
{
plan tests => 31;
chdir 't' if -d 't';
use lib '../lib';
use_ok ("Graph::Easy::Node::Anon") or die($@);
use_ok ("Graph::Easy") or die($@);
use_ok ("Graph::Easy::As_txt") or die($@);
require_ok ("Graph::Easy::As_ascii") or die($@);
};
can_ok ("Graph::Easy::Node::Anon", qw/
new
as_txt as_html
error
class
name
successors
predecessors
width
height
pos
x
y
class
del_attribute
set_attribute
set_attributes
attribute
attributes_as_txt
as_pure_txt
group add_to_group
/);
#############################################################################
my $node = Graph::Easy::Node::Anon->new();
is (ref($node), 'Graph::Easy::Node::Anon');
is ($node->error(), '', 'no error yet');
is ($node->x(), undef, 'x == undef');
is ($node->y(), undef, 'y == undef');
is ($node->width(), undef, 'w == undef');
is ($node->height(), undef, 'h == undef');
is ($node->label(), ' ', 'label');
is ($node->name(), '#0', 'name');
is ($node->title(), '', 'no title per default');
is (join(",", $node->pos()), "0,0", 'pos = 0,0');
is ($node->{graph}, undef, 'no graph');
is (scalar $node->successors(), undef, 'no outgoing links');
is (scalar $node->predecessors(), undef, 'no incoming links');
is ($node->{graph}, undef, 'successors/predecssors leave graph alone');
$node->_correct_size();
is ($node->width(), 3, 'w == 3');
is ($node->height(), 3, 'h == 3');
#############################################################################
# as_txt/as_html
my $graph = Graph::Easy->new();
$graph->add_node($node);
is ($node->as_txt(), '[ ]', 'anon as_txt');
is ($node->as_html(), " <td colspan=4 rowspan=4 class='node_anon'></td>\n",
'as_html');
is ($node->as_ascii(), " \n \n ", 'anon as_ascii');
require Graph::Easy::As_graphviz;
is ($node->as_graphviz_txt(), '"#0"', 'anon as_graphviz');
#############################################################################
# anon node as_graphviz
my $grviz = $graph->as_graphviz();
my $match = quotemeta('"#0" [ color="#ffffff", label=" ", style=filled ]');
like ($grviz, qr/$match/, 'anon node');
#############################################################################
# with border attribute
$node->set_attribute('border-style', 'dotted');
is ($node->as_txt(), '[ ] { border: dotted; }', 'anon as_txt');
is ($node->as_html(), " <td colspan=4 rowspan=4 class='node_anon' style=\"border: dotted 1px #000000\"></td>\n",
'as_html');
$grviz = $graph->as_graphviz();
$match = quotemeta('"#0" [ label=" ", style="filled,dotted" ]');
like ($grviz, qr/$match/, 'anon node as graphviz');
#############################################################################
# with fill attribute
$node->set_attribute('fill', 'orange');
is ($node->as_txt(), '[ ] { fill: orange; border: dotted; }', 'anon as_txt');
is ($node->as_html(), " <td colspan=4 rowspan=4 class='node_anon' style=\"background: #ffa500; border: dotted 1px #000000\"></td>\n",
'as_html');