use of com.google.api.expr.v1alpha1.SourceInfo in project cel-java by projectnessie.
the class ProviderTest method typeRegistryGetters.
@Test
void typeRegistryGetters() {
TypeRegistry reg = newRegistry(ParsedExpr.getDefaultInstance());
Val sourceInfo = reg.newValue("google.api.expr.v1alpha1.SourceInfo", mapOf("location", stringOf("TestTypeRegistryGetFieldValue"), "line_offsets", newGenericArrayList(reg, new Long[] { 0L, 2L }), "positions", newMaybeWrappedMap(reg, mapOf(1L, 2L, 3L, 4L))));
assertThat(sourceInfo).matches(v -> !Err.isError(v));
Indexer si = (Indexer) sourceInfo;
Val loc = si.get(stringOf("location"));
assertThat(loc.equal(stringOf("TestTypeRegistryGetFieldValue"))).isSameAs(True);
Val pos = si.get(stringOf("positions"));
assertThat(pos.equal(newMaybeWrappedMap(reg, mapOf(1, 2, 3, 4)))).isSameAs(True);
Val posKeyVal = ((Indexer) pos).get(intOf(1));
assertThat(posKeyVal.intValue()).isEqualTo(2);
Val offsets = si.get(stringOf("line_offsets"));
assertThat(offsets).matches(v -> !Err.isError(v));
Val offset1 = ((Lister) offsets).get(intOf(1));
assertThat(offset1).matches(v -> !Err.isError(v)).isEqualTo(intOf(2));
}
use of com.google.api.expr.v1alpha1.SourceInfo in project cel-java by projectnessie.
the class CEL method astToString.
/**
* AstToString converts an Ast back to a string if possible.
*
* <p>Note, the conversion may not be an exact replica of the original expression, but will
* produce a string that is semantically equivalent and whose textual representation is stable.
*/
public static String astToString(Ast a) {
Expr expr = a.getExpr();
SourceInfo info = a.getSourceInfo();
return unparse(expr, info);
}
use of com.google.api.expr.v1alpha1.SourceInfo in project cel-java by projectnessie.
the class ProviderTest method typeRegistryNewValue.
@Test
void typeRegistryNewValue() {
TypeRegistry reg = newRegistry(ParsedExpr.getDefaultInstance());
Val sourceInfo = reg.newValue("google.api.expr.v1alpha1.SourceInfo", mapOf("location", stringOf("TestTypeRegistryNewValue"), "line_offsets", newGenericArrayList(reg, new Long[] { 0L, 2L }), "positions", newMaybeWrappedMap(reg, mapOf(1L, 2, 3L, 4))));
assertThat(sourceInfo).matches(v -> !Err.isError(v));
Message info = (Message) sourceInfo.value();
SourceInfo srcInfo = SourceInfo.newBuilder().mergeFrom(info).build();
assertThat(srcInfo).extracting(SourceInfo::getLocation, SourceInfo::getLineOffsetsList, SourceInfo::getPositionsMap).containsExactly("TestTypeRegistryNewValue", asList(0, 2), mapOf(1L, 2L, 3L, 4L));
}
Aggregations