-
Notifications
You must be signed in to change notification settings - Fork 260
/
record_test.go
77 lines (72 loc) · 1007 Bytes
/
record_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"strings"
"testing"
)
func TestInputToTape(t *testing.T) {
input := `echo "Hello,.
BACKSPACE
LEFT
LEFT
RIGHT
RIGHT
world"
ENTER
ENTER
ENTER
ls
ENTER
ENTER
BACKSPACE
CTRL+C
CTRL+C
CTRL+C
CTRL+W
CTRL+A
CTRL+E
SLEEP
SLEEP
ALT+.
SLEEP
exit
`
want := `Type 'echo "Hello,.'
Backspace
Left 2
Right 2
Type ' world"'
Enter 3
Type "ls"
Enter 2
Backspace
Ctrl+C
Ctrl+C
Ctrl+C
Ctrl+W
Ctrl+A
Ctrl+E
Sleep 1s
Alt+.
Sleep 500ms
`
got := inputToTape(input)
if want != got {
t.Fatalf("want:\n%s\ngot:\n%s\n", want, got)
}
}
func TestInputToTapeLongSleep(t *testing.T) {
input := strings.Repeat("SLEEP\n", 121) + "exit"
want := "Sleep 60.5s\n"
got := inputToTape(input)
if want != got {
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)
}
}