1
Fork 0

Add depth filter

This commit is contained in:
Alex Yatskov 2024-04-15 20:52:36 -07:00
parent 0e6946b010
commit ab0a930eaa
23 changed files with 101 additions and 0 deletions

32
filters/depth/depth.go Normal file
View File

@ -0,0 +1,32 @@
package depth
import (
"path/filepath"
"strings"
"git.foosoft.net/alex/goldsmith"
)
type Depth struct {
depth int
}
func New(depth int) *Depth {
return &Depth{depth: depth}
}
func (*Depth) Name() string {
return "depth"
}
func (self *Depth) Accept(file *goldsmith.File) bool {
if self.depth == 0 {
return true
}
if parts := strings.Split(file.Path(), string(filepath.Separator)); len(parts) <= self.depth {
return true
}
return false
}

View File

@ -0,0 +1,48 @@
package depth
import (
"testing"
"git.foosoft.net/alex/goldsmith"
"git.foosoft.net/alex/goldsmith/harness"
)
func Test0(t *testing.T) {
harness.ValidateCase(
t,
"test_0",
func(gs *goldsmith.Goldsmith) {
gs.FilterPush(New(0))
},
)
}
func Test1(t *testing.T) {
harness.ValidateCase(
t,
"test_1",
func(gs *goldsmith.Goldsmith) {
gs.FilterPush(New(1))
},
)
}
func Test2(t *testing.T) {
harness.ValidateCase(
t,
"test_2",
func(gs *goldsmith.Goldsmith) {
gs.FilterPush(New(2))
},
)
}
func Test10(t *testing.T) {
harness.ValidateCase(
t,
"test_10",
func(gs *goldsmith.Goldsmith) {
gs.FilterPush(New(10))
},
)
}

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@