v0.0.67
This commit is contained in:
51
rfctime/rfc3339Nano_test.go
Normal file
51
rfctime/rfc3339Nano_test.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package rfctime
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestRoundtrip(t *testing.T) {
|
||||
|
||||
type Wrap struct {
|
||||
Value RFC3339NanoTime `json:"v"`
|
||||
}
|
||||
|
||||
val1 := NewRFC3339Nano(time.Now())
|
||||
w1 := Wrap{val1}
|
||||
|
||||
jstr1, err := json.Marshal(w1)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if string(jstr1) != "{\"v\":\"2023-01-29T20:32:36.149692117+01:00\"}" {
|
||||
t.Errorf("repr differs")
|
||||
}
|
||||
|
||||
w2 := Wrap{}
|
||||
|
||||
err = json.Unmarshal(jstr1, &w2)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
jstr2, err := json.Marshal(w2)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
assertEqual(t, string(jstr1), string(jstr2))
|
||||
|
||||
if !w1.Value.Equal(&w2.Value) {
|
||||
t.Errorf("time differs")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func assertEqual(t *testing.T, actual string, expected string) {
|
||||
if actual != expected {
|
||||
t.Errorf("values differ: Actual: '%v', Expected: '%v'", actual, expected)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user