### ----------------------------------------------------
### -- Rakuast::RakuDoc::Render
### -- Licenses: Artistic-2.0
### -- Authors: Richard Hainsworth
### -- File: xt/085-FCodes-comment-verbose.rakutest
### ----------------------------------------------------
use v6.d;
use Test;
use Test::Output;
use RakuDoc::Render;
use RakuDoc::Templates;

plan 15;

my $ast;
my $rv;
my RakuDoc::Processor $rdp .= new(:test);
# only test B as H I J K R T U O are the same but different key words
# C V S tested later
$ast = Q:to/QAST/.AST;
    =begin rakudoc
    Some thingB<to be said>inside letters.
    =end rakudoc
    QAST
$rv = $rdp.render( $ast, :pre-finalised );
like $rv.body, /
    'Some thing'
    '<markup-B>' .*? 'contents:' .*? '｢to be said｣' .*? '</markup-B>' .*?
    'inside letters.'
    /, 'B-markup works with text with spaces inside text';

$ast = Q:to/QAST/.AST;
    =begin rakudoc
    Some thing to B<say> in between words.
    =end rakudoc
    QAST
$rv = $rdp.render( $ast, :pre-finalised );
like $rv.body, /
    'Some thing to '
    '<markup-B>' .*? 'contents:' .*? '｢say｣' .+? '</markup-B>' .*?
    ' in between words.'
    /, 'B-markup works with space';

$ast = Q:to/QAST/.AST;
    =begin rakudoc
    Some thingZ<to be said>inside letters.
    =end rakudoc
    QAST
$rv = $rdp.render( $ast, :pre-finalised );
like $rv.body, /
    'Some thinginside letters.'
    /, 'Z-markup works with text with spaces inside text';

$ast = Q:to/QAST/.AST;
    =begin rakudoc
    Some thing to Z<say> in between words.
    =end rakudoc
    QAST
$rv = $rdp.render( $ast, :pre-finalised );
like $rv.body, /
    'Some thing to  in between words.'
    /, 'Z-markup works with space';

$ast = Q:to/QAST/.AST;
    =begin rakudoc
    Raku makes considerable use of the E<0xAB;0xBB> characters.
    =end rakudoc
    QAST
$rv = $rdp.render( $ast, :pre-finalised );
like $rv.body, /
    'Raku makes' .+
    '<markup-E>' .*? 'contents: ｢«»｣' .*? '</markup-E>' .*? 'characters'
    /, 'E-markup ';

# test verbose functionality for markup
$ast = Q:to/QAST/.AST;
    =begin rakudoc
    Some thingB<to be said>inside letters.
    And also I<in italics>.
    =end rakudoc
    QAST
$rdp.verbose('markup-I');
my $out = output-from {
    $rv = $rdp.render( $ast, :pre-finalised );
};
like $out, / '<markup-I>' .*? 'in italics' .+ '</markup-I>'
    /, 'the template result for I is output';
unlike $out, /
    '<markup-B>' .*? 'contents:' .*? '｢to be said｣' .*? '</markup-B>' .*?
    /, 'template result for B is not output';
like $rv.body, /
    'Some thing' .*?
    '<markup-B>' .*? 'contents:' .*? '｢to be said｣' .*? '</markup-B>' .*?
    'inside letters.' \s*
    'And also' .+? '<markup-I>' .*? 'in italics'
    /, 'B & I works with text with spaces inside text';

# test undefined ASCII
$ast = Q:to/QAST/.AST;
    =begin rakudoc
    Some thing to G<say> in between words.
    =end rakudoc
    QAST
$rv = $rdp.render( $ast, :pre-finalised );
like $rv.body, /
    'Some thing to <markup-bad' .+
    'G<say>' .+
    ' in between words.'
    /, 'G code without change';
like $rv.warnings[0], / 'is reserved' /, 'got reserved warning';

# test possible but not defined

$ast = Q:to/QAST/.AST;
    =begin rakudoc
    Some thing to Ɵ<say> in between words.
    =end rakudoc
    QAST
$rv = $rdp.render( $ast, :pre-finalised );
like $rv.body, /
    'Some thing to <markup-bad' .+
    'Ɵ<say>' .+
    ' in between words.'
    /, 'Ɵ without change';
like $rv.warnings[0], / 'could be a custom code' /, 'got possible warning';

# test impossible

$ast = Q:to/QAST/.AST;
    =begin rakudoc
    Some thing to ɤ<say> in between words.
    =end rakudoc
    QAST
$rv = $rdp.render( $ast, :pre-finalised );
like $rv.body, /
    'Some thing to '
    'ɤ<say>'
    ' in between words.'
    /, 'ɤ code without change';

## test possible and defined
$rdp.add-template: ( markup-Ɵ => sub ( %prm, $ ) {
    express-params( %prm, 'markup-Ɵ')
});

$ast = Q:to/QAST/.AST;
    =begin rakudoc
    Some thing to Ɵ<say> in between words.
    =end rakudoc
    QAST
$rv = $rdp.render( $ast, :pre-finalised );
like $rv.body, /
    'Some thing to '
    '<markup-Ɵ>' .*? 'contents:' .*? '｢say｣' .+? '</markup-Ɵ>' .*?
    ' in between words.'
    /, 'Ɵ-markup works with space';
is $rv.warnings.elems, 0, 'no warning';

done-testing;


