Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(32)

Side by Side Diff: src/pkg/exp/template/html/reverse_test.go

Issue 4808089: code review 4808089: exp/template/html: New package with a toy template tran... (Closed)
Patch Set: diff -r 48ec728c62b0 https://go.googlecode.com/hg/ Created 13 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package html
6
7 import (
8 "bytes"
9 "exp/template"
10 "testing"
11 )
12
13 type data struct {
14 World string
15 Coming bool
16 }
17
18 func TestReverse(t *testing.T) {
19 templateSource :=
20 "{{if .Coming}}Hello{{else}}Goodbye{{end}}, {{.World}}!"
21 templateData := data{
22 World: "Cincinatti",
23 Coming: true,
24 }
25
26 tmpl := template.New("test")
27 tmpl, err := tmpl.Parse(templateSource)
28 if err != nil {
29 t.Errorf("failed to parse template: %s", err)
30 return
31 }
32
33 Reverse(tmpl)
34
35 buffer := new(bytes.Buffer)
36
37 err = tmpl.Execute(buffer, templateData)
38 if err != nil {
39 t.Errorf("failed to execute reversed template: %s", err)
40 return
41 }
42
43 golden := "!ittanicniC ,olleH"
44 actual := buffer.String()
45 if golden != actual {
46 t.Errorf("reversed output: %q != %q", golden, actual)
47 }
48 }
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b