### ----------------------------------------------------
### -- Template::Nest::XS
### -- Licenses: ISC
### -- Authors: 
### -- File: t/04-indent.rakutest
### ----------------------------------------------------
use Test;

plan 4;

#use lib '../lib';

use Template::Nest::XS;




my $nest = Template::Nest::XS.new(
	template_dir => $*PROGRAM.parent.add('tests').Str,
   template_ext => '.html',
    name_label => 'NAME',
    token_delims => ['<!--%','%-->'],
    defaults_namespace_char => '',
    fixed_indent => False
);


my $nest_sq = Template::Nest::XS.new(
   template_dir => $*PROGRAM.parent.add('tests').Str,
    template_ext => '.html',
    name_label => 'NAME',
    token_delims => ['[%','%]'],
    defaults_namespace_char => '',
    fixed_indent => False
);



my $table = {
    NAME => 'table',
    rows => [{
        NAME => 'tr',
        cols => {
            NAME => 'td',
            contents => '1'
        }
    },{
        NAME => 'tr',
        cols => {
            NAME => 'td',
            contents => '2'
        }
    }]
};

my $table_sq = {
    NAME => 'table_sq',
    rows => [{
        NAME => 'tr_sq',
        cols => {
            NAME => 'td_sq',
            contents => '1'
        }
    },{
        NAME => 'tr_sq',
        cols => {
            NAME => 'td_sq',
            contents => '2'
        }
    }]
};


my $x_html = "<table>
    <tr>
    <td>
    1
</td>
</tr><tr>
    <td>
    2
</td>
</tr>
</table>";

my $html = $nest.render( $table );
my $html_sq = $nest_sq.render( $table_sq );

is( $html, $x_html, "fixed_indent = 0" );
$html_sq ~~ s:g/\r\n/\n/;
$x_html ~~ s:g/\r\n/\n/;
is( $html_sq, $x_html, "fixed_indent = 0, square token delims" );

$nest.fixed_indent = True;
$nest_sq.fixed_indent = True;

$x_html = "<table>
    <tr>
        <td>
            1
        </td>
    </tr><tr>
        <td>
            2
        </td>
    </tr>
</table>";

$html = $nest.render( $table );
$html_sq = $nest_sq.render( $table_sq );
say $html.raku;
$html ~~ s:g/\r\n/\n/;
say $html.raku;
$x_html  ~~ s:g/\r\n/\n/;
$html_sq ~~ s:g/\r\n/\n/;
say $x_html.raku;
is( $html, $x_html, "fixed_indent = 1" );
is( $html_sq, $x_html, "fixed_indent = 1, square token delims");




