Add depth filter
This commit is contained in:
parent
0e6946b010
commit
ab0a930eaa
32
filters/depth/depth.go
Normal file
32
filters/depth/depth.go
Normal 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
|
||||||
|
}
|
48
filters/depth/depth_test.go
Normal file
48
filters/depth/depth_test.go
Normal 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))
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
1
filters/depth/testdata/test_0/reference/1.txt
vendored
Normal file
1
filters/depth/testdata/test_0/reference/1.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
filters/depth/testdata/test_0/reference/child/2.txt
vendored
Normal file
1
filters/depth/testdata/test_0/reference/child/2.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
filters/depth/testdata/test_0/reference/child/child/3.txt
vendored
Normal file
1
filters/depth/testdata/test_0/reference/child/child/3.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
filters/depth/testdata/test_0/source/1.txt
vendored
Normal file
1
filters/depth/testdata/test_0/source/1.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
filters/depth/testdata/test_0/source/child/2.txt
vendored
Normal file
1
filters/depth/testdata/test_0/source/child/2.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
filters/depth/testdata/test_0/source/child/child/3.txt
vendored
Normal file
1
filters/depth/testdata/test_0/source/child/child/3.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
filters/depth/testdata/test_1/reference/1.txt
vendored
Normal file
1
filters/depth/testdata/test_1/reference/1.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
filters/depth/testdata/test_1/source/1.txt
vendored
Normal file
1
filters/depth/testdata/test_1/source/1.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
filters/depth/testdata/test_1/source/child/2.txt
vendored
Normal file
1
filters/depth/testdata/test_1/source/child/2.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
filters/depth/testdata/test_1/source/child/child/3.txt
vendored
Normal file
1
filters/depth/testdata/test_1/source/child/child/3.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
filters/depth/testdata/test_10/reference/1.txt
vendored
Normal file
1
filters/depth/testdata/test_10/reference/1.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
filters/depth/testdata/test_10/reference/child/2.txt
vendored
Normal file
1
filters/depth/testdata/test_10/reference/child/2.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
filters/depth/testdata/test_10/reference/child/child/3.txt
vendored
Normal file
1
filters/depth/testdata/test_10/reference/child/child/3.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
filters/depth/testdata/test_10/source/1.txt
vendored
Normal file
1
filters/depth/testdata/test_10/source/1.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
filters/depth/testdata/test_10/source/child/2.txt
vendored
Normal file
1
filters/depth/testdata/test_10/source/child/2.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
filters/depth/testdata/test_10/source/child/child/3.txt
vendored
Normal file
1
filters/depth/testdata/test_10/source/child/child/3.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
filters/depth/testdata/test_2/reference/1.txt
vendored
Normal file
1
filters/depth/testdata/test_2/reference/1.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
filters/depth/testdata/test_2/reference/child/2.txt
vendored
Normal file
1
filters/depth/testdata/test_2/reference/child/2.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
filters/depth/testdata/test_2/source/1.txt
vendored
Normal file
1
filters/depth/testdata/test_2/source/1.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
filters/depth/testdata/test_2/source/child/2.txt
vendored
Normal file
1
filters/depth/testdata/test_2/source/child/2.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
filters/depth/testdata/test_2/source/child/child/3.txt
vendored
Normal file
1
filters/depth/testdata/test_2/source/child/child/3.txt
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
Loading…
Reference in New Issue
Block a user