File: xml2config.t

package info (click to toggle)
libxml-stream-perl 1.24-4%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 952 kB
  • sloc: perl: 4,821; xml: 64; makefile: 4
file content (75 lines) | stat: -rw-r--r-- 1,391 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use strict;
use warnings;

use Test::More tests=>9;
use_ok 'XML::Stream', qw( Tree Node );

my @tests;
$tests[4] = 1;
$tests[8] = 1;

my $parser_tree = XML::Stream::Parser->new(style=>"tree");
my $tree = $parser_tree->parsefile("t/test.xml");

my %config = %{&XML::Stream::XML2Config($tree)};

if (exists($config{blah})) {
  my @keys = keys(%{$config{blah}});
  if ($#keys == -1) {
    $tests[2] = 1;
  }
}

if (exists($config{foo}->{bar})) {
  my @keys = keys(%{$config{foo}->{bar}});
  if ($#keys == -1) {
    $tests[3] = 1;
  }
}

if (exists($config{comment_test})) {
  $tests[4] = 0;
}


if (exists($config{last}->{test1}->{test2}->{test3})) {
  if ($config{last}->{test1}->{test2}->{test3} eq "This is a test.") {
    $tests[5] = 1;
  }
}


my $parser_node = XML::Stream::Parser->new(style=>"node");
my $node = $parser_node->parsefile("t/test.xml");

%config = %{&XML::Stream::XML2Config($node)};

if (exists($config{blah})) {
  my @keys = keys(%{$config{blah}});
  if ($#keys == -1) {
    $tests[6] = 1;
  }
}

if (exists($config{foo}->{bar})) {
  my @keys = keys(%{$config{foo}->{bar}});
  if ($#keys == -1) {
    $tests[7] = 1;
  }
}

if (exists($config{comment_test})) {
  $tests[8] = 0;
}

if (exists($config{last}->{test1}->{test2}->{test3})) {
  if ($config{last}->{test1}->{test2}->{test3} eq "This is a test.") {
    $tests[9] = 1;
  }
}


foreach (2..9) {
  ok $tests[$_];
}