accept just a string for a todo task that converts to a struct on parse
This commit is contained in:
@@ -3,6 +3,8 @@ package pttodo
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
func TestJSONTodo(t *testing.T) {
|
||||
@@ -41,3 +43,42 @@ func TestJSONTodo(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestTodoUnmarshalYAML(t *testing.T) {
|
||||
t.Run("just a string", func(t *testing.T) {
|
||||
var littleRoot struct {
|
||||
Todo Todo
|
||||
}
|
||||
if err := yaml.Unmarshal([]byte(`
|
||||
todo: my full task here
|
||||
`), &littleRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if littleRoot.Todo.Todo != "my full task here" {
|
||||
t.Fatal(littleRoot)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("full struct", func(t *testing.T) {
|
||||
var littleRoot struct {
|
||||
Todo Todo
|
||||
}
|
||||
if err := yaml.Unmarshal([]byte(`
|
||||
todo:
|
||||
todo: the todo part of my task
|
||||
detail: whatever
|
||||
schedule: "* * * * *"
|
||||
`), &littleRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if littleRoot.Todo.Todo != "the todo part of my task" {
|
||||
t.Fatal(littleRoot)
|
||||
}
|
||||
if littleRoot.Todo.Detail != "whatever" {
|
||||
t.Fatal(littleRoot)
|
||||
}
|
||||
if littleRoot.Todo.Schedule != "* * * * *" {
|
||||
t.Fatal(littleRoot)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user