-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check name pattern before add sub folders as new candidates
- Loading branch information
1 parent
f2c15df
commit b740964
Showing
8 changed files
with
66 additions
and
42 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 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 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,23 @@ | ||
package spider | ||
|
||
import ( | ||
"regexp" | ||
|
||
"github.com/golangplus/strings" | ||
) | ||
|
||
var nonGoSubFolders = stringsp.NewSet( | ||
"javascript", "js", "css", "image", "images", "font", "fonts", "script", "scripts", "themes", "templates", "vendor", "bin", "cpp", "python", "nodejs", | ||
) | ||
|
||
var nonGoSubPattern = regexp.MustCompile(`^[0-9\-_]+$`) | ||
|
||
func LikeGoSubFolder(folder string) bool { | ||
if nonGoSubFolders.Contain(folder) { | ||
return false | ||
} | ||
if nonGoSubPattern.MatchString(folder) { | ||
return false | ||
} | ||
return true | ||
} |
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,24 @@ | ||
package spider | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/golangplus/testing/assert" | ||
) | ||
|
||
func TestLikeGoSubFolder(t *testing.T) { | ||
pos_cases := []string{ | ||
"go", "v8", "v-8", | ||
} | ||
for _, c := range pos_cases { | ||
assert.True(t, fmt.Sprintf("LikeGoSubFolder %v", c), LikeGoSubFolder(c)) | ||
} | ||
|
||
neg_cases := []string{ | ||
"js", "1234", "1234-5678", "1234_5678", | ||
} | ||
for _, c := range neg_cases { | ||
assert.False(t, fmt.Sprintf("LikeGoSubFolder %v", c), LikeGoSubFolder(c)) | ||
} | ||
} |