### ----------------------------------------------------
### -- Rakuast::RakuDoc::Render
### -- Licenses: Artistic-2.0
### -- Authors: Richard Hainsworth
### -- File: xt/140-custom-template.rakutest
### ----------------------------------------------------
use v6.d;
use Test;
use RakuDoc::Render;
use RakuDoc::Templates;

plan 7;

my $ast;
my $rv;
my RakuDoc::Processor $rdp .= new(:test);

$ast = Q:to/QAST/.AST;
    =begin rakudoc
    =begin MyCustomBlock :an<option> :another<one>
    Some thingB<to be said>inside letters.
    =end MyCustomBlock
    =end rakudoc
    QAST
$rv = $rdp.render( $ast, :pre-finalised );
is $rv.warnings.elems, 1, 'warning generated';
like $rv.warnings[0], / 'No template exists for custom block ｢MyCustomBlock' /, 'got undefined warning';
like $rv.body, /
    '<unknown>' .+ 'MyCustomBlock' .+
    'Some thing' .+ '</unknown>'
/, 'rendered verbatim with unknown';

is $rv.toc.elems, 1, 'ToC includes one for custom';
is $rv.toc[0]<caption>, 'MyCustomBlock', 'caption is blockname';

$rdp.add-template: ( MyCustomBlock => -> %prm, $ {
    express-params( %prm, 'MyCustomBlock')
} );
$ast = Q:to/QAST/.AST;
    =begin rakudoc
    =begin MyCustomBlock :an<option> :another<one>
    Some thingB<to be said>inside letters.
    =end MyCustomBlock
    =end rakudoc
    QAST
$rv = $rdp.render( $ast, :pre-finalised );
is $rv.warnings.elems, 0, 'no warning';
like $rv.body, /
    '<MyCustomBlock>' .+
    'caption' .+? 'MyCustomBlock' .+
    'content' .+ 'Some thing<markup-B>' .+ 'to be said' .+ '/markup-B' .+ 'inside' .+
    'raw' .+ 'Some thingB<to be said>inside' .+
    '</MyCustomBlock>'
/, 'treated according to template';

done-testing;


