|
14 | 14 | Error in `case_match()`: |
15 | 15 | ! At least one condition must be supplied. |
16 | 16 |
|
| 17 | +--- |
| 18 | + |
| 19 | + Code |
| 20 | + vec_case_match(1, haystacks = list(), values = list()) |
| 21 | + Condition |
| 22 | + Error in `vec_case_match()`: |
| 23 | + ! At least one condition must be supplied. |
| 24 | + |
17 | 25 | # `.default` is part of common type computation |
18 | 26 |
|
19 | 27 | Code |
|
58 | 66 | Caused by error: |
59 | 67 | ! oh no! |
60 | 68 |
|
| 69 | +# `haystacks` must be castable to `needles` |
| 70 | + |
| 71 | + Code |
| 72 | + vec_case_match(1L, haystacks = list(1.5), values = list(2)) |
| 73 | + Condition |
| 74 | + Error in `vec_case_match()`: |
| 75 | + ! Can't convert from `haystacks[[1]]` <double> to <integer> due to loss of precision. |
| 76 | + * Locations: 1 |
| 77 | + |
| 78 | +# `ptype` overrides `values` common type |
| 79 | + |
| 80 | + Code |
| 81 | + vec_case_match(1:2, haystacks = list(1), values = list(1.5), ptype = integer()) |
| 82 | + Condition |
| 83 | + Error in `vec_case_match()`: |
| 84 | + ! Can't convert from `values[[1]]` <double> to <integer> due to loss of precision. |
| 85 | + * Locations: 1 |
| 86 | + |
| 87 | +# `default` respects `ptype` |
| 88 | + |
| 89 | + Code |
| 90 | + vec_case_match(needles = 1, haystacks = list(1), values = list(2L), default = 1.5, |
| 91 | + ptype = integer()) |
| 92 | + Condition |
| 93 | + Error in `vec_case_match()`: |
| 94 | + ! Can't convert from `default` <double> to <integer> due to loss of precision. |
| 95 | + * Locations: 1 |
| 96 | + |
| 97 | +# `NULL` values in `haystacks` and `values` are not dropped |
| 98 | + |
| 99 | + Code |
| 100 | + vec_case_match(1:2, list(1, NULL, 2), list("a", NULL, "b")) |
| 101 | + Condition |
| 102 | + Error in `vec_case_match()`: |
| 103 | + ! `haystacks[[2]]` must be a vector, not `NULL`. |
| 104 | + |
| 105 | +--- |
| 106 | + |
| 107 | + Code |
| 108 | + vec_case_match(1:2, list(1, NULL, 2), list("a", "a", "b")) |
| 109 | + Condition |
| 110 | + Error in `vec_case_match()`: |
| 111 | + ! `haystacks[[2]]` must be a vector, not `NULL`. |
| 112 | + |
| 113 | +--- |
| 114 | + |
| 115 | + Code |
| 116 | + vec_case_match(1:2, list(1, 1, 2), list("a", NULL, "b")) |
| 117 | + Condition |
| 118 | + Error in `vec_case_match()`: |
| 119 | + ! `values[[2]]` must be a vector, not `NULL`. |
| 120 | + |
| 121 | +# size of `needles` is maintained |
| 122 | + |
| 123 | + Code |
| 124 | + vec_case_match(1, haystacks = list(1), values = list(1:2)) |
| 125 | + Condition |
| 126 | + Error in `vec_case_match()`: |
| 127 | + ! `values[[1]]` must have size 1, not size 2. |
| 128 | + |
| 129 | +# input must be a vector |
| 130 | + |
| 131 | + Code |
| 132 | + vec_case_match(environment(), haystacks = list(environment()), values = list(1)) |
| 133 | + Condition |
| 134 | + Error in `vec_case_match()`: |
| 135 | + ! `needles` must be a vector, not an environment. |
| 136 | + |
| 137 | +# `haystacks` must be a list |
| 138 | + |
| 139 | + Code |
| 140 | + vec_case_match(1, haystacks = 1, values = list(2)) |
| 141 | + Condition |
| 142 | + Error in `vec_case_match()`: |
| 143 | + ! `haystacks` must be a list, not the number 1. |
| 144 | + |
| 145 | +# `values` must be a list |
| 146 | + |
| 147 | + Code |
| 148 | + vec_case_match(1, haystacks = list(1), values = 2) |
| 149 | + Condition |
| 150 | + Error in `vec_case_match()`: |
| 151 | + ! `values` must be a list, not the number 2. |
| 152 | + |
| 153 | +# `needles_arg` is respected |
| 154 | + |
| 155 | + Code |
| 156 | + vec_case_match(needles = environment(), haystacks = list(environment()), |
| 157 | + values = list(1), needles_arg = "foo") |
| 158 | + Condition |
| 159 | + Error in `vec_case_match()`: |
| 160 | + ! `foo` must be a vector, not an environment. |
| 161 | + |
| 162 | +--- |
| 163 | + |
| 164 | + Code |
| 165 | + vec_case_match(needles = environment(), haystacks = list(environment()), |
| 166 | + values = list(1), needles_arg = "") |
| 167 | + Condition |
| 168 | + Error in `vec_case_match()`: |
| 169 | + ! Input must be a vector, not an environment. |
| 170 | + |
| 171 | +# `haystacks_arg` is respected |
| 172 | + |
| 173 | + Code |
| 174 | + vec_case_match(needles = 1, haystacks = 1, values = list(1), haystacks_arg = "foo") |
| 175 | + Condition |
| 176 | + Error in `vec_case_match()`: |
| 177 | + ! `foo` must be a list, not the number 1. |
| 178 | + |
| 179 | +--- |
| 180 | + |
| 181 | + Code |
| 182 | + vec_case_match(needles = 1, haystacks = 1, values = list(1), haystacks_arg = "") |
| 183 | + Condition |
| 184 | + Error in `vec_case_match()`: |
| 185 | + ! Input must be a list, not the number 1. |
| 186 | + |
| 187 | +--- |
| 188 | + |
| 189 | + Code |
| 190 | + vec_case_match(needles = 1, haystacks = list(a = "x"), values = list(1), |
| 191 | + haystacks_arg = "foo") |
| 192 | + Condition |
| 193 | + Error in `vec_case_match()`: |
| 194 | + ! Can't convert `foo$a` <character> to <double>. |
| 195 | + |
| 196 | +--- |
| 197 | + |
| 198 | + Code |
| 199 | + vec_case_match(needles = 1, haystacks = list("x"), values = list(1), |
| 200 | + haystacks_arg = "") |
| 201 | + Condition |
| 202 | + Error in `vec_case_match()`: |
| 203 | + ! Can't convert `..1` <character> to <double>. |
| 204 | + |
| 205 | +# `values_arg` is respected |
| 206 | + |
| 207 | + Code |
| 208 | + vec_case_match(needles = 1, haystacks = list(1, 2), values = list("x", b = 1), |
| 209 | + values_arg = "foo") |
| 210 | + Condition |
| 211 | + Error in `vec_case_match()`: |
| 212 | + ! Can't combine `foo[[1]]` <character> and `foo$b` <double>. |
| 213 | + |
| 214 | +--- |
| 215 | + |
| 216 | + Code |
| 217 | + vec_case_match(needles = 1, haystacks = list(1, 2), values = list("x", b = 1), |
| 218 | + values_arg = "") |
| 219 | + Condition |
| 220 | + Error in `vec_case_match()`: |
| 221 | + ! Can't combine `..1` <character> and `b` <double>. |
| 222 | + |
| 223 | +# `default_arg` is respected |
| 224 | + |
| 225 | + Code |
| 226 | + vec_case_match(needles = 1, haystacks = list(1), values = list(2L), default = 1.5, |
| 227 | + default_arg = "foo", ptype = integer()) |
| 228 | + Condition |
| 229 | + Error in `vec_case_match()`: |
| 230 | + ! Can't convert from `foo` <double> to <integer> due to loss of precision. |
| 231 | + * Locations: 1 |
| 232 | + |
| 233 | +--- |
| 234 | + |
| 235 | + Code |
| 236 | + vec_case_match(needles = 1, haystacks = list(1), values = list(2L), default = 1.5, |
| 237 | + default_arg = "", ptype = integer()) |
| 238 | + Condition |
| 239 | + Error in `vec_case_match()`: |
| 240 | + ! Can't convert from <double> to <integer> due to loss of precision. |
| 241 | + * Locations: 1 |
| 242 | + |
0 commit comments