Beispiel #1
0
 public void ClassUnitTestRoundtrip()
 {
     // formatted class doesn't match the converted class because of the testMethod modifiers
     CompareLineByLine(ApexSharpParser.IndentApex(ClassUnitTest_Original), ClassUnitTest_Formatted);
     CompareLineByLine(ApexToCSharpHelpers.ConvertToCSharp(ClassUnitTest_Original, Options), ClassUnitTest_CSharp1);
     CompareLineByLine(CSharpToApexHelpers.ConvertToApex(ClassUnitTest_CSharp1)[0], ClassUnitTest_Converted);
 }
Beispiel #2
0
        public static List <FileFormatDto> FormatApexCode(DirectoryInfo apexFolderName)
        {
            List <FileFormatDto> dtoList = new List <FileFormatDto>();

            var files = Directory.GetFiles(apexFolderName.FullName, "*.cls", SearchOption.TopDirectoryOnly);

            foreach (var sourceFile in files)
            {
                FileInfo apexFileInfo = new FileInfo(sourceFile);

                Console.WriteLine($"Formatting file: {sourceFile}...");
                var backupFile = sourceFile + ".bak";

                File.Delete(backupFile);
                File.Move(sourceFile, backupFile);

                var apexCode  = File.ReadAllText(backupFile);
                var formatted = ApexSharpParser.IndentApex(apexCode);
                File.WriteAllText(sourceFile, formatted);
                File.Delete(backupFile);

                FileFormatDto dto = new FileFormatDto
                {
                    ApexFileName         = apexFileInfo.FullName,
                    ApexFileBeforeFormat = apexCode,
                    ApexFileAfterFormat  = formatted
                };
                dtoList.Add(dto);
            }

            Console.WriteLine($"Done. Formatted {dtoList.Count} files.");
            return(dtoList);
        }
Beispiel #3
0
 private void Check(string apexOriginal, string apexFormatted, string csharp)
 {
     Assert.Multiple(() =>
     {
         CompareLineByLine(ApexSharpParser.IndentApex(apexOriginal), apexFormatted);
         CompareLineByLine(ApexToCSharpHelpers.ConvertToCSharp(apexOriginal, Options), csharp);
         CompareLineByLine(CSharpToApexHelpers.ConvertToApex(csharp)[0], apexFormatted);
     });
 }
        protected void Check(BaseSyntax node, string expected)
        {
            string nows(string s) =>
            NoWhitespaceRegex.Replace(s, string.Empty);

            var nodeToApex = node.ToApex();

            Assert.AreEqual(nows(expected), nows(nodeToApex));
            CompareLineByLine(nodeToApex, ApexSharpParser.IndentApex(expected));
        }
        public void SoqlStatementFormattingDoesntMessUpParameters()
        {
            var apex = @"class SoqlDemo {
                void soql() {
                    list<r> rr = [select c, min(b) d from r WHERE
                        c in :triggerNew AND b not in :triggerNew GROUP BY c HAVING count(b) > 1];
                }
            }";

            var formatted = ApexSharpParser.IndentApex(apex);

            Assert.IsFalse(formatted.Contains("trigger new"));
            Assert.IsFalse(formatted.Contains("GROUPBY"));
        }
Beispiel #6
0
 private void Check(string source, string expected) =>
 CompareLineByLine(ApexSharpParser.IndentApex(source), expected);