package com.hubspot.jinjava.lib.tag.eager;

import com.hubspot.jinjava.JinjavaConfig;
import com.hubspot.jinjava.LegacyOverrides;
import com.hubspot.jinjava.interpret.JinjavaInterpreter;
import com.hubspot.jinjava.lib.tag.CycleTagTest;
import com.hubspot.jinjava.lib.tag.Tag;
import com.hubspot.jinjava.mode.EagerExecutionMode;
import org.junit.After;
import org.junit.Before;

public class EagerCycleTagTest extends CycleTagTest {
  private static final long MAX_OUTPUT_SIZE = 500L;
  private Tag tag;

  @Before
  public void eagerSetup() {
    interpreter =
      new JinjavaInterpreter(
        jinjava,
        context,
        JinjavaConfig
          .newBuilder()
          .withMaxOutputSize(MAX_OUTPUT_SIZE)
          .withExecutionMode(EagerExecutionMode.instance())
          .withLegacyOverrides(
            LegacyOverrides.newBuilder().withUsePyishObjectMapper(true).build()
          )
          .build()
      );

    tag = new EagerCycleTag();
    context.registerTag(tag);
    context.registerTag(new EagerForTag());
    JinjavaInterpreter.pushCurrent(interpreter);
  }

  @After
  public void teardown() {
    JinjavaInterpreter.popCurrent();
  }
}

@@ -37,16 +37,80 @@
 eager;%0A%0A
+import static org.assertj.core.api.Java6Assertions.assertThat;%0A%0A
 import c
@@ -187,16 +187,68 @@
 rrides;%0A
+import com.hubspot.jinjava.interpret.DeferredValue;%0A
 import c
@@ -485,16 +485,39 @@
 .Before;
+%0Aimport org.junit.Test;
 %0A%0Apublic
@@ -1123,16 +1123,71 @@
 g(tag);%0A
+    context.put(%22deferred%22, DeferredValue.instance());%0A
     cont
@@ -1352,11 +1352,222 @@
 t();%0A  %7D
+%0A%0A  @Test%0A  public void itHandlesDeferredCycle() %7B%0A    String template = %22%7B%25 for item in deferred %25%7D%7B%25 cycle %7B%7Bfoo%7D%7D,%7B%7Bbar%7D%7D %25%7D%7B%25 endfor %25%7D%22;%0A    assertThat(interpreter.render(template)).isEqualTo(template);%0A  %7D
 %0A%7D%0A

add unit test for eager cycle tag