### ----------------------------------------------------
### -- HTML::Tag
### -- Licenses: Artistic-2.0
### -- Authors: Mark Rushing, Márton Polgár
### -- File: t/0040-table.t
### ----------------------------------------------------
use v6;
use Test;
use lib <lib>;

plan 7;

use-ok 'HTML::Tag::Tags', 'HTML::Tag::Tags can be use-d';
use HTML::Tag::Tags;
use-ok 'HTML::Tag::Macro::Table', 'HTML::Tag::Macro::Table can be use-d';
use HTML::Tag::Macro::Table;


# Table Macro
my $table = HTML::Tag::Macro::Table.new;
my @data = 'Col1', 'Col2', 'Col3';
$table.row(:header, @data);
@data = 11, 22, 33;
$table.row(@data);
is $table.render, '<table><tr><th>Col1</th><th>Col2</th><th>Col3</th></tr><tr><td>11</td><td>22</td><td>33</td></tr></table>', 'HTML::Tag::Macro::Table works';

# Table Macro using rows()
$table = HTML::Tag::Macro::Table.new;
@data = 'Col1', 'Col2', 'Col3';
$table.row(:header, @data);
@data = ((11, 22, 33), (44, 55, 66));
$table.rows(|@data);
is $table.render, '<table><tr><th>Col1</th><th>Col2</th><th>Col3</th></tr><tr><td>11</td><td>22</td><td>33</td></tr><tr><td>44</td><td>55</td><td>66</td></tr></table>', 'HTML::Tag::Macro::Table works with rows() pt. 1';

$table = HTML::Tag::Macro::Table.new;
@data = 'Col1', 'Col2';
$table.row(:header, @data);
$table.rows(<right here>, <right now>, (42, 'dreams'));
is $table.render, '<table><tr><th>Col1</th><th>Col2</th></tr><tr><td>right</td><td>here</td></tr><tr><td>right</td><td>now</td></tr><tr><td>42</td><td>dreams</td></tr></table>', 'HTML::Tag::Macro::Table works with rows() pt. 2';

# Table Macro with td options
$table = HTML::Tag::Macro::Table.new;
@data = 'Col1', 'Col2', 'Col3';
$table.row(:header(True), @data);
@data = 0, 22, 33;
$table.row(@data);
@data = 111, 222, 333;
my $td-opts = %(1 => {class => 'pretty'},
		2 => {class => 'pretty',
		      id    => 'lastone'});
$table.row(:$td-opts, @data);
is $table.render, '<table><tr><th>Col1</th><th>Col2</th><th>Col3</th></tr><tr><td>0</td><td>22</td><td>33</td></tr><tr><td>111</td><td class="pretty">222</td><td class="pretty" id="lastone">333</td></tr></table>', 'HTML::Tag::Macro::Table works with td-opts';

$table = HTML::Tag::Macro::Table.new(:table-opts(id => 'mytable'));
@data = 'Col1', 'Col2', 'Col3';
$table.row(:header(True), @data);
@data = 11, 22, 33;
my $tr-opts = %(class => 'pretty');
$table.row(:$tr-opts, @data);
@data = 111, 222, 333;
$table.row(@data);
is $table.render, '<table id="mytable"><tr><th>Col1</th><th>Col2</th><th>Col3</th></tr><tr class="pretty"><td>11</td><td>22</td><td>33</td></tr><tr><td>111</td><td>222</td><td>333</td></tr></table>', 'HTML::Tag::Macro::Table works with tr-opts';


