TestValueClassInstanceEdgeCases tests uncovered branches in class instance methods
(t *testing.T)
| 1592 | |
| 1593 | // TestValueClassInstanceEdgeCases tests uncovered branches in class instance methods |
| 1594 | func TestValueClassInstanceEdgeCases(t *testing.T) { |
| 1595 | useStableOwnerHooksForLegacySubtests(t) |
| 1596 | |
| 1597 | rt := NewRuntime() |
| 1598 | defer rt.Close() |
| 1599 | ctx := rt.NewContext() |
| 1600 | defer ctx.Close() |
| 1601 | |
| 1602 | // Test non-object values to cover !v.IsObject() branches - Updated to use New* methods |
| 1603 | nonObjects := []struct { |
| 1604 | name string |
| 1605 | createVal func() *Value // Changed to return pointer |
| 1606 | }{ |
| 1607 | {"String", func() *Value { return ctx.NewString("test") }}, |
| 1608 | {"Number", func() *Value { return ctx.NewInt32(42) }}, |
| 1609 | {"Null", func() *Value { return ctx.NewNull() }}, |
| 1610 | {"Undefined", func() *Value { return ctx.NewUndefined() }}, |
| 1611 | } |
| 1612 | |
| 1613 | for _, no := range nonObjects { |
| 1614 | t.Run("HasInstanceData_"+no.name, func(t *testing.T) { |
| 1615 | val := no.createVal() |
| 1616 | defer val.Free() |
| 1617 | // Cover: if !v.IsObject() return false branch in HasInstanceData |
| 1618 | require.False(t, val.HasInstanceData()) |
| 1619 | }) |
| 1620 | |
| 1621 | t.Run("IsInstanceOfClassID_"+no.name, func(t *testing.T) { |
| 1622 | val := no.createVal() |
| 1623 | defer val.Free() |
| 1624 | // Cover: if !v.IsObject() return false branch in IsInstanceOfClassID |
| 1625 | require.False(t, val.IsInstanceOfClassID(123)) |
| 1626 | }) |
| 1627 | |
| 1628 | t.Run("GetGoObject"+no.name, func(t *testing.T) { |
| 1629 | val := no.createVal() |
| 1630 | defer val.Free() |
| 1631 | // Cover: if !v.IsObject() return error branch in GetGoObject |
| 1632 | _, err := val.GetGoObject() |
| 1633 | require.Error(t, err) |
| 1634 | require.Contains(t, err.Error(), "value is not an object") |
| 1635 | }) |
| 1636 | |
| 1637 | t.Run("IsInstanceOfConstructor_NonObject_"+no.name, func(t *testing.T) { |
| 1638 | val := no.createVal() |
| 1639 | defer val.Free() |
| 1640 | |
| 1641 | fn := ctx.NewFunction(func(ctx *Context, this *Value, args []*Value) *Value { |
| 1642 | return ctx.NewNull() |
| 1643 | }) |
| 1644 | defer fn.Free() |
| 1645 | |
| 1646 | // Cover: if !v.IsObject() part of condition in IsInstanceOfConstructor |
| 1647 | require.False(t, val.IsInstanceOfConstructor(fn)) |
| 1648 | }) |
| 1649 | } |
| 1650 | |
| 1651 | // Test IsInstanceOfConstructor with non-function constructor |
nothing calls this directly
no test coverage detected