diff --git a/filters/depth/depth.go b/filters/depth/depth.go new file mode 100644 index 0000000..2d16b6f --- /dev/null +++ b/filters/depth/depth.go @@ -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 +} diff --git a/filters/depth/depth_test.go b/filters/depth/depth_test.go new file mode 100644 index 0000000..0d15643 --- /dev/null +++ b/filters/depth/depth_test.go @@ -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)) + }, + ) +} diff --git a/filters/depth/testdata/test_0/reference/1.txt b/filters/depth/testdata/test_0/reference/1.txt new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/filters/depth/testdata/test_0/reference/1.txt @@ -0,0 +1 @@ + diff --git a/filters/depth/testdata/test_0/reference/child/2.txt b/filters/depth/testdata/test_0/reference/child/2.txt new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/filters/depth/testdata/test_0/reference/child/2.txt @@ -0,0 +1 @@ + diff --git a/filters/depth/testdata/test_0/reference/child/child/3.txt b/filters/depth/testdata/test_0/reference/child/child/3.txt new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/filters/depth/testdata/test_0/reference/child/child/3.txt @@ -0,0 +1 @@ + diff --git a/filters/depth/testdata/test_0/source/1.txt b/filters/depth/testdata/test_0/source/1.txt new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/filters/depth/testdata/test_0/source/1.txt @@ -0,0 +1 @@ + diff --git a/filters/depth/testdata/test_0/source/child/2.txt b/filters/depth/testdata/test_0/source/child/2.txt new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/filters/depth/testdata/test_0/source/child/2.txt @@ -0,0 +1 @@ + diff --git a/filters/depth/testdata/test_0/source/child/child/3.txt b/filters/depth/testdata/test_0/source/child/child/3.txt new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/filters/depth/testdata/test_0/source/child/child/3.txt @@ -0,0 +1 @@ + diff --git a/filters/depth/testdata/test_1/reference/1.txt b/filters/depth/testdata/test_1/reference/1.txt new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/filters/depth/testdata/test_1/reference/1.txt @@ -0,0 +1 @@ + diff --git a/filters/depth/testdata/test_1/source/1.txt b/filters/depth/testdata/test_1/source/1.txt new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/filters/depth/testdata/test_1/source/1.txt @@ -0,0 +1 @@ + diff --git a/filters/depth/testdata/test_1/source/child/2.txt b/filters/depth/testdata/test_1/source/child/2.txt new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/filters/depth/testdata/test_1/source/child/2.txt @@ -0,0 +1 @@ + diff --git a/filters/depth/testdata/test_1/source/child/child/3.txt b/filters/depth/testdata/test_1/source/child/child/3.txt new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/filters/depth/testdata/test_1/source/child/child/3.txt @@ -0,0 +1 @@ + diff --git a/filters/depth/testdata/test_10/reference/1.txt b/filters/depth/testdata/test_10/reference/1.txt new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/filters/depth/testdata/test_10/reference/1.txt @@ -0,0 +1 @@ + diff --git a/filters/depth/testdata/test_10/reference/child/2.txt b/filters/depth/testdata/test_10/reference/child/2.txt new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/filters/depth/testdata/test_10/reference/child/2.txt @@ -0,0 +1 @@ + diff --git a/filters/depth/testdata/test_10/reference/child/child/3.txt b/filters/depth/testdata/test_10/reference/child/child/3.txt new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/filters/depth/testdata/test_10/reference/child/child/3.txt @@ -0,0 +1 @@ + diff --git a/filters/depth/testdata/test_10/source/1.txt b/filters/depth/testdata/test_10/source/1.txt new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/filters/depth/testdata/test_10/source/1.txt @@ -0,0 +1 @@ + diff --git a/filters/depth/testdata/test_10/source/child/2.txt b/filters/depth/testdata/test_10/source/child/2.txt new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/filters/depth/testdata/test_10/source/child/2.txt @@ -0,0 +1 @@ + diff --git a/filters/depth/testdata/test_10/source/child/child/3.txt b/filters/depth/testdata/test_10/source/child/child/3.txt new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/filters/depth/testdata/test_10/source/child/child/3.txt @@ -0,0 +1 @@ + diff --git a/filters/depth/testdata/test_2/reference/1.txt b/filters/depth/testdata/test_2/reference/1.txt new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/filters/depth/testdata/test_2/reference/1.txt @@ -0,0 +1 @@ + diff --git a/filters/depth/testdata/test_2/reference/child/2.txt b/filters/depth/testdata/test_2/reference/child/2.txt new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/filters/depth/testdata/test_2/reference/child/2.txt @@ -0,0 +1 @@ + diff --git a/filters/depth/testdata/test_2/source/1.txt b/filters/depth/testdata/test_2/source/1.txt new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/filters/depth/testdata/test_2/source/1.txt @@ -0,0 +1 @@ + diff --git a/filters/depth/testdata/test_2/source/child/2.txt b/filters/depth/testdata/test_2/source/child/2.txt new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/filters/depth/testdata/test_2/source/child/2.txt @@ -0,0 +1 @@ + diff --git a/filters/depth/testdata/test_2/source/child/child/3.txt b/filters/depth/testdata/test_2/source/child/child/3.txt new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/filters/depth/testdata/test_2/source/child/child/3.txt @@ -0,0 +1 @@ +