From 631dc539f200df39eedef0c3b59f308ae149c0ee Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Thu, 24 Oct 2024 12:24:37 -0700 Subject: [PATCH] Move some of the test functions around for readability --- main_test.go | 65 ++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/main_test.go b/main_test.go index d78e6bd..fcceb27 100644 --- a/main_test.go +++ b/main_test.go @@ -43,38 +43,7 @@ func assertNotEqual(t *testing.T, actual, expected interface{}, msg string) { } } -// TestParseDuration tests the parseDuration function -func TestParseDuration(t *testing.T) { - tests := []struct { - input string - expected time.Duration - hasError bool - }{ - {"10", 10 * time.Minute, false}, - {"1h", 1 * time.Hour, false}, - {"invalid", 0, true}, - } - - for _, test := range tests { - result, err := parseDuration(test.input) - if test.hasError { - assertNotEqual(t, err, nil, "Expected an error for input "+test.input) - } else { - assertEqual(t, err, nil, "Did not expect an error for input "+test.input) - assertEqual(t, result, test.expected, "Expected duration for input "+test.input) - } - } -} - -// TestRunCommands tests the runCommands function -func TestRunCommands(t *testing.T) { - m := newModelBasic(false, "#ffdd57", "#57ddff") - m.onFocusStart = []string{"echo Focus Start"} - - m.Init() - m.startCommands(m.onFocusStart) -} - +// keyMsgs converts a series of strings or KeyTypes into a slice of KeyMsgs func keyMsgs(keys ...interface{}) []tea.KeyMsg { keyMessages := []tea.KeyMsg{} @@ -239,6 +208,38 @@ func TestSendKeys(t *testing.T) { } } +// TestParseDuration tests the parseDuration function +func TestParseDuration(t *testing.T) { + tests := []struct { + input string + expected time.Duration + hasError bool + }{ + {"10", 10 * time.Minute, false}, + {"1h", 1 * time.Hour, false}, + {"invalid", 0, true}, + } + + for _, test := range tests { + result, err := parseDuration(test.input) + if test.hasError { + assertNotEqual(t, err, nil, "Expected an error for input "+test.input) + } else { + assertEqual(t, err, nil, "Did not expect an error for input "+test.input) + assertEqual(t, result, test.expected, "Expected duration for input "+test.input) + } + } +} + +// TestRunCommands tests the runCommands function +func TestRunCommands(t *testing.T) { + m := newModelBasic(false, "#ffdd57", "#57ddff") + m.onFocusStart = []string{"echo Focus Start"} + + m.Init() + m.startCommands(m.onFocusStart) +} + // TestInputView tests the Update method of the model for the input view func TestInputView(t *testing.T) { m := newModel(false, "#ffdd57", "#57ddff", 0, 0, 0, []string{}, []string{}, []string{})