diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-05-23 09:45:29 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-05-23 11:04:16 +0200 |
commit | 4e5e42a1c1a9eb757743648c48df70cbd42635db (patch) | |
tree | 64220a5cf0a1ad27206bbcdbc810ea56ba5ed67f /src/pkg/template/template_test.go | |
parent | fd089e27d7260cee1c7ca449c41cdd0341ebc6cb (diff) | |
download | golang-4e5e42a1c1a9eb757743648c48df70cbd42635db.tar.gz |
Imported Upstream version 2011.05.22
Diffstat (limited to 'src/pkg/template/template_test.go')
-rw-r--r-- | src/pkg/template/template_test.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/pkg/template/template_test.go b/src/pkg/template/template_test.go index d21a5397a..a5e6a4ecc 100644 --- a/src/pkg/template/template_test.go +++ b/src/pkg/template/template_test.go @@ -94,10 +94,15 @@ func multiword(w io.Writer, format string, value ...interface{}) { } } +func printf(w io.Writer, format string, v ...interface{}) { + io.WriteString(w, fmt.Sprintf(v[0].(string), v[1:]...)) +} + var formatters = FormatterMap{ "uppercase": writer(uppercase), "+1": writer(plus1), "multiword": multiword, + "printf": printf, } var tests = []*Test{ @@ -138,6 +143,36 @@ var tests = []*Test{ out: "nil pointer: <nil>=77\n", }, + &Test{ + in: `{"Strings" ":"} {""} {"\t\u0123 \x23\\"} {"\"}{\\"}`, + + out: "Strings: \t\u0123 \x23\\ \"}{\\", + }, + + &Test{ + in: "{`Raw strings` `:`} {``} {`\\t\\u0123 \\x23\\`} {`}{\\`}", + + out: "Raw strings: \\t\\u0123 \\x23\\ }{\\", + }, + + &Test{ + in: "Characters: {'a'} {'\\u0123'} {' '} {'}'} {'{'}", + + out: "Characters: 97 291 32 125 123", + }, + + &Test{ + in: "Integers: {1} {-2} {+42} {0777} {0x0a}", + + out: "Integers: 1 -2 42 511 10", + }, + + &Test{ + in: "Floats: {.5} {-.5} {1.1} {-2.2} {+42.1} {1e10} {1.2e-3} {1.2e3} {-1.2e3}", + + out: "Floats: 0.5 -0.5 1.1 -2.2 42.1 1e+10 0.0012 1200 -1200", + }, + // Method at top level &Test{ in: "ptrmethod={PointerMethod}\n", @@ -723,6 +758,10 @@ var formatterTests = []Test{ in: "{Integer|||||}", // empty string is a valid formatter out: "77", }, + { + in: `{"%.02f 0x%02X" 1.1 10|printf}`, + out: "1.10 0x0A", + }, } func TestFormatters(t *testing.T) { |