File: roundtrip-attrs.t

package info (click to toggle)
libdata-stag-perl 0.13-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,428 kB
  • ctags: 727
  • sloc: perl: 6,394; lisp: 141; xml: 116; ansic: 55; makefile: 17; sh: 2
file content (54 lines) | stat: -rw-r--r-- 1,284 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
use lib 't';

BEGIN {
    # to handle systems with no installed Test module
    # we include the t dir (where a copy of Test.pm is located)
    # as a fallback
    eval { require Test; };
    use Test;
    plan tests => 5;
}
use Data::Stag qw(:all);

eval {
    require "XML/Parser/PerlSAX.pm";
};
if ($@) {
    for (1..5) {
        skip("XML::Parser::PerlSAX not installed",1);
    }
    exit 0;
}

my $fn = shift @ARGV || "t/data/attrs.xml";
my $sxpr = trip($fn,'sxpr');
my $xml = trip($sxpr, 'xml');
my $itext = trip($xml, 'itext');
$xml = trip($itext, 'xml');
my $doc = Data::Stag->parse($xml);
my $href = $doc->find('address/a/@/href');
ok($href eq 'mailto:cjm@fruitfly.org');
my $name = $doc->find('address/a/.');
ok($name eq 'chris mungall');
my $name2 = $doc->findval('address/a');
ok($name eq $name);
$doc->findval('address/a', 'fred');
my $address = $doc->find_address;
print $address->sxpr;
my $name3 = $doc->findval('address/a');
ok($name3 eq 'fred');
$doc->makeattrsnodes;
print $doc->xml;
my $href2 = $doc->find('address/a/href');
print "$href2\n";
ok($href2 eq $href);


sub trip {
    my ($in, $fmt) = @_;
    my $out = "$in.$fmt";
    my $w = Data::Stag->getformathandler($fmt);
    $w->file($out);
    Data::Stag->parse(-file=>$fn, -handler=>$w);
    return $out;
}