aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/index/filters_test.go
diff options
context:
space:
mode:
authorJP Appel <jeanpierre.appel01@gmail.com>2025-06-12 03:17:08 -0400
committerJP Appel <jeanpierre.appel01@gmail.com>2025-06-12 03:17:08 -0400
commitfbf242cee18655daa13a85d57cf4465736380f35 (patch)
tree434c4459423e0ccd083c74aba95f6b43cd8bb556 /pkg/index/filters_test.go
parent61d89ee58e6a4d990e6e81c951731c80c2cd1ece (diff)
Add index filter for parent directories
Diffstat (limited to 'pkg/index/filters_test.go')
-rw-r--r--pkg/index/filters_test.go52
1 files changed, 52 insertions, 0 deletions
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)
+ }
+ })
+ }
+}