From cb3f025af93a4a0e8bda092e1c7e8b351c461eac Mon Sep 17 00:00:00 2001 From: Min Huang <70873102+min0625@users.noreply.github.com> Date: Tue, 23 Jun 2026 03:57:19 +0000 Subject: [PATCH] test: add unsupported-type Scan case and clarify examples Add a table-driven test entry that verifies Scan rejects an unsupported input type ([]int) while leaving the receiver unchanged. Also split a chained one-liner in ExampleTimeZone and add inline comments to the zero-value and SQL Value examples to surface the UTC-as-zero-value and no-NULL invariants directly in the runnable docs. Co-Authored-By: Claude Sonnet 4.6 --- time_zone_example_test.go | 7 ++++++- time_zone_test.go | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/time_zone_example_test.go b/time_zone_example_test.go index 98967f6..f216a26 100644 --- a/time_zone_example_test.go +++ b/time_zone_example_test.go @@ -16,7 +16,10 @@ func ExampleTimeZone() { } fmt.Println(z.String()) - fmt.Println(time.Time{}.In(z.Location()).Location().String()) + + // Location returns a *time.Location that can be applied to a time.Time. + loc := z.Location() + fmt.Println(time.Time{}.In(loc).Location().String()) // Output: // America/New_York @@ -24,6 +27,7 @@ func ExampleTimeZone() { } func ExampleTimeZone_zeroValue() { + // Loading "UTC" (or an empty string) always yields the zero value. z, err := tz.LoadTimeZone("UTC") if err != nil { panic(err) @@ -71,6 +75,7 @@ func ExampleTimeZone_Value() { func ExampleTimeZone_Value_zeroValue() { var z tz.TimeZone + // The zero value is stored as the "UTC" string, never as NULL. v, err := z.Value() fmt.Printf("%v %T %v\n", v, v, err) diff --git a/time_zone_test.go b/time_zone_test.go index 8992865..e958217 100644 --- a/time_zone_test.go +++ b/time_zone_test.go @@ -305,6 +305,13 @@ func TestTimeZone_Scan(t *testing.T) { wantTimeZone: mustLoadTimeZone(t, "America/New_York"), wantErr: true, }, + { + name: "unsupported_type", + giveTimeZone: mustLoadTimeZone(t, "America/New_York"), + value: []int{1}, + wantTimeZone: mustLoadTimeZone(t, "America/New_York"), + wantErr: true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {