From a75d89848786247666f8fe5c222a1db03e7654f8 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Fri, 31 Dec 2021 22:27:48 -0500 Subject: [PATCH] set ts to currenttime if should display --- pttodo/todo.go | 2 +- pttodo/ts_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/pttodo/todo.go b/pttodo/todo.go index 04a11b9..dafce6e 100644 --- a/pttodo/todo.go +++ b/pttodo/todo.go @@ -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"` diff --git a/pttodo/ts_test.go b/pttodo/ts_test.go index 82fe17c..5502475 100644 --- a/pttodo/ts_test.go +++ b/pttodo/ts_test.go @@ -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)