diff options
| author | Russ Cox <rsc@golang.org> | 2019-01-29 22:24:36 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2019-02-26 05:16:56 +0000 |
| commit | ac51237affc016dd22f5b4f67dc8a2d09adf1fb2 (patch) | |
| tree | 3a8ef2099ca6356ea1d69cab83f3755d8f09cdd2 /src/fmt/fmt_test.go | |
| parent | e1a6d1fc08b2701ac9f67353cb52c51d52877669 (diff) | |
| download | go-ac51237affc016dd22f5b4f67dc8a2d09adf1fb2.tar.xz | |
fmt: format 0b, 0o prefixes in %#b and %O
This CL modifies fmt's printer to implement %#b and %O
to emit leading 0b and 0o prefixes on binary and octal.
(%#o is already taken and emits "0377"; %O emits "0o377".)
See golang.org/design/19308-number-literals for background.
For #19308.
For #12711.
Vet update is #29986.
Change-Id: I7c38a4484c48a03abe9f6d45c7d981c7c314f583
Reviewed-on: https://go-review.googlesource.com/c/160246
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/fmt/fmt_test.go')
| -rw-r--r-- | src/fmt/fmt_test.go | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/fmt/fmt_test.go b/src/fmt/fmt_test.go index 2d10c7a841..bbaf40a619 100644 --- a/src/fmt/fmt_test.go +++ b/src/fmt/fmt_test.go @@ -354,11 +354,17 @@ var fmtTests = []struct { {"%+d", -12345, "-12345"}, {"%b", 7, "111"}, {"%b", -6, "-110"}, + {"%#b", 7, "0b111"}, + {"%#b", -6, "-0b110"}, {"%b", ^uint32(0), "11111111111111111111111111111111"}, {"%b", ^uint64(0), "1111111111111111111111111111111111111111111111111111111111111111"}, {"%b", int64(-1 << 63), zeroFill("-1", 63, "")}, {"%o", 01234, "1234"}, + {"%o", -01234, "-1234"}, {"%#o", 01234, "01234"}, + {"%#o", -01234, "-01234"}, + {"%O", 01234, "0o1234"}, + {"%O", -01234, "-0o1234"}, {"%o", ^uint32(0), "37777777777"}, {"%o", ^uint64(0), "1777777777777777777777"}, {"%#X", 0, "0X0"}, |
