TestValueConversions tests type conversions including deprecated methods
(t *testing.T)
| 399 | |
| 400 | // TestValueConversions tests type conversions including deprecated methods |
| 401 | func TestValueConversions(t *testing.T) { |
| 402 | useStableOwnerHooksForLegacySubtests(t) |
| 403 | |
| 404 | rt := NewRuntime() |
| 405 | defer rt.Close() |
| 406 | ctx := rt.NewContext() |
| 407 | defer ctx.Close() |
| 408 | |
| 409 | // Test basic conversions - Updated to use New* methods |
| 410 | tests := []struct { |
| 411 | name string |
| 412 | createVal func() *Value // Changed to return pointer |
| 413 | testFunc func(*Value) // Changed parameter to pointer |
| 414 | testDeprecated func(*Value) // Changed parameter to pointer - Test deprecated methods for coverage |
| 415 | }{ |
| 416 | { |
| 417 | name: "Bool", |
| 418 | createVal: func() *Value { return ctx.NewBool(true) }, |
| 419 | testFunc: func(v *Value) { require.True(t, v.ToBool()) }, |
| 420 | testDeprecated: func(v *Value) { require.True(t, v.Bool()) }, |
| 421 | }, |
| 422 | { |
| 423 | name: "String", |
| 424 | createVal: func() *Value { return ctx.NewString("Hello") }, |
| 425 | testFunc: func(v *Value) { |
| 426 | require.Equal(t, "Hello", v.ToString()) |
| 427 | require.Equal(t, "Hello", v.String()) // String() calls ToString() |
| 428 | }, |
| 429 | }, |
| 430 | { |
| 431 | name: "Int32", |
| 432 | createVal: func() *Value { return ctx.NewInt32(42) }, |
| 433 | testFunc: func(v *Value) { require.Equal(t, int32(42), v.ToInt32()) }, |
| 434 | testDeprecated: func(v *Value) { require.Equal(t, int32(42), v.Int32()) }, |
| 435 | }, |
| 436 | { |
| 437 | name: "Int64", |
| 438 | createVal: func() *Value { return ctx.NewInt64(1234567890) }, |
| 439 | testFunc: func(v *Value) { require.Equal(t, int64(1234567890), v.ToInt64()) }, |
| 440 | testDeprecated: func(v *Value) { require.Equal(t, int64(1234567890), v.Int64()) }, |
| 441 | }, |
| 442 | { |
| 443 | name: "Uint32", |
| 444 | createVal: func() *Value { return ctx.NewUint32(4294967295) }, |
| 445 | testFunc: func(v *Value) { require.Equal(t, uint32(4294967295), v.ToUint32()) }, |
| 446 | testDeprecated: func(v *Value) { require.Equal(t, uint32(4294967295), v.Uint32()) }, |
| 447 | }, |
| 448 | { |
| 449 | name: "Float64", |
| 450 | createVal: func() *Value { return ctx.NewFloat64(3.14159) }, |
| 451 | testFunc: func(v *Value) { require.InDelta(t, 3.14159, v.ToFloat64(), 0.00001) }, |
| 452 | testDeprecated: func(v *Value) { require.InDelta(t, 3.14159, v.Float64(), 0.00001) }, |
| 453 | }, |
| 454 | } |
| 455 | |
| 456 | for _, tt := range tests { |
| 457 | t.Run(tt.name, func(t *testing.T) { |
| 458 | val := tt.createVal() |
nothing calls this directly
no test coverage detected