generated from VLADIMIR/template
clear
This commit is contained in:
@@ -2,4 +2,5 @@ package cleaner
|
||||
|
||||
type ICleaner interface {
|
||||
ClearCode(code string) string
|
||||
ClearText(text string) string
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package cleaner
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
replaceMap = map[string]string{
|
||||
@@ -18,6 +21,7 @@ var (
|
||||
"b": "в",
|
||||
"u": "и",
|
||||
}
|
||||
re = regexp.MustCompile(`\(\[[a-zA-Zа-яА-Я\d-]+\]\)`)
|
||||
)
|
||||
|
||||
type service struct{}
|
||||
@@ -39,3 +43,7 @@ func (s *service) ClearCode(code string) string {
|
||||
}
|
||||
return code
|
||||
}
|
||||
|
||||
func (s *service) ClearText(text string) string {
|
||||
return re.ReplaceAllString(text, "")
|
||||
}
|
||||
|
||||
@@ -41,3 +41,32 @@ func Test_service_ClearCode(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_service_ClearText(t *testing.T) {
|
||||
tests := []struct {
|
||||
text string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
text: "text",
|
||||
want: "text",
|
||||
},
|
||||
{
|
||||
text: "text ([Ы])",
|
||||
want: "text",
|
||||
},
|
||||
{
|
||||
text: "text ([Ы-3])",
|
||||
want: "text",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.text, func(t *testing.T) {
|
||||
var s service
|
||||
got := s.ClearText(tt.text)
|
||||
if got != tt.want {
|
||||
t.Errorf("ClearText() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user