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

http://xml-treepp.googlecode.com/ · Raku · 64 lines · 50 code · 7 blank · 7 comment · 2 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. # ----------------------------------------------------------------
  20. sub __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. # ----------------------------------------------------------------
  27. sub 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. my $title1 = $feed->title();
  34. like( $title1, qr/kawa.net/i, 'feed channel title is valid' );
  35. ok( ! utf8::is_utf8($title1), 'feed channel title is not utf8' );
  36. my $item = $feed->get_item(0);
  37. my $title2 = $item->title();
  38. like( $title2, qr/\S/i, 'feed item title is valid' );
  39. ok( ! utf8::is_utf8($title2), 'feed item title is not utf8' );
  40. my $json = $feed->call( DumpJSON => '', %$dmpopt );
  41. like( $json, qr/kawa.net/i, 'DumpJSON is valid' );
  42. ok( ! utf8::is_utf8($json), 'DumpJSON is not utf8' );
  43. my $data = __decode_json( $json );
  44. ok( ref $data, 'decode json' );
  45. my $title3 = $data->{'rdf:RDF'}->{channel}->{title};
  46. like( $title3, qr/kawa.net/i, 'json channel title is valid' );
  47. ok( ! utf8::is_utf8($title3), 'json channel title is not utf8' );
  48. my $title4 = $data->{'rdf:RDF'}->{item}->[0]->{title};
  49. like( $title4, qr/\St/i, 'json item title is valid' );
  50. ok( ! utf8::is_utf8($title4), 'json item title is not utf8' );
  51. is( $title3, $title1, 'same channel title' );
  52. is( $title4, $title2, 'same item title' );
  53. }
  54. }
  55. # ----------------------------------------------------------------
  56. ;1;
  57. # ----------------------------------------------------------------