-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(spinners): Construct new spinners with
WithSpinner
+ `WithStyl…
…e` options (#148) * Add spinner.New test Signed-off-by: Leandro López (inkel) <[email protected]> * Add spinner.Option type and spinner.WithSpinner option Signed-off-by: Leandro López (inkel) <[email protected]> * Allow passing options in spinner.New This doesn't break existing code as it uses variadic arguments, so any existing code as the following should continue to work: s := spinner.New() s.spinner = spinner.Dot This change allows for instead of those two lines, having a call: s := spinner.New(spinner.WithSpinner(spinner.Dot)) Signed-off-by: Leandro López (inkel) <[email protected]> * Add spinner.WithX option for each spinner.Spinner Signed-off-by: Leandro López (inkel) <[email protected]> * Refactor spinner tests Signed-off-by: Leandro López (inkel) <[email protected]> * Add spinner.WithStyle option function Signed-off-by: Leandro López (inkel) <[email protected]> * refactor: remove With... Spinner aliases Co-authored-by: Maas Lalani <[email protected]>
- Loading branch information
1 parent
3899e1b
commit 7cc5786
Showing
2 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package spinner_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/charmbracelet/bubbles/spinner" | ||
) | ||
|
||
func TestSpinnerNew(t *testing.T) { | ||
assertEqualSpinner := func(t *testing.T, exp, got spinner.Spinner) { | ||
t.Helper() | ||
|
||
if exp.FPS != got.FPS { | ||
t.Errorf("expecting %d FPS, got %d", exp.FPS, got.FPS) | ||
} | ||
|
||
if e, g := len(exp.Frames), len(got.Frames); e != g { | ||
t.Fatalf("expecting %d frames, got %d", e, g) | ||
} | ||
|
||
for i, e := range exp.Frames { | ||
if g := got.Frames[i]; e != g { | ||
t.Errorf("expecting frame index %d with value %q, got %q", i, e, g) | ||
} | ||
} | ||
} | ||
t.Run("default", func(t *testing.T) { | ||
s := spinner.New() | ||
|
||
assertEqualSpinner(t, spinner.Line, s.Spinner) | ||
}) | ||
|
||
t.Run("WithSpinner", func(t *testing.T) { | ||
customSpinner := spinner.Spinner{ | ||
Frames: []string{"a", "b", "c", "d"}, | ||
FPS: 16, | ||
} | ||
|
||
s := spinner.New(spinner.WithSpinner(customSpinner)) | ||
|
||
assertEqualSpinner(t, customSpinner, s.Spinner) | ||
}) | ||
|
||
tests := map[string]spinner.Spinner{ | ||
"Line": spinner.Line, | ||
"Dot": spinner.Dot, | ||
"MiniDot": spinner.MiniDot, | ||
"Jump": spinner.Jump, | ||
"Pulse": spinner.Pulse, | ||
"Points": spinner.Points, | ||
"Globe": spinner.Globe, | ||
"Moon": spinner.Moon, | ||
"Monkey": spinner.Monkey, | ||
} | ||
|
||
for name, s := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
assertEqualSpinner(t, spinner.New(spinner.WithSpinner(s)).Spinner, s) | ||
}) | ||
} | ||
} |