use v6.d;
use Test;
use RakuDoc::Templates;
use RakuDoc::PromiseStrings;

plan 4;

my $register = PCellTracker.new;

my %td is Template-directory = %(
    aaa => -> %prm, $tmpl {
        my $rv = '<begin>' ~ %prm<contents> ~ '<end>';
        $rv ~= 'custom data is: ' ~ $tmpl.globals.data<custom>.gist;
    },
    bbb => -> %prm, $tmpl {
        $tmpl.globals.data<scss> = %prm<class>;
        ''
    },
    ccc => -> %prm, $tmpl {
        'scss data is ' ~ $tmpl.globals.data<scss>
    }
);
my %custom = <one two three> Z=> 1..* ;
%td.data<custom> = %custom;
my %params = :contents(PStr.new ~ PCell.new(:$register, :id<ID1>) ), ;
my $rv = %td<aaa>( %params );
isa-ok $rv, PStr, 'if a parameter is passed as PStr, the return value is a PStr' ;
like $rv.tail, / { %custom.gist } /, 'custom data is accessed inside template';
my $test-string = '.header { background: black; }';
$rv = %td<bbb>( %(:class($test-string), ) );
is $rv, '', 'got empty string';
$rv = %td<ccc>( % );
is $rv, 'scss data is ' ~ $test-string, 'data passed from one template to another';
done-testing;
