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

Function TestConvertVal

common/ast/conversion_test.go:691–714  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

689}
690
691func TestConvertVal(t *testing.T) {
692 tests := []ref.Val{
693 types.True,
694 types.Bytes("bytes"),
695 types.Double(3.2),
696 types.Int(-1),
697 types.NullValue,
698 types.String("string"),
699 types.Uint(27),
700 }
701 for _, tst := range tests {
702 c, err := ast.ValToConstant(tst)
703 if err != nil {
704 t.Errorf("ValToConstant(%v) failed: %v", tst, err)
705 }
706 v, err := ast.ConstantToVal(c)
707 if err != nil {
708 t.Errorf("ValToConstant(%v) failed: %v", c, err)
709 }
710 if tst.Equal(v) != types.True {
711 t.Errorf("roundtrip from %v to %v and back did not produce equal results, got %v, wanted %v", tst, c, v, tst)
712 }
713 }
714}
715
716func TestValToConstantError(t *testing.T) {
717 out, err := ast.ValToConstant(types.Duration{Duration: time.Duration(10)})

Callers

nothing calls this directly

Calls 8

BytesTypeAlias · 0.92
DoubleTypeAlias · 0.92
IntTypeAlias · 0.92
StringTypeAlias · 0.92
UintTypeAlias · 0.92
ValToConstantFunction · 0.92
ConstantToValFunction · 0.92
EqualMethod · 0.65

Tested by

no test coverage detected