File: 02-content.t

package info (click to toggle)
libxml-atom-perl 0.23-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 420 kB
  • ctags: 264
  • sloc: perl: 3,357; xml: 663; makefile: 51
file content (99 lines) | stat: -rw-r--r-- 2,703 bytes parent folder | download
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
# $Id$

use strict;

use Test::More tests => 32;
use XML::Atom::Content;

my $content;

$content = XML::Atom::Content->new;
isa_ok $content, 'XML::Atom::Content';
ok $content->elem;
$content->type('image/jpeg');
is $content->type, 'image/jpeg';
$content->type('application/gzip');
is $content->type, 'application/gzip';

$content = XML::Atom::Content->new('This is a test.');
is $content->body, 'This is a test.';
is $content->mode, 'xml';

$content = XML::Atom::Content->new(Body => 'This is a test.');
is $content->body, 'This is a test.';
is $content->mode, 'xml';

$content = XML::Atom::Content->new(Body => 'This is a test.', Type => 'foo/bar');
is $content->body, 'This is a test.';
is $content->mode, 'xml';
is $content->type, 'foo/bar';

$content = XML::Atom::Content->new;
$content->body('This is a test.');
is $content->body, 'This is a test.';
is $content->mode, 'xml';
$content->type('foo/bar');
is $content->type, 'foo/bar';

$content = XML::Atom::Content->new;
$content->body('<p>This is a test with XHTML.</p>');
is $content->body, '<p>This is a test with XHTML.</p>';
is $content->mode, 'xml';

$content = XML::Atom::Content->new;
$content->body('<p>This is a test with invalid XHTML.');
is $content->body, '<p>This is a test with invalid XHTML.';
is $content->mode, 'escaped';

$content = XML::Atom::Content->new;
$content->body("This is a test that should use base64\x7f.");
$content->type('text/plain');
is $content->mode, 'base64';
is $content->body, "This is a test that should use base64\x7f.";

$content = XML::Atom::Content->new;
$content->body("My name is \xe5\xae\xae\xe5\xb7\x9d.");
is $content->mode, 'xml';
is $content->body, "My name is \xe5\xae\xae\xe5\xb7\x9d.";

$content = XML::Atom::Content->new;
$content->type('text/plain');
eval { $content->body("Non-printable: " . chr(578)) };
is $content->mode, 'base64';
is $content->body, un_utf8("Non-printable: " . chr(578));

# 1.0 with xhtml
$content = XML::Atom::Content->new(Version => 1.0);
$content->body("<div>foo bar</div>");

is $content->type, 'xhtml';
is $content->body, "<div>foo bar</div>";

# 1.0 with html
$content = XML::Atom::Content->new(Version => 1.0);
$content->body("<p>foo bar");

is $content->type, 'html';
is $content->body, "<p>foo bar";

# 1.0 as text
$content = XML::Atom::Content->new(Version => 1.0);
$content->body("foo bar");
$content->type('text');

is $content->type, 'text';
is $content->body, "foo bar";

# 1.0 as binary
$content = XML::Atom::Content->new(Version => 1.0);
$content->type('image/jpeg');
$content->body("\xff\xde\xde\xde");

is $content->type, 'image/jpeg';
is $content->body, "\xff\xde\xde\xde";

sub un_utf8 {
    my $foo = shift;
    Encode::_utf8_off($foo);
    $foo;
}