|
| 1 | +package integration |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/Notifuse/liquidgo/liquid" |
| 7 | + "github.com/Notifuse/liquidgo/liquid/tags" |
| 8 | +) |
| 9 | + |
| 10 | +func TestTraceForloopRendering(t *testing.T) { |
| 11 | + env := liquid.NewEnvironment() |
| 12 | + tags.RegisterStandardTags(env) |
| 13 | + |
| 14 | + // Test direct variable lookup in context |
| 15 | + ctx := liquid.BuildContext(liquid.ContextConfig{Environment: env}) |
| 16 | + |
| 17 | + // Create a forloop drop and add it to context |
| 18 | + drop := liquid.NewForloopDrop("test", 3, nil) |
| 19 | + ctx.Set("forloop", drop) |
| 20 | + |
| 21 | + // Test 1: Direct lookup |
| 22 | + forloopVar := ctx.FindVariable("forloop", false) |
| 23 | + t.Logf("FindVariable('forloop') = %#v (type: %T)", forloopVar, forloopVar) |
| 24 | + |
| 25 | + // Test 2: Evaluate a VariableLookup |
| 26 | + vl := liquid.VariableLookupParse("forloop.last", liquid.NewStringScanner(""), nil) |
| 27 | + result := vl.Evaluate(ctx) |
| 28 | + t.Logf("VariableLookup.Evaluate('forloop.last') = %#v (type: %T)", result, result) |
| 29 | + |
| 30 | + // Test 3: ToS on the result |
| 31 | + resultStr := liquid.ToS(result, nil) |
| 32 | + t.Logf("ToS(result) = %q", resultStr) |
| 33 | + |
| 34 | + // Test 4: Full template rendering |
| 35 | + template := `{{ forloop.last }}` |
| 36 | + tmpl := liquid.NewTemplate(&liquid.TemplateOptions{Environment: env}) |
| 37 | + err := tmpl.Parse(template, nil) |
| 38 | + if err != nil { |
| 39 | + t.Fatalf("Parse failed: %v", err) |
| 40 | + } |
| 41 | + |
| 42 | + vars := map[string]interface{}{"forloop": drop} |
| 43 | + got := tmpl.Render(vars, nil) |
| 44 | + t.Logf("Template render result = %q", got) |
| 45 | + |
| 46 | + if got == "" { |
| 47 | + t.Error("Template rendered empty string instead of 'false'") |
| 48 | + } |
| 49 | +} |
0 commit comments