Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package html | 5 package html |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "exp/template" | 9 "exp/template" |
10 "testing" | 10 "testing" |
11 ) | 11 ) |
12 | 12 |
13 type data struct { | 13 type data struct { |
14 World string | 14 World string |
15 Coming bool | 15 Coming bool |
16 } | 16 } |
17 | 17 |
18 func TestReverse(t *testing.T) { | 18 func TestReverse(t *testing.T) { |
19 templateSource := | 19 templateSource := |
20 "{{if .Coming}}Hello{{else}}Goodbye{{end}}, {{.World}}!" | 20 "{{if .Coming}}Hello{{else}}Goodbye{{end}}, {{.World}}!" |
21 templateData := data{ | 21 templateData := data{ |
22 World: "Cincinatti", | 22 World: "Cincinatti", |
23 Coming: true, | 23 Coming: true, |
24 } | 24 } |
25 | 25 |
26 tmpl := template.New("test") | 26 tmpl := template.New("test") |
27 tmpl, err := tmpl.Parse(templateSource) | 27 tmpl, err := tmpl.Parse(templateSource) |
28 if err != nil { | 28 if err != nil { |
29 » » t.Errorf("Failed to parse template: %s", err) | 29 » » t.Errorf("failed to parse template: %s", err) |
r
2011/08/11 03:57:17
no initial caps in error strings. they're not sent
MikeSamuel
2011/08/11 06:17:04
Done in 3 places.
| |
30 return | 30 return |
31 } | 31 } |
32 | 32 |
33 Reverse(tmpl) | 33 Reverse(tmpl) |
34 | 34 |
35 » buffer := bytes.NewBuffer(make([]byte, 0, 1024)) | 35 » buffer := new(bytes.Buffer) |
36 | 36 |
37 err = tmpl.Execute(buffer, templateData) | 37 err = tmpl.Execute(buffer, templateData) |
38 if err != nil { | 38 if err != nil { |
39 » » t.Errorf("Failed to execute reversed template: %s", err) | 39 » » t.Errorf("failed to execute reversed template: %s", err) |
40 return | 40 return |
41 } | 41 } |
42 | 42 |
43 golden := "!ittanicniC ,olleH" | 43 golden := "!ittanicniC ,olleH" |
44 actual := buffer.String() | 44 actual := buffer.String() |
45 if golden != actual { | 45 if golden != actual { |
46 » » t.Errorf("Reversed output: %s != %s", golden, actual) | 46 » » t.Errorf("reversed output: %q != %q", golden, actual) |
r
2011/08/11 03:57:17
s/%s/%q/g
MikeSamuel
2011/08/11 06:17:04
Done. Is the difference between %s and %q analago
| |
47 } | 47 } |
48 } | 48 } |
LEFT | RIGHT |