MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestOptionalValuesCompile

Function TestOptionalValuesCompile

cel/cel_test.go:2860–2970  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2858}
2859
2860func TestOptionalValuesCompile(t *testing.T) {
2861 env := testEnv(t,
2862 OptionalTypes(),
2863 // Test variables.
2864 Variable("m", MapType(StringType, MapType(StringType, StringType))),
2865 Variable("optm", OptionalType(MapType(StringType, MapType(StringType, StringType)))),
2866 Variable("l", ListType(StringType)),
2867 Variable("optl", OptionalType(ListType(StringType))),
2868 Variable("x", OptionalType(IntType)),
2869 Variable("y", IntType),
2870 )
2871 tests := []struct {
2872 expr string
2873 references map[int64]*celast.ReferenceInfo
2874 }{
2875 {
2876 expr: `x.or(optional.of(y)).orValue(42)`,
2877 references: map[int64]*celast.ReferenceInfo{
2878 1: {Name: "x"},
2879 2: {OverloadIDs: []string{"optional_or_optional"}},
2880 4: {OverloadIDs: []string{"optional_of"}},
2881 5: {Name: "y"},
2882 6: {OverloadIDs: []string{"optional_orValue_value"}},
2883 },
2884 },
2885 {
2886 expr: `m.?x.hasValue()`,
2887 references: map[int64]*celast.ReferenceInfo{
2888 1: {Name: "m"},
2889 3: {OverloadIDs: []string{"select_optional_field"}},
2890 4: {OverloadIDs: []string{"optional_hasValue"}},
2891 },
2892 },
2893 {
2894 expr: `has(m.?x.y)`,
2895 references: map[int64]*celast.ReferenceInfo{
2896 2: {Name: "m"},
2897 4: {OverloadIDs: []string{"select_optional_field"}},
2898 },
2899 },
2900 {
2901 // Optional index selection in map.
2902 expr: `m.k[?'dashed-index'].orValue('default value')`,
2903 references: map[int64]*celast.ReferenceInfo{
2904 1: {Name: "m"},
2905 3: {OverloadIDs: []string{"map_optindex_optional_value"}},
2906 5: {OverloadIDs: []string{"optional_orValue_value"}},
2907 },
2908 },
2909 {
2910 // Optional index selection in list.
2911 expr: `l[?y]`,
2912 references: map[int64]*celast.ReferenceInfo{
2913 1: {Name: "l"},
2914 2: {OverloadIDs: []string{"list_optindex_optional_int"}},
2915 3: {Name: "y"},
2916 },
2917 },

Callers

nothing calls this directly

Calls 8

OptionalTypesFunction · 0.85
ErrMethod · 0.80
ReferenceMapMethod · 0.80
NativeRepMethod · 0.80
EqualsMethod · 0.80
testEnvFunction · 0.70
VariableFunction · 0.70
CompileMethod · 0.65

Tested by

no test coverage detected