Пример #1
0
        public void Contract()
        {
            RoslynCompiler compiler = new RoslynCompiler();

            Excess.Entensions.XS.Contract.Apply(compiler);

            SyntaxTree tree = null;
            string     text = null;

            //usage
            var Usage = @"
                class foo
                {
                    void bar(int x, object y)
                    {
                        contract()
                        {
                            x > 3;
                            y != null;
                        }
                    }
                }";

            tree = compiler.ApplySemanticalPass(Usage, out text);
            Assert.IsTrue(tree.GetRoot()
                          .DescendantNodes()
                          .OfType <IfStatementSyntax>()
                          .Count() == 2); //must have added an if for each contract condition

            //errors
            var Errors = @"
                class foo
                {
                    void bar(int x, object y)
                    {
                        contract()
                        {
                            x > 3;
                            return 4; //contract01 - only expressions
                        }

                        var noContract = contract() //contract01 - not as expression
                        {
                            x > 3;
                            return 4; 
                        }
                    }
                }";

            var doc = compiler.CreateDocument(Errors);

            compiler.ApplySemanticalPass(doc, out text);
            Assert.IsTrue(doc
                          .GetErrors()
                          .Count() == 2); //must produce 2 errors
        }
Пример #2
0
        public void Contract()
        {
            RoslynCompiler compiler = new RoslynCompiler();
            Excess.Entensions.XS.Contract.Apply(compiler);

            SyntaxTree tree = null;
            string text = null;

            //usage
            var Usage = @"
                class foo
                {
                    void bar(int x, object y)
                    {
                        contract()
                        {
                            x > 3;
                            y != null;
                        }
                    }
                }";

            tree = compiler.ApplySemanticalPass(Usage, out text);
            Assert.IsTrue(tree.GetRoot()
                .DescendantNodes()
                .OfType<IfStatementSyntax>()
                .Count() == 2); //must have added an if for each contract condition

            //errors
            var Errors = @"
                class foo
                {
                    void bar(int x, object y)
                    {
                        contract()
                        {
                            x > 3;
                            return 4; //contract01 - only expressions
                        }

                        var noContract = contract() //contract01 - not as expression
                        {
                            x > 3;
                            return 4;
                        }
                    }
                }";

            var doc = compiler.CreateDocument(Errors);
            compiler.ApplySemanticalPass(doc, out text);
            Assert.IsTrue(doc
                .GetErrors()
                .Count() == 2); //must produce 2 errors
        }