diff --git a/go.mod b/go.mod index ff79bb2..11953b5 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,10 @@ module git.makyo.dev/makyo/gogogogogram go 1.24.6 -require github.com/charmbracelet/bubbletea v1.3.6 +require ( + github.com/charmbracelet/bubbletea v1.3.6 + github.com/smartystreets/goconvey v1.8.1 +) require ( github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect @@ -12,6 +15,8 @@ require ( github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect github.com/charmbracelet/x/term v0.2.1 // indirect github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect + github.com/gopherjs/gopherjs v1.17.2 // indirect + github.com/jtolds/gls v4.20.0+incompatible // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-localereader v0.0.1 // indirect @@ -20,8 +25,11 @@ require ( github.com/muesli/cancelreader v0.2.2 // indirect github.com/muesli/termenv v0.16.0 // indirect github.com/rivo/uniseg v0.4.7 // indirect + github.com/smarty/assertions v1.15.0 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect + golang.org/x/mod v0.9.0 // indirect golang.org/x/sync v0.15.0 // indirect golang.org/x/sys v0.33.0 // indirect golang.org/x/text v0.3.8 // indirect + golang.org/x/tools v0.7.0 // indirect ) diff --git a/go.sum b/go.sum index 85f1fed..d815c63 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,10 @@ github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQ github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4= github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM= +github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g= +github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k= +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= @@ -31,10 +35,16 @@ github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3 github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/smarty/assertions v1.15.0 h1:cR//PqUBUiQRakZWqBiFFQ9wb8emQGDb0HeGdqGByCY= +github.com/smarty/assertions v1.15.0/go.mod h1:yABtdzeQs6l1brC900WlRNwj6ZR55d7B+E8C6HtKdec= +github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sSznIX1xY= +github.com/smartystreets/goconvey v1.8.1/go.mod h1:+/u4qLyY6x1jReYOp7GOM2FSt8aP9CzCZL03bI28W60= github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E= golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= +golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs= +golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8= golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -43,3 +53,5 @@ golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4= +golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= diff --git a/model/cursor.go b/model/cursor.go index c655d74..a886bed 100644 --- a/model/cursor.go +++ b/model/cursor.go @@ -1,7 +1,7 @@ package model func (m Model) CursorCellUp() Model { - if m.cursor-m.size > 0 { + if m.cursor-m.size >= 0 { m.cursor -= m.size } return m @@ -15,21 +15,21 @@ func (m Model) CursorCellDown() Model { } func (m Model) CursorCellRight() Model { - if m.cursor%m.size < m.size { + if m.cursor%m.size < m.size-1 { m.cursor++ } return m } func (m Model) CursorCellLeft() Model { - if m.cursor%m.size != 1 { + if m.cursor%m.size != 0 { m.cursor-- } return m } func (m Model) CursorSectionUp() Model { - if m.cursor > m.size*m.perSection { + if m.cursor >= m.size*m.perSection { m.cursor -= m.size * m.perSection } return m @@ -50,7 +50,7 @@ func (m Model) CursorSectionRight() Model { } func (m Model) CursorSectionLeft() Model { - if m.cursor%m.perSection > 0 { + if m.cursor%m.perSection >= 0 { m.cursor -= m.section } return m diff --git a/model/cursor_test.go b/model/cursor_test.go new file mode 100644 index 0000000..117cab1 --- /dev/null +++ b/model/cursor_test.go @@ -0,0 +1,115 @@ +package model + +import ( + "testing" + + . "github.com/smartystreets/goconvey/convey" +) + +func TestCursor(t *testing.T) { + Convey("Given a cursor", t, func() { + + Convey("When moving cell to cell", func() { + m, err := New(4, 4) + So(err, ShouldBeNil) + So(m.cursor, ShouldEqual, 0) + + Convey("You can move down", func() { + m = m.CursorCellDown() + So(m.cursor, ShouldEqual, 16) + }) + + Convey("You can move up", func() { + m = m.CursorCellDown() + m = m.CursorCellUp() + So(m.cursor, ShouldEqual, 0) + }) + + Convey("You can move right", func() { + m = m.CursorCellRight() + So(m.cursor, ShouldEqual, 1) + }) + + Convey("You can move left", func() { + m = m.CursorCellRight() + m = m.CursorCellLeft() + So(m.cursor, ShouldEqual, 0) + }) + + Convey("You can't move up beyond the top", func() { + m = m.CursorCellUp() + So(m.cursor, ShouldEqual, 0) + }) + + Convey("You can't move left beyond the edge", func() { + m = m.CursorCellLeft() + So(m.cursor, ShouldEqual, 0) + }) + + bottomRight := (m.size * m.size) - 1 + m.cursor = bottomRight + + Convey("You can't move down below the bottom", func() { + m.cursor = bottomRight + m = m.CursorCellDown() + So(m.cursor, ShouldEqual, bottomRight) + }) + + Convey("You can't move right beyond the edge", func() { + m.cursor = bottomRight + m = m.CursorCellRight() + So(m.cursor, ShouldEqual, bottomRight) + }) + }) + + Convey("When moving section to section", func() { + m, err := New(4, 4) + So(err, ShouldBeNil) + Convey("You can move down", func() { + m = m.CursorSectionDown() + So(m.cursor, ShouldEqual, 64) + }) + + Convey("You can move up", func() { + m = m.CursorSectionDown() + m = m.CursorSectionUp() + So(m.cursor, ShouldEqual, 0) + }) + + Convey("You can move right", func() { + m = m.CursorSectionRight() + So(m.cursor, ShouldEqual, 4) + }) + + Convey("You can move left", func() { + m = m.CursorSectionRight() + m = m.CursorSectionLeft() + So(m.cursor, ShouldEqual, 0) + }) + + Convey("You can't move up beyond the top", func() { + m = m.CursorCellUp() + So(m.cursor, ShouldEqual, 0) + }) + + Convey("You can't move left beyond the edge", func() { + m = m.CursorCellLeft() + So(m.cursor, ShouldEqual, 0) + }) + + bottomRight := (m.size * m.size) - 1 + + Convey("You can't move down below the bottom", func() { + m.cursor = bottomRight + m = m.CursorSectionDown() + So(m.cursor, ShouldEqual, bottomRight) + }) + + Convey("You can't move right beyond the edge", func() { + m.cursor = bottomRight + m = m.CursorSectionRight() + So(m.cursor, ShouldEqual, bottomRight) + }) + }) + }) +}