summaryrefslogtreecommitdiff
path: root/t/01-basic.t
blob: 94ba201e1cc614b809189f93f1a4f193ba67b10b (plain)
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
use Test::More tests => 10;
use strict;
use warnings;
use Text::Restructured;
use Text::Restructured::Writer::LibXML;
use XML::LibXML::XPathContext;
 
my $input=<<'EOF';
======
 Test
======
:Author: dakkar
 
paragrafo
 
link_
 
.. _link: /gino/pino/
 
mathml: :mathml:`x^2`
 
.. mathml::
 
  (x^2)/(y^2)
 
pre::
 
  gino  pino
 rino
 
normale
 
EOF
 
my $opts={
    => {
        generator => 0,
        'source-link' => 0,
        'time' => 0,
    },
};
my $parser=Text::Restructured->new($opts,'gino');
my $dudom=$parser->Parse($input,'--inline--');
my $xdoc=Text::Restructured::Writer::LibXML->new->ProcessDOM($dudom);
 
my $ctx=XML::LibXML::XPathContext->new($xdoc);
$ctx->registerNs('m','http://www.w3.org/1998/Math/MathML');
sub xis {
    my ($expr,$val,$comment)=@_;
    is $ctx->findvalue($expr),
       $val,
       $comment||'';
}
 
=begin comment
 
<document source="--inline--" names="test" ids="test" title="Test"><title>Test
</title><docinfo><author>dakkar
</author></docinfo><paragraph>paragrafo
</paragraph><paragraph><reference refuri="/gino/pino/" name="link">link</reference></paragraph><target refuri="/gino/pino/" names="link" ids="link"/><paragraph>mathml: <math xmlns="http://www.w3.org/1998/Math/MathML" title="x^2"><mstyle><msup><mi>x</mi><mn>2</mn></msup></mstyle></math></paragraph><paragraph><math xmlns="http://www.w3.org/1998/Math/MathML" title="  (x^2)/(y^2)"><mstyle displaystyle="true"><mfrac><mrow><msup><mi>x</mi><mn>2</mn></msup></mrow><mrow><msup><mi>y</mi><mn>2</mn></msup></mrow></mfrac></mstyle></math></paragraph><paragraph>pre:
</paragraph><literal_block xml:space="preserve"> gino  pino
rino
</literal_block><paragraph>normale
</paragraph></document>
 
=end comment
 
=cut
 
xis '/document/@source','--inline--','Source name';
xis '/document/@title','Test','Title';
xis '/document/docinfo/author',"dakkar\n",'Author';
xis 'count(/document/paragraph)',6,'Paragraphs';
xis '/document/paragraph[1]',"paragrafo\n",'para 1';
xis '/document/paragraph[2]/reference/@refuri','/gino/pino/','Ref';
xis '/document/paragraph[3]/m:math','x2','MathML 1';
xis '/document/paragraph[4]/m:math','x2y2','MathML 2';
xis 'name(/document/paragraph[5]/following-sibling::*[1])','literal_block','Literal';
xis '/document/literal_block'," gino  pino\nrino\n",'Literal content';