Skip to content

Commit

Permalink
test: Add JSON marshal and unmarshal test
Browse files Browse the repository at this point in the history
  • Loading branch information
Thor-x86 committed Nov 17, 2020
1 parent 6787d14 commit a5ac9a0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
19 changes: 19 additions & 0 deletions string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ func TestSetString(t *testing.T) {
tests.AssertEqual(t, nullableString.Get(), nil)
}

func TestJSONString(t *testing.T) {
basicString1 := ""
marshalUnmarshalJSON(t, nullable.NewString(&basicString1))

basicString2 := "This is a test string"
marshalUnmarshalJSON(t, nullable.NewString(&basicString2))

basicString3 := "and This is also a test string that really really long, just in case something fails after somebody enter a really long string like this. You know what? Coding unit test is a lot stressful and spend longer time than making the real code itself. So please show me a little respect of writting this really long string. Thank you!"
marshalUnmarshalJSON(t, nullable.NewString(&basicString3))

basicString4 := "~!@#$%^&*()_+`-=:;\"'/\\"
marshalUnmarshalJSON(t, nullable.NewString(&basicString4))

basicString5 := ""
marshalUnmarshalJSON(t, nullable.NewString(&basicString5))

marshalUnmarshalJSON(t, nullable.NewString(nil))
}

func TestString(t *testing.T) {
type TestNullableString struct {
ID uint
Expand Down
7 changes: 7 additions & 0 deletions time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ func TestSetTime(t *testing.T) {
tests.AssertEqual(t, nullableTime.Get(), nil)
}

func TestJSONTime(t *testing.T) {
basicTime := time.Now()
marshalUnmarshalJSON(t, nullable.NewTime(&basicTime))

marshalUnmarshalJSON(t, nullable.NewTime(nil))
}

func TestTime(t *testing.T) {
type TestNullableTime struct {
UserID uint `gorm:"primaryKey"`
Expand Down

0 comments on commit a5ac9a0

Please sign in to comment.