Skip to content

Commit

Permalink
Clean up test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Sep 10, 2024
1 parent b4e8e25 commit 42c44cc
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions lib/typing/values/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,31 @@ func TestToString(t *testing.T) {
}
{
// ETime
_, err := ToString("2021-01-01T00:00:00Z", typing.ETime)
assert.ErrorContains(t, err, "column kind details for extended time details is null")

eTimeCol := columns.NewColumn("time", typing.ETime)
eTimeCol.KindDetails.ExtendedTimeDetails = &ext.NestedKind{Type: ext.TimeKindType}
// Using `string`
val, err := ToString("2021-01-01T03:52:00Z", eTimeCol.KindDetails)
assert.NoError(t, err)
assert.Equal(t, "03:52:00", val)

// Using `*ExtendedTime`
dustyBirthday := time.Date(2019, time.December, 31, 0, 0, 0, 0, time.UTC)
originalFmt := "2006-01-02T15:04:05Z07:00"
extendedTime := ext.NewExtendedTime(dustyBirthday, ext.DateTimeKindType, originalFmt)
{
// Error
_, err := ToString("2021-01-01T00:00:00Z", typing.ETime)
assert.ErrorContains(t, err, "extended time details is not set")
}
{
eTimeCol := columns.NewColumn("time", typing.ETime)
eTimeCol.KindDetails.ExtendedTimeDetails = &ext.NestedKind{Type: ext.TimeKindType}
{
// Using `string`
val, err := ToString("2021-01-01T03:52:00Z", eTimeCol.KindDetails)
assert.NoError(t, err)
assert.Equal(t, "03:52:00", val)
}
{
// Using `*ExtendedTime`
dustyBirthday := time.Date(2019, time.December, 31, 0, 0, 0, 0, time.UTC)
extendedTime := ext.NewExtendedTime(dustyBirthday, ext.DateTimeKindType, "2006-01-02T15:04:05Z07:00")

eTimeCol.KindDetails.ExtendedTimeDetails = &ext.NestedKind{Type: ext.DateTimeKindType}
actualValue, err := ToString(extendedTime, eTimeCol.KindDetails)
assert.NoError(t, err)
assert.Equal(t, extendedTime.String(originalFmt), actualValue)
eTimeCol.KindDetails.ExtendedTimeDetails = &ext.NestedKind{Type: ext.DateTimeKindType}
actualValue, err := ToString(extendedTime, eTimeCol.KindDetails)
assert.NoError(t, err)
assert.Equal(t, extendedTime.String(""), actualValue)
}
}
}
{
// String
Expand Down

0 comments on commit 42c44cc

Please sign in to comment.