public void testIfExp() { AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage()); VariableDeclaration variable = factory1.createVariableDeclaration("abc", getClassifier("Boolean"), null); VariableExp condition = factory1.createVariableExp(variable); IntegerLiteralExp thenExp = factory1.createIntegerLiteralExp(100, getClassifier("Integer")); RealLiteralExp elseExp = factory1.createRealLiteralExp("247.49", getClassifier("Real")); IfExp exp = factory1.createIfExp(condition, thenExp, elseExp); Assert.AreEqual("if abc then 100 else 247.49 endif", exp.ToString()); Assert.AreEqual("Real", exp.getType().getName()); }
public void testIfOK() { List <object> constraints = doTestContextOK("context Film inv: if 20 > 10 then self.name = self.name else self.name.concat(\"Alex\") = self.name endif", getCurrentMethodName()); foreach (CSTInvariantCS constraint in constraints) { CSTExpressionInOclCS expression = constraint.getExpressionNodeCS(); OclExpression oclExpression = ((ExpressionInOclImpl)expression.getAst()).getBodyExpression(); Assert.IsTrue(oclExpression is IfExp); IfExp exp = (IfExp)oclExpression; Assert.AreEqual("Boolean", exp.getType().getName()); Assert.IsTrue(((OperationCallExp)exp.getThenExpression()).getSource() is AttributeCallExp); Assert.IsTrue(((OperationCallExp)exp.getElseExpression()).getSource() is OperationCallExp); } }