diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-24 08:34:00 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-24 08:34:00 +0200 |
| commit | 89ba8287d490a0fef15a80a34ea4efe0c5ecf2e8 (patch) | |
| tree | d164744464c7997a23be60200eebf710015d8fed /internal/tui/dashboard/sparkline_test.go | |
| parent | 9c400937d9e32f3ce85c668d9ca52c351f8b5d13 (diff) | |
tui: add dashboard sparkline renderer
Diffstat (limited to 'internal/tui/dashboard/sparkline_test.go')
| -rw-r--r-- | internal/tui/dashboard/sparkline_test.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/internal/tui/dashboard/sparkline_test.go b/internal/tui/dashboard/sparkline_test.go new file mode 100644 index 0000000..d39d145 --- /dev/null +++ b/internal/tui/dashboard/sparkline_test.go @@ -0,0 +1,43 @@ +package dashboard + +import ( + "strings" + "testing" +) + +func TestRenderSparklineEmptyOrInvalidWidth(t *testing.T) { + if got := renderSparkline(nil, 5); got != "" { + t.Fatalf("expected empty sparkline for nil data, got %q", got) + } + if got := renderSparkline([]float64{1, 2, 3}, 0); got != "" { + t.Fatalf("expected empty sparkline for width 0, got %q", got) + } +} + +func TestRenderSparklineSingleValue(t *testing.T) { + got := renderSparkline([]float64{10}, 8) + if got != "▄" { + t.Fatalf("expected single mid-bar rune, got %q", got) + } +} + +func TestRenderSparklineAllEqualValues(t *testing.T) { + got := renderSparkline([]float64{5, 5, 5, 5}, 4) + if got != "▄▄▄▄" { + t.Fatalf("expected flat sparkline, got %q", got) + } +} + +func TestRenderSparklineRespectsWidthTruncation(t *testing.T) { + got := renderSparkline([]float64{1, 2, 3, 4, 5, 6, 7, 8}, 4) + if len([]rune(got)) != 4 { + t.Fatalf("expected 4 runes, got %q", got) + } +} + +func TestRenderSparklineSpansLowToHigh(t *testing.T) { + got := renderSparkline([]float64{0, 10}, 2) + if !strings.Contains(got, "▁") || !strings.Contains(got, "█") { + t.Fatalf("expected low/high bars, got %q", got) + } +} |
