func TestEquals(t *testing.T) { same1 := toki.MustParseTime("12:34") same2 := toki.MustParseTime("12:34") if !same1.Equals(same2) { t.Error(same1.String(), "≠", same2.String()) } diff := toki.MustParseTime("12:35") if same1.Equals(diff) { t.Error(same1.String(), "=", diff.String()) } }
func TestValue(t *testing.T) { time := toki.MustParseTime("12:34") v, err := time.Value() if string(v.([]byte)) != "12:34" { t.Errorf("Value: %v ≠ 12:34", v) } if err != nil { t.Errorf("Value: error: %v", err) } }
func TestMustParseTime(t *testing.T) { panicked := false defer func() { if r := recover(); r != nil { panicked = true } if !panicked { t.Error("MustParseTime: didn't panic") } }() for given, expected := range parseTable { time := toki.MustParseTime(given) result := time.String() if result != expected { t.Errorf("MustParseTime: %s → expected %s, got: %s", given, expected, result) } } toki.MustParseTime("invalid input") }
func TestScan(t *testing.T) { expected := toki.MustParseTime("12:34") strTime := toki.Time{} err := strTime.Scan("12:34") if err != nil { t.Errorf("Scan: error: %v", err) } if strTime != expected { t.Errorf("Scan: %#v ≠ %#v", strTime, expected) } byteTime := toki.Time{} 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) } timeTime := toki.Time{} err = timeTime.Scan(time.Date(1992, 2, 23, 12, 34, 0, 0, time.UTC)) if err != nil { t.Errorf("Scan: error: %v", err) } if timeTime != expected { t.Errorf("Scan: %#v ≠ %#v", timeTime, expected) } errTime := toki.Time{} err = errTime.Scan(42) if err == nil { t.Errorf("Scan: expected error, got: nil") } }
"testing" "time" "github.com/guregu/toki" ) var ( arbitraryNumber = 555 veryComplexObject = fancyObject{ User: 613, Test: customMarshaler(1), ContentID: "監獄学園", Page: 1, SkipThis: "i should disappear", Bonus: &arbitraryNumber, TestText: toki.MustParseTime("1:2:3"), StringSlice: []string{"A", "B", "C", "QQQ"}, embedMe: embedMe{ Extra: true, }, Greeting: other{ Hello: "world", }, Features: map[string]bool{ "課金": true, "dlc": true, }, Something: nil, } )