Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/smoke/crossref/tables.test.ts
12921 views
1
/*
2
* tables.test.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*/
6
7
import { ensureFileRegexMatches, ensureHtmlElements } from "../../verify.ts";
8
import { renderVerifyLatexOutput, testRender } from "../render/render.ts";
9
import { crossref } from "./utils.ts";
10
import { docs } from "../../utils.ts";
11
12
/* HTML */
13
14
const tablesQmd = crossref("tables.qmd", "html");
15
testRender(tablesQmd.input, "html", false, [
16
ensureHtmlElements(tablesQmd.output.outputPath, [
17
// tables in figure elements
18
"section#simple-crossref-table > div#tbl-letters > figure table",
19
"section#sub-tables div.quarto-layout-panel > figure div.quarto-layout-row div#tbl-first > figure table",
20
"section#sub-tables div.quarto-layout-panel > figure div.quarto-layout-row div#tbl-second > figure table",
21
22
// table captions in figure elements (with and without subfloats)
23
"section#simple-crossref-table > div#tbl-letters > figure.quarto-float-tbl > figcaption.quarto-float-tbl.quarto-float-caption",
24
"section#sub-tables div#tbl-panel.quarto-layout-panel > figure.quarto-float-tbl > figcaption.quarto-float-tbl.quarto-float-caption",
25
"section#sub-tables div.quarto-layout-panel div.quarto-layout-row div#tbl-first > figure.quarto-subfloat-tbl > figcaption.quarto-subfloat-tbl.quarto-subfloat-caption",
26
"section#sub-tables div.quarto-layout-panel div.quarto-layout-row div#tbl-second > figure.quarto-subfloat-tbl > figcaption.quarto-subfloat-tbl.quarto-subfloat-caption",
27
]),
28
ensureFileRegexMatches(tablesQmd.output.outputPath, [
29
/Table 1: My Caption/,
30
/Table 2: Main Caption/,
31
/Table 1/,
32
/Table 2/,
33
/Table 2 \(b\)/,
34
/\(a\) First Table/,
35
/\(b\) Second Table/,
36
], [
37
/\?@tbl-/,
38
]),
39
]);
40
41
const knitrTablesQmd = crossref("knitr-tables.qmd", "html");
42
testRender(knitrTablesQmd.input, "html", false, [
43
ensureHtmlElements(knitrTablesQmd.output.outputPath, [
44
"div.quarto-layout-panel div.quarto-layout-row div#tbl-cars > figure.quarto-subfloat-tbl >figcaption.quarto-subfloat-tbl.quarto-subfloat-caption",
45
"div.quarto-layout-panel div.quarto-layout-row div#tbl-pressure > figure.quarto-subfloat-tbl > figcaption.quarto-subfloat-tbl.quarto-subfloat-caption",
46
]),
47
ensureFileRegexMatches(knitrTablesQmd.output.outputPath, [
48
/Table 1: Tables/,
49
/Table 1 \(a\)/,
50
/\(a\) Cars/,
51
/\(b\) Pressure/,
52
], [
53
/\?@tbl-/,
54
]),
55
]);
56
57
/* LaTeX */
58
59
/* caption is inserted in the right place in table environment*/
60
renderVerifyLatexOutput(docs("crossrefs/knitr-tables-latex.qmd"), [
61
/\\begin{longtable}\[.*\]{.*}.*\n+\\caption{\\label{tbl-1}.*}\n+.*\\tabularnewline/,
62
/\\begin{table}\n+\\caption{\\label{tbl-2}.*}.*\n+\\centering{?\n+\\begin{tabular}{.*}/,
63
/\\begin{longtable}{.*}.*\n+\\caption{\\label{tbl-3}.*}\n+.*\\tabularnewline/,
64
// two centering calls here is ugly, but we don't control the input we get
65
/\\begin{table}\n+\\caption{\\label{tbl-4}.*}.*\n+\\centering{?\n+\\centering\n+\\begin{tabular}\[c\]{.*}/,
66
]);
67
68