Skip to content

Commit 079913c

Browse files
committed
WIP make tests pass
1 parent 7508450 commit 079913c

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/text/template/exec.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ func (s *state) walkTemplate(dot reflect.Value, t *parse.TemplateNode) {
405405
s.at(t)
406406
scope := s.scope[t.Name]
407407
if t.Parent {
408-
scope += 1
408+
scope++
409409
}
410410
s.scope[t.Name] = scope
411411
tmpl := s.tmpl.LookupWithScope(t.Name, scope)
@@ -423,7 +423,11 @@ func (s *state) walkTemplate(dot reflect.Value, t *parse.TemplateNode) {
423423
// No dynamic scoping: template invocations inherit no variables.
424424
newState.vars = []variable{{"$", dot}}
425425
newState.walk(dot, tmpl.Root)
426-
newState.scope[t.Name] = scope - 1 // TODO: unclear if this makes sense here
426+
scope--
427+
if scope < 0 { // TODO logical bug
428+
scope = 0
429+
}
430+
newState.scope[t.Name] = scope // TODO: unclear if this makes sense here
427431
}
428432

429433
// Eval functions evaluate pipelines, commands, and their elements and extract

src/text/template/multi_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ func TestMultiParse(t *testing.T) {
7171
continue
7272
}
7373
for i, name := range test.names {
74-
tmpl, ok := template.tmpl[name]
74+
tmpl, ok := template.tmpl[name] // TODO making this pass tests for now, turn into an accessor method
7575
if !ok {
7676
t.Errorf("%s: can't find template %q", test.name, name)
7777
continue
7878
}
79-
result := tmpl.Root.String()
79+
result := tmpl[0].Root.String() // TODO
8080
if result != test.results[i] {
8181
t.Errorf("%s=(%q): got\n\t%v\nexpected\n\t%v", test.name, test.input, result, test.results[i])
8282
}
@@ -234,10 +234,10 @@ func TestClone(t *testing.T) {
234234
}
235235
// Verify that the clone is self-consistent.
236236
for k, v := range clone.tmpl {
237-
if k == clone.name && v.tmpl[k] != clone {
237+
if k == clone.name && v[0].tmpl[k][0] != clone { // TODO making this pass tests for now
238238
t.Error("clone does not contain root")
239239
}
240-
if v != v.tmpl[v.name] {
240+
if v[0] != v[0].tmpl[v[0].name][0] { // TODO making this pass tests for now
241241
t.Errorf("clone does not contain self for %q", k)
242242
}
243243
}

src/text/template/template.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package template
66

77
import (
8-
"fmt"
98
"reflect"
109
"sync"
1110
"text/template/parse"
@@ -210,7 +209,7 @@ func (t *Template) lookup(name string, scope int) *Template {
210209
if scope >= len(t.tmpl[name]) {
211210
return nil
212211
}
213-
fmt.Printf("\x1b[1;35mname: %q\tscope: %d\tlen: %d\x1b[0m\n", name, scope, len(t.tmpl[name]))
212+
//fmt.Printf("\x1b[1;35mname: %q\tscope: %d\tlen: %d\x1b[0m\n", name, scope, len(t.tmpl[name]))
214213
return t.tmpl[name][scope] // TODO: invariant check: at least one
215214
}
216215

0 commit comments

Comments
 (0)