mirror of
https://github.com/golang/go
synced 2024-11-20 01:54:41 -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:
parent
29d1f3b85c
commit
15e66f9d01
@ -135,27 +135,33 @@ var fmtTests = []struct {
|
|||||||
|
|
||||||
// basic string
|
// basic string
|
||||||
{"%s", "abc", "abc"},
|
{"%s", "abc", "abc"},
|
||||||
|
{"%q", "abc", `"abc"`},
|
||||||
{"%x", "abc", "616263"},
|
{"%x", "abc", "616263"},
|
||||||
|
{"%x", "\xff\xf0\x0f\xff", "fff00fff"},
|
||||||
|
{"%X", "\xff\xf0\x0f\xff", "FFF00FFF"},
|
||||||
{"%x", "xyz", "78797a"},
|
{"%x", "xyz", "78797a"},
|
||||||
{"%X", "xyz", "78797A"},
|
{"%X", "xyz", "78797A"},
|
||||||
{"%q", "abc", `"abc"`},
|
{"% x", "xyz", "78 79 7a"},
|
||||||
{"%#x", []byte("abc\xff"), "0x616263ff"},
|
{"% X", "xyz", "78 79 7A"},
|
||||||
{"%#X", []byte("abc\xff"), "0X616263FF"},
|
{"%#x", "xyz", "0x78797a"},
|
||||||
{"%# x", []byte("abc\xff"), "0x61 0x62 0x63 0xff"},
|
{"%#X", "xyz", "0X78797A"},
|
||||||
{"%# X", []byte("abc\xff"), "0X61 0X62 0X63 0XFF"},
|
{"%# x", "xyz", "0x78 0x79 0x7a"},
|
||||||
|
{"%# X", "xyz", "0X78 0X79 0X7A"},
|
||||||
|
|
||||||
// basic bytes
|
// basic bytes
|
||||||
{"%s", []byte("abc"), "abc"},
|
{"%s", []byte("abc"), "abc"},
|
||||||
|
{"%q", []byte("abc"), `"abc"`},
|
||||||
{"%x", []byte("abc"), "616263"},
|
{"%x", []byte("abc"), "616263"},
|
||||||
{"% x", []byte("abc\xff"), "61 62 63 ff"},
|
{"%x", []byte("\xff\xf0\x0f\xff"), "fff00fff"},
|
||||||
{"%#x", []byte("abc\xff"), "0x616263ff"},
|
{"%X", []byte("\xff\xf0\x0f\xff"), "FFF00FFF"},
|
||||||
{"%#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("xyz"), "78797a"},
|
{"%x", []byte("xyz"), "78797a"},
|
||||||
{"%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
|
// escaped strings
|
||||||
{"%#q", `abc`, "`abc`"},
|
{"%#q", `abc`, "`abc`"},
|
||||||
|
Loading…
Reference in New Issue
Block a user