Path: blob/main/tests/smoke/crossref/docx.test.ts
12925 views
/*1* latex.test.ts2*3* Copyright (C) 2020-2022 Posit Software, PBC4*5*/67import { ensureDocxRegexMatches } from "../../verify.ts";8import { testRender } from "../render/render.ts";9import { crossref } from "./utils.ts";1011const allQmd = crossref("all-docx.qmd", "docx");1213function bookmarkStart(name: string) {14return RegExp(15`<w:bookmarkStart[\\s]*w:id="[0-9]+"[\\s]*w:name="${name}"[\\s]*\\/>`,16);17}1819function anchor(name: string) {20return RegExp(21`<w:hyperlink w:anchor="${name}">`,22);23}2425function text(text: string) {26return RegExp(27`>${text}<`,28);29}3031const simpleFigRegexes = [32bookmarkStart("fig-elephant"),33anchor("fig-elephant"),34// These tests no longer pass after we started introducing non-breaking35// spaces between 'Figure' and '1' (although upon cracking the file36// it seems like there are no non-breaking spaces and these strings37// are in fact in the file)38text("Figure\\u00A01: Elephant"),39text("Figure\\u00A01"),40];4142const tableRegexes = [43bookmarkStart("tbl-letters"),44anchor("tbl-letters"),45// (see comment above re: non-breaking spaces)46text("Table\\u00A01: My Caption"),47];4849const mathRegexes = [50text("Theorem 1 \\(Line\\)"),51bookmarkStart("thm-line"),52anchor("thm-line"),53];5455const _subTableRegexes = [56bookmarkStart("tbl-first"),57bookmarkStart("tbl-second"),58anchor("tbl-first"),59anchor("tbl-second"),60text("Table 2: Main Caption"),61text("(a) First Table"),62text("(b) Second Table"),63];6465const _subFigRegexes = [66bookmarkStart("fig-elephants"),67bookmarkStart("fig-abbas"),68bookmarkStart("fig-surus"),69anchor("fig-elephants"),70anchor("fig-abbas"),71anchor("fig-surus"),72text("Figure 2: Famous Elephants"),73text("Figure 2"),74text("Figure 2 (b)"),75];7677testRender(allQmd.input, "docx", true, [78ensureDocxRegexMatches(allQmd.output.outputPath, [79...simpleFigRegexes,80...tableRegexes,81...mathRegexes,82// ...subFigRegexes,83// ...subTableRegexes,84]),85]);868788