Test for class method proxy errors - unchanged except method calls
(t *testing.T)
| 1052 | |
| 1053 | // Test for class method proxy errors - unchanged except method calls |
| 1054 | func TestBridgeClassMethodErrors(t *testing.T) { |
| 1055 | // Test class method proxy error handling |
| 1056 | t.Run("MethodContextNotFound", func(t *testing.T) { |
| 1057 | rt := NewRuntime() |
| 1058 | defer rt.Close() |
| 1059 | ctx := rt.NewContext() |
| 1060 | defer ctx.Close() |
| 1061 | |
| 1062 | // MODIFIED FOR SCHEME C: Create class with new constructor signature |
| 1063 | constructor, _ := NewClassBuilder("TestClass"). |
| 1064 | Constructor(func(ctx *Context, instance *Value, args []*Value) (interface{}, error) { |
| 1065 | return &Point{X: 1, Y: 2}, nil |
| 1066 | }). |
| 1067 | Method("testMethod", func(ctx *Context, this *Value, args []*Value) *Value { |
| 1068 | return ctx.NewString("method called") // Changed: String() → NewString() |
| 1069 | }). |
| 1070 | Build(ctx) |
| 1071 | require.False(t, constructor.IsException()) |
| 1072 | |
| 1073 | ctx.Globals().Set("TestClass", constructor) |
| 1074 | |
| 1075 | // Create instance and verify method works |
| 1076 | result := ctx.Eval(` |
| 1077 | let obj = new TestClass(); |
| 1078 | obj.testMethod(); |
| 1079 | `) |
| 1080 | require.False(t, result.IsException()) |
| 1081 | require.Equal(t, "method called", result.ToString()) // Changed: String() → ToString() |
| 1082 | result.Free() |
| 1083 | |
| 1084 | // Unregister context from mapping |
| 1085 | unregisterContext(ctx.ref) |
| 1086 | |
| 1087 | // Call method - triggers goClassMethodProxy with unmapped context |
| 1088 | result2 := ctx.Eval(` |
| 1089 | try { |
| 1090 | let obj = new TestClass(); |
| 1091 | obj.testMethod(); |
| 1092 | } catch(e) { |
| 1093 | e.toString(); |
| 1094 | } |
| 1095 | `) |
| 1096 | |
| 1097 | if result2.IsException() { |
| 1098 | err := ctx.Exception() |
| 1099 | require.Contains(t, err.Error(), "Context not found") |
| 1100 | } else { |
| 1101 | defer result2.Free() |
| 1102 | require.Contains(t, result2.ToString(), "Context not found") // Changed: String() → ToString() |
| 1103 | } |
| 1104 | |
| 1105 | // Re-register context for cleanup |
| 1106 | registerContext(ctx.ref, ctx) |
| 1107 | |
| 1108 | t.Log("Successfully triggered goClassMethodProxy Context not found branch") |
| 1109 | }) |
| 1110 | |
| 1111 | t.Run("MethodNotFound", func(t *testing.T) { |
nothing calls this directly
no test coverage detected