45 lines
931 B
Go
45 lines
931 B
Go
package stringunpack_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
stringunpack "git.grachevko.ru/grachevko/h/string-unpack"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestUnpack(t *testing.T) {
|
|
testcases := []struct {
|
|
input string
|
|
expected string
|
|
}{
|
|
{input: "a4bc2d5e", expected: "aaaabccddddde"},
|
|
{input: "abcd", expected: "abcd"},
|
|
{input: "aaa0b", expected: "aab"},
|
|
{input: "", expected: ""},
|
|
{input: "d\n5abc", expected: "d\n\n\n\n\nabc"},
|
|
}
|
|
|
|
for _, tc := range testcases {
|
|
t.Run(tc.input, func(t *testing.T) {
|
|
result, err := stringunpack.Unpack(tc.input)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, tc.expected, result)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestUnpackIncorrectString(t *testing.T) {
|
|
testcases := []string{
|
|
"3abc",
|
|
"45",
|
|
"aaa10b",
|
|
}
|
|
|
|
for _, input := range testcases {
|
|
t.Run(input, func(t *testing.T) {
|
|
_, err := stringunpack.Unpack(input)
|
|
assert.Equal(t, stringunpack.ErrIncorrectString, err)
|
|
})
|
|
}
|
|
}
|