File: simple.t

package info (click to toggle)
libxml-struct-perl 0.27-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 220 kB
  • sloc: perl: 600; xml: 17; sh: 6; makefile: 2
file content (70 lines) | stat: -rw-r--r-- 1,864 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
use strict;
use Test::More;
use XML::Struct::Simple;

my $micro = [ 
    root => { xmlns => 'http://example.org/' }, 
    [ '!', [ x => {}, [42] ] ]
];

sub convert {
    XML::Struct::Simple->new(@_)->transform($micro)
}

is_deeply convert( root => 'record' ),
    { record => { xmlns => 'http://example.org/', x => 42 } },
    'synopsis';

is_deeply convert(),
    { xmlns => 'http://example.org/', x => 42 },
    'root disabled by default';

is_deeply convert( root => 1 ),
    { root => { xmlns => 'http://example.org/', x => 42 } },
    'root enabled';

is_deeply convert( depth => 0 ), 
    $micro, 
    'depth 0';

is_deeply explain convert( depth => 1 ),
    { xmlns => 'http://example.org/', x => [ [ x => {}, [42] ] ] },
    'depth 1';

is_deeply convert( depth => 1, root => 'r' ),
    { r => { xmlns => 'http://example.org/', x => [ [ x => {}, [42] ] ] } },
    'depth 1, root';

foreach ('remove','0') {
    is_deeply convert( root => 1, attributes => $_ ),
        { root => { x => 42 } },
        'remove attributes';
}

is_deeply(
    XML::Struct::Simple->new->transform(
    [ root => [ ['text'] ] ] ),
    { text => {} }, 'empty tag');

# this was a bug until 0.25
is_deeply(
    XML::Struct::Simple->new->transform(
    [ root => [ ['text', {} ] ] ] ),
    { text => {} }, 'empty tag, no attributes');

is_deeply(
    XML::Struct::Simple->new( root => 1 )->transform( [ 'root' ] ),
    { root => {} }, 'empty <root/>');

is_deeply( XML::Struct::Simple->new->transform( [ root => ['text'] ] ),
    { root => 'text' }, 'special case <root>text</root>');

is_deeply( XML::Struct::Simple->new->transform(
    [ root => { x => 1 }, [] ] ),
    { x => 1 }, 'attributes only');

is_deeply( XML::Struct::Simple->new->transform(
    [ root => { x => 1 }, ['text'] ] ),
    { x => 1, content => 'text' }, 'mix attributes and text content');

done_testing;