From 2b898fc190cfcd5cf123439b352ed13c690a927e Mon Sep 17 00:00:00 2001 From: bashbunni Date: Wed, 15 Jan 2025 07:44:02 -0800 Subject: [PATCH 1/3] fix(record): set PAGEX to PAGE_X for proper capitalization --- command.go | 4 ++-- lexer/lexer_test.go | 12 +++++------ parser/parser.go | 8 ++++---- parser/parser_test.go | 12 +++++------ record.go | 4 ++-- record_test.go | 48 +++++++++++++++++++++++++++++++++++-------- token/token.go | 10 ++++----- 7 files changed, 65 insertions(+), 33 deletions(-) diff --git a/command.go b/command.go index d60f78520..8cd72931d 100644 --- a/command.go +++ b/command.go @@ -60,8 +60,8 @@ var CommandFuncs = map[parser.CommandType]CommandFunc{ token.UP: ExecuteKey(input.ArrowUp), token.TAB: ExecuteKey(input.Tab), token.ESCAPE: ExecuteKey(input.Escape), - token.PAGEUP: ExecuteKey(input.PageUp), - token.PAGEDOWN: ExecuteKey(input.PageDown), + token.PAGE_UP: ExecuteKey(input.PageUp), + token.PAGE_DOWN: ExecuteKey(input.PageDown), token.HIDE: ExecuteHide, token.REQUIRE: ExecuteRequire, token.SHOW: ExecuteShow, diff --git a/lexer/lexer_test.go b/lexer/lexer_test.go index f981d0e94..1eead752a 100644 --- a/lexer/lexer_test.go +++ b/lexer/lexer_test.go @@ -219,10 +219,10 @@ func TestLexTapeFile(t *testing.T) { {token.AT, "@"}, {token.NUMBER, "1"}, {token.NUMBER, "3"}, - {token.PAGEDOWN, "PageDown"}, - {token.PAGEDOWN, "PageDown"}, + {token.PAGE_DOWN, "PageDown"}, + {token.PAGE_DOWN, "PageDown"}, {token.NUMBER, "2"}, - {token.PAGEDOWN, "PageDown"}, + {token.PAGE_DOWN, "PageDown"}, {token.AT, "@"}, {token.NUMBER, "1"}, {token.NUMBER, "3"}, @@ -268,10 +268,10 @@ func TestLexTapeFile(t *testing.T) { {token.AT, "@"}, {token.NUMBER, "1"}, {token.NUMBER, "3"}, - {token.PAGEUP, "PageUp"}, - {token.PAGEUP, "PageUp"}, + {token.PAGE_UP, "PageUp"}, + {token.PAGE_UP, "PageUp"}, {token.NUMBER, "2"}, - {token.PAGEUP, "PageUp"}, + {token.PAGE_UP, "PageUp"}, {token.AT, "@"}, {token.NUMBER, "1"}, {token.NUMBER, "3"}, diff --git a/parser/parser.go b/parser/parser.go index 3f06c3b93..c18c9364d 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -36,8 +36,8 @@ var CommandTypes = []CommandType{ //nolint: deadcode token.ESCAPE, token.ILLEGAL, token.LEFT, - token.PAGEUP, - token.PAGEDOWN, + token.PAGE_UP, + token.PAGE_DOWN, token.RIGHT, token.SET, token.OUTPUT, @@ -144,8 +144,8 @@ func (p *Parser) parseCommand() Command { token.LEFT, token.RIGHT, token.UP, - token.PAGEUP, - token.PAGEDOWN: + token.PAGE_UP, + token.PAGE_DOWN: return p.parseKeypress(p.cur.Type) case token.SET: return p.parseSet() diff --git a/parser/parser_test.go b/parser/parser_test.go index fd4e577b5..d10a4c9cc 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -160,9 +160,9 @@ func TestParseTapeFile(t *testing.T) { {Type: token.DOWN, Options: "", Args: "1"}, {Type: token.DOWN, Options: "", Args: "2"}, {Type: token.DOWN, Options: "1s", Args: "3"}, - {Type: token.PAGEDOWN, Options: "", Args: "1"}, - {Type: token.PAGEDOWN, Options: "", Args: "2"}, - {Type: token.PAGEDOWN, Options: "1s", Args: "3"}, + {Type: token.PAGE_DOWN, Options: "", Args: "1"}, + {Type: token.PAGE_DOWN, Options: "", Args: "2"}, + {Type: token.PAGE_DOWN, Options: "1s", Args: "3"}, {Type: token.ENTER, Options: "", Args: "1"}, {Type: token.ENTER, Options: "", Args: "2"}, {Type: token.ENTER, Options: "1s", Args: "3"}, @@ -181,9 +181,9 @@ func TestParseTapeFile(t *testing.T) { {Type: token.UP, Options: "", Args: "1"}, {Type: token.UP, Options: "", Args: "2"}, {Type: token.UP, Options: "1s", Args: "3"}, - {Type: token.PAGEUP, Options: "", Args: "1"}, - {Type: token.PAGEUP, Options: "", Args: "2"}, - {Type: token.PAGEUP, Options: "1s", Args: "3"}, + {Type: token.PAGE_UP, Options: "", Args: "1"}, + {Type: token.PAGE_UP, Options: "", Args: "2"}, + {Type: token.PAGE_UP, Options: "1s", Args: "3"}, {Type: token.DOWN, Options: "", Args: "1"}, {Type: token.DOWN, Options: "", Args: "2"}, {Type: token.DOWN, Options: "1s", Args: "3"}, diff --git a/record.go b/record.go index cafac682c..53b63674a 100644 --- a/record.go +++ b/record.go @@ -31,8 +31,8 @@ var EscapeSequences = map[string]string{ "\x1b[2~": token.INSERT, "\x1b[3~": token.DELETE, "\x1b[4~": token.END, - "\x1b[5~": token.PAGEUP, - "\x1b[6~": token.PAGEDOWN, + "\x1b[5~": token.PAGE_UP, + "\x1b[6~": token.PAGE_DOWN, "\x01": token.CTRL + "+A", "\x02": token.CTRL + "+B", "\x03": token.CTRL + "+C", diff --git a/record_test.go b/record_test.go index ea9b26dee..17a7109e6 100644 --- a/record_test.go +++ b/record_test.go @@ -6,7 +6,14 @@ import ( ) func TestInputToTape(t *testing.T) { - input := `echo "Hello,. + tests := []struct { + name string + input string + want string + }{ + { + name: "ctrl key combinations", + input: `echo "Hello,. BACKSPACE LEFT LEFT @@ -31,9 +38,8 @@ SLEEP ALT+. SLEEP exit -` - - want := `Type 'echo "Hello,.' +`, + want: `Type 'echo "Hello,.' Backspace Left 2 Right 2 @@ -51,10 +57,36 @@ Ctrl+E Sleep 1s Alt+. Sleep 500ms -` - got := inputToTape(input) - if want != got { - t.Fatalf("want:\n%s\ngot:\n%s\n", want, got) +`, + }, + { + name: "PageUp, PageDown #559", + input: `echo "Hello,. +PAGE_UP +PAGE_UP +PAGE_UP +PAGE_UP +PAGE_UP +PAGE_UP +PAGE_UP +PAGE_UP +PAGE_DOWN +PAGE_DOWN +PAGE_DOWN +PAGE_DOWN +exit +`, + want: `Type 'echo "Hello,.' +PageUp 8 +PageDown 4 +`, + }, + } + for _, tc := range tests { + got := inputToTape(tc.input) + if tc.want != got { + t.Fatalf("want:\n%s\ngot:\n%s\n", tc.want, got) + } } } diff --git a/token/token.go b/token/token.go index 318939661..b2ecef6bf 100644 --- a/token/token.go +++ b/token/token.go @@ -43,8 +43,8 @@ const ( ESCAPE = "ESCAPE" HOME = "HOME" INSERT = "INSERT" - PAGEDOWN = "PAGEDOWN" - PAGEUP = "PAGEUP" + PAGE_DOWN = "PAGE_DOWN" + PAGE_UP = "PAGE_UP" SLEEP = "SLEEP" SPACE = "SPACE" TAB = "TAB" @@ -119,8 +119,8 @@ var Keywords = map[string]Type{ "Left": LEFT, "Right": RIGHT, "Up": UP, - "PageUp": PAGEUP, - "PageDown": PAGEDOWN, + "PageUp": PAGE_UP, + "PageDown": PAGE_DOWN, "Tab": TAB, "Escape": ESCAPE, "End": END, @@ -176,7 +176,7 @@ func IsSetting(t Type) bool { func IsCommand(t Type) bool { switch t { case TYPE, SLEEP, - UP, DOWN, RIGHT, LEFT, PAGEUP, PAGEDOWN, + UP, DOWN, RIGHT, LEFT, PAGE_UP, PAGE_DOWN, ENTER, BACKSPACE, DELETE, TAB, ESCAPE, HOME, INSERT, END, CTRL, SOURCE, SCREENSHOT, COPY, PASTE, WAIT: return true From a8d495865d0684a9ae2e9e13ab4924b629f272db Mon Sep 17 00:00:00 2001 From: bashbunni Date: Wed, 15 Jan 2025 07:49:48 -0800 Subject: [PATCH 2/3] chore: fix lint + formatting --- command.go | 4 ++-- token/token.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/command.go b/command.go index 8cd72931d..e312a3e19 100644 --- a/command.go +++ b/command.go @@ -60,8 +60,8 @@ var CommandFuncs = map[parser.CommandType]CommandFunc{ token.UP: ExecuteKey(input.ArrowUp), token.TAB: ExecuteKey(input.Tab), token.ESCAPE: ExecuteKey(input.Escape), - token.PAGE_UP: ExecuteKey(input.PageUp), - token.PAGE_DOWN: ExecuteKey(input.PageDown), + token.PAGE_UP: ExecuteKey(input.PageUp), + token.PAGE_DOWN: ExecuteKey(input.PageDown), token.HIDE: ExecuteHide, token.REQUIRE: ExecuteRequire, token.SHOW: ExecuteShow, diff --git a/token/token.go b/token/token.go index b2ecef6bf..37d491c73 100644 --- a/token/token.go +++ b/token/token.go @@ -119,8 +119,8 @@ var Keywords = map[string]Type{ "Left": LEFT, "Right": RIGHT, "Up": UP, - "PageUp": PAGE_UP, - "PageDown": PAGE_DOWN, + "PageUp": PAGE_UP, //nolint:revive + "PageDown": PAGE_DOWN, //nolint:revive "Tab": TAB, "Escape": ESCAPE, "End": END, From 9c0f53d9ed2bc9133f4c0125e76f43c4817d7242 Mon Sep 17 00:00:00 2001 From: bashbunni Date: Wed, 15 Jan 2025 07:55:26 -0800 Subject: [PATCH 3/3] chore(lint): add lint ignore for snake case --- token/token.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/token/token.go b/token/token.go index 37d491c73..5b8eb84d6 100644 --- a/token/token.go +++ b/token/token.go @@ -43,8 +43,8 @@ const ( ESCAPE = "ESCAPE" HOME = "HOME" INSERT = "INSERT" - PAGE_DOWN = "PAGE_DOWN" - PAGE_UP = "PAGE_UP" + PAGE_DOWN = "PAGE_DOWN" //nolint:revive + PAGE_UP = "PAGE_UP" //nolint:revive SLEEP = "SLEEP" SPACE = "SPACE" TAB = "TAB"