-
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(config): allow add files to exception in config file
- Loading branch information
Showing
13 changed files
with
259 additions
and
168 deletions.
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
This file was deleted.
Oops, something went wrong.
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,33 @@ | ||
package path | ||
|
||
import ( | ||
"path/filepath" | ||
"regexp" | ||
) | ||
|
||
func GetPathRegex(src string) (*regexp.Regexp, error) { | ||
pattern := filepath.Base(src) | ||
|
||
reg, err := regexp.Compile("\\*") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
pattern = "^" + string(reg.ReplaceAll([]byte(pattern), []byte("[\\w|\\W]*"))) + "$" | ||
|
||
return regexp.Compile(pattern) | ||
} | ||
|
||
func isFilePathIsRegex(reg string) bool { | ||
specialChars := "*+?|[]{}()" | ||
|
||
for _, specChar := range specialChars { | ||
for _, char := range reg { | ||
if char == specChar { | ||
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,35 @@ | ||
package path | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
type argument struct { | ||
in string | ||
out string | ||
} | ||
|
||
func TestGetPathRegex(t *testing.T) { | ||
paths := []argument{ | ||
{"/path/to/example*", "example.txt"}, | ||
{"/path/to/example*", "example1234123412.txt"}, | ||
{"/path/to/example*", "example1$^&@1A.txt"}, | ||
{"/path/to/example.txt", "example.txt"}, | ||
{"/path/to/example", "example"}, | ||
{"/path/to/(example){2}", "exampleexample"}, | ||
{"/path/to/*.mp4", "example.mp4"}, | ||
} | ||
|
||
for _, p := range paths { | ||
t.Run(p.in, func(t *testing.T) { | ||
res, err := GetPathRegex(p.in) | ||
if err != nil { | ||
t.Fatalf("Failed to extract regex from path. %s", err) | ||
} | ||
|
||
if !res.MatchString(p.out) { | ||
t.Fatalf("Failed to match example.txt to regex") | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.