File: parse_edge.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 (160 lines) | stat: -rw-r--r-- 2,708 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
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
#!/usr/bin/perl -w

use Test::More;
use strict;

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

can_ok ("Graph::Easy::Parser", qw/
  new
  from_text
  from_file
  reset
  error
  _match_edge
  _match_node
  _match_attributes
  _match_optional_attributes
  /);

#############################################################################
# create parser object

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

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

my $line = 0;
my $qr_edge = $parser->_match_edge();
my $qr_node = $parser->_match_node();
my $qr_oatr = $parser->_match_optional_attributes();

#my $r = '-- Label --> [ AA ]';
#$r = '--> [ AB ]';
#$r = '<--> [ AB ]';
#$r = '<- Label -> [ AB ]';
#$r = '--> { color: red; } [ AB ]';

foreach my $l (<DATA>)
  {
  chomp ($l);
  next if $l =~ /^\s*\z/;			# skip empty ones
  next if $l =~ /^#/;				# skip comments

  my ($in,$type,$style,$label) = split /\|/, $l;

  if ($type < 0)
    {
    if (!unlike ($in, qr/^$qr_edge\z/, "$in"))
      {
      $in =~ /^$qr_edge/;
      diag ("# '$1' '$2' '$3' '$4' '$5' '$6'\n");
      }
    next;
    }

  # XXX TODO check edge style and type:
  # 0 - undirected 
  # 2 - right 
  # 3 - left and right
 
  like ($in, qr/^$qr_edge\z/, "$in");

#  $in =~ /^$qr_edge\z/;
#  diag("# '$1' '$2' '$3' '$4' '$5' '$6' '$7' '$8' '$9'\n");
  }

__DATA__
# edges without arrows
--|0|--
==|0|==
..|0|..
- |-1| -
- - |0| -
---|0|--
===|0|==
...|0|..
- - |0| -
----|0|--
====|0|==
....|0|..
<->|3|--
<=>|3|==
<.>|3|..
<- >|3| -
<-->|3|--
<==>|3|==
<..>|3|..
<- - >|3| -
<--->|3|--
<===>|3|==
<...>|3|..
<- - >|3| -
->|2|--
=>|2|==
.>|2|..
- >|2| -
-->|2|--
==>|2|==
..>|2|..
~~>|2|~~
= >|2|= 
- - >|2| -
--->|2|--
===>|2|==
...>|2|..
- - >|2| -
# with labels
<- ->|3| -
- Landstrasse --|-1|--
== Autobahn ==>|2|==
.. Im Bau ..>|2|..
-  Tunnel - >|2| -
= label =>|2|==|label
<-- Landstrasse -->|3|--
<== Autobahn ==>|3|==
<.. Im Bau ..>|3|..
<-  Tunnel - >|3| -
<- Tunnel -->|-1|
<-- Tunnel -->|3|
<-- Landstrasse -->|3|--
<~~ Landstrasse ~~>|3|~~
<== Landstrasse ==>|3|==
<.- Landstrasse .->|3|.-
<..- Landstrasse ..->|3|..-
-- Landstrasse -->|2|--
~~ Landstrasse ~~>|2|~~
== Landstrasse ==>|2|==
.- Landstrasse .->|2|.-
..- Landstrasse ..->|2|..-
##################
# Failures
# no left-only edges allowed
<-|-1|--
<=|-1|==
<.|-1|..
<- |-1| -
<--|-1|--
<==|-1|==
<..|-1|..
<- -|-1| - 
<-- Landstrasse -|-1|
<== Autobahn =|-1|
<.. Im Bau .|-1|
<- - Tunnel -|-1|
<--|-1|
# mismatching pattern
<-- Landstrasse ==>|-1|
# double "<<" or ">>" are not good
<<--|-1|
<<--|-1|
<<-->>|-1|
<<. -.->>|-1|
< - Tunnel - >|-1|