Search in sources :

Example 1 with SoyEasyList

use of com.google.template.soy.data.SoyEasyList 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

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