Commit 15e66f9d authored by Martin Möhrmann's avatar Martin Möhrmann Committed by Rob Pike

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/2611Reviewed-by: 's avatarRobert Griesemer <gri@golang.org>
Reviewed-by: 's avatarRob Pike <r@golang.org>
parent 29d1f3b8
......@@ -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`"},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment