use utf8;
use strict;
use warnings;
use Path::Class;
use Test::More 'no_plan';
use Test::Differences;
use Encode;
use WebCoso::Resource;
BEGIN {use_ok('WebCoso::Step::ReST::ToXml')}
my $step=WebCoso::Step::ReST::ToXml->new();
sub make_res {
my $resource=WebCoso::Resource->new();
$resource->set_property({filename=>'/tmp/mydoc.rest.txt'},datastream=>undef);
if (@_==1) {
$resource->set_property(rstdoc=>$_[0]);
}
else {
my %rst_doc=@_;
while (my ($lang,$str)=each %rst_doc) {
$resource->set_property(
{language=>$lang},
rstdoc=>$str
);
}
}
return $resource;
}
my $resource=make_res(<<'END_REST');
Documento
=========
paragrafo àè
END_REST
$step->process($resource,'gen');
ok(!defined $resource->get_property('xmldom'),'no action on second pass');
$step->process($resource,'meta');
my $dom=$resource->get_property('xmldom');
isa_ok($dom,'XML::LibXML::Document','parsed ok on first pass');
is($dom->findvalue('/document/@source'),
'/tmp/mydoc.rest.txt',
'source path');
is($dom->findvalue('/document/title'),
'Documento',
'title');
is($dom->findvalue('count(/document/paragraph)'),
1,
'1 paragraph');
is($dom->findvalue('/document/paragraph'),
'paragrafo àè',
'paragraph content (unicode)');
$resource=make_res(it=><<'END_REST_IT',en=><<'END_REST_EN');
Documento
=========
paragrafo
END_REST_IT
Document