mirror of https://github.com/golang/go.git
unicode/utf16: add explicit test for decoding invalid runes.
The EncodeRune test exercises DecodeRune, but only for runes that it can encode. Add an explicit test for invalid utf16 surrogate pairs. Bonus: coverage is now 100% unicode/utf16/utf16.go: IsSurrogate 100.0% unicode/utf16/utf16.go: DecodeRune 100.0% unicode/utf16/utf16.go: EncodeRune 100.0% unicode/utf16/utf16.go: Encode 100.0% unicode/utf16/utf16.go: Decode 100.0% total: (statements) 100.0% R=golang-dev, r CC=golang-dev https://golang.org/cl/39150044
This commit is contained in:
parent
fb31a0b1d0
commit
62baae6e57
|
|
@ -100,6 +100,26 @@ func TestDecode(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
var decodeRuneTests = []struct {
|
||||
r1, r2 rune
|
||||
want rune
|
||||
}{
|
||||
{0xd800, 0xdc00, 0x10000},
|
||||
{0xd800, 0xdc01, 0x10001},
|
||||
{0xd808, 0xdf45, 0x12345},
|
||||
{0xdbff, 0xdfff, 0x10ffff},
|
||||
{0xd800, 'a', 0xfffd}, // illegal, replacement rune substituted
|
||||
}
|
||||
|
||||
func TestDecodeRune(t *testing.T) {
|
||||
for i, tt := range decodeRuneTests {
|
||||
got := DecodeRune(tt.r1, tt.r2)
|
||||
if got != tt.want {
|
||||
t.Errorf("%d: DecodeRune(%q, %q) = %v; want %v", i, tt.r1, tt.r2, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var surrogateTests = []struct {
|
||||
r rune
|
||||
want bool
|
||||
|
|
|
|||
Loading…
Reference in New Issue