Beispiel #1
0
        public void TestValidate()
        {
            ExprCaseNode 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);
        }
        public static ExprCaseNode MakeCaseSyntax1Node()
        {
            // Build (case 1 expression):
            // case when s0.intPrimitive = 1 then "a"
            //      when s0.intPrimitive = 2 then "b"
            //      else "c"
            // end
            var caseNode = new ExprCaseNode(false);

            ExprNode node = MakeEqualsNode("IntPrimitive", "s0", 1);

            caseNode.AddChildNode(node);
            caseNode.AddChildNode(new SupportExprNode("a"));

            node = MakeEqualsNode("IntPrimitive", "s0", 2);
            caseNode.AddChildNode(node);
            caseNode.AddChildNode(new SupportExprNode("b"));

            caseNode.AddChildNode(new SupportExprNode("c"));

            Validate3Stream(caseNode);

            return(caseNode);
        }
        public static ExprCaseNode MakeCaseSyntax2Node()
        {
            // Build (case 2 expression):
            // case s0.intPrimitive
            //   when 1 then "a"
            //   when 2 then "b"
            //   else "c"
            // end
            var caseNode = new ExprCaseNode(true);

            caseNode.AddChildNode(MakeIdentNode("IntPrimitive", "s0"));

            caseNode.AddChildNode(new SupportExprNode(1));
            caseNode.AddChildNode(new SupportExprNode("a"));
            caseNode.AddChildNode(new SupportExprNode(2));
            caseNode.AddChildNode(new SupportExprNode("b"));
            caseNode.AddChildNode(new SupportExprNode("c"));

            Validate3Stream(caseNode);

            return(caseNode);
        }