File: class.t

package info (click to toggle)
libgraph-easy-perl 0.71-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,284 kB
  • sloc: perl: 24,909; makefile: 2
file content (80 lines) | stat: -rw-r--r-- 1,948 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl -w

# Test class selectors

use Test::More;
use strict;

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

can_ok ("Graph::Easy", qw/
  _check_class
  /);

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

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

is (ref($graph), 'Graph::Easy');

$graph->add_edge( 'A', 'B' );

for my $class ('node', 'edge', 'graph', 'group', 
	       'node.foo', 'edge.foo', 'group.foo')
  {
  _is ($class, $graph->_check_class($class));
  }

_is ('edge.foo,group.foo,node.foo', $graph->_check_class('.foo'));
_is ('edge.b,group.b,node.b', $graph->_check_class('.b'));

#############################################################################
# lists of class selectors

_is ('edge.f,group.f,node.f,edge.b,group.b,node.b', 
  $graph->_check_class('.f, .b'));

_is ('edge,group,node', $graph->_check_class('edge, group, node'));
_is ('edge,group,node', $graph->_check_class('edge,group, node'));
_is ('edge,group,node', $graph->_check_class('edge ,  group , node'));
_is ('edge,group,node', $graph->_check_class('edge, group,node'));
_is ('edge,group,node', $graph->_check_class('edge,group,node'));

_is ('edge.red,group.red,node.red,edge.green,group.green,node.green,group',
  $graph->_check_class('.red, .green, group'));

#############################################################################
# invalid classes

_is (\'.', $graph->_check_class('.'));
_is (\'node.', $graph->_check_class('node.'));
_is (\'foo', $graph->_check_class('foo'));

_is (\'.foo, bar', $graph->_check_class('.foo, bar'));

# all tests done

1;

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

sub _is
  {
  my ($expect, @results) = @_;

  if (ref($expect))
    {
    is (scalar @results, 0, "invalid selector $$expect");
    }
  else
    {
    is (join(",", @results), $expect, $expect);
    }
  }