### ----------------------------------------------------
### -- Rakuast::RakuDoc::Render
### -- Licenses: Artistic-2.0
### -- Authors: Richard Hainsworth
### -- File: xt/065-config.rakutest
### ----------------------------------------------------
use v6.d;
use Test;
use RakuDoc::Render;

plan 9;

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

$ast = Q:to/QAST/.AST;
    =begin rakudoc
    =config head2 :!toc
    =head2 Third test text
    =end rakudoc
    QAST
$rv = $rdp.render( $ast, :pre-finalised );
like $rv.body.Str, /'<head>' .+ 'level' .+ 2 .+ '</head>' /, 'plain head has level 2';
like $rv.body.Str, / '<head>' .+ 'toc' .+ 'False' .+ '</head>' /, 'head got toc data';
$ast = Q:to/QAST/.AST;
    =head2 First header
    =begin section
    =head2 Second header without option
    =config head2 :!toc
    =head2 Third test text with option
    =end section
    =head2 Fourth without option
    QAST
$rv = $rdp.render( $ast, :pre-finalised );
my regex hd { '<head>' $<cont> = (.+?) '</head>' }
my $parse = $rv.body.Str ~~ / [<hd> .*? ]+ $/;
is $parse<hd>.elems, 4, 'got 4 heads';
like $parse<hd>[0]<cont>, / 'contents' .+ 'First header' /, 'Got first head';
like $parse<hd>[0]<cont>, / 'toc' .+ 'True' /, 'First head has toc True';
like $parse<hd>[1]<cont>, /'contents' .+ 'Second header' /, 'got 2nd head';
like $parse<hd>[1]<cont>, /'toc' .+ 'True' /, '2nd head has toc True';
like $parse<hd>[2]<cont>, /'contents' .+ 'Third test text' .+ 'toc' .+ 'False' /, '3rd head has toc False';
like $parse<hd>[3]<cont>, / 'toc' .+ 'True' /, '3rd head hastoc True';

done-testing;


