(t *testing.T)
| 3255 | } |
| 3256 | |
| 3257 | func TestOptionalValuesCompile(t *testing.T) { |
| 3258 | env := testEnv(t, |
| 3259 | OptionalTypes(), |
| 3260 | // Test variables. |
| 3261 | Variable("m", MapType(StringType, MapType(StringType, StringType))), |
| 3262 | Variable("optm", OptionalType(MapType(StringType, MapType(StringType, StringType)))), |
| 3263 | Variable("l", ListType(StringType)), |
| 3264 | Variable("optl", OptionalType(ListType(StringType))), |
| 3265 | Variable("x", OptionalType(IntType)), |
| 3266 | Variable("y", IntType), |
| 3267 | ) |
| 3268 | tests := []struct { |
| 3269 | expr string |
| 3270 | references map[int64]*celast.ReferenceInfo |
| 3271 | }{ |
| 3272 | { |
| 3273 | expr: `x.or(optional.of(y)).orValue(42)`, |
| 3274 | references: map[int64]*celast.ReferenceInfo{ |
| 3275 | 1: {Name: "x"}, |
| 3276 | 2: {OverloadIDs: []string{"optional_or_optional"}}, |
| 3277 | 4: {OverloadIDs: []string{"optional_of"}}, |
| 3278 | 5: {Name: "y"}, |
| 3279 | 6: {OverloadIDs: []string{"optional_orValue_value"}}, |
| 3280 | }, |
| 3281 | }, |
| 3282 | { |
| 3283 | expr: `m.?x.hasValue()`, |
| 3284 | references: map[int64]*celast.ReferenceInfo{ |
| 3285 | 1: {Name: "m"}, |
| 3286 | 3: {OverloadIDs: []string{"select_optional_field"}}, |
| 3287 | 4: {OverloadIDs: []string{"optional_hasValue"}}, |
| 3288 | }, |
| 3289 | }, |
| 3290 | { |
| 3291 | expr: `has(m.?x.y)`, |
| 3292 | references: map[int64]*celast.ReferenceInfo{ |
| 3293 | 2: {Name: "m"}, |
| 3294 | 4: {OverloadIDs: []string{"select_optional_field"}}, |
| 3295 | }, |
| 3296 | }, |
| 3297 | { |
| 3298 | // Optional index selection in map. |
| 3299 | expr: `m.k[?'dashed-index'].orValue('default value')`, |
| 3300 | references: map[int64]*celast.ReferenceInfo{ |
| 3301 | 1: {Name: "m"}, |
| 3302 | 3: {OverloadIDs: []string{"map_optindex_optional_value"}}, |
| 3303 | 5: {OverloadIDs: []string{"optional_orValue_value"}}, |
| 3304 | }, |
| 3305 | }, |
| 3306 | { |
| 3307 | // Optional index selection in list. |
| 3308 | expr: `l[?y]`, |
| 3309 | references: map[int64]*celast.ReferenceInfo{ |
| 3310 | 1: {Name: "l"}, |
| 3311 | 2: {OverloadIDs: []string{"list_optindex_optional_int"}}, |
| 3312 | 3: {Name: "y"}, |
| 3313 | }, |
| 3314 | }, |
nothing calls this directly
no test coverage detected