ещё больше тестов
This commit is contained in:
parent
c7f4da6c44
commit
927c33af1f
14
unpack.go
14
unpack.go
|
@ -38,6 +38,13 @@ func Unpack(str string) (string, error) {
|
|||
if unicode.IsDigit(char) {
|
||||
currentState = number
|
||||
numOfRepeat, _ = strconv.Atoi(string(char))
|
||||
repStr, err := repeatRune(runeArray[i-1], numOfRepeat)
|
||||
if err != nil {
|
||||
res := result.String()
|
||||
result.Reset()
|
||||
result.WriteString(res[0 : len(res)-1])
|
||||
}
|
||||
result.WriteString(repStr)
|
||||
} else if char == '\\' {
|
||||
currentState = escape
|
||||
} else {
|
||||
|
@ -48,13 +55,6 @@ func Unpack(str string) (string, error) {
|
|||
if unicode.IsDigit(char) {
|
||||
return "", ErrInvalidString
|
||||
}
|
||||
repStr, err := repeatRune(runeArray[i-2], numOfRepeat)
|
||||
if err != nil {
|
||||
res := result.String()
|
||||
result.Reset()
|
||||
result.WriteString(res[0 : len(res)-1])
|
||||
}
|
||||
result.WriteString(repStr)
|
||||
currentState = start
|
||||
result.WriteRune(char)
|
||||
case escape:
|
||||
|
|
|
@ -16,6 +16,10 @@ func TestUnpack(t *testing.T) {
|
|||
{input: "abccd", expected: "abccd"},
|
||||
{input: "", expected: ""},
|
||||
{input: "aaa0b", expected: "aab"},
|
||||
{input: "a2", expected: "aa"},
|
||||
{input: "aa", expected: "aa"},
|
||||
{input: "a", expected: "a"},
|
||||
{input: "d\n5abc", expected: "d\n\n\n\n\nabc"},
|
||||
{input: `qwe\4\5`, expected: `qwe45`},
|
||||
{input: `qwe\45`, expected: `qwe44444`},
|
||||
{input: `qwe\\5`, expected: `qwe\\\\\`},
|
||||
|
@ -33,7 +37,7 @@ func TestUnpack(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUnpackInvalidString(t *testing.T) {
|
||||
invalidStrings := []string{"3abc", "45", "aaa10b"}
|
||||
invalidStrings := []string{"3abc", "45", "aaa10b", "1"}
|
||||
for _, tc := range invalidStrings {
|
||||
tc := tc
|
||||
t.Run(tc, func(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue