set ts to currenttime if should display
parent
f63f152b0e
commit
a75d898487
|
|
@ -7,8 +7,8 @@ import (
|
||||||
|
|
||||||
type Todo struct {
|
type Todo struct {
|
||||||
Todo string
|
Todo string
|
||||||
|
TS TS
|
||||||
Details string `yaml:",omitempty"`
|
Details string `yaml:",omitempty"`
|
||||||
TS TS `yaml:",omitempty"`
|
|
||||||
Schedule Schedule `yaml:",omitempty"`
|
Schedule Schedule `yaml:",omitempty"`
|
||||||
Tags string `yaml:",omitempty"`
|
Tags string `yaml:",omitempty"`
|
||||||
Subtasks []Todo `yaml:",omitempty"`
|
Subtasks []Todo `yaml:",omitempty"`
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,40 @@ package pttodo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"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) {
|
func TestJSONTS(t *testing.T) {
|
||||||
ts := TS(time.Now().Unix())
|
ts := TS(time.Now().Unix())
|
||||||
js, err := json.Marshal(ts)
|
js, err := json.Marshal(ts)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue