@@ -21,6 +21,162 @@ skip_if_not_available("utf8proc")
21
21
library(dplyr )
22
22
library(stringr )
23
23
24
+ test_that(" paste, paste0, and str_c" , {
25
+ df <- tibble(
26
+ v = c(" A" , " B" , " C" ),
27
+ w = c(" a" , " b" , " c" ),
28
+ x = c(" d" , NA_character_ , " f" ),
29
+ y = c(NA_character_ , " h" , " i" ),
30
+ z = c(1.1 , 2.2 , NA )
31
+ )
32
+ x <- Expression $ field_ref(" x" )
33
+ y <- Expression $ field_ref(" y" )
34
+
35
+ # no NAs in data
36
+ expect_dplyr_equal(
37
+ input %> %
38
+ transmute(paste(v , w )) %> %
39
+ collect(),
40
+ df
41
+ )
42
+ expect_dplyr_equal(
43
+ input %> %
44
+ transmute(paste(v , w , sep = " -" )) %> %
45
+ collect(),
46
+ df
47
+ )
48
+ expect_dplyr_equal(
49
+ input %> %
50
+ transmute(paste0(v , w )) %> %
51
+ collect(),
52
+ df
53
+ )
54
+ expect_dplyr_equal(
55
+ input %> %
56
+ transmute(str_c(v , w )) %> %
57
+ collect(),
58
+ df
59
+ )
60
+ expect_dplyr_equal(
61
+ input %> %
62
+ transmute(str_c(v , w , sep = " +" )) %> %
63
+ collect(),
64
+ df
65
+ )
66
+
67
+ # NAs in data
68
+ expect_dplyr_equal(
69
+ input %> %
70
+ transmute(paste(x , y )) %> %
71
+ collect(),
72
+ df
73
+ )
74
+ expect_dplyr_equal(
75
+ input %> %
76
+ transmute(paste(x , y , sep = " -" )) %> %
77
+ collect(),
78
+ df
79
+ )
80
+ expect_dplyr_equal(
81
+ input %> %
82
+ transmute(str_c(x , y )) %> %
83
+ collect(),
84
+ df
85
+ )
86
+
87
+ # non-character column in dots
88
+ expect_dplyr_equal(
89
+ input %> %
90
+ transmute(paste0(x , y , z )) %> %
91
+ collect(),
92
+ df
93
+ )
94
+
95
+ # literal string in dots
96
+ expect_dplyr_equal(
97
+ input %> %
98
+ transmute(paste(x , " foo" , y )) %> %
99
+ collect(),
100
+ df
101
+ )
102
+
103
+ # literal NA in dots
104
+ expect_dplyr_equal(
105
+ input %> %
106
+ transmute(paste(x , NA , y )) %> %
107
+ collect(),
108
+ df
109
+ )
110
+
111
+ # expressions in dots
112
+ expect_dplyr_equal(
113
+ input %> %
114
+ transmute(paste0(x , toupper(y ), as.character(z ))) %> %
115
+ collect(),
116
+ df
117
+ )
118
+
119
+ # sep is literal NA
120
+ # errors in paste() (consistent with base::paste())
121
+ expect_error(
122
+ nse_funcs $ paste(x , y , sep = NA_character_ ),
123
+ " Invalid separator"
124
+ )
125
+ # emits null in str_c() (consistent with stringr::str_c())
126
+ expect_dplyr_equal(
127
+ input %> %
128
+ transmute(str_c(x , y , sep = NA_character_ )) %> %
129
+ collect(),
130
+ df
131
+ )
132
+
133
+ # sep passed in dots to paste0 (which doesn't take a sep argument)
134
+ expect_dplyr_equal(
135
+ input %> %
136
+ transmute(paste0(x , y , sep = " -" )) %> %
137
+ collect(),
138
+ df
139
+ )
140
+
141
+ # known differences
142
+
143
+ # arrow allows the separator to be an array
144
+ expect_equal(
145
+ df %> %
146
+ Table $ create() %> %
147
+ transmute(result = paste(x , y , sep = w )) %> %
148
+ collect(),
149
+ df %> %
150
+ transmute(result = paste(x , w , y , sep = " " ))
151
+ )
152
+
153
+ # expected errors
154
+
155
+ # collapse argument not supported
156
+ expect_error(
157
+ nse_funcs $ paste(x , y , collapse = " " ),
158
+ " collapse"
159
+ )
160
+ expect_error(
161
+ nse_funcs $ paste0(x , y , collapse = " " ),
162
+ " collapse"
163
+ )
164
+ expect_error(
165
+ nse_funcs $ str_c(x , y , collapse = " " ),
166
+ " collapse"
167
+ )
168
+
169
+ # literal vectors of length != 1 not supported
170
+ expect_error(
171
+ nse_funcs $ paste(x , character (0 ), y ),
172
+ " Literal vectors of length != 1 not supported in string concatenation"
173
+ )
174
+ expect_error(
175
+ nse_funcs $ paste(x , c(" ," , " ;" ), y ),
176
+ " Literal vectors of length != 1 not supported in string concatenation"
177
+ )
178
+ })
179
+
24
180
test_that(" grepl with ignore.case = FALSE and fixed = TRUE" , {
25
181
df <- tibble(x = c(" Foo" , " bar" ))
26
182
expect_dplyr_equal(
0 commit comments