Example #1
0
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()
	}
}
Example #2
0
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)
		}
	}
}
Example #3
0
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())
	}
}
Example #4
0
func BenchmarkMarshalNull(b *testing.B) {
	for n := 0; n < b.N; n++ {
		t := toki.NullTime{toki.Time{}, false}
		t.MarshalJSON()
	}
}
Example #5
0
func BenchmarkEmptyTime(b *testing.B) {
	for n := 0; n < b.N; n++ {
		t := toki.NullTime{}
		t.UnmarshalJSON([]byte{'"', '"'})
	}
}
Example #6
0
func BenchmarkNormalTime(b *testing.B) {
	for n := 0; n < b.N; n++ {
		t := toki.NullTime{}
		t.UnmarshalJSON([]byte{'1', '2', ':', '3', '0'})
	}
}
Example #7
0
func BenchmarkNull(b *testing.B) {
	for n := 0; n < b.N; n++ {
		t := toki.NullTime{}
		t.UnmarshalJSON([]byte{'n', 'u', 'l', 'l'})
	}
}