mirror of
https://github.com/vbatts/go-mtree.git
synced 2025-10-03 20:21:01 +00:00
unvis: add some more error tests
These error cases were already handled correctly, but we really should have tests for them anyway. Now that we have proper error variables declared we can also test for specific errors as well. Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This commit is contained in:
parent
fbada2e081
commit
bcdb71fb56
1 changed files with 26 additions and 9 deletions
|
@ -19,6 +19,7 @@
|
||||||
package govis
|
package govis
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -26,17 +27,33 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUnvisError(t *testing.T) {
|
func TestUnvisError(t *testing.T) {
|
||||||
for _, test := range []string{
|
for _, test := range []struct {
|
||||||
|
input string
|
||||||
|
err error
|
||||||
|
}{
|
||||||
// Octal escape codes allow you to specify invalid ASCII values.
|
// Octal escape codes allow you to specify invalid ASCII values.
|
||||||
"\\777",
|
{"\\777", errOutsideLatin1},
|
||||||
"\\420\\322\\455",
|
{"\\420\\322\\455", errOutsideLatin1},
|
||||||
"\\652\\233",
|
{"\\652\\233", errOutsideLatin1},
|
||||||
|
// Escapes that end abruptly.
|
||||||
|
{"\\", errEndOfString},
|
||||||
|
{"\\J", errUnknownEscapeChar},
|
||||||
|
{"a bad slash: \\", errEndOfString},
|
||||||
|
{"testing -- \\x", errEndOfString},
|
||||||
|
{"\\xG0 test", strconv.ErrSyntax},
|
||||||
|
{" abc \\Mx", errUnknownEscapeChar},
|
||||||
|
{"\\Mx", errUnknownEscapeChar},
|
||||||
|
{"\\M-", errEndOfString},
|
||||||
|
{"\\M-\u5000", errOutsideLatin1},
|
||||||
|
{"\\M^", errEndOfString},
|
||||||
|
{"\\^", errEndOfString},
|
||||||
|
{"\\^\u5000", errOutsideLatin1},
|
||||||
|
{"\\M", errEndOfString},
|
||||||
} {
|
} {
|
||||||
t.Run(test, func(t *testing.T) {
|
t.Run(test.input, func(t *testing.T) {
|
||||||
_, err := Unvis(test, DefaultVisFlags)
|
_, err := Unvis(test.input, DefaultVisFlags)
|
||||||
require.Errorf(t, err, "invalid octal escape should give an error")
|
require.Errorf(t, err, "invalid escape string should give an error")
|
||||||
assert.ErrorContains(t, err, "escape base 8")
|
assert.ErrorIs(t, err, test.err, "unexpected error from invalid escape string")
|
||||||
assert.ErrorContains(t, err, "outside latin-1 encoding")
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue