package com.hubspot.jinjava.lib.filter;

import static org.assertj.core.api.Assertions.assertThat;

import com.hubspot.jinjava.BaseJinjavaTest;
import com.hubspot.jinjava.interpret.JinjavaInterpreter;
import com.hubspot.jinjava.interpret.TemplateError;
import java.util.HashMap;
import java.util.List;
import org.junit.Before;
import org.junit.Test;

public class IntersectFilterTest extends BaseJinjavaTest {

  @Before
  public void setup() {
    jinjava.getGlobalContext().registerClasses(EscapeJsFilter.class);
  }

  @Test
  public void itComputesSetIntersections() {
    assertThat(
        jinjava.render("{{ [1, 1, 2, 3]|intersect([1, 2, 5, 6]) }}", new HashMap<>())
      )
      .isEqualTo("[1, 2]");
    assertThat(
        jinjava.render("{{ ['do', 'ray']|intersect(['ray', 'me']) }}", new HashMap<>())
      )
      .isEqualTo("['ray']");
  }

  @Test
  public void itReturnsEmptyOnNullParameters() {
    assertThat(jinjava.render("{{ [1, 2, 3]|intersect(null) }}", new HashMap<>()))
      .isEqualTo("[]");
  }

  @Test
  public void itThrowsWarningOnMismatchTypes() {
    JinjavaInterpreter interpreter = jinjava.newInterpreter();

    String renderedOutput = interpreter.render(
      "{{ [1, 2, 3]|intersect(['1', '2', '3']) }}"
    );
    assertThat(renderedOutput).isEqualTo("[]");

    List<TemplateError> errors = interpreter.getErrors();
    assertThat(errors).isNotEmpty();

    TemplateError error = errors.get(0);
    assertThat(error.getSeverity()).isEqualTo(TemplateError.ErrorType.WARNING);
    assertThat(error.getMessage())
      .isEqualTo(
        "Mismatched types. `value` elements are of type `long` and `list` elements are of type `str`. This may lead to unexpected behavior."
      );
  }
}

@@ -1011,32 +1011,399 @@
 lTo(%22%5B%5D%22);%0A  %7D%0A%0A
+  @Test%0A  public void itDoesNotThrowWarningOnMatchedTypes() %7B%0A    JinjavaInterpreter interpreter = jinjava.newInterpreter();%0A%0A    String renderedOutput = interpreter.render(%22%7B%7B %5B1, 2, 3%5D%7Cintersect(%5B1, 2, 3%5D) %7D%7D%22);%0A    assertThat(renderedOutput).isEqualTo(%22%5B1, 2, 3%5D%22);%0A%0A    List%3CTemplateError%3E errors = interpreter.getErrors();%0A    assertThat(errors).isEmpty();%0A  %7D%0A%0A
   @Test%0A  public

Add unit test to IntersectFilterTest when set types are matching