package autotrack import ( "os" "path/filepath" "testing" ) func TestParseHIDIdle(t *testing.T) { out := `+-o IOHIDSystem { "HIDIdleTime" = 2216064029 }` if got := parseHIDIdle(out); got != 2 { // 2216064029 ns → 2 s t.Errorf("parseHIDIdle=%d, want 2", got) } if got := parseHIDIdle("no idle info here"); got != 0 { t.Errorf("absent key should give 0, got %d", got) } if got := parseHIDIdle(`"HIDIdleTime" = garbage`); got != 0 { t.Errorf("malformed value should give 0, got %d", got) } } func TestParseLocked(t *testing.T) { if !parseLocked(` "CGSSessionScreenIsLocked" = Yes`) { t.Error("locked output should parse true") } if parseLocked("") || parseLocked(`"SomethingElse"=Yes`) { t.Error("unlocked output should parse false") } } func TestParseWinctx(t *testing.T) { app, title := parseWinctx([]byte(`{"app":"Trace","title":"notes — repo"}`)) if app != "Trace" || title != "notes — repo" { t.Errorf("got %q/%q", app, title) } if app, title := parseWinctx([]byte("garbage")); app != "" || title != "" { t.Errorf("bad json should give empties, got %q/%q", app, title) } } func TestHelperPathFallsBackToPATH(t *testing.T) { dir := t.TempDir() bin := filepath.Join(dir, "fakehelper") if err := os.WriteFile(bin, []byte("#!/bin/sh\n"), 0o755); err != nil { t.Fatal(err) } t.Setenv("PATH", dir) if got := HelperPath("fakehelper"); got != bin { t.Errorf("HelperPath=%q, want %q", got, bin) } if got := HelperPath("definitely-not-a-helper"); got != "" { t.Errorf("missing helper should give empty, got %q", got) } }