Debian Codegraph @

tests/testthat/test-tbl-format-setup.R

raw
1 test_that("output test", {
2 x <- new_tbl(list(
3 column_zero_zero = 1:3 + 0.23,
4 `col 01` = new_tbl(list(
5 `col 02` = letters[1:3],
6 `col 03` = LETTERS[1:3],
7 `col 04` = matrix(1:9, nrow = 3, dimnames = list(letters[1:3], LETTERS[1:3]))
8 )),
9 `col 05` = ordered(letters[1:3])
10 ))
11
12 expect_snapshot({
13 options(width = 100)
14 tbl_format_setup(x, width = 4)
15 tbl_format_setup(x, width = 5)
16 tbl_format_setup(x, width = 6)
17 tbl_format_setup(x, width = 7)
18 tbl_format_setup(x, width = 8)
19 tbl_format_setup(x, width = 9)
20 tbl_format_setup(x, width = 10)
21 tbl_format_setup(x, width = 11)
22 tbl_format_setup(x, width = 12)
23 tbl_format_setup(x, width = 13)
24 tbl_format_setup(x, width = 14)
25 tbl_format_setup(x, width = 15)
26 tbl_format_setup(x, width = 16)
27 tbl_format_setup(x, width = 17)
28 tbl_format_setup(x, width = 18)
29 tbl_format_setup(x, width = 19)
30 tbl_format_setup(x, width = 20)
31 tbl_format_setup(x, width = 21)
32 tbl_format_setup(x, width = 22)
33 tbl_format_setup(x, width = 23)
34 tbl_format_setup(x, width = 24)
35 tbl_format_setup(x, width = 25)
36 tbl_format_setup(x, width = 26)
37 tbl_format_setup(x, width = 27)
38 tbl_format_setup(x, width = 28)
39 tbl_format_setup(x, width = 29)
40 tbl_format_setup(x, width = 30)
41 tbl_format_setup(x, width = 31)
42 tbl_format_setup(x, width = 32)
43 tbl_format_setup(x, width = 33)
44 tbl_format_setup(x, width = 34)
45 tbl_format_setup(x, width = 35)
46 tbl_format_setup(x, width = 36)
47 tbl_format_setup(x, width = 37)
48 tbl_format_setup(x, width = 38)
49 tbl_format_setup(x, width = 39)
50 tbl_format_setup(x, width = 40)
51 tbl_format_setup(x, width = 41)
52 tbl_format_setup(x, width = 42)
53 tbl_format_setup(x, width = 43)
54 tbl_format_setup(x, width = 44)
55 tbl_format_setup(x, width = 45)
56 tbl_format_setup(x, width = 46)
57 tbl_format_setup(x, width = 47)
58 tbl_format_setup(x, width = 48)
59 tbl_format_setup(x, width = 49)
60 tbl_format_setup(x, width = 50)
61 tbl_format_setup(x, width = 51)
62 tbl_format_setup(x, width = 52)
63 tbl_format_setup(x, width = 53)
64 tbl_format_setup(x, width = 54)
65 tbl_format_setup(x, width = 55)
66 tbl_format_setup(x, width = 56)
67 tbl_format_setup(x, width = 57)
68 tbl_format_setup(x, width = 58)
69 tbl_format_setup(x, width = 59)
70 tbl_format_setup(x, width = 60)
71 tbl_format_setup(x, width = 61)
72 tbl_format_setup(x, width = 62)
73 tbl_format_setup(x, width = 63)
74 tbl_format_setup(x, width = 64)
75 tbl_format_setup(x, width = 65)
76 tbl_format_setup(x, width = 66)
77 tbl_format_setup(x, width = 67)
78 tbl_format_setup(x, width = 68)
79 tbl_format_setup(x, width = 69)
80 tbl_format_setup(x, width = 70)
81 tbl_format_setup(x, width = 71)
82 tbl_format_setup(x, width = 72)
83 tbl_format_setup(x, width = 73)
84 tbl_format_setup(x, width = 74)
85 tbl_format_setup(x, width = 75)
86 tbl_format_setup(x, width = 76)
87 tbl_format_setup(x, width = 77)
88 tbl_format_setup(x, width = 78)
89 tbl_format_setup(x, width = 79)
90 tbl_format_setup(x, width = 80)
91 tbl_format_setup(x, width = 81)
92 tbl_format_setup(x, width = 82)
93 tbl_format_setup(x, width = 83)
94 tbl_format_setup(x, width = 84)
95 tbl_format_setup(x, width = 85)
96 tbl_format_setup(x, width = 86)
97 tbl_format_setup(x, width = 87)
98 tbl_format_setup(x, width = 88)
99 tbl_format_setup(x, width = 89)
100 tbl_format_setup(x, width = Inf)
101 })
102 })
103
104 test_that("tbl_format_setup() results", {
105 local_unknown_rows()
106
107 expect_snapshot({
108 tbl_format_setup(as_tbl(mtcars), width = 80)
109
110 tbl_format_setup(as_tbl(mtcars), width = 30, n = 8)
111
112 tbl_format_setup(as_tbl(trees), width = 30, n = 100)
113
114 "Unknown rows"
115 tbl_format_setup(as_unknown_rows(trees[1:9, ]), width = 30, n = 10)
116
117 tbl_format_setup(as_unknown_rows(trees[1:10, ]), width = 30, n = 10)
118
119 tbl_format_setup(as_unknown_rows(trees[1:11, ]), width = 30, n = 10)
120
121 "No rows"
122 tbl_format_setup(new_tbl(list(a = character(), b = logical())), width = 30)
123
124 "No columns"
125 tbl_format_setup(as_tbl(trees[character()]), width = 30, n = 5L)
126
127 "No rows, unknown"
128 tbl_format_setup(as_unknown_rows(trees[integer(), ]), width = 30, n = 5L)
129
130 "No columns, unknown"
131 tbl_format_setup(as_unknown_rows(trees[, character()]), width = 30, n = 5L)
132
133 "Long table, unknown"
134 tbl_format_setup(
135 as_unknown_rows(new_tbl(list(a = seq.int(10000)))),
136 n = 5L,
137 width = 30L
138 )
139
140 "Long table, unknown, default"
141 tbl_format_setup(
142 as_unknown_rows(new_tbl(list(a = seq.int(5)))),
143 n = structure(3, max = 6),
144 width = 60L
145 )
146 })
147 })
148
149 test_that("tbl_format_setup() for footnotes", {
150 expect_snapshot({
151 tbl_format_setup(width = 73, as_tbl(data_frame(
152 xxxabc = 1,
153 xxxdef = 1,
154 xxxghi = 1,
155 xxxjkl = 1,
156 xxxmno = 1,
157 xxxpqr = 1,
158 xxxstu = 1,
159 xxxvwx = 1,
160 xxxyza = 1,
161 xxxbcd = 1,
162 xxxefg = 1,
163 xxxhij = 1,
164 xxxklm = 1,
165 xxxnop = 1
166 )))
167 })
168 })
169
170
171 test_that("tbl_format_setup() for footnotes with min_title_chars = 4", {
172 local_pillar_option_min_title_chars(4)
173
174 expect_snapshot({
175 tbl_format_setup(width = 73, as_tbl(data_frame(
176 xxxabc = 1,
177 xxxdef = 1,
178 xxxghi = 1,
179 xxxjkl = 1,
180 xxxmno = 1,
181 xxxpqr = 1,
182 xxxstu = 1,
183 xxxvwx = 1,
184 xxxyza = 1,
185 xxxbcd = 1,
186 xxxefg = 1,
187 xxxhij = 1,
188 xxxklm = 1,
189 xxxnop = 1
190 )))
191 })
192 })
193
194 test_that("tbl_format_setup() for footnotes with UTF-8 output", {
195 skip_if(!l10n_info()$`UTF-8`)
196
197 local_utf8()
198
199 expect_snapshot({
200 tbl_format_setup(width = 73, as_tbl(data_frame(
201 xxxabc = 1,
202 xxxdef = 1,
203 xxxghi = 1,
204 xxxjkl = 1,
205 xxxmno = 1,
206 xxxpqr = 1,
207 xxxstu = 1,
208 xxxvwx = 1,
209 xxxyza = 1,
210 xxxbcd = 1,
211 xxxefg = 1,
212 xxxhij = 1,
213 xxxklm = 1,
214 xxxnop = 1
215 )))
216 })
217 })