MCPcopy Index your code
hub / github.com/google/mangle / TestTimeConstant

Function TestTimeConstant

ast/ast_test.go:677–710  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

675}
676
677func TestTimeConstant(t *testing.T) {
678 // Unix epoch
679 epoch := Time(0)
680 v, err := epoch.TimeValue()
681 if err != nil {
682 t.Fatal(err)
683 }
684 if v != 0 {
685 t.Errorf("Time(0).TimeValue() = %d, want 0", v)
686 }
687
688 // Specific timestamp: 2024-01-15 10:30:00 UTC
689 // = 1705315800 seconds * 1e9 nanoseconds
690 nanos := int64(1705315800) * int64(1e9)
691 ts := Time(nanos)
692 v, err = ts.TimeValue()
693 if err != nil {
694 t.Fatal(err)
695 }
696 if v != nanos {
697 t.Errorf("Time(%d).TimeValue() = %d, want %d", nanos, v, nanos)
698 }
699
700 // Negative time (before Unix epoch)
701 negNanos := int64(-1000000000) // 1 second before epoch
702 negTs := Time(negNanos)
703 v, err = negTs.TimeValue()
704 if err != nil {
705 t.Fatal(err)
706 }
707 if v != negNanos {
708 t.Errorf("Time(%d).TimeValue() = %d, want %d", negNanos, v, negNanos)
709 }
710}
711
712func TestTimeConstantEquality(t *testing.T) {
713 t1 := Time(1705315800000000000)

Callers

nothing calls this directly

Calls 2

TimeFunction · 0.85
TimeValueMethod · 0.80

Tested by

no test coverage detected