(t *testing.T)
| 176 | } |
| 177 | |
| 178 | func TestEncodeBool(t *testing.T) { |
| 179 | tests := []struct { |
| 180 | name string |
| 181 | input interface{} |
| 182 | expected []byte |
| 183 | }{ |
| 184 | {"true bool", true, []byte{1}}, |
| 185 | {"false bool", false, []byte{0}}, |
| 186 | {"int 1", int(1), []byte{1}}, |
| 187 | {"int 0", int(0), []byte{0}}, |
| 188 | {"int -1", int(-1), []byte{1}}, |
| 189 | {"int64 1", int64(1), []byte{1}}, |
| 190 | // Note: int64(0) returns 1 (true) due to a quirk in encodeBool's multi-type case handling |
| 191 | // The comparison `val != 0` where val is interface{} compares against int(0), not int64(0) |
| 192 | {"int64 0", int64(0), []byte{1}}, |
| 193 | {"string (unsupported)", "true", []byte{0}}, // defaults to false for unsupported types |
| 194 | } |
| 195 | |
| 196 | for _, tt := range tests { |
| 197 | t.Run(tt.name, func(t *testing.T) { |
| 198 | result := encodeBool(tt.input) |
| 199 | if len(result) != len(tt.expected) { |
| 200 | t.Errorf("encodeBool(%v) length = %d, want %d", tt.input, len(result), len(tt.expected)) |
| 201 | return |
| 202 | } |
| 203 | for i, b := range result { |
| 204 | if b != tt.expected[i] { |
| 205 | t.Errorf("encodeBool(%v)[%d] = %d, want %d", tt.input, i, b, tt.expected[i]) |
| 206 | } |
| 207 | } |
| 208 | }) |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | func TestEncodeInt2(t *testing.T) { |
| 213 | tests := []struct { |
nothing calls this directly
no test coverage detected