(t *testing.T)
| 3053 | } |
| 3054 | |
| 3055 | func TestOptionalValuesCompile(t *testing.T) { |
| 3056 | env := testEnv(t, |
| 3057 | OptionalTypes(), |
| 3058 | // Test variables. |
| 3059 | Variable("m", MapType(StringType, MapType(StringType, StringType))), |
| 3060 | Variable("optm", OptionalType(MapType(StringType, MapType(StringType, StringType)))), |
| 3061 | Variable("l", ListType(StringType)), |
| 3062 | Variable("optl", OptionalType(ListType(StringType))), |
| 3063 | Variable("x", OptionalType(IntType)), |
| 3064 | Variable("y", IntType), |
| 3065 | ) |
| 3066 | tests := []struct { |
| 3067 | expr string |
| 3068 | references map[int64]*celast.ReferenceInfo |
| 3069 | }{ |
| 3070 | { |
| 3071 | expr: `x.or(optional.of(y)).orValue(42)`, |
| 3072 | references: map[int64]*celast.ReferenceInfo{ |
| 3073 | 1: {Name: "x"}, |
| 3074 | 2: {OverloadIDs: []string{"optional_or_optional"}}, |
| 3075 | 4: {OverloadIDs: []string{"optional_of"}}, |
| 3076 | 5: {Name: "y"}, |
| 3077 | 6: {OverloadIDs: []string{"optional_orValue_value"}}, |
| 3078 | }, |
| 3079 | }, |
| 3080 | { |
| 3081 | expr: `m.?x.hasValue()`, |
| 3082 | references: map[int64]*celast.ReferenceInfo{ |
| 3083 | 1: {Name: "m"}, |
| 3084 | 3: {OverloadIDs: []string{"select_optional_field"}}, |
| 3085 | 4: {OverloadIDs: []string{"optional_hasValue"}}, |
| 3086 | }, |
| 3087 | }, |
| 3088 | { |
| 3089 | expr: `has(m.?x.y)`, |
| 3090 | references: map[int64]*celast.ReferenceInfo{ |
| 3091 | 2: {Name: "m"}, |
| 3092 | 4: {OverloadIDs: []string{"select_optional_field"}}, |
| 3093 | }, |
| 3094 | }, |
| 3095 | { |
| 3096 | // Optional index selection in map. |
| 3097 | expr: `m.k[?'dashed-index'].orValue('default value')`, |
| 3098 | references: map[int64]*celast.ReferenceInfo{ |
| 3099 | 1: {Name: "m"}, |
| 3100 | 3: {OverloadIDs: []string{"map_optindex_optional_value"}}, |
| 3101 | 5: {OverloadIDs: []string{"optional_orValue_value"}}, |
| 3102 | }, |
| 3103 | }, |
| 3104 | { |
| 3105 | // Optional index selection in list. |
| 3106 | expr: `l[?y]`, |
| 3107 | references: map[int64]*celast.ReferenceInfo{ |
| 3108 | 1: {Name: "l"}, |
| 3109 | 2: {OverloadIDs: []string{"list_optindex_optional_int"}}, |
| 3110 | 3: {Name: "y"}, |
| 3111 | }, |
| 3112 | }, |
nothing calls this directly
no test coverage detected