PageRenderTime 35ms CodeModel.GetById 1ms app.highlight 29ms RepoModel.GetById 2ms app.codeStats 0ms

/XML-FeedPP-Plugin-DumpJSON/t/47_noutf8_syck.t

http://xml-treepp.googlecode.com/
Unknown | 64 lines | 57 code | 7 blank | 0 comment | 0 complexity | b4f17d64c5e29b22df49c401a3c63478 MD5 | raw file
 1# ----------------------------------------------------------------
 2    use strict;
 3    use Test::More;
 4# ----------------------------------------------------------------
 5{
 6    local $@;
 7    eval { require JSON::Syck; };
 8    plan skip_all => 'JSON::Syck is not loaded.' if $@;
 9    plan tests => 30;
10    use_ok('XML::FeedPP');
11    ok( defined $JSON::Syck::VERSION, "JSON::Syck $JSON::Syck::VERSION" );
12}
13# ----------------------------------------------------------------
14    my $FEED_LIST = [qw(
15        t/example/index-e.rdf  t/example/index-j.rdf
16    )];
17    my $UTF8_FLAG = undef;
18    &test_main();
19# ----------------------------------------------------------------
20sub __decode_json {
21    my $json = shift;
22    1 if defined $JSON::Syck::ImplicitUnicode;          # dummy
23    local $JSON::Syck::ImplicitUnicode = $UTF8_FLAG;
24    JSON::Syck::Load($json);
25}
26# ----------------------------------------------------------------
27sub test_main {
28    my $tppopt = { utf8_flag => $UTF8_FLAG };
29    my $dmpopt = { utf8_flag => $UTF8_FLAG, use_json_pp => 0, use_json_syck => 1 };
30    foreach my $file ( @$FEED_LIST ) {
31        my $feed = XML::FeedPP::RDF->new( $file, %$tppopt );
32        ok( ref $feed, $file );
33
34        my $title1 = $feed->title();
35        like( $title1, qr/kawa.net/i, 'feed channel title is valid' );
36        ok( ! utf8::is_utf8($title1), 'feed channel title is not utf8' );
37
38        my $item = $feed->get_item(0);
39        my $title2 = $item->title();
40        like( $title2, qr/\S/i, 'feed item title is valid' );
41        ok( ! utf8::is_utf8($title2), 'feed item title is not utf8' );
42
43        my $json = $feed->call( DumpJSON => '', %$dmpopt );
44        like( $json, qr/kawa.net/i, 'DumpJSON is valid' );
45        ok( ! utf8::is_utf8($json), 'DumpJSON is not utf8' );
46
47        my $data = __decode_json( $json );
48        ok( ref $data, 'decode json' );
49
50        my $title3 = $data->{'rdf:RDF'}->{channel}->{title};
51        like( $title3, qr/kawa.net/i, 'json channel title is valid' );
52        ok( ! utf8::is_utf8($title3), 'json channel title is not utf8' );
53
54        my $title4 = $data->{'rdf:RDF'}->{item}->[0]->{title};
55        like( $title4, qr/\St/i, 'json item title is valid' );
56        ok( ! utf8::is_utf8($title4), 'json item title is not utf8' );
57
58        is( $title3, $title1, 'same channel title' );
59        is( $title4, $title2, 'same item title' );
60    }
61}
62# ----------------------------------------------------------------
63;1;
64# ----------------------------------------------------------------