Search in sources :

Example 6 with SoyValueProvider

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

the class DictImplTest method testRecordMethods.

@Test
public void testRecordMethods() {
    Map<String, SoyValueProvider> providerMap = new HashMap<>();
    SoyDict dict = DictImpl.forProviderMap(providerMap, RuntimeMapTypeTracker.Type.UNKNOWN);
    assertThat(dict.hasField("boo")).isFalse();
    assertThat(dict.getField("boo")).isNull();
    assertThat(dict.getFieldProvider("boo")).isNull();
    providerMap.put("boo", StringData.forValue("blah"));
    assertThat(dict.hasField("boo")).isTrue();
    assertThat(dict.getField("boo").stringValue()).isEqualTo("blah");
    assertThat(dict.getFieldProvider("boo").resolve().stringValue()).isEqualTo("blah");
    providerMap.remove("boo");
    assertThat(dict.hasField("boo")).isFalse();
    assertThat(dict.getField("boo")).isNull();
    assertThat(dict.getFieldProvider("boo")).isNull();
    providerMap.put("foo", FloatData.forValue(3.14));
    providerMap.put("too", BooleanData.TRUE);
    assertThat(dict.hasField("foo")).isTrue();
    assertThat(dict.getField("foo").floatValue()).isWithin(0.0).of(3.14);
    assertThat(dict.getField("too").booleanValue()).isTrue();
}
Also used : SoyValueProvider(com.google.template.soy.data.SoyValueProvider) HashMap(java.util.HashMap) SoyDict(com.google.template.soy.data.SoyDict) Test(org.junit.Test)

Aggregations

SoyValueProvider (com.google.template.soy.data.SoyValueProvider)6 Test (org.junit.Test)5 HashMap (java.util.HashMap)3 StringData (com.google.template.soy.data.restricted.StringData)2 SoyDict (com.google.template.soy.data.SoyDict)1 SoyList (com.google.template.soy.data.SoyList)1 SoyValue (com.google.template.soy.data.SoyValue)1 DetachableSoyValueProvider (com.google.template.soy.jbcsrc.runtime.DetachableSoyValueProvider)1