From 6edeefa90454f70eca5abcf60ea51f285072b250 Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Mon, 15 Jan 2024 20:11:35 -0500 Subject: [PATCH] tests --- inst/tinytest/_tinysnapshot/latex-align.txt | 27 +++++++++++ .../_tinysnapshot/latex-cell_color.txt | 25 +++++++++++ .../_tinysnapshot/latex-col_color.txt | 21 +++++++++ inst/tinytest/_tinysnapshot/latex-default.txt | 18 ++++++++ inst/tinytest/_tinysnapshot/latex-nohead.txt | 16 +++++++ .../_tinysnapshot/latex-row_color.txt | 21 +++++++++ .../_tinysnapshot/latex-theme_grid.txt | 17 +++++++ .../_tinysnapshot/latex-theme_striped.txt | 18 ++++++++ .../_tinysnapshot/latex-theme_void.txt | 15 +++++++ inst/tinytest/test-latex.R | 45 +++++++++++++++++++ 10 files changed, 223 insertions(+) create mode 100644 inst/tinytest/_tinysnapshot/latex-align.txt create mode 100644 inst/tinytest/_tinysnapshot/latex-cell_color.txt create mode 100644 inst/tinytest/_tinysnapshot/latex-col_color.txt create mode 100644 inst/tinytest/_tinysnapshot/latex-default.txt create mode 100644 inst/tinytest/_tinysnapshot/latex-nohead.txt create mode 100644 inst/tinytest/_tinysnapshot/latex-row_color.txt create mode 100644 inst/tinytest/_tinysnapshot/latex-theme_grid.txt create mode 100644 inst/tinytest/_tinysnapshot/latex-theme_striped.txt create mode 100644 inst/tinytest/_tinysnapshot/latex-theme_void.txt create mode 100644 inst/tinytest/test-latex.R diff --git a/inst/tinytest/_tinysnapshot/latex-align.txt b/inst/tinytest/_tinysnapshot/latex-align.txt new file mode 100644 index 00000000..d50e7a2d --- /dev/null +++ b/inst/tinytest/_tinysnapshot/latex-align.txt @@ -0,0 +1,27 @@ + +\begin{table} +\centering +\begin{tblr}[ %% tabularray outer open +] %% tabularray outer close +{ %% tabularray inner open +colspec={Q[]Q[]Q[]Q[]Q[]}, +column{1}={halign=c,}, +cell{1}{1}={}{halign=c,}, +column{2}={halign=c,}, +cell{1}{2}={}{halign=c,}, +column{3}={halign=l,}, +cell{1}{3}={}{halign=l,}, +column{4}={halign=l,}, +cell{1}{4}={}{halign=l,}, +column{5}={halign=r,}, +cell{1}{5}={}{halign=r,}, +} %% tabularray inner close +\toprule +mpg & cyl & disp & hp & drat \\ \midrule %% TinyTableHeader +21 & 6 & 160 & 110 & 3.9 \\ +21 & 6 & 160 & 110 & 3.9 \\ +22.8 & 4 & 108 & 93 & 3.85 \\ +21.4 & 6 & 258 & 110 & 3.08 \\ +\bottomrule +\end{tblr} +\end{table} diff --git a/inst/tinytest/_tinysnapshot/latex-cell_color.txt b/inst/tinytest/_tinysnapshot/latex-cell_color.txt new file mode 100644 index 00000000..accc7388 --- /dev/null +++ b/inst/tinytest/_tinysnapshot/latex-cell_color.txt @@ -0,0 +1,25 @@ + +\begin{table} +\centering +\begin{tblr}[ %% tabularray outer open +] %% tabularray outer close +{ %% tabularray inner open +colspec={Q[]Q[]Q[]Q[]Q[]}, +cell{2}{1}={}{,fg=orange,}, +cell{3}{1}={}{,fg=orange,}, +cell{2}{2}={}{,fg=orange,}, +cell{3}{2}={}{,fg=orange,}, +cell{2}{3}={}{,fg=orange,}, +cell{3}{3}={}{,fg=orange,}, +cell{2}{4}={}{,fg=orange,}, +cell{3}{4}={}{,fg=orange,}, +} %% tabularray inner close +\toprule +mpg & cyl & disp & hp & drat \\ \midrule %% TinyTableHeader +21 & 6 & 160 & 110 & 3.9 \\ +21 & 6 & 160 & 110 & 3.9 \\ +22.8 & 4 & 108 & 93 & 3.85 \\ +21.4 & 6 & 258 & 110 & 3.08 \\ +\bottomrule +\end{tblr} +\end{table} diff --git a/inst/tinytest/_tinysnapshot/latex-col_color.txt b/inst/tinytest/_tinysnapshot/latex-col_color.txt new file mode 100644 index 00000000..c2aa551f --- /dev/null +++ b/inst/tinytest/_tinysnapshot/latex-col_color.txt @@ -0,0 +1,21 @@ + +\begin{table} +\centering +\begin{tblr}[ %% tabularray outer open +] %% tabularray outer close +{ %% tabularray inner open +colspec={Q[]Q[]Q[]Q[]Q[]}, +column{1}={,fg=orange,}, +column{2}={,fg=orange,}, +column{3}={,fg=orange,}, +column{4}={,fg=orange,}, +} %% tabularray inner close +\toprule +mpg & cyl & disp & hp & drat \\ \midrule %% TinyTableHeader +21 & 6 & 160 & 110 & 3.9 \\ +21 & 6 & 160 & 110 & 3.9 \\ +22.8 & 4 & 108 & 93 & 3.85 \\ +21.4 & 6 & 258 & 110 & 3.08 \\ +\bottomrule +\end{tblr} +\end{table} diff --git a/inst/tinytest/_tinysnapshot/latex-default.txt b/inst/tinytest/_tinysnapshot/latex-default.txt new file mode 100644 index 00000000..183f3d55 --- /dev/null +++ b/inst/tinytest/_tinysnapshot/latex-default.txt @@ -0,0 +1,18 @@ + +\begin{table} +\centering +\begin{tblr}[ %% tabularray outer open +] %% tabularray outer close +{ %% tabularray inner open +colspec={Q[]Q[]Q[]Q[]Q[]}, +row{even}={bg=black!5!white}, +} %% tabularray inner close +\toprule +mpg & cyl & disp & hp & drat \\ \midrule %% TinyTableHeader +21 & 6 & 160 & 110 & 3.9 \\ +21 & 6 & 160 & 110 & 3.9 \\ +22.8 & 4 & 108 & 93 & 3.85 \\ +21.4 & 6 & 258 & 110 & 3.08 \\ +\bottomrule +\end{tblr} +\end{table} diff --git a/inst/tinytest/_tinysnapshot/latex-nohead.txt b/inst/tinytest/_tinysnapshot/latex-nohead.txt new file mode 100644 index 00000000..3eb3bdc6 --- /dev/null +++ b/inst/tinytest/_tinysnapshot/latex-nohead.txt @@ -0,0 +1,16 @@ + +\begin{table} +\centering +\begin{tblr}[ %% tabularray outer open +] %% tabularray outer close +{ %% tabularray inner open +colspec={Q[]Q[]Q[]Q[]Q[]}, +} %% tabularray inner close +\toprule +21 & 6 & 160 & 110 & 3.9 \\ +21 & 6 & 160 & 110 & 3.9 \\ +22.8 & 4 & 108 & 93 & 3.85 \\ +21.4 & 6 & 258 & 110 & 3.08 \\ +\bottomrule +\end{tblr} +\end{table} diff --git a/inst/tinytest/_tinysnapshot/latex-row_color.txt b/inst/tinytest/_tinysnapshot/latex-row_color.txt new file mode 100644 index 00000000..4ad4e5cf --- /dev/null +++ b/inst/tinytest/_tinysnapshot/latex-row_color.txt @@ -0,0 +1,21 @@ + +\begin{table} +\centering +\begin{tblr}[ %% tabularray outer open +] %% tabularray outer close +{ %% tabularray inner open +colspec={Q[]Q[]Q[]Q[]Q[]}, +row{2}={,fg=orange,}, +row{3}={,fg=orange,}, +row{4}={,fg=orange,}, +row{5}={,fg=orange,}, +} %% tabularray inner close +\toprule +mpg & cyl & disp & hp & drat \\ \midrule %% TinyTableHeader +21 & 6 & 160 & 110 & 3.9 \\ +21 & 6 & 160 & 110 & 3.9 \\ +22.8 & 4 & 108 & 93 & 3.85 \\ +21.4 & 6 & 258 & 110 & 3.08 \\ +\bottomrule +\end{tblr} +\end{table} diff --git a/inst/tinytest/_tinysnapshot/latex-theme_grid.txt b/inst/tinytest/_tinysnapshot/latex-theme_grid.txt new file mode 100644 index 00000000..314dfc4a --- /dev/null +++ b/inst/tinytest/_tinysnapshot/latex-theme_grid.txt @@ -0,0 +1,17 @@ + +\begin{table} +\centering +\begin{tblr}[ %% tabularray outer open +] %% tabularray outer close +{ %% tabularray inner open +hlines,vlines, +colspec={Q[]Q[]Q[]Q[]Q[]}, +hlines={},vlines={}, +} %% tabularray inner close +mpg & cyl & disp & hp & drat \\ +21 & 6 & 160 & 110 & 3.9 \\ +21 & 6 & 160 & 110 & 3.9 \\ +22.8 & 4 & 108 & 93 & 3.85 \\ +21.4 & 6 & 258 & 110 & 3.08 \\ +\end{tblr} +\end{table} diff --git a/inst/tinytest/_tinysnapshot/latex-theme_striped.txt b/inst/tinytest/_tinysnapshot/latex-theme_striped.txt new file mode 100644 index 00000000..183f3d55 --- /dev/null +++ b/inst/tinytest/_tinysnapshot/latex-theme_striped.txt @@ -0,0 +1,18 @@ + +\begin{table} +\centering +\begin{tblr}[ %% tabularray outer open +] %% tabularray outer close +{ %% tabularray inner open +colspec={Q[]Q[]Q[]Q[]Q[]}, +row{even}={bg=black!5!white}, +} %% tabularray inner close +\toprule +mpg & cyl & disp & hp & drat \\ \midrule %% TinyTableHeader +21 & 6 & 160 & 110 & 3.9 \\ +21 & 6 & 160 & 110 & 3.9 \\ +22.8 & 4 & 108 & 93 & 3.85 \\ +21.4 & 6 & 258 & 110 & 3.08 \\ +\bottomrule +\end{tblr} +\end{table} diff --git a/inst/tinytest/_tinysnapshot/latex-theme_void.txt b/inst/tinytest/_tinysnapshot/latex-theme_void.txt new file mode 100644 index 00000000..ed206c82 --- /dev/null +++ b/inst/tinytest/_tinysnapshot/latex-theme_void.txt @@ -0,0 +1,15 @@ + +\begin{table} +\centering +\begin{tblr}[ %% tabularray outer open +] %% tabularray outer close +{ %% tabularray inner open +colspec={Q[]Q[]Q[]Q[]Q[]}, +} %% tabularray inner close +mpg & cyl & disp & hp & drat \\ +21 & 6 & 160 & 110 & 3.9 \\ +21 & 6 & 160 & 110 & 3.9 \\ +22.8 & 4 & 108 & 93 & 3.85 \\ +21.4 & 6 & 258 & 110 & 3.08 \\ +\end{tblr} +\end{table} diff --git a/inst/tinytest/test-latex.R b/inst/tinytest/test-latex.R new file mode 100644 index 00000000..d9c2f4be --- /dev/null +++ b/inst/tinytest/test-latex.R @@ -0,0 +1,45 @@ +source("helpers.R") +using("tinysnapshot") + +x <- mtcars[1:4, 1:5] + +expect_snapshot_print( + tt(x, output = "latex", theme = "striped"), + label = "latex-default") + +k <- x +colnames(k) <- NULL +expect_snapshot_print( + tt(k, output = "latex"), + label = "latex-nohead") + +# Align +expect_snapshot_print( + tt(x, output = "latex", align = "ccllr"), + label = "latex-align") + +# Themes +expect_snapshot_print( + tt(x, output = "latex", theme = "striped"), + label = "latex-theme_striped") + +expect_snapshot_print( + tt(x, output = "latex", theme = "grid"), + label = "latex-theme_grid") + +expect_snapshot_print( + tt(x, output = "latex", theme = "void"), + label = "latex-theme_void") + +# Styles +expect_snapshot_print( + tt(x, output = "latex") |> style_tt(i = 1:4, color = "orange"), + label = "latex-row_color") + +expect_snapshot_print( + tt(x, output = "latex") |> style_tt(j = 1:4, color = "orange"), + label = "latex-col_color") + +expect_snapshot_print( + tt(x, output = "latex") |> style_tt(i = 1:2, j = 1:4, color = "orange"), + label = "latex-cell_color")