TestFormatFormFieldValue locks in the fix for the float64 -> scientific notation bug. JSON numbers unmarshal to float64, and fmt's default %v for float64 delegates to %g which switches to scientific notation at ~1e6 (e.g. 1185356 -> "1.185356e+06"). Backends that parse the form field as an integer r
(t *testing.T)
| 397 | // (e.g. 1185356 -> "1.185356e+06"). Backends that parse the form field as an |
| 398 | // integer reject that, surfacing as a generic "params error". |
| 399 | func TestFormatFormFieldValue(t *testing.T) { |
| 400 | t.Parallel() |
| 401 | |
| 402 | tests := []struct { |
| 403 | name string |
| 404 | in any |
| 405 | want string |
| 406 | }{ |
| 407 | {"float64 large integer avoids scientific", float64(1185356), "1185356"}, |
| 408 | {"float64 below scientific threshold", float64(358934), "358934"}, |
| 409 | {"float64 zero", float64(0), "0"}, |
| 410 | {"float64 huge", float64(20 * 1024 * 1024), "20971520"}, |
| 411 | {"float64 negative", float64(-42), "-42"}, |
| 412 | {"float64 fractional preserved", float64(3.14), "3.14"}, |
| 413 | {"string pass-through", "hello", "hello"}, |
| 414 | {"bool true", true, "true"}, |
| 415 | {"int via %v", 42, "42"}, |
| 416 | {"int64 via %v", int64(9007199254740992), "9007199254740992"}, |
| 417 | } |
| 418 | |
| 419 | for _, temp := range tests { |
| 420 | tt := temp |
| 421 | t.Run(tt.name, func(t *testing.T) { |
| 422 | t.Parallel() |
| 423 | got := formatFormFieldValue(tt.in) |
| 424 | if got != tt.want { |
| 425 | t.Fatalf("formatFormFieldValue(%v) = %q, want %q", tt.in, got, tt.want) |
| 426 | } |
| 427 | }) |
| 428 | } |
| 429 | } |
nothing calls this directly
no test coverage detected