-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow filtering by extension with -e flag
- Loading branch information
1 parent
b238641
commit 71a5749
Showing
6 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package core | ||
|
||
func ExtensionFilter(path string, extensions []string) bool { | ||
if len(extensions) == 0 { | ||
return true | ||
} | ||
|
||
for _, extension := range extensions { | ||
if extension == path[len(path)-len(extension):] { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package core_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/lucaschain/beholder/core" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestExtensionFilter(t *testing.T) { | ||
t.Run("should return true if no extensions passed", func(t *testing.T) { | ||
assert.True(t, core.ExtensionFilter("foo.go", []string{})) | ||
}) | ||
|
||
t.Run("should return true if path has one of the extensions", func(t *testing.T) { | ||
assert.True(t, core.ExtensionFilter("foo.go", []string{".go", ".rb"})) | ||
}) | ||
|
||
t.Run("should return false if the patch matches none of the extensions", func(t *testing.T) { | ||
assert.False(t, core.ExtensionFilter("foo.go", []string{".rb", ".js"})) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters