Skip to content

Commit

Permalink
Add new tests for POD tables rakudo/rakudo/#1282
Browse files Browse the repository at this point in the history
Add new tests for fix to rakudo/rakudo#1282
  • Loading branch information
tbrowder authored and samcv committed Dec 8, 2017
1 parent 1d3b572 commit 832ab07
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 1 deletion.
96 changes: 95 additions & 1 deletion S26-documentation/07a-tables.t
Expand Up @@ -4,7 +4,7 @@ use Test;
my ($r, $p, $hdrs, @rows);
$p = -1; # starting index for pod number

plan 37;
plan 61;

# includes tests for fixes for RT bugs:
# 124403 - incorrect table parse:
Expand Down Expand Up @@ -138,3 +138,97 @@ a
$r = $=pod[++$p];
is $r.headers.elems, 1;
is $r.contents.elems, 1;

# test fix for rakudo repo issue #1282:
# need to handle table cells with char column separators as data
# example table from <https://docs.perl6.org/language/regexes>
# WITHOUT the escaped characters (results in an extra, unwanted, incorrect column)
=begin table
Operator | Meaning
==========+=========
 +  | set union
 |  | set union
 &  | set intersection
 -  | set difference (first minus second)
 ^  | symmetric set intersection / XOR
=end table

$r = $=pod[++$p];
is $r.headers.elems, 3;
$hdrs = $r.headers.join(',');
is $hdrs, "Operator,Meaning,";
is $r.contents.elems, 5;
@rows = $r.contents>>.join(',');
is @rows[0], ",,set union";
is @rows[1], "|,set union,";
is @rows[2], "&,set intersection,";
is @rows[3], "-,set difference (first minus second),";
is @rows[4], "^,symmetric set intersection / XOR,";

# WITHOUT the escaped characters and without the non-breaking spaces
# (results in the desired table)
=begin table
Operator | Meaning
==========+=========
+ | set union
| | set union
& | set intersection
- | set difference (first minus second)
^ | symmetric set intersection / XOR
=end table

$r = $=pod[++$p];
is $r.headers.elems, 2;
$hdrs = $r.headers.join(',');
is $hdrs, "Operator,Meaning";
is $r.contents.elems, 5;
@rows = $r.contents>>.join(',');
is @rows[0], "+,set union";
is @rows[1], "|,set union";
is @rows[2], "&,set intersection";
is @rows[3], "-,set difference (first minus second)";
is @rows[4], "^,symmetric set intersection / XOR";

# WITH the escaped characters (results in the desired table)
=begin table
Operator | Meaning
==========+=========
 \+  | set union
 \|  | set union
 &  | set intersection
 -  | set difference (first minus second)
 ^  | symmetric set intersection / XOR
=end table

$r = $=pod[++$p];
is $r.headers.elems, 2;
$hdrs = $r.headers.join(',');
is $hdrs, "Operator,Meaning";
is $r.contents.elems, 5;
@rows = $r.contents>>.join(',');
is @rows[0], "+,set union";
is @rows[1], "|,set union";
is @rows[2], "&,set intersection";
is @rows[3], "-,set difference (first minus second)";
is @rows[4], "^,symmetric set intersection / XOR";

# WITH the escaped characters but without the non-breaking spaces
# (results in the desired table)

=begin table
Operator | Meaning
==========+=========
\+ | set union
\| | set union
& | set intersection
- | set difference (first minus second)
^ | symmetric set intersection / XOR
=end table
68 changes: 68 additions & 0 deletions S26-documentation/07c-tables.t
@@ -0,0 +1,68 @@
use v6;

use MONKEY-SEE-NO-EVAL;
use Test;

my $f = './.tmp-test-file';

my $code = gen-test($f);

EVAL $code;

##### subroutines #####
sub gen-test($f) {
my $fh = open $f, :w;

$fh.print: q:to/HERE/;
use v6;
use Test;
plan 8;
my $r;
# table with no ending ws
=table
HERE

$fh.say: " X | O |";

$fh.print: q:to/HERE/;
---+---+---
| X | O
---+---+---
| | X
# table with ending ws
=table
HERE

$fh.say: " X | O | ";

$fh.print: q:to/HERE/;
---+---+---
| X | O
---+---+---
| | X
$r = $=pod[0];
is $r.contents.elems, 3;
is $r.contents[0].join(','), 'X,O,';
is $r.contents[1].join(','), ',X,O';
is $r.contents[2].join(','), ',,X';
$r = $=pod[1];
is $r.contents.elems, 3;
is $r.contents[0].join(','), 'X,O,';
is $r.contents[1].join(','), ',X,O';
is $r.contents[2].join(','), ',,X';
HERE

$fh.close;

return slurp $f;
}

END { unlink $f }

0 comments on commit 832ab07

Please sign in to comment.