Skip to content

Commit 2342d1d

Browse files
authored
Merge pull request #353 from tbrowder/fix-rt-128221
Fix rt 128221
2 parents f1692c0 + 443b934 commit 2342d1d

File tree

4 files changed

+188
-104
lines changed

4 files changed

+188
-104
lines changed

S26-documentation/07-tables.t

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use v6;
22
use Test;
33
my $r;
4+
my $p = 0; # use as an index for the pod chunks
45

5-
plan 42;
6+
plan 34;
67

78
=begin table
89
The Shoveller Eddie Stevens King Arthur's singing shovel
@@ -11,7 +12,7 @@ plan 42;
1112
The Bowler Carol Pinnsler Haunted bowling ball
1213
=end table
1314

14-
$r = $=pod[0];
15+
$r = $=pod[$p++];
1516
isa-ok $r, Pod::Block::Table;
1617
is $r.contents.elems, 4;
1718
is $r.contents[0].join('|'),
@@ -29,7 +30,7 @@ is $r.contents[3].join('|'),
2930
Subroutines 33
3031
Everything else 57
3132

32-
$r = $=pod[1];
33+
$r = $=pod[$p++];
3334
is $r.contents.elems, 4;
3435
is $r.contents[0].join('|'), "Constants|1";
3536
is $r.contents[1].join('|'), "Variables|10";
@@ -41,7 +42,7 @@ is $r.contents[3].join('|'), "Everything else|57";
4142
horse | horses
4243
elephant | elephants
4344
44-
$r = $=pod[2];
45+
$r = $=pod[$p++];
4546
is $r.contents.elems, 3;
4647
is $r.contents[0].join('|'), "mouse|mice";
4748
is $r.contents[1].join('|'), "horse|horses";
@@ -54,7 +55,7 @@ is $r.contents[2].join('|'), "elephant|elephants";
5455
Human + 2 + Pizza
5556
Shark + 0 + Fish
5657

57-
$r = $=pod[3];
58+
$r = $=pod[$p++];
5859
is $r.headers.join('|'), "Animal|Legs|Eats";
5960
is $r.contents.elems, 3;
6061
is $r.contents[0].join('|'), "Zebra|4|Cookies";
@@ -67,7 +68,7 @@ is $r.contents[2].join('|'), "Shark|0|Fish";
6768
==============|=================|================================
6869
The Shoveller | Eddie Stevens | King Arthur's singing shovel
6970

70-
$r = $=pod[4];
71+
$r = $=pod[$p++];
7172
is $r.headers.join('|'), "Superhero|Secret Identity|Superpower";
7273
is $r.contents.elems, 1;
7374
is $r.contents[0].join('|'),
@@ -90,7 +91,7 @@ is $r.contents[0].join('|'),
9091
9192
=end table
9293

93-
$r = $=pod[5];
94+
$r = $=pod[$p++];
9495
is $r.headers.join('|'), "Superhero|Secret Identity|Superpower";
9596
is $r.contents.elems, 4;
9697
is $r.contents[0].join('|'),
@@ -109,28 +110,10 @@ is $r.contents[3].join('|'),
109110
---+---+---
110111
| | X
111112

112-
$r = $=pod[6];
113-
is $r.contents.elems, 3;
114-
is $r.contents[0].join(','), 'X,O,',
115-
'ensure trailing whitespace counts as a cell (WARNING: this test will'
116-
~ ' fail if you modified this file and your editor auto-stripped'
117-
~ ' trailing whitespace)';
118-
is $r.contents[1].join(','), ',X,O';
119-
is $r.contents[2].join(','), ',,X';
120113

121-
=table
122-
X O
123-
===========
124-
X O
125-
===========
126-
X
127-
128-
$r = $=pod[7];
114+
$r = $=pod[$p++];
129115
is $r.contents.elems, 3;
130-
is $r.contents[0].join(','), 'X,O,',
131-
'ensure trailing whitespace counts as a cell (WARNING: this test will'
132-
~ ' fail if you modified this file and your editor auto-stripped'
133-
~ ' trailing whitespace)';
116+
is $r.contents[0].join(','), 'X,O,';
134117
is $r.contents[1].join(','), ',X,O';
135118
is $r.contents[2].join(','), ',,X';
136119

@@ -141,24 +124,5 @@ bar
141124
142125
=end table
143126

144-
$r = $=pod[8];
127+
$r = $=pod[$p++];
145128
is $r.contents.elems, 2;
146-
147-
# test for issue #129862
148-
# uneven rows
149-
150-
# NOTE: This test may need to change after planned table pod fixes are
151-
# made because this is a malformed table and the user should be warned
152-
# of that fact.
153-
154-
=begin table
155-
a | b | c
156-
l | m | n
157-
x | y
158-
=end table
159-
160-
$r = $=pod[9];
161-
is $r.contents.elems, 3;
162-
is $r.contents[0].join(','), 'a,b,c';
163-
is $r.contents[1].join(','), 'l,m,n';
164-
is $r.contents[2].join(','), 'x,y';

S26-documentation/07a-tables-todo-skipped.t

Lines changed: 0 additions & 57 deletions
This file was deleted.

S26-documentation/07a-tables.t

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
use v6;
2+
use Test;
3+
4+
my ($r, $p, $hdrs, @rows);
5+
$p = -1; # starting index for pod number
6+
7+
plan 37;
8+
9+
# includes tests for fixes for RT bugs:
10+
# 124403 - incorrect table parse:
11+
# 128221 - internal error
12+
# 129862 - uneven rows
13+
# 132341 - pad rows to add empty cells to ensure all rows have same number of cells
14+
# 132348 - handle inline Z<> comments on table rows
15+
16+
# test fix for RT #124403 - incorrect table parse:
17+
=table
18+
+-----+----+---+
19+
| a | b | c |
20+
+-----+----+---+
21+
| foo | 52 | Y |
22+
| bar | 17 | N |
23+
| dz | 9 | Y |
24+
+-----+----+---+
25+
26+
$r = $=pod[++$p];
27+
# tests
28+
is $r.headers.elems, 3;
29+
$hdrs = $r.headers.join('*');
30+
is $hdrs, "a*b*c";
31+
@rows = $r.contents>>.join('*');
32+
is $r.contents.elems, 3;
33+
is @rows[0], "foo*52*Y";
34+
is @rows[1], "bar*17*N";
35+
is @rows[2], "dz*9*Y";
36+
37+
# test fix for RT #128221
38+
# This test, with a '-r0c0' entry in
39+
# the single table row, column 0,
40+
# caused an exception.
41+
=begin table
42+
-r0c0 r0c1
43+
=end table
44+
$r = $=pod[++$p];
45+
is $r.contents.elems, 1;
46+
is $r.contents[0][0], "-r0c0"; # <= note leading hyphen which caused the original issue
47+
is $r.contents[0][1], "r0c1";
48+
49+
# an expanded test (per Zoffix) for issue #128221
50+
# note expected results have been corrected from that time
51+
=begin table
52+
-Col 1 | -Col 2 | _Col 3 | =Col 4
53+
=======+========+========+=======
54+
r0Col 1 | -r0Col 2 | _r0Col 3 | =r0Col 4
55+
-------|--------|--------|-------
56+
r1Col 1 | -r1Col 2 | _r1Col 3 | =r1Col 4
57+
r1 | r1Col 2 | _r1Col 3 | =r1Col 4
58+
-------|--------|--------|-------
59+
r2Col 1 | r2Col 2 | r2Col 3 | r2Col 4
60+
=end table
61+
$r = $=pod[++$p];
62+
$hdrs = $r.headers.join('|');
63+
@rows = $r.contents>>.join('|');
64+
65+
is $r.headers.elems, 4;
66+
is $r.contents.elems, 3;
67+
is $hdrs, "-Col 1|-Col 2|_Col 3|=Col 4"; # <= note leading hyphen which caused the original issue
68+
is @rows[0], "r0Col 1|-r0Col 2|_r0Col 3|=r0Col 4";
69+
is @rows[1], "r1Col 1 r1|-r1Col 2 r1Col 2|_r1Col 3 _r1Col 3|=r1Col 4 =r1Col 4", "test for merged cells";
70+
is @rows[2], "r2Col 1|r2Col 2|r2Col 3|r2Col 4";
71+
72+
# test fix for issue RT #129862
73+
# uneven rows
74+
=begin table
75+
a | b | c
76+
l | m | n
77+
x | y
78+
=end table
79+
80+
$r = $=pod[++$p];
81+
is $r.contents.elems, 3;
82+
is $r.contents[0].join(','), 'a,b,c';
83+
is $r.contents[1].join(','), 'l,m,n';
84+
is $r.contents[2].join(','), 'x,y,';
85+
86+
is $r.contents[0].elems, 3;
87+
is $r.contents[1].elems, 3;
88+
is $r.contents[2].elems, 3;
89+
90+
# test fix for RT #132341
91+
# also tests fix for RT #129862
92+
=table
93+
X O
94+
===========
95+
X O
96+
===========
97+
X
98+
99+
$r = $=pod[++$p];
100+
is $r.contents.elems, 3;
101+
is $r.contents[0].join(','), 'X,O,', "test for empty cell";
102+
is $r.contents[1].join(','), ',X,O';
103+
is $r.contents[2].join(','), ',,X';
104+
105+
is $r.contents[0].elems, 3;
106+
is $r.contents[1].elems, 3;
107+
is $r.contents[2].elems, 3;
108+
109+
# test fix for RT #132348 (allow inline Z comments)
110+
# also tests fix for RT #129862
111+
=begin table
112+
a | b | c
113+
l | m | n
114+
x | y Z<a comment> Z<another comment>
115+
=end table
116+
$r = $=pod[++$p];
117+
is $r.contents.elems, 3;
118+
is $r.contents[0].join(','), 'a,b,c';
119+
is $r.contents[1].join(','), 'l,m,n';
120+
is $r.contents[2].join(','), 'x,y,';
121+
122+
# a single column table, no headers
123+
=begin table
124+
a
125+
=end table
126+
127+
$r = $=pod[++$p];
128+
is $r.headers.elems, 0;
129+
is $r.contents.elems, 1;
130+
131+
# a single column table, with header
132+
=begin table
133+
b
134+
-
135+
a
136+
=end table
137+
138+
$r = $=pod[++$p];
139+
is $r.headers.elems, 1;
140+
is $r.contents.elems, 1;

S26-documentation/07b-tables.t

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use v6;
2+
use Test;
3+
4+
plan 4;
5+
6+
# test for the three designed fatal table failures
7+
8+
# empty tables should cause an exception
9+
my $table1 = qq:to/HERE/;
10+
=begin table
11+
=end table
12+
HERE
13+
14+
my $table2 = qq:to/HERE/;
15+
=table
16+
HERE
17+
18+
# consecutive row separators should cause an exception
19+
my $table3 = qq:to/HERE/;
20+
=table
21+
1 | 2 | 3
22+
=========
23+
=========
24+
4 | 5 | 6
25+
HERE
26+
27+
# mixed vis and ws col separators should cause an exception
28+
my $table4 = qq:to/HERE/;
29+
=table
30+
1 | 2 | 3
31+
4 5 6
32+
HERE
33+
34+
eval-dies-ok $table1, "dies-ok, empty table";
35+
eval-dies-ok $table2, "dies-ok, empty table";
36+
eval-dies-ok $table3, "dies-ok, consecutive row separators";
37+
eval-dies-ok $table4, "dies-ok, mixed ws and vis col separators";

0 commit comments

Comments
 (0)