OLD | NEW |
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 parse | 5 package parse |
6 | 6 |
7 import ( | 7 import ( |
8 "flag" | 8 "flag" |
9 "fmt" | 9 "fmt" |
10 "testing" | 10 "testing" |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 {"multidecl outside range", "{{with $v, $u := 3}}{{end}}", hasError, ""}
, | 229 {"multidecl outside range", "{{with $v, $u := 3}}{{end}}", hasError, ""}
, |
230 {"too many decls in range", "{{range $u, $v, $w := 3}}{{end}}", hasError
, ""}, | 230 {"too many decls in range", "{{range $u, $v, $w := 3}}{{end}}", hasError
, ""}, |
231 } | 231 } |
232 | 232 |
233 var builtins = map[string]interface{}{ | 233 var builtins = map[string]interface{}{ |
234 "printf": fmt.Sprintf, | 234 "printf": fmt.Sprintf, |
235 } | 235 } |
236 | 236 |
237 func TestParse(t *testing.T) { | 237 func TestParse(t *testing.T) { |
238 for _, test := range parseTests { | 238 for _, test := range parseTests { |
239 » » tmpl, err := New(test.name).Parse(test.input, "", "", nil, built
ins) | 239 » » tmpl, err := New(test.name).Parse(test.input, "", "", make(map[s
tring]*Tree), builtins) |
240 switch { | 240 switch { |
241 case err == nil && !test.ok: | 241 case err == nil && !test.ok: |
242 t.Errorf("%q: expected error; got none", test.name) | 242 t.Errorf("%q: expected error; got none", test.name) |
243 continue | 243 continue |
244 case err != nil && test.ok: | 244 case err != nil && test.ok: |
245 t.Errorf("%q: unexpected error: %v", test.name, err) | 245 t.Errorf("%q: unexpected error: %v", test.name, err) |
246 continue | 246 continue |
247 case err != nil && !test.ok: | 247 case err != nil && !test.ok: |
248 // expected error, got one | 248 // expected error, got one |
249 if *debug { | 249 if *debug { |
250 fmt.Printf("%s: %s\n\t%s\n", test.name, test.inp
ut, err) | 250 fmt.Printf("%s: %s\n\t%s\n", test.name, test.inp
ut, err) |
251 } | 251 } |
252 continue | 252 continue |
253 } | 253 } |
254 result := tmpl.Root.String() | 254 result := tmpl.Root.String() |
255 if result != test.result { | 255 if result != test.result { |
256 t.Errorf("%s=(%q): got\n\t%v\nexpected\n\t%v", test.name
, test.input, result, test.result) | 256 t.Errorf("%s=(%q): got\n\t%v\nexpected\n\t%v", test.name
, test.input, result, test.result) |
257 } | 257 } |
258 } | 258 } |
259 } | 259 } |
OLD | NEW |