1
0
mirror of https://github.com/golang/go synced 2024-11-20 01:14:40 -07:00

fmt: improve test coverage of %x and %X format variations for strings

The tests in the basic string section are now covering more code paths
for encoding a string into the hexadecimal representation of its bytes.

Changed the basic string and basic bytes tests so that they mirror each other.

Change-Id: Ib5dc7b33876769965f9aba2ac270040abc4b2451
Reviewed-on: https://go-review.googlesource.com/2611
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
Martin Möhrmann 2015-01-09 12:32:19 +01:00 committed by Rob Pike
parent 29d1f3b85c
commit 15e66f9d01

View File

@ -135,27 +135,33 @@ var fmtTests = []struct {
// basic string
{"%s", "abc", "abc"},
{"%q", "abc", `"abc"`},
{"%x", "abc", "616263"},
{"%x", "\xff\xf0\x0f\xff", "fff00fff"},
{"%X", "\xff\xf0\x0f\xff", "FFF00FFF"},
{"%x", "xyz", "78797a"},
{"%X", "xyz", "78797A"},
{"%q", "abc", `"abc"`},
{"%#x", []byte("abc\xff"), "0x616263ff"},
{"%#X", []byte("abc\xff"), "0X616263FF"},
{"%# x", []byte("abc\xff"), "0x61 0x62 0x63 0xff"},
{"%# X", []byte("abc\xff"), "0X61 0X62 0X63 0XFF"},
{"% x", "xyz", "78 79 7a"},
{"% X", "xyz", "78 79 7A"},
{"%#x", "xyz", "0x78797a"},
{"%#X", "xyz", "0X78797A"},
{"%# x", "xyz", "0x78 0x79 0x7a"},
{"%# X", "xyz", "0X78 0X79 0X7A"},
// basic bytes
{"%s", []byte("abc"), "abc"},
{"%q", []byte("abc"), `"abc"`},
{"%x", []byte("abc"), "616263"},
{"% x", []byte("abc\xff"), "61 62 63 ff"},
{"%#x", []byte("abc\xff"), "0x616263ff"},
{"%#X", []byte("abc\xff"), "0X616263FF"},
{"%# x", []byte("abc\xff"), "0x61 0x62 0x63 0xff"},
{"%# X", []byte("abc\xff"), "0X61 0X62 0X63 0XFF"},
{"% X", []byte("abc\xff"), "61 62 63 FF"},
{"%x", []byte("\xff\xf0\x0f\xff"), "fff00fff"},
{"%X", []byte("\xff\xf0\x0f\xff"), "FFF00FFF"},
{"%x", []byte("xyz"), "78797a"},
{"%X", []byte("xyz"), "78797A"},
{"%q", []byte("abc"), `"abc"`},
{"% x", []byte("xyz"), "78 79 7a"},
{"% X", []byte("xyz"), "78 79 7A"},
{"%#x", []byte("xyz"), "0x78797a"},
{"%#X", []byte("xyz"), "0X78797A"},
{"%# x", []byte("xyz"), "0x78 0x79 0x7a"},
{"%# X", []byte("xyz"), "0X78 0X79 0X7A"},
// escaped strings
{"%#q", `abc`, "`abc`"},