### ----------------------------------------------------
### -- Raku::Pod::Render
### -- Licenses: Artistic-2.0
### -- Authors: Richard Hainsworth
### -- File: xt/10-gist-debug.rakutest
### ----------------------------------------------------
use Test;
use Test::Output;

use ProcessedPod;
# A helper sub for RakuClosureTemplates
sub gen-closure-template (Str $tag) is export {
    my $start = '<' ~ $tag ~ '>';
    my $end = '</' ~ $tag ~ '>';
    return sub (%prm, %tml? --> Str) {
        $start ~ (%prm<contents> // '') ~ $end;
    }
}
my ProcessedPod $p .= new;

plan 5;

like $p.pod-file.gist,
        /
        'renderedtime => Str=｢｣'
        .+ 'templates-used => No templates used'
        /, 'blank PodFile gist';
use RenderPod::Templating;
my @templates = SetupTemplates.new.required;

my %templates  = @templates Z=> @templates.map( { gen-closure-template( $_ ) });
%templates<escaped> = sub ($s) {
    if $s and $s ne ''
    { $s.trans(qw｢ <    >    &     " ｣ => qw｢ &lt; &gt; &amp; &quot; ｣) }
    else { '' }
};
$p .= new;
$p.templates( %templates );

=begin pod

my $d = 'one two three';

This is C<format-code C>.

=head1 A title

=defn the
definite article

=end pod
lives-ok { $p.process-pod( $=pod[0] )}, 'processing works';
$p.debug = True;
stderr-like { $p.process-pod($=pod[0]) },
    /
    'Node is Pod::Block::Named with name ｢pod｣'
    .+
    'Node is Pod::Block::Para'
    .+
    'Node is Pod::FormattingCode with type ｢C｣'
    .+
    'Completion with template ｢format-c｣'
    /, 'debugging of handle methods and completion works';
$p.debug = False;
$p.source-wrap;

my $pf = $p.emit-and-renew-processed-state;
like $pf.gist,
    /
        ':target("A_title"),'
        \s+ ':text("A title")'
    /, 'reasonable PodFile gist';
$pf.gist ~~ / \( $<rem> = (\d+) ' more chars' /;
my $rem = +$<rem>;
$pf.gist(:170output) ~~ / \( $<rem> = (\d+) ' more chars' /;
is $<rem>, $rem + 5, 'change number of output chars';

done-testing;


