From ce7124850db1757485ebc8506208ad6d86ae0f74 Mon Sep 17 00:00:00 2001 From: Tassilo Singhammer Date: Mon, 4 Apr 2022 21:58:00 +0200 Subject: [PATCH 1/7] Equality check for OptionalModifierNode plus tests (not ready) --- .../Language/HotChocolate.Language.sln | 269 +++++++++--------- .../OptionalModifierNode.cs | 38 ++- ...Chocolate.Language.SyntaxTree.Tests.csproj | 33 +++ .../OptionalModifierNodeTests.cs | 70 +++++ 4 files changed, 282 insertions(+), 128 deletions(-) create mode 100644 src/HotChocolate/Language/test/Language.SyntaxTree.Tests/HotChocolate.Language.SyntaxTree.Tests.csproj create mode 100644 src/HotChocolate/Language/test/Language.SyntaxTree.Tests/OptionalModifierNodeTests.cs diff --git a/src/HotChocolate/Language/HotChocolate.Language.sln b/src/HotChocolate/Language/HotChocolate.Language.sln index a03d52e4a7e..23d86b98da3 100644 --- a/src/HotChocolate/Language/HotChocolate.Language.sln +++ b/src/HotChocolate/Language/HotChocolate.Language.sln @@ -1,127 +1,142 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29721.120 -MinimumVisualStudioVersion = 15.0.26124.0 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{FCA1DCC3-66A9-491D-99CE-11E2726AF1D5}" - ProjectSection(SolutionItems) = preProject - src\Directory.Build.props = src\Directory.Build.props - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{5CBE099C-66CC-4D43-94FD-BCB5B4FE22D6}" - ProjectSection(SolutionItems) = preProject - test\Directory.Build.props = test\Directory.Build.props - EndProjectSection -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotChocolate.Language", "src\Language\HotChocolate.Language.csproj", "{BE45E181-1544-4505-898F-CF3F6D506863}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotChocolate.Language.SyntaxTree", "src\Language.SyntaxTree\HotChocolate.Language.SyntaxTree.csproj", "{C98C8EA8-2AA4-477E-A3A9-99EA527E3587}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotChocolate.Language.Utf8", "src\Language.Utf8\HotChocolate.Language.Utf8.csproj", "{64D87C70-3108-4443-B277-DE1B1E12EE3A}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotChocolate.Language.Visitors", "src\Language.Visitors\HotChocolate.Language.Visitors.csproj", "{82DE8A24-406B-43D7-A1B1-60B6633489D5}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmark", "benchmark", "{C951EBF9-1758-4505-8E5E-1BFA630C283C}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotChocolate.Language.Visitors.Benchmarks", "benchmark\Language.Visitors.Benchmarks\HotChocolate.Language.Visitors.Benchmarks.csproj", "{7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotChocolate.Language.Tests", "test\Language.Tests\HotChocolate.Language.Tests.csproj", "{B507C5E7-145A-4BB1-A932-26D39CB37A2B}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|Any CPU = Release|Any CPU - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {BE45E181-1544-4505-898F-CF3F6D506863}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {BE45E181-1544-4505-898F-CF3F6D506863}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BE45E181-1544-4505-898F-CF3F6D506863}.Debug|x64.ActiveCfg = Debug|Any CPU - {BE45E181-1544-4505-898F-CF3F6D506863}.Debug|x64.Build.0 = Debug|Any CPU - {BE45E181-1544-4505-898F-CF3F6D506863}.Debug|x86.ActiveCfg = Debug|Any CPU - {BE45E181-1544-4505-898F-CF3F6D506863}.Debug|x86.Build.0 = Debug|Any CPU - {BE45E181-1544-4505-898F-CF3F6D506863}.Release|Any CPU.ActiveCfg = Release|Any CPU - {BE45E181-1544-4505-898F-CF3F6D506863}.Release|Any CPU.Build.0 = Release|Any CPU - {BE45E181-1544-4505-898F-CF3F6D506863}.Release|x64.ActiveCfg = Release|Any CPU - {BE45E181-1544-4505-898F-CF3F6D506863}.Release|x64.Build.0 = Release|Any CPU - {BE45E181-1544-4505-898F-CF3F6D506863}.Release|x86.ActiveCfg = Release|Any CPU - {BE45E181-1544-4505-898F-CF3F6D506863}.Release|x86.Build.0 = Release|Any CPU - {C98C8EA8-2AA4-477E-A3A9-99EA527E3587}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C98C8EA8-2AA4-477E-A3A9-99EA527E3587}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C98C8EA8-2AA4-477E-A3A9-99EA527E3587}.Debug|x64.ActiveCfg = Debug|Any CPU - {C98C8EA8-2AA4-477E-A3A9-99EA527E3587}.Debug|x64.Build.0 = Debug|Any CPU - {C98C8EA8-2AA4-477E-A3A9-99EA527E3587}.Debug|x86.ActiveCfg = Debug|Any CPU - {C98C8EA8-2AA4-477E-A3A9-99EA527E3587}.Debug|x86.Build.0 = Debug|Any CPU - {C98C8EA8-2AA4-477E-A3A9-99EA527E3587}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C98C8EA8-2AA4-477E-A3A9-99EA527E3587}.Release|Any CPU.Build.0 = Release|Any CPU - {C98C8EA8-2AA4-477E-A3A9-99EA527E3587}.Release|x64.ActiveCfg = Release|Any CPU - {C98C8EA8-2AA4-477E-A3A9-99EA527E3587}.Release|x64.Build.0 = Release|Any CPU - {C98C8EA8-2AA4-477E-A3A9-99EA527E3587}.Release|x86.ActiveCfg = Release|Any CPU - {C98C8EA8-2AA4-477E-A3A9-99EA527E3587}.Release|x86.Build.0 = Release|Any CPU - {64D87C70-3108-4443-B277-DE1B1E12EE3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {64D87C70-3108-4443-B277-DE1B1E12EE3A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {64D87C70-3108-4443-B277-DE1B1E12EE3A}.Debug|x64.ActiveCfg = Debug|Any CPU - {64D87C70-3108-4443-B277-DE1B1E12EE3A}.Debug|x64.Build.0 = Debug|Any CPU - {64D87C70-3108-4443-B277-DE1B1E12EE3A}.Debug|x86.ActiveCfg = Debug|Any CPU - {64D87C70-3108-4443-B277-DE1B1E12EE3A}.Debug|x86.Build.0 = Debug|Any CPU - {64D87C70-3108-4443-B277-DE1B1E12EE3A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {64D87C70-3108-4443-B277-DE1B1E12EE3A}.Release|Any CPU.Build.0 = Release|Any CPU - {64D87C70-3108-4443-B277-DE1B1E12EE3A}.Release|x64.ActiveCfg = Release|Any CPU - {64D87C70-3108-4443-B277-DE1B1E12EE3A}.Release|x64.Build.0 = Release|Any CPU - {64D87C70-3108-4443-B277-DE1B1E12EE3A}.Release|x86.ActiveCfg = Release|Any CPU - {64D87C70-3108-4443-B277-DE1B1E12EE3A}.Release|x86.Build.0 = Release|Any CPU - {82DE8A24-406B-43D7-A1B1-60B6633489D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {82DE8A24-406B-43D7-A1B1-60B6633489D5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {82DE8A24-406B-43D7-A1B1-60B6633489D5}.Debug|x64.ActiveCfg = Debug|Any CPU - {82DE8A24-406B-43D7-A1B1-60B6633489D5}.Debug|x64.Build.0 = Debug|Any CPU - {82DE8A24-406B-43D7-A1B1-60B6633489D5}.Debug|x86.ActiveCfg = Debug|Any CPU - {82DE8A24-406B-43D7-A1B1-60B6633489D5}.Debug|x86.Build.0 = Debug|Any CPU - {82DE8A24-406B-43D7-A1B1-60B6633489D5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {82DE8A24-406B-43D7-A1B1-60B6633489D5}.Release|Any CPU.Build.0 = Release|Any CPU - {82DE8A24-406B-43D7-A1B1-60B6633489D5}.Release|x64.ActiveCfg = Release|Any CPU - {82DE8A24-406B-43D7-A1B1-60B6633489D5}.Release|x64.Build.0 = Release|Any CPU - {82DE8A24-406B-43D7-A1B1-60B6633489D5}.Release|x86.ActiveCfg = Release|Any CPU - {82DE8A24-406B-43D7-A1B1-60B6633489D5}.Release|x86.Build.0 = Release|Any CPU - {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}.Debug|x64.ActiveCfg = Debug|Any CPU - {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}.Debug|x64.Build.0 = Debug|Any CPU - {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}.Debug|x86.ActiveCfg = Debug|Any CPU - {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}.Debug|x86.Build.0 = Debug|Any CPU - {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}.Release|Any CPU.Build.0 = Release|Any CPU - {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}.Release|x64.ActiveCfg = Release|Any CPU - {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}.Release|x64.Build.0 = Release|Any CPU - {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}.Release|x86.ActiveCfg = Release|Any CPU - {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}.Release|x86.Build.0 = Release|Any CPU - {B507C5E7-145A-4BB1-A932-26D39CB37A2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B507C5E7-145A-4BB1-A932-26D39CB37A2B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B507C5E7-145A-4BB1-A932-26D39CB37A2B}.Debug|x64.ActiveCfg = Debug|Any CPU - {B507C5E7-145A-4BB1-A932-26D39CB37A2B}.Debug|x64.Build.0 = Debug|Any CPU - {B507C5E7-145A-4BB1-A932-26D39CB37A2B}.Debug|x86.ActiveCfg = Debug|Any CPU - {B507C5E7-145A-4BB1-A932-26D39CB37A2B}.Debug|x86.Build.0 = Debug|Any CPU - {B507C5E7-145A-4BB1-A932-26D39CB37A2B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B507C5E7-145A-4BB1-A932-26D39CB37A2B}.Release|Any CPU.Build.0 = Release|Any CPU - {B507C5E7-145A-4BB1-A932-26D39CB37A2B}.Release|x64.ActiveCfg = Release|Any CPU - {B507C5E7-145A-4BB1-A932-26D39CB37A2B}.Release|x64.Build.0 = Release|Any CPU - {B507C5E7-145A-4BB1-A932-26D39CB37A2B}.Release|x86.ActiveCfg = Release|Any CPU - {B507C5E7-145A-4BB1-A932-26D39CB37A2B}.Release|x86.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {BE45E181-1544-4505-898F-CF3F6D506863} = {FCA1DCC3-66A9-491D-99CE-11E2726AF1D5} - {C98C8EA8-2AA4-477E-A3A9-99EA527E3587} = {FCA1DCC3-66A9-491D-99CE-11E2726AF1D5} - {64D87C70-3108-4443-B277-DE1B1E12EE3A} = {FCA1DCC3-66A9-491D-99CE-11E2726AF1D5} - {82DE8A24-406B-43D7-A1B1-60B6633489D5} = {FCA1DCC3-66A9-491D-99CE-11E2726AF1D5} - {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7} = {C951EBF9-1758-4505-8E5E-1BFA630C283C} - {B507C5E7-145A-4BB1-A932-26D39CB37A2B} = {5CBE099C-66CC-4D43-94FD-BCB5B4FE22D6} - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {B771A0A0-A4AC-4841-8314-72D3403B3FC8} - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29721.120 +MinimumVisualStudioVersion = 15.0.26124.0 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{FCA1DCC3-66A9-491D-99CE-11E2726AF1D5}" + ProjectSection(SolutionItems) = preProject + src\Directory.Build.props = src\Directory.Build.props + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{5CBE099C-66CC-4D43-94FD-BCB5B4FE22D6}" + ProjectSection(SolutionItems) = preProject + test\Directory.Build.props = test\Directory.Build.props + EndProjectSection +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotChocolate.Language", "src\Language\HotChocolate.Language.csproj", "{BE45E181-1544-4505-898F-CF3F6D506863}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotChocolate.Language.SyntaxTree", "src\Language.SyntaxTree\HotChocolate.Language.SyntaxTree.csproj", "{C98C8EA8-2AA4-477E-A3A9-99EA527E3587}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotChocolate.Language.Utf8", "src\Language.Utf8\HotChocolate.Language.Utf8.csproj", "{64D87C70-3108-4443-B277-DE1B1E12EE3A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotChocolate.Language.Visitors", "src\Language.Visitors\HotChocolate.Language.Visitors.csproj", "{82DE8A24-406B-43D7-A1B1-60B6633489D5}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmark", "benchmark", "{C951EBF9-1758-4505-8E5E-1BFA630C283C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotChocolate.Language.Visitors.Benchmarks", "benchmark\Language.Visitors.Benchmarks\HotChocolate.Language.Visitors.Benchmarks.csproj", "{7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotChocolate.Language.Tests", "test\Language.Tests\HotChocolate.Language.Tests.csproj", "{B507C5E7-145A-4BB1-A932-26D39CB37A2B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Language.SyntaxTree.Tests", "test\Language.SyntaxTree.Tests\HotChocolate.Language.SyntaxTree.Tests.csproj", "{5E20BDB8-4C08-4DB8-BDFC-35B01D73603D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BE45E181-1544-4505-898F-CF3F6D506863}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BE45E181-1544-4505-898F-CF3F6D506863}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BE45E181-1544-4505-898F-CF3F6D506863}.Debug|x64.ActiveCfg = Debug|Any CPU + {BE45E181-1544-4505-898F-CF3F6D506863}.Debug|x64.Build.0 = Debug|Any CPU + {BE45E181-1544-4505-898F-CF3F6D506863}.Debug|x86.ActiveCfg = Debug|Any CPU + {BE45E181-1544-4505-898F-CF3F6D506863}.Debug|x86.Build.0 = Debug|Any CPU + {BE45E181-1544-4505-898F-CF3F6D506863}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BE45E181-1544-4505-898F-CF3F6D506863}.Release|Any CPU.Build.0 = Release|Any CPU + {BE45E181-1544-4505-898F-CF3F6D506863}.Release|x64.ActiveCfg = Release|Any CPU + {BE45E181-1544-4505-898F-CF3F6D506863}.Release|x64.Build.0 = Release|Any CPU + {BE45E181-1544-4505-898F-CF3F6D506863}.Release|x86.ActiveCfg = Release|Any CPU + {BE45E181-1544-4505-898F-CF3F6D506863}.Release|x86.Build.0 = Release|Any CPU + {C98C8EA8-2AA4-477E-A3A9-99EA527E3587}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C98C8EA8-2AA4-477E-A3A9-99EA527E3587}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C98C8EA8-2AA4-477E-A3A9-99EA527E3587}.Debug|x64.ActiveCfg = Debug|Any CPU + {C98C8EA8-2AA4-477E-A3A9-99EA527E3587}.Debug|x64.Build.0 = Debug|Any CPU + {C98C8EA8-2AA4-477E-A3A9-99EA527E3587}.Debug|x86.ActiveCfg = Debug|Any CPU + {C98C8EA8-2AA4-477E-A3A9-99EA527E3587}.Debug|x86.Build.0 = Debug|Any CPU + {C98C8EA8-2AA4-477E-A3A9-99EA527E3587}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C98C8EA8-2AA4-477E-A3A9-99EA527E3587}.Release|Any CPU.Build.0 = Release|Any CPU + {C98C8EA8-2AA4-477E-A3A9-99EA527E3587}.Release|x64.ActiveCfg = Release|Any CPU + {C98C8EA8-2AA4-477E-A3A9-99EA527E3587}.Release|x64.Build.0 = Release|Any CPU + {C98C8EA8-2AA4-477E-A3A9-99EA527E3587}.Release|x86.ActiveCfg = Release|Any CPU + {C98C8EA8-2AA4-477E-A3A9-99EA527E3587}.Release|x86.Build.0 = Release|Any CPU + {64D87C70-3108-4443-B277-DE1B1E12EE3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {64D87C70-3108-4443-B277-DE1B1E12EE3A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {64D87C70-3108-4443-B277-DE1B1E12EE3A}.Debug|x64.ActiveCfg = Debug|Any CPU + {64D87C70-3108-4443-B277-DE1B1E12EE3A}.Debug|x64.Build.0 = Debug|Any CPU + {64D87C70-3108-4443-B277-DE1B1E12EE3A}.Debug|x86.ActiveCfg = Debug|Any CPU + {64D87C70-3108-4443-B277-DE1B1E12EE3A}.Debug|x86.Build.0 = Debug|Any CPU + {64D87C70-3108-4443-B277-DE1B1E12EE3A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {64D87C70-3108-4443-B277-DE1B1E12EE3A}.Release|Any CPU.Build.0 = Release|Any CPU + {64D87C70-3108-4443-B277-DE1B1E12EE3A}.Release|x64.ActiveCfg = Release|Any CPU + {64D87C70-3108-4443-B277-DE1B1E12EE3A}.Release|x64.Build.0 = Release|Any CPU + {64D87C70-3108-4443-B277-DE1B1E12EE3A}.Release|x86.ActiveCfg = Release|Any CPU + {64D87C70-3108-4443-B277-DE1B1E12EE3A}.Release|x86.Build.0 = Release|Any CPU + {82DE8A24-406B-43D7-A1B1-60B6633489D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {82DE8A24-406B-43D7-A1B1-60B6633489D5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {82DE8A24-406B-43D7-A1B1-60B6633489D5}.Debug|x64.ActiveCfg = Debug|Any CPU + {82DE8A24-406B-43D7-A1B1-60B6633489D5}.Debug|x64.Build.0 = Debug|Any CPU + {82DE8A24-406B-43D7-A1B1-60B6633489D5}.Debug|x86.ActiveCfg = Debug|Any CPU + {82DE8A24-406B-43D7-A1B1-60B6633489D5}.Debug|x86.Build.0 = Debug|Any CPU + {82DE8A24-406B-43D7-A1B1-60B6633489D5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {82DE8A24-406B-43D7-A1B1-60B6633489D5}.Release|Any CPU.Build.0 = Release|Any CPU + {82DE8A24-406B-43D7-A1B1-60B6633489D5}.Release|x64.ActiveCfg = Release|Any CPU + {82DE8A24-406B-43D7-A1B1-60B6633489D5}.Release|x64.Build.0 = Release|Any CPU + {82DE8A24-406B-43D7-A1B1-60B6633489D5}.Release|x86.ActiveCfg = Release|Any CPU + {82DE8A24-406B-43D7-A1B1-60B6633489D5}.Release|x86.Build.0 = Release|Any CPU + {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}.Debug|x64.ActiveCfg = Debug|Any CPU + {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}.Debug|x64.Build.0 = Debug|Any CPU + {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}.Debug|x86.ActiveCfg = Debug|Any CPU + {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}.Debug|x86.Build.0 = Debug|Any CPU + {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}.Release|Any CPU.Build.0 = Release|Any CPU + {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}.Release|x64.ActiveCfg = Release|Any CPU + {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}.Release|x64.Build.0 = Release|Any CPU + {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}.Release|x86.ActiveCfg = Release|Any CPU + {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7}.Release|x86.Build.0 = Release|Any CPU + {B507C5E7-145A-4BB1-A932-26D39CB37A2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B507C5E7-145A-4BB1-A932-26D39CB37A2B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B507C5E7-145A-4BB1-A932-26D39CB37A2B}.Debug|x64.ActiveCfg = Debug|Any CPU + {B507C5E7-145A-4BB1-A932-26D39CB37A2B}.Debug|x64.Build.0 = Debug|Any CPU + {B507C5E7-145A-4BB1-A932-26D39CB37A2B}.Debug|x86.ActiveCfg = Debug|Any CPU + {B507C5E7-145A-4BB1-A932-26D39CB37A2B}.Debug|x86.Build.0 = Debug|Any CPU + {B507C5E7-145A-4BB1-A932-26D39CB37A2B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B507C5E7-145A-4BB1-A932-26D39CB37A2B}.Release|Any CPU.Build.0 = Release|Any CPU + {B507C5E7-145A-4BB1-A932-26D39CB37A2B}.Release|x64.ActiveCfg = Release|Any CPU + {B507C5E7-145A-4BB1-A932-26D39CB37A2B}.Release|x64.Build.0 = Release|Any CPU + {B507C5E7-145A-4BB1-A932-26D39CB37A2B}.Release|x86.ActiveCfg = Release|Any CPU + {B507C5E7-145A-4BB1-A932-26D39CB37A2B}.Release|x86.Build.0 = Release|Any CPU + {5E20BDB8-4C08-4DB8-BDFC-35B01D73603D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5E20BDB8-4C08-4DB8-BDFC-35B01D73603D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5E20BDB8-4C08-4DB8-BDFC-35B01D73603D}.Debug|x64.ActiveCfg = Debug|Any CPU + {5E20BDB8-4C08-4DB8-BDFC-35B01D73603D}.Debug|x64.Build.0 = Debug|Any CPU + {5E20BDB8-4C08-4DB8-BDFC-35B01D73603D}.Debug|x86.ActiveCfg = Debug|Any CPU + {5E20BDB8-4C08-4DB8-BDFC-35B01D73603D}.Debug|x86.Build.0 = Debug|Any CPU + {5E20BDB8-4C08-4DB8-BDFC-35B01D73603D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5E20BDB8-4C08-4DB8-BDFC-35B01D73603D}.Release|Any CPU.Build.0 = Release|Any CPU + {5E20BDB8-4C08-4DB8-BDFC-35B01D73603D}.Release|x64.ActiveCfg = Release|Any CPU + {5E20BDB8-4C08-4DB8-BDFC-35B01D73603D}.Release|x64.Build.0 = Release|Any CPU + {5E20BDB8-4C08-4DB8-BDFC-35B01D73603D}.Release|x86.ActiveCfg = Release|Any CPU + {5E20BDB8-4C08-4DB8-BDFC-35B01D73603D}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {BE45E181-1544-4505-898F-CF3F6D506863} = {FCA1DCC3-66A9-491D-99CE-11E2726AF1D5} + {C98C8EA8-2AA4-477E-A3A9-99EA527E3587} = {FCA1DCC3-66A9-491D-99CE-11E2726AF1D5} + {64D87C70-3108-4443-B277-DE1B1E12EE3A} = {FCA1DCC3-66A9-491D-99CE-11E2726AF1D5} + {82DE8A24-406B-43D7-A1B1-60B6633489D5} = {FCA1DCC3-66A9-491D-99CE-11E2726AF1D5} + {7FC0DC41-754A-48F8-89A4-FC3634F6E2B7} = {C951EBF9-1758-4505-8E5E-1BFA630C283C} + {B507C5E7-145A-4BB1-A932-26D39CB37A2B} = {5CBE099C-66CC-4D43-94FD-BCB5B4FE22D6} + {5E20BDB8-4C08-4DB8-BDFC-35B01D73603D} = {5CBE099C-66CC-4D43-94FD-BCB5B4FE22D6} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B771A0A0-A4AC-4841-8314-72D3403B3FC8} + EndGlobalSection +EndGlobal diff --git a/src/HotChocolate/Language/src/Language.SyntaxTree/OptionalModifierNode.cs b/src/HotChocolate/Language/src/Language.SyntaxTree/OptionalModifierNode.cs index 37dafcc2eac..0b51dfce6ea 100644 --- a/src/HotChocolate/Language/src/Language.SyntaxTree/OptionalModifierNode.cs +++ b/src/HotChocolate/Language/src/Language.SyntaxTree/OptionalModifierNode.cs @@ -1,9 +1,10 @@ +using System; using System.Collections.Generic; using HotChocolate.Language.Utilities; namespace HotChocolate.Language; -public sealed class OptionalModifierNode : INullabilityModifierNode +public sealed class OptionalModifierNode : INullabilityModifierNode, IEquatable { public OptionalModifierNode(ListNullabilityNode element) : this(null, element) { } @@ -55,4 +56,39 @@ public IEnumerable GetNodes() /// Returns the GraphQL syntax representation of this . /// public string ToString(bool indented) => SyntaxPrinter.Print(this, indented); + + /// + public bool Equals(OptionalModifierNode? other) + { + if (other is null) + { + return false; + } + + if (ReferenceEquals(this, other)) + { + return true; + } + + return Element.IsEqualTo(other.Element); + } + + public override bool Equals(object? obj) + { + return Equals(obj as OptionalModifierNode); + } + + /// + public override int GetHashCode() + => HashCode.Combine(base.GetHashCode(), Element); + + public static bool operator ==( + OptionalModifierNode? left, + OptionalModifierNode? right) + => Equals(left, right); + + public static bool operator !=( + OptionalModifierNode? left, + OptionalModifierNode? right) + => !Equals(left, right); } diff --git a/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/HotChocolate.Language.SyntaxTree.Tests.csproj b/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/HotChocolate.Language.SyntaxTree.Tests.csproj new file mode 100644 index 00000000000..e955dc5873a --- /dev/null +++ b/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/HotChocolate.Language.SyntaxTree.Tests.csproj @@ -0,0 +1,33 @@ + + + + net6.0 + enable + + false + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + + + + + diff --git a/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/OptionalModifierNodeTests.cs b/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/OptionalModifierNodeTests.cs new file mode 100644 index 00000000000..34d883e2b54 --- /dev/null +++ b/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/OptionalModifierNodeTests.cs @@ -0,0 +1,70 @@ +using Xunit; + +namespace Language.SyntaxTree.Tests; + +public class OptionalModifierNodeTests +{ + [Fact] + public void Equals_With_Same_Location() + { + // arrange + var a = new OptionalModifierNode(new Location(1, 1, 1, 1), new("aa"), new IntValueNode(123)); + var b = new ArgumentNode(new Location(1, 1, 1, 1), new("aa"), new IntValueNode(123)); + var c = new ArgumentNode(new Location(1, 1, 1, 1), new("aa"), new IntValueNode(567)); + + // act + var abResult = a.Equals(b); + var aaResult = a.Equals(a); + var acResult = a.Equals(c); + var aNullResult = a.Equals(default); + + // assert + Assert.True(abResult); + Assert.True(aaResult); + Assert.False(acResult); + Assert.False(aNullResult); + } + + [Fact] + public void Equals_With_Different_Location() + { + // arrange + var a = new ArgumentNode(new Location(1, 1, 1, 1), new("aa"), new IntValueNode(123)); + var b = new ArgumentNode(new Location(2, 2, 2, 2), new("aa"), new IntValueNode(123)); + var c = new ArgumentNode(new Location(3, 3, 3, 3), new("aa"), new IntValueNode(567)); + + // act + var abResult = a.Equals(b); + var aaResult = a.Equals(a); + var acResult = a.Equals(c); + var aNullResult = a.Equals(default); + + // assert + Assert.True(abResult); + Assert.True(aaResult); + Assert.False(acResult); + Assert.False(aNullResult); + } + + [Fact] + public void GetHashCode_With_Location() + { + // arrange + var a = new ArgumentNode(new Location(1, 1, 1, 1), new("aa"), new IntValueNode(123)); + var b = new ArgumentNode(new Location(2, 2, 2, 2), new("aa"), new IntValueNode(123)); + var c = new ArgumentNode(new Location(1, 1, 1, 1), new("aa"), new IntValueNode(567)); + var d = new ArgumentNode(new Location(2, 2, 2, 2), new("aa"), new IntValueNode(567)); + + // act + var aHash = a.GetHashCode(); + var bHash = b.GetHashCode(); + var cHash = c.GetHashCode(); + var dHash = d.GetHashCode(); + + // assert + Assert.Equal(aHash, bHash); + Assert.NotEqual(aHash, cHash); + Assert.Equal(cHash, dHash); + Assert.NotEqual(aHash, dHash); + } +} From ab9de74f8fb1395dfe1d3e2a439b7a19fefafd78 Mon Sep 17 00:00:00 2001 From: Tassilo Singhammer Date: Mon, 4 Apr 2022 22:31:46 +0200 Subject: [PATCH 2/7] Tests for OptionalModifierNode added --- .../Language/HotChocolate.Language.sln | 2 +- src/HotChocolate/Language/format.sh | 3 +- .../OptionalModifierNode.cs | 2 +- ...Chocolate.Language.SyntaxTree.Tests.csproj | 30 ++++++++----------- .../OptionalModifierNodeTests.cs | 25 +++++++++------- 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/HotChocolate/Language/HotChocolate.Language.sln b/src/HotChocolate/Language/HotChocolate.Language.sln index 23d86b98da3..b1e5a4bad9d 100644 --- a/src/HotChocolate/Language/HotChocolate.Language.sln +++ b/src/HotChocolate/Language/HotChocolate.Language.sln @@ -27,7 +27,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotChocolate.Language.Visit EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotChocolate.Language.Tests", "test\Language.Tests\HotChocolate.Language.Tests.csproj", "{B507C5E7-145A-4BB1-A932-26D39CB37A2B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Language.SyntaxTree.Tests", "test\Language.SyntaxTree.Tests\HotChocolate.Language.SyntaxTree.Tests.csproj", "{5E20BDB8-4C08-4DB8-BDFC-35B01D73603D}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.Language.SyntaxTree.Tests", "test\Language.SyntaxTree.Tests\HotChocolate.Language.SyntaxTree.Tests.csproj", "{5E20BDB8-4C08-4DB8-BDFC-35B01D73603D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/HotChocolate/Language/format.sh b/src/HotChocolate/Language/format.sh index 1c7d2fcb6ed..a6b6e099613 100755 --- a/src/HotChocolate/Language/format.sh +++ b/src/HotChocolate/Language/format.sh @@ -8,4 +8,5 @@ dotnet format $src/Language dotnet format $src/Language.SyntaxTree dotnet format $src/Language.Utf8 dotnet format $src/Language.Visitors -dotnet format $test/Language.Tests \ No newline at end of file +dotnet format $test/Language.Tests +dotnet format $test/Language.SyntaxTree.Tests diff --git a/src/HotChocolate/Language/src/Language.SyntaxTree/OptionalModifierNode.cs b/src/HotChocolate/Language/src/Language.SyntaxTree/OptionalModifierNode.cs index 0b51dfce6ea..4b56749bc15 100644 --- a/src/HotChocolate/Language/src/Language.SyntaxTree/OptionalModifierNode.cs +++ b/src/HotChocolate/Language/src/Language.SyntaxTree/OptionalModifierNode.cs @@ -80,7 +80,7 @@ public override bool Equals(object? obj) /// public override int GetHashCode() - => HashCode.Combine(base.GetHashCode(), Element); + => HashCode.Combine(Element?.GetHashCode()); public static bool operator ==( OptionalModifierNode? left, diff --git a/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/HotChocolate.Language.SyntaxTree.Tests.csproj b/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/HotChocolate.Language.SyntaxTree.Tests.csproj index e955dc5873a..e88ed353155 100644 --- a/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/HotChocolate.Language.SyntaxTree.Tests.csproj +++ b/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/HotChocolate.Language.SyntaxTree.Tests.csproj @@ -1,33 +1,27 @@ - + - net6.0 - enable - - false + HotChocolate.Language.SyntaxTree.Tests + HotChocolate.Language.SyntaxTree - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - + - + - + + Always + + + Always + - + diff --git a/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/OptionalModifierNodeTests.cs b/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/OptionalModifierNodeTests.cs index 34d883e2b54..995d90f0be0 100644 --- a/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/OptionalModifierNodeTests.cs +++ b/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/OptionalModifierNodeTests.cs @@ -1,16 +1,21 @@ using Xunit; +using HotChocolate.Language; +using System.Net.Security; namespace Language.SyntaxTree.Tests; public class OptionalModifierNodeTests { + private readonly ListNullabilityNode _element1 = new(new Location(1, 1, 1, 1), null); + private readonly ListNullabilityNode _element2 = new(new Location(1, 1, 1, 1), null); + [Fact] public void Equals_With_Same_Location() { // arrange - var a = new OptionalModifierNode(new Location(1, 1, 1, 1), new("aa"), new IntValueNode(123)); - var b = new ArgumentNode(new Location(1, 1, 1, 1), new("aa"), new IntValueNode(123)); - var c = new ArgumentNode(new Location(1, 1, 1, 1), new("aa"), new IntValueNode(567)); + var a = new OptionalModifierNode(new Location(1, 1, 1, 1), _element1); + var b = new OptionalModifierNode(new Location(1, 1, 1, 1), _element1); + var c = new OptionalModifierNode(new Location(1, 1, 1, 1), _element2); // act var abResult = a.Equals(b); @@ -29,9 +34,9 @@ public void Equals_With_Same_Location() public void Equals_With_Different_Location() { // arrange - var a = new ArgumentNode(new Location(1, 1, 1, 1), new("aa"), new IntValueNode(123)); - var b = new ArgumentNode(new Location(2, 2, 2, 2), new("aa"), new IntValueNode(123)); - var c = new ArgumentNode(new Location(3, 3, 3, 3), new("aa"), new IntValueNode(567)); + var a = new OptionalModifierNode(new Location(1, 1, 1, 1), _element1); + var b = new OptionalModifierNode(new Location(2, 2, 2, 2), _element1); + var c = new OptionalModifierNode(new Location(3, 3, 3, 3), _element2); // act var abResult = a.Equals(b); @@ -50,10 +55,10 @@ public void Equals_With_Different_Location() public void GetHashCode_With_Location() { // arrange - var a = new ArgumentNode(new Location(1, 1, 1, 1), new("aa"), new IntValueNode(123)); - var b = new ArgumentNode(new Location(2, 2, 2, 2), new("aa"), new IntValueNode(123)); - var c = new ArgumentNode(new Location(1, 1, 1, 1), new("aa"), new IntValueNode(567)); - var d = new ArgumentNode(new Location(2, 2, 2, 2), new("aa"), new IntValueNode(567)); + var a = new OptionalModifierNode(new Location(1, 1, 1, 1), _element1); + var b = new OptionalModifierNode(new Location(2, 2, 2, 2), _element1); + var c = new OptionalModifierNode(new Location(1, 1, 1, 1), _element2); + var d = new OptionalModifierNode(new Location(2, 2, 2, 2), _element2); // act var aHash = a.GetHashCode(); From 1d445c0c9af8925338fdf77b469198d3b4dd98e3 Mon Sep 17 00:00:00 2001 From: Tassilo Singhammer Date: Tue, 5 Apr 2022 22:18:06 +0200 Subject: [PATCH 3/7] Equality check for ScalarTypeDefinitionNode added --- .../ScalarTypeDefinitionNodeTests.cs | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/HotChocolate/Language/test/Language.SyntaxTree.Tests/ScalarTypeDefinitionNodeTests.cs diff --git a/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/ScalarTypeDefinitionNodeTests.cs b/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/ScalarTypeDefinitionNodeTests.cs new file mode 100644 index 00000000000..967cb588477 --- /dev/null +++ b/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/ScalarTypeDefinitionNodeTests.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using Xunit; + +namespace HotChocolate.Language.SyntaxTree; + +public class ScalarTypeDefinitionNodeTests +{ + private readonly NameNode _name = new("name1"); + private readonly StringValueNode _description1 = new("value1"); + private readonly StringValueNode _description2 = new("value2"); + private readonly IReadOnlyList _directives = Array.Empty(); + + [Fact] + public void Equals_With_Same_Location() + { + // arrange + var a = new ScalarTypeDefinitionNode(new Location(1, 1, 1, 1), _name, _description1, _directives); + var b = new ScalarTypeDefinitionNode(new Location(1, 1, 1, 1), _name, _description1, _directives); + var c = new ScalarTypeDefinitionNode(new Location(1, 1, 1, 1), _name, _description2, _directives); + + // act + var abResult = a.Equals(b); + var aaResult = a.Equals(a); + var acResult = a.Equals(c); + var aNullResult = a.Equals(default); + + // assert + Assert.True(abResult); + Assert.True(aaResult); + Assert.False(acResult); + Assert.False(aNullResult); + } + + [Fact] + public void Equals_With_Different_Location() + { + // arrange + var a = new ScalarTypeDefinitionNode(new Location(1, 1, 1, 1), _name, _description1, _directives); + var b = new ScalarTypeDefinitionNode(new Location(2, 2, 2, 2), _name, _description1, _directives); + var c = new ScalarTypeDefinitionNode(new Location(3, 3, 3, 3), _name, _description2, _directives); + + // act + var abResult = a.Equals(b); + var aaResult = a.Equals(a); + var acResult = a.Equals(c); + var aNullResult = a.Equals(default); + + // assert + Assert.True(abResult); + Assert.True(aaResult); + Assert.False(acResult); + Assert.False(aNullResult); + } + + [Fact] + public void GetHashCode_With_Location() + { + // arrange + var a = new ScalarTypeDefinitionNode(new Location(1, 1, 1, 1), _name, _description1, _directives); + var b = new ScalarTypeDefinitionNode(new Location(2, 2, 2, 2), _name, _description1, _directives); + var c = new ScalarTypeDefinitionNode(new Location(1, 1, 1, 1), _name, _description2, _directives); + var d = new ScalarTypeDefinitionNode(new Location(2, 2, 2, 2), _name, _description2, _directives); + + // act + var aHash = a.GetHashCode(); + var bHash = b.GetHashCode(); + var cHash = c.GetHashCode(); + var dHash = d.GetHashCode(); + + // assert + Assert.Equal(aHash, bHash); + Assert.NotEqual(aHash, cHash); + Assert.Equal(cHash, dHash); + Assert.NotEqual(aHash, dHash); + } +} From 02a94360b37735881f0fbfaf2360a5c2b3ab3eeb Mon Sep 17 00:00:00 2001 From: Tassilo Singhammer Date: Tue, 5 Apr 2022 23:02:11 +0200 Subject: [PATCH 4/7] Equality checks for scalar nodes added --- .../ScalarTypeDefinitionNode.cs | 56 ++++++++++++++ .../ScalarTypeDefinitionNodeBase.cs | 66 ++++++++++++++++ .../ScalarTypeExtensionNode.cs | 51 +++++++++++++ .../ScalarTypeDefinitionNodeTests.cs | 29 ++++--- .../ScalarTypeExtensionNodeTests.cs | 76 +++++++++++++++++++ 5 files changed, 267 insertions(+), 11 deletions(-) create mode 100644 src/HotChocolate/Language/test/Language.SyntaxTree.Tests/ScalarTypeExtensionNodeTests.cs diff --git a/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeDefinitionNode.cs b/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeDefinitionNode.cs index 7875b7ab926..7e56d5108ef 100644 --- a/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeDefinitionNode.cs +++ b/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeDefinitionNode.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using HotChocolate.Language.Utilities; @@ -6,6 +7,7 @@ namespace HotChocolate.Language; public sealed class ScalarTypeDefinitionNode : ScalarTypeDefinitionNodeBase , ITypeDefinitionNode + , IEquatable { public ScalarTypeDefinitionNode( Location? location, @@ -86,4 +88,58 @@ public ScalarTypeDefinitionNode WithDirectives( Location, Name, Description, directives); } + + /// + /// Determines whether the specified + /// is equal to the current . + /// + /// + /// The to compare with the current + /// . + /// + /// + /// true if the specified is equal + /// to the current ; + /// otherwise, false. + /// + public bool Equals(ScalarTypeDefinitionNode? other) + { + return base.Equals(other) && Description.IsEqualTo(other.Description); + } + + /// + /// Determines whether the specified is equal to + /// the current . + /// + /// + /// The to compare with the current + /// . + /// + /// + /// true if the specified is equal to the + /// current ; otherwise, false. + /// + public override bool Equals(object? obj) + => Equals(obj as ScalarTypeDefinitionNode); + + /// + /// Serves as a hash function for a + /// object. + /// + /// + /// A hash code for this instance that is suitable for use in + /// hashing algorithms and data structures such as a hash table. + /// + public override int GetHashCode() + => HashCode.Combine(base.GetHashCode(), Description?.GetHashCode()); + + public static bool operator ==( + ScalarTypeDefinitionNode? left, + ScalarTypeDefinitionNode? right) + => Equals(left, right); + + public static bool operator !=( + ScalarTypeDefinitionNode? left, + ScalarTypeDefinitionNode? right) + => !Equals(left, right); } diff --git a/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeDefinitionNodeBase.cs b/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeDefinitionNodeBase.cs index 43763efc141..cddc5029cf0 100644 --- a/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeDefinitionNodeBase.cs +++ b/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeDefinitionNodeBase.cs @@ -1,9 +1,11 @@ +using System; using System.Collections.Generic; namespace HotChocolate.Language; public abstract class ScalarTypeDefinitionNodeBase : NamedSyntaxNode + , IEquatable { protected ScalarTypeDefinitionNodeBase( Location? location, @@ -11,4 +13,68 @@ protected ScalarTypeDefinitionNodeBase( IReadOnlyList directives) : base(location, name, directives) { } + + /// + /// Determines whether the specified + /// is equal to the current . + /// + /// + /// The to compare with the current + /// . + /// + /// + /// true if the specified is equal + /// to the current ; + /// otherwise, false. + /// + public bool Equals(ScalarTypeDefinitionNodeBase? other) + { + if (other is null) + { + return false; + } + + if (ReferenceEquals(this, other)) + { + return true; + } + + return Name.IsEqualTo(other.Name) && Directives.IsEqualTo(other.Directives); + } + + /// + /// Determines whether the specified is equal to + /// the current . + /// + /// + /// The to compare with the current + /// . + /// + /// + /// true if the specified is equal to the + /// current ; otherwise, false. + /// + public override bool Equals(object? obj) + => Equals(obj as ScalarTypeDefinitionNodeBase); + + /// + /// Serves as a hash function for a + /// object. + /// + /// + /// A hash code for this instance that is suitable for use in + /// hashing algorithms and data structures such as a hash table. + /// + public override int GetHashCode() + => HashCode.Combine(Kind, Name?.GetHashCode(), Directives?.GetHashCode()); + + public static bool operator ==( + ScalarTypeDefinitionNodeBase? left, + ScalarTypeDefinitionNodeBase? right) + => Equals(left, right); + + public static bool operator !=( + ScalarTypeDefinitionNodeBase? left, + ScalarTypeDefinitionNodeBase? right) + => !Equals(left, right); } diff --git a/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeExtensionNode.cs b/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeExtensionNode.cs index 3fe0f696664..97dcee8d950 100644 --- a/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeExtensionNode.cs +++ b/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeExtensionNode.cs @@ -66,4 +66,55 @@ public ScalarTypeExtensionNode WithDirectives( return new ScalarTypeExtensionNode( Location, Name, directives); } + + + /// + /// Determines whether the specified + /// is equal to the current . + /// + /// + /// The to compare with the current + /// . + /// + /// + /// true if the specified is equal + /// to the current ; + /// otherwise, false. + /// + public bool Equals(ScalarTypeExtensionNode? other) => base.Equals(other); + + /// + /// Determines whether the specified is equal to + /// the current . + /// + /// + /// The to compare with the current + /// . + /// + /// + /// true if the specified is equal to the + /// current ; otherwise, false. + /// + public override bool Equals(object? obj) + => Equals(obj as ScalarTypeExtensionNode); + + /// + /// Serves as a hash function for a + /// object. + /// + /// + /// A hash code for this instance that is suitable for use in + /// hashing algorithms and data structures such as a hash table. + /// + public override int GetHashCode() => base.GetHashCode(); + + public static bool operator ==( + ScalarTypeExtensionNode? left, + ScalarTypeExtensionNode? right) + => Equals(left, right); + + public static bool operator !=( + ScalarTypeExtensionNode? left, + ScalarTypeExtensionNode? right) + => !Equals(left, right); } diff --git a/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/ScalarTypeDefinitionNodeTests.cs b/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/ScalarTypeDefinitionNodeTests.cs index 967cb588477..78a74507ca1 100644 --- a/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/ScalarTypeDefinitionNodeTests.cs +++ b/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/ScalarTypeDefinitionNodeTests.cs @@ -6,7 +6,8 @@ namespace HotChocolate.Language.SyntaxTree; public class ScalarTypeDefinitionNodeTests { - private readonly NameNode _name = new("name1"); + private readonly NameNode _name1 = new("name1"); + private readonly NameNode _name2 = new("name2"); private readonly StringValueNode _description1 = new("value1"); private readonly StringValueNode _description2 = new("value2"); private readonly IReadOnlyList _directives = Array.Empty(); @@ -15,20 +16,23 @@ public class ScalarTypeDefinitionNodeTests public void Equals_With_Same_Location() { // arrange - var a = new ScalarTypeDefinitionNode(new Location(1, 1, 1, 1), _name, _description1, _directives); - var b = new ScalarTypeDefinitionNode(new Location(1, 1, 1, 1), _name, _description1, _directives); - var c = new ScalarTypeDefinitionNode(new Location(1, 1, 1, 1), _name, _description2, _directives); + var a = new ScalarTypeDefinitionNode(TestLocations.Location1, _name1, _description1, _directives); + var b = new ScalarTypeDefinitionNode(TestLocations.Location1, _name1, _description1, _directives); + var c = new ScalarTypeDefinitionNode(TestLocations.Location1, _name1, _description2, _directives); + var d = new ScalarTypeDefinitionNode(TestLocations.Location1, _name2, _description2, _directives); // act var abResult = a.Equals(b); var aaResult = a.Equals(a); var acResult = a.Equals(c); + var cdResult = c.Equals(d); var aNullResult = a.Equals(default); // assert Assert.True(abResult); Assert.True(aaResult); Assert.False(acResult); + Assert.False(cdResult); Assert.False(aNullResult); } @@ -36,9 +40,9 @@ public void Equals_With_Same_Location() public void Equals_With_Different_Location() { // arrange - var a = new ScalarTypeDefinitionNode(new Location(1, 1, 1, 1), _name, _description1, _directives); - var b = new ScalarTypeDefinitionNode(new Location(2, 2, 2, 2), _name, _description1, _directives); - var c = new ScalarTypeDefinitionNode(new Location(3, 3, 3, 3), _name, _description2, _directives); + var a = new ScalarTypeDefinitionNode(TestLocations.Location1, _name1, _description1, _directives); + var b = new ScalarTypeDefinitionNode(TestLocations.Location2, _name1, _description1, _directives); + var c = new ScalarTypeDefinitionNode(TestLocations.Location3, _name1, _description2, _directives); // act var abResult = a.Equals(b); @@ -57,21 +61,24 @@ public void Equals_With_Different_Location() public void GetHashCode_With_Location() { // arrange - var a = new ScalarTypeDefinitionNode(new Location(1, 1, 1, 1), _name, _description1, _directives); - var b = new ScalarTypeDefinitionNode(new Location(2, 2, 2, 2), _name, _description1, _directives); - var c = new ScalarTypeDefinitionNode(new Location(1, 1, 1, 1), _name, _description2, _directives); - var d = new ScalarTypeDefinitionNode(new Location(2, 2, 2, 2), _name, _description2, _directives); + var a = new ScalarTypeDefinitionNode(TestLocations.Location1, _name1, _description1, _directives); + var b = new ScalarTypeDefinitionNode(TestLocations.Location2, _name1, _description1, _directives); + var c = new ScalarTypeDefinitionNode(TestLocations.Location1, _name1, _description2, _directives); + var d = new ScalarTypeDefinitionNode(TestLocations.Location2, _name1, _description2, _directives); + var e = new ScalarTypeDefinitionNode(TestLocations.Location1, _name2, _description2, _directives); // act var aHash = a.GetHashCode(); var bHash = b.GetHashCode(); var cHash = c.GetHashCode(); var dHash = d.GetHashCode(); + var eHash = e.GetHashCode(); // assert Assert.Equal(aHash, bHash); Assert.NotEqual(aHash, cHash); Assert.Equal(cHash, dHash); Assert.NotEqual(aHash, dHash); + Assert.NotEqual(dHash, eHash); } } diff --git a/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/ScalarTypeExtensionNodeTests.cs b/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/ScalarTypeExtensionNodeTests.cs new file mode 100644 index 00000000000..61935413b53 --- /dev/null +++ b/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/ScalarTypeExtensionNodeTests.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using Xunit; + +namespace HotChocolate.Language.SyntaxTree; + +public class ScalarTypeExtensionNodeTests +{ + private readonly NameNode _name1 = new("name1"); + private readonly NameNode _name2 = new("name2"); + private readonly IReadOnlyList _directives = Array.Empty(); + + [Fact] + public void Equals_With_Same_Location() + { + // arrange + var a = new ScalarTypeExtensionNode(TestLocations.Location1, _name1, _directives); + var b = new ScalarTypeExtensionNode(TestLocations.Location1, _name1, _directives); + var c = new ScalarTypeExtensionNode(TestLocations.Location1, _name2, _directives); + + // act + var abResult = a.Equals(b); + var aaResult = a.Equals(a); + var acResult = a.Equals(c); + var aNullResult = a.Equals(default); + + // assert + Assert.True(abResult); + Assert.True(aaResult); + Assert.False(acResult); + Assert.False(aNullResult); + } + + [Fact] + public void Equals_With_Different_Location() + { + // arrange + var a = new ScalarTypeExtensionNode(TestLocations.Location1, _name1, _directives); + var b = new ScalarTypeExtensionNode(TestLocations.Location2, _name1, _directives); + var c = new ScalarTypeExtensionNode(TestLocations.Location3, _name2, _directives); + + // act + var abResult = a.Equals(b); + var aaResult = a.Equals(a); + var acResult = a.Equals(c); + var aNullResult = a.Equals(default); + + // assert + Assert.True(abResult); + Assert.True(aaResult); + Assert.False(acResult); + Assert.False(aNullResult); + } + + [Fact] + public void GetHashCode_With_Location() + { + // arrange + var a = new ScalarTypeExtensionNode(TestLocations.Location1, _name1, _directives); + var b = new ScalarTypeExtensionNode(TestLocations.Location2, _name1, _directives); + var c = new ScalarTypeExtensionNode(TestLocations.Location1, _name2, _directives); + var d = new ScalarTypeExtensionNode(TestLocations.Location2, _name2, _directives); + + // act + var aHash = a.GetHashCode(); + var bHash = b.GetHashCode(); + var cHash = c.GetHashCode(); + var dHash = d.GetHashCode(); + + // assert + Assert.Equal(aHash, bHash); + Assert.NotEqual(aHash, cHash); + Assert.Equal(cHash, dHash); + Assert.NotEqual(aHash, dHash); + } +} From 32842f67278de6cd9845bae1067a760d9d0d124b Mon Sep 17 00:00:00 2001 From: Tassilo Singhammer Date: Wed, 6 Apr 2022 18:17:38 +0200 Subject: [PATCH 5/7] Test for RequiredMofidierNode added --- .../RequiredModifierNode.cs | 2 +- .../RequiredModifierNodeTests.cs | 75 +++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 src/HotChocolate/Language/test/Language.SyntaxTree.Tests/RequiredModifierNodeTests.cs diff --git a/src/HotChocolate/Language/src/Language.SyntaxTree/RequiredModifierNode.cs b/src/HotChocolate/Language/src/Language.SyntaxTree/RequiredModifierNode.cs index d80a1783247..a8d6e398f8d 100644 --- a/src/HotChocolate/Language/src/Language.SyntaxTree/RequiredModifierNode.cs +++ b/src/HotChocolate/Language/src/Language.SyntaxTree/RequiredModifierNode.cs @@ -57,7 +57,7 @@ public IEnumerable GetNodes() public bool Equals(RequiredModifierNode? other) { - if (ReferenceEquals(null, other)) + if (other is null) { return false; } diff --git a/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/RequiredModifierNodeTests.cs b/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/RequiredModifierNodeTests.cs new file mode 100644 index 00000000000..5c23a6803db --- /dev/null +++ b/src/HotChocolate/Language/test/Language.SyntaxTree.Tests/RequiredModifierNodeTests.cs @@ -0,0 +1,75 @@ +using Xunit; + +namespace HotChocolate.Language.SyntaxTree; + +public class RequiredModifierNodeTests +{ + private readonly ListNullabilityNode _element1 = + new(new Location(1, 1, 1, 1), null); + private readonly ListNullabilityNode _element2 = + new(new Location(1, 1, 1, 1), new RequiredModifierNode(null, null)); + + [Fact] + public void Equals_With_Same_Location() + { + // arrange + var a = new RequiredModifierNode(new Location(1, 1, 1, 1), _element1); + var b = new RequiredModifierNode(new Location(1, 1, 1, 1), _element1); + var c = new RequiredModifierNode(new Location(1, 1, 1, 1), _element2); + + // act + var abResult = a.Equals(b); + var aaResult = a.Equals(a); + var acResult = a.Equals(c); + var aNullResult = a.Equals(default); + + // assert + Assert.True(abResult); + Assert.True(aaResult); + Assert.False(acResult); + Assert.False(aNullResult); + } + + [Fact] + public void Equals_With_Different_Location() + { + // arrange + var a = new RequiredModifierNode(new Location(1, 1, 1, 1), _element1); + var b = new RequiredModifierNode(new Location(2, 2, 2, 2), _element1); + var c = new RequiredModifierNode(new Location(3, 3, 3, 3), _element2); + + // act + var abResult = a.Equals(b); + var aaResult = a.Equals(a); + var acResult = a.Equals(c); + var aNullResult = a.Equals(default); + + // assert + Assert.True(abResult); + Assert.True(aaResult); + Assert.False(acResult); + Assert.False(aNullResult); + } + + [Fact] + public void GetHashCode_With_Location() + { + // arrange + var a = new RequiredModifierNode(new Location(1, 1, 1, 1), _element1); + var b = new RequiredModifierNode(new Location(2, 2, 2, 2), _element1); + var c = new RequiredModifierNode(new Location(1, 1, 1, 1), _element2); + var d = new RequiredModifierNode(new Location(2, 2, 2, 2), _element2); + + // act + var aHash = a.GetHashCode(); + var bHash = b.GetHashCode(); + var cHash = c.GetHashCode(); + var dHash = d.GetHashCode(); + + // assert + Assert.Equal(aHash, bHash); + Assert.NotEqual(aHash, cHash); + Assert.Equal(cHash, dHash); + Assert.NotEqual(aHash, dHash); + } +} From cb41dad6cb45c55328b7a505b48563653c6d2245 Mon Sep 17 00:00:00 2001 From: Michael Staib Date: Thu, 7 Apr 2022 13:36:47 +0200 Subject: [PATCH 6/7] Added more xml docs --- .../InputObjectTypeDefinitionNode.cs | 17 +++ .../RequiredModifierNode.cs | 53 ++++++++ .../ScalarTypeDefinitionNode.cs | 125 ++++++++++++++---- 3 files changed, 166 insertions(+), 29 deletions(-) diff --git a/src/HotChocolate/Language/src/Language.SyntaxTree/InputObjectTypeDefinitionNode.cs b/src/HotChocolate/Language/src/Language.SyntaxTree/InputObjectTypeDefinitionNode.cs index 9d17e2f65b9..c9eab1c1917 100644 --- a/src/HotChocolate/Language/src/Language.SyntaxTree/InputObjectTypeDefinitionNode.cs +++ b/src/HotChocolate/Language/src/Language.SyntaxTree/InputObjectTypeDefinitionNode.cs @@ -220,11 +220,28 @@ public override bool Equals(object? obj) public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), Description); + /// + /// The equal operator. + /// + /// The left parameter + /// The right parameter + /// + /// true if and are equal. + /// + public static bool operator ==( InputObjectTypeDefinitionNode? left, InputObjectTypeDefinitionNode? right) => Equals(left, right); + /// + /// The not equal operator. + /// + /// The left parameter + /// The right parameter + /// + /// true if and are not equal. + /// public static bool operator !=( InputObjectTypeDefinitionNode? left, InputObjectTypeDefinitionNode? right) diff --git a/src/HotChocolate/Language/src/Language.SyntaxTree/RequiredModifierNode.cs b/src/HotChocolate/Language/src/Language.SyntaxTree/RequiredModifierNode.cs index a8d6e398f8d..633aa397405 100644 --- a/src/HotChocolate/Language/src/Language.SyntaxTree/RequiredModifierNode.cs +++ b/src/HotChocolate/Language/src/Language.SyntaxTree/RequiredModifierNode.cs @@ -4,10 +4,22 @@ namespace HotChocolate.Language; +/// +/// Represents the required modifier syntax. +/// public sealed class RequiredModifierNode : INullabilityModifierNode , IEquatable { + /// + /// Initializes a new instance of . + /// + /// + /// The location of the syntax node within the original source text. + /// + /// + /// The list nullability modifier. + /// public RequiredModifierNode(Location? location, ListNullabilityNode? element) { Location = location; @@ -55,6 +67,16 @@ public IEnumerable GetNodes() /// public string ToString(bool indented) => SyntaxPrinter.Print(this, indented); + /// + /// Indicates whether the current object is equal to another object of the same type. + /// + /// + /// An object to compare with this object. + /// + /// + /// true if the current object is equal to the parameter; + /// otherwise, false. + /// public bool Equals(RequiredModifierNode? other) { if (other is null) @@ -70,16 +92,47 @@ public bool Equals(RequiredModifierNode? other) return Equals(Element, other.Element); } + /// + /// Determines whether the specified object is equal to the current object. + /// + /// + /// The object to compare with the current object. + /// + /// + /// true if the specified object is equal to the current object; otherwise, false. + /// public override bool Equals(object? obj) => ReferenceEquals(this, obj) || (obj is RequiredModifierNode other && Equals(other)); + /// + /// Serves as the default hash function. + /// + /// + /// A hash code for the current object. + /// public override int GetHashCode() => HashCode.Combine(Kind, Element); + /// + /// The equal operator. + /// + /// The left parameter + /// The right parameter + /// + /// true if and are equal. + /// public static bool operator ==(RequiredModifierNode? left, RequiredModifierNode? right) => Equals(left, right); + /// + /// The not equal operator. + /// + /// The left parameter + /// The right parameter + /// + /// true if and are not equal. + /// public static bool operator !=(RequiredModifierNode? left, RequiredModifierNode? right) => !Equals(left, right); } diff --git a/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeDefinitionNode.cs b/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeDefinitionNode.cs index 7e56d5108ef..9aa6c731bfb 100644 --- a/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeDefinitionNode.cs +++ b/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeDefinitionNode.cs @@ -4,11 +4,35 @@ namespace HotChocolate.Language; +/// +/// Represents the scalar definition syntax. +/// +/// Scalar types represent primitive leaf values in a GraphQL type system. +/// GraphQL responses take the form of a hierarchical tree; +/// the leaves of this tree are typically GraphQL Scalar types +/// (but may also be Enum types or null values). +/// +/// public sealed class ScalarTypeDefinitionNode : ScalarTypeDefinitionNodeBase , ITypeDefinitionNode , IEquatable { + /// + /// Initializes a new instance of . + /// + /// + /// The location of the syntax node within the original source text. + /// + /// + /// The name of the scalar. + /// + /// + /// The description of the scalar. + /// + /// + /// The applied directives. + /// public ScalarTypeDefinitionNode( Location? location, NameNode name, @@ -19,10 +43,16 @@ public ScalarTypeDefinitionNode( Description = description; } - public override SyntaxKind Kind { get; } = SyntaxKind.ScalarTypeDefinition; + /// + public override SyntaxKind Kind => SyntaxKind.ScalarTypeDefinition; + /// + /// Gets the scalar description. + /// + /// public StringValueNode? Description { get; } + /// public override IEnumerable GetNodes() { if (Description is { }) @@ -59,35 +89,58 @@ public override IEnumerable GetNodes() /// public override string ToString(bool indented) => SyntaxPrinter.Print(this, indented); + /// + /// Creates a new node from the current instance and replaces the + /// with . + /// + /// + /// The location that shall be used to replace the current location. + /// + /// + /// Returns the new node with the new . + /// public ScalarTypeDefinitionNode WithLocation(Location? location) - { - return new ScalarTypeDefinitionNode( - location, Name, Description, - Directives); - } + => new(location, Name, Description, Directives); + /// + /// Creates a new node from the current instance and replaces the + /// with . + /// + /// + /// The name that shall be used to replace the current name. + /// + /// + /// Returns the new node with the new . + /// public ScalarTypeDefinitionNode WithName(NameNode name) - { - return new ScalarTypeDefinitionNode( - Location, name, Description, - Directives); - } + => new(Location, name, Description, Directives); - public ScalarTypeDefinitionNode WithDescription( - StringValueNode? description) - { - return new ScalarTypeDefinitionNode( - Location, Name, description, - Directives); - } + /// + /// Creates a new node from the current instance and replaces the + /// with . + /// + /// + /// The description that shall be used to replace the current description. + /// + /// + /// Returns the new node with the new . + /// + public ScalarTypeDefinitionNode WithDescription(StringValueNode? description) + => new(Location, Name, description, Directives); - public ScalarTypeDefinitionNode WithDirectives( - IReadOnlyList directives) - { - return new ScalarTypeDefinitionNode( - Location, Name, Description, - directives); - } + /// + /// Creates a new node from the current instance and replaces the + /// with . + /// + /// + /// The directives that shall be used to replace the current + /// . + /// + /// + /// Returns the new node with the new . + /// + public ScalarTypeDefinitionNode WithDirectives(IReadOnlyList directives) + => new(Location, Name, Description, directives); /// /// Determines whether the specified @@ -103,9 +156,7 @@ public ScalarTypeDefinitionNode WithDirectives( /// otherwise, false. /// public bool Equals(ScalarTypeDefinitionNode? other) - { - return base.Equals(other) && Description.IsEqualTo(other.Description); - } + => base.Equals(other) && Description.IsEqualTo(other.Description); /// /// Determines whether the specified is equal to @@ -131,13 +182,29 @@ public override bool Equals(object? obj) /// hashing algorithms and data structures such as a hash table. /// public override int GetHashCode() - => HashCode.Combine(base.GetHashCode(), Description?.GetHashCode()); + => HashCode.Combine(base.GetHashCode(), Kind, Description?.GetHashCode()); + /// + /// The equal operator. + /// + /// The left parameter + /// The right parameter + /// + /// true if and are equal. + /// public static bool operator ==( ScalarTypeDefinitionNode? left, ScalarTypeDefinitionNode? right) => Equals(left, right); + /// + /// The not equal operator. + /// + /// The left parameter + /// The right parameter + /// + /// true if and are not equal. + /// public static bool operator !=( ScalarTypeDefinitionNode? left, ScalarTypeDefinitionNode? right) From d3f41dbe0e450a9ed3c46d7b2f07f10158258ee3 Mon Sep 17 00:00:00 2001 From: Michael Staib Date: Thu, 7 Apr 2022 22:41:46 +0200 Subject: [PATCH 7/7] Added more docs --- .../ScalarTypeDefinitionNode.cs | 2 +- .../ScalarTypeDefinitionNodeBase.cs | 80 ----------------- .../ScalarTypeExtensionNode.cs | 89 +++++++++++++++---- 3 files changed, 75 insertions(+), 96 deletions(-) delete mode 100644 src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeDefinitionNodeBase.cs diff --git a/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeDefinitionNode.cs b/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeDefinitionNode.cs index 9aa6c731bfb..dda4494d376 100644 --- a/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeDefinitionNode.cs +++ b/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeDefinitionNode.cs @@ -14,7 +14,7 @@ namespace HotChocolate.Language; /// /// public sealed class ScalarTypeDefinitionNode - : ScalarTypeDefinitionNodeBase + : NamedSyntaxNode , ITypeDefinitionNode , IEquatable { diff --git a/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeDefinitionNodeBase.cs b/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeDefinitionNodeBase.cs deleted file mode 100644 index cddc5029cf0..00000000000 --- a/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeDefinitionNodeBase.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace HotChocolate.Language; - -public abstract class ScalarTypeDefinitionNodeBase - : NamedSyntaxNode - , IEquatable -{ - protected ScalarTypeDefinitionNodeBase( - Location? location, - NameNode name, - IReadOnlyList directives) - : base(location, name, directives) - { } - - /// - /// Determines whether the specified - /// is equal to the current . - /// - /// - /// The to compare with the current - /// . - /// - /// - /// true if the specified is equal - /// to the current ; - /// otherwise, false. - /// - public bool Equals(ScalarTypeDefinitionNodeBase? other) - { - if (other is null) - { - return false; - } - - if (ReferenceEquals(this, other)) - { - return true; - } - - return Name.IsEqualTo(other.Name) && Directives.IsEqualTo(other.Directives); - } - - /// - /// Determines whether the specified is equal to - /// the current . - /// - /// - /// The to compare with the current - /// . - /// - /// - /// true if the specified is equal to the - /// current ; otherwise, false. - /// - public override bool Equals(object? obj) - => Equals(obj as ScalarTypeDefinitionNodeBase); - - /// - /// Serves as a hash function for a - /// object. - /// - /// - /// A hash code for this instance that is suitable for use in - /// hashing algorithms and data structures such as a hash table. - /// - public override int GetHashCode() - => HashCode.Combine(Kind, Name?.GetHashCode(), Directives?.GetHashCode()); - - public static bool operator ==( - ScalarTypeDefinitionNodeBase? left, - ScalarTypeDefinitionNodeBase? right) - => Equals(left, right); - - public static bool operator !=( - ScalarTypeDefinitionNodeBase? left, - ScalarTypeDefinitionNodeBase? right) - => !Equals(left, right); -} diff --git a/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeExtensionNode.cs b/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeExtensionNode.cs index 97dcee8d950..bfed6303c44 100644 --- a/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeExtensionNode.cs +++ b/src/HotChocolate/Language/src/Language.SyntaxTree/ScalarTypeExtensionNode.cs @@ -3,10 +3,30 @@ namespace HotChocolate.Language; +/// +/// Scalar type extensions are used to represent a scalar type which has been +/// extended from some original scalar type. For example, this might be used +/// by a GraphQL tool or service which adds directives to an existing scalar. +/// public sealed class ScalarTypeExtensionNode - : ScalarTypeDefinitionNodeBase + : NamedSyntaxNode , ITypeExtensionNode { + /// + /// Initializes a new instance of . + /// + /// + /// The location of the syntax node within the original source text. + /// + /// + /// The name of the scalar. + /// + /// + /// The description of the scalar. + /// + /// + /// The applied directives. + /// public ScalarTypeExtensionNode( Location? location, NameNode name, @@ -15,8 +35,10 @@ public ScalarTypeExtensionNode( { } - public override SyntaxKind Kind { get; } = SyntaxKind.ScalarTypeExtension; + /// + public override SyntaxKind Kind => SyntaxKind.ScalarTypeExtension; + /// public override IEnumerable GetNodes() { yield return Name; @@ -48,25 +70,46 @@ public override IEnumerable GetNodes() /// public override string ToString(bool indented) => SyntaxPrinter.Print(this, indented); + /// + /// Creates a new node from the current instance and replaces the + /// with . + /// + /// + /// The location that shall be used to replace the current location. + /// + /// + /// Returns the new node with the new . + /// public ScalarTypeExtensionNode WithLocation(Location? location) - { - return new ScalarTypeExtensionNode( - location, Name, Directives); - } + => new(location, Name, Directives); + /// + /// Creates a new node from the current instance and replaces the + /// with . + /// + /// + /// The name that shall be used to replace the current name. + /// + /// + /// Returns the new node with the new . + /// public ScalarTypeExtensionNode WithName(NameNode name) - { - return new ScalarTypeExtensionNode( - Location, name, Directives); - } + => new(Location, name, Directives); + /// + /// Creates a new node from the current instance and replaces the + /// with . + /// + /// + /// The directives that shall be used to replace the current + /// . + /// + /// + /// Returns the new node with the new . + /// public ScalarTypeExtensionNode WithDirectives( IReadOnlyList directives) - { - return new ScalarTypeExtensionNode( - Location, Name, directives); - } - + => new(Location, Name, directives); /// /// Determines whether the specified @@ -108,11 +151,27 @@ public override bool Equals(object? obj) /// public override int GetHashCode() => base.GetHashCode(); + /// + /// The equal operator. + /// + /// The left parameter + /// The right parameter + /// + /// true if and are equal. + /// public static bool operator ==( ScalarTypeExtensionNode? left, ScalarTypeExtensionNode? right) => Equals(left, right); + /// + /// The not equal operator. + /// + /// The left parameter + /// The right parameter + /// + /// true if and are not equal. + /// public static bool operator !=( ScalarTypeExtensionNode? left, ScalarTypeExtensionNode? right)