### ----------------------------------------------------
### -- Raku::Pod::Render
### -- Licenses: Artistic-2.0
### -- Authors: Richard Hainsworth
### -- File: xt/40-templates-file.rakutest
### ----------------------------------------------------
use v6.*;
use Test;

use ProcessedPod;

plan 3;

my ProcessedPod $processor;

my $tmpl-fn = 'newtemplates.raku';
my $path = 'xt';
"$path/$tmpl-fn".IO.unlink if "$path/$tmpl-fn".IO ~~ :e & :f;

use RenderPod::Templating;
my @templates = SetupTemplates.new.required;


my %templates  = @templates Z=> ( "\<$_>\{\{\{ contents }}}\</$_>" for @templates );
%templates<format-b> = '<new-form-b>{{ contents }}</new-form-b>';
$processor .= new(:name<Testing> );

"$path/$tmpl-fn".IO.spurt(%templates.raku.substr(0, *-3 ) );

dies-ok { $processor.templates( $tmpl-fn,:$path ) }, 'bad template is trapped' ;

"$path/$tmpl-fn".IO.spurt(%templates.raku );

lives-ok { $processor.templates($tmpl-fn, :$path ) }, 'accepts a template file';

like $processor.rendition('format-b', %(:contents('Hello world'))),
        / '<new-form-b>' 'Hello world' '</new-form-b>' /, 'basic interpolation correct from file';

"$path/$tmpl-fn".IO.unlink if "$path/$tmpl-fn".IO ~~ :e & :f;

done-testing;


