diff --git a/src/UnitTests/UnitTest1.cs b/src/UnitTests/UnitTest1.cs index 3261186..9922864 100644 --- a/src/UnitTests/UnitTest1.cs +++ b/src/UnitTests/UnitTest1.cs @@ -79,6 +79,25 @@ public void SideBySideDiffView() } } + [Fact] + public void RegressionMix() + { + using (var col = new TempFileCollection()) + { + var xmlSource = col.CreateTempFile("Approval_Workflow__c.Description__cfalseApproval_Workflow__c.Migration_Id__cfalseApproval_Workflow__c.Reject_PO_Substage__cLocation.VisitorAddressIdTestAccListApexFlowLead-LeadLayoutMacro-MacroLayoutOFAC__SDN_Match__c-OFAC__MatchLayoutOFAC__SDN_Search__c-OFAC__OFACRequestLayoutOak_Office__c-OakOfficeLayoutfalsefalsefalsetruefalseAssetfalse"); + var xmlChanged = col.CreateTempFile("Approval_Workflow__c.Description__ctrueApproval_Workflow__c.Migration_Id__ctrueApproval_Workflow__c.Reject_PO_Substage__cLocation.VisitorAddressIdLead-LeadLayoutLocation-LocationLayoutMacro-MacroLayoutOak_Office__c-OakOfficeLayoutfalsefalsefalsetruefalseAddressfalsefalsefalsefalsetruefalseAssetfalse"); + + var view = new XmlDiffView(); + var options = XmlDiffOptions.IgnoreChildOrder | XmlDiffOptions.IgnoreWhitespace; + var results = view.DifferencesSideBySideAsHtml(xmlSource, xmlChanged, false, options); + + var diff = results.ReadToEnd(); + Assert.Contains("<temp", diff); + Assert.Contains("id=\"1\"", diff); + Assert.Contains("<c", diff); + } + } + [Fact] public void SideBySideDiffViewCompact() { diff --git a/src/XmlDiff.sln b/src/XmlDiff.sln index ce28846..0fafc91 100644 --- a/src/XmlDiff.sln +++ b/src/XmlDiff.sln @@ -16,6 +16,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Common\version.txt = Common\version.txt EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmlDiffTool", "XmlDiffTool\XmlDiffTool.csproj", "{BE99AC80-E1C4-48B8-8415-AF413073399C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -34,6 +36,10 @@ Global {D2FBED29-536D-4FA9-94F4-EB72BF89A900}.Debug|Any CPU.Build.0 = Debug|Any CPU {D2FBED29-536D-4FA9-94F4-EB72BF89A900}.Release|Any CPU.ActiveCfg = Release|Any CPU {D2FBED29-536D-4FA9-94F4-EB72BF89A900}.Release|Any CPU.Build.0 = Release|Any CPU + {BE99AC80-E1C4-48B8-8415-AF413073399C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BE99AC80-E1C4-48B8-8415-AF413073399C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BE99AC80-E1C4-48B8-8415-AF413073399C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BE99AC80-E1C4-48B8-8415-AF413073399C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/XmlDiffTool/Program.cs b/src/XmlDiffTool/Program.cs new file mode 100644 index 0000000..2d98658 --- /dev/null +++ b/src/XmlDiffTool/Program.cs @@ -0,0 +1,134 @@ +using Microsoft.XmlDiffPatch; +using System.IO; +using System.Numerics; +using System.Text; + +class Program +{ + string file1; + string file2; + string outputFile; + bool compact; + enum OutputFormat + { + Xml, + Html + } + OutputFormat format; + + bool ParseCommandLine(string[] args) + { + for (int i = 0; i < args.Length; i++) + { + string arg = args[i]; + if (arg[0] == '-') + { + switch (arg.TrimStart('-').ToLowerInvariant()) + { + case "?": + case "h": + case "help": + return false; + case "format": + if (i + 1 >= args.Length) + { + WriteError($"Missing --format parameter 'xml|html'"); + return false; + } + i++; + arg = args[i]; + if (arg == "xml") + { + format = OutputFormat.Xml; + } + else if (arg == "html") + { + format = OutputFormat.Html; + } + else + { + WriteError($"### Error: Unknown --format parameter {arg}, expecting 'xml' or 'html'"); + return false; + } + break; + case "compact": + compact = true; + break; + default: + WriteError($"### Error: Unknown argument: {args[i]}"); + return false; + } + } + else if (file1 == null) + { + file1 = arg; + } + else if (file2 == null) + { + file2 = arg; + } + else if (outputFile == null) + { + outputFile = arg; + } + else + { + WriteError("### Error: Too many arguments"); + return false; + } + } + if (file1 == null || file2 == null || outputFile == null) + { + WriteError("### Error: Not enough arguments"); + return false; + } + + return true; + } + + void WriteError(string msg) { + var color = Console.ForegroundColor; + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine(msg); + Console.ForegroundColor = color; + } + + void PrintUsage() + { + Console.WriteLine("Usage: xmldiff file1 file2 outputFile --format [xml|html] --compact"); + } + + static void Main(string[] args) + { + Program p = new Program(); + if (p.ParseCommandLine(args)) + { + p.Run(); + } + else + { + p.PrintUsage(); + } + } + + void Run() + { + var view = new XmlDiffView(); + var options = XmlDiffOptions.IgnoreChildOrder | XmlDiffOptions.IgnoreWhitespace; + if (File.Exists(outputFile)) + { + File.Delete(outputFile); + } + switch (format) + { + case OutputFormat.Xml: + view.DifferencesAsFormattedText(file1, file2, outputFile, false, options); + break; + case OutputFormat.Html: + view.DifferencesSideBySideAsHtml(file1, file2, outputFile, false, options, compact); + break; + default: + break; + } + } +} \ No newline at end of file diff --git a/src/XmlDiffTool/Properties/launchSettings.json b/src/XmlDiffTool/Properties/launchSettings.json new file mode 100644 index 0000000..ec1a161 --- /dev/null +++ b/src/XmlDiffTool/Properties/launchSettings.json @@ -0,0 +1,9 @@ +{ + "profiles": { + "XmlDiffTool": { + "commandName": "Project", + "commandLineArgs": "\"file1.xml\" \"file2.xml\" --format html out.htm", + "workingDirectory": "D:\\git\\lovettchris\\xmldiff" + } + } +} \ No newline at end of file diff --git a/src/XmlDiffTool/XmlDiffTool.csproj b/src/XmlDiffTool/XmlDiffTool.csproj new file mode 100644 index 0000000..255712b --- /dev/null +++ b/src/XmlDiffTool/XmlDiffTool.csproj @@ -0,0 +1,15 @@ + + + + Exe + net7.0 + enable + xmldiff + + + + + + + +