diff options
Diffstat (limited to 'tests/suite/layout/table.typ')
| -rw-r--r-- | tests/suite/layout/table.typ | 284 |
1 files changed, 284 insertions, 0 deletions
diff --git a/tests/suite/layout/table.typ b/tests/suite/layout/table.typ new file mode 100644 index 00000000..7eec46a1 --- /dev/null +++ b/tests/suite/layout/table.typ @@ -0,0 +1,284 @@ +// Test tables. + +--- table-empty --- +#table() + +--- table-newlines --- +#set page(height: 70pt) +#set table(fill: (x, y) => if calc.even(x + y) { rgb("aaa") }) + +#table( + columns: (1fr,) * 3, + stroke: 2pt + rgb("333"), + [A], [B], [C], [], [], [D \ E \ F \ \ \ G], [H], +) + +--- table-fill-basic --- +#table(columns: 3, stroke: none, fill: green, [A], [B], [C]) + +--- table-fill-bad --- +// Error: 14-19 expected color, gradient, pattern, none, array, or function, found string +#table(fill: "hey") + +--- table-align-array --- +// Test alignment with array. +#table( + columns: (1fr, 1fr, 1fr), + align: (left, center, right), + [A], [B], [C] +) + +// Test empty array. +#set align(center) +#table( + columns: (1fr, 1fr, 1fr), + align: (), + [A], [B], [C] +) + +--- table-inset --- +// Test inset. +#table( + columns: 3, + inset: 10pt, + [A], [B], [C] +) + +#table( + columns: 3, + inset: (y: 10pt), + [A], [B], [C] +) + +#table( + columns: 3, + inset: (left: 20pt, rest: 10pt), + [A], [B], [C] +) + +#table( + columns: 2, + inset: ( + left: 20pt, + right: 5pt, + top: 10pt, + bottom: 3pt, + ), + [A], + [B], +) + +#table( + columns: 3, + fill: (x, y) => (if y == 0 { aqua } else { orange }).darken(x * 15%), + inset: (x, y) => (left: if x == 0 { 0pt } else { 5pt }, right: if x == 0 { 5pt } else { 0pt }, y: if y == 0 { 0pt } else { 5pt }), + [A], [B], [C], + [A], [B], [C], +) + +#table( + columns: 3, + inset: (0pt, 5pt, 10pt), + fill: (x, _) => aqua.darken(x * 15%), + [A], [B], [C], +) + +--- table-inset-fold --- +// Test inset folding +#set table(inset: 10pt) +#set table(inset: (left: 0pt)) + +#table( + fill: red, + inset: (right: 0pt), + table.cell(inset: (top: 0pt))[a] +) + +--- table-gutters --- +// Test interaction with gutters. +#table( + columns: (3em, 3em), + fill: (x, y) => (red, blue).at(calc.rem(x, 2)), + align: (x, y) => (left, right).at(calc.rem(y, 2)), + [A], [B], + [C], [D], + [E], [F], + [G], [H] +) + +#table( + columns: (3em, 3em), + fill: (x, y) => (red, blue).at(calc.rem(x, 2)), + align: (x, y) => (left, right).at(calc.rem(y, 2)), + row-gutter: 5pt, + [A], [B], + [C], [D], + [E], [F], + [G], [H] +) + +#table( + columns: (3em, 3em), + fill: (x, y) => (red, blue).at(calc.rem(x, 2)), + align: (x, y) => (left, right).at(calc.rem(y, 2)), + column-gutter: 5pt, + [A], [B], + [C], [D], + [E], [F], + [G], [H] +) + +#table( + columns: (3em, 3em), + fill: (x, y) => (red, blue).at(calc.rem(x, 2)), + align: (x, y) => (left, right).at(calc.rem(y, 2)), + gutter: 5pt, + [A], [B], + [C], [D], + [E], [F], + [G], [H] +) + +--- table-cell-override --- +// Cell override +#table( + align: left, + fill: red, + stroke: blue, + columns: 2, + [AAAAA], [BBBBB], + [A], [B], + table.cell(align: right)[C], [D], + align(right)[E], [F], + align(horizon)[G], [A\ A\ A], + table.cell(align: horizon)[G2], [A\ A\ A], + table.cell(inset: 0pt)[I], [F], + [H], table.cell(fill: blue)[J] +) + +--- table-cell-show --- +// Cell show rule +#show table.cell: it => [Zz] + +#table( + align: left, + fill: red, + stroke: blue, + columns: 2, + [AAAAA], [BBBBB], + [A], [B], + table.cell(align: right)[C], [D], + align(right)[E], [F], + align(horizon)[G], [A\ A\ A] +) + +--- table-cell-show-and-override --- +#show table.cell: it => (it.align, it.fill) +#table( + align: left, + row-gutter: 5pt, + [A], + table.cell(align: right)[B], + table.cell(fill: aqua)[B], +) + +--- table-cell-set --- +// Cell set rules +#set table.cell(align: center) +#show table.cell: it => (it.align, it.fill, it.inset) +#set table.cell(inset: 20pt) +#table( + align: left, + row-gutter: 5pt, + [A], + table.cell(align: right)[B], + table.cell(fill: aqua)[B], +) + +--- table-cell-folding --- +// Test folding per-cell properties (align and inset) +#table( + columns: (1fr, 1fr), + rows: (2.5em, auto), + align: right, + fill: (x, y) => (green, aqua).at(calc.rem(x + y, 2)), + [Top], table.cell(align: bottom)[Bot], + table.cell(inset: (bottom: 0pt))[Bot], table.cell(inset: (bottom: 0pt))[Bot] +) + +--- table-cell-align-override --- +// Test overriding outside alignment +#set align(bottom + right) +#table( + columns: (1fr, 1fr), + rows: 2em, + align: auto, + fill: green, + [BR], [BR], + table.cell(align: left, fill: aqua)[BL], table.cell(align: top, fill: red.lighten(50%))[TR] +) + +--- table-cell-various-overrides --- +#table( + columns: 2, + fill: green, + align: right, + [*Name*], [*Data*], + table.cell(fill: blue)[J.], [Organizer], + table.cell(align: center)[K.], [Leader], + [M.], table.cell(inset: 0pt)[Player] +) + +--- table-cell-show-emph --- +#{ + show table.cell: emph + table( + columns: 2, + [Person], [Animal], + [John], [Dog] + ) +} + +--- table-cell-show-based-on-position --- +// Style based on position +#{ + show table.cell: it => { + if it.y == 0 { + strong(it) + } else if it.x == 1 { + emph(it) + } else { + it + } + } + table( + columns: 3, + gutter: 3pt, + [Name], [Age], [Info], + [John], [52], [Nice], + [Mary], [50], [Cool], + [Jake], [49], [Epic] + ) +} + +--- grid-cell-in-table --- +// Error: 8-19 cannot use `grid.cell` as a table cell; use `table.cell` instead +#table(grid.cell[]) + +--- issue-183-table-lines --- +// Ensure no empty lines before a table that doesn't fit into the first page. +#set page(height: 50pt) + +Hello +#table( + columns: 4, + [1], [2], [3], [4] +) + +--- issue-1388-table-row-missing --- +// Test that a table row isn't wrongly treated like a gutter row. +#set page(height: 70pt) +#table( + rows: 16pt, + ..range(6).map(str).flatten(), +) |
