(t *testing.T)
| 3111 | } |
| 3112 | |
| 3113 | func TestOptionalValuesCompile(t *testing.T) { |
| 3114 | env := testEnv(t, |
| 3115 | OptionalTypes(), |
| 3116 | // Test variables. |
| 3117 | Variable("m", MapType(StringType, MapType(StringType, StringType))), |
| 3118 | Variable("optm", OptionalType(MapType(StringType, MapType(StringType, StringType)))), |
| 3119 | Variable("l", ListType(StringType)), |
| 3120 | Variable("optl", OptionalType(ListType(StringType))), |
| 3121 | Variable("x", OptionalType(IntType)), |
| 3122 | Variable("y", IntType), |
| 3123 | ) |
| 3124 | tests := []struct { |
| 3125 | expr string |
| 3126 | references map[int64]*celast.ReferenceInfo |
| 3127 | }{ |
| 3128 | { |
| 3129 | expr: `x.or(optional.of(y)).orValue(42)`, |
| 3130 | references: map[int64]*celast.ReferenceInfo{ |
| 3131 | 1: {Name: "x"}, |
| 3132 | 2: {OverloadIDs: []string{"optional_or_optional"}}, |
| 3133 | 4: {OverloadIDs: []string{"optional_of"}}, |
| 3134 | 5: {Name: "y"}, |
| 3135 | 6: {OverloadIDs: []string{"optional_orValue_value"}}, |
| 3136 | }, |
| 3137 | }, |
| 3138 | { |
| 3139 | expr: `m.?x.hasValue()`, |
| 3140 | references: map[int64]*celast.ReferenceInfo{ |
| 3141 | 1: {Name: "m"}, |
| 3142 | 3: {OverloadIDs: []string{"select_optional_field"}}, |
| 3143 | 4: {OverloadIDs: []string{"optional_hasValue"}}, |
| 3144 | }, |
| 3145 | }, |
| 3146 | { |
| 3147 | expr: `has(m.?x.y)`, |
| 3148 | references: map[int64]*celast.ReferenceInfo{ |
| 3149 | 2: {Name: "m"}, |
| 3150 | 4: {OverloadIDs: []string{"select_optional_field"}}, |
| 3151 | }, |
| 3152 | }, |
| 3153 | { |
| 3154 | // Optional index selection in map. |
| 3155 | expr: `m.k[?'dashed-index'].orValue('default value')`, |
| 3156 | references: map[int64]*celast.ReferenceInfo{ |
| 3157 | 1: {Name: "m"}, |
| 3158 | 3: {OverloadIDs: []string{"map_optindex_optional_value"}}, |
| 3159 | 5: {OverloadIDs: []string{"optional_orValue_value"}}, |
| 3160 | }, |
| 3161 | }, |
| 3162 | { |
| 3163 | // Optional index selection in list. |
| 3164 | expr: `l[?y]`, |
| 3165 | references: map[int64]*celast.ReferenceInfo{ |
| 3166 | 1: {Name: "l"}, |
| 3167 | 2: {OverloadIDs: []string{"list_optindex_optional_int"}}, |
| 3168 | 3: {Name: "y"}, |
| 3169 | }, |
| 3170 | }, |
nothing calls this directly
no test coverage detected