test ezpz json
This commit is contained in:
30
pttodo/ts_test.go
Normal file
30
pttodo/ts_test.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package pttodo
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestJSONTS(t *testing.T) {
|
||||
ts := TS(time.Now().Unix())
|
||||
js, err := json.Marshal(ts)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var ts2 TS
|
||||
if err := json.Unmarshal(js, &ts2); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if ts != ts2 {
|
||||
t.Fatal(ts2)
|
||||
}
|
||||
|
||||
if err := json.Unmarshal([]byte(`123`), &ts2); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if 123 != ts2 {
|
||||
t.Fatal(ts2)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user