Tests for binary parameter decoding functions
(t *testing.T)
| 540 | // Tests for binary parameter decoding functions |
| 541 | |
| 542 | func TestDecodeBool(t *testing.T) { |
| 543 | tests := []struct { |
| 544 | name string |
| 545 | input []byte |
| 546 | expected bool |
| 547 | wantErr bool |
| 548 | }{ |
| 549 | {"true", []byte{1}, true, false}, |
| 550 | {"false", []byte{0}, false, false}, |
| 551 | {"non-zero is true", []byte{42}, true, false}, |
| 552 | {"empty data", []byte{}, false, true}, |
| 553 | } |
| 554 | |
| 555 | for _, tt := range tests { |
| 556 | t.Run(tt.name, func(t *testing.T) { |
| 557 | result, err := decodeBool(tt.input) |
| 558 | if tt.wantErr { |
| 559 | if err == nil { |
| 560 | t.Errorf("decodeBool(%v) expected error, got nil", tt.input) |
| 561 | } |
| 562 | return |
| 563 | } |
| 564 | if err != nil { |
| 565 | t.Errorf("decodeBool(%v) unexpected error: %v", tt.input, err) |
| 566 | return |
| 567 | } |
| 568 | if result != tt.expected { |
| 569 | t.Errorf("decodeBool(%v) = %v, want %v", tt.input, result, tt.expected) |
| 570 | } |
| 571 | }) |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | func TestDecodeInt2(t *testing.T) { |
| 576 | tests := []struct { |
nothing calls this directly
no test coverage detected