Search in sources :

Example 11 with CountExpression

use of org.eclipse.core.internal.expressions.CountExpression in project eclipse.platform.runtime by eclipse.

the class ExpressionTests method testCountExpressionNone.

public void testCountExpressionNone() throws Exception {
    // $NON-NLS-1$
    CountExpression exp = new CountExpression("!");
    List<String> list = new ArrayList<>();
    EvaluationContext context = new EvaluationContext(null, list);
    assertTrue(EvaluationResult.TRUE == exp.evaluate(context));
    list.clear();
    // $NON-NLS-1$
    list.add("one");
    context = new EvaluationContext(null, list);
    assertTrue(EvaluationResult.FALSE == exp.evaluate(context));
    list.clear();
    // $NON-NLS-1$
    list.add("one");
    // $NON-NLS-1$
    list.add("two");
    context = new EvaluationContext(null, list);
    assertTrue(EvaluationResult.FALSE == exp.evaluate(context));
}
Also used : ArrayList(java.util.ArrayList) CountExpression(org.eclipse.core.internal.expressions.CountExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Example 12 with CountExpression

use of org.eclipse.core.internal.expressions.CountExpression in project eclipse.platform.runtime by eclipse.

the class ExpressionTests method testCountExpressionFailure.

public void testCountExpressionFailure() throws Exception {
    // $NON-NLS-1$
    CountExpression exp = new CountExpression("!");
    EvaluationContext context = new EvaluationContext(null, new Object());
    try {
        EvaluationResult result = exp.evaluate(context);
        fail("Count should've failed for non-Collection variable.  Result = " + result.toString());
    } catch (CoreException e) {
        assertEquals(ExpressionStatus.VARIABLE_IS_NOT_A_COLLECTION, e.getStatus().getCode());
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) CountExpression(org.eclipse.core.internal.expressions.CountExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext) EvaluationResult(org.eclipse.core.expressions.EvaluationResult)

Example 13 with CountExpression

use of org.eclipse.core.internal.expressions.CountExpression in project eclipse.platform.runtime by eclipse.

the class ExpressionTests method testCountExpressionHashCode.

public void testCountExpressionHashCode() throws Exception {
    CountExpression expression1 = new CountExpression("*");
    CountExpression expression2 = new CountExpression("*");
    assertEquals("Equal expressions should have the same hash code", expression1.hashCode(), expression2.hashCode());
}
Also used : CountExpression(org.eclipse.core.internal.expressions.CountExpression)

Example 14 with CountExpression

use of org.eclipse.core.internal.expressions.CountExpression in project eclipse.platform.runtime by eclipse.

the class ExpressionTests method testCountExpressionNotEqual.

public void testCountExpressionNotEqual() throws Exception {
    CountExpression expression1 = new CountExpression("+");
    CountExpression expression2 = new CountExpression("!");
    assertTrue("These count expressions should not be equal", !expression1.equals(expression2));
}
Also used : CountExpression(org.eclipse.core.internal.expressions.CountExpression)

Example 15 with CountExpression

use of org.eclipse.core.internal.expressions.CountExpression in project eclipse.platform.runtime by eclipse.

the class ExpressionTests method testCountExpressionOneOrMore.

public void testCountExpressionOneOrMore() throws Exception {
    // $NON-NLS-1$
    CountExpression exp = new CountExpression("+");
    List<String> list = new ArrayList<>();
    EvaluationContext context = new EvaluationContext(null, list);
    assertTrue(EvaluationResult.FALSE == exp.evaluate(context));
    list.clear();
    // $NON-NLS-1$
    list.add("one");
    context = new EvaluationContext(null, list);
    assertTrue(EvaluationResult.TRUE == exp.evaluate(context));
    list.clear();
    // $NON-NLS-1$
    list.add("one");
    // $NON-NLS-1$
    list.add("two");
    context = new EvaluationContext(null, list);
    assertTrue(EvaluationResult.TRUE == exp.evaluate(context));
}
Also used : ArrayList(java.util.ArrayList) CountExpression(org.eclipse.core.internal.expressions.CountExpression) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Aggregations

CountExpression (org.eclipse.core.internal.expressions.CountExpression)18 EvaluationContext (org.eclipse.core.expressions.EvaluationContext)7 IEvaluationContext (org.eclipse.core.expressions.IEvaluationContext)7 ArrayList (java.util.ArrayList)6 EvaluationResult (org.eclipse.core.expressions.EvaluationResult)1 AndExpression (org.eclipse.core.internal.expressions.AndExpression)1 ResolveExpression (org.eclipse.core.internal.expressions.ResolveExpression)1 WithExpression (org.eclipse.core.internal.expressions.WithExpression)1 CoreException (org.eclipse.core.runtime.CoreException)1