From d27b86d29614e1aead825f4a7e50a1d89f970665 Mon Sep 17 00:00:00 2001 From: Gubarz <1037896+Gubarz@users.noreply.github.com> Date: Wed, 13 May 2026 03:19:41 -0600 Subject: [PATCH] fix single line cheat comment this resolves a bug where a single line cheat comment was not being recognised --- internal/parser/lex.go | 5 ++++- internal/parser/parser_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/internal/parser/lex.go b/internal/parser/lex.go index 6a74012..aeae0d3 100644 --- a/internal/parser/lex.go +++ b/internal/parser/lex.go @@ -141,7 +141,7 @@ func parseCodeBlockStart(line []byte) (lang, desc string, ok bool) { // parseCheatSingleLine parses and returns the content. func parseCheatSingleLine(line []byte) (string, bool) { - if len(line) < 15 { + if len(line) < len("") { return "", false } if !bytes.HasPrefix(line, []byte("\n" + if err := os.WriteFile(path, []byte(content), 0o644); err != nil { + t.Fatal(err) + } + + p := NewParser() + index, err := p.ParseSingleFile(path) + if err != nil { + t.Fatalf("ParseSingleFile() error: %v", err) + } + + if len(index.Cheats) != 1 { + t.Fatalf("ParseSingleFile() cheats = %d, want 1", len(index.Cheats)) + } + cheat := index.Cheats[0] + if !cheat.HasCheatBlock { + t.Fatal("single-line did not mark cheat as having a cheat block") + } + if cheat.Command != "echo hi" { + t.Fatalf("command = %q, want %q", cheat.Command, "echo hi") + } +} + +func TestParseCheatSingleLineRequiresKeywordBoundary(t *testing.T) { + if _, ok := parseCheatSingleLine([]byte("")); ok { + t.Fatal("parseCheatSingleLine accepted non-cheat keyword") + } +} + func TestNewCheatIndex(t *testing.T) { idx := NewCheatIndex() if idx == nil {