From fbf242cee18655daa13a85d57cf4465736380f35 Mon Sep 17 00:00:00 2001 From: JP Appel Date: Thu, 12 Jun 2025 03:17:08 -0400 Subject: Add index filter for parent directories --- pkg/index/filters_test.go | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'pkg/index/filters_test.go') diff --git a/pkg/index/filters_test.go b/pkg/index/filters_test.go index f1226b9..f46874c 100644 --- a/pkg/index/filters_test.go +++ b/pkg/index/filters_test.go @@ -65,6 +65,22 @@ func markdownExtension(t *testing.T) infoPath { return infoPath{path, info} } +func parentDirectory(t *testing.T) infoPath { + root := t.TempDir() + dir := root + "/parent" + path := dir + "/a" + + return infoPath{path: path} +} + +func grandparentDirectory(t *testing.T) infoPath { + root := t.TempDir() + dir := root + "/grandparent/parent" + path := dir + "/a" + + return infoPath{path: path} +} + func TestYamlHeaderFilter(t *testing.T) { tests := []struct { name string @@ -110,3 +126,39 @@ func TestExtensionFilter(t *testing.T) { }) } } + +func TestExcludeParentFilter(t *testing.T) { + tests := []struct { + name string + infoGen func(*testing.T) infoPath + parent string + want bool + }{ + { + "no matching parent", + parentDirectory, + "foobar", true, + }, + { + "direct parent", + parentDirectory, + "parent", false, + }, + { + "nested parent", + grandparentDirectory, + "grandparent", false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + docFilter := NewExcludeParentFilter(tt.parent) + ip := tt.infoGen(t) + got := docFilter.Filter(ip, nil) + + if got != tt.want { + t.Errorf("ExcludeParentFilter() = %v, want %v", got, tt.want) + } + }) + } +} -- cgit v1.2.3