diff options
| author | Russ Cox <rsc@golang.org> | 2008-11-24 13:04:27 -0800 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2008-11-24 13:04:27 -0800 |
| commit | 2b8e08381ab96c5e021e70d9d80023ef1b50ba65 (patch) | |
| tree | dcbf89c2abddd807510ee54812d5493c6f3c182b /test/fmt_test.go | |
| parent | 785a63d0e7eebd8af05c5037b0aa3a26bbea6138 (diff) | |
| download | golang-2b8e08381ab96c5e021e70d9d80023ef1b50ba65.tar.gz | |
utf8: add InString routines for decoding in strings
reflect: add InterfaceValue.Get(), remove Empty
strconv: add Quote, CanBackquote
fmt:
* %q go-quoted " string
* %#q go-quoted ` string if possible, " string otherwise
* %x hexadecimal string
* anywhere a string is okay, *[]byte is okay
* flags # 0 - + space
* print value inside interface, not interface itself
* tests
R=r
DELTA=756 (597 added, 121 deleted, 38 changed)
OCL=19888
CL=19916
Diffstat (limited to 'test/fmt_test.go')
| -rw-r--r-- | test/fmt_test.go | 94 |
1 files changed, 0 insertions, 94 deletions
diff --git a/test/fmt_test.go b/test/fmt_test.go deleted file mode 100644 index 27c986b43..000000000 --- a/test/fmt_test.go +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// $G $F.go && $L $F.$A && ./$A.out - -package main - -import fmt "fmt" // BUG: shouldn't need the first 'fmt'. - -func E(f *fmt.Fmt, e string) { - g := f.str(); - if sys.argc() > 1 { - print(g, "\n"); - if g != e { - print("expected <", e, ">\n"); - } - return; - } - if g != e { - print("expected <", e, ">\n"); - print("got <", g, ">\n"); - } -} - -const B32 = 1<<32 - 1 -const B64 = 1<<64 - 1 - -func main() { - f := fmt.New(); - E(f.s("d ").d(1234), "d 1234"); - E(f.s("Simple output\n"), "Simple output\n"); - E(f.s("\td ").d(-1234), "\td -1234"); - E(f.s("\tud ").ud(B32), "\tud 4294967295"); - E(f.s("\tud64 ").ud64(B64), "\tud64 18446744073709551615"); - E(f.s("\to ").o(01234), "\to 1234"); - E(f.s("\tuo ").uo(B32), "\tuo 37777777777"); - E(f.s("\tuo64 ").uo64(B64), "\tuo64 1777777777777777777777"); - E(f.s("\tx ").x(0x1234abcd), "\tx 1234abcd"); - E(f.s("\tux ").ux(B32 - 0x01234567), "\tux fedcba98"); - E(f.s("\tX ").X(0x1234abcd), "\tX 1234ABCD"); - E(f.s("\tuX ").uX(B32 - 0x01234567), "\tuX FEDCBA98"); - E(f.s("\tux64 ").ux64(B64), "\tux64 ffffffffffffffff"); - E(f.s("\tb ").b(7), "\tb 111"); - E(f.s("\tb64 ").b64(B64), "\tb64 1111111111111111111111111111111111111111111111111111111111111111"); - E(f.s("\te ").e64(1.), "\te 1.000000e+00"); - E(f.s("\te ").e64(1234.5678e3), "\te 1.234568e+06"); - E(f.s("\te ").e64(1234.5678e-8), "\te 1.234568e-05"); - E(f.s("\te ").e64(-7.0), "\te -7.000000e+00"); - E(f.s("\te ").e64(-1e-9), "\te -1.000000e-09"); - E(f.s("\tf ").f64(1234.5678e3), "\tf 1234567.800000"); - E(f.s("\tf ").f64(1234.5678e-8), "\tf 0.000012"); - E(f.s("\tf ").f64(-7.0), "\tf -7.000000"); - E(f.s("\tf ").f64(-1e-9), "\tf -0.000000"); - E(f.s("\tg ").g64(1234.5678e3), "\tg 1.2345678e+06"); - E(f.s("\tg ").g64(1234.5678e-8), "\tg 1.2345678e-05"); - E(f.s("\tg ").g64(-7.0), "\tg -7"); - E(f.s("\tg ").g64(-1e-9), "\tg -1e-09"); - E(f.s("\tc ").c('x'), "\tc x"); - E(f.s("\tc ").c(0xe4), "\tc ä"); - E(f.s("\tc ").c(0x672c), "\tc 本"); - E(f.s("\tc ").c('日'), "\tc 日"); - - E(f.s("Flags, width, and precision"), "Flags, width, and precision"); - E(f.s("\t\t|123456789_123456789_"), "\t\t|123456789_123456789_"); - E(f.s("\t20.8d\t|").wp(20,8).d(1234).s("|"), "\t20.8d\t| 00001234|"); - E(f.s("\t20.8d\t|").wp(20,8).d(-1234).s("|"), "\t20.8d\t| -00001234|"); - E(f.s("\t20d\t|").w(20).d(1234).s("|"), "\t20d\t| 1234|"); - E(f.s("\t-20.8d\t|").wp(-20,8).d(1234).s("|"), "\t-20.8d\t|00001234 |"); - E(f.s("\t-20.8d\t|").wp(-20,8).d(-1234).s("|"), "\t-20.8d\t|-00001234 |"); - E(f.s("\t.20b\t|").p(20).b(7).s("|"), "\t.20b\t|00000000000000000111|"); - E(f.s("\t20.5s\t|").wp(20,5).s("qwertyuiop").s("|"), "\t20.5s\t| qwert|"); - E(f.s("\t.5s\t|").p(5).s("qwertyuiop").s("|"), "\t.5s\t|qwert|"); - E(f.s("\t-20.5s\t|").wp(-20,5).s("qwertyuiop").s("|"), "\t-20.5s\t|qwert |"); - E(f.s("\t20c\t|").w(20).c('x').s("|"), "\t20c\t| x|"); - E(f.s("\t-20c\t|").w(-20).c('x').s("|"), "\t-20c\t|x |"); - E(f.s("\t20e\t|").wp(20, 6).e(1.2345e3).s("|"), "\t20e\t| 1.234500e+03|"); - E(f.s("\t20e\t|").wp(20, 6).e(1.2345e-3).s("|"), "\t20e\t| 1.234500e-03|"); - E(f.s("\t-20e\t|").wp(-20, 6).e(1.2345e3).s("|"), "\t-20e\t|1.234500e+03 |"); - E(f.s("\t20.8e\t|").wp(20,8).e(1.2345e3).s("|"), "\t20.8e\t| 1.23450000e+03|"); - E(f.s("\t20f\t|").w(20).f64(1.23456789e3).s("|"), "\t20f\t| 1234.567890|"); - E(f.s("\t20f\t|").w(20).f64(1.23456789e-3).s("|"), "\t20f\t| 0.001235|"); - E(f.s("\t20f\t|").w(20).f64(12345678901.23456789).s("|"), "\t20f\t| 12345678901.234568|"); - E(f.s("\t-20f\t|").w(-20).f64(1.23456789e3).s("|"), "\t-20f\t|1234.567890 |"); - E(f.s("\t20.8f\t|").wp(20,8).f64(1.23456789e3).s("|"), "\t20.8f\t| 1234.56789000|"); - E(f.s("\t20.8f\t|").wp(20,8).f64(1.23456789e-3).s("|"), "\t20.8f\t| 0.00123457|"); - E(f.s("\tg\t|").g64(1.23456789e3).s("|"), "\tg\t|1234.56789|"); - E(f.s("\tg\t|").g64(1.23456789e-3).s("|"), "\tg\t|0.00123456789|"); - E(f.s("\tg\t|").g64(1.23456789e20).s("|"), "\tg\t|1.23456789e+20|"); - - E(f.s("\tE\t|").w(20).g64(sys.Inf(1)).s("|"), "\tE\t| +Inf|"); - E(f.s("\tF\t|").w(-20).g64(sys.Inf(-1)).s("|"), "\tF\t|-Inf |"); - E(f.s("\tG\t|").w(20).g64(sys.NaN()).s("|"), "\tG\t| NaN|"); -} |
