Skip to content

Commit

Permalink
feat: scroll and clear tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cfoust committed Nov 14, 2023
1 parent a009d02 commit 37ba304
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 6 deletions.
171 changes: 171 additions & 0 deletions pkg/sessions/search/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package search
import (
"testing"

"github.com/cfoust/cy/pkg/emu"
"github.com/cfoust/cy/pkg/geom"
"github.com/cfoust/cy/pkg/sessions"

"github.com/stretchr/testify/require"
"github.com/xo/terminfo"
)

func TestGetPartial(t *testing.T) {
Expand All @@ -23,6 +25,11 @@ func TestGetPartial(t *testing.T) {
require.Equal(t, "([ads]|[1-3])", re.String())
}

var TEST_SIZE = geom.Size{
R: 4,
C: 10,
}

func TestBasic(t *testing.T) {
sim := sessions.NewSimulator().
Add(
Expand Down Expand Up @@ -64,3 +71,167 @@ func TestBasic(t *testing.T) {
},
}, results[0])
}

func TestClearScreen(t *testing.T) {
sim := sessions.NewSimulator().
Add(
TEST_SIZE,
emu.LineFeedMode,
"foo\n",
"bar\n",
"baz",
).
Term(terminfo.ClearScreen).
Add("test")

results, err := Search(sim.Events(), "foo", nil)
require.NoError(t, err)
require.Equal(t, 1, len(results))
require.Equal(t, SearchResult{
Begin: Address{
Index: 2,
Offset: 2,
},
End: Address{
Index: 5,
Offset: 6,
},
Appearances: []Appearance{
{
Begin: Address{
Index: 2,
Offset: 2,
},
End: Address{
Index: 5,
Offset: 6,
},
Selection: Selection{
From: geom.Vec2{
C: 0,
},
To: geom.Vec2{
C: 2,
},
},
},
},
}, results[0])
}

func TestClearLine(t *testing.T) {
sim := sessions.NewSimulator().
Add(
TEST_SIZE,
emu.LineFeedMode,
"foo\n",
"bar\n",
"baz",
).
Term(terminfo.CursorAddress, 0, 0).
Term(terminfo.DeleteLine)

results, err := Search(sim.Events(), "foo", nil)
require.NoError(t, err)
require.Equal(t, 1, len(results))
require.Equal(t, SearchResult{
Begin: Address{
Index: 2,
Offset: 2,
},
End: Address{
Index: 6,
Offset: 2,
},
Appearances: []Appearance{
{
Begin: Address{
Index: 2,
Offset: 2,
},
End: Address{
Index: 6,
Offset: 2,
},
Selection: Selection{
From: geom.Vec2{
C: 0,
},
To: geom.Vec2{
C: 2,
},
},
},
},
}, results[0])
}

func TestScroll(t *testing.T) {
sim := sessions.NewSimulator().
Add(
TEST_SIZE,
emu.LineFeedMode,
"foo\n",
"bar\n", // 3
"baz\n",
"\n",
"\n", // 6
"test",
)

results, err := Search(sim.Events(), "bar", nil)
require.NoError(t, err)
require.Equal(t, 1, len(results))
require.Equal(t, SearchResult{
Begin: Address{
Index: 3,
Offset: 2,
},
End: Address{
Index: 7,
Offset: 3,
},
Appearances: []Appearance{
{
Begin: Address{
Index: 3,
Offset: 2,
},
End: Address{
Index: 5,
Offset: 0,
},
Selection: Selection{
From: geom.Vec2{
R: 1,
C: 0,
},
To: geom.Vec2{
R: 1,
C: 2,
},
},
},
{
Begin: Address{
Index: 5,
Offset: 0,
},
End: Address{
Index: 7,
Offset: 3,
},
Selection: Selection{
From: geom.Vec2{
R: 0,
C: 0,
},
To: geom.Vec2{
R: 0,
C: 2,
},
},
},
},
}, results[0])
}
6 changes: 0 additions & 6 deletions pkg/sessions/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package sessions
import (
"time"

"github.com/cfoust/cy/pkg/emu"
"github.com/cfoust/cy/pkg/geom"
P "github.com/cfoust/cy/pkg/io/protocol"

Expand Down Expand Up @@ -92,11 +91,6 @@ func (s *Simulator) Add(events ...interface{}) *Simulator {
return s
}

// LineFeed causes \n to return to the start of the next line.
func (s *Simulator) LineFeed() {
s.Add(emu.LineFeedMode)
}

func (s *Simulator) Events() []Event {
return s.events
}
Expand Down

0 comments on commit 37ba304

Please sign in to comment.