(t *testing.T)
| 2838 | } |
| 2839 | |
| 2840 | func TestOptionalValuesCompile(t *testing.T) { |
| 2841 | env := testEnv(t, |
| 2842 | OptionalTypes(), |
| 2843 | // Test variables. |
| 2844 | Variable("m", MapType(StringType, MapType(StringType, StringType))), |
| 2845 | Variable("optm", OptionalType(MapType(StringType, MapType(StringType, StringType)))), |
| 2846 | Variable("l", ListType(StringType)), |
| 2847 | Variable("optl", OptionalType(ListType(StringType))), |
| 2848 | Variable("x", OptionalType(IntType)), |
| 2849 | Variable("y", IntType), |
| 2850 | ) |
| 2851 | tests := []struct { |
| 2852 | expr string |
| 2853 | references map[int64]*celast.ReferenceInfo |
| 2854 | }{ |
| 2855 | { |
| 2856 | expr: `x.or(optional.of(y)).orValue(42)`, |
| 2857 | references: map[int64]*celast.ReferenceInfo{ |
| 2858 | 1: {Name: "x"}, |
| 2859 | 2: {OverloadIDs: []string{"optional_or_optional"}}, |
| 2860 | 4: {OverloadIDs: []string{"optional_of"}}, |
| 2861 | 5: {Name: "y"}, |
| 2862 | 6: {OverloadIDs: []string{"optional_orValue_value"}}, |
| 2863 | }, |
| 2864 | }, |
| 2865 | { |
| 2866 | expr: `m.?x.hasValue()`, |
| 2867 | references: map[int64]*celast.ReferenceInfo{ |
| 2868 | 1: {Name: "m"}, |
| 2869 | 3: {OverloadIDs: []string{"select_optional_field"}}, |
| 2870 | 4: {OverloadIDs: []string{"optional_hasValue"}}, |
| 2871 | }, |
| 2872 | }, |
| 2873 | { |
| 2874 | expr: `has(m.?x.y)`, |
| 2875 | references: map[int64]*celast.ReferenceInfo{ |
| 2876 | 2: {Name: "m"}, |
| 2877 | 4: {OverloadIDs: []string{"select_optional_field"}}, |
| 2878 | }, |
| 2879 | }, |
| 2880 | { |
| 2881 | // Optional index selection in map. |
| 2882 | expr: `m.k[?'dashed-index'].orValue('default value')`, |
| 2883 | references: map[int64]*celast.ReferenceInfo{ |
| 2884 | 1: {Name: "m"}, |
| 2885 | 3: {OverloadIDs: []string{"map_optindex_optional_value"}}, |
| 2886 | 5: {OverloadIDs: []string{"optional_orValue_value"}}, |
| 2887 | }, |
| 2888 | }, |
| 2889 | { |
| 2890 | // Optional index selection in list. |
| 2891 | expr: `l[?y]`, |
| 2892 | references: map[int64]*celast.ReferenceInfo{ |
| 2893 | 1: {Name: "l"}, |
| 2894 | 2: {OverloadIDs: []string{"list_optindex_optional_int"}}, |
| 2895 | 3: {Name: "y"}, |
| 2896 | }, |
| 2897 | }, |
nothing calls this directly
no test coverage detected