### ----------------------------------------------------
### -- Raku::Pod::Render
### -- Licenses: Artistic-2.0
### -- Authors: Richard Hainsworth
### -- File: xt/901-html/40-table.rakutest
### ----------------------------------------------------
use v6.*;
use Test;

use Pod::To::HTML2;
my $def-dir = 'xt/test-def'.IO;
my $tar-dir = 'xt/tar-dir'.IO;

bail-out "Requires $def-dir and $tar-dir" unless ($def-dir ~~ :e and $tar-dir ~~ :e);
chdir ~$tar-dir;

my $processor = Pod::To::HTML2.new(:$def-dir, :plugins() );
my $rv;
my $pn = 0;

plan 4;
=table
  col1  col2

$rv = $processor.render-block( $=pod[$pn++] );

like $rv,
    /
    \s* '<table class="pod-table">'
    \s*   '<tbody>'
    \s*     '<tr>'
    \s*       '<td>col1</td>'
    \s*       '<td>col2</td>'
    \s*     '</tr>'
    \s*   '</tbody>'
    \s* '</table>'
    /, 'simple row';

=table
  H1    H2
  --    --
  col1  col2

$rv = $processor.render-block( $=pod[$pn++] );

like $rv,
    /
    \s*   '<thead>'
    \s*     '<tr>'
    \s*       '<th>H1</th>'
    \s*       '<th>H2</th>'
    \s*     '</tr>'
    \s*   '</thead>'
    \s*   '<tbody>'
    \s*     '<tr>'
    \s*       '<td>col1</td>'
    \s*       '<td>col2</td>'
    \s*     '</tr>'
    \s*   '</tbody>'
    \s* '</table>'
    /,'simple header and row';

=begin table :class<sorttable>

  H1    H2
  --    --
  col1  col2

  col1  col2

=end table

$rv = $processor.render-block( $=pod[$pn++] );

like $rv,
    /
    '<table class="' \s* 'pod-table' \s+ 'sorttable' \s* '">'
    \s*   '<thead>'
    \s*     '<tr>'
    \s*       '<th>H1</th>'
    \s*       '<th>H2</th>'
    \s*     '</tr>'
    \s*   '</thead>'
    \s*   '<tbody>'
    \s*     '<tr>'
    \s*       '<td>col1</td>'
    \s*       '<td>col2</td>'
    \s*     '</tr>'
    \s*     '<tr>'
    \s*       '<td>col1</td>'
    \s*       '<td>col2</td>'
    \s*     '</tr>'
    \s*   '</tbody>'
    \s* '</table>'
    /, 'table with class';

=begin table :caption<Test Caption>

  H1    H2
  --    --
  col1  col2

=end table

$rv = $processor.render-block( $=pod[$pn++] );

like $rv,
    /
    '<table class="pod-table">'
    \s*   '<caption>Test Caption</caption>'
    \s*   '<thead>'
    \s*     '<tr>'
    \s*       '<th>H1</th>'
    \s*       '<th>H2</th>'
    \s*     '</tr>'
    \s*   '</thead>'
    \s*   '<tbody>'
    \s*     '<tr>'
    \s*       '<td>col1</td>'
    \s*       '<td>col2</td>'
    \s*     '</tr>'
    \s*   '</tbody>'
    \s* '</table>'
    /, 'table with caption';

done-testing


