### ----------------------------------------------------
### -- RakuDoc::Load
### -- Licenses: Artistic-2.0
### -- Authors: Tom Browder
### -- File: t/1-basic.rakutest
### ----------------------------------------------------
use Test;
use RakuDoc::Load;

constant %tests = {
    "rakudoc-test.rakudoc" => /K/,
    "test.rakudoc"     => /extension/,
    "unit.rakudoc"     => /magicians/,
    "class.rakumod"    => /Hello/,
    "multi.rakudoc"    => /mortals/,
    "can.raku"         => /1/,
    "rakudoc.rakudoc"      => /Unordered/,
};

sub do-the-test() {
    diag "Testing strings";
    my $string-with-rakudoc = q:to/HERE/;
=begin rakudoc
This ordinary paragraph introduces a code block:
    $this = 1 * code('block');
    $which.is_specified(:by<indenting>);
=end rakudoc
HERE

    my @rakudoc = load( $string-with-rakudoc );
    ok( @rakudoc, "String load returns something" );
    like( @rakudoc[0].^name, /Pod\:\:/, "The first element of that is a RakuDoc");
    isa-ok( @rakudoc[0].contents[0], Pod::Block::Para, "Parsed OK" );

    diag "Testing files";
    for %tests.kv -> $file, $re {
        my $prefix = $file.IO.e??"./"!!"t/";
        my $file-name = $prefix ~ $file;
        @rakudoc = load( $file-name );
        ok( @rakudoc, "$file-name load returns something" );
        like( @rakudoc[0].^name, /Pod\:\:/, "That something is a RakuDoc");
        my $io = $file-name.IO;
        @rakudoc = load( $io );
        ok( @rakudoc, "$file load returns something" );
        like( @rakudoc[0].^name, /Pod\:\:/, "That something is a RakuDoc");
        like( @rakudoc.gist, $re, "$file gets the content right" );

    }
}

do-the-test(); # Use default values

done-testing;


