From 15e66f9d01da995d63683245a429e64d71ac698e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Mo=CC=88hrmann?= Date: Fri, 9 Jan 2015 12:32:19 +0100 Subject: [PATCH] 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 Reviewed-by: Rob Pike --- src/fmt/fmt_test.go | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/fmt/fmt_test.go b/src/fmt/fmt_test.go index d7161c291d..c14bd2f45c 100644 --- a/src/fmt/fmt_test.go +++ b/src/fmt/fmt_test.go @@ -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`"},