Search in sources :

Example 1 with FloatData

use of com.google.template.soy.data.restricted.FloatData in project closure-templates by google.

the class ListImplTest method testListMethods.

@Test
public void testListMethods() {
    StringData BLAH_0 = StringData.forValue("blah");
    FloatData PI = FloatData.forValue(3.14);
    SoyValue BLAH_2 = StringData.forValue("blah");
    SoyList list = ListImpl.forProviderList(EMPTY);
    assertThat(list.length()).isEqualTo(0);
    assertThat(list.asJavaList()).isEmpty();
    assertThat(list.asResolvedJavaList()).isEmpty();
    assertThat(list.get(0)).isNull();
    assertThat(list.getProvider(0)).isNull();
    list = ListImpl.forProviderList(ImmutableList.of(BLAH_0, PI, BLAH_2));
    // At this point, list should be [BLAH_0, PI, BLAH_2].
    assertThat(list.length()).isEqualTo(3);
    assertThat(list.asJavaList()).isEqualTo(ImmutableList.of(BLAH_0, PI, BLAH_2));
    assertThat(list.asResolvedJavaList()).isEqualTo(ImmutableList.of(BLAH_0, PI, BLAH_2));
    assertThat(list.get(0)).isSameAs(BLAH_0);
    assertThat(list.get(0)).isNotSameAs(BLAH_2);
    // not same, but they compare equal
    assertThat(list.get(0)).isEqualTo(BLAH_2);
    assertThat(list.getProvider(1).resolve().floatValue()).isWithin(0.0).of(3.14);
}
Also used : FloatData(com.google.template.soy.data.restricted.FloatData) SoyList(com.google.template.soy.data.SoyList) StringData(com.google.template.soy.data.restricted.StringData) SoyValue(com.google.template.soy.data.SoyValue) Test(org.junit.Test)

Example 2 with FloatData

use of com.google.template.soy.data.restricted.FloatData in project closure-templates by google.

the class EasyListImplTest method testListMethods.

@Test
public void testListMethods() {
    StringData BLAH_0 = StringData.forValue("blah");
    FloatData PI = FloatData.forValue(3.14);
    SoyValue BLAH_2 = StringData.forValue("blah");
    SoyEasyList list = new EasyListImpl();
    assertThat(list.length()).isEqualTo(0);
    assertThat(list.asJavaList()).isEmpty();
    assertThat(list.asResolvedJavaList()).isEmpty();
    assertThat(list.get(0)).isNull();
    assertThat(list.getProvider(0)).isNull();
    list.add(BLAH_0);
    list.add(PI);
    list.add(BLAH_2);
    // At this point, list should be [BLAH_0, PI, BLAH_2].
    assertThat(list.length()).isEqualTo(3);
    assertThat(list.asJavaList()).isEqualTo(ImmutableList.of(BLAH_0, PI, BLAH_2));
    assertThat(list.asResolvedJavaList()).isEqualTo(ImmutableList.of(BLAH_0, PI, BLAH_2));
    assertThat(list.get(0)).isSameAs(BLAH_0);
    assertThat(list.get(0)).isNotSameAs(BLAH_2);
    // not same, but they compare equal
    assertThat(list.get(0)).isEqualTo(BLAH_2);
    assertThat(list.getProvider(1).resolve().floatValue()).isWithin(0.0).of(3.14);
}
Also used : SoyEasyList(com.google.template.soy.data.SoyEasyList) FloatData(com.google.template.soy.data.restricted.FloatData) StringData(com.google.template.soy.data.restricted.StringData) SoyValue(com.google.template.soy.data.SoyValue) Test(org.junit.Test)

Aggregations

SoyValue (com.google.template.soy.data.SoyValue)2 FloatData (com.google.template.soy.data.restricted.FloatData)2 StringData (com.google.template.soy.data.restricted.StringData)2 Test (org.junit.Test)2 SoyEasyList (com.google.template.soy.data.SoyEasyList)1 SoyList (com.google.template.soy.data.SoyList)1