Exemplo n.º 1
0
        public void TestValidate()
        {
            var caseNode = supportExprNodeFactory.MakeCaseSyntax1Node();

            caseNode.Validate(SupportExprValidationContextFactory.MakeEmpty(container));

            caseNode = supportExprNodeFactory.MakeCaseSyntax2Node();
            caseNode.Validate(SupportExprValidationContextFactory.MakeEmpty(container));

            // No subnodes: Exception is thrown.
            TryInvalidValidate(new ExprCaseNode(false));
            TryInvalidValidate(new ExprCaseNode(true));

            // singe child node not possible, must be 2 at least
            caseNode = new ExprCaseNode(false);
            caseNode.AddChildNode(new SupportExprNode(4));
            TryInvalidValidate(caseNode);

            // in a case 1 expression (e.g. case when a=b then 1 else 2) the when child nodes must return boolean
            caseNode.AddChildNode(new SupportExprNode(2));
            TryInvalidValidate(caseNode);

            // in a case 2 expression (e.g. case a when b then 1 else 2) then a and b types must be comparable
            caseNode = new ExprCaseNode(true);
            caseNode.AddChildNode(new SupportExprNode("a"));
            caseNode.AddChildNode(new SupportExprNode(1));
            caseNode.AddChildNode(new SupportExprNode(2));
            TryInvalidValidate(caseNode);
        }
Exemplo n.º 2
0
 private void TryInvalidValidate(ExprCaseNode exprCaseNode)
 {
     try {
         exprCaseNode.Validate(SupportExprValidationContextFactory.MakeEmpty(container));
         Assert.Fail();
     }
     catch (ExprValidationException) {
         // expected
     }
 }
Exemplo n.º 3
0
 internal ExprCaseNodeForge(
     ExprCaseNode parent,
     Type resultType,
     IDictionary<string, object> mapResultType,
     bool isNumericResult,
     bool mustCoerce,
     Coercer coercer,
     IList<UniformPair<ExprNode>> whenThenNodeList,
     ExprNode optionalCompareExprNode,
     ExprNode optionalElseExprNode)
 {
     ForgeRenderable = parent;
     EvaluationType = resultType;
     this.mapResultType = mapResultType;
     IsNumericResult = isNumericResult;
     IsMustCoerce = mustCoerce;
     Coercer = coercer;
     WhenThenNodeList = whenThenNodeList;
     OptionalCompareExprNode = optionalCompareExprNode;
     OptionalElseExprNode = optionalElseExprNode;
 }