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 09:45:29 +0200 | 
| commit | 63d29fefab5290dc96e0a03ff70603aefa995887 (patch) | |
| tree | 95da0105686f9aba568a72e7a8ebd580a4fda20e /src/pkg/template/template_test.go | |
| parent | ad811fbb8897a9a3063274e927133915941f1dca (diff) | |
| download | golang-63d29fefab5290dc96e0a03ff70603aefa995887.tar.gz | |
Imported Upstream version 2011.05.22upstream-weekly/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) { | 
