============================================================================= ERROR COVERAGE TESTS - NEW TESTS TO COVER MISSING BRANCHES =============================================================================
(t *testing.T)
| 614 | // ============================================================================= |
| 615 | |
| 616 | func TestReflectionConstructorErrors(t *testing.T) { |
| 617 | newPersonTestContext := func(t *testing.T) *Context { |
| 618 | rt := NewRuntime() |
| 619 | ctx := rt.NewContext() |
| 620 | require.NotNil(t, ctx) |
| 621 | constructor, _ := ctx.BindClass(&Person{}) |
| 622 | require.False(t, constructor.IsException()) |
| 623 | ctx.Globals().Set("Person", constructor) |
| 624 | t.Cleanup(func() { |
| 625 | ctx.Close() |
| 626 | rt.Close() |
| 627 | }) |
| 628 | return ctx |
| 629 | } |
| 630 | |
| 631 | // Test positional argument conversion error |
| 632 | t.Run("PositionalArgumentError", func(t *testing.T) { |
| 633 | ctx := newPersonTestContext(t) |
| 634 | ret := ctx.Eval(` |
| 635 | try { |
| 636 | // Pass an object where an int is expected for age |
| 637 | new Person("John", "Doe", {invalid: "object"}, 50000, true); |
| 638 | } catch(e) { |
| 639 | throw e; |
| 640 | } |
| 641 | `) |
| 642 | defer ret.Free() |
| 643 | require.True(t, ret.IsException()) |
| 644 | |
| 645 | err := ctx.Exception() |
| 646 | require.Error(t, err) |
| 647 | require.Contains(t, err.Error(), "constructor initialization failed") |
| 648 | }) |
| 649 | |
| 650 | // Test object argument conversion error |
| 651 | t.Run("ObjectArgumentError", func(t *testing.T) { |
| 652 | ctx := newPersonTestContext(t) |
| 653 | ret := ctx.Eval(` |
| 654 | try { |
| 655 | // Pass an object where an int is expected for age accessor |
| 656 | new Person({ |
| 657 | firstName: "John", |
| 658 | lastName: "Doe", |
| 659 | age: {invalid: "object"} |
| 660 | }); |
| 661 | } catch(e) { |
| 662 | throw e; |
| 663 | } |
| 664 | `) |
| 665 | defer ret.Free() |
| 666 | require.True(t, ret.IsException()) |
| 667 | |
| 668 | err := ctx.Exception() |
| 669 | require.Error(t, err) |
| 670 | require.Contains(t, err.Error(), "constructor initialization failed") |
| 671 | }) |
| 672 | |
| 673 | // Test positional args with unexported fields - covers the continue branch |
nothing calls this directly
no test coverage detected