From 5347e94d6d52ab89942c64d263e41238c2379e66 Mon Sep 17 00:00:00 2001 From: "@mpyw" Date: Mon, 12 Oct 2026 21:32:18 +0900 Subject: [PATCH] test: tighten namespace Resolve and Spell cases Pin that a test file does not join a //declscope:namespace subject, only a core one. Drop the Spell case that repeated "named", and replace the case with an unreachable input (a stem-bearing path with an empty name) with one that shows the key uses the base name of a stemless file. Co-Authored-By: Claude Opus 5.5 --- internal/namespace/namespace_test.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/internal/namespace/namespace_test.go b/internal/namespace/namespace_test.go index 8f2c455..0f1864f 100644 --- a/internal/namespace/namespace_test.go +++ b/internal/namespace/namespace_test.go @@ -1,6 +1,9 @@ package namespace -import "testing" +import ( + "slices" + "testing" +) func TestOf(t *testing.T) { tests := []struct { @@ -324,6 +327,13 @@ func TestResolve(t *testing.T) { []Declared{{Path: "user.go"}, {Path: "user_test.go"}}, []Resolved{{Name: "user"}, {Name: "user"}}, }, + { + // Only the core is joined. A test file keeps the namespace of its + // own stem unless it states the same directive. + "test file keeps its stem under named subject", + []Declared{{Path: "user.go", Named: true, Name: "custom"}, {Path: "user_test.go"}}, + []Resolved{{Name: "custom"}, {Name: "user"}}, + }, { "mixed core and named", []Declared{ @@ -345,14 +355,8 @@ func TestResolve(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got := Resolve(tt.files) - if len(got) != len(tt.want) { - t.Fatalf("Resolve returned %d results, want %d", len(got), len(tt.want)) - } - for i := range got { - if got[i] != tt.want[i] { - t.Errorf("[%d] = %+v, want %+v", i, got[i], tt.want[i]) - } + if got := Resolve(tt.files); !slices.Equal(got, tt.want) { + t.Errorf("Resolve() = %+v, want %+v", got, tt.want) } }) } @@ -367,9 +371,8 @@ func TestSpell(t *testing.T) { }{ {"core", Resolved{Core: true}, "user.go", "(core)"}, {"named", Resolved{Name: "custom"}, "user.go", "custom"}, - {"derived", Resolved{Name: "user"}, "user.go", "user"}, {"no stem", Resolved{}, ".go", "(file .go)"}, - {"empty name with path", Resolved{}, "helper.go", "(file helper.go)"}, + {"no stem in a directory", Resolved{}, "a/b/.go", "(file .go)"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {