Cover report and geometry documents in the compatibility corpus

This commit is contained in:
gloamxun committed 2026-10-26 03:47:37 +08:00
1 parent 90cf2236ee
commit 3d01fbe589
3 files changed
+131 -9

No files matched your search

+127 -5
View File
@@ -120,7 +120,7 @@ pub fn project_preview_json_with_images(
(engine, changed, recomputed)
}
};
let mut warnings = source_warnings(source);
let mut warnings = source_warnings(source, &geometry);
warnings.extend(document_warnings(&document));
let json = render_json(
&document,
@@ -4285,7 +4285,7 @@ pub fn preview_json(source: &str) -> Result<String, String> {
let mut document = build_document(&paragraphs, &geometry);
apply_geometry(&mut document, &geometry);
let engine = layout_document(&document);
let mut warnings = source_warnings(source);
let mut warnings = source_warnings(source, &geometry);
warnings.extend(document_warnings(&document));
let json = render_json(&document, &engine, None, &geometry, &warnings);
// Keep the layout so a following `/edit` request can diff against it and
@@ -4433,7 +4433,7 @@ pub fn edit_json(source: &str, unit: usize) -> Result<String, String> {
}
let changed = engine.changed_pages().to_vec();
let recomputed = engine.recomputed_pages();
let mut warnings = source_warnings(source);
let mut warnings = source_warnings(source, &geometry);
warnings.extend(document_warnings(&next));
let json = render_json(
&next,
@@ -9247,7 +9247,7 @@ const SUPPORTED_ENVIRONMENTS: &[&str] = &[
];
/// Report environments that route-D would otherwise leave as literal text.
fn source_warnings(source: &str) -> Vec<String> {
fn source_warnings(source: &str, geometry: &PageGeometry) -> Vec<String> {
let mut warnings = Vec::new();
let mut rest = source;
while let Some(index) = rest.find("\\begin{") {
@@ -9257,7 +9257,15 @@ fn source_warnings(source: &str) -> Vec<String> {
};
let name = after[..close].trim();
let normalized = name.trim_end_matches('*');
if !SUPPORTED_ENVIRONMENTS.contains(&normalized) {
let declared = geometry
.theorem_definitions
.iter()
.any(|definition| definition.name == normalized)
|| geometry
.environments
.iter()
.any(|definition| definition.name == normalized);
if !SUPPORTED_ENVIRONMENTS.contains(&normalized) && !declared {
let message = format!("unsupported environment `{name}`");
if !warnings.contains(&message) {
warnings.push(message);
@@ -10382,6 +10390,120 @@ a & b
assert_eq!(geometry.macros.len(), 2);
}
#[test]
fn compatibility_report_document_is_warning_free() {
let source = r#"\documentclass{article}
\newcommand{\vect}[1]{\mathbf{#1}}
\newtheorem{claim}{Claim}
\newenvironment{note}{\begin{quote}}{\end{quote}}
\definecolor{accent}{HTML}{336699}
\begin{document}
\tableofcontents
\listoffigures
\section{Intro}\label{sec:intro}
Text with $\vect{x}$, \textcolor{accent}{accent} and \fcolorbox{red}{yellow}{box}.
\begin{claim}\label{cl:one}
A claim.
\end{claim}
\begin{note}
Quoted note.
\end{note}
\begin{itemize}
\item First
\begin{enumerate}
\item Nested
\end{enumerate}
\end{itemize}
\begin{center}
Centred.
\end{center}
\begin{figure}[t]
\rule{80pt}{30pt}
\caption{A figure}\label{fig:one}
\end{figure}
\begin{table}[h]
\begin{tabularx}{250pt}{lX}
A & wide cell text \\
\end{tabularx}
\caption{A table}\label{tab:one}
\end{table}
See \ref{sec:intro}, \ref{fig:one}, \pageref{tab:one}.
\appendix
\section{Extra}\label{sec:extra}
Appendix text.
\begin{thebibliography}{1}
\bibitem{k} Entry.
\end{thebibliography}
\end{document}
"#;
let json = preview_json(source).expect("preview");
assert!(json.contains("\"warnings\":[]"), "warnings: {}", json);
assert!(json.contains(">Q</text>"));
assert!(
json.contains("stroke=") && json.contains("#ff0000"),
"frame missing"
);
}
#[test]
fn compatibility_geometry_document_is_warning_free() {
let source = r#"\documentclass{article}
\usepackage[margin=1in]{geometry}
\linespread{1.15}
\hypersetup{pdftitle={Doc},urlcolor=blue,linkbordercolor=red}
\begin{document}
\setcounter{page}{3}
\section{One}\label{sec:one}
A footnote\footnote{Note.} and a link \href{https://example.com}{Example} plus \url{https://example.com/a_b}.
\begin{quotation}
Quoted paragraph with $a^2+b^2=c^2$ math.
\end{quotation}
\begin{tabular}{lc}
\hline
A & B \\
\hline
\end{tabular}
\begin{figure}[b]
\rule{60pt}{20pt}
\caption{Bottom figure}
\end{figure}
\newpage
Second page.
\end{document}
"#;
let json = preview_json(source).expect("preview");
assert!(json.contains("\"warnings\":[]"), "warnings: {}", json);
assert!(json.contains(">E</text>"));
assert!(
json.contains("fill=") && json.contains("#0000ff"),
"link colour missing"
);
assert!(
json.contains("stroke=") && json.contains("#ff0000"),
"link border missing"
);
}
#[test]
fn compatibility_sample_document_is_warning_free() {
let source = concat!(