### ----------------------------------------------------
### -- Raku::Pod::Render
### -- Licenses: Artistic-2.0
### -- Authors: Richard Hainsworth
### -- File: xt/45-filewrap.rakutest
### ----------------------------------------------------
use v6.*;
use Test;
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 $processor = ProcessedPod.new;

plan 2;

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


my %templates  = @templates Z=> @templates.map( { gen-closure-template( $_ ) });
# this creates a set of pseudo templates
$processor.templates( %templates );

=begin pod
    Some pod
=end pod

my $fn = 'xt/999-test-output';
$fn.IO.unlink if $fn.IO ~~ :e;
"$fn\.html".IO.unlink if "$fn\.html".IO ~~ :e;

$processor.file-wrap(:filename($fn));
ok $fn.IO ~~ :f, 'file is created with zero default extension';
$processor.file-wrap(:filename($fn), :ext<html>);
ok "$fn\.html".IO ~~ :f, 'file is created with given extension';

$fn.IO.unlink if $fn.IO ~~ :e;
"$fn\.html".IO.unlink if "$fn\.html".IO ~~ :e;

done-testing;


