From 7ff8352af98c1cd54c6ccefb9c61fc7aa6932527 Mon Sep 17 00:00:00 2001 From: sha1n Date: Sat, 17 Jan 2026 00:19:56 +0200 Subject: [PATCH] feat: add Row() getter to MatrixCellID --- matrix.go | 5 +++++ matrix_test.go | 1 + spinner_test.go | 17 +++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/matrix.go b/matrix.go index d78bb07..7fe724b 100644 --- a/matrix.go +++ b/matrix.go @@ -45,6 +45,11 @@ type MatrixCellID struct { row int } +// Row returns the row index associated with this ID +func (id MatrixCellID) Row() int { + return id.row +} + // MatrixRow an accessor to a line in a Matrix structure // Line feed and return characters are trimmed from written strings to prevent breaking the layout of the matrix. type MatrixRow interface { diff --git a/matrix_test.go b/matrix_test.go index f58a041..d387d4b 100644 --- a/matrix_test.go +++ b/matrix_test.go @@ -96,6 +96,7 @@ func TestMatrixGetRowByID(t *testing.T) { assert.NoError(t, err) assert.Equal(t, aRow, fetchedRow) + assert.Equal(t, 1, fetchedRow.ID().Row()) } func TestMatrixGetRowByIdWithInvalidRange(t *testing.T) { diff --git a/spinner_test.go b/spinner_test.go index 9878fd2..4dd1579 100644 --- a/spinner_test.go +++ b/spinner_test.go @@ -47,6 +47,23 @@ func TestSpinnerCancellation(t *testing.T) { assertStoppedEventually(t, probedWriter, spin.(*spinner)) } +func TestSpinnerBuilder(t *testing.T) { + expectedTitle := test.RandomString() + expectedInterval := time.Millisecond * 123 + emulatedStdout := new(bytes.Buffer) + + spin := NewSpinnerBuilder(). + WithWriter(emulatedStdout). + WithTitle(expectedTitle). + WithInterval(expectedInterval). + Build() + + s := spin.(*spinner) + assert.Equal(t, emulatedStdout, s.writer) + assert.Equal(t, expectedTitle, s.title) + assert.Equal(t, expectedInterval, s.interval) +} + func TestSpinnerTitles(t *testing.T) { t.Run("InitialTitle", func(t *testing.T) { expectedTitle := test.RandomString()