Skip to content

Commit

Permalink
Fix app crash when there is repeated SLEEP at the end of the "lines" …
Browse files Browse the repository at this point in the history
…slice (#446)

I found the issue while testing a low value of 5ms for sleepThreshold
  • Loading branch information
alaingilbert authored Mar 6, 2024
1 parent ee35faf commit 9950678
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions record.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ func inputToTape(input string) string {
repeat := 1
for lines[i] == lines[i+repeat] {
repeat++
if i+repeat == len(lines) {
break
}
}
i += repeat - 1

Expand Down
9 changes: 9 additions & 0 deletions record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,12 @@ func TestInputToTapeLongSleep(t *testing.T) {
t.Fatalf("want:\n%s\ngot:\n%s\n", want, got)
}
}

func TestInputToTape_RepeatedSleepAfterExit(t *testing.T) {
input := "SLEEP\nexit\nSLEEP\nSLEEP"
want := "Sleep 500ms\nType \"exit\"\nSleep 1s\n"
got := inputToTape(input)
if want != got {
t.Fatalf("want:\n%s\ngot:\n%s\n", want, got)
}
}

0 comments on commit 9950678

Please sign in to comment.