TestEncodeDecode does a back-and-forth test of encoding and decoding and compare the value with a given output.
(t *testing.T)
| 432 | |
| 433 | // TestEncodeDecode does a back-and-forth test of encoding and decoding and compare the value with a given output. |
| 434 | func TestEncodeDecode(t *testing.T) { |
| 435 | for _, tc := range []struct { |
| 436 | name string |
| 437 | input any |
| 438 | output any |
| 439 | encodeError string |
| 440 | }{ |
| 441 | { |
| 442 | name: "nil", |
| 443 | input: nil, |
| 444 | }, |
| 445 | { |
| 446 | name: "bool", |
| 447 | input: true, |
| 448 | }, |
| 449 | { |
| 450 | name: "int", |
| 451 | input: int64(42), |
| 452 | }, |
| 453 | { |
| 454 | name: "float", |
| 455 | input: 3.14159, |
| 456 | }, |
| 457 | { |
| 458 | name: "string", |
| 459 | input: "hello", |
| 460 | }, |
| 461 | { |
| 462 | name: "bytes", |
| 463 | input: []byte("hello"), |
| 464 | }, |
| 465 | { |
| 466 | name: "array-empty", |
| 467 | input: []any{}, |
| 468 | }, |
| 469 | { |
| 470 | name: "array", |
| 471 | input: []any{int64(1), int64(2), int64(3)}, |
| 472 | }, |
| 473 | { |
| 474 | name: "map-empty", |
| 475 | input: map[string]any{}, |
| 476 | }, |
| 477 | { |
| 478 | name: "map", |
| 479 | input: map[string]any{"a": int64(1), "b": int64(2)}, |
| 480 | }, |
| 481 | { |
| 482 | name: "map-interface", |
| 483 | input: map[string]any{"a": int64(1), "b": "2"}, |
| 484 | }, |
| 485 | { |
| 486 | name: "map-string", |
| 487 | input: map[string]string{"a": "1", "b": "2"}, |
| 488 | output: map[string]any{"a": "1", "b": "2"}, |
| 489 | }, |
| 490 | { |
| 491 | name: "map-array", |
nothing calls this directly
no test coverage detected
searching dependent graphs…