go-hep.org/x/hep@v0.38.1/groot/rbase/datime_test.go (about)

     1  // Copyright ©2022 The go-hep Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package rbase
     6  
     7  import (
     8  	"testing"
     9  	"time"
    10  
    11  	"go-hep.org/x/hep/groot/rbytes"
    12  )
    13  
    14  func TestDatime(t *testing.T) {
    15  	defer func() {
    16  		err := recover()
    17  		if err == nil {
    18  			t.Fatalf("expected a panic!")
    19  		}
    20  		var (
    21  			got  = err.(error).Error()
    22  			want = "rbase: TDatime year must be >= 1995"
    23  		)
    24  		if got != want {
    25  			t.Fatalf("invalid panic.\ngot= %q\nwant=%q", got, want)
    26  		}
    27  	}()
    28  
    29  	d := Datime(time.Date(1980, 1, 2, 15, 4, 5, 0, time.UTC))
    30  	w := rbytes.NewWBuffer(nil, nil, 0, nil)
    31  	_, err := d.MarshalROOT(w)
    32  	if err != nil {
    33  		t.Fatalf("could not marshal TDatime: %+v", err)
    34  	}
    35  }