use v6.d;
use Test;
use RakuDoc::Render;

plan 5;

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

$ast = Q:to/QAST/.AST;
    =begin rakudoc
    We can L<Link to a place|https://docs.raku.org> with no problem.
    Linking inside the file is L<like this|#Here is a header>.
    No link meta L<path/to/file> is treated as a link to a local file.
    Blank link meta L<Forgot to put link|> is an error condition.
    =end rakudoc
    QAST
$rv = $rdp.render( $ast, :pre-finalised );
like $rv.body, /
    'We can '
    '<markup-L>' .+
    'extra: ｢｣' .+
    'link-label' .+ 'Link to a place' .+
    'target' .+ 'https://docs.raku.org' .+
    'type' .+? 'external' .+
    '</markup-L>' .+
    'with no problem.'
    /, 'External L<> works';
like $rv.body, /
    'Linking inside' .+
    '<markup-L>' .+
    'extra: ｢｣'  .+
    'link-label' .+? 'like this' .+
    'target: ｢Here_is_a_header｣' .+
    'type' .+? 'internal'
    /, 'Internal L standard works';
like $rv.body, /
    'No link' .+
    '<markup-L>' .+
    'extra' .+? '｢｣' .+
    'link-label' .+? 'path/to/file' .+
    'target' .+? '｢path/to/file｣' .+
    'type' .+? 'local' .+
    'Blank link' .+
    '<markup-L>' .+
    'extra' .+? '｢｣' .+
    'link-label' .+? 'Forgot to put link' .+
    'target' .+? '｢｣' .+
    'type' .+? 'internal'
    /, 'L format with blank urls';

$ast = Q:to/QAST/.AST;
    =begin rakudoc

    We also can L<link to an index test code|format-code-index-test-pod-file_2#an item> with more text.
    Otherwise it constructs a L<Block|/type/Block>.
    To force construction of a L<Block|/type/Block>, follow the opening brace with a semicolon.

    =end rakudoc
    QAST
$rv = $rdp.render( $ast, :pre-finalised );
like $rv.body, /
    'We also' .+
    '<markup-L>' .+
    'extra' .+? 'an item' .+
    'link-label' .+? 'link to an index test code' .+
    'target' .+? 'format-code-index-test-pod-file_2' .+
    'type' .+? 'local'
/, 'Link to another file';
like $rv.body, /
    'Otherwise' .+
    '<markup-L>' .+
    'extra' .+? '｢｣' .+
    'link-label' .+? 'Block' .+
    'target' .+? '/type/Block' .+
    'type' .+? 'local' .+
    'force construction' .+
    '<markup-L>' .+
    'extra' .+? '｢｣' .+
    'link-label' .+? 'Block' .+
    'target' .+? '/type/Block' .+
    'type' .+? 'local'
    /, 'double link points to same place';

done-testing;
