From 5247a201c8ba77329c7b1ee40da7b8e43a56b567 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 1 Mar 2026 18:10:19 +0200 Subject: =?UTF-8?q?Release=20v0.1.0:=20code=20quality=20audit=20=E2=80=94?= =?UTF-8?q?=20fix=20dialog=20bug,=20refactor,=20add=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix per-keystroke dialog storm when text exceeds maxTextLength - Extract logEntry() for testable persistence with filepath.Join - Extract newInputWidget() and deduplicate shared-text loading - Rename appId to appID per Go naming conventions - Delete unused debugSharedPath function - Add error distinction in readSharedFromCache (log real errors) - Fix ANDORID_NDK_HOME typo to ANDRIOD_NDK_HOME in Magefile - Run gofmt, go mod tidy; promote defaultDirectory to const - Add unit tests for logEntry and readSharedFromCache stub Co-Authored-By: Claude Opus 4.6 --- main_test.go | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 main_test.go (limited to 'main_test.go') diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..085dc24 --- /dev/null +++ b/main_test.go @@ -0,0 +1,62 @@ +package main + +import ( + "os" + "path/filepath" + "strings" + "testing" +) + +func TestLogEntryCreatesFile(t *testing.T) { + dir := t.TempDir() + text := "hello world" + + if err := logEntry(dir, text); err != nil { + t.Fatalf("logEntry returned error: %v", err) + } + + entries, err := os.ReadDir(dir) + if err != nil { + t.Fatalf("reading dir: %v", err) + } + if len(entries) != 1 { + t.Fatalf("expected 1 file, got %d", len(entries)) + } + + name := entries[0].Name() + if !strings.HasPrefix(name, "ql-") || !strings.HasSuffix(name, ".md") { + t.Errorf("unexpected filename pattern: %s", name) + } + + content, err := os.ReadFile(filepath.Join(dir, name)) + if err != nil { + t.Fatalf("reading file: %v", err) + } + if string(content) != text { + t.Errorf("expected %q, got %q", text, string(content)) + } +} + +func TestLogEntryInvalidDir(t *testing.T) { + err := logEntry("/nonexistent/path/that/should/not/exist", "test") + if err == nil { + t.Fatal("expected error for invalid directory, got nil") + } +} + +func TestLogEntryEmptyText(t *testing.T) { + dir := t.TempDir() + if err := logEntry(dir, ""); err != nil { + t.Fatalf("logEntry with empty text returned error: %v", err) + } + + entries, _ := os.ReadDir(dir) + if len(entries) != 1 { + t.Fatalf("expected 1 file, got %d", len(entries)) + } + + content, _ := os.ReadFile(filepath.Join(dir, entries[0].Name())) + if len(content) != 0 { + t.Errorf("expected empty file, got %d bytes", len(content)) + } +} -- cgit v1.2.3