Skip to content

Commit

Permalink
fix: silly time bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cfoust committed Dec 15, 2023
1 parent 9f108bd commit 38249a9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
2 changes: 0 additions & 2 deletions pkg/mux/screen/replay/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ type Replay struct {
skipInactivity bool

// The location of Replay in time
// R: the index of the displayed event in `events`
// C: the byte within it
location search.Address
events []sessions.Event

Expand Down
45 changes: 38 additions & 7 deletions pkg/mux/screen/replay/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,48 @@ func TestTime(t *testing.T) {
i(size)
r.gotoIndex(0, -1)
require.Equal(t, e[0].Stamp, r.currentTime)

// Move into first text event
r.setTimeDelta(delta, true)
require.Equal(t, 1, r.location.Index)

// Play again, which should trigger a skip since the time is greater
// than IDLE_THRESHOLD
r.setTimeDelta(delta, true)
require.Equal(t, 2, r.location.Index)
require.Equal(t, e[2].Stamp, r.currentTime)

// Go backwards, which should bring us back to the previous event
r.setTimeDelta(-delta, true)
require.Equal(t, 1, r.location.Index)
require.Equal(t, e[2].Stamp.Add(-delta), r.currentTime)

// Backwards again, which will skip inactivity back to 0
r.setTimeDelta(-delta, true)
require.Equal(t, 0, r.location.Index)
require.Equal(t, e[0].Stamp, r.currentTime)
}

func TestTimeBug(t *testing.T) {
size := geom.Size{R: 5, C: 10}
e := sim().
Add(size).
AddTime(0, "test").
AddTime(3*time.Minute, "test").
AddTime(60*time.Minute, "test").
Events()

r, i := createTest(e)
i(size)
r.gotoIndex(0, -1)

// Simulate a jump forward
r.setTimeDelta(5*time.Minute, false)
require.Equal(t, 2, r.location.Index)
require.Equal(t, r.currentTime.Sub(e[0].Stamp), 5*time.Minute)
// And then a play
r.setTimeDelta(time.Second, r.skipInactivity)
require.Greater(t, r.currentTime.Sub(e[0].Stamp), 5*time.Minute)
}

func TestReadString(t *testing.T) {
Expand Down Expand Up @@ -329,21 +362,19 @@ func TestReadString(t *testing.T) {
}

func TestTimeJump(t *testing.T) {
hour := 3600 * time.Second
size := geom.Size{R: 5, C: 10}
e := sim().
Add(size).
AddTime(0, "test").
AddTime(hour, "test").
AddTime(3*time.Minute, "test").
AddTime(60*time.Minute, "test").
Events()

r, i := createTest(e)
i(size)
r.gotoIndex(1, -1)
i(ActionSearchForward, "5m", "enter")
require.Equal(t, e[0].Stamp.Add(5*time.Minute), r.currentTime)
i(size, ActionBeginning, ActionSearchForward, "5m", "enter")
require.Equal(t, r.currentTime.Sub(e[0].Stamp), 5*time.Minute)
i(ActionSearchBackward, "5m", "enter")
require.Equal(t, e[0].Stamp, r.currentTime)
require.Equal(t, 0, r.location.Index)
}

func TestPrompt(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/mux/screen/replay/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ func (r *Replay) setTimeDelta(delta time.Duration, skipInactivity bool) {
}
} else {
for i := r.location.Index + 1; i < len(r.events); i++ {
if newTime.After(r.events[i].Stamp) {
r.setIndex(i, -1, false)
if newTime.Before(r.events[i].Stamp) {
break
}
nextIndex = i
}
}

Expand Down

0 comments on commit 38249a9

Please sign in to comment.