]> Cypherpunks repositories - gostls13.git/commitdiff
Fix .alternates execution: it was skipping every second token.
authorDavid Symonds <dsymonds@golang.org>
Sun, 30 Aug 2009 04:13:32 +0000 (21:13 -0700)
committerDavid Symonds <dsymonds@golang.org>
Sun, 30 Aug 2009 04:13:32 +0000 (21:13 -0700)
R=r
APPROVED=r
DELTA=13  (11 added, 0 deleted, 2 changed)
OCL=34081
CL=34081

src/pkg/template/template.go
src/pkg/template/template_test.go

index 5667aba2d63aad8d5c61fa6da53b37dcec87e4e9..0df31755accbc1001603a33c33825cc8a1f2f797 100644 (file)
@@ -738,7 +738,7 @@ func (t *Template) executeRepeated(r *repeatedElement, st *state) {
 
                        // .alternates between elements
                        if !first && r.altstart >= 0 {
-                               for i := r.altstart; i < r.altend; i++ {
+                               for i := r.altstart; i < r.altend; {
                                        i = t.executeElement(i, newst)
                                }
                        }
@@ -758,7 +758,7 @@ func (t *Template) executeRepeated(r *repeatedElement, st *state) {
 
                        // .alternates between elements
                        if !first && r.altstart >= 0 {
-                               for i := r.altstart; i < r.altend; i++ {
+                               for i := r.altstart; i < r.altend; {
                                        i = t.executeElement(i, newst)
                                }
                        }
index 74db28a26830f1d263e76449a3540dfc9414877a..74418699ff5e0839c63745d6e2c064bbc83d9eef 100644 (file)
@@ -187,6 +187,17 @@ var tests = []*Test {
 
                out: "this should appear: empty field\n"
        },
+       &Test{
+               in: "{.repeated section pdata }\n"
+               "{item}\n"
+               "{.alternates with}\n"
+               "is\nover\nmultiple\nlines\n"
+               "{.end}\n",
+
+               out: "ItemNumber1\n"
+               "is\nover\nmultiple\nlines\n"
+               "ItemNumber2\n"
+       },
        &Test{
                in: "{.section pdata }\n"
                "{.repeated section @ }\n"