File: 90ex_xml.t

package info (click to toggle)
libparser-mgc-perl 0.23-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 460 kB
  • sloc: perl: 1,881; makefile: 2; sh: 1
file content (43 lines) | stat: -rw-r--r-- 1,046 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
#!/usr/bin/perl

use v5.14;
use warnings;

use Test2::V0;

use lib ".";
require "examples/parse-xml.pl";

my $parser = XmlParser->new;

sub plain { bless [ @_ ], "XmlParser::Node::Plain" }
sub elem  { bless [ @_ ], "XmlParser::Node::Element" }

sub test
{
   my ( $str, $expect, $name ) = @_;

   is( $parser->from_string( $str ), $expect, $name );
}

test q[<xml>Hello world</xml>],
     [ plain("Hello world") ],
     "Plaintext";

test q[<xml><message>Hello world</message></xml>],
     [ elem(message => {}, plain("Hello world")) ],
     "Single node";

test q[<xml><first>Hello</first><second>world</second></xml>],
     [ elem(first => {}, plain("Hello")), elem(second => {}, plain("world")) ],
     "Two nodes";

test q[<xml><first>Hello</first> <second>world</second></xml>],
     [ elem(first => {}, plain("Hello")), plain(" "), elem(second => {}, plain("world")) ],
     "Two nodes with whitespace";

test q[<xml><node a1="v1" a2="v2" /></xml>],
     [ elem(node => { a1 => "v1", a2 => "v2" }) ],
     "Node with attrs";

done_testing;