(t *testing.T)
| 1640 | } |
| 1641 | |
| 1642 | func TestNativeToValueDelegatesUnregisteredStructs(t *testing.T) { |
| 1643 | custom := &recordingAdapter{base: types.DefaultTypeAdapter} |
| 1644 | env, err := cel.NewEnv( |
| 1645 | cel.CustomTypeAdapter(custom), |
| 1646 | NativeTypes(reflect.TypeOf(registeredNativeStruct{})), |
| 1647 | ) |
| 1648 | if err != nil { |
| 1649 | t.Fatalf("cel.NewEnv() failed: %v", err) |
| 1650 | } |
| 1651 | adapter := env.CELTypeAdapter() |
| 1652 | |
| 1653 | // An unregistered struct must reach the composed base adapter. |
| 1654 | got := adapter.NativeToValue(unregisteredNativeStruct{Name: "x"}) |
| 1655 | if !custom.saw { |
| 1656 | t.Error("base adapter was not consulted for an unregistered struct") |
| 1657 | } |
| 1658 | if got.Equal(types.String("from-base-adapter")) != types.True { |
| 1659 | t.Errorf("NativeToValue(unregisteredNativeStruct) = %v, want the base adapter's value", got) |
| 1660 | } |
| 1661 | |
| 1662 | // A registered native type must still be wrapped as a native object. |
| 1663 | custom.saw = false |
| 1664 | gotReg := adapter.NativeToValue(registeredNativeStruct{Name: "y"}) |
| 1665 | if custom.saw { |
| 1666 | t.Error("base adapter was consulted for a registered native type") |
| 1667 | } |
| 1668 | if tn := gotReg.Type().TypeName(); !strings.Contains(tn, "registeredNativeStruct") { |
| 1669 | t.Errorf("NativeToValue(registeredNativeStruct).Type() = %q, want a native object type", tn) |
| 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | func BenchmarkNativeTypesEval(b *testing.B) { |
| 1674 | benchmarks := []struct { |
nothing calls this directly
no test coverage detected