1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
2//
3// SPDX-License-Identifier: AGPL-3.0-or-later
4
5package lunatask_test
6
7import (
8 "testing"
9
10 lunatask "git.secluded.site/go-lunatask"
11)
12
13func TestAllMotivations(t *testing.T) {
14 t.Parallel()
15
16 motivations := lunatask.AllMotivations()
17
18 // Check count
19 if got := len(motivations); got != 4 {
20 t.Fatalf("AllMotivations() returned %d values, want 4", got)
21 }
22
23 // Check order
24 expected := []lunatask.Motivation{
25 lunatask.MotivationUnknown,
26 lunatask.MotivationMust,
27 lunatask.MotivationShould,
28 lunatask.MotivationWant,
29 }
30 for i, want := range expected {
31 if motivations[i] != want {
32 t.Errorf("AllMotivations()[%d] = %q, want %q", i, motivations[i], want)
33 }
34 }
35
36 // Check roundtrip: each value should be parseable
37 for _, motivation := range motivations {
38 parsed, err := lunatask.ParseMotivation(motivation.String())
39 if err != nil {
40 t.Errorf("ParseMotivation(%q) failed: %v", motivation.String(), err)
41 }
42
43 if parsed != motivation {
44 t.Errorf("ParseMotivation(%q) = %q, want %q", motivation.String(), parsed, motivation)
45 }
46 }
47}
48
49func TestParseMotivation(t *testing.T) {
50 t.Parallel()
51
52 tests := []struct {
53 name string
54 input string
55 want lunatask.Motivation
56 wantErr bool
57 }{
58 {"unknown_lower", "unknown", lunatask.MotivationUnknown, false},
59 {"unknown_upper", "UNKNOWN", lunatask.MotivationUnknown, false},
60 {"unknown_mixed", "UnKnOwN", lunatask.MotivationUnknown, false},
61 {"must_lower", "must", lunatask.MotivationMust, false},
62 {"must_upper", "MUST", lunatask.MotivationMust, false},
63 {"should_lower", "should", lunatask.MotivationShould, false},
64 {"should_upper", "SHOULD", lunatask.MotivationShould, false},
65 {"want_lower", "want", lunatask.MotivationWant, false},
66 {"want_upper", "WANT", lunatask.MotivationWant, false},
67 {"want_mixed", "WaNt", lunatask.MotivationWant, false},
68 {"invalid", "invalid", "", true},
69 {"empty", "", "", true},
70 {"numeric", "1", "", true},
71 {"typo", "muust", "", true},
72 }
73
74 for _, testCase := range tests {
75 t.Run(testCase.name, func(t *testing.T) {
76 t.Parallel()
77
78 got, err := lunatask.ParseMotivation(testCase.input)
79 if (err != nil) != testCase.wantErr {
80 t.Errorf("ParseMotivation(%q) error = %v, wantErr %v", testCase.input, err, testCase.wantErr)
81
82 return
83 }
84
85 if !testCase.wantErr && got != testCase.want {
86 t.Errorf("ParseMotivation(%q) = %q, want %q", testCase.input, got, testCase.want)
87 }
88 })
89 }
90}
91
92func TestMotivation_String(t *testing.T) {
93 t.Parallel()
94
95 tests := []struct {
96 name string
97 value lunatask.Motivation
98 want string
99 }{
100 {"unknown", lunatask.MotivationUnknown, "unknown"},
101 {"must", lunatask.MotivationMust, "must"},
102 {"should", lunatask.MotivationShould, "should"},
103 {"want", lunatask.MotivationWant, "want"},
104 }
105
106 for _, tc := range tests {
107 t.Run(tc.name, func(t *testing.T) {
108 t.Parallel()
109
110 if got := tc.value.String(); got != tc.want {
111 t.Errorf("Motivation.String() = %q, want %q", got, tc.want)
112 }
113 })
114 }
115}