(t *testing.T)
| 204 | } |
| 205 | |
| 206 | func TestValidateHomogeneousAggregateLiterals(t *testing.T) { |
| 207 | env, err := NewCustomEnv( |
| 208 | Variable("name", StringType), |
| 209 | Function(operators.In, |
| 210 | Overload(overloads.InList, []*Type{StringType, ListType(StringType)}, BoolType, |
| 211 | BinaryBinding(func(lhs, rhs ref.Val) ref.Val { |
| 212 | return rhs.(traits.Container).Contains(lhs) |
| 213 | }), |
| 214 | ), |
| 215 | Overload(overloads.InMap, []*Type{StringType, MapType(StringType, BoolType)}, BoolType, |
| 216 | BinaryBinding(func(lhs, rhs ref.Val) ref.Val { |
| 217 | return rhs.(traits.Container).Contains(lhs) |
| 218 | }), |
| 219 | ), |
| 220 | ), |
| 221 | OptionalTypes(), |
| 222 | HomogeneousAggregateLiterals(), |
| 223 | ASTValidators(ValidateHomogeneousAggregateLiterals()), |
| 224 | ) |
| 225 | if err != nil { |
| 226 | t.Fatalf("NewCustomEnv() failed: %v", err) |
| 227 | } |
| 228 | |
| 229 | tests := []struct { |
| 230 | expr string |
| 231 | iss string |
| 232 | }{ |
| 233 | { |
| 234 | expr: `name in ['hello', 0]`, |
| 235 | iss: ` |
| 236 | ERROR: <input>:1:19: expected type 'string' but found 'int' |
| 237 | | name in ['hello', 0] |
| 238 | | ..................^`, |
| 239 | }, |
| 240 | { |
| 241 | expr: `{'hello':'world', 1:'!'}`, |
| 242 | iss: ` |
| 243 | ERROR: <input>:1:19: expected type 'string' but found 'int' |
| 244 | | {'hello':'world', 1:'!'} |
| 245 | | ..................^`, |
| 246 | }, |
| 247 | { |
| 248 | expr: `name in {'hello':'world', 'goodbye':true}`, |
| 249 | iss: ` |
| 250 | ERROR: <input>:1:37: expected type 'string' but found 'bool' |
| 251 | | name in {'hello':'world', 'goodbye':true} |
| 252 | | ....................................^`, |
| 253 | }, |
| 254 | { |
| 255 | expr: `name in ['hello', 'world']`, |
| 256 | }, |
| 257 | { |
| 258 | expr: `name in ['hello', ?optional.ofNonZeroValue('')]`, |
| 259 | }, |
| 260 | { |
| 261 | expr: `name in [?optional.ofNonZeroValue(''), 'hello', ?optional.of('')]`, |
| 262 | }, |
| 263 | { |
nothing calls this directly
no test coverage detected