2022-03-24 18:30:59 +01:00
|
|
|
package txt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2023-05-17 20:37:57 +02:00
|
|
|
func TestEmpty(t *testing.T) {
|
2022-03-24 18:30:59 +01:00
|
|
|
t.Run("Empty", func(t *testing.T) {
|
2022-07-22 12:38:25 +02:00
|
|
|
assert.Equal(t, true, Empty(""))
|
2022-03-24 18:30:59 +01:00
|
|
|
})
|
|
|
|
t.Run("EnNew", func(t *testing.T) {
|
2022-07-22 12:38:25 +02:00
|
|
|
assert.Equal(t, false, Empty(EnNew))
|
2022-03-24 18:30:59 +01:00
|
|
|
})
|
|
|
|
t.Run("Spaces", func(t *testing.T) {
|
2022-07-22 12:38:25 +02:00
|
|
|
assert.Equal(t, false, Empty(" new "))
|
2022-03-24 18:30:59 +01:00
|
|
|
})
|
|
|
|
t.Run("Uppercase", func(t *testing.T) {
|
2022-07-22 12:38:25 +02:00
|
|
|
assert.Equal(t, false, Empty("NEW"))
|
2022-03-24 18:30:59 +01:00
|
|
|
})
|
|
|
|
t.Run("Lowercase", func(t *testing.T) {
|
2022-07-22 12:38:25 +02:00
|
|
|
assert.Equal(t, false, Empty("new"))
|
2022-03-24 18:30:59 +01:00
|
|
|
})
|
|
|
|
t.Run("True", func(t *testing.T) {
|
2022-07-22 12:38:25 +02:00
|
|
|
assert.Equal(t, false, Empty("New"))
|
2022-03-24 18:30:59 +01:00
|
|
|
})
|
|
|
|
t.Run("False", func(t *testing.T) {
|
2022-07-22 12:38:25 +02:00
|
|
|
assert.Equal(t, false, Empty("non"))
|
2022-03-24 18:30:59 +01:00
|
|
|
})
|
|
|
|
t.Run("0", func(t *testing.T) {
|
2022-07-22 12:38:25 +02:00
|
|
|
assert.Equal(t, true, Empty("0"))
|
2022-03-24 18:30:59 +01:00
|
|
|
})
|
|
|
|
t.Run("-1", func(t *testing.T) {
|
2022-07-22 12:38:25 +02:00
|
|
|
assert.Equal(t, true, Empty("-1"))
|
|
|
|
})
|
|
|
|
t.Run("Date", func(t *testing.T) {
|
|
|
|
assert.Equal(t, true, Empty("0000:00:00 00:00:00"))
|
2022-03-24 18:30:59 +01:00
|
|
|
})
|
|
|
|
t.Run("nil", func(t *testing.T) {
|
2022-07-22 12:38:25 +02:00
|
|
|
assert.Equal(t, true, Empty("nil"))
|
2022-03-24 18:30:59 +01:00
|
|
|
})
|
|
|
|
t.Run("NaN", func(t *testing.T) {
|
2022-07-22 12:38:25 +02:00
|
|
|
assert.Equal(t, true, Empty("NaN"))
|
2022-03-24 18:30:59 +01:00
|
|
|
})
|
|
|
|
t.Run("NULL", func(t *testing.T) {
|
2022-07-22 12:38:25 +02:00
|
|
|
assert.Equal(t, true, Empty("NULL"))
|
2022-03-24 18:30:59 +01:00
|
|
|
})
|
|
|
|
t.Run("*", func(t *testing.T) {
|
2022-07-22 12:38:25 +02:00
|
|
|
assert.Equal(t, true, Empty("*"))
|
2022-03-24 18:30:59 +01:00
|
|
|
})
|
|
|
|
t.Run("%", func(t *testing.T) {
|
2022-07-22 12:38:25 +02:00
|
|
|
assert.Equal(t, true, Empty("%"))
|
2022-03-24 18:30:59 +01:00
|
|
|
})
|
2023-05-17 20:37:57 +02:00
|
|
|
t.Run("-", func(t *testing.T) {
|
|
|
|
assert.True(t, Empty("-"))
|
|
|
|
})
|
|
|
|
t.Run("z", func(t *testing.T) {
|
|
|
|
assert.True(t, Empty("z"))
|
|
|
|
})
|
|
|
|
t.Run("zz", func(t *testing.T) {
|
|
|
|
assert.False(t, Empty("zz"))
|
|
|
|
})
|
2022-03-24 18:30:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestNotEmpty(t *testing.T) {
|
|
|
|
t.Run("Empty", func(t *testing.T) {
|
|
|
|
assert.Equal(t, false, NotEmpty(""))
|
|
|
|
})
|
|
|
|
t.Run("EnNew", func(t *testing.T) {
|
|
|
|
assert.Equal(t, true, NotEmpty(EnNew))
|
|
|
|
})
|
|
|
|
t.Run("Spaces", func(t *testing.T) {
|
|
|
|
assert.Equal(t, true, NotEmpty(" new "))
|
|
|
|
})
|
|
|
|
t.Run("Uppercase", func(t *testing.T) {
|
|
|
|
assert.Equal(t, true, NotEmpty("NEW"))
|
|
|
|
})
|
|
|
|
t.Run("Lowercase", func(t *testing.T) {
|
|
|
|
assert.Equal(t, true, NotEmpty("new"))
|
|
|
|
})
|
|
|
|
t.Run("True", func(t *testing.T) {
|
|
|
|
assert.Equal(t, true, NotEmpty("New"))
|
|
|
|
})
|
|
|
|
t.Run("False", func(t *testing.T) {
|
|
|
|
assert.Equal(t, true, NotEmpty("non"))
|
|
|
|
})
|
|
|
|
t.Run("0", func(t *testing.T) {
|
|
|
|
assert.Equal(t, false, NotEmpty("0"))
|
|
|
|
})
|
|
|
|
t.Run("-1", func(t *testing.T) {
|
|
|
|
assert.Equal(t, false, NotEmpty("-1"))
|
|
|
|
})
|
2022-07-22 12:38:25 +02:00
|
|
|
t.Run("Date", func(t *testing.T) {
|
|
|
|
assert.Equal(t, false, NotEmpty("0000:00:00 00:00:00"))
|
|
|
|
})
|
2022-03-24 18:30:59 +01:00
|
|
|
t.Run("nil", func(t *testing.T) {
|
|
|
|
assert.Equal(t, false, NotEmpty("nil"))
|
|
|
|
})
|
|
|
|
t.Run("NaN", func(t *testing.T) {
|
|
|
|
assert.Equal(t, false, NotEmpty("NaN"))
|
|
|
|
})
|
|
|
|
t.Run("NULL", func(t *testing.T) {
|
|
|
|
assert.Equal(t, false, NotEmpty("NULL"))
|
|
|
|
})
|
|
|
|
t.Run("*", func(t *testing.T) {
|
|
|
|
assert.Equal(t, false, NotEmpty("*"))
|
|
|
|
})
|
|
|
|
t.Run("%", func(t *testing.T) {
|
|
|
|
assert.Equal(t, false, NotEmpty("%"))
|
|
|
|
})
|
2023-05-17 20:37:57 +02:00
|
|
|
t.Run("-", func(t *testing.T) {
|
|
|
|
assert.False(t, NotEmpty("-"))
|
|
|
|
})
|
|
|
|
t.Run("z", func(t *testing.T) {
|
|
|
|
assert.False(t, NotEmpty("z"))
|
|
|
|
})
|
|
|
|
t.Run("zz", func(t *testing.T) {
|
|
|
|
assert.True(t, NotEmpty("zz"))
|
|
|
|
})
|
2022-03-24 18:30:59 +01:00
|
|
|
}
|
2022-07-22 12:38:25 +02:00
|
|
|
|
2023-02-24 15:53:59 +01:00
|
|
|
func TestEmptyDateTime(t *testing.T) {
|
|
|
|
t.Run("Empty", func(t *testing.T) {
|
|
|
|
assert.True(t, EmptyDateTime(""))
|
|
|
|
})
|
2023-05-17 20:37:57 +02:00
|
|
|
t.Run("-", func(t *testing.T) {
|
|
|
|
assert.True(t, EmptyDateTime("-"))
|
|
|
|
})
|
|
|
|
t.Run("z", func(t *testing.T) {
|
|
|
|
assert.True(t, EmptyDateTime("z"))
|
|
|
|
})
|
|
|
|
t.Run("zz", func(t *testing.T) {
|
|
|
|
assert.False(t, EmptyDateTime("zz"))
|
|
|
|
})
|
2023-02-24 15:53:59 +01:00
|
|
|
t.Run("0", func(t *testing.T) {
|
|
|
|
assert.True(t, EmptyDateTime("0"))
|
|
|
|
})
|
|
|
|
t.Run("00-00-00", func(t *testing.T) {
|
|
|
|
assert.True(t, EmptyDateTime("00-00-00"))
|
|
|
|
})
|
|
|
|
t.Run("0000-00-00", func(t *testing.T) {
|
|
|
|
assert.True(t, EmptyDateTime("0000-00-00"))
|
|
|
|
})
|
|
|
|
t.Run("00:00:00", func(t *testing.T) {
|
|
|
|
assert.True(t, EmptyDateTime("00:00:00"))
|
|
|
|
})
|
|
|
|
t.Run("0000:00:00", func(t *testing.T) {
|
|
|
|
assert.True(t, EmptyDateTime("0000:00:00"))
|
|
|
|
})
|
|
|
|
t.Run("0000-00-00 00-00-00", func(t *testing.T) {
|
|
|
|
assert.True(t, EmptyDateTime("0000-00-00 00-00-00"))
|
|
|
|
})
|
|
|
|
t.Run("0000:00:00 00:00:00", func(t *testing.T) {
|
|
|
|
assert.True(t, EmptyDateTime("0000:00:00 00:00:00"))
|
|
|
|
})
|
|
|
|
t.Run("0000-00-00 00:00:00", func(t *testing.T) {
|
|
|
|
assert.True(t, EmptyDateTime("0000-00-00 00:00:00"))
|
|
|
|
})
|
|
|
|
t.Run("0001-01-01 00:00:00 +0000 UTC", func(t *testing.T) {
|
|
|
|
assert.True(t, EmptyDateTime("0001-01-01 00:00:00 +0000 UTC"))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDateTimeDefault(t *testing.T) {
|
|
|
|
t.Run("Empty", func(t *testing.T) {
|
|
|
|
assert.True(t, DateTimeDefault(""))
|
|
|
|
})
|
|
|
|
t.Run("nil", func(t *testing.T) {
|
|
|
|
assert.True(t, DateTimeDefault("nil"))
|
|
|
|
})
|
|
|
|
t.Run("2002", func(t *testing.T) {
|
|
|
|
assert.False(t, DateTimeDefault("2002"))
|
|
|
|
})
|
|
|
|
t.Run("1970-01-01", func(t *testing.T) {
|
|
|
|
assert.True(t, DateTimeDefault("1970-01-01"))
|
|
|
|
})
|
|
|
|
t.Run("1980-01-01", func(t *testing.T) {
|
|
|
|
assert.True(t, DateTimeDefault("1980-01-01"))
|
|
|
|
})
|
|
|
|
t.Run("1970-01-01 00:00:00", func(t *testing.T) {
|
|
|
|
assert.True(t, DateTimeDefault("1970-01-01 00:00:00"))
|
|
|
|
})
|
2023-02-24 16:15:43 +01:00
|
|
|
t.Run("1970:01:01 00:00:00", func(t *testing.T) {
|
|
|
|
assert.True(t, DateTimeDefault("1970:01:01 00:00:00"))
|
|
|
|
})
|
2023-02-24 15:53:59 +01:00
|
|
|
t.Run("1980-01-01 00:00:00", func(t *testing.T) {
|
|
|
|
assert.True(t, DateTimeDefault("1980-01-01 00:00:00"))
|
|
|
|
})
|
2023-02-24 16:15:43 +01:00
|
|
|
t.Run("1980:01:01 00:00:00", func(t *testing.T) {
|
|
|
|
assert.True(t, DateTimeDefault("1980:01:01 00:00:00"))
|
|
|
|
})
|
|
|
|
t.Run("2002-12-08 12:00:00", func(t *testing.T) {
|
|
|
|
assert.True(t, DateTimeDefault("2002-12-08 12:00:00"))
|
|
|
|
})
|
2023-02-24 15:53:59 +01:00
|
|
|
t.Run("2002:12:08 12:00:00", func(t *testing.T) {
|
|
|
|
assert.True(t, DateTimeDefault("2002:12:08 12:00:00"))
|
|
|
|
})
|
|
|
|
t.Run("0000-00-00", func(t *testing.T) {
|
|
|
|
assert.True(t, DateTimeDefault("0000-00-00"))
|
2022-07-22 12:38:25 +02:00
|
|
|
})
|
|
|
|
t.Run("0000-00-00 00-00-00", func(t *testing.T) {
|
2023-02-24 15:53:59 +01:00
|
|
|
assert.True(t, DateTimeDefault("0000-00-00 00-00-00"))
|
2022-07-22 12:38:25 +02:00
|
|
|
})
|
|
|
|
t.Run("0000:00:00 00:00:00", func(t *testing.T) {
|
2023-02-24 15:53:59 +01:00
|
|
|
assert.True(t, DateTimeDefault("0000:00:00 00:00:00"))
|
2022-07-22 12:38:25 +02:00
|
|
|
})
|
|
|
|
t.Run("0000-00-00 00:00:00", func(t *testing.T) {
|
2023-02-24 15:53:59 +01:00
|
|
|
assert.True(t, DateTimeDefault("0000-00-00 00:00:00"))
|
2022-07-22 12:38:25 +02:00
|
|
|
})
|
|
|
|
t.Run("0001-01-01 00:00:00 +0000 UTC", func(t *testing.T) {
|
2023-02-24 15:53:59 +01:00
|
|
|
assert.True(t, DateTimeDefault("0001-01-01 00:00:00 +0000 UTC"))
|
2022-07-22 12:38:25 +02:00
|
|
|
})
|
|
|
|
}
|