### ----------------------------------------------------
### -- Raku::Pod::Render
### -- Licenses: Artistic-2.0
### -- Authors: Richard Hainsworth
### -- File: xt/901-html/45-headings.rakutest
### ----------------------------------------------------
use v6.*;
use Test;

use Pod::To::HTML2;
my $def-dir = 'xt/test-def'.IO;
my $tar-dir = 'xt/tar-dir'.IO;

bail-out "Requires $def-dir and $tar-dir" unless ($def-dir ~~ :e and $tar-dir ~~ :e);
chdir ~$tar-dir;

my $processor = Pod::To::HTML2.new(:$def-dir, :plugins() );
my $rv;
my $pn = 0;

plan 8;

=begin pod
=TITLE This is a title

Some text

=end pod

$rv = $processor.render-block( $=pod[$pn++] );

unlike $rv,
        /
        'class="title"' .+? 'This is a title'
        /,
        'default html templates do not include title or subtitle with body';

$rv = $processor.source-wrap;
like $rv,
        /
        '<header>'
        .+  'class="title"' .+? 'This is a title'
        .* '</header>'
        .+ '<p>Some text</p>'
        /,
        'pod with title rendered, target rewritten for source-wrap';

=begin pod
=TITLE A Second Pod File

=SUBTITLE This is subtitled for testing

Some more text

=head2 This is a heading

Some text after a heading

=head1 An upper heading after a second level one

text

=head2 A lower heading within upper one

=end pod

$processor.emit-and-renew-processed-state;
$rv = $processor.render-block( $=pod[$pn++] );
unlike $rv, /
'<div class="subtitle">'
/, 'no subtitle with default templates in block';

$rv = $processor.source-wrap;

like $rv, /
'<div class="subtitle">'
\s* '<p>This is subtitled for testing</p>'
.+ '<p>Some more text</p>'
\s* '<h2 id="This_is_a_heading"><a href="#A_Second_Pod_File" class="u" title="go to top of document">This is a heading</a></h2>'
\s* '<p>Some text after a heading</p>'
/, 'subtitle rendered in ';

like $rv,
        /
        'id="_TOC"'
        /
        , 'rendered TOC';

$processor.no-toc = True;
$rv = $processor.render-toc;
unlike $rv,
        /
        'id="_TOC"'
        /, 'TOC not rendered';

=begin pod

=head1 Heading 1

=head2 Heading 1.1

=head2 Heading 1.2

=head1 Heading 2

=head2 Heading 2.1

=head2 Heading 2.2

=head2 L<(Exception) method message|/routine/message#class_Exception>

=head3 Heading 2.2.1

=head3 X<Heading> 2.2.2

Note that only the word Heading is indexed

=head1 Heading C<3>

=end pod

$processor.emit-and-renew-processed-state;
$processor.process-pod( $=pod[$pn++] );
$rv = $processor.source-wrap;

like $rv, /'h2 id="Heading_2.2"' .+ '>Heading 2.2'/, 'Heading 2.2 has expected id';

like $rv, /'class="glossary-entry">Heading' .+ '2.2.2</a>' / , 'Heading 2.2.2 is in glossary as well';


