use of org.eclipse.core.internal.expressions.IterateExpression in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testIterateExpressionFailure.
public void testIterateExpressionFailure() throws Exception {
IterateExpression exp = new IterateExpression((String) null);
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());
}
}
use of org.eclipse.core.internal.expressions.IterateExpression in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testIterateExpressionOrTrue.
public void testIterateExpressionOrTrue() throws Exception {
final List<Object> result = new ArrayList<>();
Expression myExpression = new Expression() {
@Override
public EvaluationResult evaluate(IEvaluationContext context) throws CoreException {
result.add(context.getDefaultVariable());
return EvaluationResult.TRUE;
}
};
// $NON-NLS-1$
IterateExpression exp = new IterateExpression("or");
exp.add(myExpression);
List<String> input = new ArrayList<>();
// $NON-NLS-1$
input.add("one");
// $NON-NLS-1$
input.add("two");
EvaluationContext context = new EvaluationContext(null, input);
assertTrue(EvaluationResult.TRUE == exp.evaluate(context));
// $NON-NLS-1$
assertTrue(result.size() == 1 && result.get(0).equals("one"));
}
use of org.eclipse.core.internal.expressions.IterateExpression in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testAdaptExpressionWithNull.
/**
* Bug 484325
*/
public void testAdaptExpressionWithNull() throws Exception {
// it's surprisingly difficult to craft an EvaluationContext that
// provides
// a defaultVariable == null
IEvaluationContext testContext = new EvaluationContext(null, new Adaptee());
testContext.addVariable("nullCarrier", Arrays.asList((Object) null, (Object) null, (Object) null));
WithExpression withExpression = new WithExpression("nullCarrier");
IterateExpression iterateExpression = new IterateExpression("and");
iterateExpression.add(new AdaptExpression("org.eclipse.core.internal.expressions.tests.NotExisting"));
withExpression.add(iterateExpression);
EvaluationResult result = withExpression.evaluate(testContext);
assertTrue(result == EvaluationResult.FALSE);
}
use of org.eclipse.core.internal.expressions.IterateExpression in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testIterateExpressionWithAdapterManagerIfEmptyFalse.
public void testIterateExpressionWithAdapterManagerIfEmptyFalse() throws Exception {
// $NON-NLS-1$
IterateExpression exp = new IterateExpression("or", "false");
final List<String> input = new ArrayList<>();
CollectionWrapper wrapper = new CollectionWrapper();
wrapper.collection = input;
EvaluationContext context = new EvaluationContext(null, wrapper);
assertTrue(EvaluationResult.FALSE == exp.evaluate(context));
}
use of org.eclipse.core.internal.expressions.IterateExpression in project eclipse.platform.runtime by eclipse.
the class ExpressionTests method testIterateExpressionOrMultiChildren.
public void testIterateExpressionOrMultiChildren() throws Exception {
// Test for Bug 260522: <iterate> iterates over collection elements,
// thereby *and*-ing all evaluated child expressions
// $NON-NLS-1$
IterateExpression exp = new IterateExpression("or");
exp.add(Expression.FALSE);
exp.add(Expression.TRUE);
List<String> input = new ArrayList<>();
// $NON-NLS-1$
input.add("one");
EvaluationContext context = new EvaluationContext(null, input);
assertTrue(EvaluationResult.FALSE == exp.evaluate(context));
}
Aggregations