2020-06-10 15:01:14 +03:00

108 lines
1.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package hw02_unpack_string //nolint:golint,stylecheck
import (
"testing"
"github.com/stretchr/testify/require"
)
type test struct {
input string
expected string
err error
}
func TestUnpack(t *testing.T) {
for _, tst := range [...]test{
{
input: "a4bc2d5e",
expected: "aaaabccddddde",
},
{
input: "abccd",
expected: "abccd",
},
{
input: "3abc",
expected: "",
err: ErrInvalidString,
},
{
input: "45",
expected: "",
err: ErrInvalidString,
},
{
input: "aaa10b",
expected: "",
err: ErrInvalidString,
},
{
input: "",
expected: "",
},
{
input: "aaa0b",
expected: "aab",
},
{
input: "fftcwerv ervev sva5scs",
expected: "",
err: ErrInvalidString,
},
{
input: `||\||(8^`,
expected: "",
err: ErrInvalidString,
},
{
input: суРАкс2еу",
expected: "иссскуРАкссеу",
},
{
input: "рлрплотчрв",
expected: "рлрплотчрв",
},
{
input: string([]rune{1234, 67, 45, 2324, 899, 353, 2345, 65}),
expected: "",
err: ErrInvalidString,
},
} {
result, err := Unpack(tst.input)
require.Equal(t, tst.err, err)
require.Equal(t, tst.expected, result)
}
}
func TestUnpackWithEscape(t *testing.T) {
for _, tst := range [...]test{
{
input: `qwe\4\5`,
expected: `qwe45`,
},
{
input: `qwe\45`,
expected: `qwe44444`,
},
{
input: `qwe\\5`,
expected: `qwe\\\\\`,
},
{
input: `qwe\\\3`,
expected: `qwe\3`,
},
{
input: `3\\cds\4`,
expected: ``,
err: ErrInvalidString,
},
} {
result, err := Unpack(tst.input)
require.Equal(t, tst.err, err)
require.Equal(t, tst.expected, result)
}
}