set ts to currenttime if should display
This commit is contained in:
@@ -2,10 +2,40 @@ package pttodo
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
func TestTSMarshalYaml(t *testing.T) {
|
||||
t.Run("nonzero", func(t *testing.T) {
|
||||
var ts TS
|
||||
if b, err := yaml.Marshal(TS(5)); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if s := string(b); strings.TrimSpace(s) != `5` {
|
||||
t.Fatal(s)
|
||||
} else if err := yaml.Unmarshal(b, &ts); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if ts != 5 {
|
||||
t.Fatal(ts)
|
||||
}
|
||||
})
|
||||
t.Run("zero", func(t *testing.T) {
|
||||
var ts TS
|
||||
if b, err := yaml.Marshal(TS(0)); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if s := string(b); strings.TrimSpace(s) == `0` {
|
||||
t.Fatal(s)
|
||||
} else if err := yaml.Unmarshal(b, &ts); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if ts == 0 {
|
||||
t.Fatal(ts)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestJSONTS(t *testing.T) {
|
||||
ts := TS(time.Now().Unix())
|
||||
js, err := json.Marshal(ts)
|
||||
|
||||
Reference in New Issue
Block a user