From 362d42adf41abd9398ddbb0b1e34ffd275cd746f Mon Sep 17 00:00:00 2001 From: Bassem Srouji Date: Wed, 2 Jun 2021 17:42:25 -0400 Subject: [PATCH 1/3] Fix comparison to respect -1, 0 or 1 return value, we can't assume returning 1 if col1 is lower than col2 Also improved comparison so when xml element have the same name and the same attributes, we shall then compare based on the xml content for example: 2 1 should sort to: 1 2 --- Program.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Program.cs b/Program.cs index 1179385..8051dfa 100644 --- a/Program.cs +++ b/Program.cs @@ -187,8 +187,8 @@ static int SortDelegate( XmlNode a, XmlNode b ) // Sorting attributes, if specified, is done before node sorting happens.. if (result == 0) { - var col1 = (a.Attributes.Count >= b.Attributes.Count) ? a.Attributes : b.Attributes; - var col2 = (a.Attributes.Count >= b.Attributes.Count) ? b.Attributes : a.Attributes; + var col1 = a.Attributes; + var col2 = b.Attributes; for (var i = 0; i < col1.Count; i++) { if (i < col2.Count) { @@ -209,6 +209,13 @@ static int SortDelegate( XmlNode a, XmlNode b ) } } + if (result == 0 && col1.Count < col2.Count) { + return -1; + } + + if (result == 0) { + result = string.Compare(a.InnerText, b.InnerText, sort_node_comp); + } // If we get here, that means that the node's attributes (and values) all match.. // TODO: Should we go down into the child node collections for sorting? // See example `c.xml`.. From f898cba905f6ffb3a4ed2e9fd4b1b9907157a8c2 Mon Sep 17 00:00:00 2001 From: Bassem Srouji Date: Thu, 3 Jun 2021 17:21:57 -0400 Subject: [PATCH 2/3] Proper fix with unit test for all use cases --- Program.cs | 8 +-- sortxml.sln | 19 ++++++- test_files/b.xml | 59 ---------------------- test_files/b_handsorted.xml | 59 ---------------------- test_files/b_sorted.xml | 59 ---------------------- test_files/c.xml | 35 ------------- test_files/c_handsorted.xml | 35 ------------- test_files/c_sorted.xml | 35 ------------- test_files/d.xml | 54 -------------------- test_files/d_handsorted.xml | 53 -------------------- test_files/d_sorted.xml | 49 ------------------- test_files/e.xml | 40 --------------- test_files/e_handsorted.xml | 39 --------------- test_files/e_sorted.xml | 35 ------------- test_files/f.xml | 98 ------------------------------------- test_files/f_handsorted.xml | 87 -------------------------------- test_files/f_sorted.xml | 87 -------------------------------- test_files/g.xml | 43 ---------------- test_files/g_handsorted.xml | 35 ------------- test_files/g_sorted.xml | 35 ------------- 20 files changed, 23 insertions(+), 941 deletions(-) delete mode 100644 test_files/b.xml delete mode 100644 test_files/b_handsorted.xml delete mode 100644 test_files/b_sorted.xml delete mode 100644 test_files/c.xml delete mode 100644 test_files/c_handsorted.xml delete mode 100644 test_files/c_sorted.xml delete mode 100644 test_files/d.xml delete mode 100644 test_files/d_handsorted.xml delete mode 100644 test_files/d_sorted.xml delete mode 100644 test_files/e.xml delete mode 100644 test_files/e_handsorted.xml delete mode 100644 test_files/e_sorted.xml delete mode 100644 test_files/f.xml delete mode 100644 test_files/f_handsorted.xml delete mode 100644 test_files/f_sorted.xml delete mode 100644 test_files/g.xml delete mode 100644 test_files/g_handsorted.xml delete mode 100644 test_files/g_sorted.xml diff --git a/Program.cs b/Program.cs index 8051dfa..273715c 100644 --- a/Program.cs +++ b/Program.cs @@ -31,7 +31,7 @@ DEALINGS IN THE SOFTWARE. namespace sortxml { - class Program + public class Program { static bool sort_node = true; static bool sort_attr = true; @@ -43,7 +43,7 @@ class Program static string primary_attr = ""; - static int Main( string[] arguments ) + public static int Main( string[] arguments ) { var inf = ""; var outf = ""; @@ -187,6 +187,7 @@ static int SortDelegate( XmlNode a, XmlNode b ) // Sorting attributes, if specified, is done before node sorting happens.. if (result == 0) { + // We need to respect return values of -1, 0 and 1, see test file h var col1 = a.Attributes; var col2 = b.Attributes; @@ -209,12 +210,13 @@ static int SortDelegate( XmlNode a, XmlNode b ) } } + // We need to respect return values of -1, 0 and 1, see test file h if (result == 0 && col1.Count < col2.Count) { return -1; } if (result == 0) { - result = string.Compare(a.InnerText, b.InnerText, sort_node_comp); + result = string.Compare(a.InnerXml, b.InnerXml, sort_node_comp); } // If we get here, that means that the node's attributes (and values) all match.. // TODO: Should we go down into the child node collections for sorting? diff --git a/sortxml.sln b/sortxml.sln index ab31c1b..4335b02 100644 --- a/sortxml.sln +++ b/sortxml.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.30104.148 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sortxml", "sortxml.csproj", "{F015ED1D-89EF-4251-9788-D581536501F2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "sortxml", "sortxml.csproj", "{F015ED1D-89EF-4251-9788-D581536501F2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sortxmlXUnitProject", "..\sortxmlXUnitProject\sortxmlXUnitProject.csproj", "{08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -27,8 +29,23 @@ Global {F015ED1D-89EF-4251-9788-D581536501F2}.Release|x64.Build.0 = Release|x64 {F015ED1D-89EF-4251-9788-D581536501F2}.Release|x86.ActiveCfg = Release|x86 {F015ED1D-89EF-4251-9788-D581536501F2}.Release|x86.Build.0 = Release|x86 + {08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}.Debug|x64.ActiveCfg = Debug|Any CPU + {08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}.Debug|x64.Build.0 = Debug|Any CPU + {08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}.Debug|x86.ActiveCfg = Debug|Any CPU + {08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}.Debug|x86.Build.0 = Debug|Any CPU + {08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}.Release|Any CPU.Build.0 = Release|Any CPU + {08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}.Release|x64.ActiveCfg = Release|Any CPU + {08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}.Release|x64.Build.0 = Release|Any CPU + {08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}.Release|x86.ActiveCfg = Release|Any CPU + {08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6AB24862-E35C-4F40-A1F7-A77F74667605} + EndGlobalSection EndGlobal diff --git a/test_files/b.xml b/test_files/b.xml deleted file mode 100644 index e081cdb..0000000 --- a/test_files/b.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 2 - - - - - - diff --git a/test_files/b_handsorted.xml b/test_files/b_handsorted.xml deleted file mode 100644 index 5f00fa9..0000000 --- a/test_files/b_handsorted.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 2 - - - - - - diff --git a/test_files/b_sorted.xml b/test_files/b_sorted.xml deleted file mode 100644 index 1b2298a..0000000 --- a/test_files/b_sorted.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 2 - - - - - - \ No newline at end of file diff --git a/test_files/c.xml b/test_files/c.xml deleted file mode 100644 index 0651af8..0000000 --- a/test_files/c.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - -
- - SurroundsWith - - locgettext - Kody Brown - Outputs: Loc.GetText("") - - - ll -
- - - -
- -
- - Expansion - - return false - Kody Brown - Outputs: return false - - - rf -
- - - -
-
\ No newline at end of file diff --git a/test_files/c_handsorted.xml b/test_files/c_handsorted.xml deleted file mode 100644 index c44bfe6..0000000 --- a/test_files/c_handsorted.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - -
- Kody Brown - Outputs: Loc.GetText("") - - - ll - - SurroundsWith - - locgettext -
- - - -
- -
- Kody Brown - Outputs: return false - - - rf - - Expansion - - return false -
- - - -
-
diff --git a/test_files/c_sorted.xml b/test_files/c_sorted.xml deleted file mode 100644 index dac82e7..0000000 --- a/test_files/c_sorted.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - -
- Kody Brown - Outputs: return false - - - rf - - Expansion - - return false -
- - - -
- -
- Kody Brown - Outputs: Loc.GetText("") - - - ll - - SurroundsWith - - locgettext -
- - - -
-
\ No newline at end of file diff --git a/test_files/d.xml b/test_files/d.xml deleted file mode 100644 index 904d8c9..0000000 --- a/test_files/d.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - -
- Check if object is not null (if stmt) - Kody Brown - Check if object is not null (if stmt) - notnull - - Expansion - -
- - - - obj - The object to check for null. - objValue - - - - - - -
- - -
- Check if object is null (if stmt) - Kody Brown - Check if object is null (if stmt) - isnull - - Expansion - -
- - - - obj - The object to check for null. - objValue - - - - - - -
-
\ No newline at end of file diff --git a/test_files/d_handsorted.xml b/test_files/d_handsorted.xml deleted file mode 100644 index 04f4b29..0000000 --- a/test_files/d_handsorted.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - -
- Kody Brown - Check if object is not null (if stmt) - notnull - - Expansion - - Check if object is not null (if stmt) -
- - - - - - - objValue - obj - The object to check for null. - - - -
- -
- Kody Brown - Check if object is null (if stmt) - isnull - - Expansion - - Check if object is null (if stmt) -
- - - - - - - objValue - obj - The object to check for null. - - - -
-
diff --git a/test_files/d_sorted.xml b/test_files/d_sorted.xml deleted file mode 100644 index c6ef071..0000000 --- a/test_files/d_sorted.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - -
- Kody Brown - Check if object is null (if stmt) - isnull - - Expansion - - Check if object is null (if stmt) -
- - - - - objValue - obj - The object to check for null. - - - -
- -
- Kody Brown - Check if object is not null (if stmt) - notnull - - Expansion - - Check if object is not null (if stmt) -
- - - - - objValue - obj - The object to check for null. - - - -
-
\ No newline at end of file diff --git a/test_files/e.xml b/test_files/e.xml deleted file mode 100644 index 3e63931..0000000 --- a/test_files/e.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - -
- - Expansion - - return true - Kody Brown - Outputs: return true - - - rt -
- - - - - -
- - -
- - Expansion - - return false - Kody Brown - Outputs: return false - - - rf -
- - - - - -
-
\ No newline at end of file diff --git a/test_files/e_handsorted.xml b/test_files/e_handsorted.xml deleted file mode 100644 index f81612d..0000000 --- a/test_files/e_handsorted.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - -
- Kody Brown - Outputs: return true - - - rt - - Expansion - - return true -
- - - - - -
- -
- Kody Brown - Outputs: return false - - - rf - - Expansion - - return false -
- - - - - -
-
diff --git a/test_files/e_sorted.xml b/test_files/e_sorted.xml deleted file mode 100644 index 6b61e8e..0000000 --- a/test_files/e_sorted.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - -
- Kody Brown - Outputs: return false - - - rf - - Expansion - - return false -
- - - -
- -
- Kody Brown - Outputs: return true - - - rt - - Expansion - - return true -
- - - -
-
\ No newline at end of file diff --git a/test_files/f.xml b/test_files/f.xml deleted file mode 100644 index 4a9837f..0000000 --- a/test_files/f.xml +++ /dev/null @@ -1,98 +0,0 @@ - - - -
- Check if string is not null and not empty (trimmed) - Kody Brown - Check if string is not null and not empty (trimmed) - notnull - - Expansion - -
- - - - str - The variable to check for null and length. - strValue - - - - - - -
- - -
- Check if string is null or empty (trimmed) - Kody Brown - Check if string is null or empty (trimmed) - isnull - - Expansion - -
- - - - str - The variable to check for null and length. - strValue - - - - - - -
- - -
- Check if string is not null and not empty - Kody Brown - Check if string is non-null and not empty - notnull - - Expansion - -
- - - - str - The variable to check for null and length. - strValue - - - - - - -
- - -
- Check if string is null or empty - Kody Brown - Check if string is null or empty - isnull - - Expansion - -
- - - - str - The variable to check for null and length. - strValue - - - - - - -
-
\ No newline at end of file diff --git a/test_files/f_handsorted.xml b/test_files/f_handsorted.xml deleted file mode 100644 index 2818a92..0000000 --- a/test_files/f_handsorted.xml +++ /dev/null @@ -1,87 +0,0 @@ - - - -
- Kody Brown - Check if string is not null and not empty (trimmed) - notnull - - Expansion - - Check if string is not null and not empty (trimmed) -
- - - - - strValue - str - The variable to check for null and length. - - - -
- -
- Kody Brown - Check if string is null or empty (trimmed) - isnull - - Expansion - - Check if string is null or empty (trimmed) -
- - - - - strValue - str - The variable to check for null and length. - - - -
- -
- Kody Brown - Check if string is non-null and not empty - notnull - - Expansion - - Check if string is not null and not empty -
- - - - - strValue - str - The variable to check for null and length. - - - -
- -
- Kody Brown - Check if string is null or empty - isnull - - Expansion - - Check if string is null or empty -
- - - - - strValue - str - The variable to check for null and length. - - - -
-
diff --git a/test_files/f_sorted.xml b/test_files/f_sorted.xml deleted file mode 100644 index 8de1821..0000000 --- a/test_files/f_sorted.xml +++ /dev/null @@ -1,87 +0,0 @@ - - - -
- Kody Brown - Check if string is null or empty - isnull - - Expansion - - Check if string is null or empty -
- - - - - strValue - str - The variable to check for null and length. - - - -
- -
- Kody Brown - Check if string is non-null and not empty - notnull - - Expansion - - Check if string is not null and not empty -
- - - - - strValue - str - The variable to check for null and length. - - - -
- -
- Kody Brown - Check if string is null or empty (trimmed) - isnull - - Expansion - - Check if string is null or empty (trimmed) -
- - - - - strValue - str - The variable to check for null and length. - - - -
- -
- Kody Brown - Check if string is not null and not empty (trimmed) - notnull - - Expansion - - Check if string is not null and not empty (trimmed) -
- - - - - strValue - str - The variable to check for null and length. - - - -
-
\ No newline at end of file diff --git a/test_files/g.xml b/test_files/g.xml deleted file mode 100644 index e4350db..0000000 --- a/test_files/g.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - Check if string is null or empty (trimmed) - - - - - - - - - - Check if string is not null and not empty (trimmed) - - - - - - - - - - - - - - - Check if string is not null and not empty - - - - - Check if string is null or empty - - - - - - - - \ No newline at end of file diff --git a/test_files/g_handsorted.xml b/test_files/g_handsorted.xml deleted file mode 100644 index 000291f..0000000 --- a/test_files/g_handsorted.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - Check if string is not null and not empty (trimmed) - - - - - - - - Check if string is null or empty (trimmed) - - - - - - - - Check if string is null or empty - - - - - - - - Check if string is not null and not empty - - - \ No newline at end of file diff --git a/test_files/g_sorted.xml b/test_files/g_sorted.xml deleted file mode 100644 index 0793b25..0000000 --- a/test_files/g_sorted.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - Check if string is null or empty - - - - - - - - Check if string is not null and not empty - - - - - - - - Check if string is not null and not empty (trimmed) - - - - - - - - Check if string is null or empty (trimmed) - - - \ No newline at end of file From 738b2e9cc93cf09819de5173014668335f61a994 Mon Sep 17 00:00:00 2001 From: Bassem Srouji Date: Thu, 3 Jun 2021 17:34:02 -0400 Subject: [PATCH 3/3] restructure folders --- sortxml.sln | 52 +++++----- Program.cs => sortxml/Program.cs | 0 .../Properties}/PublishProfiles/any.pubxml | 0 .../PublishProfiles/linux-arm.pubxml | 0 .../PublishProfiles/linux-x64.pubxml | 0 .../PublishProfiles/macos-x64.pubxml | 0 .../PublishProfiles/win-arm.pubxml | 0 .../PublishProfiles/win-x64.pubxml | 0 .../PublishProfiles/win-x86.pubxml | 0 sortxml.csproj => sortxml/sortxml.csproj | 0 sortxmlXUnitProject/UnitTestAll.cs | 45 +++++++++ .../sortxmlXUnitProject.csproj | 26 +++++ sortxmlXUnitProject/test_files/b.xml | 59 +++++++++++ .../test_files/b_handsorted.xml | 59 +++++++++++ sortxmlXUnitProject/test_files/b_sorted.xml | 59 +++++++++++ sortxmlXUnitProject/test_files/c.xml | 35 +++++++ .../test_files/c_handsorted.xml | 35 +++++++ sortxmlXUnitProject/test_files/c_sorted.xml | 35 +++++++ sortxmlXUnitProject/test_files/d.xml | 54 ++++++++++ .../test_files/d_handsorted.xml | 53 ++++++++++ sortxmlXUnitProject/test_files/d_sorted.xml | 49 ++++++++++ sortxmlXUnitProject/test_files/e.xml | 40 ++++++++ .../test_files/e_handsorted.xml | 39 ++++++++ sortxmlXUnitProject/test_files/e_sorted.xml | 35 +++++++ sortxmlXUnitProject/test_files/f.xml | 98 +++++++++++++++++++ .../test_files/f_handsorted.xml | 87 ++++++++++++++++ sortxmlXUnitProject/test_files/f_sorted.xml | 87 ++++++++++++++++ sortxmlXUnitProject/test_files/g.xml | 43 ++++++++ .../test_files/g_handsorted.xml | 35 +++++++ sortxmlXUnitProject/test_files/g_sorted.xml | 35 +++++++ sortxmlXUnitProject/test_files/h.xml | 29 ++++++ sortxmlXUnitProject/test_files/h_sorted.xml | 29 ++++++ 32 files changed, 1092 insertions(+), 26 deletions(-) rename Program.cs => sortxml/Program.cs (100%) rename {Properties => sortxml/Properties}/PublishProfiles/any.pubxml (100%) rename {Properties => sortxml/Properties}/PublishProfiles/linux-arm.pubxml (100%) rename {Properties => sortxml/Properties}/PublishProfiles/linux-x64.pubxml (100%) rename {Properties => sortxml/Properties}/PublishProfiles/macos-x64.pubxml (100%) rename {Properties => sortxml/Properties}/PublishProfiles/win-arm.pubxml (100%) rename {Properties => sortxml/Properties}/PublishProfiles/win-x64.pubxml (100%) rename {Properties => sortxml/Properties}/PublishProfiles/win-x86.pubxml (100%) rename sortxml.csproj => sortxml/sortxml.csproj (100%) create mode 100644 sortxmlXUnitProject/UnitTestAll.cs create mode 100644 sortxmlXUnitProject/sortxmlXUnitProject.csproj create mode 100644 sortxmlXUnitProject/test_files/b.xml create mode 100644 sortxmlXUnitProject/test_files/b_handsorted.xml create mode 100644 sortxmlXUnitProject/test_files/b_sorted.xml create mode 100644 sortxmlXUnitProject/test_files/c.xml create mode 100644 sortxmlXUnitProject/test_files/c_handsorted.xml create mode 100644 sortxmlXUnitProject/test_files/c_sorted.xml create mode 100644 sortxmlXUnitProject/test_files/d.xml create mode 100644 sortxmlXUnitProject/test_files/d_handsorted.xml create mode 100644 sortxmlXUnitProject/test_files/d_sorted.xml create mode 100644 sortxmlXUnitProject/test_files/e.xml create mode 100644 sortxmlXUnitProject/test_files/e_handsorted.xml create mode 100644 sortxmlXUnitProject/test_files/e_sorted.xml create mode 100644 sortxmlXUnitProject/test_files/f.xml create mode 100644 sortxmlXUnitProject/test_files/f_handsorted.xml create mode 100644 sortxmlXUnitProject/test_files/f_sorted.xml create mode 100644 sortxmlXUnitProject/test_files/g.xml create mode 100644 sortxmlXUnitProject/test_files/g_handsorted.xml create mode 100644 sortxmlXUnitProject/test_files/g_sorted.xml create mode 100644 sortxmlXUnitProject/test_files/h.xml create mode 100644 sortxmlXUnitProject/test_files/h_sorted.xml diff --git a/sortxml.sln b/sortxml.sln index 4335b02..5cbd3b7 100644 --- a/sortxml.sln +++ b/sortxml.sln @@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.30104.148 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "sortxml", "sortxml.csproj", "{F015ED1D-89EF-4251-9788-D581536501F2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "sortxmlXUnitProject", "sortxmlXUnitProject\sortxmlXUnitProject.csproj", "{292ABDF4-3CA6-499F-9EF5-A758D71DE929}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sortxmlXUnitProject", "..\sortxmlXUnitProject\sortxmlXUnitProject.csproj", "{08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "sortxml", "sortxml\sortxml.csproj", "{20D5AD14-A78A-441F-8EA8-E99F58F7B6F9}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -17,30 +17,30 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {F015ED1D-89EF-4251-9788-D581536501F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F015ED1D-89EF-4251-9788-D581536501F2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F015ED1D-89EF-4251-9788-D581536501F2}.Debug|x64.ActiveCfg = Debug|x64 - {F015ED1D-89EF-4251-9788-D581536501F2}.Debug|x64.Build.0 = Debug|x64 - {F015ED1D-89EF-4251-9788-D581536501F2}.Debug|x86.ActiveCfg = Debug|x86 - {F015ED1D-89EF-4251-9788-D581536501F2}.Debug|x86.Build.0 = Debug|x86 - {F015ED1D-89EF-4251-9788-D581536501F2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F015ED1D-89EF-4251-9788-D581536501F2}.Release|Any CPU.Build.0 = Release|Any CPU - {F015ED1D-89EF-4251-9788-D581536501F2}.Release|x64.ActiveCfg = Release|x64 - {F015ED1D-89EF-4251-9788-D581536501F2}.Release|x64.Build.0 = Release|x64 - {F015ED1D-89EF-4251-9788-D581536501F2}.Release|x86.ActiveCfg = Release|x86 - {F015ED1D-89EF-4251-9788-D581536501F2}.Release|x86.Build.0 = Release|x86 - {08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}.Debug|x64.ActiveCfg = Debug|Any CPU - {08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}.Debug|x64.Build.0 = Debug|Any CPU - {08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}.Debug|x86.ActiveCfg = Debug|Any CPU - {08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}.Debug|x86.Build.0 = Debug|Any CPU - {08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}.Release|Any CPU.Build.0 = Release|Any CPU - {08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}.Release|x64.ActiveCfg = Release|Any CPU - {08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}.Release|x64.Build.0 = Release|Any CPU - {08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}.Release|x86.ActiveCfg = Release|Any CPU - {08533546-F9AA-4DD3-8C8F-87D1AD74EA1B}.Release|x86.Build.0 = Release|Any CPU + {292ABDF4-3CA6-499F-9EF5-A758D71DE929}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {292ABDF4-3CA6-499F-9EF5-A758D71DE929}.Debug|Any CPU.Build.0 = Debug|Any CPU + {292ABDF4-3CA6-499F-9EF5-A758D71DE929}.Debug|x64.ActiveCfg = Debug|Any CPU + {292ABDF4-3CA6-499F-9EF5-A758D71DE929}.Debug|x64.Build.0 = Debug|Any CPU + {292ABDF4-3CA6-499F-9EF5-A758D71DE929}.Debug|x86.ActiveCfg = Debug|Any CPU + {292ABDF4-3CA6-499F-9EF5-A758D71DE929}.Debug|x86.Build.0 = Debug|Any CPU + {292ABDF4-3CA6-499F-9EF5-A758D71DE929}.Release|Any CPU.ActiveCfg = Release|Any CPU + {292ABDF4-3CA6-499F-9EF5-A758D71DE929}.Release|Any CPU.Build.0 = Release|Any CPU + {292ABDF4-3CA6-499F-9EF5-A758D71DE929}.Release|x64.ActiveCfg = Release|Any CPU + {292ABDF4-3CA6-499F-9EF5-A758D71DE929}.Release|x64.Build.0 = Release|Any CPU + {292ABDF4-3CA6-499F-9EF5-A758D71DE929}.Release|x86.ActiveCfg = Release|Any CPU + {292ABDF4-3CA6-499F-9EF5-A758D71DE929}.Release|x86.Build.0 = Release|Any CPU + {20D5AD14-A78A-441F-8EA8-E99F58F7B6F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {20D5AD14-A78A-441F-8EA8-E99F58F7B6F9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {20D5AD14-A78A-441F-8EA8-E99F58F7B6F9}.Debug|x64.ActiveCfg = Debug|x64 + {20D5AD14-A78A-441F-8EA8-E99F58F7B6F9}.Debug|x64.Build.0 = Debug|x64 + {20D5AD14-A78A-441F-8EA8-E99F58F7B6F9}.Debug|x86.ActiveCfg = Debug|x86 + {20D5AD14-A78A-441F-8EA8-E99F58F7B6F9}.Debug|x86.Build.0 = Debug|x86 + {20D5AD14-A78A-441F-8EA8-E99F58F7B6F9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {20D5AD14-A78A-441F-8EA8-E99F58F7B6F9}.Release|Any CPU.Build.0 = Release|Any CPU + {20D5AD14-A78A-441F-8EA8-E99F58F7B6F9}.Release|x64.ActiveCfg = Release|x64 + {20D5AD14-A78A-441F-8EA8-E99F58F7B6F9}.Release|x64.Build.0 = Release|x64 + {20D5AD14-A78A-441F-8EA8-E99F58F7B6F9}.Release|x86.ActiveCfg = Release|x86 + {20D5AD14-A78A-441F-8EA8-E99F58F7B6F9}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Program.cs b/sortxml/Program.cs similarity index 100% rename from Program.cs rename to sortxml/Program.cs diff --git a/Properties/PublishProfiles/any.pubxml b/sortxml/Properties/PublishProfiles/any.pubxml similarity index 100% rename from Properties/PublishProfiles/any.pubxml rename to sortxml/Properties/PublishProfiles/any.pubxml diff --git a/Properties/PublishProfiles/linux-arm.pubxml b/sortxml/Properties/PublishProfiles/linux-arm.pubxml similarity index 100% rename from Properties/PublishProfiles/linux-arm.pubxml rename to sortxml/Properties/PublishProfiles/linux-arm.pubxml diff --git a/Properties/PublishProfiles/linux-x64.pubxml b/sortxml/Properties/PublishProfiles/linux-x64.pubxml similarity index 100% rename from Properties/PublishProfiles/linux-x64.pubxml rename to sortxml/Properties/PublishProfiles/linux-x64.pubxml diff --git a/Properties/PublishProfiles/macos-x64.pubxml b/sortxml/Properties/PublishProfiles/macos-x64.pubxml similarity index 100% rename from Properties/PublishProfiles/macos-x64.pubxml rename to sortxml/Properties/PublishProfiles/macos-x64.pubxml diff --git a/Properties/PublishProfiles/win-arm.pubxml b/sortxml/Properties/PublishProfiles/win-arm.pubxml similarity index 100% rename from Properties/PublishProfiles/win-arm.pubxml rename to sortxml/Properties/PublishProfiles/win-arm.pubxml diff --git a/Properties/PublishProfiles/win-x64.pubxml b/sortxml/Properties/PublishProfiles/win-x64.pubxml similarity index 100% rename from Properties/PublishProfiles/win-x64.pubxml rename to sortxml/Properties/PublishProfiles/win-x64.pubxml diff --git a/Properties/PublishProfiles/win-x86.pubxml b/sortxml/Properties/PublishProfiles/win-x86.pubxml similarity index 100% rename from Properties/PublishProfiles/win-x86.pubxml rename to sortxml/Properties/PublishProfiles/win-x86.pubxml diff --git a/sortxml.csproj b/sortxml/sortxml.csproj similarity index 100% rename from sortxml.csproj rename to sortxml/sortxml.csproj diff --git a/sortxmlXUnitProject/UnitTestAll.cs b/sortxmlXUnitProject/UnitTestAll.cs new file mode 100644 index 0000000..bb11682 --- /dev/null +++ b/sortxmlXUnitProject/UnitTestAll.cs @@ -0,0 +1,45 @@ +using System; +using Xunit; +using sortxml; +using System.Reflection; +using System.IO; +using System.Linq; + +namespace sortxmlXUnitProject +{ + public class UnitTestAll + { + static string GetTestFilesPath() + { + var codeBaseUrl = new Uri(Assembly.GetExecutingAssembly().CodeBase); + var codeBasePath = Uri.UnescapeDataString(codeBaseUrl.AbsolutePath); + var dirPath = Path.GetFullPath(Path.GetDirectoryName(codeBasePath) + @"/../../../test_files/"); + return dirPath; + } + + static bool CompareFiles(string baseFilePath, string generatedTestFilePath) + { + var testData = File.ReadAllBytes(generatedTestFilePath); + var baseData = File.ReadAllBytes(baseFilePath); + return testData.SequenceEqual(baseData); + } + + [Fact] + public void TestAllFiles() + { + var testFilesPath = GetTestFilesPath(); + foreach(var file in Directory.GetFiles(testFilesPath, "*.xml")) + { + if (!file.Contains("_handsorted.xml") && !file.Contains("_sorted.xml") && !file.Contains("_test.xml")) + { + var name = Path.GetFileNameWithoutExtension(file); + var resultFile = testFilesPath + name + "_test.xml"; + var baseFile = testFilesPath + name + "_sorted.xml"; + sortxml.Program.Main(new string[] { "--sort", file, resultFile}); + Assert.True(CompareFiles(baseFile, resultFile), "Comparing " + file); + File.Delete(resultFile); + } + } + } + } +} diff --git a/sortxmlXUnitProject/sortxmlXUnitProject.csproj b/sortxmlXUnitProject/sortxmlXUnitProject.csproj new file mode 100644 index 0000000..94d2145 --- /dev/null +++ b/sortxmlXUnitProject/sortxmlXUnitProject.csproj @@ -0,0 +1,26 @@ + + + + netcoreapp3.1 + + false + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/sortxmlXUnitProject/test_files/b.xml b/sortxmlXUnitProject/test_files/b.xml new file mode 100644 index 0000000..e081cdb --- /dev/null +++ b/sortxmlXUnitProject/test_files/b.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + + diff --git a/sortxmlXUnitProject/test_files/b_handsorted.xml b/sortxmlXUnitProject/test_files/b_handsorted.xml new file mode 100644 index 0000000..5f00fa9 --- /dev/null +++ b/sortxmlXUnitProject/test_files/b_handsorted.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + + diff --git a/sortxmlXUnitProject/test_files/b_sorted.xml b/sortxmlXUnitProject/test_files/b_sorted.xml new file mode 100644 index 0000000..1b2298a --- /dev/null +++ b/sortxmlXUnitProject/test_files/b_sorted.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2 + + + + + + \ No newline at end of file diff --git a/sortxmlXUnitProject/test_files/c.xml b/sortxmlXUnitProject/test_files/c.xml new file mode 100644 index 0000000..0651af8 --- /dev/null +++ b/sortxmlXUnitProject/test_files/c.xml @@ -0,0 +1,35 @@ + + + +
+ + SurroundsWith + + locgettext + Kody Brown + Outputs: Loc.GetText("") + + + ll +
+ + + +
+ +
+ + Expansion + + return false + Kody Brown + Outputs: return false + + + rf +
+ + + +
+
\ No newline at end of file diff --git a/sortxmlXUnitProject/test_files/c_handsorted.xml b/sortxmlXUnitProject/test_files/c_handsorted.xml new file mode 100644 index 0000000..c44bfe6 --- /dev/null +++ b/sortxmlXUnitProject/test_files/c_handsorted.xml @@ -0,0 +1,35 @@ + + + +
+ Kody Brown + Outputs: Loc.GetText("") + + + ll + + SurroundsWith + + locgettext +
+ + + +
+ +
+ Kody Brown + Outputs: return false + + + rf + + Expansion + + return false +
+ + + +
+
diff --git a/sortxmlXUnitProject/test_files/c_sorted.xml b/sortxmlXUnitProject/test_files/c_sorted.xml new file mode 100644 index 0000000..ad16fdf --- /dev/null +++ b/sortxmlXUnitProject/test_files/c_sorted.xml @@ -0,0 +1,35 @@ + + + +
+ Kody Brown + Outputs: Loc.GetText("") + + + ll + + SurroundsWith + + locgettext +
+ + + +
+ +
+ Kody Brown + Outputs: return false + + + rf + + Expansion + + return false +
+ + + +
+
\ No newline at end of file diff --git a/sortxmlXUnitProject/test_files/d.xml b/sortxmlXUnitProject/test_files/d.xml new file mode 100644 index 0000000..904d8c9 --- /dev/null +++ b/sortxmlXUnitProject/test_files/d.xml @@ -0,0 +1,54 @@ + + + +
+ Check if object is not null (if stmt) + Kody Brown + Check if object is not null (if stmt) + notnull + + Expansion + +
+ + + + obj + The object to check for null. + objValue + + + + + + +
+ + +
+ Check if object is null (if stmt) + Kody Brown + Check if object is null (if stmt) + isnull + + Expansion + +
+ + + + obj + The object to check for null. + objValue + + + + + + +
+
\ No newline at end of file diff --git a/sortxmlXUnitProject/test_files/d_handsorted.xml b/sortxmlXUnitProject/test_files/d_handsorted.xml new file mode 100644 index 0000000..04f4b29 --- /dev/null +++ b/sortxmlXUnitProject/test_files/d_handsorted.xml @@ -0,0 +1,53 @@ + + + +
+ Kody Brown + Check if object is not null (if stmt) + notnull + + Expansion + + Check if object is not null (if stmt) +
+ + + + + + + objValue + obj + The object to check for null. + + + +
+ +
+ Kody Brown + Check if object is null (if stmt) + isnull + + Expansion + + Check if object is null (if stmt) +
+ + + + + + + objValue + obj + The object to check for null. + + + +
+
diff --git a/sortxmlXUnitProject/test_files/d_sorted.xml b/sortxmlXUnitProject/test_files/d_sorted.xml new file mode 100644 index 0000000..ba8b3ae --- /dev/null +++ b/sortxmlXUnitProject/test_files/d_sorted.xml @@ -0,0 +1,49 @@ + + + +
+ Kody Brown + Check if object is not null (if stmt) + notnull + + Expansion + + Check if object is not null (if stmt) +
+ + + + + objValue + obj + The object to check for null. + + + +
+ +
+ Kody Brown + Check if object is null (if stmt) + isnull + + Expansion + + Check if object is null (if stmt) +
+ + + + + objValue + obj + The object to check for null. + + + +
+
\ No newline at end of file diff --git a/sortxmlXUnitProject/test_files/e.xml b/sortxmlXUnitProject/test_files/e.xml new file mode 100644 index 0000000..3e63931 --- /dev/null +++ b/sortxmlXUnitProject/test_files/e.xml @@ -0,0 +1,40 @@ + + + +
+ + Expansion + + return true + Kody Brown + Outputs: return true + + + rt +
+ + + + + +
+ + +
+ + Expansion + + return false + Kody Brown + Outputs: return false + + + rf +
+ + + + + +
+
\ No newline at end of file diff --git a/sortxmlXUnitProject/test_files/e_handsorted.xml b/sortxmlXUnitProject/test_files/e_handsorted.xml new file mode 100644 index 0000000..f81612d --- /dev/null +++ b/sortxmlXUnitProject/test_files/e_handsorted.xml @@ -0,0 +1,39 @@ + + + +
+ Kody Brown + Outputs: return true + + + rt + + Expansion + + return true +
+ + + + + +
+ +
+ Kody Brown + Outputs: return false + + + rf + + Expansion + + return false +
+ + + + + +
+
diff --git a/sortxmlXUnitProject/test_files/e_sorted.xml b/sortxmlXUnitProject/test_files/e_sorted.xml new file mode 100644 index 0000000..6b61e8e --- /dev/null +++ b/sortxmlXUnitProject/test_files/e_sorted.xml @@ -0,0 +1,35 @@ + + + +
+ Kody Brown + Outputs: return false + + + rf + + Expansion + + return false +
+ + + +
+ +
+ Kody Brown + Outputs: return true + + + rt + + Expansion + + return true +
+ + + +
+
\ No newline at end of file diff --git a/sortxmlXUnitProject/test_files/f.xml b/sortxmlXUnitProject/test_files/f.xml new file mode 100644 index 0000000..4a9837f --- /dev/null +++ b/sortxmlXUnitProject/test_files/f.xml @@ -0,0 +1,98 @@ + + + +
+ Check if string is not null and not empty (trimmed) + Kody Brown + Check if string is not null and not empty (trimmed) + notnull + + Expansion + +
+ + + + str + The variable to check for null and length. + strValue + + + + + + +
+ + +
+ Check if string is null or empty (trimmed) + Kody Brown + Check if string is null or empty (trimmed) + isnull + + Expansion + +
+ + + + str + The variable to check for null and length. + strValue + + + + + + +
+ + +
+ Check if string is not null and not empty + Kody Brown + Check if string is non-null and not empty + notnull + + Expansion + +
+ + + + str + The variable to check for null and length. + strValue + + + + + + +
+ + +
+ Check if string is null or empty + Kody Brown + Check if string is null or empty + isnull + + Expansion + +
+ + + + str + The variable to check for null and length. + strValue + + + + + + +
+
\ No newline at end of file diff --git a/sortxmlXUnitProject/test_files/f_handsorted.xml b/sortxmlXUnitProject/test_files/f_handsorted.xml new file mode 100644 index 0000000..2818a92 --- /dev/null +++ b/sortxmlXUnitProject/test_files/f_handsorted.xml @@ -0,0 +1,87 @@ + + + +
+ Kody Brown + Check if string is not null and not empty (trimmed) + notnull + + Expansion + + Check if string is not null and not empty (trimmed) +
+ + + + + strValue + str + The variable to check for null and length. + + + +
+ +
+ Kody Brown + Check if string is null or empty (trimmed) + isnull + + Expansion + + Check if string is null or empty (trimmed) +
+ + + + + strValue + str + The variable to check for null and length. + + + +
+ +
+ Kody Brown + Check if string is non-null and not empty + notnull + + Expansion + + Check if string is not null and not empty +
+ + + + + strValue + str + The variable to check for null and length. + + + +
+ +
+ Kody Brown + Check if string is null or empty + isnull + + Expansion + + Check if string is null or empty +
+ + + + + strValue + str + The variable to check for null and length. + + + +
+
diff --git a/sortxmlXUnitProject/test_files/f_sorted.xml b/sortxmlXUnitProject/test_files/f_sorted.xml new file mode 100644 index 0000000..369e712 --- /dev/null +++ b/sortxmlXUnitProject/test_files/f_sorted.xml @@ -0,0 +1,87 @@ + + + +
+ Kody Brown + Check if string is non-null and not empty + notnull + + Expansion + + Check if string is not null and not empty +
+ + + + + strValue + str + The variable to check for null and length. + + + +
+ +
+ Kody Brown + Check if string is not null and not empty (trimmed) + notnull + + Expansion + + Check if string is not null and not empty (trimmed) +
+ + + + + strValue + str + The variable to check for null and length. + + + +
+ +
+ Kody Brown + Check if string is null or empty (trimmed) + isnull + + Expansion + + Check if string is null or empty (trimmed) +
+ + + + + strValue + str + The variable to check for null and length. + + + +
+ +
+ Kody Brown + Check if string is null or empty + isnull + + Expansion + + Check if string is null or empty +
+ + + + + strValue + str + The variable to check for null and length. + + + +
+
\ No newline at end of file diff --git a/sortxmlXUnitProject/test_files/g.xml b/sortxmlXUnitProject/test_files/g.xml new file mode 100644 index 0000000..e4350db --- /dev/null +++ b/sortxmlXUnitProject/test_files/g.xml @@ -0,0 +1,43 @@ + + + + + Check if string is null or empty (trimmed) + + + + + + + + + + Check if string is not null and not empty (trimmed) + + + + + + + + + + + + + + + Check if string is not null and not empty + + + + + Check if string is null or empty + + + + + + + + \ No newline at end of file diff --git a/sortxmlXUnitProject/test_files/g_handsorted.xml b/sortxmlXUnitProject/test_files/g_handsorted.xml new file mode 100644 index 0000000..000291f --- /dev/null +++ b/sortxmlXUnitProject/test_files/g_handsorted.xml @@ -0,0 +1,35 @@ + + + + + + + + Check if string is not null and not empty (trimmed) + + + + + + + + Check if string is null or empty (trimmed) + + + + + + + + Check if string is null or empty + + + + + + + + Check if string is not null and not empty + + + \ No newline at end of file diff --git a/sortxmlXUnitProject/test_files/g_sorted.xml b/sortxmlXUnitProject/test_files/g_sorted.xml new file mode 100644 index 0000000..18056bc --- /dev/null +++ b/sortxmlXUnitProject/test_files/g_sorted.xml @@ -0,0 +1,35 @@ + + + + + + + + Check if string is not null and not empty (trimmed) + + + + + + + + Check if string is null or empty (trimmed) + + + + + + + + Check if string is null or empty + + + + + + + + Check if string is not null and not empty + + + \ No newline at end of file diff --git a/sortxmlXUnitProject/test_files/h.xml b/sortxmlXUnitProject/test_files/h.xml new file mode 100644 index 0000000..7e6fa58 --- /dev/null +++ b/sortxmlXUnitProject/test_files/h.xml @@ -0,0 +1,29 @@ + + + 4 + 1 + 2 + 3 + + + yes + + + + + yes2 + + + yes + + + + + no + + + 1 + 3 + 2 + 3 + \ No newline at end of file diff --git a/sortxmlXUnitProject/test_files/h_sorted.xml b/sortxmlXUnitProject/test_files/h_sorted.xml new file mode 100644 index 0000000..1da5087 --- /dev/null +++ b/sortxmlXUnitProject/test_files/h_sorted.xml @@ -0,0 +1,29 @@ + + + 1 + 2 + 3 + 3 + 2 + + + no + + + + + yes + + + + + yes + + + yes2 + + + 1 + 3 + 4 + \ No newline at end of file