summaryrefslogtreecommitdiff
path: root/internal/collector/parse_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-18 09:00:35 +0200
committerPaul Buetow <paul@buetow.org>2026-02-18 09:00:35 +0200
commit88f4e239a7521112a4db8c7842e3a05db4446cd4 (patch)
tree8c331f9f2e23ad9c9319d6dc8275205b23ce811a /internal/collector/parse_test.go
parent11204092b5ab5dc0f71515adfcaa6f07111363e5 (diff)
feat: triple-toggle CPU display mode via 1 key; add tooltip, font, hit-test
CPU display now cycles through three states with each press of 1: 0 = CPUModeAverage – aggregate bar only (default) 1 = CPUModeCores – individual core bars + aggregate 2 = CPUModeOff – all CPU bars hidden Config file stores cpumode=N (integer); old showcores=0/1 is read for backward compatibility. CLI flag --showcores replaced by --cpumode. Other improvements landed in this commit: - internal/display: add font.go (text rendering), hittest.go (bar hit testing), tooltip.go (mouse-over tooltip), tooltip_test.go - internal/display: mouse tracking and drawOverlay hook in display.go - internal/display: update build tags to //go:build form - internal/collector: embed remote script via script_embed.go / scriptdata/loadbars-remote.sh - internal/collector: CPULine.Total() changed to value receiver - internal/collector: table test improvements (name field, t.Run) - internal/constants: BytesPerSec consts promoted from var to const - Magefile.go: fix error formatting and install path Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/collector/parse_test.go')
-rw-r--r--internal/collector/parse_test.go34
1 files changed, 18 insertions, 16 deletions
diff --git a/internal/collector/parse_test.go b/internal/collector/parse_test.go
index ec77067..fe7a73c 100644
--- a/internal/collector/parse_test.go
+++ b/internal/collector/parse_test.go
@@ -44,29 +44,31 @@ func TestParseCPULine(t *testing.T) {
func TestParseMemLine(t *testing.T) {
tests := []struct {
+ name string
line string
wantKey string
wantValue int64
wantOK bool
}{
- {"MemTotal: 123456 kB", "MemTotal", 123456, true},
- {"MemFree: 99999 kB", "MemFree", 99999, true},
- {"Buffers: 0 kB", "Buffers", 0, true},
- {"not a mem line", "", 0, false},
- {"", "", 0, false},
+ {"MemTotal", "MemTotal: 123456 kB", "MemTotal", 123456, true},
+ {"MemFree", "MemFree: 99999 kB", "MemFree", 99999, true},
+ {"Buffers_zero", "Buffers: 0 kB", "Buffers", 0, true},
+ {"not_a_mem_line", "not a mem line", "", 0, false},
+ {"empty_string", "", "", 0, false},
}
for _, tt := range tests {
- got, ok := ParseMemLine(tt.line)
- if ok != tt.wantOK {
- t.Errorf("ParseMemLine(%q) ok = %v, want %v", tt.line, ok, tt.wantOK)
- continue
- }
- if !tt.wantOK {
- continue
- }
- if got.Key != tt.wantKey || got.Value != tt.wantValue {
- t.Errorf("ParseMemLine(%q) = %+v, want key=%q value=%d", tt.line, got, tt.wantKey, tt.wantValue)
- }
+ t.Run(tt.name, func(t *testing.T) {
+ got, ok := ParseMemLine(tt.line)
+ if ok != tt.wantOK {
+ t.Fatalf("ParseMemLine(%q) ok = %v, want %v", tt.line, ok, tt.wantOK)
+ }
+ if !tt.wantOK {
+ return
+ }
+ if got.Key != tt.wantKey || got.Value != tt.wantValue {
+ t.Errorf("ParseMemLine(%q) = %+v, want key=%q value=%d", tt.line, got, tt.wantKey, tt.wantValue)
+ }
+ })
}
}