File: test-tbl-format-setup.R

package info (click to toggle)
r-cran-pillar 1.8.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,840 kB
  • sloc: sh: 13; makefile: 2
file content (210 lines) | stat: -rw-r--r-- 5,823 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
test_that("output test", {
  x <- new_tbl(list(
    column_zero_zero = 1:3 + 0.23,
    `col 01` = new_tbl(list(
      `col 02` = letters[1:3],
      `col 03` = LETTERS[1:3],
      `col 04` = matrix(1:9, nrow = 3, dimnames = list(letters[1:3], LETTERS[1:3]))
    )),
    `col 05` = ordered(letters[1:3])
  ))

  expect_snapshot({
    options(width = 100)
    tbl_format_setup(x, width = 4)
    tbl_format_setup(x, width = 5)
    tbl_format_setup(x, width = 6)
    tbl_format_setup(x, width = 7)
    tbl_format_setup(x, width = 8)
    tbl_format_setup(x, width = 9)
    tbl_format_setup(x, width = 10)
    tbl_format_setup(x, width = 11)
    tbl_format_setup(x, width = 12)
    tbl_format_setup(x, width = 13)
    tbl_format_setup(x, width = 14)
    tbl_format_setup(x, width = 15)
    tbl_format_setup(x, width = 16)
    tbl_format_setup(x, width = 17)
    tbl_format_setup(x, width = 18)
    tbl_format_setup(x, width = 19)
    tbl_format_setup(x, width = 20)
    tbl_format_setup(x, width = 21)
    tbl_format_setup(x, width = 22)
    tbl_format_setup(x, width = 23)
    tbl_format_setup(x, width = 24)
    tbl_format_setup(x, width = 25)
    tbl_format_setup(x, width = 26)
    tbl_format_setup(x, width = 27)
    tbl_format_setup(x, width = 28)
    tbl_format_setup(x, width = 29)
    tbl_format_setup(x, width = 30)
    tbl_format_setup(x, width = 31)
    tbl_format_setup(x, width = 32)
    tbl_format_setup(x, width = 33)
    tbl_format_setup(x, width = 34)
    tbl_format_setup(x, width = 35)
    tbl_format_setup(x, width = 36)
    tbl_format_setup(x, width = 37)
    tbl_format_setup(x, width = 38)
    tbl_format_setup(x, width = 39)
    tbl_format_setup(x, width = 40)
    tbl_format_setup(x, width = 41)
    tbl_format_setup(x, width = 42)
    tbl_format_setup(x, width = 43)
    tbl_format_setup(x, width = 44)
    tbl_format_setup(x, width = 45)
    tbl_format_setup(x, width = 46)
    tbl_format_setup(x, width = 47)
    tbl_format_setup(x, width = 48)
    tbl_format_setup(x, width = 49)
    tbl_format_setup(x, width = 50)
    tbl_format_setup(x, width = 51)
    tbl_format_setup(x, width = 52)
    tbl_format_setup(x, width = 53)
    tbl_format_setup(x, width = 54)
    tbl_format_setup(x, width = 55)
    tbl_format_setup(x, width = 56)
    tbl_format_setup(x, width = 57)
    tbl_format_setup(x, width = 58)
    tbl_format_setup(x, width = 59)
    tbl_format_setup(x, width = 60)
    tbl_format_setup(x, width = 61)
    tbl_format_setup(x, width = 62)
    tbl_format_setup(x, width = 63)
    tbl_format_setup(x, width = 64)
    tbl_format_setup(x, width = 65)
    tbl_format_setup(x, width = 66)
    tbl_format_setup(x, width = 67)
    tbl_format_setup(x, width = 68)
    tbl_format_setup(x, width = 69)
    tbl_format_setup(x, width = 70)
    tbl_format_setup(x, width = 71)
    tbl_format_setup(x, width = 72)
    tbl_format_setup(x, width = 73)
    tbl_format_setup(x, width = 74)
    tbl_format_setup(x, width = 75)
    tbl_format_setup(x, width = 76)
    tbl_format_setup(x, width = 77)
    tbl_format_setup(x, width = 78)
    tbl_format_setup(x, width = 79)
    tbl_format_setup(x, width = 80)
    tbl_format_setup(x, width = 81)
    tbl_format_setup(x, width = 82)
    tbl_format_setup(x, width = 83)
    tbl_format_setup(x, width = 84)
    tbl_format_setup(x, width = 85)
    tbl_format_setup(x, width = 86)
    tbl_format_setup(x, width = 87)
    tbl_format_setup(x, width = 88)
    tbl_format_setup(x, width = 89)
    tbl_format_setup(x, width = Inf)
  })
})

test_that("tbl_format_setup() results", {
  local_unknown_rows()

  expect_snapshot({
    tbl_format_setup(as_tbl(mtcars), width = 80)

    tbl_format_setup(as_tbl(mtcars), width = 30, n = 8)

    tbl_format_setup(as_tbl(trees), width = 30, n = 100)

    "Unknown rows"
    tbl_format_setup(as_unknown_rows(trees[1:9, ]), width = 30, n = 10)

    tbl_format_setup(as_unknown_rows(trees[1:10, ]), width = 30, n = 10)

    tbl_format_setup(as_unknown_rows(trees[1:11, ]), width = 30, n = 10)

    "No rows"
    tbl_format_setup(new_tbl(list(a = character(), b = logical())), width = 30)

    "No columns"
    tbl_format_setup(as_tbl(trees[character()]), width = 30, n = 5L)

    "No rows, unknown"
    tbl_format_setup(as_unknown_rows(trees[integer(), ]), width = 30, n = 5L)

    "No columns, unknown"
    tbl_format_setup(as_unknown_rows(trees[, character()]), width = 30, n = 5L)

    "Long table, unknown"
    tbl_format_setup(
      as_unknown_rows(new_tbl(list(a = seq.int(10000)))),
      n = 5L,
      width = 30L
    )
  })
})

test_that("tbl_format_setup() for footnotes", {
  expect_snapshot({
    tbl_format_setup(width = 73, as_tbl(data_frame(
      xxxabc = 1,
      xxxdef = 1,
      xxxghi = 1,
      xxxjkl = 1,
      xxxmno = 1,
      xxxpqr = 1,
      xxxstu = 1,
      xxxvwx = 1,
      xxxyza = 1,
      xxxbcd = 1,
      xxxefg = 1,
      xxxhij = 1,
      xxxklm = 1,
      xxxnop = 1
    )))
  })
})


test_that("tbl_format_setup() for footnotes with min_title_chars = 4", {
  local_pillar_option_min_title_chars(4)

  expect_snapshot({
    tbl_format_setup(width = 73, as_tbl(data_frame(
      xxxabc = 1,
      xxxdef = 1,
      xxxghi = 1,
      xxxjkl = 1,
      xxxmno = 1,
      xxxpqr = 1,
      xxxstu = 1,
      xxxvwx = 1,
      xxxyza = 1,
      xxxbcd = 1,
      xxxefg = 1,
      xxxhij = 1,
      xxxklm = 1,
      xxxnop = 1
    )))
  })
})

test_that("tbl_format_setup() for footnotes with UTF-8 output", {
  skip_if(!l10n_info()$`UTF-8`)

  local_utf8()

  expect_snapshot({
    tbl_format_setup(width = 73, as_tbl(data_frame(
      xxxabc = 1,
      xxxdef = 1,
      xxxghi = 1,
      xxxjkl = 1,
      xxxmno = 1,
      xxxpqr = 1,
      xxxstu = 1,
      xxxvwx = 1,
      xxxyza = 1,
      xxxbcd = 1,
      xxxefg = 1,
      xxxhij = 1,
      xxxklm = 1,
      xxxnop = 1
    )))
  })
})