Search in sources :

Example 6 with FormulaValidator

use of org.activityinfo.analysis.FormulaValidator in project activityinfo by bedatadriven.

the class FormulaValidatorTest method badSymbols.

@Test
public void badSymbols() {
    FormulaValidator validator = validate("XX+ZZ");
    assertThat(validator.getErrors(), hasSize(2));
}
Also used : FormulaValidator(org.activityinfo.analysis.FormulaValidator) Test(org.junit.Test)

Example 7 with FormulaValidator

use of org.activityinfo.analysis.FormulaValidator in project activityinfo by bedatadriven.

the class FormulaValidatorTest method invalidTypeArguments.

@Test
public void invalidTypeArguments() {
    FormulaValidator validator = validate("IF('Foo', 1, 0)");
    assertThat(validator.getErrors(), hasSize(1));
    assertFalse(validator.isValid());
}
Also used : FormulaValidator(org.activityinfo.analysis.FormulaValidator) Test(org.junit.Test)

Example 8 with FormulaValidator

use of org.activityinfo.analysis.FormulaValidator in project activityinfo by bedatadriven.

the class FormulaValidatorTest method validate.

private FormulaValidator validate(String formula) {
    Survey surveyForm = catalog.getSurvey();
    FormulaValidator validator = new FormulaValidator(catalog.getFormTree(surveyForm.getFormId()));
    validator.validate(FormulaParser.parse(formula));
    for (FormulaError error : validator.getErrors()) {
        System.out.println("Error at " + error.getSourceRange() + ": " + error.getMessage());
    }
    return validator;
}
Also used : Survey(org.activityinfo.store.testing.Survey) FormulaValidator(org.activityinfo.analysis.FormulaValidator) FormulaError(org.activityinfo.model.formula.FormulaError)

Aggregations

FormulaValidator (org.activityinfo.analysis.FormulaValidator)8 Test (org.junit.Test)7 QuantityType (org.activityinfo.model.type.number.QuantityType)2 FormClass (org.activityinfo.model.form.FormClass)1 FormTree (org.activityinfo.model.formTree.FormTree)1 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)1 TestBatchFormClassProvider (org.activityinfo.model.formTree.TestBatchFormClassProvider)1 FormulaError (org.activityinfo.model.formula.FormulaError)1 SourcePos (org.activityinfo.model.formula.SourcePos)1 SourceRange (org.activityinfo.model.formula.SourceRange)1 Survey (org.activityinfo.store.testing.Survey)1