Search in sources :

Example 1 with SoyMapImpl

use of com.google.template.soy.data.internal.SoyMapImpl in project closure-templates by google.

the class MapToLegacyObjectMapFunctionTest method computeForJava.

@Test
public void computeForJava() {
    SoyMapImpl map = SoyMapImpl.forProviderMap(ImmutableMap.of(IntegerData.forValue(42), CONVERTER.convert("y"), StringData.forValue("z"), SoyValueConverterUtility.newDict("xx", 2)));
    SoyDict expectedMap = SoyValueConverterUtility.newDict("42", "y", "z", SoyValueConverterUtility.newDict("xx", 2));
    SoyDict convertedMap = (SoyDict) MAP_TO_LEGACY_OBJECT_MAP.computeForJava(ImmutableList.of(map));
    // Keys are coerced to strings in the legacy object map.
    assertThat(expectedMap.getItem(StringData.forValue("42"))).isEqualTo(convertedMap.getItem(StringData.forValue("42")));
}
Also used : SoyMapImpl(com.google.template.soy.data.internal.SoyMapImpl) SoyDict(com.google.template.soy.data.SoyDict) Test(org.junit.Test)

Example 2 with SoyMapImpl

use of com.google.template.soy.data.internal.SoyMapImpl in project closure-templates by google.

the class LegacyObjectMapToMapFunctionTest method computeForJava.

@Test
public void computeForJava() {
    SoyLegacyObjectMap legacyObjectMap = SoyValueConverterUtility.newDict("x", "y", "z", SoyValueConverterUtility.newDict("xx", 2));
    SoyMapImpl map = SoyMapImpl.forProviderMap(ImmutableMap.of(StringData.forValue("x"), CONVERTER.convert("y"), StringData.forValue("z"), SoyValueConverterUtility.newDict("xx", 2)));
    SoyMapImpl convertedMap = (SoyMapImpl) LEGACY_OBJECT_MAP_TO_MAP.computeForJava(ImmutableList.of(legacyObjectMap));
    assertThat(map.get(StringData.forValue("x"))).isEqualTo(convertedMap.get(StringData.forValue("x")));
}
Also used : SoyMapImpl(com.google.template.soy.data.internal.SoyMapImpl) SoyLegacyObjectMap(com.google.template.soy.data.SoyLegacyObjectMap) Test(org.junit.Test)

Aggregations

SoyMapImpl (com.google.template.soy.data.internal.SoyMapImpl)2 Test (org.junit.Test)2 SoyDict (com.google.template.soy.data.SoyDict)1 SoyLegacyObjectMap (com.google.template.soy.data.SoyLegacyObjectMap)1