File: fb.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 (172 lines) | stat: -rw-r--r-- 4,613 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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/perl -w

# test printing into a framebuffer

use Test::More;
use strict;

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

can_ok ("Graph::Easy::Node", qw/
  as_ascii

  _printfb
  _printfb_ver
  _draw_label
  _framebuffer
  _aligned_label
  /);

#############################################################################
# general framebuffer tests

my $node = Graph::Easy::Node->new();

is (ref($node), 'Graph::Easy::Node');

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

my $fb = $node->_framebuffer(2,3);

is (join ("::", @$fb), "  ::  ::  ", 'framebuffer set up');

$node->_printfb( $fb, 0,0, '+');
is (join ("::", @$fb), "+ ::  ::  ", 'print +');

$node->_printfb( $fb, 1,0, '+');
is (join ("::", @$fb), "++::  ::  ", 'print +');

$node->_printfb( $fb, 1,2, '+');
is (join ("::", @$fb), "++::  :: +", 'print +');

$node->_printfb( $fb, 0,0, '--');
is (join ("::", @$fb), "--::  :: +", 'print --');

$node->_printfb( $fb, 0,1, "''");
is (join ("::", @$fb), "--::'':: +", "print ''");

#############################################################################
# multiline printing

$fb = $node->_framebuffer(2,5);

$node->_printfb( $fb, 0,3, "+", "+");
is (join ("::", @$fb), "  ::  ::  ::+ ::+ ", 'print "+\n+"');

$node->_printfb( $fb, 0,2, "|", "|");
is (join ("::", @$fb), "  ::  ::| ::| ::+ ", 'print "\|\n\|"');

$fb = $node->_framebuffer(4,5);
is (join ("::", @$fb), "    ::    ::    ::    ::    ", 'new fb set up');

$node->_printfb( $fb, 1,1, "01", "234");

is (join ("::", @$fb), "    :: 01 :: 234::    ::    ", 'new fb set up');

#############################################################################
# _draw_border() tests

$fb = $node->_framebuffer(12,6);

$node->{w} = 12;
$node->{h} = 6;

$node->_draw_border( $fb, 'solid', 'solid', 'solid', 'solid');

is (join ("::", @$fb),
  '+----------+::|          |::|          |::|          |::|          |::+----------+',
  'solid border');


$fb = $node->_framebuffer(8,4);

$node->{w} = 8;
$node->{h} = 4;

my @expect = (
  '        \n        \n        \n        ',
  '+------+\n|      |\n|      |\n+------+',
  '........\n:      :\n:      :\n:......:',
  '+ - - -+\n\'      \'\n\'      \'\n+ - - -+',
  '+-.-.-.+\n!      !\n!      !\n+-.-.-.+',
  '+.-..-.+\n|      |\n:      :\n+.-..-.+',
  '########\n#      #\n#      #\n########',
  '#======#\nH      H\nH      H\n#======#',
  '# = = =#\n"      "\n"      "\n# = = =#',
  '+~~~~~~+\n{      {\n}      }\n+~~~~~~+',
  );

my $i = 0;
for my $style (qw/ none solid dotted dashed dot-dash dot-dot-dash bold double double-dash wave/)
  {
  $node->_draw_border( $fb, $style, $style, $style, $style);
  is (join ('\n', @$fb),
    $expect[$i],
    "$style border");
  $i++;
  }

#############################################################################
# _draw_border() tests with different styles

$fb = $node->_framebuffer(8,4);

$node->{w} = 8;
$node->{h} = 4;

$node->_draw_border( $fb, 'solid', 'dotted', 'solid', 'solid');

is (join ("::", @$fb),
  '+------+::|      |::|      |:::......:',
  'solid border, except bottom, which is dotted');

#############################################################################
# label alignments

$node->set_attribute('label', 'left\r right\l left\c center\n normal');

my ($lines,$aligns) = $node->_aligned_label();

is_deeply ( $lines, [ 'left', 'right', 'left', 'center', 'normal' ],
           'lines are ok');
is_deeply ( $aligns, [ 'c', 'r', 'l', 'c', 'c', ], 'aligns is ok');

# empty lines at the are thrown away
$node->set_attribute('label', 'left\r right\l left\c center\n normal\c');

($lines,$aligns) = $node->_aligned_label();

is_deeply ( $lines, [ 'left', 'right', 'left', 'center', 'normal' ],
           'lines are ok');
is_deeply ( $aligns, [ 'c', 'r', 'l', 'c', 'c', ], 'aligns is ok');

# start with alignment
$node->set_attribute('label', '\rleft\r right\l left\c center\n normal\c');

($lines,$aligns) = $node->_aligned_label();

is_deeply ( $lines, [ '', 'left', 'right', 'left', 'center', 'normal' ],
           'lines are ok');
is_deeply ( $aligns, [ 'c', 'r', 'r', 'l', 'c', 'c', ], 'aligns is ok');

# start with alignment
$node->set_attribute('label', '\r\l\rleft\r right\l left\c center\n normal\c');

($lines,$aligns) = $node->_aligned_label();

is_deeply ( $lines, [ '','','','left', 'right', 'left', 'center', 'normal' ],
           'lines are ok');
is_deeply ( $aligns, [ 'c','r','l','r', 'r', 'l', 'c', 'c', ], 'aligns is ok');