root does not marshal TSs on todos, always on schedules, dones. Test.

Bel LaPointe 2022-01-02 20:44:04 -05:00
parent 4d171d10d0
commit 6203ced79b
2 changed files with 40 additions and 0 deletions

View File

@ -36,3 +36,17 @@ func (root *Root) MergeIn(root2 Root) {
} }
} }
} }
func (root Root) MarshalYAML() (interface{}, error) {
for i := range root.Todo {
root.Todo[i].writeTS = false
}
for i := range root.Scheduled {
root.Scheduled[i].writeTS = true
}
for i := range root.Done {
root.Done[i].writeTS = true
}
type Alt Root
return (Alt)(root), nil
}

View File

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"strconv" "strconv"
"strings"
"testing" "testing"
"time" "time"
@ -145,3 +146,28 @@ todo:
t.Fatalf("want \n\t%+v, got \n\t%+v", rootWant, root0) t.Fatalf("want \n\t%+v, got \n\t%+v", rootWant, root0)
} }
} }
func TestRootMarshalYAMLWriteTS(t *testing.T) {
root := Root{
Todo: []Todo{Todo{Todo: "todo", TS: 1, writeTS: true}},
Scheduled: []Todo{Todo{Todo: "sched", TS: 2, writeTS: false, Schedule: "2099-01-01"}},
Done: []Todo{Todo{Todo: "done", TS: 3, writeTS: false}},
}
got, err := yaml.Marshal(root)
if err != nil {
t.Fatal(err)
}
if strings.TrimSpace(string(got)) != strings.TrimSpace(`
todo:
- todo
scheduled:
- todo: sched
schedule: "2099-01-01"
ts: Wed Dec 31 19:00:02 EST 1969
done:
- todo: done
ts: Wed Dec 31 19:00:03 EST 1969
`) {
t.Fatal(string(got))
}
}