예제 #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);
 }
예제 #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);
        }
예제 #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);
     });
 }
예제 #4
0
        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));
        }
예제 #5
0
        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"));
        }
예제 #6
0
 private void Check(string source, string expected) =>
 CompareLineByLine(ApexSharpParser.IndentApex(source), expected);