use of org.activityinfo.analysis.FormulaValidator in project activityinfo by bedatadriven.
the class FormulaValidatorTest method booleanEnumReference.
@Test
public void booleanEnumReference() {
FormulaValidator validator = validate("Gender.Female || Gender.Male");
assertThat(validator.getErrors(), hasSize(0));
assertTrue(validator.isValid());
assertThat(validator.getResultType(), equalTo(BooleanType.INSTANCE));
}
use of org.activityinfo.analysis.FormulaValidator in project activityinfo by bedatadriven.
the class FormulaValidatorTest method badNumberOfArguments.
@Test
public void badNumberOfArguments() {
FormulaValidator validator = validate("IF(1)");
assertThat(validator.getErrors(), hasSize(1));
assertThat(validator.getErrors().get(0).getSourceRange(), equalTo(new SourceRange(new SourcePos(0, 0), 5)));
}
use of org.activityinfo.analysis.FormulaValidator in project activityinfo by bedatadriven.
the class FormulaValidatorTest method invalidFormSchema.
@Test
public void invalidFormSchema() {
FormClass formClass = new FormClass(ResourceId.valueOf("XYZ"));
formClass.addField(ResourceId.valueOf("F1")).setCode("A").setLabel("Field A1").setType(TextType.SIMPLE);
formClass.addField(ResourceId.valueOf("F2")).setCode("A").setLabel("Field A2").setType(TextType.SIMPLE);
TestBatchFormClassProvider formProvider = new TestBatchFormClassProvider();
formProvider.add(formClass);
FormTreeBuilder formTreeBuilder = new FormTreeBuilder(formProvider);
FormTree formTree = formTreeBuilder.queryTree(formClass.getId());
FormulaValidator validator = new FormulaValidator(formTree);
assertFalse(validator.validate(FormulaParser.parse("A")));
assertThat(validator.getErrors(), hasSize(1));
}
use of org.activityinfo.analysis.FormulaValidator in project activityinfo by bedatadriven.
the class FormulaValidatorTest method goodSymbols.
@Test
public void goodSymbols() {
FormulaValidator validator = validate("AGE");
assertThat(validator.getErrors(), hasSize(0));
assertTrue(validator.isValid());
assertThat(validator.getResultType(), instanceOf(QuantityType.class));
}
use of org.activityinfo.analysis.FormulaValidator in project activityinfo by bedatadriven.
the class FormulaValidatorTest method validTypeArguments.
@Test
public void validTypeArguments() {
FormulaValidator validator = validate("IF(TRUE, 1, 0)");
assertThat(validator.getErrors(), hasSize(0));
assertTrue(validator.isValid());
assertThat(validator.getResultType(), instanceOf(QuantityType.class));
}
Aggregations