set ts to currenttime if should display

Bel LaPointe 2021-12-31 22:27:48 -05:00
parent 24154df995
commit 183f39bd2a
2 changed files with 31 additions and 1 deletions

View File

@ -7,8 +7,8 @@ import (
type Todo struct {
Todo string
TS TS
Details string `yaml:",omitempty"`
TS TS `yaml:",omitempty"`
Schedule Schedule `yaml:",omitempty"`
Tags string `yaml:",omitempty"`
Subtasks []Todo `yaml:",omitempty"`

View File

@ -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)