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();
}
Aggregations