]> Cypherpunks repositories - gostls13.git/commitdiff
fmt: improve test coverage of %x and %X format variations for strings
authorMartin Möhrmann <martisch@uos.de>
Fri, 9 Jan 2015 11:32:19 +0000 (12:32 +0100)
committerRob Pike <r@golang.org>
Wed, 1 Apr 2015 00:55:30 +0000 (00:55 +0000)
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>
src/fmt/fmt_test.go

index d7161c291ded3fac5e82d47b9adfb0a719b97955..c14bd2f45c0f469934ece8e9f1210ed4ffc174b2 100644 (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`"},