<commit_before>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."
      );
  }
}<commit_msg>Add unit test to IntersectFilterTest when set types are matching<commit_after>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 itDoesNotThrowWarningOnMatchedTypes() {
    JinjavaInterpreter interpreter = jinjava.newInterpreter();

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

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

  @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."
      );
  }
}
{'fraction_non_alphanumeric': 0.15511971472236372, 'fraction_numerical': 0.012480896586856851, 'mean_word_length': 4.167105263157895, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5404879', 'n_tokens_mistral': 1283, 'n_tokens_neox': 1257, 'n_words': 255}