Skip to content

Commit

Permalink
save work, good tests for Pod fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrowder committed Nov 6, 2017
1 parent 72c9444 commit 3636ca7
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 183 deletions.
74 changes: 12 additions & 62 deletions S26-documentation/07-tables.t
@@ -1,8 +1,9 @@
use v6;
use Test;
my $r;
my $p = 0; # use as an index for the pod chunks

plan 42;
plan 34;

=begin table
The Shoveller Eddie Stevens King Arthur's singing shovel
Expand All @@ -11,8 +12,7 @@ plan 42;
The Bowler Carol Pinnsler Haunted bowling ball
=end table

$r = $=pod[0];
# tests 1-6:
$r = $=pod[$p++];
isa-ok $r, Pod::Block::Table;
is $r.contents.elems, 4;
is $r.contents[0].join('|'),
Expand All @@ -30,8 +30,7 @@ is $r.contents[3].join('|'),
Subroutines 33
Everything else 57

$r = $=pod[1];
# tests 7-11:
$r = $=pod[$p++];
is $r.contents.elems, 4;
is $r.contents[0].join('|'), "Constants|1";
is $r.contents[1].join('|'), "Variables|10";
Expand All @@ -43,8 +42,7 @@ is $r.contents[3].join('|'), "Everything else|57";
horse | horses
elephant | elephants
$r = $=pod[2];
# tests 12-15:
$r = $=pod[$p++];
is $r.contents.elems, 3;
is $r.contents[0].join('|'), "mouse|mice";
is $r.contents[1].join('|'), "horse|horses";
Expand All @@ -57,8 +55,7 @@ is $r.contents[2].join('|'), "elephant|elephants";
Human + 2 + Pizza
Shark + 0 + Fish

$r = $=pod[3];
# tests 16-20:
$r = $=pod[$p++];
is $r.headers.join('|'), "Animal|Legs|Eats";
is $r.contents.elems, 3;
is $r.contents[0].join('|'), "Zebra|4|Cookies";
Expand All @@ -71,8 +68,7 @@ is $r.contents[2].join('|'), "Shark|0|Fish";
==============|=================|================================
The Shoveller | Eddie Stevens | King Arthur's singing shovel

$r = $=pod[4];
# tests 21-23:
$r = $=pod[$p++];
is $r.headers.join('|'), "Superhero|Secret Identity|Superpower";
is $r.contents.elems, 1;
is $r.contents[0].join('|'),
Expand All @@ -95,8 +91,7 @@ is $r.contents[0].join('|'),
=end table

$r = $=pod[5];
# tests 24-29:
$r = $=pod[$p++];
is $r.headers.join('|'), "Superhero|Secret Identity|Superpower";
is $r.contents.elems, 4;
is $r.contents[0].join('|'),
Expand All @@ -109,40 +104,16 @@ is $r.contents[3].join('|'),
"The Bowler|Carol Pinnsler|Haunted bowling ball";

=table
X | O |
X | O |
---+---+---
| X | O
---+---+---
| | X


$r = $=pod[6];
# tests 30-33:
$r = $=pod[$p++];
is $r.contents.elems, 3;
my $s1 := $r.contents[0].join(',');
is $r.contents[0].join(','), 'X,O,',
"got '$s1'; ensure trailing whitespace counts as a cell (WARNING: this test will"
~ " fail if you modified this file and your editor auto-stripped"
~ " trailing whitespace)";
my $s2 := $r.contents[1].join(',');
is $r.contents[1].join(','), ',X,O', "got '$s2'";
my $s3 := $r.contents[1].join(',');
is $r.contents[2].join(','), ',,X', "got '$s3'";

=table
X O
===========
X O
===========
X

$r = $=pod[7];
# tests 34-37:
is $r.contents.elems, 3;
is $r.contents[0].join(','), 'X,O,',
'ensure trailing whitespace counts as a cell (WARNING: this test will'
~ ' fail if you modified this file and your editor auto-stripped'
~ ' trailing whitespace)';
is $r.contents[0].join(','), 'X,O,';
is $r.contents[1].join(','), ',X,O';
is $r.contents[2].join(','), ',,X';

Expand All @@ -153,26 +124,5 @@ bar
=end table

$r = $=pod[8];
# test 38:
$r = $=pod[$p++];
is $r.contents.elems, 2;

# test for issue #129862
# uneven rows

# NOTE: This test may need to change after planned table pod fixes are
# made because this is a malformed table and the user should be warned
# of that fact. But the table can also be fixed automatically which
# is the planned fix.
=begin table
a | b | c
l | m | n
x | y
=end table

$r = $=pod[9];
# tests 39-42:
is $r.contents.elems, 3;
is $r.contents[0].join(','), 'a,b,c';
is $r.contents[1].join(','), 'l,m,n';
is $r.contents[2].join(','), 'x,y'; # should change to "x,y," after a planned fix
166 changes: 115 additions & 51 deletions S26-documentation/07a-tables.t
@@ -1,54 +1,118 @@
use v6;
use Test;

plan 8;

my $r;
my $t = 0;

# tests for 'RT #128221'
# test for issue #128221 when it's closed
# This test, with a '-r0c0' entry in
# the single table row, column 0,
# caused an exception.
=begin table
-r0c0 r0c1
=end table
$r = $=pod[0];
# 3 tests
is $r.contents.elems, 1, "test {++$t}";
is $r.contents[0][0], "-r0c0", "test {++$t}"; # <= note leading hyphen which caused the original issue
is $r.contents[0][1], "r0c1", "test {++$t}";

# an expanded test (per Zoffix) for issue #128221
# when it's closed.
# This test is for other table parsing issues
# discovered in Zoffix's work on the problem.
=begin table
-Col 1 | -Col 2 | _Col 3 | =Col 4
=======+========+========+=======
r0Col 1 | -r0Col 2 | _r0Col 3 | =r0Col 4
-------|--------|--------|-------
r1Col 1 | -r1Col 2 | _r1Col 3 | =r1Col 4
r1 | r1Col 2 | _r2Col 3 | =r2Col 4
-------|--------|--------|-------
r6Col 1 | r6Col 2 | r6Col 3 | r6Col 4
=end table
$r = $=pod[1];
my $hdrs = $r.headers.join(' ');
my @rows = $r.contents>>.join(' ');

# 10 tests
my $s = $r.headers.elems;
is $r.headers.elems, 4, "test {++$t}, got '$s'";
is $r.contents.elems, 3, "test{++$t}";
is $hdrs, "-Col 1 -Col 2 _Col 3 =Col 4", "got '$hdrs'"; # <= note leading hyphen which caused the original issue
is @rows[0], "r0Col 1 -r0Col 2 _r0Col 3 =r0Col 4";
=begin comment
is @rows[1], "r1Col 1 -r1Col 2 _r1Col 3 =r1Col 4";
is @rows[2], "r2Col 1 -r2Col 2 _r2Col 3 =r2Col 4";
is @rows[3], "r3Col 1 -r3Col 2 _r3Col 3 =r3Col 4";
is @rows[4], "r4Col 1 -r4Col 2 _r4Col 3 =r4Col 4";
is @rows[5], "r5Col 1 -r5Col 2 _r5Col 3 =r5Col 4";
=end comment
is @rows[2], "r6Col 1 r6Col 2 r6Col 3 r6Col 4";
my ($r, $p, $hdrs, @rows);
$p = -1; # starting index for pod number

plan 33;

# includes tests for fixes for RT bugs:
# 124403 - incorrect table parse:
# 128221 - internal error
# 129862 - uneven rows
# 132341 - pad rows to add empty cells to ensure all rows have same number of cells
# 132348 - handle inline Z<> comments on table rows

# test fix for RT #124403 - incorrect table parse:
=table
+-----+----+---+
| a | b | c |
+-----+----+---+
| foo | 52 | Y |
| bar | 17 | N |
| dz | 9 | Y |
+-----+----+---+

$r = $=pod[++$p];
# tests
is $r.headers.elems, 3;
$hdrs = $r.headers.join('*');
is $hdrs, "a*b*c";
@rows = $r.contents>>.join('*');
is $r.contents.elems, 3;
is @rows[0], "foo*52*Y";
is @rows[1], "bar*17*N";
is @rows[2], "dz*9*Y";

# test fix for RT #128221
# This test, with a '-r0c0' entry in
# the single table row, column 0,
# caused an exception.
=begin table
-r0c0 r0c1
=end table
$r = $=pod[++$p];
is $r.contents.elems, 1;
is $r.contents[0][0], "-r0c0"; # <= note leading hyphen which caused the original issue
is $r.contents[0][1], "r0c1";

# an expanded test (per Zoffix) for issue #128221
# note expected results have been corrected from that time
=begin table
-Col 1 | -Col 2 | _Col 3 | =Col 4
=======+========+========+=======
r0Col 1 | -r0Col 2 | _r0Col 3 | =r0Col 4
-------|--------|--------|-------
r1Col 1 | -r1Col 2 | _r1Col 3 | =r1Col 4
r1 | r1Col 2 | _r1Col 3 | =r1Col 4
-------|--------|--------|-------
r2Col 1 | r2Col 2 | r2Col 3 | r2Col 4
=end table
$r = $=pod[++$p];
$hdrs = $r.headers.join('|');
@rows = $r.contents>>.join('|');

is $r.headers.elems, 4;
is $r.contents.elems, 3;
is $hdrs, "-Col 1|-Col 2|_Col 3|=Col 4"; # <= note leading hyphen which caused the original issue
is @rows[0], "r0Col 1|-r0Col 2|_r0Col 3|=r0Col 4";
is @rows[1], "r1Col 1 r1|-r1Col 2 r1Col 2|_r1Col 3 _r1Col 3|=r1Col 4 =r1Col 4", "test for merged cells";
is @rows[2], "r2Col 1|r2Col 2|r2Col 3|r2Col 4";

# test fix for issue RT #129862
# uneven rows
=begin table
a | b | c
l | m | n
x | y
=end table

$r = $=pod[++$p];
is $r.contents.elems, 3;
is $r.contents[0].join(','), 'a,b,c';
is $r.contents[1].join(','), 'l,m,n';
is $r.contents[2].join(','), 'x,y,';

is $r.contents[0].elems, 3;
is $r.contents[1].elems, 3;
is $r.contents[2].elems, 3;

# test fix for RT #132341
=table
X O
===========
X O
===========
X

$r = $=pod[++$p];
is $r.contents.elems, 3;
is $r.contents[0].join(','), 'X,O,', "test for empty cell";
is $r.contents[1].join(','), ',X,O';
is $r.contents[2].join(','), ',,X';

is $r.contents[0].elems, 3;
is $r.contents[1].elems, 3;
is $r.contents[2].elems, 3;

# test fix for RT #132348 (allow inline Z comments)
=begin table
a | b | c
l | m | n
x | y Z<a comment> Z<another comment>
=end table
$r = $=pod[++$p];
is $r.contents.elems, 3;
is $r.contents[0].join(','), 'a,b,c';
is $r.contents[1].join(','), 'l,m,n';
is $r.contents[2].join(','), 'x,y,';

0 comments on commit 3636ca7

Please sign in to comment.