diff options
| author | Paul Bütow <1224732+snonux@users.noreply.github.com> | 2025-06-20 00:23:30 +0300 |
|---|---|---|
| committer | Paul Bütow <1224732+snonux@users.noreply.github.com> | 2025-06-20 00:23:30 +0300 |
| commit | 17ae0b210c109e625f8afb54b08de2c25f272c96 (patch) | |
| tree | cf37cacd7af2d3c837d1bd9cffeef962450c93a8 /internal/task/task_test.go | |
| parent | 77620dcd609aa53a81effd23174d56e622f16cc8 (diff) | |
Add task manipulation helpers and tests
Diffstat (limited to 'internal/task/task_test.go')
| -rw-r--r-- | internal/task/task_test.go | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/internal/task/task_test.go b/internal/task/task_test.go index 8940bfe..e48011a 100644 --- a/internal/task/task_test.go +++ b/internal/task/task_test.go @@ -54,3 +54,70 @@ func TestAddAndExport(t *testing.T) { t.Errorf("missing task 'hello universe'") } } + +func TestModifyHelpers(t *testing.T) { + tmp := t.TempDir() + if err := os.Setenv("TASKDATA", tmp); err != nil { + t.Fatal(err) + } + if err := os.Setenv("TASKRC", "/dev/null"); err != nil { + t.Fatal(err) + } + t.Cleanup(func() { + os.Unsetenv("TASKDATA") + os.Unsetenv("TASKRC") + }) + + if err := Add("hello", nil); err != nil { + t.Fatalf("add task: %v", err) + } + + if err := SetPriority(1, "H"); err != nil { + t.Fatalf("set priority: %v", err) + } + if err := AddTags(1, []string{"foo"}); err != nil { + t.Fatalf("add tags: %v", err) + } + if err := SetDescription(1, "hello there"); err != nil { + t.Fatalf("set description: %v", err) + } + if err := Annotate(1, "note"); err != nil { + t.Fatalf("annotate: %v", err) + } + + tasks, err := Export() + if err != nil { + t.Fatalf("export: %v", err) + } + + if len(tasks) != 1 { + t.Fatalf("expected 1 task, got %d", len(tasks)) + } + t1 := tasks[0] + if t1.Priority != "H" { + t.Errorf("priority not set: %v", t1.Priority) + } + found := false + for _, tag := range t1.Tags { + if tag == "foo" { + found = true + break + } + } + if !found { + t.Errorf("tag not added") + } + if t1.Description != "hello there" { + t.Errorf("description not set: %v", t1.Description) + } + annFound := false + for _, a := range t1.Annotations { + if a.Description == "note" { + annFound = true + break + } + } + if !annFound { + t.Errorf("annotation not added") + } +} |
