package com.hubspot.jinjava.lib.fn;

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

import java.util.Arrays;

import org.junit.Test;

public class RangeFunctionTest {

  @Test
  public void itGeneratesSimpleRanges() {
    assertThat(Functions.range(1)).isEqualTo(Arrays.asList(0));
    assertThat(Functions.range(2)).isEqualTo(Arrays.asList(0, 1));
    assertThat(Functions.range(2, 4)).isEqualTo(Arrays.asList(2, 3));
    assertThat(Functions.range("2", "4")).isEqualTo(Arrays.asList(2, 3));
    assertThat(Functions.range(2, 8, 2)).isEqualTo(Arrays.asList(2, 4, 6));
  }

  @Test
  public void itGeneratesBackwardsRanges() {
    assertThat(Functions.range(2, -1, -1)).isEqualTo(Arrays.asList(2, 1, 0));
    assertThat(Functions.range(8, 2, -2)).isEqualTo(Arrays.asList(8, 6, 4));
    assertThat(Functions.range(2, -1, "-1")).isEqualTo(Arrays.asList(2, 1, 0));
  }

  @Test
  public void itHandlesBadRanges() {
    assertThat(Functions.range(-2)).isEmpty();
    assertThat(Functions.range(-2, -4)).isEmpty();
    assertThat(Functions.range(-2, -2)).isEmpty();
    assertThat(Functions.range(2, 2)).isEmpty();
    assertThat(Functions.range(2, 2000, 0)).isEmpty();
    assertThat(Functions.range(2, 2000, -5)).isEmpty();
  }

  public void itHandlesBadValues() {
    assertThat(Functions.range(2, "f")).isEmpty();
  }


  @Test
  public void itTruncatesHugeRanges() {
    assertThat(Functions.range(2, 200000000).size()).isEqualTo(Functions.RANGE_LIMIT);
  }

}

@@ -113,16 +113,46 @@
 .Arrays;
+%0Aimport java.util.Collections;
 %0A%0Aimport
@@ -294,33 +294,45 @@
 ).isEqualTo(
-Arrays.as
+Collections.singleton
 List(0));%0A  
@@ -1273,16 +1273,24 @@
 );%0A  %7D%0A%0A
+  @Test%0A
   public
@@ -1374,17 +1374,16 @@
 );%0A  %7D%0A%0A
-%0A
   @Test%0A

test wasn't being run