From 71bac5c2cce1687c197817dc4dcf2132cd3ff3d2 Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Sat, 25 Apr 2026 07:03:28 +0000 Subject: [PATCH] test(normalize): cover manager helper edge cases --- brew/brew_test.go | 2 ++ snap/snap_test.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/brew/brew_test.go b/brew/brew_test.go index 8e72ae7..2838850 100644 --- a/brew/brew_test.go +++ b/brew/brew_test.go @@ -139,6 +139,7 @@ func TestNormalizeName(t *testing.T) { {"node@18", "node"}, {"go", "go"}, {"ruby@3.2", "ruby"}, + {"postgresql@16@beta", "postgresql@16"}, } b := New() @@ -347,6 +348,7 @@ func TestParseVersionSuffix(t *testing.T) { {"node@18", "node", "18"}, {"git", "git", ""}, {"ruby@3.2", "ruby", "3.2"}, + {"postgresql@16@beta", "postgresql@16", "beta"}, {"", "", ""}, {"@3.12", "@3.12", ""}, // @ at position 0, LastIndex returns 0 which is not > 0 } diff --git a/snap/snap_test.go b/snap/snap_test.go index 20d11e9..de66d7c 100644 --- a/snap/snap_test.go +++ b/snap/snap_test.go @@ -455,3 +455,49 @@ func TestName(t *testing.T) { t.Errorf("Name() = %q, want %q", s.Name(), "snap") } } + +func TestNormalizeName(t *testing.T) { + tests := []struct { + input string + want string + }{ + {"firefox", "firefox"}, + {"hello-world", "hello-world"}, + {"snap.with.dots", "snap.with.dots"}, + {" keep-whitespace ", " keep-whitespace "}, + {"", ""}, + } + + s := New() + for _, tt := range tests { + t.Run(tt.input, func(t *testing.T) { + if got := s.NormalizeName(tt.input); got != tt.want { + t.Errorf("NormalizeName(%q) = %q, want %q", tt.input, got, tt.want) + } + }) + } +} + +func TestParseArch(t *testing.T) { + tests := []struct { + input string + wantName string + wantArch string + }{ + {"firefox", "firefox", ""}, + {"hello-world", "hello-world", ""}, + {"snap.with.dots", "snap.with.dots", ""}, + {"", "", ""}, + } + + s := New() + for _, tt := range tests { + t.Run(tt.input, func(t *testing.T) { + gotName, gotArch := s.ParseArch(tt.input) + if gotName != tt.wantName || gotArch != tt.wantArch { + t.Errorf("ParseArch(%q) = (%q, %q), want (%q, %q)", + tt.input, gotName, gotArch, tt.wantName, tt.wantArch) + } + }) + } +}