-
Notifications
You must be signed in to change notification settings - Fork 92
/
unpack_test.go
45 lines (40 loc) · 1.04 KB
/
unpack_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package hw02unpackstring
import (
"errors"
"testing"
"github.com/stretchr/testify/require"
)
func TestUnpack(t *testing.T) {
tests := []struct {
input string
expected string
}{
{input: "a4bc2d5e", expected: "aaaabccddddde"},
{input: "abccd", expected: "abccd"},
{input: "", expected: ""},
{input: "aaa0b", expected: "aab"},
// uncomment if task with asterisk completed
// {input: `qwe\4\5`, expected: `qwe45`},
// {input: `qwe\45`, expected: `qwe44444`},
// {input: `qwe\\5`, expected: `qwe\\\\\`},
// {input: `qwe\\\3`, expected: `qwe\3`},
}
for _, tc := range tests {
tc := tc
t.Run(tc.input, func(t *testing.T) {
result, err := Unpack(tc.input)
require.NoError(t, err)
require.Equal(t, tc.expected, result)
})
}
}
func TestUnpackInvalidString(t *testing.T) {
invalidStrings := []string{"3abc", "45", "aaa10b"}
for _, tc := range invalidStrings {
tc := tc
t.Run(tc, func(t *testing.T) {
_, err := Unpack(tc)
require.Truef(t, errors.Is(err, ErrInvalidString), "actual error %q", err)
})
}
}