Search in sources :

Example 6 with CountExpression

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

the class ExpressionTests method testCountExpressionNoneWithAdapterManager.

public void testCountExpressionNoneWithAdapterManager() throws Exception {
    // $NON-NLS-1$
    CountExpression exp = new CountExpression("!");
    List<String> list = new ArrayList<>();
    CollectionWrapper wrapper = new CollectionWrapper();
    wrapper.collection = list;
    EvaluationContext context = new EvaluationContext(null, wrapper);
    assertTrue(EvaluationResult.TRUE == exp.evaluate(context));
    list.clear();
    // $NON-NLS-1$
    list.add("one");
    context = new EvaluationContext(null, wrapper);
    assertTrue(EvaluationResult.FALSE == exp.evaluate(context));
    list.clear();
    // $NON-NLS-1$
    list.add("one");
    // $NON-NLS-1$
    list.add("two");
    context = new EvaluationContext(null, wrapper);
    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 7 with CountExpression

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

the class ExpressionTests method testCountExpressionAnyNumber.

public void testCountExpressionAnyNumber() 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.TRUE == exp.evaluate(context));
    list.clear();
    // $NON-NLS-1$
    list.add("one");
    // $NON-NLS-1$
    list.add("two");
    // $NON-NLS-1$
    list.add("three");
    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)

Example 8 with CountExpression

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

the class ExpressionTests method testCountExpressionExact.

public void testCountExpressionExact() throws Exception {
    // $NON-NLS-1$
    CountExpression exp = new CountExpression("2");
    List<String> list = new ArrayList<>();
    // $NON-NLS-1$
    list.add("one");
    EvaluationContext 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.TRUE == exp.evaluate(context));
    list.clear();
    // $NON-NLS-1$
    list.add("one");
    // $NON-NLS-1$
    list.add("two");
    // $NON-NLS-1$
    list.add("three");
    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 9 with CountExpression

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

the class ExpressionTests method testCountExpressionNoneOrOne.

public void testCountExpressionNoneOrOne() 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.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.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 10 with CountExpression

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

the class CountExpressionTest method testNoneExpression.

public void testNoneExpression() throws CoreException {
    // $NON-NLS-1$
    CountExpression e = new CountExpression("!");
    Assert.assertEquals(EvaluationResult.TRUE, e.evaluate(evaluationContext(0)));
    Assert.assertEquals(EvaluationResult.FALSE, e.evaluate(evaluationContext(1)));
}
Also used : CountExpression(org.eclipse.core.internal.expressions.CountExpression)

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