示例#1
0
        public void SampleWalkerDisplaysTheSyntaxTreeStructure()
        {
            var unit = ApexSharpParser.ParseText(
                @"using System;
                using System.Collections;
                using System.Linq.Think;
                using System.Text;
                using system.debug;

                namespace Demo
                {
                    struct Program
                    {
                        static void Main(string[] args)
                        {
                            Console.WriteLine(""Hello, World!"");
                        }
                    }
                }");

            var walker = new SampleWalker();

            unit.Accept(walker);

            var tree = walker.ToString();

            Assert.False(string.IsNullOrWhiteSpace(tree));
        }
示例#2
0
        public void CSharpHelperParsesTheCSharpCodeAndReturnsTheSyntaxTree()
        {
            var unit = ApexSharpParser.ParseText(
                @"using System;
                using System.Collections;
                using System.Linq.Think;
                using System.Text;
                using system.debug;

                namespace HelloWorld
                {
                    class Program
                    {
                        static void Main(string[] args)
                        {
                            Console.WriteLine(""Hello, World!"");
                        }
                    }
                }");

            Assert.NotNull(unit);

            var txt = ApexSharpParser.ToCSharp(unit);

            Assert.NotNull(txt);
        }
示例#3
0
        protected void Check(string csharpUnit, params string[] apexClasses)
        {
            var csharpNode = ApexSharpParser.ParseText(csharpUnit);
            var apexNodes  = ApexSyntaxBuilder.GetApexSyntaxNodes(csharpNode);

            Assert.Multiple(() =>
            {
                Assert.AreEqual(apexClasses.Length, apexNodes.Count);
                foreach (var apexItem in apexNodes.Zip(apexClasses, (node, text) => new { node, text }))
                {
                    Check(apexItem.node, apexItem.text);
                }
            });
        }
示例#4
0
        public void EmptyClassIsGenerated()
        {
            var csharp = "class Test {}";
            var cs     = ApexSharpParser.ParseText(csharp);
            var apex   = ApexSyntaxBuilder.GetApexSyntaxNodes(cs);

            Assert.NotNull(apex);
            Assert.AreEqual(1, apex.Count);

            var cd = apex.OfType <ClassDeclarationSyntax>().FirstOrDefault();

            Assert.NotNull(cd);
            Assert.AreEqual("Test", cd.Identifier);

            Check(csharp, "class Test {}");
        }