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 TestParseMotivation(t *testing.T) {
14 t.Parallel()
15
16 tests := []struct {
17 name string
18 input string
19 want lunatask.Motivation
20 wantErr bool
21 }{
22 {"unknown_lower", "unknown", lunatask.MotivationUnknown, false},
23 {"unknown_upper", "UNKNOWN", lunatask.MotivationUnknown, false},
24 {"unknown_mixed", "UnKnOwN", lunatask.MotivationUnknown, false},
25 {"must_lower", "must", lunatask.MotivationMust, false},
26 {"must_upper", "MUST", lunatask.MotivationMust, false},
27 {"should_lower", "should", lunatask.MotivationShould, false},
28 {"should_upper", "SHOULD", lunatask.MotivationShould, false},
29 {"want_lower", "want", lunatask.MotivationWant, false},
30 {"want_upper", "WANT", lunatask.MotivationWant, false},
31 {"want_mixed", "WaNt", lunatask.MotivationWant, false},
32 {"invalid", "invalid", "", true},
33 {"empty", "", "", true},
34 {"numeric", "1", "", true},
35 {"typo", "muust", "", true},
36 }
37
38 for _, testCase := range tests {
39 t.Run(testCase.name, func(t *testing.T) {
40 t.Parallel()
41
42 got, err := lunatask.ParseMotivation(testCase.input)
43 if (err != nil) != testCase.wantErr {
44 t.Errorf("ParseMotivation(%q) error = %v, wantErr %v", testCase.input, err, testCase.wantErr)
45
46 return
47 }
48
49 if !testCase.wantErr && got != testCase.want {
50 t.Errorf("ParseMotivation(%q) = %q, want %q", testCase.input, got, testCase.want)
51 }
52 })
53 }
54}
55
56func TestMotivation_String(t *testing.T) {
57 t.Parallel()
58
59 tests := []struct {
60 name string
61 value lunatask.Motivation
62 want string
63 }{
64 {"unknown", lunatask.MotivationUnknown, "unknown"},
65 {"must", lunatask.MotivationMust, "must"},
66 {"should", lunatask.MotivationShould, "should"},
67 {"want", lunatask.MotivationWant, "want"},
68 }
69
70 for _, tc := range tests {
71 t.Run(tc.name, func(t *testing.T) {
72 t.Parallel()
73
74 if got := tc.value.String(); got != tc.want {
75 t.Errorf("Motivation.String() = %q, want %q", got, tc.want)
76 }
77 })
78 }
79}