Debian Codegraph @

tests/testthat/test-format_character.R

raw
1 chartype_frame <- function() {
2 chars <- character()
3 desc <- character()
4
5 chars[1] <- "\u0001\u001f"
6 desc[1] <- "C0 control code"
7
8 chars[2] <- "\a\b\f\n\r\t"
9 desc[2] <- "Named control code"
10
11 chars[3] <- "abcdefuvwxyz"
12 desc[3] <- "ASCII"
13
14 chars[4] <- "\u0080\u009f"
15 desc[4] <- "C1 control code"
16
17 chars[5] <- paste0(
18 "\u00a0\u00a1\u00a2\u00a3\u00a4\u00a5",
19 "\u00fa\u00fb\u00fc\u00fd\u00fe\u00ff"
20 )
21 desc[5] <- "Latin-1"
22
23 chars[6] <- paste0(
24 "\u0100\u0101\u0102\u0103\u0104\u0105",
25 "\u0106\u0107\u0108\u0109\u010a\u010b"
26 )
27 desc[6] <- "Unicode"
28
29 chars[7] <- "\uff01\uff02\uff03\uff04\uff05\uff06"
30 desc[7] <- "Unicode wide"
31
32 chars[8] <- "\ue00\u2029"
33 desc[8] <- "Unicode control"
34
35 chars[9] <- paste0(
36 "x\u00adx\u200bx\u200cx\u200dx\u200ex\u200f",
37 "x\u034fx\ufeffx", intToUtf8(0xE0001), "x",
38 intToUtf8(0xE0020), "x", intToUtf8(0xE01EF), "x"
39 )
40 desc[9] <- "Unicode ignorable"
41
42 chars[10] <- paste0(
43 "a\u0300a\u0301a\u0302a\u0303a\u0304a\u0305",
44 "a\u0306a\u0307a\u0308a\u0309a\u030aa\u030b"
45 )
46 desc[10] <- "Unicode mark"
47
48 chars[11] <- paste0(
49 intToUtf8(0x1F600), intToUtf8(0x1F601),
50 intToUtf8(0x1F602), intToUtf8(0x1F603),
51 intToUtf8(0x1F604), intToUtf8(0x1F483)
52 )
53 desc[11] <- "Emoji"
54
55 chars[12] <- paste0("x", intToUtf8(0x10ffff), "x")
56 desc[12] <- "Unassigned"
57
58 chars[13] <- "\xfd\xfe\xff"
59 desc[13] <- "Invalid"
60
61 chars[14] <- "\\"
62 desc[14] <- "Backslash"
63
64 chars[15] <- '"'
65 desc[15] <- "Quote"
66
67 Encoding(chars) <- "UTF-8"
68
69 data.frame(chars, desc, stringsAsFactors = FALSE)
70 }
71
72 test_that("output test", {
73 expect_snapshot({
74 pillar(add_special(letters[1:5]))
75 pillar(add_special(paste(letters, collapse = "")))
76 pillar(add_special(paste(letters, collapse = "")), width = 10)
77 pillar(add_special(paste(letters, collapse = "")), width = 3)
78 pillar(add_special(c("")), width = 5)
79 pillar(add_special(c(" ")), width = 5)
80 pillar(add_special(c(" a")), width = 5)
81 pillar(add_special(c("a ")), width = 5)
82 pillar(add_special(c("a b")), width = 5)
83 pillar(add_special(c("\t")), width = 10)
84 pillar(add_special(c("a\nb")), width = 10)
85 pillar(add_special(c("a\001b")), width = 10)
86 })
87 })
88
89 test_that("output test (not on Windows)", {
90 skip_on_os("windows")
91
92 if (getRversion() == "4.0.4") {
93 # This seems to show differently on the Mac:
94 # writeLines(evaluate::evaluate('c("\\u6210", "\\u6210")')[[1]]$src)
95 skip_on_os("mac")
96 }
97
98 expect_snapshot({
99 pillar(add_special("\u6210\u4ea4\u65e5"), title = "\u6210\u4ea4")
100 pillar(add_special("\u6210\u4ea4"), title = "\u6210\u4ea4\u65e5")
101 pillar(add_special(1L), title = "\u6210\u4ea4\u65e5")
102 })
103
104 # Spurious warnings on Windows
105 skip_on_os("solaris")
106 suppressWarnings(
107 expect_snapshot({
108 ctl_colonnade(chartype_frame(), width = 50)
109 })
110 )
111 })