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)); }
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); }
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); } }); }
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 {}"); }