summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-04 00:11:01 +0200
committerPaul Buetow <paul@buetow.org>2026-03-04 00:11:01 +0200
commit790ed02ed9d1bae8624c30831d4114187463abd9 (patch)
treebdf70b010967ec93bff8892dd40a050a08fcf37b
parent79b21d5b7d82ceed208fbf488cbac2f01f6ba635 (diff)
ascii: add coverage for GetFont and rendering
-rw-r--r--internal/ascii/render_test.go87
1 files changed, 87 insertions, 0 deletions
diff --git a/internal/ascii/render_test.go b/internal/ascii/render_test.go
new file mode 100644
index 0000000..1ba4f90
--- /dev/null
+++ b/internal/ascii/render_test.go
@@ -0,0 +1,87 @@
+package ascii
+
+import (
+ "testing"
+
+ "github.com/charmbracelet/lipgloss"
+)
+
+func TestGetFont(t *testing.T) {
+ tests := []struct {
+ name string
+ fontName string
+ want Font
+ }{
+ {
+ name: "known font",
+ fontName: Rebel,
+ want: fonts[Rebel],
+ },
+ {
+ name: "unknown font falls back to default",
+ fontName: "missing-font",
+ want: fonts[DefaultFont],
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := GetFont(tt.fontName)
+ if got != tt.want {
+ t.Fatalf("GetFont(%q) returned unexpected font", tt.fontName)
+ }
+ })
+ }
+}
+
+func TestRenderNumber(t *testing.T) {
+ font := fonts[Mono12]
+
+ tests := []struct {
+ name string
+ input string
+ expect string
+ }{
+ {
+ name: "digits and colon",
+ input: "10:2",
+ expect: lipgloss.JoinHorizontal(lipgloss.Top, font[1], font[0], font[10], font[2]),
+ },
+ {
+ name: "unsupported runes are empty",
+ input: "1x2",
+ expect: lipgloss.JoinHorizontal(lipgloss.Top, font[1], "", font[2]),
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := RenderNumber(tt.input, font)
+ if got != tt.expect {
+ t.Fatalf("RenderNumber(%q) returned unexpected output", tt.input)
+ }
+ })
+ }
+}
+
+func TestRenderDigit(t *testing.T) {
+ font := fonts[Ansi]
+
+ tests := []struct {
+ name string
+ input rune
+ want string
+ }{
+ {name: "digit", input: '3', want: font[3]},
+ {name: "colon", input: ':', want: font[10]},
+ {name: "unsupported", input: 'x', want: ""},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := renderDigit(tt.input, font); got != tt.want {
+ t.Fatalf("renderDigit(%q) = %q, want %q", tt.input, got, tt.want)
+ }
+ })
+ }
+}