func BenchmarkMarshal(b *testing.B) { for n := 0; n < b.N; n++ { t := toki.NullTime{ toki.Time{ Hours: 12, Minutes: 34, Seconds: 00, }, true} t.MarshalJSON() } }
func TestMarshalNullJSON(t *testing.T) { for given, expected := range jsonTable { time := toki.NullTime{} time.UnmarshalJSON([]byte(given)) data, err := json.Marshal(time) if err != nil { t.Errorf("MarshalJSON: error: %s", err) } result := string(data) if result != expected { t.Errorf("MarshalJSON: %s ≠ %s (%#v)", result, expected, time) } } }
func TestNullScan(t *testing.T) { expected := toki.MustParseNullTime("12:34") byteTime := toki.NullTime{} err := byteTime.Scan([]byte("12:34:00")) if err != nil { t.Errorf("Scan: error: %v", err) } if byteTime != expected { t.Errorf("Scan: %#v ≠ %#v", byteTime, expected) } nullTime := toki.NullTime{} err = nullTime.Scan(nil) if err != nil { t.Errorf("Scan: error: %v", err) } if nullTime.Valid { t.Errorf("Scan: not null, got %s", nullTime.String()) } emptyTime := toki.NullTime{} err = emptyTime.Scan("") if err != nil { t.Errorf("Scan: error: %v", err) } if emptyTime.Valid { t.Errorf("Scan: not null, got %s", emptyTime.String()) } emptyByteTime := toki.NullTime{} err = emptyByteTime.Scan([]byte{}) if err != nil { t.Errorf("Scan: error: %v", err) } if emptyByteTime.Valid { t.Errorf("Scan: not null, got %s", emptyByteTime.String()) } }
func BenchmarkMarshalNull(b *testing.B) { for n := 0; n < b.N; n++ { t := toki.NullTime{toki.Time{}, false} t.MarshalJSON() } }
func BenchmarkEmptyTime(b *testing.B) { for n := 0; n < b.N; n++ { t := toki.NullTime{} t.UnmarshalJSON([]byte{'"', '"'}) } }
func BenchmarkNormalTime(b *testing.B) { for n := 0; n < b.N; n++ { t := toki.NullTime{} t.UnmarshalJSON([]byte{'1', '2', ':', '3', '0'}) } }
func BenchmarkNull(b *testing.B) { for n := 0; n < b.N; n++ { t := toki.NullTime{} t.UnmarshalJSON([]byte{'n', 'u', 'l', 'l'}) } }